char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
0afb805b1
char/aliceai-t5-moe
1/** 2* Parsing helpers for `exec_shell_command` tool output. 3* 4* The server appends one final line to the response - an exit-code summary 5* shaped as `[exit code: N]` (and optionally followed by `[exit due to timed 6* out]`) - so the renderer can color that final line based on success/failure 7* without parsing the entire output stream. 8*/ 9 10export interface ExecShellExitStatus { 11code :number ; 12timedOut :boolean ; 13/** Length-prefix slice for matching against the rendered lines list. */ 14rawText :string ; 15} 16 17// Anchor to the absolute end so intermediate "[exit code: N]" string content 18// (e.g. a shell echo) doesn't false-positive. The marker is at most ~50 chars 19// with the timed-out suffix, so matching a tail slice keeps the cost constant 20// for megabyte exec outputs instead of scanning the whole blob. 21const EXIT_CODE_TAIL_REGEX = / \[exit code: (-?\d+)\](?: \[exit due to timed out\])?\s*$ / ; 22const EXIT_CODE_TAIL_SCAN = 128 ; 23 24export function parseExecShellCommandExitStatus ( 25toolResultString :string | undefined 26) :ExecShellExitStatus | undefined { 27if ( ! toolResultString ) return undefined ; 28 29const match = toolResultString . slice ( - EXIT_CODE_TAIL_SCAN ). match ( EXIT_CODE_TAIL_REGEX ); 30 31if ( ! match ) return undefined ; 32 33return { 34code :Number . parseInt ( match [ 1 ], 10 ), 35rawText :match [ 0 ], 36timedOut :match [ 0 ]. includes ( 'exit due to timed out' ) 37}; 38} 39 40/** 41* Returns true when the supplied rendered line equals (trimmed) the 42* trailing exit-code text. Used by the renderer to drop the duplicated 43* representation (since the trailing line is replaced by a status badge). 44*/ 45export function isExitCodeSummaryLine ( 46lineText :string , 47status :ExecShellExitStatus | undefined 48) :boolean { 49if ( ! status ) return false ; 50 51return lineText . trim () === status . rawText . trim (); 52}