claude-mycelium 2.0.0

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 (207) hide show
  1. package/.claude/settings.local.json +14 -0
  2. package/README.md +304 -0
  3. package/dist/coordination/gradient-cache.d.ts +48 -0
  4. package/dist/coordination/gradient-cache.d.ts.map +1 -0
  5. package/dist/coordination/gradient-cache.js +145 -0
  6. package/dist/coordination/gradient-cache.js.map +1 -0
  7. package/dist/coordination/index.d.ts +10 -0
  8. package/dist/coordination/index.d.ts.map +1 -0
  9. package/dist/coordination/index.js +10 -0
  10. package/dist/coordination/index.js.map +1 -0
  11. package/dist/core/agent-executor.d.ts +31 -0
  12. package/dist/core/agent-executor.d.ts.map +1 -0
  13. package/dist/core/agent-executor.js +257 -0
  14. package/dist/core/agent-executor.js.map +1 -0
  15. package/dist/core/change-applier.d.ts +10 -0
  16. package/dist/core/change-applier.d.ts.map +1 -0
  17. package/dist/core/change-applier.js +32 -0
  18. package/dist/core/change-applier.js.map +1 -0
  19. package/dist/core/gradient.d.ts +60 -0
  20. package/dist/core/gradient.d.ts.map +1 -0
  21. package/dist/core/gradient.js +191 -0
  22. package/dist/core/gradient.js.map +1 -0
  23. package/dist/core/index.d.ts +24 -0
  24. package/dist/core/index.d.ts.map +1 -0
  25. package/dist/core/index.js +24 -0
  26. package/dist/core/index.js.map +1 -0
  27. package/dist/core/mode-selector.d.ts +44 -0
  28. package/dist/core/mode-selector.d.ts.map +1 -0
  29. package/dist/core/mode-selector.js +208 -0
  30. package/dist/core/mode-selector.js.map +1 -0
  31. package/dist/core/signals/centrality.d.ts +44 -0
  32. package/dist/core/signals/centrality.d.ts.map +1 -0
  33. package/dist/core/signals/centrality.js +264 -0
  34. package/dist/core/signals/centrality.js.map +1 -0
  35. package/dist/core/signals/churn.d.ts +41 -0
  36. package/dist/core/signals/churn.d.ts.map +1 -0
  37. package/dist/core/signals/churn.js +188 -0
  38. package/dist/core/signals/churn.js.map +1 -0
  39. package/dist/core/signals/complexity.d.ts +29 -0
  40. package/dist/core/signals/complexity.d.ts.map +1 -0
  41. package/dist/core/signals/complexity.js +169 -0
  42. package/dist/core/signals/complexity.js.map +1 -0
  43. package/dist/core/signals/debt.d.ts +27 -0
  44. package/dist/core/signals/debt.d.ts.map +1 -0
  45. package/dist/core/signals/debt.js +80 -0
  46. package/dist/core/signals/debt.js.map +1 -0
  47. package/dist/core/signals/errors.d.ts +32 -0
  48. package/dist/core/signals/errors.d.ts.map +1 -0
  49. package/dist/core/signals/errors.js +73 -0
  50. package/dist/core/signals/errors.js.map +1 -0
  51. package/dist/core/signals/index.d.ts +19 -0
  52. package/dist/core/signals/index.d.ts.map +1 -0
  53. package/dist/core/signals/index.js +19 -0
  54. package/dist/core/signals/index.js.map +1 -0
  55. package/dist/cost/cost-tracker.d.ts +90 -0
  56. package/dist/cost/cost-tracker.d.ts.map +1 -0
  57. package/dist/cost/cost-tracker.js +305 -0
  58. package/dist/cost/cost-tracker.js.map +1 -0
  59. package/dist/cost/index.d.ts +56 -0
  60. package/dist/cost/index.d.ts.map +1 -0
  61. package/dist/cost/index.js +111 -0
  62. package/dist/cost/index.js.map +1 -0
  63. package/dist/index.d.ts +35 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +40 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/llm/anthropic-client.d.ts +52 -0
  68. package/dist/llm/anthropic-client.d.ts.map +1 -0
  69. package/dist/llm/anthropic-client.js +310 -0
  70. package/dist/llm/anthropic-client.js.map +1 -0
  71. package/dist/llm/index.d.ts +27 -0
  72. package/dist/llm/index.d.ts.map +1 -0
  73. package/dist/llm/index.js +34 -0
  74. package/dist/llm/index.js.map +1 -0
  75. package/dist/prompts/complexity-reducer.d.ts +7 -0
  76. package/dist/prompts/complexity-reducer.d.ts.map +1 -0
  77. package/dist/prompts/complexity-reducer.js +55 -0
  78. package/dist/prompts/complexity-reducer.js.map +1 -0
  79. package/dist/prompts/debt-payer.d.ts +7 -0
  80. package/dist/prompts/debt-payer.d.ts.map +1 -0
  81. package/dist/prompts/debt-payer.js +55 -0
  82. package/dist/prompts/debt-payer.js.map +1 -0
  83. package/dist/prompts/error-reducer.d.ts +7 -0
  84. package/dist/prompts/error-reducer.d.ts.map +1 -0
  85. package/dist/prompts/error-reducer.js +54 -0
  86. package/dist/prompts/error-reducer.js.map +1 -0
  87. package/dist/prompts/index.d.ts +22 -0
  88. package/dist/prompts/index.d.ts.map +1 -0
  89. package/dist/prompts/index.js +112 -0
  90. package/dist/prompts/index.js.map +1 -0
  91. package/dist/prompts/stabilizer.d.ts +7 -0
  92. package/dist/prompts/stabilizer.d.ts.map +1 -0
  93. package/dist/prompts/stabilizer.js +55 -0
  94. package/dist/prompts/stabilizer.js.map +1 -0
  95. package/dist/prompts/types.d.ts +14 -0
  96. package/dist/prompts/types.d.ts.map +1 -0
  97. package/dist/prompts/types.js +5 -0
  98. package/dist/prompts/types.js.map +1 -0
  99. package/dist/trace/index.d.ts +51 -0
  100. package/dist/trace/index.d.ts.map +1 -0
  101. package/dist/trace/index.js +60 -0
  102. package/dist/trace/index.js.map +1 -0
  103. package/dist/trace/trace-event.d.ts +72 -0
  104. package/dist/trace/trace-event.d.ts.map +1 -0
  105. package/dist/trace/trace-event.js +244 -0
  106. package/dist/trace/trace-event.js.map +1 -0
  107. package/dist/types/index.d.ts +206 -0
  108. package/dist/types/index.d.ts.map +1 -0
  109. package/dist/types/index.js +6 -0
  110. package/dist/types/index.js.map +1 -0
  111. package/dist/utils/ci-provider.d.ts +43 -0
  112. package/dist/utils/ci-provider.d.ts.map +1 -0
  113. package/dist/utils/ci-provider.js +130 -0
  114. package/dist/utils/ci-provider.js.map +1 -0
  115. package/dist/utils/config.d.ts +31 -0
  116. package/dist/utils/config.d.ts.map +1 -0
  117. package/dist/utils/config.js +85 -0
  118. package/dist/utils/config.js.map +1 -0
  119. package/dist/utils/error-provider.d.ts +51 -0
  120. package/dist/utils/error-provider.d.ts.map +1 -0
  121. package/dist/utils/error-provider.js +123 -0
  122. package/dist/utils/error-provider.js.map +1 -0
  123. package/dist/utils/file-utils.d.ts +18 -0
  124. package/dist/utils/file-utils.d.ts.map +1 -0
  125. package/dist/utils/file-utils.js +95 -0
  126. package/dist/utils/file-utils.js.map +1 -0
  127. package/dist/utils/index.d.ts +10 -0
  128. package/dist/utils/index.d.ts.map +1 -0
  129. package/dist/utils/index.js +10 -0
  130. package/dist/utils/index.js.map +1 -0
  131. package/dist/utils/logger.d.ts +36 -0
  132. package/dist/utils/logger.d.ts.map +1 -0
  133. package/dist/utils/logger.js +74 -0
  134. package/dist/utils/logger.js.map +1 -0
  135. package/docs/IMPLEMENTATION-STATUS.md +199 -0
  136. package/docs/PHASE-0-COMPLETE.md +252 -0
  137. package/docs/PHASE-1-COMPLETE.md +204 -0
  138. package/docs/PHASE-2-COMPLETE.md +233 -0
  139. package/docs/PHASE2_COMPLETION_CHECKLIST.md +290 -0
  140. package/docs/PHASE2_INTEGRATION_SUMMARY.md +255 -0
  141. package/docs/PHASE2_QUICK_REFERENCE.md +365 -0
  142. package/docs/PHASE2_TEST_RESULTS.md +282 -0
  143. package/docs/ROADMAP.md +746 -0
  144. package/docs/SNAPSHOT.md +376 -0
  145. package/docs/adrs/ADR-001-signal-computation.md +76 -0
  146. package/docs/adrs/ADR-002-inhibitor-signals.md +108 -0
  147. package/docs/adrs/ADR-003-llm-integration.md +156 -0
  148. package/docs/adrs/ADR-004-process-architecture.md +175 -0
  149. package/docs/adrs/ADR-005-testing-strategy.md +243 -0
  150. package/docs/pitch.md +94 -0
  151. package/docs/specs/fourth-spec.md +1973 -0
  152. package/docs/specs/initial-spec.md +2096 -0
  153. package/docs/specs/second-spec.md +2690 -0
  154. package/package.json +50 -0
  155. package/src/coordination/gradient-cache.ts +185 -0
  156. package/src/coordination/index.ts +10 -0
  157. package/src/core/agent-executor.ts +327 -0
  158. package/src/core/change-applier.ts +338 -0
  159. package/src/core/gradient.ts +258 -0
  160. package/src/core/index.ts +24 -0
  161. package/src/core/mode-selector.ts +243 -0
  162. package/src/core/signals/centrality.ts +328 -0
  163. package/src/core/signals/churn.ts +239 -0
  164. package/src/core/signals/complexity.ts +206 -0
  165. package/src/core/signals/debt.ts +111 -0
  166. package/src/core/signals/errors.ts +93 -0
  167. package/src/core/signals/index.ts +19 -0
  168. package/src/cost/cost-tracker.ts +410 -0
  169. package/src/cost/index.ts +143 -0
  170. package/src/index.ts +43 -0
  171. package/src/llm/anthropic-client.ts +415 -0
  172. package/src/llm/index.ts +43 -0
  173. package/src/prompts/complexity-reducer.ts +59 -0
  174. package/src/prompts/debt-payer.ts +59 -0
  175. package/src/prompts/error-reducer.ts +58 -0
  176. package/src/prompts/index.ts +128 -0
  177. package/src/prompts/stabilizer.ts +59 -0
  178. package/src/prompts/types.ts +15 -0
  179. package/src/trace/README.md +178 -0
  180. package/src/trace/index.ts +88 -0
  181. package/src/trace/trace-event.ts +324 -0
  182. package/src/types/index.ts +271 -0
  183. package/src/utils/ci-provider.ts +145 -0
  184. package/src/utils/config.ts +95 -0
  185. package/src/utils/error-provider.ts +138 -0
  186. package/src/utils/file-utils.ts +111 -0
  187. package/src/utils/index.ts +10 -0
  188. package/src/utils/logger.ts +94 -0
  189. package/test-8d713cc8-f4b7-403d-8153-57573172b94c.ts +3 -0
  190. package/tests/coordination/gradient-cache.test.ts +270 -0
  191. package/tests/core/agent-executor.test.ts +217 -0
  192. package/tests/core/change-applier.test.ts +336 -0
  193. package/tests/core/gradient.test.ts +263 -0
  194. package/tests/core/mode-selector.test.ts +239 -0
  195. package/tests/core/signals/centrality.test.ts +512 -0
  196. package/tests/core/signals/churn.test.ts +355 -0
  197. package/tests/core/signals/complexity.test.ts +284 -0
  198. package/tests/core/signals/debt.test.ts +437 -0
  199. package/tests/core/signals/errors.test.ts +350 -0
  200. package/tests/cost/cost-tracker.test.ts +475 -0
  201. package/tests/integration/phase2.test.ts +405 -0
  202. package/tests/llm/anthropic-client.test.ts +437 -0
  203. package/tests/prompts/prompts.test.ts +266 -0
  204. package/tests/trace/trace-event.test.ts +666 -0
  205. package/tests/utils/file-utils.test.ts +148 -0
  206. package/tsconfig.json +24 -0
  207. package/vitest.config.ts +28 -0
