Skip to content

Commit e0e093c

Browse files
committed
chore(gates): forbid the daemon importing the CLI schema layer
Declare the command-defaults export subpath and make the daemon↔cli-schema decoupling structural so it cannot reopen: - R10 (scripts/layering/daemon-modularity) now rejects any daemon import of src/cli-schema/, value or type. Before, two value edges reached command-schema.ts; with them gone, a total boundary is available, and an explicit rule beats a rank that would let the next daemon module reach the layer again. - command-defaults-parity.test.ts ties the CLI facet default to the daemon's command-defaults table across every command, so the two budget-forced declarations stay one fact. Closes #2543.
1 parent 71e332f commit e0e093c

4 files changed

Lines changed: 90 additions & 0 deletions

File tree

‎packages/command-registry/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"types": "./src/catalog.ts",
2424
"default": "./src/catalog.ts"
2525
},
26+
"./command-defaults": {
27+
"types": "./src/command-defaults.ts",
28+
"default": "./src/command-defaults.ts"
29+
},
2630
"./types": {
2731
"types": "./src/types.ts",
2832
"default": "./src/types.ts"

‎scripts/layering/daemon-modularity.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,38 @@ test('R10 banks an R7 shrink with no edit anywhere', () => {
106106
);
107107
});
108108

109+
test('R10 forbids the daemon importing the CLI schema layer, value or type', () => {
110+
const valueEdge: ResolvedImportEdge = {
111+
...importEdge('src/daemon/request-execution-scope.ts', 'src/cli-schema/command-schema.ts'),
112+
typeOnly: false,
113+
};
114+
const typeEdge = importEdge(
115+
'src/daemon/session-action-recorder.ts',
116+
'src/cli-schema/command-schema.ts',
117+
);
118+
const violations = checkDaemonModularityRatchets(
119+
[...baselineEdges(), valueEdge, typeEdge],
120+
REFERENCE,
121+
REFERENCE,
122+
);
123+
assert.deepEqual(
124+
violations.map(({ rule, file }) => ({ rule, file })),
125+
[
126+
{ rule: 'R10 daemon-modularity', file: 'src/daemon/request-execution-scope.ts' },
127+
{ rule: 'R10 daemon-modularity', file: 'src/daemon/session-action-recorder.ts' },
128+
],
129+
);
130+
assert.match(violations[0]!.message, /must not import src\/cli-schema\/command-schema\.ts/);
131+
});
132+
133+
test('R10 permits a non-daemon importer of the CLI schema layer', () => {
134+
const cliEdge = importEdge('src/cli/parser/args.ts', 'src/cli-schema/command-schema.ts');
135+
assert.deepEqual(
136+
checkDaemonModularityRatchets([...baselineEdges(), cliEdge], REFERENCE, REFERENCE),
137+
[],
138+
);
139+
});
140+
109141
test('external daemon request/session-state importer membership changes require the baseline to change', () => {
110142
const edges = resolveImportEdges(
111143
new Map([

‎scripts/layering/daemon-modularity.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,35 @@ export function checkDaemonModularityRatchets(
7272
...checkSessionStateBaseline(measured.sessionState, reference.sessionState),
7373
...checkTypeCycleBaseline(measured.largestTypeCycle, reference.largestTypeCycle),
7474
...checkDaemonTypesImporters(edges),
75+
...checkDaemonCliSchemaBoundary(edges),
7576
...checkLogicalModuleImports(edges),
7677
];
7778
}
7879

80+
// The daemon resolves command routes through the registry and fills request defaults through the
81+
// command registry, so it never needs the CLI schema layer. #2543 cut the last two value edges
82+
// (`request-execution-scope.ts` and `session-action-recorder.ts`); this pins that decoupling so a
83+
// future daemon module cannot reach `src/cli-schema/` again and re-pull the parser closure.
84+
const DAEMON_FORBIDDEN_CLI_SCHEMA_ROOT = 'src/cli-schema/';
85+
86+
function checkDaemonCliSchemaBoundary(edges: readonly ResolvedImportEdge[]): LayeringViolation[] {
87+
return edges
88+
.filter(
89+
(edge) =>
90+
edge.file.startsWith('src/daemon/') &&
91+
matchesDeclaredRoot(edge.target, DAEMON_FORBIDDEN_CLI_SCHEMA_ROOT),
92+
)
93+
.map((edge) => ({
94+
rule: 'R10 daemon-modularity',
95+
file: edge.file,
96+
line: edge.line,
97+
message:
98+
`${edge.file} must not import ${edge.target}: the daemon resolves routes through ` +
99+
'@agent-device/command-registry and must not load the CLI schema layer. Declare the shared ' +
100+
'shape in the command registry or contracts, not in src/cli-schema/.',
101+
}));
102+
}
103+
79104
export function checkRetiredSessionLifecyclePaths(
80105
sourceFiles: readonly string[],
81106
): LayeringViolation[] {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { test } from 'vitest';
2+
import assert from 'node:assert/strict';
3+
import { applyCommandDefaults, getCommandSchema } from './command-schema.ts';
4+
import { applyCommandDefaults as applyRegistryDefaults } from '@agent-device/command-registry/command-defaults';
5+
import { listCommandMetadata } from '../commands/command-metadata.ts';
6+
7+
// The CLI parser and the daemon each hold a copy of the apps filter default, because the eager
8+
// closure budget forbids pulling `command-defaults` into `cli.ts` and the daemon-modularity gate
9+
// forbids pulling `cli-schema` into the daemon. This guard makes the two declarations one fact:
10+
// whatever the facet applies, the daemon's table must apply identically for every command.
11+
test('the daemon default table matches every CLI facet default', () => {
12+
for (const { name } of listCommandMetadata()) {
13+
const viaCli: Record<string, unknown> = {};
14+
const viaDaemon: Record<string, unknown> = {};
15+
applyCommandDefaults(name, viaCli);
16+
applyRegistryDefaults(name, viaDaemon);
17+
assert.deepEqual(viaDaemon, viaCli, `defaults for "${name}" diverged from the facet`);
18+
}
19+
});
20+
21+
test('the apps facet and the daemon table both yield the shared apps filter default', () => {
22+
const facet = getCommandSchema('apps');
23+
const viaCli: Record<string, unknown> = {};
24+
const viaDaemon: Record<string, unknown> = {};
25+
applyCommandDefaults('apps', viaCli);
26+
applyRegistryDefaults('apps', viaDaemon);
27+
assert.deepEqual(viaCli, facet?.defaults);
28+
assert.equal(viaDaemon.appsFilter, viaCli.appsFilter);
29+
});

0 commit comments

Comments
 (0)