fix: use model cache context flag for runtime context limits
This commit is contained in:
@@ -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