Skip to content

fix(agents): correct copilot flag order and mastracode prompt mode#3869

Merged
Kitenite merged 4 commits intomainfrom
cli-agents-audit-upgrade
Apr 29, 2026
Merged

fix(agents): correct copilot flag order and mastracode prompt mode#3869
Kitenite merged 4 commits intomainfrom
cli-agents-audit-upgrade

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Apr 29, 2026

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

promptCommand was copilot -i --allow-tool=write, which rendered to copilot -i --allow-tool=write "PROMPT". commander.js consumes the next token as -i's value, so it absorbed --allow-tool=write and then errored on the prompt:

error: too many arguments. Expected 0 arguments but got 1.

Reordered to copilot --allow-tool=write -i so the prompt heredoc lands directly after -i as its <prompt> value.

mastracode — prompt silently dropped

command: "mastracode" with the default argv transport rendered mastracode "PROMPT". Mastracode's cli.js only runs parseArgs on the headless path (gated by --prompt/-p); the TUI path (tuiMain) constructs MastraTUI without any initialMessage, 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 -i or gemini's -i, --prompt-interactive), so prompt-mode now exits after completion. The no-prompt command: "mastracode" still opens the TUI.

Other agents verified

Rendered the live shell command from buildPromptCommandString for 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

Agent Before → After
amp 0.0.17757518860.0.1777480150 (amp update)
gemini 0.34.00.38.2 (brew upgrade gemini-cli)
mastracode 0.14.00.16.0 (bun add -g mastracode@latest) — desktop dep also bumped from 0.15.0-alpha.30.16.0
opencode 1.2.211.14.29 (brew upgrade opencode)
copilot 0.0.4121.0.39 (brew upgrade copilot-cli) — major version bump, -i/-p interface unchanged

claude (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.ts still carries the same copilot -i --allow-all ordering, 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 pass
  • bun test apps/desktop/src/main/lib/agent-setup — 54 pass
  • Rendered each agent's prompt command via buildPromptCommandString; all 9 land the prompt in the right slot
  • copilot: copilot --allow-tool=write -i "PROMPT" parses cleanly (no more too many arguments)
  • mastracode: mastracode --prompt "PROMPT" returns model output and exits 0
  • Smoke test in a real Superset terminal pane that starting each agent with a task prompt drops you in interactively (or in mastracode's case, runs the prompt and exits)

Summary by cubic

Fixes prompt handling for copilot and mastracode so prompts parse, run, and return to an interactive session. Also corrects the legacy copilot migration and reverts the desktop mastracode bump to keep workspace versions aligned.

  • Bug Fixes

    • copilot (registry): Reordered to copilot --allow-tool=write -i so the prompt is consumed by -i instead of erroring.
    • copilot (legacy migration): Reordered to copilot --allow-all -i; keeps the --yolo suffix.
    • mastracode: Added promptCommand: "mastracode --prompt" and promptCommandSuffix: "; mastracode" to run the prompt headlessly, then relaunch the TUI on the same thread. Starting without a prompt still opens the TUI.
  • Dependencies

    • Reverted the apps/desktop mastracode bump; workspace remains on 0.15.0-alpha.3.

Written for commit 34e85ce. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • New Features

    • Added a prompt-command capability for the mastracode terminal agent to improve interactive prompts.
  • Chores

    • Updated mastracode to v0.16.0 to pick up latest improvements.
    • Adjusted the Copilot terminal agent’s prompt command ordering for more consistent and predictable behavior, including the legacy override.

- 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.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

Updated desktop dependency mastracode to 0.16.0; added promptCommand and promptCommandSuffix for the mastracode builtin terminal agent; reordered -i flag in copilot promptCommand in both builtin agents and legacy override entries.

Changes

Cohort / File(s) Summary
Dependency Update
apps/desktop/package.json
Bumped mastracode from 0.15.0-alpha.3 to 0.16.0.
Terminal Agent Commands
packages/shared/src/builtin-terminal-agents.ts
Added promptCommand: "mastracode --prompt" and promptCommandSuffix: "; mastracode" for mastracode; changed copilot promptCommand ordering from copilot -i --allow-tool=write to copilot --allow-tool=write -i.
Legacy Agent Overrides
packages/shared/src/agent-permissions-migration.ts
Updated legacy copilot override promptCommand from copilot -i --allow-all to copilot --allow-all -i.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped in code, a quiet tweak,
Mastracode blooms, prompts now speak,
Copilot’s flags danced to the end,
Tiny changes—cheers I send,
Nibbles, hops, and one more peek 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately captures the two main bug fixes: correcting copilot flag order and fixing mastracode prompt mode for proper prompt handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description is comprehensive, well-structured, and follows the template with all required sections including Description, Related Issues (implicitly addressed), Type of Change, Testing, and Additional Notes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cli-agents-audit-upgrade

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR fixes two silent/breaking bugs in the agent prompt registry: the copilot promptCommand had flags in the wrong order causing commander.js to misparse the prompt argument, and mastracode lacked a promptCommand entirely so prompts were silently swallowed by the TUI path. It also bumps the mastracode desktop dependency from 0.15.0-alpha.3 to 0.16.0 and upgrades several other agents locally.

Confidence Score: 5/5

Safe 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 agent-permissions-migration.ts, which the author already flagged as a known open question — it does not block this PR.

No files require special attention, though agent-permissions-migration.ts carries the same copilot flag-order bug for legacy backfilled users.

Important Files Changed

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
Loading

Comments Outside Diff (1)

  1. packages/shared/src/agent-permissions-migration.ts, line 44 (link)

    P2 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.

    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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) View Branch
Vercel API (Vercel) Open Preview
Vercel Web (Vercel) Open Preview
Vercel Marketing (Vercel) Open Preview
Vercel Admin (Vercel) Open Preview
Vercel Docs (Vercel) Open Preview

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.
@Kitenite Kitenite merged commit f5cf3f1 into main Apr 29, 2026
12 of 13 checks passed
@Kitenite Kitenite deleted the cli-agents-audit-upgrade branch April 29, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant