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

Function getFirstWordPrefix

src/tools/BashTool/bashPermissions.ts:244–265  ·  view source on GitHub ↗
(command: string)

Source from the content-addressed store, hash-verified

242 * because stripSafeWrappers won't strip RUN.
243 */
244export function getFirstWordPrefix(command: string): string | null {
245 const tokens = command.trim().split(/\s+/).filter(Boolean)
246
247 let i = 0
248 while (i < tokens.length && ENV_VAR_ASSIGN_RE.test(tokens[i]!)) {
249 const varName = tokens[i]!.split('=')[0]!
250 const isAntOnlySafe =
251 isInternalBuild() && ANT_ONLY_SAFE_ENV_VARS.has(varName)
252 if (!SAFE_ENV_VARS.has(varName) && !isAntOnlySafe) {
253 return null
254 }
255 i++
256 }
257
258 const cmd = tokens[i]
259 if (!cmd) return null
260 // Same shape check as the subcommand regex in getSimpleCommandPrefix:
261 // rejects paths (./script.sh, /usr/bin/python), flags, numbers, filenames.
262 if (!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(cmd)) return null
263 if (BARE_SHELL_PREFIXES.has(cmd)) return null
264 return cmd
265}
266
267function suggestionForExactCommand(command: string): PermissionUpdate[] {
268 // Heredoc commands contain multi-line content that changes each invocation,

Callers 1

Calls 2

isInternalBuildFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected