Skip to content

Commit 8084e00

Browse files
maria-rcksLucenx9
andauthored
fix(shared): stop parsing CLI flags after -- (#25204)
Co-authored-by: Simone <[email protected]>
1 parent aaba9de commit 8084e00

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ function makeClaudeTestTurnInput(input: {
235235
}
236236

237237
describe("ClaudeAdapterV2 runtime query policy", () => {
238+
it.each([
239+
"-- --thinking-display omitted",
240+
"--thinking-display summarized -- --thinking-display omitted",
241+
])("does not treat operands after -- as SDK flags: %s", (launchArgs) => {
242+
const options = ClaudeAdapterV2.makeClaudeQueryOptions({
243+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
244+
nativeThreadId: "thinking-thread",
245+
resume: false,
246+
cwd: "/workspace",
247+
settings: { ...DEFAULT_CLAUDE_SETTINGS, launchArgs },
248+
});
249+
assert.deepEqual(options.thinking, { type: "adaptive", display: "summarized" });
250+
assert.equal(options.extraArgs?.["thinking-display"], "summarized");
251+
});
252+
238253
it.each([
239254
["--permission-mode acceptEdits", "acceptEdits"],
240255
["--dangerously-skip-permissions", "bypassPermissions"],

‎packages/shared/src/cliArgs.test.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,41 @@ describe("parseCliArgs", () => {
5454
});
5555
});
5656

57-
it("ignores bare -- with no flag name", () => {
57+
it("accepts a trailing -- without operands", () => {
5858
expect(parseCliArgs("--")).toEqual({ flags: {}, positionals: [] });
5959
});
6060

61+
it.each([
62+
{ args: "--effort low -- --effort high --chrome" },
63+
{ args: ["--effort", "low", "--", "--effort", "high", "--chrome"] },
64+
])("ends option parsing at -- for $args", ({ args }) => {
65+
expect(parseCliArgs(args)).toEqual({
66+
flags: { effort: "low" },
67+
positionals: ["--effort", "high", "--chrome"],
68+
});
69+
});
70+
71+
it("preserves all operands after --, including empty strings and another --", () => {
72+
expect(parseCliArgs(["--", "", "--", "--model=example", "-x"])).toEqual({
73+
flags: {},
74+
positionals: ["", "--", "--model=example", "-x"],
75+
});
76+
});
77+
78+
it("ends option parsing with explicit boolean flags too", () => {
79+
expect(parseCliArgs(["--chrome", "--", "--verbose"], { booleanFlags: ["chrome"] })).toEqual({
80+
flags: { chrome: null },
81+
positionals: ["--verbose"],
82+
});
83+
});
84+
85+
it("keeps -- inside an equals-form option value", () => {
86+
expect(parseCliArgs("--append-system-prompt=-- --chrome")).toEqual({
87+
flags: { "append-system-prompt": "--", chrome: null },
88+
positionals: [],
89+
});
90+
});
91+
6192
it("boolean flag does not consume next token as value", () => {
6293
expect(parseCliArgs(["--github-output", "1.2.3"], { booleanFlags: ["github-output"] })).toEqual(
6394
{

‎packages/shared/src/cliArgs.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ export function parseCliArgs(
7777
for (let i = 0; i < tokens.length; i++) {
7878
const token = tokens[i]!;
7979

80+
if (token === "--") {
81+
positionals.push(...tokens.slice(i + 1));
82+
break;
83+
}
84+
8085
if (token.startsWith("--")) {
8186
const rest = token.slice(2);
82-
if (!rest) continue;
8387

8488
const eqIndex = rest.indexOf("=");
8589
if (eqIndex !== -1) {

0 commit comments

Comments
 (0)