refactor(dcp-for-compaction): migrate from experimental config to hook system
- Add 'dcp-for-compaction' to HookNameSchema - Remove dcp_for_compaction from ExperimentalConfigSchema - Update executor.ts to use dcpForCompaction parameter - Enable DCP by default (can be disabled via disabled_hooks) - Update all 4 README files (EN, KO, JA, ZH-CN) 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -66,6 +66,7 @@ export const HookNameSchema = z.enum([
|
||||
"empty-message-sanitizer",
|
||||
"thinking-block-validator",
|
||||
"ralph-loop",
|
||||
"dcp-for-compaction",
|
||||
])
|
||||
|
||||
export const BuiltinCommandNameSchema = z.enum([
|
||||
@@ -172,8 +173,6 @@ export const ExperimentalConfigSchema = z.object({
|
||||
truncate_all_tool_outputs: z.boolean().default(true),
|
||||
/** Dynamic context pruning configuration */
|
||||
dynamic_context_pruning: DynamicContextPruningConfigSchema.optional(),
|
||||
/** Enable DCP (Dynamic Context Pruning) for compaction - runs first when token limit exceeded (default: false) */
|
||||
dcp_for_compaction: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const SkillSourceSchema = z.union([
|
||||
|
||||
@@ -151,6 +151,7 @@ describe("executeCompact lock management", () => {
|
||||
truncate_all_tool_outputs: false,
|
||||
aggressive_truncation: true,
|
||||
}
|
||||
const dcpForCompaction = true
|
||||
|
||||
// #when: Execute compaction with experimental flag
|
||||
await executeCompact(
|
||||
@@ -160,6 +161,7 @@ describe("executeCompact lock management", () => {
|
||||
mockClient,
|
||||
directory,
|
||||
experimental,
|
||||
dcpForCompaction,
|
||||
)
|
||||
|
||||
// #then: Lock should be cleared even on early return
|
||||
|
||||
@@ -337,6 +337,7 @@ export async function executeCompact(
|
||||
client: any,
|
||||
directory: string,
|
||||
experimental?: ExperimentalConfig,
|
||||
dcpForCompaction?: boolean,
|
||||
): Promise<void> {
|
||||
if (autoCompactState.compactionInProgress.has(sessionID)) {
|
||||
await (client as Client).tui
|
||||
@@ -358,10 +359,10 @@ export async function executeCompact(
|
||||
const errorData = autoCompactState.errorDataBySession.get(sessionID);
|
||||
const truncateState = getOrCreateTruncateState(autoCompactState, sessionID);
|
||||
|
||||
// DCP FIRST - run before any other recovery attempts when token limit exceeded
|
||||
// DCP FIRST - run before any other recovery attempts when token limit exceeded (controlled by dcp-for-compaction hook)
|
||||
const dcpState = getOrCreateDcpState(autoCompactState, sessionID);
|
||||
if (
|
||||
experimental?.dcp_for_compaction &&
|
||||
dcpForCompaction !== false &&
|
||||
!dcpState.attempted &&
|
||||
errorData?.currentTokens &&
|
||||
errorData?.maxTokens &&
|
||||
@@ -374,7 +375,7 @@ export async function executeCompact(
|
||||
maxTokens: errorData.maxTokens,
|
||||
});
|
||||
|
||||
const dcpConfig = experimental.dynamic_context_pruning ?? {
|
||||
const dcpConfig = experimental?.dynamic_context_pruning ?? {
|
||||
enabled: true,
|
||||
notification: "detailed" as const,
|
||||
protected_tools: ["task", "todowrite", "todoread", "lsp_rename", "lsp_code_action_resolve"],
|
||||
@@ -618,6 +619,7 @@ export async function executeCompact(
|
||||
client,
|
||||
directory,
|
||||
experimental,
|
||||
dcpForCompaction,
|
||||
);
|
||||
}, 500);
|
||||
return;
|
||||
@@ -696,6 +698,7 @@ export async function executeCompact(
|
||||
client,
|
||||
directory,
|
||||
experimental,
|
||||
dcpForCompaction,
|
||||
);
|
||||
}, cappedDelay);
|
||||
return;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { log } from "../../shared/logger"
|
||||
|
||||
export interface AnthropicContextWindowLimitRecoveryOptions {
|
||||
experimental?: ExperimentalConfig
|
||||
dcpForCompaction?: boolean
|
||||
}
|
||||
|
||||
function createRecoveryState(): AutoCompactState {
|
||||
@@ -25,6 +26,7 @@ function createRecoveryState(): AutoCompactState {
|
||||
export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput, options?: AnthropicContextWindowLimitRecoveryOptions) {
|
||||
const autoCompactState = createRecoveryState()
|
||||
const experimental = options?.experimental
|
||||
const dcpForCompaction = options?.dcpForCompaction
|
||||
|
||||
const eventHandler = async ({ event }: { event: { type: string; properties?: unknown } }) => {
|
||||
const props = event.properties as Record<string, unknown> | undefined
|
||||
@@ -81,7 +83,8 @@ export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput,
|
||||
autoCompactState,
|
||||
ctx.client,
|
||||
ctx.directory,
|
||||
experimental
|
||||
experimental,
|
||||
dcpForCompaction
|
||||
)
|
||||
}, 300)
|
||||
}
|
||||
@@ -140,7 +143,8 @@ export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput,
|
||||
autoCompactState,
|
||||
ctx.client,
|
||||
ctx.directory,
|
||||
experimental
|
||||
experimental,
|
||||
dcpForCompaction
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +274,10 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
||||
disabledHooks: (pluginConfig.claude_code?.hooks ?? true) ? undefined : true,
|
||||
});
|
||||
const anthropicContextWindowLimitRecovery = isHookEnabled("anthropic-context-window-limit-recovery")
|
||||
? createAnthropicContextWindowLimitRecoveryHook(ctx, { experimental: pluginConfig.experimental })
|
||||
? createAnthropicContextWindowLimitRecoveryHook(ctx, {
|
||||
experimental: pluginConfig.experimental,
|
||||
dcpForCompaction: isHookEnabled("dcp-for-compaction"),
|
||||
})
|
||||
: null;
|
||||
const compactionContextInjector = createCompactionContextInjector();
|
||||
const preemptiveCompaction = createPreemptiveCompactionHook(ctx, {
|
||||
|
||||
Reference in New Issue
Block a user