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

Function extractBashToolsFromMessages

src/utils/queryHelpers.ts:502–529  ·  view source on GitHub ↗
(messages: Message[])

Source from the content-addressed store, hash-verified

500 * Returns a deduplicated set of command names (e.g. 'vercel', 'aws', 'git').
501 */
502export function extractBashToolsFromMessages(messages: Message[]): Set<string> {
503 const tools = new Set<string>()
504 for (const message of messages) {
505 if (
506 message.type === 'assistant' &&
507 Array.isArray(message.message.content)
508 ) {
509 for (const content of message.message.content) {
510 if (content.type === 'tool_use' && content.name === BASH_TOOL_NAME) {
511 const { input } = content
512 if (
513 typeof input !== 'object' ||
514 input === null ||
515 !('command' in input)
516 )
517 continue
518 const cmd = extractCliName(
519 typeof input.command === 'string' ? input.command : undefined,
520 )
521 if (cmd) {
522 tools.add(cmd)
523 }
524 }
525 }
526 }
527 }
528 return tools
529}
530
531const STRIPPED_COMMANDS = new Set(['sudo'])
532

Callers 1

REPLFunction · 0.85

Calls 2

extractCliNameFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected