import type { AgentMessage } from "../internal/harness.js"; import type { Model } from "../internal/llm.js"; /** * Last-resort, in-task context trim. Proper compaction (LLM summary) runs *between* tasks; * this prevents a single task whose internal tool-loop balloons from overflowing the window. * * Keeps all summary messages (compaction/branch) and the most recent messages that fit the * budget, dropping older regular messages at a safe boundary (never starting on an orphan * toolResult). Returns the original array when already within budget. * * design/123 D3 (codex-B1 = fable-M5) — anchored accounting: when `anchoredTotalTokens` * (= `estimateContextTokens(messages, charsPerToken).tokens` for the SAME array) is provided, the * trigger gate and the internal bookkeeping start from the usage-anchored value instead of the * structural sum (which underestimates code/CJK and lets over-window requests through). Dropping a * message AFTER the usage anchor reduces the accounted total by its structural estimate; dropping a * message AT/BEFORE the anchor reduces it by ZERO (the anchor usage was billed with that content — * a request-view drop only pays off on the NEXT request), so the trim keeps cutting deeper until * the anchored total meets the budget or only the minimal tail is left. Absent ⇒ legacy structural * behavior, byte-identical. `charsPerToken` (design/123 D2): structural coefficient, default 4. */ export declare function trimToBudget(messages: AgentMessage[], budgetTokens: number, anchoredTotalTokens?: number, charsPerToken?: number): AgentMessage[]; /** * design/123 D3 belt (invariant-level, live-caught 16k 400s): the FINAL request view must never * contain a toolResult whose tool-call assistant is absent — strict gateways hard-400 on it * ("Messages with role 'tool' must be a response to a preceding message with 'tool_calls'"). Every * individual producer is turn-aligned (findCutPoint never cuts on a toolResult; trimToBudget * turn-aligns its floor), but NO pipeline combination may ship an orphan, so the prepare-task * context hook sweeps its output through this last. Deterministic ⇒ byte-stable per request ⇒ * prefix-cache safe. Returns the SAME array when clean (zero-cost fast path); `dropped` carries a * diagnostic per removed orphan (toolCallId + neighbor roles) for onError attribution. */ export declare function dropOrphanToolResults(messages: AgentMessage[]): { messages: AgentMessage[]; dropped: Array<{ toolCallId: string; index: number; prevRole: string; nextRole: string; }>; }; /** Budget the in-task guard targets for a model. */ export declare function guardBudget(model: Model): number; //# sourceMappingURL=context-guard.d.ts.map