From 3b13dccdbbe36beee0812a025752cacc3c5c6e14 Mon Sep 17 00:00:00 2001 From: Alex Dunmow Date: Thu, 19 Nov 2026 23:28:35 +0800 Subject: [PATCH] Pack codeless .bnp artifacts in the SDK Moves the codeless build, validation and pack path from cli/internal/bnp into a public bnp package so the CLI and the orchestrator share it. BuildCodelessFS packs from an fs.FS and returns the artifact bytes; the directory form calls it through os.DirFS. Output is byte-identical to the old CLI build. ADR 0009. Co-Authored-By: Claude Fable 5.2 --- bnp/codeless.go | 570 ++++++++++++++++++ bnp/codeless_test.go | 242 ++++++++ bnp/mixed_test.go | 80 +++ bnp/pack.go | 133 ++++ bnp/screenshots.go | 121 ++++ bnp/screenshots_test.go | 158 +++++ ...odeless-artifacts-are-packed-by-the-sdk.md | 44 ++ go.mod | 4 + go.sum | 11 + 9 files changed, 1363 insertions(+) create mode 100644 bnp/codeless.go create mode 100644 bnp/codeless_test.go create mode 100644 bnp/mixed_test.go create mode 100644 bnp/pack.go create mode 100644 bnp/screenshots.go create mode 100644 bnp/screenshots_test.go create mode 100644 docs/adr/0009-codeless-artifacts-are-packed-by-the-sdk.md diff --git a/bnp/codeless.go b/bnp/codeless.go new file mode 100644 index 0000000..31300b8 --- /dev/null +++ b/bnp/codeless.go @@ -0,0 +1,570 @@ +// Package bnp builds codeless .bnp plugin artifacts: it validates the +// declarative plugin files and packs them as a zstd-compressed tar. +package bnp + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "io/fs" + "os" + "path" + "path/filepath" + "strings" + + abiv1 "git.dev.alexdunmow.com/block/pluginsdk/abi/v1" + core "git.dev.alexdunmow.com/block/pluginsdk/plugin" + "google.golang.org/protobuf/proto" + "gopkg.in/yaml.v3" +) + +// Codeless artifacts (WO-WZ-020): a .bnp with NO plugin.wasm — pure +// declaration the host runs. Classification is by repo shape: a plugin repo +// with no Go source builds codeless; a repo with Go builds wasm as always +// (a converted repo DELETES its Go — that's the point). Both artifact kinds +// may carry blocks/, templates/, and seed/; codeless just has nothing else. + +// Required top-level artifact members (mirrors the CMS reader). +const ( + FileMod = "plugin.mod" + FileManifest = "manifest.pb" +) + +// Declarative artifact dirs shared by both build paths. +const ( + DirBlocks = "blocks" + DirTemplates = "templates" + DirSeed = "seed" +) + +// hostAbiVersion is the ABI major version the packer speaks. It must equal +// the guest AbiVersion / the reader's supported major (1). +const hostAbiVersion uint32 = 1 + +// manifestYAMLName is the optional root-level declarative manifest source for +// codeless plugins (the counterpart of what DESCRIBE captures from Go code). +const manifestYAMLName = "manifest.yaml" + +// BuildOptions configures BuildCodeless. +type BuildOptions struct { + // Dir is the plugin repo root (holds plugin.mod and the main Go package). + Dir string + // Output is the destination .bnp path. Empty → "-.bnp" in + // the current working directory. + Output string +} + +// BuildResult summarizes a produced artifact for the CLI summary table. +type BuildResult struct { + OutputPath string + Name string + Version string + // Codeless marks a declarative artifact (no plugin.wasm, WO-WZ-020). + Codeless bool + WasmBytes int64 + ManifestBytes int64 + ArtifactBytes int64 // on-disk .bnp size + UncompBytes int64 // sum of packed file sizes + BlockCount int + TemplateCount int + AdminPages int + JobTypes int + Hooks []string + DataDir bool + IncludedDirs []string + // PreviewIncluded/ScreenshotCount report the packed presentation members + // (root preview.png + screenshots/); the registry ingests these into the + // plugin's gallery at publish. + PreviewIncluded bool + ScreenshotCount int +} + +// manifestYAML mirrors the declarative PluginManifest fields a codeless +// plugin can set. File-valued keys are paths relative to the repo root. +type manifestYAML struct { + ThemePresets string `yaml:"theme_presets"` // JSON file + BundledFonts string `yaml:"bundled_fonts"` // JSON file + SettingsSchema string `yaml:"settings_schema"` // JSON file + MasterPages string `yaml:"master_pages"` // JSON file ([]masterPageJSON) + RequiredIconPacks []string `yaml:"required_icon_packs"` + SystemTemplates []struct { + Key string `yaml:"key"` + Title string `yaml:"title"` + Description string `yaml:"description"` + } `yaml:"system_templates"` + PageTemplates []struct { + System string `yaml:"system"` + Key string `yaml:"key"` + Title string `yaml:"title"` + Description string `yaml:"description"` + Slots []string `yaml:"slots"` + } `yaml:"page_templates"` + // TemplateOverrides declare theme-scoped overrides of builtin block + // rendering. Source convention: templates/overrides/