feat(hooks): add empty-task-response-detector hook

This commit is contained in:
YeonGyu-Kim
2025-12-08 16:54:44 +09:00
parent 9ed23d4037
commit 6ece7476ef
2 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import type { PluginInput } from "@opencode-ai/plugin"
const EMPTY_RESPONSE_WARNING = `[Task Empty Response Warning]
Task invocation completed but returned no response. This indicates the agent either:
- Failed to execute properly
- Did not terminate correctly
- Returned an empty result
Note: The call has already completed - you are NOT waiting for a response. Proceed accordingly.`
export function createEmptyTaskResponseDetectorHook(_ctx: PluginInput) {
return {
"tool.execute.after": async (
input: { tool: string; sessionID: string; callID: string },
output: { title: string; output: string; metadata: unknown }
) => {
if (input.tool !== "Task") return
const responseText = output.output?.trim() ?? ""
if (responseText === "") {
output.output = EMPTY_RESPONSE_WARNING
}
},
}
}

View File

@@ -8,6 +8,7 @@ import {
createGrepOutputTruncatorHook,
createPulseMonitorHook,
createDirectoryAgentsInjectorHook,
createEmptyTaskResponseDetectorHook,
} from "./hooks";
import { updateTerminalTitle } from "./features/terminal";
import { builtinTools } from "./tools";
@@ -57,6 +58,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
const commentChecker = createCommentCheckerHooks();
const grepOutputTruncator = createGrepOutputTruncatorHook(ctx);
const directoryAgentsInjector = createDirectoryAgentsInjectorHook(ctx);
const emptyTaskResponseDetector = createEmptyTaskResponseDetectorHook(ctx);
updateTerminalTitle({ sessionId: "main" });
@@ -212,6 +214,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
await contextWindowMonitor["tool.execute.after"](input, output);
await commentChecker["tool.execute.after"](input, output);
await directoryAgentsInjector["tool.execute.after"](input, output);
await emptyTaskResponseDetector["tool.execute.after"](input, output);
if (input.sessionID === mainSessionID) {
updateTerminalTitle({