- Import PreemptiveCompactionOptions type - Export hook from hooks/index.ts - Add todo-codebase-compaction to HookNameSchema - Use todoCodebaseCompactionInjector when hook is enabled
75 lines
3.2 KiB
TypeScript
75 lines
3.2 KiB
TypeScript
import type { SummarizeContext, PreemptiveCompactionOptions } from "../preemptive-compaction"
|
|
import { injectHookMessage } from "../../features/hook-message-injector"
|
|
import { log } from "../../shared/logger"
|
|
import { createPreemptiveCompactionHook } from "../preemptive-compaction"
|
|
import type { PluginInput } from "@opencode-ai/plugin"
|
|
|
|
// Custom compaction prompt focused on Todos and Codebase changes (essential for understanding the complex summarization strategy)
|
|
const TODO_CODEBASE_COMPACTION_PROMPT = `[TODO + CODEBASE FOCUSED COMPACTION]
|
|
|
|
When summarizing this session, focus EXCLUSIVELY on the following:
|
|
|
|
## Current Todo State
|
|
- [ ] List ALL active todos from the current session
|
|
- [x] Mark completed todos with [x] and brief completion note
|
|
- Add any implicit todos discovered during work
|
|
- Remove completed or irrelevant todos
|
|
|
|
## Codebase Changes Summary
|
|
For EACH file that was modified, created, or read during this session:
|
|
- **File Path**: Exact path and what happened
|
|
- **Code Changes**: Specific functions, classes, or logic added/modified
|
|
- **Technical Details**: Variable names, algorithms, patterns used
|
|
- **Dependencies**: New imports, packages, or external services added
|
|
|
|
## Session Context
|
|
- **Current Task**: What the user was working on when compaction triggered
|
|
- **Progress State**: How far along the current task/goal
|
|
- **Next Steps**: What needs to happen next based on current state
|
|
|
|
## Critical Information (MUST PRESERVE)
|
|
- Specific file paths and line numbers mentioned
|
|
- Variable names, function names, class names
|
|
- Error messages and their solutions
|
|
- API endpoints, database schemas, configuration changes
|
|
- User preferences and constraints
|
|
|
|
DO NOT include:
|
|
- Generic conversation ("I see", "Let me check", "Working on this")
|
|
- Process descriptions ("I used grep to find", "I ran the tests")
|
|
- Redundant explanations of what tools do
|
|
- Chatty responses without technical substance
|
|
|
|
Focus on STATE and ARTIFACTS that enable continuation of the actual work.
|
|
`
|
|
|
|
export function createTodoCodebaseCompactionInjector() {
|
|
return async (ctx: SummarizeContext): Promise<void> => {
|
|
log("[todo-codebase-compaction] injecting custom context", { sessionID: ctx.sessionID })
|
|
|
|
const success = injectHookMessage(ctx.sessionID, TODO_CODEBASE_COMPACTION_PROMPT, {
|
|
agent: "general",
|
|
model: { providerID: ctx.providerID, modelID: ctx.modelID },
|
|
path: { cwd: ctx.directory },
|
|
})
|
|
|
|
if (success) {
|
|
log("[todo-codebase-compaction] custom context injected", { sessionID: ctx.sessionID })
|
|
} else {
|
|
log("[todo-codebase-compaction] injection failed", { sessionID: ctx.sessionID })
|
|
}
|
|
}
|
|
}
|
|
|
|
// Alternative: Custom compaction hook that completely overrides summarization
|
|
// This would require more complex implementation to replace the core summarization behavior
|
|
export function createCustomCompactionHook(ctx: PluginInput, options?: PreemptiveCompactionOptions) {
|
|
// This would implement the full custom compaction logic
|
|
// For now, we use the context injector approach which is simpler and works with existing hooks
|
|
const compactionInjector = createTodoCodebaseCompactionInjector()
|
|
|
|
return createPreemptiveCompactionHook(ctx, {
|
|
...options,
|
|
onBeforeSummarize: compactionInjector,
|
|
})
|
|
} |