| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- /**
- * Multi-Agent Logging System - Formatters
- *
- * Visual formatting utilities for pretty-printing delegation hierarchies.
- */
- /**
- * Format a session header with box drawing
- */
- export function formatSessionHeader(
- sessionId: string,
- agent: string,
- depth: number,
- parentId?: string
- ): string {
- const indent = ' '.repeat(depth);
- const type = depth === 0 ? 'PARENT' : 'CHILD';
- const shortId = sessionId.substring(0, 12);
- const boxWidth = 60;
-
- let header = `\n${indent}┌${'─'.repeat(boxWidth)}┐\n`;
- header += `${indent}│ 🎯 ${type}: ${agent} (${shortId}...)`;
-
- // Pad to box width
- const contentLength = ` 🎯 ${type}: ${agent} (${shortId}...)`.length;
- const padding = boxWidth - contentLength;
- header += ' '.repeat(Math.max(0, padding)) + '│\n';
-
- if (parentId) {
- const shortParent = parentId.substring(0, 12);
- header += `${indent}│ Parent: ${shortParent}...`;
- const parentLineLength = ` Parent: ${shortParent}...`.length;
- const parentPadding = boxWidth - parentLineLength;
- header += ' '.repeat(Math.max(0, parentPadding)) + '│\n';
-
- header += `${indent}│ Depth: ${depth}`;
- const depthLineLength = ` Depth: ${depth}`.length;
- const depthPadding = boxWidth - depthLineLength;
- header += ' '.repeat(Math.max(0, depthPadding)) + '│\n';
- }
-
- header += `${indent}└${'─'.repeat(boxWidth)}┘`;
-
- return header;
- }
- /**
- * Format a message with emoji and indentation
- */
- export function formatMessage(
- role: 'user' | 'assistant',
- text: string,
- depth: number
- ): string {
- const indent = ' '.repeat(depth + 1);
- const emoji = role === 'user' ? '📝' : '🤖';
- const label = role === 'user' ? 'User' : 'Agent';
-
- // Truncate long messages
- const maxLength = 80;
- const displayText = text.length > maxLength
- ? text.substring(0, maxLength) + '...'
- : text;
-
- return `${indent}${emoji} ${label}: ${displayText}`;
- }
- /**
- * Format a tool call with indentation
- */
- export function formatToolCall(
- tool: string,
- input: any,
- depth: number
- ): string {
- const indent = ' '.repeat(depth + 1);
-
- let output = `${indent}🔧 TOOL: ${tool}`;
-
- // Add relevant input details
- if (input?.filePath) {
- output += `\n${indent} └─ file: ${input.filePath}`;
- } else if (input?.pattern) {
- output += `\n${indent} └─ pattern: ${input.pattern}`;
- } else if (input?.command) {
- const cmd = input.command.substring(0, 50);
- output += `\n${indent} └─ command: ${cmd}${input.command.length > 50 ? '...' : ''}`;
- }
-
- return output;
- }
- /**
- * Format a delegation event
- */
- export function formatDelegation(
- toAgent: string,
- prompt: string,
- depth: number
- ): string {
- const indent = ' '.repeat(depth + 1);
-
- // Truncate long prompts
- const maxLength = 50;
- const displayPrompt = prompt.length > maxLength
- ? prompt.substring(0, maxLength) + '...'
- : prompt;
-
- let output = `\n${indent}🔧 TOOL: task\n`;
- output += `${indent} ├─ subagent: ${toAgent}\n`;
- output += `${indent} ├─ prompt: ${displayPrompt}\n`;
- output += `${indent} └─ Creating child session...`;
-
- return output;
- }
- /**
- * Format child session linked message
- */
- export function formatChildLinked(
- childSessionId: string,
- depth: number,
- verbose: boolean = false
- ): string {
- if (verbose) {
- // Verbose mode: show full details with indentation
- const indent = ' '.repeat(depth + 1);
- const shortId = childSessionId.substring(0, 12);
- return `${indent} └─ Child session: ${shortId}...`;
- } else {
- // Non-verbose mode: show concise message
- const shortId = childSessionId.substring(0, 12);
- return ` → Child agent started (session: ${shortId}...)`;
- }
- }
- /**
- * Format session completion
- */
- export function formatSessionComplete(
- sessionType: 'PARENT' | 'CHILD',
- duration: number,
- depth: number,
- agent?: string,
- verbose: boolean = false
- ): string {
- if (verbose) {
- // Verbose mode: show full details with indentation
- const indent = ' '.repeat(depth);
- const durationSec = (duration / 1000).toFixed(1);
- return `${indent}✅ ${sessionType} COMPLETE (${durationSec}s)\n`;
- } else {
- // Non-verbose mode: show concise message for child sessions only
- const durationSec = (duration / 1000).toFixed(1);
- const agentName = agent || 'child agent';
- return ` ✓ Child agent completed (${agentName}, ${durationSec}s)`;
- }
- }
- /**
- * Format a system message
- */
- export function formatSystemMessage(
- message: string,
- depth: number
- ): string {
- const indent = ' '.repeat(depth + 1);
- return `${indent}ℹ️ ${message}`;
- }
|