fix(hooks): guard against non-string tool output in afterToolResult hooks

MCP tools can return non-string results (e.g. structured JSON objects).
When this happens, output.output is undefined, causing TypeError crashes
in edit-error-recovery and delegate-task-retry hooks that call methods
like .toLowerCase() without checking the type first.

Add typeof string guard in both hooks, consistent with the existing
pattern used in tool-output-truncator.
This commit is contained in:
bob_karrot
2026-02-11 14:23:37 +09:00
parent bfe1730e9f
commit bb6a011964
2 changed files with 2 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ export function createDelegateTaskRetryHook(_ctx: PluginInput) {
output: { title: string; output: string; metadata: unknown }
) => {
if (input.tool.toLowerCase() !== "task") return
if (typeof output.output !== "string") return
const errorInfo = detectDelegateTaskError(output.output)
if (errorInfo) {

View File

@@ -43,6 +43,7 @@ export function createEditErrorRecoveryHook(_ctx: PluginInput) {
output: { title: string; output: string; metadata: unknown }
) => {
if (input.tool.toLowerCase() !== "edit") return
if (typeof output.output !== "string") return
const outputLower = output.output.toLowerCase()
const hasEditError = EDIT_ERROR_PATTERNS.some((pattern) =>