@caph42/pi-cursor-provider 0.5.2 → 0.5.3
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 +4 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/index.ts +61 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.3
|
|
4
|
+
|
|
5
|
+
- The Cursor catalogue refresh on `session_start` no longer blocks the session in the TUI. Pi paints before it binds extensions and awaits `session_start` handlers one at a time, so the network round trip left the built-in footer on screen for as long as it took — measured 1.9 s with a healthy connection, up to the 15 s timeout without one — and every extension registered after this one waited with it. The TUI path now starts the refresh in the background and publishes when it lands; a new session, a reload, or a shutdown cancels the request it replaced, so `refreshModels` cannot publish a catalogue for a session that ended, and no status or warning from it is applied. Headless modes still await it: an RPC host reads the catalogue right after startup and has no other signal that it changed.
|
|
6
|
+
|
|
3
7
|
## 0.5.2
|
|
4
8
|
|
|
5
9
|
- The `cursor-fast` status is always published with `ctx.ui.setStatus`, not only when Pi's own footer is in use. A footer that renders extension statuses — including pi-ccline, which takes the only custom-footer slot on Pi 1.4 — now shows `fast: on/off/unavailable` instead of losing it. Cursor's own footer still filters that key out, so the inline badge never appears twice.
|
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Then select a model:
|
|
|
53
53
|
|
|
54
54
|
The extension registers a native Pi provider. Its synchronous model directory and availability filter read `cursor.json`, so local rules apply even when Cursor cannot refresh its remote catalogue. The availability filter also covers models added through `models.json`.
|
|
55
55
|
|
|
56
|
-
Successful discovery saves the complete catalogue in Pi's `models-store.json`. Startup and `/reload` restore that catalogue before applying the current hide rules; a session-start refresh discovers models when no cache exists. Offline mode restores the cache without fetching. A failed remote refresh keeps the previous catalogue, and a first-load failure is reported instead of silently returning an empty list.
|
|
56
|
+
Successful discovery saves the complete catalogue in Pi's `models-store.json`. Startup and `/reload` restore that catalogue before applying the current hide rules; a session-start refresh discovers models when no cache exists. In the TUI that refresh runs in the background, so the session opens without waiting for the network and the fast badge or a failure notice arrives when it lands; headless hosts await it. Offline mode restores the cache without fetching. A failed remote refresh keeps the previous catalogue, and a first-load failure is reported instead of silently returning an empty list.
|
|
57
57
|
|
|
58
58
|
A pattern matches the whole id `/model` shows (the part after `cursor/`), ignoring case. `*` stands for any run of characters; every other character, `?` included, is literal. A pattern without the `@300k` size suffix hides every context size of that model. A missing or malformed file hides nothing, and `/cursor.doctor` prints the patterns in force. Reopen `/model` and let its catalogue refresh finish to see the new list. After updating the extension itself, run `/reload` once. When developing from a checkout, configure that local path as the package source; `/reload` reloads configured sources and does not copy checkout changes into an npm installation.
|
|
59
59
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { createHash } from "node:crypto"
|
|
10
10
|
import type { Model, Provider } from "@earendil-works/pi-ai"
|
|
11
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"
|
|
11
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent"
|
|
12
12
|
import { login, refresh, resolveAccessToken } from "./auth.ts"
|
|
13
13
|
import { AGENT, clientVersion } from "./client.ts"
|
|
14
14
|
import { hiddenPatterns, visible } from "./config.ts"
|
|
@@ -127,15 +127,69 @@ export default function (pi: ExtensionAPI) {
|
|
|
127
127
|
|
|
128
128
|
// Startup and /reload restore cached models first. Discover the catalogue
|
|
129
129
|
// for a first install too, once the host has bound credentials and context.
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
const refreshCatalogue = (ctx: ExtensionContext, signal: AbortSignal) =>
|
|
131
|
+
ctx.modelRegistry.refresh({
|
|
132
132
|
providers: ["cursor"],
|
|
133
133
|
allowNetwork: process.env.PI_OFFLINE === undefined,
|
|
134
|
-
signal
|
|
134
|
+
signal,
|
|
135
135
|
})
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
|
|
137
|
+
// Pi awaits session_start handlers one at a time, so awaiting the network
|
|
138
|
+
// round trip here holds back every extension registered later in the session:
|
|
139
|
+
// the TUI paints its built-in footer before it binds extensions, and a custom
|
|
140
|
+
// footer stays unpainted until this handler returns (measured: ~1.9 s). Run
|
|
141
|
+
// the refresh in the background there and let it publish when it lands.
|
|
142
|
+
// Headless modes keep awaiting: an RPC host reads the catalogue right after
|
|
143
|
+
// startup and has no other signal that it changed.
|
|
144
|
+
let catalogueGeneration = 0
|
|
145
|
+
let catalogueAbort: AbortController | null = null
|
|
146
|
+
|
|
147
|
+
// A new session, a reload, or a shutdown owns the registry and the status row
|
|
148
|
+
// from now on: bump the generation and stop the request the previous session
|
|
149
|
+
// started, so `refreshModels` cannot publish a catalogue for it either.
|
|
150
|
+
function retireCatalogue(): number {
|
|
151
|
+
catalogueGeneration += 1
|
|
152
|
+
catalogueAbort?.abort()
|
|
153
|
+
catalogueAbort = null
|
|
154
|
+
return catalogueGeneration
|
|
155
|
+
}
|
|
156
|
+
pi.on("session_shutdown", () => { retireCatalogue() })
|
|
157
|
+
|
|
158
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
159
|
+
const generation = retireCatalogue()
|
|
160
|
+
const timeout = AbortSignal.timeout(15_000)
|
|
161
|
+
if (ctx.mode !== "tui") {
|
|
162
|
+
const result = await refreshCatalogue(ctx, timeout)
|
|
163
|
+
fast.updateStatus(ctx)
|
|
164
|
+
const error = result.errors.get("cursor")
|
|
165
|
+
if (error && ctx.hasUI) ctx.ui.notify(`Cursor model catalogue: ${error.message}`, "warning")
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
const request = new AbortController()
|
|
169
|
+
catalogueAbort = request
|
|
170
|
+
const signal = AbortSignal.any([timeout, request.signal])
|
|
171
|
+
void (async () => {
|
|
172
|
+
try {
|
|
173
|
+
const result = await refreshCatalogue(ctx, signal)
|
|
174
|
+
// The status row and the warning belong to the session that asked, and
|
|
175
|
+
// that session is gone as soon as the generation moved on.
|
|
176
|
+
if (generation !== catalogueGeneration) return
|
|
177
|
+
fast.updateStatus(ctx)
|
|
178
|
+
const error = result.errors.get("cursor")
|
|
179
|
+
if (error && ctx.hasUI) ctx.ui.notify(`Cursor model catalogue: ${error.message}`, "warning")
|
|
180
|
+
} catch (error) {
|
|
181
|
+
// Nothing awaits this task, so Pi's error listener cannot see the throw,
|
|
182
|
+
// and a superseded ctx throws as soon as it is touched.
|
|
183
|
+
if (generation !== catalogueGeneration) return
|
|
184
|
+
try {
|
|
185
|
+
if (ctx.hasUI) ctx.ui.notify(`Cursor model catalogue: ${error instanceof Error ? error.message : String(error)}`, "warning")
|
|
186
|
+
} catch {
|
|
187
|
+
// The session ended while the refresh was in flight.
|
|
188
|
+
}
|
|
189
|
+
} finally {
|
|
190
|
+
if (catalogueAbort === request) catalogueAbort = null
|
|
191
|
+
}
|
|
192
|
+
})()
|
|
139
193
|
})
|
|
140
194
|
|
|
141
195
|
registerCursorDoctor(pi)
|