claude-flow-novice 1.5.4 → 1.5.5

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.
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * SDK Phase 1 Verification Script
5
+ *
6
+ * Verifies that Phase 1 implementation is complete and functional
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+
12
+ console.log('\n' + '='.repeat(70));
13
+ console.log('šŸ” CLAUDE AGENT SDK - PHASE 1 VERIFICATION');
14
+ console.log('='.repeat(70) + '\n');
15
+
16
+ let allPassed = true;
17
+ const results = [];
18
+
19
+ function check(name, condition, details = '') {
20
+ const passed = condition;
21
+ results.push({ name, passed, details });
22
+
23
+ if (passed) {
24
+ console.log(`āœ… ${name}`);
25
+ if (details) console.log(` ${details}`);
26
+ } else {
27
+ console.log(`āŒ ${name}`);
28
+ if (details) console.log(` ${details}`);
29
+ allPassed = false;
30
+ }
31
+ }
32
+
33
+ // 1. Check package installation
34
+ console.log('\nšŸ“¦ CHECKING PACKAGE INSTALLATION\n');
35
+
36
+ try {
37
+ const packageJson = require('../package.json');
38
+ check(
39
+ 'Package.json exists',
40
+ true,
41
+ 'Located at root directory'
42
+ );
43
+
44
+ check(
45
+ '@anthropic-ai/claude-agent-sdk installed',
46
+ packageJson.dependencies['@anthropic-ai/claude-agent-sdk'] !== undefined,
47
+ `Version: ${packageJson.dependencies['@anthropic-ai/claude-agent-sdk']}`
48
+ );
49
+ } catch (error) {
50
+ check('Package.json readable', false, error.message);
51
+ }
52
+
53
+ // 2. Check SDK files
54
+ console.log('\nšŸ“‚ CHECKING SDK FILES\n');
55
+
56
+ const requiredFiles = [
57
+ { path: 'src/sdk/config.cjs', desc: 'SDK configuration' },
58
+ { path: 'src/sdk/monitor.cjs', desc: 'Token usage monitoring' },
59
+ { path: 'src/sdk/index.cjs', desc: 'Main integration layer' }
60
+ ];
61
+
62
+ requiredFiles.forEach(({ path: filePath, desc }) => {
63
+ const fullPath = path.join(__dirname, '..', filePath);
64
+ const exists = fs.existsSync(fullPath);
65
+ const size = exists ? fs.statSync(fullPath).size : 0;
66
+
67
+ check(
68
+ `${filePath} exists`,
69
+ exists,
70
+ `${desc} - ${(size / 1024).toFixed(1)} KB`
71
+ );
72
+ });
73
+
74
+ // 3. Check test files
75
+ console.log('\n🧪 CHECKING TEST FILES\n');
76
+
77
+ const testFile = path.join(__dirname, '../tests/sdk-integration.test.js');
78
+ check(
79
+ 'tests/sdk-integration.test.js exists',
80
+ fs.existsSync(testFile),
81
+ 'Phase 1 test suite'
82
+ );
83
+
84
+ // 4. Check documentation
85
+ console.log('\nšŸ“š CHECKING DOCUMENTATION\n');
86
+
87
+ const docFiles = [
88
+ 'docs/sdk-integration-phase1.md',
89
+ 'docs/sdk-phase1-summary.md'
90
+ ];
91
+
92
+ docFiles.forEach((docFile) => {
93
+ const fullPath = path.join(__dirname, '..', docFile);
94
+ const exists = fs.existsSync(fullPath);
95
+
96
+ check(
97
+ `${docFile} exists`,
98
+ exists,
99
+ exists ? `${(fs.statSync(fullPath).size / 1024).toFixed(1)} KB` : ''
100
+ );
101
+ });
102
+
103
+ // 5. Check environment configuration
104
+ console.log('\nāš™ļø CHECKING ENVIRONMENT CONFIGURATION\n');
105
+
106
+ const envFile = path.join(__dirname, '../.env');
107
+ if (fs.existsSync(envFile)) {
108
+ const envContent = fs.readFileSync(envFile, 'utf-8');
109
+
110
+ const envVars = [
111
+ 'ENABLE_SDK_CACHING',
112
+ 'ENABLE_CONTEXT_EDITING',
113
+ 'SDK_INTEGRATION_MODE',
114
+ 'ENABLE_SDK_INTEGRATION'
115
+ ];
116
+
117
+ envVars.forEach((varName) => {
118
+ check(
119
+ `${varName} in .env`,
120
+ envContent.includes(varName),
121
+ `Environment variable configured`
122
+ );
123
+ });
124
+ } else {
125
+ check('.env file exists', false, 'Environment file not found');
126
+ }
127
+
128
+ // 6. Test SDK loading
129
+ console.log('\nšŸ”§ TESTING SDK LOADING\n');
130
+
131
+ try {
132
+ const sdk = require('../src/sdk/index.cjs');
133
+
134
+ check(
135
+ 'SDK module loads',
136
+ true,
137
+ 'No syntax errors'
138
+ );
139
+
140
+ check(
141
+ 'SDK exports initialize',
142
+ typeof sdk.initialize === 'function',
143
+ 'Initialize function available'
144
+ );
145
+
146
+ check(
147
+ 'SDK exports monitoring',
148
+ typeof sdk.getMonitor === 'function',
149
+ 'Monitoring functions available'
150
+ );
151
+
152
+ check(
153
+ 'SDK exports config',
154
+ typeof sdk.getSDKConfig === 'function',
155
+ 'Configuration functions available'
156
+ );
157
+
158
+ check(
159
+ 'TOKEN_COSTS defined',
160
+ sdk.TOKEN_COSTS !== undefined,
161
+ `Input: $${sdk.TOKEN_COSTS.input}, Cached: $${sdk.TOKEN_COSTS.cached}`
162
+ );
163
+ } catch (error) {
164
+ check('SDK module loads', false, error.message);
165
+ }
166
+
167
+ // 7. Test monitor functionality
168
+ console.log('\nšŸ“Š TESTING MONITOR FUNCTIONALITY\n');
169
+
170
+ try {
171
+ const { SDKMonitor } = require('../src/sdk/index.cjs');
172
+
173
+ const monitor = new SDKMonitor({ persistMetrics: false });
174
+
175
+ check(
176
+ 'Monitor instantiates',
177
+ monitor !== null,
178
+ 'Monitor object created'
179
+ );
180
+
181
+ check(
182
+ 'Monitor tracks metrics',
183
+ monitor.metrics !== undefined,
184
+ 'Metrics object exists'
185
+ );
186
+
187
+ check(
188
+ 'Monitor calculates savings',
189
+ typeof monitor.calculateSavings === 'function',
190
+ 'Savings calculation available'
191
+ );
192
+
193
+ // Test savings calculation
194
+ const savings = monitor.calculateSavings(1000);
195
+ check(
196
+ 'Savings calculation works',
197
+ savings > 0,
198
+ `1000 tokens → ${savings.toFixed(0)} saved`
199
+ );
200
+
201
+ // Test report generation
202
+ monitor.metrics.tokensBefore = 10000;
203
+ monitor.metrics.tokensAfter = 1000;
204
+ monitor.metrics.totalCostSaved = 0.027;
205
+ monitor.metrics.operations = 5;
206
+
207
+ const report = monitor.getSavingsReport();
208
+ check(
209
+ 'Report generation works',
210
+ report.summary !== undefined,
211
+ `Operations: ${report.summary.operations}, Savings: ${report.summary.costSaved}`
212
+ );
213
+ } catch (error) {
214
+ check('Monitor functionality', false, error.message);
215
+ }
216
+
217
+ // 8. Test configuration
218
+ console.log('\nāš™ļø TESTING CONFIGURATION\n');
219
+
220
+ try {
221
+ const { getSDKConfig, isSDKEnabled } = require('../src/sdk/index.cjs');
222
+
223
+ const config = getSDKConfig();
224
+
225
+ check(
226
+ 'Config loads',
227
+ config !== null,
228
+ 'Configuration object returned'
229
+ );
230
+
231
+ check(
232
+ 'Config has required fields',
233
+ config.caching !== undefined && config.contextEditing !== undefined,
234
+ `Caching: ${config.caching}, Context: ${config.contextEditing}`
235
+ );
236
+
237
+ // Test enable/disable
238
+ const originalMode = process.env.SDK_INTEGRATION_MODE;
239
+
240
+ process.env.SDK_INTEGRATION_MODE = 'parallel';
241
+ const enabledParallel = isSDKEnabled();
242
+
243
+ process.env.SDK_INTEGRATION_MODE = 'disabled';
244
+ const disabledMode = isSDKEnabled();
245
+
246
+ process.env.SDK_INTEGRATION_MODE = originalMode;
247
+
248
+ check(
249
+ 'Enable/disable works',
250
+ enabledParallel === true && disabledMode === false,
251
+ 'Integration mode control functional'
252
+ );
253
+ } catch (error) {
254
+ check('Configuration', false, error.message);
255
+ }
256
+
257
+ // Summary
258
+ console.log('\n' + '='.repeat(70));
259
+ console.log('šŸ“‹ VERIFICATION SUMMARY');
260
+ console.log('='.repeat(70) + '\n');
261
+
262
+ const passed = results.filter(r => r.passed).length;
263
+ const total = results.length;
264
+ const percentage = ((passed / total) * 100).toFixed(1);
265
+
266
+ console.log(`Tests Passed: ${passed}/${total} (${percentage}%)`);
267
+
268
+ if (allPassed) {
269
+ console.log('\nāœ… PHASE 1 IMPLEMENTATION VERIFIED SUCCESSFULLY\n');
270
+ console.log('All components are in place and functional:');
271
+ console.log(' • SDK configuration with extended caching and context editing');
272
+ console.log(' • Token usage monitoring and cost tracking');
273
+ console.log(' • Integration layer with easy-to-use API');
274
+ console.log(' • Test suite for validation');
275
+ console.log(' • Comprehensive documentation');
276
+ console.log(' • Environment configuration');
277
+ console.log('\nNext steps:');
278
+ console.log(' 1. Set CLAUDE_API_KEY in .env');
279
+ console.log(' 2. Run: node src/sdk/index.cjs');
280
+ console.log(' 3. Start using SDK with executeWithTracking()');
281
+ console.log(' 4. Monitor savings with getSavingsReport()');
282
+ } else {
283
+ console.log('\nāš ļø SOME VERIFICATIONS FAILED\n');
284
+ console.log('Please review the failed checks above and ensure:');
285
+ console.log(' • All files are created in correct locations');
286
+ console.log(' • Package dependencies are installed');
287
+ console.log(' • Environment variables are configured');
288
+ console.log(' • No syntax errors in SDK modules');
289
+ }
290
+
291
+ console.log('\n' + '='.repeat(70) + '\n');
292
+
293
+ process.exit(allPassed ? 0 : 1);
@@ -105,6 +105,7 @@ async function readClaudeMdTemplate() {
105
105
  for (const templatePath of possiblePaths) {
106
106
  try {
107
107
  const content = await fs.readFile(templatePath, 'utf8');
108
+ console.log(`āœ… Using CLAUDE.md template from: ${templatePath}`);
108
109
  return content;
109
110
  } catch (error) {
110
111
  // Try next path
@@ -112,9 +113,8 @@ async function readClaudeMdTemplate() {
112
113
  }
113
114
  }
114
115
 
115
- // Fallback to generating if template file is not found in any location
116
- console.warn('Warning: Template file not found in any location, using generated content');
117
- return createOptimizedSparcClaudeMd();
116
+ // If template not found, throw error instead of falling back
117
+ throw new Error('CLAUDE.md template file not found! Please ensure templates are included in the build.');
118
118
  }
119
119
 
120
120
  /**
@@ -7,16 +7,34 @@
7
7
  * Keeps it focused and lightweight - no bloat!
8
8
  */
9
9
 
10
- import { ClaudeMdGenerator } from '../language/claude-md-generator.js';
11
- import { LanguageDetector } from '../language/language-detector.js';
12
10
  import fs from 'fs/promises';
13
11
  import path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+ import { dirname } from 'path';
14
14
 
15
15
  export class ClaudeMdSlashCommand {
16
16
  constructor(projectPath = process.cwd()) {
17
17
  this.projectPath = projectPath;
18
18
  this.claudeMdPath = path.join(projectPath, 'CLAUDE.md');
19
19
  this.copyToMainPath = path.join(projectPath, 'claude-copy-to-main.md');
20
+
21
+ // Get the directory of this module to find the template
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = dirname(__filename);
24
+ this.templatePath = path.join(__dirname, '..', 'cli', 'simple-commands', 'init', 'templates', 'CLAUDE.md');
25
+ }
26
+
27
+ /**
28
+ * Read the CLAUDE.md template file
29
+ */
30
+ async readTemplate() {
31
+ try {
32
+ const content = await fs.readFile(this.templatePath, 'utf8');
33
+ console.log('āœ… Using CLAUDE.md template');
34
+ return content;
35
+ } catch (error) {
36
+ throw new Error(`CLAUDE.md template not found at ${this.templatePath}`);
37
+ }
20
38
  }
21
39
 
22
40
  /**
@@ -37,13 +55,8 @@ export class ClaudeMdSlashCommand {
37
55
  const existingClaudeExists = await this.fileExists(this.claudeMdPath);
38
56
  const shouldUseNpxProtection = isNpxInstall && existingClaudeExists;
39
57
 
40
- // Step 2: Generate content using existing system
41
- const generator = new ClaudeMdGenerator(this.projectPath, {
42
- backupExisting: backup && !shouldUseNpxProtection,
43
- preserveCustomSections: true
44
- });
45
-
46
- const newContent = await generator.generateClaudeMd();
58
+ // Step 2: Read template content (no language detection, just use template)
59
+ const newContent = await this.readTemplate();
47
60
 
48
61
  // Step 3: Handle NPX protection
49
62
  if (shouldUseNpxProtection) {