@sparkleideas/claude-flow-patch 3.1.0-alpha.44.patch.10

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.
Files changed (120) hide show
  1. package/AGENTS.md +162 -0
  2. package/CLAUDE.md +506 -0
  3. package/README.md +351 -0
  4. package/bin/claude-flow-patch.mjs +148 -0
  5. package/check-patches.sh +195 -0
  6. package/lib/categories.json +15 -0
  7. package/lib/common.py +97 -0
  8. package/lib/discover.mjs +181 -0
  9. package/lib/discover.sh +160 -0
  10. package/package.json +86 -0
  11. package/patch/010-CF-001-doctor-yaml/README.md +11 -0
  12. package/patch/010-CF-001-doctor-yaml/fix.py +20 -0
  13. package/patch/010-CF-001-doctor-yaml/sentinel +1 -0
  14. package/patch/020-CF-002-config-export-yaml/README.md +11 -0
  15. package/patch/020-CF-002-config-export-yaml/fix.py +130 -0
  16. package/patch/020-CF-002-config-export-yaml/sentinel +1 -0
  17. package/patch/030-DM-001-daemon-log-zero/README.md +12 -0
  18. package/patch/030-DM-001-daemon-log-zero/fix.py +37 -0
  19. package/patch/030-DM-001-daemon-log-zero/sentinel +1 -0
  20. package/patch/040-DM-002-cpu-load-threshold/README.md +11 -0
  21. package/patch/040-DM-002-cpu-load-threshold/fix.py +6 -0
  22. package/patch/040-DM-002-cpu-load-threshold/sentinel +1 -0
  23. package/patch/050-DM-003-macos-freemem/README.md +11 -0
  24. package/patch/050-DM-003-macos-freemem/fix.py +7 -0
  25. package/patch/050-DM-003-macos-freemem/sentinel +1 -0
  26. package/patch/060-DM-004-preload-worker-stub/README.md +11 -0
  27. package/patch/060-DM-004-preload-worker-stub/fix.py +34 -0
  28. package/patch/060-DM-004-preload-worker-stub/sentinel +1 -0
  29. package/patch/070-DM-005-consolidation-worker-stub/README.md +11 -0
  30. package/patch/070-DM-005-consolidation-worker-stub/fix.py +46 -0
  31. package/patch/070-DM-005-consolidation-worker-stub/sentinel +1 -0
  32. package/patch/080-EM-001-embedding-ignores-config/README.md +11 -0
  33. package/patch/080-EM-001-embedding-ignores-config/fix.py +111 -0
  34. package/patch/080-EM-001-embedding-ignores-config/sentinel +1 -0
  35. package/patch/090-EM-002-transformers-cache-eacces/README.md +11 -0
  36. package/patch/090-EM-002-transformers-cache-eacces/fix.sh +12 -0
  37. package/patch/090-EM-002-transformers-cache-eacces/sentinel +1 -0
  38. package/patch/100-GV-001-hnsw-ghost-vectors/README.md +11 -0
  39. package/patch/100-GV-001-hnsw-ghost-vectors/fix.py +34 -0
  40. package/patch/100-GV-001-hnsw-ghost-vectors/sentinel +1 -0
  41. package/patch/110-HK-001-post-edit-file-path/README.md +44 -0
  42. package/patch/110-HK-001-post-edit-file-path/fix.py +23 -0
  43. package/patch/110-HK-001-post-edit-file-path/sentinel +1 -0
  44. package/patch/120-HK-002-hooks-tools-stub/README.md +36 -0
  45. package/patch/120-HK-002-hooks-tools-stub/fix.py +155 -0
  46. package/patch/120-HK-002-hooks-tools-stub/sentinel +1 -0
  47. package/patch/130-HK-003-metrics-hardcoded/README.md +30 -0
  48. package/patch/130-HK-003-metrics-hardcoded/fix.py +82 -0
  49. package/patch/130-HK-003-metrics-hardcoded/sentinel +1 -0
  50. package/patch/135-HK-004-respect-daemon-autostart/README.md +11 -0
  51. package/patch/135-HK-004-respect-daemon-autostart/fix.py +14 -0
  52. package/patch/135-HK-004-respect-daemon-autostart/sentinel +1 -0
  53. package/patch/137-HK-005-daemon-pid-guard/README.md +11 -0
  54. package/patch/137-HK-005-daemon-pid-guard/fix.py +53 -0
  55. package/patch/137-HK-005-daemon-pid-guard/sentinel +2 -0
  56. package/patch/140-HW-001-stdin-hang/README.md +11 -0
  57. package/patch/140-HW-001-stdin-hang/fix.py +6 -0
  58. package/patch/140-HW-001-stdin-hang/sentinel +1 -0
  59. package/patch/150-HW-002-failures-swallowed/README.md +11 -0
  60. package/patch/150-HW-002-failures-swallowed/fix.py +42 -0
  61. package/patch/150-HW-002-failures-swallowed/sentinel +1 -0
  62. package/patch/160-HW-003-aggressive-intervals/README.md +11 -0
  63. package/patch/160-HW-003-aggressive-intervals/fix.py +52 -0
  64. package/patch/160-HW-003-aggressive-intervals/sentinel +3 -0
  65. package/patch/170-IN-001-intelligence-stub/README.md +64 -0
  66. package/patch/170-IN-001-intelligence-stub/fix.py +63 -0
  67. package/patch/170-IN-001-intelligence-stub/sentinel +1 -0
  68. package/patch/180-MM-001-memory-persist-path/README.md +27 -0
  69. package/patch/180-MM-001-memory-persist-path/fix.py +54 -0
  70. package/patch/180-MM-001-memory-persist-path/sentinel +1 -0
  71. package/patch/190-NS-001-discovery-default-namespace/README.md +16 -0
  72. package/patch/190-NS-001-discovery-default-namespace/fix.py +68 -0
  73. package/patch/190-NS-001-discovery-default-namespace/sentinel +2 -0
  74. package/patch/200-NS-002-targeted-require-namespace/README.md +19 -0
  75. package/patch/200-NS-002-targeted-require-namespace/fix.py +158 -0
  76. package/patch/200-NS-002-targeted-require-namespace/sentinel +2 -0
  77. package/patch/210-NS-003-namespace-typo-pattern/README.md +15 -0
  78. package/patch/210-NS-003-namespace-typo-pattern/fix.py +23 -0
  79. package/patch/210-NS-003-namespace-typo-pattern/sentinel +1 -0
  80. package/patch/220-RS-001-better-sqlite3-node24/README.md +54 -0
  81. package/patch/220-RS-001-better-sqlite3-node24/fix.py +27 -0
  82. package/patch/220-RS-001-better-sqlite3-node24/rebuild.sh +31 -0
  83. package/patch/220-RS-001-better-sqlite3-node24/sentinel +2 -0
  84. package/patch/230-RV-001-force-learn-tick/README.md +31 -0
  85. package/patch/230-RV-001-force-learn-tick/fix.py +14 -0
  86. package/patch/230-RV-001-force-learn-tick/sentinel +2 -0
  87. package/patch/240-RV-002-trajectory-load/README.md +28 -0
  88. package/patch/240-RV-002-trajectory-load/fix.py +14 -0
  89. package/patch/240-RV-002-trajectory-load/sentinel +2 -0
  90. package/patch/250-RV-003-trajectory-stats-sync/README.md +31 -0
  91. package/patch/250-RV-003-trajectory-stats-sync/fix.py +18 -0
  92. package/patch/250-RV-003-trajectory-stats-sync/sentinel +2 -0
  93. package/patch/260-SG-001-init-settings/README.md +29 -0
  94. package/patch/260-SG-001-init-settings/fix.py +143 -0
  95. package/patch/260-SG-001-init-settings/sentinel +4 -0
  96. package/patch/270-SG-003-init-helpers-all-paths/README.md +60 -0
  97. package/patch/270-SG-003-init-helpers-all-paths/fix.py +165 -0
  98. package/patch/270-SG-003-init-helpers-all-paths/sentinel +3 -0
  99. package/patch/280-UI-001-intelligence-stats-crash/README.md +11 -0
  100. package/patch/280-UI-001-intelligence-stats-crash/fix.py +57 -0
  101. package/patch/280-UI-001-intelligence-stats-crash/sentinel +1 -0
  102. package/patch/290-UI-002-neural-status-not-loaded/README.md +11 -0
  103. package/patch/290-UI-002-neural-status-not-loaded/fix.py +19 -0
  104. package/patch/290-UI-002-neural-status-not-loaded/sentinel +1 -0
  105. package/patch/300-DM-006-log-rotation/README.md +12 -0
  106. package/patch/300-DM-006-log-rotation/fix.py +72 -0
  107. package/patch/300-DM-006-log-rotation/sentinel +2 -0
  108. package/patch/310-HW-004-runwithtimeout-orphan/README.md +11 -0
  109. package/patch/310-HW-004-runwithtimeout-orphan/fix.py +10 -0
  110. package/patch/310-HW-004-runwithtimeout-orphan/sentinel +1 -0
  111. package/patch/320-SG-004-wizard-parity/README.md +40 -0
  112. package/patch/320-SG-004-wizard-parity/fix.py +208 -0
  113. package/patch/320-SG-004-wizard-parity/sentinel +3 -0
  114. package/patch/330-SG-005-start-all-subcommand/README.md +32 -0
  115. package/patch/330-SG-005-start-all-subcommand/fix.py +58 -0
  116. package/patch/330-SG-005-start-all-subcommand/sentinel +1 -0
  117. package/patch-all.sh +199 -0
  118. package/repair-post-init.sh +263 -0
  119. package/scripts/preflight.mjs +249 -0
  120. package/scripts/upstream-log.mjs +257 -0
@@ -0,0 +1,27 @@
1
+ # RS-001: ruv-swarm better-sqlite3 Node 24 compatibility
2
+ # GitHub: ruvnet/ruv-FANN#185
3
+ #
4
+ # ruv-swarm@1.0.20 pins better-sqlite3@^11.6.0 which lacks Node 24
5
+ # prebuilt binaries. Bump to ^12.0.0 which supports Node 24 (v137 ABI).
6
+ #
7
+ # This patch targets the ruv-swarm package.json, NOT @claude-flow/cli.
8
+ # Uses RUV_SWARM_ROOT from discover.sh, with glob fallback for backward compat.
9
+
10
+ import glob
11
+
12
+ # Prefer RUV_SWARM_ROOT from discover.sh; fall back to glob for standalone use
13
+ rs_pkg = ""
14
+ if ruv_swarm_root:
15
+ _candidate = os.path.join(ruv_swarm_root, "package.json")
16
+ if os.path.isfile(_candidate):
17
+ rs_pkg = _candidate
18
+ if not rs_pkg:
19
+ rs_pkg_candidates = glob.glob(os.path.expanduser(
20
+ "~/.npm/_npx/*/node_modules/ruv-swarm/package.json"
21
+ ))
22
+ rs_pkg = rs_pkg_candidates[0] if rs_pkg_candidates else ""
23
+
24
+ patch("RS-001: better-sqlite3 ^11 -> ^12 (Node 24)",
25
+ rs_pkg,
26
+ '"better-sqlite3": "^11.6.0"',
27
+ '"better-sqlite3": "^12.0.0"')
@@ -0,0 +1,31 @@
1
+ #!/bin/bash
2
+ # RS-001: After patching package.json, reinstall better-sqlite3 with
3
+ # correct prebuilt binaries for Node 24.
4
+ #
5
+ # Usage: bash rebuild.sh
6
+
7
+ set -euo pipefail
8
+
9
+ RS_DIR=$(find ~/.npm/_npx -path "*/node_modules/ruv-swarm" -type d 2>/dev/null | head -1)
10
+
11
+ if [ -z "$RS_DIR" ]; then
12
+ echo "[RS-001] ruv-swarm not found in npx cache, skipping rebuild"
13
+ exit 0
14
+ fi
15
+
16
+ # Install at the npx cache root (where better-sqlite3 is hoisted),
17
+ # not inside ruv-swarm's own node_modules
18
+ NPX_ROOT=$(echo "$RS_DIR" | sed 's|/node_modules/ruv-swarm$||')
19
+
20
+ echo "[RS-001] Reinstalling better-sqlite3@^12.0.0 in: $NPX_ROOT"
21
+
22
+ cd "$NPX_ROOT"
23
+ npm install better-sqlite3@"^12.0.0" --no-save 2>&1
24
+
25
+ echo "[RS-001] Verifying..."
26
+ if npx -y ruv-swarm --version 2>/dev/null; then
27
+ echo "[RS-001] OK: ruv-swarm starts successfully"
28
+ else
29
+ echo "[RS-001] WARN: ruv-swarm still failing — may need full cache clear"
30
+ echo " Try: rm -rf ~/.npm/_npx/$(basename $(dirname $RS_DIR)) && npx -y ruv-swarm --version"
31
+ fi
@@ -0,0 +1,2 @@
1
+ package: ruv-swarm
2
+ grep "better-sqlite3.*\^12" package.json
@@ -0,0 +1,31 @@
1
+ # RV-001: force-learn command calls intel.tick() which doesn't exist
2
+
3
+ **Severity**: Medium
4
+ **GitHub**: [#1156](https://github.com/ruvnet/claude-flow/issues/1156)
5
+
6
+ ## Root Cause
7
+
8
+ The `hooks force-learn` command (line 4224) creates an Intelligence instance with
9
+ `skipEngine: true` (fast mode), then calls `intel.tick()`. The `tick()` method
10
+ exists on the engine object (`eng.tick()`), not on the Intelligence class itself.
11
+ With `skipEngine: true`, no engine is created, so the call crashes.
12
+
13
+ ```javascript
14
+ // Line 4224-4226
15
+ const intel = new Intelligence({ skipEngine: true }); // Fast mode
16
+ intel.tick(); // BUG: tick() doesn't exist on Intelligence
17
+ ```
18
+
19
+ ## Fix
20
+
21
+ 1. Remove `skipEngine: true` so the engine can initialize
22
+ 2. Call `intel.engine.tick()` instead of `intel.tick()`
23
+ 3. Add null check for when engine fails to load
24
+
25
+ ## Files Patched
26
+
27
+ - `ruvector/bin/cli.js`
28
+
29
+ ## Ops
30
+
31
+ 2 ops in fix.py
@@ -0,0 +1,14 @@
1
+ # RV-001: force-learn calls intel.tick() which doesn't exist
2
+ # The tick() method is on the engine, not the Intelligence class
3
+
4
+ # Fix 1: Remove skipEngine: true so engine can initialize
5
+ patch("RV-001a: remove skipEngine from force-learn",
6
+ ruvector_cli,
7
+ "const intel = new Intelligence({ skipEngine: true }); // Fast mode\n intel.tick();",
8
+ "const intel = new Intelligence(); // Need engine for tick()\n const eng = intel.engine;\n if (eng) { eng.tick(); }")
9
+
10
+ # Fix 2: Update the success message to handle no-engine case
11
+ patch("RV-001b: handle no-engine case in force-learn",
12
+ ruvector_cli,
13
+ "if (eng) { eng.tick(); }\n console.log(JSON.stringify({ success: true, result: 'Learning cycle triggered', stats: intel.stats() }));",
14
+ "if (eng) { eng.tick(); }\n console.log(JSON.stringify({ success: true, result: eng ? 'Learning cycle triggered' : 'Engine not available', stats: intel.stats() }));")
@@ -0,0 +1,2 @@
1
+ package: ruvector
2
+ grep "Need engine for tick" bin/cli.js
@@ -0,0 +1,28 @@
1
+ # RV-002: activeTrajectories not loaded from saved file
2
+
3
+ **Severity**: High
4
+ **GitHub**: [#1157](https://github.com/ruvnet/claude-flow/issues/1157)
5
+
6
+ ## Root Cause
7
+
8
+ The `load()` method in the Intelligence class (line ~2721) doesn't include
9
+ `activeTrajectories` in the returned object. When `trajectory-begin` saves an
10
+ active trajectory, it's written to the file, but the next command
11
+ (`trajectory-step`) creates a new Intelligence instance that doesn't load
12
+ `activeTrajectories` back from the file.
13
+
14
+ This causes `trajectory-step` and `trajectory-end` to fail with
15
+ "No active trajectory" error.
16
+
17
+ ## Fix
18
+
19
+ 1. Add `activeTrajectories: {}` to the defaults object
20
+ 2. Add `activeTrajectories: data.activeTrajectories || {}` to the loaded data return
21
+
22
+ ## Files Patched
23
+
24
+ - `ruvector/bin/cli.js`
25
+
26
+ ## Ops
27
+
28
+ 2 ops in fix.py
@@ -0,0 +1,14 @@
1
+ # RV-002: activeTrajectories not loaded from saved file
2
+ # The load() method doesn't include activeTrajectories in the return object
3
+
4
+ # Fix 1: Add activeTrajectories to defaults
5
+ patch("RV-002a: add activeTrajectories to defaults",
6
+ ruvector_cli,
7
+ "stats: { total_patterns: 0, total_memories: 0, total_trajectories: 0, total_errors: 0, session_count: 0, last_session: 0 }\n };",
8
+ "stats: { total_patterns: 0, total_memories: 0, total_trajectories: 0, total_errors: 0, session_count: 0, last_session: 0 },\n activeTrajectories: {}\n };")
9
+
10
+ # Fix 2: Add activeTrajectories to loaded data return
11
+ patch("RV-002b: load activeTrajectories from file",
12
+ ruvector_cli,
13
+ "// Preserve learning data if present\n learning: data.learning || undefined",
14
+ "// Preserve learning data if present\n learning: data.learning || undefined,\n // Preserve active trajectories for cross-command persistence\n activeTrajectories: data.activeTrajectories || {}")
@@ -0,0 +1,2 @@
1
+ package: ruvector
2
+ grep "activeTrajectories: data.activeTrajectories" bin/cli.js
@@ -0,0 +1,31 @@
1
+ # RV-003: trajectory-end does not update stats counters
2
+
3
+ **Severity**: Medium
4
+ **GitHub**: [ruv-FANN#186](https://github.com/ruvnet/ruv-FANN/issues/186)
5
+
6
+ ## Root Cause
7
+
8
+ The `hooks trajectory-end` command pushes completed trajectories to
9
+ `data.trajectories[]` and calls `intel.save()`, but never syncs the
10
+ `data.stats.total_trajectories` counter. The `hooks stats` command reads
11
+ the stale counter and reports 0 trajectories even when the array has entries.
12
+
13
+ Compare with `learn()` which correctly does:
14
+ ```javascript
15
+ this.data.stats.total_trajectories = this.data.trajectories.length;
16
+ ```
17
+
18
+ ## Fix
19
+
20
+ Add stats counter sync before `intel.save()` in the `trajectory-end` handler:
21
+ - `total_trajectories` from `trajectories.length`
22
+ - `total_patterns` from `Object.keys(patterns).length`
23
+ - `total_memories` from `memories.length`
24
+
25
+ ## Files Patched
26
+
27
+ - `bin/cli.js` (ruvector)
28
+
29
+ ## Ops
30
+
31
+ 1 op in fix.py
@@ -0,0 +1,18 @@
1
+ # RV-003: trajectory-end does not update stats counters
2
+ # GitHub: #186 (ruv-FANN)
3
+
4
+ patch("RV-003a: sync stats counters before save in trajectory-end",
5
+ ruvector_cli,
6
+ """ if (!intel.data.trajectories) intel.data.trajectories = [];
7
+ intel.data.trajectories.push(traj);
8
+ delete trajectories[latestTrajId];
9
+ intel.save();""",
10
+ """ if (!intel.data.trajectories) intel.data.trajectories = [];
11
+ intel.data.trajectories.push(traj);
12
+ delete trajectories[latestTrajId];
13
+ // RV-003: sync stats counters from actual data before saving
14
+ if (!intel.data.stats) intel.data.stats = {};
15
+ intel.data.stats.total_trajectories = intel.data.trajectories.length;
16
+ intel.data.stats.total_patterns = Object.keys(intel.data.patterns || {}).length;
17
+ intel.data.stats.total_memories = (intel.data.memories || []).length;
18
+ intel.save();""")
@@ -0,0 +1,2 @@
1
+ package: ruvector
2
+ grep "RV-003: sync stats" bin/cli.js
@@ -0,0 +1,29 @@
1
+ # SG-001: Init generates invalid settings
2
+
3
+ **Severity**: High
4
+ **GitHub**: [#1150](https://github.com/ruvnet/claude-flow/issues/1150)
5
+
6
+ ## Root Cause
7
+
8
+ 1. **Invalid hook events**: `TeammateIdle` and `TaskCompleted` are not valid Claude Code hooks
9
+ 2. **Overly broad permissions**: Glob patterns like `Bash(npx @claude-flow*)` match unintended commands
10
+ 3. **Relative hook paths**: `node .claude/helpers/` breaks when running from subdirectories
11
+ 4. **Phantom statusLine config**: `--minimal` and `init hooks` emit `statusLine` config
12
+ referencing `statusline.cjs` but the file is never generated (`components.statusline: false`)
13
+ 5. **MINIMAL statusline inconsistency**: `MINIMAL_INIT_OPTIONS` inherits
14
+ `statusline.enabled: true` from DEFAULT but sets `components.statusline: false`
15
+
16
+ ## Fix
17
+
18
+ Replace invalid hooks with `SubagentStop` (valid event), fix permission patterns, use
19
+ `$CLAUDE_PROJECT_DIR` for all hook paths, gate statusLine config emission on
20
+ `components.statusline`, and override `statusline.enabled` to `false` in MINIMAL preset.
21
+
22
+ ## Files Patched
23
+
24
+ - `init/settings-generator.js`
25
+ - `init/types.js`
26
+
27
+ ## Ops
28
+
29
+ 5 ops in fix.py (SG-001a: replace invalid hooks, SG-001b: fix permissions, SG-001c: CLAUDE_PROJECT_DIR paths, SG-001d: gate statusLine on component flag, SG-001e: MINIMAL statusline.enabled=false)
@@ -0,0 +1,143 @@
1
+ # SG-001: Init generates invalid settings
2
+ # GitHub: #1150
3
+ #
4
+ # Problems:
5
+ # 1. TeammateIdle and TaskCompleted are not valid Claude Code hook events
6
+ # 2. Permission patterns are too broad (glob wildcards)
7
+ # 3. Hook paths use relative .claude/helpers/ which breaks from subdirectories
8
+ #
9
+ # Fix: Replace invalid hooks with SubagentStop, fix permissions, use $CLAUDE_PROJECT_DIR
10
+
11
+ # SG-001a: Replace invalid hooks with SubagentStop (with correct $CLAUDE_PROJECT_DIR paths)
12
+ patch("SG-001a: replace invalid hooks with SubagentStop",
13
+ SETTINGS_GEN,
14
+ """ // SubagentStart — status update
15
+ hooks.SubagentStart = [
16
+ {
17
+ hooks: [
18
+ {
19
+ type: 'command',
20
+ command: 'node .claude/helpers/hook-handler.cjs status',
21
+ timeout: 3000,
22
+ },
23
+ ],
24
+ },
25
+ ];
26
+ // TeammateIdle — auto-assign pending tasks to idle teammates
27
+ hooks.TeammateIdle = [
28
+ {
29
+ hooks: [
30
+ {
31
+ type: 'command',
32
+ command: 'node .claude/helpers/hook-handler.cjs post-task',
33
+ timeout: 5000,
34
+ },
35
+ ],
36
+ },
37
+ ];
38
+ // TaskCompleted — train patterns and record completion
39
+ hooks.TaskCompleted = [
40
+ {
41
+ hooks: [
42
+ {
43
+ type: 'command',
44
+ command: 'node .claude/helpers/hook-handler.cjs post-task',
45
+ timeout: 5000,
46
+ },
47
+ ],
48
+ },
49
+ ];
50
+ return hooks;""",
51
+ """ // SubagentStart — status update
52
+ hooks.SubagentStart = [
53
+ {
54
+ hooks: [
55
+ {
56
+ type: 'command',
57
+ command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs status',
58
+ timeout: 3000,
59
+ },
60
+ ],
61
+ },
62
+ ];
63
+ // SubagentStop — task completion + teammate idle (replaces invalid TeammateIdle/TaskCompleted)
64
+ hooks.SubagentStop = [
65
+ {
66
+ hooks: [
67
+ {
68
+ type: 'command',
69
+ command: 'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/hook-handler.cjs post-task',
70
+ timeout: 5000,
71
+ },
72
+ {
73
+ type: 'command',
74
+ command: 'npx @claude-flow/cli@latest hooks teammate-idle',
75
+ timeout: 5000,
76
+ },
77
+ ],
78
+ },
79
+ ];
80
+ // TeammateIdle removed — not a valid Claude Code hook event (see #1150)
81
+ // TaskCompleted removed — not a valid Claude Code hook event (see #1150)
82
+ return hooks;""")
83
+
84
+ # SG-001b: Fix permission patterns (too broad) and add $CLAUDE_PROJECT_DIR
85
+ patch("SG-001b: fix permissions",
86
+ SETTINGS_GEN,
87
+ """ settings.permissions = {
88
+ allow: [
89
+ 'Bash(npx @claude-flow*)',
90
+ 'Bash(npx claude-flow*)',
91
+ 'Bash(node .claude/*)',
92
+ 'mcp__claude-flow__:*',
93
+ ],""",
94
+ """ settings.permissions = {
95
+ allow: [
96
+ 'Bash(npx @claude-flow/cli:*)',
97
+ 'Bash(npx claude-flow:*)',
98
+ 'Bash(node "$CLAUDE_PROJECT_DIR"/.claude/*)',
99
+ 'mcp__claude-flow__:*',
100
+ ],""")
101
+
102
+ # SG-001c: Fix all other hook paths to use $CLAUDE_PROJECT_DIR
103
+ # (catches statusline, pre-bash, post-edit, route, session hooks, etc.)
104
+ patch_all("SG-001c: use CLAUDE_PROJECT_DIR for all hook paths",
105
+ SETTINGS_GEN,
106
+ "command: 'node .claude/helpers/",
107
+ 'command: \'node "$CLAUDE_PROJECT_DIR"/.claude/helpers/')
108
+
109
+ # SG-001d: statusLine config emitted even when statusline component is off
110
+ # MINIMAL_INIT_OPTIONS has components.statusline=false but statusline.enabled=true.
111
+ # Settings-generator checks statusline.enabled, emitting statusLine config for a
112
+ # file that won't exist. Gate on components.statusline too.
113
+ patch("SG-001d: only emit statusLine when statusline component is generated",
114
+ SETTINGS_GEN,
115
+ """ if (options.statusline.enabled) {""",
116
+ """ // SG-001: Only emit statusLine config if the component will actually be generated
117
+ if (options.components.statusline && options.statusline.enabled) {""")
118
+
119
+ # SG-001e: MINIMAL_INIT_OPTIONS inherits statusline.enabled=true from DEFAULT
120
+ # but sets components.statusline=false. Override to prevent inconsistency.
121
+ # (SG-001d guards at the consumer; this fixes the producer for MINIMAL)
122
+ patch("SG-001e: MINIMAL statusline.enabled matches components.statusline",
123
+ TYPES,
124
+ """ hooks: {
125
+ ...DEFAULT_INIT_OPTIONS.hooks,
126
+ userPromptSubmit: false,
127
+ stop: false,
128
+ notification: false,
129
+ },
130
+ skills: {""",
131
+ """ hooks: {
132
+ ...DEFAULT_INIT_OPTIONS.hooks,
133
+ userPromptSubmit: false,
134
+ stop: false,
135
+ notification: false,
136
+ },
137
+ // SG-001: statusline file not generated (components.statusline: false)
138
+ // so disable the feature flag to prevent dangling settings.json references
139
+ statusline: {
140
+ ...DEFAULT_INIT_OPTIONS.statusline,
141
+ enabled: false,
142
+ },
143
+ skills: {""")
@@ -0,0 +1,4 @@
1
+ grep "hooks.SubagentStop" init/settings-generator.js
2
+ grep "CLAUDE_PROJECT_DIR" init/settings-generator.js
3
+ grep "components.statusline && options.statusline.enabled" init/settings-generator.js
4
+ grep "SG-001" init/types.js
@@ -0,0 +1,60 @@
1
+ # SG-003: Init missing helpers for --dual, --minimal, hooks, and upgrade paths
2
+
3
+ **Severity**: Critical
4
+ **GitHub**: [#1169](https://github.com/ruvnet/claude-flow/issues/1169)
5
+
6
+ ## Root Cause
7
+
8
+ Multiple `init` code paths generate `settings.json` (which references `hook-handler.cjs`,
9
+ `auto-memory-hook.mjs`, `statusline.cjs`) without generating the helper files those hooks need.
10
+
11
+ | Path | Generates settings? | Generates helpers? | Result |
12
+ |------|--------------------|--------------------|--------|
13
+ | `init` (default) | YES | YES | OK |
14
+ | `init --dual` | NO (bypasses executeInit) | NO | Broken: no Claude infra despite CLAUDE.md |
15
+ | `init --codex` | NO (bypasses executeInit) | NO | OK (no Claude Code expected) |
16
+ | `init --minimal` | YES | NO (helpers: false) | Broken: dangling settings refs |
17
+ | `init hooks` | YES | NO (helpers: false) | Broken: dangling settings refs |
18
+ | `init upgrade` | Only with --settings | Partial (3 of 8) | Broken: missing router/session/memory |
19
+ | `init wizard` | YES | YES (default) | OK |
20
+
21
+ Additionally:
22
+ - `helpers-generator.js` generates a `hook-handler.cjs` that hardcodes `require('router.js')`
23
+ instead of `require('router.cjs')`, failing when `package.json` has `"type": "module"`.
24
+ - `executeUpgrade()` only upgrades 3 critical helpers but `hook-handler.cjs` needs 6.
25
+ - `executeUpgrade()` fallback also only generates 3 in `generatedCritical`.
26
+
27
+ ## Fix
28
+
29
+ 7 ops across 4 files:
30
+
31
+ 1. **init.js** — After `--dual` codex init succeeds, call `executeInit()` with
32
+ all components so full Claude Code infrastructure is created.
33
+ 2. **executor.js** — When `settings` is generated but `helpers` is not, also generate
34
+ the critical helpers that `settings.json` references (fixes `--minimal` and `init hooks`).
35
+ 3. **executor.js** — Expand `executeUpgrade()` critical helpers list to include `router.cjs`,
36
+ `session.cjs`, `memory.cjs`.
37
+ 4. **helpers-generator.js** — Fix generated `hook-handler.cjs` to `require('router.cjs')`
38
+ instead of `require('router.js')` (same for session and memory).
39
+ 5. **hook-handler.cjs** (source template) — Fix source-shipped copy to use `.cjs` requires.
40
+ 6. **executor.js** — Expand `executeUpgrade()` fallback `generatedCritical` to include
41
+ `router.cjs`, `session.cjs`, `memory.cjs` when source helpers aren't found.
42
+ 7. **init.js** — Transition op: update `--dual` components from `skills: false` to `true`.
43
+
44
+ ## Files Patched
45
+
46
+ - `commands/init.js`
47
+ - `init/executor.js`
48
+ - `init/helpers-generator.js`
49
+ - `<pkg-root>/.claude/helpers/hook-handler.cjs` (source template)
50
+
51
+ ## Dependencies
52
+
53
+ Depends on IN-001 (170) — SG-003's `old_string` contains code introduced by IN-001.
54
+
55
+ ## Ops
56
+
57
+ 7 ops (11 patch calls) in fix.py
58
+
59
+ Note: .js copies of .cjs helpers are not needed. All require() paths use .cjs
60
+ exclusively after ops d-i. The former SG-002 compat copy approach was retired.
@@ -0,0 +1,165 @@
1
+ # SG-003: Init missing helpers for --dual, --minimal, hooks, and upgrade paths
2
+ # GitHub: #1169
3
+ #
4
+ # Root cause:
5
+ # 1. init --dual bypasses executeInit() entirely — no .claude/helpers/ created
6
+ # 2. init --minimal and init hooks set components.helpers=false but settings=true
7
+ # so settings.json references helpers that don't exist
8
+ # 3. executeUpgrade() only upgrades 3 of 8 helpers (missing router/session/memory)
9
+ # 4. helpers-generator.js generates hook-handler.cjs with require('router.js')
10
+ # instead of require('router.cjs'), failing with "type":"module"
11
+ #
12
+ # 5 ops: dual path (init.js), settings guard (executor.js),
13
+ # upgrade helpers (executor.js), generated requires (helpers-generator.js),
14
+ # source-shipped hook-handler.cjs requires (SRC_HOOK_HANDLER)
15
+
16
+ # Op 1: init --dual should also generate Claude Code infrastructure
17
+ # After codex init succeeds, call executeInit() for helpers/settings/statusline
18
+ patch("SG-003a: --dual also generates helpers + settings via executeInit",
19
+ INIT_CMD,
20
+ """ // If codex mode, use the Codex initializer
21
+ if (codexMode || dualMode) {
22
+ return initCodexAction(ctx, { codexMode, dualMode, force, minimal, full });
23
+ }""",
24
+ """ // If codex mode, use the Codex initializer
25
+ if (codexMode || dualMode) {
26
+ const codexResult = await initCodexAction(ctx, { codexMode, dualMode, force, minimal, full });
27
+ // SG-003: --dual must also create Claude Code infrastructure (.claude/helpers + settings)
28
+ if (dualMode) {
29
+ try {
30
+ await executeInit({
31
+ ...DEFAULT_INIT_OPTIONS,
32
+ targetDir: cwd,
33
+ force,
34
+ components: {
35
+ settings: true,
36
+ helpers: true,
37
+ statusline: true,
38
+ skills: true,
39
+ commands: true,
40
+ agents: true,
41
+ mcp: true,
42
+ runtime: false,
43
+ claudeMd: false,
44
+ },
45
+ });
46
+ } catch { /* non-fatal — codex init already succeeded */ }
47
+ }
48
+ return codexResult;
49
+ }""")
50
+
51
+ # Op 2: When settings is generated but helpers component is off, still generate
52
+ # the critical helpers that settings.json references
53
+ patch("SG-003b: generate critical helpers when settings references them",
54
+ EXECUTOR,
55
+ """ // Generate helpers
56
+ if (options.components.helpers) {
57
+ await writeHelpers(targetDir, options, result);
58
+ }""",
59
+ """ // Generate helpers
60
+ if (options.components.helpers) {
61
+ await writeHelpers(targetDir, options, result);
62
+ }
63
+ // SG-003: If settings will be generated but helpers were skipped,
64
+ // generate the critical helpers that settings.json hooks reference
65
+ else if (options.components.settings) {
66
+ const hDir = path.join(targetDir, '.claude', 'helpers');
67
+ fs.mkdirSync(hDir, { recursive: true });
68
+ const criticalForSettings = {
69
+ 'hook-handler.cjs': generateHookHandler(),
70
+ 'auto-memory-hook.mjs': generateAutoMemoryHook(),
71
+ };
72
+ for (const [name, content] of Object.entries(criticalForSettings)) {
73
+ const fp = path.join(hDir, name);
74
+ if (!fs.existsSync(fp)) {
75
+ fs.writeFileSync(fp, content, 'utf-8');
76
+ try { fs.chmodSync(fp, '755'); } catch {}
77
+ result.created.files.push(`.claude/helpers/${name}`);
78
+ }
79
+ }
80
+ }""")
81
+
82
+ # Op 3: Expand executeUpgrade() critical helpers to include router/session/memory
83
+ # and add compat-copy sweep after statusline
84
+ patch("SG-003c: upgrade generates all helpers + compat sweep",
85
+ EXECUTOR,
86
+ """ const criticalHelpers = ['auto-memory-hook.mjs', 'hook-handler.cjs', 'intelligence.cjs'];""",
87
+ """ const criticalHelpers = ['auto-memory-hook.mjs', 'hook-handler.cjs', 'intelligence.cjs', 'router.cjs', 'session.cjs', 'memory.cjs'];""")
88
+
89
+ # Op 4: Fix generated hook-handler.cjs to require .cjs instead of .js
90
+ # This is the fallback generator used when source helpers aren't found
91
+ patch_all("SG-003d: generated hook-handler requires .cjs not .js",
92
+ HELPERS_GEN,
93
+ """safeRequire(path.join(helpersDir, 'router.js'))""",
94
+ """safeRequire(path.join(helpersDir, 'router.cjs'))""")
95
+
96
+ patch_all("SG-003e: generated hook-handler requires session.cjs",
97
+ HELPERS_GEN,
98
+ """safeRequire(path.join(helpersDir, 'session.js'))""",
99
+ """safeRequire(path.join(helpersDir, 'session.cjs'))""")
100
+
101
+ patch_all("SG-003f: generated hook-handler requires memory.cjs",
102
+ HELPERS_GEN,
103
+ """safeRequire(path.join(helpersDir, 'memory.js'))""",
104
+ """safeRequire(path.join(helpersDir, 'memory.cjs'))""")
105
+
106
+ # Op 5: Fix the source-shipped hook-handler.cjs (copied by writeHelpers when source found)
107
+ # This file is at <pkg-root>/.claude/helpers/hook-handler.cjs and gets copied as-is
108
+ patch_all("SG-003g: source hook-handler requires router.cjs",
109
+ SRC_HOOK_HANDLER,
110
+ """safeRequire(path.join(helpersDir, 'router.js'))""",
111
+ """safeRequire(path.join(helpersDir, 'router.cjs'))""")
112
+
113
+ patch_all("SG-003h: source hook-handler requires session.cjs",
114
+ SRC_HOOK_HANDLER,
115
+ """safeRequire(path.join(helpersDir, 'session.js'))""",
116
+ """safeRequire(path.join(helpersDir, 'session.cjs'))""")
117
+
118
+ patch_all("SG-003i: source hook-handler requires memory.cjs",
119
+ SRC_HOOK_HANDLER,
120
+ """safeRequire(path.join(helpersDir, 'memory.js'))""",
121
+ """safeRequire(path.join(helpersDir, 'memory.cjs'))""")
122
+
123
+ # Op 6: Fix executeUpgrade() fallback — generatedCritical missing router/session/memory
124
+ # When source helpers aren't found, only 3 files were generated but hook-handler.cjs needs 6
125
+ # Also replaces generateIntelligenceStub() → intelligenceContent (set by IN-001a above)
126
+ patch("SG-003j: upgrade fallback generates router/session/memory",
127
+ EXECUTOR,
128
+ """ const generatedCritical = {
129
+ 'hook-handler.cjs': generateHookHandler(),
130
+ 'intelligence.cjs': generateIntelligenceStub(),
131
+ 'auto-memory-hook.mjs': generateAutoMemoryHook(),
132
+ };""",
133
+ """ const generatedCritical = {
134
+ 'hook-handler.cjs': generateHookHandler(),
135
+ 'intelligence.cjs': intelligenceContent,
136
+ 'auto-memory-hook.mjs': generateAutoMemoryHook(),
137
+ // SG-003: hook-handler.cjs requires these — generate fallback versions
138
+ 'router.cjs': generateAgentRouter(),
139
+ 'session.cjs': generateSessionManager(),
140
+ 'memory.cjs': generateMemoryHelper(),
141
+ };""")
142
+
143
+ # Transition: update caches that already have old SG-003a (skills: false) to new (skills: true)
144
+ # On fresh cache SG-003a applies directly; this skips (new already present).
145
+ # On pre-patched cache SG-003a warns (upstream old_string gone); this catches the delta.
146
+ patch("SG-003l: --dual enables skills/commands/agents (transition)",
147
+ INIT_CMD,
148
+ """ skills: false,
149
+ commands: false,
150
+ agents: false,
151
+ mcp: true,
152
+ runtime: false,
153
+ claudeMd: false,
154
+ },
155
+ });
156
+ } catch { /* non-fatal — codex init already succeeded */ }""",
157
+ """ skills: true,
158
+ commands: true,
159
+ agents: true,
160
+ mcp: true,
161
+ runtime: false,
162
+ claudeMd: false,
163
+ },
164
+ });
165
+ } catch { /* non-fatal — codex init already succeeded */ }""")
@@ -0,0 +1,3 @@
1
+ grep "SG-003" commands/init.js
2
+ grep "SG-003" init/executor.js
3
+ grep "router.cjs" init/helpers-generator.js
@@ -0,0 +1,11 @@
1
+ # UI-001: intelligence stats crashes on .toFixed()
2
+ **Severity**: Critical
3
+ **GitHub**: [#1145](https://github.com/ruvnet/claude-flow/issues/1145)
4
+ ## Root Cause
5
+ `hooks intelligence stats` calls `.toFixed()` on potentially undefined properties (learningTimeMs, adaptationTimeMs, avgQuality, routingAccuracy, loadBalance, cacheHitRate, performance.*) without null checks. Crashes when the intelligence system returns incomplete data.
6
+ ## Fix
7
+ Add null checks with 'N/A' fallback for all numeric display values. Wrap performance section in an `if (result.performance)` guard.
8
+ ## Files Patched
9
+ - commands/hooks.js
10
+ ## Ops
11
+ 7 ops in fix.py