Alex Dunmow b6d40ed8ac feat: bootstrap block/pluginsdk — the proto-first plugin SDK (P1)
Bootstrap the plugin-facing SDK module so the fleet migration (P2) becomes a
mechanical block/core/X -> block/pluginsdk/X import rewrite.

- abi/proto/v1: the single source-of-truth ABI proto tree, copied from the cms
  authoring source (cms/backend/abi/proto/v1) with go_package retargeted to
  git.dev.alexdunmow.com/block/pluginsdk/abi/v1;abiv1. Kills the hand-kept
  cms/core proto duplication (audit gap 4).
- abi/v1: generated Go bindings (buf generate); byte-identical to core's abi/v1
  save the embedded go_package path.
- plugin/ (registration + DI surface), plugin/wasmguest/** (transport shim,
  caps stubs, bnwasm db driver, testdata fixtures + golden .pb), and the
  guest-facing type packages: blocks (+builtin/shared/tags), templates
  (+pongo/bn), auth, settings, content, gating, crypto, rbac, video, ai,
  subscriptions, menus, datasources. Internal imports rewritten core ->
  pluginsdk; zero block/core references remain.
- README/AGENTS(+CLAUDE symlink)/Makefile: proto is the contract, Go is one
  binding; no replace directives; templates/bn is a synced copy authored in cms.

Spec: cms docs/superpowers/specs/2026-07-07-proto-first-plugin-sdk-design.md

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 10:51:00 +08:00

98 lines
3.6 KiB
Go

// Package main is the WO-WZ-002 acceptance fixture: a minimal plugin with
// one block, one template, and one admin page, compiled to wasm with only
// the wasmguest boilerplate (main.go).
package main
import (
"context"
"fmt"
"io"
"strings"
"git.dev.alexdunmow.com/block/pluginsdk/blocks"
"git.dev.alexdunmow.com/block/pluginsdk/plugin"
"git.dev.alexdunmow.com/block/pluginsdk/templates"
)
// capReport is populated by the Load hook from capability calls, then
// surfaced through the greeting block ({"report": true}). It is the runtime
// proof that deps.Content / deps.Settings / deps.Bridge cross the wasm ABI
// end-to-end through the guest capability stubs (WO-WZ-003 acceptance).
var capReport string
// Registration is the fixture's plugin registration — the same shape a .so
// plugin exports, untouched by the wasm migration.
var Registration = plugin.PluginRegistration{
Name: "wasmfixture",
Version: "0.0.1",
Register: func(tr templates.TemplateRegistry, br blocks.BlockRegistry) error {
br.Register(blocks.BlockMeta{
Key: "greeting",
Title: "Greeting",
Description: "Renders a greeting",
Category: blocks.CategoryContent,
}, func(ctx context.Context, content map[string]any) string {
if boom, _ := content["boom"].(bool); boom {
panic("fixture kaboom")
}
if report, _ := content["report"].(bool); report {
return "<p>capreport:" + capReport + "</p>"
}
name, _ := content["name"].(string)
if name == "" {
name = "world"
}
if powered, _ := content["powered"].(bool); powered {
// Powered path: hand the host a template + data instead of final
// HTML, so the host renders it (pongo2) after this call returns.
return blocks.PoweredBlock("<p>hello {{ name }}</p>", map[string]any{"name": name})
}
return fmt.Sprintf("<p>hello %s</p>", name)
})
// Custom template tag + filter the host wires from manifest.declared_tags
// / declared_filters, invoked via HOOK_RENDER_TAG / HOOK_APPLY_FILTER.
blocks.RegisterTag("shout", func(args map[string]any, rctx blocks.RenderContext) (string, error) {
msg, _ := args["msg"].(string)
return "<strong>" + strings.ToUpper(msg) + "</strong>", nil
})
blocks.RegisterFilter("exclaim", func(input string, args map[string]any) (string, error) {
return input + "!", nil
})
return tr.Register("wasmfixture-page", func(ctx context.Context, doc map[string]any) templates.HTMLComponent {
title, _ := doc["title"].(string)
return htmlString("<!doctype html><title>" + title + "</title>")
})
},
// Load exercises the guest capability stubs exactly as a real plugin's
// service code does — unchanged calls against deps.Content / deps.Settings
// / deps.Bridge — proving they compile and cross the ABI for wasip1.
Load: func(deps plugin.CoreServices) error {
page, err := deps.Content.GetPage(context.Background(), "about")
if err != nil {
capReport = "content-err:" + err.Error()
return nil
}
site, err := deps.Settings.GetSiteSettings(context.Background())
if err != nil {
capReport = "settings-err:" + err.Error()
return nil
}
svc := deps.Bridge.GetService("other", "search") // cannot cross; expected nil
capReport = fmt.Sprintf("page=%s site=%v bridge_nil=%t",
page.Title, site["site_name"], svc == nil)
return nil
},
AdminPages: func() []plugin.AdminPage {
return []plugin.AdminPage{{
Key: "wasmfixture", Title: "Wasm Fixture", Icon: "flask", Route: "/admin/wasmfixture",
}}
},
}
type htmlString string
func (s htmlString) Render(_ context.Context, w io.Writer) error {
_, err := io.WriteString(w, string(s))
return err
}