feat(preemptive-compaction): add onBeforeSummarize callback and context injection

- Added BeforeSummarizeCallback type to allow injecting context before session summarization
- Added onBeforeSummarize option to PreemptiveCompactionOptions
- Created compaction-context-injector module that injects summarization instructions with sections:
  - User Requests (As-Is)
  - Final Goal
  - Work Completed
  - Remaining Tasks
  - MUST NOT Do (Critical Constraints)
- Wired up callback invocation in preemptive-compaction before calling summarize API
- Exported new hook from src/hooks/index.ts

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2025-12-20 15:39:54 +09:00
parent 8406f3d6d7
commit a3ff28b250
4 changed files with 83 additions and 2 deletions

View File

@@ -8,8 +8,19 @@ import {
} from "./constants"
import { log } from "../../shared/logger"
export interface SummarizeContext {
sessionID: string
providerID: string
modelID: string
usageRatio: number
directory: string
}
export type BeforeSummarizeCallback = (ctx: SummarizeContext) => Promise<void> | void
export interface PreemptiveCompactionOptions {
experimental?: ExperimentalConfig
onBeforeSummarize?: BeforeSummarizeCallback
}
interface MessageInfo {
@@ -68,6 +79,7 @@ export function createPreemptiveCompactionHook(
options?: PreemptiveCompactionOptions
) {
const experimental = options?.experimental
const onBeforeSummarize = options?.onBeforeSummarize
const enabled = experimental?.preemptive_compaction !== false
const threshold = experimental?.preemptive_compaction_threshold ?? DEFAULT_THRESHOLD
@@ -132,6 +144,16 @@ export function createPreemptiveCompactionHook(
log("[preemptive-compaction] triggering compaction", { sessionID, usageRatio })
try {
if (onBeforeSummarize) {
await onBeforeSummarize({
sessionID,
providerID,
modelID,
usageRatio,
directory: ctx.directory,
})
}
await ctx.client.session.summarize({
path: { id: sessionID },
body: { providerID, modelID },