UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

110 lines • 6.22 kB
import type { AuthCheck, AuthContext, Credential, OAuthAuth, OAuthCredential, OAuthCredentials, OAuthLoginCallbacks } from "@earendil-works/pi-ai"; import { type CursorCliAccountSlot, type CursorCliOauthCredential } from "./accounts.ts"; import { type CursorCliOauthProviderSettings } from "./settings.ts"; export declare const CURSOR_CLI_OAUTH_PROVIDER_ID = "cursor-cli-oauth"; export declare const CURSOR_CLI_OAUTH_NAME = "Cursor CLI (OAuth)"; declare const FILE_STORE_LANE: "file-store"; type CursorCliOauthSettings = Pick<CursorCliOauthProviderSettings, "enabled" | "executablePath"> & Partial<Pick<CursorCliOauthProviderSettings, "explicitlyDisabled">>; /** * The opt-in rule, in one place so availability, turn-time resolution, and the * host-derived bootstrap gate cannot disagree. * * - `enabled: false` written verbatim in settings or the environment is a kill * switch: the lane is off regardless of what is stored. * - Otherwise the flag gates only the host-CLI-derived opt-in. Stored senpi account slots * exist only because the user ran `/login cursor-cli-oauth` or * `/cursor-account import`, and that explicit action IS the opt-in. */ export declare function isCursorCliOauthLaneEnabled(settings: CursorCliOauthSettings, storedAccountCount: number): boolean; type ImportedCursorCredential = { access: string; refresh: string; expires?: number; }; export type CursorCliOauthConfigDeps = { readCurrent: () => Promise<Credential | undefined>; readSettings: () => CursorCliOauthSettings; resolveExecutable: (settings: CursorCliOauthSettings) => string; loadOAuth?: () => Promise<OAuthAuth>; readCursorFile?: () => Promise<ImportedCursorCredential | undefined>; readCursorKeychain?: () => Promise<ImportedCursorCredential | undefined>; /** Clock for acknowledgement timestamps; injectable so tests stay deterministic. */ now?: () => Date; /** Persists the no-approval acknowledgement; the disk default is wired in defaultCursorCliOauthConfig. */ persistAcknowledgement?: (acknowledgedAt: string) => void; /** Persists explicit provider activation after a successful login. */ persistEnabled?: (enabled: boolean) => void; }; export type CursorCliOauthLaneResolution = { lane: typeof FILE_STORE_LANE; account: CursorCliAccountSlot; accounts: CursorCliAccountSlot[]; }; export type CursorCliOauthConfig = { name: string; isSubscription: true; check(input: { ctx: AuthContext; credential?: OAuthCredential; signal?: AbortSignal; }): Promise<AuthCheck | undefined>; login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>; refreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>; getApiKey(credentials: OAuthCredentials): string; }; export type LocalCursorImportDeps = { platform?: NodeJS.Platform; readCursorFile?: () => Promise<ImportedCursorCredential | undefined>; readCursorKeychain?: () => Promise<ImportedCursorCredential | undefined>; onPrompt?: OAuthLoginCallbacks["onPrompt"]; }; type ConfigurationAssessment = { accounts: CursorCliAccountSlot[]; message: string; }; /** The single condition evaluation behind both the tolerant `check` and the throwing turn-time resolution. */ export type ConfigurationOutcome = { status: "disabled"; } | { status: "not-installed"; error: unknown; } | { status: "no-accounts"; } | { status: "configured"; assessment: ConfigurationAssessment; }; /** * One predicate so availability and resolution cannot disagree: evaluates the * same conditions for every caller and reports why the lane is unusable * instead of deciding per call-site whether that is fatal. */ export declare function assessConfiguration(deps: CursorCliOauthConfigDeps): Promise<ConfigurationOutcome>; /** * The typed turn-path error for a missing cursor-agent binary: carries the * `cursor-agent not installed` marker plus the install guidance verbatim, with * the underlying resolution failure preserved as `cause`. */ export declare function cursorAgentNotInstalledError(cause: unknown): Error; /** Resolve credentials immediately before execution so a concurrent refresh cannot leave a stale token in memory. */ export declare function resolveCursorCliOauthLane(deps: CursorCliOauthConfigDeps): Promise<CursorCliOauthLaneResolution>; /** The one-screen login explanation: what unattended Cursor CLI execution gives up, and the plan-mode alternative. */ export declare const CURSOR_CLI_OAUTH_LOGIN_ACKNOWLEDGEMENT_EXPLANATION = "The Cursor CLI executes its own tools autonomously: with --force there is no senpi approval, no senpi sandboxing, and no tool-level audit for what it runs. Plan mode (planning only, no tool execution) is available via the executionMode setting."; /** * Present the no-approval explanation exactly once and return the ISO * acknowledgement timestamp on explicit confirmation, undefined otherwise. * Shared by the login flow and the /cursor-account acknowledge subcommand so * both surfaces present the identical explanation and persist identically. */ export declare function confirmCursorCliNoApprovalAcknowledgement(onPrompt: ((prompt: { message: string; placeholder?: string; }) => Promise<string>) | undefined, now: () => Date): Promise<string | undefined>; export declare function createCursorCliOauthConfig(deps: CursorCliOauthConfigDeps): CursorCliOauthConfig; /** Explicitly copy the user's local Cursor credential into this provider's managed account slots. */ export declare function importLocalCursorCredential(current: CursorCliOauthCredential, deps?: LocalCursorImportDeps): Promise<CursorCliOauthCredential>; /** Explicitly copy Senpi's native `cursor` OAuth credential into a managed CLI account slot. */ export declare function importNativeCursorCredential(current: CursorCliOauthCredential, readNativeCredential: () => Credential | undefined | Promise<Credential | undefined>): Promise<CursorCliOauthCredential>; export declare function defaultCursorCliOauthConfig(cwd: string, readCurrent: () => Promise<Credential | undefined>): CursorCliOauthConfig; export {}; //# sourceMappingURL=oauth-login.d.ts.map