claude-flow-novice 2.4.3 → 2.5.1

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.
@@ -1,94 +1,160 @@
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
- */
8
-
9
- import { existsSync, readdirSync, statSync, copyFileSync, mkdirSync } from 'fs';
10
- import { dirname, join, relative } from 'path';
11
- import { fileURLToPath } from 'url';
12
-
13
- const __filename = fileURLToPath(import.meta.url);
14
- const __dirname = dirname(__filename);
15
-
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
+ }
16
23
 
17
- /**
18
- * Copy .claude directory from node_modules to project root
19
- * Shows progress for each file copied
20
- */
21
- function copyClaudeDirectory() {
24
+ // Check if running in development mode (not as installed dependency)
25
+ function isDevMode() {
22
26
  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);
46
- }
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
+ }
47
34
 
48
- let fileCount = 0;
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
+ }
49
47
 
50
- /**
51
- * Recursively copy directory with progress output
52
- */
53
- function copyWithProgress(source, target) {
54
- const stat = statSync(source);
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
+ }
55
55
 
56
- if (stat.isDirectory()) {
57
- // Create directory if it doesn't exist
58
- if (!existsSync(target)) {
59
- mkdirSync(target, { recursive: true });
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')
72
+ }
73
+ ];
74
+
75
+ // Sync individual reference files from .claude root
76
+ const referenceFiles = [
77
+ 'cfn-loop-rules.md',
78
+ 'cfn-mode-patterns.md',
79
+ 'coordinator-feedback-pattern.md',
80
+ 'coordinator-patterns.md',
81
+ 'redis-agent-dependencies.md',
82
+ 'spawn-pattern-examples.md'
83
+ ];
84
+
85
+ const claudeRoot = path.join(__dirname, '..', '.claude');
86
+ const targetClaudeRoot = path.join(projectRoot, '.claude');
87
+
88
+ // Ensure target .claude directory exists
89
+ fs.mkdirSync(targetClaudeRoot, { recursive: true });
90
+
91
+ for (const filename of referenceFiles) {
92
+ try {
93
+ const sourceFile = path.join(claudeRoot, filename);
94
+ const targetFile = path.join(targetClaudeRoot, filename);
95
+
96
+ if (fs.existsSync(sourceFile)) {
97
+ // Backup existing file if it exists
98
+ if (fs.existsSync(targetFile)) {
99
+ const backupFile = getBackupFilename(targetFile);
100
+ fs.renameSync(targetFile, backupFile);
101
+ log(`Backed up existing ${filename}`, 'info');
60
102
  }
61
103
 
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++;
104
+ // Copy reference file
105
+ fs.copyFileSync(sourceFile, targetFile);
106
+ log(`Synced ${filename} to project`, 'info');
107
+ }
108
+ } catch (err) {
109
+ log(`Failed to sync ${filename}: ${err.message}`, 'error');
110
+ }
111
+ }
112
+
113
+ for (const config of syncConfigs) {
114
+ try {
115
+ // Create target directory if it doesn't exist
116
+ fs.mkdirSync(path.dirname(config.target), { recursive: true });
117
+
118
+ // Backup existing directory
119
+ await backupDirectory(config.source, config.target);
120
+
121
+ // Perform directory copy using cp command
122
+ const sourcePath = config.source;
123
+ const targetPath = config.target;
124
+
125
+ try {
126
+ execSync(`cp -r "${sourcePath}" "${targetPath}"`, { stdio: 'ignore' });
127
+ log(`Synced ${path.basename(config.source)}/ to project`, 'info');
128
+ } catch (cpError) {
129
+ // Fallback to recursive copy for Windows
130
+ copyDirRecursive(sourcePath, targetPath);
131
+ log(`Synced ${path.basename(config.source)}/ to project`, 'info');
75
132
  }
133
+ } catch (err) {
134
+ log(`Sync failed for ${path.basename(config.source)}: ${err.message}`, 'error');
76
135
  }
136
+ }
137
+ }
77
138
 
78
- // Start copying
79
- copyWithProgress(sourceDir, targetDir);
139
+ // Fallback recursive copy for Windows
140
+ function copyDirRecursive(src, dest) {
141
+ fs.mkdirSync(dest, { recursive: true });
142
+ const entries = fs.readdirSync(src, { withFileTypes: true });
80
143
 
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.');
144
+ for (const entry of entries) {
145
+ const srcPath = path.join(src, entry.name);
146
+ const destPath = path.join(dest, entry.name);
85
147
 
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);
148
+ if (entry.isDirectory()) {
149
+ copyDirRecursive(srcPath, destPath);
150
+ } else {
151
+ fs.copyFileSync(srcPath, destPath);
152
+ }
90
153
  }
91
154
  }
92
155
 
93
- // Run the installation
94
- copyClaudeDirectory();
156
+ // Run sync
157
+ syncDirectories().catch(err => {
158
+ log(`Sync encountered an error: ${err.message}`, 'error');
159
+ process.exit(1);
160
+ });
@@ -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