claude-flow-novice 2.4.3 → 2.5.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow-novice",
3
- "version": "2.4.3",
3
+ "version": "2.5.0",
4
4
  "description": "AI Agent Orchestration CLI",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -23,6 +23,7 @@
23
23
  "readme"
24
24
  ],
25
25
  "scripts": {
26
+ "postinstall": "node scripts/postinstall.js",
26
27
  "build": "npm run clean && tsc && rollup -c",
27
28
  "clean": "rimraf dist",
28
29
  "lint": "eslint . --ext .ts",
@@ -1,94 +1,122 @@
1
1
  #!/usr/bin/env node
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const { execSync } = require('node:child_process');
5
+
6
+ // Logging utility
7
+ function log(message, type = 'info') {
8
+ const colors = {
9
+ info: '\x1b[36m', // Cyan
10
+ warn: '\x1b[33m', // Yellow
11
+ error: '\x1b[31m' // Red
12
+ };
13
+ console.log(`${colors[type]}[Claude Flow] ${message}\x1b[0m`);
14
+ }
2
15
 
3
- /**
4
- * Post-installation script for claude-flow-novice
5
- * Copies .claude directory from package to project root
6
- * Overwrites existing files to ensure updates work correctly
7
- */
16
+ // Generate timestamped backup filename
17
+ function getBackupFilename(basePath) {
18
+ const timestamp = new Date().toISOString()
19
+ .replace(/:/g, '-')
20
+ .replace(/\./g, '_');
21
+ return `${basePath}_backup_${timestamp}`;
22
+ }
8
23
 
9
- import { existsSync, readdirSync, statSync, copyFileSync, mkdirSync } from 'fs';
10
- import { dirname, join, relative } from 'path';
11
- import { fileURLToPath } from 'url';
24
+ // Check if running in development mode (not as installed dependency)
25
+ function isDevMode() {
26
+ try {
27
+ const packageJson = require(path.resolve(process.cwd(), 'package.json'));
28
+ // We're in dev mode if the package name matches (developing the package itself)
29
+ return packageJson.name === 'claude-flow-novice';
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
12
34
 
13
- const __filename = fileURLToPath(import.meta.url);
14
- const __dirname = dirname(__filename);
35
+ // Perform backup before sync
36
+ async function backupDirectory(sourcePath, targetPath) {
37
+ if (fs.existsSync(targetPath)) {
38
+ const backupPath = getBackupFilename(targetPath);
39
+ try {
40
+ fs.renameSync(targetPath, backupPath);
41
+ log(`Created backup: ${backupPath}`, 'info');
42
+ } catch (err) {
43
+ log(`Failed to create backup: ${err.message}`, 'warn');
44
+ }
45
+ }
46
+ }
15
47
 
48
+ // Sync directories
49
+ async function syncDirectories() {
50
+ // Skip if we're in development mode (developing the package itself)
51
+ if (isDevMode()) {
52
+ log('Development mode detected - skipping auto-sync', 'info');
53
+ return;
54
+ }
16
55
 
17
- /**
18
- * Copy .claude directory from node_modules to project root
19
- * Shows progress for each file copied
20
- */
21
- function copyClaudeDirectory() {
22
- try {
23
- const projectRoot = process.cwd();
24
-
25
- // Try multiple source locations (handles both dev and installed package scenarios)
26
- const possibleSources = [
27
- join(__dirname, '../dist/.claude'), // Installed package: node_modules/claude-flow-novice/scripts/ → dist/.claude
28
- join(__dirname, '../.claude'), // Direct execution from repo root
29
- join(__dirname, '../../.claude'), // Execution from dist/scripts/
30
- ];
31
-
32
- const sourceDir = possibleSources.find(dir => existsSync(dir));
33
- const targetDir = join(projectRoot, '.claude');
34
-
35
- console.log('🚀 claude-flow-novice post-install: Setting up .claude directory...');
36
- console.log('📂 Source:', sourceDir);
37
- console.log('📁 Target:', targetDir);
38
- console.log('');
39
-
40
- // Check if source directory was found
41
- if (!sourceDir) {
42
- console.error('❌ Source .claude directory not found. Tried:');
43
- possibleSources.forEach(dir => console.error(` - ${dir}`));
44
- console.log(' This indicates a broken npm package installation.');
45
- process.exit(1);
56
+ log('Auto-syncing agents, commands, and hooks to your project...', 'info');
57
+
58
+ const projectRoot = process.cwd();
59
+
60
+ const syncConfigs = [
61
+ {
62
+ source: path.join(__dirname, '..', '.claude', 'agents'),
63
+ target: path.join(projectRoot, '.claude', 'agents')
64
+ },
65
+ {
66
+ source: path.join(__dirname, '..', '.claude', 'commands'),
67
+ target: path.join(projectRoot, '.claude', 'commands')
68
+ },
69
+ {
70
+ source: path.join(__dirname, '..', 'config', 'hooks'),
71
+ target: path.join(projectRoot, 'config', 'hooks')
46
72
  }
47
-
48
- let fileCount = 0;
49
-
50
- /**
51
- * Recursively copy directory with progress output
52
- */
53
- function copyWithProgress(source, target) {
54
- const stat = statSync(source);
55
-
56
- if (stat.isDirectory()) {
57
- // Create directory if it doesn't exist
58
- if (!existsSync(target)) {
59
- mkdirSync(target, { recursive: true });
60
- }
61
-
62
- // Copy all entries in directory
63
- const entries = readdirSync(source);
64
- for (const entry of entries) {
65
- copyWithProgress(join(source, entry), join(target, entry));
66
- }
67
- } else {
68
- // Copy file and show progress
69
- const relativePath = relative(sourceDir, source);
70
- const status = existsSync(target) ? '♻️ Overwriting' : '📄 Copying';
71
- console.log(`${status}: ${relativePath}`);
72
-
73
- copyFileSync(source, target);
74
- fileCount++;
73
+ ];
74
+
75
+ for (const config of syncConfigs) {
76
+ try {
77
+ // Create target directory if it doesn't exist
78
+ fs.mkdirSync(path.dirname(config.target), { recursive: true });
79
+
80
+ // Backup existing directory
81
+ await backupDirectory(config.source, config.target);
82
+
83
+ // Perform directory copy using cp command
84
+ const sourcePath = config.source;
85
+ const targetPath = config.target;
86
+
87
+ try {
88
+ execSync(`cp -r "${sourcePath}" "${targetPath}"`, { stdio: 'ignore' });
89
+ log(`Synced ${path.basename(config.source)}/ to project`, 'info');
90
+ } catch (cpError) {
91
+ // Fallback to recursive copy for Windows
92
+ copyDirRecursive(sourcePath, targetPath);
93
+ log(`Synced ${path.basename(config.source)}/ to project`, 'info');
75
94
  }
95
+ } catch (err) {
96
+ log(`Sync failed for ${path.basename(config.source)}: ${err.message}`, 'error');
76
97
  }
98
+ }
99
+ }
77
100
 
78
- // Start copying
79
- copyWithProgress(sourceDir, targetDir);
101
+ // Fallback recursive copy for Windows
102
+ function copyDirRecursive(src, dest) {
103
+ fs.mkdirSync(dest, { recursive: true });
104
+ const entries = fs.readdirSync(src, { withFileTypes: true });
80
105
 
81
- console.log('');
82
- console.log(`✅ Successfully copied ${fileCount} files`);
83
- console.log('📁 Location:', targetDir);
84
- console.log('🎉 Installation complete! claude-flow-novice is ready to use.');
106
+ for (const entry of entries) {
107
+ const srcPath = path.join(src, entry.name);
108
+ const destPath = path.join(dest, entry.name);
85
109
 
86
- } catch (error) {
87
- console.error('❌ Post-install script failed:', error.message);
88
- console.error(' Please run manually: cp -r node_modules/claude-flow-novice/dist/.claude .claude');
89
- process.exit(1);
110
+ if (entry.isDirectory()) {
111
+ copyDirRecursive(srcPath, destPath);
112
+ } else {
113
+ fs.copyFileSync(srcPath, destPath);
114
+ }
90
115
  }
91
116
  }
92
117
 
93
- // Run the installation
94
- copyClaudeDirectory();
118
+ // Run sync
119
+ syncDirectories().catch(err => {
120
+ log(`Sync encountered an error: ${err.message}`, 'error');
121
+ process.exit(1);
122
+ });
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  /**
3
3
  * Cost-Savings Mode Toggle Script
4
4
  * Switches between CLI-based (cost-savings) and Task-tool coordination
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  /**
4
4
  * Agent Lifecycle Hooks Validator
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  /**
4
4
  * Real Hybrid Routing CLI - Spawns actual Claude agents with bash execution