refactor(move): extract the daemon server into @agent-device/daemon (11b)

Merged
TH
2mo ago
+4026-2435

What this is

PR 11b of the daemon-extraction plan: an atomic move of src/daemon/ into packages/daemon/src/ as the new workspace package @agent-device/daemon, with every mechanical path rewrite, the rule/config/doc retargets the move requires, and the export façade the #3546 review asked to settle in this PR. Re-run from a hard reset on 11a-4 (refactor/daemon-runtime-fakes @ 980c484d7 — the re-synced #3544 head, tree-identical to its pre-resync push; the stack sits on current main via #3519 @ df0af2a13 and #3517 @ e615de39d); base retargeted accordingly. Main's daemon-side changes (#3536's /rpc backstop test + server changes, #3547's minted-per-producer ref, #3549's vitest 5 syntax, and the rest) are base content the move absorbs: the codemod moved 669 files, 763 inbound import sites.

Commit topology

CommitFilesHand-written?
refactor(move) — pure codemod: 669 files git mv'd, 763 inbound import sites rewritten (16 named production/script subpaths + one ./testing/* pattern entry decided by the importing file's path), generated manifest + composite tsconfig, root/examples project references, and the exists-at-head path-literal sweep over code/docs/ADRs961No — reproducible with one script on a clean tree
refactor(gates) — R11 vi.mock sweep, ratchet + wire-compat rename canonicalization, rule fixture re-anchoring (synthetic coordinates), config retargets (stryker, di-seams, .fallowrc, baselines), new URL re-anchors, seam fixes (dead root vi.mock tunnels dropped — 11a-4 fakes those ports; device-inventory test moved onto the production withAppleToolProvider scope; ownership-scan roots extended over packages/daemon/src); deletes scripts/daemon-edge-residue-scan.mjs — run once before deletion (0 edges), R11 owns that invariant now49Yes
refactor(daemon) — the façade: two internal/* suites split into the package, R11 refuses ./testing/* for non-test importers (unit-tested + bite-proved), DAEMON_SOURCE_ROOT adopted by all filter sites, docs/agents trim24Yes
docs(adr) — façade policy amendment to ADR 00331Yes
chore(gates) — renamedSince head-ref + renameLimit, wire-compat uses it, fixture-repo rename test3Yes
chore(gates) — format re-flow42No
test(gates) — fixture-repo git identity + commit.gpgsign in its own config (CI fix)1Yes
fix(test) — daemon-stop test mocks the SUT's exact @agent-device/daemon/daemon-stop specifier (mutation-lane resolution)1Yes
refactor(daemon) — façade narrowed per the second review: the 82 production modules root tests reached through the wildcard become named subpaths (one spelling each); fixtures keep ./testing/ spelling as 25 named entries + four per-folder ./testing/<dir>/* patterns exposing only __tests__ folders; 150 files re-spelled151Yes (codemod-assisted)
fix(gates) — resolveWorkspaceSpecifier owns exports-pattern expansion once for the layering edges, depgraph, mutation ownership, and the Stryker alias table (capture-group aliases, exact-first ordering); R11's test-data refusal keys on the ./testing/ namespace, not a pattern entry; ADR 0033 amendment updated6Yes
fix(gates) — pattern alias splices at its known * index (CodeQL String#replace first-occurrence finding)2Yes
refactor(daemon) — test-only reach no longer defines production surface: the 72 named entries whose only consumers (import + vi.mock sweep) are tests move to named ./testing/<module> entries, 133 files re-spelled; 16 production subpaths remain133Yes (codemod-assisted)
refactor(gates) — namedByExports delegates to resolveWorkspaceSpecifier; the alias table orders its Vite first-match list to Node precedence (exact, then patterns by prefix length desc) with a cross-semantics test over every export key (the ADR/amendment hunks of this commit are already base content after the rebase, so it lands as 1 file)1Yes
test(gates) — the named-entry seam proves the specifier resolves (owner note 1): restores the fixture's @agent-device/daemon/session-store spelling and asserts [] in compiled and uncompiled mode, so an unexported spelling can no longer pass vacuously; bite-proved1Yes
test(gates) — proves the alias table orders overlapping patterns longest-first (owner note 2): a sandbox manifest declares ./testing/* before ./testing/handlers/* with targets that fill to different trees; deleting patterns.sort fails exactly this case; bite-proved1Yes

Acceptance evidence (head a4c6208c2 on base 980c484d7 — every item re-run on this lineage)

  • Typecheck: pnpm typecheck → 0 errors.
  • check:layering: green — 319 rule tests pass; guard summary reports R11 holds 28 packages behind 543 exported subpaths with zero undeclared or relative-tunnel routes — EMPTY residue. (The residue scan measured 0 daemon→root edges on the move commit before its supersession by R11.)
  • depgraph: pnpm depgraph + edge scan → 0 edges from packages/daemon/src into root src/.
  • Bite proofs (planted into a production root file, restored after each): value import, dynamic import, vi.mock, and type-only import through @agent-device/daemon/testing/* each fire R11; a relative tunnel into packages/daemon/src fires; a named production subpath does not fire. The ./testing/ refusal is additionally pinned by scripts/layering/package-boundaries-facade.test.ts (4 tests).
  • Test-name parity (vitest json reporter, per-file full titles; base captured from a worktree at 11a-4 @ 980c484d7): unit-core 13,622 → 13,799, fuzz-worker 11 → 11. Every delta is accounted for: the façade split relocates 13 titles between two file pairs with byte-identical names (touch-response 10, session-open-surface 3); daemon-registration-owner.test.ts swaps 6-for-6 parametrized titles embedding pid/Date.now() stamps; eager-closure-budgets.test.ts grows 854 → 1,031 rows — the suite's test.for entry-surface expansion over the new shape (the daemon package's export subpaths are newly discovered entry surfaces; the session-teardown parameter retargeted to the moved file) — plus the new rename-detection fixture test from this branch's own gates commit. After folding those, every remaining test name occurs exactly the same number of times on both sides — no test lost, gained, or silently relocated.
  • Bundle equivalence: tsdown --sourcemap built on base and head; folding packages/daemon/src/ back onto src/daemon/: daemon-entry closure 124 modules = 124 modules, identical set; whole-build first-party source multiset 1,574 = 1,574 instances, identical.
  • Wire: check:daemon-wire-compat → 191 declarations, 0 changed, 0 removed, 0 added, 0 moved against v0.21.27.
  • pnpm check:package: the publishable package is sound. pnpm check:fallow: clean. check:affected --run: exit 0 — blast-radius analysis over the full diff. gate mutation --modules kernel-errors --shard 1/5: lane passes (94.74%, 72/76 killed, 0 harness errors; envelope pass recorded at pre-parent-swap SHA bf8a98610615, whose tree hash is byte-identical to this head, scope 1,277/1,277 files; scores advisory per #1457). workspace-aliases.test.ts + config.test.ts: 11/11 pass incl. the cross-semantics alias test over every export key and the two new bite-proved seams. lint + gate-manifest: clean (57 checks / 27 lanes).
  • docs/agents: 39,948 / 40,000 bytes (headroom kept for PR 10; cap untouched).
  • Unified test-consumer rule (isTestConsumerFile, latest lineage): spelling the rule once intentionally widens the test-consumer set at the TEST_ONLY_FIXTURE_SUBPATHS gate — a root __tests__/ file and *.test.tsx/*.test.mts/*.test.js now count as test consumers there too (the two superseded inline copies disagreed); pinned by the accept/deny table in package-boundaries-facade.test.ts.

The façade (settled here, per review)

  • Exports: 16 named production/script subpaths (the importer sweep names exactly these, zero test-only entries) + 97 named ./testing/ entries + 4 per-folder fixture patterns. Every module has exactly one spelling; nothing is reachable two ways.
  • ./testing/ is the whole test-only surface: fixture files (./testing/__tests__/<fixture>), fixture-folder patterns (target templates reconstruct __tests__ folders only), and production modules root tests drive (./testing/<module>). R11 refuses the namespace for any non-test importer — files, package-internal sites, and vi.mock/doMock/importActual — so root production code cannot import daemon internals (./interaction/internal/types et al.) at all.
  • One resolution semantics: resolveWorkspaceSpecifier (scripts/layering/model.ts) implements Node's exports rules (exact first, longest prefix, suffix fills the target *) and owns the layering edges, depgraph, mutation ownership, and R11's named-surface check; the Stryker alias table orders its Vite first-match list to that precedence, and a test asserts the alias hit equals the resolver's target for every export key of every workspace package — a pattern-exported module names the same module id in every lane.