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/verification-hooks.js

rUv3cb0ce569f44
diff --git a/.claude/checkpoints/1755013808.json b/.claude/checkpoints/1755013808.json
new file mode 100644
index 0000000000..a78e41983a
--- /dev/null
+++ b/.claude/checkpoints/1755013808.json
@@ -0,0 +1 @@
+{"branch": "checkpoint/pre-edit-20250812-155008", "file": "/workspaces/claude-code-flow/src/cli/simple-commands/verification-integration.js", "timestamp": "2025-08-12T15:50:08Z", "type": "pre-edit", "original_branch": "alpha-89"}
diff --git a/.claude/checkpoints/1755013810.json b/.claude/checkpoints/1755013810.json
new file mode 100644
index 0000000000..fe27de54a2
--- /dev/null
+++ b/.claude/checkpoints/1755013810.json
@@ -0,0 +1 @@
+{"tag": "checkpoint-20250812-155010", "file": "/workspaces/claude-code-flow/src/cli/simple-commands/verification-integration.js", "timestamp": "2025-08-12T15:50:10Z", "type": "post-edit", "branch": "alpha-89", "diff_summary": " .claude-flow/metrics/performance.json | 2 +- .claude-flow/metrics/system-metrics.json | 24 ++ .claude-flow/metrics/task-metrics.json | 6 +- .claude/checkpoints/task-1755013749.json | 1 + .../simple-commands/verification-integration.js | 472 +++++++++++++++++++++ 5 files changed, 501 insertions(+), 4 deletions(-) "}
diff --git a/src/cli/simple-commands/verification-hooks.js b/src/cli/simple-commands/verification-hooks.js
new file mode 100644
index 0000000000..559db1aafd
--- /dev/null
+++ b/src/cli/simple-commands/verification-hooks.js
@@ -0,0 +1,341 @@
+#!/usr/bin/env node
+/**
+ * Verification Hooks CLI
+ * Provides verification integration for other commands via CLI
+ */
+
+import { execSync } from 'child_process';
+import fs from 'fs';
+import path from 'path';
+
+// Parse command line arguments
+const args = process.argv.slice(2);
+const command = args[0];
+const taskId = args[1];
+const agentType = args[2] || 'unknown';
+const additionalData = args[3] ? JSON.parse(args[3]) : {};
+
+// Verification thresholds
+const THRESHOLDS = {
+ strict: 0.95,
+ moderate: 0.85,
+ development: 0.75
+};
+
+// Get current mode from environment or default
+const mode = process.env.VERIFICATION_MODE || 'moderate';
+const threshold = THRESHOLDS[mode];
+
+/**
+ * Pre-task verification
+ */
+async function preTaskVerification(taskId, agentType, data) {
+ console.log(`πŸ” Pre-task verification: ${taskId} (${agentType})`);
+
+ const checks = [];
+
+ // Check git status
+ try {
+ const gitStatus = execSync('git status --porcelain', { encoding: 'utf8' });
+ const isClean = gitStatus.trim() === '';
+ checks.push({
+ name: 'git-status',
+ passed: isClean || data.allowDirty,
+ score: isClean ? 1.0 : 0.7
+ });
+ } catch (e) {
+ checks.push({ name: 'git-status', passed: false, score: 0 });
+ }
+
+ // Check npm dependencies
+ if (fs.existsSync('package.json')) {
+ try {
+ execSync('npm ls --depth=0', { stdio: 'ignore' });
+ checks.push({ name: 'npm-deps', passed: true, score: 1.0 });
+ } catch {
+ checks.push({ name: 'npm-deps', passed: false, score: 0.5 });
+ }
+ }
+
+ const avgScore = checks.reduce((sum, c) => sum + c.score, 0) / checks.length;
+ const passed = avgScore >= threshold;
+
+ // Store result
+ storeVerification(taskId, 'pre', {
+ passed,
+ score: avgScore,
+ checks,
+ agentType
+ });
+
+ if (!passed) {
+ console.error(`❌ Pre-task verification failed (${avgScore.toFixed(2)} < ${threshold})`);
+ process.exit(1);
+ }
+
+ console.log(`βœ… Pre-task verification passed (${avgScore.toFixed(2)})`);
+ return 0;
+}
+
+/**
+ * Post-task verification
+ */
+async function postTaskVerification(taskId, agentType, data) {
+ console.log(`πŸ” Post-task verification: ${taskId} (${agentType})`);
+
+ const checks = [];
+
+ // Run type checking if available
+ if (fs.existsSync('tsconfig.json') || fs.existsSync('package.json')) {
+ try {
+ const result = execSync('npm run typecheck 2>&1 || true', { encoding: 'utf8' });
+ const hasErrors = result.toLowerCase().includes('error');
+ checks.push({
+ name: 'typecheck',
+ passed: !hasErrors,
+ score: hasErrors ? 0.5 : 1.0
+ });
+ } catch {
+ checks.push({ name: 'typecheck', passed: false, score: 0.3 });
+ }
+ }
+
+ // Run tests if available
+ if (fs.existsSync('package.json')) {
+ try {
+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
+ if (pkg.scripts && pkg.scripts.test) {
+ const result = execSync('npm test 2>&1 || true', { encoding: 'utf8' });
+ const passed = result.includes('PASS') || result.includes('passing');
+ checks.push({
+ name: 'tests',
+ passed,
+ score: passed ? 1.0 : 0.4
+ });
+ }
+ } catch {
+ checks.push({ name: 'tests', passed: false, score: 0.2 });
+ }
+ }
+
+ // Run linting if available
+ if (fs.existsSync('.eslintrc.js') || fs.existsSync('.eslintrc.json')) {
+ try {
+ const result = execSync('npm run lint 2>&1 || true', { encoding: 'utf8' });
+ const hasErrors = result.toLowerCase().includes('error');
+ checks.push({
+ name: 'lint',
+ passed: !hasErrors,
+ score: hasErrors ? 0.6 : 1.0
+ });
+ } catch {
+ checks.push({ name: 'lint', passed: false, score: 0.4 });
+ }
+ }
+
+ // If no checks were possible, use default
+ if (checks.length === 0) {
+ checks.push({
+ name: 'default',
+ passed: true,
+ score: 0.8
+ });
+ }
+
+ const avgScore = checks.reduce((sum, c) => sum + c.score, 0) / checks.length;
+ const passed = avgScore >= threshold;
+
+ // Store result
+ storeVerification(taskId, 'post', {
+ passed,
+ score: avgScore,
+ checks,
+ agentType
+ });
+
+ if (!passed) {
+ console.error(`❌ Post-task verification failed (${avgScore.toFixed(2)} < ${threshold})`);
+
+ // Attempt rollback if enabled
+ if (process.env.VERIFICATION_ROLLBACK === 'true') {
+ console.log('πŸ”„ Attempting rollback...');
+ try {
+ execSync('git reset --hard HEAD');
+ console.log('βœ… Rollback completed');
+ } catch (e) {
+ console.error('❌ Rollback failed:', e.message);
+ }
+ }
+
+ process.exit(1);
+ }
+
+ console.log(`βœ… Post-task verification passed (${avgScore.toFixed(2)})`);
+ return 0;
+}
+
+/**
+ * Training integration - feed results to training system
+ */
+async function feedToTraining(taskId, agentType, data) {
+ const verificationData = loadVerification(taskId);
+
+ if (!verificationData) {
+ console.log('⚠️ No verification data to feed to training');
+ return;
+ }
+
+ // Format for training system
+ const trainingData = {
+ taskId,
+ agentType,
+ preScore: verificationData.pre?.score || 0,
+ postScore: verificationData.post?.score || 0,
+ success: verificationData.post?.passed || false,
+ timestamp: new Date().toISOString()
+ };
+
+ // Store in training data file
+ const trainingFile = '.claude-flow/training/verification-data.jsonl';
+ const dir = path.dirname(trainingFile);
+
+ if (!fs.existsSync(dir)) {
+ fs.mkdirSync(dir, { recursive: true });
+ }
+
+ fs.appendFileSync(trainingFile, JSON.stringify(trainingData) + '\n');
+ console.log(`πŸ“Š Verification data fed to training system`);
+
+ // If score is particularly low, flag for attention
+ if (trainingData.postScore < 0.5) {
+ console.warn(`⚠️ Low verification score for ${agentType}: ${trainingData.postScore}`);
+ }
+}
+
+/**
+ * Store verification results
+ */
+function storeVerification(taskId, phase, data) {
+ const file = '.swarm/verification-memory.json';
+ const dir = path.dirname(file);
+
+ if (!fs.existsSync(dir)) {
+ fs.mkdirSync(dir, { recursive: true });
+ }
+
+ let memory = {};
+ if (fs.existsSync(file)) {
+ try {
+ memory = JSON.parse(fs.readFileSync(file, 'utf8'));
+ } catch {
+ memory = {};
+ }
+ }
+
+ if (!memory.history) memory.history = [];
+ if (!memory.tasks) memory.tasks = {};
+
+ // Store task-specific data
+ if (!memory.tasks[taskId]) {
+ memory.tasks[taskId] = {};
+ }
+ memory.tasks[taskId][phase] = data;
+
+ // Add to history
+ memory.history.push({
+ taskId,
+ phase,
+ ...data,
+ timestamp: new Date().toISOString()
+ });
+
+ // Keep only last 1000 entries
+ if (memory.history.length > 1000) {
+ memory.history = memory.history.slice(-1000);
+ }
+
+ fs.writeFileSync(file, JSON.stringify(memory, null, 2));
+}
+
+/**
+ * Load verification results
+ */
+function loadVerification(taskId) {
+ const file = '.swarm/verification-memory.json';
+
+ if (!fs.existsSync(file)) {
+ return null;
+ }
+
+ try {
+ const memory = JSON.parse(fs.readFileSync(file, 'utf8'));
+ return memory.tasks?.[taskId] || null;
+ } catch {
+ return null;
+ }
+}
+
+/**
+ * Show verification status
+ */
+function showStatus() {
+ const file = '.swarm/verification-memory.json';
+
+ if (!fs.existsSync(file)) {
+ console.log('No verification history found');
+ return;
+ }
+
+ try {
+ const memory = JSON.parse(fs.readFileSync(file, 'utf8'));
+ const recent = memory.history?.slice(-10) || [];
+
+ console.log(`πŸ“Š Verification Status`);
+ console.log(`Mode: ${mode} (threshold: ${threshold})`);
+ console.log(`Total verifications: ${memory.history?.length || 0}`);
+
+ if (recent.length > 0) {
+ console.log(`\nRecent verifications:`);
+ for (const v of recent) {
+ const status = v.passed ? 'βœ…' : '❌';
+ console.log(` ${status} ${v.taskId} (${v.phase}): ${v.score.toFixed(2)}`);
+ }
+ }
+ } catch (e) {
+ console.error('Error reading verification history:', e.message);
+ }
+}
+
+// Main CLI handler
+async function main() {
+ switch (command) {
+ case 'pre':
+ return preTaskVerification(taskId, agentType, additionalData);
+
+ case 'post':
+ return postTaskVerification(taskId, agentType, additionalData);
+
+ case 'train':
+ return feedToTraining(taskId, agentType, additionalData);
+
+ case 'status':
+ return showStatus();
+
+ default:
+ console.log('Usage: verification-hooks <pre|post|train|status> <taskId> [agentType] [data]');
+ process.exit(1);
+ }
+}
+
+// Run if called directly
+if (require.main === module) {
+ main().catch(console.error);
+}
+
+// Export for programmatic use
+export {
+ preTaskVerification,
+ postTaskVerification,
+ feedToTraining,
+ showStatus
+};
\ No newline at end of file