moflo 4.8.3 → 4.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,21 +39,119 @@ function loadGateConfig() {
39
39
  var config = loadGateConfig();
40
40
  var command = process.argv[2];
41
41
 
42
- var EXEMPT = ['.claude/', '.claude\\', 'CLAUDE.md', 'MEMORY.md', 'workflow-state', 'node_modules'];
43
42
  var DANGEROUS = ['rm -rf /', 'format c:', 'del /s /q c:\\', ':(){:|:&};:', 'mkfs.', '> /dev/sda'];
44
43
  var DIRECTIVE_RE = /^(yes|no|yeah|yep|nope|sure|ok|okay|correct|right|exactly|perfect)\b/i;
45
44
  var TASK_RE = /\b(fix|bug|error|implement|add|create|build|write|refactor|debug|test|feature|issue|security|optimi)\b/i;
46
45
 
46
+ // Deny a tool call cleanly via structured JSON (no "hook error" noise).
47
+ // Exit 0 + permissionDecision:"deny" is the Claude Code way to block a tool.
48
+ function blockTool(reason) {
49
+ console.log(JSON.stringify({
50
+ hookSpecificOutput: {
51
+ hookEventName: 'PreToolUse',
52
+ permissionDecision: 'deny',
53
+ permissionDecisionReason: reason
54
+ }
55
+ }));
56
+ process.exit(0);
57
+ }
58
+
59
+ // Determine if a Grep/Glob target is a mechanical/administrative search
60
+ // that should bypass the memory-first gate. The idea: if memory/guidance
61
+ // wouldn't improve the search outcome, don't block it.
62
+ //
63
+ // Strategy: path is the strongest signal. When a path clearly points to
64
+ // tooling/deps/tests, allow it. When it points to source/docs/scripts,
65
+ // block it (require memory). Pattern-based rules only kick in when there's
66
+ // no path or when the path is neutral.
67
+ function isMechanicalSearch() {
68
+ var searchPath = (process.env.TOOL_INPUT_path || '').replace(/\\/g, '/').toLowerCase();
69
+ var pattern = (process.env.TOOL_INPUT_pattern || '').toLowerCase();
70
+ var filePath = (process.env.TOOL_INPUT_file_path || '').replace(/\\/g, '/').toLowerCase();
71
+ var anyPath = searchPath || filePath;
72
+
73
+ // --- PATH-BASED RULES (strongest signal, checked first) ---
74
+
75
+ if (anyPath) {
76
+ // Always mechanical: dependencies, tooling internals, CI, test dirs
77
+ var mechanicalPaths = [
78
+ 'node_modules/', '.claude/', '.claude-flow/', '.swarm/', '.github/',
79
+ 'tests/', 'test/', 'config/', 'examples/',
80
+ ];
81
+ for (var i = 0; i < mechanicalPaths.length; i++) {
82
+ if (anyPath.indexOf(mechanicalPaths[i]) >= 0) return true;
83
+ }
84
+
85
+ // Targeting a specific config/meta file by path extension
86
+ if (/\.(json|yaml|yml|toml|lock|env|cjs|mjs)$/i.test(anyPath)) return true;
87
+
88
+ // If path points to source, docs, or scripts — these are knowledge-rich.
89
+ // Do NOT fall through to pattern-based exemptions; the path is authoritative.
90
+ // (Still allow test-file glob patterns even within source dirs.)
91
+ var knowledgePaths = [
92
+ 'src/', 'back-office/', 'front-office/', 'docs/', 'scripts/', 'lib/',
93
+ ];
94
+ var inKnowledgePath = false;
95
+ for (var k = 0; k < knowledgePaths.length; k++) {
96
+ if (anyPath.indexOf(knowledgePaths[k]) >= 0) { inKnowledgePath = true; break; }
97
+ }
98
+ if (inKnowledgePath) {
99
+ // Exception: searching for test/spec files within source is structural
100
+ if (/\*\*?[/\\]?\*?\.(test|spec)\.(ts|js|tsx|jsx)\b/i.test(pattern)) return true;
101
+ // Everything else in a knowledge path requires memory
102
+ return false;
103
+ }
104
+ }
105
+
106
+ // --- PATTERN-BASED RULES (no path, or path is neutral) ---
107
+
108
+ // Glob patterns looking for config/build/tooling files by extension
109
+ if (/\*\*?[/\\]?\*?\.(json|yaml|yml|toml|lock|env|config|cjs|mjs)\b/i.test(pattern)) return true;
110
+
111
+ // Glob patterns for specific config filenames (eslintrc, Dockerfile, etc.)
112
+ if (/\*\*?[/\\]?\*?\.?(eslint|prettier|babel|stylelint|editor|git|docker|nginx|jest|vitest|vite|webpack|rollup|esbuild|tsconfig|browserslist)/i.test(pattern)) return true;
113
+
114
+ // Glob patterns for lock files and test files (structural lookups)
115
+ if (/\*\*?[/\\]?\*?[\w-]*[-.]lock\b/i.test(pattern)) return true;
116
+ if (/\*\*?[/\\]?\*?\.(test|spec)\.(ts|js|tsx|jsx)\b/i.test(pattern)) return true;
117
+
118
+ // Config/tooling name searches (bare names without a path).
119
+ // Only exempt if ALL tokens in a pipe-separated pattern are config names.
120
+ // "webpack|vite" = exempt. "webpack|merchant" = NOT exempt.
121
+ var CONFIG_NAME = /^\.?(eslint|prettier|babel|stylelint|editor|gitignore|gitattributes|dockerignore|dockerfile|docker-compose|nginx|jest|vitest|vite|webpack|rollup|esbuild|tsconfig|changelog|license|makefile|procfile|browserslist|commitlint|husky|lint-staged)\b/i;
122
+ var tokens = pattern.split(/[|,\s]+/).filter(function(t) { return t.length > 0; });
123
+ if (tokens.length > 0 && tokens.every(function(t) { return CONFIG_NAME.test(t.trim()); })) return true;
124
+
125
+ // Known tooling/meta file names as substrings (but avoid false matches like "process.env")
126
+ var toolingNames = [
127
+ 'claude.md', 'memory.md', 'workflow-state', '.mcp.json',
128
+ 'package.json', 'package-lock', 'daemon.lock', 'moflo.yaml',
129
+ ];
130
+ var target = pattern + ' ' + anyPath;
131
+ for (var j = 0; j < toolingNames.length; j++) {
132
+ if (target.indexOf(toolingNames[j]) >= 0) return true;
133
+ }
134
+
135
+ // Env file lookups (but NOT "process.env" which is source code searching)
136
+ if (/^\.env\b/.test(pattern) || /\*\*?[/\\]?\.env/.test(pattern)) return true;
137
+
138
+ // Git/process/system-level pattern searches
139
+ if (/^(git\b|pid|daemon|lock|wmic|tasklist|powershell|ps\s)/i.test(pattern)) return true;
140
+
141
+ // CI/CD folder exploration
142
+ if (/\.github/i.test(pattern)) return true;
143
+
144
+ return false;
145
+ }
146
+
47
147
  switch (command) {
48
148
  case 'check-before-agent': {
49
149
  var s = readState();
50
150
  if (config.task_create_first && !s.tasksCreated) {
51
- console.log('BLOCKED: Call TaskCreate before spawning agents.');
52
- process.exit(1);
151
+ blockTool('Call TaskCreate before spawning agents. Task tool is blocked until then.');
53
152
  }
54
153
  if (config.memory_first && !s.memorySearched) {
55
- console.log('BLOCKED: Search memory before spawning agents.');
56
- process.exit(1);
154
+ blockTool('Search memory before spawning agents. Use mcp__claude-flow__memory_search first.');
57
155
  }
58
156
  break;
59
157
  }
@@ -61,31 +159,21 @@ switch (command) {
61
159
  if (!config.memory_first) break;
62
160
  var s = readState();
63
161
  if (s.memorySearched || !s.memoryRequired) break;
64
- var target = (process.env.TOOL_INPUT_pattern || '') + ' ' + (process.env.TOOL_INPUT_path || '');
65
- if (EXEMPT.some(function(p) { return target.indexOf(p) >= 0; })) break;
66
- var now = Date.now();
67
- var last = s.lastBlockedAt ? new Date(s.lastBlockedAt).getTime() : 0;
68
- if (now - last > 2000) {
69
- s.lastBlockedAt = new Date(now).toISOString();
70
- writeState(s);
71
- console.log('BLOCKED: Search memory before exploring files.');
72
- }
73
- process.exit(1);
162
+ if (isMechanicalSearch()) break;
163
+ s.lastBlockedAt = new Date().toISOString();
164
+ writeState(s);
165
+ blockTool('Search memory before exploring files. Use mcp__claude-flow__memory_search with namespace "code-map", "patterns", "knowledge", or "guidance".');
74
166
  }
75
167
  case 'check-before-read': {
76
168
  if (!config.memory_first) break;
77
169
  var s = readState();
78
170
  if (s.memorySearched || !s.memoryRequired) break;
79
- var fp = process.env.TOOL_INPUT_file_path || '';
80
- if (fp.indexOf('.claude/guidance/') < 0 && fp.indexOf('.claude\\guidance\\') < 0) break;
81
- var now = Date.now();
82
- var last = s.lastBlockedAt ? new Date(s.lastBlockedAt).getTime() : 0;
83
- if (now - last > 2000) {
84
- s.lastBlockedAt = new Date(now).toISOString();
85
- writeState(s);
86
- console.log('BLOCKED: Search memory before reading guidance files.');
87
- }
88
- process.exit(1);
171
+ var fp = (process.env.TOOL_INPUT_file_path || '').replace(/\\/g, '/');
172
+ // Block reads of guidance files (that's exactly what memory indexes)
173
+ if (fp.indexOf('.claude/guidance/') < 0) break;
174
+ s.lastBlockedAt = new Date().toISOString();
175
+ writeState(s);
176
+ blockTool('Search memory before reading guidance files. Use mcp__claude-flow__memory_search with namespace "guidance".');
89
177
  }
90
178
  case 'record-task-created': {
91
179
  var s = readState();
package/README.md CHANGED
@@ -4,8 +4,6 @@
4
4
 
5
5
  # MoFlo
6
6
 
7
- **⚠️ MoFlo is experimental software. APIs, commands, and behavior may change without notice.**
8
-
9
7
  **An opinionated fork of [Ruflo/Claude Flow](https://github.com/ruvnet/ruflo), optimized for local development.**
10
8
 
11
9
  MoFlo adds automatic code and guidance cataloging along with memory gating on top of the original Ruflo/Claude Flow orchestration engine. Where the upstream project provides raw building blocks, MoFlo ships opinionated defaults — workflow gates that enforce memory-first patterns, semantic indexing that runs at session start, and learned routing that improves over time — so you get a productive setup from `flo init` without manual tuning.
@@ -477,6 +475,16 @@ When `flo init` runs, it appends a workflow section to your CLAUDE.md that teach
477
475
 
478
476
  MoFlo builds on top of the full [Ruflo/Claude Flow](https://github.com/ruvnet/ruflo) engine. For detailed documentation on the underlying capabilities — swarm topologies, hive-mind consensus, HNSW vector search, neural routing, MCP server internals, and more — check out the [Ruflo repository](https://github.com/ruvnet/ruflo).
479
477
 
478
+ ## Why I Made This
479
+
480
+ [Ruflo/Claude Flow](https://github.com/ruvnet/ruflo) is an incredible piece of work. The engineering that [rUv](https://github.com/ruvnet) and the contributors have put into it — swarm topologies, hive-mind consensus, HNSW vector search, neural routing, and so much more — makes it one of the most comprehensive agent orchestration frameworks available. It's a massive, versatile toolbox built to support a wide range of scenarios: distributed systems, multi-agent swarms, enterprise orchestration, research workflows, and beyond.
481
+
482
+ My use case was just one of those many scenarios: day-to-day local coding, enhancing my normal Claude Code experience on a single project. Claude Flow absolutely supports this — it's all in there — but because the project serves so many different needs, I found myself spending time configuring and tailoring things for my specific workflow each time I pulled in updates. That's not a shortcoming of the project; it's the natural trade-off of a tool designed to be that flexible and powerful.
483
+
484
+ So I forked the excellent foundation and narrowed the focus to my particular corner of it. I baked in the defaults I kept setting manually, added automatic indexing and memory gating at session start, and tuned the out-of-box experience so that `npm install` and `flo init` gets you straight to coding.
485
+
486
+ If you're exploring the full breadth of what agent orchestration can do, go use [Ruflo/Claude Flow](https://github.com/ruvnet/ruflo) directly — it's the real deal. But if your needs are similar to mine — a focused, opinionated local dev setup that just works — then hopefully MoFlo saves you the same configuration time it saves me.
487
+
480
488
  ## License
481
489
 
482
490
  MIT (inherited from [Ruflo/Claude Flow](https://github.com/ruvnet/ruflo))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moflo",
3
- "version": "4.8.3",
3
+ "version": "4.8.4",
4
4
  "description": "MoFlo — AI agent orchestration for Claude Code. Forked from ruflo/claude-flow with patches applied to source, plus feature-level orchestration.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -407,47 +407,69 @@ async function checkAgenticFlow() {
407
407
  return { name: 'agentic-flow', status: 'warn', message: 'Check failed' };
408
408
  }
409
409
  }
410
- // Find and optionally kill orphaned moflo/claude-flow node processes
410
+ // Check whether a given PID is still running.
411
+ // Uses signal 0 which works cross-platform (Windows, Linux, macOS) without
412
+ // needing PowerShell or /proc — Node handles the platform abstraction.
413
+ function isProcessAlive(pid) {
414
+ try {
415
+ process.kill(pid, 0);
416
+ return true;
417
+ }
418
+ catch {
419
+ return false;
420
+ }
421
+ }
422
+ // Find and optionally kill orphaned moflo/claude-flow node processes.
423
+ // A process is only "orphaned" if its parent is no longer alive — meaning
424
+ // nothing will clean it up. MCP servers spawned by a live Claude Code session
425
+ // have a live parent (claude.exe) and must not be flagged.
411
426
  async function findZombieProcesses(kill = false) {
412
427
  const legitimatePid = getDaemonLockHolder(process.cwd());
413
428
  const currentPid = process.pid;
414
429
  const parentPid = process.ppid;
415
430
  const found = [];
416
431
  let killed = 0;
432
+ // Collect candidates as { pid, ppid } so we can check parent liveness
433
+ const candidates = [];
417
434
  try {
418
435
  if (process.platform === 'win32') {
419
- // Windows: use WMIC to find node processes with moflo/claude-flow in command line
420
- const result = execSync('powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter \\"Name=\'node.exe\'\\" | Select-Object ProcessId,CommandLine | Format-Table -AutoSize -Wrap"', { encoding: 'utf-8', timeout: 10000, windowsHide: true });
436
+ // Windows: include ParentProcessId so we can verify orphan status
437
+ const result = execSync('powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter \\"Name=\'node.exe\'\\" | Select-Object ProcessId,ParentProcessId,CommandLine | Format-Table -AutoSize -Wrap"', { encoding: 'utf-8', timeout: 10000, windowsHide: true });
421
438
  const lines = result.split('\n');
422
439
  for (const line of lines) {
423
440
  if (/moflo|claude-flow|flo\s+(hooks|gate|mcp|daemon)/i.test(line)) {
424
- const pidMatch = line.match(/^\s*(\d+)/);
425
- if (pidMatch) {
426
- const pid = parseInt(pidMatch[1], 10);
427
- // Skip our own process, parent, and the legitimate daemon
428
- if (pid === currentPid || pid === parentPid || pid === legitimatePid)
429
- continue;
430
- found.push(pid);
441
+ // Format-Table columns: ProcessId ParentProcessId CommandLine...
442
+ const match = line.match(/^\s*(\d+)\s+(\d+)/);
443
+ if (match) {
444
+ candidates.push({ pid: parseInt(match[1], 10), ppid: parseInt(match[2], 10) });
431
445
  }
432
446
  }
433
447
  }
434
448
  }
435
449
  else {
436
- // Unix/macOS: use ps to find node processes
437
- const result = execSync('ps aux | grep -E "node.*(moflo|claude-flow)" | grep -v grep', { encoding: 'utf-8', timeout: 5000 });
450
+ // Unix/macOS: use ps with explicit PID+PPID columns for reliable parsing
451
+ const result = execSync('ps -eo pid,ppid,command | grep -E "node.*(moflo|claude-flow)" | grep -v grep', { encoding: 'utf-8', timeout: 5000 });
438
452
  const lines = result.trim().split('\n');
439
453
  for (const line of lines) {
440
- const parts = line.trim().split(/\s+/);
441
- const pid = parseInt(parts[1], 10);
442
- if (pid === currentPid || pid === parentPid || pid === legitimatePid)
443
- continue;
444
- found.push(pid);
454
+ const match = line.trim().match(/^(\d+)\s+(\d+)/);
455
+ if (match) {
456
+ candidates.push({ pid: parseInt(match[1], 10), ppid: parseInt(match[2], 10) });
457
+ }
445
458
  }
446
459
  }
447
460
  }
448
461
  catch {
449
462
  // No matches found (grep exits non-zero) or command failed
450
463
  }
464
+ // Filter: skip known-good PIDs and processes whose parent is still alive.
465
+ // A live parent (e.g. claude.exe for MCP servers) means the process is managed, not orphaned.
466
+ for (const { pid, ppid } of candidates) {
467
+ if (pid === currentPid || pid === parentPid || pid === legitimatePid)
468
+ continue;
469
+ if (isProcessAlive(ppid))
470
+ continue;
471
+ found.push(pid);
472
+ }
451
473
  if (kill && found.length > 0) {
452
474
  for (const pid of found) {
453
475
  try {