Repository navigation
Better SDK UX: "modules-max" design - #13992
Conversation
70487d6 to
e3e4bd7
Compare
|
when listing modules, I have weird output: $ dagger module list
NAME SOURCE INSTALLED SDK
java-sdk github.com/eunomie/java-sdk@module-max true
^[[?2026;0$y |
Implement clientScope/generateModule/generateClient (returning Workspace) for the engine-owned SDK-module interface (dagger/dagger#13992). Drop the beta surface — initModule, modules, generateAll(+Client), initClient, the old 3-arg generateClient, every @generate hook, currentModule.asSDK and withLocalDependenciesGenerated: the engine now owns provider detection, scope/client records, target resolution, the local generation graph/order and the atomic workspace changeset. Signed-off-by: Yves Brissaud <[email protected]>
|
This part feels off: It feels inconsistent because, while it's module-related, it operates on the workspace. I would expect these to be under Same goes for I could be swayed if there's just a different perspective I should have on the set of commands and I'm just carrying baggage of the old mental model. Could be worth testing against LLMs and seeing what they guess without letting them cheat |
1e2e43f to
9f25ad7
Compare
|
@eunomie this is claude. Solomon is sleeping but asked to tell you that you were right, and we pushed an implementation of your suggestion for dagger module init go
dagger module init go --path=target --starter=emptyThe SDK is now a required positional argument, and its setting flags lost the SDK prefix ( |
5043d97 to
b2d9e3d
Compare
a31ff38 to
275e06f
Compare
a22fbf6 to
e0be49c
Compare
Yeah I was wondering about that. I was going to add top-level aliases for 'install', 'uninstall' and 'settings', while keeping them in module (because I was worrying also about the opposite problem: users expect module installation to be in |
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Remove the obsolete schema and client definitions. Regenerate the PHP reference files. Write the dependency-order test module configuration through Workspace.withNewFile. Signed-off-by: Solomon Hykes <[email protected]>
Return the generated Workspace from the SDK graph. Keep it through group composition and CLI export. Convert to Changeset only for legacy queries, previews, and merges with regular generators. Cover nested command directories, writes above scopes, mixed generators, conflict handling, and Workspace result behavior. Regenerate API files for GeneratorGroup.workspace. Signed-off-by: Solomon Hykes <[email protected]>
Remove OriginalModuleResult and its persistence code. Keep the original module on ModTreeNode as the only source for normal generators. Signed-off-by: Solomon Hykes <[email protected]>
Reject installed names and unmarked local paths. Preserve explicit local paths and remote addresses. Keep invalid saved targets removable, and report when remaining invalid targets prevent generation. Signed-off-by: Solomon Hykes <[email protected]>
5b5b046 to
2fdd046
Compare
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
Signed-off-by: Solomon Hykes <[email protected]>
* chore: add ts sdk module max Signed-off-by: Vasek - Tom C <[email protected]> * fix: track the engine SDK provider interface rename The engine renamed detectScope to findClientRoot and made its result nullable, and it validates the provider by exact match on name, argument names and types, and return type (core/sdkmodule/provider.go validate). A mismatch is not a load error: dagger module install simply never records [sdks.typescript], and this repo stops being an SDK. Null, not "", is now how a provider declines a directory. Signed-off-by: Yves Brissaud <[email protected]> * fix: build the module manifest with the sdk-helpers module The engine dropped ModuleManifest from its core schema; the builder now lives in github.com/dagger/sdk-helpers, a standalone Dang implementation that needs no engine newer than v0.21.9. Depend on it and call sdkHelpers.moduleManifest instead of the removed builtin. Write the manifest with Workspace.withNewFile rather than Workspace.withFile. withFile landed after v1.0.0-beta.11, and Dang infers the whole type on every call, so one field the running engine does not have fails every check that touches this SDK — including checks that only read a constant. With this the module loads and infers on the release its own checks run against, which is what keeps them green. runtimeSource goes with it: withLegacyTypescriptRuntime names the runtime the constant held. Signed-off-by: Yves Brissaud <[email protected]> * refactor: drop the generate skip marker The marker predates scopes. A module is generated because dagger.toml records it as an SDK scope, so "do not generate this tree" is now spelled by leaving it out of the scope list, and the marker can only contradict a decision the workspace already made. It cost one findUp per scope per generate to say nothing. Nothing in this repo used it for anything else: fixtures/skip was already dead, and the two scopes registered with a marker above them — managed-toml/app and parent-source — exist for `mod` resolution and for reading a module's config, not for generation. Unregister those rather than start writing generated trees into them; the scope list and Fixtures.managedScopes now say the same thing without a footnote. Signed-off-by: Yves Brissaud <[email protected]> * feat: migrate a scope's pre-1.0 dagger.json to a manifest A scope whose module is still configured by dagger.json used to read as a scope with no module at all: the starter was rendered over the source being adopted, and a second manifest was written beside the first, leaving the module with two config files free to disagree. Split the two things seeding did. The starter is laid down only for a scope with neither config, and the manifest is written for a scope without a dagger-module.toml — from a dagger.json when there is one, which is then removed. The manifest schema round-trips through the sdk-helpers builder, so source, include, [[dependencies]] and the module's engine pin survive the migration. Refuse rather than migrate two kinds of dagger.json, because migration deletes the original and what it cannot carry is then gone. `toolchains` and `blueprint` have no table in dagger-module.toml — the builder validates them on load and emits neither — so migrating either silently strips it. And the builder copies whatever `sdk` names straight into `[runtime]`, so a scope mistakenly recorded as TypeScript over a Go module would have its config rewritten as a Go manifest and its source run through TypeScript codegen. Recognizing that second case needs the older `"sdk": "typescript"` spelling to count as TypeScript, which it did not: a module written that way was refused by `mod --path` too. A scope that already has a manifest keeps it untouched. Clients become a generated package here rather than manifest dependencies, so there is nothing to reconcile into an existing manifest, and rewriting one would not even round-trip: the builder normalizes an absent source to ".", so generate would report a diff on the run after every init. Signed-off-by: Yves Brissaud <[email protected]> * fix: generate a scope with the workspace cwd at its root The engine resolves a module's local [[dependencies]] to workspace-root- relative paths and then reads them relative to Workspace.cwd (ResolveDepToSource). generateScope is called with the cwd set to the scope, so a dependency declared as "../dep" was looked for at <scope>/<workspace-relative-path-of-dep> and the module's schema failed to load: workspace module source ".../generate-deps/app/.../generate-deps/dep" does not contain a dagger config file Do the work with the cwd at the workspace root — every path here is workspace-root-relative already — and put the cwd back before returning, because the engine rejects a generateScope that hands back a workspace standing somewhere else. Only the branch engine resolves dependencies this way, so nothing on v1.0.0-beta.11 shows it. engine-e-2-e:checks-check is what caught it, on its first run: six of the e-2-e checks, all of them the ones that touch a module with a local dependency. Signed-off-by: Yves Brissaud <[email protected]> * fix: detect a module's runtime from its source directory A module's manifest can point `source` away from the directory holding it — config in .dagger/modules/<name>/, code in ci/, the layout `dagger setup` migration produces. The config files the runtime is detected from move with the code, but generateScope detected before it resolved `source`, so it looked for deno.json and bun.lock beside the manifest and found neither. A split-layout Deno or Bun module was therefore regenerated as a Node one: package.json and tsconfig.json laid into a Deno project, which then cannot resolve @dagger.io/dagger at all. It generates cleanly and fails at `dagger call`. Resolve `source` first and detect from there. Seeding keeps detecting from the scope, because a scope with no module has no manifest to resolve `source` out of — and is its own source directory anyway; after seeding, re-detection reads the config files seeding just wrote and agrees with the runtime it was handed. The split-deno fixture is a Deno project on the far side of a `source` pointer, which is the shape no existing fixture had: parent-source is Node, so it passes either way. Signed-off-by: Yves Brissaud <[email protected]> * test: assert that generating a scope twice writes nothing Idempotence is a stated contract — the engine calls generateScope on the same scope for module init, client add, client rm, client update, module update, workspace update and generate, and every one of them diffs the result — but nothing asserted it. The design doc's test plan listed the check; the check did not exist. Generate a scope, apply the changeset, generate again, and the second one has to be empty. isEmpty rather than the path lists, so a spurious removal counts too. On a dependency-free scope, so it stays cheap. It passes today. It would not have, had the manifest been regenerated on every call: the sdk-helpers builder normalizes an absent `source` to ".", so the manifest written at init comes back changed on the next run. Signed-off-by: Yves Brissaud <[email protected]> * test: check the SDK against the engine it targets, not the one it deletes sdk-sdk drives a released CLI through the beta SDK contract — initModule, the as-sdk marker, the @generate rollups, module deps — every piece of which this work removes. Its 23 red checks were reporting that removal, so they go, along with the runtimes check built on the same harness. What they covered was the engine half of the contract, and nothing else reached it: whether the engine accepts the provider at all, whether a scope's settings arrive, whether a generated module runs. That is what .dagger/modules/engine-e2e replaces it with, on the branch that has the interface. It builds an engine from the pinned dagger/dagger#13992 commit, runs it as a playground with this checkout mounted, and drives the real CLI: `sdk list`, `module init` with and without settings, `call`, and the whole check suite. Provider validation is silent when it fails — the engine just never records [sdks.typescript] — so devSdkCheck asserts on the recorded scope entry rather than on the command exiting zero. The playground gets the engine commit as its `version`, or its state cache volume is named randomly and every run starts cold. `.git` is excluded from the mounted checkout and re-created inside: in a worktree it is a file pointing at a directory the container does not have. Signed-off-by: Yves Brissaud <[email protected]> * docs: bring the README and the design doc up to what this is now The README still described the beta contract — initModule, initClient, the @generate rollups, `dagger api client init` with a path argument, a `modules` function that no longer exists — so every command in it was wrong. Rewrite it around the provider interface: what the engine asks for, what the settings are, where a generated client package lands and why, and what the checks cover. design/module-max.md is edited in place rather than appended to, so it still reads as a design rather than a changelog. What changed since it was written: the interface rename, the manifest builder leaving the engine for dagger/sdk-helpers, writing the manifest once instead of on every generation, migrating a pre-1.0 dagger.json, and dropping the skip marker — §4.10 now argues the opposite of what it argued, and says so. Two things are worth more than the rest of the edit. §8.2 records that settings now reach the provider, which was the one unworked-around engine gap. §8.3 is new: one engine field the running engine does not have fails every check that touches this SDK, because Dang infers the whole program per call. That is what 67 red checks were, it is why the manifest is written with withNewFile, and it is expensive to rediscover. Signed-off-by: Yves Brissaud <[email protected]> * docs: record the engine bug that breaks `module client add` `dagger module client add` fails for every SDK provider whose findClientRoot answers with a path. The engine selects the result into a dagql.Nullable[dagql.String]; the module returns a well-formed DynamicOptional wrapping a String; and DynamicOptional.SetField assigns the unwrapped String into the Nullable, which nothing in dagql can do. Valid == false returns early without assigning, so only the null answer works — and since module init never calls findClientRoot, the declining answer is the only one that had ever been exercised. Nothing here can work around it: the interface fixes the return type, and the engine never inspects the value beyond unwrapping it. Written down with the reasoning rather than the symptom, because the message names three dagql types and none of this repo's code. Reproduced at the pinned 8fd9b22b with two plain TypeScript modules. Signed-off-by: Yves Brissaud <[email protected]> * chore: bump dagger/sdk-helpers to 64645f1 Picks up "Omit the default module source from dagger-module.toml": a module source of "." means the manifest directory, which is what a reader assumes when the field is absent, so the builder no longer writes it. That removes a wart from what this SDK produces. Migrating a dagger.json with no `source` used to emit `source = "."`, because the builder fills the field in when the legacy config names an SDK — so every migrated manifest carried a line stating the default. generateMigratesLegacyConfigCheck now asserts it stays unwritten; the assertion fails on the previous pin and passes on this one, which is what says the bump took effect. It also retires half an argument. Writing the manifest only when a scope has none was justified partly by that normalization: a manifest this SDK wrote came back changed on the next generation, so regenerating could not be a fixed point. That is no longer true, and the note in withModuleManifest and design/module-max.md §4.6 said so as if it were load-bearing. The reason that survives is the one that was doing the work all along — clients are a generated package here, not manifest dependencies, so there is nothing to reconcile into a manifest that already exists. Bumped in dagger.lock only. `dagger module deps update` writes a pin into dagger.json instead and leaves the lock contradicting it, which is not the shape this repo or python-sdk uses. Signed-off-by: Yves Brissaud <[email protected]> * feat: bind a scope's clients into the module that records them `dagger module client add` inside a module generated a package the module itself could not reach. The standalone package under `clients/` carries the bootstrap that serves its targets, which is what code outside the module needs; the module's own source imports @dagger.io/dagger, which resolves to the generated sdk/ directory, and the target was not bound there. Fold each target into the module's own bindings too, so `sdk/<target>.gen.ts` sits beside the module's types and its manifest dependencies, re-exported through client.gen.ts. The fold is filtered rather than merged. A target's schema is core plus one module, and its core half is the client-facing one, which hides nothing -- merging it whole would hand a module bindings for core types its own schema withholds. Schema.Include keeps the target's own types and, on the extendable types, only the fields it contributed. Mod.generate cannot reconstruct a scope's targets, since they live in dagger.toml and only the engine reads it. Rather than prune the bindings it cannot regenerate, it now refuses when the module has a clients/ directory. Also name and version the generated package so it can be installed. The name came from the directory the package sits in, which is `clients` in every scope, so every generated package in a workspace had the same name and two of them could not be installed side by side; it now comes from the scope. npm and yarn both refuse a package with no version, so the file: dependency a user adds to reach it could not resolve at all. The engine does not yet install a scope's client targets into the module's own session, so `dag.<target>()` type-checks and then fails at run time unless the target is also a manifest dependency. That half is the engine's; recorded in design/module-max.md section 8.5 rather than worked around. Signed-off-by: Tom Chauveau <[email protected]> * fix: serve a scope's clients by recording them as module dependencies A client generated into a module type-checked and then failed at run time with `Cannot query field "<target>" on type "Query"`. A module's session serves what its manifest lists in [[dependencies]]; a scope's clients live in dagger.toml, which only the engine reads, so nothing ever installed them. Write them into the manifest, the way the Go SDK does. A git target is recorded by its canonical ref and pin, a local one by its path relative to the module that declares it -- the form a manifest uses for any local dependency. This has to run before the module's schema is read, since the schema is what the bindings are generated from and a target that is not a dependency yet is not in it. So it runs for every module scope, not only the ones being created, which is why it is separate from writing the manifest itself. Dependencies are upserted, never pruned: a manifest may carry entries written by hand or migrated from a pre-1.0 dagger.json, and they are indistinguishable from ours, so removing what is missing from the client set would take those with it. Dropping a client therefore leaves its dependency behind. Signed-off-by: Tom Chauveau <[email protected]> * docs: correct what it takes to make a client callable Section 8.5 recorded the run-time failure as the engine's to fix and said nothing here could close it. Both were wrong: the Go SDK already wrote its scope's clients into the module manifest, which is what gets them served, and this SDK now does the same. Signed-off-by: Tom Chauveau <[email protected]> --------- Signed-off-by: Vasek - Tom C <[email protected]> Signed-off-by: Yves Brissaud <[email protected]> Signed-off-by: Tom Chauveau <[email protected]> Co-authored-by: Yves Brissaud <[email protected]>
The pinned engine was a dagger/dagger#13992 branch commit on no release. Signed-off-by: Yves Brissaud <[email protected]>
Closes #13912
Summary
Improve the UX of SDKs by:
dagger module.dagger.tomlschemaSDK Support
This breaks the SDK interface introduced in earlier 1.0 betas. SDKs must be updated to support it. Below is the status of these updates:
SDK module interface
An SDK module is an installed module that implements:
An SDK module can also implement:
A scope can contain one module, generated clients, or both. The engine sets
Workspace.cwdto the persisted scope before generation. The SDK can update files anywhere in the workspace.Lifecycle
dagger module init <SDK>records the module scope and runs its generator.dagger module client add,rm, andupdateregenerate the affected scope.dagger generateregenerates persisted scopes in dependency order.dagger workspace updaterefreshes all lock entries and regenerates every client scope.--no-generateupdates only the lockfile.dagger module updaterefreshes installed modules and regenerates scopes that target an updated module.All config, lockfile, and generated-file changes use one atomic workspace export.
Manifest builder
The manifest builder API lives in the
github.com/dagger/sdk-helpersmodule. See its README for the full API.This PR serializes entrypoint manifests. Loading entrypoint manifests is separate work in #14038.
CLI changes
This PR moves module operations under
dagger module, including install, uninstall, search, settings, initialization, and generated clients. It addsdagger sdk listanddagger sdk scopefor SDK scope metadata. It removesdagger module sdk,dagger module deps,dagger module engine, anddagger api client.dagger module client add <module> [--sdk=SDK]selects one scope. Without--sdk, the engine selects the unique deepest scope across installed SDKs. A tie requires an explicit SDK. Flag help lists the available SDKs. Client add accepts no SDK settings.Client targets are explicit local paths or module addresses. Installed module names are not accepted. Relative paths must use
./or../(or.and..).client list --allshows every saved target. Each target can be removed from its listed scope withclient rm <TARGET> --sdk=<SDK>. Removal preserves the scope and its other data.Scope names are optional. Module initialization saves an explicit name and preserves any existing saved name. Before generation, unnamed module scopes use their matching local entrypoint name or scope directory name. The SDK interface stays unchanged.
Generation keeps its Workspace result through export, including writes above the command directory. Equivalent scope paths use one configuration record. Compatible duplicate records are combined; conflicts produce an error before generation or writes.
The beta SDK-module interface has no compatibility adapter. The legacy module runtime interface does not change.
Validation
Scope-name inference tests were updated but not run, at user request. Formatting and diff checks passed.
The focused CLI suite passed 101 tests. The schema suite passed 87 tests. Earlier integration runs covered scope selection, Workspace export, conflicts, and client removal. The final integration command was stopped at user request. Its warning checks remain unconfirmed.
Design
future/cli-1.0.mdis the source of truth. Related issue: #13912.