fix: use model cache context flag for runtime context limits
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { HookName, OhMyOpenCodeConfig } from "../../config"
|
||||
import type { PluginContext } from "../types"
|
||||
import type { ModelCacheState } from "../../plugin-state"
|
||||
|
||||
import { createSessionHooks } from "./create-session-hooks"
|
||||
import { createToolGuardHooks } from "./create-tool-guard-hooks"
|
||||
@@ -8,14 +9,16 @@ import { createTransformHooks } from "./create-transform-hooks"
|
||||
export function createCoreHooks(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
modelCacheState: ModelCacheState
|
||||
isHookEnabled: (hookName: HookName) => boolean
|
||||
safeHookEnabled: boolean
|
||||
}) {
|
||||
const { ctx, pluginConfig, isHookEnabled, safeHookEnabled } = args
|
||||
const { ctx, pluginConfig, modelCacheState, isHookEnabled, safeHookEnabled } = args
|
||||
|
||||
const session = createSessionHooks({
|
||||
ctx,
|
||||
pluginConfig,
|
||||
modelCacheState,
|
||||
isHookEnabled,
|
||||
safeHookEnabled,
|
||||
})
|
||||
@@ -23,6 +26,7 @@ export function createCoreHooks(args: {
|
||||
const tool = createToolGuardHooks({
|
||||
ctx,
|
||||
pluginConfig,
|
||||
modelCacheState,
|
||||
isHookEnabled,
|
||||
safeHookEnabled,
|
||||
})
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { HookName, OhMyOpenCodeConfig } from "../../config"
|
||||
import type { ModelCacheState } from "../../plugin-state"
|
||||
import type { PluginContext } from "../types"
|
||||
|
||||
import {
|
||||
@@ -35,10 +36,11 @@ export type ToolGuardHooks = {
|
||||
export function createToolGuardHooks(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
modelCacheState: ModelCacheState
|
||||
isHookEnabled: (hookName: HookName) => boolean
|
||||
safeHookEnabled: boolean
|
||||
}): ToolGuardHooks {
|
||||
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 })
|
||||
|
||||
@@ -48,7 +50,10 @@ export function createToolGuardHooks(args: {
|
||||
|
||||
const toolOutputTruncator = isHookEnabled("tool-output-truncator")
|
||||
? safeHook("tool-output-truncator", () =>
|
||||
createToolOutputTruncatorHook(ctx, { experimental: pluginConfig.experimental }))
|
||||
createToolOutputTruncatorHook(ctx, {
|
||||
anthropicContext1MEnabled: modelCacheState.anthropicContext1MEnabled,
|
||||
experimental: pluginConfig.experimental,
|
||||
}))
|
||||
: null
|
||||
|
||||
let directoryAgentsInjector: ReturnType<typeof createDirectoryAgentsInjectorHook> | null = null
|
||||
@@ -62,12 +67,14 @@ export function createToolGuardHooks(args: {
|
||||
nativeVersion: OPENCODE_NATIVE_AGENTS_INJECTION_VERSION,
|
||||
})
|
||||
} else {
|
||||
directoryAgentsInjector = safeHook("directory-agents-injector", () => createDirectoryAgentsInjectorHook(ctx))
|
||||
directoryAgentsInjector = safeHook("directory-agents-injector", () =>
|
||||
createDirectoryAgentsInjectorHook(ctx, modelCacheState.anthropicContext1MEnabled))
|
||||
}
|
||||
}
|
||||
|
||||
const directoryReadmeInjector = isHookEnabled("directory-readme-injector")
|
||||
? safeHook("directory-readme-injector", () => createDirectoryReadmeInjectorHook(ctx))
|
||||
? safeHook("directory-readme-injector", () =>
|
||||
createDirectoryReadmeInjectorHook(ctx, modelCacheState.anthropicContext1MEnabled))
|
||||
: null
|
||||
|
||||
const emptyTaskResponseDetector = isHookEnabled("empty-task-response-detector")
|
||||
@@ -75,7 +82,8 @@ export function createToolGuardHooks(args: {
|
||||
: null
|
||||
|
||||
const rulesInjector = isHookEnabled("rules-injector")
|
||||
? safeHook("rules-injector", () => createRulesInjectorHook(ctx))
|
||||
? safeHook("rules-injector", () =>
|
||||
createRulesInjectorHook(ctx, modelCacheState.anthropicContext1MEnabled))
|
||||
: null
|
||||
|
||||
const tasksTodowriteDisabler = isHookEnabled("tasks-todowrite-disabler")
|
||||
|
||||
Reference in New Issue
Block a user