claude-flow-novice 2.3.9 → 2.4.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/SYNC_USAGE.md ADDED
@@ -0,0 +1,191 @@
1
+ # Claude Flow Novice - Sync Guide
2
+
3
+ ## Installation & Setup
4
+
5
+ ### 1. Install Package
6
+
7
+ ```bash
8
+ npm install claude-flow-novice
9
+ ```
10
+
11
+ ### 2. Sync Agents, Commands, and Hooks
12
+
13
+ After installation, sync the latest agents, slash commands, and validation hooks to your project:
14
+
15
+ ```bash
16
+ # Sync everything with backup
17
+ npx claude-flow-sync --backup
18
+
19
+ # Or use the longer form
20
+ node node_modules/claude-flow-novice/scripts/sync-from-package.js --backup
21
+ ```
22
+
23
+ ## Sync Options
24
+
25
+ ### Sync Everything (Recommended for first time)
26
+
27
+ ```bash
28
+ npx claude-flow-sync --backup
29
+ ```
30
+
31
+ This syncs:
32
+ - `.claude/agents/` - All agent definitions (94 files)
33
+ - `.claude/commands/` - Slash commands
34
+ - `config/hooks/` - Validation hooks
35
+
36
+ ### Selective Sync
37
+
38
+ ```bash
39
+ # Sync only agents
40
+ npx claude-flow-sync --agents --backup
41
+
42
+ # Sync only commands
43
+ npx claude-flow-sync --commands --backup
44
+
45
+ # Sync only hooks
46
+ npx claude-flow-sync --hooks --backup
47
+
48
+ # Combine multiple
49
+ npx claude-flow-sync --agents --hooks --backup
50
+ ```
51
+
52
+ ### Force Overwrite
53
+
54
+ Use `--force` to overwrite existing files without prompting:
55
+
56
+ ```bash
57
+ npx claude-flow-sync --force --backup
58
+ ```
59
+
60
+ **⚠️ Warning**: `--force` will overwrite your customizations. Always use `--backup` with `--force`.
61
+
62
+ ## Update Workflow
63
+
64
+ ### When Package Updates
65
+
66
+ ```bash
67
+ # 1. Update package
68
+ npm update claude-flow-novice
69
+
70
+ # 2. Sync new changes (creates backup automatically)
71
+ npx claude-flow-sync --backup
72
+
73
+ # 3. Review changes
74
+ git diff .claude/ config/
75
+
76
+ # 4. Merge customizations if needed
77
+ # Restore from .backup-YYYY-MM-DD if you need your custom changes
78
+ ```
79
+
80
+ ### Customizing Agents/Commands
81
+
82
+ 1. **Initial sync**:
83
+ ```bash
84
+ npx claude-flow-sync --backup
85
+ ```
86
+
87
+ 2. **Customize** your local copies in:
88
+ - `.claude/agents/`
89
+ - `.claude/commands/`
90
+ - `config/hooks/`
91
+
92
+ 3. **Update from package** (preserves your changes):
93
+ ```bash
94
+ # WITHOUT --force, you'll be warned about existing files
95
+ npx claude-flow-sync --backup
96
+
97
+ # Review what changed in the package
98
+ diff -r .claude/agents/ .claude/agents.backup-YYYY-MM-DD/
99
+
100
+ # Manually merge changes you want
101
+ ```
102
+
103
+ ## File Locations After Sync
104
+
105
+ ```
106
+ your-project/
107
+ ├── .claude/
108
+ │ ├── agents/ # ✅ Synced from package (94 files)
109
+ │ └── commands/ # ✅ Synced from package
110
+ ├── config/
111
+ │ └── hooks/ # ✅ Synced from package (13+ files)
112
+ └── node_modules/
113
+ └── claude-flow-novice/
114
+ ├── .claude/ # Source (in npm package)
115
+ ├── config/ # Source (in npm package)
116
+ └── scripts/ # Source (in npm package)
117
+ ```
118
+
119
+ ## Backup Management
120
+
121
+ Backups are created as:
122
+ - `.claude/agents.backup-2025-10-17/`
123
+ - `.claude/commands.backup-2025-10-17/`
124
+ - `config/hooks.backup-2025-10-17/`
125
+
126
+ ### Restore from Backup
127
+
128
+ ```bash
129
+ # If you need to restore
130
+ rm -rf .claude/agents/
131
+ mv .claude/agents.backup-2025-10-17/ .claude/agents/
132
+ ```
133
+
134
+ ## Examples
135
+
136
+ ### First-Time Setup
137
+ ```bash
138
+ npm install claude-flow-novice
139
+ npx claude-flow-sync --backup
140
+ ```
141
+
142
+ ### Regular Updates
143
+ ```bash
144
+ npm update claude-flow-novice
145
+ npx claude-flow-sync --backup
146
+ # Review changes with: git diff
147
+ ```
148
+
149
+ ### Force Update Everything
150
+ ```bash
151
+ npx claude-flow-sync --force --backup
152
+ ```
153
+
154
+ ### Update Only Hooks (Get Latest Validators)
155
+ ```bash
156
+ npx claude-flow-sync --hooks --force --backup
157
+ ```
158
+
159
+ ## What Gets Synced
160
+
161
+ | Directory | Files | Description |
162
+ |-----------|-------|-------------|
163
+ | `.claude/agents/` | 94 | Agent definitions (optimized, Phase 4) |
164
+ | `.claude/commands/` | 50+ | Slash commands |
165
+ | `config/hooks/` | 13+ | Validation hooks (post-edit, etc.) |
166
+
167
+ ## What Doesn't Get Synced
168
+
169
+ - `scripts/` - Only package utilities, not project-specific scripts
170
+ - `readme/` - Package documentation (not project-specific)
171
+ - `src/` - Package source code (not for project use)
172
+
173
+ ## Troubleshooting
174
+
175
+ ### "Source directory not found"
176
+ Your package might be outdated. Update it:
177
+ ```bash
178
+ npm update claude-flow-novice
179
+ ```
180
+
181
+ ### "Destination exists" Warning
182
+ Without `--force`, sync won't overwrite. Use:
183
+ ```bash
184
+ npx claude-flow-sync --force --backup
185
+ ```
186
+
187
+ ### Lost Customizations
188
+ Restore from backup:
189
+ ```bash
190
+ mv .claude/agents.backup-YYYY-MM-DD/ .claude/agents/
191
+ ```
@@ -1480,6 +1480,43 @@ class UnifiedPostEditPipeline {
1480
1480
  }
