claude-flow 2.5.0-alpha.139 → 2.7.0-alpha

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 (171) hide show
  1. package/.claude/agents/reasoning/README.md +171 -0
  2. package/.claude/agents/reasoning/agent.md +816 -0
  3. package/.claude/agents/reasoning/example-reasoning-agent-template.md +362 -0
  4. package/.claude/agents/reasoning/goal-planner.md +73 -0
  5. package/.claude/settings.json +2 -1
  6. package/.claude/sparc-modes.json +108 -0
  7. package/README.md +45 -55
  8. package/bin/claude-flow +1 -1
  9. package/dist/src/cli/command-registry.js +70 -6
  10. package/dist/src/cli/command-registry.js.map +1 -1
  11. package/dist/src/cli/commands/hive-mind/pause.js +2 -9
  12. package/dist/src/cli/commands/hive-mind/pause.js.map +1 -1
  13. package/dist/src/cli/commands/index.js +1 -114
  14. package/dist/src/cli/commands/index.js.map +1 -1
  15. package/dist/src/cli/commands/swarm-spawn.js +5 -33
  16. package/dist/src/cli/commands/swarm-spawn.js.map +1 -1
  17. package/dist/src/cli/help-formatter.js +0 -3
  18. package/dist/src/cli/help-formatter.js.map +1 -1
  19. package/dist/src/cli/help-text.js +69 -7
  20. package/dist/src/cli/help-text.js.map +1 -1
  21. package/dist/src/cli/simple-cli.js +182 -172
  22. package/dist/src/cli/simple-cli.js.map +1 -1
  23. package/dist/src/cli/simple-commands/agent-booster.js +415 -0
  24. package/dist/src/cli/simple-commands/agent-booster.js.map +1 -0
  25. package/dist/src/cli/simple-commands/agent.js +856 -13
  26. package/dist/src/cli/simple-commands/agent.js.map +1 -1
  27. package/dist/src/cli/simple-commands/env-template.js +180 -0
  28. package/dist/src/cli/simple-commands/env-template.js.map +1 -0
  29. package/dist/src/cli/simple-commands/hooks.js +233 -0
  30. package/dist/src/cli/simple-commands/hooks.js.map +1 -1
  31. package/dist/src/cli/simple-commands/init/help.js +23 -0
  32. package/dist/src/cli/simple-commands/init/help.js.map +1 -1
  33. package/dist/src/cli/simple-commands/init/index.js +63 -0
  34. package/dist/src/cli/simple-commands/init/index.js.map +1 -1
  35. package/dist/src/cli/simple-commands/memory.js +307 -16
  36. package/dist/src/cli/simple-commands/memory.js.map +1 -1
  37. package/dist/src/cli/simple-commands/proxy.js +304 -0
  38. package/dist/src/cli/simple-commands/proxy.js.map +1 -0
  39. package/dist/src/cli/simple-commands/sparc.js +16 -19
  40. package/dist/src/cli/simple-commands/sparc.js.map +1 -1
  41. package/dist/src/cli/validation-helper.js.map +1 -1
  42. package/dist/src/execution/agent-executor.js +181 -0
  43. package/dist/src/execution/agent-executor.js.map +1 -0
  44. package/dist/src/execution/index.js +12 -0
  45. package/dist/src/execution/index.js.map +1 -0
  46. package/dist/src/execution/provider-manager.js +110 -0
  47. package/dist/src/execution/provider-manager.js.map +1 -0
  48. package/dist/src/hooks/index.js +0 -3
  49. package/dist/src/hooks/index.js.map +1 -1
  50. package/dist/src/hooks/redaction-hook.js +89 -0
  51. package/dist/src/hooks/redaction-hook.js.map +1 -0
  52. package/dist/src/mcp/claude-flow-tools.js +205 -150
  53. package/dist/src/mcp/claude-flow-tools.js.map +1 -1
  54. package/dist/src/mcp/mcp-server.js +125 -0
  55. package/dist/src/mcp/mcp-server.js.map +1 -1
  56. package/dist/src/sdk/query-control.js +293 -139
  57. package/dist/src/sdk/query-control.js.map +1 -1
  58. package/dist/src/sdk/session-forking.js +206 -129
  59. package/dist/src/sdk/session-forking.js.map +1 -1
  60. package/dist/src/utils/key-redactor.js +108 -0
  61. package/dist/src/utils/key-redactor.js.map +1 -0
  62. package/dist/src/utils/metrics-reader.js +37 -39
  63. package/dist/src/utils/metrics-reader.js.map +1 -1
  64. package/docs/AGENT-BOOSTER-INTEGRATION.md +407 -0
  65. package/docs/AGENTIC-FLOW-INTEGRATION-GUIDE.md +753 -0
  66. package/docs/AGENTIC_FLOW_EXECUTION_FIX_REPORT.md +474 -0
  67. package/docs/AGENTIC_FLOW_INTEGRATION_STATUS.md +143 -0
  68. package/docs/AGENTIC_FLOW_MVP_COMPLETE.md +367 -0
  69. package/docs/AGENTIC_FLOW_SECURITY_TEST_REPORT.md +369 -0
  70. package/docs/COMMAND-VERIFICATION-REPORT.md +441 -0
  71. package/docs/COMMIT_SUMMARY.md +247 -0
  72. package/docs/DEEP_REVIEW_COMPREHENSIVE_REPORT.md +922 -0
  73. package/docs/DOCKER-VALIDATION-REPORT.md +281 -0
  74. package/docs/ENV-SETUP-GUIDE.md +270 -0
  75. package/docs/FINAL_PRE_PUBLISH_VALIDATION.md +823 -0
  76. package/docs/FINAL_VALIDATION_REPORT.md +165 -0
  77. package/docs/HOOKS-V2-MODIFICATION.md +146 -0
  78. package/docs/INDEX.md +568 -0
  79. package/docs/INTEGRATION_COMPLETE.md +414 -0
  80. package/docs/MEMORY_REDACTION_TEST_REPORT.md +300 -0
  81. package/docs/PERFORMANCE-SYSTEMS-STATUS.md +340 -0
  82. package/docs/PRE_RELEASE_FIXES_REPORT.md +435 -0
  83. package/docs/README.md +35 -0
  84. package/docs/REASONING-AGENTS.md +482 -0
  85. package/docs/REASONINGBANK-AGENT-CREATION-GUIDE.md +813 -0
  86. package/docs/REASONINGBANK-ANALYSIS-COMPLETE.md +479 -0
  87. package/docs/REASONINGBANK-BENCHMARK-RESULTS.md +166 -0
  88. package/docs/REASONINGBANK-BENCHMARK.md +396 -0
  89. package/docs/REASONINGBANK-CLI-INTEGRATION.md +455 -0
  90. package/docs/REASONINGBANK-CORE-INTEGRATION.md +658 -0
  91. package/docs/REASONINGBANK-COST-OPTIMIZATION.md +329 -0
  92. package/docs/REASONINGBANK-DEMO.md +419 -0
  93. package/docs/REASONINGBANK-INTEGRATION-COMPLETE.md +249 -0
  94. package/docs/REASONINGBANK-VALIDATION.md +532 -0
  95. package/docs/REASONINGBANK_ARCHITECTURE.md +475 -0
  96. package/docs/REASONINGBANK_INTEGRATION_COMPLETE.md +558 -0
  97. package/docs/REASONINGBANK_INTEGRATION_PLAN.md +1188 -0
  98. package/docs/REGRESSION-ANALYSIS-REPORT.md +500 -0
  99. package/docs/RELEASE_v2.6.0-alpha.2.md +658 -0
  100. package/docs/api/API_DOCUMENTATION.md +721 -0
  101. package/docs/architecture/ARCHITECTURE.md +1690 -0
  102. package/docs/ci-cd/README.md +368 -0
  103. package/docs/development/DEPLOYMENT.md +2348 -0
  104. package/docs/development/DEVELOPMENT_WORKFLOW.md +1333 -0
  105. package/docs/development/build-analysis-report.md +252 -0
  106. package/docs/development/pair-optimization.md +156 -0
  107. package/docs/development/token-tracking-status.md +103 -0
  108. package/docs/development/training-pipeline-demo.md +163 -0
  109. package/docs/development/training-pipeline-real-only.md +196 -0
  110. package/docs/epic-sdk-integration.md +1269 -0
  111. package/docs/experimental/RIEMANN_HYPOTHESIS_PROOF.md +124 -0
  112. package/docs/experimental/computational_verification.py +436 -0
  113. package/docs/experimental/novel_approaches.md +560 -0
  114. package/docs/experimental/riemann_hypothesis_analysis.md +263 -0
  115. package/docs/experimental/riemann_proof_attempt.md +124 -0
  116. package/docs/experimental/riemann_synthesis.md +277 -0
  117. package/docs/experimental/verification_results.json +12 -0
  118. package/docs/experimental/visualization_insights.md +720 -0
  119. package/docs/guides/USER_GUIDE.md +1138 -0
  120. package/docs/guides/token-tracking-guide.md +291 -0
  121. package/docs/reference/AGENTS.md +1011 -0
  122. package/docs/reference/MCP_TOOLS.md +2188 -0
  123. package/docs/reference/SPARC.md +717 -0
  124. package/docs/reference/SWARM.md +2000 -0
  125. package/docs/sdk/CLAUDE-CODE-SDK-DEEP-ANALYSIS.md +649 -0
  126. package/docs/sdk/CLAUDE-FLOW-SDK-INTEGRATION-ANALYSIS.md +242 -0
  127. package/docs/sdk/INTEGRATION-ROADMAP.md +420 -0
  128. package/docs/sdk/MCP-TOOLS-UPDATE.md +270 -0
  129. package/docs/sdk/SDK-ADVANCED-FEATURES-INTEGRATION.md +723 -0
  130. package/docs/sdk/SDK-ALL-FEATURES-INTEGRATION-MATRIX.md +612 -0
  131. package/docs/sdk/SDK-INTEGRATION-COMPLETE.md +358 -0
  132. package/docs/sdk/SDK-INTEGRATION-PHASES-V2.5.md +750 -0
  133. package/docs/sdk/SDK-LEVERAGE-REAL-FEATURES.md +676 -0
  134. package/docs/sdk/SDK-VALIDATION-RESULTS.md +400 -0
  135. package/docs/sdk/epic-sdk-integration.md +1269 -0
  136. package/docs/setup/remote-setup.md +93 -0
  137. package/docs/validation/final-validation-summary.md +220 -0
  138. package/docs/validation/verification-integration.md +190 -0
  139. package/docs/validation/verification-validation.md +349 -0
  140. package/docs/wiki/background-commands.md +1213 -0
  141. package/docs/wiki/session-persistence.md +342 -0
  142. package/docs/wiki/stream-chain-command.md +537 -0
  143. package/package.json +4 -2
  144. package/src/cli/command-registry.js +70 -5
  145. package/src/cli/commands/hive-mind/pause.ts +2 -15
  146. package/src/cli/commands/index.ts +1 -84
  147. package/src/cli/commands/swarm-spawn.ts +3 -47
  148. package/src/cli/help-text.js +42 -7
  149. package/src/cli/simple-cli.ts +18 -8
  150. package/src/cli/simple-commands/agent-booster.js +515 -0
  151. package/src/cli/simple-commands/agent.js +1001 -12
  152. package/src/cli/simple-commands/agent.ts +137 -0
  153. package/src/cli/simple-commands/config.ts +127 -0
  154. package/src/cli/simple-commands/env-template.js +190 -0
  155. package/src/cli/simple-commands/hooks.js +310 -0
  156. package/src/cli/simple-commands/init/help.js +23 -0
  157. package/src/cli/simple-commands/init/index.js +84 -6
  158. package/src/cli/simple-commands/memory.js +363 -16
  159. package/src/cli/simple-commands/proxy.js +384 -0
  160. package/src/cli/simple-commands/sparc.js +16 -19
  161. package/src/execution/agent-executor.ts +306 -0
  162. package/src/execution/index.ts +19 -0
  163. package/src/execution/provider-manager.ts +187 -0
  164. package/src/hooks/index.ts +0 -5
  165. package/src/hooks/redaction-hook.ts +115 -0
  166. package/src/mcp/claude-flow-tools.ts +203 -120
  167. package/src/mcp/mcp-server.js +86 -0
  168. package/src/sdk/query-control.ts +377 -223
  169. package/src/sdk/session-forking.ts +312 -207
  170. package/src/utils/key-redactor.js +178 -0
  171. package/src/utils/key-redactor.ts +184 -0
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Agent CLI Commands - Execute agents with agentic-flow
3
+ */
4
+
5
+ import { Command } from 'commander';
6
+ import chalk from 'chalk';
7
+ import ora from 'ora';
8
+ import { AgentExecutor } from '../../execution/agent-executor.js';
9
+ import { ProviderManager } from '../../execution/provider-manager.js';
10
+
11
+ export function createAgentCommand(): Command {
12
+ const agent = new Command('agent')
13
+ .description('Execute and manage AI agents with multi-provider support');
14
+
15
+ // agent run command
16
+ agent
17
+ .command('run')
18
+ .description('Execute an agent with a specific task')
19
+ .argument('<agent-name>', 'Agent to execute (e.g., coder, researcher)')
20
+ .argument('<task>', 'Task description for the agent')
21
+ .option('-p, --provider <provider>', 'Provider to use (anthropic, openrouter, onnx, gemini)')
22
+ .option('-m, --model <model>', 'Model to use')
23
+ .option('-t, --temperature <temp>', 'Temperature (0.0-1.0)', parseFloat)
24
+ .option('--max-tokens <tokens>', 'Maximum tokens', parseInt)
25
+ .option('-f, --format <format>', 'Output format (text, json, markdown)', 'text')
26
+ .option('--stream', 'Enable streaming output')
27
+ .option('-v, --verbose', 'Verbose output')
28
+ .action(async (agentName, task, options) => {
29
+ const spinner = ora('Executing agent...').start();
30
+
31
+ try {
32
+ const executor = new AgentExecutor();
33
+ const providerManager = new ProviderManager();
34
+
35
+ // Use specified provider or default
36
+ const provider = options.provider || providerManager.getDefaultProvider();
37
+
38
+ const result = await executor.execute({
39
+ agent: agentName,
40
+ task: task,
41
+ provider: provider as any,
42
+ model: options.model,
43
+ temperature: options.temperature,
44
+ maxTokens: options.maxTokens,
45
+ outputFormat: options.format,
46
+ stream: options.stream,
47
+ verbose: options.verbose,
48
+ });
49
+
50
+ spinner.stop();
51
+
52
+ if (result.success) {
53
+ console.log(chalk.green('✓ Agent execution completed\n'));
54
+ console.log(result.output);
55
+
56
+ if (options.verbose) {
57
+ console.log(chalk.gray(`\nProvider: ${result.provider}`));
58
+ console.log(chalk.gray(`Duration: ${result.duration}ms`));
59
+ if (result.tokens) console.log(chalk.gray(`Tokens: ${result.tokens}`));
60
+ if (result.cost) console.log(chalk.gray(`Cost: $${result.cost.toFixed(4)}`));
61
+ }
62
+ } else {
63
+ console.error(chalk.red('✗ Agent execution failed'));
64
+ console.error(result.error);
65
+ process.exit(1);
66
+ }
67
+ } catch (error: any) {
68
+ spinner.stop();
69
+ console.error(chalk.red('✗ Error:'), error.message);
70
+ process.exit(1);
71
+ }
72
+ });
73
+
74
+ // agent list command
75
+ agent
76
+ .command('list')
77
+ .description('List available agents')
78
+ .option('-s, --source <source>', 'Filter by source (all, package, local)', 'all')
79
+ .option('-f, --format <format>', 'Output format (text, json)', 'text')
80
+ .action(async (options) => {
81
+ const spinner = ora('Loading agents...').start();
82
+
83
+ try {
84
+ const executor = new AgentExecutor();
85
+ const agents = await executor.listAgents(options.source as any);
86
+
87
+ spinner.stop();
88
+
89
+ if (options.format === 'json') {
90
+ console.log(JSON.stringify(agents, null, 2));
91
+ } else {
92
+ console.log(chalk.cyan(`\n📋 Available Agents (${agents.length}):\n`));
93
+ agents.forEach(agent => {
94
+ console.log(chalk.white(` • ${agent}`));
95
+ });
96
+ console.log('');
97
+ }
98
+ } catch (error: any) {
99
+ spinner.stop();
100
+ console.error(chalk.red('✗ Error:'), error.message);
101
+ process.exit(1);
102
+ }
103
+ });
104
+
105
+ // agent info command
106
+ agent
107
+ .command('info')
108
+ .description('Get information about a specific agent')
109
+ .argument('<agent-name>', 'Agent name')
110
+ .action(async (agentName) => {
111
+ const spinner = ora('Loading agent info...').start();
112
+
113
+ try {
114
+ const executor = new AgentExecutor();
115
+ const info = await executor.getAgentInfo(agentName);
116
+
117
+ spinner.stop();
118
+
119
+ if (info) {
120
+ console.log(chalk.cyan(`\n📝 Agent: ${agentName}\n`));
121
+ console.log(chalk.white(`Description: ${info.description || 'N/A'}`));
122
+ console.log(chalk.white(`Category: ${info.category || 'N/A'}`));
123
+ console.log(chalk.white(`Source: ${info.source || 'N/A'}`));
124
+ console.log('');
125
+ } else {
126
+ console.error(chalk.red('✗ Agent not found'));
127
+ process.exit(1);
128
+ }
129
+ } catch (error: any) {
130
+ spinner.stop();
131
+ console.error(chalk.red('✗ Error:'), error.message);
132
+ process.exit(1);
133
+ }
134
+ });
135
+
136
+ return agent;
137
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Config CLI Commands - Manage provider configuration
3
+ */
4
+
5
+ import { Command } from 'commander';
6
+ import chalk from 'chalk';
7
+ import inquirer from 'inquirer';
8
+ import { ProviderManager } from '../../execution/provider-manager.js';
9
+
10
+ export function createConfigCommand(): Command {
11
+ const config = new Command('config')
12
+ .description('Manage provider configuration');
13
+
14
+ // config set-provider command
15
+ config
16
+ .command('set-provider')
17
+ .description('Set default provider')
18
+ .argument('<provider>', 'Provider name (anthropic, openrouter, onnx, gemini)')
19
+ .option('-m, --model <model>', 'Default model for provider')
20
+ .action(async (provider, options) => {
21
+ try {
22
+ const manager = new ProviderManager();
23
+
24
+ await manager.setDefaultProvider(provider);
25
+
26
+ if (options.model) {
27
+ await manager.configureProvider(provider, {
28
+ model: options.model,
29
+ enabled: true,
30
+ } as any);
31
+ }
32
+
33
+ console.log(chalk.green(`✓ Default provider set to: ${provider}`));
34
+ if (options.model) {
35
+ console.log(chalk.green(`✓ Default model set to: ${options.model}`));
36
+ }
37
+ } catch (error: any) {
38
+ console.error(chalk.red('✗ Error:'), error.message);
39
+ process.exit(1);
40
+ }
41
+ });
42
+
43
+ // config list-providers command
44
+ config
45
+ .command('list-providers')
46
+ .alias('list')
47
+ .description('List configured providers')
48
+ .option('-f, --format <format>', 'Output format (text, json)', 'text')
49
+ .action(async (options) => {
50
+ try {
51
+ const manager = new ProviderManager();
52
+ const providers = manager.listProviders();
53
+ const defaultProvider = manager.getDefaultProvider();
54
+
55
+ if (options.format === 'json') {
56
+ console.log(JSON.stringify({ defaultProvider, providers }, null, 2));
57
+ } else {
58
+ console.log(chalk.cyan('\n📋 Configured Providers:\n'));
59
+ console.log(chalk.white(`Default: ${chalk.bold(defaultProvider)}\n`));
60
+
61
+ providers.forEach(provider => {
62
+ const isDefault = provider.name === defaultProvider;
63
+ const prefix = isDefault ? chalk.green('●') : chalk.gray('○');
64
+ const status = provider.enabled ? chalk.green('enabled') : chalk.gray('disabled');
65
+
66
+ console.log(`${prefix} ${chalk.bold(provider.name)}`);
67
+ console.log(` Model: ${provider.model || 'default'}`);
68
+ console.log(` Priority: ${provider.priority || 'balanced'}`);
69
+ console.log(` Status: ${status}`);
70
+ console.log('');
71
+ });
72
+ }
73
+ } catch (error: any) {
74
+ console.error(chalk.red('✗ Error:'), error.message);
75
+ process.exit(1);
76
+ }
77
+ });
78
+
79
+ // config wizard command
80
+ config
81
+ .command('wizard')
82
+ .description('Interactive provider configuration wizard')
83
+ .action(async () => {
84
+ try {
85
+ const manager = new ProviderManager();
86
+
87
+ console.log(chalk.cyan('\n🧙 Provider Configuration Wizard\n'));
88
+
89
+ const answers = await inquirer.prompt([
90
+ {
91
+ type: 'list',
92
+ name: 'defaultProvider',
93
+ message: 'Select default provider:',
94
+ choices: [
95
+ { name: 'Anthropic (Highest quality)', value: 'anthropic' },
96
+ { name: 'OpenRouter (99% cost savings)', value: 'openrouter' },
97
+ { name: 'ONNX (Free local inference)', value: 'onnx' },
98
+ { name: 'Gemini (Free tier)', value: 'gemini' },
99
+ ],
100
+ },
101
+ {
102
+ type: 'list',
103
+ name: 'optimization',
104
+ message: 'Optimization priority:',
105
+ choices: [
106
+ { name: 'Balanced (recommended)', value: 'balanced' },
107
+ { name: 'Cost (cheapest)', value: 'cost' },
108
+ { name: 'Quality (best results)', value: 'quality' },
109
+ { name: 'Speed (fastest)', value: 'speed' },
110
+ { name: 'Privacy (local only)', value: 'privacy' },
111
+ ],
112
+ },
113
+ ]);
114
+
115
+ await manager.setDefaultProvider(answers.defaultProvider);
116
+
117
+ console.log(chalk.green('\n✓ Configuration saved successfully!'));
118
+ console.log(chalk.gray(`\nDefault provider: ${answers.defaultProvider}`));
119
+ console.log(chalk.gray(`Optimization: ${answers.optimization}`));
120
+ } catch (error: any) {
121
+ console.error(chalk.red('\n✗ Error:'), error.message);
122
+ process.exit(1);
123
+ }
124
+ });
125
+
126
+ return config;
127
+ }
@@ -0,0 +1,190 @@
1
+ // env-template.js - Environment template generator
2
+ import { printSuccess, printError, printWarning } from '../utils.js';
3
+ import { existsSync } from 'fs';
4
+ import { promises as fs } from 'fs';
5
+ import path from 'path';
6
+
7
+ /**
8
+ * Generate .env template with configuration instructions
9
+ */
10
+ export async function generateEnvTemplate(workingDir = process.cwd(), force = false) {
11
+ const envPath = path.join(workingDir, '.env');
12
+
13
+ // Check if .env already exists
14
+ if (existsSync(envPath) && !force) {
15
+ printWarning('⚠️ .env file already exists');
16
+ console.log('Use --force to overwrite existing .env file');
17
+ return { exists: true, created: false };
18
+ }
19
+
20
+ const template = `# Agentic Flow Configuration
21
+ # Generated by claude-flow init --env
22
+ # Created: ${new Date().toISOString()}
23
+
24
+ # ============================================
25
+ # REQUIRED FOR REASONINGBANK MEMORY
26
+ # ============================================
27
+ # Without these, ReasoningBank will fall back to heuristic mode (regex matching)
28
+ # For actual learning and memory consolidation, you MUST provide API keys
29
+
30
+ # Anthropic API key for Claude models (sk-ant-...)
31
+ # Get your key: https://console.anthropic.com/settings/keys
32
+ ANTHROPIC_API_KEY=
33
+
34
+ # OpenRouter API key for alternative models (sk-or-v1-...)
35
+ # Get your key: https://openrouter.ai/keys
36
+ # Enables 99% cost savings with DeepSeek R1 for judge/distill
37
+ OPENROUTER_API_KEY=
38
+
39
+ # Google Gemini API key (optional, for free tier)
40
+ # Get your key: https://aistudio.google.com/app/apikey
41
+ GOOGLE_GEMINI_API_KEY=
42
+
43
+ # ============================================
44
+ # MODEL CONFIGURATION
45
+ # ============================================
46
+ # Default model for completions (Claude 3.5 Sonnet v2 - latest)
47
+ COMPLETION_MODEL=claude-3-5-sonnet-20241022
48
+
49
+ # Default provider (anthropic, openrouter, onnx, gemini)
50
+ PROVIDER=anthropic
51
+
52
+ # ============================================
53
+ # ADVANCED: REASONINGBANK COST OPTIMIZATION
54
+ # ============================================
55
+ # To use cheap models for memory operations (46% savings):
56
+ # 1. Set OPENROUTER_API_KEY above
57
+ # 2. Create .swarm/reasoningbank.yaml with:
58
+ #
59
+ # reasoningbank:
60
+ # judge:
61
+ # model: "deepseek/deepseek-r1"
62
+ # max_tokens: 512
63
+ # temperature: 0
64
+ # distill:
65
+ # model: "deepseek/deepseek-r1"
66
+ # max_tokens: 2048
67
+ # temperature: 0.3
68
+ # embeddings:
69
+ # provider: "openrouter"
70
+ # model: "deepseek/deepseek-r1"
71
+ # dimensions: 1024
72
+ #
73
+ # This keeps Claude for main work but uses DeepSeek for memory (99% cheaper)
74
+ # Result: $0.37 → $0.20 per task with memory (46% savings!)
75
+
76
+ # ============================================
77
+ # OPTIONAL API KEYS
78
+ # ============================================
79
+ # Perplexity API key (for GOAP search integration)
80
+ PERPLEXITY_API_KEY=
81
+
82
+ # Hugging Face API key (for ONNX models)
83
+ HUGGINGFACE_API_KEY=
84
+
85
+ # E2B API keys (for Flow Nexus sandbox deployment)
86
+ E2B_API_KEY=
87
+ E2B_ACCESS_TOKEN=
88
+
89
+ # Supabase configuration (for Flow Nexus cloud features)
90
+ SUPABASE_URL=
91
+ SUPABASE_ANON_KEY=
92
+ SUPABASE_ACCESS_TOKEN=
93
+ SUPABASE_PROJECT_ID=
94
+
95
+ # ============================================
96
+ # WHAT HAPPENS WITHOUT .env?
97
+ # ============================================
98
+ # Without this file:
99
+ # 1. No automatic environment variable loading
100
+ # 2. ReasoningBank falls back to heuristic judgment (regex-based)
101
+ # 3. No actual learning or memory consolidation
102
+ # 4. Demo will appear to work but uses pattern matching only
103
+ #
104
+ # You can still work without .env by:
105
+ # - Manually exporting environment variables
106
+ # - Or passing inline with commands
107
+ #
108
+ # But using .env is recommended for convenience and security.
109
+
110
+ # ============================================
111
+ # SECURITY NOTES
112
+ # ============================================
113
+ # 1. NEVER commit this file to git (it's in .gitignore)
114
+ # 2. Use different keys for dev/staging/production
115
+ # 3. Rotate keys regularly
116
+ # 4. Use key-specific permissions when possible
117
+ `;
118
+
119
+ // Write template
120
+ try {
121
+ await fs.writeFile(envPath, template, 'utf8');
122
+ printSuccess('✅ Created .env template file');
123
+ return { exists: false, created: true, path: envPath };
124
+ } catch (error) {
125
+ printError(`❌ Failed to create .env template: ${error.message}`);
126
+ return { exists: false, created: false, error: error.message };
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Check if .env exists and has required keys
132
+ */
133
+ export async function checkEnvConfig(workingDir = process.cwd()) {
134
+ const envPath = path.join(workingDir, '.env');
135
+
136
+ if (!existsSync(envPath)) {
137
+ return {
138
+ exists: false,
139
+ hasApiKeys: false,
140
+ message: '.env file not found'
141
+ };
142
+ }
143
+
144
+ try {
145
+ const envContent = await fs.readFile(envPath, 'utf8');
146
+
147
+ // Check for API keys (not commented out and not empty)
148
+ const hasAnthropicKey = /^ANTHROPIC_API_KEY=[^\s]+$/m.test(envContent);
149
+ const hasOpenRouterKey = /^OPENROUTER_API_KEY=[^\s]+$/m.test(envContent);
150
+ const hasGeminiKey = /^GOOGLE_GEMINI_API_KEY=[^\s]+$/m.test(envContent);
151
+
152
+ return {
153
+ exists: true,
154
+ hasApiKeys: hasAnthropicKey || hasOpenRouterKey || hasGeminiKey,
155
+ keys: {
156
+ anthropic: hasAnthropicKey,
157
+ openrouter: hasOpenRouterKey,
158
+ gemini: hasGeminiKey
159
+ },
160
+ message: 'Configuration found'
161
+ };
162
+ } catch (error) {
163
+ return {
164
+ exists: true,
165
+ hasApiKeys: false,
166
+ message: `Error reading .env: ${error.message}`
167
+ };
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Show .env setup instructions
173
+ */
174
+ export function showEnvSetupInstructions() {
175
+ console.log('\n📋 Setting up .env for ReasoningBank capabilities:\n');
176
+ console.log('1. Create .env file:');
177
+ console.log(' claude-flow init --env\n');
178
+ console.log('2. Add your API keys to .env:');
179
+ console.log(' ANTHROPIC_API_KEY=sk-ant-...');
180
+ console.log(' OPENROUTER_API_KEY=sk-or-v1-... # Optional: 99% cost savings\n');
181
+ console.log('3. Get API keys:');
182
+ console.log(' • Anthropic: https://console.anthropic.com/settings/keys');
183
+ console.log(' • OpenRouter: https://openrouter.ai/keys (for cost optimization)\n');
184
+ console.log('💡 Without API keys:');
185
+ console.log(' • ReasoningBank falls back to regex pattern matching (no learning)');
186
+ console.log(' • Memory operations will appear to work but won\'t actually learn\n');
187
+ console.log('💰 Cost optimization:');
188
+ console.log(' • Use OpenRouter + DeepSeek R1 for judge/distill (99% cheaper)');
189
+ console.log(' • See: docs/REASONINGBANK-COST-OPTIMIZATION.md\n');
190
+ }