fix: use model cache context flag for runtime context limits

This commit is contained in:
YeonGyu-Kim
2026-02-17 10:33:17 +09:00
parent b1e7bb4c59
commit b444899153
12 changed files with 94 additions and 39 deletions

View File

@@ -1,4 +1,5 @@
import type { OhMyOpenCodeConfig, HookName } from "../../config"
import type { ModelCacheState } from "../../plugin-state"
import type { PluginContext } from "../types"
import {
@@ -55,21 +56,24 @@ export type SessionHooks = {
export function createSessionHooks(args: {
ctx: PluginContext
pluginConfig: OhMyOpenCodeConfig
modelCacheState: ModelCacheState
isHookEnabled: (hookName: HookName) => boolean
safeHookEnabled: boolean
}): SessionHooks {
const { ctx, pluginConfig, isHookEnabled, safeHookEnabled } = args
const { ctx, pluginConfig, modelCacheState, isHookEnabled, safeHookEnabled } = args
const safeHook = <T>(hookName: HookName, factory: () => T): T | null =>
safeCreateHook(hookName, factory, { enabled: safeHookEnabled })
const contextWindowMonitor = isHookEnabled("context-window-monitor")
? safeHook("context-window-monitor", () => createContextWindowMonitorHook(ctx))
? safeHook("context-window-monitor", () =>
createContextWindowMonitorHook(ctx, modelCacheState.anthropicContext1MEnabled))
: null
const preemptiveCompaction =
isHookEnabled("preemptive-compaction") &&
pluginConfig.experimental?.preemptive_compaction
? safeHook("preemptive-compaction", () => createPreemptiveCompactionHook(ctx))
? safeHook("preemptive-compaction", () =>
createPreemptiveCompactionHook(ctx, modelCacheState.anthropicContext1MEnabled))
: null
const sessionRecovery = isHookEnabled("session-recovery")