refactor: decompose the three largest TypeScript god files into single-responsibility modules

Merged
WI
4mo ago
+1840-1099

Summary

Continues the god-file decomposition pattern (prior e7fd375 did the CLI) on the three largest TypeScript files — the system's most central client/orchestration surfaces. Each change is a behavior-preserving pure move behind an unchanged public API.

FileBefore → AfterNew modules
sdk/messaging/relaycast.ts1654 → 1126relaycast-translate.ts, relaycast-placement.ts, relaycast-client.ts
harness-driver/client.ts1199 → 931spawn-request.ts, broker-process.ts
cloud/workflows.ts1129 → 893workflow-paths.ts

The common thread: separate pure logic (wire↔domain translation, spawn-request shaping, workflow-path parsing) from the stateful/IO code (messaging client, broker-process client, cloud S3/API orchestrator). Public surfaces are preserved via re-exports, so consumers and tests are unaffected.

Per-file detail

  • relaycast.ts → relaycast-translate.ts (pure wire↔domain translation + record readers), relaycast-placement.ts (RelayPlacementError, placement payload helpers), relaycast-client.ts (structural relaycast adapter types, options, createRelaycastClient). Re-exports RelayPlacementError and RelaycastMessagingOptions. A follow-up commit also unexports the translate readers that don't cross a module boundary (review feedback).
  • harness-driver/client.ts → spawn-request.ts (/api/spawn body builders + patch applier), broker-process.ts (managed broker child-process lifecycle: API-URL wait, stdio drain, recent-output buffering, startup-error formatting, shutdown). BrokerExitInfo moved and re-exported so the package barrel is unchanged.
  • cloud/workflows.ts → workflow-paths.ts (YAML path parser + TS literal scanner + parseWorkflowPaths/inferWorkflowFileType/shouldSyncCodeByDefault). Validation (which shells out), the runtime PATH_NAME_RE guard, GitHub-remote helpers, and all execution/API/S3 code stay behind; the three parser entry points are re-exported so the barrel and tests still import from ./workflows.js.

Verification (every step)

  • Build: npm run build:core green, 0 TS errors.
  • Tests: full vitest run — 959 passed / 5 skipped, identical to baseline throughout.
  • Live smoke tests: exercised the moved code through the built packages (SDK public surface + agents.list; harness-driver isProcessRunning/buffer-cap/spawn-body builders; cloud YAML+TS path parsing + re-export identity).
  • Independent autoreview on each diff (finder + verifier agents): all returned APPROVE / empty bug list — verbatim-move integrity, import hygiene, public-surface preservation, and no-import-cycle confirmed.

Notes

  • One reviewer flag was deliberately not acted on: merging the translate.ts record readers with normalize.ts's. They have genuine semantic divergence (normalize.readString coerces numbers→strings; readRecord clones) — consolidating would be a silent behavior change, not a refactor.
  • No CHANGELOG.md entry: these are internal module reorganizations with no user-visible effect.

🤖 Generated with Claude Code


Generated by Claude Code