Skip to content

Commit 12c8f55

Browse files
committed
refactor(chat): improve command status determination and exit code parsing
- Refine `deriveCommandStatus` logic to better classify success, error, and running states - Consolidate exit code regex into reusable constant for `stripTrailingExitCode` parsing
1 parent 3e4e1a2 commit 12c8f55

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

apps/web/src/components/chat/CommandExecutionCard.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ const PREVIEW_MAX_HEIGHT_PX = 120;
1616
const MIN_OVERFLOW_PX = 24;
1717

1818
function deriveCommandStatus(entry: WorkLogEntry, isLive: boolean): CommandStatus {
19-
if (!entry.toolCompleted && entry.exitCode === undefined) return "running";
20-
if (isLive && entry.exitCode === undefined) return "running";
21-
if (entry.tone === "error" || (entry.exitCode !== undefined && entry.exitCode !== 0))
22-
return "error";
19+
if (entry.toolCompleted || entry.exitCode !== undefined) {
20+
if (entry.tone === "error" || (entry.exitCode !== undefined && entry.exitCode !== 0))
21+
return "error";
22+
return "success";
23+
}
24+
if (isLive) return "running";
2325
return "success";
2426
}
2527

apps/web/src/session-logic.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,14 +1135,15 @@ function extractToolResultText(payload: Record<string, unknown> | null): string
11351135
return null;
11361136
}
11371137

1138+
const EXIT_CODE_RE =
1139+
/^(?<output>[\s\S]*?)(?:\s*<?(?:exited with (?:exit )?code|Exited with code) (?<code>\d+)>?)\s*$/i;
1140+
11381141
function stripTrailingExitCode(value: string): {
11391142
output: string | null;
11401143
exitCode?: number | undefined;
11411144
} {
11421145
const trimmed = value.trim();
1143-
const match = /^(?<output>[\s\S]*?)(?:\s*<exited with exit code (?<code>\d+)>)\s*$/i.exec(
1144-
trimmed,
1145-
);
1146+
const match = EXIT_CODE_RE.exec(trimmed);
11461147
if (!match?.groups) {
11471148
return {
11481149
output: trimmed.length > 0 ? trimmed : null,

0 commit comments

Comments
 (0)