fix(sdk): declare typescript and undici as runtime dependencies so flows check works on a clean install

Merged
AG
1mo ago
+172-3

Fixes #605. flows check crashes on a clean install (ERR_MODULE_NOT_FOUND: typescript) because @relayflows/sdk imports typescript at runtime (src/cli/check-activities.ts) but only declared it as a devDependency.

Change

  • packages/sdk/package.json / package-lock.json: move typescript (^5.6.0, range unchanged) to dependencies, and declare undici (^7.29.1), which the SDK already imports at runtime and was likewise only resolving transitively. Lock regenerated without upgrades: TypeScript loses its dev: true marker; there is one undici entry. TypeScript, not acorn, is needed because the activity checker parses TypeScript syntax.

  • packages/sdk/tests/runtime-dependencies.test.ts: AST-scans the built SDK JavaScript for literal imports / re-exports / require calls and fails on any bare package not declared in dependencies/peerDependencies. Computed imports are a documented blind spot.

  • packages/sdk/tests/cli-package-gate.test.ts + scripts/cli-package-gate.mjs: the clean-install regression #605 asked for. Packs surface, SDK and relayflows with the existing scripts/pack-release.mjs, installs the real tarballs into a temp dir outside the repo (it rejects any ancestor node_modules and clears NODE_PATH/NODE_OPTIONS), and runs flows check on examples/dependency-upgrade-bot for:

    • a local install, via both npm's linked flows bin and the relayflows wrapper entry point. Both the SDK and relayflows claim the flows bin, so checking only the bin would leave the wrapper unexercised.
    • a global install, which must expose only flows (no tsc/tsserver) and is checked against a consumer project that has no TypeScript of its own.

    It also asserts TypeScript resolves inside the installation. It needs Node >=22.18.0 and built surface/SDK dist, which the CI SDK job already provides. Registry errors fail the test. FLOWS_SKIP_PACKAGE_GATE=1 is an explicit, loudly reported local opt-out.

  • tsconfig.tests.json includes the two new tests.

No workflow files change and no committed evidence ships; an earlier revision's evidence/ transcripts were removed.

Verification

Packaging regression is red on base, green on head. I copied the two new tests and the gate script onto base d1877301 (main, typescript still a devDependency) and ran vitest run tests/runtime-dependencies.test.ts tests/cli-package-gate.test.ts in both trees:

# base d1877301 + new tests  -> exit 1, Tests 2 failed (2)
→ Undeclared runtime dependencies: expected [ 'typescript', 'undici' ] to deeply equal []
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'typescript' imported from …/flows-cli-package-p2vJWw/local/node_modules/@relayflows/sdk/dist/cli/check-activities.js

# head 812000a3              -> exit 0, Tests 2 passed (2)
CHECK PASSED examples/dependency-upgrade-bot.flow.ts   (x4: local bin, local wrapper, global bin, global wrapper)
CLI_PACKAGE_OK: local and global installs

Full SDK suite: the PR adds no failures. CI's linux-x64-artifact job runs the whole SDK suite, including both new tests, and is green on 812000a3. The first attempt hit two known main flakes, both seen on main: authored-parallel-agents "never starts queued agents once the body has failed" (main run 37137600293) and a named-gate-diagnostics word_count_bounds "could not run wc" spawn error (main run 37103010381). They passed on --failed rerun.

Locally (macOS arm64, Node 26.8.1, bun 1.4.0, a freshly built relayflowd via RELAYFLOWD_BIN, RELAYFLOWS_ALLOW_ANALYZER_SKIP=1), I ran the full suite with an identical command and environment on head and on its base d1877301, one after the other: vitest run --no-file-parallelism, after CI's setup steps (surface build, npm ci, local-surface override, typecheck, build, typecheck:tests).

Test filesTests
base d18773018 failed / 239 passed / 1 skipped (248)52 failed / 3676 passed / 55 skipped
head 812000a38 failed / 241 passed / 1 skipped (250)52 failed / 3678 passed / 55 skipped

The sets of failing tests, by file and full name, are identical (comm: 0 head-only, 0 base-only). The two extra passing files on head are the new tests. The 52 shared failures are environmental on this Mac:

  • hosted-base-snapshot (15), hosted-extension-isolation (12), hosted-extension-protocol (7): "hosted extension isolation requires Linux" (bubblewrap sandbox).
  • authored-node-runtime (14), cli (2), live-kernel (1), authored-parallel-agents (1): local authored-runtime/worker failures that also fail on base and pass in CI on Linux.

Also: npm run typecheck, npm run build and npm run typecheck:tests in packages/sdk exit 0 on head.

Not covered / follow-ups

  • CI path filter. cloud-runtime-artifact.yml triggers the SDK job on packages/sdk/** (among others). A future PR touching only scripts/cli-package-gate.mjs, scripts/pack-release.mjs, packages/surface/**, packages/relayflows/** or the example would not run this gate. Adding those paths is a one-line follow-up that needs a workflow-scoped push; it was left out of this PR.
  • Standalone Bun binaries, Windows packaging, Node <22.18, the broader published engines range and the stale SDK bun.lock are outside this fix.

🤖 Generated with Claude Code


Agent Relay sessions

  • claude session 03e53226 · contributor · ran gh pr commands · last active 2026-10-04
  • claude session 570354ad · contributor · ran gh pr commands · last active 2026-10-04