Skip to content

feat: unified clients — every module its own client, one clients/ directory per scope - #54

Merged
TomChv merged 2 commits into
mainfrom
feat/unified-clients
Sep 17, 2026
Merged

TomChv merged 2 commits into
mainfrom
feat/unified-clients

Conversation

@TomChv

@TomChv TomChv commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

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 under design/ record how the model converged, with design/unified-clients-per-scope.md as 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 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

Each client serves its own module before its first query — a git target through dag.moduleSource(ref, { refPin }), a local one through a currentWorkspace query — 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 generated clients/loader.gen.ts map instead of a namespace lookup.

2. One clients/ directory per scope, the same installable shape everywhere

Every scope that has clients carries one self-contained npm package per client, plus the scope's own @dagger.io/dagger package 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.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 shared workspace directory.

<scope>/clients/
  dagger/          @dagger.io/dagger — bundle + core bindings, real package (main/types/exports)
  <name>/          @dagger.io/<name> — file: deps on ../dagger and siblings
  loader.gen.ts    module scopes only

The UX

  • dagger module init typescript --entrypoint → the module carries clients/dagger (installed by default — its one @dagger.io/* dep) and nothing else. npm install once and the editor resolves everything.
  • dagger module client add <ref> → clients/<name>/ appears, wired as file:./clients/<name>.
  • dagger module client add . → the self client: recorded (as the resolved path), generated at clients/<self>/, dep wired; npm install and the module calls itself. client rm takes package and dep back out. A module that never calls itself carries no self client.
  • A client-only scope gets the same clients/ tree with its own core; plain user code consumes it with npm install + connection() under dagger 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 (embedded sdk/, 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

  • CI green, including engine-e-2-e:checks-check (the full suite inside the pinned engine) and engine-e-2-e:generate.
  • Exercised end to end on a manifest-v2 dev engine: init, client add ., self-call through the generated client, client rm, a client-only scope consumed from plain user code via dagger run npx tsx, and byte-quiet regeneration throughout.
  • Unit + golden tests green (helpers/codegen, helpers/config-updater).

Related

  • Allow a scope to record a client for its own module dagger#14188 — engine: allow a scope to record a client for its own module. Only dagger module client add . waits on it; everything else works on today's engine.
  • A published @dagger.io/dagger later replaces every file:../dagger with a version and deletes the dagger/ directories; the layout is shaped so that swap touches specifiers only.

@TomChv

TomChv commented Sep 17, 2026

Copy link
Copy Markdown
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
TomChv force-pushed the feat/unified-clients branch from 590fb39 to 8ed885a Compare September 17, 2026 19:26
@TomChv TomChv changed the title feat: render every module as its own client feat: unified clients — every module its own client, one clients/ directory per scope Sep 17, 2026
@TomChv
TomChv merged commit 2f33e16 into main Sep 17, 2026
5 checks passed
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