Skip to content

Commit 0980853

Browse files
committed
refactor(cli): own injected daemon dispatches at a typed construction seam
The syntactic scan recognized only a direct sendToDaemon call whose first argument was an inline object literal, so a variable envelope or a computed callee was omitted from every result. Rather than teach the scanner more shapes, the CLI's injected dispatches now flow through one typed construction point whose route/command pairs are declared, and the gate reads that declaration instead of recovering it from syntax. Part of #1739 (wave 0)
1 parent 4f871a2 commit 0980853

3 files changed

Lines changed: 183 additions & 324 deletions

File tree

‎src/cli.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import type { FlagKey } from './commands/cli-grammar/flag-types.ts';
4646
import type { CliFlags } from '@agent-device/contracts/command';
4747
import type { SessionRuntimeHints } from '@agent-device/kernel/contracts';
4848
import { INTERNAL_COMMANDS, isKnownCliCommandName } from './command-catalog.ts';
49+
import { sendInjectedDaemonRequest } from './cli/injected-daemon-dispatch.ts';
4950

5051
type CliDeps = {
5152
sendToDaemon: typeof sendToDaemon;
@@ -342,9 +343,10 @@ async function runReactDevtoolsCli(ctx: CliRunContext, deps: CliDeps): Promise<n
342343
cwd: process.cwd(),
343344
env: process.env,
344345
configureDirectPortReverse: async () => {
345-
const response = await deps.sendToDaemon(
346-
{
347-
command: INTERNAL_COMMANDS.runtime,
346+
const response = await sendInjectedDaemonRequest({
347+
route: 'react-devtools',
348+
command: INTERNAL_COMMANDS.runtime,
349+
request: {
348350
positionals: ['port-reverse'],
349351
flags: {
350352
...directRequestFlags,
@@ -355,8 +357,9 @@ async function runReactDevtoolsCli(ctx: CliRunContext, deps: CliDeps): Promise<n
355357
},
356358
session: ctx.effectiveFlags.session ?? ctx.sessionName,
357359
},
358-
{ authToken: daemonAuthToken },
359-
);
360+
transport: deps.sendToDaemon,
361+
transportOptions: { authToken: daemonAuthToken },
362+
});
360363
if (!response.ok) throwDaemonError(response.error);
361364
},
362365
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { DaemonResponse, sendToDaemon } from '../daemon/client/daemon-client.ts';
2+
import { INTERNAL_COMMANDS } from '../command-catalog.ts';
3+
import type { DescriptorCliCommandName } from '../core/command-descriptor/registry.ts';
4+
5+
type CliDaemonTransport = typeof sendToDaemon;
6+
type CliDaemonRequest = Parameters<CliDaemonTransport>[0];
7+
type CliDaemonTransportOptions = Parameters<CliDaemonTransport>[1];
8+
9+
/**
10+
* The CLI's injected daemon dispatches (ADR 0019 §6).
11+
*
12+
* Ordinary commands reach the daemon through the client transport, carrying their own
13+
* name. A few CLI routes additionally inject a *different* command into their flow —
14+
* `react-devtools start` on a Limrun Android instance sets up its port reverse by
15+
* dispatching internal `runtime`. That injection is the case where a descriptor's own
16+
* module is platform-free while its route reaches platform behavior, so the pairs must
17+
* be enumerable to keep the migration denominator honest.
18+
*
19+
* This table is that enumeration, and {@link sendInjectedDaemonRequest} is the only way
20+
* to perform one: the route and command are typed parameters checked against this table,
21+
* so an undeclared pair is a compile error rather than something a scanner must find.
22+
*/
23+
export const CLI_INJECTED_DAEMON_DISPATCHES = {
24+
'react-devtools': [INTERNAL_COMMANDS.runtime],
25+
} as const satisfies Partial<Record<DescriptorCliCommandName, readonly string[]>>;
26+
27+
export type CliInjectedRoute = keyof typeof CLI_INJECTED_DAEMON_DISPATCHES;
28+
29+
type InjectedCommandFor<Route extends CliInjectedRoute> =
30+
(typeof CLI_INJECTED_DAEMON_DISPATCHES)[Route][number];
31+
32+
/**
33+
* The single construction point for a CLI-injected daemon request. `command` comes from
34+
* the declared pair rather than from the caller's object literal, so the dispatched
35+
* command is known by type at every call site.
36+
*/
37+
export async function sendInjectedDaemonRequest<Route extends CliInjectedRoute>(params: {
38+
route: Route;
39+
command: InjectedCommandFor<Route>;
40+
request: Omit<CliDaemonRequest, 'command'>;
41+
transport: CliDaemonTransport;
42+
transportOptions?: CliDaemonTransportOptions;
43+
}): Promise<DaemonResponse> {
44+
const { command, request, transport, transportOptions } = params;
45+
return await transport({ ...request, command }, transportOptions);
46+
}

0 commit comments

Comments
 (0)