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

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 (107) hide show
  1. package/AGENTS.md +162 -0
  2. package/CLAUDE.md +458 -0
  3. package/README.md +306 -0
  4. package/bin/claude-flow-patch.mjs +148 -0
  5. package/check-patches.sh +176 -0
  6. package/lib/categories.json +15 -0
  7. package/lib/common.py +92 -0
  8. package/lib/discover.mjs +181 -0
  9. package/package.json +85 -0
  10. package/patch/010-CF-001-doctor-yaml/README.md +11 -0
  11. package/patch/010-CF-001-doctor-yaml/fix.py +20 -0
  12. package/patch/010-CF-001-doctor-yaml/sentinel +1 -0
  13. package/patch/020-CF-002-config-export-yaml/README.md +11 -0
  14. package/patch/020-CF-002-config-export-yaml/fix.py +130 -0
  15. package/patch/020-CF-002-config-export-yaml/sentinel +1 -0
  16. package/patch/030-DM-001-daemon-log-zero/README.md +12 -0
  17. package/patch/030-DM-001-daemon-log-zero/fix.py +37 -0
  18. package/patch/030-DM-001-daemon-log-zero/sentinel +1 -0
  19. package/patch/040-DM-002-cpu-load-threshold/README.md +11 -0
  20. package/patch/040-DM-002-cpu-load-threshold/fix.py +6 -0
  21. package/patch/040-DM-002-cpu-load-threshold/sentinel +1 -0
  22. package/patch/050-DM-003-macos-freemem/README.md +11 -0
  23. package/patch/050-DM-003-macos-freemem/fix.py +7 -0
  24. package/patch/050-DM-003-macos-freemem/sentinel +1 -0
  25. package/patch/060-DM-004-preload-worker-stub/README.md +11 -0
  26. package/patch/060-DM-004-preload-worker-stub/fix.py +34 -0
  27. package/patch/060-DM-004-preload-worker-stub/sentinel +1 -0
  28. package/patch/070-DM-005-consolidation-worker-stub/README.md +11 -0
  29. package/patch/070-DM-005-consolidation-worker-stub/fix.py +46 -0
  30. package/patch/070-DM-005-consolidation-worker-stub/sentinel +1 -0
  31. package/patch/080-EM-001-embedding-ignores-config/README.md +11 -0
  32. package/patch/080-EM-001-embedding-ignores-config/fix.py +111 -0
  33. package/patch/080-EM-001-embedding-ignores-config/sentinel +1 -0
  34. package/patch/090-EM-002-transformers-cache-eacces/README.md +11 -0
  35. package/patch/090-EM-002-transformers-cache-eacces/fix.sh +12 -0
  36. package/patch/090-EM-002-transformers-cache-eacces/sentinel +1 -0
  37. package/patch/100-GV-001-hnsw-ghost-vectors/README.md +11 -0
  38. package/patch/100-GV-001-hnsw-ghost-vectors/fix.py +34 -0
  39. package/patch/100-GV-001-hnsw-ghost-vectors/sentinel +1 -0
  40. package/patch/110-HK-001-post-edit-file-path/README.md +44 -0
  41. package/patch/110-HK-001-post-edit-file-path/fix.py +23 -0
  42. package/patch/110-HK-001-post-edit-file-path/sentinel +1 -0
  43. package/patch/120-HK-002-hooks-tools-stub/README.md +36 -0
  44. package/patch/120-HK-002-hooks-tools-stub/fix.py +155 -0
  45. package/patch/120-HK-002-hooks-tools-stub/sentinel +1 -0
  46. package/patch/130-HK-003-metrics-hardcoded/README.md +30 -0
  47. package/patch/130-HK-003-metrics-hardcoded/fix.py +82 -0
  48. package/patch/130-HK-003-metrics-hardcoded/sentinel +1 -0
  49. package/patch/140-HW-001-stdin-hang/README.md +11 -0
  50. package/patch/140-HW-001-stdin-hang/fix.py +6 -0
  51. package/patch/140-HW-001-stdin-hang/sentinel +1 -0
  52. package/patch/150-HW-002-failures-swallowed/README.md +11 -0
  53. package/patch/150-HW-002-failures-swallowed/fix.py +42 -0
  54. package/patch/150-HW-002-failures-swallowed/sentinel +1 -0
  55. package/patch/160-HW-003-aggressive-intervals/README.md +11 -0
  56. package/patch/160-HW-003-aggressive-intervals/fix.py +16 -0
  57. package/patch/160-HW-003-aggressive-intervals/sentinel +1 -0
  58. package/patch/170-IN-001-intelligence-stub/README.md +64 -0
  59. package/patch/170-IN-001-intelligence-stub/fix.py +70 -0
  60. package/patch/170-IN-001-intelligence-stub/sentinel +1 -0
  61. package/patch/180-MM-001-memory-persist-path/README.md +27 -0
  62. package/patch/180-MM-001-memory-persist-path/fix.py +54 -0
  63. package/patch/180-MM-001-memory-persist-path/sentinel +1 -0
  64. package/patch/190-NS-001-discovery-default-namespace/README.md +16 -0
  65. package/patch/190-NS-001-discovery-default-namespace/fix.py +68 -0
  66. package/patch/190-NS-001-discovery-default-namespace/sentinel +2 -0
  67. package/patch/200-NS-002-targeted-require-namespace/README.md +19 -0
  68. package/patch/200-NS-002-targeted-require-namespace/fix.py +158 -0
  69. package/patch/200-NS-002-targeted-require-namespace/sentinel +2 -0
  70. package/patch/210-NS-003-namespace-typo-pattern/README.md +15 -0
  71. package/patch/210-NS-003-namespace-typo-pattern/fix.py +23 -0
  72. package/patch/210-NS-003-namespace-typo-pattern/sentinel +1 -0
  73. package/patch/220-RS-001-better-sqlite3-node24/README.md +54 -0
  74. package/patch/220-RS-001-better-sqlite3-node24/fix.py +22 -0
  75. package/patch/220-RS-001-better-sqlite3-node24/rebuild.sh +31 -0
  76. package/patch/220-RS-001-better-sqlite3-node24/sentinel +2 -0
  77. package/patch/230-RV-001-force-learn-tick/README.md +31 -0
  78. package/patch/230-RV-001-force-learn-tick/fix.py +14 -0
  79. package/patch/230-RV-001-force-learn-tick/sentinel +2 -0
  80. package/patch/240-RV-002-trajectory-load/README.md +28 -0
  81. package/patch/240-RV-002-trajectory-load/fix.py +14 -0
  82. package/patch/240-RV-002-trajectory-load/sentinel +2 -0
  83. package/patch/250-RV-003-trajectory-stats-sync/README.md +31 -0
  84. package/patch/250-RV-003-trajectory-stats-sync/fix.py +18 -0
  85. package/patch/250-RV-003-trajectory-stats-sync/sentinel +2 -0
  86. package/patch/260-SG-001-init-settings/README.md +29 -0
  87. package/patch/260-SG-001-init-settings/fix.py +143 -0
  88. package/patch/260-SG-001-init-settings/sentinel +4 -0
  89. package/patch/270-SG-003-init-helpers-all-paths/README.md +60 -0
  90. package/patch/270-SG-003-init-helpers-all-paths/fix.py +164 -0
  91. package/patch/270-SG-003-init-helpers-all-paths/sentinel +3 -0
  92. package/patch/280-UI-001-intelligence-stats-crash/README.md +11 -0
  93. package/patch/280-UI-001-intelligence-stats-crash/fix.py +57 -0
  94. package/patch/280-UI-001-intelligence-stats-crash/sentinel +1 -0
  95. package/patch/290-UI-002-neural-status-not-loaded/README.md +11 -0
  96. package/patch/290-UI-002-neural-status-not-loaded/fix.py +19 -0
  97. package/patch/290-UI-002-neural-status-not-loaded/sentinel +1 -0
  98. package/patch/300-DM-006-log-rotation/README.md +11 -0
  99. package/patch/300-DM-006-log-rotation/fix.py +58 -0
  100. package/patch/300-DM-006-log-rotation/sentinel +1 -0
  101. package/patch/310-HW-004-runwithtimeout-orphan/README.md +11 -0
  102. package/patch/310-HW-004-runwithtimeout-orphan/fix.py +10 -0
  103. package/patch/310-HW-004-runwithtimeout-orphan/sentinel +1 -0
  104. package/patch-all.sh +203 -0
  105. package/repair-post-init.sh +245 -0
  106. package/scripts/update-docs.mjs +208 -0
  107. package/scripts/upstream-log.mjs +257 -0
