import { injectHookMessage } from "../../features/hook-message-injector" import { log } from "../../shared/logger" import { createSystemDirective, SystemDirectiveTypes } from "../../shared/system-directive" export interface SummarizeContext { sessionID: string providerID: string modelID: string usageRatio: number directory: string } const SUMMARIZE_CONTEXT_PROMPT = `${createSystemDirective(SystemDirectiveTypes.COMPACTION_CONTEXT)} When summarizing this session, you MUST include the following sections in your summary: ## 1. User Requests (As-Is) - List all original user requests exactly as they were stated - Preserve the user's exact wording and intent ## 2. Final Goal - What the user ultimately wanted to achieve - The end result or deliverable expected ## 3. Work Completed - What has been done so far - Files created/modified - Features implemented - Problems solved ## 4. Remaining Tasks - What still needs to be done - Pending items from the original request - Follow-up tasks identified during the work ## 5. Active Working Context (For Seamless Continuation) - **Files**: Paths of files currently being edited or frequently referenced - **Code in Progress**: Key code snippets, function signatures, or data structures under active development - **External References**: Documentation URLs, library APIs, or external resources being consulted - **State & Variables**: Important variable names, configuration values, or runtime state relevant to ongoing work ## 6. MUST NOT Do (Critical Constraints) - Things that were explicitly forbidden - Approaches that failed and should not be retried - User's explicit restrictions or preferences - Anti-patterns identified during the session ## 7. Agent Verification State (Critical for Reviewers) - **Current Agent**: What agent is running (momus, oracle, etc.) - **Verification Progress**: Files already verified/validated - **Pending Verifications**: Files still needing verification - **Previous Rejections**: If reviewer agent, what was rejected and why - **Acceptance Status**: Current state of review process This section is CRITICAL for reviewer agents (momus, oracle) to maintain continuity. This context is critical for maintaining continuity after compaction. ` export function createCompactionContextInjector() { return async (ctx: SummarizeContext): Promise => { log("[compaction-context-injector] injecting context", { sessionID: ctx.sessionID }) const success = injectHookMessage(ctx.sessionID, SUMMARIZE_CONTEXT_PROMPT, { agent: "general", model: { providerID: ctx.providerID, modelID: ctx.modelID }, path: { cwd: ctx.directory }, }) if (success) { log("[compaction-context-injector] context injected", { sessionID: ctx.sessionID }) } else { log("[compaction-context-injector] injection failed", { sessionID: ctx.sessionID }) } } }