mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 22:28:10 +09:00
🚀 Fix headless mode for swarm command - Enable Claude CLI in non-interactive environments
- Move headless configuration to beginning of swarmCommand function - Fix issue where headless mode was falling back to basic executor - Ensure stream-json format is used for Claude compatibility - Clean up debug console.log statements - Support CI/CD and Docker environments with proper non-interactive flags
This commit is contained in:
1 parent
7b47b52b23
commit
7107d5fc71
140 files changed
+4096
-25220
No files matched your search
+37
-119
@@ -1,15 +1,19 @@
|
||||
/**
|
||||
* DEPRECATED: Use github-cli-safety-wrapper.js instead
|
||||
* This file is maintained for backward compatibility only
|
||||
*
|
||||
* Safe GitHub CLI command execution utilities
|
||||
* Prevents shell injection and timeout issues with special characters
|
||||
*/
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import { tmpdir } from 'os';
|
||||
import { join } from 'path';
|
||||
import { randomBytes } from 'crypto';
|
||||
import { spawn } from 'child_process';
|
||||
import {
|
||||
GitHubCliSafe,
|
||||
githubCli,
|
||||
safeGhCommand as newSafeGhCommand
|
||||
} from './github-cli-safety-wrapper.js';
|
||||
|
||||
/**
|
||||
* @deprecated Use GitHubCliSafe class from github-cli-safety-wrapper.js
|
||||
* Execute GitHub CLI command with safe body content handling
|
||||
* @param {string} command - The gh command (e.g., 'issue comment')
|
||||
* @param {string} target - Target (issue/PR number or repo)
|
||||
@@ -18,36 +22,18 @@ import { spawn } from 'child_process';
|
||||
* @returns {Promise<string>} - Command output
|
||||
*/
|
||||
export async function safeGhCommand(command, target, body, options = {}) {
|
||||
const tmpFile = join(tmpdir(), `gh-body-${randomBytes(8).toString('hex')}.tmp`);
|
||||
console.warn('safeGhCommand is deprecated. Use GitHubCliSafe from github-cli-safety-wrapper.js');
|
||||
|
||||
try {
|
||||
// Write body content to temporary file
|
||||
await fs.writeFile(tmpFile, body, 'utf8');
|
||||
|
||||
// Build command arguments
|
||||
const args = command.split(' ');
|
||||
args.push(target);
|
||||
args.push('--body-file', tmpFile);
|
||||
|
||||
// Add any additional options
|
||||
Object.entries(options).forEach(([key, value]) => {
|
||||
args.push(`--${key}`, value);
|
||||
});
|
||||
|
||||
// Execute command with timeout
|
||||
const result = await executeWithTimeout('gh', args, options.timeout || 30000);
|
||||
return result;
|
||||
} finally {
|
||||
// Clean up temp file
|
||||
try {
|
||||
await fs.unlink(tmpFile);
|
||||
} catch (err) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
const result = await newSafeGhCommand(command, target, body, options);
|
||||
return result.stdout;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This function is deprecated and will be removed
|
||||
* Execute command with timeout and proper cleanup
|
||||
* @param {string} command - Command to execute
|
||||
* @param {string[]} args - Command arguments
|
||||
@@ -55,132 +41,64 @@ export async function safeGhCommand(command, target, body, options = {}) {
|
||||
* @returns {Promise<string>} - Command output
|
||||
*/
|
||||
function executeWithTimeout(command, args, timeout) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(command, args, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
shell: false, // Important: don't use shell
|
||||
});
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
let timedOut = false;
|
||||
|
||||
// Set timeout
|
||||
const timer = setTimeout(() => {
|
||||
timedOut = true;
|
||||
child.kill('SIGTERM');
|
||||
setTimeout(() => child.kill('SIGKILL'), 5000); // Force kill after 5s
|
||||
}, timeout);
|
||||
|
||||
child.stdout.on('data', (data) => {
|
||||
stdout += data.toString();
|
||||
});
|
||||
|
||||
child.stderr.on('data', (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
|
||||
child.on('close', (code) => {
|
||||
clearTimeout(timer);
|
||||
|
||||
if (timedOut) {
|
||||
reject(new Error(`Command timed out after ${timeout}ms`));
|
||||
} else if (code !== 0) {
|
||||
reject(new Error(`Command failed with exit code ${code}: ${stderr}`));
|
||||
} else {
|
||||
resolve(stdout.trim());
|
||||
}
|
||||
});
|
||||
|
||||
child.on('error', (err) => {
|
||||
clearTimeout(timer);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
console.warn('executeWithTimeout is deprecated. Use GitHubCliSafe.executeWithTimeout instead');
|
||||
|
||||
// Forward to new implementation via GitHubCliSafe
|
||||
const ghSafe = new GitHubCliSafe({ timeout });
|
||||
return ghSafe.executeWithTimeout(command.replace('gh ', ''), args.slice(1), { timeout });
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use gh object from github-cli-safety-wrapper.js
|
||||
* Safe methods for common GitHub CLI operations
|
||||
*/
|
||||
export const gh = {
|
||||
/**
|
||||
* @deprecated Use githubCli.addIssueComment instead
|
||||
* Create issue comment safely
|
||||
* @param {number|string} issue - Issue number
|
||||
* @param {string} body - Comment body
|
||||
* @param {Object} options - Additional options
|
||||
*/
|
||||
async issueComment(issue, body, options = {}) {
|
||||
return safeGhCommand('issue comment', issue.toString(), body, options);
|
||||
console.warn('gh.issueComment is deprecated. Use githubCli.addIssueComment instead');
|
||||
const result = await githubCli.addIssueComment(issue, body, options);
|
||||
return result.stdout;
|
||||
},
|
||||
|
||||
/**
|
||||
* @deprecated Use githubCli.addPRComment instead
|
||||
* Create PR comment safely
|
||||
* @param {number|string} pr - PR number
|
||||
* @param {string} body - Comment body
|
||||
* @param {Object} options - Additional options
|
||||
*/
|
||||
async prComment(pr, body, options = {}) {
|
||||
return safeGhCommand('pr comment', pr.toString(), body, options);
|
||||
console.warn('gh.prComment is deprecated. Use githubCli.addPRComment instead');
|
||||
const result = await githubCli.addPRComment(pr, body, options);
|
||||
return result.stdout;
|
||||
},
|
||||
|
||||
/**
|
||||
* @deprecated Use githubCli.createIssue instead
|
||||
* Create issue safely
|
||||
* @param {Object} params - Issue parameters
|
||||
*/
|
||||
async createIssue({ title, body, labels = [], assignees = [] }) {
|
||||
const tmpFile = join(tmpdir(), `gh-issue-${randomBytes(8).toString('hex')}.tmp`);
|
||||
|
||||
try {
|
||||
await fs.writeFile(tmpFile, body, 'utf8');
|
||||
|
||||
const args = ['issue', 'create', '--title', title, '--body-file', tmpFile];
|
||||
|
||||
if (labels.length > 0) {
|
||||
args.push('--label', labels.join(','));
|
||||
}
|
||||
|
||||
if (assignees.length > 0) {
|
||||
args.push('--assignee', assignees.join(','));
|
||||
}
|
||||
|
||||
return await executeWithTimeout('gh', args, 30000);
|
||||
} finally {
|
||||
try {
|
||||
await fs.unlink(tmpFile);
|
||||
} catch (err) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
}
|
||||
console.warn('gh.createIssue is deprecated. Use githubCli.createIssue instead');
|
||||
const result = await githubCli.createIssue({ title, body, labels, assignees });
|
||||
return result.stdout;
|
||||
},
|
||||
|
||||
/**
|
||||
* @deprecated Use githubCli.createPR instead
|
||||
* Create PR safely
|
||||
* @param {Object} params - PR parameters
|
||||
*/
|
||||
async createPR({ title, body, base = 'main', head, draft = false }) {
|
||||
const tmpFile = join(tmpdir(), `gh-pr-${randomBytes(8).toString('hex')}.tmp`);
|
||||
|
||||
try {
|
||||
await fs.writeFile(tmpFile, body, 'utf8');
|
||||
|
||||
const args = ['pr', 'create', '--title', title, '--body-file', tmpFile, '--base', base];
|
||||
|
||||
if (head) {
|
||||
args.push('--head', head);
|
||||
}
|
||||
|
||||
if (draft) {
|
||||
args.push('--draft');
|
||||
}
|
||||
|
||||
return await executeWithTimeout('gh', args, 30000);
|
||||
} finally {
|
||||
try {
|
||||
await fs.unlink(tmpFile);
|
||||
} catch (err) {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
}
|
||||
console.warn('gh.createPR is deprecated. Use githubCli.createPR instead');
|
||||
const result = await githubCli.createPR({ title, body, base, head, draft });
|
||||
return result.stdout;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user