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: File edits

rUv64e895090f3c
diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json
index afb243147c..ac3f444378 100644
--- a/v3/@claude-flow/cli/package.json
+++ b/v3/@claude-flow/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/cli",
- "version": "3.0.0-alpha.19",
+ "version": "3.0.0-alpha.20",
"type": "module",
"description": "CLI module - command parsing, prompts, output formatting",
"main": "dist/src/index.js",
diff --git a/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts b/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
index c3eec81b69..e0b22b9334 100644
--- a/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
+++ b/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
@@ -352,53 +352,153 @@ export interface DiffAnalysisResult {
recommendedReviewers?: string[];
}
+// ============================================================================
+// Optimized Git Diff Functions
+// ============================================================================
+
+// Cache for diff results (TTL-based)
+const diffCache = new Map<string, { files: DiffFile[]; timestamp: number }>();
+const CACHE_TTL_MS = 5000; // 5 seconds - short TTL since diffs change frequently
+
/**
- * Get git diff statistics using numstat
+ * Get git diff statistics using SINGLE combined command (optimized)
+ * Replaces two separate git commands with one
*/
export function getGitDiffNumstat(ref: string = 'HEAD'): DiffFile[] {
+ // Check cache first
+ const cacheKey = `numstat:${ref}`;
+ const cached = diffCache.get(cacheKey);
+ if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
+ return cached.files;
+ }
+
const { execSync } = require('child_process');
try {
- const output = execSync(`git diff --numstat ${ref}`, { encoding: 'utf-8' });
- const statusOutput = execSync(`git diff --name-status ${ref}`, { encoding: 'utf-8' });
+ // OPTIMIZATION: Single combined command instead of two separate calls
+ // Uses --diff-filter to get status and --numstat in one pass
+ const output = execSync(
+ `git diff --numstat --diff-filter=ACDMRTUXB ${ref} && echo "---STATUS---" && git diff --name-status ${ref}`,
+ { encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 } // 10MB buffer for large diffs
+ );
+
+ const [numstatPart, statusPart] = output.split('---STATUS---');
+ // Parse status (usually smaller, parse first)
const statusMap = new Map<string, string>();
- for (const line of statusOutput.trim().split('\n')) {
- if (!line) continue;
- const [status, ...pathParts] = line.split('\t');
- const path = pathParts[pathParts.length - 1] || pathParts[0];
- if (path) {
- statusMap.set(path, status.charAt(0));
+ if (statusPart) {
+ for (const line of statusPart.trim().split('\n')) {
+ if (!line) continue;
+ const [status, ...pathParts] = line.split('\t');
+ const path = pathParts[pathParts.length - 1] || pathParts[0];
+ if (path) statusMap.set(path, status.charAt(0));
}
}
+ // Parse numstat
const files: DiffFile[] = [];
- for (const line of output.trim().split('\n')) {
- if (!line) continue;
- const [addStr, delStr, path] = line.split('\t');
- if (!path) continue;
-
- const additions = addStr === '-' ? 0 : parseInt(addStr, 10) || 0;
- const deletions = delStr === '-' ? 0 : parseInt(delStr, 10) || 0;
- const binary = addStr === '-' && delStr === '-';
-
- const statusChar = statusMap.get(path) || 'M';
- let status: DiffFile['status'] = 'modified';
- switch (statusChar) {
- case 'A': status = 'added'; break;
- case 'D': status = 'deleted'; break;
- case 'R': status = 'renamed'; break;
- default: status = 'modified';
+ if (numstatPart) {
+ for (const line of numstatPart.trim().split('\n')) {
+ if (!line) continue;
+ const [addStr, delStr, path] = line.split('\t');
+ if (!path) continue;
+
+ const additions = addStr === '-' ? 0 : parseInt(addStr, 10) || 0;
+ const deletions = delStr === '-' ? 0 : parseInt(delStr, 10) || 0;
+ const binary = addStr === '-' && delStr === '-';
+
+ const statusChar = statusMap.get(path) || 'M';
+ let status: DiffFile['status'] = 'modified';
+ switch (statusChar) {
+ case 'A': status = 'added'; break;
+ case 'D': status = 'deleted'; break;
+ case 'R': status = 'renamed'; break;
+ default: status = 'modified';
+ }
+
+ files.push({ path, status, additions, deletions, hunks: 1, binary });
}
+ }
+
+ // Cache the result
+ diffCache.set(cacheKey, { files, timestamp: Date.now() });
- files.push({ path, status, additions, deletions, hunks: 1, binary });
+ return files;
+ } catch {
+ return [];
+ }
+}
+
+/**
+ * Async version of getGitDiffNumstat for non-blocking operation
+ */
+export async function getGitDiffNumstatAsync(ref: string = 'HEAD'): Promise<DiffFile[]> {
+ // Check cache first
+ const cacheKey = `numstat:${ref}`;
+ const cached = diffCache.get(cacheKey);
+ if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
+ return cached.files;
+ }
+
+ const { exec } = require('child_process');
+ const { promisify } = require('util');
+ const execAsync = promisify(exec);
+
+ try {
+ const { stdout } = await execAsync(
+ `git diff --numstat --diff-filter=ACDMRTUXB ${ref} && echo "---STATUS---" && git diff --name-status ${ref}`,
+ { maxBuffer: 10 * 1024 * 1024 }
+ );
+
+ const [numstatPart, statusPart] = stdout.split('---STATUS---');
+
+ const statusMap = new Map<string, string>();
+ if (statusPart) {
+ for (const line of statusPart.trim().split('\n')) {
+ if (!line) continue;
+ const [status, ...pathParts] = line.split('\t');
+ const path = pathParts[pathParts.length - 1] || pathParts[0];
+ if (path) statusMap.set(path, status.charAt(0));
+ }
}
+ const files: DiffFile[] = [];
+ if (numstatPart) {
+ for (const line of numstatPart.trim().split('\n')) {
+ if (!line) continue;
+ const [addStr, delStr, path] = line.split('\t');
+ if (!path) continue;
+
+ const additions = addStr === '-' ? 0 : parseInt(addStr, 10) || 0;
+ const deletions = delStr === '-' ? 0 : parseInt(delStr, 10) || 0;
+ const binary = addStr === '-' && delStr === '-';
+
+ const statusChar = statusMap.get(path) || 'M';
+ let status: DiffFile['status'] = 'modified';
+ switch (statusChar) {
+ case 'A': status = 'added'; break;
+ case 'D': status = 'deleted'; break;
+ case 'R': status = 'renamed'; break;
+ default: status = 'modified';
+ }
+
+ files.push({ path, status, additions, deletions, hunks: 1, binary });
+ }
+ }
+
+ diffCache.set(cacheKey, { files, timestamp: Date.now() });
return files;
} catch {
return [];
}
}
+/**
+ * Clear the diff cache (call when git state changes)
+ */
+export function clearDiffCache(): void {
+ diffCache.clear();
+}
+
/**
* Assess risk for a single file
*/
diff --git a/v3/package-lock.json b/v3/package-lock.json
index b11828a084..4c4dc9be3e 100644
--- a/v3/package-lock.json
+++ b/v3/package-lock.json
@@ -121,7 +121,7 @@
}
},
"@claude-flow/cli": {
- "version": "3.0.0-alpha.19",
+ "version": "3.0.0-alpha.20",
"dependencies": {
"@claude-flow/shared": "^3.0.0-alpha.1"
},