mycontext-cli 2.0.2 → 2.0.4

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 (69) hide show
  1. package/README.md +426 -103
  2. package/dist/README.md +426 -103
  3. package/dist/agents/implementations/ClaudeAgentWorkflow.d.ts.map +1 -1
  4. package/dist/agents/implementations/ClaudeAgentWorkflow.js +75 -4
  5. package/dist/agents/implementations/ClaudeAgentWorkflow.js.map +1 -1
  6. package/dist/agents/implementations/CodeGenSubAgent.d.ts.map +1 -1
  7. package/dist/agents/implementations/CodeGenSubAgent.js +69 -0
  8. package/dist/agents/implementations/CodeGenSubAgent.js.map +1 -1
  9. package/dist/agents/implementations/PromptConstructorAgent.d.ts.map +1 -1
  10. package/dist/agents/implementations/PromptConstructorAgent.js +23 -0
  11. package/dist/agents/implementations/PromptConstructorAgent.js.map +1 -1
  12. package/dist/agents/interfaces/SubAgent.d.ts +2 -0
  13. package/dist/agents/interfaces/SubAgent.d.ts.map +1 -1
  14. package/dist/cli.js +13 -40
  15. package/dist/cli.js.map +1 -1
  16. package/dist/commands/generate-components.d.ts +0 -5
  17. package/dist/commands/generate-components.d.ts.map +1 -1
  18. package/dist/commands/generate-components.js +0 -101
  19. package/dist/commands/generate-components.js.map +1 -1
  20. package/dist/commands/health-check.d.ts +28 -0
  21. package/dist/commands/health-check.d.ts.map +1 -0
  22. package/dist/commands/health-check.js +271 -0
  23. package/dist/commands/health-check.js.map +1 -0
  24. package/dist/commands/init.d.ts.map +1 -1
  25. package/dist/commands/init.js +2 -6
  26. package/dist/commands/init.js.map +1 -1
  27. package/dist/config/build-strategies.json +173 -22
  28. package/dist/package.json +2 -2
  29. package/dist/utils/NextJSProjectGenerator.d.ts +70 -0
  30. package/dist/utils/NextJSProjectGenerator.d.ts.map +1 -0
  31. package/dist/utils/NextJSProjectGenerator.js +811 -0
  32. package/dist/utils/NextJSProjectGenerator.js.map +1 -0
  33. package/dist/utils/NextJSProjectValidator.d.ts +103 -0
  34. package/dist/utils/NextJSProjectValidator.d.ts.map +1 -0
  35. package/dist/utils/NextJSProjectValidator.js +759 -0
  36. package/dist/utils/NextJSProjectValidator.js.map +1 -0
  37. package/dist/utils/PreCommandValidator.d.ts +77 -0
  38. package/dist/utils/PreCommandValidator.d.ts.map +1 -0
  39. package/dist/utils/PreCommandValidator.js +251 -0
  40. package/dist/utils/PreCommandValidator.js.map +1 -0
  41. package/dist/utils/ProjectHealthMonitor.d.ts +131 -0
  42. package/dist/utils/ProjectHealthMonitor.d.ts.map +1 -0
  43. package/dist/utils/ProjectHealthMonitor.js +454 -0
  44. package/dist/utils/ProjectHealthMonitor.js.map +1 -0
  45. package/dist/utils/ProjectInitializationSafeguards.d.ts +81 -0
  46. package/dist/utils/ProjectInitializationSafeguards.d.ts.map +1 -0
  47. package/dist/utils/ProjectInitializationSafeguards.js +620 -0
  48. package/dist/utils/ProjectInitializationSafeguards.js.map +1 -0
  49. package/dist/utils/ProjectStructureRepair.d.ts +110 -0
  50. package/dist/utils/ProjectStructureRepair.d.ts.map +1 -0
  51. package/dist/utils/ProjectStructureRepair.js +785 -0
  52. package/dist/utils/ProjectStructureRepair.js.map +1 -0
  53. package/dist/utils/ProjectStructureValidator.d.ts +128 -0
  54. package/dist/utils/ProjectStructureValidator.d.ts.map +1 -0
  55. package/dist/utils/ProjectStructureValidator.js +662 -0
  56. package/dist/utils/ProjectStructureValidator.js.map +1 -0
  57. package/dist/utils/agentDefinitions.d.ts +5 -0
  58. package/dist/utils/agentDefinitions.d.ts.map +1 -1
  59. package/dist/utils/agentDefinitions.js +99 -1
  60. package/dist/utils/agentDefinitions.js.map +1 -1
  61. package/dist/utils/mcpTools.d.ts +189 -0
  62. package/dist/utils/mcpTools.d.ts.map +1 -1
  63. package/dist/utils/mcpTools.js +462 -1
  64. package/dist/utils/mcpTools.js.map +1 -1
  65. package/package.json +2 -2
  66. package/dist/commands/core.d.ts +0 -24
  67. package/dist/commands/core.d.ts.map +0 -1
  68. package/dist/commands/core.js +0 -410
  69. package/dist/commands/core.js.map +0 -1
