Repository navigation
Expand file tree
/
Copy pathowner-files.ts
More file actions
103 lines (97 loc) · 4.42 KB
/
Copy pathowner-files.ts
File metadata and controls
103 lines (97 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { DEVICE_OPERATION_COMMAND_DESCRIPTORS } from './descriptors/device-operations.ts';
import { SESSION_OPERATION_COMMAND_DESCRIPTORS } from './descriptors/session-operations.ts';
import { LOCAL_CLI_COMMAND_DESCRIPTORS } from './descriptors/local-cli.ts';
import type { DaemonCommandRoute } from './daemon-command-descriptor.ts';
import { RAW_COMMAND_DESCRIPTORS, type Command } from './registry.ts';
/**
* Development-only owner-file navigation claims for every command (ADR 0008,
* "Completeness guards"; follow-up
* https://github.com/callstack/agent-device/issues/1178).
*
* These paths point a reader at the module that owns each command's surface so
* `explain:command` can render "where does this live". They are pure tooling
* metadata: nothing in the daemon/CLI runtime reads them, so they were removed
* from the production {@link CommandDescriptor} objects (and therefore from the
* emitted bundles) and kept as a derived view on the source-of-truth registry.
*
* The key space is the descriptor-derived {@link Command} union, so deriving the
* projection from {@link RAW_COMMAND_DESCRIPTORS} makes a missing or misspelled
* command a type error and forbids owner claims for commands that do not exist.
* Only `command-explain.ts` and its tests import this module; the production
* import graph never reaches it, so the bundler drops it entirely.
*/
type OwnerFilesFromDescriptors<
T extends readonly {
readonly name: string;
readonly ownerFiles?: readonly [string, ...string[]];
}[],
> = {
[K in keyof T & number as T[K]['name']]: NonNullable<T[K]['ownerFiles']>;
};
const buildOwnerFiles = <
const T extends readonly {
readonly name: string;
readonly ownerFiles?: readonly [string, ...string[]];
}[],
>(
entries: T,
): OwnerFilesFromDescriptors<T> =>
Object.fromEntries(
entries.map((entry) => [entry.name, entry.ownerFiles]),
) as OwnerFilesFromDescriptors<T>;
export const COMMAND_OWNER_FILES = buildOwnerFiles(RAW_COMMAND_DESCRIPTORS) satisfies Record<
Command,
readonly [string, ...string[]]
>;
/** The owner-file claims for one command (development-only navigation metadata). */
export function ownerFilesForCommand(command: Command): readonly [string, ...string[]] {
const families: readonly {
descriptors: readonly { name: string }[];
file: string;
}[] = [
{
descriptors: SESSION_OPERATION_COMMAND_DESCRIPTORS,
file: 'packages/command-registry/src/descriptors/session-operations.ts',
},
{
descriptors: [
...DEVICE_OPERATION_COMMAND_DESCRIPTORS.captureAndSystem,
...DEVICE_OPERATION_COMMAND_DESCRIPTORS.interactionAndHardware,
],
file: 'packages/command-registry/src/descriptors/device-operations.ts',
},
{
descriptors: LOCAL_CLI_COMMAND_DESCRIPTORS,
file: 'packages/command-registry/src/descriptors/local-cli.ts',
},
];
const declaration = families.find(({ descriptors }) =>
descriptors.some(({ name }) => name === command),
);
return declaration
? [declaration.file, ...COMMAND_OWNER_FILES[command]]
: COMMAND_OWNER_FILES[command];
}
/**
* Development-only owner-file navigation claims for each daemon route. The route's runtime
* binding is its lazy loader in the daemon's handler table; this map is tooling metadata only
* `explain:command` reads, so it lives with the command claims above and the bundler drops it.
*
* `satisfies Record<DaemonCommandRoute, string>` keeps the map complete: adding or renaming a
* route is a compile error until this map matches. The daemon's `request-handler-chain` parity
* test asserts each path still points at the module that route's loader imports.
*/
const DAEMON_ROUTE_OWNER_FILES = {
humanControl: 'packages/daemon/src/sessions/handlers/human-control.ts',
lease: 'packages/daemon/src/sessions/handlers/lease.ts',
session: 'packages/daemon/src/sessions/handlers/session.ts',
snapshot: 'packages/daemon/src/sessions/handlers/snapshot.ts',
reactNative: 'packages/daemon/src/execution/handlers/react-native.ts',
recordTrace: 'packages/daemon/src/sessions/handlers/record-trace.ts',
find: 'packages/daemon/src/execution/interaction/index.ts',
interaction: 'packages/daemon/src/execution/interaction/index.ts',
generic: 'packages/daemon/src/execution/request-generic-dispatch.ts',
} as const satisfies Record<DaemonCommandRoute, string>;
export function getDaemonRouteOwnerFiles(): Record<DaemonCommandRoute, string> {
return { ...DAEMON_ROUTE_OWNER_FILES };
}