Skip to content

feat: share one client directory across the whole workspace - #56

Closed
TomChv wants to merge 22 commits into
feat/unified-clientsfrom
feat/workspace-clients
Closed

TomChv wants to merge 22 commits into
feat/unified-clientsfrom
feat/workspace-clients

Conversation

@TomChv

@TomChv TomChv commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Stacked on #54 — review that one first; the base here is feat/unified-clients, so this PR's diff is the single commit on top of it.

What this does

A module kept its own sdk/ library and clients/, and a client-only scope kept another copy of both under its own .dagger/clients. Two renderings of the same bytes, drifting apart on their own schedules.

They become one directory beside dagger.toml:

.dagger/clients/
  dagger/          the vendored library, as its @dagger.io/dagger package
  <module>/        one package per module, named @dagger.io/<module>

Every consumer reads that one directory — a module's own source, another module, or plain user code. This works without any deduplication because the renderings already converged on #54: a module's client file is byte-identical whichever scope asked for it.

How a module reaches clients outside its own directory

No [[include]], and no host copy. Manifest v2 rejects include outright, and the builtin runtime mounts only the module's directory, so neither could have worked. The generated entrypoint's call() already mounts the whole workspace, so a single

withMountedDirectory("node_modules/@dagger.io", workspace.directory("/.dagger/clients"))

replaces the per-module sdk mount — the subdirectory names are exactly the @dagger.io/* package names.

This is gated on the entrypoint setting for that reason: a [runtime] module cannot reach the workspace root at all, so those keep today's embedded layout.

Where the union comes from

The directory's desired state is the union over every recorded scope, so every scope's generation renders and writes the whole thing. That is deterministic in the workspace alone, which makes every pass after the first byte-quiet under the engine's sequential fold, and prunes a module no scope records any more.

The union cannot come from the scopes the engine passes in: a run from a subdirectory only plans the scopes near the cwd, and a union built from those would delete the siblings' packages. So the SDK reads dagger.toml itself, through a new workspace-config helper. Two scopes binding one module name to different sources is now an error rather than a silent race.

Two latent bugs this surfaced

Both would have shipped as runtime-only errors — neither is visible to the golden tests, which build schemas by hand at one version and never run npm.

  • Each module is served its own core. clientSchemaIntrospectionJSON returns a compatibility view of core keyed on the engine version that module declares. The merge took core from whichever schema sorted first, so a dependency pinned a few releases back rendered the whole workspace against its stale core and every query failed with Unknown argument "directory" on field "Container.withDirectory". Core now comes from the newest-versioned target; the others contribute only their own types, which is what module mode always did.
  • npm file: deps are symlinks, and node resolves the realpath. A client installed into a consumer's node_modules resolves its own imports from .dagger/clients/<mod>/ and walks up a tree with no node_modules, never reaching the consumer's. The old per-scope layout hid this because the packages sat under the consuming scope.

Verified

Against a live engine, on a workspace with an entrypoint module, a git dependency, a self client and a client-only scope: generate, regenerate from three different directories, self and remote calls, npm install + tsx, and tsc --noEmit for both the module and the consumer. Plus the e2e suite and the runtime-execution checks.

Follow-up: resolving the clients natively (00ef07a)

Review testing found the out-of-module consumer path was not native enough: tsx main.ts failed with ERR_MODULE_NOT_FOUND for @dagger.io/dagger. Three workarounds are now gone.

  • A generated client names the library and its siblings by package, always. The relative rewrite (ModuleGeneratorConfig.PackagedClients -> ../dagger/index.js) is deleted; the install resolves the name.
  • A scope on the shared layout declares its clients as ordinary file: dependencies, and the tsconfig path aliases come back out. The embedded layout keeps its aliases, since the clients there are loose files rather than packages.
  • The shared directory carries a node_modules of its own: one symlink per package, pointing at the sibling beside it.

That last one is the interesting part. Measured on a three-package tree of the same shape, dependencies declared and nothing else:

manager node_modules/@x/ result
npm 11.6.2 cli only (symlink) fails
bun 1.3.14 cli only (symlink) fails
pnpm 10.26.2 cli -> store tree carrying the dep works
yarn 1.22.22 cli and lib, hoisted copies works

npm and bun resolve a package's own imports from the symlink's real path, which lands back in the shared tree — a tree with no node_modules — and walk up from there without reaching the consumer's. The links are exactly what a manager would have created had one been run in that directory, and they are generated because there is no project in there to install: no root package.json, no workspaces, no lockfile, nothing a manager has an opinion about. Every package stays plain, small, and installable from any project by any manager.

They are written as a directory and only when the package set changes — a Workspace has no withSymlink, so they cannot go through writeChanged, and rewriting them each run would report the subtree as written on a run that changed nothing.

Verified

Against the dev engine, on a workspace with an entrypoint module, a git dependency and a client-only consumer: generate, regenerate reporting no changes to apply, then npm install + tsc --noEmit + tsx in the consumer — printing a core call, a local module call, and that module's own remote dependency. Same run under bun. All 52 e2e checks pass.

A module's bindings merged every dependency into the one core Client:
per-module files declaration-merged into client.gen.ts, patched
Client.prototype at load time through __apply<Dep>Augmentations, and the
core file re-exported them all back out. One Client, one namespace,
every module folded into it — which is what let two modules collide,
what forced the ESM-cycle workarounds, and what made the standalone
client package a second, different rendering of the same bindings.

Now each module renders as a self-contained client: its own root Client
built from the fields it contributes to Query, its own dag on the shared
session, and a top-level function per root field, so a consumer writes
hey.hey() instead of dag.hey(). The core file holds core types only —
no module imports, no export *, no footer — and the module and
standalone shapes become the same rendering, differing only in how they
resolve the runtime.

Cross-module type references import from the owning module's file
instead of failing generation: the fail-closed sibling guard was already
wrong for a module whose own API returns a dependency's type, which any
self client can hit.

The entrypoints lose their namespace lookup over @dagger.io/dagger —
with no merged namespace there is nothing to look classes up in — and
import a generated loader.gen.ts instead: an explicit type-name -> class
map, baked from the schema split, so a name two modules both export
cannot resolve by import order. "client", "dagger" and "loader" become
reserved module names rather than silent file collisions.

Verified offline: unit + golden tests, and a generated module tree
(core + module client + loader + dispatcher + user source importing
@dagger.io/dagger/<mod>) type-checks clean under tsc --strict.

Signed-off-by: Tom Chauveau <[email protected]>
A module's source now reaches a generated client through its own
specifier — import { hey } from "@dagger.io/dagger/hey" — instead of the
merged core namespace, so the config writers gain the list of module
clients and emit one alias per module: a tsconfig path or an import-map
entry pointing at ./sdk/<module>.gen.ts.

The alias set is synced, not appended: an entry under the
@dagger.io/dagger/ prefix whose module left the closure is removed, so a
dropped client does not leave a dangling specifier that resolves at
type-check time and fails at run time. User-owned aliases and the static
telemetry entry are untouched.

Signed-off-by: Tom Chauveau <[email protected]>
The config step becomes part of what a pass produces: moduleDirectory
derives one @dagger.io/dagger/<module> alias per generated client file,
and the second pass — the one that folds the module's own API in —
re-runs it from the bindings that really exist, so the self client's
alias appears the moment its file does. The first pass carries the
module's own name speculatively: the staged tree built from it must be
loadable, and a module whose source imports its own client needs that
alias resolvable during the staged load; the second pass replaces the
set with the derived one, so a speculative name that never materializes
is corrected rather than kept.

Regeneration stays quiet: the alias set only changes when the binding
file set does, so an edit that touches neither leaves tsconfig.json and
deno.json byte-identical and the file-by-file writer skips them.

The e2e expectations follow the shape: a target's file carries its own
client instead of being re-exported by the core one, the loader lands
beside the bindings, and the config aliases each module client.

Signed-off-by: Tom Chauveau <[email protected]>
Bring design/unified-clients.md into the branch (it was the system of
record other design docs cross-reference) and prepend a status note:
what shipped, where it diverged from the proposal — the generated
loader.gen.ts over a namespace lookup, reserved module names, synced
config aliases — and what stays out of scope.

Signed-off-by: Tom Chauveau <[email protected]>
Three things the repro surfaced, all fixed here.

The per-module client files and the loader moved out of sdk/ into a
clients/ directory beside it. sdk/ is now the @dagger.io/dagger library
and nothing else — core bindings, bundle, index — so it can one day be
pulled as an npm package rather than generated. The client files reach
the library through the @dagger.io/dagger specifier (they no longer sit
next to the bundle) and a sibling module relatively; the loader imports
core from the package and each client from its relative sibling. The
tsconfig/deno aliases point at ./clients/<module>.gen.ts, and the
entrypoints import the loader from clients/.

This subsumes the clients/ directory dualClients used to produce — the
module's own clients and a standalone caller's are the same rendering in
the same place now — so the dualClients setting is removed.

The dispatcher serves the module into its own session. A nested dispatch
session carries only the active module's dependencies, so a self client
(test(this.ws).container()...) resolved nothing and raised "Cannot query
field". Codegen serves the module itself there too, from a new
--self-serve-path the dang side passes as the module's own source path.

Verified offline: the generated tree — sdk/ library, clients/ per-module
clients + loader, a dispatcher serving a git dep and self, user source
importing @dagger.io/dagger/<mod> — type-checks clean under tsc --strict;
unit and golden suites updated and green.

Signed-off-by: Tom Chauveau <[email protected]>
The user-facing specifier for a module client is @dagger.io/<module>,
not @dagger.io/dagger/<module> — the @dagger.io npm scope, one segment
per module, the name a client would carry if published one package per
module. @dagger.io/dagger stays the core library.

config-updater writes the tsconfig/deno alias under that name and prunes
stale ones by the same rule, taking care never to touch @dagger.io/dagger
or its /telemetry sub-path. Generated cross-client imports follow suit:
a client reaches a sibling module through @dagger.io/<sibling> and the
loader imports each client the same way, so the generated code matches
what a user writes and is ready for real per-module packages.

Also locks a regression: a core type referenced only as a module root
field's argument (a constructor's "ws: Workspace") is imported — the
field becomes a Client method, so its argument types must resolve.

Verified: the generated tree type-checks under tsc --strict with the new
@dagger.io/<name> aliases; helper suites green.

Signed-off-by: Tom Chauveau <[email protected]>
A generated module client now serves its own module into the session
before its first query, so a client reached outside the dispatcher — dev
mode, or one module's source calling another — resolves without relying
on the central serve.

Runtime: Context carries an optional serve spec, propagated to every
context derived from it; the first query on such a context awaits the
serve, memoized per session on the Connection so a module is served at
most once however many queries run. The serve runs through the core dag,
which carries no serve of its own, so it cannot recurse. The core client
and the serve itself are unaffected.

Codegen: each module client whose bound source is known (a client target
or the module itself, from the client meta) bakes its serve — a git
module through dag.moduleSource(ref, {refPin}), a local one through a
currentWorkspace raw query — and constructs its dag with that serve
attached. A manifest dependency the engine already serves gets no hook.

The dispatcher keeps its own serve for now; the two are redundant (serve
is memoized) and the dispatcher one can be retired once this is proven on
an engine.

NOTE: library/bundle/ is not rebuilt in this commit — it must be
regenerated through the packager (pinned bun) so the committed core.js /
core.d.ts carry the hook; a local rebuild is not byte-identical and would
fail the staleness check. Verified offline against a locally-built
bundle: the generated tree type-checks under tsc --strict, and a runtime
test confirms the serve fires once, before the first query, memoized, and
skipped for the core context.

Signed-off-by: Tom Chauveau <[email protected]>
Regenerated library/bundle/ through the packager (packager:library-bundle,
pinned bun) so the committed core.js / core.d.ts carry the Context serve
hook and Connection.ensureServed the generated clients rely on. The
introspector bundle rebuilds from the same source tree and comes along.

Idempotent: a second packager run reports no changes, so the
packager:library-bundle staleness check passes. The generated module tree
type-checks under tsc --strict against this committed bundle.

Also records serve-on-use as shipped in the design doc.

Signed-off-by: Tom Chauveau <[email protected]>
The engine encodes an object-typed argument as a raw ID scalar with an
@expectedType directive naming the object, and the renderer resolves the
signature to that name (formatInputType). collectReferencedNames walked
only the raw TypeRef — the ID — so an object passed solely as an argument,
like a module constructor's `ws: Workspace`, rendered in the signature
but was never collected and never imported. An object return type keeps
its object TypeRef, which is why those imported fine and only arguments
were affected.

collectReferencedNames now resolves @expectedType on arguments and input
fields to the type the renderer emits. Verified against the real
module-facing and client-facing schemas dumped from the engine: the self
client now imports Workspace. The regression test uses the engine's
ID + @expectedType encoding so it actually guards the path.

Signed-off-by: Tom Chauveau <[email protected]>
The dispatcher's serveBoundModules was still there because the per-client
serve only covered calls originated from a client (dag.<module>()). A
function that *receives* a dependency object loads it through the loader's
__loadObject with a bare context, and a module type is only in the nested
session's schema once its module is served — so that path still needed a
serve, which the dispatcher was providing.

Move that onto the client too: each module client exposes __servedContext()
(the context its dag already uses), and the loader wraps a received ID in
the owning client's served context. So both paths — originate a call, or
load a received value — serve the module lazily before the query runs, and
the dispatcher serves nothing.

Removes serveBoundModules from the dispatcher, the --self-serve-path and
--client-meta-path plumbing on `codegen entrypoint`, the BoundModules /
SelfServePath entrypoint config, and the dang wiring that fed them. The
dispatcher no longer imports dag.

Verified: the consolidated tree type-checks under tsc --strict (self client
serves via __servedContext, loader serves module types, dispatcher serves
nothing); helper suites and entrypoint goldens updated and green. No
library/src change this turn, so the committed bundle stands.

Signed-off-by: Tom Chauveau <[email protected]>
Correcting the previous commit's premise. A module's exposed function
signatures use core types or its own types, never a dependency's — so a
dependency object is never received as an argument or return, and the
entrypoint loader's __loadObject only ever loads core types, which are
always in the session and need no serve.

So the loader-serve machinery (per-module served contexts threaded through
__loadObject, the __servedContext export) was dead code. Revert it: the
loader wraps a loaded core object in a bare context again, and a client's
dag inlines its served context. The single serve path is a dag.<module>()
call through the client's served context — which is all a module ever uses
to reach another module or itself.

The dispatcher still serves nothing (that removal was correct — it was
redundant with the per-client dag hook, just not for the loader reason).

Verified: the tree type-checks under tsc --strict; suites and goldens green.

Signed-off-by: Tom Chauveau <[email protected]>
A standalone client scope generated a different thing from a module: a
dagger.gen.ts core with serveBoundModule/connect wrappers importing the
remote @dagger.io/dagger, and clients with no serve hook. Now it renders
the same as a module — the vendored library under sdk/, one flat
<module>.gen.ts client per target serving its own module on use, and a
tsconfig aliasing @dagger.io/dagger to the local sdk. No remote
dependency; the two shapes converge, so a shared .dagger/clients can back
both a module and the user's code later.

Codegen: the ClientConfig / IsClientOnly path is deleted. One
ModuleGeneratorConfig drives both a module's own bindings and a standalone
client, with FlatClients (flat root vs clients/ subdir) and EmitLoader
(module entrypoint only) the sole differences. `codegen client` merges
the target schemas and renders through the module path with FlatClients.
The serveBoundModule/connect header block, dagger.gen.ts naming, and the
per-scope package name/version are gone.

config-updater's tsconfig/deno-config take a clients-dir so the
@dagger.io/<module> alias points at ./clients/<m>.gen.ts (module) or
./<m>.gen.ts (flat client). The client-only config path uses the same
module-style package.json and tsconfig now.

Dang: clientDirectory vendors the sdk (moduleSdkDirectory), lays the flat
clients beside it, and writes module-style config with flat aliases.

Verified offline: a vendored-sdk client scope type-checks under tsc
--strict with no remote dependency; helper suites and e2e assertions
updated and green.

Signed-off-by: Tom Chauveau <[email protected]>
A client-only scope generated a working tree that nothing could import:
the @dagger.io/dagger and @dagger.io/<module> aliases only existed in
.dagger/clients/tsconfig.json, while the user's code lives at the scope
root under the user's own tsconfig — so `import { test } from
"@dagger.io/test"` failed with "Cannot find module". (The old
consumption model — installing the dir as a named npm package — is gone
with the converged shape, which ships no package entrypoint.)

Generation now syncs the aliases into the scope's own tsconfig.json (or
deno.json, by the scope's flavor), pointing into .dagger/clients: the
library at ./.dagger/clients/sdk and each client at its file. Only the
SDK-owned @dagger.io/* alias keys are written — the file is the user's,
so nothing else in it is touched, and package.json never is. Removing
the last target strips the aliases along with the tree, and a scope that
never had the config file is not given one just to hold zero aliases.

config-updater grows scope-tsconfig / scope-deno-config modes that sync
only those aliases (no compiler options, no typescript pin), sharing the
lib-alias sync the module modes now use too.

Also makes generated optional properties exactOptionalPropertyTypes-
clean (`_x?: T | undefined`): a client-only scope's generated .ts is
compiled under the user's tsconfig, and a stock `tsc --init` config
enables that flag — the constructor assignment was a TS2412 under it.

Verified against the real repro: a project with a tsc --init config
(nodenext, verbatimModuleSyntax, exactOptionalPropertyTypes) imports
@dagger.io/dagger and @dagger.io/test and type-checks clean.

Signed-off-by: Tom Chauveau <[email protected]>
Course-correcting the previous commit's mechanism. Syncing @dagger.io/*
aliases into the user's tsconfig made the clients importable, but it is
the wrong foundation: the goal is clients you can `npm install` into any
existing scope — file: links today, a published registry package later —
not resolution wired through config the SDK has to keep editing. Revert
the scope-alias sync (scope-tsconfig / scope-deno-config are gone) and
package the clients instead.

A client-only scope now renders one npm package per module:

  .dagger/clients/
    dagger/          the vendored @dagger.io/dagger library
    <module>/        one package per target, named @dagger.io/<module>

The library package exports "." (index.ts) and "./telemetry"; each
client package exports its client file and declares file: dependencies
on the library and every sibling, so installing one client pulls along
everything it can reference. The user consumes it with
`npm install ./.dagger/clients/<module>` — plain package resolution, no
aliases anywhere, and nothing of the user's is ever edited. The .dagger
nesting is what makes node's realpath walk-up from the symlinked
packages land in the project's node_modules.

The client files themselves are unchanged — the same rendering a module
scope's clients/ gets — so the shapes stay converged; only the packaging
differs. "dagger" becomes a reserved module name in a client scope (the
library package dir). The dead client-package-json / client-tsconfig /
client-deno-config config-updater modes are removed; module scopes keep
their tsconfig aliases, unchanged.

The compile e2e check now proves the installability contract end to end:
npm install of the generated packages in a consumer project, then a
plain nodenext tsc with no path aliases.

Verified offline against the real repro: npm install + tsc clean under a
stock tsc --init config, and a tsx run resolves the packages and fires
the serve-on-use hook (failing only at the absent engine workspace).

Signed-off-by: Tom Chauveau <[email protected]>
Deleting existingClientConfig left the first two lines of its docstring
orphaned above clientScope's, and two docstrings back to back do not
parse — so the whole SDK module failed to load, taking every dagger
command in a workspace pinned to this branch down with it. Verified this
time by loading the module (dagger functions) after the edit.

Signed-off-by: Tom Chauveau <[email protected]>
CI was red on engine-e-2-e:generate and engine-e-2-e:checks-check. Three
causes, all mine:

The library's own bindings are rendered through the same templates a
module's are, so making generated optional properties
exactOptionalPropertyTypes-clean (`_x?: T | undefined`) left
library/src/api/client.gen.ts stale against its own generator.
Regenerated through the packager inside the pinned engine — the diff is
exactly that annotation, no schema drift — which is what the generate
check compares against.

Two client checks asserted `asModule().serve()`, the form a *git* target
renders. Every fixture they run against is local, which renders the
currentWorkspace raw query instead, so the assertions were checking a
shape the fixtures never produce. They now go through one helper that
pins the whole selection — path and serve together — so it says which
module is served, not merely that the word appears.

The self-call check still asserted the dispatcher serves the module;
that moved to the module's own client two commits ago. It now asserts
the self client serves, and that the dispatcher serves nothing —
matched on asModule, since the dispatcher still mentions serving in the
comment explaining that it does not.

Verified with the pinned engine, the way CI runs them:
engine-e-2-e:generate reports no changes, and engine-e-2-e:checks-check
passes the whole suite.

Signed-off-by: Tom Chauveau <[email protected]>
Brings in #55, which split module generation onto one loading path at a time
and moved the entrypoint manifest onto the sdk-helpers builder.

The conflict is moduleDirectory, which both sides restructured. Resolution
keeps #55's shape — one branch per loading path, never both — and puts this
branch's clients/ in the part common to them: the per-module bindings are what
the module's own source imports, which is independent of how the module is
loaded. The dispatcher keeps this branch's signature without targets, since
serve moved onto each client here and the dispatcher no longer stages client
meta.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the feat/workspace-clients branch from f1794a6 to 1ffa763 Compare September 16, 2026 16:54
@TomChv
TomChv marked this pull request as draft September 16, 2026 17:15
#55 made a module get one loading path's files and not the other's, so a
`[runtime]` module no longer carries a __dagger.dispatch.ts. generateSelfCallCheck
still read one — it was written when both halves were generated — and failed on a
missing file rather than on anything it was checking.

The claim is worth keeping: serving moved onto the clients, so no dispatch file
stages modules of its own. But it can only be asserted where a dispatcher exists,
which is the entrypoint path. Gen.scope gains the `entrypoint` setting, and the
assertion moves to a check of its own covering both paths — the entrypoint's
dispatcher, which this branch took the serving out of, and the legacy entrypoint,
which never had any. generateSelfCallCheck keeps what it is named for.

Also drops the superseded dispatcher-serves-self bullet from the design note; the
per-client serve below it replaced that mechanism.

Signed-off-by: Tom Chauveau <[email protected]>
A module kept its own sdk/ library and clients/, and a client-only scope kept
another copy of both under its own .dagger/clients. Two renderings of the same
bytes, drifting apart on their own schedules.

They are now one directory beside dagger.toml — .dagger/clients, holding the
vendored library as its @dagger.io/dagger package and one package per module —
which every consumer reads: a module's own source, another module, or plain
user code. This is possible without any deduplication because the renderings
already converged on the unified-clients branch: a module client file is
byte-identical whichever scope asked for it.

Gated on the entrypoint setting. The engine's builtin TypeScript runtime mounts
only the module's own directory, so a legacy module cannot reach the workspace
root at all; those keep today's embedded layout. An entrypoint module's recipe
already mounts the workspace, so the shared directory needs no [[include]] and
no host copy — one mount of it at node_modules/@dagger.io replaces the per-module
sdk mount, its subdirectories being exactly the @dagger.io package names.

The directory's desired state is the union over every recorded scope, so every
scope's generation renders and writes the whole thing. That is deterministic in
the workspace alone, so the engine's sequential fold makes every pass after the
first byte-quiet, and a module no scope records any more is pruned by whichever
scope generates next. The union cannot come from the scopes the engine passes:
a run from a subdirectory only plans the scopes around the cwd, and a union
built from those would prune the siblings' packages. So the SDK reads
dagger.toml itself through a new workspace-config helper. Two scopes binding one
module name to different sources is now an error rather than a silent race.

Two bugs surfaced verifying this, both of which would have shipped as runtime
errors:

- The engine serves each module a compatibility view of core keyed on its
  declared engine version, and the client merge took core from whichever schema
  came first. A dependency pinned four releases back therefore rendered the
  whole workspace against its core, and every query was rejected. Core now comes
  from the newest-versioned target; the others contribute only their own types,
  which is what module mode already did.
- npm links a file: package as a symlink and node resolves from the real path,
  so a client installed into a consumer's node_modules searched for its siblings
  in the shared tree, which has no node_modules. Generated files inside the
  directory now reach each other by relative path; the package names stay the
  user-facing surface.

Verified end to end against a live engine on a workspace with an entrypoint
module, a git dependency, a self client and a client-only scope: generate,
regenerate from three directories, self and remote calls, npm install + tsx, and
tsc for both the module and the consumer.

Signed-off-by: Tom Chauveau <[email protected]>
The shared directory held real npm packages that nothing could install. Each
one declared its dependencies as file: links, but no manager was ever run in
there, so the packages could not find each other and the bindings reached
around the gap: a generated client imported ../dagger/index.js instead of
@dagger.io/dagger, and a consuming scope reached its clients through
tsconfig path aliases rather than dependencies. Neither survives contact with
a real project — `tsx main.ts` in a consumer failed with
ERR_MODULE_NOT_FOUND for @dagger.io/dagger.

Three changes, all of them removing a workaround rather than adding one:

- A generated client names the library and its siblings by package, always.
  The relative rewrite (ModuleGeneratorConfig.PackagedClients) is gone; what
  resolves the name is the install.
- A scope on the shared layout declares its clients as ordinary file:
  dependencies, and the path aliases come back out. An alias that outlives the
  layout points into a scope-local sdk/ and clients/ the move takes away, and
  it wins over the install that replaced it. The embedded layout keeps its
  aliases — the clients there are loose files, not packages.
- The shared directory carries a node_modules of its own: one symlink per
  package, pointing at the sibling beside it.

That last one is what makes a bare specifier resolve locally, and it is worth
saying why it is needed at all. Measured on a three-package tree of the same
shape, with the dependencies declared and nothing else:

  npm 11.6.2    symlinks the package, does not hoist its file: dep   fails
  bun 1.3.14    same                                                 fails
  pnpm 10.26.2  copies into a store tree that carries the dep        works
  yarn 1.22.22  copies both into node_modules, hoisted               works

The two that fail resolve a package's own imports from the symlink's real
path, which lands back in the shared tree — a tree with no node_modules — and
walk up from there without ever reaching the consumer's. The links are exactly
what a manager would have created had one been run in the directory, and they
are generated because there is no project in there to install: no root
package.json, no workspaces, no lockfile, nothing a manager has an opinion
about. Each package stays plain and small and installable from any project by
any manager, which is the point of the layout.

They are written as a directory and only when the package set changes: a
Workspace has no withSymlink, so they cannot go through writeChanged, and
rewriting them every run would report the subtree as written on a run that
changed nothing. The links are a pure function of the names, so comparing the
names is comparing the links.

Verified against the dev engine on a workspace with an entrypoint module, a
git dependency and a client-only consumer: generate, regenerate reporting no
changes, then npm install + tsc --noEmit + tsx in the consumer, printing a
core call, a local module call and that module's own remote dependency. The
same run under bun. All 52 e2e checks pass.

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the feat/workspace-clients branch from 00ef07a to 5a4a9c5 Compare September 16, 2026 18:48
Three things stood between a generated scope and a working editor, and the
first two are this stack's doing.

A module reached its clients through path aliases until they became installed
dependencies; nothing then installed them, so its own source resolved nothing
until someone ran a package manager inside the module — which the embedded
layout never asked for. The links in the shared directory do not help: a
module's walk-up passes through its scope and then the workspace root, never
through .dagger/clients. So a module scope gets its own
node_modules/@dagger.io, pointing back at the shared packages. The whole set
is linked rather than the module's declared subset, which is what a hoisted
node_modules does in any monorepo: package.json stays the declaration, and
this is only resolution.

The packages also advertised one entry point where a resolver reads one of
three. `exports` is the modern spelling and the only one node honours here,
but it is invisible to TypeScript's classic `node` moduleResolution, which
reports "there are types at ..., but this result could not be resolved under
your current moduleResolution setting" — the packages now carry `main` and
`types` beside it, the same way a published package does.

The third is older than this stack. A generated tsconfig held nothing but
experimentalDecorators, so a scope whose tsconfig we created sat on tsc's
defaults: ES5, where every async method in the bindings is an error, and
classic resolution. The engine's own module template ships target ES2022,
moduleResolution Node, strict and skipLibCheck; ours ships no tsconfig at all,
so config-updater seeds those four — never overwriting one the scope has
chosen for itself.

Verified against the dev engine on an entrypoint module with a git dependency
and a client-only consumer: the module typechecks with no node_modules of its
own, regeneration reports no changes, and the consumer installs, typechecks
and runs — a core call, a local module call and a self call. All 55 e2e checks
pass, including a new one that pins all three halves of the module's
resolution together.

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

TomChv commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

Closed in favor of #58

@TomChv TomChv closed this Sep 17, 2026
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