MCPcopy Index your code
hub / github.com/codeaashu/claude-code / parseCommandRaw

Function parseCommandRaw

src/utils/bash/parser.ts:104–136  ·  view source on GitHub ↗
(
  command: string,
)

Source from the content-addressed store, hash-verified

102 * - PARSE_ABORTED: module loaded but parse failed (timeout/panic)
103 */
104export 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
138function findCommandNode(node: Node, parent: Node | null): Node | null {
139 const { type, children } = node

Callers 2

bashToolHasPermissionFunction · 0.85
parseForSecurityFunction · 0.85

Calls 6

featureFunction · 0.85
ensureParserInitializedFunction · 0.85
getParserModuleFunction · 0.85
logLoadOnceFunction · 0.85
logEventFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected