UNPKG

@phren/cli

Version:

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

79 lines (78 loc) • 3.61 kB
/** * The injected layer's size, and what to demote when it is too big. * * What phren puts in front of every session for a project regardless of the * prompt is (see `shared/retrieval.ts` and `cli/hooks.ts`): * - the whole of the project's `truths.md` (canonical rows are prepended to * every search for the detected project), and * - the "What phren knows" block from `summary.md`, once per session, capped * at 520 characters by the hook. * Everything else the hook injects is chosen by relevance and already sits * under its own token budget. Errors in the always-on part spread to every * session, so dreaming keeps it under `dreaming.injectBudgetKB`. */ export interface Truth { /** The truth as written, without the leading "- " and the "_(added …)_" stamp. */ text: string; /** The full bullet line as stored, for an exact demote. */ line: string; added?: string; /** Bytes this line costs in the injected file (line plus newline). */ bytes: number; } export interface InjectedSize { project: string; /** Bytes of truths.md as stored; the hook injects the file as is. */ truthsBytes: number; /** Bytes of the knows block as the hook injects it (after its trim). */ knowsBytes: number; bytes: number; kb: number; truths: Truth[]; } export interface DemotionCandidate extends Truth { /** Most recent evidence that the truth was used: a lookup hit, a caller-supplied citation, or its added date. */ lastCited?: string; } export interface BudgetState { project: string; budgetBytes: number; bytes: number; over: boolean; /** Bytes to free to get back under budget; 0 when under. */ excessBytes: number; /** The shortest least-recently-cited-first prefix that, demoted, gets under budget. Empty when under. */ candidates: DemotionCandidate[]; /** Every truth, least recently cited first. */ ranking: DemotionCandidate[]; } export interface OverBudgetOptions { /** Extra citation dates by truth text (e.g. transcript mentions found by collect). Newer dates win. */ citedAt?: Map<string, string> | Record<string, string>; /** Skip reading the lookup log (tests, or callers that pass citedAt themselves). */ skipLookupLog?: boolean; } export declare function parseTruths(content: string): Truth[]; export declare function injectedSize(store: string, project: string): InjectedSize; export declare function rankTruths(store: string, project: string, truths: Truth[], opts?: OverBudgetOptions): DemotionCandidate[]; export declare function overBudget(store: string, project: string, budgetKB: number, opts?: OverBudgetOptions): BudgetState; /** * Bytes a new truth costs once `upsertCanonical` has written it: a new file is * the header plus "- text _(added YYYY-MM-DD)_\n"; an existing one gets the * line plus a blank-line separator inserted under "## Truths". */ export declare function truthCost(project: string, text: string, fileExists: boolean): number; export interface PromotionCheck { fits: boolean; bytesBefore: number; bytesAfter: number; budgetBytes: number; } /** * Whether promoting `text` to a truth keeps the injected layer under budget, * counting the truths the same changeset demotes. `apply` refuses a * promote_truth that does not fit. */ export declare function checkPromotion(store: string, project: string, budgetKB: number, text: string, demoted?: string[]): PromotionCheck; /** One line for the dreaming prompt: where the injected layer stands. */ export declare function describeBudget(state: BudgetState): string;