Skip to content

Commit bb9658d

Browse files
perf(shared): command output failure scan rejects clean output in one pass (pingdotgg#26935)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 6f21b0f commit bb9658d

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎packages/shared/src/toolOutput.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ describe("toolOutputIndicatesFailure", () => {
156156
"<exited with exit code 2>",
157157
"Exited with exit code 1",
158158
"exit code: 127",
159+
"clean exit first, then ExIt CoDe: 3",
159160
])
160161
expect(toolOutputIndicatesFailure(text)).toBe(true);
161162
});
@@ -167,6 +168,9 @@ describe("toolOutputIndicatesFailure", () => {
167168
"Exited with exit code 0",
168169
"cannot find path",
169170
"is not recognized",
171+
"exit",
172+
"not found",
173+
"the path cannot be found",
170174
]) {
171175
expect(toolOutputIndicatesFailure(text)).toBe(false);
172176
}

‎packages/shared/src/toolOutput.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,21 @@ export function mcpAppFromToolItem(item: {
232232
: undefined;
233233
}
234234

235+
// A superset of every needle below, so most outputs are rejected by this single scan.
236+
const FAILURE_HINT =
237+
/enoent|no such|no files found|not found|commandnotfound|not recognized|cannot (?:find path|be found)|exit/i;
238+
235239
/** Some providers report completion even when command output describes a failure. */
236240
export function toolOutputIndicatesFailure(text: string): boolean {
237241
return (
238-
/file not found|no files found|enoent|no such file|commandnotfoundexception|command not found|is not recognized as the name of a cmdlet|a parameter cannot be found that matches parameter name/i.test(
242+
FAILURE_HINT.test(text) &&
243+
(/file not found|no files found|enoent|no such file|commandnotfoundexception|command not found|is not recognized as the name of a cmdlet|a parameter cannot be found that matches parameter name/i.test(
239244
text,
240245
) ||
241-
(/cannot find path/i.test(text) && /because it does not exist/i.test(text)) ||
242-
(/is not recognized/i.test(text) && /the term '/i.test(text)) ||
243-
/<exited with exit code\s+[1-9]\d*\s*>/i.test(text) ||
244-
/exit(?:ed)? with exit code\s+[1-9]\d*/i.test(text) ||
245-
/exit code\s*[:\s]\s*[1-9]\d*\b/i.test(text)
246+
(/cannot find path/i.test(text) && /because it does not exist/i.test(text)) ||
247+
(/is not recognized/i.test(text) && /the term '/i.test(text)) ||
248+
/exit(?:ed)? with exit code\s+[1-9]\d*/i.test(text) ||
249+
/exit code\s*[:\s]\s*[1-9]\d*\b/i.test(text))
246250
);
247251
}
248252

0 commit comments

Comments
 (0)