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

fix: #1859 #1862 ruflo-core hooks + CLI flag priority

Reuven8d06e427ca6b
diff --git a/.github/workflows/v3-ci.yml b/.github/workflows/v3-ci.yml
index 17a0735530..302818d0eb 100644
--- a/.github/workflows/v3-ci.yml
+++ b/.github/workflows/v3-ci.yml
@@ -176,6 +176,47 @@ jobs:
cd /tmp/smoke
node smoke-no-bsqlite.mjs
+ plugin-hooks-smoke:
+ # Regression guard for ruvnet/ruflo#1859 + #1862 — drives each PostToolUse
+ # hook from plugins/ruflo-core/hooks/hooks.json with synthetic Claude-Code
+ # JSON against the locally built CLI. Catches:
+ # - hooks calling flags the CLI doesn't accept (#1862's --format true)
+ # - CLI parser ambiguity recording the wrong value (#1859's "true" filename)
+ name: Plugin hooks smoke / Node ${{ matrix.node }}
+ runs-on: ubuntu-latest
+ needs: [build]
+ strategy:
+ fail-fast: false
+ matrix:
+ node: ['20', '22']
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Setup pnpm
+ uses: pnpm/action-setup@v2
+ with:
+ version: ${{ env.PNPM_VERSION }}
+
+ - name: Setup Node.js ${{ matrix.node }}
+ uses: actions/setup-node@v4
+ with:
+ node-version: ${{ matrix.node }}
+ cache: 'pnpm'
+ cache-dependency-path: v3/pnpm-lock.yaml
+
+ - name: Install + build v3
+ working-directory: v3
+ run: |
+ pnpm install --frozen-lockfile
+ pnpm build
+
+ - name: Run plugin hooks smoke against local CLI build
+ run: |
+ node plugins/ruflo-core/scripts/test-hooks.mjs \
+ "node $GITHUB_WORKSPACE/v3/@claude-flow/cli/bin/cli.js"
+
publish:
name: Publish to npm (alpha)
runs-on: ubuntu-latest
diff --git a/plugins/ruflo-core/hooks/hooks.json b/plugins/ruflo-core/hooks/hooks.json
index ecaa90a6f2..168400eee1 100644
--- a/plugins/ruflo-core/hooks/hooks.json
+++ b/plugins/ruflo-core/hooks/hooks.json
@@ -26,7 +26,7 @@
"hooks": [
{
"type": "command",
- "command": "cat | jq -r '.tool_input.command // empty' | tr '\\n' '\\0' | xargs -0 -I {} npx claude-flow@alpha hooks post-command --command '{}' --track-metrics true --store-results true"
+ "command": "/bin/bash -c 'INPUT=$(cat); CMD=$(printf %s \"$INPUT\" | jq -r \".tool_input.command // empty\"); [ -z \"$CMD\" ] && exit 0; EXIT=$(printf %s \"$INPUT\" | jq -r \".tool_response.exit_code // 0\"); SUCCESS=$([ \"$EXIT\" = \"0\" ] && echo true || echo false); npx claude-flow@alpha hooks post-command -c \"$CMD\" -s \"$SUCCESS\" -e \"$EXIT\"'"
}
]
},
@@ -35,7 +35,7 @@
"hooks": [
{
"type": "command",
- "command": "cat | jq -r '.tool_input.file_path // .tool_input.path // empty' | tr '\\n' '\\0' | xargs -0 -I {} npx claude-flow@alpha hooks post-edit --file '{}' --format true --update-memory true"
+ "command": "/bin/bash -c 'INPUT=$(cat); FILE=$(printf %s \"$INPUT\" | jq -r \".tool_input.file_path // .tool_input.path // empty\"); [ -z \"$FILE\" ] && exit 0; npx claude-flow@alpha hooks post-edit -f \"$FILE\" -s true'"
}
]
}
diff --git a/plugins/ruflo-core/scripts/test-hooks.mjs b/plugins/ruflo-core/scripts/test-hooks.mjs
new file mode 100644
index 0000000000..c17728cb03
--- /dev/null
+++ b/plugins/ruflo-core/scripts/test-hooks.mjs
@@ -0,0 +1,120 @@
+#!/usr/bin/env node
+/**
+ * Regression guard for ruvnet/ruflo#1859 + #1862.
+ *
+ * Drives each PostToolUse hook command from `hooks/hooks.json` with synthetic
+ * Claude-Code-style stdin against a locally built CLI, asserting:
+ *
+ * - Exit code 0 (no parser errors like "Invalid value for --format")
+ * - Output records the *intended* value (the file path / command), not a
+ * stray boolean like "true" — the symptom that #1859 reported
+ *
+ * The script substitutes `npx claude-flow@alpha` → the local CLI binary, so
+ * we exercise the same flag wiring users hit in production but pinned to
+ * the build under test.
+ *
+ * Usage (from repo root):
+ * node plugins/ruflo-core/scripts/test-hooks.mjs <path-to-cli-binary>
+ *
+ * Wired into .github/workflows/v3-ci.yml as the `plugin-hooks-smoke` job.
+ */
+
+import { readFileSync } from 'node:fs';
+import { spawnSync } from 'node:child_process';
+import { join, dirname } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+const HOOKS_JSON = join(__dirname, '..', 'hooks', 'hooks.json');
+
+// `cliInvoke` is the literal token-string that should run the CLI — caller
+// passes the full thing so this script doesn't need to guess shebangs:
+// - local node script: "node /abs/path/to/bin/cli.js"
+// - shell wrapper: "/abs/path/to/wrapper.sh"
+// - npx fallthrough: "npx --yes @claude-flow/cli@latest"
+const cliInvoke = process.argv[2];
+if (!cliInvoke) {
+ console.error('Usage: node test-hooks.mjs "<cli-invocation-string>"');
+ console.error('Examples:');
+ console.error(' node test-hooks.mjs "node $PWD/v3/@claude-flow/cli/bin/cli.js"');
+ console.error(' node test-hooks.mjs "npx --yes @claude-flow/cli@latest"');
+ process.exit(2);
+}
+
+const hooks = JSON.parse(readFileSync(HOOKS_JSON, 'utf8'));
+const post = hooks.hooks?.PostToolUse ?? [];
+
+const findHook = (matcher) => {
+ const hit = post.find(h => h.matcher === matcher);
+ if (!hit) throw new Error(`No PostToolUse hook with matcher=${matcher}`);
+ return hit.hooks[0].command.replace(/npx claude-flow@alpha/g, cliInvoke);
+};
+
+const cmdBash = findHook('Bash');
+const cmdEdit = findHook('Write|Edit|MultiEdit');
+
+let failed = 0;
+const cases = [];
+
+const run = (name, cmd, stdin, assertions) => {
+ const r = spawnSync('bash', ['-c', cmd], { input: stdin, encoding: 'utf8' });
+ const combined = (r.stdout ?? '') + (r.stderr ?? '');
+ const errors = [];
+ if (r.status !== 0) errors.push(`exit ${r.status} (expected 0)`);
+ for (const a of assertions) {
+ if (a.contains && !combined.includes(a.contains)) errors.push(`missing "${a.contains}" in output`);
+ if (a.absent && combined.includes(a.absent)) errors.push(`unexpected "${a.absent}" in output`);
+ }
+ if (errors.length === 0) {
+ console.log(`ok: ${name}`);
+ } else {
+ console.error(`FAIL: ${name}`);
+ for (const e of errors) console.error(` - ${e}`);
+ if (combined.trim()) {
+ console.error(' output:');
+ for (const line of combined.split('\n').slice(0, 8)) console.error(` ${line}`);
+ }
+ failed++;
+ }
+ cases.push(name);
+};
+
+// --- Edit hook ---
+run('Edit hook records file_path (regression #1859: was "true")',
+ cmdEdit,
+ '{"tool_input":{"file_path":"/tmp/foo.ts"}}',
+ [{ contains: '/tmp/foo.ts' }, { absent: 'Recording outcome for: true' }, { absent: 'Invalid value' }]);
+
+run('Edit hook records legacy "path" field',
+ cmdEdit,
+ '{"tool_input":{"path":"/tmp/bar.ts"}}',
+ [{ contains: '/tmp/bar.ts' }, { absent: 'Invalid value' }]);
+
+run('Edit hook silently no-ops when no path present',
+ cmdEdit,
+ '{"tool_input":{}}',
+ []);
+
+// --- Bash hook ---
+run('Bash hook records simple command',
+ cmdBash,
+ '{"tool_input":{"command":"echo hi"},"tool_response":{"exit_code":0}}',
+ [{ contains: 'echo hi' }, { absent: 'Required option missing' }, { absent: 'Invalid value' }]);
+
+run('Bash hook records multi-line heredoc (regression #1859)',
+ cmdBash,
+ '{"tool_input":{"command":"cat <<EOF\\nline1\\nline2\\nEOF"},"tool_response":{"exit_code":0}}',
+ [{ contains: 'cat <<EOF' }, { absent: 'Required option missing' }]);
+
+run('Bash hook records non-zero exit (distinct from -s value)',
+ cmdBash,
+ '{"tool_input":{"command":"echo failing-cmd"},"tool_response":{"exit_code":1}}',
+ [{ contains: 'echo failing-cmd' }, { absent: 'Recording command outcome: false' }, { absent: 'Recording command outcome: true' }]);
+
+run('Bash hook silently no-ops when no command present',
+ cmdBash,
+ '{"tool_input":{},"tool_response":{}}',
+ []);
+
+console.log(`\n${cases.length - failed}/${cases.length} passed`);
+process.exit(failed === 0 ? 0 : 1);
diff --git a/v3/@claude-flow/cli/src/commands/hooks.ts b/v3/@claude-flow/cli/src/commands/hooks.ts
index 7921f8dfcd..68eb39db31 100644
--- a/v3/@claude-flow/cli/src/commands/hooks.ts
+++ b/v3/@claude-flow/cli/src/commands/hooks.ts
@@ -299,7 +299,7 @@ const preEditCommand: Command = {
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
// Default file to 'unknown' for backward compatibility (env var may be empty)
- const filePath = ctx.args[0] || ctx.flags.file as string || 'unknown';
+ const filePath = (ctx.flags.file as string) || ctx.args[0] || 'unknown';
const operation = ctx.flags.operation as string || 'update';
output.printInfo(`Analyzing context for: ${output.highlight(filePath)}`);
@@ -428,7 +428,7 @@ const postEditCommand: Command = {
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
// Default file to 'unknown' for backward compatibility (env var may be empty)
- const filePath = ctx.args[0] || ctx.flags.file as string || 'unknown';
+ const filePath = (ctx.flags.file as string) || ctx.args[0] || 'unknown';
// Default success to true for backward compatibility (PostToolUse = success, PostToolUseFailure = failure)
const success = ctx.flags.success !== undefined ? (ctx.flags.success as boolean) : true;
@@ -527,7 +527,7 @@ const preCommandCommand: Command = {
{ command: 'claude-flow hooks pre-command -c "npm install lodash"', description: 'Check package install' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const command = ctx.args[0] || ctx.flags.command as string;
+ const command = (ctx.flags.command as string) || ctx.args[0];
if (!command) {
output.printError('Command is required. Use --command or -c flag.');
@@ -656,7 +656,7 @@ const postCommandCommand: Command = {
{ command: 'claude-flow hooks post-command -c "npm build" --success false -e 1', description: 'Record failed build' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const command = ctx.args[0] || ctx.flags.command as string;
+ const command = (ctx.flags.command as string) || ctx.args[0];
// Default success to true for backward compatibility
const success = ctx.flags.success !== undefined ? (ctx.flags.success as boolean) : true;
@@ -742,7 +742,7 @@ const routeCommand: Command = {
{ command: 'claude-flow hooks route -t "Optimize database queries" -K 5', description: 'Get top 5 suggestions' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const task = ctx.args[0] || ctx.flags.task as string;
+ const task = (ctx.flags.task as string) || ctx.args[0];
const topK = ctx.flags.topK as number || 3;
if (!task) {
@@ -894,7 +894,7 @@ const explainCommand: Command = {
{ command: 'claude-flow hooks explain -t "Optimize queries" -a coder --verbose', description: 'Verbose explanation for specific agent' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const task = ctx.args[0] || ctx.flags.task as string;
+ const task = (ctx.flags.task as string) || ctx.args[0];
if (!task) {
output.printError('Task description is required. Use --task or -t flag.');
@@ -1522,7 +1522,7 @@ const transferFromProjectCommand: Command = {
{ command: 'claude-flow hooks transfer from-project -s ../prod --filter security -m 0.9', description: 'Transfer high-confidence security patterns' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const sourcePath = ctx.args[0] || ctx.flags.source as string;
+ const sourcePath = (ctx.flags.source as string) || ctx.args[0];
const minConfidence = ctx.flags.minConfidence as number || 0.7;
if (!sourcePath) {
@@ -1761,7 +1761,7 @@ const preTaskCommand: Command = {
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
const taskId = (ctx.flags.taskId as string) || `task-${Date.now().toString(36)}`;
- const description = ctx.args[0] || ctx.flags.description as string;
+ const description = (ctx.flags.description as string) || ctx.args[0];
if (!description) {
output.printError('Description is required: --description "your task"');
@@ -2103,7 +2103,7 @@ const sessionRestoreCommand: Command = {
{ command: 'claude-flow hooks session-restore -i session-12345', description: 'Restore specific session' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const sessionId = ctx.args[0] || ctx.flags.sessionId as string || 'latest';
+ const sessionId = (ctx.flags.sessionId as string) || ctx.args[0] || 'latest';
output.printInfo(`Restoring session: ${output.highlight(sessionId)}`);
@@ -3064,7 +3064,7 @@ const coverageRouteCommand: Command = {
{ command: 'claude-flow hooks coverage-route -t "add tests" --threshold 90', description: 'Route with custom threshold' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const task = ctx.args[0] || ctx.flags.task as string;
+ const task = (ctx.flags.task as string) || ctx.args[0];
const threshold = ctx.flags.threshold as number || 80;
const useRuvector = !ctx.flags['no-ruvector'];
@@ -3336,7 +3336,7 @@ const coverageSuggestCommand: Command = {
{ command: 'claude-flow hooks coverage-suggest -p src/services --threshold 90', description: 'Stricter threshold' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const targetPath = ctx.args[0] || ctx.flags.path as string;
+ const targetPath = (ctx.flags.path as string) || ctx.args[0];
const threshold = ctx.flags.threshold as number || 80;
const limit = ctx.flags.limit as number || 20;
@@ -4727,7 +4727,7 @@ const modelRouteCommand: Command = {
{ command: 'claude-flow hooks model-route -t "architect auth system"', description: 'Route complex task (likely opus)' },
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const task = ctx.args[0] || ctx.flags.task as string;
+ const task = (ctx.flags.task as string) || ctx.args[0];
if (!task) {
output.printError('Task description required. Use --task or -t flag.');
return { success: false, exitCode: 1 };
@@ -5090,7 +5090,7 @@ const taskCompletedCommand: Command = {
{ command: 'claude-flow hooks task-completed -i task-456 --notify-lead --quality 0.95', description: 'Complete with quality score' }
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const taskId = ctx.args[0] || ctx.flags.taskId as string;
+ const taskId = (ctx.flags.taskId as string) || ctx.args[0];
const trainPatterns = ctx.flags.trainPatterns !== false;
const notifyLead = ctx.flags.notifyLead !== false;
const success = ctx.flags.success !== false;
@@ -5189,7 +5189,7 @@ const notifyCommand: Command = {
{ command: 'claude-flow hooks notify -m "Test failed" -l error', description: 'Send error notification' },
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const message = ctx.args[0] || ctx.flags.message as string;
+ const message = (ctx.flags.message as string) || ctx.args[0];
const level = (ctx.flags.level as string) || 'info';
if (!message) {