feat: add two-layer thinking block validation (proactive + reactive) (#248)

- Add thinking-block-validator hook for proactive prevention before API calls
- Enhance session-recovery to include previous thinking content
- Fix hook registration to actually invoke the validator

Addresses extended thinking errors with Claude Opus/Sonnet 4.5 using tool calls.

Related: https://github.com/vercel/ai/issues/7729
Related: https://github.com/sst/opencode/issues/2599
This commit is contained in:
Steven Vo
2025-12-26 21:14:11 +07:00
committed by GitHub
parent e05d9dfc35
commit 15de6f637e
6 changed files with 219 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ import {
createNonInteractiveEnvHook,
createInteractiveBashSessionHook,
createEmptyMessageSanitizerHook,
createThinkingBlockValidatorHook,
} from "./hooks";
import { createGoogleAntigravityAuthPlugin } from "./auth/antigravity";
import {
@@ -319,6 +320,9 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
const emptyMessageSanitizer = isHookEnabled("empty-message-sanitizer")
? createEmptyMessageSanitizerHook()
: null;
const thinkingBlockValidator = isHookEnabled("thinking-block-validator")
? createThinkingBlockValidatorHook()
: null;
const backgroundManager = new BackgroundManager(ctx);
@@ -365,6 +369,8 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
input: Record<string, never>,
output: { messages: Array<{ info: unknown; parts: unknown[] }> }
) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await thinkingBlockValidator?.["experimental.chat.messages.transform"]?.(input, output as any);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await emptyMessageSanitizer?.["experimental.chat.messages.transform"]?.(input, output as any);
},