Skip to content

feat(codegen): generate module bindings - #18

Closed
TomChv wants to merge 1 commit into
mainfrom
feat/codegen-module-mode
Closed

TomChv wants to merge 1 commit into
mainfrom
feat/codegen-module-mode

Conversation

@TomChv

@TomChv TomChv commented Aug 10, 2026

Copy link
Copy Markdown
Member

Add a module subcommand alongside client. Same generator, different
contract: the module's own types stay in client.gen.ts, only its dependencies
split into per-module files, and the bindings import the bundled library from
./core.js. The engine runtime mounts a module's sdk/ directory as
@dagger.io/dagger, so the files are emitted flat into --output for the caller
to lay down there — upstream nested them under sdk/src/api only to dig them
back out again.

The mode now drives what used to be independent config, so the two cannot
disagree: bundle imports are implied by module codegen, and the source-map
breadcrumbs rendered beside declarations resolve one level up from sdk/ rather
than the three the old nesting needed.

Drop the surface a TypeScript-only, engine-free generator never reads: the
SDKLang enum and Config.Lang, the Generator interface (one implementation, one
caller), GenerateTypeDefs (unimplemented), PostCommands and NeedRegenerate
(Go-only), and the module config fields that only ever fed the Go generator.

Design doc for the wider move included as design/module-gen.md.

Signed-off-by: Tom Chauveau [email protected]


Stack created with GitHub Stacks CLI • Give Feedback 💬

@TomChv
TomChv force-pushed the feat/codegen-module-mode branch from 217c7d5 to c8d6a12 Compare August 21, 2026 12:11
@TomChv
TomChv marked this pull request as ready for review August 25, 2026 16:02
@TomChv
TomChv force-pushed the feat/codegen-module-mode branch from c8d6a12 to 12f660c Compare August 25, 2026 16:06
@TomChv
TomChv requested a review from eunomie August 26, 2026 09:01
Add a `module` subcommand alongside `client`. Same generator, different
contract: the module's own types stay in client.gen.ts, only its dependencies
split into per-module files, and the bindings import the bundled library from
./core.js. The engine runtime mounts a module's sdk/ directory as
@dagger.io/dagger, so the files are emitted flat into --output for the caller
to lay down there — upstream nested them under sdk/src/api only to dig them
back out again.

The mode now drives what used to be independent config, so the two cannot
disagree: bundle imports are implied by module codegen, and the source-map
breadcrumbs rendered beside declarations resolve one level up from sdk/ rather
than the three the old nesting needed.

Drop the surface a TypeScript-only, engine-free generator never reads: the
SDKLang enum and Config.Lang, the Generator interface (one implementation, one
caller), GenerateTypeDefs (unimplemented), PostCommands and NeedRegenerate
(Go-only), and the module config fields that only ever fed the Go generator.

A per-dep file has two arms — declare the dep's own types, import core ones
from client.gen.ts — and no third for a sibling dependency's. The engine does
not let a module's API expose a type it neither owns nor gets from core, so
that case is unreachable; assert it rather than assume it, since the failure
mode is a file referencing a name it never imported.

Design doc for the wider move included as design/module-gen.md.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv

TomChv commented Aug 28, 2026

Copy link
Copy Markdown
Member Author

Superseded by #39, which squashes this whole stack into a single PR off main (same tree, byte for byte).

The stack had PRs overwriting each other — this one included — which made the intermediate states hard to reason about, and thirteen PRs each fanning out a full check suite made CI unreadable. Branch is left pushed, so nothing here is lost.

@TomChv TomChv closed this Aug 28, 2026
TomChv added a commit that referenced this pull request Aug 28, 2026
A TypeScript module's generated files — `sdk/`, `__dagger.entrypoint.ts`, and
the config the runtime reads — were produced by the engine: `dagger generate`
called into this SDK, which handed straight back to the engine's built-in
TypeScript runtime, which ran `cmd/codegen` and `ts-introspector` in nested
sessions. This SDK now produces them itself, the way it already produced
clients: schema and module metadata in as plain data, container execs, changeset
out, no round trip.

Three reasons, the same ones the client move had. The SDK repo should own what
the SDK emits, so a codegen fix is not an engine release. The upstream path
carries three SDK-lib origins, a Go+TypeScript shared binary, module/client
coexistence and per-runtime duplication, nearly all of which is dead on arrival
for our narrower contract. And codegen becomes `go test` plus `dagger check`
here instead of an engine integration test.

Running a module stays with the engine's runtime. That split is the hardest
constraint in the design: for a `dagger-module.toml` module the runtime does no
codegen at call time, it mounts `sdk/` as `@dagger.io/dagger` and executes the
committed entrypoint. Whatever generate writes *is* the artifact that runs, and
it has to satisfy an unchanged runtime byte for byte in the parts it reads.

