pi-cursor-sdk 0.1.22 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +3 -3
- package/docs/cursor-live-smoke-checklist.md +7 -7
- package/docs/cursor-model-ux-spec.md +7 -7
- package/docs/cursor-native-tool-replay.md +2 -2
- package/docs/cursor-native-tool-visual-audit.md +4 -4
- package/docs/cursor-testing-lessons.md +1 -1
- package/package.json +5 -5
- package/src/cursor-api-key.ts +15 -0
- package/src/cursor-bridge-contract.ts +9 -1
- package/src/cursor-pi-tool-bridge-mcp.ts +1 -0
- package/src/cursor-pi-tool-bridge-snapshot.ts +2 -0
- package/src/cursor-pi-tool-bridge-types.ts +1 -0
- package/src/cursor-provider-turn-api-key.ts +1 -8
- package/src/cursor-tool-manifest.ts +1 -1
- package/src/index.ts +2 -1
- package/src/model-discovery.ts +5 -12
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.23 - 2026-05-28
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Upgrade the pinned Cursor SDK runtime dependency to `@cursor/sdk@1.0.15` and validate development/test packages against pi `0.77.0`.
|
|
10
|
+
- Register Cursor provider auth with pi 0.77's `$CURSOR_API_KEY` config-value syntax while keeping legacy `CURSOR_API_KEY` placeholder handling for older stored auth and pi 0.76 compatibility.
|
|
11
|
+
- Keep pi peer dependencies minimum-only with no upper bound so users can try newer pi releases before a matching extension update is published; `0.77.0` is the validation baseline, not a maximum supported version.
|
|
12
|
+
|
|
5
13
|
## 0.1.22 - 2026-05-28
|
|
6
14
|
|
|
7
15
|
### Fixed
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ If pi started without a key, run `/cursor-refresh-models` after `/login` to refr
|
|
|
34
34
|
- pi 0.76.0 or newer
|
|
35
35
|
- a Cursor API key saved through `/login`, available as `CURSOR_API_KEY`, or passed with pi's `--api-key`
|
|
36
36
|
|
|
37
|
-
No global `@cursor/sdk` install is required. This package depends on exact `@cursor/sdk@1.0.
|
|
37
|
+
No global `@cursor/sdk` install is required. This package depends on exact `@cursor/sdk@1.0.15`, so normal package installation brings in the SDK version this extension was built and tested against. This package declares a pi **minimum** of 0.76.0 with no maximum peer version, so users who update pi before this extension is republished are not blocked from trying the existing extension. The current validation baseline is pi 0.77.0 plus Cursor SDK 1.0.15; older pi or Cursor SDK compatibility paths are not maintained.
|
|
38
38
|
|
|
39
39
|
## Install
|
|
40
40
|
|
|
@@ -236,7 +236,7 @@ Cursor runs use local Cursor SDK agents with two separate tool surfaces:
|
|
|
236
236
|
- **Cursor-native surface:** Cursor local-agent tools, Cursor settings, plugins, and configured Cursor MCP servers. These remain owned by the Cursor SDK local agent path.
|
|
237
237
|
- **pi bridge surface:** pi-cursor-sdk exposes bridgeable active pi tools through a per-run local loopback MCP bridge when the bridge is enabled and the current pi tool registry has exposed tools.
|
|
238
238
|
|
|
239
|
-
Bridge capabilities are snapshotted from `pi.getActiveTools()` and `pi.getAllTools()` for each Cursor run. Cursor sees active bridgeable pi tools as collision-safe MCP names such as `pi__sem_reindex` only when they are exposed in that current run. Pi session output, tool cards, confirmations, hooks, renderers, history, and abort behavior use the real pi tool name, such as `sem_reindex`. The bridge queues Cursor's MCP call, emits a normal pi `toolCall`, waits for the matching pi `toolResult`, and resolves that result back into the same live Cursor SDK run without creating a new `Agent`, unless the run was disposed, aborted, or cancelled. The bridge does not call pi tool `execute()` handlers directly.
|
|
239
|
+
Bridge capabilities are snapshotted from `pi.getActiveTools()` and `pi.getAllTools()` for each Cursor run, including per-tool prompt guidelines when pi exposes them. Cursor sees active bridgeable pi tools as collision-safe MCP names such as `pi__sem_reindex` only when they are exposed in that current run. Pi session output, tool cards, confirmations, hooks, renderers, history, and abort behavior use the real pi tool name, such as `sem_reindex`. The bridge queues Cursor's MCP call, emits a normal pi `toolCall`, waits for the matching pi `toolResult`, and resolves that result back into the same live Cursor SDK run without creating a new `Agent`, unless the run was disposed, aborted, or cancelled. The bridge does not call pi tool `execute()` handlers directly.
|
|
240
240
|
|
|
241
241
|
Overlapping built-in pi tools (`read`, `bash`, `write`, `edit`, `grep`, `find`, `ls`) are hidden by default because Cursor local agents already have native equivalents. Extension/custom tools and non-overlapping active tools present in pi's active tool registry normally remain exposed. The bridge also exposes `cursor_ask_question` as `pi__cursor_ask_question` when enabled, allowing Cursor to ask the user through pi UI instead of silently choosing a default.
|
|
242
242
|
|
|
@@ -272,7 +272,7 @@ On bootstrap sends, a compact **callable tool surfaces** block is injected into
|
|
|
272
272
|
|
|
273
273
|
### Maintainer live smoke release gate
|
|
274
274
|
|
|
275
|
-
For Cursor provider/runtime changes, follow the manual [Cursor live smoke checklist](docs/cursor-live-smoke-checklist.md) before release. For a faster minimal-surface pass first, see [Cursor dogfood checklist](docs/cursor-dogfood-checklist.md). See [Cursor testing lessons](docs/cursor-testing-lessons.md) for auth.json seeding, isolated `/tmp` harness layout, JSONL replay-error scans, and other regression traps. Assume every runtime surface is in scope. The checklist uses real `pi -e . --cursor-no-fast --model cursor/composer-2.5` runs with temporary session dirs, pi 0.
|
|
275
|
+
For Cursor provider/runtime changes, follow the manual [Cursor live smoke checklist](docs/cursor-live-smoke-checklist.md) before release. For a faster minimal-surface pass first, see [Cursor dogfood checklist](docs/cursor-dogfood-checklist.md). See [Cursor testing lessons](docs/cursor-testing-lessons.md) for auth.json seeding, isolated `/tmp` harness layout, JSONL replay-error scans, and other regression traps. Assume every runtime surface is in scope. The checklist uses real `pi -e . --cursor-no-fast --model cursor/composer-2.5` runs with temporary session dirs, pi 0.77.0 `--session-id`, sealed smoke-runner PATH/env wrappers, Cursor SDK `plan` mode, and mandatory visual TUI card/color inspection. The canonical visual path is `npm run smoke:visual`: offscreen PTY capture rendered through a browser/xterm view and saved as PNG screenshots with Playwright, or with `agent_browser` from the generated HTML when available. Its default matrix is native replay only: native replay registration is forced on, Cursor setting sources are disabled, the pi bridge is off, overlapping built-in pi tools are not exposed, and inherited Cursor SDK event-debug artifact env is cleared; `--event-debug` writes to a deterministic debug directory under the visual output directory. The visible TUI/output, rendered screenshots, scrubbed diagnostics, and persisted JSONL must agree. Do not mark a release ready with optional, deferred, mostly-passing, or unobserved smoke checks outstanding.
|
|
276
276
|
|
|
277
277
|
### Maintainer Cursor SDK event capture
|
|
278
278
|
|
|
@@ -65,8 +65,8 @@ The replay scan flags only error `toolResult` / error assistant messages with `T
|
|
|
65
65
|
|
|
66
66
|
Pass criteria:
|
|
67
67
|
|
|
68
|
-
- `pi --version` reports pi 0.
|
|
69
|
-
- `npm ls` shows `@cursor/sdk@1.0.
|
|
68
|
+
- `pi --version` reports pi 0.77.0 for this cutover baseline.
|
|
69
|
+
- `npm ls` shows `@cursor/sdk@1.0.15` and local `@earendil-works/*@0.77.0` packages.
|
|
70
70
|
- `cursor/composer-2.5` appears in the model list.
|
|
71
71
|
- No Cursor key or auth token is printed.
|
|
72
72
|
- If neither `~/.pi/agent/auth.json` cursor auth nor `CURSOR_API_KEY` is available, stop and report the live smoke as blocked.
|
|
@@ -115,7 +115,7 @@ Run a real interactive session under tmux:
|
|
|
115
115
|
```bash
|
|
116
116
|
SESSION="pi-cursor-sdk-smoke-$(date +%s)"
|
|
117
117
|
tmux new-session -d -s "$SESSION" -x 120 -y 40 -- zsh -lc \
|
|
118
|
-
"cd '$PWD' && PI_CURSOR_SETTING_SOURCES=none pi -e . --cursor-no-fast --model cursor/composer-2.5 --session-dir '$SMOKE_DIR/tui' --session-id cursor-sdk-
|
|
118
|
+
"cd '$PWD' && PI_CURSOR_SETTING_SOURCES=none pi -e . --cursor-no-fast --model cursor/composer-2.5 --session-dir '$SMOKE_DIR/tui' --session-id cursor-sdk-1015-tui --no-tools 'TUI smoke. Compute 19 + 23. Reply only with SUM=<number>.'"
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
Observe with `tmux capture-pane -pt "$SESSION"` or attach manually.
|
|
@@ -123,7 +123,7 @@ Observe with `tmux capture-pane -pt "$SESSION"` or attach manually.
|
|
|
123
123
|
Pass criteria:
|
|
124
124
|
|
|
125
125
|
- Footer shows `(cursor) composer-2.5`. With `--cursor-no-fast`, Cursor fast mode is off and the Cursor extension status should not show `cursor fast`; ignore unrelated status text from other extensions.
|
|
126
|
-
- The run uses pi 0.
|
|
126
|
+
- The run uses pi 0.77.0 `--session-id` successfully.
|
|
127
127
|
- Assistant answer appears correctly.
|
|
128
128
|
- `/session` shows one user and one assistant message for the simple run.
|
|
129
129
|
- Persisted JSONL has one assistant message. If the screen appears duplicated, inspect JSONL before deciding whether it is a rendering bug.
|
|
@@ -131,10 +131,10 @@ Pass criteria:
|
|
|
131
131
|
|
|
132
132
|
## 4. Mandatory visual card/color rendering check
|
|
133
133
|
|
|
134
|
-
This is the canonical visual release path for Cursor provider/runtime changes. It requires offscreen TUI visual inspection, not only JSONL or code review. Use pi 0.
|
|
134
|
+
This is the canonical visual release path for Cursor provider/runtime changes. It requires offscreen TUI visual inspection, not only JSONL or code review. Use pi 0.77.0, `@cursor/sdk@1.0.15`, a fresh temporary session dir, Cursor SDK `plan` mode, native replay enabled, and the checked-in visual runner. The runner resolves `pi` by directly walking the parent `PATH`, uses `process.execPath` for Node, and prepends that Node directory for both prereq checks and tmux launches so `#!/usr/bin/env node` shims use the validated Node. The default matrix is native replay only: native replay registration is forced on, settings sources are `none`, the pi bridge is off, overlapping built-in pi tools are not exposed, and inherited Cursor SDK event-debug artifact env is cleared. With `--event-debug`, debug capture writes to a deterministic directory under `VISUAL_DIR`.
|
|
135
135
|
|
|
136
136
|
```bash
|
|
137
|
-
VISUAL_DIR="$(mktemp -d /tmp/pi-cursor-sdk-
|
|
137
|
+
VISUAL_DIR="$(mktemp -d /tmp/pi-cursor-sdk-1015-visual.XXXXXX)"
|
|
138
138
|
VISUAL_ARGS=(
|
|
139
139
|
--ext "$PWD"
|
|
140
140
|
--cwd "$PWD"
|
|
@@ -204,7 +204,7 @@ Pass criteria:
|
|
|
204
204
|
PI_CURSOR_SETTING_SOURCES=none \
|
|
205
205
|
pi -e . --cursor-no-fast --cursor-mode plan --model cursor/composer-2.5 \
|
|
206
206
|
--session-dir "$SMOKE_DIR/cursor-mode-plan" \
|
|
207
|
-
--session-id cursor-sdk-
|
|
207
|
+
--session-id cursor-sdk-1015-plan \
|
|
208
208
|
--no-tools \
|
|
209
209
|
-p 'Cursor mode smoke. Reply with one short implementation plan for printing hello.' \
|
|
210
210
|
> "$SMOKE_DIR/cursor-mode-plan.stdout.txt" \
|
|
@@ -15,29 +15,29 @@ Current implementation notes:
|
|
|
15
15
|
- Cursor status uses one coordinated `ctx.ui.setStatus("cursor", ...)` value for fast and non-default plan mode; the default pi footer remains intact.
|
|
16
16
|
- Installed `@cursor/sdk` user messages accept images, and Cursor models are treated as image-capable; registered input metadata is `text` plus `image`.
|
|
17
17
|
- Image payload forwarding sends images only from the latest user message. If the latest user turn is plain text after an earlier image turn, the transcript keeps an `[image omitted from transcript]` placeholder but no image bytes are sent to Cursor. The prompt explicitly tells Cursor that prior image bytes are unavailable and to ask the user to reattach or describe a prior image when needed. Carrying images forward across turns remains a future product decision because it affects token cost, privacy, stale visual context, and expected multimodal follow-up behavior.
|
|
18
|
-
- Exact `@cursor/sdk@1.0.
|
|
18
|
+
- Exact `@cursor/sdk@1.0.15` is a package dependency of this extension; users should not need a global SDK install. pi 0.77.0 is the current validation baseline, while published pi peer dependencies are minimum-only `>=0.76.0` ranges with no upper bound. Newer pi versions are allowed to attempt loading this extension before a matching extension release exists; compatibility is best-effort until validated.
|
|
19
19
|
- Cursor auth uses pi-native API-key resolution for provider `cursor`: CLI `--api-key`, stored `~/.pi/agent/auth.json` API key from `/login`, then `CURSOR_API_KEY`. The extension config file stores only non-secret Cursor-only state such as fast defaults.
|
|
20
20
|
- Local agents pass `settingSources: ["all"]` by default so Cursor MCP servers, plugin tools, project/user settings, and related Cursor-native capabilities are available. Users can narrow loading with a comma-separated list such as `PI_CURSOR_SETTING_SOURCES=project,user,plugins`, or disable ambient setting sources with `PI_CURSOR_SETTING_SOURCES=none`. The provider suppresses direct Cursor SDK bootstrap stdout/stderr/console noise (including late first-send workspace loading such as hook compatibility warnings) so it does not pollute pi's TUI.
|
|
21
21
|
- On `cursor/*` models, pi-cursor-sdk removes only pi-generated `<project_instructions>` blocks that overlap the effective Cursor `settingSources`: `user` for `~/.pi/agent/AGENTS.md`; `project` for discovered repo/parent `AGENTS.md` and `CLAUDE.md` (verified Cursor behavior: local agents load project `AGENTS.md` and `CLAUDE.md`). `~/.pi/agent/CLAUDE.md` is not removed (Cursor user layer uses `~/.claude/CLAUDE.md`). Blocks are removed by exact pi serialization match from structured `contextFiles` via the `before_agent_start` hook, not in `buildCursorPrompt` sanitization. Suppression is skipped with `-nc`, `PI_CURSOR_SETTING_SOURCES=none`, narrowed sources such as `plugins` that omit the matching layer, or `PI_CURSOR_PRESERVE_PI_AGENTS_MD=1`. Switching away from a Cursor model restores pi's full context block on the next user message.
|
|
22
22
|
- Cursor SDK models are treated as thinking-capable even when pi reports `thinking=no`; that pi column only means the SDK did not expose a pi-controllable thinking parameter for that model.
|
|
23
23
|
- Cursor-side thinking remains visible through pi's native thinking rendering when the Cursor SDK emits thinking or summary deltas.
|
|
24
24
|
- Local Cursor agents get two tool surfaces. First, Cursor keeps the Cursor SDK local-agent tool surface plus configured Cursor settings, plugins, and Cursor MCP servers. Second, pi-cursor-sdk exposes active pi tools through a default-on, tokenized loopback MCP bridge when bridgeable tools exist.
|
|
25
|
-
- `buildCursorPiToolBridgeSnapshot()` is the runtime capability source for pi bridge tools. It snapshots `pi.getActiveTools()` and `pi.getAllTools()`, filters internal replay names, hides overlapping built-in pi tools (`read`, `bash`, `write`, `edit`, `grep`, `find`, `ls`) unless `PI_CURSOR_EXPOSE_BUILTIN_TOOLS=1`, and creates collision-safe MCP names such as `pi__sem_reindex`. Cursor discovers the current run's exposed bridge tools through MCP `listTools`. Bootstrap prompts include a compact callable-surface manifest from `buildCursorToolManifestText()` by default (`PI_CURSOR_TOOL_MANIFEST=1`); disable with `PI_CURSOR_TOOL_MANIFEST=0`. There is no per-turn visible tool list, status manifest, or footer manifest. User-facing summary: [Cursor tool surfaces in pi](./cursor-tool-surfaces.md).
|
|
25
|
+
- `buildCursorPiToolBridgeSnapshot()` is the runtime capability source for pi bridge tools. It snapshots `pi.getActiveTools()` and `pi.getAllTools()`, carries pi 0.77+ per-tool `promptGuidelines` into bridge MCP descriptions, filters internal replay names, hides overlapping built-in pi tools (`read`, `bash`, `write`, `edit`, `grep`, `find`, `ls`) unless `PI_CURSOR_EXPOSE_BUILTIN_TOOLS=1`, and creates collision-safe MCP names such as `pi__sem_reindex`. Cursor discovers the current run's exposed bridge tools through MCP `listTools`. Bootstrap prompts include a compact callable-surface manifest from `buildCursorToolManifestText()` by default (`PI_CURSOR_TOOL_MANIFEST=1`); disable with `PI_CURSOR_TOOL_MANIFEST=0`. There is no per-turn visible tool list, status manifest, or footer manifest. User-facing summary: [Cursor tool surfaces in pi](./cursor-tool-surfaces.md).
|
|
26
26
|
- Prompt text is the primary provider/bridge contract. Bootstrap prompts carry a short boundary block plus the callable-surface manifest by default (`PI_CURSOR_TOOL_MANIFEST=1`). MCP `listTools` descriptions use a one-line pointer to the bootstrap prompt instead of repeating the full contract (`buildCursorPiBridgeMcpToolDescription()`). Cursor must call the exposed `pi__*` MCP name, not the real pi tool name shown in pi history or transcripts. Pi emits and executes the real pi tool name. Maintainer debug: `/cursor-tools` prints bridge/manifest enablement, effective `PI_CURSOR_SETTING_SOURCES`, and the current callable-surface snapshot.
|
|
27
27
|
- The provider also registers `cursor_ask_question` for Cursor models when the bridge is enabled. Cursor sees it as `pi__cursor_ask_question`, and pi executes it through the normal tool path so interactive users can choose options from pi UI. In non-UI modes it reports that UI is unavailable so Cursor can state a default assumption instead. `PI_CURSOR_PI_TOOL_BRIDGE=0` disables the local bridge, including question bridging. Cloud Cursor agents remain out of scope for the bridge.
|
|
28
28
|
- The bridge queues MCP calls, emits provider `toolcall_*` events, waits for matching pi `toolResult` messages by `toolCallId`, resolves the result back into the same live Cursor SDK run without creating a new `Agent`, and never calls tool `execute()` handlers directly. The same-run resume invariant holds unless the run was disposed, aborted, or cancelled.
|
|
29
|
-
- Cursor SDK MCP tool calls use a guarded timeout override because installed `@cursor/sdk` 1.0.
|
|
29
|
+
- Cursor SDK MCP tool calls use a guarded timeout override because installed `@cursor/sdk` 1.0.15 has a 60-second MCP request default with no public per-server timeout option. The extension extends the verified Cursor SDK MCP `callTool` timeout path to 3600 seconds by default and shortens the verified first-send MCP initialize/listTools timeout paths to 10 seconds by default so unavailable configured MCP servers do not block the first reply for a full minute; unknown MCP protocol timeout stacks keep the SDK default. Users can override tool-call timeouts with `PI_CURSOR_MCP_TOOL_TIMEOUT_MS` or `PI_CURSOR_MCP_TOOL_TIMEOUT_SECONDS`, and initialize/listTools timeouts with `PI_CURSOR_MCP_CONNECT_TIMEOUT_MS` or `PI_CURSOR_MCP_CONNECT_TIMEOUT_SECONDS`.
|
|
30
30
|
- Bridge diagnostics are opt-in only: `PI_CURSOR_PI_TOOL_BRIDGE_DEBUG=1` writes typed, allowlisted, scrubbed single-line JSONL records to `process.stderr` with prefix `[pi-cursor-sdk:bridge]`. Diagnostics are scrubbed operational logs, not anonymous telemetry. They intentionally include tool names, safe correlation IDs, run lifecycle, exposed pi↔MCP name pairs, queued requests, result resolution, rejection, cancellation, and pending counts. Correlation IDs are generated independently from the tokenized endpoint path, and Cursor MCP call IDs are hashed before serialization. Diagnostics must not include endpoint paths/URLs/path components/tokens, API keys, bearer tokens, cookies, session credentials, raw args/results, stdout/stderr payloads, file contents, Cursor settings output, or local private session paths in tracked docs, and they must not call pi UI status, notification, or footer APIs. If tool names themselves are unacceptable for a release target, bridge debug diagnostics are not safe for shared logs under the current contract.
|
|
31
31
|
- This repo does not provide a generic desktop-automation, browser-driver, or CDP recipe. Provider docs should describe pi-cursor-sdk's Cursor provider/bridge contract only.
|
|
32
|
-
- Cursor internal tool activity is recorded from SDK events and scrubbed. Maintainer reference for all 16 `@cursor/sdk@1.0.
|
|
32
|
+
- Cursor internal tool activity is recorded from SDK events and scrubbed. Maintainer reference for all 16 `@cursor/sdk@1.0.15` `ToolType` values, runtime alias normalization, and intentional mapping/fallback rules: [Cursor native tool replay — SDK ToolType replay matrix](./cursor-native-tool-replay.md#sdk-tooltype-replay-matrix) (official SDK docs: https://cursor.com/docs/sdk/typescript). In interactive TTY sessions, supported completed `read`, `bash`, `grep`, `find`, `ls`, `edit`, `write`, diagnostics, delete, todo/plan, task, image generation, MCP, semantic search, and screen recording activity is replayed through pi's native tool-call rendering path with recorded Cursor results, so the TUI can show native-looking cards without rerunning Cursor's reads/shell commands/file edits. Cursor `glob` activity is replayed through native `find` cards. Cursor write activity is replayed through native-looking `write` cards, and Cursor StrReplace/edit activity uses native-looking `edit` only when recorded arguments truthfully satisfy pi's `edit` schema; path-only Cursor edit and notebook edit replay falls back to neutral Cursor activity before pi validation. Diagnostics, delete, todos/plans, task, image, and MCP activity use neutral Cursor activity cards with pi's default success/error shell. Neutral Cursor activity calls include `activityTitle` and, when available, `activitySummary` so partial/collapsed cards preserve identity such as `Cursor plan`, `Cursor todos`, `Cursor MCP`, or `Cursor edit`. For long-running or externally meaningful Cursor tools (`task`, `shell`, `mcp`, `generateImage`, `recordScreen`, `semSearch`, web search/fetch, plan/todo), the provider may surface one low-noise deferred in-progress thinking line such as `Cursor MCP: external_search` from bounded, scrubbed SDK args; fast local tools (`read`, `grep`, `glob`, and similar) skip lifecycle lines when completion follows immediately, and pi bridge MCP calls are excluded because pi already shows real pi tool execution ([lifecycle visibility](./cursor-native-tool-replay.md#low-noise-tool-lifecycle-visibility)). Replay-only tools display recorded Cursor results, normalize workspace-local paths/diff headers for display, use pi diff colors for edit previews and path-inferred syntax highlighting for write previews, and fail closed if called without a recorded result. Native replay wrappers are registered only for tool names not already owned by another extension; conflicting tools use the bounded scrubbed transcript fallback. Cursor workflow tools such as mode/task/todo/plan activity are not pi workflow controls; reported todo/plan events are displayed as Cursor activity only. Plan/todo replay cards can be followed by Cursor's final plan text, selected from `run.wait().result` when Cursor provides one and trimmed against already-emitted text. Started Cursor SDK tool calls that never receive a completion event are surfaced with bounded user-visible labels/traces (neutral activity cards when native replay routing allows, otherwise the same inactive or transcript trace fallbacks used for completed replay) instead of being silently discarded when the run failed/aborted, produced no assistant text, or involved external/side-effectful tools; incomplete fast local discovery starts (`read`, `grep`, `glob`, `ls`) remain maintainer-debug-only after successful text-producing runs so stale SDK start events do not create red post-answer cards. Explicit failures remain visible when Cursor reports them through completed tool calls or step results. Pi bridge MCP starts remain excluded from duplicate incomplete Cursor cards because pi already shows real pi tool execution. `PI_CURSOR_NATIVE_TOOL_DISPLAY=0` disables native replay, and `PI_CURSOR_REGISTER_NATIVE_TOOLS=0` is a registration-only opt-out that keeps the transcript fallback without shadowing pi tool names. When bridge or native replay cards are emitted, the provider mirrors Codex's turn shape as Cursor SDK activity arrives: assistant `toolUse`, pi `toolResult`s, live post-tool Cursor thinking/text, any later tool batches as further `toolUse` turns, then Cursor's final assistant answer. For shell replay, completed `stdout` / `stderr` are primary; unambiguous `shell-output-delta` data is used only as display-only fallback for empty successful shell completions, and overlapping shell calls drop ambiguous deltas instead of guessing. Non-interactive runs keep bounded scrubbed transcript output instead, preserving `pi -p` assistant text output. Cursor text deltas stream live when no live-run turn split is active.
|
|
33
33
|
- Synthetic replay names are internal compatibility details. New model-facing prompt text and user-visible cards use native tool names when renderer-compatible, or neutral Cursor activity labels when not. Legacy sessions containing old internal replay names are sanitized before prompt/display. Bridge MCP names such as `pi__sem_reindex` are MCP-only; pi session output uses real pi tool names.
|
|
34
34
|
- Cursor SDK usage events report cumulative internal agent/tool/cache work, not the replayable pi prompt context. The extension does not copy raw Cursor SDK usage into pi usage or compaction. For Cursor assistant messages, `usage.input`/`usage.output` are approximate pi session activity components: initial Cursor prompt input is counted once, consumed split-run tool results are counted as deduped input on the following assistant turn, and assistant output includes visible text/thinking/tool-call content. `usage.totalTokens` is the replayable Cursor prompt/context estimate derived from the same `buildCursorPrompt()` path used for `Agent.send`; it may differ from `input + output` and is the context-safe value for display/compaction. `src/cursor-usage-accounting.ts` owns this usage policy, and `src/cursor-live-run-accounting.ts` owns prompt-once and consumed-tool-result accounting so provider usage and bridge result resolution share the same matched tool-result boundary.
|
|
35
35
|
- Audit observation, 2026-05-19, superseded by the 2026-05-21 replay pass and #68 incomplete visibility, then narrowed by the 2026-05-26 fast-local suppression: a missing-file read with Composer 2.5 emitted `tool-call-started` for Cursor `read`, then streamed final text `Error: File not found`, but did not emit `tool-call-completed` or an `onStep` `toolCall` error result. Leftover external/side-effectful started calls are surfaced at run completion through the same native replay routing as completed tools (activity cards when allowed, otherwise inactive/transcript traces), while fast local discovery starts are debug-only after a successful text-producing run. Cursor-reported completed/step errors remain visible.
|
|
36
36
|
- Maintainer visual verification for replay-card changes should follow [Cursor Native Tool Visual Audit Workflow](./cursor-native-tool-visual-audit.md): offscreen PTY-driven pi run, xterm.js/Playwright screenshot rendering, and JSONL inspection before accepting commits or PRs.
|
|
37
37
|
- Cursor provider/runtime releases should follow [Cursor Live Smoke Checklist](./cursor-live-smoke-checklist.md) with real `pi -e . --cursor-no-fast --model cursor/composer-2.5` invocations, manual observation, temporary session dirs, diagnostics scans, and persisted JSONL inspection. See [Cursor testing lessons](./cursor-testing-lessons.md) for auth.json seeding, isolated smoke harnesses, and replay JSONL scans. Assume every runtime surface is in scope. A release is not ready when any live check is optional, deferred, mostly passing, or unobserved.
|
|
38
38
|
- For models without a catalog `context` parameter, context windows are not hardcoded. The extension ships a bundled SDK-derived default/non-Max cache generated from `createAgentPlatform().checkpointStore.loadLatest(agentId).tokenDetails.maxTokens`. Successful runs can update a local override cache, but model discovery does not probe models at startup.
|
|
39
|
-
- Max Mode context windows are distinct from default/non-Max context windows. `@cursor/sdk` 1.0.
|
|
40
|
-
- `@cursor/sdk` 1.0.
|
|
39
|
+
- Max Mode context windows are distinct from default/non-Max context windows. `@cursor/sdk` 1.0.15 documentation says the SDK may enable Max Mode automatically when a selected model requires it, but the public local-agent `ModelSelection` path still does not expose a manual Max Mode selector. Do not advertise Max Mode context windows unless the SDK catalog exposes an exact parameter/variant or the SDK public API adds a Max Mode selector that the extension actually sends.
|
|
40
|
+
- `@cursor/sdk` 1.0.15 adds latest-style `ModelListItem.aliases`. The extension registers only unambiguous aliases as pi model IDs (with the same context suffixes when applicable) and sends the alias back in `ModelSelection.id`, while sharing Cursor-only state such as fast defaults with the underlying catalog `id`. Aliases shared by multiple base models, such as generic family aliases, are skipped because the pi row metadata would otherwise imply one base model while Cursor may resolve the alias to another.
|
|
41
41
|
- Session-scoped Cursor SDK agent pooling reuses one live `@cursor/sdk` agent across compatible follow-up turns within the same pi session scope. `planCursorSessionSend()` in `src/cursor-session-send-policy.ts` decides whether the next turn sends a full bootstrap prompt or an incremental follow-up, whether the SDK agent must be recreated, and why. `computeCursorContextFingerprint()` and `shouldBootstrapCursorContext()` remain the context-only bootstrap signal. The pool recreates the agent when context diverges, when branch or compaction summaries appear after `/tree` navigation or compaction, after 20 completed incremental sends, when the API key identity changes, after send errors, on `session_shutdown`, and when `session_before_tree` / `session_tree` invalidate the active branch. Incremental sends omit the full Cursor SDK tool boundary block because the session agent retains prior bootstrap context, but every send ends with a short tool tail guard placed after the latest user request (including an explicit shell `cd` hint).
|
|
42
42
|
- Pi steering/follow-up delivery can arrive while a split live Cursor SDK run is still active. The provider resolves pending live runs by scanning trailing `toolResult` messages while skipping trailing `user` messages, tracks the active live run per session scope, and resumes the in-flight run instead of calling `Agent.send()` again. When the context ends with steering user text after tool results, the provider releases the prior live run and chains an incremental `Agent.send()` for the latest user message in the same provider turn; if the prior run emits more text or tool requests after steering arrives, that stale activity is cancelled instead of surfacing another old-run tool turn and losing the new user input. A pre-send guard waits for or resumes any still-active scoped live run before starting a fresh send so `@cursor/sdk` `AgentBusyError` (`already has active run`) does not surface to pi users. Pooled session agents mark busy as soon as live/direct `run.wait()` tracking starts (`trackRunCompletion` on the session lease), and `acquireSessionCursorAgent()` awaits that busy state before returning a lease so send planning, transcript offsets, and later `Agent.send()` do not race the prior turn's SDK run completion (for example pi auto-compaction summarization). `session_before_compact` calls `prepareCursorSessionForCompaction()` to release scoped live-run drain state and reset the pooled agent before summarization streams. Tracked completions and send commits are scoped to the pooled agent `instanceId` so disposal/replacement drops stale tracking and ignores late commits from disposed agents.
|
|
43
43
|
|
|
@@ -382,7 +382,7 @@ cursor fast
|
|
|
382
382
|
|
|
383
383
|
## Cursor SDK Mode Behavior
|
|
384
384
|
|
|
385
|
-
Cursor SDK 1.0.
|
|
385
|
+
Cursor SDK 1.0.15 exposes SDK-native conversation mode:
|
|
386
386
|
|
|
387
387
|
```ts
|
|
388
388
|
type AgentModeOption = "agent" | "plan";
|
|
@@ -62,13 +62,13 @@ When Cursor reports completed tool activity, the extension can display recorded
|
|
|
62
62
|
|
|
63
63
|
Cursor `glob` activity is displayed through native `find` cards.
|
|
64
64
|
|
|
65
|
-
For the full `@cursor/sdk@1.0.
|
|
65
|
+
For the full `@cursor/sdk@1.0.15` `ToolType` set, disposition matrix, and runtime alias normalization, see [SDK ToolType replay matrix](#sdk-tooltype-replay-matrix) below. Official SDK reference: https://cursor.com/docs/sdk/typescript
|
|
66
66
|
|
|
67
67
|
Edit and write activity replays through pi-facing `edit` and `write` cards only when replay arguments truthfully satisfy the matching pi schema, but still uses recorded Cursor results only. The adapter passes through truthful Cursor paths, content when Cursor reported it, and recorded diff/details; it does not pretend Cursor's editing schema is pi's schema and it fails closed if a recorded replay result is missing. Cursor `StrReplace` with recorded replacement text displays as native-looking `edit`; path-only Cursor `edit` and notebook edit activity fall back to neutral Cursor activity so pi does not reject the replay before recorded-result handling. Cursor `write` displays as native-looking `write`. Diagnostics, delete, todos/plans, task, image, MCP, semantic search, screen recording, and web search/fetch activity use neutral Cursor activity cards with pi's default success/error tool shell. MCP completions whose `toolName` is `WebSearch` / `web_search` / `WebFetch` / similar are labeled **Cursor web search** or **Cursor web fetch** instead of generic **Cursor MCP**. Neutral Cursor activity cards carry display metadata such as `activityTitle` and `activitySummary`, so partial/collapsed cards can say `Cursor plan`, `Cursor todos`, `Cursor MCP`, `Cursor semantic search`, `Cursor screen recording`, `Cursor web search`, `Cursor web fetch`, or `Cursor edit` instead of only `Cursor activity`. These replay tools only display recorded Cursor results; they never mutate files or execute tool work directly. Replay paths are normalized to workspace-relative paths when possible. Most collapsed replay cards include bounded previews for diffs and text details so small edits, todos, task output, and MCP results are visible without expanding; web search/fetch activity stays summary-only while collapsed because those cards often arrive after final text and can otherwise bury the answer. Ctrl+O expansion shows the recorded details. Edit previews omit raw unified diff headers and show compact numbered changed/context lines using pi's native diff added/removed/context colors, and write previews use syntax highlighting when pi can infer a language from the path. Image generation replay cards show the saved image path in the collapsed summary and render the image inline when pi terminal image display is enabled and the generated file is still readable.
|
|
68
68
|
|
|
69
69
|
## SDK ToolType replay matrix
|
|
70
70
|
|
|
71
|
-
Source of truth for SDK tool names: `@cursor/sdk@1.0.
|
|
71
|
+
Source of truth for SDK tool names: `@cursor/sdk@1.0.15` conversation `ToolType` values and https://cursor.com/docs/sdk/typescript
|
|
72
72
|
|
|
73
73
|
Implementation owners: `src/cursor-tool-presentation-registry.ts` (canonical names, labels, visibility, replay policy, bridge exclusions for internal replay wrappers, and display-spec key completeness), `src/cursor-transcript-tool-specs.ts` (registry-keyed `TOOL_DISPLAY_SPECS` formatters/builders), `src/cursor-native-tool-display-replay.ts` (replay card rendering derived from registry replay metadata), and `src/cursor-transcript-utils.ts` (`normalizeToolName()` delegating to the registry).
|
|
74
74
|
|
|
@@ -4,19 +4,19 @@ This workflow is the canonical repo path for verifying Cursor SDK tool replay th
|
|
|
4
4
|
|
|
5
5
|
Use it before accepting replay-card commits or PRs, and for every Cursor provider/runtime release where TUI card/color behavior could regress. Text logs and JSONL are necessary, but they are not enough when the claim is visual parity: always keep PNGs for the exact prompt, and keep before/after PNGs when reviewing a rendering change.
|
|
6
6
|
|
|
7
|
-
Current
|
|
7
|
+
Current validation baseline: pi 0.77.0, exact `@cursor/sdk@1.0.15`, local validation packages `@earendil-works/pi-ai`, `@earendil-works/pi-coding-agent`, and `@earendil-works/pi-tui` at 0.77.0. Published peer dependencies remain minimum-only at pi 0.76.0+ with no upper bound, so newer pi installs can try the extension before a matching validation release exists.
|
|
8
8
|
|
|
9
|
-
## Cursor SDK 1.0.
|
|
9
|
+
## Cursor SDK 1.0.15 / pi 0.77.0 cutover visual record
|
|
10
10
|
|
|
11
11
|
Record the required cutover validation here or in the final release handoff. The default matrix is native replay only: the runner forces native replay registration on, forces Cursor setting sources off, disables the pi bridge, disables overlapping built-in pi tool exposure, and clears inherited Cursor SDK event-debug artifact env. With `--event-debug`, debug capture writes to a deterministic directory under the visual output directory. Do not commit raw ANSI logs, screenshots, terminal recordings, debug artifacts, or `.debug/visual-smoke` scratch files.
|
|
12
12
|
|
|
13
13
|
| Field | Required value / evidence |
|
|
14
14
|
| --- | --- |
|
|
15
15
|
| Command/session used | `npm run smoke:visual -- --ext "$PWD" --cwd "$PWD" --mode plan --out-dir <fresh /tmp dir> --label <matrix label> --prompt <matrix prompt>` with default native-replay isolation |
|
|
16
|
-
| Baseline versions | `pi --version` = 0.
|
|
16
|
+
| Baseline versions | `pi --version` = 0.77.0; `npm ls` = `@cursor/sdk@1.0.15` and local `@earendil-works/*@0.77.0` |
|
|
17
17
|
| Card categories checked | Claim only categories proven by both PNG and JSONL. Required cutover categories are read, grep/search, find/glob, list, shell success, write, edit/diff, and true read failure. Neutral Cursor plan/todo/task/mode activity is optional/opportunistic and only counts when JSONL contains a completed Cursor workflow event. |
|
|
18
18
|
| Observed status/card colors | Confirm native-looking cards use native pi styling; neutral Cursor activity is not red; true errors are distinct; diff previews show red/green; plan status is readable |
|
|
19
|
-
| Screenshot/ANSI evidence location | External path only, for example `/tmp/pi-cursor-sdk-
|
|
19
|
+
| Screenshot/ANSI evidence location | External path only, for example `/tmp/pi-cursor-sdk-1015-visual.*/read-package.{ansi,txt,html,png,jsonl.path}` |
|
|
20
20
|
| Debug artifact location | External `.debug/cursor-sdk-events/...` or temp artifact directory path only; do not commit raw artifacts |
|
|
21
21
|
| Pass/fail notes | Summarize any mismatch, blocker, or auth/environment limitation |
|
|
22
22
|
|
|
@@ -238,7 +238,7 @@ The script writes timestamped artifacts under `--out` (default `/tmp/pi-cursor-s
|
|
|
238
238
|
|
|
239
239
|
Stdout prints artifact paths and summary counts only. Raw payloads stay on disk and may contain local paths, project text, tool args/results, or secrets — do not commit or share them.
|
|
240
240
|
|
|
241
|
-
Hard repo rule: Cursor SDK behavior claims must come from the installed `@cursor/sdk` package and/or https://cursor.com/docs/sdk/typescript, not from memory or ad-hoc probes alone. Current cutover validation targets exact `@cursor/sdk@1.0.
|
|
241
|
+
Hard repo rule: Cursor SDK behavior claims must come from the installed `@cursor/sdk` package and/or https://cursor.com/docs/sdk/typescript, not from memory or ad-hoc probes alone. Current cutover validation targets exact `@cursor/sdk@1.0.15` and pi 0.77.0 local packages.
|
|
242
242
|
|
|
243
243
|
## Pi provider SDK event capture
|
|
244
244
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-cursor-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"description": "pi provider extension backed by @cursor/sdk local agents",
|
|
5
5
|
"author": "Mitch Fultz (https://github.com/fitchmultz)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"debug:mcp-coldstart": "node scripts/probe-mcp-coldstart.mjs"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@cursor/sdk": "1.0.
|
|
85
|
+
"@cursor/sdk": "1.0.15",
|
|
86
86
|
"@modelcontextprotocol/sdk": "^1.29.0"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
@@ -92,9 +92,9 @@
|
|
|
92
92
|
"typebox": "*"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
|
-
"@earendil-works/pi-ai": "0.
|
|
96
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
97
|
-
"@earendil-works/pi-tui": "0.
|
|
95
|
+
"@earendil-works/pi-ai": "0.77.0",
|
|
96
|
+
"@earendil-works/pi-coding-agent": "0.77.0",
|
|
97
|
+
"@earendil-works/pi-tui": "0.77.0",
|
|
98
98
|
"@xterm/xterm": "^6.0.0",
|
|
99
99
|
"playwright": "^1.60.0",
|
|
100
100
|
"typebox": "^1.1.38",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const CURSOR_API_KEY_ENV_VAR = "CURSOR_API_KEY";
|
|
2
|
+
export const CURSOR_API_KEY_CONFIG_VALUE = `$${CURSOR_API_KEY_ENV_VAR}`;
|
|
3
|
+
|
|
4
|
+
const CURSOR_API_KEY_PLACEHOLDERS = new Set([
|
|
5
|
+
CURSOR_API_KEY_ENV_VAR,
|
|
6
|
+
CURSOR_API_KEY_CONFIG_VALUE,
|
|
7
|
+
`\${${CURSOR_API_KEY_ENV_VAR}}`,
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
export function resolveCursorApiKey(apiKey?: string): string | undefined {
|
|
11
|
+
const trimmed = apiKey?.trim();
|
|
12
|
+
if (!trimmed) return undefined;
|
|
13
|
+
if (CURSOR_API_KEY_PLACEHOLDERS.has(trimmed)) return process.env.CURSOR_API_KEY?.trim() || undefined;
|
|
14
|
+
return trimmed;
|
|
15
|
+
}
|
|
@@ -13,13 +13,21 @@ export function getCursorPiBridgeContractText(): string {
|
|
|
13
13
|
return CURSOR_PI_BRIDGE_CONTRACT_LINES.join("\n");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
function formatPromptGuidelines(promptGuidelines: readonly string[] | undefined): string | undefined {
|
|
17
|
+
const guidelines = promptGuidelines?.map((guideline) => guideline.trim()).filter(Boolean) ?? [];
|
|
18
|
+
if (guidelines.length === 0) return undefined;
|
|
19
|
+
return ["Pi tool prompt guidelines:", ...guidelines.map((guideline) => `- ${guideline}`)].join("\n");
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
export function buildCursorPiBridgeMcpToolDescription(options: {
|
|
17
23
|
piToolName: string;
|
|
18
24
|
mcpToolName: string;
|
|
19
25
|
piToolDescription: string;
|
|
26
|
+
piToolPromptGuidelines?: readonly string[];
|
|
20
27
|
}): string {
|
|
21
28
|
return [
|
|
22
29
|
options.piToolDescription,
|
|
30
|
+
formatPromptGuidelines(options.piToolPromptGuidelines),
|
|
23
31
|
`Call MCP name ${options.mcpToolName} (pi tool: ${options.piToolName}). Full tool-surface rules are in the session bootstrap prompt.`,
|
|
24
|
-
].join("\n");
|
|
32
|
+
].filter((line): line is string => line !== undefined).join("\n");
|
|
25
33
|
}
|
|
@@ -64,6 +64,7 @@ export function snapshotToolToMcpTool(tool: CursorPiBridgeToolDefinition): Tool
|
|
|
64
64
|
piToolName: tool.piToolName,
|
|
65
65
|
mcpToolName: tool.mcpToolName,
|
|
66
66
|
piToolDescription: tool.description,
|
|
67
|
+
piToolPromptGuidelines: tool.promptGuidelines,
|
|
67
68
|
}),
|
|
68
69
|
inputSchema: tool.inputSchema,
|
|
69
70
|
_meta: { piToolName: tool.piToolName },
|
|
@@ -42,6 +42,7 @@ export function buildCursorPiToolBridgeSurfaceSignature(snapshot: CursorPiToolBr
|
|
|
42
42
|
piToolName: tool.piToolName,
|
|
43
43
|
mcpToolName: tool.mcpToolName,
|
|
44
44
|
description: tool.description,
|
|
45
|
+
promptGuidelines: tool.promptGuidelines,
|
|
45
46
|
inputSchema: tool.inputSchema,
|
|
46
47
|
source: tool.sourceInfo?.source,
|
|
47
48
|
path: tool.sourceInfo?.path,
|
|
@@ -79,6 +80,7 @@ export function buildCursorPiToolBridgeSnapshot(
|
|
|
79
80
|
piToolName: tool.name,
|
|
80
81
|
mcpToolName,
|
|
81
82
|
description,
|
|
83
|
+
promptGuidelines: tool.promptGuidelines,
|
|
82
84
|
inputSchema: normalizeMcpInputSchema(tool.parameters),
|
|
83
85
|
sourceInfo: tool.sourceInfo,
|
|
84
86
|
});
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function resolveCursorApiKey(apiKey?: string): string | undefined {
|
|
4
|
-
const trimmed = apiKey?.trim();
|
|
5
|
-
if (!trimmed) return undefined;
|
|
6
|
-
if (trimmed === CURSOR_API_KEY_ENV_VAR) return process.env.CURSOR_API_KEY?.trim();
|
|
7
|
-
return trimmed;
|
|
8
|
-
}
|
|
1
|
+
export { resolveCursorApiKey } from "./cursor-api-key.js";
|
|
@@ -4,7 +4,7 @@ import type { CursorPiToolBridgeSnapshot } from "./cursor-pi-tool-bridge-types.j
|
|
|
4
4
|
export const CURSOR_TOOL_MANIFEST_ENV = "PI_CURSOR_TOOL_MANIFEST";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Representative @cursor/sdk@1.0.
|
|
7
|
+
* Representative @cursor/sdk@1.0.15 local-agent ToolType values; actual exposure can vary by run.
|
|
8
8
|
* See docs/cursor-native-tool-replay.md#sdk-tooltype-replay-matrix.
|
|
9
9
|
*/
|
|
10
10
|
export const CURSOR_HOST_TOOL_MANIFEST_SUMMARY =
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { registerCursorAgentsContextDedup } from "./cursor-agents-context.js";
|
|
|
9
9
|
import { registerCursorSessionAgent } from "./cursor-session-agent.js";
|
|
10
10
|
import { prepareCursorSessionForCompaction } from "./cursor-session-compaction-prep.js";
|
|
11
11
|
import { streamCursor } from "./cursor-provider.js";
|
|
12
|
+
import { CURSOR_API_KEY_CONFIG_VALUE } from "./cursor-api-key.js";
|
|
12
13
|
|
|
13
14
|
type CursorExtensionApi =
|
|
14
15
|
& Pick<ExtensionAPI, "registerProvider" | "registerCommand" | "on">
|
|
@@ -24,7 +25,7 @@ function createCursorProviderConfig(models: ProviderModelConfig[]): ProviderConf
|
|
|
24
25
|
return {
|
|
25
26
|
name: "Cursor",
|
|
26
27
|
baseUrl: "https://cursor.com",
|
|
27
|
-
apiKey:
|
|
28
|
+
apiKey: CURSOR_API_KEY_CONFIG_VALUE,
|
|
28
29
|
api: "cursor-sdk",
|
|
29
30
|
models,
|
|
30
31
|
streamSimple: streamCursor,
|
package/src/model-discovery.ts
CHANGED
|
@@ -8,10 +8,10 @@ import type {
|
|
|
8
8
|
import { AuthStorage, type ProviderModelConfig } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
import type { ModelThinkingLevel, ThinkingLevelMap } from "@earendil-works/pi-ai";
|
|
10
10
|
import { loadContextWindowCache } from "./context-window-cache.js";
|
|
11
|
+
import { CURSOR_API_KEY_ENV_VAR, resolveCursorApiKey } from "./cursor-api-key.js";
|
|
11
12
|
import { FALLBACK_MODEL_ITEMS } from "./cursor-fallback-models.generated.js";
|
|
12
13
|
|
|
13
14
|
const CURSOR_PROVIDER_ID = "cursor";
|
|
14
|
-
const CURSOR_API_KEY_ENV_VAR = "CURSOR_API_KEY";
|
|
15
15
|
const FALLBACK_CONTEXT_WINDOW = 128000;
|
|
16
16
|
const FALLBACK_MAX_TOKENS = 16384;
|
|
17
17
|
const ZERO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
@@ -50,29 +50,22 @@ function getCliApiKeyFromArgv(argv: string[] = process.argv): string | undefined
|
|
|
50
50
|
return undefined;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function normalizeApiKey(value: string | undefined): string | undefined {
|
|
54
|
-
const trimmed = value?.trim();
|
|
55
|
-
if (!trimmed) return undefined;
|
|
56
|
-
if (trimmed === CURSOR_API_KEY_ENV_VAR) return process.env.CURSOR_API_KEY?.trim() || undefined;
|
|
57
|
-
return trimmed;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
53
|
async function getStoredCursorApiKey(): Promise<string | undefined> {
|
|
61
54
|
try {
|
|
62
|
-
return
|
|
55
|
+
return resolveCursorApiKey(await AuthStorage.create().getApiKey(CURSOR_PROVIDER_ID, { includeFallback: false }));
|
|
63
56
|
} catch {
|
|
64
57
|
return undefined;
|
|
65
58
|
}
|
|
66
59
|
}
|
|
67
60
|
|
|
68
61
|
async function getDiscoveryApiKey(): Promise<string | undefined> {
|
|
69
|
-
const cliApiKey =
|
|
62
|
+
const cliApiKey = resolveCursorApiKey(getCliApiKeyFromArgv());
|
|
70
63
|
if (cliApiKey) return cliApiKey;
|
|
71
64
|
|
|
72
65
|
const storedApiKey = await getStoredCursorApiKey();
|
|
73
66
|
if (storedApiKey) return storedApiKey;
|
|
74
67
|
|
|
75
|
-
return
|
|
68
|
+
return resolveCursorApiKey(process.env.CURSOR_API_KEY);
|
|
76
69
|
}
|
|
77
70
|
|
|
78
71
|
export interface CursorModelMetadata {
|
|
@@ -472,5 +465,5 @@ export const __testUtils = {
|
|
|
472
465
|
parseContextWindow,
|
|
473
466
|
registerModelItems,
|
|
474
467
|
getCliApiKeyFromArgv,
|
|
475
|
-
normalizeApiKey,
|
|
468
|
+
normalizeApiKey: resolveCursorApiKey,
|
|
476
469
|
};
|