Skip to content

Commit 8a2580d

Browse files
thymikeeCopilot
andauthored
refactor(move): extract the daemon-contracts zone into packages/daemon-contracts (#3395)
* refactor(move): extract the daemon-contracts zone into packages/daemon-contracts The ten files of the daemon-contracts zone (the nine root modules declared by ROOT_MODULE_ZONES plus src/daemon-contracts/daemon-diagnostics-scope.ts) move behind a workspace-package boundary with narrow per-file subpath exports. The shared daemon/client placement from #2559 and the #3288 zone declaration become physical: R11 and the package manifest hold the boundary where the per-file rows held it before. Consumers switch from relative specifiers to @agent-device/daemon-contracts/<file>; the tests move with their sources. Behavior is unchanged. * chore(gates): retarget daemon-contracts path-keyed enforcement at the package ROOT_MODULE_ZONES sheds its daemon-contracts rows (the package derives the zone), the R78 guidance names the package as the shared-contract home, the wire-compat manifest/ledger/mutation keys move with request-progress-protocol, the mutation-lane exclusion pins the moved test path, and ADR 0033 records the extraction with its rationale. * test(daemon-contracts): own the daemon-registration fixture and export it as a subpath publishDaemonRegistration was duplicated verbatim between packages/daemon-contracts/src/daemon-registration.fixtures.ts and src/__tests__/test-utils/device-claim-store.ts. Keep the package as the single owner: export the fixture via ./daemon-registration-fixtures the way capture-kit exports ./recording-artifact-fixtures, delete the root copy, and point the six root tests at the subpath. Co-authored-by: Copilot <2235562194+Copilot[bot]@users.noreply.github.com> * docs(layering): name packages/daemon-contracts/ in the root-zone migration note The example repeated src/command-runtime/ after the daemon-contracts zone moved out of src/daemon-contracts/; name the package instead. Co-authored-by: Copilot <2235562194+Copilot[bot]@users.noreply.github.com> * fix(layering): place the two port files R81 found unlayered #3391's manifest was cut before #3403 and #3404 landed, so src/daemon/platform-services.ts (imported by daemon-core files, so core) and src/daemon/device/claim-recovery-gateway.ts (imported only from daemon-server, beside its device-claim siblings in resources) were the only files R81 found unowned. This PR re-ran check:layering after rebasing over them and assigns both. Co-authored-by: Copilot <2235562194+Copilot[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot <2235562194+Copilot[bot]@users.noreply.github.com>
1 parent 907ca42 commit 8a2580d

124 files changed

Lines changed: 363 additions & 215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/adr/0030-process-lock-exclusion.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ require the same confirmation for every process using their own paths.
6565

6666
## Registration operations
6767

68-
[Shared retirement](../../src/daemon-registration-owner.ts) owns verified termination, protected
68+
[Shared retirement](../../packages/daemon-contracts/src/daemon-registration-owner.ts) owns verified termination, protected
6969
metadata inspection and removal, and release. Takeover, failed startup, replay cleanup, timeout
7070
reset and manual stop await its result. Abandoned recovery uses the same protected retirement
7171
sequence without signaling a live process. Daemon publication and shutdown use functions bound

‎docs/adr/0033-collocation-decision-table.md‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,33 +123,36 @@ already owns the operations behind the vocabulary.
123123
### (root)
124124

125125
`#3288` assigns every process-root module a logical zone in
126-
`scripts/layering/root-module-zones.ts` (`daemon-contracts` rank 2, `command-runtime` rank 3,
126+
`scripts/layering/root-module-zones.ts` (`command-runtime` rank 3,
127127
`platform-runtime` rank 4, …) while leaving the files physically in place. Per the maintainer
128128
design decision, that reclassification is **not** completed collocation: the physical moves under
129129
#3294 (child of #3276) replace each file's row with folder-derived ownership.
130-
`daemon-diagnostics-scope.ts` has moved into `src/daemon-contracts/`; the runtime assembly pair
131-
`runtime-command-surface.ts` / `runtime-factory.ts` has moved into `src/command-runtime/`.
132-
The other rows below are keeps: the
133-
daemon ⇄ client shared files (`daemon-policy-file.ts`, `provider-credential-fingerprint.ts`,
134-
`request-progress-protocol.ts`) trace to #2559, which relocated the shared contracts **to the
135-
process root** so the client stops importing `src/daemon/` at all; R78 keeps any client→daemon
130+
The runtime assembly pair
131+
`runtime-command-surface.ts` / `runtime-factory.ts` has moved into `src/command-runtime/`, and
132+
the whole `daemon-contracts` zone has moved into `packages/daemon-contracts` — the folder and
133+
package derive the zone, so every moved file's `ROOT_MODULE_ZONES` row is gone.
134+
The daemon ⇄ client shared files that remain here (`provider-credential-fingerprint.ts`) trace
135+
to #2559, which relocated the shared contracts **to the process root** so the client stops
136+
importing `src/daemon/` at all; R78 keeps any client→daemon
136137
edge at zero runtime and a five-line recorded type-only residue, and #3288's `daemon-contracts`
137-
zone is the declaration of that shared-below-both ownership. Rows on path-keyed evidence alone
138-
(the `platform-runtime-*` seams) say "retain for this batch": a guard's current path lists
139-
constrain a relocation, they are not independent proof the placement is optimal.
138+
zone was the declaration of that shared-below-both ownership — the extraction makes it
139+
physical, with R11 and the package's dependency edges holding the same boundary. Rows on
140+
path-keyed evidence alone (the `platform-runtime-*` seams) say "retain for this batch": a guard's
141+
current path lists constrain a relocation, they are not independent proof the placement is
142+
optimal.
140143

141144
| File | Decision | Reason |
142145
| --- | --- | --- |
143-
| `src/daemon-diagnostics-scope.ts` | moved → `src/daemon-contracts/daemon-diagnostics-scope.ts` ([#3297](https://github.com/callstack/agent-device/pull/3297)) | Physical move landed: the helper now lives under the folder that derives its `daemon-contracts` zone, so `topFolder` replaces the per-file `ROOT_MODULE_ZONES` row and an internal rename needs no ownership-table edit. |
144-
| `src/daemon-policy-file.ts` | keep | Daemon ⇄ client shared contract from #2559, declared `daemon-contracts` by #3288 — the shared-below-both ownership the spine needs, since daemon-client (rank 5) dynamically imports it. |
146+
| `src/daemon-diagnostics-scope.ts` | moved → `packages/daemon-contracts/src/daemon-diagnostics-scope.ts` ([#3297](https://github.com/callstack/agent-device/pull/3297) into `src/daemon-contracts/`, then the package extraction) | The whole `daemon-contracts` zone now lives as `packages/daemon-contracts`, so the package directory derives the zone and the per-file `ROOT_MODULE_ZONES` row stays deleted; an internal rename needs no ownership-table edit. |
147+
| `src/daemon-policy-file.ts` | moved → `packages/daemon-contracts/src/daemon-policy-file.ts` | Daemon ⇄ client shared contract from #2559, declared `daemon-contracts` by #3288 — the shared-below-both ownership the spine needs, since daemon-client (rank 5) dynamically imports it. The extraction makes that placement physical: the package sits below both sides and its manifest exports own the boundary. |
145148
| `src/daemon.ts` | keep | Entry point (`internal/daemon` bundle entry); composition roots stay in root by umbrella §4. |
146149
| `src/platform-runtime-apple-runner-owner.ts` | retain for this batch | `platform-runtime-*` composition seam: R13's exact-importer rule and the ADR 0022 R76 inventory key on its path, so relocation requires coordinated ownership changes to both declarations — the rules constrain the move, they do not independently prove the placement. |
147150
| `src/platform-runtime-daemon-lifecycle.ts` | retain for this batch | Same path-keyed R13/ADR 0022 seam: relocation is possible only with coordinated changes to those declarations. |
148151
| `src/platform-runtime-device-boot.ts` | retain for this batch | Same path-keyed R13/ADR 0022 seam. |
149152
| `src/platform-runtime-resource-cleanup.ts` | retain for this batch | Same path-keyed R13/ADR 0022 seam. |
150153
| `src/provider-credential-fingerprint.ts` | keep | Daemon ⇄ client shared contract from the same #2559 decision as `daemon-policy-file.ts`; #3288 declares its zone beside the provider composition that reads the credentials it fingerprints. |
151154
| `src/provider-limrun-runtime.ts` | keep | Proposed → provider-limrun, but there is no seam: the class's constructor self-builds the root dependency factory (`src/sdk/limrun-runtime-dependencies.ts`), which is the ADR 0019 composition seam — it loads the root's adb-host binder, core Android interactor, and platform-runtime app-state helpers that the package must not import. Moving the class means moving that composition, which is design, not a move. |
152-
| `src/request-progress-protocol.ts` | keep | Daemon ⇄ client shared contract from the same #2559 decision — the client reads it statically (`daemon-client-progress.ts`) and the server through `src/daemon/server/`, so only #2559's shared-placement boundary and the wire-compat ledgers pin it; declared `daemon-contracts` by #3288. Contracts was considered and R18 keeps contracts free of envelope validation mechanics. |
155+
| `src/request-progress-protocol.ts` | moved → `packages/daemon-contracts/src/request-progress-protocol.ts` | Daemon ⇄ client shared contract from the same #2559 decision — the client reads it statically (`daemon-client-progress.ts`) and the server through `src/daemon/server/`, so only #2559's shared-placement boundary and the wire-compat ledgers pin it; declared `daemon-contracts` by #3288 and now physically placed by the extraction. Contracts was considered and R18 keeps contracts free of envelope validation mechanics. The wire-ledger keys moved with the file. |
153156
| `src/runtime-command-surface.ts` | moved → `src/command-runtime/runtime-command-surface.ts` ([#3299](https://github.com/callstack/agent-device/pull/3299)) | Physical move landed with `runtime-factory.ts` as one assembly group: the command-surface binding sits beside the factory it composes, under the folder that derives its `command-runtime` zone, so `topFolder` replaces the per-file `ROOT_MODULE_ZONES` row. |
154157
| `src/runtime-factory.ts` | moved → `src/command-runtime/runtime-factory.ts` ([#3299](https://github.com/callstack/agent-device/pull/3299)) | Physical move landed: the runtime assembly now lives under the folder that derives its `command-runtime` zone, with the same row deletion through folder-derived ownership. |
155158

@@ -173,12 +176,17 @@ files have no seam (published facade, public-type collision, root dependency fac
173176
## Follow-ups (tracked on #3281)
174177

175178
- Physical root-pass moves under [#3294](https://github.com/callstack/agent-device/issues/3294)
176-
(child of #3276): `daemon-diagnostics-scope.ts` has moved into `src/daemon-contracts/`
177-
([#3297](https://github.com/callstack/agent-device/pull/3297)); the runtime assembly pair
179+
(child of #3276): the runtime assembly pair
178180
`runtime-command-surface.ts` / `runtime-factory.ts` is collocated in `src/command-runtime/`
179181
([#3299](https://github.com/callstack/agent-device/pull/3299)). Each folder derives its zone,
180182
replacing the moved files' `ROOT_MODULE_ZONES` rows; #3288's zone assignments alone were
181-
classification, and each landed move completes its own file's collocation.
183+
classification, and each landed move completes its own file's collocation. The
184+
`daemon-contracts` side landed as a workspace package: the zone's ten files (`daemon-owner-cleanup`,
185+
`daemon-policy-file`, `daemon-process`, `daemon-registration-owner`, `daemon-registration`,
186+
`daemon-resolution`, `daemon-shutdown-report`, `request-progress-protocol`,
187+
`session-repair-tombstone`, and `daemon-diagnostics-scope` from `src/daemon-contracts/`, first
188+
moved there by [#3297](https://github.com/callstack/agent-device/pull/3297)) are now
189+
`packages/daemon-contracts/src/` behind narrow per-file subpath exports.
182190

183191
## Refuted alternatives
184192

‎examples/sdk/tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
{ "path": "../../packages/capture-kit" },
4040
{ "path": "../../packages/command-registry" },
4141
{ "path": "../../packages/contracts" },
42+
{ "path": "../../packages/daemon-contracts" },
4243
{ "path": "../../packages/device-selection" },
4344
{ "path": "../../packages/host-kit" },
4445
{ "path": "../../packages/kernel" },

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@
293293
"@agent-device/capture-kit": "workspace:*",
294294
"@agent-device/command-registry": "workspace:*",
295295
"@agent-device/contracts": "workspace:*",
296+
"@agent-device/daemon-contracts": "workspace:*",
296297
"@agent-device/device-selection": "workspace:*",
297298
"@agent-device/host-kit": "workspace:*",
298299
"@agent-device/kernel": "workspace:*",

‎packages/contracts/src/request-progress.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Progress events the daemon streams to a connected client while a request runs.
33
*
4-
* These are wire values: `src/request-progress-protocol.ts` serializes them onto the
4+
* These are wire values: `packages/daemon-contracts/src/request-progress-protocol.ts` serializes them onto the
55
* response stream and the CLI reconstructs them before handing them to the replay-test
66
* reporter registry. They therefore belong to neither side — the daemon's request-global
77
* progress plumbing carries them, and the replay-test scheduler produces and interprets
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "@agent-device/daemon-contracts",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"description": "On-disk and wire contracts a daemon process shares with its clients (#2559): state-dir and transport resolution, registration and ownership, process liveness, shutdown reports, the repair tombstone, progress-envelope framing, the diagnostics scope, and owner-cleanup vocabulary. Internal workspace package bundled into the published agent-device artifact.",
7+
"dependencies": {
8+
"@agent-device/command-registry": "workspace:*",
9+
"@agent-device/contracts": "workspace:*",
10+
"@agent-device/host-kit": "workspace:*",
11+
"@agent-device/kernel": "workspace:*"
12+
},
13+
"exports": {
14+
"./daemon-diagnostics-scope": {
15+
"types": "./src/daemon-diagnostics-scope.ts",
16+
"default": "./src/daemon-diagnostics-scope.ts"
17+
},
18+
"./daemon-owner-cleanup": {
19+
"types": "./src/daemon-owner-cleanup.ts",
20+
"default": "./src/daemon-owner-cleanup.ts"
21+
},
22+
"./daemon-policy-file": {
23+
"types": "./src/daemon-policy-file.ts",
24+
"default": "./src/daemon-policy-file.ts"
25+
},
26+
"./daemon-process": {
27+
"types": "./src/daemon-process.ts",
28+
"default": "./src/daemon-process.ts"
29+
},
30+
"./daemon-registration": {
31+
"types": "./src/daemon-registration.ts",
32+
"default": "./src/daemon-registration.ts"
33+
},
34+
"./daemon-registration-fixtures": {
35+
"types": "./src/daemon-registration.fixtures.ts",
36+
"default": "./src/daemon-registration.fixtures.ts"
37+
},
38+
"./daemon-registration-owner": {
39+
"types": "./src/daemon-registration-owner.ts",
40+
"default": "./src/daemon-registration-owner.ts"
41+
},
42+
"./daemon-resolution": {
43+
"types": "./src/daemon-resolution.ts",
44+
"default": "./src/daemon-resolution.ts"
45+
},
46+
"./daemon-shutdown-report": {
47+
"types": "./src/daemon-shutdown-report.ts",
48+
"default": "./src/daemon-shutdown-report.ts"
49+
},
50+
"./request-progress-protocol": {
51+
"types": "./src/request-progress-protocol.ts",
52+
"default": "./src/request-progress-protocol.ts"
53+
},
54+
"./session-repair-tombstone": {
55+
"types": "./src/session-repair-tombstone.ts",
56+
"default": "./src/session-repair-tombstone.ts"
57+
}
58+
}
59+
}

src/daemon-contracts/daemon-diagnostics-scope.test.ts renamed to packages/daemon-contracts/src/daemon-diagnostics-scope.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'node:path';
44
import { afterEach, beforeEach, test } from 'vitest';
55
import { emitDiagnostic } from '@agent-device/host-kit/diagnostics';
66
import { withDaemonDiagnosticsScope } from './daemon-diagnostics-scope.ts';
7-
import { mkdtempForTestSync } from '../__tests__/test-utils/tmp-dir.ts';
7+
import { mkdtempForTestSync } from './tmp-dir.fixtures.ts';
88

99
let dir: string;
1010
let logPath: string;
File renamed without changes.

src/daemon-owner-cleanup.ts renamed to packages/daemon-contracts/src/daemon-owner-cleanup.ts

File renamed without changes.

src/__tests__/daemon-policy-file.test.ts renamed to packages/daemon-contracts/src/daemon-policy-file.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import path from 'node:path';
44
import { expect, test } from 'vitest';
55
import { commandDescriptors } from '@agent-device/command-registry/registry';
66
import type { CommandDescriptor } from '@agent-device/command-registry/types';
7-
import { mkdtempForTestSync } from './test-utils/tmp-dir.ts';
8-
import { DAEMON_POLICY_ENV, loadDaemonPolicy, parseDaemonPolicy } from '../daemon-policy-file.ts';
7+
import { mkdtempForTestSync } from './tmp-dir.fixtures.ts';
8+
import { DAEMON_POLICY_ENV, loadDaemonPolicy, parseDaemonPolicy } from './daemon-policy-file.ts';
99

1010
const SOURCE = '/etc/agent-device/policy.json';
1111

0 commit comments

Comments
 (0)