@caph42/pi-cursor-provider 0.6.0 → 0.7.0
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 +4 -3
- package/package.json +1 -1
- package/src/fast-footer.ts +2 -2
- package/src/fast.ts +9 -6
- package/src/native-session.ts +5 -2
- package/src/pi-stream.ts +60 -1
- package/src/protocol.ts +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.7.0
|
|
6
|
+
|
|
7
|
+
- `/cursor.fast` with no argument toggles the current model between off and on. `/cursor.fast on`, `/cursor.fast off`, and `/cursor.fast status` are unchanged.
|
|
8
|
+
- Fast stays off the footer while it is off or unavailable. Enabling it publishes `Fast`; an enabled preference that the current thinking level no longer supports publishes `Fast unavailable`. Non-Cursor models still publish nothing.
|
|
9
|
+
- Each assistant stream event carries `cursorOutputTiming`, copied when the event is queued. The shared partial stays the one live message, so a consumer that reads the queue later still sees the reading from that moment: estimated output tokens, elapsed time, and a receive-side tokens-per-second once a measured interval exists. Bytes that open a burst, including the first delta after a tool call, are not in the rate. Cursor's own output count arrives with the stop and replaces the estimate only when it is measured. Replayed native events are marked and do not move the clock.
|
|
10
|
+
|
|
3
11
|
## 0.6.0
|
|
4
12
|
|
|
5
13
|
- A merged (unified) subscription now offers only the models its included weekly allowance covers. `GetPlanInfo`'s `isMerged` decides whether the filter runs; the current period's `autoBucketModels` names the ids that allowance pays for, and an entry is offered when the id a Run at its default parameters resolves to is one of them. The filter is applied when the catalogue is read, not to the catalogue itself: the stored list stays complete, request resolution keeps every variant, and `{ "showAllModels": true }` in `cursor.json` offers everything again without a refresh and without the plan lookups. Cursor's own plans filter nothing, and a plan or period report that cannot be read filters nothing either. Checked against a live X unified account: 6 of 65 entries stayed (auto, Grok 4.7 at two context sizes, Grok 4.6, Grok 4.5, Composer 2.5); two of the excluded ones were sampled and both were refused with `429 … is not included in your weekly usage`, and the rest were not each exercised. A refresh makes one more request (`GetPlanInfo`), and a second one (`GetCurrentPeriodUsage`) only on a merged plan.
|
package/README.md
CHANGED
|
@@ -101,16 +101,17 @@ Cost stays zero for every model: a subscription bill is not a token price.
|
|
|
101
101
|
Select a Cursor model, then use:
|
|
102
102
|
|
|
103
103
|
```text
|
|
104
|
+
/cursor.fast
|
|
104
105
|
/cursor.fast on
|
|
105
|
-
/cursor.fast status
|
|
106
106
|
/cursor.fast off
|
|
107
|
+
/cursor.fast status
|
|
107
108
|
```
|
|
108
109
|
|
|
109
|
-
With no argument, `/cursor.fast`
|
|
110
|
+
With no argument, `/cursor.fast` toggles the current model: off becomes on, and on becomes off. `/cursor.fast on` and `/cursor.fast off` set it explicitly. In the TUI, type `/cursor.fast ` and press Tab to choose `on` or `off`; a unique prefix such as `of` completes to `off` without executing the command. `/cursor.fast status` only reports the current state. In the TUI, enabled fast shows `Fast` on the second footer row beside the model/thinking information. Off shows nothing there. Other extension statuses retain their own row. The same text is also published through `ctx.ui.setStatus`, so a footer that renders extension statuses — Pi's own footer, or pi-ccline's — still shows it when another extension owns the footer slot; Cursor's footer filters that key out, so it never appears twice. RPC clients continue receiving the `cursor-fast` status text. Enabling fast preserves the selected model ID, context size, and thinking level. It requires an account-available fast variant at the same context and effective thinking parameters; unsupported combinations are rejected.
|
|
110
111
|
|
|
111
112
|
The setting defaults to off and belongs to the current model in the current session. Other models keep their own settings. Reloading or resuming that session restores the setting from its current branch; a new session starts with fast off. Changes apply to the next request and require the current response to finish first.
|
|
112
113
|
|
|
113
|
-
If fast is enabled and a later thinking change or catalogue update removes support, the footer shows `
|
|
114
|
+
If fast is enabled and a later thinking change or catalogue update removes support, the footer shows `Fast unavailable` and requests report an error until you select a supported thinking level or run `/cursor.fast off`. The command does not add duplicate fast models to `/model`.
|
|
114
115
|
|
|
115
116
|
The second-row display uses Pi 1.4's custom-footer slot and its default renderer. On other Pi versions it falls back to the standard status row until the footer adapter is verified. Extensions that replace the same footer slot can replace this layout; Cursor yields if another extension takes ownership. The `cursor-fast` status row is still set in that case, so a footer that renders extension statuses keeps showing the fast state; otherwise `/cursor.fast status` remains the source of truth.
|
|
116
117
|
|
package/package.json
CHANGED
package/src/fast-footer.ts
CHANGED
|
@@ -70,8 +70,8 @@ export function createFastFooter(
|
|
|
70
70
|
render(width: number): string[] {
|
|
71
71
|
footer.setAutoCompactEnabled(pi.getSettings().compaction?.enabled ?? true)
|
|
72
72
|
const lines = footer.render(width)
|
|
73
|
-
const text = badge()
|
|
74
|
-
const label = theme.fg(text === "
|
|
73
|
+
const text = badge()
|
|
74
|
+
const label = theme.fg(text === "Fast" ? "accent" : "warning", text)
|
|
75
75
|
const suffix = ` • ${label}`
|
|
76
76
|
const reserved = visibleWidth(suffix)
|
|
77
77
|
lines[1] = width <= reserved
|
package/src/fast.ts
CHANGED
|
@@ -70,8 +70,10 @@ export function registerCursorFast(pi: ExtensionAPI) {
|
|
|
70
70
|
return
|
|
71
71
|
}
|
|
72
72
|
const on = enabled.has(model.id)
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// Off is the default, so it stays off the footer. Only an enabled preference
|
|
74
|
+
// earns the row; an unsupported thinking level keeps it visible as a warning.
|
|
75
|
+
if (!on) { display(ctx, undefined); return }
|
|
76
|
+
display(ctx, supported(model, pi.getThinkingLevel()) ? "Fast" : "Fast unavailable")
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
function restore(ctx: ExtensionContext) {
|
|
@@ -108,12 +110,12 @@ export function registerCursorFast(pi: ExtensionAPI) {
|
|
|
108
110
|
pi.on("before_agent_start", (_event, ctx) => updateStatus(ctx))
|
|
109
111
|
|
|
110
112
|
pi.registerCommand("cursor.fast", {
|
|
111
|
-
description: "
|
|
113
|
+
description: "Toggle Cursor fast for the current model, or set on, off, or status",
|
|
112
114
|
getArgumentCompletions: (prefix) => ["on", "off"].filter((value) => value.startsWith(prefix.trimStart().toLowerCase())).map((value) => ({ value, label: value })),
|
|
113
115
|
handler: async (args, ctx) => {
|
|
114
|
-
const
|
|
115
|
-
if (!["on", "off", "status"].includes(
|
|
116
|
-
ctx.ui.notify("Usage: /cursor.fast on|off|status", "warning")
|
|
116
|
+
const requested = args.trim().toLowerCase()
|
|
117
|
+
if (requested && !["on", "off", "status"].includes(requested)) {
|
|
118
|
+
ctx.ui.notify("Usage: /cursor.fast [on|off|status]", "warning")
|
|
117
119
|
return
|
|
118
120
|
}
|
|
119
121
|
const model = modelOf(ctx)
|
|
@@ -121,6 +123,7 @@ export function registerCursorFast(pi: ExtensionAPI) {
|
|
|
121
123
|
ctx.ui.notify("Select a Cursor model with /model before using /cursor.fast.", "warning")
|
|
122
124
|
return
|
|
123
125
|
}
|
|
126
|
+
const action = requested || (enabled.has(model.id) ? "off" : "on")
|
|
124
127
|
if (action !== "status" && !ctx.isIdle()) {
|
|
125
128
|
ctx.ui.notify("Wait for the current response to finish before changing Cursor fast mode.", "warning")
|
|
126
129
|
return
|
package/src/native-session.ts
CHANGED
|
@@ -334,12 +334,13 @@ class Segment {
|
|
|
334
334
|
}
|
|
335
335
|
if (at < segment.events.length) {
|
|
336
336
|
const event = segment.events[at++]
|
|
337
|
-
if (replay && event.stop) return { value: { ...event, usage: {
|
|
337
|
+
if (replay && event.stop) return { value: { ...event, replay: true, usage: {
|
|
338
338
|
prompt_tokens: 0, completion_tokens: 0, total_tokens: 0,
|
|
339
|
+
cursor_output_source: "replayed",
|
|
339
340
|
prompt_tokens_details: { cached_tokens: 0, cache_write_tokens: 0 },
|
|
340
341
|
magpie_native: { accounting: "replayed" },
|
|
341
342
|
} }, done: false }
|
|
342
|
-
return { value: event, done: false }
|
|
343
|
+
return { value: replay ? { ...event, replay: true } : event, done: false }
|
|
343
344
|
}
|
|
344
345
|
return { done: true }
|
|
345
346
|
},
|
|
@@ -758,6 +759,7 @@ class NativeSession {
|
|
|
758
759
|
for (const c of segment.calls) this.pool.handles.set(c.id, { owner: this, batch: segment })
|
|
759
760
|
segment.finish({ stop: "tool_calls", usage: {
|
|
760
761
|
prompt_tokens: 0, completion_tokens: 0, total_tokens: 0,
|
|
762
|
+
cursor_output_source: "pending",
|
|
761
763
|
prompt_tokens_details: { cached_tokens: 0, cache_write_tokens: 0 },
|
|
762
764
|
magpie_native: { accounting: "pending" },
|
|
763
765
|
} })
|
|
@@ -872,6 +874,7 @@ class NativeSession {
|
|
|
872
874
|
const prompt = u.input + u.cacheRead + u.cacheWrite
|
|
873
875
|
this.finalUsage = {
|
|
874
876
|
prompt_tokens: prompt, completion_tokens: u.output, total_tokens: prompt + u.output,
|
|
877
|
+
cursor_output_source: !measuredOutput ? "estimated" : this.steps > 1 ? "allocated" : "measured",
|
|
875
878
|
prompt_tokens_details: { cached_tokens: u.cacheRead, cache_write_tokens: u.cacheWrite },
|
|
876
879
|
...(this.usageFields?.some((f) => f.num === 5) ? { completion_tokens_details: { reasoning_tokens: u.reasoning } } : {}),
|
|
877
880
|
...(!measuredInput || !measuredOutput ? { magpie_native: { accounting: "estimated" } } : {}),
|
package/src/pi-stream.ts
CHANGED
|
@@ -38,10 +38,25 @@ export interface CursorStreamOptions extends SimpleStreamOptions {
|
|
|
38
38
|
/** Shown when no Cursor credential is available. */
|
|
39
39
|
export const CURSOR_NOT_SIGNED_IN = "Cursor isn't signed in. Run /login cursor or set CURSOR_ACCESS_TOKEN."
|
|
40
40
|
|
|
41
|
+
export type CursorOutputTiming = {
|
|
42
|
+
outputTokens: number
|
|
43
|
+
source: "estimated" | "measured"
|
|
44
|
+
accountingSource?: "measured" | "estimated" | "allocated" | "pending" | "replayed" | "unavailable"
|
|
45
|
+
elapsedMs: number
|
|
46
|
+
/** Receive-side estimate after the first delta; absent without a measurable interval. */
|
|
47
|
+
tokensPerSecond?: number
|
|
48
|
+
tokensPerSecondSource?: "estimated"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type CursorMessage = AssistantMessage & { cursorOutputTiming?: CursorOutputTiming }
|
|
52
|
+
|
|
53
|
+
type Timed<T> = T & { cursorOutputTiming?: CursorOutputTiming }
|
|
54
|
+
|
|
41
55
|
type RunTool = { id: string; name: string; args: string }
|
|
42
56
|
type RunUsage = {
|
|
43
57
|
prompt_tokens?: number
|
|
44
58
|
completion_tokens?: number
|
|
59
|
+
cursor_output_source?: CursorOutputTiming["accountingSource"]
|
|
45
60
|
prompt_tokens_details?: { cached_tokens?: number; cache_write_tokens?: number }
|
|
46
61
|
completion_tokens_details?: { reasoning_tokens?: number }
|
|
47
62
|
/** Earlier steps' usage collected with this step; not applied to Pi context size. */
|
|
@@ -53,6 +68,7 @@ type RunUsage = {
|
|
|
53
68
|
}
|
|
54
69
|
}
|
|
55
70
|
type RunEvent = {
|
|
71
|
+
replay?: boolean
|
|
56
72
|
text?: string
|
|
57
73
|
reasoning?: string
|
|
58
74
|
tool?: RunTool
|
|
@@ -175,14 +191,45 @@ export async function emitCursorEvents(
|
|
|
175
191
|
events: AsyncIterable<RunEvent>,
|
|
176
192
|
options?: SimpleStreamOptions,
|
|
177
193
|
): Promise<void> {
|
|
178
|
-
const message = blank(model)
|
|
194
|
+
const message: CursorMessage = blank(model)
|
|
179
195
|
if (options?.reasoning) message.thinkingLevel = options.reasoning
|
|
196
|
+
let streamingAt: number | undefined
|
|
197
|
+
let elapsedMs = 0
|
|
198
|
+
let outputBytes = 0
|
|
199
|
+
// Bytes that opened a burst have no interval of their own, so the rate counts only what arrived after one.
|
|
200
|
+
let rateBytes = 0
|
|
201
|
+
const updateTiming = (text: string) => {
|
|
202
|
+
const now = performance.now()
|
|
203
|
+
const size = Buffer.byteLength(text, "utf8")
|
|
204
|
+
if (streamingAt === undefined) {
|
|
205
|
+
streamingAt = now
|
|
206
|
+
} else {
|
|
207
|
+
elapsedMs += Math.max(0, now - streamingAt)
|
|
208
|
+
streamingAt = now
|
|
209
|
+
rateBytes += size
|
|
210
|
+
}
|
|
211
|
+
outputBytes += size
|
|
212
|
+
const rateTokens = rateBytes / 4
|
|
213
|
+
// A fresh object each time: the previous event still points at the last one.
|
|
214
|
+
message.cursorOutputTiming = {
|
|
215
|
+
outputTokens: Math.ceil(outputBytes / 4),
|
|
216
|
+
source: "estimated",
|
|
217
|
+
elapsedMs,
|
|
218
|
+
...(elapsedMs > 0 && rateTokens > 0 ? { tokensPerSecond: rateTokens * 1000 / elapsedMs, tokensPerSecondSource: "estimated" as const } : {}),
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const pauseTiming = () => {
|
|
222
|
+
streamingAt = undefined
|
|
223
|
+
}
|
|
180
224
|
let finished = false
|
|
181
225
|
let open: { kind: "text" | "thinking"; index: number } | null = null
|
|
182
226
|
|
|
183
227
|
const push = (event: AssistantMessageEvent) => {
|
|
184
228
|
if (finished) return
|
|
185
229
|
if (event.type === "done" || event.type === "error") finished = true
|
|
230
|
+
// partial stays the one shared message. Its timing object is replaced as deltas arrive and the queue
|
|
231
|
+
// holds events until the consumer reads, so the reading for this event is copied onto the event itself.
|
|
232
|
+
if (message.cursorOutputTiming) (event as Timed<typeof event>).cursorOutputTiming = { ...message.cursorOutputTiming }
|
|
186
233
|
stream.push(event)
|
|
187
234
|
}
|
|
188
235
|
const endOpen = () => {
|
|
@@ -217,6 +264,7 @@ export async function emitCursorEvents(
|
|
|
217
264
|
return
|
|
218
265
|
}
|
|
219
266
|
if (event.text) {
|
|
267
|
+
if (!event.replay) updateTiming(event.text)
|
|
220
268
|
if (open?.kind === "thinking") endOpen()
|
|
221
269
|
if (!open) {
|
|
222
270
|
message.content.push({ type: "text", text: "" })
|
|
@@ -228,6 +276,7 @@ export async function emitCursorEvents(
|
|
|
228
276
|
push({ type: "text_delta", contentIndex: open.index, delta: event.text, partial: message })
|
|
229
277
|
}
|
|
230
278
|
if (event.reasoning) {
|
|
279
|
+
if (!event.replay) updateTiming(event.reasoning)
|
|
231
280
|
if (open?.kind === "text") endOpen()
|
|
232
281
|
if (!open) {
|
|
233
282
|
message.content.push({ type: "thinking", thinking: "" })
|
|
@@ -239,6 +288,7 @@ export async function emitCursorEvents(
|
|
|
239
288
|
push({ type: "thinking_delta", contentIndex: open.index, delta: event.reasoning, partial: message })
|
|
240
289
|
}
|
|
241
290
|
if (event.tool) {
|
|
291
|
+
pauseTiming()
|
|
242
292
|
endOpen()
|
|
243
293
|
sawTool = true
|
|
244
294
|
const call: ToolCall = {
|
|
@@ -256,6 +306,15 @@ export async function emitCursorEvents(
|
|
|
256
306
|
if (event.stop) {
|
|
257
307
|
endOpen()
|
|
258
308
|
applyUsage(message, model, event.usage)
|
|
309
|
+
if (message.cursorOutputTiming && event.usage?.cursor_output_source) {
|
|
310
|
+
const source = event.usage.cursor_output_source
|
|
311
|
+
const measured = source === "measured" && typeof event.usage.completion_tokens === "number"
|
|
312
|
+
message.cursorOutputTiming = {
|
|
313
|
+
...message.cursorOutputTiming,
|
|
314
|
+
accountingSource: source,
|
|
315
|
+
...(measured ? { source: "measured", outputTokens: event.usage.completion_tokens } : {}),
|
|
316
|
+
}
|
|
317
|
+
}
|
|
259
318
|
const reason: Extract<StopReason, "stop" | "toolUse"> = sawTool || event.stop === "tool_calls" ? "toolUse" : "stop"
|
|
260
319
|
message.stopReason = reason
|
|
261
320
|
push({ type: "done", reason, message })
|
package/src/protocol.ts
CHANGED
|
@@ -37,6 +37,7 @@ export type RunUsage = {
|
|
|
37
37
|
/** Earlier steps' usage collected with this one. It is not this step's context size. */
|
|
38
38
|
magpie_deferred?: { prompt_tokens: number; completion_tokens: number; cached_tokens: number; cache_write_tokens: number }
|
|
39
39
|
magpie_native?: { accounting: "pending" | "estimated" | "replayed" }
|
|
40
|
+
cursor_output_source?: "measured" | "estimated" | "allocated" | "pending" | "replayed" | "unavailable"
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/** What a Run streams to the caller. Each event sets one of text, reasoning, tool, stop, or error. */
|
|
@@ -355,8 +356,12 @@ export async function* decode(
|
|
|
355
356
|
let wrote = 0
|
|
356
357
|
let usage: UsageCounts = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0 }
|
|
357
358
|
let counted = false
|
|
359
|
+
let outputSource: RunUsage["cursor_output_source"] = "unavailable"
|
|
358
360
|
const finish = (more: UsageCounts | null) => {
|
|
359
|
-
if (!counted && !usage.output)
|
|
361
|
+
if (!counted && !usage.output) {
|
|
362
|
+
usage.output = Math.floor((said + 3) / 4)
|
|
363
|
+
outputSource = "estimated"
|
|
364
|
+
}
|
|
360
365
|
if (!counted && !usage.input && !usage.cacheRead && !usage.cacheWrite) usage.input = estimate
|
|
361
366
|
const prompt = usage.input + usage.cacheRead + usage.cacheWrite
|
|
362
367
|
const deferred = more && more.input + more.output + more.cacheRead + more.cacheWrite > 0
|
|
@@ -365,6 +370,7 @@ export async function* decode(
|
|
|
365
370
|
usage: {
|
|
366
371
|
prompt_tokens: prompt,
|
|
367
372
|
completion_tokens: usage.output,
|
|
373
|
+
cursor_output_source: outputSource,
|
|
368
374
|
total_tokens: prompt + usage.output,
|
|
369
375
|
prompt_tokens_details: { cached_tokens: usage.cacheRead, cache_write_tokens: usage.cacheWrite },
|
|
370
376
|
...(usage.reasoning ? { completion_tokens_details: { reasoning_tokens: usage.reasoning } } : {}),
|
|
@@ -385,7 +391,10 @@ export async function* decode(
|
|
|
385
391
|
if (calls > 0 && !ended && stepUsage) {
|
|
386
392
|
close?.()
|
|
387
393
|
const u = await stepUsage().catch(() => null)
|
|
388
|
-
if (u)
|
|
394
|
+
if (u) {
|
|
395
|
+
usage = u
|
|
396
|
+
outputSource = "measured"
|
|
397
|
+
}
|
|
389
398
|
counted = u === false || !!u
|
|
390
399
|
} else if (calls > 0) {
|
|
391
400
|
close?.()
|
|
@@ -455,6 +464,7 @@ export async function* decode(
|
|
|
455
464
|
}
|
|
456
465
|
case 14: // turn ended, with what it used
|
|
457
466
|
usage = usageOf(uf)
|
|
467
|
+
outputSource = uf.some((field) => field.num === 2) ? "measured" : "unavailable"
|
|
458
468
|
ended = true
|
|
459
469
|
counted = true
|
|
460
470
|
if (calls === 0) {
|