1481
1481
 
1482
1482
  const projectDir = this.findProjectRoot(filePath);
1483
+
1484
+ // TypeScript incremental type checking (single-file mode)
1485
+ if (language === 'typescript' && tool === 'tsc') {
1486
+ const tsArgs = [...args, '--skipLibCheck', filePath];
1487
+
1488
+ try {
1489
+ const result = await this.runCommand(tool, tsArgs, projectDir);
1490
+
1491
+ // Parse TypeScript error output from both stdout and stderr
1492
+ const allOutput = result.stdout + result.stderr;
1493
+ const errorLines = allOutput.split('\n').filter(line => line.includes('error TS'));
1494
+ const errorCount = errorLines.length;
1495
+
1496
+ return {
1497
+ success: result.code === 0 && errorCount === 0,
1498
+ message: result.code === 0 ? 'TypeScript compilation passed' : `${errorCount} TypeScript error(s)`,
1499
+ output: allOutput,
1500
+ errors: errorCount > 0 ? errorLines.join('\n') : '',
1501
+ errorCount,
1502
+ errorLines: errorLines.slice(0, 10), // First 10 errors for feedback
1503
+ wasmAccelerated
1504
+ };
1505
+ } catch (error) {
1506
+ // Handle TypeScript compiler crashes gracefully
1507
+ return {
1508
+ success: false,
1509
+ message: 'TypeScript compiler error',
1510
+ output: error.message || error.stderr || '',
1511
+ errors: error.message || 'TypeScript compilation failed',
1512
+ errorCount: 1,
1513
+ errorLines: [(error.message || 'Unknown compiler error')],
1514
+ wasmAccelerated
1515
+ };
1516
+ }
1517
+ }
1518
+
1519
+ // Standard type checking for other languages
1483
1520
  const result = await this.runCommand(tool, args, projectDir);
1484
1521
 
