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

Function parseCommandRaw

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

Source from the content-addressed store, hash-verified

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

Callers 2

bashToolHasPermissionFunction · 0.85
parseForSecurityFunction · 0.85

Calls 4

ensureParserInitializedFunction · 0.85
getParserModuleFunction · 0.85
logLoadOnceFunction · 0.85
logEventFunction · 0.85

Tested by

no test coverage detected