feat(hooks): add empty-task-response-detector hook
This commit is contained in:
27
src/hooks/empty-task-response-detector.ts
Normal file
27
src/hooks/empty-task-response-detector.ts
Normal 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
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
createGrepOutputTruncatorHook,
|
createGrepOutputTruncatorHook,
|
||||||
createPulseMonitorHook,
|
createPulseMonitorHook,
|
||||||
createDirectoryAgentsInjectorHook,
|
createDirectoryAgentsInjectorHook,
|
||||||
|
createEmptyTaskResponseDetectorHook,
|
||||||
} from "./hooks";
|
} from "./hooks";
|
||||||
import { updateTerminalTitle } from "./features/terminal";
|
import { updateTerminalTitle } from "./features/terminal";
|
||||||
import { builtinTools } from "./tools";
|
import { builtinTools } from "./tools";
|
||||||
@@ -57,6 +58,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
const commentChecker = createCommentCheckerHooks();
|
const commentChecker = createCommentCheckerHooks();
|
||||||
const grepOutputTruncator = createGrepOutputTruncatorHook(ctx);
|
const grepOutputTruncator = createGrepOutputTruncatorHook(ctx);
|
||||||
const directoryAgentsInjector = createDirectoryAgentsInjectorHook(ctx);
|
const directoryAgentsInjector = createDirectoryAgentsInjectorHook(ctx);
|
||||||
|
const emptyTaskResponseDetector = createEmptyTaskResponseDetectorHook(ctx);
|
||||||
|
|
||||||
updateTerminalTitle({ sessionId: "main" });
|
updateTerminalTitle({ sessionId: "main" });
|
||||||
|
|
||||||
@@ -212,6 +214,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
await contextWindowMonitor["tool.execute.after"](input, output);
|
await contextWindowMonitor["tool.execute.after"](input, output);
|
||||||
await commentChecker["tool.execute.after"](input, output);
|
await commentChecker["tool.execute.after"](input, output);
|
||||||
await directoryAgentsInjector["tool.execute.after"](input, output);
|
await directoryAgentsInjector["tool.execute.after"](input, output);
|
||||||
|
await emptyTaskResponseDetector["tool.execute.after"](input, output);
|
||||||
|
|
||||||
if (input.sessionID === mainSessionID) {
|
if (input.sessionID === mainSessionID) {
|
||||||
updateTerminalTitle({
|
updateTerminalTitle({
|
||||||
|
|||||||
Reference in New Issue
Block a user