@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
package/README.md ADDED
@@ -0,0 +1,351 @@
1
+ # @sparkleideas/claude-flow-patch
2
+
3
+ ## Contents
4
+
5
+ - [Quick Start](#quick-start)
6
+ - [CLI Commands](#cli-commands)
7
+ - [How It Works](#how-it-works)
8
+ - [Sentinel Files](#sentinel-files)
9
+ - [Target Packages](#target-packages)
10
+ - [Dependency Order](#dependency-order)
11
+ - [Key Design Decisions](#key-design-decisions)
12
+ - [Repository Structure](#repository-structure)
13
+ - [Defect Index](#defect-index)
14
+ - [Init-Script Patches](#init-script-patches)
15
+ - [Compatibility](#compatibility)
16
+ - [Links](#links)
17
+
18
+ ---
19
+
20
+ Community patches for [`@claude-flow/cli`](https://www.npmjs.com/package/@claude-flow/cli) **v3.1.0-alpha.41**, [`ruvector`](https://www.npmjs.com/package/ruvector), and [`ruv-swarm`](https://www.npmjs.com/package/ruv-swarm) **v1.0.20**.
21
+
22
+ These patches fix 29 defects across 13 categories. They are applied at runtime via idempotent Python scripts that perform targeted string replacements on the npx-cached source files.
23
+
24
+ <a id="quick-start"></a>
25
+
26
+ ## Quick Start
27
+
28
+ **Patch before init.** Several patches fix the init/generator scripts. If you run `claude-flow init` before patching, the generated `.claude/helpers/` files will be stubs with no learning, no PageRank, and no-op feedback. Always patch first:
29
+
30
+ ```bash
31
+ # 1. Patch first -- fixes the init generators
32
+ npx --yes @sparkleideas/claude-flow-patch --global
33
+
34
+ # 2. Then init (or re-init if already initialized)
35
+ npx @claude-flow/cli@latest init # fresh project
36
+ npx @claude-flow/cli@latest init upgrade # existing project
37
+
38
+ # 3. Verify
39
+ npx --yes @sparkleideas/claude-flow-patch check
40
+ ```
41
+
42
+ If you already initialized before patching:
43
+
44
+ ```bash
45
+ npx --yes @sparkleideas/claude-flow-patch repair --target /path/to/project
46
+ ```
47
+
48
+ ### Target Options
49
+
50
+ ```bash
51
+ npx --yes @sparkleideas/claude-flow-patch # global npx cache (default)
52
+ npx --yes @sparkleideas/claude-flow-patch --global # explicit global
53
+ npx --yes @sparkleideas/claude-flow-patch --target ~/my-project # project's node_modules
54
+ npx --yes @sparkleideas/claude-flow-patch --global --target ~/my-project # both
55
+ ```
56
+
57
+ `npx @claude-flow/cli` uses local `node_modules` if present, otherwise the global npx cache. Use `--target` to patch a project's local install.
58
+
59
+ <a id="cli-commands"></a>
60
+
61
+ ## CLI Commands
62
+
63
+ | Command | Purpose |
64
+ |---|---|
65
+ | `claude-flow-patch [--global] [--target <dir>]` | Apply all patches (default: `--global`) |
66
+ | `claude-flow-patch apply <ID>` | Apply a single patch by defect ID (e.g. `SG-002`) |
67
+ | `claude-flow-patch check` | Verify patch sentinels and auto-detect drift |
68
+ | `claude-flow-patch repair --target <dir> [--source auto\|local\|global] [--dry-run]` | Rehydrate `.claude/helpers` in projects initialized before patching |
69
+
70
+ <a id="how-it-works"></a>
71
+
72
+ ## How It Works
73
+
74
+ 1. `patch-all.sh` locates the `@claude-flow/cli` dist files in the npm/npx cache
75
+ 2. Globs `patch/*/fix.py` (numeric prefixes on directories ensure correct execution order)
76
+ 3. Concatenates `lib/common.py` with each `fix.py` and runs as a single Python process
77
+ 4. Each patch is idempotent: skips if already applied, warns if source changed
78
+
79
+ The `check-patches.sh` sentinel runs on session start to detect npx cache wipes and auto-reapply. It reads `sentinel` files from each patch directory — no hardcoded patch list.
80
+
81
+ <a id="sentinel-files"></a>
82
+
83
+ ### Sentinel Files
84
+
85
+ Each patch directory contains a `sentinel` file that declares how to verify the patch is applied:
86
+
87
+ ```
88
+ grep "pattern to find" relative/path/to/file.js
89
+ absent "pattern that should NOT exist" relative/path.js
90
+ none
91
+ package: ruvector
92
+ ```
93
+
94
+ | Directive | Meaning |
95
+ |-----------|---------|
96
+ | `grep "..." file` | Pass if pattern is found in file (standard check) |
97
+ | `absent "..." file` | Pass if pattern is **not** found (removal check) |
98
+ | `none` | No sentinel — skip verification |
99
+ | `package: X` | Target package (default: `@claude-flow/cli`). Skipped if package not installed |
100
+
101
+ `check-patches.sh` and `lib/discover.mjs` both read these files dynamically. Adding a new patch requires no edits to any script — just create the `sentinel` file in the new patch directory.
102
+
103
+ <a id="target-packages"></a>
104
+
105
+ ### Target Packages
106
+
107
+ | Package | Version | Location | Env var |
108
+ |---------|---------|----------|---------|
109
+ | `@claude-flow/cli` | `3.1.0-alpha.41` | `~/.npm/_npx/*/node_modules/@claude-flow/cli/dist/src/` | `BASE` |
110
+ | `ruvector` | (bundled) | `~/.npm/_npx/*/node_modules/ruvector/bin/cli.js` | `RUVECTOR_CLI` |
111
+ | `ruv-swarm` | `1.0.20` | `~/.npm/_npx/*/node_modules/ruv-swarm/` | (found via glob) |
112
+
113
+ `BASE` is set by `patch-all.sh`. All path variables in `lib/common.py` derive from it.
114
+ `RUVECTOR_CLI` is set by `patch-all.sh` to the ruvector CLI entry point.
115
+ RS-001 locates its own target via `find`.
116
+
117
+ <a id="dependency-order"></a>
118
+
119
+ ### Dependency Order
120
+
121
+ Execution order is controlled by 3-digit numeric prefixes on directory names (e.g. `010-CF-001-*`,
122
+ `170-IN-001-*`). `patch-all.sh` globs `patch/*/fix.py`, which sorts lexicographically — numeric
123
+ prefixes guarantee correct order.
124
+
125
+ Two dependency chains exist:
126
+
127
+ | Chain | Directories | Reason |
128
+ |-------|-------------|--------|
129
+ | IN-001 -> SG-003 | `170-IN-001-*` before `270-SG-003-*` | SG-003's patch targets code introduced by IN-001 |
130
+ | NS-001 -> NS-002 -> NS-003 | `190-NS-001-*` before `200-NS-002-*` before `210-NS-003-*` | Sequential namespace fixes |
131
+
132
+ All other patches are independent.
133
+
134
+ <a id="key-design-decisions"></a>
135
+
136
+ ### Key Design Decisions
137
+
138
+ - **Zero-maintenance discovery**: `patch-all.sh`, `check-patches.sh`, and doc generation all discover patches dynamically — no hardcoded lists.
139
+ - **Idempotent**: `patch()` checks if `new` string is already present before replacing.
140
+ - **Non-destructive**: patches only modify the npx cache, never the npm registry package.
141
+ - **Platform-aware**: DM-003 is macOS-only (auto-skipped on Linux).
142
+ - **Sentinel-guarded**: `check-patches.sh` reads `sentinel` files from each patch directory to detect cache wipes and auto-reapply.
143
+
144
+ <a id="repository-structure"></a>
145
+
146
+ ### Repository Structure
147
+
148
+ ```
149
+ claude-flow-patch/
150
+ README.md # This file
151
+ CLAUDE.md # Claude Code instructions (defect workflow, policies)
152
+ AGENTS.md # Codex agent configuration
153
+ patch-all.sh # Apply all patches (globs patch/*/fix.py dynamically)
154
+ check-patches.sh # Sentinel: reads patch/*/sentinel files dynamically
155
+ repair-post-init.sh # Post-init helper repair
156
+ lib/
157
+ common.py # Shared patch()/patch_all() helpers + path variables
158
+ discover.mjs # Dynamic patch discovery — single source of truth
159
+ categories.json # Prefix-to-label mapping (e.g. HW → Headless Worker)
160
+ scripts/
161
+ preflight.mjs # Pre-commit sync: doc tables, versions, config
162
+ patch/
163
+ {NNN}-{PREFIX}-{NNN}-{slug}/ # NNN = 3-digit execution order
164
+ README.md # Defect report: title, severity, root cause, fix
165
+ fix.py # Idempotent patch script
166
+ fix.sh # Shell-based patch script (EM-002 only)
167
+ sentinel # Verification directives for check-patches.sh
168
+ (29 defect directories total)
169
+ ```
170
+
171
+ <a id="defect-index"></a>
172
+
173
+ ## Defect Index
174
+
175
+ <!-- GENERATED:defect-index:begin -->
176
+ 35 defects across 13 categories.
177
+
178
+ ### CF -- Config & Doctor
179
+
180
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
181
+ |----|-------------|----------|--------------|
182
+ | [CF&#8209;001](patch/010-CF-001-doctor-yaml/) | Doctor ignores YAML config files | Low | [#1141](https://github.com/ruvnet/claude-flow/issues/1141) |
183
+ | [CF&#8209;002](patch/020-CF-002-config-export-yaml/) | Config export shows hardcoded defaults | Medium | [#1142](https://github.com/ruvnet/claude-flow/issues/1142) |
184
+
185
+ ### DM -- Daemon & Workers
186
+
187
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
188
+ |----|-------------|----------|--------------|
189
+ | [DM&#8209;001](patch/030-DM-001-daemon-log-zero/) | daemon.log always 0 bytes | Medium | [#1116](https://github.com/ruvnet/claude-flow/issues/1116) |
190
+ | [DM&#8209;002](patch/040-DM-002-cpu-load-threshold/) | maxCpuLoad=2.0 blocks all workers on multi-core | Critical | [#1138](https://github.com/ruvnet/claude-flow/issues/1138) |
191
+ | [DM&#8209;003](patch/050-DM-003-macos-freemem/) | macOS freemem() always ~0% — workers blocked | Critical | [#1077](https://github.com/ruvnet/claude-flow/issues/1077) |
192
+ | [DM&#8209;004](patch/060-DM-004-preload-worker-stub/) | Preload worker stub + missing from defaults | Enhancement | [#1139](https://github.com/ruvnet/claude-flow/issues/1139) |
193
+ | [DM&#8209;005](patch/070-DM-005-consolidation-worker-stub/) | Consolidation worker stub (no decay/rebuild) | Enhancement | [#1140](https://github.com/ruvnet/claude-flow/issues/1140) |
194
+ | [DM&#8209;006](patch/300-DM-006-log-rotation/) | No log rotation — logs grow unbounded | Medium | [#1114](https://github.com/ruvnet/claude-flow/issues/1114) |
195
+
196
+ ### EM -- Embeddings & HNSW
197
+
198
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
199
+ |----|-------------|----------|--------------|
200
+ | [EM&#8209;001](patch/080-EM-001-embedding-ignores-config/) | Embedding system ignores project config (model + HNSW dims) | High | [#1143](https://github.com/ruvnet/claude-flow/issues/1143) |
201
+ | [EM&#8209;002](patch/090-EM-002-transformers-cache-eacces/) | @xenova/transformers cache EACCES | Medium | [#1144](https://github.com/ruvnet/claude-flow/issues/1144) |
202
+
203
+ ### GV -- Ghost Vectors
204
+
205
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
206
+ |----|-------------|----------|--------------|
207
+ | [GV&#8209;001](patch/100-GV-001-hnsw-ghost-vectors/) | HNSW ghost vectors persist after memory delete | Medium | [#1122](https://github.com/ruvnet/claude-flow/issues/1122) |
208
+
209
+ ### HK -- Hooks
210
+
211
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
212
+ |----|-------------|----------|--------------|
213
+ | [HK&#8209;001](patch/110-HK-001-post-edit-file-path/) | post-edit hook records file_path as "unknown" | Medium | [#1155](https://github.com/ruvnet/claude-flow/issues/1155) |
214
+ | [HK&#8209;002](patch/120-HK-002-hooks-tools-stub/) | MCP hook handlers are stubs that don't persist data | High | [#1058](https://github.com/ruvnet/claude-flow/issues/1058) |
215
+ | [HK&#8209;003](patch/130-HK-003-metrics-hardcoded/) | hooks_metrics MCP handler returns hardcoded fake data | High | [#1158](https://github.com/ruvnet/claude-flow/issues/1158) |
216
+ | [HK&#8209;004](patch/135-HK-004-respect-daemon-autostart/) | hooks_session-start ignores daemon.autoStart from settings.json | High | [#1175](https://github.com/ruvnet/claude-flow/issues/1175) |
217
+ | [HK&#8209;005](patch/137-HK-005-daemon-pid-guard/) | Multiple MCP servers start independent in-process daemons | Critical | [#1171](https://github.com/ruvnet/claude-flow/issues/1171) |
218
+
219
+ ### HW -- Headless Worker
220
+
221
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
222
+ |----|-------------|----------|--------------|
223
+ | [HW&#8209;001](patch/140-HW-001-stdin-hang/) | Headless workers hang — stdin pipe never closed | Critical | [#1111](https://github.com/ruvnet/claude-flow/issues/1111) |
224
+ | [HW&#8209;002](patch/150-HW-002-failures-swallowed/) | Headless failures silently swallowed as success | High | [#1112](https://github.com/ruvnet/claude-flow/issues/1112) |
225
+ | [HW&#8209;003](patch/160-HW-003-aggressive-intervals/) | Worker scheduling intervals too aggressive + settings ignored | High | [#1113](https://github.com/ruvnet/claude-flow/issues/1113) |
226
+ | [HW&#8209;004](patch/310-HW-004-runwithtimeout-orphan/) | runWithTimeout rejects but does not kill child process | Medium | [#1117](https://github.com/ruvnet/claude-flow/issues/1117) |
227
+
228
+ ### IN -- Intelligence
229
+
230
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
231
+ |----|-------------|----------|--------------|
232
+ | [IN&#8209;001](patch/170-IN-001-intelligence-stub/) | intelligence.cjs is a stub that doesn't actually learn | Critical | [#1154](https://github.com/ruvnet/claude-flow/issues/1154) |
233
+
234
+ ### MM -- Memory Management
235
+
236
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
237
+ |----|-------------|----------|--------------|
238
+ | [MM&#8209;001](patch/180-MM-001-memory-persist-path/) | Remove dead persistPath config option | Low | [#1152](https://github.com/ruvnet/claude-flow/issues/1152) |
239
+
240
+ ### NS -- Memory Namespace
241
+
242
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
243
+ |----|-------------|----------|--------------|
244
+ | [NS&#8209;001](patch/190-NS-001-discovery-default-namespace/) | Discovery ops default to wrong namespace | Critical | [#1123](https://github.com/ruvnet/claude-flow/issues/1123) |
245
+ | [NS&#8209;002](patch/200-NS-002-targeted-require-namespace/) | Store/delete/retrieve fall back to 'default' + accept 'all' | Critical | [#581](https://github.com/ruvnet/claude-flow/issues/581) |
246
+ | [NS&#8209;003](patch/210-NS-003-namespace-typo-pattern/) | Namespace typo 'pattern' vs 'patterns' | Medium | [#1136](https://github.com/ruvnet/claude-flow/issues/1136) |
247
+
248
+ ### RS -- ruv-swarm
249
+
250
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
251
+ |----|-------------|----------|--------------|
252
+ | [RS&#8209;001](patch/220-RS-001-better-sqlite3-node24/) | ruv-swarm MCP fails on Node 24 — better-sqlite3 missing native bindings | Critical | [ruv-FANN#185](https://github.com/ruvnet/ruv-FANN/issues/185) |
253
+
254
+ ### RV -- RuVector Intelligence
255
+
256
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
257
+ |----|-------------|----------|--------------|
258
+ | [RV&#8209;001](patch/230-RV-001-force-learn-tick/) | force-learn command calls intel.tick() which doesn't exist | Medium | [#1156](https://github.com/ruvnet/claude-flow/issues/1156) |
259
+ | [RV&#8209;002](patch/240-RV-002-trajectory-load/) | activeTrajectories not loaded from saved file | High | [#1157](https://github.com/ruvnet/claude-flow/issues/1157) |
260
+ | [RV&#8209;003](patch/250-RV-003-trajectory-stats-sync/) | trajectory-end does not update stats counters | Medium | [ruv-FANN#186](https://github.com/ruvnet/ruv-FANN/issues/186) |
261
+
262
+ ### SG -- Settings Generator
263
+
264
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
265
+ |----|-------------|----------|--------------|
266
+ | [SG&#8209;001](patch/260-SG-001-init-settings/) | Init generates invalid settings | High | [#1150](https://github.com/ruvnet/claude-flow/issues/1150) |
267
+ | [SG&#8209;003](patch/270-SG-003-init-helpers-all-paths/) | Init missing helpers for --dual, --minimal, hooks, and upgrade paths | Critical | [#1169](https://github.com/ruvnet/claude-flow/issues/1169) |
268
+ | [SG&#8209;004](patch/320-SG-004-wizard-parity/) | init wizard lacks parity with init | High | [#1181](https://github.com/ruvnet/claude-flow/issues/1181) |
269
+ | [SG&#8209;005](patch/330-SG-005-start-all-subcommand/) | add 'start all' subcommand to start everything at once | Enhancement | [#1177](https://github.com/ruvnet/claude-flow/issues/1177) |
270
+
271
+ ### UI -- Display & Cosmetic
272
+
273
+ | ID | Description <img width="500" height="1" /> | Severity | GitHub&nbsp;Issue |
274
+ |----|-------------|----------|--------------|
275
+ | [UI&#8209;001](patch/280-UI-001-intelligence-stats-crash/) | intelligence stats crashes on .toFixed() | Critical | [#1145](https://github.com/ruvnet/claude-flow/issues/1145) |
276
+ | [UI&#8209;002](patch/290-UI-002-neural-status-not-loaded/) | neural status shows "Not loaded" | Low | [#1146](https://github.com/ruvnet/claude-flow/issues/1146) |
277
+ <!-- GENERATED:defect-index:end -->
278
+
279
+ <a id="init-script-patches"></a>
280
+
281
+ ## Init-Script Patches (Local Project Action Required)
282
+
283
+ Five patches target the **init/generator scripts** (`executor.js`, `settings-generator.js`, `helpers-generator.js`). These fix the code that *generates* your `.claude/` project files -- but applying patches does **not** update files already generated in your project. You must take one additional step.
284
+
285
+ ### Affected Defects
286
+
287
+ | ID | Generator patched | Local file affected | Problem if not refreshed |
288
+ |----|-------------------|---------------------|--------------------------|
289
+ | IN-001 | `init/executor.js` | `.claude/helpers/intelligence.cjs` | 197-line stub: no PageRank, no graph, `feedback()` is a no-op, no learning |
290
+ | HK-001 | `init/helpers-generator.js` | `.claude/helpers/hook-handler.cjs` | Reads env vars instead of stdin JSON; post-edit logs `file: "unknown"` |
291
+ | SG-001 | `init/settings-generator.js` | `.claude/settings.json` | May contain invalid hook events, broad permissions, relative paths |
292
+ | SG-002 | `init/executor.js` | `.claude/helpers/*.js` / `*.cjs` | Missing .js/.cjs compat copies; `hook-handler.cjs` require() calls fail silently |
293
+ | MM-001 | `init/executor.js` | `.claude-flow/config.yaml` | Misleading `persistPath` setting that nothing reads |
294
+
295
+ ### How to Fix
296
+
297
+ **Option A: Run `repair`** (recommended)
298
+
299
+ ```bash
300
+ npx --yes @sparkleideas/claude-flow-patch --global
301
+ npx --yes @sparkleideas/claude-flow-patch repair --target .
302
+ npx --yes @sparkleideas/claude-flow-patch apply SG-002 # apply a single patch
303
+ ```
304
+
305
+ This copies patched helper files into your project and creates any missing .js/.cjs compat copies.
306
+
307
+ **Option B: Copy full helpers from the package manually**
308
+
309
+ ```bash
310
+ npx --yes @sparkleideas/claude-flow-patch --global
311
+ SRC=$(find ~/.npm/_npx -path '*/@claude-flow/cli/.claude/helpers' -type d 2>/dev/null | head -1)
312
+ for f in intelligence.cjs hook-handler.cjs session.js learning-service.mjs metrics-db.mjs statusline.cjs; do
313
+ [ -f "$SRC/$f" ] && cp "$SRC/$f" .claude/helpers/ && echo "Copied: $f"
314
+ done
315
+ ```
316
+
317
+ **Option C: Re-run init upgrade** (regenerates from patched scripts)
318
+
319
+ ```bash
320
+ npx --yes @sparkleideas/claude-flow-patch --global
321
+ npx @claude-flow/cli@latest init upgrade --force
322
+ ```
323
+
324
+ Caution: Option C may overwrite other customizations in `.claude/`.
325
+
326
+ ### Why This Happens
327
+
328
+ These patches fix the **generator functions** inside the npm package (e.g., `generateIntelligenceStub()` in `executor.js`). When the generator runs via `claude-flow init`, it produces the project files in `.claude/helpers/`. If your project was initialized *before* patches were applied, the stubs are already on disk. Patches only modify the npm package source -- they do not touch files already generated in your project.
329
+
330
+ Additionally, `init upgrade` only force-overwrites 3 "critical" helpers (`auto-memory-hook.mjs`, `hook-handler.cjs`, `intelligence.cjs`). The other 30+ helper files (shell scripts for daemon management, health monitoring, security scanning, swarm hooks, etc.) are only copied on fresh `init`, not on upgrade. If these are missing, use Option A above.
331
+
332
+ <a id="compatibility"></a>
333
+
334
+ ## Compatibility
335
+
336
+ - Tested against `@claude-flow/cli@3.1.0-alpha.41` and `ruv-swarm@1.0.20`
337
+ - Requires Python 3.6+ and Bash
338
+ - Works on Linux and macOS (DM-003 is macOS-only, auto-skipped on Linux)
339
+
340
+ <a id="links"></a>
341
+
342
+ ## Links
343
+
344
+ - Homepage: https://sparklingideas.co.uk/claude-flow/patch
345
+ - Package: https://www.npmjs.com/package/@sparkleideas/claude-flow-patch
346
+ - GitHub: https://github.com/sparkling/claude-flow-patch
347
+ - Issues: https://github.com/sparkling/claude-flow-patch/issues
348
+
349
+ ## License
350
+
351
+ MIT
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { readdirSync } from 'node:fs';
4
+ import { dirname, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const rootDir = resolve(__dirname, '..');
9
+ const patchDir = resolve(rootDir, 'patch');
10
+
11
+ const COMMAND_MAP = new Map([
12
+ ['check', 'check-patches.sh'],
13
+ ['repair', 'repair-post-init.sh'],
14
+ ]);
15
+
16
+ function findPatch(id) {
17
+ try {
18
+ const dirs = readdirSync(patchDir, { withFileTypes: true });
19
+ const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
20
+ const re = new RegExp(`^(\\d+-)?${escaped}-`);
21
+ const match = dirs.find(d => d.isDirectory() && re.test(d.name));
22
+ return match ? resolve(patchDir, match.name, 'fix.py') : null;
23
+ } catch { return null; }
24
+ }
25
+
26
+ function listPatchIds() {
27
+ try {
28
+ return readdirSync(patchDir, { withFileTypes: true })
29
+ .filter(d => d.isDirectory())
30
+ .map(d => {
31
+ const name = d.name.replace(/^\d+-/, '');
32
+ const i = name.indexOf('-', name.indexOf('-') + 1);
33
+ return i > 0 ? name.slice(0, i) : name;
34
+ })
35
+ .sort();
36
+ } catch { return []; }
37
+ }
38
+
39
+ function usage() {
40
+ console.log(`Usage:
41
+ claude-flow-patch Apply all patches (default: --global)
42
+ claude-flow-patch apply <ID> Apply a single patch by defect ID (e.g. SG-002)
43
+ claude-flow-patch check Verify patch sentinels are present
44
+ claude-flow-patch repair [options] Post-init repair
45
+
46
+ Options for default (all patches) and check:
47
+ --global Patch the npx cache (~/.npm/_npx/*)
48
+ --target <dir> Patch node_modules inside <dir>
49
+ --include <regex> Only patches matching regex (against dir name)
50
+ --exclude <regex> Skip patches matching regex (against dir name)
51
+
52
+ If neither --global nor --target is given, --global is assumed.
53
+
54
+ Examples:
55
+ claude-flow-patch --global --target ~/my-project Patch both locations
56
+ claude-flow-patch --target ~/my-project Patch only project node_modules
57
+ claude-flow-patch --include "^DM-" Only daemon patches
58
+ claude-flow-patch --exclude "^RV-" Skip ruvector patches
59
+
60
+ Options for repair:
61
+ --target <dir> Target directory
62
+ --source auto|local|global Source scope
63
+ --dry-run Show what would happen
64
+ `);
65
+ }
66
+
67
+ function run(cmd, args, opts = {}) {
68
+ const result = spawnSync(cmd, args, { stdio: 'inherit', cwd: process.cwd(), env: process.env, ...opts });
69
+ if (result.error) { console.error(result.error.message); process.exit(1); }
70
+ process.exit(result.status ?? 1);
71
+ }
72
+
73
+ // ── Parse options from anywhere in argv ──
74
+
75
+ function extractOpt(argv, name) {
76
+ const idx = argv.indexOf(name);
77
+ if (idx < 0 || idx + 1 >= argv.length) return null;
78
+ const val = argv[idx + 1];
79
+ argv.splice(idx, 2);
80
+ return val;
81
+ }
82
+
83
+ function extractFlag(argv, name) {
84
+ const idx = argv.indexOf(name);
85
+ if (idx < 0) return false;
86
+ argv.splice(idx, 1);
87
+ return true;
88
+ }
89
+
90
+ const rawArgs = process.argv.slice(2);
91
+ const includeRe = extractOpt(rawArgs, '--include');
92
+ const excludeRe = extractOpt(rawArgs, '--exclude');
93
+ const globalFlag = extractFlag(rawArgs, '--global');
94
+ const targetDir = extractOpt(rawArgs, '--target');
95
+
96
+ const [subcommand, ...args] = rawArgs;
97
+
98
+ // Pass filter regexes to patch-all.sh / check-patches.sh via env
99
+ function filterEnv() {
100
+ const env = { ...process.env };
101
+ if (includeRe) env.PATCH_INCLUDE = includeRe;
102
+ if (excludeRe) env.PATCH_EXCLUDE = excludeRe;
103
+ return env;
104
+ }
105
+
106
+ // Build --global / --target args to pass to shell scripts
107
+ function scopeArgs() {
108
+ const a = [];
109
+ if (globalFlag) a.push('--global');
110
+ if (targetDir) a.push('--target', targetDir);
111
+ return a;
112
+ }
113
+
114
+ // No args → apply all patches (most common use case)
115
+ if (!subcommand) {
116
+ run('bash', [resolve(rootDir, 'patch-all.sh'), ...scopeArgs()], { env: filterEnv() });
117
+ }
118
+
119
+ if (subcommand === '--help' || subcommand === '-h') {
120
+ usage();
121
+ process.exit(0);
122
+ }
123
+
124
+ // apply <ID> — run a single patch
125
+ if (subcommand === 'apply') {
126
+ const patchId = args[0];
127
+ if (!patchId) {
128
+ console.error('Error: apply requires a patch ID (e.g. claude-flow-patch apply SG-002)');
129
+ process.exit(1);
130
+ }
131
+ const fixPath = findPatch(patchId);
132
+ if (!fixPath) {
133
+ console.error(`Error: no patch found for ID "${patchId}"`);
134
+ console.error(`Available patches: ${listPatchIds().join(', ')}`);
135
+ process.exit(1);
136
+ }
137
+ run('python3', [fixPath, ...args.slice(1)]);
138
+ }
139
+
140
+ // Named subcommands: check, repair
141
+ const scriptName = COMMAND_MAP.get(subcommand);
142
+ if (!scriptName) {
143
+ console.error(`Unknown command: ${subcommand}`);
144
+ usage();
145
+ process.exit(1);
146
+ }
147
+
148
+ run('bash', [resolve(rootDir, scriptName), ...scopeArgs(), ...args], { env: filterEnv() });