**The library.** Generated bindings import their runtime from `./core.js`, a
bundle that only existed inside the engine image. `library/` vendors
dagger/dagger's `sdk/typescript` at v1.0.0-beta.11 and `.dagger/modules/packager`
builds the bundle from it with the same recipe and pinned image the engine uses,
committed so that generating a module needs no bun toolchain and no network. A
copy has no merge base git can compute, so `library/VENDOR.md` records the one it
would have had: source tag and commit, what was deliberately left behind, the
exhaustive list of local deltas, and the re-import procedure.

**Codegen.** `helpers/codegen` gains `module` (a module's own bindings, split
per dependency), `entrypoint` (the static dispatcher, rendered from the
introspector's typedef scan) and `library` (the vendored library's own
bindings) alongside `client`. `helpers/config-updator` writes the module config
the runtime reads.

**Routing.** `Mod.generate` takes the local path for `dagger-module.toml`
modules and keeps delegating for `dagger.json` ones, which regenerate at call
time regardless. Both stage the local dependency closure first — a dependent's
schema is only loadable once its deps' generated files exist — and both take
that staging back out of the changeset, each in the way its route requires.

Regeneration prunes the `*.gen.ts` it owns out of the baseline the generated
tree is layered onto. Layering is what keeps the module's own source and config
in the changeset, but it can only add, so a dependency dropped from the config
would otherwise keep its `<dep>.gen.ts` — an API against a module that is no
longer served, which a default tsc rejects. Pruned in one place, matching what
#37 established for client generation once `withNewDirectory` stopped meaning
different things on different workspace kinds.

**Engine pairing.** Everything here is built for one release. The SDK states it
once as `targetEngineVersion`; the runtime harness and every fixture read from
there, and a check fails when they disagree.

**Tests.** Golden tests over the renderers; e2e checks over the generated tree,
the routing, dependency edges in both config formats, config preservation and
binding pruning; a differential check that generates a fixture through this SDK
and through the engine and diffs everything but the bundle; and one fixture per
TypeScript runtime that loads a generated module and calls a function on it,
which is the only thing that proves the on-disk contract end to end.

Replaces the #18 → #34 stack, squashed: several of those PRs overwrote earlier
ones, which made the intermediate states hard to reason about and impossible to
test independently.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit that referenced this pull request Aug 28, 2026
A TypeScript module's generated files — `sdk/`, `__dagger.entrypoint.ts`, and
the config the runtime reads — were produced by the engine: `dagger generate`
called into this SDK, which handed straight back to the engine's built-in
TypeScript runtime, which ran `cmd/codegen` and `ts-introspector` in nested
sessions. This SDK now produces them itself, the way it already produced
clients: schema and module metadata in as plain data, container execs, changeset
out, no round trip.

Three reasons, the same ones the client move had. The SDK repo should own what
the SDK emits, so a codegen fix is not an engine release. The upstream path
carries three SDK-lib origins, a Go+TypeScript shared binary, module/client
coexistence and per-runtime duplication, nearly all of which is dead on arrival
for our narrower contract. And codegen becomes `go test` plus `dagger check`
here instead of an engine integration test.

Running a module stays with the engine's runtime. That split is the hardest
constraint in the design: for a `dagger-module.toml` module the runtime does no
codegen at call time, it mounts `sdk/` as `@dagger.io/dagger` and executes the
committed entrypoint. Whatever generate writes *is* the artifact that runs, and
it has to satisfy an unchanged runtime byte for byte in the parts it reads.

**The library.** Generated bindings import their runtime from `./core.js`, a
bundle that only existed inside the engine image. `library/` vendors
dagger/dagger's `sdk/typescript` at v1.0.0-beta.11 and `.dagger/modules/packager`
builds the bundle from it with the same recipe and pinned image the engine uses,
committed so that generating a module needs no bun toolchain and no network. A
copy has no merge base git can compute, so `library/VENDOR.md` records the one it
would have had: source tag and commit, what was deliberately left behind, the
exhaustive list of local deltas, and the re-import procedure.

**Codegen.** `helpers/codegen` gains `module` (a module's own bindings, split
per dependency), `entrypoint` (the static dispatcher, rendered from the
introspector's typedef scan) and `library` (the vendored library's own
bindings) alongside `client`. `helpers/config-updater` writes the module config
the runtime reads.

**Routing.** `Mod.generate` takes the local path for `dagger-module.toml`
modules and keeps delegating for `dagger.json` ones, which regenerate at call
time regardless. Both stage the local dependency closure first — a dependent's
schema is only loadable once its deps' generated files exist — and both take
that staging back out of the changeset, each in the way its route requires.

Regeneration prunes the `*.gen.ts` it owns out of the baseline the generated
tree is layered onto. Layering is what keeps the module's own source and config
in the changeset, but it can only add, so a dependency dropped from the config
would otherwise keep its `<dep>.gen.ts` — an API against a module that is no
longer served, which a default tsc rejects. Pruned in one place, matching what
different things on different workspace kinds.

**Engine pairing.** Everything here is built for one release. The SDK states it
once as `targetEngineVersion`; the runtime harness and every fixture read from
there, and a check fails when they disagree.

**Tests.** Golden tests over the renderers; e2e checks over the generated tree,
the routing, dependency edges in both config formats, config preservation and
binding pruning; a differential check that generates a fixture through this SDK
and through the engine and diffs everything but the bundle; and one fixture per
TypeScript runtime that loads a generated module and calls a function on it,
which is the only thing that proves the on-disk contract end to end.

Replaces the #18 → #34 stack, squashed: several of those PRs overwrote earlier
ones, which made the intermediate states hard to reason about and impossible to
test independently. Rebased onto #37 (beta.11) and #38 (the interface-return
fix and the config-updater rename); the entrypoint golden #38 added is
regenerated here, because this generator emits the source maps the engine
expects and main's did not.

Signed-off-by: Tom Chauveau <[email protected]>
TomChv added a commit that referenced this pull request Sep 1, 2026
A TypeScript module's generated files — `sdk/`, `__dagger.entrypoint.ts`, and
the config the runtime reads — were produced by the engine: `dagger generate`
called into this SDK, which handed straight back to the engine's built-in
TypeScript runtime, which ran `cmd/codegen` and `ts-introspector` in nested
sessions. This SDK now produces them itself, the way it already produced
clients: schema and module metadata in as plain data, container execs, changeset
out, no round trip.

Three reasons, the same ones the client move had. The SDK repo should own what
the SDK emits, so a codegen fix is not an engine release. The upstream path
carries three SDK-lib origins, a Go+TypeScript shared binary, module/client
coexistence and per-runtime duplication, nearly all of which is dead on arrival
for our narrower contract. And codegen becomes `go test` plus `dagger check`
here instead of an engine integration test.

Running a module stays with the engine's runtime. That split is the hardest
constraint in the design: for a `dagger-module.toml` module the runtime does no
codegen at call time, it mounts `sdk/` as `@dagger.io/dagger` and executes the
committed entrypoint. Whatever generate writes *is* the artifact that runs, and
it has to satisfy an unchanged runtime byte for byte in the parts it reads.

**The library.** Generated bindings import their runtime from `./core.js`, a
bundle that only existed inside the engine image. `library/` vendors
dagger/dagger's `sdk/typescript` at v1.0.0-beta.11 and `.dagger/modules/packager`
builds the bundle from it with the same recipe and pinned image the engine uses,
committed so that generating a module needs no bun toolchain and no network. A
copy has no merge base git can compute, so `library/VENDOR.md` records the one it
would have had: source tag and commit, what was deliberately left behind, the
exhaustive list of local deltas, and the re-import procedure.

**Codegen.** `helpers/codegen` gains `module` (a module's own bindings, split
per dependency), `entrypoint` (the static dispatcher, rendered from the
introspector's typedef scan) and `library` (the vendored library's own
bindings) alongside `client`. `helpers/config-updater` writes the module config
the runtime reads.

**Routing.** `Mod.generate` takes the local path for `dagger-module.toml`
modules and keeps delegating for `dagger.json` ones, which regenerate at call
time regardless. Both stage the local dependency closure first — a dependent's
schema is only loadable once its deps' generated files exist — and both take
that staging back out of the changeset, each in the way its route requires.

Regeneration prunes the `*.gen.ts` it owns out of the baseline the generated
tree is layered onto. Layering is what keeps the module's own source and config
in the changeset, but it can only add, so a dependency dropped from the config
would otherwise keep its `<dep>.gen.ts` — an API against a module that is no
longer served, which a default tsc rejects. Pruned in one place, matching what
different things on different workspace kinds.

**Engine pairing.** Everything here is built for one release. The SDK states it
once as `targetEngineVersion`; the runtime harness and every fixture read from
there, and a check fails when they disagree.

**Tests.** Golden tests over the renderers; e2e checks over the generated tree,
the routing, dependency edges in both config formats, config preservation and
binding pruning; a differential check that generates a fixture through this SDK
and through the engine and diffs everything but the bundle; and one fixture per
TypeScript runtime that loads a generated module and calls a function on it,
which is the only thing that proves the on-disk contract end to end.

Replaces the #18 → #34 stack, squashed: several of those PRs overwrote earlier
ones, which made the intermediate states hard to reason about and impossible to
test independently. Rebased onto #37 (beta.11) and #38 (the interface-return
fix and the config-updater rename); the entrypoint golden #38 added is
regenerated here, because this generator emits the source maps the engine
expects and main's did not.

Signed-off-by: Tom Chauveau <[email protected]>
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.

1 participant