Skip to content

Commit 944c734

Browse files
committed
🐛 Refuse a valued --run instead of reading it as the switch (#260)
An option's name is read up to its first `=`, so `--run=false` arrived under the name of the switch and was taken for it. That set the flag saying execution had been requested, which is also what satisfies the gate refusing options that only configure a run — so `--run=false --journal trace.jsonl` was accepted. What followed is worth stating precisely, because it is not what the flag being set suggests. The ordinary parser reads `--run=false` as false and `--run=true` as the field's default, which is also false. So the command took the write path either way: `--run=false --journal <path>` completed successfully, created no journal, and never told the caller that the journal they asked for was not a thing this invocation would produce; and `--run=true` was silently answered by a command that wrote the Plan instead of running it. One half of the command believed a run had been requested and the other half did not, and neither told anybody. Every valued spelling — `--run=false`, `--run=true`, `--run=` — now fails fixed preflight, before it establishes that execution was requested and before it can answer for the gate. Nothing is loaded, built, contacted, opened, created or executed. The regressions fail without it: the scanner cases find no error, and the command-level case exits 0 where it now exits 1 — the old behaviour was a success, not an incidental failure, which is what makes the tripwires worth asserting. Claude-Session: https://claude.ai/code/session_015HcqB9kJM9KFnMNToAuZF6
1 parent 142272d commit 944c734

4 files changed

Lines changed: 109 additions & 1 deletion

File tree

‎packages/cli/src/prompt-args.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ export function scanPromptArgs(args: readonly string[]): PromptScan {
228228
}
229229

230230
if (name === RUN_OPTION) {
231+
// `optionName` stops at the first `=`, so every `--run=…` spelling
232+
// arrives here under the name of the switch. Reading one as the switch
233+
// would let a token satisfy the gate below while meaning the opposite,
234+
// and the ordinary parser reads `--run=true` as the default rather than
235+
// as true — so a caller who spelled it that way is answered by neither
236+
// half of this command. Refused instead, before it establishes anything.
237+
if (equals !== -1) {
238+
return {
239+
...(request === undefined ? {} : { request }),
240+
fixed,
241+
occurrences,
242+
error:
243+
`${RUN_OPTION} does not take a value — write ${RUN_OPTION} to execute the Plan ` +
244+
"or leave it out to write the Plan",
245+
};
246+
}
231247
runs = true;
232248
}
233249
if (runOnly === undefined && RUN_ONLY.has(name)) {

‎packages/cli/tests/prompt-args.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,36 @@ describe("Tier PR — xmd prompt fixed grammar", () => {
269269
}
270270
});
271271

272+
it("C1: --run is a switch, and every valued spelling of it is refused", function* () {
273+
// An option name is read up to its first `=`, so `--run=false` arrives under
274+
// the name of the switch. Taken as the switch it would establish the
275+
// opposite of what was written, and satisfy the run-only gate on the way.
276+
const REFUSAL =
277+
"--run does not take a value — write --run to execute the Plan " +
278+
"or leave it out to write the Plan";
279+
280+
for (const spelling of ["--run=false", "--run=true", "--run="]) {
281+
const scan = scanPromptArgs(["prompt", REQUEST, spelling]);
282+
expect(scan.error).toBe(REFUSAL);
283+
// It established nothing: the token reached neither the parser's argv nor
284+
// the record of what this invocation asked for.
285+
expect(scan.fixed).toEqual(["prompt", REQUEST]);
286+
287+
// And it does not answer for `--run` where a run is what makes an option
288+
// meaningful. Without the fix this command line is accepted, and then
289+
// nothing runs — so the journal the caller asked for is never created.
290+
const gated = scanPromptArgs(["prompt", REQUEST, spelling, "--journal", "trace.jsonl"]);
291+
expect(gated.error).toBe(REFUSAL);
292+
expect(gated.fixed).toEqual(["prompt", REQUEST]);
293+
}
294+
295+
// The switch itself is unaffected, wherever it is written.
296+
expect(scanPromptArgs(["prompt", REQUEST, "--run"]).error).toBe(undefined);
297+
expect(scanPromptArgs(["prompt", REQUEST, "--run", "--journal", "t.jsonl"]).error).toBe(
298+
undefined,
299+
);
300+
});
301+
272302
it("C1: an option this command does not define is refused, not dropped", function* () {
273303
// The parser stops at the first option it does not define and drops the
274304
// rest, so silence here would mean accepting a command line nobody honoured.

‎packages/cli/tests/prompt-cli.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,53 @@ describe(
206206
});
207207
});
208208

209+
it("C1: --run=false reaches no authorship and no durable effect", function* () {
210+
// `--run=false` used to be read as the switch, which satisfied the gate
211+
// that only exists because a run is what makes `--journal` mean anything.
212+
// The command line was then accepted, nothing ran, and the journal the
213+
// caller asked for was never created — so the gate answered a request it
214+
// had not honoured. Nonzero alone would not catch that: the invocation
215+
// below would have failed anyway, on the agent it cannot reach.
216+
yield* useWorkingDirectory(function* (dir, profileRoot) {
217+
const journal = join(dir, "trace.jsonl");
218+
const harness = createPromptHarness({ profileRoot });
219+
harness.deps.execute = executor(dir, journal);
220+
harness.fake.script({ reply: PLAIN });
221+
harness.script({ decision: "Approve" });
222+
223+
const argv = ["prompt", REQUEST, "--run=false", "--journal", journal];
224+
const written = console.error;
225+
const lines: string[] = [];
226+
const value = yield* scoped(function* (): Operation<number> {
227+
yield* ensure(() => {
228+
console.error = written;
229+
});
230+
console.error = (...parts: unknown[]) => {
231+
lines.push(parts.map((part) => String(part)).join(" "));
232+
};
233+
return yield* runPrompt(
234+
{ argv, scan: scanPromptArgs(argv), include: [dir], run: false, stack: STACK },
235+
harness.deps,
236+
);
237+
});
238+
239+
expect(value).toBe(1);
240+
// The refusal is the one the fixed grammar owes this command line, not
241+
// an incidental failure further along.
242+
expect(lines).toEqual([
243+
"--run does not take a value — write --run to execute the Plan " +
244+
"or leave it out to write the Plan",
245+
]);
246+
// Every phase after preflight stayed at zero: no catalog, no provider,
247+
// no session, no turn, no review, no execution.
248+
expect(untouched(harness)).toEqual(NOTHING);
249+
// And nothing durable exists — neither the journal it named nor
250+
// anything else.
251+
expect(yield* exists(journal)).toBe(false);
252+
expect(yield* until(readdir(dir))).toEqual([]);
253+
});
254+
});
255+
209256
it("C1: --save is gone, and is refused as the unknown option it is", function* () {
210257
// Nothing was released under the old spelling, so there is no alias and
211258
// nothing to keep compatible with. Proven on a command line that is

‎specs/prompt-command-spec.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ drops the rest — accepting a command line nobody honoured. `--save` is named i
126126
particular: it was replaced by `--output` before release, so there is no alias,
127127
and the refusal says where an approved Plan goes now.
128128

129+
`--run` is a switch, and every valued spelling of it — `--run=false`,
130+
`--run=true`, `--run=` — is refused there too:
131+
132+
```console
133+
$ xmd prompt "…" --run=false
134+
--run does not take a value — write --run to execute the Plan or leave it out to
135+
write the Plan
136+
```
137+
138+
An option's name is read up to its first `=`, so such a token arrives under the
139+
name of the switch. Taken as the switch it would establish the opposite of what
140+
was written and satisfy the run-only gate on the way, which is how
141+
`--run=false --journal <path>` came to be accepted by a command that then created
142+
no journal. It establishes nothing and reaches no later phase.
143+
129144
`-e`/`--eval` stays exclusive to `xmd run`. A prompt supplies a request, not a
130145
document. Supplying one anyway is refused in the command's own preflight, with
131146
`unrecognized option for xmd prompt: --eval — inline documents are exclusive to
@@ -574,7 +589,7 @@ Every failure below exits non-zero, and each one stops the phases after it:
574589

575590
| Failure | Reaches |
576591
| --- | --- |
577-
| a malformed command line, an unknown option, or `--save` | nothing |
592+
| a malformed command line, an unknown option, `--save`, or a valued `--run=…` | nothing |
578593
| incompatible permission flags or an unknown `--agent-provider` | nothing |
579594
| a catalog an include makes unreadable | no command document |
580595
| a provider that cannot establish the prompt profile's ceiling | no session, no turn |

0 commit comments

Comments
 (0)