Skip to content

refactor(shared): move the harness wire contracts to @decocms/shared/harness - #5577

Merged
viktormarinho merged 1 commit into
mainfrom
refactor/harness-contracts-to-shared
Aug 3, 2026
Merged

viktormarinho merged 1 commit into
mainfrom
refactor/harness-contracts-to-shared

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Step 2 of the packages/harness teardown; #5573 (merged) was step 1. Rebased onto it — clean, no conflicts, as the shim design intended.

Post-rebase pruning (composing with #5573's enumerated exports map): the offload-messages shim came out fully orphaned — nothing consumed it via subpath or barrel — so shim + barrel re-exports + exports entry are deleted rather than kept. And knip (now able to see the package, per #5573) immediately flagged the chat-tier.ts shim as unused: its last importer died in #5573 and agent-tiers derives ChatTier from the schema now. Deleted too. Two shims fewer than originally described below.

Why

apps/web (19 files) and packages/sandbox (3 files) imported 7 subpaths of @decocms/harness. Every one of them is a contract — HarnessId, ModelsConfig, ChatMode, HarnessStreamInput, the run-stream codec, the offload envelope, the skill front-matter parser, the todo-write schema, storage-uri helpers, agent tiers. None of them is the agent loop.

That dependency is what made a 10.4k-line package look shared when 92% of it is consumed by apps/api alone. After this PR, @decocms/harness is API-only — which is what makes the endgame (folding decopilot/ into apps/api/src and deleting the package) a mechanical follow-up instead of a design question.

What moved

~820 LOC + their co-located tests, via git mv, into packages/shared/src/harness/ — the package CLAUDE.md already defines as "isomorphic contracts, browser-safe SDK utilities". They qualify: no node: builtins, dependencies only ai + zod, both already in packages/shared.

from @decocms/harness/… to @decocms/shared/harness/…
types (domain/wire part) types
run-stream-codec run-stream-codec
offload-messages offload-messages
skills/skill-md skill-md
decopilot/built-in-tools/todo-write todo-write
decopilot/studio-storage-uri studio-storage-uri
claude-code/model/agent-tiers agent-tiers

Three judgment calls

1. types.ts is split, not moved whole. The domain/wire types move; the host-side execution contracts (Harness, HarnessContext, HarnessFactory) stay in @decocms/harness. Only the API uses them, HarnessContext is typed against @opentelemetry/api (which packages/shared doesn't and shouldn't have), and all three are slated to die when the one-entry registry collapses in the follow-up.

2. @decocms/harness keeps re-export shims at the old paths. The API and harness internals import these modules from ~50 places; repointing them here would drag half of apps/api into this diff and conflict with #5573. The shims are 3 lines each and are deleted by the follow-up that folds decopilot/ into apps/api. This PR's blast radius is: moved files + the 22 web/sandbox import sites + two package.jsons.

3. ChatTier stops being a mirror. chat-tier.ts's doc said it mirrored @decocms/shared/organization/schema:ChatTierSchema "so the harness tree carries no @/* reach". Living in packages/shared, the reach exists natively — the type now derives from the schema it used to mirror. One duplication deleted.

The visible result

apps/web/package.json and packages/sandbox/package.json drop @decocms/harness entirely.

Testing

  • bun run check clean across all 15 workspaces — which is also the proof that every consumer resolved after the move.
  • bun test over the moved tests + both consumers' suites (packages/shared/src/harness, packages/harness, packages/sandbox/dispatch, the touched web tests): 460 pass, 0 fail.
  • bun run lint: 14 warnings / 0 errors, identical to main baseline (kebab-case plugin covers the new packages/shared files).
  • knip exit 0.
  • Grep for remaining @decocms/harness references in apps/web + packages/sandbox: zero (three stale doc comments updated).

Follow-up (not here)

With web/sandbox off the package: move decopilot/ + the top-level utilities into apps/api/src/, delete the shims, delete @decocms/harness, and collapse the one-entry registry (InProcessSandboxClient → localDispatch → getHarnessFactory → factory.create().stream() becomes a function call). That is ~9.5k lines of git mv and import rewrites — mechanical after this, but a conflict bomb for open decopilot PRs, so it wants its own window.

…harness

apps/web (19 files) and packages/sandbox (3) imported 7 subpaths of
@decocms/harness — all of them contracts (HarnessId, ModelsConfig, ChatMode,
HarnessStreamInput, the run-stream codec, offload envelope, skill front-matter
parser, todo-write schema, storage-uri helpers, agent tiers), none of them the
agent loop. That dependency is what kept a 10.4k-line package looking shared
when 92% of it is consumed by apps/api alone.

Moves those surfaces (~820 LOC + their tests, via git mv) into
packages/shared/src/harness/ — the package CLAUDE.md already defines as
'isomorphic contracts, browser-safe'. They fit: no node: builtins, deps only
ai + zod, both already in packages/shared.

- types.ts is split: domain/wire types move; the host-side execution
  contracts (Harness, HarnessContext, HarnessFactory — API-only, and the
  otel-typed part) stay in @decocms/harness.
- chat-tier.ts's ChatTier existed only to mirror
  @decocms/shared/organization/schema:ChatTierSchema without a cross-package
  reach. Living in shared, it now derives from the schema it mirrored.
- @decocms/harness keeps re-export shims at the old paths so the API and
  harness internals are untouched here; the shims go when decopilot/ folds
  into apps/api.
- apps/web and packages/sandbox drop the @decocms/harness dependency
  entirely: the package is now consumed by apps/api only.
@viktormarinho
viktormarinho force-pushed the refactor/harness-contracts-to-shared branch from c1904b6 to 9ba142e Compare August 3, 2026 01:48
@viktormarinho
viktormarinho enabled auto-merge (squash) August 3, 2026 01:50
@viktormarinho
viktormarinho merged commit 6620a52 into main Aug 3, 2026
24 checks passed
@viktormarinho
viktormarinho deleted the refactor/harness-contracts-to-shared branch August 3, 2026 01:57
decocms Bot pushed a commit that referenced this pull request Aug 3, 2026
PR: #5577 refactor(shared): move the harness wire contracts to @decocms/shared/harness
Bump type: patch

- decocms (apps/api/package.json): 4.160.4 -> 4.160.5
- @decocms/native (apps/native/package.json): 4.160.4 -> 4.160.5
- @decocms/harness (packages/harness/package.json): 2.8.5 -> 2.8.6
- @decocms/sandbox (packages/sandbox/package.json): 1.35.4 -> 1.35.5
- @decocms/shared (packages/shared/package.json): 0.13.3 -> 0.13.4
- deploy/helm/sandbox-env (chart 0.10.4) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.35.5

Deploy-Scope: web
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