Skip to content

Standalone binary cannot mount file/flows/sessions: dynamic specifiers defeat the bundler #1795

Closed

Description

@AgentRelayBot

All three mounted product groups are broken in the standalone binary distribution. npm installs are fine.

Repro

$ readlink -f "$(command -v agent-relay)"
/home/<user>/.agentworkforce/relay/bin/agent-relay      # 102 MB, single file

$ agent-relay --version
12.2.5

$ agent-relay file -h
`agent-relay file` needs @relayfile/sdk, which is not installed.
$ agent-relay flows -h
`agent-relay flows` needs @relayflows/sdk, which is not installed.
$ agent-relay sessions -h
`agent-relay sessions` needs ai-hist, which is not installed.

The same version installed from npm mounts all three correctly, globally or locally. This is specific to the bundled binary, and it takes precedence when ~/.local/bin precedes the Node paths in PATH — which it does by default, via a wrapper:

~/.local/bin/agent-relay → exec ~/.agentworkforce/relay/bin/agent-relay

Cause

scripts/build-standalone.sh bundles with esbuild, then compiles with bun --compile. esbuild resolves imports statically. The mount does not give it anything to resolve:

// product-surfaces.ts
const PRODUCT_SURFACES = [
  { as: 'file', specifier: '@relayfile/sdk/relay-cli' },   // a string field
  …
];
…
importModule: (specifier: string) => Promise<unknown>      // await import(specifier)

The specifier reaches import() as a runtime value, so esbuild cannot see it, does not bundle those packages, and leaves a dynamic import that has no node_modules to resolve against inside a compiled binary. It fails as MODULE_NOT_FOUND — which the current message reports as "not installed", accurately from its point of view and uselessly for the user, since reinstalling changes nothing.

Worth noting the indirection is deliberate elsewhere for a different reason — RELAYHISTORY_CLOUD_CLIENT is held in a variable specifically so TypeScript will not resolve an optional dependency at compile time. The same shape that defeats tsc defeats the bundler.

scripts/link-product-surfaces.sh exists to link sibling SDK builds for local development, but it is not wired into build-standalone.sh and would not help: it populates node_modules, which the compiled binary does not consult.

Options

  1. Make the imports statically analyzable. Replace the specifier strings with literal thunks — load: () => import('@relayfile/sdk/relay-cli') — so esbuild bundles all three. Keeps one distribution working like the other. The DI seam for tests stays; only the default loader changes.
  2. Mark them external and ship a node_modules beside the binary. Defeats the point of a standalone binary.
  3. Detect the bundled runtime and say so. Not a fix, but any of the above should still land — the present message sends people to reinstall something that cannot help.

I would take (1), with a smoke test in ci-standalone-smoke.sh that runs file|flows|sessions --help against the compiled binary. Nothing currently exercises the mount in that distribution, which is why this shipped.

How it was missed

I verified the mount against local and global npm installs and reported it working. I did not know the standalone distribution existed, and never tested it. The check that would have caught this is one line in the standalone smoke script.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions