( command: string, )
| 102 | * - PARSE_ABORTED: module loaded but parse failed (timeout/panic) |
| 103 | */ |
| 104 | export async function parseCommandRaw( |
| 105 | command: string, |
| 106 | ): Promise<Node | null | typeof PARSE_ABORTED> { |
| 107 | if (!command || command.length > MAX_COMMAND_LENGTH) return null |
| 108 | if (feature('TREE_SITTER_BASH') || feature('TREE_SITTER_BASH_SHADOW')) { |
| 109 | await ensureParserInitialized() |
| 110 | const mod = getParserModule() |
| 111 | logLoadOnce(mod !== null) |
| 112 | if (!mod) return null |
| 113 | try { |
| 114 | const result = mod.parse(command) |
| 115 | // SECURITY: Module loaded; null here = timeout/node-budget abort in |
| 116 | // bashParser.ts (PARSE_TIMEOUT_MS=50, MAX_NODES=50_000). |
| 117 | // Previously collapsed into `return null` → parse-unavailable → legacy |
| 118 | // path, which lacks EVAL_LIKE_BUILTINS — `trap`, `enable`, `hash` leaked. |
| 119 | if (result === null) { |
| 120 | logEvent('tengu_tree_sitter_parse_abort', { |
| 121 | cmdLength: command.length, |
| 122 | panic: false, |
| 123 | }) |
| 124 | return PARSE_ABORTED |
| 125 | } |
| 126 | return result |
| 127 | } catch { |
| 128 | logEvent('tengu_tree_sitter_parse_abort', { |
| 129 | cmdLength: command.length, |
| 130 | panic: true, |
| 131 | }) |
| 132 | return PARSE_ABORTED |
| 133 | } |
| 134 | } |
| 135 | return null |
| 136 | } |
| 137 | |
| 138 | function findCommandNode(node: Node, parent: Node | null): Node | null { |
| 139 | const { type, children } = node |
no test coverage detected