pm-orchestrator-enhancement
Version:
PM Orchestrator Enhancement - Multi-agent parallel execution system
118 lines (117 loc) • 3.45 kB
JavaScript
;
/**
* Tool Visualizer Module
*
* Read、Edit、Bash等のツール呼び出しを可視化します。
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolVisualizer = void 0;
const color_code_1 = require("./color-code");
class ToolVisualizer {
constructor() {
this.toolCalls = [];
}
/**
* ツール呼び出しを記録
*/
recordToolCall(tool, description) {
this.toolCalls.push({
tool,
description,
timestamp: new Date()
});
}
/**
* ツール呼び出しの結果を記録
*/
recordToolResult(result, output) {
const lastCall = this.toolCalls[this.toolCalls.length - 1];
if (lastCall) {
lastCall.result = result;
lastCall.output = output;
}
}
/**
* ツール呼び出しを表示
*/
displayToolCall(toolCall) {
const header = color_code_1.ColorCode.formatToolCall(toolCall.tool, toolCall.description);
if (!toolCall.result) {
return header;
}
const resultIcon = toolCall.result === 'success' ? '✅' : '❌';
const resultColor = toolCall.result === 'success' ? '\x1b[32m' : '\x1b[31m';
const resultText = `${resultColor}${resultIcon} ${toolCall.result}${color_code_1.AgentColor.RESET}`;
let output = `${header}\n ${resultText}`;
if (toolCall.output) {
const preview = this.truncateOutput(toolCall.output);
output += `\n Output: ${preview}`;
}
return output;
}
/**
* 全てのツール呼び出しを表示
*/
displayAll() {
if (this.toolCalls.length === 0) {
return 'No tool calls recorded.';
}
const lines = this.toolCalls.map(call => this.displayToolCall(call));
return lines.join('\n\n');
}
/**
* ツール呼び出しのサマリーを表示
*/
displaySummary() {
const total = this.toolCalls.length;
const successful = this.toolCalls.filter(c => c.result === 'success').length;
const failed = this.toolCalls.filter(c => c.result === 'error').length;
const toolCounts = this.countToolUsage();
const topTools = Object.entries(toolCounts)
.sort((a, b) => b[1] - a[1])
.slice(0, 5)
.map(([tool, count]) => ` - ${tool}: ${count}`)
.join('\n');
return `
Tool Call Summary:
Total: ${total}
Successful: ${successful}
Failed: ${failed}
Top Tools:
${topTools}
`.trim();
}
/**
* ツール使用頻度をカウント
*/
countToolUsage() {
const counts = {};
for (const call of this.toolCalls) {
counts[call.tool] = (counts[call.tool] || 0) + 1;
}
return counts;
}
/**
* 出力を切り詰める
*/
truncateOutput(output, maxLength = 100) {
if (output.length <= maxLength) {
return output;
}
return `${output.substring(0, maxLength)}... (${output.length} chars total)`;
}
/**
* ツール呼び出し履歴をクリア
*/
clear() {
this.toolCalls = [];
}
/**
* ツール呼び出し履歴を取得
*/
getToolCalls() {
return [...this.toolCalls];
}
}
exports.ToolVisualizer = ToolVisualizer;
//# sourceMappingURL=tool-visualizer.js.map