Skip to content

Commit 955ebd0

Browse files
thymikeeclaude
andcommitted
test(help): parse find commands in the TS command validator
Address review: importing @agent-device/selectors into the scorer modules broke bare node on the Node 22 floor, where .ts imports need type stripping. The command validator, which already runs with --experimental-strip-types, now attaches each find command's parseFindArgs action and query, and the plain-JS scorer reads that. The scorer modules import no TypeScript again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 26b520f commit 955ebd0

3 files changed

Lines changed: 26 additions & 26 deletions

File tree

‎scripts/help-conformance-command-validator.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { pathToFileURL } from 'node:url';
22
import { parseArgs } from '../src/cli/parser/args.ts';
33
import { isCommandName, readInputFromCli } from '@agent-device/command-surface';
4+
import { parseFindArgs } from '@agent-device/selectors';
45

56
type ValidationKind = 'agent-device-grammar' | 'pseudo-ref';
67

78
type ParsedAgentCommand = {
89
command: string;
910
positionals: string[];
11+
/** A `find` command's action and query, as `parseFindArgs` reads them; the scorers stay plain JS. */
12+
find?: { action: string; query: string };
1013
};
1114

1215
type ValidationResult = { valid: true } | { valid: false; kind: ValidationKind; error: string };
@@ -91,10 +94,21 @@ function validatePlanCommand(value: unknown): PlanValidationResult {
9194
agentCommand: {
9295
command: parsed.command,
9396
positionals: [...parsed.positionals],
97+
...(parsed.command === 'find' ? readFind(parsed.positionals) : {}),
9498
},
9599
};
96100
}
97101

102+
/** An unsupported action is no find the plan can act on, so it carries no parsed find. */
103+
function readFind(positionals: string[]): Pick<ParsedAgentCommand, 'find'> {
104+
try {
105+
const { action, query } = parseFindArgs(positionals);
106+
return { find: { action, query } };
107+
} catch {
108+
return {};
109+
}
110+
}
111+
98112
function runCli(): void {
99113
const encodedInput = process.argv[2];
100114
if (!encodedInput) throw new Error('Expected a JSON argv array.');
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { parseFindArgs } from '@agent-device/selectors';
2-
31
export function opensAndCloses({ commands }) {
42
return hasAgentDeviceCommand(commands, 'open') && hasAgentDeviceCommand(commands, 'close');
53
}
@@ -24,32 +22,15 @@ function isPnpmScript(command, script) {
2422

2523
/**
2624
* Whether the plan holds a read-only `find`: one whose action is `exists` (bare find clicks).
27-
* `parseFindArgs` owns the find grammar; `subject`, when given, must appear in the query.
25+
* The command validator parses each find with `parseFindArgs`; `subject`, when given, must appear
26+
* in the query. A find that failed validation carries no parse and does not verify.
2827
*/
2928
export function hasFindExists(commandValidation, subject) {
30-
return commandValidation.some((command) => {
31-
const positionals = findPositionals(command);
32-
if (!positionals) return false;
33-
const parsed = tryParseFindArgs(positionals);
29+
return commandValidation.some(({ agentCommand }) => {
30+
const find = agentCommand?.find;
3431
return (
35-
parsed?.action === 'exists' &&
36-
(subject === undefined || parsed.query.toLowerCase().includes(subject))
32+
find?.action === 'exists' &&
33+
(subject === undefined || find.query.toLowerCase().includes(subject))
3734
);
3835
});
3936
}
40-
41-
/** An unsupported action is a plan the model got wrong, not a read-only find, so it scores false. */
42-
function tryParseFindArgs(positionals) {
43-
try {
44-
return parseFindArgs(positionals);
45-
} catch {
46-
return undefined;
47-
}
48-
}
49-
50-
/** A find command's positionals: parsed when it validated, else its tokens without flags. */
51-
function findPositionals({ tokens, agentCommand }) {
52-
if (agentCommand) return agentCommand.command === 'find' ? agentCommand.positionals : undefined;
53-
if (tokens[0] !== 'agent-device' || tokens[1] !== 'find') return undefined;
54-
return tokens.slice(2).filter((token) => !token.startsWith('-'));
55-
}

‎scripts/help-conformance-plan-validator.d.mts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
// `./help-conformance-plan-validator.mjs`; keep it in step with the exports there.
44
export type PlanCommandIssue = { kind: string; error: string };
55

6-
export type PlanAgentCommand = { command: string; positionals: string[] };
6+
export type PlanAgentCommand = {
7+
command: string;
8+
positionals: string[];
9+
/** A `find` command's action and query, as `parseFindArgs` reads them. */
10+
find?: { action: string; query: string };
11+
};
712

813
export type PlanCommandValidation = {
914
command: string;

0 commit comments

Comments
 (0)