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:
@@ -10,6 +10,7 @@ export function createDelegateTaskRetryHook(_ctx: PluginInput) {
|
|||||||
output: { title: string; output: string; metadata: unknown }
|
output: { title: string; output: string; metadata: unknown }
|
||||||
) => {
|
) => {
|
||||||
if (input.tool.toLowerCase() !== "task") return
|
if (input.tool.toLowerCase() !== "task") return
|
||||||
|
if (typeof output.output !== "string") return
|
||||||
|
|
||||||
const errorInfo = detectDelegateTaskError(output.output)
|
const errorInfo = detectDelegateTaskError(output.output)
|
||||||
if (errorInfo) {
|
if (errorInfo) {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export function createEditErrorRecoveryHook(_ctx: PluginInput) {
|
|||||||
output: { title: string; output: string; metadata: unknown }
|
output: { title: string; output: string; metadata: unknown }
|
||||||
) => {
|
) => {
|
||||||
if (input.tool.toLowerCase() !== "edit") return
|
if (input.tool.toLowerCase() !== "edit") return
|
||||||
|
if (typeof output.output !== "string") return
|
||||||
|
|
||||||
const outputLower = output.output.toLowerCase()
|
const outputLower = output.output.toLowerCase()
|
||||||
const hasEditError = EDIT_ERROR_PATTERNS.some((pattern) =>
|
const hasEditError = EDIT_ERROR_PATTERNS.some((pattern) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user