/** * How large is the context this session is carrying, and is it over budget? * * 91% of what an AIDLC project spends on inference is cache traffic — re-reading * the same conversation prefix, turn after turn. Measured over 20,920 attributed * ledger records, the average carried prefix grows monotonically through the * lifecycle: 80k tokens in ideation, 164k in requirements, 259k in implementation, * 395k in deployment, 791k in maintenance. The `complete` phase does comparable * work at 76k for one reason — it runs in its own session. * * So a phase boundary is a free context reset, and this is how a phase skill checks * whether it should have taken one. * * **Reads the transcript, not the ledger.** The question is asked at a phase * boundary, which is exactly when no capture has run recently and the ledger is * stale or empty — and it must answer on a machine where no cost hook was ever * installed, because this project already has a lesson about a capability whose * arming was manual and was therefore inert on arrival. * * Only token counts are read. No transcript content — no prompt text, no file * body, no tool output — is copied anywhere, so nothing here can leak a secret into * a report (NFR-4). * * Requirements: context-budget/AC-16, AC-17, AC-18, AC-19; NFR-4 * Design: design.md Part 4 (D4.3, D4.4) * * @module */ import type { CostConfig } from './types.js'; import type { ProviderEnv } from './providers/provider.js'; export interface ContextReading { /** * Resident prefix at the most recent API call, in tokens — everything the model * had to be *given*. Null when no usage-bearing transcript line was found for * this project, which is an ordinary state (a fresh session that has not yet made * a call), not a failure. */ residentTokens: number | null; /** Model of that call, for context. Null when unknown. */ model: string | null; /** ISO timestamp of that call. Null when unknown. */ at: string | null; /** The budget in force, from config or the measured default. */ budgetTokens: number; /** True when `residentTokens` exceeds the budget. Always false when unmeasured. */ overBudget: boolean; /** Transcripts belonging to this project that were considered. */ transcriptsScanned: number; /** * Transcripts that could not be read through to the end. * * Counted rather than swallowed. A silent fail-soft here would report `unmeasured` * with no reason on a machine where every transcript is unreadable, which looks * identical to a fresh session — and "an unmeasured reading with no explanation" is * the shape of failure this project has already paid for once. SOC 2 CC7.2 asks the * same thing of any failure path: record it with enough context to notice. */ transcriptsUnreadable: number; } /** The budget in force: config when set to a positive number, else the measured default. */ export declare function contextBudget(config: CostConfig | null): number; /** * Read resident context for this project's most recent API call. * * Scopes to this repository via `projectClaudeCodeRecords`, which resolves each * transcript's `cwd` to a git common dir rather than comparing path prefixes — the * transcript root holds every project this machine has ever worked on, and a * prefix match once put 711 entries of another repository's work into this one's * ledgers. */ export declare function readContext(projectRoot: string, config: CostConfig | null, env?: ProviderEnv): Promise; //# sourceMappingURL=context.d.ts.map