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