UNPKG

@phren/cli

Version:

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

50 lines (49 loc) • 2.66 kB
import { type ClaudeHome } from "./claude-accounts.js"; import type { ApiCredit, UsageWindow } from "./usage.js"; export interface ClaudeCredit { /** Short id derived from the entry, for `--remove`. */ id: string; amountUSD: number; /** Spend counts from this day (UTC midnight). */ since: string; expiresAt?: string; label?: string; } /** One session's cost as Claude Code reported it, and when the session began. */ export interface SessionCost { costUSD: number; startedAt: string; } /** The credits entered for one Claude home, in `<bridge>/accounts.yaml` under `credits`. */ export declare function claudeCredits(home: string): ClaudeCredit[]; /** `phren bridge accounts credit <id> --amount <usd> [--expires <date>] [--since <date>] [--label <name>]`. */ export declare function addClaudeCredit(home: string, entry: { amount: string; expires?: string; since?: string; label?: string; }, now?: Date): Promise<ClaudeCredit>; export declare function removeClaudeCredit(home: string, id: string): Promise<boolean>; /** Per-session costs from the status line, kept only for homes with a credit. */ export declare const costLedgerFile: (home: ClaudeHome) => string; /** * Record one status-line render or helper run: the session's running total only grows, so the largest seen * stands. Writes run one at a time in this process and under the ledger's lock across processes (the status * line and the helper tool both write it), so none drops another's session. */ export declare function recordSessionCost(home: ClaudeHome, payload: unknown, now?: Date): Promise<void>; /** * Every session cost known for a home: the status-line ledger, plus the * `lastCost` Claude Code keeps per project in the home's `.claude.json` * (which also covers sessions with no status line), dated by the session's * transcript. The larger figure for one session stands. */ export declare function homeSessionCosts(home: ClaudeHome): Record<string, SessionCost>; /** * One window per live credit: spend is drawn from the credit that expires * first among those active when the session began, overflowing to the next. * Expired credits are left out. The window's `resetsAt` is the expiry. */ export declare function creditWindows(credits: readonly ClaudeCredit[], sessions: Record<string, SessionCost>, now?: Date): UsageWindow[]; /** The credit windows added up: dollars left and the soonest expiry among those with money left. None: undefined. */ export declare function creditSummary(windows: ReadonlyArray<Pick<UsageWindow, "id" | "usedUSD" | "limitUSD" | "remainingUSD" | "expiresAt">>): ApiCredit | undefined;