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:
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user