Skip to content

Commit ec61350

Browse files
committed
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)
1 parent 6125173 commit ec61350

File tree

9 files changed

+35
-24
lines changed

9 files changed

+35
-24
lines changed

README.ja.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ Oh My OpenCode は以下の場所からフックを読み込んで実行しま
874874
}
875875
```
876876

877-
利用可能なフック:`todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `empty-message-sanitizer`, `preemptive-compaction`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`
877+
利用可能なフック:`todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `empty-message-sanitizer`, `preemptive-compaction`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`, `dcp-for-compaction`
878878

879879
**`auto-update-checker``startup-toast`について**: `startup-toast` フックは `auto-update-checker` のサブ機能です。アップデートチェックは有効なまま起動トースト通知のみを無効化するには、`disabled_hooks``"startup-toast"` を追加してください。すべてのアップデートチェック機能(トーストを含む)を無効化するには、`"auto-update-checker"` を追加してください。
880880

@@ -928,8 +928,7 @@ OpenCode でサポートされるすべての LSP 構成およびカスタム設
928928
"experimental": {
929929
"aggressive_truncation": true,
930930
"auto_resume": true,
931-
"truncate_all_tool_outputs": false,
932-
"dcp_for_compaction": true
931+
"truncate_all_tool_outputs": false
933932
}
934933
}
935934
```
@@ -939,7 +938,8 @@ OpenCode でサポートされるすべての LSP 構成およびカスタム設
939938
| `aggressive_truncation` | `false` | トークン制限を超えた場合、ツール出力を積極的に切り詰めて制限内に収めます。デフォルトの切り詰めより積極的です。不十分な場合は要約/復元にフォールバックします。 |
940939
| `auto_resume` | `false` | thinking block エラーや thinking disabled violation からの回復成功後、自動的にセッションを再開します。最後のユーザーメッセージを抽出して続行します。 |
941940
| `truncate_all_tool_outputs` | `true` | プロンプトが長くなりすぎるのを防ぐため、コンテキストウィンドウの使用状況に基づいてすべてのツール出力を動的に切り詰めます。完全なツール出力が必要な場合は`false`に設定して無効化します。 |
942-
| `dcp_for_compaction` | `false` | 有効にすると、トークン制限エラー発生時にDCP(Dynamic Context Pruning)が最初に実行され、その後コンパクションが実行されます。DCPが不要なコンテキストを整理した後、すぐにコンパクションが進行します。トークン制限に達した際によりスマートな回復が必要な場合は有効にしてください。 |
941+
942+
**注意**: `dcp-for-compaction`(コンパクション用動的コンテキスト整理)はフックとして管理されるようになりました。デフォルトで有効で、`disabled_hooks: ["dcp-for-compaction"]`で無効化できます。
943943

944944
**警告**:これらの機能は実験的であり、予期しない動作を引き起こす可能性があります。影響を理解した場合にのみ有効にしてください。
945945

