fix: guard output.output in tool after-hooks for MCP tools (#1720)
MCP tool responses can have undefined output.output, causing TypeError crashes in tool.execute.after hooks. Changes: - comment-checker/hook.ts: guard output.output with ?? '' before toLowerCase() - edit-error-recovery/hook.ts: guard output.output with ?? '' before toLowerCase() - task-resume-info/hook.ts: extract output.output ?? '' into outputText before all string operations - Added tests for undefined output.output in edit-error-recovery and task-resume-info
This commit is contained in:
@@ -21,14 +21,15 @@ export function createTaskResumeInfoHook() {
|
||||
output: { title: string; output: string; metadata: unknown }
|
||||
) => {
|
||||
if (!TARGET_TOOLS.includes(input.tool)) return
|
||||
if (output.output.startsWith("Error:") || output.output.startsWith("Failed")) return
|
||||
if (output.output.includes("\nto continue:")) return
|
||||
const outputText = output.output ?? ""
|
||||
if (outputText.startsWith("Error:") || outputText.startsWith("Failed")) return
|
||||
if (outputText.includes("\nto continue:")) return
|
||||
|
||||
const sessionId = extractSessionId(output.output)
|
||||
const sessionId = extractSessionId(outputText)
|
||||
if (!sessionId) return
|
||||
|
||||
output.output =
|
||||
output.output.trimEnd() +
|
||||
outputText.trimEnd() +
|
||||
`\n\nto continue: task(session_id="${sessionId}", prompt="...")`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user