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.
Files changed (39) hide show
  1. package/.agent-meta/tasks/_active.json +4 -0
  2. package/.agent-meta/tasks/task_0657b028-05a0-4b0c-b0b9-a4eae3d66cd9.json +168 -0
  3. package/README.md +6 -0
  4. package/dist/agent/task-worker.d.ts +11 -0
  5. package/dist/agent/task-worker.d.ts.map +1 -0
  6. package/dist/agent/task-worker.js +173 -0
  7. package/dist/agent/task-worker.js.map +1 -0
  8. package/dist/cli/gradients.d.ts.map +1 -1
  9. package/dist/cli/gradients.js +1 -0
  10. package/dist/cli/gradients.js.map +1 -1
  11. package/dist/cli/grow.d.ts +17 -0
  12. package/dist/cli/grow.d.ts.map +1 -0
  13. package/dist/cli/grow.js +373 -0
  14. package/dist/cli/grow.js.map +1 -0
  15. package/dist/cli/index.d.ts.map +1 -1
  16. package/dist/cli/index.js +2 -0
  17. package/dist/cli/index.js.map +1 -1
  18. package/dist/core/agent-executor.d.ts +4 -1
  19. package/dist/core/agent-executor.d.ts.map +1 -1
  20. package/dist/core/agent-executor.js +10 -2
  21. package/dist/core/agent-executor.js.map +1 -1
  22. package/dist/task/agent-coordinator.d.ts +40 -0
  23. package/dist/task/agent-coordinator.d.ts.map +1 -0
  24. package/dist/task/agent-coordinator.js +168 -0
  25. package/dist/task/agent-coordinator.js.map +1 -0
  26. package/dist/task/executor.d.ts +9 -2
  27. package/dist/task/executor.d.ts.map +1 -1
  28. package/dist/task/executor.js +64 -31
  29. package/dist/task/executor.js.map +1 -1
  30. package/docs/ROADMAP.md +139 -59
  31. package/package.json +10 -2
  32. package/src/agent/task-worker.ts +196 -0
  33. package/src/cli/gradients.ts +2 -0
  34. package/src/cli/grow.ts +416 -0
  35. package/src/cli/index.ts +2 -0
  36. package/src/core/agent-executor.ts +17 -4
  37. package/src/task/agent-coordinator.ts +220 -0
  38. package/src/task/executor.ts +71 -66
  39. package/tests/trace/trace-event.test.ts +62 -20
package/README.md CHANGED
@@ -30,6 +30,9 @@ export ANTHROPIC_API_KEY=sk-ant-...
30
30
  ### CLI Commands
31
31
 
32
32
  ```bash
33
+ # Interactive mode - chat with mycelium to spawn agents
34
+ npx claude-mycelium grow
35
+
33
36
  # Check code quality scores
34
37
  npx claude-mycelium gradients ./src
35
38
 
@@ -41,6 +44,9 @@ npx claude-mycelium cost
41
44
 
42
45
  # Run garbage collection
43
46
  npx claude-mycelium gc
47
+
48
+ # Single task mode
49
+ npx claude-mycelium grow --task "fix bugs in src/api.ts"
44
50
  ```
45
51
 
46
52
  ## ✨ Features