@@ -0,0 +1,785 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ProjectStructureRepair = void 0;
40
+ const fs = __importStar(require("fs-extra"));
41
+ const path = __importStar(require("path"));
42
+ const chalk_1 = __importDefault(require("chalk"));
43
+ const ProjectStructureValidator_1 = require("./ProjectStructureValidator");
44
+ class ProjectStructureRepair {
45
+ constructor(projectRoot = process.cwd()) {
46
+ this.backupEnabled = true;
47
+ this.dryRun = false;
48
+ this.projectRoot = projectRoot;
49
+ this.validator = new ProjectStructureValidator_1.ProjectStructureValidator(projectRoot);
50
+ }
51
+ /**
52
+ * Comprehensive project structure repair
53
+ */
54
+ async repairProject(options = {}) {
55
+ this.dryRun = options.dryRun || false;
56
+ this.backupEnabled = options.backup !== false;
57
+ const result = {
58
+ success: false,
59
+ repaired: 0,
60
+ failed: 0,
61
+ skipped: 0,
62
+ errors: [],
63
+ warnings: [],
64
+ actions: []
65
+ };
66
+ console.log(chalk_1.default.blue("🔧 Starting comprehensive project structure repair..."));
67
+ console.log(chalk_1.default.blue("==================================================\n"));
68
+ if (this.dryRun) {
69
+ console.log(chalk_1.default.yellow("🧪 DRY RUN MODE - No changes will be made\n"));
70
+ }
71
+ try {
72
+ // Step 1: Create backup if enabled
73
+ if (this.backupEnabled && !this.dryRun) {
74
+ await this.createBackup(result);
75
+ }
76
+ // Step 2: Analyze current structure
77
+ const report = await this.validator.validate();
78
+ console.log(chalk_1.default.blue(`📊 Found ${report.issues.length} issues to address\n`));
79
+ // Step 3: Repair critical issues first
80
+ await this.repairCriticalIssues(report, result);
81
+ // Step 4: Repair high priority issues
82
+ await this.repairHighPriorityIssues(report, result);
83
+ // Step 5: Repair medium priority issues
84
+ await this.repairMediumPriorityIssues(report, result);
85
+ // Step 6: Repair low priority issues
86
+ await this.repairLowPriorityIssues(report, result);
87
+ // Step 7: Optimize project structure
88
+ await this.optimizeProjectStructure(result);
89
+ // Step 8: Final validation
90
+ await this.performFinalValidation(result);
91
+ result.success = result.failed === 0;
92
+ console.log(chalk_1.default.blue("\n📋 Repair Summary:"));
93
+ console.log(` ✅ Repaired: ${chalk_1.default.green(result.repaired)}`);
94
+ console.log(` ❌ Failed: ${chalk_1.default.red(result.failed)}`);
95
+ console.log(` ⏭️ Skipped: ${chalk_1.default.yellow(result.skipped)}`);
96
+ if (result.errors.length > 0) {
97
+ console.log(chalk_1.default.red("\n❌ Errors:"));
98
+ result.errors.forEach(error => console.log(chalk_1.default.red(` ${error}`)));
99
+ }
100
+ if (result.warnings.length > 0) {
101
+ console.log(chalk_1.default.yellow("\n⚠️ Warnings:"));
102
+ result.warnings.forEach(warning => console.log(chalk_1.default.yellow(` ${warning}`)));
103
+ }
104
+ return result;
105
+ }
106
+ catch (error) {
107
+ result.errors.push(`Repair failed: ${error}`);
108
+ console.log(chalk_1.default.red(`❌ Repair failed: ${error}`));
109
+ return result;
110
+ }
111
+ }
112
+ /**
113
+ * Create backup of current project
114
+ */
115
+ async createBackup(result) {
116
+ try {
117
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
118
+ const backupPath = path.join(this.projectRoot, '..', `.backup-${path.basename(this.projectRoot)}-${timestamp}`);
119
+ console.log(chalk_1.default.blue("💾 Creating backup..."));
120
+ await fs.copy(this.projectRoot, backupPath, {
121
+ filter: (src) => {
122
+ // Skip node_modules and other large directories
123
+ const relativePath = path.relative(this.projectRoot, src);
124
+ return !relativePath.startsWith('node_modules') &&
125
+ !relativePath.startsWith('.git') &&
126
+ !relativePath.startsWith('.next') &&
127
+ !relativePath.startsWith('dist');
128
+ }
129
+ });
130
+ result.actions.push({
131
+ type: "create",
132
+ description: `Created backup at ${backupPath}`,
133
+ success: true
134
+ });
135
+ console.log(chalk_1.default.green(`✅ Backup created: ${backupPath}`));
136
+ }
137
+ catch (error) {
138
+ result.warnings.push(`Failed to create backup: ${error}`);
139
+ console.log(chalk_1.default.yellow(`⚠️ Could not create backup: ${error}`));
140
+ }
141
+ }
142
+ /**
143
+ * Repair critical issues
144
+ */
145
+ async repairCriticalIssues(report, result) {
146
+ const criticalIssues = report.issues.filter(issue => issue.severity === "critical");
147
+ if (criticalIssues.length === 0)
148
+ return;
149
+ console.log(chalk_1.default.red(`🚨 Repairing ${criticalIssues.length} critical issues...`));
150
+ for (const issue of criticalIssues) {
151
+ await this.repairIssue(issue, result);
152
+ }
153
+ }
154
+ /**
155
+ * Repair high priority issues
156
+ */
157
+ async repairHighPriorityIssues(report, result) {
158
+ const highIssues = report.issues.filter(issue => issue.severity === "high");
159
+ if (highIssues.length === 0)
160
+ return;
161
+ console.log(chalk_1.default.yellow(`⚠️ Repairing ${highIssues.length} high priority issues...`));
162
+ for (const issue of highIssues) {
163
+ await this.repairIssue(issue, result);
164
+ }
165
+ }
166
+ /**
167
+ * Repair medium priority issues
168
+ */
169
+ async repairMediumPriorityIssues(report, result) {
170
+ const mediumIssues = report.issues.filter(issue => issue.severity === "medium");
171
+ if (mediumIssues.length === 0)
172
+ return;
173
+ console.log(chalk_1.default.blue(`ℹ️ Repairing ${mediumIssues.length} medium priority issues...`));
174
+ for (const issue of mediumIssues) {
175
+ await this.repairIssue(issue, result);
176
+ }
177
+ }
178
+ /**
179
+ * Repair low priority issues
180
+ */
181
+ async repairLowPriorityIssues(report, result) {
182
+ const lowIssues = report.issues.filter(issue => issue.severity === "low");
183
+ if (lowIssues.length === 0)
184
+ return;
185
+ console.log(chalk_1.default.gray(`ℹ️ Repairing ${lowIssues.length} low priority issues...`));
186
+ for (const issue of lowIssues) {
187
+ await this.repairIssue(issue, result);
188
+ }
189
+ }
190
+ /**
191
+ * Repair a specific issue
192
+ */
193
+ async repairIssue(issue, result) {
194
+ try {
195
+ let action = null;
196
+ if (issue.message.includes("Multiple package.json")) {
197
+ action = await this.repairMultiplePackageJson(issue);
198
+ }
199
+ else if (issue.message.includes("Nested node_modules")) {
200
+ action = await this.repairNestedNodeModules(issue);
201
+ }
202
+ else if (issue.message.includes("Multiple lock files")) {
203
+ action = await this.repairMultipleLockFiles(issue);
204
+ }
205
+ else if (issue.message.includes("Multiple build configurations")) {
206
+ action = await this.repairMultipleBuildConfigs(issue);
207
+ }
208
+ else if (issue.message.includes("No package.json")) {
209
+ action = await this.repairMissingPackageJson(issue);
210
+ }
211
+ else if (issue.message.includes("No lock file")) {
212
+ action = await this.repairMissingLockFile(issue);
213
+ }
214
+ else if (issue.message.includes("No TypeScript configuration")) {
215
+ action = await this.repairMissingTsConfig(issue);
216
+ }
217
+ else if (issue.message.includes("No build configuration")) {
218
+ action = await this.repairMissingBuildConfig(issue);
219
+ }
220
+ else if (issue.message.includes("Package manager")) {
221
+ action = await this.repairPackageManager(issue);
222
+ }
223
+ else {
224
+ result.skipped++;
225
+ return;
226
+ }
227
+ if (action) {
228
+ result.actions.push(action);
229
+ if (action.success) {
230
+ result.repaired++;
231
+ console.log(chalk_1.default.green(` ✅ ${action.description}`));
232
+ }
233
+ else {
234
+ result.failed++;
235
+ result.errors.push(action.error || "Unknown error");
236
+ console.log(chalk_1.default.red(` ❌ ${action.description}: ${action.error}`));
237
+ }
238
+ }
239
+ }
240
+ catch (error) {
241
+ result.failed++;
242
+ result.errors.push(`Failed to repair issue: ${error}`);
243
+ console.log(chalk_1.default.red(` ❌ Failed to repair: ${issue.message}`));
244
+ }
245
+ }
246
+ /**
247
+ * Repair multiple package.json files
248
+ */
249
+ async repairMultiplePackageJson(issue) {
250
+ const action = {
251
+ type: "delete",
252
+ description: "Remove nested package.json files",
253
+ success: false
254
+ };
255
+ try {
256
+ if (this.dryRun) {
257
+ action.success = true;
258
+ action.description += " (dry run)";
259
+ return action;
260
+ }
261
+ const packageJsonFiles = await this.findFiles("package.json");
262
+ const rootPackageJson = path.join(this.projectRoot, "package.json");
263
+ let removedCount = 0;
264
+ for (const file of packageJsonFiles) {
265
+ if (file !== rootPackageJson) {
266
+ await fs.remove(file);
267
+ removedCount++;
268
+ }
269
+ }
270
+ action.success = true;
271
+ action.description = `Removed ${removedCount} nested package.json files`;
272
+ return action;
273
+ }
274
+ catch (error) {
275
+ action.error = String(error);
276
+ return action;
277
+ }
278
+ }
279
+ /**
280
+ * Repair nested node_modules directories
281
+ */
282
+ async repairNestedNodeModules(issue) {
283
+ const action = {
284
+ type: "delete",
285
+ description: "Remove nested node_modules directories",
286
+ success: false
287
+ };
288
+ try {
289
+ if (this.dryRun) {
290
+ action.success = true;
291
+ action.description += " (dry run)";
292
+ return action;
293
+ }
294
+ const nodeModulesDirs = await this.findDirectories("node_modules");
295
+ const rootNodeModules = path.join(this.projectRoot, "node_modules");
296
+ let removedCount = 0;
297
+ for (const dir of nodeModulesDirs) {
298
+ if (dir !== rootNodeModules) {
299
+ await fs.remove(dir);
300
+ removedCount++;
301
+ }
302
+ }
303
+ action.success = true;
304
+ action.description = `Removed ${removedCount} nested node_modules directories`;
305
+ return action;
306
+ }
307
+ catch (error) {
308
+ action.error = String(error);
309
+ return action;
310
+ }
311
+ }
312
+ /**
313
+ * Repair multiple lock files
314
+ */
315
+ async repairMultipleLockFiles(issue) {
316
+ const action = {
317
+ type: "delete",
318
+ description: "Remove conflicting lock files",
319
+ success: false
320
+ };
321
+ try {
322
+ if (this.dryRun) {
323
+ action.success = true;
324
+ action.description += " (dry run)";
325
+ return action;
326
+ }
327
+ const lockFiles = await this.findFiles("*-lock.yaml", "package-lock.json", "yarn.lock", "bun.lockb");
328
+ const preferredLockFile = path.join(this.projectRoot, "pnpm-lock.yaml");
329
+ let removedCount = 0;
330
+ for (const file of lockFiles) {
331
+ if (file !== preferredLockFile) {
332
+ await fs.remove(file);
333
+ removedCount++;
334
+ }
335
+ }
336
+ action.success = true;
337
+ action.description = `Removed ${removedCount} conflicting lock files`;
338
+ return action;
339
+ }
340
+ catch (error) {
341
+ action.error = String(error);
342
+ return action;
343
+ }
344
+ }
345
+ /**
346
+ * Repair multiple build configurations
347
+ */
348
+ async repairMultipleBuildConfigs(issue) {
349
+ const action = {
350
+ type: "delete",
351
+ description: "Remove conflicting build configurations",
352
+ success: false
353
+ };
354
+ try {
355
+ if (this.dryRun) {
356
+ action.success = true;
357
+ action.description += " (dry run)";
358
+ return action;
359
+ }
360
+ const buildConfigs = await this.findFiles("next.config.*", "webpack.config.*", "vite.config.*", "rollup.config.*", "esbuild.config.*");
361
+ const preferredConfig = path.join(this.projectRoot, "next.config.ts");
362
+ let removedCount = 0;
363
+ for (const file of buildConfigs) {
364
+ if (file !== preferredConfig) {
365
+ await fs.remove(file);
366
+ removedCount++;
367
+ }
368
+ }
369
+ action.success = true;
370
+ action.description = `Removed ${removedCount} conflicting build configurations`;
371
+ return action;
372
+ }
373
+ catch (error) {
374
+ action.error = String(error);
375
+ return action;
376
+ }
377
+ }
378
+ /**
379
+ * Repair missing package.json
380
+ */
381
+ async repairMissingPackageJson(issue) {
382
+ const action = {
383
+ type: "create",
384
+ description: "Create default package.json",
385
+ success: false
386
+ };
387
+ try {
388
+ if (this.dryRun) {
389
+ action.success = true;
390
+ action.description += " (dry run)";
391
+ return action;
392
+ }
393
+ const packageJsonPath = path.join(this.projectRoot, "package.json");
394
+ const packageJson = this.generateDefaultPackageJson();
395
+ await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
396
+ action.success = true;
397
+ action.description = "Created default package.json";
398
+ return action;
399
+ }
400
+ catch (error) {
401
+ action.error = String(error);
402
+ return action;
403
+ }
404
+ }
405
+ /**
406
+ * Repair missing lock file
407
+ */
408
+ async repairMissingLockFile(issue) {
409
+ const action = {
410
+ type: "create",
411
+ description: "Generate pnpm-lock.yaml",
412
+ success: false
413
+ };
414
+ try {
415
+ if (this.dryRun) {
416
+ action.success = true;
417
+ action.description += " (dry run)";
418
+ return action;
419
+ }
420
+ const { execSync } = require("child_process");
421
+ execSync("pnpm install", { cwd: this.projectRoot, stdio: "pipe" });
422
+ action.success = true;
423
+ action.description = "Generated pnpm-lock.yaml";
424
+ return action;
425
+ }
426
+ catch (error) {
427
+ action.error = String(error);
428
+ return action;
429
+ }
430
+ }
431
+ /**
432
+ * Repair missing TypeScript configuration
433
+ */
434
+ async repairMissingTsConfig(issue) {
435
+ const action = {
436
+ type: "create",
437
+ description: "Create default tsconfig.json",
438
+ success: false
439
+ };
440
+ try {
441
+ if (this.dryRun) {
442
+ action.success = true;
443
+ action.description += " (dry run)";
444
+ return action;
445
+ }
446
+ const tsConfigPath = path.join(this.projectRoot, "tsconfig.json");
447
+ const tsConfig = this.generateDefaultTsConfig();
448
+ await fs.writeJson(tsConfigPath, tsConfig, { spaces: 2 });
449
+ action.success = true;
450
+ action.description = "Created default tsconfig.json";
451
+ return action;
452
+ }
453
+ catch (error) {
454
+ action.error = String(error);
455
+ return action;
456
+ }
457
+ }
458
+ /**
459
+ * Repair missing build configuration
460
+ */
461
+ async repairMissingBuildConfig(issue) {
462
+ const action = {
463
+ type: "create",
464
+ description: "Create default next.config.ts",
465
+ success: false
466
+ };
467
+ try {
468
+ if (this.dryRun) {
469
+ action.success = true;
470
+ action.description += " (dry run)";
471
+ return action;
472
+ }
473
+ const nextConfigPath = path.join(this.projectRoot, "next.config.ts");
474
+ const nextConfig = this.generateDefaultNextConfig();
475
+ await fs.writeFile(nextConfigPath, nextConfig);
476
+ action.success = true;
477
+ action.description = "Created default next.config.ts";
478
+ return action;
479
+ }
480
+ catch (error) {
481
+ action.error = String(error);
482
+ return action;
483
+ }
484
+ }
485
+ /**
486
+ * Repair package manager configuration
487
+ */
488
+ async repairPackageManager(issue) {
489
+ const action = {
490
+ type: "update",
491
+ description: "Update package manager configuration",
492
+ success: false
493
+ };
494
+ try {
495
+ if (this.dryRun) {
496
+ action.success = true;
497
+ action.description += " (dry run)";
498
+ return action;
499
+ }
500
+ const packageJsonPath = path.join(this.projectRoot, "package.json");
501
+ if (await fs.pathExists(packageJsonPath)) {
502
+ const packageJson = await fs.readJson(packageJsonPath);
503
+ packageJson.packageManager = "pnpm@10.11.0";
504
+ await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
505
+ }
506
+ action.success = true;
507
+ action.description = "Updated package manager to pnpm";
508
+ return action;
509
+ }
510
+ catch (error) {
511
+ action.error = String(error);
512
+ return action;
513
+ }
514
+ }
515
+ /**
516
+ * Optimize project structure
517
+ */
518
+ async optimizeProjectStructure(result) {
519
+ console.log(chalk_1.default.blue("🔧 Optimizing project structure..."));
520
+ try {
521
+ // Ensure essential directories exist
522
+ const essentialDirs = ["src", "components", "lib", "hooks", "types", "public"];
523
+ for (const dir of essentialDirs) {
524
+ const dirPath = path.join(this.projectRoot, dir);
525
+ if (!(await fs.pathExists(dirPath))) {
526
+ if (!this.dryRun) {
527
+ await fs.ensureDir(dirPath);
528
+ }
529
+ result.actions.push({
530
+ type: "create",
531
+ description: `Created directory: ${dir}`,
532
+ success: true
533
+ });
534
+ result.repaired++;
535
+ }
536
+ }
537
+ // Ensure .gitignore exists
538
+ const gitignorePath = path.join(this.projectRoot, ".gitignore");
539
+ if (!(await fs.pathExists(gitignorePath))) {
540
+ if (!this.dryRun) {
541
+ const gitignoreContent = this.generateGitignoreContent();
542
+ await fs.writeFile(gitignorePath, gitignoreContent);
543
+ }
544
+ result.actions.push({
545
+ type: "create",
546
+ description: "Created .gitignore",
547
+ success: true
548
+ });
549
+ result.repaired++;
550
+ }
551
+ console.log(chalk_1.default.green("✅ Project structure optimized"));
552
+ }
553
+ catch (error) {
554
+ result.errors.push(`Failed to optimize project structure: ${error}`);
555
+ }
556
+ }
557
+ /**
558
+ * Perform final validation
559
+ */
560
+ async performFinalValidation(result) {
561
+ console.log(chalk_1.default.blue("🔍 Performing final validation..."));
562
+ try {
563
+ const report = await this.validator.validate();
564
+ if (report.isValid) {
565
+ console.log(chalk_1.default.green("✅ Project structure is now healthy"));
566
+ }
567
+ else {
568
+ const remainingIssues = report.issues.length;
569
+ result.warnings.push(`${remainingIssues} issues remain after repair`);
570
+ console.log(chalk_1.default.yellow(`⚠️ ${remainingIssues} issues remain`));
571
+ }
572
+ }
573
+ catch (error) {
574
+ result.errors.push(`Final validation failed: ${error}`);
575
+ }
576
+ }
577
+ /**
578
+ * Helper methods
579
+ */
580
+ async findFiles(...patterns) {
581
+ const files = [];
582
+ for (const pattern of patterns) {
583
+ const glob = require("glob");
584
+ const matches = await glob(pattern, {
585
+ cwd: this.projectRoot,
586
+ absolute: true,
587
+ ignore: ["**/node_modules/**"]
588
+ });
589
+ files.push(...matches);
590
+ }
591
+ return [...new Set(files)];
592
+ }
593
+ async findDirectories(dirName) {
594
+ const glob = require("glob");
595
+ const matches = await glob(`**/${dirName}`, {
596
+ cwd: this.projectRoot,
597
+ absolute: true,
598
+ ignore: ["**/node_modules/**"]
599
+ });
600
+ return matches;
601
+ }
602
+ generateDefaultPackageJson() {
603
+ return {
604
+ name: path.basename(this.projectRoot).toLowerCase().replace(/[^a-z0-9-]/g, '-'),
605
+ version: "0.1.0",
606
+ private: true,
607
+ scripts: {
608
+ dev: "next dev",
609
+ build: "next build",
610
+ start: "next start",
611
+ lint: "next lint",
612
+ "type-check": "tsc --noEmit"
613
+ },
614
+ dependencies: {
615
+ react: "^18.0.0",
616
+ "react-dom": "^18.0.0",
617
+ next: "^14.0.0"
618
+ },
619
+ devDependencies: {
620
+ typescript: "^5.0.0",
621
+ "@types/node": "^20.0.0",
622
+ "@types/react": "^18.0.0",
623
+ "@types/react-dom": "^18.0.0",
624
+ "eslint": "^8.0.0",
625
+ "eslint-config-next": "^14.0.0"
626
+ },
627
+ packageManager: "pnpm@10.11.0"
628
+ };
629
+ }
630
+ generateDefaultTsConfig() {
631
+ return {
632
+ compilerOptions: {
633
+ target: "es5",
634
+ lib: ["dom", "dom.iterable", "es6"],
635
+ allowJs: true,
636
+ skipLibCheck: true,
637
+ strict: true,
638
+ noEmit: true,
639
+ esModuleInterop: true,
640
+ module: "esnext",
641
+ moduleResolution: "bundler",
642
+ resolveJsonModule: true,
643
+ isolatedModules: true,
644
+ jsx: "preserve",
645
+ incremental: true,
646
+ plugins: [
647
+ {
648
+ name: "next"
649
+ }
650
+ ],
651
+ paths: {
652
+ "@/*": ["./*"]
653
+ }
654
+ },
655
+ include: ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
656
+ exclude: ["node_modules"]
657
+ };
658
+ }
659
+ generateDefaultNextConfig() {
660
+ return `import type { NextConfig } from "next";
661
+
662
+ const nextConfig: NextConfig = {
663
+ experimental: {
664
+ turbo: true,
665
+ },
666
+ typescript: {
667
+ ignoreBuildErrors: false,
668
+ },
669
+ eslint: {
670
+ ignoreDuringBuilds: false,
671
+ },
672
+ };
673
+
674
+ export default nextConfig;
675
+ `;
676
+ }
677
+ generateGitignoreContent() {
678
+ return `# Dependencies
679
+ node_modules/
680
+ .pnp
681
+ .pnp.js
682
+
683
+ # Production builds
684
+ .next/
685
+ out/
686
+ build/
687
+ dist/
688
+
689
+ # Environment variables
690
+ .env
691
+ .env.local
692
+ .env.development.local
693
+ .env.test.local
694
+ .env.production.local
695
+
696
+ # Logs
697
+ npm-debug.log*
698
+ yarn-debug.log*
699
+ yarn-error.log*
700
+ pnpm-debug.log*
701
+ lerna-debug.log*
702
+
703
+ # Runtime data
704
+ pids
705
+ *.pid
706
+ *.seed
707
+ *.pid.lock
708
+
709
+ # Coverage directory used by tools like istanbul
710
+ coverage/
711
+ *.lcov
712
+
713
+ # nyc test coverage
714
+ .nyc_output
715
+
716
+ # Dependency directories
717
+ node_modules/
718
+ jspm_packages/
719
+
720
+ # TypeScript cache
721
+ *.tsbuildinfo
722
+
723
+ # Optional npm cache directory
724
+ .npm
725
+
726
+ # Optional eslint cache
727
+ .eslintcache
728
+
729
+ # Optional REPL history
730
+ .node_repl_history
731
+
732
+ # Output of 'npm pack'
733
+ *.tgz
734
+
735
+ # Yarn Integrity file
736
+ .yarn-integrity
737
+
738
+ # parcel-bundler cache (https://parceljs.org/)
739
+ .cache
740
+ .parcel-cache
741
+
742
+ # Next.js build output
743
+ .next
744
+
745
+ # Nuxt.js build / generate output
746
+ .nuxt
747
+ dist
748
+
749
+ # Gatsby files
750
+ .cache/
751
+ public
752
+
753
+ # Storybook build outputs
754
+ .out
755
+ .storybook-out
756
+
757
+ # Temporary folders
758
+ tmp/
759
+ temp/
760
+
761
+ # Editor directories and files
762
+ .vscode/
763
+ .idea/
764
+ *.swp
765
+ *.swo
766
+ *~
767
+
768
+ # OS generated files
769
+ .DS_Store
770
+ .DS_Store?
771
+ ._*
772
+ .Spotlight-V100
773
+ .Trashes
774
+ ehthumbs.db
775
+ Thumbs.db
776
+
777
+ # MyContext specific
778
+ .mycontext/.env
779
+ .mycontext/logs/
780
+ .mycontext/cache/
781
+ `;
782
+ }
783
+ }
784
+ exports.ProjectStructureRepair = ProjectStructureRepair;
785
+ //# sourceMappingURL=ProjectStructureRepair.js.map