README.ko.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ Schema 자동 완성이 지원됩니다:
871871
}
872872
```
873873

874-
사용 가능한 훅: `todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `empty-message-sanitizer`, `preemptive-compaction`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`
874+
사용 가능한 훅: `todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `empty-message-sanitizer`, `preemptive-compaction`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`, `dcp-for-compaction`
875875

876876
**`auto-update-checker``startup-toast`에 대한 참고사항**: `startup-toast` 훅은 `auto-update-checker`의 하위 기능입니다. 업데이트 확인은 유지하면서 시작 토스트 알림만 비활성화하려면 `disabled_hooks``"startup-toast"`를 추가하세요. 모든 업데이트 확인 기능(토스트 포함)을 비활성화하려면 `"auto-update-checker"`를 추가하세요.
877877

@@ -925,8 +925,7 @@ OpenCode 에서 지원하는 모든 LSP 구성 및 커스텀 설정 (opencode.js
925925
"experimental": {
926926
"aggressive_truncation": true,
927927
"auto_resume": true,
928-
"truncate_all_tool_outputs": false,
929-
"dcp_for_compaction": true
928+
"truncate_all_tool_outputs": false
930929
}
931930
}
932931
```
@@ -936,7 +935,8 @@ OpenCode 에서 지원하는 모든 LSP 구성 및 커스텀 설정 (opencode.js
936935
| `aggressive_truncation` | `false` | 토큰 제한을 초과하면 도구 출력을 공격적으로 잘라내어 제한 내에 맞춥니다. 기본 truncation보다 더 공격적입니다. 부족하면 요약/복구로 fallback합니다. |
937936
| `auto_resume` | `false` | thinking block 에러나 thinking disabled violation으로부터 성공적으로 복구한 후 자동으로 세션을 재개합니다. 마지막 사용자 메시지를 추출하여 계속합니다. |
938937
| `truncate_all_tool_outputs` | `true` | 프롬프트가 너무 길어지는 것을 방지하기 위해 컨텍스트 윈도우 사용량에 따라 모든 도구 출력을 동적으로 잘라냅니다. 전체 도구 출력이 필요한 경우 `false`로 설정하여 비활성화하세요. |
939-
| `dcp_for_compaction` | `false` | 활성화하면, 토큰 제한 에러 발생 시 DCP(Dynamic Context Pruning)가 가장 먼저 실행되고, 그 다음 compaction이 실행됩니다. DCP가 불필요한 컨텍스트를 정리한 후 바로 compaction이 진행됩니다. 토큰 제한에 도달했을 때 더 스마트한 복구를 원하면 활성화하세요. |
938+
939+
**참고**: `dcp-for-compaction` (컴팩션용 동적 컨텍스트 정리)은 이제 훅으로 관리됩니다. 기본으로 활성화되어 있으며, `disabled_hooks: ["dcp-for-compaction"]`으로 비활성화할 수 있습니다.
940940

941941
**경고**: 이 기능들은 실험적이며 예상치 못한 동작을 유발할 수 있습니다. 의미를 이해한 경우에만 활성화하세요.
942942

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ Disable specific built-in hooks via `disabled_hooks` in `~/.config/opencode/oh-m
910910
}
911911
```
912912

913-
Available hooks: `todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `empty-message-sanitizer`, `preemptive-compaction`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`
913+
Available hooks: `todo-continuation-enforcer`, `context-window-monitor`, `session-recovery`, `session-notification`, `comment-checker`, `grep-output-truncator`, `tool-output-truncator`, `directory-agents-injector`, `directory-readme-injector`, `empty-task-response-detector`, `think-mode`, `anthropic-context-window-limit-recovery`, `rules-injector`, `background-notification`, `auto-update-checker`, `startup-toast`, `keyword-detector`, `agent-usage-reminder`, `non-interactive-env`, `interactive-bash-session`, `empty-message-sanitizer`, `preemptive-compaction`, `compaction-context-injector`, `thinking-block-validator`, `claude-code-hooks`, `ralph-loop`, `dcp-for-compaction`
914914

915915
**Note on `auto-update-checker` and `startup-toast`**: The `startup-toast` hook is a sub-feature of `auto-update-checker`. To disable only the startup toast notification while keeping update checking enabled, add `"startup-toast"` to `disabled_hooks`. To disable all update checking features (including the toast), add `"auto-update-checker"` to `disabled_hooks`.
916916

@@ -964,8 +964,7 @@ Opt-in experimental features that may change or be removed in future versions. U
964964
"experimental": {
965965
"aggressive_truncation": true,
966966
"auto_resume": true,
967-
"truncate_all_tool_outputs": false,
968-
"dcp_for_compaction": true
967+
"truncate_all_tool_outputs": false
969968
}
970969
}
971970
```
@@ -975,7 +974,8 @@ Opt-in experimental features that may change or be removed in future versions. U
975974
| `aggressive_truncation` | `false` | When token limit is exceeded, aggressively truncates tool outputs to fit within limits. More aggressive than the default truncation behavior. Falls back to summarize/revert if insufficient. |
976975
| `auto_resume` | `false` | Automatically resumes session after successful recovery from thinking block errors or thinking disabled violations. Extracts the last user message and continues. |
977976
| `truncate_all_tool_outputs` | `true` | Dynamically truncates ALL tool outputs based on context window usage to prevent prompts from becoming too long. Disable by setting to `false` if you need full tool outputs. |
978-
| `dcp_for_compaction` | `false` | When enabled, Dynamic Context Pruning (DCP) runs FIRST when token limit errors occur, before attempting compaction. DCP prunes redundant context, then compaction runs immediately. Enable this for smarter recovery when hitting token limits. |
977+
978+
**Note**: `dcp-for-compaction` (Dynamic Context Pruning for compaction) is now a hook, not an experimental feature. It's enabled by default and can be disabled via `disabled_hooks: ["dcp-for-compaction"]`.
979979

980980
**Warning**: These features are experimental and may cause unexpected behavior. Enable only if you understand the implications.
981981

README.zh-cn.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ Sisyphus Agent 也能自定义:
878878
}
879879
```
880880