@@ -0,0 +1,11 @@
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
+ export {};
11
+ //# sourceMappingURL=task-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-worker.d.ts","sourceRoot":"","sources":["../../src/agent/task-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,173 @@
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
+ import { executeAgent } from '../core/agent-executor.js';
11
+ import { tryAcquireLock, releaseLock } from '../coordination/file-locks.js';
12
+ import { isQuarantined, recordExplorerAttempt } from '../quarantine/manager.js';
13
+ import { logDebug, logError, logInfo } from '../utils/logger.js';
14
+ /**
15
+ * Parse task context from environment variables
16
+ */
17
+ function getTaskContext() {
18
+ const agentId = process.env.AGENT_ID;
19
+ const taskId = process.env.TASK_ID;
20
+ const stepOrder = process.env.STEP_ORDER;
21
+ const targetFile = process.env.TARGET_FILE;
22
+ const mode = process.env.MODE;
23
+ const description = process.env.STEP_DESCRIPTION;
24
+ if (!agentId || !taskId || !stepOrder || !targetFile || !mode) {
25
+ throw new Error('Missing required environment variables for task worker');
26
+ }
27
+ return {
28
+ agentId,
29
+ taskId,
30
+ stepOrder: parseInt(stepOrder, 10),
31
+ targetFile,
32
+ mode: mode,
33
+ description: description || '',
34
+ };
35
+ }
36
+ /**
37
+ * Send IPC message to parent process
38
+ */
39
+ function sendMessage(type, data) {
40
+ if (process.send) {
41
+ process.send({ type, ...data });
42
+ }
43
+ }
44
+ /**
45
+ * Main worker execution
46
+ */
47
+ async function main() {
48
+ let lockAcquired = false;
49
+ let lockId;
50
+ try {
51
+ const context = getTaskContext();
52
+ logInfo('Task worker started', {
53
+ agentId: context.agentId,
54
+ taskId: context.taskId,
55
+ stepOrder: context.stepOrder,
56
+ targetFile: context.targetFile,
57
+ mode: context.mode,
58
+ });
59
+ sendMessage('progress', {
60
+ message: `Starting work on ${context.targetFile}`,
61
+ });
62
+ // Check if file is quarantined
63
+ if (await isQuarantined(context.targetFile)) {
64
+ // Only explorer mode can work on quarantined files
65
+ if (context.mode === 'explorer') {
66
+ logInfo('Explorer mode working on quarantined file', {
67
+ file: context.targetFile,
68
+ });
69
+ await recordExplorerAttempt(context.targetFile);
70
+ }
71
+ else {
72
+ logInfo('File is quarantined, skipping', {
73
+ file: context.targetFile,
74
+ mode: context.mode,
75
+ });
76
+ sendMessage('result', {
77
+ success: false,
78
+ error: `File ${context.targetFile} is quarantined. Only explorer mode can work on it.`,
79
+ });
80
+ process.exit(1);
81
+ }
82
+ }
83
+ // Try to acquire file lock
84
+ logDebug('Attempting to acquire lock', {
85
+ file: context.targetFile,
86
+ agentId: context.agentId,
87
+ });
88
+ const lockResult = await tryAcquireLock(context.targetFile, {
89
+ agent_id: context.agentId,
90
+ task_id: context.taskId,
91
+ mode: context.mode,
92
+ });
93
+ if (!lockResult.acquired) {
94
+ logInfo('Lock acquisition failed', {
95
+ file: context.targetFile,
96
+ reason: lockResult.reason,
97
+ });
98
+ sendMessage('result', {
99
+ success: false,
100
+ error: `Could not acquire lock: ${lockResult.reason}`,
101
+ });
102
+ process.exit(1);
103
+ }
104
+ lockAcquired = true;
105
+ lockId = lockResult.lockId;
106
+ logInfo('Lock acquired', {
107
+ file: context.targetFile,
108
+ lockId,
109
+ });
110
+ sendMessage('progress', {
111
+ message: 'Lock acquired, executing agent cycle',
112
+ });
113
+ // Execute the full agent cycle (RALPH loop)
114
+ // This includes:
115
+ // - Reading file and calculating gradient
116
+ // - Building prompt with inhibitors
117
+ // - Calling LLM
118
+ // - Applying changes
119
+ // - Running CI validation
120
+ // - Recording trace
121
+ // - Emitting inhibitors on failure
122
+ const result = await executeAgent(context.targetFile, context.mode, {
123
+ dryRun: false,
124
+ agentId: context.agentId,
125
+ taskId: context.taskId,
126
+ });
127
+ logInfo('Agent execution complete', {
128
+ file: context.targetFile,
129
+ success: result.success,
130
+ traceId: result.trace?.id,
131
+ });
132
+ // Send result back to coordinator
133
+ sendMessage('result', {
134
+ success: result.success,
135
+ traceId: result.trace?.id,
136
+ error: result.error,
137
+ });
138
+ // Clean exit
139
+ process.exit(result.success ? 0 : 1);
140
+ }
141
+ catch (error) {
142
+ const errorObj = error instanceof Error ? error : new Error(String(error));
143
+ logError('Task worker failed', errorObj, {
144
+ agentId: process.env.AGENT_ID,
145
+ });
146
+ sendMessage('result', {
147
+ success: false,
148
+ error: errorObj.message,
149
+ });
150
+ process.exit(1);
151
+ }
152
+ finally {
153
+ // Always release lock if we acquired it
154
+ if (lockAcquired && lockId) {
155
+ try {
156
+ const targetFile = process.env.TARGET_FILE;
157
+ if (targetFile) {
158
+ await releaseLock(targetFile, lockId);
159
+ logDebug('Lock released', { file: targetFile, lockId });
160
+ }
161
+ }
162
+ catch (error) {
163
+ logError('Failed to release lock', error, { lockId });
164
+ }
165
+ }
166
+ }
167
+ }
168
+ // Run the worker
169
+ main().catch((error) => {
170
+ console.error('Fatal error in task worker:', error);
171
+ process.exit(1);
172
+ });
173
+ //# sourceMappingURL=task-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-worker.js","sourceRoot":"","sources":["../../src/agent/task-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAYjE;;GAEG;AACH,SAAS,cAAc;IACrB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACrC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IACnC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IACzC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;IAC9B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAEjD,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC;QAC9D,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO;QACL,OAAO;QACP,MAAM;QACN,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC;QAClC,UAAU;QACV,IAAI,EAAE,IAAY;QAClB,WAAW,EAAE,WAAW,IAAI,EAAE;KAC/B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,WA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,CAAC;oBACf,MAAM,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;oBACtC,QAAQ,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;gBAC1D,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,QAAQ,CAAC,wBAAwB,EAAE,KAAc,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;YACjE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,iBAAiB;AACjB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"gradients.d.ts","sourceRoot":"","sources":["../../src/cli/gradients.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,QAAA,MAAM,OAAO,SAgFT,CAAC;AAEL,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"gradients.d.ts","sourceRoot":"","sources":["../../src/cli/gradients.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,QAAA,MAAM,OAAO,SAiFT,CAAC;AAEL,eAAe,OAAO,CAAC"}
@@ -20,6 +20,7 @@ const command = new Command()
20
20
  const files = await glob('**/*.ts', {
21
21
  cwd: rootPath,
22
22
  ignore: ['node_modules/**', 'dist/**', '**/*.d.ts', '**/*.test.ts', '**/*.spec.ts'],
23
+ absolute: true, // Get absolute paths
23
24
  });
