Commit 88937a9
committed
feat(cursor): setup writers + cursor_sdk auth + AgentSdk factory (PR-2 of #129)
Phase 1 / 3 second pass — adds the user-visible Cursor pieces on top of
the IDE abstraction landed earlier in this PR:
Setup writers (src/setup/cursor-writers.ts, ~155 LOC)
- writeCursorMcpJson / writeCursorHooksJson / writeCursorRulesMdc
- All idempotent: re-runs preserve user-added entries, dedupe axme
entries by command-string match. version:1 hooks.json + frontmatter
on .cursor/rules/axme-code.mdc (alwaysApply: true).
- Hook commands include "--ide cursor" so the spawned subprocess picks
the right adapter without re-detecting.
CLI setup branch (src/cli.ts)
- Parse --ide=<claude-code|cursor> flag (default claude-code).
- Cursor branch: write .cursor/{mcp,hooks}.json + rules/axme-code.mdc;
skip CLAUDE.md (D-080) and .claude/settings.json. Root .mcp.json is
always written so a repo can be opened in either IDE.
- Reject --ide=cursor + --plugin combination (Phase 2 follow-up).
- usage() documents --ide.
AuthMode = subscription | api_key | cursor_sdk (src/types.ts)
- New CursorApiKeyConfig type for ~/.config/axme-code/cursor.yaml.
- auth-config.ts: loadCursorApiKey / saveCursorApiKey (chmod 600 on
POSIX), heuristicMode prefers cursor_sdk only when nothing else
detected, validate-mode whitelist extended.
- auth-detect.ts: detectCursorSdk reads CURSOR_API_KEY env or
~/.config/axme-code/cursor.yaml, surfaces as third AuthOption.
- auth-prompt.ts: option [3] Cursor SDK in formatDetectionBlock and
promptAuthChoice; new promptCursorApiKey() paste-once flow.
- cli.ts auth subcommand: cursor_sdk handled in both interactive
(paste-on-pick) and "auth use cursor_sdk" non-interactive paths.
AgentSdk factory (src/utils/agent-sdk.ts + agent-sdk-{claude,cursor}.ts)
- IDE-agnostic interface mirroring the Claude SDK message envelope.
- createAgentSdk(role) selects IDE via opts → AXME_IDE env →
authImpliedIde → "claude-code" default. Fallback chain: cursor →
claude (if findClaudePath() or ANTHROPIC_API_KEY). Throws
AgentSdkUnavailableError when neither usable; the detached audit
worker (PR-3) will catch and skip.
- win-arm64 short-circuit: never attempts @cursor/sdk import there
(no native binary in 1.0.12).
- Cursor wrapper translates Cursor stream events (assistant /
thinking / status / tool_call) into the shared AgentMessage shape
and synthesizes a terminal "result" message.
- System-prompt injection: prepend <system>\n...\n</system>\n\n to
the first agent.send() — Cursor SDK has no top-level systemPrompt
option (verified via Cursor agent spec-check on PR-1).
agent-options.ts
- buildAgentEnv(): mode=cursor_sdk hydrates CURSOR_API_KEY from
cursor.yaml and deletes ANTHROPIC_API_KEY (preempt dual-provider
surprise if Cursor ever adds one).
- mapClaudeToolsToCursor(): Bash → Shell, drops NotebookEdit / Agent
/ Skill / TodoWrite / WebFetch / WebSearch / ToolSearch (not in
Cursor tool taxonomy).
@cursor/sdk@1.0.12 added to optionalDependencies (exact pin), so npm
install succeeds on win-arm64 (no native binary) without erroring.
Tests (+22):
- test/cursor-setup-writers.test.ts: idempotent merge for hooks/mcp,
user-entry preservation, frontmatter on rules.mdc.
- test/cursor-auth-config.test.ts: cursor_sdk YAML round-trip,
cursor.yaml chmod 600, missing/empty key handling.
- test/agent-sdk-factory.test.ts: IDE selection precedence,
fallback chain when CURSOR_API_KEY missing, mapClaudeToolsToCursor.
Full suite: 595 / 595 (was 573). tsc clean. build clean.
This commit is PR-2 of the cursor-full-support series, all of which
land in PR #129 (per user direction: don't merge until full Cursor E2E).
PR-3 will wire the session-auditor + scanners through the new
AgentSdk factory and add a Cursor-aware branch to transcript-parser.
#!axme pr=129 repo=AxmeAI/axme-code1 parent 5ff0a9e commit 88937a9
15 files changed
Lines changed: 2779 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
200 | 212 | | |
201 | 213 | | |
202 | 214 | | |
| |||
320 | 332 | | |
321 | 333 | | |
322 | 334 | | |
323 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
324 | 339 | | |
325 | 340 | | |
326 | 341 | | |
| |||
335 | 350 | | |
336 | 351 | | |
337 | 352 | | |
338 | | - | |
| 353 | + | |
| 354 | + | |
339 | 355 | | |
340 | | - | |
| 356 | + | |
| 357 | + | |
341 | 358 | | |
342 | 359 | | |
343 | 360 | | |
| |||
367 | 384 | | |
368 | 385 | | |
369 | 386 | | |
370 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
371 | 403 | | |
372 | 404 | | |
373 | 405 | | |
| |||
481 | 513 | | |
482 | 514 | | |
483 | 515 | | |
484 | | - | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
485 | 520 | | |
486 | 521 | | |
487 | 522 | | |
| |||
504 | 539 | | |
505 | 540 | | |
506 | 541 | | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
513 | 558 | | |
514 | | - | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
515 | 566 | | |
516 | 567 | | |
517 | 568 | | |
| |||
774 | 825 | | |
775 | 826 | | |
776 | 827 | | |
777 | | - | |
778 | | - | |
| 828 | + | |
| 829 | + | |
779 | 830 | | |
780 | 831 | | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
781 | 848 | | |
782 | 849 | | |
783 | 850 | | |
| |||
794 | 861 | | |
795 | 862 | | |
796 | 863 | | |
797 | | - | |
| 864 | + | |
798 | 865 | | |
799 | 866 | | |
800 | 867 | | |
801 | 868 | | |
802 | 869 | | |
803 | 870 | | |
804 | 871 | | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
805 | 883 | | |
806 | 884 | | |
807 | 885 | | |
808 | 886 | | |
809 | 887 | | |
810 | | - | |
| 888 | + | |
811 | 889 | | |
812 | 890 | | |
813 | 891 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
402 | 413 | | |
403 | 414 | | |
404 | 415 | | |
405 | 416 | | |
406 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
0 commit comments