Skip to content

Commit 1c55988

Browse files
刘一cursoragent
andcommitted
fix(cursor-agent): enable CLI dispatch via -p --trust headless mode
Restores the ability for ``specify workflow run`` to dispatch the cursor-agent CLI, complementing the existing in-IDE skill flow. Without this fix, ``specify workflow run speckit --input integration=cursor-agent ...`` fails with a misleading ``CLI not found or not installed`` error even when the CLI is installed (since cursor-agent had ``requires_cli=False`` and an unset ``build_exec_args``). The cursor-agent CLI (>= 2026.05.16) supports headless execution via ``-p`` (print mode with full tool access including write/shell) and ``--trust`` (bypass Workspace Trust prompt). Without ``--trust`` the CLI exits non-zero in non-TTY contexts (verified locally). Changes to ``src/specify_cli/integrations/cursor_agent/__init__.py``: * ``config.requires_cli``: ``False`` -> ``True`` * ``config.install_url``: ``None`` -> Cursor CLI docs URL * Override ``build_exec_args()`` to emit ``[cursor-agent, -p, --trust, <prompt>, ...]`` with optional ``--model`` and ``--output-format json`` flags, mirroring the shape used by ``claude``/``codex``/``gemini``. Tests: * 34 existing cursor-agent tests still pass. * 6 new tests in ``TestCursorAgentCliDispatch`` pin ``requires_cli``, ``install_url``, and the exact argv shape (default, text-output, with-model, and the hyphenated skill invocation form ``/speckit-<name>``). * Full repo: 1085 / 1085 passed, no regressions. Fixes github#2629 Co-authored-by: Cursor <[email protected]>
1 parent 51e6a14 commit 1c55988

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

‎src/specify_cli/integrations/cursor_agent/__init__.py‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
Cursor Agent uses the ``.cursor/skills/speckit-<name>/SKILL.md`` layout.
44
Commands are deprecated; ``--skills`` defaults to ``True``.
5+
6+
CLI dispatch via ``cursor-agent -p --trust <prompt>`` is supported so
7+
``specify workflow run`` can drive cursor-agent headlessly, in addition
8+
to the existing in-IDE skill flow.
59
"""
610

711
from __future__ import annotations
@@ -15,8 +19,8 @@ class CursorAgentIntegration(SkillsIntegration):
1519
"name": "Cursor",
1620
"folder": ".cursor/",
1721
"commands_subdir": "skills",
18-
"install_url": None,
19-
"requires_cli": False,
22+
"install_url": "https://docs.cursor.com/en/cli/overview",
23+
"requires_cli": True,
2024
}
2125
registrar_config = {
2226
"dir": ".cursor/skills",
@@ -28,6 +32,29 @@ class CursorAgentIntegration(SkillsIntegration):
2832
context_file = ".cursor/rules/specify-rules.mdc"
2933
multi_install_safe = True
3034

35+
def build_exec_args(
36+
self,
37+
prompt: str,
38+
*,
39+
model: str | None = None,
40+
output_json: bool = True,
41+
) -> list[str] | None:
42+
"""Build CLI arguments for non-interactive ``cursor-agent`` execution.
43+
44+
Uses ``-p`` (print/headless mode, which gives access to all
45+
tools including write and shell) plus ``--trust`` (bypass the
46+
Workspace Trust prompt — mandatory for headless execution; the
47+
CLI exits non-zero without it).
48+
"""
49+
if not self.config or not self.config.get("requires_cli"):
50+
return None
51+
args = [self.key, "-p", "--trust", prompt]
52+
if model:
53+
args.extend(["--model", model])
54+
if output_json:
55+
args.extend(["--output-format", "json"])
56+
return args
57+
3158
@classmethod
3259
def options(cls) -> list[IntegrationOption]:
3360
return [

‎tests/integrations/test_integration_cursor_agent.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,55 @@ def test_ai_cursor_agent_without_ai_skills_auto_promotes(self, tmp_path):
106106
assert result.exit_code == 0, f"init --ai cursor-agent failed: {result.output}"
107107
assert (target / ".cursor" / "skills" / "speckit-plan" / "SKILL.md").exists()
108108

109+
110+
class TestCursorAgentCliDispatch:
111+
"""Verify the CLI dispatch path for cursor-agent (issue #2629).
112+
113+
The ``cursor-agent`` CLI supports headless execution via ``-p`` (with
114+
full tool access including write/shell) and requires ``--trust`` to
115+
bypass the Workspace Trust prompt. These tests pin the exact argv
116+
shape that the workflow runner will use.
117+
"""
118+
119+
def test_requires_cli_is_true(self):
120+
i = get_integration("cursor-agent")
121+
assert i.config.get("requires_cli") is True
122+
123+
def test_install_url_is_set(self):
124+
i = get_integration("cursor-agent")
125+
url = i.config.get("install_url")
126+
assert url is not None
127+
assert "cursor.com" in url
128+
129+
def test_build_exec_args_default_includes_trust_and_json(self):
130+
i = get_integration("cursor-agent")
131+
args = i.build_exec_args("/speckit-specify some-feature")
132+
assert args == [
133+
"cursor-agent", "-p", "--trust",
134+
"/speckit-specify some-feature",
135+
"--output-format", "json",
136+
]
137+
138+
def test_build_exec_args_text_output_omits_format(self):
139+
i = get_integration("cursor-agent")
140+
args = i.build_exec_args("/speckit-plan", output_json=False)
141+
assert args == [
142+
"cursor-agent", "-p", "--trust", "/speckit-plan",
143+
]
144+
145+
def test_build_exec_args_with_model(self):
146+
i = get_integration("cursor-agent")
147+
args = i.build_exec_args(
148+
"/speckit-specify", model="sonnet-4-thinking", output_json=False
149+
)
150+
assert args == [
151+
"cursor-agent", "-p", "--trust", "/speckit-specify",
152+
"--model", "sonnet-4-thinking",
153+
]
154+
155+
def test_build_command_invocation_uses_hyphenated_skill_name(self):
156+
"""SkillsIntegration: /speckit-plan (not /speckit.plan)."""
157+
i = get_integration("cursor-agent")
158+
assert i.build_command_invocation("speckit.plan", "feature-x") == "/speckit-plan feature-x"
159+
assert i.build_command_invocation("plan") == "/speckit-plan"
160+

0 commit comments

Comments
 (0)