package/AGENTS.md ADDED
@@ -0,0 +1,162 @@
1
+ # @sparkleideas/claude-flow-patch
2
+
3
+ > Runtime patches for `@claude-flow/cli` v3.1.0-alpha.40, `ruvector`, and `ruv-swarm` v1.0.20
4
+
5
+ **Claude Code instructions are in [CLAUDE.md](CLAUDE.md). Project-specific instructions (defect index, workflows, policies) are in [README.md](README.md).**
6
+
7
+ ## Project Overview
8
+
9
+ A Claude Flow powered project
10
+
11
+ **Tech Stack**: Python (patches), Bash (orchestration)
12
+ **Architecture**: Idempotent runtime patching via string replacement
13
+
14
+ ## Quick Start
15
+
16
+ ### Apply Patches
17
+ ```bash
18
+ bash patch-all.sh
19
+ ```
20
+
21
+ ### Verify
22
+ ```bash
23
+ bash check-patches.sh
24
+ ```
25
+
26
+ ## Agent Coordination
27
+
28
+ ### Swarm Configuration
29
+
30
+ This project uses hierarchical swarm coordination for complex tasks:
31
+
32
+ | Setting | Value | Purpose |
33
+ |---------|-------|---------|
34
+ | Topology | `hierarchical` | Queen-led coordination (anti-drift) |
35
+ | Max Agents | 8 | Optimal team size |
36
+ | Strategy | `specialized` | Clear role boundaries |
37
+ | Consensus | `raft` | Leader-based consistency |
38
+
39
+ ### When to Use Swarms
40
+
41
+ **Invoke swarm for:**
42
+ - Multi-file changes (3+ files)
43
+ - New feature implementation
44
+ - Cross-module refactoring
45
+ - API changes with tests
46
+ - Security-related changes
47
+ - Performance optimization
48
+
49
+ **Skip swarm for:**
50
+ - Single file edits
51
+ - Simple bug fixes (1-2 lines)
52
+ - Documentation updates
53
+ - Configuration changes
54
+
55
+ ### Available Skills
56
+
57
+ Use `$skill-name` syntax to invoke:
58
+
59
+ | Skill | Use Case |
60
+ |-------|----------|
61
+ | `$swarm-orchestration` | Multi-agent task coordination |
62
+ | `$memory-management` | Pattern storage and retrieval |
63
+ | `$sparc-methodology` | Structured development workflow |
64
+ | `$security-audit` | Security scanning and CVE detection |
65
+
66
+ ### Agent Types
67
+
68
+ | Type | Role | Use Case |
69
+ |------|------|----------|
70
+ | `researcher` | Requirements analysis | Understanding scope |
71
+ | `architect` | System design | Planning structure |
72
+ | `coder` | Implementation | Writing code |
73
+ | `tester` | Test creation | Quality assurance |
74
+ | `reviewer` | Code review | Security and quality |
75
+
76
+ ## Code Standards
77
+
78
+ ### File Organization
79
+ - **NEVER** save to root folder
80
+ - `/src` - Source code files
81
+ - `/tests` - Test files
82
+ - `/docs` - Documentation
83
+ - `/config` - Configuration files
84
+
85
+ ### Quality Rules
86
+ - Files under 500 lines
87
+ - No hardcoded secrets
88
+ - Input validation at boundaries
89
+ - Typed interfaces for public APIs
90
+ - TDD London School (mock-first) preferred
91
+
92
+ ### Commit Messages
93
+ ```
94
+ <type>(<scope>): <description>
95
+
96
+ [optional body]
97
+
98
+ Co-Authored-By: claude-flow <ruv@ruv.net>
99
+ ```
100
+
101
+ Types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`
102
+
103
+ ## Security
104
+
105
+ ### Critical Rules
106
+ - NEVER commit secrets, credentials, or .env files
107
+ - NEVER hardcode API keys
108
+ - Always validate user input
109
+ - Use parameterized queries for SQL
110
+ - Sanitize output to prevent XSS
111
+
112
+ ### Path Security
113
+ - Validate all file paths
114
+ - Prevent directory traversal (../)
115
+ - Use absolute paths internally
116
+
117
+ ## Memory System
118
+
119
+ ### Storing Patterns
120
+ ```bash
121
+ npx @claude-flow/cli memory store \
122
+ --key "pattern-name" \
123
+ --value "pattern description" \
124
+ --namespace patterns
125
+ ```
126
+
127
+ ### Searching Memory
128
+ ```bash
129
+ npx @claude-flow/cli memory search \
130
+ --query "search terms" \
131
+ --namespace patterns
132
+ ```
133
+
134
+ ## Links
135
+
136
+ - Documentation: https://github.com/ruvnet/claude-flow
137
+ - Issues: https://github.com/ruvnet/claude-flow/issues
138
+
139
+ ## Guidance Lifecycle Wiring (Codex)
140
+
141
+ Codex does not expose Claude Code-style event-command hook maps in `config.toml`.
142
+ This project uses an explicit bridge script:
143
+
144
+ - `scripts/guidance-codex-bridge.js` -> dispatches lifecycle events to:
145
+ - `.claude/helpers/hook-handler.cjs` (enforcement path)
146
+ - optional `npx @claude-flow/cli@latest hooks ...` telemetry calls
147
+
148
+ Primary commands:
149
+
150
+ ```bash
151
+ npm run guidance:codex:session-start
152
+ npm run guidance:codex:pre-task -- --description "Implement feature X"
153
+ npm run guidance:codex:pre-command -- --command "git status"
154
+ npm run guidance:codex:pre-edit -- --file src/example.ts
155
+ npm run guidance:codex:post-edit -- --file src/example.ts
156
+ npm run guidance:codex:post-task -- --task-id task-123 --status completed
157
+ npm run guidance:codex:session-end
158
+ ```
159
+
160
+ Control flags:
161
+ - `--skip-cf-hooks` skips secondary `@claude-flow/cli` hook invocations
162
+ - `GUIDANCE_CODEX_SKIP_CF_HOOKS=1` disables secondary invocations globally
package/CLAUDE.md ADDED
@@ -0,0 +1,458 @@
1
+ # @sparkleideas/claude-flow-patch
2
+
3
+ Runtime patches for `@claude-flow/cli` **v3.1.0-alpha.41**, `ruvector`, and `ruv-swarm` **v1.0.20**.
4
+
5
+ ## Terminology
6
+
7
+ | Term | Meaning | Example |
8
+ |------|---------|---------|
9
+ | **Defect** | A tracked problem (bug or missing feature). Each defect has its own directory under `patch/` with a README.md and fix.py. | "Defect HW-001", "29 defects across 13 categories" |
10
+ | **Patch** | The code change that addresses a defect. Implemented as `fix.py` (or `fix.sh`) using `patch()`/`patch_all()` calls. We patch because we can't fix upstream. | "fix.py contains 3 patch ops" |
11
+ | **GitHub issue** | The upstream issue on github.com/ruvnet/claude-flow. Always say "GitHub issue", never just "issue". | "GitHub issue #1111" |
12
+ | **Defect ID** | The unique identifier for a defect: `{PREFIX}-{NNN}`. | HW-001, NS-003, RS-001 |
13
+ | **Execution order number** | 3-digit numeric prefix on the directory name that controls patch application order. Spaced by 10 to allow insertions. | `010-`, `170-`, `270-` |
14
+
15
+ - Use **defect** for the tracked problem (the folder, the ID, the concept).
16
+ - Use **patch** for the code change applied to the library (`fix.py`, `patch()`, `patch-all.sh`).
17
+ - Always say **GitHub issue** for the upstream reference -- never bare "issue".
18
+
19
+ ## Rules
20
+
21
+ - NEVER modify files inside the npm/npx cache directly -- edit `fix.py` scripts in `patch/`
22
+ - NEVER run individual `fix.py` files standalone -- always use `bash patch-all.sh`
23
+ - NEVER delete a defect without confirming it is truly obsolete -- see "Removing a Defect" below
24
+ - NEVER reuse a defect ID that was previously assigned to a different GitHub issue
25
+ - ONE defect directory and ONE fix.py per GitHub issue -- do not combine multiple GitHub issues into one defect or split one GitHub issue across multiple defects
26
+ - ALWAYS verify with `bash check-patches.sh` after applying
27
+ - ALWAYS update ALL listing files when adding/removing a defect (see checklist)
28
+ - Execution order is determined by the numeric prefix on each defect directory name. Dependencies between defects are expressed by assigning lower numbers to prerequisites.
29
+
30
+ ## Project Structure
31
+
32
+ ```
33
+ patch-all.sh # Orchestrator -- globs patch/*/fix.py (no hardcoded list)
34
+ check-patches.sh # Sentinel -- reads patch/*/sentinel files dynamically
35
+ repair-post-init.sh # Post-init helper repair for existing projects
36
+ lib/
37
+ common.py # Shared helpers: patch(), patch_all(), path variables
38
+ discover.mjs # Dynamic discovery: scans patch/*/ → structured JSON
39
+ categories.json # Prefix-to-label mapping (one line per category)
40
+ scripts/
41
+ update-docs.mjs # Regenerates doc tables from discovery (npm run update-docs)
42
+ upstream-log.mjs # Show recent upstream releases (npm run upstream-log [count])
43
+ patch/
44
+ {NNN}-{PREFIX}-{NNN}-{slug}/ # NNN = 3-digit execution order
45
+ README.md # Defect report: title, severity, root cause, fix
46
+ fix.py # patch()/patch_all() calls
47
+ sentinel # Verification directives for check-patches.sh
48
+ ```
49
+
50
+ ## Target Packages
51
+
52
+ | Package | Version | Location | Env var |
53
+ |---------|---------|----------|---------|
54
+ | `@claude-flow/cli` | `3.1.0-alpha.41` | `~/.npm/_npx/*/node_modules/@claude-flow/cli/dist/src/` | `BASE` |
55
+ | `ruvector` | (bundled) | `~/.npm/_npx/*/node_modules/ruvector/bin/cli.js` | `RUVECTOR_CLI` |
56
+ | `ruv-swarm` | `1.0.20` | `~/.npm/_npx/*/node_modules/ruv-swarm/` | (found via glob) |
57
+
58
+ `BASE` is set by `patch-all.sh`. All path variables in `lib/common.py` derive from it.
59
+ `RUVECTOR_CLI` is set by `patch-all.sh` to the ruvector CLI entry point.
60
+ RS-001 locates its own target via `find`.
61
+
62
+ ## GitHub Issue Policy
63
+
64
+ Every defect MUST link to exactly one GitHub issue. No exceptions. One defect = one GitHub issue.
65
+
66
+ ### Where the fix description goes
67
+
68
+ The `## Fix` section MUST always be present. Where it lives depends on who created the GitHub issue:
69
+
70
+ | Who created the issue? | Where does `## Fix` go? |
71
+ |------------------------|------------------------|
72
+ | **sparkling** (us) | In the **issue body** — edit the issue to include `## Fix` |
73
+ | **Someone else** | In a **single comment** on the issue — do NOT edit their body |
74
+
75
+ This rule is absolute. Every linked GitHub issue must have a `## Fix` section visible — either in the body (if we created it) or in exactly one comment (if someone else created it).
76
+
77
+ ### Before creating a new defect, always search first:
78
+
79
+ ```bash
80
+ gh issue list --repo ruvnet/claude-flow --search "<keywords>" --limit 10
81
+ ```
82
+
83
+ ### If an open GitHub issue exists (created by someone else):
84
+
85
+ Post a single comment with the patch details. Do NOT edit the issue body. Do NOT post multiple comments, closing remarks, or history. One clean comment per defect:
86
+
87
+ ```bash
88
+ gh issue comment <NUMBER> --repo ruvnet/claude-flow --body "$(cat <<'EOF'
89
+ ## Fix
90
+
91
+ Defect **{PREFIX}-{NNN}** in [claude-flow-patch](https://github.com/sparkling/claude-flow-patch).
92
+
93
+ <What the patch does. Be specific. Include a table if multiple ops.>
94
+ EOF
95
+ )"
96
+ ```
97
+
98
+ ### If no GitHub issue exists (we create it):
99
+
100
+ The `## Fix` section goes directly in the issue body. This is mandatory — sparkling-created issues MUST contain the fix in the body, not in a follow-up comment.
101
+
102
+ ```bash
103
+ gh issue create --repo ruvnet/claude-flow \
104
+ --title "Bug: <short description>" \
105
+ --body "$(cat <<'EOF'
106
+ ## Summary
107
+ <1-2 sentences>
108
+
109
+ ## Root Cause
110
+ <what's wrong and why>
111
+
112
+ ## Fix
113
+ <what the patch does — be specific, include a table if multiple ops>
114
+
115
+ ## Files Affected
116
+ - <dist/src/path/to/file.js>
117
+ EOF
118
+ )"
119
+ ```
120
+
121
+ Save the returned GitHub issue number for the defect README.md.
122
+
123
+ ### Comment hygiene:
124
+
125
+ - One comment per defect, describing the patch. No meta-commentary.
126
+ - If you need to replace a comment, delete the old one first (`gh api -X DELETE`).
127
+ - Do not reference defect history, deletion/restoration, or internal decisions.
128
+
129
+ ## Defect Categories
130
+
131
+ <!-- GENERATED:defect-tables:begin -->
132
+ | Prefix | Category | Count |
133
+ |--------|----------|-------|
134
+ | CF | Config & Doctor | 2 |
135
+ | DM | Daemon & Workers | 6 |
136
+ | EM | Embeddings & HNSW | 2 |
137
+ | GV | Ghost Vectors | 1 |
138
+ | HK | Hooks | 3 |
139
+ | HW | Headless Worker | 4 |
140
+ | IN | Intelligence | 1 |
141
+ | MM | Memory Management | 1 |
142
+ | NS | Memory Namespace | 3 |
143
+ | RS | ruv-swarm | 1 |
144
+ | RV | RuVector Intelligence | 3 |
145
+ | SG | Settings Generator | 2 |
146
+ | UI | Display & Cosmetic | 2 |
147
+
148
+ ## All 31 Defects
149
+
150
+ | ID | GitHub Issue | Severity |
151
+ |----|-------------|----------|
152
+ | CF-001 | [#1141 Doctor ignores YAML config files](https://github.com/ruvnet/claude-flow/issues/1141) | Low |
153
+ | CF-002 | [#1142 Config export shows hardcoded defaults](https://github.com/ruvnet/claude-flow/issues/1142) | Medium |
154
+ | DM-001 | [#1116 daemon.log always 0 bytes](https://github.com/ruvnet/claude-flow/issues/1116) | Medium |
155
+ | DM-002 | [#1138 maxCpuLoad=2.0 blocks all workers on multi-core](https://github.com/ruvnet/claude-flow/issues/1138) | Critical |
156
+ | DM-003 | [#1077 macOS freemem() always ~0% — workers blocked](https://github.com/ruvnet/claude-flow/issues/1077) | Critical |
157
+ | DM-004 | [#1139 Preload worker stub + missing from defaults](https://github.com/ruvnet/claude-flow/issues/1139) | Enhancement |
158
+ | DM-005 | [#1140 Consolidation worker stub (no decay/rebuild)](https://github.com/ruvnet/claude-flow/issues/1140) | Enhancement |
159
+ | EM-001 | [#1143 Embedding system ignores project config (model + HNSW dims)](https://github.com/ruvnet/claude-flow/issues/1143) | High |
160
+ | EM-002 | [#1144 @xenova/transformers cache EACCES](https://github.com/ruvnet/claude-flow/issues/1144) | Medium |
161
+ | GV-001 | [#1122 HNSW ghost vectors persist after memory delete](https://github.com/ruvnet/claude-flow/issues/1122) | Medium |
162
+ | HK-001 | [#1155 post-edit hook records file_path as "unknown"](https://github.com/ruvnet/claude-flow/issues/1155) | Medium |
163
+ | HK-002 | [#1058 MCP hook handlers are stubs that don't persist data](https://github.com/ruvnet/claude-flow/issues/1058) | High |
164
+ | HK-003 | [#1158 hooks_metrics MCP handler returns hardcoded fake data](https://github.com/ruvnet/claude-flow/issues/1158) | High |
165
+ | HW-001 | [#1111 Headless workers hang — stdin pipe never closed](https://github.com/ruvnet/claude-flow/issues/1111) | Critical |
166
+ | HW-002 | [#1112 Headless failures silently swallowed as success](https://github.com/ruvnet/claude-flow/issues/1112) | High |
167
+ | HW-003 | [#1113 Worker scheduling intervals too aggressive](https://github.com/ruvnet/claude-flow/issues/1113) | High |
168
+ | IN-001 | [#1154 intelligence.cjs is a stub that doesn't actually learn](https://github.com/ruvnet/claude-flow/issues/1154) | Critical |
169
+ | MM-001 | [#1152 Remove dead persistPath config option](https://github.com/ruvnet/claude-flow/issues/1152) | Low |
170
+ | NS-001 | [#1123 Discovery ops default to wrong namespace](https://github.com/ruvnet/claude-flow/issues/1123) | Critical |
171
+ | NS-002 | [#581 Store/delete/retrieve fall back to 'default' + accept 'all'](https://github.com/ruvnet/claude-flow/issues/581) | Critical |
172
+ | NS-003 | [#1136 Namespace typo 'pattern' vs 'patterns'](https://github.com/ruvnet/claude-flow/issues/1136) | Medium |
173
+ | RS-001 | [ruv-FANN#185 ruv-swarm MCP fails on Node 24 — better-sqlite3 missing native bindings](https://github.com/ruvnet/ruv-FANN/issues/185) | Critical |
174
+ | RV-001 | [#1156 force-learn command calls intel.tick() which doesn't exist](https://github.com/ruvnet/claude-flow/issues/1156) | Medium |
175
+ | RV-002 | [#1157 activeTrajectories not loaded from saved file](https://github.com/ruvnet/claude-flow/issues/1157) | High |
176
+ | RV-003 | [ruv-FANN#186 trajectory-end does not update stats counters](https://github.com/ruvnet/ruv-FANN/issues/186) | Medium |
177
+ | SG-001 | [#1150 Init generates invalid settings](https://github.com/ruvnet/claude-flow/issues/1150) | High |
178
+ | SG-003 | [#1169 Init missing helpers for --dual, --minimal, hooks, and upgrade paths](https://github.com/ruvnet/claude-flow/issues/1169) | Critical |
179
+ | UI-001 | [#1145 intelligence stats crashes on .toFixed()](https://github.com/ruvnet/claude-flow/issues/1145) | Critical |
180
+ | UI-002 | [#1146 neural status shows "Not loaded"](https://github.com/ruvnet/claude-flow/issues/1146) | Low |
181
+ | DM-006 | [#1114 No log rotation — headless execution logs grow unbounded](https://github.com/ruvnet/claude-flow/issues/1114) | Medium |
182
+ | HW-004 | [#1117 runWithTimeout rejects but does not kill child process](https://github.com/ruvnet/claude-flow/issues/1117) | Medium |
183
+ <!-- GENERATED:defect-tables:end -->
184
+
185
+ ---
186
+
187
+ ## Creating a New Defect
188
+
189
+ Follow every step. Do not skip any.
190
+
191
+ ### Step 1: Find or create a GitHub issue
192
+
193
+ Search first:
194
+
195
+ ```bash
196
+ gh issue list --repo ruvnet/claude-flow --search "<keywords>" --limit 10
197
+ ```
198
+
199
+ - **GitHub issue exists and is open**: note the number, post a patch comment (see GitHub Issue Policy above).
200
+ - **GitHub issue exists but is closed**: reopen it with a comment explaining why.
201
+ - **No GitHub issue exists**: create one (see GitHub Issue Policy above). Save the returned `#number`.
202
+
203
+ ### Step 2: Choose a defect ID
204
+
205
+ Format: `{PREFIX}-{NNN}`
206
+
207
+ - `PREFIX`: 2-letter category code from the table above. Create a new prefix if no existing category fits.
208
+ - `NNN`: next sequential number within that category (e.g. if HK-002 exists, next is HK-003).
209
+ - NEVER reuse an ID previously assigned to a different GitHub issue, even if that defect was deleted.
210
+
211
+ ### Step 3: Create the defect directory
212
+
213
+ ```bash
214
+ mkdir -p patch/{ORDER}-{PREFIX}-{NNN}-{slug}/
215
+ ```
216
+
217
+ `ORDER`: 3-digit execution order number in 10-increments (e.g. `300`). Choose the next available number. If this defect depends on another, its number must be higher than the dependency's.
218
+
219
+ `slug`: lowercase-kebab-case summary (e.g. `post-edit-file-path`).
220
+
221
+ ### Step 4: Write README.md
222
+
223
+ Create `patch/{PREFIX}-{NNN}-{slug}/README.md`:
224
+
225
+ ```markdown
226
+ # {PREFIX}-{NNN}: Short title
227
+
228
+ **Severity**: Critical | High | Medium | Low | Enhancement
229
+ **GitHub**: [#{number}](https://github.com/ruvnet/claude-flow/issues/{number})
230
+
231
+ ## Root Cause
232
+
233
+ <What's wrong and why. Include code snippets showing the bug.>
234
+
235
+ ## Fix
236
+
237
+ <What the patch does. Be specific about each change.>
238
+
239
+ ## Files Patched
240
+
241
+ - <relative path from dist/src/ for each file>
242
+
243
+ ## Ops
244
+
245
+ <N> ops in fix.py
246
+ ```
247
+
248
+ ### Step 5: Write fix.py and sentinel
249
+
250
+ Create `patch/{PREFIX}-{NNN}-{slug}/fix.py` with patch calls:
251
+
252
+ ```python
253
+ # {PREFIX}-{NNN}: Short title
254
+ # GitHub: #{number}
255
+
256
+ patch("{PREFIX}-{NNN}a: description of first change",
257
+ TARGET_VAR, # Path variable from lib/common.py
258
+ """old string""", # Exact string to find (copy-paste from target file)
259
+ """new string""") # Replacement string
260
+ ```
261
+
262
+ Create `patch/{PREFIX}-{NNN}-{slug}/sentinel` to declare how `check-patches.sh` verifies this patch:
263
+
264
+ ```
265
+ grep "unique_string" path/to/target.js
266
+ ```
267
+
268
+ **Sentinel directives** (one per line):
269
+
270
+ ```
271
+ grep "unique_string" path/to/target.js # String must be present
272
+ absent "old_string" path/to/target.js # String must be absent
273
+ none # No sentinel (e.g. permissions-only)
274
+ package: ruvector # Gate on optional package
275
+ ```
276
+
277
+ Paths are relative to `@claude-flow/cli/dist/src/` (e.g. `services/worker-daemon.js`, `init/executor.js`). For external packages, add `package: ruvector` or `package: ruv-swarm` and use paths relative to that package root.
278
+
279
+ The sentinel pattern must:
280
+ - Only appear in the target file AFTER the patch is applied
281
+ - Be specific enough not to match unrelated code
282
+
283
+ **Patch API**:
284
+ - `patch(label, filepath, old, new)` -- replace first occurrence only
285
+ - `patch_all(label, filepath, old, new)` -- replace ALL occurrences
286
+
287
+ Both are idempotent: skip if `new` already present, warn if `old` not found.
288
+
289
+ **Path variables** (defined in `lib/common.py`):
290
+
291
+ | Variable | File | Package |
292
+ |----------|------|---------|
293
+ | `HWE` | `services/headless-worker-executor.js` | @claude-flow/cli |
294
+ | `WD` | `services/worker-daemon.js` | @claude-flow/cli |
295
+ | `DJ` | `commands/daemon.js` | @claude-flow/cli |
296
+ | `DOC` | `commands/doctor.js` | @claude-flow/cli |
297
+ | `MI` | `memory/memory-initializer.js` | @claude-flow/cli |
298
+ | `MCP_MEMORY` | `mcp-tools/memory-tools.js` | @claude-flow/cli |
299
+ | `MCP_HOOKS` | `mcp-tools/hooks-tools.js` | @claude-flow/cli |
300
+ | `CLI_MEMORY` | `commands/memory.js` | @claude-flow/cli |
301
+ | `CONF` | `commands/config.js` | @claude-flow/cli |
302
+ | `HOOKS_CMD` | `commands/hooks.js` | @claude-flow/cli |
303
+ | `NEURAL` | `commands/neural.js` | @claude-flow/cli |
304
+ | `EMB_TOOLS` | `mcp-tools/embeddings-tools.js` | @claude-flow/cli |
305
+ | `SETTINGS_GEN` | `init/settings-generator.js` | @claude-flow/cli |
306
+ | `HELPERS_GEN` | `init/helpers-generator.js` | @claude-flow/cli |
307
+ | `EXECUTOR` | `init/executor.js` | @claude-flow/cli |
308
+ | `ruvector_cli` | `bin/cli.js` | ruvector |
309
+
310
+ To target a new file, add a variable to `lib/common.py` following the existing pattern.
311
+
312
+ ### Step 6: Update docs and test
313
+
314
+ ```bash
315
+ # Regenerate all documentation from dynamic discovery
316
+ npm run update-docs
317
+
318
+ # Apply -- should show "Applied: ..."
319
+ bash patch-all.sh --global
320
+
321
+ # Idempotency -- should show "0 applied, N already present"
322
+ bash patch-all.sh --global
323
+
324
+ # Sentinel -- should show "OK: All patches verified"
325
+ bash check-patches.sh
326
+
327
+ # Tests
328
+ npm test
329
+ ```
330
+
331
+ **No manual edits needed** to `patch-all.sh`, `check-patches.sh`, `README.md`, `CLAUDE.md`, `npm/README.md`, or `npm/config.json`. Dynamic discovery handles everything.
332
+
333
+ ### Full Checklist
334
+
335
+ - [ ] GitHub issue exists (searched first, created only if none found)
336
+ - [ ] GitHub issue comment posted with patch details
337
+ - [ ] `patch/{PREFIX}-{NNN}-{slug}/README.md` created with all required sections
338
+ - [ ] `patch/{PREFIX}-{NNN}-{slug}/fix.py` created with `patch()`/`patch_all()` calls
339
+ - [ ] `patch/{PREFIX}-{NNN}-{slug}/sentinel` created with verification directives
340
+ - [ ] Path variable added to `lib/common.py` (if targeting a new file)
341
+ - [ ] If new category prefix: add one line to `lib/categories.json`
342
+ - [ ] `npm run update-docs` regenerates all doc tables
343
+ - [ ] `bash patch-all.sh` applies successfully
344
+ - [ ] `bash patch-all.sh` is idempotent (0 applied on re-run)
345
+ - [ ] `bash check-patches.sh` shows OK
346
+ - [ ] Tests added to `03-patch-apply.test.mjs` and `04-idempotency.test.mjs`
347
+ - [ ] `npm test` passes
348
+
349
+ ---
350
+
351
+ ## Removing a Defect
352
+
353
+ Before removing any defect:
354
+
355
+ 1. Confirm the bug is genuinely fixed upstream or the patch is truly unreachable.
356
+ 2. Do NOT remove a defect just because a local workaround exists -- the MCP-level patch may still be needed.
357
+ 3. If removing, retire the defect ID permanently. Never reassign a deleted ID to a different GitHub issue.
358
+ 4. Run `npm run update-docs` to regenerate all documentation.
359
+
360
+ ---
361
+
362
+ ## Testing
363
+
364
+ ```bash
365
+ npm test # run all tests
366
+ node --test tests/02-common-library.test.mjs # run one suite
367
+ ```
368
+
369
+ Uses `node:test` (built-in, zero dependencies). Tests live in `tests/`.
370
+
371
+ | Suite | File | What it covers |
372
+ |-------|------|----------------|
373
+ | CLI dispatch | `01-cli-dispatch.test.mjs` | `--help`, unknown commands, `apply` valid/invalid IDs, `check` delegation |
374
+ | common.py | `02-common-library.test.mjs` | `patch()` apply/skip/warn/idempotent, `patch_all()`, path resolution from `BASE` |
375
+ | Patch apply | `03-patch-apply.test.mjs` | Individual patches (HW-001, DM-002, SG-002) applied against fixtures |
376
+ | Idempotency | `04-idempotency.test.mjs` | Double-apply produces identical files, second run reports skipped |
377
+ | Error handling | `05-error-handling.test.mjs` | Empty `BASE`, `/dev/null`, nonexistent dir, unknown options |
378
+
379
+ ### Fixtures
380
+
381
+ `tests/fixtures/cli/dist/src/` mirrors the subset of `@claude-flow/cli` that patches target. Each file contains the exact `old` strings patches search for — just enough for `patch()` to match, not full upstream JS files.
382
+
383
+ `tests/helpers/` provides:
384
+ - `fixture-factory.mjs` — copies fixtures to a temp dir, returns `{ base, cleanup }`
385
+ - `run-cli.mjs` — wraps `spawnSync('node', ['bin/claude-flow-patch.mjs', ...args])`
386
+ - `run-python.mjs` — concatenates `common.py` + `fix.py` and pipes to `python3` with `BASE` set
387
+
388
+ ### Adding tests for a new defect
389
+
390
+ 1. Ensure `tests/fixtures/cli/dist/src/<target-file>.js` contains the `old` string from the new `fix.py`
391
+ 2. Add a row to the `TESTS` array in `03-patch-apply.test.mjs`
392
+ 3. Add a row to the `PATCHES` array in `04-idempotency.test.mjs`
393
+ 4. Run `npm test`
394
+
395
+ ---
396
+
397
+ ## Commands
398
+
399
+ ```bash
400
+ # Apply all patches (default: --global)
401
+ bash patch-all.sh
402
+
403
+ # Patch only the npx cache
404
+ bash patch-all.sh --global
405
+
406
+ # Patch a specific project's node_modules
407
+ bash patch-all.sh --target /path/to/project
408
+
409
+ # Patch both
410
+ bash patch-all.sh --global --target /path/to/project
411
+
412
+ # Verify patches
413
+ bash check-patches.sh
414
+
415
+ # Repair a project initialized before patching
416
+ bash repair-post-init.sh --target /path/to/project
417
+
418
+ # Check target version
419
+ grep '"version"' ~/.npm/_npx/*/node_modules/@claude-flow/cli/package.json
420
+
421
+ # Show recent upstream releases (requires npm; gh optional for commit messages)
422
+ npm run upstream-log # last 10 versions
423
+ npm run upstream-log -- 20 # last 20 versions
424
+ npm run upstream-log -- --diff # also show dependency changes vs baseline
425
+ ```
426
+
427
+ ### Target Options
428
+
429
+ | Flag | Target | When to use |
430
+ |------|--------|-------------|
431
+ | (none) | Global npx cache (default) | Most common — patches the npx cache |
432
+ | `--global` | `~/.npm/_npx/*/node_modules/` | Explicit global-only |
433
+ | `--target <dir>` | `<dir>/node_modules/` | Project with a local install |
434
+ | `--global --target <dir>` | Both locations | Covers both invocation paths |
435
+
436
+ `npx @claude-flow/cli` uses local `node_modules` if present, otherwise the global npx cache.
437
+
438
+ ## Dependency Order
439
+
440
+ Execution order is controlled by the 3-digit numeric prefix on each directory name.
441
+ `patch-all.sh` globs `patch/*/fix.py` which sorts lexicographically, so numeric prefixes
442
+ execute in the correct order automatically.
443
+
444
+ Two dependency chains exist:
445
+
446
+ | Chain | Directories | Reason |
447
+ |-------|-------------|--------|
448
+ | IN-001 -> SG-003 | `170-IN-001-*` before `270-SG-003-*` | SG-003's `old_string` contains code introduced by IN-001 |
449
+ | NS-001 -> NS-002 -> NS-003 | `190-NS-001-*` before `200-NS-002-*` before `210-NS-003-*` | Sequential namespace fixes |
450
+
451
+ All other patches are independent.
452
+
453
+ ## Key Design Decisions
454
+
455
+ - **Idempotent**: `patch()` checks if `new` string is already present before replacing.
456
+ - **Non-destructive**: patches only modify the npx cache, never the npm registry package.
457
+ - **Platform-aware**: DM-003 is macOS-only (auto-skipped on Linux).
458
+ - **Sentinel-guarded**: `check-patches.sh` detects cache wipes and auto-reapplies.