proagents 1.0.5 → 1.0.6

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.
@@ -287,6 +287,21 @@ async function smartUpdate(sourceDir, targetDir) {
287
287
  }
288
288
  }
289
289
 
290
+ // Before updating, migrate any modified template files
291
+ const migrationResult = migrateModifiedTemplates(sourceDir, targetDir);
292
+ if (migrationResult.migrated.length > 0) {
293
+ console.log(chalk.green(`✓ Migrated ${migrationResult.migrated.length} modified template(s) to user files`));
294
+ for (const file of migrationResult.migrated) {
295
+ console.log(chalk.gray(` • ${file}`));
296
+ }
297
+ }
298
+ if (migrationResult.backedUp.length > 0) {
299
+ console.log(chalk.yellow(`⚠️ Backed up ${migrationResult.backedUp.length} modified template(s)`));
300
+ for (const file of migrationResult.backedUp) {
301
+ console.log(chalk.gray(` • ${file}`));
302
+ }
303
+ }
304
+
290
305
  // Update framework folders
291
306
  let updatedCount = 0;
292
307
  for (const folder of FRAMEWORK_FOLDERS) {
@@ -304,6 +319,9 @@ async function smartUpdate(sourceDir, targetDir) {
304
319
  }
305
320
  console.log(chalk.green(`✓ Updated ${updatedCount} framework folders`));
306
321
 
322
+ // Restore user files that were migrated (they were saved before folder deletion)
323
+ restoreUserFiles(targetDir, migrationResult);
324
+
307
325
  // Update framework root files
308
326
  let filesUpdated = 0;
309
327
  for (const file of FRAMEWORK_FILES) {
@@ -427,3 +445,131 @@ function mergeConfigs(userConfigPath, newConfigPath) {
427
445
  return { newOptions: 0, newKeys: [] };
428
446
  }
429
447
  }
448
+
449
+ /**
450
+ * Find all template files in a directory recursively
451
+ * Template files have '.template.' in their name
452
+ */
453
+ function findTemplateFiles(dir, baseDir = dir) {
454
+ const templates = [];
455
+
456
+ if (!existsSync(dir)) return templates;
457
+
458
+ const entries = readdirSync(dir, { withFileTypes: true });
459
+
460
+ for (const entry of entries) {
461
+ const fullPath = join(dir, entry.name);
462
+ const relativePath = fullPath.replace(baseDir + '/', '');
463
+
464
+ if (entry.isDirectory()) {
465
+ templates.push(...findTemplateFiles(fullPath, baseDir));
466
+ } else if (entry.name.includes('.template.')) {
467
+ templates.push(relativePath);
468
+ }
469
+ }
470
+
471
+ return templates;
472
+ }
473
+
474
+ /**
475
+ * Get the user file path for a template file
476
+ * e.g., 'config/rules/custom-rules.template.yaml' -> 'config/rules/custom-rules.yaml'
477
+ */
478
+ function getUserFilePath(templatePath) {
479
+ return templatePath.replace('.template.', '.');
480
+ }
481
+
482
+ /**
483
+ * Check if a file has been modified by comparing with source
484
+ */
485
+ function isFileModified(sourcePath, targetPath) {
486
+ if (!existsSync(targetPath)) return false;
487
+ if (!existsSync(sourcePath)) return true; // File exists in target but not source = modified/custom
488
+
489
+ try {
490
+ const sourceContent = readFileSync(sourcePath, 'utf-8');
491
+ const targetContent = readFileSync(targetPath, 'utf-8');
492
+ return sourceContent !== targetContent;
493
+ } catch {
494
+ return false;
495
+ }
496
+ }
497
+
498
+ /**
499
+ * Migrate modified template files to user files before update
500
+ * Returns info about migrated and backed up files
501
+ */
502
+ function migrateModifiedTemplates(sourceDir, targetDir) {
503
+ const result = {
504
+ migrated: [], // Templates copied to user files
505
+ backedUp: [], // Templates backed up (user file already existed)
506
+ userFiles: {} // Map of user file paths to their content (for restoration)
507
+ };
508
+
509
+ // Find all template files in target directory
510
+ const templateFiles = findTemplateFiles(targetDir);
511
+
512
+ for (const templateRelPath of templateFiles) {
513
+ const templateTargetPath = join(targetDir, templateRelPath);
514
+ const templateSourcePath = join(sourceDir, templateRelPath);
515
+ const userFileRelPath = getUserFilePath(templateRelPath);
516
+ const userFilePath = join(targetDir, userFileRelPath);
517
+
518
+ // Check if template was modified by user
519
+ if (isFileModified(templateSourcePath, templateTargetPath)) {
520
+ try {
521
+ const modifiedContent = readFileSync(templateTargetPath, 'utf-8');
522
+
523
+ if (existsSync(userFilePath)) {
524
+ // User file already exists - backup the modified template
525
+ const backupPath = templateTargetPath + '.backup';
526
+ writeFileSync(backupPath, modifiedContent);
527
+ result.backedUp.push(templateRelPath);
528
+ // Save backup content for restoration after folder deletion
529
+ result.userFiles[templateRelPath + '.backup'] = modifiedContent;
530
+ } else {
531
+ // No user file - migrate template to user file
532
+ result.userFiles[userFileRelPath] = modifiedContent;
533
+ result.migrated.push(`${templateRelPath} → ${userFileRelPath}`);
534
+ }
535
+ } catch (error) {
536
+ // Skip files that can't be read
537
+ continue;
538
+ }
539
+ }
540
+
541
+ // Also preserve existing user files (non-template versions)
542
+ if (existsSync(userFilePath)) {
543
+ try {
544
+ const userContent = readFileSync(userFilePath, 'utf-8');
545
+ result.userFiles[userFileRelPath] = userContent;
546
+ } catch {
547
+ // Skip files that can't be read
548
+ }
549
+ }
550
+ }
551
+
552
+ return result;
553
+ }
554
+
555
+ /**
556
+ * Restore user files after framework folders have been updated
557
+ */
558
+ function restoreUserFiles(targetDir, migrationResult) {
559
+ for (const [relativePath, content] of Object.entries(migrationResult.userFiles)) {
560
+ const fullPath = join(targetDir, relativePath);
561
+ const dirPath = dirname(fullPath);
562
+
563
+ try {
564
+ // Ensure directory exists
565
+ if (!existsSync(dirPath)) {
566
+ mkdirSync(dirPath, { recursive: true });
567
+ }
568
+
569
+ // Write the user file
570
+ writeFileSync(fullPath, content);
571
+ } catch (error) {
572
+ console.log(chalk.yellow(`⚠️ Could not restore ${relativePath}: ${error.message}`));
573
+ }
574
+ }
575
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proagents",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "AI-agnostic development workflow framework that automates the full software development lifecycle",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",