claude-flow-novice 2.2.4 → 2.2.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.
- package/package.json +9 -8
- package/scripts/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/.claude-flow/metrics/performance.json +9 -0
- package/scripts/.claude-flow/metrics/task-metrics.json +10 -0
- package/scripts/CLEANUP_OPTIMIZATION_REPORT.json +312 -0
- package/scripts/CLEANUP_PERFORMANCE_OPTIMIZATION.md +387 -0
- package/scripts/CLEANUP_QUICK_START.md +268 -0
- package/scripts/CLEANUP_TEST_RESULTS.md +205 -0
- package/scripts/README.md +339 -0
- package/scripts/ace-query.sh +384 -0
- package/scripts/agent-token-analysis.js +430 -0
- package/scripts/auto-setup.js +332 -0
- package/scripts/build/README.md +167 -0
- package/scripts/build/build-config.js +27 -0
- package/scripts/build/build-prompt-copier.sh +30 -0
- package/scripts/build/performance-monitor.js +869 -0
- package/scripts/build/prepare-publish.js +150 -0
- package/scripts/build/typescript-fixer.js +621 -0
- package/scripts/build/unified-builder.sh +428 -0
- package/scripts/build/update-bin-version.js +32 -0
- package/scripts/build/validate-agents.js +238 -0
- package/scripts/build-index.js +43 -0
- package/scripts/build-orchestrator.js +320 -0
- package/scripts/check-routing-stats.cjs +122 -0
- package/scripts/ci-validation.js +375 -0
- package/scripts/cleanup-blocking-coordination.sh +420 -0
- package/scripts/cleanup-idle-sessions.sh +59 -0
- package/scripts/collect-build-metrics.js +65 -0
- package/scripts/demo/README.md +79 -0
- package/scripts/demo/autoscaling-demo-simplified.js +963 -0
- package/scripts/demo/comprehensive-dashboard-test.js +693 -0
- package/scripts/demo/confidence-log.js +87 -0
- package/scripts/demo/confidence-report.js +82 -0
- package/scripts/demo/demo-multi-swarm-coordination.js +325 -0
- package/scripts/demo/demo-production-deployment.js +399 -0
- package/scripts/demo/demo-visualization-system.js +149 -0
- package/scripts/demo/performance-analysis.cjs +71 -0
- package/scripts/demo/performance-analysis.js +71 -0
- package/scripts/demo/test-autoscaling-demo.js +314 -0
- package/scripts/dependency-optimizer.js +349 -0
- package/scripts/dependency-security-assessment.js +331 -0
- package/scripts/deploy-sdk.sh +176 -0
- package/scripts/deployment-readiness-report.json +179 -0
- package/scripts/dev/README.md +264 -0
- package/scripts/dev/claude-flow-wrapper.sh +35 -0
- package/scripts/dev/claude-monitor.py +419 -0
- package/scripts/dev/claude-sparc.sh +562 -0
- package/scripts/dev/claude-wrapper.sh +17 -0
- package/scripts/dev/demo-phase3-compliance.js +172 -0
- package/scripts/dev/demo-task-system.ts +224 -0
- package/scripts/dev/deployment-validator.js +315 -0
- package/scripts/dev/spawn-claude-terminal.sh +32 -0
- package/scripts/dev/start-portal.sh +506 -0
- package/scripts/dev/start-web-ui.js +15 -0
- package/scripts/dev/stop-portal.sh +311 -0
- package/scripts/dev/validate-examples.ts +288 -0
- package/scripts/dev/validate-phase2.cjs +451 -0
- package/scripts/dev/validate-phase2.js +785 -0
- package/scripts/dev/validate-phase3.cjs +208 -0
- package/scripts/dev/validate-security-remediation.js +1 -0
- package/scripts/ecosystem.config.cjs +90 -0
- package/scripts/fix-js-extensions.js +167 -0
- package/scripts/generate-basic-types.js +73 -0
- package/scripts/generate-changelog.js +318 -0
- package/scripts/git-hooks/pre-commit.sh +143 -0
- package/scripts/health-checks.js +634 -0
- package/scripts/hook-wrapper.sh +54 -0
- package/scripts/install/README.md +375 -0
- package/scripts/install/REDIS_SETUP_VALIDATION.json +245 -0
- package/scripts/install/check-prerequisites.js +303 -0
- package/scripts/install/config-wizard.js +606 -0
- package/scripts/install/dependency-checker.js +385 -0
- package/scripts/install/health-check.js +765 -0
- package/scripts/install/install.js +256 -0
- package/scripts/install/installation-benchmark.js +461 -0
- package/scripts/install/quick-install.js +720 -0
- package/scripts/install/quick-start-wizard.js +295 -0
- package/scripts/install/redis-cli.js +289 -0
- package/scripts/install/redis-install-guides.md +407 -0
- package/scripts/install/redis-setup.js +559 -0
- package/scripts/install/redis-test.js +278 -0
- package/scripts/install/service-manager.js +672 -0
- package/scripts/install/setup.js +832 -0
- package/scripts/install/uninstall.js +526 -0
- package/scripts/install/update.js +461 -0
- package/scripts/install-pre-commit-hook.sh +127 -0
- package/scripts/legacy/README.md +272 -0
- package/scripts/legacy/batch-fix-ts.sh +54 -0
- package/scripts/legacy/build-migration.sh +105 -0
- package/scripts/legacy/build-monitor.js +209 -0
- package/scripts/legacy/build-with-filter.sh +84 -0
- package/scripts/legacy/build-workaround.sh +71 -0
- package/scripts/legacy/fix-ts-advanced.js +358 -0
- package/scripts/legacy/fix-ts-final.sh +50 -0
- package/scripts/legacy/fix-ts-targeted.sh +49 -0
- package/scripts/legacy/fix-typescript-errors.js +305 -0
- package/scripts/legacy/force-build.sh +63 -0
- package/scripts/legacy/optimize-performance.js +400 -0
- package/scripts/legacy/performance-monitor.js +263 -0
- package/scripts/legacy/performance-monitoring.js +532 -0
- package/scripts/legacy/performance-test-runner.js +645 -0
- package/scripts/legacy/quick-fix-ts.js +281 -0
- package/scripts/legacy/safe-build.sh +63 -0
- package/scripts/memory-monitor-coordinator.js +322 -0
- package/scripts/migrate-to-sdk.sh +520 -0
- package/scripts/migration/QUICK-START.md +189 -0
- package/scripts/migration/QUICK-START.md.backup-1760135091363 +189 -0
- package/scripts/migration/README.md +464 -0
- package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md +500 -0
- package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md.backup-1760135091348 +500 -0
- package/scripts/migration/UPDATE-PATHS-README.md +464 -0
- package/scripts/migration/UPDATE-PATHS-README.md.backup-1760135091337 +464 -0
- package/scripts/migration/example-patterns.json +19 -0
- package/scripts/migration/install-arm64.js +78 -0
- package/scripts/migration/install.js +83 -0
- package/scripts/migration/migrate-hooks.js +173 -0
- package/scripts/migration/migration-examples.ts +318 -0
- package/scripts/migration/reorganize-workspace.js +504 -0
- package/scripts/migration/test-update-paths.js +359 -0
- package/scripts/migration/update-paths.js +664 -0
- package/scripts/migration/validate-migration.js +647 -0
- package/scripts/monitor-loop.sh +65 -0
- package/scripts/monitor-memory.sh +47 -0
- package/scripts/monitor-migration.js +339 -0
- package/scripts/monitor.py +43 -0
- package/scripts/monitoring/README.md +178 -0
- package/scripts/monitoring/alert-monitor.sh +220 -0
- package/scripts/monitoring/analyze-resources.sh +199 -0
- package/scripts/monitoring/dashboards/rate-limiting-dashboard.json +211 -0
- package/scripts/monitoring/dynamic-monitor.sh +85 -0
- package/scripts/monitoring/launch-stability-test.sh +184 -0
- package/scripts/monitoring/monitor-test.sh +93 -0
- package/scripts/monitoring/pre-test-validation.sh +208 -0
- package/scripts/monitoring/quick-test-alerting.sh +118 -0
- package/scripts/monitoring/quick-test-rate-limiting.sh +206 -0
- package/scripts/monitoring/rate-limiting-monitor.sh +380 -0
- package/scripts/monitoring/resource-monitor.sh +126 -0
- package/scripts/monitoring/stability-monitor.js +429 -0
- package/scripts/monitoring/test-monitor-quick.sh +54 -0
- package/scripts/monitoring/view-alerts.sh +307 -0
- package/scripts/npm-metrics-collector.js +482 -0
- package/scripts/npm-package-validation.cjs +299 -0
- package/scripts/optimization/build-optimizer.js +438 -0
- package/scripts/optimization/config-validator.js +761 -0
- package/scripts/optimization/test-optimization.js +432 -0
- package/scripts/optimization/unified-activation.js +839 -0
- package/scripts/optimize-package-swarm.js +54 -0
- package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
- package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
- package/scripts/performance/test-enhanced-backend.sh +504 -0
- package/scripts/performance-monitor.js +644 -0
- package/scripts/performance-test-runner.js +698 -0
- package/scripts/post-deployment-monitoring.js +350 -0
- package/scripts/post-edit-pipeline.js +2091 -0
- package/scripts/post-install-claude-md.js +78 -0
- package/scripts/postinstall.js +79 -0
- package/scripts/pre-publish-validation.cjs +212 -0
- package/scripts/pre-publish-validation.js +429 -0
- package/scripts/redis-lua/cleanup-blocking-coordination.lua +198 -0
- package/scripts/release-announcement.js +425 -0
- package/scripts/release-notification.js +248 -0
- package/scripts/release-rollback.js +376 -0
- package/scripts/release-validation.js +460 -0
- package/scripts/rollback-sdk.sh +66 -0
- package/scripts/run-production-validation.ts +590 -0
- package/scripts/run-stability-validation.sh +687 -0
- package/scripts/security/README.md +339 -0
- package/scripts/security/deployment-validation.cjs +279 -0
- package/scripts/security/envelope-encryption-confidence-report.cjs +422 -0
- package/scripts/security/install-git-hooks.sh +132 -0
- package/scripts/security/install-git-secrets.sh +295 -0
- package/scripts/security/rotate-api-keys.js +469 -0
- package/scripts/security/ruv-swarm-safe.js +74 -0
- package/scripts/security/security-audit.cjs +538 -0
- package/scripts/security/setup-redis-auth.sh +397 -0
- package/scripts/security/validate-envelope-encryption.cjs +340 -0
- package/scripts/security-scan.js +492 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
- package/scripts/switch-api.sh +158 -0
- package/scripts/sync-agents.js +290 -0
- package/scripts/test/50-agent-test.js +625 -0
- package/scripts/test/NEW_STABILITY_TEST_GUIDE.md +407 -0
- package/scripts/test/README.md +236 -0
- package/scripts/test/STABILITY_TEST_EXAMPLE.md +347 -0
- package/scripts/test/STABILITY_TEST_README.md +480 -0
- package/scripts/test/agent-worker.js +309 -0
- package/scripts/test/ai-coordination-test.js +650 -0
- package/scripts/test/ai-mesh-coordination-test.js +416 -0
- package/scripts/test/check-links.ts +274 -0
- package/scripts/test/check-performance-regression.ts +168 -0
- package/scripts/test/cli-agent-coordination-test.js +313 -0
- package/scripts/test/coordinator-multilingual-test.js +396 -0
- package/scripts/test/coordinator-transparency-demo.js +585 -0
- package/scripts/test/coverage-report.ts +692 -0
- package/scripts/test/generate-swarm-tests.js +633 -0
- package/scripts/test/integration-test-validation.cjs +253 -0
- package/scripts/test/load-test-swarm.js +576 -0
- package/scripts/test/mesh-coordination-zero-overlap-test.js +740 -0
- package/scripts/test/multilingual-hello-world-test.js +390 -0
- package/scripts/test/quick-multilingual-demo.js +464 -0
- package/scripts/test/real-agent-test.js +312 -0
- package/scripts/test/run-phase3-compliance-tests.js +427 -0
- package/scripts/test/run-stability-test-examples.sh +292 -0
- package/scripts/test/stability-results/stability-metrics.jsonl +83 -0
- package/scripts/test/stability-results/stability-test-report.json +128 -0
- package/scripts/test/stability-results/stability-test.log +1827 -0
- package/scripts/test/stability-test-50-agents.js +734 -0
- package/scripts/test/test-batch-tasks.ts +29 -0
- package/scripts/test/test-byzantine-resolution.js +246 -0
- package/scripts/test/test-claude-spawn-options.sh +63 -0
- package/scripts/test/test-cli-wizard.js +331 -0
- package/scripts/test/test-comprehensive.js +401 -0
- package/scripts/test/test-coordination-features.ts +238 -0
- package/scripts/test/test-fallback-systems.js +276 -0
- package/scripts/test/test-init-command.ts +302 -0
- package/scripts/test/test-mcp.ts +251 -0
- package/scripts/test/test-runner.ts +568 -0
- package/scripts/test/test-swarm-integration.sh +92 -0
- package/scripts/test/test-swarm.ts +142 -0
- package/scripts/test/validation-summary.ts +408 -0
- package/scripts/test-cleanup-performance.sh +416 -0
- package/scripts/test-dashboard-auth.cjs +203 -0
- package/scripts/test-docker-deployment.sh +207 -0
- package/scripts/test-npm-package.cjs +167 -0
- package/scripts/test-provider-routing.cjs +226 -0
- package/scripts/test-routing-telemetry.cjs +147 -0
- package/scripts/test-runner.cjs +154 -0
- package/scripts/test-zai-10k.cjs +81 -0
- package/scripts/test-zai-api.cjs +191 -0
- package/scripts/test-zai-diagnostic.cjs +151 -0
- package/scripts/test-zai-final.cjs +128 -0
- package/scripts/test-zai-with-env.cjs +85 -0
- package/scripts/utils/README.md +261 -0
- package/scripts/utils/clean-build-artifacts.sh +94 -0
- package/scripts/utils/cleanup-root.sh +69 -0
- package/scripts/utils/fix-cliffy-imports.js +307 -0
- package/scripts/utils/fix-duplicate-imports.js +114 -0
- package/scripts/utils/fix-error-handling.cjs +70 -0
- package/scripts/utils/fix-import-paths.js +104 -0
- package/scripts/utils/fix-imports.js +116 -0
- package/scripts/utils/fix-shebang.js +78 -0
- package/scripts/utils/fix-test-modules.js +27 -0
- package/scripts/utils/fix-timezone-issue-246.js +200 -0
- package/scripts/utils/fix-ts-comprehensive.py +182 -0
- package/scripts/utils/fix-ts-targeted-batch.js +250 -0
- package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
- package/scripts/utils/simple-test-fixer.js +190 -0
- package/scripts/utils/validate-metrics-structure.cjs +144 -0
- package/scripts/validate-agent-hooks.js +506 -0
- package/scripts/validate-changelog.js +241 -0
- package/scripts/validate-coordination-cli.js +69 -0
- package/scripts/validate-coordination-toggle-integration.cjs +501 -0
- package/scripts/validate-docker-infrastructure.sh +502 -0
- package/scripts/validate-entry-points.js +300 -0
- package/scripts/validate-stage3-performance.ts +377 -0
- package/scripts/validate-template-bundling.js +180 -0
- package/scripts/validation/README.md +33 -0
- package/scripts/validation/acl-security-validation.cjs +214 -0
- package/scripts/validation/acl-security-validation.js +402 -0
- package/scripts/validation/byzantine-verification.js +407 -0
- package/scripts/validation/final-phase-2-consensus.cjs +219 -0
- package/scripts/validation/final-security-validation.js +791 -0
- package/scripts/validation/final-wasm-validation.cjs +840 -0
- package/scripts/validation/integration-test-analysis.js +105 -0
- package/scripts/validation/phase-0-comprehensive-validation.js +474 -0
- package/scripts/validation/phase-0-consensus-report.js +139 -0
- package/scripts/validation/phase-0-final-report.js +112 -0
- package/scripts/validation/phase-0-redis-consensus-report.js +129 -0
- package/scripts/validation/phase-0-validation-improved.js +490 -0
- package/scripts/validation/phase-0-validation-test.js +65 -0
- package/scripts/validation/phase-1-consensus-report.cjs +342 -0
- package/scripts/validation/phase-1-consensus-validation.cjs +551 -0
- package/scripts/validation/phase-1-consensus-validation.js +551 -0
- package/scripts/validation/phase-2-consensus-report.cjs +186 -0
- package/scripts/validation/phase-2-validation.cjs +171 -0
- package/scripts/validation/phase-2-validation.js +171 -0
- package/scripts/validation/phase-4-consensus-report.js +181 -0
- package/scripts/validation/phase-4-final-validation.js +351 -0
- package/scripts/validation/phase-5-consensus-report.cjs +113 -0
- package/scripts/validation/phase-5-consensus-report.js +113 -0
- package/scripts/validation/security-analysis.js +49 -0
- package/scripts/validation/security-validation.js +492 -0
- package/scripts/validation/simple-security-validation.js +464 -0
- package/scripts/verify-installation.js +112 -0
- package/scripts/verify-mcp-server.js +86 -0
- package/scripts/verify-sdk-phase1.cjs +293 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* NPM Package Metrics Collector
|
|
5
|
+
*
|
|
6
|
+
* Collects and reports metrics for claude-flow-novice NPM package:
|
|
7
|
+
* - Download statistics
|
|
8
|
+
* - Installation success rate
|
|
9
|
+
* - Version adoption tracking
|
|
10
|
+
* - Error reporting and analytics
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import https from 'https';
|
|
14
|
+
import fs from 'fs/promises';
|
|
15
|
+
import path from 'path';
|
|
16
|
+
import { EventEmitter } from 'events';
|
|
17
|
+
|
|
18
|
+
export class NPMMetricsCollector extends EventEmitter {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
|
|
22
|
+
this.packageName = options.packageName || 'claude-flow-novice';
|
|
23
|
+
this.metricsDir = options.metricsDir || './logs/npm-metrics';
|
|
24
|
+
this.apiBaseURL = 'https://api.npmjs.org';
|
|
25
|
+
this.registryURL = 'https://registry.npmjs.org';
|
|
26
|
+
|
|
27
|
+
// Metrics cache
|
|
28
|
+
this.cache = {
|
|
29
|
+
downloads: null,
|
|
30
|
+
versions: null,
|
|
31
|
+
packageInfo: null,
|
|
32
|
+
lastUpdate: null
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Installation tracking
|
|
36
|
+
this.installations = {
|
|
37
|
+
successful: 0,
|
|
38
|
+
failed: 0,
|
|
39
|
+
errors: []
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
this.ensureMetricsDir();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async ensureMetricsDir() {
|
|
46
|
+
try {
|
|
47
|
+
await fs.mkdir(this.metricsDir, { recursive: true });
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error('Failed to create metrics directory:', error.message);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Fetch download statistics from NPM API
|
|
55
|
+
*/
|
|
56
|
+
async getDownloadStats(period = 'last-day') {
|
|
57
|
+
const validPeriods = ['last-day', 'last-week', 'last-month'];
|
|
58
|
+
if (!validPeriods.includes(period)) {
|
|
59
|
+
period = 'last-day';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const url = `${this.apiBaseURL}/downloads/point/${period}/${this.packageName}`;
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const data = await this.fetchJSON(url);
|
|
66
|
+
|
|
67
|
+
const stats = {
|
|
68
|
+
downloads: data.downloads || 0,
|
|
69
|
+
period: period,
|
|
70
|
+
package: data.package,
|
|
71
|
+
start: data.start,
|
|
72
|
+
end: data.end,
|
|
73
|
+
timestamp: new Date().toISOString()
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
this.cache.downloads = stats;
|
|
77
|
+
await this.saveMetrics('downloads', stats);
|
|
78
|
+
this.emit('downloads:collected', stats);
|
|
79
|
+
|
|
80
|
+
return stats;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error('Failed to fetch download stats:', error.message);
|
|
83
|
+
return {
|
|
84
|
+
downloads: 0,
|
|
85
|
+
period,
|
|
86
|
+
error: error.message,
|
|
87
|
+
timestamp: new Date().toISOString()
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get download trends over time
|
|
94
|
+
*/
|
|
95
|
+
async getDownloadTrends() {
|
|
96
|
+
const periods = ['last-day', 'last-week', 'last-month'];
|
|
97
|
+
const trends = {};
|
|
98
|
+
|
|
99
|
+
for (const period of periods) {
|
|
100
|
+
trends[period] = await this.getDownloadStats(period);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
trends,
|
|
105
|
+
growth: this.calculateGrowth(trends),
|
|
106
|
+
timestamp: new Date().toISOString()
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Calculate download growth rate
|
|
112
|
+
*/
|
|
113
|
+
calculateGrowth(trends) {
|
|
114
|
+
const daily = trends['last-day']?.downloads || 0;
|
|
115
|
+
const weekly = (trends['last-week']?.downloads || 0) / 7;
|
|
116
|
+
const monthly = (trends['last-month']?.downloads || 0) / 30;
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
dailyAverage: Math.round(daily),
|
|
120
|
+
weeklyAverage: Math.round(weekly),
|
|
121
|
+
monthlyAverage: Math.round(monthly),
|
|
122
|
+
weekOverDay: weekly > 0 ? ((daily - weekly) / weekly * 100).toFixed(2) : 0,
|
|
123
|
+
monthOverWeek: monthly > 0 ? ((weekly - monthly) / monthly * 100).toFixed(2) : 0
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get package version information
|
|
129
|
+
*/
|
|
130
|
+
async getVersionInfo() {
|
|
131
|
+
const url = `${this.registryURL}/${this.packageName}`;
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const data = await this.fetchJSON(url);
|
|
135
|
+
|
|
136
|
+
const versions = Object.keys(data.versions || {});
|
|
137
|
+
const latestVersion = data['dist-tags']?.latest || 'unknown';
|
|
138
|
+
const allTags = data['dist-tags'] || {};
|
|
139
|
+
|
|
140
|
+
const versionInfo = {
|
|
141
|
+
package: this.packageName,
|
|
142
|
+
latestVersion,
|
|
143
|
+
totalVersions: versions.length,
|
|
144
|
+
versions: versions.sort((a, b) => {
|
|
145
|
+
// Semver sorting
|
|
146
|
+
const aParts = a.split('.').map(Number);
|
|
147
|
+
const bParts = b.split('.').map(Number);
|
|
148
|
+
for (let i = 0; i < 3; i++) {
|
|
149
|
+
if (aParts[i] !== bParts[i]) {
|
|
150
|
+
return bParts[i] - aParts[i];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return 0;
|
|
154
|
+
}),
|
|
155
|
+
tags: allTags,
|
|
156
|
+
created: data.time?.created,
|
|
157
|
+
modified: data.time?.modified,
|
|
158
|
+
timestamp: new Date().toISOString()
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
this.cache.versions = versionInfo;
|
|
162
|
+
await this.saveMetrics('versions', versionInfo);
|
|
163
|
+
this.emit('versions:collected', versionInfo);
|
|
164
|
+
|
|
165
|
+
return versionInfo;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error('Failed to fetch version info:', error.message);
|
|
168
|
+
return {
|
|
169
|
+
error: error.message,
|
|
170
|
+
timestamp: new Date().toISOString()
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Get version adoption statistics
|
|
177
|
+
*/
|
|
178
|
+
async getVersionAdoption() {
|
|
179
|
+
const versionInfo = await this.getVersionInfo();
|
|
180
|
+
const trends = await this.getDownloadTrends();
|
|
181
|
+
|
|
182
|
+
// In real scenario, we'd track which versions are being downloaded
|
|
183
|
+
// For now, providing framework for this data
|
|
184
|
+
return {
|
|
185
|
+
latestVersion: versionInfo.latestVersion,
|
|
186
|
+
totalVersions: versionInfo.totalVersions,
|
|
187
|
+
downloadTrends: trends,
|
|
188
|
+
adoptionRate: {
|
|
189
|
+
latest: '85%', // Placeholder - would be calculated from real data
|
|
190
|
+
previousMajor: '12%',
|
|
191
|
+
older: '3%'
|
|
192
|
+
},
|
|
193
|
+
recommendations: this.generateVersionRecommendations(versionInfo),
|
|
194
|
+
timestamp: new Date().toISOString()
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Generate version recommendations
|
|
200
|
+
*/
|
|
201
|
+
generateVersionRecommendations(versionInfo) {
|
|
202
|
+
const recommendations = [];
|
|
203
|
+
|
|
204
|
+
if (versionInfo.totalVersions > 50) {
|
|
205
|
+
recommendations.push({
|
|
206
|
+
type: 'cleanup',
|
|
207
|
+
priority: 'low',
|
|
208
|
+
message: 'Consider deprecating old versions to reduce version count'
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const latest = versionInfo.latestVersion;
|
|
213
|
+
if (latest && latest.includes('beta') || latest.includes('alpha')) {
|
|
214
|
+
recommendations.push({
|
|
215
|
+
type: 'stability',
|
|
216
|
+
priority: 'high',
|
|
217
|
+
message: 'Latest version is pre-release. Consider releasing a stable version'
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return recommendations;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Track installation success/failure
|
|
226
|
+
*/
|
|
227
|
+
async trackInstallation(success, error = null) {
|
|
228
|
+
if (success) {
|
|
229
|
+
this.installations.successful++;
|
|
230
|
+
} else {
|
|
231
|
+
this.installations.failed++;
|
|
232
|
+
if (error) {
|
|
233
|
+
this.installations.errors.push({
|
|
234
|
+
error: error.message || error,
|
|
235
|
+
timestamp: new Date().toISOString(),
|
|
236
|
+
stack: error.stack
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const stats = this.getInstallationStats();
|
|
242
|
+
await this.saveMetrics('installations', stats);
|
|
243
|
+
this.emit('installation:tracked', { success, error, stats });
|
|
244
|
+
|
|
245
|
+
return stats;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Get installation statistics
|
|
250
|
+
*/
|
|
251
|
+
getInstallationStats() {
|
|
252
|
+
const total = this.installations.successful + this.installations.failed;
|
|
253
|
+
const successRate = total > 0
|
|
254
|
+
? (this.installations.successful / total * 100).toFixed(2)
|
|
255
|
+
: 100;
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
successful: this.installations.successful,
|
|
259
|
+
failed: this.installations.failed,
|
|
260
|
+
total,
|
|
261
|
+
successRate: parseFloat(successRate),
|
|
262
|
+
errorSamples: this.installations.errors.slice(-10), // Last 10 errors
|
|
263
|
+
timestamp: new Date().toISOString()
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Report error with context
|
|
269
|
+
*/
|
|
270
|
+
async reportError(error, context = {}) {
|
|
271
|
+
const errorReport = {
|
|
272
|
+
error: {
|
|
273
|
+
message: error.message,
|
|
274
|
+
stack: error.stack,
|
|
275
|
+
name: error.name
|
|
276
|
+
},
|
|
277
|
+
context: {
|
|
278
|
+
...context,
|
|
279
|
+
packageVersion: context.version || 'unknown',
|
|
280
|
+
nodeVersion: process.version,
|
|
281
|
+
platform: process.platform,
|
|
282
|
+
arch: process.arch
|
|
283
|
+
},
|
|
284
|
+
timestamp: new Date().toISOString()
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
await this.saveMetrics('errors', errorReport);
|
|
288
|
+
this.emit('error:reported', errorReport);
|
|
289
|
+
|
|
290
|
+
return errorReport;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Get comprehensive package metrics
|
|
295
|
+
*/
|
|
296
|
+
async getComprehensiveMetrics() {
|
|
297
|
+
const [downloads, versions, adoption] = await Promise.all([
|
|
298
|
+
this.getDownloadTrends(),
|
|
299
|
+
this.getVersionInfo(),
|
|
300
|
+
this.getVersionAdoption()
|
|
301
|
+
]);
|
|
302
|
+
|
|
303
|
+
const installations = this.getInstallationStats();
|
|
304
|
+
|
|
305
|
+
const metrics = {
|
|
306
|
+
package: this.packageName,
|
|
307
|
+
downloads,
|
|
308
|
+
versions,
|
|
309
|
+
adoption,
|
|
310
|
+
installations,
|
|
311
|
+
health: this.calculatePackageHealth(downloads, installations),
|
|
312
|
+
timestamp: new Date().toISOString()
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
await this.saveMetrics('comprehensive', metrics);
|
|
316
|
+
this.emit('metrics:collected', metrics);
|
|
317
|
+
|
|
318
|
+
return metrics;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Calculate overall package health score
|
|
323
|
+
*/
|
|
324
|
+
calculatePackageHealth(downloads, installations) {
|
|
325
|
+
const scores = {
|
|
326
|
+
downloads: 0,
|
|
327
|
+
installations: 0,
|
|
328
|
+
overall: 0
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// Download health (based on daily average)
|
|
332
|
+
const dailyDownloads = downloads.trends['last-day']?.downloads || 0;
|
|
333
|
+
if (dailyDownloads > 100) scores.downloads = 100;
|
|
334
|
+
else if (dailyDownloads > 50) scores.downloads = 80;
|
|
335
|
+
else if (dailyDownloads > 10) scores.downloads = 60;
|
|
336
|
+
else scores.downloads = 40;
|
|
337
|
+
|
|
338
|
+
// Installation health (based on success rate)
|
|
339
|
+
scores.installations = installations.successRate;
|
|
340
|
+
|
|
341
|
+
// Overall health
|
|
342
|
+
scores.overall = Math.round((scores.downloads + scores.installations) / 2);
|
|
343
|
+
|
|
344
|
+
return {
|
|
345
|
+
scores,
|
|
346
|
+
status: scores.overall >= 80 ? 'healthy' : scores.overall >= 60 ? 'fair' : 'needs-attention',
|
|
347
|
+
timestamp: new Date().toISOString()
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Save metrics to file
|
|
353
|
+
*/
|
|
354
|
+
async saveMetrics(type, data) {
|
|
355
|
+
const filename = path.join(this.metricsDir, `${type}-${Date.now()}.json`);
|
|
356
|
+
|
|
357
|
+
try {
|
|
358
|
+
await fs.writeFile(filename, JSON.stringify(data, null, 2));
|
|
359
|
+
return filename;
|
|
360
|
+
} catch (error) {
|
|
361
|
+
console.error(`Failed to save ${type} metrics:`, error.message);
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Fetch JSON from URL
|
|
368
|
+
*/
|
|
369
|
+
fetchJSON(url) {
|
|
370
|
+
return new Promise((resolve, reject) => {
|
|
371
|
+
https.get(url, {
|
|
372
|
+
headers: {
|
|
373
|
+
'User-Agent': 'claude-flow-novice-metrics-collector'
|
|
374
|
+
}
|
|
375
|
+
}, (res) => {
|
|
376
|
+
let data = '';
|
|
377
|
+
|
|
378
|
+
res.on('data', (chunk) => {
|
|
379
|
+
data += chunk;
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
res.on('end', () => {
|
|
383
|
+
try {
|
|
384
|
+
resolve(JSON.parse(data));
|
|
385
|
+
} catch (error) {
|
|
386
|
+
reject(new Error(`Failed to parse JSON: ${error.message}`));
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}).on('error', (error) => {
|
|
390
|
+
reject(error);
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Start periodic metrics collection
|
|
397
|
+
*/
|
|
398
|
+
startPeriodicCollection(interval = 3600000) { // Default: 1 hour
|
|
399
|
+
console.log(`Starting periodic metrics collection (interval: ${interval}ms)`);
|
|
400
|
+
|
|
401
|
+
this.collectionInterval = setInterval(async () => {
|
|
402
|
+
try {
|
|
403
|
+
await this.getComprehensiveMetrics();
|
|
404
|
+
} catch (error) {
|
|
405
|
+
console.error('Periodic collection failed:', error.message);
|
|
406
|
+
}
|
|
407
|
+
}, interval);
|
|
408
|
+
|
|
409
|
+
// Collect immediately on start
|
|
410
|
+
this.getComprehensiveMetrics();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Stop periodic collection
|
|
415
|
+
*/
|
|
416
|
+
stopPeriodicCollection() {
|
|
417
|
+
if (this.collectionInterval) {
|
|
418
|
+
clearInterval(this.collectionInterval);
|
|
419
|
+
console.log('Stopped periodic metrics collection');
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// CLI interface
|
|
425
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
426
|
+
const collector = new NPMMetricsCollector();
|
|
427
|
+
|
|
428
|
+
const command = process.argv[2] || 'comprehensive';
|
|
429
|
+
|
|
430
|
+
switch (command) {
|
|
431
|
+
case 'downloads':
|
|
432
|
+
collector.getDownloadTrends().then(data => {
|
|
433
|
+
console.log(JSON.stringify(data, null, 2));
|
|
434
|
+
});
|
|
435
|
+
break;
|
|
436
|
+
|
|
437
|
+
case 'versions':
|
|
438
|
+
collector.getVersionInfo().then(data => {
|
|
439
|
+
console.log(JSON.stringify(data, null, 2));
|
|
440
|
+
});
|
|
441
|
+
break;
|
|
442
|
+
|
|
443
|
+
case 'adoption':
|
|
444
|
+
collector.getVersionAdoption().then(data => {
|
|
445
|
+
console.log(JSON.stringify(data, null, 2));
|
|
446
|
+
});
|
|
447
|
+
break;
|
|
448
|
+
|
|
449
|
+
case 'comprehensive':
|
|
450
|
+
collector.getComprehensiveMetrics().then(data => {
|
|
451
|
+
console.log(JSON.stringify(data, null, 2));
|
|
452
|
+
});
|
|
453
|
+
break;
|
|
454
|
+
|
|
455
|
+
case 'monitor':
|
|
456
|
+
const interval = parseInt(process.argv[3]) || 3600000;
|
|
457
|
+
collector.startPeriodicCollection(interval);
|
|
458
|
+
console.log('Monitoring started. Press Ctrl+C to stop.');
|
|
459
|
+
break;
|
|
460
|
+
|
|
461
|
+
default:
|
|
462
|
+
console.log(`
|
|
463
|
+
NPM Metrics Collector - claude-flow-novice
|
|
464
|
+
|
|
465
|
+
Usage:
|
|
466
|
+
node npm-metrics-collector.js [command]
|
|
467
|
+
|
|
468
|
+
Commands:
|
|
469
|
+
downloads - Get download statistics
|
|
470
|
+
versions - Get version information
|
|
471
|
+
adoption - Get version adoption stats
|
|
472
|
+
comprehensive - Get all metrics (default)
|
|
473
|
+
monitor [ms] - Start periodic collection
|
|
474
|
+
|
|
475
|
+
Examples:
|
|
476
|
+
node npm-metrics-collector.js downloads
|
|
477
|
+
node npm-metrics-collector.js monitor 1800000 # Monitor every 30 minutes
|
|
478
|
+
`);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export default NPMMetricsCollector;
|