From e13cc5b66baef7f492ecf2c8152820d5c83bdf28 Mon Sep 17 00:00:00 2001 From: Tristan Manchester Date: Sun, 22 Feb 2026 08:39:34 +0100 Subject: [PATCH] CLI: keep passthrough --profile args after -- --- src/cli/profile.test.ts | 66 +++++++++++++++++++++++++++++++++++++++++ src/cli/profile.ts | 12 ++++++++ 2 files changed, 78 insertions(+) diff --git a/src/cli/profile.test.ts b/src/cli/profile.test.ts index d117dfac4a7..36067ab12f6 100644 --- a/src/cli/profile.test.ts +++ b/src/cli/profile.test.ts @@ -68,6 +68,72 @@ describe("parseCliProfileArgs", () => { expect(res.ok).toBe(false); }); + it("does not intercept --profile after passthrough terminator", () => { + const res = parseCliProfileArgs([ + "node", + "openclaw", + "nodes", + "run", + "--node", + "abc123", + "--", + "aws", + "--profile", + "prod", + "sts", + "get-caller-identity", + ]); + if (!res.ok) { + throw new Error(res.error); + } + expect(res.profile).toBeNull(); + expect(res.argv).toEqual([ + "node", + "openclaw", + "nodes", + "run", + "--node", + "abc123", + "--", + "aws", + "--profile", + "prod", + "sts", + "get-caller-identity", + ]); + }); + + it("keeps passthrough --profile when global --profile is set before terminator", () => { + const res = parseCliProfileArgs([ + "node", + "openclaw", + "--profile", + "work", + "nodes", + "run", + "--", + "aws", + "--profile=prod", + "sts", + "get-caller-identity", + ]); + if (!res.ok) { + throw new Error(res.error); + } + expect(res.profile).toBe("work"); + expect(res.argv).toEqual([ + "node", + "openclaw", + "nodes", + "run", + "--", + "aws", + "--profile=prod", + "sts", + "get-caller-identity", + ]); + }); + it("parses --profile value and strips it", () => { const res = parseCliProfileArgs(["node", "openclaw", "--profile", "work", "status"]); if (!res.ok) { diff --git a/src/cli/profile.ts b/src/cli/profile.ts index 69b7d4b8acb..0ddc879675e 100644 --- a/src/cli/profile.ts +++ b/src/cli/profile.ts @@ -36,6 +36,7 @@ export function parseCliProfileArgs(argv: string[]): CliProfileParseResult { let profile: string | null = null; let sawDev = false; let sawCommand = false; + let sawTerminator = false; const args = argv.slice(2); for (let i = 0; i < args.length; i += 1) { @@ -44,6 +45,17 @@ export function parseCliProfileArgs(argv: string[]): CliProfileParseResult { continue; } + if (sawTerminator) { + out.push(arg); + continue; + } + + if (arg === "--") { + sawTerminator = true; + out.push(arg); + continue; + } + if (sawCommand && arg !== "--profile" && !arg.startsWith("--profile=")) { out.push(arg); continue;