claude-flow 3.0.0-alpha.10 → 3.0.0-alpha.11

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 (239) hide show
  1. package/package.json +10 -23
  2. package/README.md +0 -1186
  3. package/bin/cli.js +0 -14
  4. package/dist/src/commands/agent.d.ts +0 -8
  5. package/dist/src/commands/agent.d.ts.map +0 -1
  6. package/dist/src/commands/agent.js +0 -819
  7. package/dist/src/commands/agent.js.map +0 -1
  8. package/dist/src/commands/config.d.ts +0 -8
  9. package/dist/src/commands/config.d.ts.map +0 -1
  10. package/dist/src/commands/config.js +0 -406
  11. package/dist/src/commands/config.js.map +0 -1
  12. package/dist/src/commands/daemon.d.ts +0 -8
  13. package/dist/src/commands/daemon.d.ts.map +0 -1
  14. package/dist/src/commands/daemon.js +0 -545
  15. package/dist/src/commands/daemon.js.map +0 -1
  16. package/dist/src/commands/hive-mind.d.ts +0 -8
  17. package/dist/src/commands/hive-mind.d.ts.map +0 -1
  18. package/dist/src/commands/hive-mind.js +0 -844
  19. package/dist/src/commands/hive-mind.js.map +0 -1
  20. package/dist/src/commands/hooks.d.ts +0 -8
  21. package/dist/src/commands/hooks.d.ts.map +0 -1
  22. package/dist/src/commands/hooks.js +0 -2098
  23. package/dist/src/commands/hooks.js.map +0 -1
  24. package/dist/src/commands/index.d.ts +0 -52
  25. package/dist/src/commands/index.d.ts.map +0 -1
  26. package/dist/src/commands/index.js +0 -108
  27. package/dist/src/commands/index.js.map +0 -1
  28. package/dist/src/commands/init.d.ts +0 -8
  29. package/dist/src/commands/init.d.ts.map +0 -1
  30. package/dist/src/commands/init.js +0 -532
  31. package/dist/src/commands/init.js.map +0 -1
  32. package/dist/src/commands/mcp.d.ts +0 -11
  33. package/dist/src/commands/mcp.d.ts.map +0 -1
  34. package/dist/src/commands/mcp.js +0 -662
  35. package/dist/src/commands/mcp.js.map +0 -1
  36. package/dist/src/commands/memory.d.ts +0 -8
  37. package/dist/src/commands/memory.d.ts.map +0 -1
  38. package/dist/src/commands/memory.js +0 -977
  39. package/dist/src/commands/memory.js.map +0 -1
  40. package/dist/src/commands/migrate.d.ts +0 -8
  41. package/dist/src/commands/migrate.d.ts.map +0 -1
  42. package/dist/src/commands/migrate.js +0 -398
  43. package/dist/src/commands/migrate.js.map +0 -1
  44. package/dist/src/commands/process.d.ts +0 -10
  45. package/dist/src/commands/process.d.ts.map +0 -1
  46. package/dist/src/commands/process.js +0 -641
  47. package/dist/src/commands/process.js.map +0 -1
  48. package/dist/src/commands/session.d.ts +0 -8
  49. package/dist/src/commands/session.d.ts.map +0 -1
  50. package/dist/src/commands/session.js +0 -750
  51. package/dist/src/commands/session.js.map +0 -1
  52. package/dist/src/commands/start.d.ts +0 -8
  53. package/dist/src/commands/start.d.ts.map +0 -1
  54. package/dist/src/commands/start.js +0 -398
  55. package/dist/src/commands/start.js.map +0 -1
  56. package/dist/src/commands/status.d.ts +0 -8
  57. package/dist/src/commands/status.d.ts.map +0 -1
  58. package/dist/src/commands/status.js +0 -584
  59. package/dist/src/commands/status.js.map +0 -1
  60. package/dist/src/commands/swarm.d.ts +0 -8
  61. package/dist/src/commands/swarm.d.ts.map +0 -1
  62. package/dist/src/commands/swarm.js +0 -573
  63. package/dist/src/commands/swarm.js.map +0 -1
  64. package/dist/src/commands/task.d.ts +0 -8
  65. package/dist/src/commands/task.d.ts.map +0 -1
  66. package/dist/src/commands/task.js +0 -671
  67. package/dist/src/commands/task.js.map +0 -1
  68. package/dist/src/commands/workflow.d.ts +0 -8
  69. package/dist/src/commands/workflow.d.ts.map +0 -1
  70. package/dist/src/commands/workflow.js +0 -617
  71. package/dist/src/commands/workflow.js.map +0 -1
  72. package/dist/src/config-adapter.d.ts +0 -15
  73. package/dist/src/config-adapter.d.ts.map +0 -1
  74. package/dist/src/config-adapter.js +0 -185
  75. package/dist/src/config-adapter.js.map +0 -1
  76. package/dist/src/index.d.ts +0 -55
  77. package/dist/src/index.d.ts.map +0 -1
  78. package/dist/src/index.js +0 -353
  79. package/dist/src/index.js.map +0 -1
  80. package/dist/src/infrastructure/in-memory-repositories.d.ts +0 -68
  81. package/dist/src/infrastructure/in-memory-repositories.d.ts.map +0 -1
  82. package/dist/src/infrastructure/in-memory-repositories.js +0 -264
  83. package/dist/src/infrastructure/in-memory-repositories.js.map +0 -1
  84. package/dist/src/init/claudemd-generator.d.ts +0 -15
  85. package/dist/src/init/claudemd-generator.d.ts.map +0 -1
  86. package/dist/src/init/claudemd-generator.js +0 -626
  87. package/dist/src/init/claudemd-generator.js.map +0 -1
  88. package/dist/src/init/executor.d.ts +0 -11
  89. package/dist/src/init/executor.d.ts.map +0 -1
  90. package/dist/src/init/executor.js +0 -652
  91. package/dist/src/init/executor.js.map +0 -1
  92. package/dist/src/init/helpers-generator.d.ts +0 -42
  93. package/dist/src/init/helpers-generator.d.ts.map +0 -1
  94. package/dist/src/init/helpers-generator.js +0 -613
  95. package/dist/src/init/helpers-generator.js.map +0 -1
  96. package/dist/src/init/index.d.ts +0 -12
  97. package/dist/src/init/index.d.ts.map +0 -1
  98. package/dist/src/init/index.js +0 -15
  99. package/dist/src/init/index.js.map +0 -1
  100. package/dist/src/init/mcp-generator.d.ts +0 -18
  101. package/dist/src/init/mcp-generator.d.ts.map +0 -1
  102. package/dist/src/init/mcp-generator.js +0 -71
  103. package/dist/src/init/mcp-generator.js.map +0 -1
  104. package/dist/src/init/settings-generator.d.ts +0 -14
  105. package/dist/src/init/settings-generator.d.ts.map +0 -1
  106. package/dist/src/init/settings-generator.js +0 -267
  107. package/dist/src/init/settings-generator.js.map +0 -1
  108. package/dist/src/init/statusline-generator.d.ts +0 -14
  109. package/dist/src/init/statusline-generator.d.ts.map +0 -1
  110. package/dist/src/init/statusline-generator.js +0 -206
  111. package/dist/src/init/statusline-generator.js.map +0 -1
  112. package/dist/src/init/types.d.ts +0 -240
  113. package/dist/src/init/types.d.ts.map +0 -1
  114. package/dist/src/init/types.js +0 -210
  115. package/dist/src/init/types.js.map +0 -1
  116. package/dist/src/mcp-client.d.ts +0 -92
  117. package/dist/src/mcp-client.d.ts.map +0 -1
  118. package/dist/src/mcp-client.js +0 -203
  119. package/dist/src/mcp-client.js.map +0 -1
  120. package/dist/src/mcp-server.d.ts +0 -153
  121. package/dist/src/mcp-server.d.ts.map +0 -1
  122. package/dist/src/mcp-server.js +0 -453
  123. package/dist/src/mcp-server.js.map +0 -1
  124. package/dist/src/mcp-tools/agent-tools.d.ts +0 -8
  125. package/dist/src/mcp-tools/agent-tools.d.ts.map +0 -1
  126. package/dist/src/mcp-tools/agent-tools.js +0 -426
  127. package/dist/src/mcp-tools/agent-tools.js.map +0 -1
  128. package/dist/src/mcp-tools/config-tools.d.ts +0 -8
  129. package/dist/src/mcp-tools/config-tools.d.ts.map +0 -1
  130. package/dist/src/mcp-tools/config-tools.js +0 -333
  131. package/dist/src/mcp-tools/config-tools.js.map +0 -1
  132. package/dist/src/mcp-tools/hive-mind-tools.d.ts +0 -8
  133. package/dist/src/mcp-tools/hive-mind-tools.d.ts.map +0 -1
  134. package/dist/src/mcp-tools/hive-mind-tools.js +0 -447
  135. package/dist/src/mcp-tools/hive-mind-tools.js.map +0 -1
  136. package/dist/src/mcp-tools/hooks-tools.d.ts +0 -41
  137. package/dist/src/mcp-tools/hooks-tools.d.ts.map +0 -1
  138. package/dist/src/mcp-tools/hooks-tools.js +0 -1711
  139. package/dist/src/mcp-tools/hooks-tools.js.map +0 -1
  140. package/dist/src/mcp-tools/index.d.ts +0 -16
  141. package/dist/src/mcp-tools/index.d.ts.map +0 -1
  142. package/dist/src/mcp-tools/index.js +0 -15
  143. package/dist/src/mcp-tools/index.js.map +0 -1
  144. package/dist/src/mcp-tools/memory-tools.d.ts +0 -8
  145. package/dist/src/mcp-tools/memory-tools.d.ts.map +0 -1
  146. package/dist/src/mcp-tools/memory-tools.js +0 -235
  147. package/dist/src/mcp-tools/memory-tools.js.map +0 -1
  148. package/dist/src/mcp-tools/session-tools.d.ts +0 -8
  149. package/dist/src/mcp-tools/session-tools.d.ts.map +0 -1
  150. package/dist/src/mcp-tools/session-tools.js +0 -315
  151. package/dist/src/mcp-tools/session-tools.js.map +0 -1
  152. package/dist/src/mcp-tools/swarm-tools.d.ts +0 -8
  153. package/dist/src/mcp-tools/swarm-tools.d.ts.map +0 -1
  154. package/dist/src/mcp-tools/swarm-tools.js +0 -102
  155. package/dist/src/mcp-tools/swarm-tools.js.map +0 -1
  156. package/dist/src/mcp-tools/task-tools.d.ts +0 -8
  157. package/dist/src/mcp-tools/task-tools.d.ts.map +0 -1
  158. package/dist/src/mcp-tools/task-tools.js +0 -302
  159. package/dist/src/mcp-tools/task-tools.js.map +0 -1
  160. package/dist/src/mcp-tools/types.d.ts +0 -31
  161. package/dist/src/mcp-tools/types.d.ts.map +0 -1
  162. package/dist/src/mcp-tools/types.js +0 -7
  163. package/dist/src/mcp-tools/types.js.map +0 -1
  164. package/dist/src/mcp-tools/workflow-tools.d.ts +0 -8
  165. package/dist/src/mcp-tools/workflow-tools.d.ts.map +0 -1
  166. package/dist/src/mcp-tools/workflow-tools.js +0 -481
  167. package/dist/src/mcp-tools/workflow-tools.js.map +0 -1
  168. package/dist/src/output.d.ts +0 -133
  169. package/dist/src/output.d.ts.map +0 -1
  170. package/dist/src/output.js +0 -513
  171. package/dist/src/output.js.map +0 -1
  172. package/dist/src/parser.d.ts +0 -41
  173. package/dist/src/parser.d.ts.map +0 -1
  174. package/dist/src/parser.js +0 -353
  175. package/dist/src/parser.js.map +0 -1
  176. package/dist/src/prompt.d.ts +0 -44
  177. package/dist/src/prompt.d.ts.map +0 -1
  178. package/dist/src/prompt.js +0 -501
  179. package/dist/src/prompt.js.map +0 -1
  180. package/dist/src/services/index.d.ts +0 -7
  181. package/dist/src/services/index.d.ts.map +0 -1
  182. package/dist/src/services/index.js +0 -6
  183. package/dist/src/services/index.js.map +0 -1
  184. package/dist/src/services/worker-daemon.d.ts +0 -153
  185. package/dist/src/services/worker-daemon.d.ts.map +0 -1
  186. package/dist/src/services/worker-daemon.js +0 -567
  187. package/dist/src/services/worker-daemon.js.map +0 -1
  188. package/dist/src/types.d.ts +0 -198
  189. package/dist/src/types.d.ts.map +0 -1
  190. package/dist/src/types.js +0 -38
  191. package/dist/src/types.js.map +0 -1
  192. package/dist/tsconfig.tsbuildinfo +0 -1
  193. package/src/commands/agent.ts +0 -955
  194. package/src/commands/config.ts +0 -452
  195. package/src/commands/daemon.ts +0 -621
  196. package/src/commands/hive-mind.ts +0 -928
  197. package/src/commands/hooks.ts +0 -2603
  198. package/src/commands/index.ts +0 -118
  199. package/src/commands/init.ts +0 -597
  200. package/src/commands/mcp.ts +0 -753
  201. package/src/commands/memory.ts +0 -1161
  202. package/src/commands/migrate.ts +0 -447
  203. package/src/commands/process.ts +0 -695
  204. package/src/commands/session.ts +0 -891
  205. package/src/commands/start.ts +0 -457
  206. package/src/commands/status.ts +0 -736
  207. package/src/commands/swarm.ts +0 -648
  208. package/src/commands/task.ts +0 -792
  209. package/src/commands/workflow.ts +0 -742
  210. package/src/config-adapter.ts +0 -210
  211. package/src/index.ts +0 -427
  212. package/src/infrastructure/in-memory-repositories.ts +0 -310
  213. package/src/init/claudemd-generator.ts +0 -631
  214. package/src/init/executor.ts +0 -762
  215. package/src/init/helpers-generator.ts +0 -628
  216. package/src/init/index.ts +0 -60
  217. package/src/init/mcp-generator.ts +0 -83
  218. package/src/init/settings-generator.ts +0 -284
  219. package/src/init/statusline-generator.ts +0 -211
  220. package/src/init/types.ts +0 -447
  221. package/src/mcp-client.ts +0 -241
  222. package/src/mcp-server.ts +0 -577
  223. package/src/mcp-tools/agent-tools.ts +0 -466
  224. package/src/mcp-tools/config-tools.ts +0 -370
  225. package/src/mcp-tools/hive-mind-tools.ts +0 -521
  226. package/src/mcp-tools/hooks-tools.ts +0 -1888
  227. package/src/mcp-tools/index.ts +0 -16
  228. package/src/mcp-tools/memory-tools.ts +0 -270
  229. package/src/mcp-tools/session-tools.ts +0 -359
  230. package/src/mcp-tools/swarm-tools.ts +0 -105
  231. package/src/mcp-tools/task-tools.ts +0 -347
  232. package/src/mcp-tools/types.ts +0 -33
  233. package/src/mcp-tools/workflow-tools.ts +0 -573
  234. package/src/output.ts +0 -639
  235. package/src/parser.ts +0 -417
  236. package/src/prompt.ts +0 -619
  237. package/src/services/index.ts +0 -15
  238. package/src/services/worker-daemon.ts +0 -726
  239. package/src/types.ts +0 -287
