Skip to content

feat(cursor): add support for Cursor Agent CLI integration - #236

Merged
tiann merged 5 commits into
tiann:mainfrom
hairyf:feature/support-cursor-cli
Mar 3, 2026
Merged

feat(cursor): add support for Cursor Agent CLI integration#236
tiann merged 5 commits into
tiann:mainfrom
hairyf:feature/support-cursor-cli

Conversation

@hairyf

@hairyf hairyf commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Closes #207

Summary

Add cursor-cli support to HAPI. Cursor CLI usage is similar to claude code, gemini, codex - this PR enables \hapi cursor\ to run Cursor Agent with remote control via web/phone.

Changes

  • Add \cursor\ to AgentFlavor in shared/modes
  • Add \cursor\ CLI subcommand and cursor runner (mirroring codex structure)
  • Update agentFlavorUtils for cursor
  • Update docs and help text

hairyf added 2 commits March 2, 2026 11:10
- Introduced new command `hapi cursor` to start Cursor Agent sessions.
- Added functionality for resuming sessions and managing permission modes.
- Updated documentation to include Cursor Agent usage and installation instructions.
- Enhanced existing codebase to accommodate Cursor as a recognized agent flavor.
- Implemented local and remote session handling for Cursor Agent.

This update expands HAPI's capabilities by integrating support for the Cursor Agent, allowing users to leverage its features alongside existing agents.
…on of Cursor Agent CLI support. This cleanup helps streamline project documentation and reflects the completion of the associated tasks.
i += 1
continue
}
if (arg === '--started-by') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[MAJOR] Bug: internal flag forwarded to Cursor CLI

Why this is a problem: runner appends --hapi-starting-mode remote for spawned sessions, but the cursor command does not consume it. That flag is then forwarded to agent via cursorArgs, and Cursor CLI does not define it, so runner-spawned cursor sessions can fail to start.

Suggested fix:

} else if (arg === '--hapi-starting-mode') {
    const value = commandArgs[++i]
    if (value !== 'local' && value !== 'remote') {
        throw new Error('Invalid --hapi-starting-mode (expected local or remote)')
    }
    // consume only; do not forward to cursorArgs
    continue
}

