MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseCommand

Function parseCommand

source code/utils/bash/parser.ts:58–86  ·  view source on GitHub ↗
(
  command: string,
)

Source from the content-addressed store, hash-verified

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

Callers 3

ParsedCommand.tsFile · 0.70
doParseFunction · 0.70
getCommandPrefixStaticFunction · 0.70

Calls 5

ensureParserInitializedFunction · 0.85
getParserModuleFunction · 0.85
logLoadOnceFunction · 0.85
findCommandNodeFunction · 0.85
extractEnvVarsFunction · 0.85

Tested by

no test coverage detected