1485
1522
  return {
@@ -2126,6 +2163,18 @@ class UnifiedPostEditPipeline {
2126
2163
  if (!results.steps.typeCheck.success) {
2127
2164
  results.summary.errors.push(`Type errors in ${path.basename(filePath)}`);
2128
2165
  results.summary.success = false;
2166
+
2167
+ // Send TYPE_ERROR feedback to agent
2168
+ await this.sendAgentFeedback({
2169
+ type: 'TYPE_ERROR',
2170
+ file: filePath,
2171
+ severity: 'error',
2172
+ language,
2173
+ errorCount: results.steps.typeCheck.errorCount || 0,
2174
+ errorLines: results.steps.typeCheck.errorLines || [],
2175
+ errors: results.steps.typeCheck.errors,
2176
+ message: `${results.steps.typeCheck.errorCount || 'Unknown'} TypeScript error(s) in ${path.basename(filePath)}`
2177
+ });
2129
2178
  }
2130
2179
 
2131
2180
  // Step 4: Rust Quality Enforcement (if Rust and strict mode)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow-novice",
3
- "version": "2.3.9",
3
+ "version": "2.4.0",
4
4
  "description": "AI Agent Orchestration CLI",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -12,6 +12,7 @@
12
12
  "README.md",
13
13
  "CHANGELOG.md",
14
14
  "LICENSE",
15
+ "SYNC_USAGE.md",
15
16
  "config",
16
17
  "scripts",
17
18
  ".claude",
@@ -22,6 +23,8 @@
22
23
  "clean": "rimraf dist",
23
24
  "lint": "eslint . --ext .ts",
24
25
  "typecheck": "tsc --noEmit",
26
+ "type-coverage": "type-coverage --detail --ignore-files 'src/__tests__/**' --ignore-files '**/*.test.ts'",
27
+ "type-coverage:ci": "type-coverage --at-least 80 --ignore-files 'src/__tests__/**' --ignore-files '**/*.test.ts'",
25
28
  "test": "jest",
26
29
  "test:coverage": "jest --coverage",
27
30
  "prepublish-checks": "node scripts/prepublish-checks.js",
@@ -29,7 +32,8 @@
29
32
  "security-scan": "snyk test && npm audit --audit-level=high",
30
33
  "bundle-size-check": "bundlesize",
31
34
  "smoke-test": "npm pack && node scripts/smoke-test.js",
32
- "changelog": "standard-version"
35
+ "changelog": "standard-version",
36
+ "create:component": "node scripts/create-component.js"
33
37
  },
34
38
  "keywords": [
35
39
  "ai",
@@ -54,15 +58,19 @@
54
58
  },
55
59
  "devDependencies": {
56
60
  "@types/node": "^20.0.0",
57
- "typescript": "^5.0.0",
58
- "jest": "^29.0.0",
61
+ "bundlesize": "^0.18.1",
59
62
  "eslint": "^8.0.0",
60
- "rollup": "^3.0.0",
63
+ "husky": "^8.0.0",
64
+ "jest": "^29.0.0",
61
65
  "rimraf": "^5.0.0",
62
- "bundlesize": "^0.18.1",
63
- "snyk": "^1.0.0",
66
+ "rollup": "^3.0.0",
64
67
  "semantic-release": "^21.0.0",
68
+ "snyk": "^1.0.0",
65
69
  "standard-version": "^9.0.0",
66
- "husky": "^8.0.0"
70
+ "type-coverage": "^2.29.7",
71
+ "typescript": "^5.9.3"
72
+ },
73
+ "dependencies": {
74
+ "ioredis": "^5.8.1"
67
75
  }
68
76
  }
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Component Template Generator
5
+ * Creates TypeScript components with proper type declarations and tests
6
+ *
7
+ * Usage:
8
+ * node scripts/create-component.js <ComponentName> <directory>
9
+ *
10
+ * Example:
11
+ * node scripts/create-component.js SwarmCoordinator src/coordination
12
+ */
13
+
14
+ import fs from 'fs';
15
+ import path from 'path';
16
+ import { fileURLToPath } from 'url';
17
+
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+
21
+ const [, , componentName, componentDir] = process.argv;
22
+
23
+ if (!componentName || !componentDir) {
24
+ console.log(`
25
+ 🔧 Component Template Generator
26
+
27
+ Usage: node scripts/create-component.js <ComponentName> <directory>
28
+
29
+ Arguments:
30
+ ComponentName Name of the component (PascalCase)
31
+ directory Target directory (e.g., src/coordination)
32
+
33
+ Examples:
34
+ node scripts/create-component.js SwarmCoordinator src/coordination
35
+ node scripts/create-component.js TaskValidator src/validation
36
+ node scripts/create-component.js RedisClient src/services
37
+
38
+ Generated files:
39
+ ✅ <directory>/<ComponentName>.ts - Main implementation
40
+ ✅ <directory>/<ComponentName>.test.ts - Test file with basic setup
41
+ ✅ <directory>/types.ts - Type definitions (if doesn't exist)
42
+ `);
43
+ process.exit(1);
44
+ }
45
+
46
+ const projectRoot = path.resolve(__dirname, '..');
47
+
48
+ // Validate component name (PascalCase)
49
+ if (!/^[A-Z][a-zA-Z0-9]*$/.test(componentName)) {
50
+ console.error(`❌ Error: Component name must be PascalCase (e.g., SwarmCoordinator, not swarm-coordinator)`);
51
+ process.exit(1);
52
+ }
53
+
54
+ // Create directory if it doesn't exist
55
+ const targetDir = path.join(projectRoot, componentDir);
56
+ if (!fs.existsSync(targetDir)) {
57
+ fs.mkdirSync(targetDir, { recursive: true });
58
+ console.log(`📁 Created directory: ${componentDir}/`);
59
+ }
60
+
61
+ // Component file template
62
+ const componentTemplate = `/**
63
+ * ${componentName}
64
+ *
65
+ * TODO: Add component description
66
+ */
67
+
68
+ export interface ${componentName}Options {
69
+ // TODO: Define configuration options
70
+ }
71
+
72
+ export class ${componentName} {
73
+ private options: ${componentName}Options;
74
+
75
+ constructor(options: ${componentName}Options) {
76
+ this.options = options;
77
+ }
78
+
79
+ // TODO: Implement methods
80
+ async initialize(): Promise<void> {
81
+ // Initialization logic
82
+ }
83
+
84
+ async execute(): Promise<void> {
85
+ // Main execution logic
86
+ }
87
+
88
+ async cleanup(): Promise<void> {
89
+ // Cleanup logic
90
+ }
91
+ }
92
+ `;
93
+
94
+ // Test file template
95
+ const testTemplate = `import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
96
+ import { ${componentName} } from './${componentName}';
97
+
98
+ describe('${componentName}', () => {
99
+ let component: ${componentName};
100
+
101
+ beforeEach(() => {
102
+ component = new ${componentName}({
103
+ // TODO: Add test configuration
104
+ });
105
+ });
106
+
107
+ afterEach(async () => {
108
+ await component.cleanup();
109
+ });
110
+
111
+ describe('initialization', () => {
112
+ it('should initialize successfully', async () => {
113
+ await component.initialize();
114
+ // TODO: Add assertions
115
+ expect(component).toBeDefined();
116
+ });
117
+ });
118
+
119
+ describe('execution', () => {
120
+ it('should execute successfully', async () => {
121
+ await component.initialize();
122
+ await component.execute();
123
+ // TODO: Add assertions
124
+ });
125
+ });
126
+
127
+ describe('error handling', () => {
128
+ it('should handle errors gracefully', async () => {
129
+ // TODO: Test error scenarios
130
+ });
131
+ });
132
+ });
133
+ `;
134
+
135
+ // Types file template (only create if doesn't exist)
136
+ const typesTemplate = `/**
137
+ * Type definitions for ${componentDir}
138
+ */
139
+
140
+ export interface BaseOptions {
141
+ enabled?: boolean;
142
+ debug?: boolean;
143
+ }
144
+
145
+ // Add shared types here
146
+ `;
147
+
148
+ // Write component file
149
+ const componentPath = path.join(targetDir, `${componentName}.ts`);
150
+ if (fs.existsSync(componentPath)) {
151
+ console.error(`❌ Error: Component file already exists: ${componentPath}`);
152
+ process.exit(1);
153
+ }
154
+ fs.writeFileSync(componentPath, componentTemplate);
155
+ console.log(`✅ Created: ${path.relative(projectRoot, componentPath)}`);
156
+
157
+ // Write test file
158
+ const testPath = path.join(targetDir, `${componentName}.test.ts`);
159
+ if (fs.existsSync(testPath)) {
160
+ console.warn(`⚠️ Warning: Test file already exists: ${testPath} (skipping)`);
161
+ } else {
162
+ fs.writeFileSync(testPath, testTemplate);
163
+ console.log(`✅ Created: ${path.relative(projectRoot, testPath)}`);
164
+ }
165
+
166
+ // Create types file if doesn't exist
167
+ const typesPath = path.join(targetDir, 'types.ts');
168
+ if (!fs.existsSync(typesPath)) {
169
+ fs.writeFileSync(typesPath, typesTemplate);
170
+ console.log(`✅ Created: ${path.relative(projectRoot, typesPath)}`);
171
+ } else {
172
+ console.log(`ℹ️ Types file exists: ${path.relative(projectRoot, typesPath)} (not modified)`);
173
+ }
174
+
175
+ // Create index.ts barrel export if doesn't exist
176
+ const indexPath = path.join(targetDir, 'index.ts');
177
+ const exportLine = `export * from './${componentName}';\n`;
178
+
179
+ if (fs.existsSync(indexPath)) {
180
+ const content = fs.readFileSync(indexPath, 'utf8');
181
+ if (!content.includes(`from './${componentName}'`)) {
182
+ fs.appendFileSync(indexPath, exportLine);
183
+ console.log(`✅ Added export to: ${path.relative(projectRoot, indexPath)}`);
184
+ } else {
185
+ console.log(`ℹ️ Export already exists in: ${path.relative(projectRoot, indexPath)}`);
186
+ }
187
+ } else {
188
+ fs.writeFileSync(indexPath, `export * from './types';\n${exportLine}`);
189
+ console.log(`✅ Created: ${path.relative(projectRoot, indexPath)}`);
190
+ }
191
+
192
+ console.log(`
193
+ ✨ Component generated successfully!
194
+
195
+ Next steps:
196
+ 1. Implement ${componentName} logic in ${componentPath}
197
+ 2. Write tests in ${testPath}
198
+ 3. Run tests: npm test -- ${componentName}
199
+ 4. Run type check: npm run typecheck
200
+ `);
@@ -923,7 +923,8 @@ Execute the task using available tools. Report confidence score (0.0-1.0) at the
923
923
  const MAX_TOOL_ITERATIONS = 1000; // Increased from 25 to allow comprehensive optimization tasks
