Parity with magpie's built-ins: a failed sign-in says why, CLI-backed Command Code and Devin accounts follow the CLI's key, Factory's refused renewal is a 401 in the caller's API shape

- every {type:"failed"} carries an error reason magpie shows
- commandcode/devin: accounts taken from the CLI are marked metadata.cli and re-read its credentials on each request, usage and models
- factory: a refused refresh answers 401 authentication_error (Anthropic shape on /llm/a/, OpenAI's elsewhere) instead of throwing; the whoami back-off is per account; 403 hints name the account to sign in again
- versions: factory/devin/commandcode/cursor/kiro/mimo/zed/zcode 0.1.2, workbuddy 0.1.3
This commit is contained in:
yetone
2026-10-01 00:55:50 +08:00
parent bd9c0780cc
commit c8f4d448df
22 changed files with 228 additions and 75 deletions
+7 -6
View File
@@ -268,7 +268,7 @@ async function browserSignIn() {
try {
res = await fetch(`${API}/auth/poll?uuid=${uuid}&verifier=${verifier}`, { headers, signal: AbortSignal.timeout(15_000) })
} catch {
if (++errors >= 3) return { type: "failed" }
if (++errors >= 3) return { type: "failed", error: "couldn't reach Cursor" }
await sleep(wait)
continue
}
@@ -278,12 +278,12 @@ async function browserSignIn() {
continue
}
if (!res.ok) {
if (res.status === 403 || ++errors >= 3) return { type: "failed" }
if (res.status === 403 || ++errors >= 3) return { type: "failed", error: res.status === 403 ? "Cursor refused the sign-in (403)" : `Cursor's sign-in answered HTTP ${res.status}` }
await sleep(wait)
continue
}
const j = await res.json().catch(() => null)
if (!j?.accessToken || !("refreshToken" in j)) return { type: "failed" }
if (!j?.accessToken || !("refreshToken" in j)) return { type: "failed", error: "Cursor sent back no token" }
const who = await whoIs(j.accessToken)
return {
type: "success",
@@ -294,7 +294,7 @@ async function browserSignIn() {
...(who.plan ? { plan: who.plan } : {}),
}
}
return { type: "failed" }
return { type: "failed", error: "the sign-in timed out" }
},
}
}
@@ -309,9 +309,10 @@ async function cliSignIn() {
async callback() {
const tok = await cliToken()
const exp = expiry(tok)
if (!tok || (exp && exp <= Date.now())) return { type: "failed" }
if (!tok) return { type: "failed", error: "cursor-agent isn't signed in: run `cursor-agent login`" }
if (exp && exp <= Date.now()) return { type: "failed", error: "cursor-agent's sign-in has run out: run `cursor-agent login` again" }
const who = await whoIs(tok)
if (!who.email) return { type: "failed" }
if (!who.email) return { type: "failed", error: "Cursor couldn't say which account is signed in" }
return { type: "success", access: "", refresh: CLI_MARK, expires: 0, accountId: who.email, ...(who.plan ? { plan: who.plan } : {}) }
},
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-cursor-auth",
"version": "0.1.1",
"version": "0.1.2",
"description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to",
"type": "module",
"main": "./index.mjs",