Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

🔖 Checkpoint: Edit /workspaces/claude-code-flow/src/cli/simple-commands/stream-chain.js

rUv2982587bd000
diff --git a/src/cli/simple-commands/stream-chain.js b/src/cli/simple-commands/stream-chain.js
index 2ff651231f..bfc33be89f 100644
--- a/src/cli/simple-commands/stream-chain.js
+++ b/src/cli/simple-commands/stream-chain.js
@@ -36,53 +36,49 @@ function mockResponse(prompt) {
*/
async function executeClaudeCommand(prompt, timeout = 20000, useStreamJson = false) {
return new Promise((resolve) => {
- // Build command arguments array for spawn
- const args = ['-p'];
+ // For testing, let's just test Claude CLI availability first
+ if (!checkClaudeAvailable()) {
+ console.log('⚠️ Claude CLI not available, using mock response...');
+ resolve(mockResponse(prompt));
+ return;
+ }
+ // Build command string exactly like we know works
+ let command;
if (useStreamJson) {
- args.push('--output-format', 'stream-json', '--verbose');
+ command = `claude -p --output-format stream-json --verbose "${prompt.replace(/"/g, '\\"')}"`;
+ } else {
+ command = `claude -p "${prompt.replace(/"/g, '\\"')}"`;
}
- // Add the prompt as final argument
- args.push(prompt);
-
- console.log(`🔄 Executing: claude ${args.map(arg => arg.includes(' ') ? `"${arg}"` : arg).join(' ')}`);
+ console.log(`🔄 Executing: ${command}`);
const startTime = Date.now();
- // Use spawn instead of exec to handle arguments properly
- const claudeProcess = spawn('claude', args, {
- stdio: ['pipe', 'pipe', 'pipe'],
- env: process.env
- });
-
- let stdout = '';
- let stderr = '';
- let processCompleted = false;
-
- claudeProcess.stdout.on('data', (data) => {
- stdout += data.toString();
- });
-
- claudeProcess.stderr.on('data', (data) => {
- stderr += data.toString();
- });
-
- claudeProcess.on('close', (code) => {
- if (processCompleted) return;
- processCompleted = true;
-
+ // Use exec with shell=true for better compatibility
+ exec(command, {
+ timeout,
+ maxBuffer: 1024 * 1024 * 10, // 10MB buffer
+ env: process.env,
+ shell: true // Ensure shell processing
+ }, (error, stdout, stderr) => {
const duration = Date.now() - startTime;
- if (code !== 0) {
- console.error('Claude CLI error: Process exited with code', code);
- if (stderr) {
- console.error('stderr:', stderr);
+ if (error) {
+ if (error.code === 'TIMEOUT') {
+ console.log('⚠️ Claude CLI timed out, using mock response...');
+ } else {
+ console.error('Claude CLI error:', error.message);
+ if (stderr) {
+ console.error('stderr:', stderr);
+ }
}
resolve(mockResponse(prompt));
return;
}
+ // Real success case
+ console.log(`✅ Claude CLI executed successfully (${duration}ms)`);
resolve({
success: true,
duration,
@@ -91,28 +87,6 @@ async function executeClaudeCommand(prompt, timeout = 20000, useStreamJson = fal
error: stderr ? stderr.trim() : null
});
});
-
- claudeProcess.on('error', (error) => {
- if (processCompleted) return;
- processCompleted = true;
-
- console.error('Claude CLI spawn error:', error.message);
- resolve(mockResponse(prompt));
- });
-
- // Set timeout
- const timeoutId = setTimeout(() => {
- if (processCompleted) return;
- processCompleted = true;
-
- console.log('⚠️ Claude CLI timed out, using mock response...');
- claudeProcess.kill();
- resolve(mockResponse(prompt));
- }, timeout);
-
- claudeProcess.on('close', () => {
- clearTimeout(timeoutId);
- });
});
}