924
924
  let content = '';
925
925
 
926
- // Tool use loop
926
+ // Tool use loop with context window management
927
+ const MAX_CONTEXT_MESSAGES = 20; // Keep only last 20 messages
927
928
  while (toolUseCount < MAX_TOOL_ITERATIONS) {
928
929
  const response = await this.anthropic.createMessage({
929
930
  model: this.model,
@@ -979,6 +980,12 @@ Execute the task using available tools. Report confidence score (0.0-1.0) at the
979
980
  });
980
981
 
981
982
  toolUseCount++;
983
+
984
+ // Trim context window to prevent memory leak
985
+ if (messages.length > MAX_CONTEXT_MESSAGES) {
986
+ // Keep first message (initial task) + last N messages
987
+ messages = [messages[0], ...messages.slice(-MAX_CONTEXT_MESSAGES + 1)];
988
+ }
982
989
  }
983
990
 
984
991
  if (toolUseCount >= MAX_TOOL_ITERATIONS) {
@@ -1103,7 +1110,7 @@ Execute the task using available tools. Report confidence score (0.0-1.0) at the
1103
1110
  }
1104
1111
 
1105
1112
  /**
1106
- * Recursively scan directory for .md files
1113
+ * Recursively scan directory for .md files (excludes node_modules)
1107
1114
  */