881-
可关的 hook:`todo-continuation-enforcer``context-window-monitor``session-recovery``session-notification``comment-checker``grep-output-truncator``tool-output-truncator``directory-agents-injector``directory-readme-injector``empty-task-response-detector``think-mode``anthropic-context-window-limit-recovery``rules-injector``background-notification``auto-update-checker``startup-toast``keyword-detector``agent-usage-reminder``non-interactive-env``interactive-bash-session``empty-message-sanitizer``preemptive-compaction``compaction-context-injector``thinking-block-validator``claude-code-hooks``ralph-loop`
881+
可关的 hook:`todo-continuation-enforcer``context-window-monitor``session-recovery``session-notification``comment-checker``grep-output-truncator``tool-output-truncator``directory-agents-injector``directory-readme-injector``empty-task-response-detector``think-mode``anthropic-context-window-limit-recovery``rules-injector``background-notification``auto-update-checker``startup-toast``keyword-detector``agent-usage-reminder``non-interactive-env``interactive-bash-session``empty-message-sanitizer``preemptive-compaction``compaction-context-injector``thinking-block-validator``claude-code-hooks``ralph-loop``dcp-for-compaction`
882882

883883
**关于 `auto-update-checker``startup-toast`**: `startup-toast` hook 是 `auto-update-checker` 的子功能。若想保持更新检查但只禁用启动提示通知,在 `disabled_hooks` 中添加 `"startup-toast"`。若要禁用所有更新检查功能(包括提示),添加 `"auto-update-checker"`
884884

