import type { CompactionResult, ExtensionAPI, ExtensionContext, SessionBeforeCompactEvent, SessionBeforeCompactResult, SessionBeforeTreeEvent, SessionBeforeTreeResult, SessionEntry } from "@earendil-works/pi-coding-agent"; import { type CompactionEnricher } from "./enrichers.js"; import { type CompactionInstructionDecodeError, type CompactionInstructionPolicy } from "./instructions.js"; import { type ProjectionOmittedCounts } from "./projections.js"; type CompactionEngine = "pi" | "fabric"; export interface FabricCompactionBudget { contextWindow?: number; targetContextRatio?: number; reserveTokens: number; keepRecentTokens: number; /** False for a new executor: source-model usage does not calibrate its context. */ calibrateUsage?: boolean; } type FabricCompactionBindingConstraint = "continuity" | "occupancy" | "reserve" | "reduction"; export interface FabricCompactionBudgetDetails { strategy: "adaptive" | "continuity"; contextWindow: number; targetContextRatio: number; targetContextTokens: number; reserveTokens: number; keepRecentTokens: number; rawTokensBefore: number; tokenScale: number; fixedOverheadTokens: number; retainedRawTokens: number; projectedTokensAfter: number; continuityTargetTokens?: number; occupancyCeilingTokens?: number; safeCeilingTokens?: number; reductionCeilingTokens?: number; rawTailTokenBudget?: number; bindingConstraint?: FabricCompactionBindingConstraint; } export declare const rawContextTokens: (branchEntries: SessionEntry[]) => number; export type CutResult = { ok: true; summarized: SessionEntry[]; firstKeptEntryId: string; firstSummarizedEntryId: string; lastSummarizedEntryId: string; lastTimestamp: string; budget?: Omit; } | { ok: false; reason: "empty"; }; /** Selection stays an optimized TypeScript producer. Every successful proposal, * including legacy and compact-all paths, passes the compiled acceptance gate. */ export declare const computeCut: (branchEntries: SessionEntry[], options?: { tokensBefore: number; budget: FabricCompactionBudget; }) => CutResult; interface EntryRange { first: string; last: string; } export interface FabricCompactionDetailsV2 { compactor: "fabric"; version: 2; sections: string[]; coverage: { cumulativeSourceRange: EntryRange; liveCutRange: EntryRange; }; counts: { branchEntries: number; cumulativeSourceEntries: number; sourceEvents: number; liveCutEntries: number; priorFabricV1: number; priorFabricV2: number; }; omittedCounts: ProjectionOmittedCounts & { preserve: number; thinking?: number; }; instructionPolicy: CompactionInstructionPolicy; stableAddresses: { firstKeptEntryId: string; cumulativeSourceRange: EntryRange; recall: "session-entry-id-range"; }; budget?: FabricCompactionBudgetDetails; /** Carry-forward focus rendered into this summary (absent when the list is empty). */ carry?: { count: number; renderedOmittedBytes: number; }; timestamp: string; /** * Set only on a claim owner's fallback summary: the owner's name. Fabric's * own engine never writes it. */ claimOwner?: string; } export declare const fabricCompactionVersion: (details: unknown) => 1 | 2 | undefined; export declare const compileFabricSummary: (branchEntries: SessionEntry[], tokensBefore: number, enrichers?: readonly CompactionEnricher[], customInstructions?: string, budget?: FabricCompactionBudget, /** Carry-forward items to render instead of the branch's stored list. */ carryItems?: readonly string[]) => { compaction: CompactionResult; } | { cancel: true; reason: string; instructionError?: CompactionInstructionDecodeError; }; export interface CompactionHookOptions { getEngine: () => CompactionEngine; getTargetContextRatio?: () => number; getThresholdContextRatio?: (modelKey: string) => number | undefined; getThresholdTokens?: (modelKey: string) => number | undefined; /** `compaction.outputReserveTokens`; a breached reserve never defers Pi's threshold compaction. */ getOutputReserveTokens?: () => number; /** Fabric deliberately left this compaction to another owner (pi-vcc sentinel/override). */ onYield?: () => void; enrichers?: readonly CompactionEnricher[]; /** * The extension holding the compaction owner claim. While present, Fabric's * compaction handler returns nothing (no summary, no threshold deferral); * `/tree` summaries stay with Fabric unless the claim declares `branchSummary`. */ getOwnerClaim?: () => { readonly branchSummary: boolean; } | undefined; } /** * Fabric's deterministic compaction for one `session_before_compact` event: * the budget the hook derives from the event and model, then the summary * compiler. Shared by the hook and the owner-claim fallback. */ export declare const compileFabricCompactionForEvent: (event: Pick, context: Pick | undefined, targetContextRatio?: number, enrichers?: readonly CompactionEnricher[], carryItems?: readonly string[]) => ReturnType; export interface CompactionHandlers { beforeCompact: (event: SessionBeforeCompactEvent, context: ExtensionContext) => SessionBeforeCompactResult | undefined; beforeTree: (event: SessionBeforeTreeEvent, context: ExtensionContext) => SessionBeforeTreeResult | undefined; } export declare const compactionHandlers: (options: CompactionHookOptions) => CompactionHandlers; export declare const registerCompactionHook: (pi: ExtensionAPI, options: CompactionHookOptions) => void; export {}; //# sourceMappingURL=hook.d.ts.map