Skip to content

Commit 1b92b01

Browse files
committed
refactor(daemon): move session observability behind facade
1 parent af2c65d commit 1b92b01

37 files changed

Lines changed: 386 additions & 185 deletions

‎fallow-baselines/health.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
"count": 1
172172
}
173173
},
174-
"src/daemon/handlers/__tests__/session-appstate-input-perf.test.ts": {
174+
"src/daemon/handlers/__tests__/session-appstate-input.test.ts": {
175175
"crap_high": {
176176
"count": 3
177177
},
@@ -189,7 +189,7 @@
189189
"count": 1
190190
}
191191
},
192-
"src/daemon/handlers/__tests__/session-logs.test.ts": {
192+
"src/daemon/session-observability/internal/__tests__/session-logs.test.ts": {
193193
"crap_moderate": {
194194
"count": 1
195195
}
@@ -230,7 +230,7 @@
230230
"count": 1
231231
}
232232
},
233-
"src/daemon/handlers/session-observability.ts": {
233+
"src/daemon/session-observability/internal/session-observability.ts": {
234234
"crap_moderate": {
235235
"count": 2
236236
}

‎scripts/layering/architecture-ownership.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ARCHITECTURE_OWNERSHIP,
77
matchesDeclaredRoot,
88
SESSION_LIFECYCLE_RETIRED_HANDLER_PATHS,
9+
SESSION_OBSERVABILITY_RETIRED_HANDLER_PATHS,
910
} from './architecture-ownership.ts';
1011
import { readNamedExports } from './facade-exports.ts';
1112
import { resolveImportEdges } from './model.ts';
@@ -66,6 +67,13 @@ test('session lifecycle retires its handler-owned helper paths', () => {
6667
}
6768
});
6869

