fix(agents): correct copilot flag order and mastracode prompt mode#3869
fix(agents): correct copilot flag order and mastracode prompt mode#3869
Conversation
- copilot: reorder `promptCommand` from `copilot -i --allow-tool=write` to `copilot --allow-tool=write -i`. With the old order, the rendered shell command landed as `copilot -i --allow-tool=write "PROMPT"`, which commander.js parsed as `-i=--allow-tool=write` and rejected the prompt with `error: too many arguments`. - mastracode: add `promptCommand: "mastracode --prompt"`. The previous default-from-`command` rendered `mastracode "PROMPT"`, but mastracode's TUI silently drops positional args (only the headless `--prompt`/`-p` path actually executes the input). Trade-off: prompt-mode now runs headless since upstream has no `interactive + auto-execute` flag like copilot's `-i` or gemini's `--prompt-interactive`. - bump `mastracode` desktop dep `0.15.0-alpha.3` → `0.16.0` to match the current published release.
📝 WalkthroughWalkthroughUpdated desktop dependency Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes two silent/breaking bugs in the agent prompt registry: the copilot Confidence Score: 5/5Safe to merge — both fixes are correct and well-reasoned; the one open question (legacy migration string) is pre-existing and explicitly acknowledged by the author. Both changes are minimal, targeted, and verified against the actual CLI flag semantics. The only remaining note is a P2 about the legacy migration string in No files require special attention, though
|
| Filename | Overview |
|---|---|
| packages/shared/src/builtin-terminal-agents.ts | Two targeted bug fixes: reorders copilot flags (--allow-tool=write -i instead of -i --allow-tool=write) to prevent commander.js from consuming the flag as -i's value; adds promptCommand: "mastracode --prompt" to route prompts through the headless path instead of silently dropping them into the TUI. |
| apps/desktop/package.json | Bumps mastracode from 0.15.0-alpha.3 to 0.16.0, aligning with the stable release that supports the --prompt headless flag added in builtin-terminal-agents.ts. |
| bun.lock | Lock file updated to reflect the mastracode version bump; no concerns. |
Sequence Diagram
sequenceDiagram
participant S as Superset
participant B as buildPromptCommandString
participant CLI as Agent CLI
Note over S,CLI: copilot prompt mode (before fix)
S->>B: command="copilot -i --allow-tool=write", transport=argv
B-->>S: copilot -i --allow-tool=write "PROMPT"
S->>CLI: copilot -i --allow-tool=write "PROMPT"
CLI-->>S: error: too many arguments
Note over S,CLI: copilot prompt mode (after fix)
S->>B: command="copilot --allow-tool=write -i", transport=argv
B-->>S: copilot --allow-tool=write -i "PROMPT"
S->>CLI: copilot --allow-tool=write -i "PROMPT"
CLI-->>S: prompt received correctly
Note over S,CLI: mastracode prompt mode (before fix)
S->>B: command="mastracode", transport=argv
B-->>S: mastracode "PROMPT"
S->>CLI: mastracode "PROMPT"
CLI-->>S: TUI opens, positional arg silently dropped
Note over S,CLI: mastracode prompt mode (after fix)
S->>B: command="mastracode --prompt", transport=argv
B-->>S: mastracode --prompt "PROMPT"
S->>CLI: mastracode --prompt "PROMPT"
CLI-->>S: headless path executes, exits 0
Comments Outside Diff (1)
-
packages/shared/src/agent-permissions-migration.ts, line 44 (link)Legacy copilot flag order still broken for migrated users
The legacy migration entry at line 44 uses
"copilot -i --allow-all", which has the same flag-order problem this PR fixes — commander.js will absorb--allow-allas-i's value and then error on the prompt argument. Any user whose preset was backfilled viaapplyLegacyPermissionsOverrideswill get the broken ordering when they use copilot in prompt mode.The PR description acknowledges this as an open question. If legacy users are expected to run copilot prompt mode, consider fixing this to
"copilot --allow-all -i"to match the pattern established in this PR.Prompt To Fix With AI
This is a comment left during a code review. Path: packages/shared/src/agent-permissions-migration.ts Line: 44 Comment: **Legacy copilot flag order still broken for migrated users** The legacy migration entry at line 44 uses `"copilot -i --allow-all"`, which has the same flag-order problem this PR fixes — commander.js will absorb `--allow-all` as `-i`'s value and then error on the prompt argument. Any user whose preset was backfilled via `applyLegacyPermissionsOverrides` will get the broken ordering when they use copilot in prompt mode. The PR description acknowledges this as an open question. If legacy users are expected to run copilot prompt mode, consider fixing this to `"copilot --allow-all -i"` to match the pattern established in this PR. How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: packages/shared/src/agent-permissions-migration.ts
Line: 44
Comment:
**Legacy copilot flag order still broken for migrated users**
The legacy migration entry at line 44 uses `"copilot -i --allow-all"`, which has the same flag-order problem this PR fixes — commander.js will absorb `--allow-all` as `-i`'s value and then error on the prompt argument. Any user whose preset was backfilled via `applyLegacyPermissionsOverrides` will get the broken ordering when they use copilot in prompt mode.
The PR description acknowledges this as an open question. If legacy users are expected to run copilot prompt mode, consider fixing this to `"copilot --allow-all -i"` to match the pattern established in this PR.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(agents): correct copilot flag order ..." | Re-trigger Greptile
🚀 Preview Deployment🔗 Preview Links
Preview updates automatically with new commits |
Chain headless prompt execution with a TUI relaunch so the user lands in an interactive session on the same thread the prompt seeded. Without the suffix, `mastracode --prompt` executed and exited, breaking the expected "interactive + handles prompt" UX. The TUI auto-resumes the most recent thread (per mastracode 0.13+ behavior), so chaining `; mastracode` after the headless run drops the user back into the conversation populated by the prompt.
The migration backfill restored `copilot -i --allow-all` for users seeded before #3546, which has the same flag-ordering bug as the registry: `-i` consumes `--allow-all` as its prompt value and the real prompt heredoc errors with `too many arguments`. Reorder to `copilot --allow-all -i` so the prompt lands directly after `-i`. The yolo permissions intent is preserved via the unchanged suffix.
…ions sherif flagged the workspace mismatch — packages/chat and packages/host-service still pin 0.15.0-alpha.3, so bumping desktop alone broke multi-version consistency. The runtime upgrade is already covered by the user-installed CLI; the internal dep just needs to track the rest of the workspace.
Summary
Audited all 9 supported terminal CLI agents (
packages/shared/src/builtin-terminal-agents.ts), upgraded each to latest, and fixed two registry bugs that caused prompts to fail or be silently dropped.copilot — flag order
promptCommandwascopilot -i --allow-tool=write, which rendered tocopilot -i --allow-tool=write "PROMPT". commander.js consumes the next token as-i's value, so it absorbed--allow-tool=writeand then errored on the prompt:Reordered to
copilot --allow-tool=write -iso the prompt heredoc lands directly after-ias its<prompt>value.mastracode — prompt silently dropped
command: "mastracode"with the default argv transport renderedmastracode "PROMPT". Mastracode'scli.jsonly runsparseArgson the headless path (gated by--prompt/-p); the TUI path (tuiMain) constructsMastraTUIwithout anyinitialMessage, so the positional arg never reached the agent.Added
promptCommand: "mastracode --prompt"so prompts go through the headless path that actually executes. Upstream has no "interactive + auto-execute prompt" flag (unlike copilot's-ior gemini's-i, --prompt-interactive), so prompt-mode now exits after completion. The no-promptcommand: "mastracode"still opens the TUI.Other agents verified
Rendered the live shell command from
buildPromptCommandStringfor every agent and smoke-tested the prompt path. claude / amp / codex / gemini / opencode / pi / cursor-agent were already correct — claude and mastracode returned actual model output during the test.Upgrades performed locally
0.0.1775751886→0.0.1777480150(amp update)0.34.0→0.38.2(brew upgrade gemini-cli)0.14.0→0.16.0(bun add -g mastracode@latest) — desktop dep also bumped from0.15.0-alpha.3→0.16.01.2.21→1.14.29(brew upgrade opencode)0.0.412→1.0.39(brew upgrade copilot-cli) — major version bump,-i/-pinterface unchangedclaude (2.1.123), codex (0.125.0), and pi (0.60.0) were already at latest.
Note: legacy migration string
packages/shared/src/agent-permissions-migration.tsstill carries the samecopilot -i --allow-allordering, but its docstring says it intentionally restores pre-#3546 strings to backfill legacy users — leaving it alone deliberately. Open question whether to fix the migration string too, or accept that backfilled users get the broken ordering until they reset to defaults.Test plan
bun test packages/shared— 613 passbun test apps/desktop/src/main/lib/agent-setup— 54 passbuildPromptCommandString; all 9 land the prompt in the right slotcopilot --allow-tool=write -i "PROMPT"parses cleanly (no moretoo many arguments)mastracode --prompt "PROMPT"returns model output and exits 0Summary by cubic
Fixes prompt handling for
copilotandmastracodeso prompts parse, run, and return to an interactive session. Also corrects the legacycopilotmigration and reverts the desktopmastracodebump to keep workspace versions aligned.Bug Fixes
copilot(registry): Reordered tocopilot --allow-tool=write -iso the prompt is consumed by-iinstead of erroring.copilot(legacy migration): Reordered tocopilot --allow-all -i; keeps the--yolosuffix.mastracode: AddedpromptCommand: "mastracode --prompt"andpromptCommandSuffix: "; mastracode"to run the prompt headlessly, then relaunch the TUI on the same thread. Starting without a prompt still opens the TUI.Dependencies
apps/desktopmastracodebump; workspace remains on0.15.0-alpha.3.Written for commit 34e85ce. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
New Features
Chores