@wundr.io/cli 1.0.0 → 1.0.3

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 (224) hide show
  1. package/README.md +696 -280
  2. package/dist/ai/ai-service.d.ts +2 -2
  3. package/dist/ai/ai-service.d.ts.map +1 -1
  4. package/dist/ai/ai-service.js +1 -1
  5. package/dist/ai/ai-service.js.map +1 -1
  6. package/dist/ai/claude-client.d.ts.map +1 -1
  7. package/dist/ai/claude-client.js +2 -1
  8. package/dist/ai/claude-client.js.map +1 -1
  9. package/dist/ai/conversation-manager.d.ts +2 -2
  10. package/dist/ai/conversation-manager.d.ts.map +1 -1
  11. package/dist/ai/conversation-manager.js +5 -3
  12. package/dist/ai/conversation-manager.js.map +1 -1
  13. package/dist/cli.d.ts.map +1 -1
  14. package/dist/cli.js +32 -13
  15. package/dist/cli.js.map +1 -1
  16. package/dist/commands/ai.d.ts +3 -3
  17. package/dist/commands/ai.d.ts.map +1 -1
  18. package/dist/commands/ai.js +2 -2
  19. package/dist/commands/ai.js.map +1 -1
  20. package/dist/commands/alignment.d.ts +78 -0
  21. package/dist/commands/alignment.d.ts.map +1 -0
  22. package/dist/commands/alignment.js +817 -0
  23. package/dist/commands/alignment.js.map +1 -0
  24. package/dist/commands/analyze-optimized.d.ts.map +1 -1
  25. package/dist/commands/analyze-optimized.js +9 -6
  26. package/dist/commands/analyze-optimized.js.map +1 -1
  27. package/dist/commands/analyze.d.ts +3 -3
  28. package/dist/commands/analyze.d.ts.map +1 -1
  29. package/dist/commands/analyze.js +2 -2
  30. package/dist/commands/analyze.js.map +1 -1
  31. package/dist/commands/batch.d.ts +3 -3
  32. package/dist/commands/batch.d.ts.map +1 -1
  33. package/dist/commands/batch.js +7 -7
  34. package/dist/commands/batch.js.map +1 -1
  35. package/dist/commands/chat.d.ts +3 -3
  36. package/dist/commands/chat.d.ts.map +1 -1
  37. package/dist/commands/chat.js +3 -3
  38. package/dist/commands/chat.js.map +1 -1
  39. package/dist/commands/claude-init.d.ts +1 -1
  40. package/dist/commands/claude-init.d.ts.map +1 -1
  41. package/dist/commands/claude-init.js +11 -7
  42. package/dist/commands/claude-init.js.map +1 -1
  43. package/dist/commands/claude-setup.d.ts +88 -1
  44. package/dist/commands/claude-setup.d.ts.map +1 -1
  45. package/dist/commands/claude-setup.js +549 -46
  46. package/dist/commands/claude-setup.js.map +1 -1
  47. package/dist/commands/computer-setup-commands.d.ts +17 -3
  48. package/dist/commands/computer-setup-commands.d.ts.map +1 -1
  49. package/dist/commands/computer-setup-commands.js +145 -3
  50. package/dist/commands/computer-setup-commands.js.map +1 -1
  51. package/dist/commands/computer-setup.d.ts.map +1 -1
  52. package/dist/commands/computer-setup.js +372 -4
  53. package/dist/commands/computer-setup.js.map +1 -1
  54. package/dist/commands/create-command.d.ts.map +1 -1
  55. package/dist/commands/create-command.js +3 -3
  56. package/dist/commands/create-command.js.map +1 -1
  57. package/dist/commands/create.d.ts +3 -3
  58. package/dist/commands/create.d.ts.map +1 -1
  59. package/dist/commands/create.js +3 -3
  60. package/dist/commands/create.js.map +1 -1
  61. package/dist/commands/dashboard.d.ts +3 -3
  62. package/dist/commands/dashboard.d.ts.map +1 -1
  63. package/dist/commands/dashboard.js +4 -3
  64. package/dist/commands/dashboard.js.map +1 -1
  65. package/dist/commands/govern.d.ts +3 -3
  66. package/dist/commands/govern.d.ts.map +1 -1
  67. package/dist/commands/govern.js +4 -3
  68. package/dist/commands/govern.js.map +1 -1
  69. package/dist/commands/governance.d.ts +17 -0
  70. package/dist/commands/governance.d.ts.map +1 -0
  71. package/dist/commands/governance.js +703 -0
  72. package/dist/commands/governance.js.map +1 -0
  73. package/dist/commands/guardian.d.ts +20 -0
  74. package/dist/commands/guardian.d.ts.map +1 -0
  75. package/dist/commands/guardian.js +597 -0
  76. package/dist/commands/guardian.js.map +1 -0
  77. package/dist/commands/init.d.ts +7 -3
  78. package/dist/commands/init.d.ts.map +1 -1
  79. package/dist/commands/init.js +71 -5
  80. package/dist/commands/init.js.map +1 -1
  81. package/dist/commands/performance-optimizer.d.ts +2 -2
  82. package/dist/commands/performance-optimizer.d.ts.map +1 -1
  83. package/dist/commands/performance-optimizer.js +8 -7
  84. package/dist/commands/performance-optimizer.js.map +1 -1
  85. package/dist/commands/plugins.d.ts +3 -3
  86. package/dist/commands/plugins.d.ts.map +1 -1
  87. package/dist/commands/plugins.js +2 -2
  88. package/dist/commands/plugins.js.map +1 -1
  89. package/dist/commands/rag.d.ts +7 -0
  90. package/dist/commands/rag.d.ts.map +1 -0
  91. package/dist/commands/rag.js +748 -0
  92. package/dist/commands/rag.js.map +1 -0
  93. package/dist/commands/session.d.ts +41 -0
  94. package/dist/commands/session.d.ts.map +1 -0
  95. package/dist/commands/session.js +441 -0
  96. package/dist/commands/session.js.map +1 -0
  97. package/dist/commands/setup.d.ts +3 -3
  98. package/dist/commands/setup.d.ts.map +1 -1
  99. package/dist/commands/setup.js +1 -3
  100. package/dist/commands/setup.js.map +1 -1
  101. package/dist/commands/test-init.d.ts.map +1 -1
  102. package/dist/commands/test-init.js +2 -2
  103. package/dist/commands/test-init.js.map +1 -1
  104. package/dist/commands/test.d.ts.map +1 -1
  105. package/dist/commands/test.js +2 -2
  106. package/dist/commands/test.js.map +1 -1
  107. package/dist/commands/vp.d.ts +7 -0
  108. package/dist/commands/vp.d.ts.map +1 -0
  109. package/dist/commands/vp.js +571 -0
  110. package/dist/commands/vp.js.map +1 -0
  111. package/dist/commands/watch.d.ts +3 -3
  112. package/dist/commands/watch.d.ts.map +1 -1
  113. package/dist/commands/watch.js +10 -7
  114. package/dist/commands/watch.js.map +1 -1
  115. package/dist/commands/worktree.d.ts +63 -0
  116. package/dist/commands/worktree.d.ts.map +1 -0
  117. package/dist/commands/worktree.js +774 -0
  118. package/dist/commands/worktree.js.map +1 -0
  119. package/dist/context/context-manager.d.ts +1 -1
  120. package/dist/context/context-manager.d.ts.map +1 -1
  121. package/dist/context/context-manager.js +1 -1
  122. package/dist/context/context-manager.js.map +1 -1
  123. package/dist/context/session-manager.d.ts +2 -2
  124. package/dist/context/session-manager.d.ts.map +1 -1
  125. package/dist/context/session-manager.js +9 -5
  126. package/dist/context/session-manager.js.map +1 -1
  127. package/dist/index.d.ts.map +1 -1
  128. package/dist/index.js +1 -1
  129. package/dist/index.js.map +1 -1
  130. package/dist/interactive/interactive-mode.d.ts +2 -2
  131. package/dist/interactive/interactive-mode.d.ts.map +1 -1
  132. package/dist/interactive/interactive-mode.js +6 -4
  133. package/dist/interactive/interactive-mode.js.map +1 -1
  134. package/dist/nlp/command-mapper.d.ts +1 -1
  135. package/dist/nlp/command-mapper.d.ts.map +1 -1
  136. package/dist/nlp/command-mapper.js +3 -2
  137. package/dist/nlp/command-mapper.js.map +1 -1
  138. package/dist/nlp/command-parser.d.ts +1 -1
  139. package/dist/nlp/command-parser.d.ts.map +1 -1
  140. package/dist/nlp/command-parser.js +2 -1
  141. package/dist/nlp/command-parser.js.map +1 -1
  142. package/dist/nlp/intent-parser.d.ts +1 -1
  143. package/dist/nlp/intent-parser.d.ts.map +1 -1
  144. package/dist/nlp/intent-parser.js +14 -9
  145. package/dist/nlp/intent-parser.js.map +1 -1
  146. package/dist/plugins/plugin-manager.d.ts +2 -2
  147. package/dist/plugins/plugin-manager.d.ts.map +1 -1
  148. package/dist/plugins/plugin-manager.js +3 -3
  149. package/dist/plugins/plugin-manager.js.map +1 -1
  150. package/dist/types/index.d.ts +1 -1
  151. package/dist/types/index.d.ts.map +1 -1
  152. package/dist/utils/backup-rollback-manager.d.ts +72 -0
  153. package/dist/utils/backup-rollback-manager.d.ts.map +1 -0
  154. package/dist/utils/backup-rollback-manager.js +289 -0
  155. package/dist/utils/backup-rollback-manager.js.map +1 -0
  156. package/dist/utils/claude-config-installer.d.ts +94 -0
  157. package/dist/utils/claude-config-installer.d.ts.map +1 -0
  158. package/dist/utils/claude-config-installer.js +628 -0
  159. package/dist/utils/claude-config-installer.js.map +1 -0
  160. package/dist/utils/config-manager.d.ts +1 -1
  161. package/dist/utils/config-manager.d.ts.map +1 -1
  162. package/dist/utils/config-manager.js +5 -5
  163. package/dist/utils/config-manager.js.map +1 -1
  164. package/dist/utils/error-handler.d.ts +1 -1
  165. package/dist/utils/error-handler.d.ts.map +1 -1
  166. package/dist/utils/error-handler.js.map +1 -1
  167. package/dist/utils/logger.d.ts +1 -1
  168. package/dist/utils/logger.d.ts.map +1 -1
  169. package/dist/utils/logger.js +22 -11
  170. package/dist/utils/logger.js.map +1 -1
  171. package/package.json +26 -7
  172. package/src/ai/ai-service.ts +22 -19
  173. package/src/ai/claude-client.ts +20 -16
  174. package/src/ai/conversation-manager.ts +37 -30
  175. package/src/cli.ts +42 -13
  176. package/src/commands/ai.ts +59 -57
  177. package/src/commands/alignment.ts +1212 -0
  178. package/src/commands/analyze-optimized.ts +70 -62
  179. package/src/commands/analyze.ts +22 -20
  180. package/src/commands/batch.ts +41 -38
  181. package/src/commands/chat.ts +37 -34
  182. package/src/commands/claude-init.ts +38 -30
  183. package/src/commands/claude-setup.ts +692 -97
  184. package/src/commands/computer-setup-commands.ts +203 -37
  185. package/src/commands/computer-setup.ts +474 -4
  186. package/src/commands/create-command.ts +7 -7
  187. package/src/commands/create.ts +36 -33
  188. package/src/commands/dashboard.ts +33 -28
  189. package/src/commands/govern.ts +34 -29
  190. package/src/commands/governance.ts +1005 -0
  191. package/src/commands/guardian.ts +887 -0
  192. package/src/commands/init.ts +112 -22
  193. package/src/commands/performance-optimizer.ts +48 -42
  194. package/src/commands/plugins.ts +35 -32
  195. package/src/commands/project-update.ts +1053 -0
  196. package/src/commands/rag.ts +904 -0
  197. package/src/commands/session.ts +631 -0
  198. package/src/commands/setup.ts +35 -31
  199. package/src/commands/test-init.ts +6 -5
  200. package/src/commands/test.ts +7 -6
  201. package/src/commands/vp.ts +762 -0
  202. package/src/commands/watch.ts +44 -33
  203. package/src/commands/worktree.ts +1057 -0
  204. package/src/context/context-manager.ts +15 -12
  205. package/src/context/session-manager.ts +51 -40
  206. package/src/index.ts +7 -6
  207. package/src/interactive/interactive-mode.ts +25 -18
  208. package/src/lib/conflict-resolution.ts +28 -0
  209. package/src/lib/merge-strategy.ts +28 -0
  210. package/src/lib/safety-mechanisms.ts +47 -0
  211. package/src/lib/state-detection.ts +28 -0
  212. package/src/nlp/command-mapper.ts +35 -30
  213. package/src/nlp/command-parser.ts +20 -17
  214. package/src/nlp/intent-classifier.ts +7 -7
  215. package/src/nlp/intent-parser.ts +61 -49
  216. package/src/plugins/plugin-manager.ts +27 -23
  217. package/src/tests/computer-setup-integration.test.ts +439 -0
  218. package/src/types/index.ts +1 -1
  219. package/src/types/modules.d.ts +1 -0
  220. package/src/utils/backup-rollback-manager.ts +363 -0
  221. package/src/utils/claude-config-installer.ts +734 -0
  222. package/src/utils/config-manager.ts +12 -9
  223. package/src/utils/error-handler.ts +5 -3
  224. package/src/utils/logger.ts +35 -12
