fix(cursor-agent): enable headless CLI dispatch end-to-end (-p --trust --approve-mcps --force + Windows .cmd shim resolution)
## Summary
Enable specify workflow run to dispatch the cursor-agent CLI headlessly end-to-end on Windows, matching the way it already dispatches claude / codex / gemini. Existing in-IDE skill flow (via .cursor/skills/speckit-*/SKILL.md) is preserved exactly — this PR only adds the CLI dispatch path on top.
Fixes #2629.
Integration config (final): requires_cli remains False so specify init --ai cursor-agent works without the CLI installed (IDE/skills flow unchanged). Workflow dispatch is enabled by overriding build_exec_args() — the same pattern as CopilotIntegration — with CLI presence enforced at dispatch time via shutil.which, not as a hard specify init precheck.
Problem
Before this PR, specify workflow run speckit --input integration=cursor-agent ... fails immediately with:
Cannot dispatch command 'speckit.specify': integration 'cursor-agent' CLI not found or not installed.
Install the CLI tool or check 'specify integration list'.
even when cursor-agent is installed and healthy (cursor-agent --version returns 2026.05.16-0338208).
Three separate gaps each independently block the headless path; this PR fixes all three.
Commits
Functional fixes (three gaps)
1) 1c55988 fix(cursor-agent): enable CLI dispatch via -p --trust headless mode
CursorAgentIntegration had requires_cli: False and did not override build_exec_args, so SkillsIntegration.build_exec_args returned None, the dispatcher in workflows/steps/command/__init__.py::_try_dispatch returned None, and the misleading CLI-missing error was surfaced. The CLI is actually fully headless-capable:
-p / --print— print mode, "Has access to all tools, including write and shell"--output-format text | json | stream-json--model <name>--trust— "Trust the current workspace without prompting (only works with --print/headless mode)"
Without --trust, the CLI exits non-zero with âš Workspace Trust Required.
This commit (superseded on requires_cli by ff07cc0 below — kept here for history):
config["install_url"]:None→https://docs.cursor.com/en/cli/overview- First override of
build_exec_argsto emit[self.key, "-p", "--trust", prompt, …](later commits add--approve-mcps --force;ff07cc0setsrequires_cliback toFalsefor IDE-first init).
2) 454d3d0 fix(integrations): resolve .cmd/.bat shims before subprocess.run
After commit (1), the dispatcher still failed on Windows with FileNotFoundError [WinError 2]. Root cause:
shutil.which("cursor-agent")returnscursor-agent.CMD(honoringPATHEXT).subprocess.run(["cursor-agent", ...])callsCreateProcess, which does not consultPATHEXT, so the bare command name fails to launch.
The same bug affects every .cmd/.bat-wrapped CLI on Windows (verified for codex as well; only .exe CLIs like claude were unaffected).
Fix in IntegrationBase.dispatch_command: resolve exec_args[0] via shutil.which before subprocess.run. No-op on POSIX (no PATHEXT to consult); transparent fix on Windows.
3) 595bcab fix(cursor-agent): inject --approve-mcps --force for headless MCP/tool access
After commits (1)+(2), subprocess.run succeeds and cursor-agent starts, but the first MCP call (e.g. to read a DingTalk PRD) fails with The tool call was rejected. I can't retrieve the document name without permission to call the tool. Two more flags are needed:
--approve-mcps— without it, every MCP server staysnot loaded (needs approval)and tool calls are silently dropped.--force— without it, the agent halts on the first tool-call approval prompt; the workflow returns a misleading non-zero exit. With it, cursor-agent matches the implicit "trusted environment" semantics thatclaude -pandcodex --execalready have by default — the right semantics for an unattendedspecify workflow run.
Final argv after all three commits:
args = [self.key, "-p", "--trust", "--approve-mcps", "--force", prompt]
if model: args.extend(["--model", model])
if output_json: args.extend(["--output-format", "json"])
Review feedback (ff07cc0, 422b250, 6e3819c)
4) ff07cc0 refactor(cursor-agent): express dispatch support via build_exec_args() instead of requires_cli
Addresses Copilot review: keep requires_cli: False so specify init does not hard-fail for IDE-only users. Remove the requires_cli guard inside build_exec_args(); dispatch support is signalled by overriding build_exec_args() (mirrors CopilotIntegration). Headless argv shape unchanged: -p --trust --approve-mcps --force.
5) 422b250 test(cursor-agent): use urlparse hostname check and cover dispatch without requires_cli
Addresses CodeQL: replace "cursor.com" in url substring check with urlparse(...).hostname comparison; add regression test that dispatch works with requires_cli=False.
6) 6e3819c — docstring: mention --approve-mcps --force in module-level dispatch description (Copilot doc consistency).
End-to-end verification (real DingTalk PRD, just a URL as input)
Repro on Windows 10 + cursor-agent 2026.05.16-0338208:
cd D:\Code\MBM\MBM-Backend # real Maven multi-module Java project
specify workflow run speckit `
--input "spec=https://alidocs.dingtalk.com/i/nodes/<dingtalk-prd-node>" `
--input "integration=cursor-agent" `
--input "scope=full"
Two independent runs (df8c4b9b, 388d3c15) both reach the review-spec gate:
specify step:
dispatched=true, exit_code=0, status=completed, duration ~156s / ~147s
agent behaviour (autonomously, from a URL-only spec input):
- calls dingtalk-doc MCP get_document_content to fetch the PRD
- reads project constitution + existing specs/ layout
- decides specs/ subpath itself (e.g. specs/tooling/mold-assembly/202605/<feature>/)
- produces spec.md (31.5 KB) + checklists/requirements.md
- updates .specify/feature.json and specs/menu-dictionary.md
- marks 3 [NEEDS CLARIFICATION] items for Gate 1 review
next step (review-spec gate):
(gate started; status would be `paused` on a normal completion)
(Both runs above were eventually cancelled by Ctrl+C while the gate step was just starting, which surfaced an [Errno 22] Invalid argument from the interrupted subprocess.run. That was an artifact of my cancellation, not a gate-step bug — review-spec is a gate step and its designed terminal status is paused. Independent of this PR either way.)
Backward compatibility
- In-IDE skill flow (
.cursor/skills/speckit-*/SKILL.md,--skillsdefault) — unchanged. multi_install_safe,context_file,registrar_config,options()— unchanged.- POSIX behaviour —
shutil.whichlookup is a no-op for already-absolute exec_args[0], and the--approve-mcps --forceflags exist on Linux/macOS cursor-agent identically. catalog.json,workflow.yml, templates — untouched.- Other integrations (
claude,codex,gemini) — theirbuild_exec_argspaths are not touched; the only shared change isbase.py::dispatch_commandadding theshutil.whichshim resolution, which only takes effect whenshutil.whichreturns a different path than the input (i.e..cmd/.batshim case on Windows).
Testing
$ uv run python -m pytest tests/integrations/test_integration_cursor_agent.py -v
============================= 43 passed in 3.72s ==============================
$ uv run python -m pytest -q
========== 12 failed, 2867 passed, 109 skipped in 372.85s (0:06:12) ===========
- 44 cursor-agent integration tests pass (CI green on this branch).
- New tests pin:
requires_cli is False(IDE-first init) andinstall_urlis set; dispatch viabuild_exec_args()overrideinstall_urlhostname validated withurlparse(not substring match)- Exact argv layout
[cursor-agent, -p, --trust, --approve-mcps, --force, …](default + text-output + with-model variants) - All four mandatory headless flags are always present together
- Hyphenated skill invocation (
/speckit-plannot/speckit.plan) .cmdshim resolution: subprocess receives fullcursor-agent.CMDpath, not barecursor-agent- Passthrough when
shutil.whichreturnsNone
- Existing
tests/test_workflows.py::TestCommandStep::test_dispatch_with_mock_cliandtest_dispatch_failure_returns_failed_statusupdated to patchshutil.whichat thebase.pylayer (was previously only patching the dispatcher layer, which made the test environment-sensitive — passed on CI with noclaudeon PATH, failed locally withclaudeinstalled). - Full repo: 2867 passed, 0 regressions from this PR. The 12 remaining pre-existing failures are unrelated Windows
symlinkprivilege issues (WinError 1314) requiring elevated runner — not introduced or affected by this PR.
Out of scope (deliberately)
- The misleading
"CLI not found or not installed. Install the CLI tool."error message itself (it conflates 5 distinct dispatch failure modes into one). Worth a separate PR to split per-failure-mode messages — happy to do that as a follow-up if maintainers want. - Adding
cursor-agentto bundledspeckitworkflow'srequires.integrations.anylist (currently["copilot", "claude", "gemini"]). Not strictly required —specify workflow rundoes not enforce that list strictly today — but worth a follow-up sospecify workflow info speckitis consistent with the actual support matrix. docs/reference/integrations.mdpage for cursor-agent (none exists today; happy to add if wanted).- Adding a
speckit.git.featurestep tospeckitworkflow.yml (current workflow doesn't auto-create feature branches; that's by design but worth surfacing as an opt-in for teams that want branch-per-feature).
Please address code scanning resulsts
Thanks for the review! I've addressed both points in ff07cc0 + 422b250:
- Copilot (requires_cli): reverted
requires_clitoFalsesospecify initno longer hard-fails for IDE-only users. Dispatch support is now expressed by overridingbuild_exec_args()(same shape asCopilotIntegration), and therequires_cliguard inbuild_exec_args()is removed. - CodeQL (URL substring): replaced the
"cursor.com" in urlsubstring check with an exacturlparse(...).hostnamecomparison, plus a regression test.
pytest tests/integrations/test_integration_cursor_agent.py is green (44 passed) and ruff check src/ is clean. Could you re-run the workflows when you get a chance?
Please address Copilot feedback
This autofix suggestion was applied.
Can you please update the PR description as per Copilot feedback
@mnriem Updated the PR description to match the current implementation:
requires_clistaysFalse(IDE-firstspecify init; dispatch viabuild_exec_args()override, same asCopilotIntegration).- Documented review commits
ff07cc0,422b250, and6e3819c(docstring flags). - Corrected the Testing section (no longer claims
requires_cli is True).
CI on 6e3819c is all green. Ready for another look when you have time.