Skip to content

chore(harness): delete the TypeScript CLI harnesses and un-blind knip on the package - #5573

Merged
viktormarinho merged 5 commits into
mainfrom
chore/drop-dead-cli-harness-registration
Aug 3, 2026
Merged

viktormarinho merged 5 commits into
mainfrom
chore/drop-dead-cli-harness-registration

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #5570 (desktop link removal) and #5575 (TypeScript daemon removal). One causal chain, in five commits — each step is what made the next one visible.

1. The cluster registered two harness factories nothing could look up

apps/api/src/harnesses/index.ts registered claudeCodeHarnessFactory and codexHarnessFactory. Both were unreachable — the cluster dispatch path guards them twice, before any registry lookup:

  • assertHarnessRunsInCluster (dispatch-queue/thread-gate-workflow.ts) throws for claude-code / codex at the gate.
  • dispatchRunAndWait throws again on any non-decopilot id before constructing InProcessSandboxClient.

localDispatch → getHarnessFactory is only reachable past both, so the registration could only ever produce a factory nobody can call.

2. …which left the whole TypeScript CLI harness implementation dead

#5575 deleted the TS sandbox daemon — the last runtime that registered those two factories. With the cluster registration gone too, packages/harness/src/{claude-code,codex} had zero production consumers.

The live CLI implementation is Rust (apps/native/crates/harness/), and it is a port of this code, not a consumer — a TypeScript factory interface does nothing for it.

Deleted (~2,050 lines): the codex/ subtree, claude-code/{index,resolve-executable,model/index}, cli-session-error, cli-stream-metadata, the ./claude-code + ./codex export subpaths, and the ai-sdk-provider-claude-code / ai-sdk-provider-codex-cli dependencies.

Kept:

  • claude-code/model/agent-tiers.ts + chat-tier.ts — apps/web/src/components/chat/use-agent-mode.ts and apps/api/src/api/routes/decopilot/routes.ts import resolveAgentTier to build the model picker.
  • cli-harness.ts's cliProviderName — the read side of CLI session resume (resolveCliSessionRef / computeCliDelta) still needs it.

HarnessId is not touched: it stays a 3-value union. It is persisted in threads.harness_id, drives the chat agent picker, and is the wire vocabulary the Rust crate speaks. That is a domain enum and it is legitimate — what died is the TS implementation behind two of its values.

3. …which knip could not see, because the exports map was a wildcard

packages/harness/package.json's exports ended in "./*": ["./src/*.ts", "./src/*/index.ts"]. Every file under src/ therefore looked like a public entry point, so knip could never report anything in this package as unused — it returned exit 0 both before and after deleting 2k lines. The orphans above had to be found by grepping module reachability by hand.

Replaced the glob with the 56 subpaths actually imported (plus "."), generated from the real import specifiers across apps/ and packages/, each verified to resolve to a file on disk. No consumer changes.

Knip then immediately found two more things the glob had been hiding:

  • src/no-background-tasks-prompt.ts — deleted. Its own doc says "Shared across CLI harnesses (claude-code, codex)"; orphaned by step 2, zero remaining references.
  • THOUGHT_SIGNATURE_SEPARATOR — narrowed to module-private. Used only inside decopilot/thought-signature.ts.

Knip is now exit 0 on a map that can actually go stale, which is the point.

Testing

  • Zero new test failures. bun test over packages/harness apps/api/src/{harnesses,dispatch-queue,api/routes/decopilot}: 1017 pass / 16 fail on this branch, and the same 16 on origin/main — diff of the two sorted failure lists is empty. They are the DB-dependent tests (no local Postgres). bun test packages/harness alone: 341 pass, 0 fail.
  • bun run check clean across all 15 workspaces — which is also the proof that nothing reachable before is unreachable now.
  • bun run lint: 14 warnings / 0 errors, identical to the main baseline (diffed via stash).
  • knip exit 0.
  • Checked for harness consumers outside .ts/.tsx (.js, .mjs, .cjs, .json, dynamic import(), require): none.

Tests changed, not just deleted

  • cli-import-boundary.test.ts deleted, because it breaks: it read claude-code/index.ts and codex/index.ts off disk and fails ENOENT once they are gone. (It was also a source-text assertion, which is not a test.)
  • cli-harness.test.ts repointed: it only covered isCliHarness, which was dead. It now covers cliProviderName — the surviving export, and a cross-language contract with the Rust crate that previously had no test at all.
  • cli-message-prep.ts lost prepCliMessages (CLI-only, self-tested) and kept extractUserText (used by decopilot). Renamed to extract-user-text.ts so the filename stops describing code that no longer exists.

No guard test for the exports map, deliberately

Forgetting an entry for a newly shared module already fails loudly at bun run check — verified by probing with a real unexported subpath:

error TS2307: Cannot find module '@decocms/harness/extract-user-text'
             or its corresponding type declarations.

The compiler is the check. It is documented in the README, because that message reads as "the file is missing" when the file is merely unexported.

README

Corrected, because these deletions made it wrong. It still advertised Claude Code and Codex harnesses, a codexHarnessFactory usage example, and "portable between the API and sandbox daemon" as the boundary rationale. All three are gone.

What this leaves, for the record

Exactly one harness now runs in Kubernetes: decopilot, in the API worker. Not even in the sandbox pod — the Go daemon dispatches harnesses through a HARNESS_RUNNER_CMD subprocess, and that env is set nowhere in the Dockerfile or the helm chart, so POST /_sandbox/dispatch always answers unknown_harness.

