mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 04:50:52 +00:00
* feat(ai): support Cursor CLI login for subscription quota Allow the managed Cursor agent to authenticate via local `agent` CLI login as an alternative to CURSOR_API_KEY, so Catty can use subscription Auto quota. Keep API key and CLI login mutually exclusive, isolate resume sessions by auth mode, and expose selectable CLI models with auto as the default. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(ai): harden Cursor CLI login path after review Address multi-agent review findings: soft-cancel abort without late stream errors, prefer cursor-agent over ambiguous agent binaries, mode-aware availability without wiping API keys or sticky-disabling, and concurrent MCP merge refcount restore. Add unit coverage for the new contracts. --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: bincxz <16399091+binaricat@users.noreply.github.com>
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
const SDK_SESSION_ID_PREFIX = "netcatty-sdk-session:";
|
|
|
|
function normalizeCursorAuthMode(authMode) {
|
|
return authMode === "cli-login" ? "cli-login" : authMode === "api-key" ? "api-key" : undefined;
|
|
}
|
|
|
|
function encodeSdkSessionIdentity(sessionId, sdkBackend, binPath, runtime = "sdk", authMode) {
|
|
if (!sessionId || !sdkBackend) return sessionId;
|
|
const payload = {
|
|
v: 1,
|
|
id: sessionId,
|
|
backend: sdkBackend,
|
|
binPath: binPath || "",
|
|
runtime: runtime === "app-server" ? "app-server" : "sdk",
|
|
};
|
|
const normalizedAuthMode = normalizeCursorAuthMode(authMode);
|
|
if (normalizedAuthMode) payload.authMode = normalizedAuthMode;
|
|
return `${SDK_SESSION_ID_PREFIX}${encodeURIComponent(JSON.stringify(payload))}`;
|
|
}
|
|
|
|
function parseSdkSessionIdentity(value) {
|
|
const raw = String(value || "").trim();
|
|
if (!raw.startsWith(SDK_SESSION_ID_PREFIX)) return null;
|
|
try {
|
|
const parsed = JSON.parse(decodeURIComponent(raw.slice(SDK_SESSION_ID_PREFIX.length)));
|
|
if (!parsed || parsed.v !== 1 || !parsed.id || !parsed.backend) return null;
|
|
const authMode = normalizeCursorAuthMode(parsed.authMode);
|
|
return {
|
|
...parsed,
|
|
runtime: parsed.runtime === "app-server" ? "app-server" : "sdk",
|
|
...(authMode ? { authMode } : {}),
|
|
};
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
SDK_SESSION_ID_PREFIX,
|
|
encodeSdkSessionIdentity,
|
|
normalizeCursorAuthMode,
|
|
parseSdkSessionIdentity,
|
|
};
|