Skip to content

Commit 3896c44

Browse files
committed
fix: preserve agent-cdp passthrough flags
1 parent 7f1ce40 commit 3896c44

4 files changed

Lines changed: 55 additions & 4 deletions

File tree

src/utils/__tests__/args.test.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ test('parseArgs preserves agent-cdp arguments as passthrough positionals', () =>
308308
{ strictFlags: true },
309309
);
310310
assert.equal(parsed.command, 'agent-cdp');
311-
assert.equal(parsed.flags.json, true);
312-
assert.equal(parsed.flags.session, 'rn');
311+
assert.equal(parsed.flags.json, false);
312+
assert.equal(parsed.flags.session, undefined);
313313
assert.deepEqual(parsed.positionals, [
314314
'memory',
315315
'snapshot',
@@ -319,6 +319,46 @@ test('parseArgs preserves agent-cdp arguments as passthrough positionals', () =>
319319
'--compare',
320320
'ms_2',
321321
'--limit=10',
322+
'--json',
323+
'--session',
324+
'rn',
325+
]);
326+
});
327+
328+
test('parseArgs preserves agent-cdp help as a downstream flag', () => {
329+
const parsed = parseArgs(['agent-cdp', '--help'], { strictFlags: true });
330+
assert.equal(parsed.command, 'agent-cdp');
331+
assert.equal(parsed.flags.help, false);
332+
assert.deepEqual(parsed.positionals, ['--help']);
333+
});
334+
335+
test('parseArgs accepts agent-device globals before agent-cdp passthrough args', () => {
336+
const parsed = parseArgs(
337+
[
338+
'--session',
339+
'outer-session',
340+
'agent-cdp',
341+
'target',
342+
'list',
343+
'--target',
344+
'Hermes',
345+
'--device',
346+
'rn-app',
347+
'--json',
348+
],
349+
{ strictFlags: true },
350+
);
351+
assert.equal(parsed.command, 'agent-cdp');
352+
assert.equal(parsed.flags.session, 'outer-session');
353+
assert.equal(parsed.flags.json, false);
354+
assert.deepEqual(parsed.positionals, [
355+
'target',
356+
'list',
357+
'--target',
358+
'Hermes',
359+
'--device',
360+
'rn-app',
361+
'--json',
322362
]);
323363
});
324364

src/utils/args.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export function parseRawArgs(argv: string[]): RawParsedArgs {
5959
else positionals.push(arg);
6060
continue;
6161
}
62+
if (shouldPreservePostCommandArgs(command)) {
63+
positionals.push(arg);
64+
continue;
65+
}
6266
const isLongFlag = arg.startsWith('--');
6367
const isShortFlag = arg.startsWith('-') && arg.length > 1;
6468
if (!isLongFlag && !isShortFlag) {
@@ -112,11 +116,15 @@ function shouldPassThroughLocalToolFlag(
112116
command: string | null,
113117
definition: FlagDefinition | undefined,
114118
): boolean {
115-
if (command !== 'react-devtools' && command !== 'agent-cdp') return false;
119+
if (command !== 'react-devtools') return false;
116120
if (!definition) return true;
117121
return !isFlagSupportedForCommand(definition.key, command);
118122
}
119123

124+
function shouldPreservePostCommandArgs(command: string | null): boolean {
125+
return command === 'agent-cdp';
126+
}
127+
120128
function resolveFlagDefinition(token: string, command: string | null): FlagDefinition | undefined {
121129
const definitions = getFlagDefinitions().filter((definition) => definition.names.includes(token));
122130
if (definitions.length <= 1) return definitions[0] ?? getFlagDefinition(token);

src/utils/cli-help.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ Allocation pressure:
501501
agent-device agent-cdp memory allocation source-maps
502502
503503
Recommended subset:
504+
agent-cdp dynamically runs pinned agent-cdp@1.6.0 through npm; the first run may download the pinned package, and later runs can reuse the npm cache.
505+
Every argument after agent-cdp is passed to agent-cdp. Put agent-device global flags before agent-cdp when you need the outer CLI to consume them.
504506
Use agent-cdp memory usage, memory snapshot, memory allocation, and targeted runtime eval.
505507
Avoid agent-cdp profile cpu, trace, network, and console by default because agent-device already has perf cpu, trace, network, logs, and react-devtools guidance for those areas.
506508

website/docs/docs/commands.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ agent-device agent-cdp memory snapshot leak-triplet --baseline ms_1 --action ms_
692692
agent-device agent-cdp memory snapshot retainers --snapshot ms_3 --id <node-id> --depth 8 --limit 10
693693
```
694694
695-
- `agent-cdp` dynamically runs pinned `agent-cdp@1.6.0` through npm and passes arguments through 1:1.
695+
- `agent-cdp` dynamically runs pinned `agent-cdp@1.6.0` through npm; the first run may download the pinned package, and later runs can reuse the npm cache.
696+
- Every argument after `agent-cdp` is passed to `agent-cdp`. Put `agent-device` global flags before `agent-cdp` when you need the outer CLI to consume them.
696697
- Use it when a React Native or Expo app exposes a Metro CDP target and the task needs JavaScript heap usage, heap snapshots, allocation hotspots, retained-object diffs, retaining paths, or a small runtime eval to confirm JS state.
697698
- Start with `memory usage sample --gc` for a quick JS heap growth signal. Use snapshot diff and `leak-triplet` for proof that objects stayed retained after cleanup.
698699
- Until `agent-cdp` has a compact leak report command, synthesize one from `memory usage diff`, `memory snapshot diff`, `memory snapshot leak-triplet`, and `memory snapshot retainers`.

0 commit comments

Comments
 (0)