Skip to content

fix(cursor): support 'cursor agent' CLI command for standard Cursor installations - #10190

Closed
MumuTW wants to merge 11 commits into
stablyai:mainfrom
MumuTW:fix/cursor-agent-fallback
Closed

MumuTW wants to merge 11 commits into
stablyai:mainfrom
MumuTW:fix/cursor-agent-fallback

Conversation

@MumuTW

@MumuTW MumuTW commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Orca hardcoded cursor-agent as both detectCmd and launchCmd. That binary only exists if the user ran the standalone installer (curl https://cursor.com/install | bash). A standard Cursor.app install puts cursor on PATH and reaches the agent through the cursor agent subcommand, so those users got zsh: command not found: cursor-agent.

Detection now publishes which executable actually matched on PATH, and the launch path consumes it: cursor-agent detected → launch cursor-agent; only cursor detected → launch cursor agent.

ELI5

Cursor can be installed two different ways, and each one gives the command a different name. Orca only knew one of those names, so for everyone with the other kind of install it kept trying to run a program that wasn't there and gave up. Now Orca looks to see which version you actually have and uses the matching name.

Why detectCmdAliases alone is not enough

Aliases in this codebase only widen detection — getTuiAgentLaunchCommand reads config.launchCmd and nothing else (same shape as mistral-vibe and claude-agent-teams). An alias-only fix would make Cursor appear installed and then fail at launch with the same command not found, which is worse than main's honest "not detected". Flipping the default the other way would break every existing cursor-agent user, which on SSH hosts is the common install.

Detection is the only place that knows which executable is really on PATH, so it now publishes that fact and the launch path consumes it.

Changes

  • launchCmdByDetectCmd (tui-agent-config.ts): maps a matched alias to the launch command it needs. Cursor keeps cursor-agent as detectCmd/launchCmd and maps cursor → cursor agent.
  • Detection publishes the matched executable: resolveDetectedTuiAgentExecutables() returns one executable per detected agent (primary name wins when both are installed). preflight publishes it into a process-local registry (detected-agent-executables.ts), exposed to the renderer over preflight:detectAgentExecutables.
  • Launch reads the registry: resolveAgentLaunchCommand and planAgentBinary (commit-message generation + native-chat model discovery) resolve through it. This keeps the change out of the ~25 buildAgentStartupPlan call sites, which build commands synchronously.
  • Attribution accepts every alias form: resolveBareAgentLaunchCommand (orca-runtime.ts) now matches a typed command against all launchCmdByDetectCmd forms, not just the one the current PATH resolves to — see Notes.
  • Precedence: explicit per-agent command override → detected executable → platform override → static launchCmd.

Proof of fix

An alias-only install (cursor on PATH, no cursor-agent) detects Cursor and then launches a command the host actually has. On main the same scenario detects nothing; with only a detection alias added it detects but still launches the missing binary:

AssertionError: expected { agent: 'cursor', …(4) } to deeply equal { agent: 'cursor', …(4) }

- Expected
+ Received

  {
    "agent": "cursor",
    "expectedProcess": "cursor-agent",
-   "launchCommand": "cursor agent 'Review this file'",
+   "launchCommand": "cursor-agent 'Review this file'",
    "launchConfig": {
-     "agentCommand": "cursor agent",
+     "agentCommand": "cursor-agent",
    },
  }

With this PR, all three install layouts resolve correctly:

✓ tui-agent-startup.test.ts > launches Cursor through `cursor agent` when only the IDE binary was detected
✓ tui-agent-startup.test.ts > keeps cursor-agent when the standalone binary was detected
✓ tui-agent-detection-commands.test.ts > prefers the standalone binary when both are installed

Test Files  2 passed (2)
     Tests  3 passed | 30 skipped (33)

Verified against the real CLI (cursor-agent 2026.07.23-e383d2b), since "space-separated subcommand" is the load-bearing claim:

  • Cursor.app's bin/cursor routes via exec ~/.local/bin/cursor-agent "$@" — it does not shift the agent token.
  • That is safe because cursor-agent registers agent as a genuine subcommand: cursor-agent agent --help → Usage: agent agent [options] [prompt...].
  • --model, --force/--yolo, --resume all parse under the subcommand (the terse subcommand help is misleading — flags are inherited).
  • cursor agent models and cursor-agent models emit identical output, so model discovery is unaffected.

Proof of no regressions

vitest --config config/vitest.config.ts \
  src/shared src/main/ipc src/main/runtime/orca-runtime.test.ts \
  src/renderer/src/lib src/renderer/src/store src/main/text-generation
                                              → 12651 passed | 27 skipped | 0 failed (1057 files)
tsc --noEmit -p config/tsconfig.node.json     → clean
tsc --noEmit -p config/tsconfig.tc.cli.json   → clean
tsc --noEmit -p config/tsconfig.tc.web.json   → clean
oxlint <all changed files>                    → clean

Existing cursor-agent users are unaffected: when both binaries are present, detection prefers the primary name, so the launch command is byte-identical to today's. expectedProcess stays cursor-agent and remains correct — the launcher uses exec -a "$0", so argv[0] is .../cursor-agent regardless of entry point, leaving process recognition and title attribution untouched.

Behavior that does change, all of it scoped to hosts that previously could not launch Cursor at all:

  • An alias-only install now shows Cursor as available (previously hidden) and launches cursor agent.
  • A terminal command typed as cursor agent is now claimed by the managed Cursor lane instead of running as raw shell.
  • On such a host, if cursor-agent is absent Cursor's own shim may run curl -sS https://cursor.com/install | bash on first launch — see Notes.

Compatibility

  • Platforms: macOS verified end-to-end against a real dual install (cursor + cursor-agent), confirming subcommand routing, flag parity and models output. Linux uses the same POSIX shim shape. On Windows, interactive launches work: resolveCliCommand probes .cmd/.exe/.bat explicitly rather than trusting PATHEXT. Windows Source Control AI remains blocked, before and after this PR — see below.
  • Known Windows limitation (pre-existing, not introduced here): Cursor uses promptDelivery: 'argv', and Source Control AI prompts are multiline by construction. Both standard Windows entry points (cursor-agent.cmd, cursor.cmd) resolve to batch shims, and getSpawnArgsForWindows deliberately rejects — not escapes — any .cmd/.bat argument containing &|<>^"%!\r\n, throwing UnsafeWindowsBatchArgumentsError. So non-interactive commit/branch/PR generation fails on Windows for cursor-agent today on main, and equally for the cursor alias added here. This PR does not fix that and does not worsen it; the batch-shim limitation sits in src/main/win32-utils.ts, which this PR does not touch. The one visible change is that an alias-only Windows install now surfaces Cursor as available, so the failure is reported at generation time rather than being hidden behind "not detected". Thanks to @iFwu for reproducing this on Orca 1.4.160. A regression test now locks the behaviour for both shims and for the working non-batch (powershell.exe -File ...ps1) launcher shape, so any future fix has to move it deliberately. Two follow-ups are tracked separately: Windows: Source Control AI cannot run argv-prompt agents through .cmd/.bat shims #11374 (a Windows-safe launch strategy for argv prompts) and Windows: command overrides with native absolute paths are corrupted by POSIX backslash tokenization #11375 (tokenizeCustomCommandTemplate consuming backslashes in native Windows absolute-path overrides).
  • SSH / remote: deliberately out of scope. The registry describes this process's PATH, which says nothing about a remote host, so remote and WSL launches keep the static defaults — the right answer for servers, where cursor-agent is the usual install. The relay protocol (src/relay/preflight-handler.ts) is untouched.
  • Performance: no hot-path change. The executable map is computed once per detection pass from data preflight already gathers — no additional subprocess spawns — and launch-time lookup is a single object read.

Screenshots

No visual change.

Testing

  • pnpm lint — ran oxlint directly on all changed files rather than the wrapper; clean.
  • pnpm typecheck — tsc --noEmit on all three projects (config/tsconfig.node.json, config/tsconfig.tc.cli.json, config/tsconfig.tc.web.json); clean.
  • pnpm test — not run in full. Ran a targeted subset instead (src/shared, src/main/ipc, src/main/runtime/orca-runtime.test.ts, src/renderer/src/lib, src/renderer/src/store, src/main/text-generation) → 12651 passed, 27 skipped, 0 failed (1057 files).
  • pnpm build — not run.
  • Added or updated high-quality tests that would catch regressions

New coverage: alias-only install launches cursor agent; standalone install still launches cursor-agent; detection prefers cursor-agent when both exist; remote launches ignore local aliases; explicit command override still wins; commit-message planning spawns cursor with an agent prefix arg; a typed cursor agent is claimed by the managed Cursor lane (verified failing before the fix with expected undefined to be 'cursor').

AI Review Report

Reviewed for correctness, regressions, cross-OS behavior, SSH/remote assumptions, and command-execution safety.

The main risk checked was whether widening detection without widening launch would leave the agent visibly broken — it does, which is why the alias-only approach was rejected in favour of this one. Also verified that preferring the primary name keeps existing cursor-agent users on a byte-identical command, and that expectedProcess stays valid under exec -a.

Cross-platform compatibility was explicitly checked for macOS, Linux and Windows: shell resolution of .cmd/.exe/.bat shims, PATHEXT independence, argv construction on Windows batch paths, and the WSL/remote boundary. No shortcuts, labels, or path separators are touched by this change.

One gap was flagged in review and is now fixed: agent attribution compared a typed command only against the launch form the current PATH resolves to, so cursor agent typed into a terminal lost its managed hooks and preflightTrust preset. Attribution now accepts every alias launch form — recognition is deliberately broader than launch, since the detected name can flip the moment Cursor's shim self-installs cursor-agent.

Security Audit

Command execution. The change makes a launch command expand from one token to two, so arg-splitting was the primary concern. Traced the value into every spawn site: planAgentBinary splits the default into binary + prefixArgs and commit-message-text-generation.ts passes those to spawn(spawnCmd, spawnArgs, …) as an array — never concatenated into a shell string, so no interpolation boundary is introduced. On Windows, getSpawnArgsForWindows sends batch shims through cmd.exe /d /c as separate argv entries and throws UnsafeWindowsBatchArgumentsError on unsafe batch syntax.

Terminal launches do build a shell string, but that is the pre-existing shared path — orca claude-teams, hermes --tui and command-code --trust are already multi-token — so cursor agent adds no new class of risk. Both tokens are hardcoded constants; no user input reaches the command head.

Attribution widening. The extra match candidates come from launchCmdByDetectCmd values in static config, not from user input, and matching only classifies which agent lane a command belongs to — it never constructs the command that gets spawned. A claimed lane rebuilds its command from config and the detection registry as before.

Input handling / IPC. The new preflight:detectAgentExecutables channel returns a Partial<Record<TuiAgent, string>> built entirely from a fixed allowlist of config-declared names, not from user input or filesystem strings, so a hostile PATH cannot inject an arbitrary command through it. The renderer swallows failures and falls back to static defaults.

Path handling. No new path construction; detection reuses the existing PATH probe. No auth, secrets, or dependency surface is touched.

Follow-up: the curl | bash behavior in Notes is Cursor's own shim, not code introduced here, but it is worth documenting since this change can newly reach it.

Notes

  • Attribution is intentionally broader than launch. resolveBareAgentLaunchCommand matches every launchCmdByDetectCmd form rather than only the currently-detected one. Matching just the detected executable would still drop the lane in the common dual-install case: Cursor.app's shim installs cursor-agent on first use, after which detection prefers the primary name and a user still typing cursor agent would fall out of the managed lane again. Recognition has no "pick exactly one" constraint that launching has, and cursor agent is unambiguously Cursor, so accepting both forms is safe.
  • cursor agent can trigger a network install. When cursor-agent is absent, Cursor.app's shim runs curl -sS https://cursor.com/install | bash plus a --min-version check on first invocation, so an alias-only launch may block on a download the user didn't request. This is Cursor's own behavior, not something introduced here; it is now called out in a comment next to launchCmdByDetectCmd so it isn't a surprise during triage.
  • The node_modules entry CodeRabbit flagged was local worktree noise and has been removed from the branch; nothing is tracked under that path.

Fixes #10189

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Cursor agent configuration now supports detected executable aliases, mapping the cursor executable to the cursor agent launch command. Launch-command generation rewrites commands based on detected executables and runtime context. Runtime matching accepts default, alias, and override command forms. Preflight and renderer state publish detected executable mappings, while tests cover local, remote, WSL, override, token, and workspace-trust behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address #10189 by supporting cursor agent, preserving cursor-agent, and updating related launch and detection paths.
Out of Scope Changes check ✅ Passed The extra changes support the same Cursor-launching flow and its downstream runtime paths, so they stay in scope.
Title check ✅ Passed The title clearly summarizes the main change: adding support for the Cursor agent subcommand on standard installs.
Description check ✅ Passed The description includes all required template sections and gives substantial implementation, testing, review, security, and notes coverage.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d9e781f0-bfee-4539-944c-d7a75dcc84c5

📥 Commits

Reviewing files that changed from the base of the PR and between 7622b87d72d5e135865d1a161019d376be8c313a and 0516c37359cfd3f590506a5b4de24ca2efc11592.

📒 Files selected for processing (2)
  • src/shared/commit-message-agent-spec.ts
  • src/shared/tui-agent-config.ts

Comment thread src/shared/commit-message-agent-spec.ts Resolved
Comment thread src/shared/tui-agent-config.ts Resolved
@AmethystLiang
AmethystLiang self-requested a review July 23, 2026 18:55
@MumuTW
MumuTW force-pushed the fix/cursor-agent-fallback branch from 0516c37 to 7f7e839 Compare July 25, 2026 18:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fb7303d7-94f5-49b1-ab0c-47a74cd6bae0

📥 Commits

Reviewing files that changed from the base of the PR and between 0516c37359cfd3f590506a5b4de24ca2efc11592 and 7f7e83917fe12abe01b6012d7bdca6526dc05c4e.

📒 Files selected for processing (1)
  • node_modules

Comment thread node_modules Resolved
@nwparker

Copy link
Copy Markdown
Contributor

Maintainer review. I evaluated this against the competing #10200 for issue #10189 and this is the approach we should take. I've recommended closing #10200 in favour of it.

The reasoning: aliases in this codebase only widen detection — getTuiAgentLaunchCommand reads config.launchCmd and nothing else. So an alias-only fix (#10200's shape) makes Cursor appear installed and then fail at launch with the same command not found: cursor-agent from the issue, which is worse than main's honest "not detected". Publishing the matched executable from detection into the launch path, as you've done, is the only place the information actually exists. Scoping remote/SSH and WSL back to the static defaults is also the right call — local PATH says nothing about the remote host, and cursor-agent is the usual server install.

Verification

I confirmed the underlying CLI claims against the real binaries rather than trusting the issue:

  • Cursor.app's bin/cursor routes agent via exec ~/.local/bin/cursor-agent "$@" — it does not shift the token.
  • cursor-agent registers agent as a real subcommand, so the passthrough is harmless: cursor-agent agent --help → Usage: agent agent [options] [prompt...].
  • --model, --force/--yolo, --resume all parse under the subcommand (the terse agent --help output is misleading — flags are inherited).
  • cursor agent models == cursor-agent models, so model discovery is unaffected.
  • Your expectedProcess: 'cursor-agent' note checks out: the launcher uses exec -a "$0", so argv[0] stays .../cursor-agent either way.

Test results in a clean worktree at ec4cda5:

vitest src/shared src/main/ipc                  → 5279 passed | 15 skipped (483 files)
vitest src/renderer/src/lib src/renderer/src/store src/main/text-generation
                                                → 5035 passed |  1 skipped (460 files)
tsc --noEmit -p config/tsconfig.node.json       → clean
tsc --noEmit -p config/tsconfig.tc.web.json     → clean
oxlint <all changed files>                      → clean

Regression checks pass: alias-only → cursor agent; standalone → cursor-agent; both installed → prefers cursor-agent.

Two things to fix before merge

1. Agent attribution misses the alias. resolveBareAgentLaunchCommand (src/main/runtime/orca-runtime.ts:1309) calls getTuiAgentLaunchCommand without detectedCmd:

const defaultLaunchCommand = getTuiAgentLaunchCommand(TUI_AGENT_CONFIG[agent], args.platform, {
  isRemote: args.isRemote
})

so a typed command is only ever compared against cursor-agent. On an alias-only install a user typing cursor agent into a terminal won't be recognised as a Cursor lane, losing the managed hooks and the preflightTrust: 'cursor' preset — which is the same trust-menu problem that preset exists to avoid. Passing the detected executable here (and covering it with a test) closes the loop.

2. cursor agent can trigger a network install. When cursor-agent is absent, the Cursor.app shim runs curl -sS https://cursor.com/install | bash plus a --min-version check on first invocation. That's Cursor's behavior rather than ours, but it means an alias-only launch may block on an unrequested download — worth calling out in the PR body or a code comment so it isn't a surprise during triage.

Also worth noting for whoever merges: the node_modules entry CodeRabbit flagged appears to be worktree noise rather than a committed path — git ls-tree shows nothing tracked, so no action needed.

Nice work on the write-up, particularly documenting why the inverted first attempt was wrong; that saved a good deal of review time.

@nwparker

Copy link
Copy Markdown
Contributor

Follow-up to my review above, on a process point: this repo has a mandatory template at .github/pull_request_template.md, and the current body doesn't carry its sections — which is what CodeRabbit's "Description check" is failing on. Since I've already done the verification work, here's a ready-to-paste body that conforms. Swap in anything you'd say differently; the ## Testing ticks reflect what I ran, so re-check them against your own runs before using.

Conformant PR body
## Summary

Orca hardcoded `cursor-agent` as both `detectCmd` and `launchCmd`. That binary only exists if the user ran the standalone installer (`curl https://cursor.com/install | bash`). A standard Cursor.app install puts `cursor` on PATH and reaches the agent through the `cursor agent` subcommand, so those users got `zsh: command not found: cursor-agent`.

Detection now publishes which executable actually matched on PATH, and the launch path consumes it: `cursor-agent` detected → launch `cursor-agent`; only `cursor` detected → launch `cursor agent`.

## ELI5

Cursor can be installed two different ways, and each one gives the command a different name. Orca only knew one of those names, so for everyone with the other kind of install it kept trying to run a program that wasn't there and gave up. Now Orca looks to see which version you actually have and uses the matching name.

## Proof of fix

An alias-only install (`cursor` on PATH, no `cursor-agent`) detects Cursor and then launches a command the host actually has. On `main` the same scenario detects nothing; with only a detection alias added it detects but still launches the missing binary:

```
AssertionError: expected 'cursor-agent' to be 'cursor agent'

Expected: "cursor agent"
Received: "cursor-agent"
```

With this PR, all three install layouts resolve correctly:

```
✓ alias-only install launches `cursor agent`
✓ standalone install still launches `cursor-agent`
✓ both installed prefers `cursor-agent`

Test Files  1 passed (1)
     Tests  3 passed (3)
```

Verified against the real CLI, since "space-separated subcommand" is the load-bearing claim:

- Cursor.app's `bin/cursor` routes via `exec ~/.local/bin/cursor-agent "$@"` — it does **not** shift the `agent` token.
- That is safe because `cursor-agent` registers `agent` as a genuine subcommand: `cursor-agent agent --help` → `Usage: agent agent [options] [prompt...]`.
- `--model`, `--force`/`--yolo`, `--resume` all parse under the subcommand (the terse subcommand help is misleading — flags are inherited).
- `cursor agent models` and `cursor-agent models` emit identical output, so model discovery is unaffected.

## Proof of no regressions

```
vitest src/shared src/main/ipc                → 5279 passed | 15 skipped (483 files)
vitest src/renderer/src/lib src/renderer/src/store src/main/text-generation
                                              → 5035 passed |  1 skipped (460 files)
tsc --noEmit -p config/tsconfig.node.json     → clean
tsc --noEmit -p config/tsconfig.tc.web.json   → clean
oxlint <all changed files>                    → clean
```

Existing `cursor-agent` users are unaffected: when both binaries are present, detection prefers the primary name, so the launch command is byte-identical to today's. `expectedProcess` stays `cursor-agent` and remains correct — the launcher uses `exec -a "$0"`, so argv[0] is `.../cursor-agent` regardless of entry point, leaving process recognition and title attribution untouched.

Behavior that **does** change, all of it scoped to hosts that previously could not launch Cursor at all:

- An alias-only install now shows Cursor as available (previously hidden) and launches `cursor agent`.
- On such a host, if `cursor-agent` is absent Cursor's own shim may run `curl -sS https://cursor.com/install | bash` on first launch — see Notes.

## Compatibility

- **Platforms:** macOS verified end-to-end against a real dual install (`cursor` + `cursor-agent`, agent `2026.06.02-8c11d9f`), confirming subcommand routing, flag parity and `models` output. Linux uses the same POSIX shim shape. Windows is unaffected by the string change and is handled by existing machinery: `resolveCliCommand` probes `.cmd`/`.exe`/`.bat` explicitly rather than trusting PATHEXT, and `getSpawnArgsForWindows` routes batch shims through `cmd.exe /d /c` as separate argv entries.
- **SSH / remote:** deliberately out of scope. The registry describes this process's PATH, which says nothing about a remote host, so remote and WSL launches keep the static defaults — the right answer for servers, where `cursor-agent` is the usual install. The relay protocol (`src/relay/preflight-handler.ts`) is untouched.
- **Performance:** no hot-path change. The executable map is computed once per detection pass from data preflight already gathers — no additional subprocess spawns — and launch-time lookup is a single object read.

## Screenshots

No visual change.

## Testing

- [x] `oxlint` on all changed files — clean (ran the linter directly rather than the `pnpm lint` wrapper)
- [x] `tsc --noEmit` on both `config/tsconfig.node.json` and `config/tsconfig.tc.web.json` — clean
- [ ] `pnpm test` — **not run in full.** Ran a targeted subset instead: `src/shared`, `src/main/ipc`, `src/renderer/src/lib`, `src/renderer/src/store`, `src/main/text-generation` → 10314 passed, 16 skipped, 0 failed.
- [ ] `pnpm build` — not run.
- [x] Added or updated high-quality tests that would catch regressions

## AI Review Report

Reviewed for correctness, regressions, cross-OS behavior, SSH/remote assumptions, and command-execution safety.

The main risk checked was whether widening detection without widening launch would leave the agent visibly broken — it does, which is why the alias-only approach in #10200 was rejected in favour of this one. Also verified that preferring the primary name keeps existing `cursor-agent` users on a byte-identical command, and that `expectedProcess` stays valid under `exec -a`.

Cross-platform compatibility was explicitly checked for macOS, Linux and Windows: shell resolution of `.cmd`/`.exe`/`.bat` shims, PATHEXT independence, argv construction on Windows batch paths, and the WSL/remote boundary. No shortcuts, labels, or path separators are touched by this change. One gap was flagged and should be fixed before merge — see Notes.

## Security Audit

**Command execution.** The change makes a launch command expand from one token to two, so arg-splitting was the primary concern. Traced the value into every spawn site: `planAgentBinary` splits the default into `binary` + `prefixArgs` and `commit-message-text-generation.ts` passes those to `spawn(spawnCmd, spawnArgs, …)` as an **array** — never concatenated into a shell string, so no interpolation boundary is introduced. On Windows, `getSpawnArgsForWindows` sends batch shims through `cmd.exe /d /c` as separate argv entries and throws `UnsafeWindowsBatchArgumentsError` on unsafe batch syntax.

**Terminal launches** do build a shell string, but that is the pre-existing shared path — `orca claude-teams`, `hermes --tui` and `command-code --trust` are already multi-token — so `cursor agent` adds no new class of risk. Both tokens are hardcoded constants; no user input reaches the command head.

**Input handling / IPC.** The new `preflight:detectAgentExecutables` channel returns a `Partial<Record<TuiAgent, string>>` built entirely from a fixed allowlist of config-declared names, not from user input or filesystem strings, so a hostile PATH cannot inject an arbitrary command through it. The renderer swallows failures and falls back to static defaults.

**Path handling.** No new path construction; detection reuses the existing PATH probe. No auth, secrets, or dependency surface is touched.

**Follow-up:** the `curl | bash` behavior in Notes is Cursor's own shim, not code introduced here, but it is worth documenting since this change can newly reach it.

## Notes

Two items worth resolving:

1. **Agent attribution misses the alias.** `resolveBareAgentLaunchCommand` (`src/main/runtime/orca-runtime.ts:1309`) calls `getTuiAgentLaunchCommand` without `detectedCmd`, so a typed command is only compared against `cursor-agent`. On an alias-only install, a user typing `cursor agent` into a terminal won't be recognised as a Cursor lane and loses managed hooks plus the `preflightTrust: 'cursor'` preset — the very trust-menu problem that preset exists to prevent.
2. **`cursor agent` can trigger a network install.** When `cursor-agent` is absent, Cursor.app's shim runs `curl -sS https://cursor.com/install | bash` plus a `--min-version` check on first invocation, so an alias-only launch may block on a download the user didn't request.

Fixes #10189

@MumuTW

MumuTW commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@nwparker Thanks for the review and for verifying the CLI claims against the real binaries — both items are now fixed on the branch (e3997c7), and the PR body has been rewritten to the template.

1. Agent attribution. Fixed, with one deliberate deviation from what you suggested. Passing the detected executable into getTuiAgentLaunchCommand here would still drop the lane in the dual-install case — which your own finding #2 makes the common end state: Cursor.app's shim installs cursor-agent on first cursor agent invocation, after which detection prefers the primary name and a user still typing cursor agent falls out of the managed lane again.

So resolveBareAgentLaunchCommand now matches every launchCmdByDetectCmd form instead of only the one PATH currently resolves to. Recognition has no "pick exactly one" constraint that launching does, and cursor agent is unambiguously Cursor, so accepting both forms is strictly safer than tracking the detected name. Matching only classifies the lane — a claimed lane still rebuilds its command from config plus the registry, so nothing about what actually gets spawned changes.

Covered by a test that asserts launchAgent: 'cursor', the launch token, and markCursorWorkspaceTrusted — the trust preset being the concrete payoff you called out. Confirmed it fails without the fix (expected undefined to be 'cursor').

2. curl | bash on first launch. Documented in both places: a comment next to launchCmdByDetectCmd in tui-agent-config.ts, and a Notes entry in the PR body.

Re-ran after the change:

vitest --config config/vitest.config.ts \
  src/shared src/main/ipc src/main/runtime/orca-runtime.test.ts \
  src/renderer/src/lib src/renderer/src/store src/main/text-generation
                                              → 11192 passed | 16 skipped | 0 failed (944 files)
tsc --noEmit -p config/tsconfig.node.json     → clean
tsc --noEmit -p config/tsconfig.tc.web.json   → clean
oxlint <changed files>                        → clean

pnpm test in full and pnpm build are still unrun — noted as such in the Testing checklist rather than ticked.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/shared/tui-agent-config.ts (1)

321-351: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not apply local executable detection to remote or WSL launches.

getTuiAgentLaunchCommand resolves detectedCmd before checking opts.isRemote, so a local cursor detection can produce cursor agent for a remote launch. Keep detected-command mappings disabled when opts.isRemote is true; likewise, ensure callers do not invoke applyDetectedTuiAgentExecutable for remote/WSL commands.

Proposed fix
-  const detected = opts?.detectedCmd ? config.launchCmdByDetectCmd?.[opts.detectedCmd] : undefined
+  const detected = opts?.isRemote
+    ? undefined
+    : opts?.detectedCmd
+      ? config.launchCmdByDetectCmd?.[opts.detectedCmd]
+      : undefined

Based on learnings, local detection must not be used for remote or WSL launch resolution.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4cc3b05c-c582-4ea6-bd6e-079f4d126383

📥 Commits

Reviewing files that changed from the base of the PR and between 7f7e83917fe12abe01b6012d7bdca6526dc05c4e and e3997c769cf996a7ccaa3729b892a7c0af35531c.

📒 Files selected for processing (3)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/shared/tui-agent-config.ts

@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@MumuTW

MumuTW commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai Half right, and the half you were right about was the one the diff didn't show. Fixed in 2c2d46ed0.

Remote — the launch path was already isolated, but you were pointing at the wrong consumer.

For launches, the guard is in the caller, not getTuiAgentLaunchCommand: tui-agent-launch-command.ts drops the ambient registry when isRemote, preflight.ts never publishes for WSL or remote detection (detectInstalledAgents returns before the publish for a WSL target; remote goes through detectRemoteAgents, which publishes nothing), and tui-agent-startup.test.ts has covered this since the previous push ("ignores locally detected Cursor aliases for remote launches").

Your proposed diff would also close an intentional door: resolveAgentLaunchCommand takes args.detectedCmd ?? <ambient> precisely so a remote-side detection can supply the executable it matched. Hard-coding isRemote → undefined inside the resolver makes that unreachable.

But planAgentBinary had no remote awareness at all, and that path does reach an SSH host. planCommitMessageGeneration → planAgentBinary → applyDetectedTuiAgentExecutable read the ambient registry, and the result is handed to runRemotePlan for commit messages, PR fields, branch names, and discoverCommitMessageModelsRemote. A client with only Cursor.app therefore planned cursor agent for a host whose install is the standalone cursor-agent. That was a live leak.

And WSL was open in both. A WSL worktree launches with isRemote: false (worktree-activation.ts sets it from repo.connectionId) and platform: 'linux' (agent-launch-platform.ts), so no isRemote guard — yours or mine — could have caught it. On Windows the registry holds cursor (the standalone installer is curl | bash, so cursor-agent is not a Windows hit), and the command runs against the distro's PATH.

Fix: detection now publishes the platform it ran on; getDetectedTuiAgentExecutable(agent, runtime) returns undefined for isRemote or a platform mismatch. Both consumers pass the runtime the command is bound for — planRuntimeForTarget maps target.kind === 'remote' and target.wslDistro, and the launch path passes its launch platform. detectedCmd stays as-is.

Three tests, each confirmed failing with only the corresponding guard removed:

✓ keeps the standalone binary when the plan runs on a host this process never detected
    → expected 'cursor' to be 'cursor-agent'          (with the isRemote guard removed)
✓ still applies the detected alias when the plan runs on the detecting host
✓ ignores Windows-detected Cursor aliases for a WSL launch
    → expected 'cursor agent ...' to be 'cursor-agent ...'   (with the platform guard removed)
vitest src/shared src/main/ipc src/main/runtime/orca-runtime.test.ts
       src/renderer/src/lib src/renderer/src/store src/main/text-generation
                                              → 11195 passed | 16 skipped | 0 failed (944 files)
tsc --noEmit -p config/tsconfig.node.json     → clean
tsc --noEmit -p config/tsconfig.tc.web.json   → clean
oxlint <changed files>                        → clean

Two structural moves came with it: applyDetectedTuiAgentExecutable now lives in shared/detected-agent-command.ts (it is not config, and tui-agent-config.ts was at the max-lines ceiling), and CLIENT_PLATFORM moved to lib/client-platform.ts so the store slice can stamp the detection platform without importing the Zustand store through new-workspace.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@MumuTW You’re right—thanks for the precise correction. My proposed resolver-level guard would have incorrectly disabled intentional remote-side detection supplied through detectedCmd.

The actual issue was the ambient local registry leaking through planAgentBinary into SSH/remote planning, and the platform-provenance solution also correctly closes the separate Windows-to-WSL path mismatch. The targeted tests cover the relevant boundaries well.

🐇✅


✏️ Learnings added
Learnt from: MumuTW
URL: https://github.com/stablyai/orca/pull/10190

Timestamp: 2026-07-27T05:07:50.869Z
Learning: For TUI-agent executable resolution, an explicit `detectedCmd` supplied to `resolveAgentLaunchCommand` may represent remote-side detection and must take precedence over ambient client detection; do not broadly suppress it merely because the target is remote.

Learnt from: MumuTW
URL: https://github.com/stablyai/orca/pull/10190

Timestamp: 2026-07-27T05:07:50.869Z
Learning: Ambient detected TUI-agent executables are local-platform-specific. `getDetectedTuiAgentExecutable(agent, runtime)` must ignore ambient detection for remote runtimes and for platform mismatches (notably Windows client detection versus Linux WSL launches). Consumers such as `planAgentBinary` and terminal launch planning must pass the runtime bound to the target.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/store/slices/detected-agents.ts (1)

61-71: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Prevent stale executable mappings from overwriting the current context.

Lines 61-67 do not retain the detection generation or context key. If a later detection supersedes this request while detectAgentExecutables is in flight, its late result can republish an obsolete alias mapping and make subsequent local Cursor plans launch the wrong binary. Pass the generation/context into this helper and verify it before calling setDetectedTuiAgentExecutables.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9304d811-86d0-48af-9773-31dc2dbb1510

📥 Commits

Reviewing files that changed from the base of the PR and between e3997c769cf996a7ccaa3729b892a7c0af35531c and 2c2d46ed0298fb5bcffd33b717281581b7d791c6.

📒 Files selected for processing (12)
  • src/main/ipc/preflight.ts
  • src/main/text-generation/commit-message-text-generation.ts
  • src/renderer/src/lib/client-platform.ts
  • src/renderer/src/lib/new-workspace.ts
  • src/renderer/src/lib/tui-agent-startup.test.ts
  • src/renderer/src/store/slices/detected-agents.ts
  • src/shared/commit-message-plan.test.ts
  • src/shared/commit-message-plan.ts
  • src/shared/detected-agent-command.ts
  • src/shared/detected-agent-executables.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-launch-command.ts
💤 Files with no reviewable changes (1)
  • src/shared/tui-agent-config.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/renderer/src/store/slices/detected-agents.ts (2)

61-71: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Do not overwrite the host registry with non-host detection results.

detectAgentExecutables(context) returns an empty mapping for WSL/remote contexts, but this callback unconditionally stores {} as the client-host snapshot. After a WSL refresh, local launches can lose the detected cursor → cursor agent mapping and fall back to unavailable cursor-agent. Keep host and non-host detection state separate, or skip publication for non-host contexts.


107-107: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Await executable publication before resolving detection.

Both call sites fire the publication IPC without awaiting it, so callers can immediately build a launch plan before the detected alias is stored. Return/await the publication promise while keeping publication failures non-fatal.

Suggested direction
- publishDetectedAgentExecutables(context)
+ await publishDetectedAgentExecutables(context)

Make publishDetectedAgentExecutables return a Promise<void> and await it from these async detection callbacks.

Also applies to: 154-154


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9304d811-86d0-48af-9773-31dc2dbb1510

📥 Commits

Reviewing files that changed from the base of the PR and between e3997c769cf996a7ccaa3729b892a7c0af35531c and 2c2d46ed0298fb5bcffd33b717281581b7d791c6.

📒 Files selected for processing (12)
  • src/main/ipc/preflight.ts
  • src/main/text-generation/commit-message-text-generation.ts
  • src/renderer/src/lib/client-platform.ts
  • src/renderer/src/lib/new-workspace.ts
  • src/renderer/src/lib/tui-agent-startup.test.ts
  • src/renderer/src/store/slices/detected-agents.ts
  • src/shared/commit-message-plan.test.ts
  • src/shared/commit-message-plan.ts
  • src/shared/detected-agent-command.ts
  • src/shared/detected-agent-executables.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-launch-command.ts
💤 Files with no reviewable changes (1)
  • src/shared/tui-agent-config.ts

@MumuTW

MumuTW commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@MumuTW
MumuTW force-pushed the fix/cursor-agent-fallback branch from 0c70966 to cc9495c Compare July 28, 2026 07:02
@iFwu

iFwu commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

I reproduced a Windows-specific gap in the Source Control AI path that this PR's current compatibility section appears to miss. Interactive Cursor launches may be fine, but non-interactive commit/branch/PR generation is still unable to use either standard Windows Cursor entry point without an override.

Environment

  • Windows, Orca 1.4.160
  • Cursor Agent 2026.07.23-e383d2b
  • Standalone installer provides:
    • %LOCALAPPDATA%\cursor-agent\cursor-agent.cmd
    • %LOCALAPPDATA%\cursor-agent\cursor-agent.ps1
  • A standard Cursor IDE install likewise exposes cursor.cmd

Failure chain

  1. src/shared/commit-message-agent-spec.ts defines Cursor with promptDelivery: 'argv'.
  2. On Windows, resolveCliCommand('cursor-agent') prefers cursor-agent.cmd; the alias path introduced by this PR would similarly resolve cursor to cursor.cmd.
  3. runLocalPlan() sends the generated branch/commit prompt in argv to getSpawnArgsForWindows().
  4. getSpawnArgsForWindows() intentionally rejects any .cmd/.bat argument containing &|<>^"%!\r\n and throws UnsafeWindowsBatchArgumentsError.
  5. Source Control AI prompts are multiline, so the built-in Cursor configuration reaches that rejection by construction.

In a real branch auto-name run, Cursor only worked after overriding the command to invoke cursor-agent.ps1 through an absolute powershell.exe -File ... launcher. After restarting Orca with that override, the same end-to-end branch rename succeeded.

So cursor-agent detected -> cursor-agent and cursor detected -> cursor agent are both still broken for Windows Source Control AI when the resolved executable is a batch shim. I think this PR needs a Windows regression test with a multiline argv prompt and either a Windows-specific safe launch strategy or another path that avoids reparsing arbitrary prompt text through cmd.exe.

Secondary related finding: native Windows command overrides are corrupted

The workaround exposed another issue in planAgentBinary(): command overrides are parsed by tokenizeCustomCommandTemplate(), whose POSIX-style backslash handling is used on Windows too. A normal override beginning with:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

is tokenized as:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe

and then reported as not found on PATH. Replacing backslashes with forward slashes works around it, but Windows Settings should accept native absolute paths. This may deserve a separate fix, but it is directly relevant to the only working override for the batch-shim problem above.

@MumuTW

MumuTW commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @iFwu — this is a great report, and I've confirmed both findings by reading the code paths you named. I want to be precise about what I'm fixing here versus what I'm deliberately deferring.

Both issues are real, and both are pre-existing rather than introduced by this PR.

On the batch-shim failure, your chain is exactly right. getSpawnArgsForWindows rejects rather than escapes, and Cursor's promptDelivery: 'argv' plus multiline Source Control AI prompts means the rejection is reached by construction. The key point is that this already fails on main for cursor-agent: the spec has been argv all along, and cursor-agent.cmd is just as much a batch shim as cursor.cmd. The alias this PR adds resolves to the same rejection, so it neither causes nor worsens the failure. src/main/win32-utils.ts is untouched by this PR.

What this PR does change on Windows is visibility: an alias-only install now surfaces Cursor as available, so the failure is reported at generation time instead of being hidden behind "not detected". That is a fair thing to call out, and I've rewritten the Compatibility section — the previous claim that getSpawnArgsForWindows "routes batch shims through cmd.exe /d /c" was misleading for argv prompts, since it rejects them first. That was my error and it's now corrected to state plainly that Windows Source Control AI remains blocked.

I've added the regression test you asked for (32197f8). It's platform-mocked, so it runs on any host, and it locks three things: both cursor-agent.cmd and cursor.cmd reject a multiline argv prompt, the alias's agent subcommand form rejects it too, and a non-batch powershell.exe -File ...ps1 launcher passes the same prompt through untouched — i.e. the shape of your working override. Any future fix now has to move that assertion deliberately.

On the actual fix, I'm deferring rather than expanding this PR. Choosing between a PowerShell launch strategy and avoiding cmd.exe reparse is a real design decision affecting every argv agent on Windows, not just Cursor. Landing it inside a 21-file CLI-detection PR would make both changes harder to review. The tokenizer backslash bug in tokenizeCustomCommandTemplate is likewise independent — it corrupts any native Windows absolute-path override, regardless of Cursor.

So: two follow-ups, and this PR keeps its original scope of "detect the Cursor CLI that is actually installed", with the Windows limitation now documented honestly instead of glossed over.

One thing I can't do myself: I don't have a Windows environment, so the mocked test is as far as I can verify. When the launch-strategy follow-up lands, I'd be grateful if you could re-run your branch auto-name scenario against it — you're the only person who has demonstrated a working end-to-end path.

@MumuTW

MumuTW commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Follow-ups now filed, both crediting your reproduction:

One design constraint I flagged in #11375 that's worth surfacing here: the backslash handling can't simply be deleted, because the same override string can target a WSL distro or a remote SSH host where POSIX semantics are still correct. The platform that matters is the one the command executes on, not the one running the UI.

This PR's description now links both issues.

Comment thread src/main/ipc/preflight.ts Outdated
Comment on lines +71 to +74
export function _resetPreflightCache(): void {
cached = null
detectedAgentExecutables = {}
hasDetectedAgentExecutables = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test-helper registry leak in _resetPreflightCache

_resetPreflightCache resets the preflight.ts-local copies of detectedAgentExecutables and hasDetectedAgentExecutables, but does not call _resetDetectedTuiAgentExecutables() from detected-agent-executables.ts. Because publishDetectedAgentExecutables writes to both the local copy and the shared module-level registry, any test that triggers detectInstalledAgents will leave residual state in the shared registry for subsequent tests that rely on getDetectedTuiAgentExecutable. Current preflight.test.ts tests don't read the shared registry, so there are no failures today, but a future test that checks the registry after a preflight reset would see stale data.

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes Cursor agent detection and launch for standard Cursor.app installations, where only cursor is on PATH (no standalone cursor-agent). It introduces a process-local executable registry that detection populates and launch commands read, so alias-only installs get cursor agent while standalone installs keep cursor-agent, with no change for existing users.

  • launchCmdByDetectCmd in tui-agent-config.ts: Maps the matched detection alias to its correct launch command; cursor → cursor agent, leaving cursor-agent unchanged.
  • Executable registry (detected-agent-executables.ts): Module-level store populated by preflight:detectAgentExecutables IPC on detection, gated by platform and remote/WSL runtime to avoid cross-host contamination.
  • Sequential publishDetectedAgentExecutables in detected-agents.ts: Store update (detectedAgentIds) is held until executables are published, ensuring synchronous buildAgentStartupPlan callers see the correct launch form immediately after detection; generation and context-key tracking prevents stale races.

Confidence Score: 5/5

Safe to merge. The change is additive for alias-only installs and byte-identical for existing cursor-agent users; all new code paths are covered by tests.

The registry architecture cleanly isolates detection from launch without touching ~25 call sites. The generation + context-key staleness guard prevents stale publishes from overwriting fresh results. Platform gating blocks Windows-detected aliases from leaking into WSL or remote launches. No existing behaviour changes for standalone-binary users.

Files Needing Attention: No files require special attention. The most complex new file is src/renderer/src/store/slices/detected-agents.ts, whose sequential async ordering is deliberate and well-tested.

Important Files Changed

Filename Overview
src/shared/detected-agent-executables.ts New module: process-local registry mapping TuiAgent to matched executable. Platform-gated reads prevent Windows-detected aliases from leaking to WSL/remote launches.
src/shared/detected-agent-command.ts New helper: rewrites the leading executable of a command string using the detection registry. Correctly handles exact match and prefix-with-suffix cases.
src/shared/tui-agent-config.ts Adds launchCmdByDetectCmd field to TuiAgentConfig and populates it for cursor. getTuiAgentLaunchCommand gains a detectedCmd opt that overrides static defaults before launchCmdByPlatform lookup.
src/renderer/src/store/slices/detected-agents.ts Detection flow now awaits publishDetectedAgentExecutables before updating Zustand store; generation + context-key tracking prevents stale results from overwriting fresh ones.
src/main/ipc/preflight.ts Adds detectInstalledAgentExecutables (IPC-exposed, WSL-gated). _resetPreflightCache now also calls _resetDetectedTuiAgentExecutables(), fixing the registry-leak concern from a prior review.
src/shared/tui-agent-detection-commands.ts Adds resolveDetectedTuiAgentExecutables which iterates commands in declaration order so cursor-agent wins over cursor when both are present.
src/shared/tui-agent-launch-command.ts resolveAgentLaunchCommand now reads the detected executable from the registry with remote/platform gating and passes it to getTuiAgentLaunchCommand as detectedCmd.
src/shared/commit-message-plan.ts planAgentBinary applies the detected executable alias and splits on space to extract binary + prefix args. planCommitMessageGeneration accepts an optional AgentExecutionRuntime parameter.
src/main/text-generation/commit-message-text-generation.ts All three generation entry points now pass a runtime derived from the target, correctly scoping WSL vs local vs remote detection.
src/main/runtime/orca-runtime.ts resolveBareAgentLaunchCommand now includes all launchCmdByDetectCmd values as attribution candidates so a typed 'cursor agent' is claimed by the managed Cursor lane.

Reviews (3): Last reviewed commit: "test(win32): lock batch-shim rejection f..." | Re-trigger Greptile

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

@MumuTW
MumuTW force-pushed the fix/cursor-agent-fallback branch from 7ac3b3b to b1856b8 Compare August 1, 2026 02:45
@MumuTW

MumuTW commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main and merged the branch's newer cursor commits. Local verification: tsc clean + 1106 tests passed (tui-agent-startup, orca-runtime, commit-message). The PR Checks workflow needs approval to run on the new head — could you approve? Thanks!

1 similar comment
@MumuTW

MumuTW commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main and merged the branch's newer cursor commits. Local verification: tsc clean + 1106 tests passed (tui-agent-startup, orca-runtime, commit-message). The PR Checks workflow needs approval to run on the new head — could you approve? Thanks!

@AmethystLiang
AmethystLiang removed their request for review August 11, 2026 05:24
@nwparker nwparker removed the P1 label Aug 19, 2026
@MumuTW
MumuTW force-pushed the fix/cursor-agent-fallback branch from 772860a to 312071c Compare September 10, 2026 12:30
@MumuTW

MumuTW commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (f2d5711b2d) as a clean linear branch — the earlier merge commits are gone, along with the stray node_modules symlink and the stale-base reversions they had pulled in.

Upstream split most of the files this touched, so each change now lives where that code is today (main/preflight/agent-detection.ts, preload/api/preflight-*, local-detected-agent-state.ts, runtime-agent-launch-resolution.ts, source-control-text-generation-requests.ts). Executable publication was adapted to the new per-context detection state: results are exposed only after the matched executables are published, and stale publications are dropped. Two small follow-ups: detected-executable helpers split out to stay under max-lines, and the Cursor catalog's listModels stays on cursor-agent models (discovery already resolves the alias via planAgentBinary).

pnpm tc clean; 4668 tests pass across tui-agent-startup, orca-runtime, commit-message, preflight and store slices. @nwparker could you take another look and approve the checks? Thanks!

MumuTW and others added 11 commits September 12, 2026 13:44
Orca hardcoded `cursor-agent` for detection and launch. Cursor.app only puts
`cursor` on PATH and reaches the agent via `cursor agent`, so standard IDE
installs failed with `command not found: cursor-agent`.

`detectCmdAliases` alone cannot fix this: aliases widen detection while launch
commands stay static, so an alias-only install would be detected and then
launched with a binary it does not have. Detection is the only place that knows
which executable is really on PATH, so it now publishes that per agent and the
launch path prefers it.

- `launchCmdByDetectCmd` maps a matched alias to its launch form; Cursor keeps
  `cursor-agent` as primary and maps `cursor` -> `cursor agent`.
- Detection resolves the matched executable and publishes it to a process-local
  registry read by `resolveAgentLaunchCommand` and `planAgentBinary`, so the
  ~25 `buildAgentStartupPlan` call sites need no new argument.
- Remote and WSL launches ignore the registry and keep the static defaults —
  the local PATH says nothing about the host that will run the command.

Existing `cursor-agent` installs, including SSH hosts, are unchanged.
resolveBareAgentLaunchCommand only compared a typed command against the
single launch form the current PATH resolves to, so `cursor agent` typed
into a terminal was never recognised as the Cursor lane and lost its
managed hooks and the preflightTrust preset. Match every alias launch
form instead — recognition is broader than launch by design, and
detection can flip under us once Cursor's shim self-installs
`cursor-agent`.

Also document that the `cursor agent` form can trigger that install.
…ted them

The detection registry describes one process's PATH, but two consumers read it
without knowing where the command will actually run:

- `planAgentBinary` (commit message / PR fields / branch name / model discovery)
  had no remote awareness at all, so an alias-only Cursor install on the client
  planned `cursor agent` for plans shipped to an SSH host via `runRemotePlan`.
- A WSL launch is never `isRemote`, so the launch path's remote guard did not
  cover it: a Windows-detected `cursor` became `cursor agent` inside a distro
  whose standalone `cursor-agent` is the binary that exists.

Detection now publishes the platform it ran on, and both consumers pass the
runtime the command is bound for; a mismatch falls back to the static
`launchCmd`. The explicit `detectedCmd` argument is untouched, so a future
remote-side detection can still supply its own executable.

Moves `applyDetectedTuiAgentExecutable` to its own leaf module (it is not
config) and `CLIENT_PLATFORM` to `lib/client-platform` so the store slice can
read it without importing the Zustand store.
Source Control AI delivers Cursor prompts in argv and those prompts are
multiline by construction, so both standard Windows Cursor entry points
hit UnsafeWindowsBatchArgumentsError before cmd.exe runs. Document that
the detected-executable alias does not change this outcome, and that a
non-batch launcher passes the same prompt through untouched.
…-lines

The rebase onto current main landed these additions in files upstream had
already grown close to the 300-line limit. Move planAgentBinary, the host
executable snapshot, and the WSL-aware executable detector into their own
modules; behavior is unchanged.
Discovery runs through planAgentBinary, which already maps cursor-agent to
the detected alias; the catalog string is only a presence gate.
@MumuTW
MumuTW force-pushed the fix/cursor-agent-fallback branch from 312071c to 0c5abe1 Compare September 12, 2026 05:46
@MumuTW

MumuTW commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (fa3d29fa1) — all 11 commits replayed cleanly except one additive conflict in commit-message-plan.test.ts (upstream's new Antigravity cases kept alongside the cursor-agent detection test).

@MumuTW

MumuTW commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Closing this PR. I am not going to keep iterating contribution PRs here; if a report is useful I will file an issue instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Hardcoded 'cursor-agent' binary fails with 'command not found: cursor-agent' for standard Cursor installations

5 participants