Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 1x 1x | /**
* Parses shell command output from different runtime formats.
*
* Codex emits `[exit N] output` format. Other runtimes emit plain output.
*/
/** Parsed shell command result. */
export interface ShellResult {
/** Exit code, or undefined if not available. */
exitCode: number | undefined;
/** Command output (stdout/stderr). */
output: string;
}
/** Pattern matching Codex's `[exit N] rest` format. */
const EXIT_CODE_PATTERN: RegExp = /^\[exit (\d+)\]\s*/;
/** Parses shell output, extracting exit code if present. */
export function parseShellOutput(content: string): ShellResult {
const match: RegExpExecArray | null = EXIT_CODE_PATTERN.exec(content);
if (match) {
return {
exitCode: Number(match[1]),
output: content.slice(match[0].length),
};
}
return { exitCode: undefined, output: content };
}
|