24
25
  if (files.length === 0) {
25
26
  console.log(chalk.yellow('No TypeScript files found'));
@@ -1 +1 @@
1
- {"version":3,"file":"gradients.js","sourceRoot":"","s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command - Interactive Mycelium Growth Interface
3
+ *
4
+ * Interactive terminal for spawning agents to improve your codebase
5
+ * Usage: npx claude-mycelium grow
6
+ */
7
+ import { Command } from 'commander';
8
+ /**
9
+ * Start interactive grow session
10
+ */
11
+ export declare function startGrowSession(): Promise<void>;
12
+ /**
13
+ * Commander.js command definition
14
+ */
15
+ declare const command: Command;
16
+ export default command;
17
+ //# sourceMappingURL=grow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grow.d.ts","sourceRoot":"","sources":["../../src/cli/grow.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkHpC;;GAEG;AACH,wBAAsB,gBAAgB,kBA6MrC;AAED;;GAEG;AACH,QAAA,MAAM,OAAO,SA+ET,CAAC;AAEL,eAAe,OAAO,CAAC"}
@@ -0,0 +1,373 @@
1
+ /**
2
+ * Grow CLI Command - Interactive Mycelium Growth Interface
3
+ *
4
+ * Interactive terminal for spawning agents to improve your codebase
5
+ * Usage: npx claude-mycelium grow
6
+ */
7
+ import { Command } from 'commander';
8
+ import prompts from 'prompts';
9
+ import chalk from 'chalk';
10
+ import ora from 'ora';
11
+ import { executeAgent } from '../core/agent-executor.js';
12
+ import { calculateGradient } from '../core/gradient.js';
13
+ import { planTask, executeTask } from '../task/index.js';
14
+ import { storeTask } from '../task/storage.js';
15
+ import { randomUUID } from 'crypto';
16
+ /**
17
+ * Parse natural language task into action
18
+ */
19
+ function parseTask(input) {
20
+ const lower = input.toLowerCase().trim();
21
+ if (lower === 'help' || lower === '?') {
22
+ return { type: 'help' };
23
+ }
24
+ if (lower === 'exit' || lower === 'quit' || lower === 'q') {
25
+ return { type: 'exit' };
26
+ }
27
+ if (lower.startsWith('analyze ') || lower.startsWith('check ')) {
28
+ const file = lower.split(/\s+/).slice(1).join(' ');
29
+ return { type: 'analyze', file };
30
+ }
31
+ // Check if input has a file path - if so, use quick spawn commands
32
+ const file = extractFilePath(input);
33
+ if (file) {
34
+ // File-specific quick commands
35
+ if (lower.includes('fix') || lower.includes('bug') || lower.includes('error')) {
36
+ return { type: 'spawn', mode: 'error_reducer', file };
37
+ }
38
+ if (lower.includes('complex') || lower.includes('simplify') || lower.includes('reduce')) {
39
+ return { type: 'spawn', mode: 'complexity_reducer', file };
40
+ }
41
+ if (lower.includes('clean') || lower.includes('debt') || lower.includes('lint')) {
42
+ return { type: 'spawn', mode: 'debt_payer', file };
43
+ }
44
+ if (lower.includes('stabil') || lower.includes('churn')) {
45
+ return { type: 'spawn', mode: 'stabilizer', file };
46
+ }
47
+ // Has file but no recognized keywords - analyze it
48
+ return { type: 'analyze', file };
49
+ }
50
+ // No file path - treat as general task (like "implement MCP", "add health check", etc.)
51
+ // Keywords that indicate a general task
52
+ if (lower.includes('implement') ||
53
+ lower.includes('create') ||
54
+ lower.includes('add') ||
55
+ lower.includes('build') ||
56
+ lower.includes('make') ||
57
+ lower.includes('develop') ||
58
+ lower.includes('write') ||
59
+ lower.startsWith('let\'s')) {
60
+ return { type: 'task', description: input };
61
+ }
62
+ return { type: 'help' };
63
+ }
64
+ /**
65
+ * Extract file path from natural language
66
+ */
67
+ function extractFilePath(input) {
68
+ const words = input.split(/\s+/);
69
+ const fileWord = words.find((w) => w.includes('/') || w.endsWith('.ts') || w.endsWith('.js') || w.endsWith('.tsx') || w.endsWith('.jsx'));
70
+ return fileWord;
71
+ }
72
+ /**
73
+ * Show help message
74
+ */
75
+ function showHelp() {
76
+ console.log('');
77
+ console.log(chalk.bold.green('🍄 Claude Mycelium - Interactive Growth'));
78
+ console.log('');
79
+ console.log(chalk.bold('General Tasks (Multi-Step):'));
80
+ console.log('');
81
+ console.log(chalk.cyan(' "implement MCP server"') + ' - Plan and execute multi-step task');
82
+ console.log(chalk.cyan(' "add health check endpoint"') + ' - Create feature with tests');
83
+ console.log(chalk.cyan(' "create authentication system"') + ' - Build complete feature');
84
+ console.log('');
85
+ console.log(chalk.bold('File-Specific Commands (Quick):'));
86
+ console.log('');
87
+ console.log(chalk.cyan(' "fix bugs in src/api.ts"') + ' - Spawn error_reducer agent');
88
+ console.log(chalk.cyan(' "reduce complexity in src/utils.ts"') + ' - Spawn complexity_reducer agent');
89
+ console.log(chalk.cyan(' "clean up src/legacy.ts"') + ' - Spawn debt_payer agent');
90
+ console.log(chalk.cyan(' "stabilize src/volatile.ts"') + ' - Spawn stabilizer agent');
91
+ console.log(chalk.cyan(' "analyze src/app.ts"') + ' - Show gradient analysis');
92
+ console.log('');
93
+ console.log(chalk.dim(' Type "exit" to quit'));
94
+ console.log('');
95
+ }
96
+ /**
97
+ * Start interactive grow session
98
+ */
99
+ export async function startGrowSession() {
100
+ console.clear();
101
+ console.log(chalk.bold.green('🍄 Mycelium Network Active'));
102
+ console.log(chalk.dim('Growing intelligence through autonomous agents'));
103
+ console.log('');
104
+ showHelp();
105
+ let running = true;
106
+ while (running) {
107
+ try {
108
+ const response = await prompts({
109
+ type: 'text',
110
+ name: 'task',
111
+ message: chalk.green('🌱 What would you like to grow?'),
112
+ validate: (value) => value.length > 0 || 'Please enter a task',
113
+ });
114
+ if (!response.task) {
115
+ // User cancelled with Ctrl+C
116
+ running = false;
117
+ break;
118
+ }
119
+ const task = parseTask(response.task);
120
+ if (task.type === 'help') {
121
+ showHelp();
122
+ continue;
123
+ }
124
+ if (task.type === 'exit') {
125
+ running = false;
126
+ break;
127
+ }
128
+ if (task.type === 'analyze') {
129
+ if (!task.file) {
130
+ console.log(chalk.yellow('⚠️ Please specify a file to analyze'));
131
+ continue;
132
+ }
133
+ const spinner = ora(`Analyzing ${task.file}...`).start();
134
+ try {
135
+ const gradient = await calculateGradient(task.file);
136
+ spinner.succeed(chalk.green(`Analysis complete for ${task.file}`));
137
+ console.log('');
138
+ console.log(chalk.bold('📊 Gradient Analysis:'));
139
+ console.log(chalk.dim('─'.repeat(50)));
140
+ console.log(`${chalk.bold('Overall Score:')} ${gradient.score.toFixed(3)}`);
141
+ console.log(`${chalk.bold('Dominant Signal:')} ${gradient.dominantSignal.name}`);
142
+ console.log('');
143
+ console.log(chalk.dim('Signal Breakdown:'));
144
+ console.log(` Complexity: ${gradient.signals.complexity.toFixed(3)}`);
145
+ console.log(` Churn: ${gradient.signals.churn.toFixed(3)}`);
146
+ console.log(` Debt: ${gradient.signals.debt.toFixed(3)}`);
147
+ console.log(` Error Rate: ${gradient.signals.error_rate.toFixed(3)}`);
148
+ console.log(` Centrality: ${gradient.signals.centrality.toFixed(3)}`);
149
+ console.log('');
150
+ }
151
+ catch (error) {
152
+ spinner.fail(chalk.red('Analysis failed'));
153
+ console.error(chalk.red(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
154
+ }
155
+ continue;
156
+ }
157
+ if (task.type === 'task') {
158
+ if (!task.description) {
159
+ console.log(chalk.yellow('⚠️ Could not determine task description'));
160
+ continue;
161
+ }
162
+ const spinner = ora('Planning task...').start();
163
+ try {
164
+ // Create task object
165
+ const newTask = {
166
+ id: randomUUID(),
167
+ description: task.description,
168
+ status: 'planning',
169
+ created_at: new Date().toISOString(),
170
+ acceptance_criteria: [],
171
+ steps_completed: 0,
172
+ steps_total: 0,
173
+ files_created: [],
174
+ files_modified: [],
175
+ traces: [],
176
+ };
177
+ spinner.text = 'Generating task plan...';
178
+ const plan = await planTask(newTask);
179
+ newTask.plan = plan;
180
+ newTask.steps_total = plan.steps.length;
181
+ newTask.status = 'in_progress';
182
+ await storeTask(newTask);
183
+ spinner.succeed(chalk.green('Task plan generated'));
184
+ console.log('');
185
+ console.log(chalk.bold('📋 Task Plan:'));
186
+ console.log(chalk.dim('─'.repeat(50)));
187
+ console.log(`${chalk.bold('Summary:')} ${plan.summary}`);
188
+ console.log(`${chalk.bold('Steps:')} ${plan.steps.length}`);
189
+ console.log(`${chalk.bold('Complexity:')} ${plan.estimated_complexity}`);
190
+ if (plan.risks.length > 0) {
191
+ console.log(`${chalk.bold('Risks:')}`);
192
+ plan.risks.forEach(risk => console.log(chalk.yellow(` ⚠️ ${risk}`)));
193
+ }
194
+ console.log('');
195
+ // Show steps
196
+ console.log(chalk.bold('Steps:'));
197
+ plan.steps.forEach(step => {
198
+ console.log(` ${step.order}. ${step.description}`);
199
+ console.log(` ${chalk.dim(`File: ${step.target_file}, Mode: ${step.mode}`)}`);
200
+ });
201
+ console.log('');
202
+ const executeSpinner = ora('Executing task...').start();
203
+ const executedTask = await executeTask(newTask);
204
+ if (executedTask.status === 'completed') {
205
+ executeSpinner.succeed(chalk.green('Task completed successfully'));
206
+ console.log('');
207
+ console.log(chalk.bold('✅ Results:'));
208
+ console.log(chalk.dim('─'.repeat(50)));
209
+ console.log(`${chalk.bold('Task ID:')} ${executedTask.id}`);
210
+ console.log(`${chalk.bold('Steps:')} ${executedTask.steps_completed}/${executedTask.steps_total}`);
211
+ console.log(`${chalk.bold('Files Created:')} ${executedTask.files_created.length}`);
212
+ console.log(`${chalk.bold('Files Modified:')} ${executedTask.files_modified.length}`);
213
+ console.log('');
214
+ if (executedTask.files_created.length > 0) {
215
+ console.log(chalk.bold('Created:'));
216
+ executedTask.files_created.forEach(f => console.log(` ${chalk.green('+')} ${f}`));
217
+ }
218
+ if (executedTask.files_modified.length > 0) {
219
+ console.log(chalk.bold('Modified:'));
220
+ executedTask.files_modified.forEach(f => console.log(` ${chalk.yellow('~')} ${f}`));
221
+ }
222
+ console.log('');
223
+ console.log(chalk.green('💡 Task completed. Run tests to verify.'));
224
+ }
225
+ else {
226
+ executeSpinner.fail(chalk.red('Task execution failed'));
227
+ console.error(chalk.red(`Error: ${executedTask.error || 'Unknown error'}`));
228
+ }
229
+ await storeTask(executedTask);
230
+ console.log('');
231
+ }
232
+ catch (error) {
233
+ spinner.fail(chalk.red('Task execution failed'));
234
+ console.error(chalk.red(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
235
+ console.log('');
236
+ }
237
+ continue;
238
+ }
239
+ if (task.type === 'spawn') {
240
+ if (!task.file || !task.mode) {
241
+ console.log(chalk.yellow('⚠️ Could not determine file and mode from task'));
242
+ continue;
243
+ }
244
+ const spinner = ora(`Spawning ${task.mode} agent for ${task.file}...`).start();
245
+ try {
246
+ const result = await executeAgent(task.file, task.mode, { dryRun: false });
247
+ spinner.succeed(chalk.green(`Agent completed successfully`));
248
+ console.log('');
249
+ console.log(chalk.bold('✅ Results:'));
250
+ console.log(chalk.dim('─'.repeat(50)));
251
+ console.log(`${chalk.bold('File:')} ${task.file}`);
252
+ console.log(`${chalk.bold('Mode:')} ${task.mode}`);
253
+ console.log(`${chalk.bold('Changes:')} ${result.changes} modifications`);
254
+ console.log(`${chalk.bold('Cost:')} $${result.cost.toFixed(4)}`);
255
+ console.log(`${chalk.bold('Efficiency:')} ${result.trace.efficiency.toFixed(3)}`);
256
+ console.log('');
257
+ if (result.changes && result.changes.length > 0) {
258
+ console.log(chalk.green('💡 Changes have been applied. Run tests to verify.'));
259
+ }
260
+ else {
261
+ console.log(chalk.yellow('ℹ️ No changes were needed.'));
262
+ }
263
+ console.log('');
264
+ }
265
+ catch (error) {
266
+ spinner.fail(chalk.red('Agent execution failed'));
267
+ console.error(chalk.red(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
268
+ console.log('');
269
+ }
270
+ continue;
271
+ }
272
+ }
273
+ catch (error) {
274
+ if (error instanceof Error && error.message.includes('User force closed')) {
275
+ running = false;
276
+ break;
277
+ }
278
+ console.error(chalk.red(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
279
+ }
280
+ }
281
+ console.log('');
282
+ console.log(chalk.green('🍄 Mycelium network dormant. Growth complete.'));
283
+ console.log('');
284
+ }
285
+ /**
286
+ * Commander.js command definition
287
+ */
288
+ const command = new Command()
289
+ .name('grow')
290
+ .description('Start interactive mycelium growth interface')
291
+ .option('--task <description>', 'Run a single task and exit')
292
+ .action(async (options) => {
293
+ if (options.task) {
294
+ // Non-interactive mode - single task
295
+ const task = parseTask(options.task);
296
+ if (task.type === 'task' && task.description) {
297
+ const spinner = ora('Planning task...').start();
298
+ try {
299
+ // Create and execute task
300
+ const newTask = {
301
+ id: randomUUID(),
302
+ description: task.description,
303
+ status: 'planning',
304
+ created_at: new Date().toISOString(),
305
+ acceptance_criteria: [],
306
+ steps_completed: 0,
307
+ steps_total: 0,
308
+ files_created: [],
309
+ files_modified: [],
310
+ traces: [],
311
+ };
312
+ const plan = await planTask(newTask);
313
+ newTask.plan = plan;
314
+ newTask.steps_total = plan.steps.length;
315
+ newTask.status = 'in_progress';
316
+ await storeTask(newTask);
317
+ spinner.text = 'Executing task...';
318
+ const executedTask = await executeTask(newTask);
319
+ await storeTask(executedTask);
320
+ if (executedTask.status === 'completed') {
321
+ spinner.succeed(chalk.green('Task completed'));
322
+ console.log(`Steps: ${executedTask.steps_completed}/${executedTask.steps_total}, Created: ${executedTask.files_created.length}, Modified: ${executedTask.files_modified.length}`);
323
+ }
324
+ else {
325
+ spinner.fail(chalk.red('Task failed'));
326
+ console.error(chalk.red(`Error: ${executedTask.error || 'Unknown error'}`));
327
+ process.exit(1);
328
+ }
329
+ }
330
+ catch (error) {
331
+ spinner.fail(chalk.red('Task failed'));
332
+ console.error(chalk.red(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
333
+ process.exit(1);
334
+ }
335
+ }
336
+ else if (task.type === 'spawn' && task.file && task.mode) {
337
+ const spinner = ora(`Spawning ${task.mode} agent...`).start();
338
+ try {
339
+ const result = await executeAgent(task.file, task.mode, { dryRun: false });
340
+ spinner.succeed(chalk.green('Agent completed'));
341
+ console.log(`Changes: ${result.changes}, Cost: $${result.cost.toFixed(4)}, Efficiency: ${result.trace.efficiency.toFixed(3)}`);
342
+ }
343
+ catch (error) {
344
+ spinner.fail(chalk.red('Agent failed'));
345
+ console.error(chalk.red(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
346
+ process.exit(1);
347
+ }
348
+ }
349
+ else if (task.type === 'analyze' && task.file) {
350
+ const spinner = ora(`Analyzing ${task.file}...`).start();
351
+ try {
352
+ const gradient = await calculateGradient(task.file);
353
+ spinner.succeed(chalk.green('Analysis complete'));
354
+ console.log(`Score: ${gradient.score.toFixed(3)}, Dominant: ${gradient.dominantSignal.name}`);
355
+ }
356
+ catch (error) {
357
+ spinner.fail(chalk.red('Analysis failed'));
358
+ console.error(chalk.red(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
359
+ process.exit(1);
360
+ }
361
+ }
362
+ else {
363
+ console.log(chalk.yellow('Could not parse task. Use interactive mode for help.'));
364
+ process.exit(1);
365
+ }
366
+ }
367
+ else {
368
+ // Interactive TUI mode
369
+ await startGrowSession();
370
+ }
371
+ });
372
+ export default command;
373
+ //# sourceMappingURL=grow.js.map