diff --git a/examples/bug-fixer/cli.ts b/examples/bug-fixer/cli.ts index a47b208..16514f1 100755 --- a/examples/bug-fixer/cli.ts +++ b/examples/bug-fixer/cli.ts @@ -22,6 +22,7 @@ import { showStatus, reset, sayHello, + listFilesInSrc, } from './fixer.js'; async function main() { @@ -31,6 +32,7 @@ async function main() { status: { type: 'boolean', default: false }, reset: { type: 'boolean', default: false }, help: { type: 'boolean', short: 'h', default: false }, + list: { type: 'boolean', default: false }, }, allowPositionals: true, }); @@ -45,6 +47,11 @@ async function main() { return; } + if (values.list) { + await listFilesInSrc(); + return; + } + const state = await loadState(); if (values.status) { @@ -86,6 +93,7 @@ USAGE: bun cli.ts Interactive mode bun cli.ts --status Show agent status bun cli.ts --reset Reset agent (forget everything) + bun cli.ts --list List files in src/ bun cli.ts -h, --help Show this help EXAMPLES: diff --git a/examples/bug-fixer/fixer.ts b/examples/bug-fixer/fixer.ts index 67ce74d..262edd3 100644 --- a/examples/bug-fixer/fixer.ts +++ b/examples/bug-fixer/fixer.ts @@ -147,17 +147,21 @@ export async function chat( let response = ''; const printer = onOutput || createStreamPrinter(); + let lastToolName = ''; for await (const msg of session.stream()) { if (msg.type === 'assistant') { response += msg.content; printer(msg.content); - } else if (msg.type === 'tool_call') { - // @ts-ignore - tool name might be in different places - const toolName = msg.name || msg.tool || 'tool'; - console.log(`\n${COLORS.system}[${toolName}]${COLORS.reset}`); + lastToolName = ''; // Reset after assistant output + } else if (msg.type === 'tool_call' && 'toolName' in msg) { + // Only show tool name if different from last (reduces spam) + if (msg.toolName !== lastToolName) { + console.log(`\n${COLORS.system}[${msg.toolName}]${COLORS.reset}`); + lastToolName = msg.toolName; + } } else if (msg.type === 'tool_result') { - console.log(`${COLORS.system}[done]${COLORS.reset}\n`); + // Don't print anything for tool results - cleaner output } } @@ -252,6 +256,25 @@ export function sayHello(): void { console.log('Hello'); } +/** + * List files in src/ directory + */ +export async function listFilesInSrc(): Promise { + const srcPath = '../../src'; + const fs = await import('node:fs/promises'); + + try { + const files = await fs.readdir(srcPath); + console.log('\nFiles in src/:\n'); + files.forEach((file) => { + console.log(` ${file}`); + }); + console.log(''); + } catch (error) { + console.error('Error reading src directory:', error); + } +} + /** * Reset state */ diff --git a/examples/file-organizer/organizer.ts b/examples/file-organizer/organizer.ts index b5d432f..39079ed 100644 --- a/examples/file-organizer/organizer.ts +++ b/examples/file-organizer/organizer.ts @@ -141,15 +141,18 @@ export async function chat( let response = ''; const printer = onOutput || createStreamPrinter(); + let lastToolName = ''; for await (const msg of session.stream()) { if (msg.type === 'assistant') { response += msg.content; printer(msg.content); - } else if (msg.type === 'tool_call') { - console.log(`\n${COLORS.system}[${msg.name}]${COLORS.reset}`); - } else if (msg.type === 'tool_result') { - console.log(`${COLORS.system}[done]${COLORS.reset}\n`); + lastToolName = ''; + } else if (msg.type === 'tool_call' && 'toolName' in msg) { + if (msg.toolName !== lastToolName) { + console.log(`\n${COLORS.system}[${msg.toolName}]${COLORS.reset}`); + lastToolName = msg.toolName; + } } } diff --git a/examples/release-notes/generator.ts b/examples/release-notes/generator.ts index d30242e..ad14059 100644 --- a/examples/release-notes/generator.ts +++ b/examples/release-notes/generator.ts @@ -153,15 +153,18 @@ export async function chat( let response = ''; const printer = onOutput || createStreamPrinter(); + let lastToolName = ''; for await (const msg of session.stream()) { if (msg.type === 'assistant') { response += msg.content; printer(msg.content); - } else if (msg.type === 'tool_call') { - console.log(`\n${COLORS.system}[${msg.name}]${COLORS.reset}`); - } else if (msg.type === 'tool_result') { - console.log(`${COLORS.system}[done]${COLORS.reset}\n`); + lastToolName = ''; + } else if (msg.type === 'tool_call' && 'toolName' in msg) { + if (msg.toolName !== lastToolName) { + console.log(`\n${COLORS.system}[${msg.toolName}]${COLORS.reset}`); + lastToolName = msg.toolName; + } } }