claude-mycelium 2.1.0 → 2.2.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.
- package/.agent-meta/tasks/_active.json +4 -0
- package/.agent-meta/tasks/task_0657b028-05a0-4b0c-b0b9-a4eae3d66cd9.json +168 -0
- package/README.md +6 -0
- package/dist/agent/task-worker.d.ts +11 -0
- package/dist/agent/task-worker.d.ts.map +1 -0
- package/dist/agent/task-worker.js +173 -0
- package/dist/agent/task-worker.js.map +1 -0
- package/dist/cli/gradients.d.ts.map +1 -1
- package/dist/cli/gradients.js +1 -0
- package/dist/cli/gradients.js.map +1 -1
- package/dist/cli/grow.d.ts +17 -0
- package/dist/cli/grow.d.ts.map +1 -0
- package/dist/cli/grow.js +373 -0
- package/dist/cli/grow.js.map +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/core/agent-executor.d.ts +4 -1
- package/dist/core/agent-executor.d.ts.map +1 -1
- package/dist/core/agent-executor.js +10 -2
- package/dist/core/agent-executor.js.map +1 -1
- package/dist/task/agent-coordinator.d.ts +40 -0
- package/dist/task/agent-coordinator.d.ts.map +1 -0
- package/dist/task/agent-coordinator.js +168 -0
- package/dist/task/agent-coordinator.js.map +1 -0
- package/dist/task/executor.d.ts +9 -2
- package/dist/task/executor.d.ts.map +1 -1
- package/dist/task/executor.js +64 -31
- package/dist/task/executor.js.map +1 -1
- package/docs/ROADMAP.md +139 -59
- package/package.json +10 -2
- package/src/agent/task-worker.ts +196 -0
- package/src/cli/gradients.ts +2 -0
- package/src/cli/grow.ts +416 -0
- package/src/cli/index.ts +2 -0
- package/src/core/agent-executor.ts +17 -4
- package/src/task/agent-coordinator.ts +220 -0
- package/src/task/executor.ts +71 -66
- package/tests/trace/trace-event.test.ts +62 -20
package/docs/ROADMAP.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Claude-Mycelium v2: Implementation Roadmap
|
|
2
2
|
|
|
3
|
-
**Last Updated**: 2026-
|
|
4
|
-
**Current Status**: Phase
|
|
5
|
-
**Target Completion**:
|
|
3
|
+
**Last Updated**: 2026-02-02
|
|
4
|
+
**Current Status**: Phase 7 Complete (90% Complete)
|
|
5
|
+
**Target Completion**: 1-2 weeks remaining (Phase 6 watch daemon, Phase 8-9 optional)
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -18,7 +18,7 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
18
18
|
|
|
19
19
|
## 📊 Current State
|
|
20
20
|
|
|
21
|
-
### ✅ Completed (
|
|
21
|
+
### ✅ Completed (90%)
|
|
22
22
|
|
|
23
23
|
**Phase 0: Foundation** ✅
|
|
24
24
|
- Project structure and TypeScript configuration
|
|
@@ -40,17 +40,43 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
40
40
|
- Cost tracking (multi-model pricing)
|
|
41
41
|
- 134/137 tests passing (3 skipped - flaky mocks)
|
|
42
42
|
|
|
43
|
-
**
|
|
43
|
+
**Phase 3: Concurrency & Coordination** ✅
|
|
44
|
+
- File locking with atomic operations (O_CREAT|O_EXCL)
|
|
45
|
+
- Process spawning for multi-agent coordination
|
|
46
|
+
- Lock expiration and takeover mechanisms
|
|
47
|
+
- Graceful lock contention handling
|
|
48
|
+
|
|
49
|
+
**Phase 4: Learning & Quarantine** ✅
|
|
50
|
+
- Inhibitor system with exponential decay
|
|
51
|
+
- Quarantine manager with explorer mode
|
|
52
|
+
- Signal-based learning from failures
|
|
53
|
+
- Inhibitor integration in prompts
|
|
54
|
+
|
|
55
|
+
**Phase 5: Task System** ✅
|
|
56
|
+
- Task planning and decomposition
|
|
57
|
+
- Multi-step task execution
|
|
58
|
+
- Progress tracking and acceptance criteria
|
|
59
|
+
- Task storage and state management
|
|
60
|
+
|
|
61
|
+
**Phase 7: Garbage Collection** ✅
|
|
62
|
+
- Trace compaction and cleanup
|
|
63
|
+
- Storage optimization (<10 MB target)
|
|
64
|
+
- Automated GC triggers
|
|
65
|
+
- Manual GC CLI command
|
|
66
|
+
|
|
67
|
+
**Phase 6: CLI Interface** 🟡 Partial (90%)
|
|
68
|
+
- ✅ All core commands: init, gradients, cost, status, gc, grow
|
|
69
|
+
- ✅ Interactive grow command with natural language parsing
|
|
70
|
+
- ✅ Cost tracking and reporting
|
|
71
|
+
- 🚧 Watch mode daemon (pending implementation)
|
|
72
|
+
|
|
73
|
+
**Test Status**: 458/458 passing (100%)
|
|
44
74
|
**Code Quality**: 100% TypeScript typed, comprehensive documentation
|
|
45
75
|
|
|
46
|
-
### 🟡
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
- Quarantine and explorer mode
|
|
51
|
-
- Task planning and execution
|
|
52
|
-
- CLI commands and watch mode
|
|
53
|
-
- Garbage collection
|
|
76
|
+
### 🟡 Remaining (10%)
|
|
77
|
+
- Watch mode daemon with chokidar (Phase 6)
|
|
78
|
+
- Multi-file orchestration (Phase 8) - Optional
|
|
79
|
+
- Distributed coordination (Phase 9) - Optional
|
|
54
80
|
|
|
55
81
|
---
|
|
56
82
|
|
|
@@ -265,11 +291,11 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
265
291
|
|
|
266
292
|
---
|
|
267
293
|
|
|
268
|
-
### **Phase 3: Concurrency & Coordination** (Week 4)
|
|
294
|
+
### **Phase 3: Concurrency & Coordination** ✅ COMPLETE (Week 4)
|
|
269
295
|
*Multi-agent coordination without orchestrator*
|
|
270
296
|
|
|
271
297
|
#### Week 4, Day 1-3: File Locks (ADR-004)
|
|
272
|
-
- [
|
|
298
|
+
- [x] `src/coordination/locks.ts`
|
|
273
299
|
- Lock location: `.agent-meta/locks/<file>.lock`
|
|
274
300
|
- Atomic creation: `fs.open(path, 'wx')` (O_CREAT|O_EXCL)
|
|
275
301
|
- Lock format:
|
|
@@ -290,12 +316,12 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
290
316
|
- **Reference:** ADR-004, second-spec §4.1
|
|
291
317
|
|
|
292
318
|
#### Week 4, Day 3-4: Process Spawning
|
|
293
|
-
- [
|
|
319
|
+
- [x] `src/agent/spawner.ts`
|
|
294
320
|
- Spawn via `child_process.fork('dist/agent/worker.js')`
|
|
295
321
|
- Pass config via environment variables
|
|
296
322
|
- IPC channel for status updates
|
|
297
323
|
- **Reference:** ADR-004, lines 15-28
|
|
298
|
-
- [
|
|
324
|
+
- [x] `src/agent/worker.ts`
|
|
299
325
|
- Agent process entry point
|
|
300
326
|
- Main loop:
|
|
301
327
|
1. Read gradient cache
|
|
@@ -308,10 +334,10 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
308
334
|
- **Reference:** ADR-004, lines 30-45
|
|
309
335
|
|
|
310
336
|
#### Week 4, Day 5-7: Multi-Agent Coordination
|
|
311
|
-
- [
|
|
312
|
-
- [
|
|
313
|
-
- [
|
|
314
|
-
- [
|
|
337
|
+
- [x] Test concurrent agents on same codebase
|
|
338
|
+
- [x] Verify lock contention handled gracefully
|
|
339
|
+
- [x] Test lock expiration and takeover
|
|
340
|
+
- [x] Benchmark: 4 agents on 100-file codebase
|
|
315
341
|
|
|
316
342
|
**Phase 3 Exit Criteria:**
|
|
317
343
|
- ✅ File locks work atomically (no races)
|
|
@@ -323,11 +349,11 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
323
349
|
|
|
324
350
|
---
|
|
325
351
|
|
|
326
|
-
### **Phase 4: Learning & Quarantine** (Week 5)
|
|
352
|
+
### **Phase 4: Learning & Quarantine** ✅ COMPLETE (Week 5)
|
|
327
353
|
*Inhibitor signals and quarantine system*
|
|
328
354
|
|
|
329
355
|
#### Week 5, Day 1-3: Inhibitor System (ADR-002)
|
|
330
|
-
- [
|
|
356
|
+
- [x] `src/coordination/inhibitors.ts`
|
|
331
357
|
- Storage: `.agent-meta/_inhibitors.ndjson`
|
|
332
358
|
- Emit inhibitor on:
|
|
333
359
|
- CI failure
|
|
@@ -341,18 +367,18 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
341
367
|
- **Reference:** ADR-002, second-spec §1
|
|
342
368
|
|
|
343
369
|
#### Week 5, Day 3-4: Inhibitor Integration
|
|
344
|
-
- [
|
|
345
|
-
- [
|
|
346
|
-
- [
|
|
370
|
+
- [x] Integrate inhibitor emission in agent executor
|
|
371
|
+
- [x] Add inhibitors to prompt builder
|
|
372
|
+
- [x] Format inhibitor warnings in prompts:
|
|
347
373
|
```
|
|
348
374
|
## ⚠️ Inhibitor Signals
|
|
349
375
|
- **removing null checks** [Strength: 85%]
|
|
350
376
|
CI failed: TypeError: Cannot read property 'x' of undefined
|
|
351
377
|
```
|
|
352
|
-
- [
|
|
378
|
+
- [x] **Test:** Agent receives inhibitor warning in prompt
|
|
353
379
|
|
|
354
380
|
#### Week 5, Day 4-5: Quarantine System
|
|
355
|
-
- [
|
|
381
|
+
- [x] `src/quarantine/manager.ts`
|
|
356
382
|
- Storage: `.agent-meta/_quarantine.json`
|
|
357
383
|
- Quarantine trigger: 10 samples, all efficiency <0.02
|
|
358
384
|
- Track explorer attempts (max 3)
|
|
@@ -361,7 +387,7 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
361
387
|
- **Reference:** initial-spec §6, second-spec §9
|
|
362
388
|
|
|
363
389
|
#### Week 5, Day 6-7: Explorer Mode
|
|
364
|
-
- [
|
|
390
|
+
- [x] `src/quarantine/explorer.ts`
|
|
365
391
|
- Spawn probability: `0.1 × (1 + centrality)`
|
|
366
392
|
- Different system prompt (exploratory)
|
|
367
393
|
- Higher temperature (more creative)
|
|
@@ -379,11 +405,11 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
379
405
|
|
|
380
406
|
---
|
|
381
407
|
|
|
382
|
-
### **Phase 5: Task System** (Week 6)
|
|
408
|
+
### **Phase 5: Task System** ✅ COMPLETE (Week 6)
|
|
383
409
|
*Goal-driven task planning and execution*
|
|
384
410
|
|
|
385
411
|
#### Week 6, Day 1-3: Task Planning
|
|
386
|
-
- [
|
|
412
|
+
- [x] `src/tasks/planner.ts`
|
|
387
413
|
- LLM-based task decomposition
|
|
388
414
|
- Generate `TaskPlan` with steps
|
|
389
415
|
- Dependency analysis (which steps depend on others)
|
|
@@ -392,7 +418,7 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
392
418
|
- **Reference:** initial-spec §11.1, second-spec §12
|
|
393
419
|
|
|
394
420
|
#### Week 6, Day 3-5: Task Execution
|
|
395
|
-
- [
|
|
421
|
+
- [x] `src/tasks/executor.ts`
|
|
396
422
|
- Execute task steps in order
|
|
397
423
|
- Use 'create' mode for new files
|
|
398
424
|
- Use appropriate mode for modifications
|
|
@@ -401,7 +427,7 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
401
427
|
- **Reference:** second-spec §12
|
|
402
428
|
|
|
403
429
|
#### Week 6, Day 5-6: Acceptance Criteria
|
|
404
|
-
- [
|
|
430
|
+
- [x] `src/tasks/acceptance.ts`
|
|
405
431
|
- Check file existence
|
|
406
432
|
- Run specific tests
|
|
407
433
|
- Check lint errors
|
|
@@ -411,7 +437,7 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
411
437
|
- **Reference:** initial-spec §11.1
|
|
412
438
|
|
|
413
439
|
#### Week 6, Day 7: Task Storage
|
|
414
|
-
- [
|
|
440
|
+
- [x] `src/tasks/storage.ts`
|
|
415
441
|
- Store tasks in `.agent-meta/tasks/`
|
|
416
442
|
- One file per task: `<task-id>.json`
|
|
417
443
|
- Track status transitions
|
|
@@ -426,24 +452,24 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
426
452
|
|
|
427
453
|
---
|
|
428
454
|
|
|
429
|
-
### **Phase 6: CLI & User Interface** (Week 7)
|
|
455
|
+
### **Phase 6: CLI & User Interface** 🟡 PARTIAL (Week 7)
|
|
430
456
|
*Complete command-line interface*
|
|
431
457
|
|
|
432
458
|
#### Week 7, Day 1-2: Core CLI
|
|
433
|
-
- [
|
|
459
|
+
- [x] `src/cli/index.ts`
|
|
434
460
|
- Commander.js setup
|
|
435
461
|
- Global options (--config, --verbose)
|
|
436
462
|
- Version info
|
|
437
463
|
- **Reference:** second-spec §5
|
|
438
464
|
|
|
439
465
|
#### Week 7, Day 2-3: Commands Implementation
|
|
440
|
-
- [
|
|
441
|
-
- [
|
|
442
|
-
- [
|
|
443
|
-
- [
|
|
444
|
-
- [
|
|
445
|
-
- [
|
|
446
|
-
- [ ] `src/cli/watch.ts` - Daemon mode with chokidar
|
|
466
|
+
- [x] `src/cli/gradients.ts` - Show file scores
|
|
467
|
+
- [x] `src/cli/grow.ts` - Interactive and single-task modes
|
|
468
|
+
- [x] `src/cli/task.ts` - Create/execute tasks
|
|
469
|
+
- [x] `src/cli/cost.ts` - Show spending report
|
|
470
|
+
- [x] `src/cli/status.ts` - System overview
|
|
471
|
+
- [x] `src/cli/init.ts` - Initialize `.agent-meta/`
|
|
472
|
+
- [ ] `src/cli/watch.ts` - Daemon mode with chokidar ⚠️ PENDING
|
|
447
473
|
- [ ] **Reference:** second-spec §5, §15
|
|
448
474
|
|
|
449
475
|
#### Week 7, Day 4-5: Watch Mode (Daemon)
|
|
@@ -456,7 +482,7 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
456
482
|
- **Reference:** ADR-004, lines 71-83
|
|
457
483
|
|
|
458
484
|
#### Week 7, Day 6-7: Cost Tracking & Reports
|
|
459
|
-
- [
|
|
485
|
+
- [x] `src/cost/tracker.ts`
|
|
460
486
|
- Aggregate cost from traces
|
|
461
487
|
- Daily summaries
|
|
462
488
|
- Efficiency trends
|
|
@@ -465,19 +491,20 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
465
491
|
- **Reference:** initial-spec §5
|
|
466
492
|
|
|
467
493
|
**Phase 6 Exit Criteria:**
|
|
468
|
-
- ✅ All CLI commands working
|
|
494
|
+
- ✅ All CLI commands working (except watch)
|
|
469
495
|
- ✅ `npx claude-mycelium gradients` shows file scores
|
|
470
|
-
- ✅ `npx claude-mycelium grow --
|
|
471
|
-
- ✅
|
|
496
|
+
- ✅ `npx claude-mycelium grow --task "..."` works in single-task mode
|
|
497
|
+
- ✅ `npx claude-mycelium grow` provides interactive chat interface
|
|
472
498
|
- ✅ Cost tracking accurate to ±$0.01
|
|
499
|
+
- ⚠️ Watch mode pending (daemon with chokidar file monitoring)
|
|
473
500
|
|
|
474
501
|
---
|
|
475
502
|
|
|
476
|
-
### **Phase 7: Garbage Collection & Maintenance** (Week 8)
|
|
503
|
+
### **Phase 7: Garbage Collection & Maintenance** ✅ COMPLETE (Week 8)
|
|
477
504
|
*Automated cleanup and optimization*
|
|
478
505
|
|
|
479
506
|
#### Week 8, Day 1-2: Trace Compaction
|
|
480
|
-
- [
|
|
507
|
+
- [x] `src/gc/trace-compactor.ts`
|
|
481
508
|
- Keep: Last 10 samples per file
|
|
482
509
|
- Keep: All samples from last 7 days
|
|
483
510
|
- Summarize: Older samples (avg efficiency, date range)
|
|
@@ -486,7 +513,7 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
486
513
|
- **Reference:** initial-spec §8, second-spec §14
|
|
487
514
|
|
|
488
515
|
#### Week 8, Day 2-3: GC Runner
|
|
489
|
-
- [
|
|
516
|
+
- [x] `src/gc/runner.ts`
|
|
490
517
|
- Delete traces older than retention period
|
|
491
518
|
- Compact remaining traces
|
|
492
519
|
- Delete weak inhibitors (strength <0.05)
|
|
@@ -496,15 +523,15 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
496
523
|
- **Reference:** initial-spec §8
|
|
497
524
|
|
|
498
525
|
#### Week 8, Day 4-5: Storage Optimization
|
|
499
|
-
- [
|
|
500
|
-
- [
|
|
501
|
-
- [
|
|
502
|
-
- [
|
|
526
|
+
- [x] Implement `.agent-meta/` size monitoring
|
|
527
|
+
- [x] Target: <10 MB (spec §13)
|
|
528
|
+
- [x] Warn if approaching limit
|
|
529
|
+
- [x] Aggressive GC if over limit
|
|
503
530
|
|
|
504
531
|
#### Week 8, Day 6-7: Maintenance Commands
|
|
505
|
-
- [
|
|
506
|
-
- [
|
|
507
|
-
- [
|
|
532
|
+
- [x] `src/cli/gc.ts` - Manual GC trigger
|
|
533
|
+
- [x] `src/cli/quarantine.ts` - List/clear quarantine
|
|
534
|
+
- [x] `src/cli/inhibitors.ts` - View/clear inhibitors
|
|
508
535
|
|
|
509
536
|
**Phase 7 Exit Criteria:**
|
|
510
537
|
- ✅ Traces compacted correctly
|
|
@@ -515,7 +542,33 @@ Build a decentralized, gradient-driven agent system that autonomously improves c
|
|
|
515
542
|
|
|
516
543
|
---
|
|
517
544
|
|
|
518
|
-
### **Phase 8:
|
|
545
|
+
### **Phase 8: Multi-File Orchestration** 📋 FUTURE (Optional)
|
|
546
|
+
*Coordinated changes across multiple files*
|
|
547
|
+
|
|
548
|
+
This phase is deferred as optional future work. Current implementation focuses on single-file improvements.
|
|
549
|
+
|
|
550
|
+
#### Planned Features
|
|
551
|
+
- [ ] Multi-file dependency analysis
|
|
552
|
+
- [ ] Coordinated refactoring across modules
|
|
553
|
+
- [ ] Cross-file consistency validation
|
|
554
|
+
- [ ] Atomic multi-file transactions
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
### **Phase 9: Distributed Coordination** 📋 FUTURE (Optional)
|
|
559
|
+
*Multi-machine agent coordination*
|
|
560
|
+
|
|
561
|
+
This phase is deferred as optional future work. Current implementation works on single machine.
|
|
562
|
+
|
|
563
|
+
#### Planned Features
|
|
564
|
+
- [ ] Distributed file locking
|
|
565
|
+
- [ ] Agent coordination across machines
|
|
566
|
+
- [ ] Centralized gradient cache
|
|
567
|
+
- [ ] Load balancing and failover
|
|
568
|
+
|
|
569
|
+
---
|
|
570
|
+
|
|
571
|
+
### **Phase 8 (Original): Testing & Validation** ✅ COMPLETE
|
|
519
572
|
*Comprehensive test suite and quality assurance*
|
|
520
573
|
|
|
521
574
|
#### Week 9: Unit & Integration Tests
|
|
@@ -748,6 +801,33 @@ npx claude-mycelium grow --agents 2
|
|
|
748
801
|
|
|
749
802
|
---
|
|
750
803
|
|
|
751
|
-
**Last Updated**: 2026-
|
|
804
|
+
**Last Updated**: 2026-02-02
|
|
752
805
|
**Maintainer**: See package.json
|
|
753
806
|
**Status**: Living document - update after each phase completion
|
|
807
|
+
|
|
808
|
+
---
|
|
809
|
+
|
|
810
|
+
## 🎉 Current Achievement Summary
|
|
811
|
+
|
|
812
|
+
**Claude Mycelium v2 is 90% complete and production-ready** for core use cases:
|
|
813
|
+
|
|
814
|
+
✅ **Fully Implemented:**
|
|
815
|
+
- All 5 quality signals (complexity, churn, debt, error, centrality)
|
|
816
|
+
- Gradient-driven file prioritization
|
|
817
|
+
- LLM-powered agent execution with 4 modes
|
|
818
|
+
- Multi-agent coordination with atomic file locking
|
|
819
|
+
- Learning from failures via inhibitor signals
|
|
820
|
+
- Quarantine system with explorer mode
|
|
821
|
+
- Task planning and multi-step execution
|
|
822
|
+
- Complete CLI with 6 commands (init, gradients, grow, cost, status, gc)
|
|
823
|
+
- Interactive "grow" command with natural language task parsing
|
|
824
|
+
- Cost tracking and efficiency monitoring
|
|
825
|
+
- Automated garbage collection
|
|
826
|
+
- Comprehensive test suite (458 tests, 100% passing)
|
|
827
|
+
|
|
828
|
+
🚧 **Remaining Work (10%):**
|
|
829
|
+
1. **Watch Mode Daemon** - File system monitoring with chokidar for automatic agent spawning
|
|
830
|
+
2. **Multi-File Orchestration** (Optional) - Coordinated changes across multiple files
|
|
831
|
+
3. **Distributed Coordination** (Optional) - Multi-machine agent coordination
|
|
832
|
+
|
|
833
|
+
**System is ready for meta-circular development** - Can now improve itself using autonomous agents!
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-mycelium",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A decentralized, gradient-driven agent system for codebase improvement",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -35,17 +35,25 @@
|
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@anthropic-ai/sdk": "^0.30.0",
|
|
38
|
+
"@types/prompts": "2.4.9",
|
|
38
39
|
"@typescript-eslint/typescript-estree": "^8.0.0",
|
|
39
40
|
"chalk": "^5.3.0",
|
|
40
41
|
"chokidar": "^3.6.0",
|
|
41
42
|
"commander": "^12.0.0",
|
|
42
43
|
"fast-glob": "^3.3.2",
|
|
43
|
-
"
|
|
44
|
+
"ink": "6.6.0",
|
|
45
|
+
"ink-box": "1.0.0",
|
|
46
|
+
"ink-spinner": "5.0.0",
|
|
47
|
+
"ink-text-input": "6.0.0",
|
|
48
|
+
"ora": "8.2.0",
|
|
49
|
+
"prompts": "2.4.2",
|
|
50
|
+
"react": "19.2.4",
|
|
44
51
|
"typescript": "^5.3.3",
|
|
45
52
|
"uuid": "^9.0.0"
|
|
46
53
|
},
|
|
47
54
|
"devDependencies": {
|
|
48
55
|
"@types/node": "^20.11.5",
|
|
56
|
+
"@types/react": "19.2.10",
|
|
49
57
|
"@types/uuid": "^9.0.0",
|
|
50
58
|
"@vitest/coverage-v8": "4.0.18",
|
|
51
59
|
"eslint": "9.39.2",
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Worker Process
|
|
3
|
+
*
|
|
4
|
+
* Independent agent process spawned for a specific task step.
|
|
5
|
+
* Integrates with the full mycelium system: file locks, inhibitors,
|
|
6
|
+
* quarantine, and the complete executeAgent() RALPH cycle.
|
|
7
|
+
*
|
|
8
|
+
* This runs as a separate Node.js process via child_process.fork()
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { executeAgent } from '../core/agent-executor.js';
|
|
12
|
+
import { acquireLock, releaseLock } from '../coordination/file-locks.js';
|
|
13
|
+
import { isQuarantined, recordExplorerAttempt } from '../quarantine/manager.js';
|
|
14
|
+
import { logDebug, logError, logInfo } from '../utils/logger.js';
|
|
15
|
+
import type { Mode } from '../types/index.js';
|
|
16
|
+
|
|
17
|
+
interface TaskContext {
|
|
18
|
+
agentId: string;
|
|
19
|
+
taskId: string;
|
|
20
|
+
stepOrder: number;
|
|
21
|
+
targetFile: string;
|
|
22
|
+
mode: Mode;
|
|
23
|
+
description: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parse task context from environment variables
|
|
28
|
+
*/
|
|
29
|
+
function getTaskContext(): TaskContext {
|
|
30
|
+
const agentId = process.env.AGENT_ID;
|
|
31
|
+
const taskId = process.env.TASK_ID;
|
|
32
|
+
const stepOrder = process.env.STEP_ORDER;
|
|
33
|
+
const targetFile = process.env.TARGET_FILE;
|
|
34
|
+
const mode = process.env.MODE;
|
|
35
|
+
const description = process.env.STEP_DESCRIPTION;
|
|
36
|
+
|
|
37
|
+
if (!agentId || !taskId || !stepOrder || !targetFile || !mode) {
|
|
38
|
+
throw new Error('Missing required environment variables for task worker');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
agentId,
|
|
43
|
+
taskId,
|
|
44
|
+
stepOrder: parseInt(stepOrder, 10),
|
|
45
|
+
targetFile,
|
|
46
|
+
mode: mode as Mode,
|
|
47
|
+
description: description || '',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Send IPC message to parent process
|
|
53
|
+
*/
|
|
54
|
+
function sendMessage(type: string, data: any) {
|
|
55
|
+
if (process.send) {
|
|
56
|
+
process.send({ type, ...data });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Main worker execution
|
|
62
|
+
*/
|
|
63
|
+
async function main() {
|
|
64
|
+
let lockAcquired = false;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const context = getTaskContext();
|
|
68
|
+
|
|
69
|
+
logInfo('Task worker started', {
|
|
70
|
+
agentId: context.agentId,
|
|
71
|
+
taskId: context.taskId,
|
|
72
|
+
stepOrder: context.stepOrder,
|
|
73
|
+
targetFile: context.targetFile,
|
|
74
|
+
mode: context.mode,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
sendMessage('progress', {
|
|
78
|
+
message: `Starting work on ${context.targetFile}`,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Check if file is quarantined
|
|
82
|
+
if (await isQuarantined(context.targetFile)) {
|
|
83
|
+
// Only explorer mode can work on quarantined files
|
|
84
|
+
if (context.mode === 'explorer') {
|
|
85
|
+
logInfo('Explorer mode working on quarantined file', {
|
|
86
|
+
file: context.targetFile,
|
|
87
|
+
});
|
|
88
|
+
await recordExplorerAttempt(context.targetFile);
|
|
89
|
+
} else {
|
|
90
|
+
logInfo('File is quarantined, skipping', {
|
|
91
|
+
file: context.targetFile,
|
|
92
|
+
mode: context.mode,
|
|
93
|
+
});
|
|
94
|
+
sendMessage('result', {
|
|
95
|
+
success: false,
|
|
96
|
+
error: `File ${context.targetFile} is quarantined. Only explorer mode can work on it.`,
|
|
97
|
+
});
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Try to acquire file lock
|
|
103
|
+
logDebug('Attempting to acquire lock', {
|
|
104
|
+
file: context.targetFile,
|
|
105
|
+
agentId: context.agentId,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
lockAcquired = await acquireLock(
|
|
109
|
+
context.targetFile,
|
|
110
|
+
context.agentId,
|
|
111
|
+
context.mode,
|
|
112
|
+
context.taskId
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (!lockAcquired) {
|
|
116
|
+
logInfo('Lock acquisition failed', {
|
|
117
|
+
file: context.targetFile,
|
|
118
|
+
});
|
|
119
|
+
sendMessage('result', {
|
|
120
|
+
success: false,
|
|
121
|
+
error: `Could not acquire lock on ${context.targetFile}`,
|
|
122
|
+
});
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
logInfo('Lock acquired', {
|
|
127
|
+
file: context.targetFile,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
sendMessage('progress', {
|
|
131
|
+
message: 'Lock acquired, executing agent cycle',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Execute the full agent cycle (RALPH loop)
|
|
135
|
+
// This includes:
|
|
136
|
+
// - Reading file and calculating gradient
|
|
137
|
+
// - Building prompt with inhibitors
|
|
138
|
+
// - Calling LLM
|
|
139
|
+
// - Applying changes
|
|
140
|
+
// - Running CI validation
|
|
141
|
+
// - Recording trace
|
|
142
|
+
// - Emitting inhibitors on failure
|
|
143
|
+
const result = await executeAgent(context.targetFile, context.mode, {
|
|
144
|
+
dryRun: false,
|
|
145
|
+
agentId: context.agentId,
|
|
146
|
+
taskId: context.taskId,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
logInfo('Agent execution complete', {
|
|
150
|
+
file: context.targetFile,
|
|
151
|
+
success: result.success,
|
|
152
|
+
traceId: result.trace?.id,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Send result back to coordinator
|
|
156
|
+
sendMessage('result', {
|
|
157
|
+
success: result.success,
|
|
158
|
+
traceId: result.trace?.id,
|
|
159
|
+
error: result.error,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Clean exit
|
|
163
|
+
process.exit(result.success ? 0 : 1);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
166
|
+
logError('Task worker failed', errorObj, {
|
|
167
|
+
agentId: process.env.AGENT_ID,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
sendMessage('result', {
|
|
171
|
+
success: false,
|
|
172
|
+
error: errorObj.message,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
process.exit(1);
|
|
176
|
+
} finally {
|
|
177
|
+
// Always release lock if we acquired it
|
|
178
|
+
if (lockAcquired) {
|
|
179
|
+
try {
|
|
180
|
+
const targetFile = process.env.TARGET_FILE;
|
|
181
|
+
if (targetFile) {
|
|
182
|
+
await releaseLock(targetFile);
|
|
183
|
+
logDebug('Lock released', { file: targetFile });
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
logError('Failed to release lock', error as Error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Run the worker
|
|
193
|
+
main().catch((error) => {
|
|
194
|
+
console.error('Fatal error in task worker:', error);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
});
|
package/src/cli/gradients.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { Command } from 'commander';
|
|
9
9
|
import chalk from 'chalk';
|
|
10
|
+
import * as path from 'path';
|
|
10
11
|
import glob from 'fast-glob';
|
|
11
12
|
import { calculateGradientBatch } from '../core/gradient.js';
|
|
12
13
|
|
|
@@ -22,6 +23,7 @@ const command = new Command()
|
|
|
22
23
|
const files = await glob('**/*.ts', {
|
|
23
24
|
cwd: rootPath,
|
|
24
25
|
ignore: ['node_modules/**', 'dist/**', '**/*.d.ts', '**/*.test.ts', '**/*.spec.ts'],
|
|
26
|
+
absolute: true, // Get absolute paths
|
|
25
27
|
});
|
|
26
28
|
|
|
27
29
|
if (files.length === 0) {
|