🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
🔖 Checkpoint: Edit /workspaces/claude-code-flow/src/cli/simple-commands/stream-processor.js
rUv253647d5bed5
diff --git a/.claude/checkpoints/task-1754338920.json b/.claude/checkpoints/task-1754338920.jsonnew file mode 100644index 0000000000..c33d807476--- /dev/null+++ b/.claude/checkpoints/task-1754338920.json@@ -0,0 +1 @@+{"checkpoint": "task-20250804-202159", "task": "{{user_prompt}} ", "timestamp": "2025-08-04T20:22:00Z", "commit": "4944d536cfc8c71331e8c305822dc17007edd1d6", "github_release": "true"}diff --git a/src/cli/simple-commands/stream-processor.js b/src/cli/simple-commands/stream-processor.jsnew file mode 100644index 0000000000..35b4649fed--- /dev/null+++ b/src/cli/simple-commands/stream-processor.js@@ -0,0 +1,169 @@+/**+ * Stream processor for Claude stream-json output+ * Provides real-time status updates and progress tracking+ */++import { Transform } from 'stream';++export class StreamJsonProcessor extends Transform {+ constructor(options = {}) {+ super({ objectMode: false });+ this.buffer = '';+ this.agentName = options.agentName || 'Agent';+ this.agentIcon = options.agentIcon || '🤖';+ this.taskId = options.taskId || 'unknown';+ this.startTime = Date.now();+ this.eventCount = 0;+ this.lastUpdate = Date.now();+ this.options = options;+ }++ _transform(chunk, encoding, callback) {+ this.buffer += chunk.toString();+ const lines = this.buffer.split('\n');+ this.buffer = lines.pop() || '';++ for (const line of lines) {+ if (line.trim()) {+ try {+ const event = JSON.parse(line);+ this.processEvent(event);+ } catch (e) {+ // Not JSON, pass through if in verbose mode+ if (this.options.verbose) {+ console.log(`[${this.agentName}] ${line}`);+ }+ }+ }+ }++ // Update progress display periodically+ if (Date.now() - this.lastUpdate > 1000) {+ this.updateProgress();+ this.lastUpdate = Date.now();+ }++ callback();+ }++ _flush(callback) {+ if (this.buffer.trim()) {+ try {+ const event = JSON.parse(this.buffer);+ this.processEvent(event);+ } catch (e) {+ // Ignore+ }+ }+ this.showFinalStatus();+ callback();+ }++ processEvent(event) {+ this.eventCount++;++ // Clear previous line and move cursor up+ if (!this.options.verbose) {+ process.stdout.write('\r\x1B[K'); // Clear current line+ }++ const elapsed = this.formatDuration(Date.now() - this.startTime);+ const spinner = this.getSpinner();++ switch (event.type) {+ case 'system':+ if (event.subtype === 'init') {+ console.log(` ${this.agentIcon} ${this.agentName} initialized [Session: ${event.session_id?.substring(0, 8)}]`);+ }+ break;++ case 'assistant':+ if (event.message?.content?.length > 0) {+ const content = event.message.content[0];+ if (content.type === 'text') {+ const preview = content.text.substring(0, 60) + (content.text.length > 60 ? '...' : '');+ console.log(` ${spinner} ${this.agentName}: ${preview}`);+ } else if (content.type === 'tool_use') {+ console.log(` 🔧 ${this.agentName}: Using ${content.name} tool`);+ }+ }+ break;++ case 'user':+ // Tool results - usually indicates progress+ if (event.message?.content?.[0]?.type === 'tool_result') {+ const result = event.message.content[0];+ if (!result.is_error) {+ console.log(` ✓ Tool completed successfully`);+ }+ }+ break;++ case 'result':+ if (event.subtype === 'success') {+ console.log(` ✅ ${this.agentName} completed in ${this.formatDuration(event.duration_ms)}`);+ if (event.total_cost_usd) {+ console.log(` 💰 Cost: $${event.total_cost_usd.toFixed(4)}`);+ }+ } else if (event.is_error) {+ console.log(` ❌ ${this.agentName} failed: ${event.error || 'Unknown error'}`);+ }+ break;++ default:+ if (this.options.verbose) {+ console.log(` [${event.type}] ${JSON.stringify(event).substring(0, 100)}...`);+ }+ }++ // Show running status+ if (this.eventCount % 5 === 0 && event.type !== 'result') {+ this.updateProgress();+ }+ }++ updateProgress() {+ const elapsed = this.formatDuration(Date.now() - this.startTime);+ const spinner = this.getSpinner();+ const progress = this.getProgressBar(Date.now() - this.startTime, 60000);++ process.stdout.write(`\r ${spinner} ${this.agentName} ${progress} ${elapsed} | Events: ${this.eventCount}`);+ }++ showFinalStatus() {+ const elapsed = this.formatDuration(Date.now() - this.startTime);+ console.log(`\n 📊 ${this.agentName} processed ${this.eventCount} events in ${elapsed}`);+ }++ getSpinner() {+ const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];+ return frames[Math.floor(Date.now() / 100) % frames.length];+ }++ getProgressBar(elapsed, expected) {+ const progress = Math.min(elapsed / expected, 1);+ const filled = Math.floor(progress * 10);+ const empty = 10 - filled;+ return '[' + '█'.repeat(filled) + '░'.repeat(empty) + ']';+ }++ formatDuration(ms) {+ const seconds = Math.floor(ms / 1000);+ const minutes = Math.floor(seconds / 60);+ if (minutes > 0) {+ return `${minutes}m ${seconds % 60}s`;+ }+ return `${seconds}s`;+ }+}++/**+ * Create a stream processor for an agent+ */+export function createStreamProcessor(agentName, agentIcon, options = {}) {+ return new StreamJsonProcessor({+ agentName,+ agentIcon,+ ...options+ });+}\ No newline at end of file