@@ -0,0 +1,734 @@
1
+ /**
2
+ * Claude Code Configuration Installer
3
+ * Handles installation of CLAUDE.md, hooks, conventions, and agent templates
4
+ */
5
+
6
+ import { existsSync } from 'fs';
7
+ import * as fs from 'fs/promises';
8
+ import * as path from 'path';
9
+
10
+ import chalk from 'chalk';
11
+ import ora from 'ora';
12
+
13
+ import { BackupRollbackManager } from './backup-rollback-manager';
14
+ import { logger } from './logger';
15
+
16
+ export interface ClaudeConfigOptions {
17
+ claudeDir?: string;
18
+ sourceDir?: string;
19
+ dryRun?: boolean;
20
+ skipBackup?: boolean;
21
+ overwrite?: boolean;
22
+ verbose?: boolean;
23
+ }
24
+
25
+ export interface InstallResult {
26
+ success: boolean;
27
+ installed: string[];
28
+ skipped: string[];
29
+ errors: Array<{ file: string; error: string }>;
30
+ backupId?: string;
31
+ }
32
+
33
+ export class ClaudeConfigInstaller {
34
+ private claudeDir: string;
35
+ private sourceDir: string;
36
+ private backupManager: BackupRollbackManager;
37
+ private homeDir: string;
38
+
39
+ constructor(options: ClaudeConfigOptions = {}) {
40
+ this.homeDir = process.env.HOME || process.env.USERPROFILE || '';
41
+ this.claudeDir = options.claudeDir || path.join(this.homeDir, '.claude');
42
+ this.sourceDir = options.sourceDir || process.cwd();
43
+ this.backupManager = new BackupRollbackManager();
44
+ }
45
+
46
+ /**
47
+ * Initialize installer
48
+ */
49
+ async initialize(): Promise<void> {
50
+ await this.backupManager.initialize();
51
+
52
+ // Create Claude directory structure
53
+ await this.createDirectoryStructure();
54
+ }
55
+
56
+ /**
57
+ * Install all Claude Code configurations
58
+ */
59
+ async install(options: ClaudeConfigOptions = {}): Promise<InstallResult> {
60
+ const { dryRun = false, skipBackup = false, overwrite = false, verbose = false } = options;
61
+
62
+ const result: InstallResult = {
63
+ success: false,
64
+ installed: [],
65
+ skipped: [],
66
+ errors: [],
67
+ };
68
+
69
+ try {
70
+ console.log(chalk.cyan('\nšŸ”§ Installing Claude Code Configuration\n'));
71
+
72
+ // Create backup of existing configs
73
+ if (!skipBackup && !dryRun) {
74
+ const existingFiles = await this.getExistingConfigFiles();
75
+ if (existingFiles.length > 0) {
76
+ const spinner = ora('Creating backup of existing configurations...').start();
77
+ const backup = await this.backupManager.createBackup(
78
+ existingFiles,
79
+ 'Pre-installation backup',
80
+ );
81
+ result.backupId = backup.backupId;
82
+ spinner.succeed(`Backup created: ${backup.backupId}`);
83
+ }
84
+ }
85
+
86
+ // Install CLAUDE.md
87
+ await this.installClaudeMd(result, { dryRun, overwrite, verbose });
88
+
89
+ // Install hooks
90
+ await this.installHooks(result, { dryRun, overwrite, verbose });
91
+
92
+ // Install conventions
93
+ await this.installConventions(result, { dryRun, overwrite, verbose });
94
+
95
+ // Install agent templates
96
+ await this.installAgentTemplates(result, { dryRun, overwrite, verbose });
97
+
98
+ // Install git-worktree workflows
99
+ await this.installGitWorktreeWorkflows(result, { dryRun, overwrite, verbose });
100
+
101
+ // Install validation scripts
102
+ await this.installValidationScripts(result, { dryRun, overwrite, verbose });
103
+
104
+ result.success = result.errors.length === 0;
105
+
106
+ // Display summary
107
+ this.displayInstallSummary(result, dryRun);
108
+
109
+ return result;
110
+ } catch (error) {
111
+ logger.error('Installation failed', error);
112
+ result.errors.push({
113
+ file: 'general',
114
+ error: error instanceof Error ? error.message : String(error),
115
+ });
116
+ return result;
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Install enhanced CLAUDE.md to ~/.claude/
122
+ */
123
+ private async installClaudeMd(
124
+ result: InstallResult,
125
+ options: { dryRun: boolean; overwrite: boolean; verbose: boolean },
126
+ ): Promise<void> {
127
+ const spinner = ora('Installing CLAUDE.md...').start();
128
+
129
+ try {
130
+ const sourcePath = path.join(this.sourceDir, 'CLAUDE.md');
131
+ const targetPath = path.join(this.claudeDir, 'CLAUDE.md');
132
+
133
+ if (!existsSync(sourcePath)) {
134
+ spinner.warn('CLAUDE.md not found in source directory');
135
+ result.skipped.push('CLAUDE.md');
136
+ return;
137
+ }
138
+
139
+ if (existsSync(targetPath) && !options.overwrite) {
140
+ if (options.verbose) {
141
+ spinner.info('CLAUDE.md already exists (use --overwrite to replace)');
142
+ }
143
+ result.skipped.push('CLAUDE.md');
144
+ return;
145
+ }
146
+
147
+ if (options.dryRun) {
148
+ spinner.info('Would install CLAUDE.md');
149
+ result.installed.push('CLAUDE.md (dry-run)');
150
+ return;
151
+ }
152
+
153
+ await fs.copyFile(sourcePath, targetPath);
154
+ spinner.succeed('CLAUDE.md installed');
155
+ result.installed.push('CLAUDE.md');
156
+
157
+ logger.info('CLAUDE.md installed', { target: targetPath });
158
+ } catch (error) {
159
+ spinner.fail('Failed to install CLAUDE.md');
160
+ result.errors.push({
161
+ file: 'CLAUDE.md',
162
+ error: error instanceof Error ? error.message : String(error),
163
+ });
164
+ logger.error('CLAUDE.md installation failed', error);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Install hooks configuration
170
+ */
171
+ private async installHooks(
172
+ result: InstallResult,
173
+ options: { dryRun: boolean; overwrite: boolean; verbose: boolean },
174
+ ): Promise<void> {
175
+ const spinner = ora('Installing hooks...').start();
176
+
177
+ try {
178
+ const hooksDir = path.join(this.claudeDir, 'hooks');
179
+ await fs.mkdir(hooksDir, { recursive: true });
180
+
181
+ const hooks = this.generateHooksConfig();
182
+
183
+ for (const [hookName, hookContent] of Object.entries(hooks)) {
184
+ const hookPath = path.join(hooksDir, hookName);
185
+
186
+ if (existsSync(hookPath) && !options.overwrite) {
187
+ result.skipped.push(`hooks/${hookName}`);
188
+ continue;
189
+ }
190
+
191
+ if (options.dryRun) {
192
+ result.installed.push(`hooks/${hookName} (dry-run)`);
193
+ continue;
194
+ }
195
+
196
+ await fs.writeFile(hookPath, hookContent);
197
+ await fs.chmod(hookPath, 0o755); // Make executable
198
+ result.installed.push(`hooks/${hookName}`);
199
+ }
200
+
201
+ spinner.succeed(`Hooks installed (${Object.keys(hooks).length} files)`);
202
+ logger.info('Hooks installed', { count: Object.keys(hooks).length });
203
+ } catch (error) {
204
+ spinner.fail('Failed to install hooks');
205
+ result.errors.push({
206
+ file: 'hooks',
207
+ error: error instanceof Error ? error.message : String(error),
208
+ });
209
+ logger.error('Hooks installation failed', error);
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Install conventions
215
+ */
216
+ private async installConventions(
217
+ result: InstallResult,
218
+ options: { dryRun: boolean; overwrite: boolean; verbose: boolean },
219
+ ): Promise<void> {
220
+ const spinner = ora('Installing conventions...').start();
221
+
222
+ try {
223
+ const conventionsPath = path.join(this.claudeDir, 'conventions.json');
224
+ const conventions = this.generateConventions();
225
+
226
+ if (existsSync(conventionsPath) && !options.overwrite) {
227
+ spinner.info('Conventions already exist');
228
+ result.skipped.push('conventions.json');
229
+ return;
230
+ }
231
+
232
+ if (options.dryRun) {
233
+ spinner.info('Would install conventions');
234
+ result.installed.push('conventions.json (dry-run)');
235
+ return;
236
+ }
237
+
238
+ await fs.writeFile(conventionsPath, JSON.stringify(conventions, null, 2));
239
+ spinner.succeed('Conventions installed');
240
+ result.installed.push('conventions.json');
241
+
242
+ logger.info('Conventions installed', { path: conventionsPath });
243
+ } catch (error) {
244
+ spinner.fail('Failed to install conventions');
245
+ result.errors.push({
246
+ file: 'conventions.json',
247
+ error: error instanceof Error ? error.message : String(error),
248
+ });
249
+ logger.error('Conventions installation failed', error);
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Install agent templates
255
+ */
256
+ private async installAgentTemplates(
257
+ result: InstallResult,
258
+ options: { dryRun: boolean; overwrite: boolean; verbose: boolean },
259
+ ): Promise<void> {
260
+ const spinner = ora('Installing agent templates...').start();
261
+
262
+ try {
263
+ const agentsDir = path.join(this.claudeDir, 'agents');
264
+ await fs.mkdir(agentsDir, { recursive: true });
265
+
266
+ const templates = this.generateAgentTemplates();
267
+
268
+ for (const [agentName, agentConfig] of Object.entries(templates)) {
269
+ const agentPath = path.join(agentsDir, `${agentName}.json`);
270
+
271
+ if (existsSync(agentPath) && !options.overwrite) {
272
+ result.skipped.push(`agents/${agentName}.json`);
273
+ continue;
274
+ }
275
+
276
+ if (options.dryRun) {
277
+ result.installed.push(`agents/${agentName}.json (dry-run)`);
278
+ continue;
279
+ }
280
+
281
+ await fs.writeFile(agentPath, JSON.stringify(agentConfig, null, 2));
282
+ result.installed.push(`agents/${agentName}.json`);
283
+ }
284
+
285
+ spinner.succeed(`Agent templates installed (${Object.keys(templates).length} templates)`);
286
+ logger.info('Agent templates installed', { count: Object.keys(templates).length });
287
+ } catch (error) {
288
+ spinner.fail('Failed to install agent templates');
289
+ result.errors.push({
290
+ file: 'agent-templates',
291
+ error: error instanceof Error ? error.message : String(error),
292
+ });
293
+ logger.error('Agent templates installation failed', error);
294
+ }
295
+ }
296
+
297
+ /**
298
+ * Install git-worktree workflows
299
+ */
300
+ private async installGitWorktreeWorkflows(
301
+ result: InstallResult,
302
+ options: { dryRun: boolean; overwrite: boolean; verbose: boolean },
303
+ ): Promise<void> {
304
+ const spinner = ora('Installing git-worktree workflows...').start();
305
+
306
+ try {
307
+ const workflowsDir = path.join(this.claudeDir, 'workflows');
308
+ await fs.mkdir(workflowsDir, { recursive: true });
309
+
310
+ const workflows = this.generateGitWorktreeWorkflows();
311
+
312
+ for (const [workflowName, workflowContent] of Object.entries(workflows)) {
313
+ const workflowPath = path.join(workflowsDir, `${workflowName}.json`);
314
+
315
+ if (existsSync(workflowPath) && !options.overwrite) {
316
+ result.skipped.push(`workflows/${workflowName}.json`);
317
+ continue;
318
+ }
319
+
320
+ if (options.dryRun) {
321
+ result.installed.push(`workflows/${workflowName}.json (dry-run)`);
322
+ continue;
323
+ }
324
+
325
+ await fs.writeFile(workflowPath, JSON.stringify(workflowContent, null, 2));
326
+ result.installed.push(`workflows/${workflowName}.json`);
327
+ }
328
+
329
+ spinner.succeed(`Git-worktree workflows installed (${Object.keys(workflows).length} workflows)`);
330
+ logger.info('Git-worktree workflows installed', { count: Object.keys(workflows).length });
331
+ } catch (error) {
332
+ spinner.fail('Failed to install git-worktree workflows');
333
+ result.errors.push({
334
+ file: 'git-worktree-workflows',
335
+ error: error instanceof Error ? error.message : String(error),
336
+ });
337
+ logger.error('Git-worktree workflows installation failed', error);
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Install validation scripts
343
+ */
344
+ private async installValidationScripts(
345
+ result: InstallResult,
346
+ options: { dryRun: boolean; overwrite: boolean; verbose: boolean },
347
+ ): Promise<void> {
348
+ const spinner = ora('Installing validation scripts...').start();
349
+
350
+ try {
351
+ const scriptsDir = path.join(this.claudeDir, 'scripts');
352
+ await fs.mkdir(scriptsDir, { recursive: true });
353
+
354
+ const scripts = this.generateValidationScripts();
355
+
356
+ for (const [scriptName, scriptContent] of Object.entries(scripts)) {
357
+ const scriptPath = path.join(scriptsDir, scriptName);
358
+
359
+ if (existsSync(scriptPath) && !options.overwrite) {
360
+ result.skipped.push(`scripts/${scriptName}`);
361
+ continue;
362
+ }
363
+
364
+ if (options.dryRun) {
365
+ result.installed.push(`scripts/${scriptName} (dry-run)`);
366
+ continue;
367
+ }
368
+
369
+ await fs.writeFile(scriptPath, scriptContent);
370
+ await fs.chmod(scriptPath, 0o755); // Make executable
371
+ result.installed.push(`scripts/${scriptName}`);
372
+ }
373
+
374
+ spinner.succeed(`Validation scripts installed (${Object.keys(scripts).length} scripts)`);
375
+ logger.info('Validation scripts installed', { count: Object.keys(scripts).length });
376
+ } catch (error) {
377
+ spinner.fail('Failed to install validation scripts');
378
+ result.errors.push({
379
+ file: 'validation-scripts',
380
+ error: error instanceof Error ? error.message : String(error),
381
+ });
382
+ logger.error('Validation scripts installation failed', error);
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Create directory structure
388
+ */
389
+ private async createDirectoryStructure(): Promise<void> {
390
+ const dirs = [
391
+ this.claudeDir,
392
+ path.join(this.claudeDir, 'hooks'),
393
+ path.join(this.claudeDir, 'agents'),
394
+ path.join(this.claudeDir, 'workflows'),
395
+ path.join(this.claudeDir, 'scripts'),
396
+ path.join(this.claudeDir, 'templates'),
397
+ ];
398
+
399
+ for (const dir of dirs) {
400
+ await fs.mkdir(dir, { recursive: true });
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Get existing config files for backup
406
+ */
407
+ private async getExistingConfigFiles(): Promise<string[]> {
408
+ const files: string[] = [];
409
+ const checkFiles = [
410
+ path.join(this.claudeDir, 'CLAUDE.md'),
411
+ path.join(this.claudeDir, 'conventions.json'),
412
+ ];
413
+
414
+ for (const file of checkFiles) {
415
+ if (existsSync(file)) {
416
+ files.push(file);
417
+ }
418
+ }
419
+
420
+ return files;
421
+ }
422
+
423
+ /**
424
+ * Generate hooks configuration files
425
+ */
426
+ private generateHooksConfig(): Record<string, string> {
427
+ return {
428
+ 'pre-commit': `#!/bin/bash
429
+ # Claude Code pre-commit hook
430
+ # Auto-generated by Wundr computer-setup
431
+
432
+ echo "šŸ” Running pre-commit checks..."
433
+
434
+ # Run linting
435
+ if command -v npm &> /dev/null; then
436
+ npm run lint --if-present || true
437
+ fi
438
+
439
+ # Run type checking
440
+ if command -v npm &> /dev/null; then
441
+ npm run typecheck --if-present || true
442
+ fi
443
+
444
+ echo "āœ… Pre-commit checks completed"
445
+ `,
446
+ 'post-checkout': `#!/bin/bash
447
+ # Claude Code post-checkout hook
448
+ # Auto-generated by Wundr computer-setup
449
+
450
+ echo "šŸ”„ Post-checkout: Installing dependencies..."
451
+
452
+ # Install dependencies if package.json changed
453
+ if command -v npm &> /dev/null; then
454
+ npm install --if-present || true
455
+ fi
456
+
457
+ echo "āœ… Post-checkout completed"
458
+ `,
459
+ };
460
+ }
461
+
462
+ /**
463
+ * Generate conventions configuration
464
+ */
465
+ private generateConventions(): any {
466
+ return {
467
+ fileNaming: {
468
+ components: 'PascalCase',
469
+ utilities: 'camelCase',
470
+ constants: 'UPPER_SNAKE_CASE',
471
+ types: 'PascalCase',
472
+ },
473
+ codeStyle: {
474
+ indentation: 2,
475
+ quotes: 'single',
476
+ semicolons: true,
477
+ trailingComma: 'es5',
478
+ },
479
+ imports: {
480
+ order: ['external', 'internal', 'parent', 'sibling', 'index'],
481
+ grouping: true,
482
+ },
483
+ testing: {
484
+ framework: 'jest',
485
+ coverage: {
486
+ statements: 80,
487
+ branches: 80,
488
+ functions: 80,
489
+ lines: 80,
490
+ },
491
+ },
492
+ git: {
493
+ commitMessage: 'conventional-commits',
494
+ branchNaming: 'feature/*, fix/*, chore/*',
495
+ },
496
+ };
497
+ }
498
+
499
+ /**
500
+ * Generate agent templates
501
+ */
502
+ private generateAgentTemplates(): Record<string, any> {
503
+ return {
504
+ 'backend-developer': {
505
+ name: 'Backend Developer',
506
+ role: 'backend-dev',
507
+ responsibilities: [
508
+ 'Design RESTful and GraphQL APIs',
509
+ 'Implement database models and queries',
510
+ 'Create authentication and authorization',
511
+ 'Write comprehensive API documentation',
512
+ ],
513
+ tools: ['node', 'typescript', 'postgresql', 'redis'],
514
+ patterns: [
515
+ 'Controller-Service-Repository',
516
+ 'DTO pattern',
517
+ 'Middleware pattern',
518
+ ],
519
+ },
520
+ 'frontend-developer': {
521
+ name: 'Frontend Developer',
522
+ role: 'frontend-dev',
523
+ responsibilities: [
524
+ 'Build responsive user interfaces',
525
+ 'Implement state management',
526
+ 'Create reusable components',
527
+ 'Optimize performance',
528
+ ],
529
+ tools: ['react', 'typescript', 'tailwind', 'vite'],
530
+ patterns: ['Component composition', 'Custom hooks', 'Context API'],
531
+ },
532
+ 'fullstack-developer': {
533
+ name: 'Fullstack Developer',
534
+ role: 'fullstack-dev',
535
+ responsibilities: [
536
+ 'Develop end-to-end features',
537
+ 'Integrate frontend and backend',
538
+ 'Manage database schemas',
539
+ 'Deploy applications',
540
+ ],
541
+ tools: ['node', 'react', 'typescript', 'docker'],
542
+ patterns: ['Full-stack architecture', 'API integration', 'CI/CD'],
543
+ },
544
+ };
545
+ }
546
+
547
+ /**
548
+ * Generate git-worktree workflows
549
+ */
550
+ private generateGitWorktreeWorkflows(): Record<string, any> {
551
+ return {
552
+ 'feature-development': {
553
+ name: 'Feature Development Workflow',
554
+ description: 'Workflow for developing new features in isolation',
555
+ steps: [
556
+ {
557
+ name: 'Create worktree',
558
+ command: 'git worktree add ../feature-name feature/name',
559
+ },
560
+ {
561
+ name: 'Setup environment',
562
+ command: 'cd ../feature-name && npm install',
563
+ },
564
+ {
565
+ name: 'Run tests',
566
+ command: 'npm test',
567
+ },
568
+ {
569
+ name: 'Commit changes',
570
+ command: 'git add . && git commit -m "feat: description"',
571
+ },
572
+ ],
573
+ },
574
+ 'bug-fix': {
575
+ name: 'Bug Fix Workflow',
576
+ description: 'Workflow for fixing bugs without affecting main development',
577
+ steps: [
578
+ {
579
+ name: 'Create worktree',
580
+ command: 'git worktree add ../fix-bug fix/bug-name',
581
+ },
582
+ {
583
+ name: 'Reproduce bug',
584
+ command: 'npm test -- bug.test.ts',
585
+ },
586
+ {
587
+ name: 'Fix and verify',
588
+ command: 'npm test',
589
+ },
590
+ {
591
+ name: 'Commit fix',
592
+ command: 'git add . && git commit -m "fix: description"',
593
+ },
594
+ ],
595
+ },
596
+ };
597
+ }
598
+
599
+ /**
600
+ * Generate validation scripts
601
+ */
602
+ private generateValidationScripts(): Record<string, string> {
603
+ return {
604
+ 'validate-setup.sh': `#!/bin/bash
605
+ # Validate Claude Code setup
606
+ # Auto-generated by Wundr computer-setup
607
+
608
+ echo "šŸ” Validating Claude Code setup..."
609
+
610
+ # Check for required files
611
+ FILES=(
612
+ "$HOME/.claude/CLAUDE.md"
613
+ "$HOME/.claude/conventions.json"
614
+ )
615
+
616
+ MISSING=0
617
+ for file in "\${FILES[@]}"; do
618
+ if [ ! -f "$file" ]; then
619
+ echo "āŒ Missing: $file"
620
+ MISSING=$((MISSING + 1))
621
+ else
622
+ echo "āœ… Found: $file"
623
+ fi
624
+ done
625
+
626
+ # Check for required directories
627
+ DIRS=(
628
+ "$HOME/.claude/hooks"
629
+ "$HOME/.claude/agents"
630
+ "$HOME/.claude/workflows"
631
+ )
632
+
633
+ for dir in "\${DIRS[@]}"; do
634
+ if [ ! -d "$dir" ]; then
635
+ echo "āŒ Missing directory: $dir"
636
+ MISSING=$((MISSING + 1))
637
+ else
638
+ echo "āœ… Found directory: $dir"
639
+ fi
640
+ done
641
+
642
+ if [ $MISSING -eq 0 ]; then
643
+ echo "āœ… All validations passed!"
644
+ exit 0
645
+ else
646
+ echo "āŒ $MISSING validation(s) failed"
647
+ exit 1
648
+ fi
649
+ `,
650
+ 'check-config.sh': `#!/bin/bash
651
+ # Check Claude Code configuration
652
+ # Auto-generated by Wundr computer-setup
653
+
654
+ echo "šŸ”§ Checking Claude Code configuration..."
655
+
656
+ # Check Claude CLI
657
+ if command -v claude &> /dev/null; then
658
+ echo "āœ… Claude CLI: $(claude --version)"
659
+ else
660
+ echo "āš ļø Claude CLI not found"
661
+ fi
662
+
663
+ # Check Node.js
664
+ if command -v node &> /dev/null; then
665
+ echo "āœ… Node.js: $(node --version)"
666
+ else
667
+ echo "āŒ Node.js not found"
668
+ fi
669
+
670
+ # Check Git
671
+ if command -v git &> /dev/null; then
672
+ echo "āœ… Git: $(git --version)"
673
+ else
674
+ echo "āŒ Git not found"
675
+ fi
676
+
677
+ echo "āœ… Configuration check complete"
678
+ `,
679
+ };
680
+ }
681
+
682
+ /**
683
+ * Display installation summary
684
+ */
685
+ private displayInstallSummary(result: InstallResult, dryRun: boolean): void {
686
+ console.log(chalk.cyan('\nšŸ“Š Installation Summary\n'));
687
+
688
+ if (dryRun) {
689
+ console.log(chalk.yellow('šŸ” DRY RUN MODE - No files were modified\n'));
690
+ }
691
+
692
+ if (result.backupId) {
693
+ console.log(chalk.gray(`Backup ID: ${result.backupId}\n`));
694
+ }
695
+
696
+ if (result.installed.length > 0) {
697
+ console.log(chalk.green(`āœ… Installed (${result.installed.length}):`));
698
+ result.installed.forEach(file => {
699
+ console.log(chalk.white(` • ${file}`));
700
+ });
701
+ console.log();
702
+ }
703
+
704
+ if (result.skipped.length > 0) {
705
+ console.log(chalk.yellow(`ā­ļø Skipped (${result.skipped.length}):`));
706
+ result.skipped.forEach(file => {
707
+ console.log(chalk.gray(` • ${file}`));
708
+ });
709
+ console.log();
710
+ }
711
+
712
+ if (result.errors.length > 0) {
713
+ console.log(chalk.red(`āŒ Errors (${result.errors.length}):`));
714
+ result.errors.forEach(error => {
715
+ console.log(chalk.red(` • ${error.file}: ${error.error}`));
716
+ });
717
+ console.log();
718
+ }
719
+
720
+ if (result.success) {
721
+ console.log(chalk.green('āœ… Installation completed successfully!\n'));
722
+ console.log(chalk.cyan('Next steps:'));
723
+ console.log(chalk.white(' 1. Review installed configurations'));
724
+ console.log(chalk.white(' 2. Run validation: ~/.claude/scripts/validate-setup.sh'));
725
+ console.log(chalk.white(' 3. Customize agent templates as needed'));
726
+ } else {
727
+ console.log(chalk.red('āŒ Installation completed with errors\n'));
728
+ if (result.backupId) {
729
+ console.log(chalk.cyan('To rollback:'));
730
+ console.log(chalk.white(` wundr computer-setup rollback --backup ${result.backupId}`));
731
+ }
732
+ }
733
+ }
734
+ }