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

Function parseCommand

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

Source from the content-addressed store, hash-verified

63}
64
65export async function parseCommand(
66 command: string,
67): Promise<ParsedCommandData | null> {
68 if (!command || command.length > MAX_COMMAND_LENGTH) return null
69
70 // Gate: ant-only until pentest. External builds fall back to legacy
71 // regex/shell-quote path. Guarding the whole body inside the positive
72 // branch lets Bun DCE the NAPI import AND keeps telemetry honest — we
73 // only fire ncode_tree_sitter_load when a load was genuinely attempted.
74 if (feature('TREE_SITTER_BASH')) {
75 await ensureParserInitialized()
76 const mod = getParserModule()
77 logLoadOnce(mod !== null)
78 if (!mod) return null
79
80 try {
81 const rootNode = mod.parse(command)
82 if (!rootNode) return null
83
84 const commandNode = findCommandNode(rootNode, null)
85 const envVars = extractEnvVars(commandNode)
86
87 return { rootNode, envVars, commandNode, originalCommand: command }
88 } catch {
89 return null
90 }
91 }
92 return null
93}
94
95/**
96 * 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