diff --git a/scripts/src/agentrun.test.ts b/scripts/src/agentrun.test.ts new file mode 100644 index 00000000..d27e08e0 --- /dev/null +++ b/scripts/src/agentrun.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, test } from "bun:test"; +import { stripAgentRunResourceWrapperArgs } from "./agentrun"; + +describe("AgentRun resource bridge argv", () => { + test("does not forward UniDesk output flags to create task prompt argv", () => { + expect(stripAgentRunResourceWrapperArgs([ + "--aipod", + "Artificer", + "--prompt-stdin", + "-o", + "json", + "--idempotency-key", + "case-262", + "--dry-run", + ])).toEqual([ + "--aipod", + "Artificer", + "--prompt-stdin", + "--idempotency-key", + "case-262", + "--dry-run", + ]); + }); + + test("strips wrapper display flags while preserving official apply arguments", () => { + expect(stripAgentRunResourceWrapperArgs([ + "-f", + "-", + "--output=yaml", + "--raw", + "--full", + "--full-text", + "--dry-run", + ])).toEqual([ + "-f", + "-", + "--dry-run", + ]); + }); +}); diff --git a/scripts/src/agentrun.ts b/scripts/src/agentrun.ts index 6662227c..f647506f 100644 --- a/scripts/src/agentrun.ts +++ b/scripts/src/agentrun.ts @@ -272,26 +272,42 @@ async function runAgentRunResourceCommand(config: UniDeskConfig, verb: AgentRunR if (verb === "explain") return renderedCliResult(true, "agentrun explain", agentRunExplain(action ?? "task")); const resourceArgs = action === undefined ? actionArgs : [action, ...actionArgs]; const options = parseResourceOptions(resourceArgs); + const bridgeActionArgs = stripAgentRunResourceWrapperArgs(actionArgs); const command = `agentrun ${canonicalArgs.join(" ")}`.trim(); try { - if (verb === "get") return await resourceGet(config, command, action, actionArgs, options); - if (verb === "describe") return await resourceDescribe(config, command, action, actionArgs, options); - if (verb === "events") return await resourceEvents(config, command, action, actionArgs, options); - if (verb === "logs") return await resourceLogs(config, command, action, actionArgs, options); - if (verb === "result") return await resourceResult(config, command, action, actionArgs, options); - if (verb === "ack") return await resourceAck(config, command, action, actionArgs, options); - if (verb === "cancel") return await resourceCancel(config, command, action, actionArgs, options); - if (verb === "dispatch") return await resourceDispatch(config, command, action, actionArgs, options); - if (verb === "create") return await resourceCreate(config, command, action, actionArgs, options); - if (verb === "apply") return await resourceApply(config, command, actionArgs, options); - if (verb === "steer") return await resourceSessionPromptCommand(config, command, "steer", action, actionArgs, options); - if (verb === "send") return await resourceSessionPromptCommand(config, command, "turn", action, actionArgs, options); + if (verb === "get") return await resourceGet(config, command, action, bridgeActionArgs, options); + if (verb === "describe") return await resourceDescribe(config, command, action, bridgeActionArgs, options); + if (verb === "events") return await resourceEvents(config, command, action, bridgeActionArgs, options); + if (verb === "logs") return await resourceLogs(config, command, action, bridgeActionArgs, options); + if (verb === "result") return await resourceResult(config, command, action, bridgeActionArgs, options); + if (verb === "ack") return await resourceAck(config, command, action, bridgeActionArgs, options); + if (verb === "cancel") return await resourceCancel(config, command, action, bridgeActionArgs, options); + if (verb === "dispatch") return await resourceDispatch(config, command, action, bridgeActionArgs, options); + if (verb === "create") return await resourceCreate(config, command, action, bridgeActionArgs, options); + if (verb === "apply") return await resourceApply(config, command, bridgeActionArgs, options); + if (verb === "steer") return await resourceSessionPromptCommand(config, command, "steer", action, bridgeActionArgs, options); + if (verb === "send") return await resourceSessionPromptCommand(config, command, "turn", action, bridgeActionArgs, options); } catch (error) { return renderedCliResult(false, command, `Error: ${error instanceof Error ? error.message : String(error)}`); } return renderedCliResult(false, command, `Unsupported AgentRun resource command. Try: bun scripts/cli.ts agentrun --help`); } +export function stripAgentRunResourceWrapperArgs(args: string[]): string[] { + const result: string[] = []; + for (let index = 0; index < args.length; index += 1) { + const arg = args[index] ?? ""; + if (arg === "-o" || arg === "--output") { + index += 1; + continue; + } + if (arg.startsWith("--output=") || arg.startsWith("-o=")) continue; + if (arg === "--full" || arg === "--raw" || arg === "--debug" || arg === "--full-text") continue; + result.push(arg); + } + return result; +} + function parseResourceOptions(args: string[]): AgentRunResourceOptions { const options: AgentRunResourceOptions = { output: "human",