70+
test('session observability retires its handler-owned paths', () => {
71+
const tracked = new Set(listTrackedTypeScriptFiles(repoRoot));
72+
for (const retiredPath of SESSION_OBSERVABILITY_RETIRED_HANDLER_PATHS) {
73+
assert.equal(tracked.has(retiredPath), false, `retired path was restored: ${retiredPath}`);
74+
}
75+
});
76+
6977
test('vocabulary roots are exported contract facades', () => {
7078
const manifest = JSON.parse(
7179
fs.readFileSync(path.join(repoRoot, 'packages/contracts/package.json'), 'utf8'),

‎scripts/layering/architecture-ownership.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const DAEMON_SESSION_LIFECYCLE_FACADE = {
2828
],
2929
} as const;
3030

31+
const DAEMON_SESSION_OBSERVABILITY_FACADE = {
32+
root: 'src/daemon/session-observability/index.ts',
33+
exports: ['SessionObservabilityCommandInput', 'handleSessionObservabilityCommands'],
34+
} as const;
35+
3136
export const SESSION_LIFECYCLE_RETIRED_HANDLER_PATHS = [
3237
'src/daemon/handlers/session-device-utils.ts',
3338
'src/daemon/handlers/session-runtime-admission.ts',
@@ -60,6 +65,13 @@ const DAEMON_INTERACTION_FACADE = {
6065
],
6166
} as const;
6267

68+
export const SESSION_OBSERVABILITY_RETIRED_HANDLER_PATHS = [
69+
'src/daemon/handlers/session-observability.ts',
70+
'src/daemon/handlers/session-perf-runtime.ts',
71+
'src/daemon/handlers/session-network.ts',
72+
'src/daemon/handlers/session-audio.ts',
73+
] as const;
74+
6375
export const LOGICAL_MODULE_POLICIES = [
6476
{
6577
name: 'ad-replay',
@@ -106,6 +118,12 @@ export const LOGICAL_MODULE_POLICIES = [
106118
internalForbiddenTargetRoots: ['src/daemon/handlers/'],
107119
facade: DAEMON_INTERACTION_FACADE,
108120
},
121+
{
122+
name: 'daemon-session-observability',
123+
roots: ['src/daemon/session-observability/'],
124+
forbiddenTargetRoots: ['src/daemon/handlers/'],
125+
facade: DAEMON_SESSION_OBSERVABILITY_FACADE,
126+
},
109127
] as const satisfies readonly LogicalModulePolicy[];
110128

111129
export const ARCHITECTURE_OWNERSHIP = {

‎scripts/layering/check.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
import {
7878
checkDaemonModularityRatchets,
7979
checkRetiredSessionLifecyclePaths,
80+
checkRetiredSessionObservabilityPaths,
8081
daemonModularitySummary,
8182
} from './daemon-modularity.ts';
8283
import {
@@ -585,6 +586,7 @@ export const LAYERING_RULES: Readonly<Record<LayeringRuleId, LayeringRule>> = {
585586
'daemon-modularity-ratchets': (context) => [
586587
...checkDaemonModularityRatchets(context.edges, context.typeCycleMembers),
587588
...checkRetiredSessionLifecyclePaths(context.sourceFiles),
589+
...checkRetiredSessionObservabilityPaths(context.sourceFiles),
588590
],
589591
'daemon-platform-boundary': (context) =>
590592
checkDaemonPlatformBoundary([...context.sources].map(([path, source]) => ({ path, source }))),

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { test } from 'node:test';
33
import {
44
checkDaemonModularityRatchets,
55
checkRetiredSessionLifecyclePaths,
6+
checkRetiredSessionObservabilityPaths,
67
DAEMON_MODULARITY_BASELINE,
78
TYPE_CYCLE_BASELINE,
89
} from './daemon-modularity.ts';
@@ -370,6 +371,50 @@ test('interaction rejects handler crossings and deep imports around its facade',
370371
);
371372
});
372373

374+
test('session observability rejects handler deep imports in both directions', () => {
375+
const edges = resolveImportEdges(
376+
new Map([
377+
[
378+
'src/daemon/handlers/session.ts',
379+
"import { handleSessionObservabilityCommands } from '../session-observability/internal/session-observability.ts';\nexport function handleSessionCommands() {}",
380+
],
381+
[
382+
'src/daemon/session-observability/internal/session-observability.ts',
383+
"import { handleSessionCommands } from '../../handlers/session.ts';\nexport function handleSessionObservabilityCommands() {}",
384+
],
385+
[
386+
'src/daemon/session-observability/index.ts',
387+
'export function handleSessionObservabilityCommands() {}',
388+
],
389+
]),
390+
);
391+
392+
const violations = checkDaemonModularityRatchets(
393+
[...baselineEdges(), ...edges],
394+
baselineTypeCycleMembers(),
395+
);
396+
assert.deepEqual(
397+
violations.map(({ file, line, message }) => ({
398+
file,
399+
line,
400+
message: message.replace(/;.*/, ''),
401+
})),
402+
[
403+
{
404+
file: 'src/daemon/handlers/session.ts',
405+
line: 1,
406+
message:
407+
"src/daemon/handlers/session.ts must not import daemon-session-observability's internal tree (src/daemon/session-observability/internal/session-observability.ts)",
408+
},
409+
{
410+
file: 'src/daemon/session-observability/internal/session-observability.ts',
411+
line: 1,
412+
message: 'daemon-session-observability must not import src/daemon/handlers/session.ts',
413+
},
414+
],
415+
);
416+
});
417+
373418
test('session lifecycle rejects restored neutral helper paths', () => {
374419
const violations = checkRetiredSessionLifecyclePaths([
375420
'src/daemon/session-device-resolution.ts',
@@ -422,6 +467,30 @@ test('session lifecycle rejects any restored open or close handler path', () =>
422467
);
423468
});
424469

470+
test('session observability rejects restored handler paths', () => {
471+
const restoredPaths = [
472+
'src/daemon/handlers/session-observability.ts',
473+
'src/daemon/handlers/session-perf-runtime.ts',
474+
'src/daemon/handlers/session-network.ts',
475+
'src/daemon/handlers/session-audio.ts',
476+
'src/daemon/handlers/session-network-regressed.ts',
477+
'src/daemon/handlers/session-perf.ts',
478+
'src/daemon/handlers/session-logs.ts',
479+
'src/daemon/handlers/session-events.ts',
480+
] as const;
481+
const violations = checkRetiredSessionObservabilityPaths(restoredPaths);
482+
483+
assert.deepEqual(
484+
violations.map(({ file, message }) => ({ file, message })),
485+
restoredPaths.map((file) => ({
486+
file,
487+
message:
488+
`retired session observability path was restored: ${file}. ` +
489+
'Keep the neutral seam at its daemon owner instead of rebuilding a handler grab-bag.',
490+
})),
491+
);
492+
});
493+
425494
test('R9 records zone ceilings and keeps engine files outside the largest component', () => {
426495
// One commands file and one engine file traded for two provider-webdriver ones, so the
427496
// total stays at the baseline and only the per-zone claims are on trial.

‎scripts/layering/daemon-modularity.ts‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
LOGICAL_MODULE_POLICIES,
44
matchesDeclaredRoot,
55
SESSION_LIFECYCLE_RETIRED_HANDLER_PATHS,
6+
SESSION_OBSERVABILITY_RETIRED_HANDLER_PATHS,
67
type LogicalModulePolicy,
78
} from './architecture-ownership.ts';
89
import { targetDagZone, type LayeringViolation, type ResolvedImportEdge } from './model.ts';
@@ -57,19 +58,41 @@ export function checkDaemonModularityRatchets(
5758
export function checkRetiredSessionLifecyclePaths(
5859
sourceFiles: readonly string[],
5960
): LayeringViolation[] {
60-
const restoredPaths = sourceFiles.filter(
61-
(file) =>
62-
SESSION_LIFECYCLE_RETIRED_HANDLER_PATHS.some((retiredPath) => retiredPath === file) ||
63-
/^src\/daemon\/handlers\/session-(?:open|close)(?:-[^/]+)?\.ts$/.test(file),
61+
return checkRetiredHandlerPaths(
62+
sourceFiles,
63+
SESSION_LIFECYCLE_RETIRED_HANDLER_PATHS,
64+
/^src\/daemon\/handlers\/session-(?:open|close)(?:-[^/]+)?\.ts$/,
65+
'session lifecycle',
6466
);
65-
return restoredPaths.map((file) => ({
66-
rule: 'R10 daemon-modularity',
67-
file,
68-
line: 1,
69-
message:
70-
`retired session lifecycle path was restored: ${file}. ` +
71-
'Keep the neutral seam at its daemon owner instead of rebuilding a handler grab-bag.',
72-
}));
67+
}
68+
69+
export function checkRetiredSessionObservabilityPaths(
70+
sourceFiles: readonly string[],
71+
): LayeringViolation[] {
72+
return checkRetiredHandlerPaths(
73+
sourceFiles,
74+
SESSION_OBSERVABILITY_RETIRED_HANDLER_PATHS,
75+
/^src\/daemon\/handlers\/session-(?:observability|perf|logs|events|network|audio)(?:-[^/]+)?\.ts$/,
76+
'session observability',
77+
);
78+
}
79+
80+
function checkRetiredHandlerPaths(
81+
sourceFiles: readonly string[],
82+
retiredPaths: readonly string[],
83+
pattern: RegExp,
84+
capability: string,
85+
): LayeringViolation[] {
86+
return sourceFiles
87+
.filter((file) => retiredPaths.includes(file) || pattern.test(file))
88+
.map((file) => ({
89+
rule: 'R10 daemon-modularity',
90+
file,
91+
line: 1,
92+
message:
93+
`retired ${capability} path was restored: ${file}. ` +
94+
'Keep the neutral seam at its daemon owner instead of rebuilding a handler grab-bag.',
95+
}));
7396
}
7497

7598
function checkSessionStateBaseline(): LayeringViolation[] {

‎scripts/layering/model.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ test('session-state writes are found by field, and non-daemon or undeclared name
313313
// a runner session outside the daemon is a different type that happens to share a name
314314
['src/platforms/apple/runner-session.ts', 'session.refFrameState = 1;'],
315315
// a local that is not a declared SessionState field
316-
['src/daemon/handlers/session-audio.ts', 'session.somethingElse = 1;'],
316+
['src/daemon/session-observability/internal/session-audio.ts', 'session.somethingElse = 1;'],
317317
// reads and comparisons are not writes
318318
['src/daemon/handlers/find.ts', "if (session.refFrameState === 'active') return;"],
319319
// a write into a sub-object is not a write to the field itself

src/daemon/handlers/__tests__/session-appstate-input-perf.test.ts renamed to src/daemon/handlers/__tests__/session-appstate-input.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -272,25 +272,3 @@ test('clipboard rejects unsupported iOS physical devices', async () => {
272272
expect(response.error.message).toMatch(/clipboard is not supported on this device/i);
273273
}
274274
});
275-
276-
test('perf requires an active session', async () => {
277-
const sessionStore = makeSessionStore();
278-
const response = await handleSessionCommands({
279-
req: {
280-
token: 't',
281-
session: 'default',
282-
command: 'perf',
283-
positionals: [],
284-
flags: {},
285-
},
286-
sessionName: 'default',
287-
logPath: path.join(os.tmpdir(), 'daemon.log'),
288-
sessionStore,
289-
invoke: noopInvoke,
290-
});
291-
expect(response).toBeTruthy();
292-
expect(response?.ok).toBe(false);
293-
if (response && !response.ok) {
294-
expect(response.error.code).toBe('SESSION_NOT_FOUND');
295-
}
296-
});

‎src/daemon/handlers/find.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { contextFromFlags } from '../context.ts';
1515
import { readCommandMessage, successText } from '@agent-device/kernel/success-text';
1616
import { errorResponse, noActiveSessionError } from '../response.ts';
1717
import { withSystemSurfaceDisclosure } from './system-surface-disclosure.ts';
18-
import { recordSessionAction } from './handler-utils.ts';
18+
import { recordSessionAction } from '../session-action-recorder.ts';
1919
import { stripInternalInteractionFlags } from '../interaction-outcome-policy.ts';
2020
import { resolveFindMatch } from './find-match-resolution.ts';
2121
import { executeFocusPoint } from '../focus-runtime.ts';

‎src/daemon/handlers/handler-utils.ts‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)