/** * compaction-sections.ts * * Section builder functions for prompt compaction. * * Rule-based builders return CompactionSection | null directly. * LLM-assisted builders return a string prompt to be sent to the LLM by the * orchestrator; the caller assembles the section from the LLM response. * * Empty sections return null, the orchestrator omits them entirely (no header). */ import type { ProviderMessage, ContentPart } from '../providers/interface.js'; import type { AgentRecord } from '../tools/agent/index.js'; import type { WrfcChain } from '../agents/wrfc-types.js'; import type { ExecutionPlan } from './execution-plan.js'; import type { CompactionSection, SessionMemory } from './compaction-types.js'; /** Extract plain text from a ProviderMessage content field. */ export declare function extractText(content: string | ContentPart[]): string; /** * The mandatory first line of every compacted output. Exported so transcript * renderers can recognize a compaction-continuation user message (it is * machinery, not something the user typed) and present it folded instead of * as a full multi-kilobyte wall of re-injected instructions. */ export declare const COMPACTION_HANDOFF_HEADER = "IMPORTANT: This session is not new! Context was compacted, please read the following for proper handoff so you may resume work!"; /** * buildHandoffHeader, always returns the mandatory handoff header. * This is the first line of every compacted output. */ export declare function buildHandoffHeader(): CompactionSection; /** * Sentinel markers wrapping the re-injected instruction block. They let a * later compaction pass strip a prior re-injected block out of the message * history before it is summarized again, so the instructions appear exactly * once no matter how many times compaction runs. */ export declare const REINJECT_INSTRUCTIONS_START = ""; export declare const REINJECT_INSTRUCTIONS_END = ""; /** * Remove any previously re-injected instruction block(s) from a piece of text. * Used to keep repeated compactions from stacking duplicate instruction copies. */ export declare function stripReinjectedInstructions(text: string): string; /** * buildReinjectedInstructions, re-includes the standing system instruction * chain and the frontmatter of any active skill at the compaction boundary so * compaction never silently strips them. Returns null when neither is present. * * The block is wrapped in sentinel markers ({@link REINJECT_INSTRUCTIONS_START} * / {@link REINJECT_INSTRUCTIONS_END}) so a subsequent compaction can strip the * prior copy before re-adding a fresh one (no duplication across passes). */ export declare function buildReinjectedInstructions(instructionChain: string | undefined, activeSkillFrontmatter: string | undefined): CompactionSection | null; /** * buildSessionMemories, format pinned memories. * Returns null if there are no memories. */ export declare function buildSessionMemories(memories: SessionMemory[]): CompactionSection | null; /** * buildCurrentTask, one line stating what the user is currently doing. * Uses plan title if a plan exists, otherwise falls back to the last user message. */ export declare function buildCurrentTask(planTitle: string | null, lastUserMessage: string | null): CompactionSection | null; /** * buildRunningAgents, list agents in running or pending status. * Includes WRFC chain ID, agent ID, and task (truncated to 80 chars). * Returns null if no agents are running. */ export declare function buildRunningAgents(agents: AgentRecord[], chains: WrfcChain[]): CompactionSection | null; /** * buildCompletedAgentWork, list standalone (non-WRFC) agents that finished * (completed or failed) this session, with a best-effort files-touched summary. * Agents that belong to a WRFC chain are excluded, they are already * summarized per-chain by buildAgentActivityTable, and listing them again * here would double-report the same work. */ export declare function buildCompletedAgentWork(agents: AgentRecord[], chains: WrfcChain[]): CompactionSection | null; /** * gatherRecentConversation, collect user/assistant messages backward from most * recent, stopping when adding the next message would exceed maxTokens. * Returns full messages only (no partial messages). * * The returned messages are raw, they will be further filtered by the LLM * substance filter in the orchestrator. */ export declare function gatherRecentConversation(messages: ProviderMessage[], maxTokens?: number): ProviderMessage[]; /** * buildToolResultsPrompt, build the prompt for LLM-assisted tool relevance extraction. * * The caller sends this to the LLM and uses the response as the section content. */ export declare function buildToolResultsPrompt(toolMessages: ProviderMessage[]): string; /** * buildConversationFilterPrompt, build the LLM prompt for filtering gathered * recent messages for substance. * * The caller sends this to the LLM; the response replaces the raw gathered messages. * Multi-turn coherence rule: keep user-assistant PAIRS. */ export declare function buildConversationFilterPrompt(gatheredMessages: ProviderMessage[]): string; /** * buildAgentActivityTable, rule-based table from WRFC chain data. * One row per chain, most recent first. Skips intermediate reviews/fix cycles. * Stops when adding the next row would exceed the token budget. * * Returns: * - section: the table section (or null if no chains) * - remainingChains: chains that did not fit in the table (for older summary) */ export declare function buildAgentActivityTable(chains: WrfcChain[], tokenBudget: number): { section: CompactionSection | null; remainingChains: WrfcChain[]; }; /** * buildOlderAgentSummaryPrompt, build the prompt for LLM-assisted summary of * agents that did not fit in the activity table. * * Returns empty string if no older chains. */ export declare function buildOlderAgentSummaryPrompt(olderChains: WrfcChain[]): string; /** * buildResolvedProblemsPrompt, build the prompt for LLM-assisted extraction * of problem → resolution pairs from the conversation. * * Returns empty string if no messages. */ export declare function buildResolvedProblemsPrompt(messages: ProviderMessage[]): string; /** * buildPlanProgress, rule-based from plan state. * Returns null if no active plan. */ export declare function buildPlanProgress(plan: ExecutionPlan | null): CompactionSection | null; /** * buildSessionLineage, format the append-only micro-log. * Each compaction adds one entry; prior entries are never modified. */ export declare function buildSessionLineage(originalTask: string | undefined, lineageEntries: string[], compactionCount: number): CompactionSection | null; //# sourceMappingURL=compaction-sections.d.ts.map