@@ -1,762 +0,0 @@
1
- /**
2
- * Init Executor
3
- * Main execution logic for V3 initialization
4
- */
5
-
6
- import * as fs from 'fs';
7
- import * as path from 'path';
8
- import { fileURLToPath } from 'url';
9
- import { dirname } from 'path';
10
-
11
- // ESM-compatible __dirname
12
- const __filename = fileURLToPath(import.meta.url);
13
- const __dirname = dirname(__filename);
14
- import type { InitOptions, InitResult, PlatformInfo } from './types.js';
15
- import { detectPlatform } from './types.js';
16
- import { generateSettingsJson } from './settings-generator.js';
17
- import { generateMCPJson } from './mcp-generator.js';
18
- import { generateStatuslineScript, generateStatuslineHook } from './statusline-generator.js';
19
- import {
20
- generatePreCommitHook,
21
- generatePostCommitHook,
22
- generateSessionManager,
23
- generateAgentRouter,
24
- generateMemoryHelper,
25
- } from './helpers-generator.js';
26
- import { generateClaudeMd, generateMinimalClaudeMd } from './claudemd-generator.js';
27
-
28
- /**
29
- * Skills to copy based on configuration
30
- */
31
- const SKILLS_MAP: Record<string, string[]> = {
32
- core: [
33
- 'swarm-orchestration',
34
- 'swarm-advanced',
35
- 'sparc-methodology',
36
- 'hooks-automation',
37
- 'pair-programming',
38
- 'verification-quality',
39
- 'stream-chain',
40
- 'skill-builder',
41
- ],
42
- agentdb: [
43
- 'agentdb-advanced',
44
- 'agentdb-learning',
45
- 'agentdb-memory-patterns',
46
- 'agentdb-optimization',
47
- 'agentdb-vector-search',
48
- 'reasoningbank-agentdb',
49
- 'reasoningbank-intelligence',
50
- ],
51
- github: [
52
- 'github-code-review',
53
- 'github-multi-repo',
54
- 'github-project-management',
55
- 'github-release-management',
56
- 'github-workflow-automation',
57
- ],
58
- flowNexus: [
59
- 'flow-nexus-neural',
60
- 'flow-nexus-platform',
61
- 'flow-nexus-swarm',
62
- ],
63
- v3: [
64
- 'v3-cli-modernization',
65
- 'v3-core-implementation',
66
- 'v3-ddd-architecture',
67
- 'v3-integration-deep',
68
- 'v3-mcp-optimization',
69
- 'v3-memory-unification',
70
- 'v3-performance-optimization',
71
- 'v3-security-overhaul',
72
- 'v3-swarm-coordination',
73
- ],
74
- };
75
-
76
- /**
77
- * Commands to copy based on configuration
78
- */
79
- const COMMANDS_MAP: Record<string, string[]> = {
80
- core: ['claude-flow-help.md', 'claude-flow-swarm.md', 'claude-flow-memory.md'],
81
- analysis: ['analysis'],
82
- automation: ['automation'],
83
- github: ['github'],
84
- hooks: ['hooks'],
85
- monitoring: ['monitoring'],
86
- optimization: ['optimization'],
87
- sparc: ['sparc'],
88
- };
89
-
90
- /**
91
- * Agents to copy based on configuration
92
- */
93
- const AGENTS_MAP: Record<string, string[]> = {
94
- core: ['core'],
95
- consensus: ['consensus'],
96
- github: ['github'],
97
- hiveMind: ['hive-mind'],
98
- sparc: ['sparc'],
99
- swarm: ['swarm'],
100
- };
101
-
102
- /**
103
- * Directory structure to create
104
- */
105
- const DIRECTORIES = {
106
- claude: [
107
- '.claude',
108
- '.claude/skills',
109
- '.claude/commands',
110
- '.claude/agents',
111
- '.claude/helpers',
112
- ],
113
- runtime: [
114
- '.claude-flow',
115
- '.claude-flow/data',
116
- '.claude-flow/logs',
117
- '.claude-flow/sessions',
118
- '.claude-flow/hooks',
119
- '.claude-flow/agents',
120
- '.claude-flow/workflows',
121
- ],
122
- };
123
-
124
- /**
125
- * Execute initialization
126
- */
127
- export async function executeInit(options: InitOptions): Promise<InitResult> {
128
- // Detect platform
129
- const platform = detectPlatform();
130
-
131
- const result: InitResult = {
132
- success: true,
133
- platform,
134
- created: {
135
- directories: [],
136
- files: [],
137
- },
138
- skipped: [],
139
- errors: [],
140
- summary: {
141
- skillsCount: 0,
142
- commandsCount: 0,
143
- agentsCount: 0,
144
- hooksEnabled: 0,
145
- },
146
- };
147
-
148
- const targetDir = options.targetDir;
149
-
150
- try {
151
- // Create directory structure
152
- await createDirectories(targetDir, options, result);
153
-
154
- // Generate and write settings.json
155
- if (options.components.settings) {
156
- await writeSettings(targetDir, options, result);
157
- }
158
-
159
- // Generate and write .mcp.json
160
- if (options.components.mcp) {
161
- await writeMCPConfig(targetDir, options, result);
162
- }
163
-
164
- // Copy skills
165
- if (options.components.skills) {
166
- await copySkills(targetDir, options, result);
167
- }
168
-
169
- // Copy commands
170
- if (options.components.commands) {
171
- await copyCommands(targetDir, options, result);
172
- }
173
-
174
- // Copy agents
175
- if (options.components.agents) {
176
- await copyAgents(targetDir, options, result);
177
- }
178
-
179
- // Generate helpers
180
- if (options.components.helpers) {
181
- await writeHelpers(targetDir, options, result);
182
- }
183
-
184
- // Generate statusline
185
- if (options.components.statusline) {
186
- await writeStatusline(targetDir, options, result);
187
- }
188
-
189
- // Generate runtime config
190
- if (options.components.runtime) {
191
- await writeRuntimeConfig(targetDir, options, result);
192
- }
193
-
194
- // Generate CLAUDE.md
195
- if (options.components.claudeMd) {
196
- await writeClaudeMd(targetDir, options, result);
197
- }
198
-
199
- // Count enabled hooks
200
- result.summary.hooksEnabled = countEnabledHooks(options);
201
-
202
- } catch (error) {
203
- result.success = false;
204
- result.errors.push(error instanceof Error ? error.message : String(error));
205
- }
206
-
207
- return result;
208
- }
209
-
210
- /**
211
- * Create directory structure
212
- */
213
- async function createDirectories(
214
- targetDir: string,
215
- options: InitOptions,
216
- result: InitResult
217
- ): Promise<void> {
218
- const dirs = [
219
- ...DIRECTORIES.claude,
220
- ...(options.components.runtime ? DIRECTORIES.runtime : []),
221
- ];
222
-
223
- for (const dir of dirs) {
224
- const fullPath = path.join(targetDir, dir);
225
- if (!fs.existsSync(fullPath)) {
226
- fs.mkdirSync(fullPath, { recursive: true });
227
- result.created.directories.push(dir);
228
- }
229
- }
230
- }
231
-
232
- /**
233
- * Write settings.json
234
- */
235
- async function writeSettings(
236
- targetDir: string,
237
- options: InitOptions,
238
- result: InitResult
239
- ): Promise<void> {
240
- const settingsPath = path.join(targetDir, '.claude', 'settings.json');
241
-
242
- if (fs.existsSync(settingsPath) && !options.force) {
243
- result.skipped.push('.claude/settings.json');
244
- return;
245
- }
246
-
247
- const content = generateSettingsJson(options);
248
- fs.writeFileSync(settingsPath, content, 'utf-8');
249
- result.created.files.push('.claude/settings.json');
250
- }
251
-
252
- /**
253
- * Write .mcp.json
254
- */
255
- async function writeMCPConfig(
256
- targetDir: string,
257
- options: InitOptions,
258
- result: InitResult
259
- ): Promise<void> {
260
- const mcpPath = path.join(targetDir, '.mcp.json');
261
-
262
- if (fs.existsSync(mcpPath) && !options.force) {
263
- result.skipped.push('.mcp.json');
264
- return;
265
- }
266
-
267
- const content = generateMCPJson(options);
268
- fs.writeFileSync(mcpPath, content, 'utf-8');
269
- result.created.files.push('.mcp.json');
270
- }
271
-
272
- /**
273
- * Copy skills from source
274
- */
275
- async function copySkills(
276
- targetDir: string,
277
- options: InitOptions,
278
- result: InitResult
279
- ): Promise<void> {
280
- const skillsConfig = options.skills;
281
- const targetSkillsDir = path.join(targetDir, '.claude', 'skills');
282
-
283
- // Determine which skills to copy
284
- const skillsToCopy: string[] = [];
285
-
286
- if (skillsConfig.all) {
287
- // Copy all available skills
288
- Object.values(SKILLS_MAP).forEach(skills => skillsToCopy.push(...skills));
289
- } else {
290
- if (skillsConfig.core) skillsToCopy.push(...SKILLS_MAP.core);
291
- if (skillsConfig.agentdb) skillsToCopy.push(...SKILLS_MAP.agentdb);
292
- if (skillsConfig.github) skillsToCopy.push(...SKILLS_MAP.github);
293
- if (skillsConfig.flowNexus) skillsToCopy.push(...SKILLS_MAP.flowNexus);
294
- if (skillsConfig.v3) skillsToCopy.push(...SKILLS_MAP.v3);
295
- }
296
-
297
- // Find source skills directory
298
- const sourceSkillsDir = findSourceDir('skills', options.sourceBaseDir);
299
- if (!sourceSkillsDir) {
300
- result.errors.push('Could not find source skills directory');
301
- return;
302
- }
303
-
304
- // Copy each skill
305
- for (const skillName of [...new Set(skillsToCopy)]) {
306
- const sourcePath = path.join(sourceSkillsDir, skillName);
307
- const targetPath = path.join(targetSkillsDir, skillName);
308
-
309
- if (fs.existsSync(sourcePath)) {
310
- if (!fs.existsSync(targetPath) || options.force) {
311
- copyDirRecursive(sourcePath, targetPath);
312
- result.created.files.push(`.claude/skills/${skillName}`);
313
- result.summary.skillsCount++;
314
- } else {
315
- result.skipped.push(`.claude/skills/${skillName}`);
316
- }
317
- }
318
- }
319
- }
320
-
321
- /**
322
- * Copy commands from source
323
- */
324
- async function copyCommands(
325
- targetDir: string,
326
- options: InitOptions,
327
- result: InitResult
328
- ): Promise<void> {
329
- const commandsConfig = options.commands;
330
- const targetCommandsDir = path.join(targetDir, '.claude', 'commands');
331
-
332
- // Determine which commands to copy
333
- const commandsToCopy: string[] = [];
334
-
335
- if (commandsConfig.all) {
336
- Object.values(COMMANDS_MAP).forEach(cmds => commandsToCopy.push(...cmds));
337
- } else {
338
- if (commandsConfig.core) commandsToCopy.push(...COMMANDS_MAP.core);
339
- if (commandsConfig.analysis) commandsToCopy.push(...COMMANDS_MAP.analysis);
340
- if (commandsConfig.automation) commandsToCopy.push(...COMMANDS_MAP.automation);
341
- if (commandsConfig.github) commandsToCopy.push(...COMMANDS_MAP.github);
342
- if (commandsConfig.hooks) commandsToCopy.push(...COMMANDS_MAP.hooks);
343
- if (commandsConfig.monitoring) commandsToCopy.push(...COMMANDS_MAP.monitoring);
344
- if (commandsConfig.optimization) commandsToCopy.push(...COMMANDS_MAP.optimization);
345
- if (commandsConfig.sparc) commandsToCopy.push(...COMMANDS_MAP.sparc);
346
- }
347
-
348
- // Find source commands directory
349
- const sourceCommandsDir = findSourceDir('commands', options.sourceBaseDir);
350
- if (!sourceCommandsDir) {
351
- result.errors.push('Could not find source commands directory');
352
- return;
353
- }
354
-
355
- // Copy each command/directory
356
- for (const cmdName of [...new Set(commandsToCopy)]) {
357
- const sourcePath = path.join(sourceCommandsDir, cmdName);
358
- const targetPath = path.join(targetCommandsDir, cmdName);
359
-
360
- if (fs.existsSync(sourcePath)) {
361
- if (!fs.existsSync(targetPath) || options.force) {
362
- if (fs.statSync(sourcePath).isDirectory()) {
363
- copyDirRecursive(sourcePath, targetPath);
364
- } else {
365
- fs.copyFileSync(sourcePath, targetPath);
366
- }
367
- result.created.files.push(`.claude/commands/${cmdName}`);
368
- result.summary.commandsCount++;
369
- } else {
370
- result.skipped.push(`.claude/commands/${cmdName}`);
371
- }
372
- }
373
- }
374
- }
375
-
376
- /**
377
- * Copy agents from source
378
- */
379
- async function copyAgents(
380
- targetDir: string,
381
- options: InitOptions,
382
- result: InitResult
383
- ): Promise<void> {
384
- const agentsConfig = options.agents;
385
- const targetAgentsDir = path.join(targetDir, '.claude', 'agents');
386
-
387
- // Determine which agents to copy
388
- const agentsToCopy: string[] = [];
389
-
390
- if (agentsConfig.all) {
391
- Object.values(AGENTS_MAP).forEach(agents => agentsToCopy.push(...agents));
392
- } else {
393
- if (agentsConfig.core) agentsToCopy.push(...AGENTS_MAP.core);
394
- if (agentsConfig.consensus) agentsToCopy.push(...AGENTS_MAP.consensus);
395
- if (agentsConfig.github) agentsToCopy.push(...AGENTS_MAP.github);
396
- if (agentsConfig.hiveMind) agentsToCopy.push(...AGENTS_MAP.hiveMind);
397
- if (agentsConfig.sparc) agentsToCopy.push(...AGENTS_MAP.sparc);
398
- if (agentsConfig.swarm) agentsToCopy.push(...AGENTS_MAP.swarm);
399
- }
400
-
401
- // Find source agents directory
402
- const sourceAgentsDir = findSourceDir('agents', options.sourceBaseDir);
403
- if (!sourceAgentsDir) {
404
- result.errors.push('Could not find source agents directory');
405
- return;
406
- }
407
-
408
- // Copy each agent category
409
- for (const agentCategory of [...new Set(agentsToCopy)]) {
410
- const sourcePath = path.join(sourceAgentsDir, agentCategory);
411
- const targetPath = path.join(targetAgentsDir, agentCategory);
412
-
413
- if (fs.existsSync(sourcePath)) {
414
- if (!fs.existsSync(targetPath) || options.force) {
415
- copyDirRecursive(sourcePath, targetPath);
416
- // Count agent files
417
- const agentFiles = countFiles(sourcePath, '.md');
418
- result.summary.agentsCount += agentFiles;
419
- result.created.files.push(`.claude/agents/${agentCategory}`);
420
- } else {
421
- result.skipped.push(`.claude/agents/${agentCategory}`);
422
- }
423
- }
424
- }
425
- }
426
-
427
- /**
428
- * Write helper scripts
429
- */
430
- async function writeHelpers(
431
- targetDir: string,
432
- options: InitOptions,
433
- result: InitResult
434
- ): Promise<void> {
435
- const helpersDir = path.join(targetDir, '.claude', 'helpers');
436
- const sourceBaseDir = options.sourceBaseDir;
437
-
438
- // Try to copy existing helpers from source first
439
- if (sourceBaseDir) {
440
- const sourceHelpersDir = path.join(sourceBaseDir, '.claude', 'helpers');
441
- if (fs.existsSync(sourceHelpersDir)) {
442
- const helperFiles = fs.readdirSync(sourceHelpersDir);
443
- for (const file of helperFiles) {
444
- const sourcePath = path.join(sourceHelpersDir, file);
445
- const destPath = path.join(helpersDir, file);
446
-
447
- // Skip directories and only copy files
448
- if (!fs.statSync(sourcePath).isFile()) continue;
449
-
450
- if (!fs.existsSync(destPath) || options.force) {
451
- fs.copyFileSync(sourcePath, destPath);
452
-
453
- // Make shell scripts executable
454
- if (file.endsWith('.sh')) {
455
- fs.chmodSync(destPath, '755');
456
- }
457
-
458
- result.created.files.push(`.claude/helpers/${file}`);
459
- } else {
460
- result.skipped.push(`.claude/helpers/${file}`);
461
- }
462
- }
463
- return; // Skip generating if we copied from source
464
- }
465
- }
466
-
467
- // Fall back to generating helpers if source not available
468
- const helpers: Record<string, string> = {
469
- 'pre-commit': generatePreCommitHook(),
470
- 'post-commit': generatePostCommitHook(),
471
- 'session.js': generateSessionManager(),
472
- 'router.js': generateAgentRouter(),
473
- 'memory.js': generateMemoryHelper(),
474
- };
475
-
476
- for (const [name, content] of Object.entries(helpers)) {
477
- const filePath = path.join(helpersDir, name);
478
-
479
- if (!fs.existsSync(filePath) || options.force) {
480
- fs.writeFileSync(filePath, content, 'utf-8');
481
-
482
- // Make shell scripts executable
483
- if (!name.endsWith('.js')) {
484
- fs.chmodSync(filePath, '755');
485
- }
486
-
487
- result.created.files.push(`.claude/helpers/${name}`);
488
- } else {
489
- result.skipped.push(`.claude/helpers/${name}`);
490
- }
491
- }
492
- }
493
-
494
- /**
495
- * Write statusline configuration
496
- */
497
- async function writeStatusline(
498
- targetDir: string,
499
- options: InitOptions,
500
- result: InitResult
501
- ): Promise<void> {
502
- const claudeDir = path.join(targetDir, '.claude');
503
- const helpersDir = path.join(targetDir, '.claude', 'helpers');
504
-
505
- // Try to copy existing advanced statusline files from source
506
- const sourceBaseDir = options.sourceBaseDir;
507
- const advancedStatuslineFiles = [
508
- { src: 'statusline.sh', dest: 'statusline.sh', dir: claudeDir },
509
- { src: 'statusline.mjs', dest: 'statusline.mjs', dir: claudeDir },
510
- ];
511
-
512
- let copiedAdvanced = false;
513
- if (sourceBaseDir) {
514
- for (const file of advancedStatuslineFiles) {
515
- const sourcePath = path.join(sourceBaseDir, '.claude', file.src);
516
- const destPath = path.join(file.dir, file.dest);
517
-
518
- if (fs.existsSync(sourcePath)) {
519
- if (!fs.existsSync(destPath) || options.force) {
520
- fs.copyFileSync(sourcePath, destPath);
521
- // Make shell scripts executable
522
- if (file.src.endsWith('.sh')) {
523
- fs.chmodSync(destPath, '755');
524
- }
525
- result.created.files.push(`.claude/${file.dest}`);
526
- copiedAdvanced = true;
527
- } else {
528
- result.skipped.push(`.claude/${file.dest}`);
529
- }
530
- }
531
- }
532
- }
533
-
534
- // Fall back to generating simple statusline if advanced files not available
535
- if (!copiedAdvanced) {
536
- const statuslineScript = generateStatuslineScript(options);
537
- const statuslineHook = generateStatuslineHook(options);
538
-
539
- const files: Record<string, string> = {
540
- 'statusline.js': statuslineScript,
541
- 'statusline-hook.sh': statuslineHook,
542
- };
543
-
544
- for (const [name, content] of Object.entries(files)) {
545
- const filePath = path.join(helpersDir, name);
546
-
547
- if (!fs.existsSync(filePath) || options.force) {
548
- fs.writeFileSync(filePath, content, 'utf-8');
549
- result.created.files.push(`.claude/helpers/${name}`);
550
- } else {
551
- result.skipped.push(`.claude/helpers/${name}`);
552
- }
553
- }
554
- }
555
- }
556
-
557
- /**
558
- * Write runtime configuration (.claude-flow/)
559
- */
560
- async function writeRuntimeConfig(
561
- targetDir: string,
562
- options: InitOptions,
563
- result: InitResult
564
- ): Promise<void> {
565
- const configPath = path.join(targetDir, '.claude-flow', 'config.yaml');
566
-
567
- if (fs.existsSync(configPath) && !options.force) {
568
- result.skipped.push('.claude-flow/config.yaml');
569
- return;
570
- }
571
-
572
- const config = `# Claude Flow V3 Runtime Configuration
573
- # Generated: ${new Date().toISOString()}
574
-
575
- version: "3.0.0"
576
-
577
- swarm:
578
- topology: ${options.runtime.topology}
579
- maxAgents: ${options.runtime.maxAgents}
580
- autoScale: true
581
- coordinationStrategy: consensus
582
-
583
- memory:
584
- backend: ${options.runtime.memoryBackend}
585
- enableHNSW: ${options.runtime.enableHNSW}
586
- persistPath: .claude-flow/data
587
- cacheSize: 100
588
-
589
- neural:
590
- enabled: ${options.runtime.enableNeural}
591
- modelPath: .claude-flow/neural
592
-
593
- hooks:
594
- enabled: true
595
- autoExecute: true
596
-
597
- mcp:
598
- autoStart: ${options.mcp.autoStart}
599
- port: ${options.mcp.port}
600
- `;
601
-
602
- fs.writeFileSync(configPath, config, 'utf-8');
603
- result.created.files.push('.claude-flow/config.yaml');
604
-
605
- // Write .gitignore
606
- const gitignorePath = path.join(targetDir, '.claude-flow', '.gitignore');
607
- const gitignore = `# Claude Flow runtime files
608
- data/
609
- logs/
610
- sessions/
611
- neural/
612
- *.log
613
- *.tmp
614
- `;
615
-
616
- if (!fs.existsSync(gitignorePath) || options.force) {
617
- fs.writeFileSync(gitignorePath, gitignore, 'utf-8');
618
- result.created.files.push('.claude-flow/.gitignore');
619
- }
620
- }
621
-
622
- /**
623
- * Write CLAUDE.md with swarm guidance
624
- */
625
- async function writeClaudeMd(
626
- targetDir: string,
627
- options: InitOptions,
628
- result: InitResult
629
- ): Promise<void> {
630
- const claudeMdPath = path.join(targetDir, 'CLAUDE.md');
631
-
632
- if (fs.existsSync(claudeMdPath) && !options.force) {
633
- result.skipped.push('CLAUDE.md');
634
- return;
635
- }
636
-
637
- // Use minimal version for minimal init, full version otherwise
638
- const isMinimal = !options.components.commands && !options.components.agents;
639
- const content = isMinimal ? generateMinimalClaudeMd(options) : generateClaudeMd(options);
640
-
641
- fs.writeFileSync(claudeMdPath, content, 'utf-8');
642
- result.created.files.push('CLAUDE.md');
643
- }
644
-
645
- /**
646
- * Find source directory for skills/commands/agents
647
- */
648
- function findSourceDir(type: 'skills' | 'commands' | 'agents', sourceBaseDir?: string): string | null {
649
- // Build list of possible paths to check
650
- const possiblePaths: string[] = [];
651
-
652
- // If explicit source base directory is provided, use it first
653
- if (sourceBaseDir) {
654
- possiblePaths.push(path.join(sourceBaseDir, '.claude', type));
655
- }
656
-
657
- // From dist/src/init -> go up to project root
658
- // __dirname is typically /path/to/v3/@claude-flow/cli/dist/src/init
659
- const distPath = __dirname;
660
-
661
- // Try to find the project root by looking for .claude directory
662
- let currentDir = distPath;
663
- for (let i = 0; i < 10; i++) {
664
- const parentDir = path.dirname(currentDir);
665
- const dotClaudePath = path.join(parentDir, '.claude', type);
666
- if (fs.existsSync(dotClaudePath)) {
667
- possiblePaths.push(dotClaudePath);
668
- }
669
- currentDir = parentDir;
670
- }
671
-
672
- // Also check relative to process.cwd() for development
673
- const cwdBased = [
674
- path.join(process.cwd(), '.claude', type),
675
- path.join(process.cwd(), '..', '.claude', type),
676
- path.join(process.cwd(), '..', '..', '.claude', type),
677
- ];
678
- possiblePaths.push(...cwdBased);
679
-
680
- // Check v2 directory for agents
681
- if (type === 'agents') {
682
- possiblePaths.push(
683
- path.join(process.cwd(), 'v2', '.claude', type),
684
- path.join(process.cwd(), '..', 'v2', '.claude', type),
685
- );
686
- }
687
-
688
- // Plugin directory
689
- possiblePaths.push(
690
- path.join(process.cwd(), 'plugin', type),
691
- path.join(process.cwd(), '..', 'plugin', type),
692
- );
693
-
694
- for (const p of possiblePaths) {
695
- if (fs.existsSync(p)) {
696
- return p;
697
- }
698
- }
699
-
700
- return null;
701
- }
702
-
703
- /**
704
- * Copy directory recursively
705
- */
706
- function copyDirRecursive(src: string, dest: string): void {
707
- fs.mkdirSync(dest, { recursive: true });
708
-
709
- const entries = fs.readdirSync(src, { withFileTypes: true });
710
-
711
- for (const entry of entries) {
712
- const srcPath = path.join(src, entry.name);
713
- const destPath = path.join(dest, entry.name);
714
-
715
- if (entry.isDirectory()) {
716
- copyDirRecursive(srcPath, destPath);
717
- } else {
718
- fs.copyFileSync(srcPath, destPath);
719
- }
720
- }
721
- }
722
-
723
- /**
724
- * Count files with extension in directory
725
- */
726
- function countFiles(dir: string, ext: string): number {
727
- let count = 0;
728
-
729
- const entries = fs.readdirSync(dir, { withFileTypes: true });
730
-
731
- for (const entry of entries) {
732
- const fullPath = path.join(dir, entry.name);
733
-
734
- if (entry.isDirectory()) {
735
- count += countFiles(fullPath, ext);
736
- } else if (entry.name.endsWith(ext)) {
737
- count++;
738
- }
739
- }
740
-
741
- return count;
742
- }
743
-
744
- /**
745
- * Count enabled hooks
746
- */
747
- function countEnabledHooks(options: InitOptions): number {
748
- const hooks = options.hooks;
749
- let count = 0;
750
-
751
- if (hooks.preToolUse) count++;
752
- if (hooks.postToolUse) count++;
753
- if (hooks.userPromptSubmit) count++;
754
- if (hooks.sessionStart) count++;
755
- if (hooks.stop) count++;
756
- if (hooks.notification) count++;
757
- if (hooks.permissionRequest) count++;
758
-
759
- return count;
760
- }
761
-
762
- export default executeInit;