1108
1115
  async scanAgentFiles(dirPath, basePath) {
1109
1116
  const { promises: fs } = await import('fs');
@@ -1115,6 +1122,11 @@ Execute the task using available tools. Report confidence score (0.0-1.0) at the
1115
1122
  const entries = await fs.readdir(dirPath, { withFileTypes: true });
1116
1123
 
1117
1124
  for (const entry of entries) {
1125
+ // Skip node_modules to prevent memory leak
1126
+ if (entry.name === 'node_modules') {
1127
+ continue;
1128
+ }
1129
+
1118
1130
  const fullPath = path.join(dirPath, entry.name);
1119
1131
 
1120
1132
  if (entry.isDirectory()) {
package/src/index.ts CHANGED
@@ -27,10 +27,10 @@ export const AgentType = {
27
27
  API_DOCS: 'api-docs',
28
28
  BACKEND_DEV: 'backend-dev',
29
29
  FRONTEND_DEV: 'frontend-dev',
30
- MOBILE_DEV: 'mobile-dev'
30
+ MOBILE_DEV: 'mobile-dev',
31
31
  } as const;
32
32
 
33
- export type AgentType = typeof AgentType[keyof typeof AgentType];
33
+ export type AgentType = (typeof AgentType)[keyof typeof AgentType];
34
34
 
35
35
  // Version
36
36
  export const VERSION = '2.0.4';
@@ -41,6 +41,6 @@ export const defaultConfig = {
41
41
  strategy: 'development',
42
42
  mode: 'mesh',
43
43
  persistence: true,
44
- consensusThreshold: 0.90,
45
- gateThreshold: 0.75
44
+ consensusThreshold: 0.9,
45
+ gateThreshold: 0.75,
46
46
  };