Skip to content

feat(sdk-go): TinyGo-targeted plugin SDK with typed host call wrappers#462

Merged
tayebmokni merged 2 commits into
mainfrom
feat/plugin-sdk-go
May 25, 2026
Merged

feat(sdk-go): TinyGo-targeted plugin SDK with typed host call wrappers#462
tayebmokni merged 2 commits into
mainfrom
feat/plugin-sdk-go

Conversation

@tayebmokni
Copy link
Copy Markdown
Contributor

Closes #237.

packages/go/sdk: TinyGo-compatible Go SDK for GoNext plugin authors.

  • PluginInit + RegisterAction / RegisterFilter
  • Typed wrappers over every gn_* host ABI (Host.HTTP / .DB / .Cache / .Audit / .Cron / .KV / .Media / .Users / .Secrets / .Metric / .Event / .Span / .I18n / .Log / .Time)
  • Manifest builder (NewManifest().WithCapability(...).Build())
  • cli/gonext/templates/go/ + gonext plugin init --template=go
  • examples/plugins/sdk-go-hello with TinyGo build
  • Codec unit tests + optional TinyGo integration test

🤖 Generated with Claude Code

tib0o0o and others added 2 commits May 25, 2026 22:10
…ifest, host wrappers)

Adds packages/go/sdk as its own Go module. The SDK provides typed
wrappers over every gn_* host ABI so plugin authors write Go that
compiles via TinyGo to a wasm32-wasi target.

Pieces:
  - codec.go         JSON-envelope mirror of abi/hooks (action / filter payloads,
                     ResultStatus, PackResult, MarshalActionPayload, ...)
  - hooks.go         Package-level dispatch registry, RegisterAction,
                     RegisterFilter, DispatchHook, PluginInit
  - manifest.go      Plugin-author-facing Manifest + fluent ManifestBuilder
                     (NewManifest().WithCapability().WithAction()....Build())
  - host.go          Top-level Host singleton with typed sub-APIs
                     (HTTP / DB / KV / Cache / Media / Users / Secrets /
                     Audit / Cron / Metric / Event / Span / I18n / Log / Time)
  - host_methods.go  Typed Host.X.Y methods that marshal Go shapes into
                     the host wire envelopes
  - host_stub.go     hostCall* stubs for the stock Go toolchain (so plugin
                     authors can unit-test handlers without TinyGo)
  - host_wasm.go     //go:wasmimport bindings to every gn_* host export,
                     gn_alloc / gn_free / gn_handle_hook exports
                     (wasm32-wasi build only)

Tests: 37 codec/hook/manifest unit tests covering round-trips, error
paths, dedup, builder defaults. All pass under the stock toolchain.

The SDK is wired into go.work so `go test
./packages/go/sdk/...` runs from the repo root. The package has zero
non-stdlib deps so the TinyGo build (added in a follow-up commit)
doesn't drag in the host module's pgx / redis / asynq closure.

Refs #237.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
…ation test

Closes the user-facing surface of the Go plugin SDK:

  - cli/gonext/cmd/plugin/init.go: `gonext plugin init --template=go
    <dir>` scaffolds a working plugin project from the embedded
    templates (main.go, manifest.json, go.mod, Makefile, .gitignore).
    Slug substitution honours --name= or sanitises the project
    basename to fit the manifest schema's regex.

  - cli/gonext/cmd/plugin/templates/go/: the embedded templates the
    scaffolder renders. The go.mod and main.go are .tmpl-suffixed so
    the cli/gonext module's build doesn't accidentally try to compile
    them as Go.

  - examples/plugins/sdk-go-hello/: worked example exercising
    posts.publish action + the_content filter + KV.Set + Audit.Emit
    via the SDK surface. Includes Makefile / build.sh / unit tests
    for the handler logic.

  - packages/go/sdk/README.md: 10-line hello-world plus the SDK
    surface inventory.

  - packages/go/sdk/tinygo_integration_test.go: optional integration
    test that runs `tinygo build -target=wasi` against
    sdk-go-hello when tinygo is on PATH. Skips otherwise so CI
    without the toolchain still passes.

