Skip to content

Commit 1e5d6f4

Browse files
hieu-leeclaude
andcommitted
perf(shared): command output failure scan rejects clean output in one pass
A superset hint regex gates the six failure checks, so outputs with no failure wording are scanned once. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 3748c5c commit 1e5d6f4

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
@@ -150,6 +150,7 @@ describe("toolOutputIndicatesFailure", () => {
150150
"<exited with exit code 2>",
151151
"Exited with exit code 1",
152152
"exit code: 127",
153+
"clean exit first, then ExIt CoDe: 3",
153154
])
154155
expect(toolOutputIndicatesFailure(text)).toBe(true);
155156
});
@@ -161,6 +162,9 @@ describe("toolOutputIndicatesFailure", () => {
161162
"Exited with exit code 0",
162163
"cannot find path",
163164
"is not recognized",
165+
"exit",
166+
"not found",
167+
"the path cannot be found",
164168
]) {
165169
expect(toolOutputIndicatesFailure(text)).toBe(false);
166170
}

‎packages/shared/src/toolOutput.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,21 @@ export function mcpAppFromToolItem(item: {
194194
return app !== undefined && item.toolName === `${app.server}.${app.tool}` ? app : undefined;
195195
}
196196

197+
// A superset of every needle below, so most outputs are rejected by this single scan.
198+
const FAILURE_HINT =
199+
/enoent|no such|no files found|not found|commandnotfound|not recognized|cannot (?:find path|be found)|exit/i;
200+
197201
/** Some providers report completion even when command output describes a failure. */
198202
export function toolOutputIndicatesFailure(text: string): boolean {
199203
return (
200-
/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(
204+
FAILURE_HINT.test(text) &&
205+
(/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(
201206
text,
202207
) ||
203-
(/cannot find path/i.test(text) && /because it does not exist/i.test(text)) ||
204-
(/is not recognized/i.test(text) && /the term '/i.test(text)) ||
205-
/<exited with exit code\s+[1-9]\d*\s*>/i.test(text) ||
206-
/exit(?:ed)? with exit code\s+[1-9]\d*/i.test(text) ||
207-
/exit code\s*[:\s]\s*[1-9]\d*\b/i.test(text)
208+
(/cannot find path/i.test(text) && /because it does not exist/i.test(text)) ||
209+
(/is not recognized/i.test(text) && /the term '/i.test(text)) ||
210+
/exit(?:ed)? with exit code\s+[1-9]\d*/i.test(text) ||
211+
/exit code\s*[:\s]\s*[1-9]\d*\b/i.test(text))
208212
);
209213
}
210214

0 commit comments

Comments
 (0)