( command: string, )
| 54 | } |
| 55 | |
| 56 | export async function parseCommand( |
| 57 | command: string, |
| 58 | ): Promise<ParsedCommandData | null> { |
| 59 | if (!command || command.length > MAX_COMMAND_LENGTH) return null |
| 60 | |
| 61 | // Gate: ant-only until pentest. External builds fall back to legacy |
| 62 | // regex/shell-quote path. Guarding the whole body inside the positive |
| 63 | // branch lets Bun DCE the NAPI import AND keeps telemetry honest — we |
| 64 | // only fire tengu_tree_sitter_load when a load was genuinely attempted. |
| 65 | if (feature('TREE_SITTER_BASH')) { |
| 66 | await ensureParserInitialized() |
| 67 | const mod = getParserModule() |
| 68 | logLoadOnce(mod !== null) |
| 69 | if (!mod) return null |
| 70 | |
| 71 | try { |
| 72 | const rootNode = mod.parse(command) |
| 73 | if (!rootNode) return null |
| 74 | |
| 75 | const commandNode = findCommandNode(rootNode, null) |
| 76 | const envVars = extractEnvVars(commandNode) |
| 77 | |
| 78 | return { rootNode, envVars, commandNode, originalCommand: command } |
| 79 | } catch { |
| 80 | return null |
| 81 | } |
| 82 | } |
| 83 | return null |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * SECURITY: Sentinel for "parser was loaded and attempted, but aborted" |
no test coverage detected