Skip to content

refactor(api): fold @decocms/harness into apps/api and collapse the harness registry - #5578

Merged
viktormarinho merged 1 commit into
mainfrom
refactor/fold-harness-into-api
Aug 3, 2026
Merged

viktormarinho merged 1 commit into
mainfrom
refactor/fold-harness-into-api

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Final step of the packages/harness teardown. #5573 deleted the dead TS CLI harnesses; #5577 moved the wire contracts to @decocms/shared/harness; this deletes the package.

Why the package had to go

After the previous two steps it was 9.5k lines consumed by apps/api alone — 49 of its 56 import subpaths had no consumer outside the API. Its stated reason to exist ("portable into the desktop daemon's bundle", per its own types.ts) died with the link daemon (#5570) and the TS sandbox daemon (#5575). What remained was apps/api importing its own agent loop through a package boundary, at the cost of a 56-entry exports map and a knip blind spot.

The move (mechanical bulk of the diff)

  • packages/harness/src → apps/api/src/harnesses/lib via git mv — history preserved, internal relative imports untouched.
  • 58 apps/api files rewritten from "@decocms/harness/X" to "@/harnesses/lib/X".
  • Every dependency the lib needs was already in apps/api's manifest (the six missing from dependencies are in devDependencies because the server bundle inlines them). Nothing added.
  • Workspace package, README, tsconfig, and the dependency edges are gone. bun run check:readmes now validates 14 workspaces.

The leaf discipline survives the package's death, as a directory rule. plugins/ban-cross-tree-imports.js now applies its harness clauses — no @/ imports, no @/core/studio-context (flat HarnessDeps, never the recursive context, spec §4.2), no @aws-sdk/* — to apps/api/src/harnesses/lib/, and no-cross-tree.test.ts moved with the tree and still scans it. Verified: the lib has zero @/ imports after the rewrite. The engine stays a leaf; only the wrapper is gone.

The registry collapse (spec §5.4, executed at last)

in-process-sandbox-client.ts's own header said it: "localDispatch is then folded fully into this client (§5.4)". Done:

  • InProcessSandboxClient.dispatch hard-wires decopilotHarnessFactory — the registry it consulted was a Map with one entry, populated by an import side effect, and localDispatch had exactly one caller. registry.ts, local-dispatch.ts, the orphaned lib barrel (lib/index.ts — nothing imported it), and their registration tests are deleted.
  • The CLI guard stays truthful: dispatch throws eagerly for claude-code/codex, same posture as assertHarnessRunsInCluster at the gate.
  • apps/api/src/harnesses/index.ts keeps its one load-bearing side effect: registering the cluster environment builder the factory requires (stream() throws without it — same coupling as before, now documented as the reason the barrel exists).
  • Tests rewritten against the real factory instead of stubbing a registry seam: the CLI guard fires eagerly, and dispatch("decopilot") returns a lazy stream (create()+stream() do no eager work — nothing executes until first pull). No mocks, per TESTING.md.

What knip caught once the boundary stopped hiding it

  • buildRepoEnvironmentPrompt — deleted. Nothing in the repo builds the <repo-environment> prompt block; only a stale comment referenced it.
  • CHAT_MODES — narrowed to module-private. Only its derived ChatMode type is consumed.

Testing

  • One behavioral delta vs main, and it's the known one: bun test over apps/api/src plugins scripts fails 199 on this branch vs 198 baseline (same scope + packages/harness on origin/main, sorted lists diffed) — the one new failure was the DBOS workflow-source snapshot guard, because import-specifier text is hashed. Re-baselined via apps/api/scripts/update-workflow-source-snapshot.ts (8 hashes), now green. The 198 are the pre-existing no-local-Postgres failures, byte-identical.
  • bun run check clean across all 14 workspaces. bun run lint identical to baseline. knip exit 0.
  • Remaining @decocms/harness mentions in the repo: 3, all deliberate — two "the former @decocms/harness" historical notes, one lint-test fixture that needs an unlisted @decocms/* name (a deleted package is now guaranteed unlisted).

Rebase note (not a breaking change — private workspace package, nothing external consumed it)

Open PRs importing @decocms/harness rebase onto @/harnesses/lib/* (api) or @decocms/shared/harness/* (contracts).

After this PR

The five-hop dispatch chain is two: InProcessSandboxClient → factory.create(ctx).stream(input). One harness, one host, one package fewer, and knip sees all of it.

…arness registry

Final step of the harness-package teardown (#5573 deleted the dead TS CLI
harnesses; #5577 moved the wire contracts to @decocms/shared/harness). After
those, the package was 9.5k lines consumed by apps/api alone — its stated
reason to exist (portability into the desktop daemon's bundle) died with the
link daemon (#5570) and the TS sandbox daemon (#5575).

The move:
- packages/harness/src → apps/api/src/harnesses/lib (git mv, history kept).
  58 api files rewritten from "@decocms/harness/X" to "@/harnesses/lib/X".
  All the lib's deps were already in apps/api's manifest; the workspace
  package, its README, tsconfig and dependency edges are gone.
- The leaf discipline survives as a directory rule: ban-cross-tree-imports
  now applies its harness clauses (no @/ imports, no @/core/studio-context,
  no @aws-sdk/*) to apps/api/src/harnesses/lib/, and no-cross-tree.test.ts
  moved with the tree and still guards it. The engine stays a leaf; only the
  package wrapper is gone.

The registry collapse (spec §5.4, executed at last):
- InProcessSandboxClient absorbs localDispatch and hard-wires
  decopilotHarnessFactory — the registry it consulted was a Map with one
  entry, populated by an import side effect. registry.ts, localDispatch, the
  orphaned lib barrel and their registration tests are deleted; the client's
  tests now assert the real factory's contract (eager CLI guard, lazy stream)
  instead of stubbing a seam.
- apps/api/src/harnesses/index.ts keeps one side effect: registering the
  cluster environment builder the factory requires.

Fallout knip caught once the package boundary stopped hiding it:
- buildRepoEnvironmentPrompt: dead (nothing builds that prompt block). Deleted.
- CHAT_MODES: only its derived type is consumed. Narrowed to module-private.

DBOS workflow-source snapshot re-baselined (import-specifier text is hashed;
apps/api/scripts/update-workflow-source-snapshot.ts, 8 hashes).

Infra: sandbox-daemon.yml change filter, release-changes test fixtures, root
README workspace table, bundle-server-script comment.
@viktormarinho viktormarinho changed the title refactor(api)!: fold @decocms/harness into apps/api and collapse the harness registry refactor(api): fold @decocms/harness into apps/api and collapse the harness registry Aug 3, 2026
@viktormarinho
viktormarinho force-pushed the refactor/fold-harness-into-api branch from 174c4ef to e6fec02 Compare August 3, 2026 02:16
@viktormarinho
viktormarinho merged commit 5cbef07 into main Aug 3, 2026
25 checks passed
@viktormarinho
viktormarinho deleted the refactor/fold-harness-into-api branch August 3, 2026 02:44
decocms Bot pushed a commit that referenced this pull request Aug 3, 2026
PR: #5578 refactor(api): fold @decocms/harness into apps/api and collapse the harness registry
Bump type: patch

- decocms (apps/api/package.json): 4.160.5 -> 4.160.6
- @decocms/native (apps/native/package.json): 4.160.5 -> 4.160.6
- @decocms/sandbox (packages/sandbox/package.json): 1.35.5 -> 1.35.6
- @decocms/shared (packages/shared/package.json): 0.13.4 -> 0.13.5
- deploy/helm/sandbox-env (chart 0.10.5) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.35.6

Deploy-Scope: server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant