Skip to content

Commit 6ece747

Browse files
committed
feat(hooks): add empty-task-response-detector hook
1 parent 9ed23d4 commit 6ece747

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { PluginInput } from "@opencode-ai/plugin"
2+
3+
const EMPTY_RESPONSE_WARNING = `[Task Empty Response Warning]
4+
5+
Task invocation completed but returned no response. This indicates the agent either:
6+
- Failed to execute properly
7+
- Did not terminate correctly
8+
- Returned an empty result
9+
10+
Note: The call has already completed - you are NOT waiting for a response. Proceed accordingly.`
11+
12+
export function createEmptyTaskResponseDetectorHook(_ctx: PluginInput) {
13+
return {
14+
"tool.execute.after": async (
15+
input: { tool: string; sessionID: string; callID: string },
16+
output: { title: string; output: string; metadata: unknown }
17+
) => {
18+
if (input.tool !== "Task") return
19+
20+
const responseText = output.output?.trim() ?? ""
21+
22+
if (responseText === "") {
23+
output.output = EMPTY_RESPONSE_WARNING
24+
}
25+
},
26+
}
27+
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
createGrepOutputTruncatorHook,
99
createPulseMonitorHook,
1010
createDirectoryAgentsInjectorHook,
11+
createEmptyTaskResponseDetectorHook,
1112
} from "./hooks";
1213
import { updateTerminalTitle } from "./features/terminal";
1314
import { builtinTools } from "./tools";
@@ -57,6 +58,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
5758
const commentChecker = createCommentCheckerHooks();
5859
const grepOutputTruncator = createGrepOutputTruncatorHook(ctx);
5960
const directoryAgentsInjector = createDirectoryAgentsInjectorHook(ctx);
61+
const emptyTaskResponseDetector = createEmptyTaskResponseDetectorHook(ctx);
6062

6163
updateTerminalTitle({ sessionId: "main" });
6264

@@ -212,6 +214,7 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
212214
await contextWindowMonitor["tool.execute.after"](input, output);
213215
await commentChecker["tool.execute.after"](input, output);
214216
await directoryAgentsInjector["tool.execute.after"](input, output);
217+
await emptyTaskResponseDetector["tool.execute.after"](input, output);
215218

216219
if (input.sessionID === mainSessionID) {
217220
updateTerminalTitle({

0 commit comments

Comments
 (0)