@@ -0,0 +1,376 @@
1
+ # Claude-Mycelium v2: Current Snapshot
2
+
3
+ **Date**: 2026-01-30 (Updated after Phase 1)
4
+ **Status**: Signal & Gradient System Complete (40% Complete)
5
+ **Phase Completed**: Phase 0 + Phase 1 ✅
6
+ **Next Phase**: Phase 2 - Agent Execution System
7
+
8
+ ---
9
+
10
+ ## 🎯 What This Document Is
11
+
12
+ This is a **point-in-time walkthrough** of the codebase as it exists right now:
13
+ - What files exist and what they contain
14
+ - What works and what doesn't
15
+ - What you can run today
16
+ - What's missing
17
+
18
+ Think of this as a guided tour of the current state. For history, see the ADRs. For future plans, see ROADMAP.md.
19
+
20
+ ---
21
+
22
+ ## 📊 Quick Stats
23
+
24
+ - **Total Files**: 25 files (production + tests)
25
+ - **Lines of Code**: ~4,500 lines production, ~2,500 lines tests
26
+ - **Tests**: 155 passing tests across 9 test suites
27
+ - **Test Coverage**: ~90% for implemented modules (core/, utils/)
28
+ - **Implementation Status**: Foundation + Signals + Gradient complete
29
+
30
+ ---
31
+
32
+ ## 📂 Directory Structure (What Exists Now)
33
+
34
+ ```
35
+ claude-mycelium/
36
+ ├── docs/ ✅ Complete
37
+ │ ├── specs/ ✅ Moved from root
38
+ │ │ ├── initial-spec.md ✅ Full system spec (2096 lines)
39
+ │ │ └── second-spec.md ✅ Implementation details (2690 lines)
40
+ │ ├── adrs/ ✅ 5 ADRs documented
41
+ │ │ ├── ADR-001-signal-computation.md
42
+ │ │ ├── ADR-002-inhibitor-signals.md
43
+ │ │ ├── ADR-003-llm-integration.md
44
+ │ │ ├── ADR-004-process-architecture.md
45
+ │ │ └── ADR-005-testing-strategy.md
46
+ │ ├── IMPLEMENTATION-STATUS.md ✅ Progress tracking
47
+ │ ├── ROADMAP.md ✅ 8-phase implementation plan
48
+ │ ├── SNAPSHOT.md ✅ This file
49
+ │ ├── PHASE-0-COMPLETE.md ✅ Foundation completion report
50
+ │ └── PHASE-1-COMPLETE.md ✅ Signal/gradient completion report
51
+
52
+ ├── src/ 🟢 40% Complete
53
+ │ ├── types/ ✅ Complete (100%)
54
+ │ │ └── index.ts ✅ 267 lines - All core types
55
+ │ │
56
+ │ ├── utils/ ✅ Complete (100%)
57
+ │ │ ├── index.ts ✅ Centralized exports
58
+ │ │ ├── file-utils.ts ✅ 112 lines - File I/O, LOC counting
59
+ │ │ ├── config.ts ✅ 95 lines - Config + spawn tracking
60
+ │ │ ├── logger.ts ✅ 89 lines - Structured logging
61
+ │ │ ├── error-provider.ts ✅ 127 lines - Error data provider
62
+ │ │ └── ci-provider.ts ✅ 132 lines - npm test/lint
63
+ │ │
64
+ │ ├── core/ 🟢 Partial (60% complete)
65
+ │ │ ├── signals/ ✅ Complete (100%)
66
+ │ │ │ ├── index.ts ✅ Signal exports
67
+ │ │ │ ├── complexity.ts ✅ 200 lines - AST cyclomatic complexity
68
+ │ │ │ ├── churn.ts ✅ 240 lines - Git commit frequency
69
+ │ │ │ ├── centrality.ts ✅ 326 lines - Import graph analysis
70
+ │ │ │ ├── debt.ts ✅ 150 lines - ESLint errors/warnings
71
+ │ │ │ └── errors.ts ✅ 94 lines - Runtime error tracking
72
+ │ │ ├── gradient.ts ✅ 280 lines - Gradient calculation
73
+ │ │ └── mode-selector.ts ✅ 220 lines - Mode selection logic
74
+ │ │
75
+ │ ├── coordination/ 🟢 Partial (30% complete)
76
+ │ │ ├── index.ts ✅ Coordination exports
77
+ │ │ └── gradient-cache.ts ✅ 180 lines - 5-min caching
78
+ │ │ # Missing: file-locks.ts, process-manager.ts (Phase 3)
79
+ │ │
80
+ │ ├── agent/ ❌ Empty (Phase 2)
81
+ │ ├── cli/ ❌ Empty (Phase 6)
82
+ │ ├── task/ ❌ Empty (Phase 5)
83
+ │ ├── trace/ ❌ Empty (Phase 2)
84
+ │ ├── quarantine/ ❌ Empty (Phase 4)
85
+ │ ├── cost/ ❌ Empty (Phase 2)
86
+ │ └── gc/ ❌ Empty (Phase 7)
87
+
88
+ ├── tests/ 🟢 155 tests passing
89
+ │ ├── utils/ ✅ Complete
90
+ │ │ └── file-utils.test.ts ✅ 18 tests
91
+ │ ├── core/
92
+ │ │ ├── signals/ ✅ Complete
93
+ │ │ │ ├── complexity.test.ts ✅ 12 tests
94
+ │ │ │ ├── churn.test.ts ✅ 15 tests
95
+ │ │ │ ├── centrality.test.ts ✅ 30 tests
96
+ │ │ │ ├── debt.test.ts ✅ 14 tests
97
+ │ │ │ └── errors.test.ts ✅ 13 tests
98
+ │ │ ├── gradient.test.ts ✅ 14 tests
99
+ │ │ └── mode-selector.test.ts ✅ 36 tests
100
+ │ └── coordination/
101
+ │ └── gradient-cache.test.ts ✅ 21 tests
102
+
103
+ ├── .agent-meta/ ✅ Initialized
104
+ │ ├── locks/ ✅ Ready for file locks
105
+ │ └── (runtime directories created as needed)
106
+
107
+ ├── package.json ✅ Complete (all deps correct)
108
+ ├── tsconfig.json ✅ Complete
109
+ ├── vitest.config.ts ✅ Complete (75% coverage target)
110
+ └── .gitignore ✅ Complete
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 🎯 What Works Right Now
116
+
117
+ ### You Can Run These Commands
118
+
119
+ ```bash
120
+ # Run all 155 tests
121
+ npm test
122
+
123
+ # Check test coverage
124
+ npm run test:coverage
125
+
126
+ # Build TypeScript
127
+ npm run build
128
+
129
+ # Calculate gradient for a file
130
+ node -e "
131
+ const { calculateGradient } = require('./dist/core/gradient.js');
132
+ calculateGradient('./src/core/gradient.ts').then(g => {
133
+ console.log('File:', g.file);
134
+ console.log('Gradient Score:', g.score.toFixed(3));
135
+ console.log('Dominant Signal:', g.dominantSignal.name);
136
+ console.log('Signals:', {
137
+ complexity: g.signals.complexity.toFixed(3),
138
+ churn: g.signals.churn.toFixed(3),
139
+ error_rate: g.signals.error_rate.toFixed(3),
140
+ debt: g.signals.debt.toFixed(3),
141
+ centrality: g.signals.centrality.toFixed(3)
142
+ });
143
+ });
144
+ "
145
+
146
+ # Check mode selection
147
+ node -e "
148
+ const { calculateGradient, selectModeFromGradient } = require('./dist/core/gradient.js');
149
+ calculateGradient('./src/core/signals/complexity.ts').then(g => {
150
+ const mode = selectModeFromGradient(g);
151
+ console.log('Recommended Mode:', mode);
152
+ });
153
+ "
154
+ ```
155
+
156
+ ### Working Features
157
+
158
+ 1. **All 5 Signals**
159
+ - ✅ Complexity (AST-based cyclomatic complexity)
160
+ - ✅ Churn (git log analysis with 30-day window)
161
+ - ✅ Centrality (import graph with fan-in/fan-out)
162
+ - ✅ Debt (ESLint errors/warnings)
163
+ - ✅ Error Rate (file-based error provider)
164
+
165
+ 2. **Gradient Calculation**
166
+ - ✅ Weighted combination of all signals
167
+ - ✅ Impact multiplier based on centrality
168
+ - ✅ Formula: `baseScore * impactMultiplier - efficiencyPenalty`
169
+ - ✅ Batch processing for multiple files
170
+
171
+ 3. **Caching System**
172
+ - ✅ 5-minute TTL for computed gradients
173
+ - ✅ Automatic expiration
174
+ - ✅ Manual invalidation
175
+ - ✅ Cache statistics
176
+
177
+ 4. **Mode Selection**
178
+ - ✅ 5 modes implemented (error_reducer, complexity_reducer, debt_payer, stabilizer, explorer)
179
+ - ✅ Automatic selection based on dominant signal
180
+ - ✅ Mode-specific instructions for agents
181
+ - ✅ Multi-mode suggestions
182
+
183
+ 5. **Utilities**
184
+ - ✅ File operations (read, write, LOC counting)
185
+ - ✅ Configuration management
186
+ - ✅ Structured logging
187
+ - ✅ Error tracking
188
+ - ✅ CI integration (npm test/lint)
189
+
190
+ ---
191
+
192
+ ## ❌ What's Missing (By Phase)
193
+
194
+ ### Phase 2: Agent Execution (Next)
195
+ - ❌ Anthropic API client
196
+ - ❌ LLM streaming
197
+ - ❌ Mode-specific prompts
198
+ - ❌ Agent executor main loop
199
+ - ❌ Change applier
200
+ - ❌ Trace event system
201
+
202
+ ### Phase 3: Concurrency & Safety
203
+ - ❌ File locks
204
+ - ❌ Process spawning
205
+ - ❌ Max concurrent agents
206
+ - ❌ Resource cleanup
207
+
208
+ ### Phase 4: Learning System
209
+ - ❌ Inhibitors
210
+ - ❌ Quarantine
211
+ - ❌ Explorer mode logic
212
+ - ❌ Efficiency tracking
213
+
214
+ ### Phase 5: Task Management
215
+ - ❌ Task queue
216
+ - ❌ Task selection
217
+ - ❌ Priority ordering
218
+
219
+ ### Phase 6: CLI Interface
220
+ - ❌ commander CLI
221
+ - ❌ `grow` command
222
+ - ❌ `gradients` command
223
+ - ❌ `watch` daemon
224
+
225
+ ### Phase 7: Garbage Collection
226
+ - ❌ Trace cleanup
227
+ - ❌ Lock cleanup
228
+ - ❌ Inhibitor decay
229
+
230
+ ### Phase 8: Testing & Polish
231
+ - ❌ Integration tests
232
+ - ❌ E2E tests
233
+ - ❌ Documentation
234
+ - ❌ Examples
235
+
236
+ ---
237
+
238
+ ## 🔍 Key Implementation Details
239
+
240
+ ### Signal Computation
241
+
242
+ Each signal returns a normalized score (0.0 - 1.0):
243
+
244
+ ```typescript
245
+ interface SignalResult {
246
+ // Raw metrics
247
+ [metric: string]: number;
248
+
249
+ // Normalized score (0.0 - 1.0)
250
+ normalized: number;
251
+ }
252
+ ```
253
+
254
+ **Normalization Strategies:**
255
+ - **Complexity**: `(cyclomatic/LOC) / 0.5`, capped at 1.0
256
+ - **Churn**: `commits_to_file / max(commits_to_any_file)`
257
+ - **Centrality**: `(fanIn/maxFanIn)*0.67 + (fanOut/maxFanOut)*0.33`
258
+ - **Debt**: `(errors*3 + warnings) / LOC / 0.5`, capped at 1.0
259
+ - **Error Rate**: `(errors / LOC) / 0.1`, capped at 1.0
260
+
261
+ ### Gradient Formula
262
+
263
+ ```typescript
264
+ // Weights from initial-spec §2
265
+ const baseScore = (
266
+ complexity * 0.25 +
267
+ churn * 0.15 +
268
+ error_rate * 0.35 +
269
+ debt * 0.25
270
+ );
271
+
272
+ // Centrality boosts central files
273
+ const impactMultiplier = 0.5 + (centrality * 0.5); // 0.5-1.0
274
+
275
+ // Efficiency penalty (Phase 2)
276
+ const efficiencyPenalty = recentEfficiency !== null
277
+ ? Math.max(0, 0.3 - recentEfficiency)
278
+ : 0;
279
+
280
+ const gradient = Math.max(0, baseScore * impactMultiplier - efficiencyPenalty);
281
+ ```
282
+
283
+ ### Mode Selection
284
+
285
+ ```typescript
286
+ // Threshold: signals must exceed 0.3 to be "dominant"
287
+ const DOMINANCE_THRESHOLD = 0.3;
288
+
289
+ // Mode mapping
290
+ const modeMap = {
291
+ 'error_rate': 'error_reducer', // Fix bugs
292
+ 'complexity': 'complexity_reducer', // Simplify
293
+ 'debt': 'debt_payer', // Fix lint
294
+ 'churn': 'stabilizer' // Add tests
295
+ };
296
+
297
+ // Default to debt_payer if nothing dominant
298
+ return mode || 'debt_payer';
299
+ ```
300
+
301
+ ---
302
+
303
+ ## 🧪 Test Status
304
+
305
+ ### All Tests Passing ✅
306
+
307
+ ```
308
+ Test Files 9 passed (9)
309
+ Tests 155 passed (155)
310
+ Duration 13.16s
311
+ ```
312
+
313
+ ### Coverage by Module
314
+
315
+ | Module | Tests | Files | Coverage |
316
+ |--------|-------|-------|----------|
317
+ | utils/ | 18 | 1 | ~95% |
318
+ | signals/ | 84 | 5 | ~90% |
319
+ | gradient | 14 | 1 | ~95% |
320
+ | mode-selector | 36 | 1 | ~95% |
321
+ | gradient-cache | 21 | 1 | ~95% |
322
+ | **Total** | **155** | **9** | **~92%** |
323
+
324
+ ---
325
+
326
+ ## 🚧 Known Issues
327
+
328
+ ### None! ✅
329
+
330
+ Phase 0 and Phase 1 are complete with no known issues.
331
+
332
+ ---
333
+
334
+ ## 📈 Progress Tracking
335
+
336
+ ### Overall Completion: 40%
337
+
338
+ | Phase | Status | Files | Tests | Notes |
339
+ |-------|--------|-------|-------|-------|
340
+ | Phase 0: Foundation | ✅ Complete | 6/6 | 18/18 | Dependencies, types, utils |
341
+ | Phase 1: Signals | ✅ Complete | 9/9 | 137/137 | 5 signals + gradient + cache + mode |
342
+ | Phase 2: Agent Execution | ⏳ Next | 0/7 | 0/~50 | LLM, prompts, executor |
343
+ | Phase 3: Concurrency | ⏳ Pending | 0/3 | 0/~30 | Locks, spawning |
344
+ | Phase 4: Learning | ⏳ Pending | 0/3 | 0/~40 | Inhibitors, quarantine |
345
+ | Phase 5: Tasks | ⏳ Pending | 0/2 | 0/~20 | Queue, selection |
346
+ | Phase 6: CLI | ⏳ Pending | 0/2 | 0/~15 | Commands, daemon |
347
+ | Phase 7: GC | ⏳ Pending | 0/1 | 0/~10 | Cleanup |
348
+ | Phase 8: Polish | ⏳ Pending | 0/? | 0/~20 | Integration tests, docs |
349
+
350
+ ### Files Implemented: 15/30+ (50% of core files)
351
+ ### Tests Passing: 155/~300 (52% of planned tests)
352
+
353
+ ---
354
+
355
+ ## 🎯 Next Steps
356
+
357
+ Ready to start **Phase 2: Agent Execution System**
358
+
359
+ **Implementation Strategy:**
360
+ - Use 5-7 agent swarm for parallel implementation
361
+ - 7 core files + test suites
362
+ - Estimated: 2-3 days with swarm, 8-10 days sequential
363
+
364
+ **Phase 2 Deliverables:**
365
+ 1. Anthropic API client with streaming
366
+ 2. 4 mode-specific prompts (fix, refactor, stabilizer, test)
367
+ 3. Agent executor main loop
368
+ 4. Change applier (safe code modifications)
369
+ 5. Trace event system (learning foundation)
370
+ 6. Cost tracking ($$ per agent run)
371
+ 7. Comprehensive test suite (~50 tests)
372
+
373
+ ---
374
+
375
+ **Last Updated**: January 30, 2026 after Phase 1 completion
376
+ **Next Update**: After Phase 2 completion
@@ -0,0 +1,76 @@
1
+ # ADR-001: Signal Computation Implementation
2
+
3
+ ## Status
4
+ Accepted
5
+
6
+ ## Context
7
+ The initial spec defined 5 signals (complexity, churn, error_rate, debt, centrality) but didn't specify HOW to compute them. We needed concrete implementations for:
8
+ - AST parsing for cyclomatic complexity
9
+ - Git history analysis for churn
10
+ - Import graph extraction for centrality
11
+ - ESLint integration for debt
12
+ - Error provider mechanism
13
+
14
+ ## Decision
15
+
16
+ ### Complexity Signal
17
+ - **Library**: `@typescript-eslint/typescript-estree` for TypeScript AST parsing
18
+ - **Algorithm**: Manual cyclomatic complexity counting by walking AST and counting decision points (if, for, while, switch, catch, logical operators)
19
+ - **Normalization**: `(cyclomatic / LOC) / 0.5` capped at 1.0 (heuristic: 0.5 complexity/LOC is very high)
20
+ - **LOC counting**: Exclude blank lines and comments
21
+
22
+ ### Churn Signal
23
+ - **Method**: Shell out to `git log --since="30 days" --name-only`
24
+ - **No git library**: Simple exec for Phase 1, avoids dependency
25
+ - **Caching**: 5-minute TTL cache to avoid repeated git calls
26
+ - **Normalization**: commits_to_file / max(commits_to_any_file)
27
+
28
+ ### Import Graph (Centrality)
29
+ - **Method**: Regex-based import extraction (fast, good enough)
30
+ - **Pattern**: Matches `import ... from '...'`, `require('...')`, `import('...')`
31
+ - **Resolution**: Try extensions `.ts`, `.tsx`, `.js`, `.jsx`, `/index.*`
32
+ - **Fallback**: AST parsing for edge cases (future)
33
+
34
+ ### Debt Signal
35
+ - **Method**: Run `npx eslint <file> --format json` as subprocess
36
+ - **Formula**: `(errors × 3 + warnings) / LOC` per spec
37
+ - **Normalization**: Divide by 0.5, cap at 1.0
38
+
39
+ ### Error Signal
40
+ - **Phase 1**: File-based provider (`.agent-meta/_errors.json`)
41
+ - **Population**: Manual, script hook, or external tool
42
+ - **Phase 2+**: Sentry/Datadog integration (future)
43
+
44
+ ## Consequences
45
+
46
+ ### Positive
47
+ - ✅ No heavy dependencies (escomplex, js-ast, etc.)
48
+ - ✅ Fast: regex and git shell-out are quick
49
+ - ✅ Extensible: Easy to add Sentry/Datadog later
50
+ - ✅ Cross-platform: Works on any system with git
51
+
52
+ ### Negative
53
+ - ⚠️ Regex may miss complex import patterns (dynamic imports)
54
+ - ⚠️ Git must be available (fails gracefully if not)
55
+ - ⚠️ ESLint must be configured (returns 0 if missing)
56
+ - ⚠️ Error provider requires manual setup
57
+
58
+ ## Alternatives Considered
59
+
60
+ ### Complexity
61
+ - **escomplex**: Rejected (abandoned, doesn't support TS well)
62
+ - **SonarQube API**: Rejected (heavy, requires SonarQube server)
63
+
64
+ ### Churn
65
+ - **nodegit/isomorphic-git**: Rejected (heavy dependencies, native compilation issues)
66
+ - **simple-git**: Considered but shell-out is simpler
67
+
68
+ ### Import Graph
69
+ - **typescript compiler API**: Rejected (slow, heavy)
70
+ - **dependency-cruiser**: Rejected (overkill)
71
+
72
+ ## Implementation Notes
73
+ - All signal calculations are in `src/core/signals/`
74
+ - Each signal has its own file: `complexity.ts`, `churn.ts`, `debt.ts`, `errors.ts`, `centrality.ts`
75
+ - Caching is used for expensive operations (git, import graph)
76
+ - Graceful fallbacks when tools unavailable (git, eslint)
@@ -0,0 +1,108 @@
1
+ # ADR-002: Inhibitor Signals (Learning from Failures)
2
+
3
+ ## Status
4
+ Accepted
5
+
6
+ ## Context
7
+ From RALPH research: Systems need "guardrails" to avoid repeating failed patterns. The initial spec had quarantine (file-level blocking), but lacked surgical, pattern-specific warnings.
8
+
9
+ Inspired by mycelial inhibitors: chemical markers that repel growth from areas where nutrients were already depleted.
10
+
11
+ ## Decision
12
+
13
+ ### Concept
14
+ **Inhibitor signals** are pattern-specific warnings emitted after failures. They:
15
+ - Decay over time (30-60 day half-life)
16
+ - Are included in agent prompts
17
+ - Target specific file + mode + pattern combinations
18
+
19
+ ### When Inhibitors Are Emitted
20
+ 1. **CI Failed**: After test/lint failure
21
+ 2. **Regression**: When gradient increases (made things worse)
22
+ 3. **Loop Detected**: 3+ attempts, no progress (efficiency < 0.02 each)
23
+
24
+ ### Storage
25
+ - **File**: `.agent-meta/_inhibitors.ndjson` (append-only)
26
+ - **Schema**:
27
+ ```typescript
28
+ interface Inhibitor {
29
+ id: string;
30
+ timestamp: string;
31
+ trigger: { file?: string; pattern?: string; mode?: Mode };
32
+ signal: string; // Human-readable warning
33
+ origin: {
34
+ agent_id: string;
35
+ trace_id: string;
36
+ energy_wasted: number; // Cost in USD
37
+ failure_type: 'ci_failed' | 'regression' | 'reverted' | 'loop_detected';
38
+ };
39
+ strength: number; // 1.0 = fresh, decays toward 0
40
+ half_life_days: number; // Default: 30
41
+ }
42
+ ```
43
+
44
+ ### Decay Function
45
+ ```
46
+ strength(t) = initial_strength × 0.5^(days / half_life)
47
+ ```
48
+
49
+ Examples:
50
+ - Day 0: 1.0
51
+ - Day 30: 0.5 (one half-life)
52
+ - Day 60: 0.25
53
+ - Day 90: 0.125
54
+
55
+ ### Relevance Threshold
56
+ - Inhibitors with strength < 0.2 are ignored
57
+ - Inhibitors with strength < 0.05 are garbage collected
58
+
59
+ ### Agent Prompt Integration
60
+ Relevant inhibitors (matching file/mode) are added to agent prompts:
61
+ ```
62
+ ## ⚠️ Inhibitor Signals
63
+ - **removing null checks** [Strength: 85%]
64
+ CI failed: TypeError: Cannot read property 'x' of undefined
65
+ Failed: ci_failed by agent-abc, wasted $0.04
66
+ ```
67
+
68
+ ## Consequences
69
+
70
+ ### Positive
71
+ - ✅ **Surgical avoidance**: Warns against specific patterns, not entire files
72
+ - ✅ **Self-healing**: Decays naturally as code changes
73
+ - ✅ **Cost-aware**: Tracks wasted money, prioritizes expensive failures
74
+ - ✅ **Complements quarantine**: Different mechanisms for different severities
75
+
76
+ ### Negative
77
+ - ⚠️ **Prompt bloat**: Too many inhibitors could exceed context window (mitigated by relevance filtering)
78
+ - ⚠️ **Pattern extraction is heuristic**: CI output parsing is imperfect
79
+ - ⚠️ **Requires storage**: Another file to manage
80
+
81
+ ## Comparison: Inhibitor vs Quarantine
82
+
83
+ | Mechanism | Scope | Trigger | Reversibility | Purpose |
84
+ |-----------|-------|---------|---------------|---------|
85
+ | **Inhibitor** | file + mode + pattern | Single failure | Decays (30-60 days) | "Don't try X on Y" |
86
+ | **Quarantine** | Entire file, all modes | 10 samples, no progress | Requires explorer success | "Stop all work on Y" |
87
+
88
+ A file can have many inhibitors without being quarantined. Quarantine is full withdrawal; inhibitors are warnings.
89
+
90
+ ## Implementation
91
+
92
+ ### Files
93
+ - `src/coordination/inhibitors.ts` - Emit, query, decay logic
94
+ - Integration in `src/agent/executor.ts` - Check after each run
95
+ - Integration in `src/agent/prompt-builder.ts` - Add to prompts
96
+ - GC in `src/storage/gc.ts` - Remove decayed inhibitors
97
+
98
+ ### CLI Commands
99
+ ```bash
100
+ npx claude-mycelium inhibitors list
101
+ npx claude-mycelium inhibitors show <file>
102
+ npx claude-mycelium inhibitors clear <id>
103
+ ```
104
+
105
+ ## Future Work
106
+ - Machine learning to improve pattern extraction
107
+ - Cluster similar inhibitors
108
+ - Inhibitor strength boosting (multiple hits → stronger signal)