From 61ff3f00f7185916d9ef47ba127b1102fbb98bd3 Mon Sep 17 00:00:00 2001 From: rUv Date: Mon, 4 Aug 2025 19:21:06 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20Checkpoint:=20Edit=20/workspaces?= =?UTF-8?q?/claude-code-flow/src/cli/simple-commands/automation-executor.j?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/checkpoints/1754335216.json | 1 + .claude/checkpoints/1754335218.json | 1 + .../simple-commands/automation-executor.js | 175 ++++++++++++++---- 3 files changed, 138 insertions(+), 39 deletions(-) create mode 100644 .claude/checkpoints/1754335216.json create mode 100644 .claude/checkpoints/1754335218.json diff --git a/.claude/checkpoints/1754335216.json b/.claude/checkpoints/1754335216.json new file mode 100644 index 0000000000..de0a5530d3 --- /dev/null +++ b/.claude/checkpoints/1754335216.json @@ -0,0 +1 @@ +{"branch": "checkpoint/pre-edit-20250804-192016", "file": "/workspaces/claude-code-flow/hello-world-test.json", "timestamp": "2025-08-04T19:20:16Z", "type": "pre-edit", "original_branch": "alpha-85"} diff --git a/.claude/checkpoints/1754335218.json b/.claude/checkpoints/1754335218.json new file mode 100644 index 0000000000..2f49a31bee --- /dev/null +++ b/.claude/checkpoints/1754335218.json @@ -0,0 +1 @@ +{"tag": "checkpoint-20250804-192018", "file": "/workspaces/claude-code-flow/hello-world-test.json", "timestamp": "2025-08-04T19:20:18Z", "type": "post-edit", "branch": "alpha-85", "diff_summary": " .claude-flow/metrics/performance.json | 2 +- .claude-flow/metrics/system-metrics.json | 36 ++++++++++++++++++++++++++++ .claude-flow/metrics/task-metrics.json | 6 ++--- .claude/checkpoints/1754335177.json | 1 + .claude/checkpoints/1754335178.json | 1 + claude-flow-wiki | 0 hello-world-test.json | 41 ++++++++++++++++++++++++++++++++ 7 files changed, 83 insertions(+), 4 deletions(-) "} diff --git a/src/cli/simple-commands/automation-executor.js b/src/cli/simple-commands/automation-executor.js index 31b76130da..806ca1422a 100644 --- a/src/cli/simple-commands/automation-executor.js +++ b/src/cli/simple-commands/automation-executor.js @@ -525,26 +525,19 @@ Execute your role in the MLE-STAR workflow with full coordination and hook integ }); } - // Simulate task execution for now - // In a full implementation, this would: - // 1. Assign task to appropriate Claude instance - // 2. Monitor execution progress - // 3. Handle task communication and coordination - // 4. Collect and validate results - console.log(` 🔄 Executing: ${task.description}`); - // Simulate variable execution time based on task timeout - const executionTime = Math.min( - 1000 + Math.random() * 3000, // 1-4 seconds simulation - task.timeout || 30000 - ); - - await new Promise(resolve => setTimeout(resolve, executionTime)); - // For demonstration/testing mode (when Claude integration is disabled) // we simulate successful task completion if (!this.options.enableClaude) { + // Simulate variable execution time + const executionTime = Math.min( + 1000 + Math.random() * 3000, // 1-4 seconds simulation + task.timeout || 30000 + ); + + await new Promise(resolve => setTimeout(resolve, executionTime)); + // Simulate successful completion for demo/testing const result = { success: true, @@ -572,33 +565,137 @@ Execute your role in the MLE-STAR workflow with full coordination and hook integ // When Claude integration is enabled, delegate to actual Claude instance const claudeInstance = this.claudeInstances.get(task.assignTo); if (!claudeInstance) { - throw new Error(`No Claude instance found for agent: ${task.assignTo}`); - } - - // In a full implementation, this would communicate with the Claude instance - // For now, return success as the framework is working - const result = { - success: true, - taskId: task.id, - duration: Date.now() - startTime, - output: { - status: 'completed', - agent: task.assignTo, - executionTime: Date.now() - startTime, - metadata: { - timestamp: new Date().toISOString(), - executionId: this.executionId, - mode: 'claude-integration' + // If no pre-spawned instance, create one for this task + const agent = workflow.agents.find(a => a.id === task.assignTo); + if (!agent) { + throw new Error(`No agent definition found for: ${task.assignTo}`); + } + + // Create task-specific prompt + const taskPrompt = this.createTaskPrompt(task, agent, workflow); + + // Spawn Claude instance for this specific task + const taskClaudeProcess = await this.spawnClaudeInstance(agent, taskPrompt); + + // Store the instance + this.claudeInstances.set(agent.id, { + process: taskClaudeProcess, + agent: agent, + status: 'active', + startTime: Date.now(), + taskId: task.id + }); + + // Wait for task completion or timeout + const timeout = task.timeout || this.options.timeout || 60000; + + const completionPromise = new Promise((resolve, reject) => { + taskClaudeProcess.on('exit', (code) => { + if (code === 0) { + resolve({ success: true, code }); + } else { + reject(new Error(`Process exited with code ${code}`)); + } + }); + + taskClaudeProcess.on('error', (err) => { + reject(err); + }); + }); + + const timeoutPromise = new Promise((_, reject) => { + setTimeout(() => reject(new Error('Task timeout')), timeout); + }); + + try { + await Promise.race([completionPromise, timeoutPromise]); + + const result = { + success: true, + taskId: task.id, + duration: Date.now() - startTime, + output: { + status: 'completed', + agent: task.assignTo, + executionTime: Date.now() - startTime, + metadata: { + timestamp: new Date().toISOString(), + executionId: this.executionId, + mode: 'claude-task-execution' + } + } + }; + + // Store result in memory + if (this.hooksEnabled) { + await this.storeTaskResult(task.id, result.output); } + + return result; + } catch (error) { + throw error; + } + } else { + // Use existing Claude instance + // In a full implementation, this would send the task to the running instance + // For now, we'll spawn a new instance per task for simplicity + + const agent = claudeInstance.agent; + const taskPrompt = this.createTaskPrompt(task, agent, workflow); + + // For now, spawn a new instance for each task + const taskClaudeProcess = await this.spawnClaudeInstance(agent, taskPrompt); + + // Wait for completion + const timeout = task.timeout || this.options.timeout || 60000; + + const completionPromise = new Promise((resolve, reject) => { + taskClaudeProcess.on('exit', (code) => { + if (code === 0) { + resolve({ success: true, code }); + } else { + reject(new Error(`Process exited with code ${code}`)); + } + }); + + taskClaudeProcess.on('error', (err) => { + reject(err); + }); + }); + + const timeoutPromise = new Promise((_, reject) => { + setTimeout(() => reject(new Error('Task timeout')), timeout); + }); + + try { + await Promise.race([completionPromise, timeoutPromise]); + + const result = { + success: true, + taskId: task.id, + duration: Date.now() - startTime, + output: { + status: 'completed', + agent: task.assignTo, + executionTime: Date.now() - startTime, + metadata: { + timestamp: new Date().toISOString(), + executionId: this.executionId, + mode: 'claude-task-execution' + } + } + }; + + // Store result in memory + if (this.hooksEnabled) { + await this.storeTaskResult(task.id, result.output); + } + + return result; + } catch (error) { + throw error; } - }; - - // Store result in memory - if (this.hooksEnabled) { - await this.storeTaskResult(task.id, result.output); } - - return result; } } catch (error) {