MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / parseCommand

Function parseCommand

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

Source from the content-addressed store, hash-verified

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