fix(cli): bundle the mounted product SDKs into the standalone binary

Closed
AG
3mo ago
+1492-126

Fixes #1795. All three mounted groups are broken in the standalone binary; npm installs are fine, which is why this was reported as working.

$ readlink -f "$(command -v agent-relay)"
~/.agentworkforce/relay/bin/agent-relay      # 102 MB, single file, 12.2.5

$ agent-relay file -h
`agent-relay file` needs @relayfile/sdk, which is not installed.

Cause

scripts/build-standalone.sh bundles with esbuild, then bun --compile. esbuild resolves imports statically, and the mount gave it nothing to resolve — the specifier reached import() as a string field of PRODUCT_SURFACES. Nothing was bundled, and a compiled binary has no node_modules to fall back on.

The fix, measured

Literal imports in a map keyed by specifier. Same input, before and after:

variable specifier:      173 bytes   SDK included: no
literal in a map:     27,280 bytes   SDK included: yes

The DI seam is untouched: importModule keeps its signature, tests override it as before, and the dynamic fallback stays for specifiers outside the table — the end-to-end test mounts product builds by absolute path.

Dependency floors are part of the fix

Not incidental. The pins admitted versions with no relay-cli subpath at all — ^0.10.63 and ^0.18.0 — and the lockfile held exactly those, so a literal import failed to typecheck on a clean install:

error TS2307: Cannot find module '@relayfile/sdk/relay-cli'
error TS2307: Cannot find module 'ai-hist/relay-cli'

They now start where the subpath exists (^0.10.64, ^2.0.19, ^0.18.1), verified against the registry. That was a latent bug on its own: the old floors permitted an install where the mount could never work.

Two guards

A type error is not what this failure looks like, so neither guard is a typecheck:

  1. Unit test — every PRODUCT_SURFACES entry must have a literal import('<specifier>') in the source. A new group without one compiles, passes every other test, and breaks only in the compiled binary. Mutation-verified: removing the ai-hist literal fails it.
  2. ci-standalone-smoke.sh — now runs file|flows|sessions --help against the compiled binary and requires each to render Usage: agent-relay <group>. This is the check whose absence let it ship; --help needs no daemon, network, or credentials.

Verification

20 tests pass in product-surfaces.test.ts; product-surfaces.ts typechecks clean against the new floors. The bundle measurement above is the direct evidence — the remaining proof is the smoke script running in CI on a real compiled binary, which is where I could not reach locally.

How it shipped

I verified the mount against local and global npm installs and called it done. I did not know the standalone distribution existed and never tested it. One line in the standalone smoke script would have caught it.

🤖 Generated with Claude Code


[!NOTE]
Medium Risk
First-use standalone behavior now depends on npm, network, and filesystem writes under the data directory; npm installs are unchanged but provisioning races and install failures are new operational paths.

Overview
Fixes #1795 so the compiled standalone agent-relay can mount file, flows, and sessions instead of failing with “SDK not installed” when there is no node_modules.

When the binary detects a compiled Bun standalone build and a pinned surface import cannot resolve, it npm-installs @relayfile/sdk, @relayflows/sdk, and ai-hist (versions mirrored in SURFACE_PACKAGES) under ~/.agentworkforce/relay/surfaces, then loads each surface via a child Node runner so Go binaries, native addons, and import.meta.url assets stay on real disk paths.

importProductSurface wires this into command registration; npm/global installs still use a normal dynamic import() with no provisioning. Load failures are split into clearer cases (missing vs incomplete install, transitive deps, provisioning errors).

Dependency floors move to versions that export relay-cli (^0.10.64, ^2.0.19, ^0.18.1); monorepo 12.2.5 and lockfile follow. CI now smoke-tests all three groups on the standalone binary (ci-standalone-smoke.sh, standalone-mount-probe.sh, unit tests for the store and import path).

Reviewed by Cursor Bugbot for commit 8aab829c54b0bda6b7e075c9fc5ef1ab7a98e52d. Bugbot is set up for automated code reviews on this repo. Configure here.