</label>
<div className="flex gap-3">
{(['claude', 'codex', 'gemini', 'opencode'] as const).map((agentType) => (
{(['claude', 'codex', 'cursor', 'gemini', 'opencode'] as const).map((agentType) => (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[MAJOR] Bug: web spawn offers Cursor while remote mode exits immediately

Why this is a problem: web new-session flow is remote-start, but the Cursor remote launcher exits immediately with a "not supported" message. Exposing Cursor in the web selector creates a broken flow where newly spawned sessions terminate right away.

Suggested fix:

{(['claude', 'codex', 'gemini', 'opencode'] as const).map((agentType) => (

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings

  • [Major] Internal runner flag forwarded to Cursor CLI — runner adds --hapi-starting-mode, cursor command forwards unknown args to agent; likely startup failure for runner-spawned sessions. Evidence cli/src/commands/cursor.ts:24-75, cli/src/runner/run.ts:345.
    Suggested fix:
    } else if (arg === '--hapi-starting-mode') {
        const value = commandArgs[++i]
        if (value !== 'local' && value !== 'remote') {
            throw new Error('Invalid --hapi-starting-mode (expected local or remote)')
        }
        // consume only; do not forward to cursorArgs
        continue
    }
  • [Major] Web spawn offers Cursor while remote mode exits immediately — Cursor remote launcher always exits; exposing Cursor in web selector creates broken remote-start flow. Evidence web/src/components/NewSession/AgentSelector.tsx:16-33, cli/src/cursor/cursorRemoteLauncher.ts:26-43, cli/src/runner/run.ts:345.
    Suggested fix:
    {(['claude', 'codex', 'gemini', 'opencode'] as const).map((agentType) => (

Summary

  • 2 major issues; runner-spawned cursor sessions can fail; web spawn path broken for cursor.

Testing

  • Not run (automation)

HAPI Bot

- Consume --hapi-starting-mode in cursor command (do not forward to agent)
- Implement cursorRemoteLauncher: spawn agent -p with stream-json, --trust
- Add cursorEventConverter for NDJSON parsing (system/assistant/tool_call/result)
- Multi-turn via --resume session_id
- Update docs: cursor supports both local and remote modes

Made-with: Cursor
@hairyf

hairyf commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

Reply to review

Thanks for the review. Addressed both issues in 602a9c1:

1. --hapi-starting-mode forwarded to Cursor CLI

Fixed. The cursor command now consumes --hapi-starting-mode and its value (local/remote) without forwarding to the agent CLI. See cli/src/commands/cursor.ts.

2. Web spawn offers Cursor while remote mode exits immediately

Fixed. Implemented full Cursor remote mode:

  • cursorRemoteLauncher now spawns agent -p "message" --output-format stream-json --trust
  • Parses NDJSON from stdout (system/init, assistant, tool_call, result)
  • Multi-turn via --resume <session_id>
  • Cursor in the web selector now works for remote spawn

Cursor Agent CLI supports --print + --output-format stream-json for programmatic use (per Cursor docs).

@tiann

tiann commented Mar 2, 2026

Copy link
Copy Markdown
Owner

@tiann review again

@github-actions

github-actions Bot commented Mar 2, 2026

Copy link
Copy Markdown

Findings

  1. Cursor model mode UI shown for cursor sessions; HappyComposer uses !isCodexFamilyFlavor so cursor gets Claude model toggle/shortcut and modelMode updates even though cursor has no model modes. web/src/components/AssistantChat/HappyComposer.tsx:325-401, web/src/lib/agentFlavorUtils.ts:1-3.
  2. Cursor local resume never updates metadata/sessionId; cursorLocalLauncher does not pass onChatFound, so session.onSessionFound not called and cursorSessionId stays unset. Remote switch can’t resume same chat. cli/src/cursor/cursorLocalLauncher.ts:30-38, cli/src/cursor/cursorLocal.ts:23-38.
  3. Duplicate cursor CLI flags in local mode: cursorCommand forwards --resume/--mode/--model/--yolo into cursorArgs, then cursorLocal adds them again, so agent gets duplicates. cli/src/commands/cursor.ts:37-63, cli/src/cursor/cursorLocal.ts:35-55.

Tests

  • not run (review only)

HAPI Bot

…ate flags

- HappyComposer: use isClaudeFlavor for model mode (cursor has no model modes)
- cursorLocalLauncher: call onSessionFound for resume so cursorSessionId in metadata
- cursorCommand: do not forward parsed flags to cursorArgs (avoid duplicates)

Made-with: Cursor
@tiann
tiann merged commit c9be289 into tiann:main Mar 3, 2026
1 check passed
Unintendedz referenced this pull request in Unintendedz/hapii Mar 3, 2026
* feat(cursor): add support for Cursor Agent CLI integration

- Introduced new command `hapi cursor` to start Cursor Agent sessions.
- Added functionality for resuming sessions and managing permission modes.
- Updated documentation to include Cursor Agent usage and installation instructions.
- Enhanced existing codebase to accommodate Cursor as a recognized agent flavor.
- Implemented local and remote session handling for Cursor Agent.

This update expands HAPI's capabilities by integrating support for the Cursor Agent, allowing users to leverage its features alongside existing agents.

* Remove TODO.md file as it is no longer needed following the integration of Cursor Agent CLI support. This cleanup helps streamline project documentation and reflects the completion of the associated tasks.

* feat(cursor): implement remote mode and fix --hapi-starting-mode

- Consume --hapi-starting-mode in cursor command (do not forward to agent)
- Implement cursorRemoteLauncher: spawn agent -p with stream-json, --trust
- Add cursorEventConverter for NDJSON parsing (system/assistant/tool_call/result)
- Multi-turn via --resume session_id
- Update docs: cursor supports both local and remote modes

Made-with: Cursor

* fix: type error

* fix(cursor): address PR review - model UI, sessionId metadata, duplicate flags

- HappyComposer: use isClaudeFlavor for model mode (cursor has no model modes)
- cursorLocalLauncher: call onSessionFound for resume so cursorSessionId in metadata
- cursorCommand: do not forward parsed flags to cursorArgs (avoid duplicates)

Made-with: Cursor
jasonczc pushed a commit to jasonczc/haqi that referenced this pull request Mar 15, 2026
* feat(cursor): add support for Cursor Agent CLI integration

- Introduced new command `hapi cursor` to start Cursor Agent sessions.
- Added functionality for resuming sessions and managing permission modes.
- Updated documentation to include Cursor Agent usage and installation instructions.
- Enhanced existing codebase to accommodate Cursor as a recognized agent flavor.
- Implemented local and remote session handling for Cursor Agent.

This update expands HAPI's capabilities by integrating support for the Cursor Agent, allowing users to leverage its features alongside existing agents.

* Remove TODO.md file as it is no longer needed following the integration of Cursor Agent CLI support. This cleanup helps streamline project documentation and reflects the completion of the associated tasks.

* feat(cursor): implement remote mode and fix --hapi-starting-mode

- Consume --hapi-starting-mode in cursor command (do not forward to agent)
- Implement cursorRemoteLauncher: spawn agent -p with stream-json, --trust
- Add cursorEventConverter for NDJSON parsing (system/assistant/tool_call/result)
- Multi-turn via --resume session_id
- Update docs: cursor supports both local and remote modes

Made-with: Cursor

* fix: type error

* fix(cursor): address PR review - model UI, sessionId metadata, duplicate flags

- HappyComposer: use isClaudeFlavor for model mode (cursor has no model modes)
- cursorLocalLauncher: call onSessionFound for resume so cursorSessionId in metadata
- cursorCommand: do not forward parsed flags to cursorArgs (avoid duplicates)

Made-with: Cursor
(cherry picked from commit c9be289)
SeeFlowerX pushed a commit to SeeFlowerX/hapi that referenced this pull request Apr 1, 2026
* feat(cursor): add support for Cursor Agent CLI integration

- Introduced new command `hapi cursor` to start Cursor Agent sessions.
- Added functionality for resuming sessions and managing permission modes.
- Updated documentation to include Cursor Agent usage and installation instructions.
- Enhanced existing codebase to accommodate Cursor as a recognized agent flavor.
- Implemented local and remote session handling for Cursor Agent.

This update expands HAPI's capabilities by integrating support for the Cursor Agent, allowing users to leverage its features alongside existing agents.

* Remove TODO.md file as it is no longer needed following the integration of Cursor Agent CLI support. This cleanup helps streamline project documentation and reflects the completion of the associated tasks.

* feat(cursor): implement remote mode and fix --hapi-starting-mode

- Consume --hapi-starting-mode in cursor command (do not forward to agent)
- Implement cursorRemoteLauncher: spawn agent -p with stream-json, --trust
- Add cursorEventConverter for NDJSON parsing (system/assistant/tool_call/result)
- Multi-turn via --resume session_id
- Update docs: cursor supports both local and remote modes

Made-with: Cursor

* fix: type error

* fix(cursor): address PR review - model UI, sessionId metadata, duplicate flags

- HappyComposer: use isClaudeFlavor for model mode (cursor has no model modes)
- cursorLocalLauncher: call onSessionFound for resume so cursorSessionId in metadata
- cursorCommand: do not forward parsed flags to cursorArgs (avoid duplicates)

Made-with: Cursor
SeeFlowerX pushed a commit to SeeFlowerX/hapi that referenced this pull request Apr 1, 2026
* feat(cursor): add support for Cursor Agent CLI integration

- Introduced new command `hapi cursor` to start Cursor Agent sessions.
- Added functionality for resuming sessions and managing permission modes.
- Updated documentation to include Cursor Agent usage and installation instructions.
- Enhanced existing codebase to accommodate Cursor as a recognized agent flavor.
- Implemented local and remote session handling for Cursor Agent.

This update expands HAPI's capabilities by integrating support for the Cursor Agent, allowing users to leverage its features alongside existing agents.

* Remove TODO.md file as it is no longer needed following the integration of Cursor Agent CLI support. This cleanup helps streamline project documentation and reflects the completion of the associated tasks.

* feat(cursor): implement remote mode and fix --hapi-starting-mode

- Consume --hapi-starting-mode in cursor command (do not forward to agent)
- Implement cursorRemoteLauncher: spawn agent -p with stream-json, --trust
- Add cursorEventConverter for NDJSON parsing (system/assistant/tool_call/result)
- Multi-turn via --resume session_id
- Update docs: cursor supports both local and remote modes

Made-with: Cursor

* fix: type error

* fix(cursor): address PR review - model UI, sessionId metadata, duplicate flags

- HappyComposer: use isClaudeFlavor for model mode (cursor has no model modes)
- cursorLocalLauncher: call onSessionFound for resume so cursorSessionId in metadata
- cursorCommand: do not forward parsed flags to cursorArgs (avoid duplicates)

Made-with: Cursor
SeeFlowerX pushed a commit to SeeFlowerX/hapi that referenced this pull request Apr 1, 2026
* feat(cursor): add support for Cursor Agent CLI integration

- Introduced new command `hapi cursor` to start Cursor Agent sessions.
- Added functionality for resuming sessions and managing permission modes.
- Updated documentation to include Cursor Agent usage and installation instructions.
- Enhanced existing codebase to accommodate Cursor as a recognized agent flavor.
- Implemented local and remote session handling for Cursor Agent.

This update expands HAPI's capabilities by integrating support for the Cursor Agent, allowing users to leverage its features alongside existing agents.

* Remove TODO.md file as it is no longer needed following the integration of Cursor Agent CLI support. This cleanup helps streamline project documentation and reflects the completion of the associated tasks.

* feat(cursor): implement remote mode and fix --hapi-starting-mode

- Consume --hapi-starting-mode in cursor command (do not forward to agent)
- Implement cursorRemoteLauncher: spawn agent -p with stream-json, --trust
- Add cursorEventConverter for NDJSON parsing (system/assistant/tool_call/result)
- Multi-turn via --resume session_id
- Update docs: cursor supports both local and remote modes

Made-with: Cursor

* fix: type error

* fix(cursor): address PR review - model UI, sessionId metadata, duplicate flags

- HappyComposer: use isClaudeFlavor for model mode (cursor has no model modes)
- cursorLocalLauncher: call onSessionFound for resume so cursorSessionId in metadata
- cursorCommand: do not forward parsed flags to cursorArgs (avoid duplicates)

Made-with: Cursor
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.

大佬能否让 HAPI 支持下 cursor-cli

2 participants