MCPcopy Create free account
hub / github.com/Noumena-Network/code / parseCommandRaw

Function parseCommandRaw

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

Source from the content-addressed store, hash-verified

111 * - PARSE_ABORTED: module loaded but parse failed (timeout/panic)
112 */
113export async function parseCommandRaw(
114 command: string,
115): Promise<Node | null | typeof PARSE_ABORTED> {
116 if (!command || command.length > MAX_COMMAND_LENGTH) return null
117
118 if (feature('TREE_SITTER_BASH') || feature('TREE_SITTER_BASH_SHADOW')) {
119 const cached = parseCommandRawCache.get(command)
120 if (cached !== undefined) {
121 return cached
122 }
123
124 await ensureParserInitialized()
125 const mod = getParserModule()
126 logLoadOnce(mod !== null)
127 if (!mod) return null
128 try {
129 const result = mod.parse(command)
130 // SECURITY: Module loaded; null here = timeout/node-budget abort in
131 // bashParser.ts (PARSE_TIMEOUT_MS=50, MAX_NODES=50_000).
132 // Previously collapsed into `return null` → parse-unavailable → legacy
133 // path, which lacks EVAL_LIKE_BUILTINS — `trap`, `enable`, `hash` leaked.
134 if (result === null) {
135 logEvent('ncode_tree_sitter_parse_abort', {
136 cmdLength: command.length,
137 panic: false,
138 })
139 parseCommandRawCache.set(command, PARSE_ABORTED)
140 return PARSE_ABORTED
141 }
142 parseCommandRawCache.set(command, result)
143 return result
144 } catch {
145 logEvent('ncode_tree_sitter_parse_abort', {
146 cmdLength: command.length,
147 panic: true,
148 })
149 parseCommandRawCache.set(command, PARSE_ABORTED)
150 return PARSE_ABORTED
151 }
152 }
153 return null
154}
155
156function findCommandNode(node: Node, parent: Node | null): Node | null {
157 const { type, children } = node

Callers 2

bashToolHasPermissionFunction · 0.85
parseForSecurityFunction · 0.85

Calls 6

ensureParserInitializedFunction · 0.85
getParserModuleFunction · 0.85
logLoadOnceFunction · 0.85
setMethod · 0.80
logEventFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected