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

Function extractBashToolsFromMessages

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

Source from the content-addressed store, hash-verified

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

Callers 1

REPLFunction · 0.85

Calls 2

extractCliNameFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected