Repository navigation
feat: unified clients — every module its own client, one clients/ directory per scope - #54
Merged
Merged
Conversation
TomChv
force-pushed
the
feat/unified-clients
branch
from
September 15, 2026 22:17
3360542 to
84ef634
Compare
This was referenced Sep 16, 2026
Merged
TomChv
marked this pull request as draft
September 16, 2026 21:38
TomChv
force-pushed
the
feat/unified-clients
branch
from
September 16, 2026 21:47
ccb9675 to
06a414c
Compare
TomChv
marked this pull request as ready for review
September 17, 2026 19:16
Member
Author
|
Depends on dagger/dagger#14038 before merging that one |
A TypeScript module's dependencies were grafted onto one core Client: each
per-module file declaration-merged into client.gen.ts, patched Client.prototype
at load time, and the core file re-exported them all. One Client, one namespace,
every module folded in — which is what let two modules collide and what forced
the ESM-cycle workarounds.
Now each module renders as its own self-contained client: its own root Client
built from the fields it contributes to Query, its own dag, a top-level function
per root field, and its own serve. A module's source and a caller outside it
write the same thing —
import { dag, Container } from "@dagger.io/dagger" // core
import { hey } from "@dagger.io/hey" // a bound module
- _client.ts.gtpl replaces _dep.ts.gtpl + _augmentations.ts.gtpl; the
declaration-merge / prototype-patch machinery is deleted and the core file
holds core types only. The library (sdk/) splits from the clients, which live
beside it, so it can one day be an npm package rather than generated.
- Serve-on-use per client, the only serve: Context carries an optional serve
spec propagated to every derived context, the first query awaits it, memoized
per session on Connection, run through the core dag so it cannot recurse. A
git target serves through dag.moduleSource(ref, { refPin }), a local one
through a currentWorkspace query — so a client resolves wherever it is used,
and the dispatcher serves nothing (which also fixes self-calls).
- A module's own API folds into its bindings as a self client, generated in a
second pass against the staged module's schema.
- clients/loader.gen.ts replaces the entrypoint's namespace lookup: an explicit
type-name -> class map baked from the schema split.
- config-updater writes one @dagger.io/<module> alias per client into
tsconfig.json / deno.json, synced; dualClients is removed.
- A standalone client scope converges with a module, packaged for npm install:
the vendored library as a real @dagger.io/dagger package plus one
@dagger.io/<module> package per target, wired by file: dependencies.
- Two codegen correctness fixes surfaced by running it: an object type passed
only as an argument is now imported, and generated optional properties are
exactOptionalPropertyTypes-clean. library/bundle is rebuilt via the packager.
Breaking: import { Hi } from "@dagger.io/dagger" stops resolving — a module's
types come from @dagger.io/<module>; core imports are unchanged.
Signed-off-by: Tom Chauveau <[email protected]>
…erywhere Every scope that has clients carries a clients/ directory of self-contained npm packages — one per client, the scope's own @dagger.io/dagger package beside them — and a module scope and a client-only scope generate the identical shape. The package manifest is the only link: package.json file: dependencies, written by the SDK for what it generates and by npm install for what the user opts into. No tsconfig aliases, no per-scope .dagger/clients, no embedded sdk/ for entrypoint modules. The design notes under design/ record how the model got here; design/unified-clients-per-scope.md is the final form. - A fresh entrypoint module gets clients/dagger — installed by default, the one @dagger.io/* dep it carries — and nothing else. Its tsconfig is experimentalDecorators only: package.json is the resolver. - The self client is opt-in: `dagger module client add .` records it (as the resolved path), generates clients/<self>/ and wires the dep; the user runs npm install and calls themselves. `client rm` takes the package and the dep back out. Needs dagger/dagger#14188, which stops the generation graph from reading a scope's own module as a self-cycle. The embedded [runtime] layout keeps its always-generated self client unchanged. - A declared client lands at clients/<name>/, wired as file:./clients/<name>. Each package carries main/types/exports and depends on file:../dagger and its siblings, so installing one from anywhere pulls everything it references. - codegen grows --packaged-clients: clients nest in their own package directories and the loader imports them relatively, so an uninstalled self client still resolves at dispatch time; the loader lives at clients/loader.gen.ts beside them. - The entrypoint recipe installs from the module manifest plus clients/** — the file: targets ride with the manifest, so a source edit reinstalls nothing, and npm's relative symlinks resolve identically under the runtime's workspace mount. requireGenerated checks the packaged files. - config-updater: shared-deps writes a scope's @dagger.io/* namespace as file: deps and prunes only its own (a dep the user pointed elsewhere is theirs); npm's file:x spelling is treated as equivalent to file:./x rather than fought; "-" empties a scope that lost its last client; tsconfig learns a no-alias sentinel. The second generation pass re-runs the config against the user's original files, not the first pass's output. - Migration pruning removes what earlier layouts left: a workspace-level .dagger/core, a scope-level .dagger/clients, packages at the scope root, a root-level loader, and the embedded sdk/. Verified end to end on the manifest-v2 engine: init, client add ., self-call, client rm, a client-only scope consumed with dagger run npx tsx, byte-quiet regeneration throughout, and the full e2e suite. Signed-off-by: Tom Chauveau <[email protected]>
TomChv
force-pushed
the
feat/unified-clients
branch
from
September 17, 2026 19:26
590fb39 to
8ed885a
Compare
This was referenced Sep 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased on
main(includes #59) and squashed into two commits, one per half of the work. The full iteration history lives in #58; the design notes underdesign/record how the model converged, withdesign/unified-clients-per-scope.mdas the final form. Needs no engine change to run; one engine PR extends it (see below).What this does
1. Every module renders as its own self-contained client
A TypeScript module's dependencies were grafted onto one core
Client— declaration-merging, prototype patching, and a core file that re-exported every module. Now each module is its own client: its own rootClientbuilt from the fields it contributes toQuery, its owndag, a top-level function per root field, and its own serve. A module's source and a caller outside it write the same thing:Each client serves its own module before its first query — a git target through
dag.moduleSource(ref, { refPin }), a local one through acurrentWorkspacequery — memoized per session, so a client resolves wherever it is used and the dispatcher serves nothing (which also fixes self-calls). Received values load through a generatedclients/loader.gen.tsmap instead of a namespace lookup.2. One
clients/directory per scope, the same installable shape everywhereEvery scope that has clients carries one self-contained npm package per client, plus the scope's own
@dagger.io/daggerpackage beside them. A module scope and a client-only scope generate the identical tree, and the packages install and run anywhere. The package manifest is the only link:package.jsonfile:dependencies, written by the SDK for what it generates and bynpm installfor what the user opts into. No tsconfig aliases, no shared workspace directory.The UX
dagger module init typescript --entrypoint→ the module carriesclients/dagger(installed by default — its one@dagger.io/*dep) and nothing else.npm installonce and the editor resolves everything.dagger module client add <ref>→clients/<name>/appears, wired asfile:./clients/<name>.dagger module client add .→ the self client: recorded (as the resolved path), generated atclients/<self>/, dep wired;npm installand the module calls itself.client rmtakes package and dep back out. A module that never calls itself carries no self client.clients/tree with its own core; plain user code consumes it withnpm install+connection()underdagger run.The entrypoint recipe installs from the module manifest plus
clients/**, so a source edit reinstalls nothing and npm's relative symlinks resolve identically under the runtime's workspace mount.[runtime]modules keep the legacy embedded layout untouched; leftovers of earlier layouts (embeddedsdk/, scope-level.dagger/clients, a workspace-level core) are pruned on regeneration.Breaking change
import { Hi } from "@dagger.io/dagger"stops resolving — a module's types come from@dagger.io/<module>. Core imports are unchanged.Verification
engine-e-2-e:checks-check(the full suite inside the pinned engine) andengine-e-2-e:generate.client add ., self-call through the generated client,client rm, a client-only scope consumed from plain user code viadagger run npx tsx, and byte-quiet regeneration throughout.helpers/codegen,helpers/config-updater).Related
dagger module client add .waits on it; everything else works on today's engine.@dagger.io/daggerlater replaces everyfile:../daggerwith a version and deletes thedagger/directories; the layout is shaped so that swap touches specifiers only.