(messages: Message[])
| 505 | * Returns a deduplicated set of command names (e.g. 'vercel', 'aws', 'git'). |
| 506 | */ |
| 507 | export 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 | |
| 536 | const STRIPPED_COMMANDS = new Set(['sudo']) |
| 537 |
no test coverage detected