A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
support -- end-of-options separator in CLI arg parsing (#296)
kt73c1e406fe0c
diff --git a/packages/coding-agent/src/cli/args.ts b/packages/coding-agent/src/cli/args.tsindex 1aa7268c53..b5e59d278b 100644--- a/packages/coding-agent/src/cli/args.ts+++ b/packages/coding-agent/src/cli/args.ts@@ -68,9 +68,22 @@ export function parseArgs(args: string[]): Args {diagnostics: [],};+ let endOfOptions = false;+for (let i = 0; i < args.length; i++) {const arg = args[i];+ // POSIX end-of-options: everything after a standalone "--" is a positional+ // message, even if it starts with a dash (e.g. a Markdown-bullet prompt).+ if (endOfOptions) {+ result.messages.push(arg);+ continue;+ }+ if (arg === "--") {+ endOfOptions = true;+ continue;+ }+if (arg === "--help" || arg === "-h") {result.help = true;} else if (arg === "--version" || arg === "-v") {@@ -268,6 +281,7 @@ ${chalk.bold("Options:")}--offline Disable startup network operations (same as PI_OFFLINE=1)--help, -h Show this help--version, -v Show version number+ -- End of options; treat all following args as messagesExtensions can register additional flags (e.g., --plan from plan-mode extension).${extensionFlagsText}@@ -287,6 +301,9 @@ ${chalk.bold("Examples:")}# Multiple messages (interactive)${APP_NAME} "Read package.json" "What dependencies do we have?"+ # Prompt that starts with a dash (use -- to end option parsing)+ ${APP_NAME} -- "- You are given a state dictionary..."+# Continue previous session${APP_NAME} --continue "What did we discuss?"diff --git a/packages/coding-agent/test/args.test.ts b/packages/coding-agent/test/args.test.tsindex 53744843f8..a502290cc7 100644--- a/packages/coding-agent/test/args.test.ts+++ b/packages/coding-agent/test/args.test.ts@@ -387,4 +387,43 @@ describe("parseArgs", () => {expect(result.messages).toEqual(["Do the task"]);});});++ describe("-- end-of-options separator", () => {+ test("treats a dash-leading prompt after -- as a positional message", () => {+ const result = parseArgs(["--", "- You are given a state dictionary (/app/weights.pt)..."]);+ expect(result.messages).toEqual(["- You are given a state dictionary (/app/weights.pt)..."]);+ expect(result.diagnostics).toEqual([]);+ expect(result.unknownFlags.size).toBe(0);+ });++ test("a dash-leading prompt without -- still errors", () => {+ const result = parseArgs(["- do the thing"]);+ expect(result.messages).toEqual([]);+ expect(result.diagnostics).toEqual([+ { type: "error", message: "Unknown option: - do the thing" },+ ]);+ });++ test("does not parse flags after -- as options", () => {+ const result = parseArgs(["--", "--provider", "openai"]);+ expect(result.provider).toBeUndefined();+ expect(result.messages).toEqual(["--provider", "openai"]);+ expect(result.unknownFlags.size).toBe(0);+ });++ test("parses flags before -- and treats the rest as messages", () => {+ const result = parseArgs(["--provider", "openai", "--", "-p", "@file"]);+ expect(result.provider).toBe("openai");+ expect(result.print).toBeUndefined();+ expect(result.fileArgs).toEqual([]);+ expect(result.messages).toEqual(["-p", "@file"]);+ });++ test("a lone -- produces no messages and no diagnostics", () => {+ const result = parseArgs(["--"]);+ expect(result.messages).toEqual([]);+ expect(result.diagnostics).toEqual([]);+ expect(result.unknownFlags.size).toBe(0);+ });+ });});