UNPKG

@phren/cli

Version:

Knowledge layer for AI agents - CLI, MCP server, and data layer

104 lines (103 loc) • 6.16 kB
import { type ChildProcess } from "node:child_process"; import { type Subscription } from "./subscription.js"; export declare const DEFAULT_ACCOUNT = "default"; export interface ClaudeHome { /** "default", or the slug of ~/.claude-<slug>. */ id: string; /** The config directory (CLAUDE_CONFIG_DIR for non-default homes). */ dir: string; /** Where Claude Code keeps this home's .claude.json. */ configFile: string; isDefault: boolean; } /** What rows, usage and receipts carry to name an account. */ export interface AccountRef { id: string; label: string; key: string; email?: string; } export declare function isAccountSlug(value: string): boolean; /** Every Claude home on this computer, default first, then by slug. The Hook asks several times per pane * per overview, so a listing is reused for HOMES_REUSE_MS, and after that while the home folder and * every `.claude-*` folder in it are unchanged, up to HOMES_MAX_AGE_MS. */ export declare function claudeHomes(env?: NodeJS.ProcessEnv): ClaudeHome[]; export declare function claudeHome(id: string | undefined, env?: NodeJS.ProcessEnv): ClaudeHome | undefined; /** The home a transcript or other file lives in, by longest matching directory. */ export declare function claudeHomeOfPath(file: string, env?: NodeJS.ProcessEnv): ClaudeHome | undefined; /** Environment a launch into this home needs; empty for the default home. */ export declare function claudeLaunchEnv(home: ClaudeHome): Record<string, string>; /** The config home a running Claude process uses, from its CLAUDE_CONFIG_DIR. */ export declare function claudeHomeOfEnv(value: string | undefined, env?: NodeJS.ProcessEnv): ClaudeHome | undefined; export declare const accountsFile: () => string; /** `accounts.yaml` as an object: empty when there is none (or it is blank), an error when it is there but is * not a mapping, so a write never replaces what it couldn't read. */ export declare function parseAccountsYaml(text: string | undefined): Record<string, unknown>; /** * The one way `accounts.yaml` is changed (labels, credits, pools): reads it, applies `change`, and writes it back * atomically. Writes in this process run one at a time, and each holds the file's lock against other processes * (the CLI beside the Hook), so no write drops another's change. A file that can't be read is never replaced. */ export declare function updateAccountsFile(change: (parsed: Record<string, unknown>) => void): Promise<void>; export declare function accountLabel(id: string, labels?: Record<string, string>): string; export declare function setAccountLabel(id: string, label: string): Promise<void>; /** * Stable across computers for one subscription; home-scoped when unknown. * One login can belong to several organizations (a personal plan and a Team * seat), each its own allowance, so the organization is part of the key. */ export declare function claudeAccountKey(home: ClaudeHome): string; /** The login's email, so the phone can name a card merged across computers. Usage rows only. */ export declare function claudeAccountEmail(home: ClaudeHome): string | undefined; /** A login is recorded but its profile names no plan Phren knows. */ export declare function claudePlanUnknown(home: ClaudeHome): boolean; /** * The account home's own subscription, independent of the quota snapshot's * age. `checkedAt` is when Claude Code last fetched the profile, so the * newest profile wins when computers disagree about a plan that changed. */ export declare function claudeAccountSubscription(home: ClaudeHome, now?: Date, fallbackPlan?: string): Subscription | undefined; export declare function claudeAccountRef(home: ClaudeHome, labels?: Record<string, string>): AccountRef; /** * A privacy-preserving fingerprint of a home's login: the signed-in account's stable identity and the * credential file's own metadata, never the main config file's (a trust prompt or project setting * rewrites it without changing the login). A re-login changes it, so cached and persisted answers for * the old login are dropped. Undefined when the config names no identity: the last classification is * then kept rather than discarded. Only the hash is ever stored. */ export declare function claudeLoginFingerprint(home: ClaudeHome): string | undefined; export declare const CODEX_ACCOUNT: AccountRef; /** Only for tests. */ /** Drop the cached home listing, so a home made in this process is seen at once. */ export declare function forgetClaudeHomes(): void; export declare function clearAccountCaches(): void; /** `unknown`: Claude gave no answer (timeout, crash, unparseable), which must not block a launch. */ export interface AuthStatus { signedIn: boolean; unknown?: boolean; plan?: string; reason?: string; /** Signed in with a Console (API billing) login. */ console?: boolean; } /** Parse `claude auth status --json`. Never keeps anything but the state and plan. */ export declare function parseAuthStatus(output: string): AuthStatus; export type AuthRunner = (home: ClaudeHome) => Promise<string>; /** How the sign-in probe starts Claude: an npm install on Windows is `claude.cmd`, which only a shell starts. */ export declare function claudeAuthSpawn(platform?: NodeJS.Platform): { command: string; shell: boolean; }; type AuthKillSpawn = (command: string, args: readonly string[], options: { stdio: "ignore"; windowsHide: boolean; }) => Pick<ChildProcess, "on">; /** * Stops the sign-in probe and anything it started. On Windows the child is cmd.exe, so * killing it alone leaves the claude started by claude.cmd running: kill the tree with * taskkill. Elsewhere the child is claude itself. */ export declare function claudeAuthKill(child: Pick<ChildProcess, "pid" | "kill">, platform?: NodeJS.Platform, run?: AuthKillSpawn, env?: NodeJS.ProcessEnv): void; /** Only for tests: settles when the most recent sign-in probe's child has exited. */ export declare function claudeAuthProbeExit(): Promise<void> | undefined; export declare function claudeAuthStatus(home: ClaudeHome, run?: AuthRunner, now?: number): Promise<AuthStatus>; export {};