@@ -932,8 +932,7 @@ Oh My OpenCode 送你重构工具(重命名、代码操作)。
932932
"experimental": {
933933
"aggressive_truncation": true,
934934
"auto_resume": true,
935-
"truncate_all_tool_outputs": false,
936-
"dcp_for_compaction": true
935+
"truncate_all_tool_outputs": false
937936
}
938937
}
939938
```
@@ -943,7 +942,8 @@ Oh My OpenCode 送你重构工具(重命名、代码操作)。
943942
| `aggressive_truncation` | `false` | 超出 token 限制时,激进地截断工具输出以适应限制。比默认截断更激进。不够的话会回退到摘要/恢复。 |
944943
| `auto_resume` | `false` | 从 thinking block 错误或 thinking disabled violation 成功恢复后,自动恢复会话。提取最后一条用户消息继续执行。 |
945944
| `truncate_all_tool_outputs` | `true` | 为防止提示过长,根据上下文窗口使用情况动态截断所有工具输出。如需完整工具输出,设置为 `false` 禁用此功能。 |
946-
| `dcp_for_compaction` | `false` | 启用后,当发生 token 限制错误时,DCP(动态上下文剪枝)首先运行,然后立即执行压缩。DCP 清理不必要的上下文后,压缩立即进行。当达到 token 限制时需要更智能的恢复请启用此选项。 |
945+
946+
**注意**: `dcp-for-compaction`(压缩用动态上下文剪枝)现在作为 hook 管理。默认启用,可通过 `disabled_hooks: ["dcp-for-compaction"]` 禁用。
947947

948948
**警告**:这些功能是实验性的,可能会导致意外行为。只有在理解其影响的情况下才启用。
949949

src/config/schema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const HookNameSchema = z.enum([
6666
"empty-message-sanitizer",
6767
"thinking-block-validator",
6868
"ralph-loop",
69+
"dcp-for-compaction",
6970
])
7071

7172
export const BuiltinCommandNameSchema = z.enum([
@@ -172,8 +173,6 @@ export const ExperimentalConfigSchema = z.object({
172173
truncate_all_tool_outputs: z.boolean().default(true),
173174
/** Dynamic context pruning configuration */
174175
dynamic_context_pruning: DynamicContextPruningConfigSchema.optional(),
175-
/** Enable DCP (Dynamic Context Pruning) for compaction - runs first when token limit exceeded (default: false) */
176-
dcp_for_compaction: z.boolean().optional(),
177176
})
178177

179178
export const SkillSourceSchema = z.union([

src/hooks/anthropic-context-window-limit-recovery/executor.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ describe("executeCompact lock management", () => {
151151
truncate_all_tool_outputs: false,
152152
aggressive_truncation: true,
153153
}
154+
const dcpForCompaction = true
154155

155156
// #when: Execute compaction with experimental flag
156157
await executeCompact(
@@ -160,6 +161,7 @@ describe("executeCompact lock management", () => {
160161
mockClient,
161162
directory,
162163
experimental,
164+
dcpForCompaction,
163165
)
164166

165167
// #then: Lock should be cleared even on early return

src/hooks/anthropic-context-window-limit-recovery/executor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export async function executeCompact(
337337
client: any,
338338
directory: string,
339339
experimental?: ExperimentalConfig,
340+
dcpForCompaction?: boolean,
340341
): Promise<void> {
341342
if (autoCompactState.compactionInProgress.has(sessionID)) {
342343
await (client as Client).tui
@@ -358,10 +359,10 @@ export async function executeCompact(
358359
const errorData = autoCompactState.errorDataBySession.get(sessionID);
359360
const truncateState = getOrCreateTruncateState(autoCompactState, sessionID);
360361

361-
// DCP FIRST - run before any other recovery attempts when token limit exceeded
362+
// DCP FIRST - run before any other recovery attempts when token limit exceeded (controlled by dcp-for-compaction hook)
362363
const dcpState = getOrCreateDcpState(autoCompactState, sessionID);
363364
if (
364-
experimental?.dcp_for_compaction &&
365+
dcpForCompaction !== false &&
365366
!dcpState.attempted &&
366367
errorData?.currentTokens &&
367368
errorData?.maxTokens &&
@@ -374,7 +375,7 @@ export async function executeCompact(
374375
maxTokens: errorData.maxTokens,
375376
});
376377

377-
const dcpConfig = experimental.dynamic_context_pruning ?? {
378+
const dcpConfig = experimental?.dynamic_context_pruning ?? {
378379
enabled: true,
379380
notification: "detailed" as const,
380381
protected_tools: ["task", "todowrite", "todoread", "lsp_rename", "lsp_code_action_resolve"],
@@ -618,6 +619,7 @@ export async function executeCompact(
618619
client,
619620
directory,
620621
experimental,
622+
dcpForCompaction,
621623
);
622624
}, 500);
623625
return;
@@ -696,6 +698,7 @@ export async function executeCompact(
696698
client,
697699
directory,
698700
experimental,
701+
dcpForCompaction,
699702
);
700703
}, cappedDelay);
701704
return;

src/hooks/anthropic-context-window-limit-recovery/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { log } from "../../shared/logger"
77

88
export interface AnthropicContextWindowLimitRecoveryOptions {
99
experimental?: ExperimentalConfig
10+
dcpForCompaction?: boolean
1011
}
1112

1213
function createRecoveryState(): AutoCompactState {
@@ -25,6 +26,7 @@ function createRecoveryState(): AutoCompactState {
2526
export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput, options?: AnthropicContextWindowLimitRecoveryOptions) {
2627
const autoCompactState = createRecoveryState()
2728
const experimental = options?.experimental
29+
const dcpForCompaction = options?.dcpForCompaction
2830

2931
const eventHandler = async ({ event }: { event: { type: string; properties?: unknown } }) => {
3032
const props = event.properties as Record<string, unknown> | undefined
@@ -81,7 +83,8 @@ export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput,
8183
autoCompactState,
8284
ctx.client,
8385
ctx.directory,
84-
experimental
86+
experimental,
87+
dcpForCompaction
8588
)
8689
}, 300)
8790
}
@@ -140,7 +143,8 @@ export function createAnthropicContextWindowLimitRecoveryHook(ctx: PluginInput,
140143
autoCompactState,
141144
ctx.client,
142145
ctx.directory,
143-
experimental
146+
experimental,
147+
dcpForCompaction
144148
)
145149
}
146150
}

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
274274
disabledHooks: (pluginConfig.claude_code?.hooks ?? true) ? undefined : true,
275275
});
276276
const anthropicContextWindowLimitRecovery = isHookEnabled("anthropic-context-window-limit-recovery")
277-
? createAnthropicContextWindowLimitRecoveryHook(ctx, { experimental: pluginConfig.experimental })
277+
? createAnthropicContextWindowLimitRecoveryHook(ctx, {
278+
experimental: pluginConfig.experimental,
279+
dcpForCompaction: isHookEnabled("dcp-for-compaction"),
280+
})
278281
: null;
279282
const compactionContextInjector = createCompactionContextInjector();
280283
const preemptiveCompaction = createPreemptiveCompactionHook(ctx, {

0 commit comments

Comments
 (0)