To reach that single implementation the cluster still goes through five hops: InProcessSandboxClient (1 impl of SandboxClient) → localDispatch → getHarnessFactory (a Map with one entry, populated by import side-effect) → HarnessFactory.create (1 impl) → Harness.stream (1 impl).

And packages/harness is now 10.4k lines of which src/decopilot/ is 73%, imported by apps/api only. apps/web (5 subpaths) and packages/sandbox (3) consume contracts, not the agent loop. The package's stated rationale — portability into the desktop daemon's bundle — died with #5570 and #5575; what justifies the boundary today is that apps/web and packages/sandbox are lint-barred from importing apps/api/src.

Both of those are design changes rather than dead-code deletions, so neither is in this PR.

…harnesses

`assertHarnessRunsInCluster` throws for claude-code/codex at the dispatch
gate, and `dispatchRunAndWait` throws again on any non-decopilot id — so the
factories the barrel registered could never be reached by a lookup. Local CLI
runs happen in the Tauri app's Rust harness crate; cloud-CLI is unimplemented.

Also removes `buildSandboxDaemon()` from the server bundler: it built
packages/sandbox's daemon bundle + typegen tarball on every API build for
host/runner.ts's text-import, and that file no longer exists (#5570). The
sandbox image workflow runs its own `bun run --cwd=packages/sandbox build`,
so the image is unaffected.
… test

Asserting a file's source does not contain a symbol tests the deletion, not
the behavior. The registry lookup is already covered by the gate's own tests.
… hosts them

#5575 deleted the TS sandbox daemon, which was the last runtime that
registered `claudeCodeHarnessFactory`/`codexHarnessFactory`; the preceding
commit dropped the cluster's unreachable registration. That left the whole TS
CLI harness implementation with zero production consumers — the live one is
Rust (`apps/native/crates/harness`), which is a port, not a consumer.

Deleted: packages/harness/src/{codex,claude-code/index,resolve-executable,
model/index}, cli-session-error, cli-stream-metadata, the ./claude-code and
./codex export subpaths, and the ai-sdk-provider-{claude-code,codex-cli} deps.

Kept: claude-code/model/agent-tiers.ts + chat-tier.ts (apps/web and apps/api
import `resolveAgentTier` to build the model picker), and cli-harness.ts's
`cliProviderName` (the read side of CLI session resume).

Knip could not see any of this: packages/harness's exports map has a "./*"
glob, so every src file looks like a public entrypoint.

- cli-import-boundary.test.ts deleted: it read claude-code/index.ts and
  codex/index.ts off disk, so it fails ENOENT once they are gone.
- cli-harness.test.ts covered only `isCliHarness`, which was dead. Repointed
  to `cliProviderName` — the surviving export, and a cross-language contract
  with the Rust crate that had no test at all.
- cli-message-prep.ts lost `prepCliMessages` (CLI-only) and kept
  `extractUserText` (decopilot). Renamed to extract-user-text.ts so the
  filename stops describing code that is gone.
@viktormarinho
viktormarinho force-pushed the chore/drop-dead-cli-harness-registration branch from 1f90718 to e83b7c9 Compare August 3, 2026 00:59
@viktormarinho viktormarinho changed the title chore(harness): drop the unreachable CLI harness registration and the orphaned daemon bundle build chore(harness): delete the TypeScript CLI harnesses and their unreachable cluster registration Aug 3, 2026
The overview still advertised Claude Code and Codex harnesses, a codex usage
example, and "portable between the API and sandbox daemon" as the boundary
rationale — all three are gone. Restates the real one: apps/web and
packages/sandbox are lint-barred from apps/api/src, so the contracts the three
share have to live outside the API.
packages/harness's exports ended in "./*": ["./src/*.ts", "./src/*/index.ts"],
so every file under src/ looked like a public entry point and knip could never
report anything here as unused. That is how ~2k lines of dead CLI harness code
stayed invisible until it was grepped by hand.

Replaces the glob with the 56 subpaths actually imported (plus "."), generated
from the real import specifiers across apps/ and packages/ and verified to
resolve. No consumer changes: bun run check passes in all 15 workspaces.

Knip now reports on this package, and immediately found two things the glob was
hiding:
- no-background-tasks-prompt.ts — a system-prompt fragment whose own doc says
  "shared across CLI harnesses (claude-code, codex)"; orphaned when those were
  deleted. Removed.
- THOUGHT_SIGNATURE_SEPARATOR — used only inside its own module. Narrowed to
  module-private.

No guard test: a missing entry is already a compile error (TS2307) on
bun run check. Documented in the README, since that message reads as "file
missing" when the file is merely unexported.
@viktormarinho viktormarinho changed the title chore(harness): delete the TypeScript CLI harnesses and their unreachable cluster registration chore(harness): delete the TypeScript CLI harnesses and un-blind knip on the package Aug 3, 2026
@viktormarinho
viktormarinho merged commit f4292ca into main Aug 3, 2026
48 checks passed
@viktormarinho
viktormarinho deleted the chore/drop-dead-cli-harness-registration branch August 3, 2026 01:46
decocms Bot pushed a commit that referenced this pull request Aug 3, 2026
PR: #5573 chore(harness): delete the TypeScript CLI harnesses and un-blind knip on the package
Bump type: patch

- decocms (apps/api/package.json): 4.160.3 -> 4.160.4
- @decocms/native (apps/native/package.json): 4.160.3 -> 4.160.4
- @decocms/harness (packages/harness/package.json): 2.8.4 -> 2.8.5

Deploy-Scope: server
viktormarinho added a commit that referenced this pull request Aug 3, 2026
…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 added a commit that referenced this pull request Aug 3, 2026
…arness registry (#5578)

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.
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