Wired into go.work; all SDK + CLI + example tests pass under the
stock toolchain. The example builds cleanly under
`GOOS=wasip1 GOARCH=wasm go build` as a basic sanity check that
the SDK's wasmimport stanzas compile.

Refs #237.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
@tayebmokni tayebmokni enabled auto-merge (squash) May 25, 2026 20:17
@tayebmokni tayebmokni merged commit 97d06db into main May 25, 2026
12 of 15 checks passed
@tayebmokni tayebmokni deleted the feat/plugin-sdk-go branch May 25, 2026 20:24
tayebmokni pushed a commit that referenced this pull request May 25, 2026
Closes #242.

packages/ts/sdk-plugin: TypeScript SDK for GoNext plugin authors via
Javy (JavaScript → WASM).

- pluginInit + registerAction / registerFilter
- Typed wrappers over every gn_* host ABI through globalThis
- JSON envelope codec
- Manifest builder mirroring the Go side
- bin/gonext-sdk-build.js wraps esbuild + javy compile
- cli/gonext/templates/typescript + 'gonext plugin init --template=typescript'
- examples/plugins/sdk-ts-hello working example
- 54 Vitest tests (codec + manifest + dispatch)

This PR was rebased onto main after #460/#461/#462 landed; the
runInit dispatch now switches on template name and embeds both
templates/go and templates/typescript via the single templatesFS.

Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
tayebmokni pushed a commit that referenced this pull request May 25, 2026
Closes #239.

packages/rust/gonext-sdk + packages/rust/gonext-sdk-macros:
Cargo crates for Rust plugin authors.

- plugin_init! proc-macro generates gn_alloc/gn_free/_start/gn_handle_hook exports
- Safe typed wrappers over every gn_* host ABI (env, env_net, gonext_data, env_platform)
- JSON envelope codec via serde_json
- Manifest builder mirroring the Go side
- cli/gonext/cmd/plugin/templates/rust + 'gonext plugin init --template=rust'
- examples/plugins/sdk-rust-hello: working example (action + filter + kv.set + audit.emit)

Rebased onto main after #460/#461/#462 landed; init.go now switches
on template name. TestRunInitUnknownTemplate updated to use a
clearly-not-real template name so it stays robust as new templates
land.

Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
tayebmokni pushed a commit that referenced this pull request May 25, 2026
Closes #242.

packages/ts/sdk-plugin: TypeScript SDK for GoNext plugin authors via
Javy (JavaScript → WASM).

- pluginInit + registerAction / registerFilter
- Typed wrappers over every gn_* host ABI through globalThis
- JSON envelope codec
- Manifest builder mirroring the Go side
- bin/gonext-sdk-build.js wraps esbuild + javy compile
- cli/gonext/templates/typescript + 'gonext plugin init --template=typescript'
- examples/plugins/sdk-ts-hello working example
- 54 Vitest tests (codec + manifest + dispatch)

This PR was rebased onto main after #460/#461/#462 landed; the
runInit dispatch now switches on template name and embeds both
templates/go and templates/typescript via the single templatesFS.

Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
tayebmokni pushed a commit that referenced this pull request May 26, 2026
Closes #242.

packages/ts/sdk-plugin: TypeScript SDK for GoNext plugin authors via
Javy (JavaScript → WASM).

- pluginInit + registerAction / registerFilter
- Typed wrappers over every gn_* host ABI through globalThis
- JSON envelope codec
- Manifest builder mirroring the Go side
- bin/gonext-sdk-build.js wraps esbuild + javy compile
- cli/gonext/templates/typescript + 'gonext plugin init --template=typescript'
- examples/plugins/sdk-ts-hello working example
- 54 Vitest tests (codec + manifest + dispatch)

This PR was rebased onto main after #460/#461/#462 landed; the
runInit dispatch now switches on template name and embeds both
templates/go and templates/typescript via the single templatesFS.

Signed-off-by: Tayeb Mokni <tayeb.mokni@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin SDK (Go): TinyGo-targeted SDK with hook surface + typed host calls + manifest generator

2 participants