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.
Files changed (288) hide show
  1. package/package.json +9 -8
  2. package/scripts/.claude-flow/metrics/agent-metrics.json +1 -0
  3. package/scripts/.claude-flow/metrics/performance.json +9 -0
  4. package/scripts/.claude-flow/metrics/task-metrics.json +10 -0
  5. package/scripts/CLEANUP_OPTIMIZATION_REPORT.json +312 -0
  6. package/scripts/CLEANUP_PERFORMANCE_OPTIMIZATION.md +387 -0
  7. package/scripts/CLEANUP_QUICK_START.md +268 -0
  8. package/scripts/CLEANUP_TEST_RESULTS.md +205 -0
  9. package/scripts/README.md +339 -0
  10. package/scripts/ace-query.sh +384 -0
  11. package/scripts/agent-token-analysis.js +430 -0
  12. package/scripts/auto-setup.js +332 -0
  13. package/scripts/build/README.md +167 -0
  14. package/scripts/build/build-config.js +27 -0
  15. package/scripts/build/build-prompt-copier.sh +30 -0
  16. package/scripts/build/performance-monitor.js +869 -0
  17. package/scripts/build/prepare-publish.js +150 -0
  18. package/scripts/build/typescript-fixer.js +621 -0
  19. package/scripts/build/unified-builder.sh +428 -0
  20. package/scripts/build/update-bin-version.js +32 -0
  21. package/scripts/build/validate-agents.js +238 -0
  22. package/scripts/build-index.js +43 -0
  23. package/scripts/build-orchestrator.js +320 -0
  24. package/scripts/check-routing-stats.cjs +122 -0
  25. package/scripts/ci-validation.js +375 -0
  26. package/scripts/cleanup-blocking-coordination.sh +420 -0
  27. package/scripts/cleanup-idle-sessions.sh +59 -0
  28. package/scripts/collect-build-metrics.js +65 -0
  29. package/scripts/demo/README.md +79 -0
  30. package/scripts/demo/autoscaling-demo-simplified.js +963 -0
  31. package/scripts/demo/comprehensive-dashboard-test.js +693 -0
  32. package/scripts/demo/confidence-log.js +87 -0
  33. package/scripts/demo/confidence-report.js +82 -0
  34. package/scripts/demo/demo-multi-swarm-coordination.js +325 -0
  35. package/scripts/demo/demo-production-deployment.js +399 -0
  36. package/scripts/demo/demo-visualization-system.js +149 -0
  37. package/scripts/demo/performance-analysis.cjs +71 -0
  38. package/scripts/demo/performance-analysis.js +71 -0
  39. package/scripts/demo/test-autoscaling-demo.js +314 -0
  40. package/scripts/dependency-optimizer.js +349 -0
  41. package/scripts/dependency-security-assessment.js +331 -0
  42. package/scripts/deploy-sdk.sh +176 -0
  43. package/scripts/deployment-readiness-report.json +179 -0
  44. package/scripts/dev/README.md +264 -0
  45. package/scripts/dev/claude-flow-wrapper.sh +35 -0
  46. package/scripts/dev/claude-monitor.py +419 -0
  47. package/scripts/dev/claude-sparc.sh +562 -0
  48. package/scripts/dev/claude-wrapper.sh +17 -0
  49. package/scripts/dev/demo-phase3-compliance.js +172 -0
  50. package/scripts/dev/demo-task-system.ts +224 -0
  51. package/scripts/dev/deployment-validator.js +315 -0
  52. package/scripts/dev/spawn-claude-terminal.sh +32 -0
  53. package/scripts/dev/start-portal.sh +506 -0
  54. package/scripts/dev/start-web-ui.js +15 -0
  55. package/scripts/dev/stop-portal.sh +311 -0
  56. package/scripts/dev/validate-examples.ts +288 -0
  57. package/scripts/dev/validate-phase2.cjs +451 -0
  58. package/scripts/dev/validate-phase2.js +785 -0
  59. package/scripts/dev/validate-phase3.cjs +208 -0
  60. package/scripts/dev/validate-security-remediation.js +1 -0
  61. package/scripts/ecosystem.config.cjs +90 -0
  62. package/scripts/fix-js-extensions.js +167 -0
  63. package/scripts/generate-basic-types.js +73 -0
  64. package/scripts/generate-changelog.js +318 -0
  65. package/scripts/git-hooks/pre-commit.sh +143 -0
  66. package/scripts/health-checks.js +634 -0
  67. package/scripts/hook-wrapper.sh +54 -0
  68. package/scripts/install/README.md +375 -0
  69. package/scripts/install/REDIS_SETUP_VALIDATION.json +245 -0
  70. package/scripts/install/check-prerequisites.js +303 -0
  71. package/scripts/install/config-wizard.js +606 -0
  72. package/scripts/install/dependency-checker.js +385 -0
  73. package/scripts/install/health-check.js +765 -0
  74. package/scripts/install/install.js +256 -0
  75. package/scripts/install/installation-benchmark.js +461 -0
  76. package/scripts/install/quick-install.js +720 -0
  77. package/scripts/install/quick-start-wizard.js +295 -0
  78. package/scripts/install/redis-cli.js +289 -0
  79. package/scripts/install/redis-install-guides.md +407 -0
  80. package/scripts/install/redis-setup.js +559 -0
  81. package/scripts/install/redis-test.js +278 -0
  82. package/scripts/install/service-manager.js +672 -0
  83. package/scripts/install/setup.js +832 -0
  84. package/scripts/install/uninstall.js +526 -0
  85. package/scripts/install/update.js +461 -0
  86. package/scripts/install-pre-commit-hook.sh +127 -0
  87. package/scripts/legacy/README.md +272 -0
  88. package/scripts/legacy/batch-fix-ts.sh +54 -0
  89. package/scripts/legacy/build-migration.sh +105 -0
  90. package/scripts/legacy/build-monitor.js +209 -0
  91. package/scripts/legacy/build-with-filter.sh +84 -0
  92. package/scripts/legacy/build-workaround.sh +71 -0
  93. package/scripts/legacy/fix-ts-advanced.js +358 -0
  94. package/scripts/legacy/fix-ts-final.sh +50 -0
  95. package/scripts/legacy/fix-ts-targeted.sh +49 -0
  96. package/scripts/legacy/fix-typescript-errors.js +305 -0
  97. package/scripts/legacy/force-build.sh +63 -0
  98. package/scripts/legacy/optimize-performance.js +400 -0
  99. package/scripts/legacy/performance-monitor.js +263 -0
  100. package/scripts/legacy/performance-monitoring.js +532 -0
  101. package/scripts/legacy/performance-test-runner.js +645 -0
  102. package/scripts/legacy/quick-fix-ts.js +281 -0
  103. package/scripts/legacy/safe-build.sh +63 -0
  104. package/scripts/memory-monitor-coordinator.js +322 -0
  105. package/scripts/migrate-to-sdk.sh +520 -0
  106. package/scripts/migration/QUICK-START.md +189 -0
  107. package/scripts/migration/QUICK-START.md.backup-1760135091363 +189 -0
  108. package/scripts/migration/README.md +464 -0
  109. package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md +500 -0
  110. package/scripts/migration/TASK-1.3.2-COMPLETION-REPORT.md.backup-1760135091348 +500 -0
  111. package/scripts/migration/UPDATE-PATHS-README.md +464 -0
  112. package/scripts/migration/UPDATE-PATHS-README.md.backup-1760135091337 +464 -0
  113. package/scripts/migration/example-patterns.json +19 -0
  114. package/scripts/migration/install-arm64.js +78 -0
  115. package/scripts/migration/install.js +83 -0
  116. package/scripts/migration/migrate-hooks.js +173 -0
  117. package/scripts/migration/migration-examples.ts +318 -0
  118. package/scripts/migration/reorganize-workspace.js +504 -0
  119. package/scripts/migration/test-update-paths.js +359 -0
  120. package/scripts/migration/update-paths.js +664 -0
  121. package/scripts/migration/validate-migration.js +647 -0
  122. package/scripts/monitor-loop.sh +65 -0
  123. package/scripts/monitor-memory.sh +47 -0
  124. package/scripts/monitor-migration.js +339 -0
  125. package/scripts/monitor.py +43 -0
  126. package/scripts/monitoring/README.md +178 -0
  127. package/scripts/monitoring/alert-monitor.sh +220 -0
  128. package/scripts/monitoring/analyze-resources.sh +199 -0
  129. package/scripts/monitoring/dashboards/rate-limiting-dashboard.json +211 -0
  130. package/scripts/monitoring/dynamic-monitor.sh +85 -0
  131. package/scripts/monitoring/launch-stability-test.sh +184 -0
  132. package/scripts/monitoring/monitor-test.sh +93 -0
  133. package/scripts/monitoring/pre-test-validation.sh +208 -0
  134. package/scripts/monitoring/quick-test-alerting.sh +118 -0
  135. package/scripts/monitoring/quick-test-rate-limiting.sh +206 -0
  136. package/scripts/monitoring/rate-limiting-monitor.sh +380 -0
  137. package/scripts/monitoring/resource-monitor.sh +126 -0
  138. package/scripts/monitoring/stability-monitor.js +429 -0
  139. package/scripts/monitoring/test-monitor-quick.sh +54 -0
  140. package/scripts/monitoring/view-alerts.sh +307 -0
  141. package/scripts/npm-metrics-collector.js +482 -0
  142. package/scripts/npm-package-validation.cjs +299 -0
  143. package/scripts/optimization/build-optimizer.js +438 -0
  144. package/scripts/optimization/config-validator.js +761 -0
  145. package/scripts/optimization/test-optimization.js +432 -0
  146. package/scripts/optimization/unified-activation.js +839 -0
  147. package/scripts/optimize-package-swarm.js +54 -0
  148. package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
  149. package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
  150. package/scripts/performance/test-enhanced-backend.sh +504 -0
  151. package/scripts/performance-monitor.js +644 -0
  152. package/scripts/performance-test-runner.js +698 -0
  153. package/scripts/post-deployment-monitoring.js +350 -0
  154. package/scripts/post-edit-pipeline.js +2091 -0
  155. package/scripts/post-install-claude-md.js +78 -0
  156. package/scripts/postinstall.js +79 -0
  157. package/scripts/pre-publish-validation.cjs +212 -0
  158. package/scripts/pre-publish-validation.js +429 -0
  159. package/scripts/redis-lua/cleanup-blocking-coordination.lua +198 -0
  160. package/scripts/release-announcement.js +425 -0
  161. package/scripts/release-notification.js +248 -0
  162. package/scripts/release-rollback.js +376 -0
  163. package/scripts/release-validation.js +460 -0
  164. package/scripts/rollback-sdk.sh +66 -0
  165. package/scripts/run-production-validation.ts +590 -0
  166. package/scripts/run-stability-validation.sh +687 -0
  167. package/scripts/security/README.md +339 -0
  168. package/scripts/security/deployment-validation.cjs +279 -0
  169. package/scripts/security/envelope-encryption-confidence-report.cjs +422 -0
  170. package/scripts/security/install-git-hooks.sh +132 -0
  171. package/scripts/security/install-git-secrets.sh +295 -0
  172. package/scripts/security/rotate-api-keys.js +469 -0
  173. package/scripts/security/ruv-swarm-safe.js +74 -0
  174. package/scripts/security/security-audit.cjs +538 -0
  175. package/scripts/security/setup-redis-auth.sh +397 -0
  176. package/scripts/security/validate-envelope-encryption.cjs +340 -0
  177. package/scripts/security-scan.js +492 -0
  178. package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
  179. package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
  180. package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
  181. package/scripts/switch-api.sh +158 -0
  182. package/scripts/sync-agents.js +290 -0
  183. package/scripts/test/50-agent-test.js +625 -0
  184. package/scripts/test/NEW_STABILITY_TEST_GUIDE.md +407 -0
  185. package/scripts/test/README.md +236 -0
  186. package/scripts/test/STABILITY_TEST_EXAMPLE.md +347 -0
  187. package/scripts/test/STABILITY_TEST_README.md +480 -0
  188. package/scripts/test/agent-worker.js +309 -0
  189. package/scripts/test/ai-coordination-test.js +650 -0
  190. package/scripts/test/ai-mesh-coordination-test.js +416 -0
  191. package/scripts/test/check-links.ts +274 -0
  192. package/scripts/test/check-performance-regression.ts +168 -0
  193. package/scripts/test/cli-agent-coordination-test.js +313 -0
  194. package/scripts/test/coordinator-multilingual-test.js +396 -0
  195. package/scripts/test/coordinator-transparency-demo.js +585 -0
  196. package/scripts/test/coverage-report.ts +692 -0
  197. package/scripts/test/generate-swarm-tests.js +633 -0
  198. package/scripts/test/integration-test-validation.cjs +253 -0
  199. package/scripts/test/load-test-swarm.js +576 -0
  200. package/scripts/test/mesh-coordination-zero-overlap-test.js +740 -0
  201. package/scripts/test/multilingual-hello-world-test.js +390 -0
  202. package/scripts/test/quick-multilingual-demo.js +464 -0
  203. package/scripts/test/real-agent-test.js +312 -0
  204. package/scripts/test/run-phase3-compliance-tests.js +427 -0
  205. package/scripts/test/run-stability-test-examples.sh +292 -0
  206. package/scripts/test/stability-results/stability-metrics.jsonl +83 -0
  207. package/scripts/test/stability-results/stability-test-report.json +128 -0
  208. package/scripts/test/stability-results/stability-test.log +1827 -0
  209. package/scripts/test/stability-test-50-agents.js +734 -0
  210. package/scripts/test/test-batch-tasks.ts +29 -0
  211. package/scripts/test/test-byzantine-resolution.js +246 -0
  212. package/scripts/test/test-claude-spawn-options.sh +63 -0
  213. package/scripts/test/test-cli-wizard.js +331 -0
  214. package/scripts/test/test-comprehensive.js +401 -0
  215. package/scripts/test/test-coordination-features.ts +238 -0
  216. package/scripts/test/test-fallback-systems.js +276 -0
  217. package/scripts/test/test-init-command.ts +302 -0
  218. package/scripts/test/test-mcp.ts +251 -0
  219. package/scripts/test/test-runner.ts +568 -0
  220. package/scripts/test/test-swarm-integration.sh +92 -0
  221. package/scripts/test/test-swarm.ts +142 -0
  222. package/scripts/test/validation-summary.ts +408 -0
  223. package/scripts/test-cleanup-performance.sh +416 -0
  224. package/scripts/test-dashboard-auth.cjs +203 -0
  225. package/scripts/test-docker-deployment.sh +207 -0
  226. package/scripts/test-npm-package.cjs +167 -0
  227. package/scripts/test-provider-routing.cjs +226 -0
  228. package/scripts/test-routing-telemetry.cjs +147 -0
  229. package/scripts/test-runner.cjs +154 -0
  230. package/scripts/test-zai-10k.cjs +81 -0
  231. package/scripts/test-zai-api.cjs +191 -0
  232. package/scripts/test-zai-diagnostic.cjs +151 -0
  233. package/scripts/test-zai-final.cjs +128 -0
  234. package/scripts/test-zai-with-env.cjs +85 -0
  235. package/scripts/utils/README.md +261 -0
  236. package/scripts/utils/clean-build-artifacts.sh +94 -0
  237. package/scripts/utils/cleanup-root.sh +69 -0
  238. package/scripts/utils/fix-cliffy-imports.js +307 -0
  239. package/scripts/utils/fix-duplicate-imports.js +114 -0
  240. package/scripts/utils/fix-error-handling.cjs +70 -0
  241. package/scripts/utils/fix-import-paths.js +104 -0
  242. package/scripts/utils/fix-imports.js +116 -0
  243. package/scripts/utils/fix-shebang.js +78 -0
  244. package/scripts/utils/fix-test-modules.js +27 -0
  245. package/scripts/utils/fix-timezone-issue-246.js +200 -0
  246. package/scripts/utils/fix-ts-comprehensive.py +182 -0
  247. package/scripts/utils/fix-ts-targeted-batch.js +250 -0
  248. package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
  249. package/scripts/utils/simple-test-fixer.js +190 -0
  250. package/scripts/utils/validate-metrics-structure.cjs +144 -0
  251. package/scripts/validate-agent-hooks.js +506 -0
  252. package/scripts/validate-changelog.js +241 -0
  253. package/scripts/validate-coordination-cli.js +69 -0
  254. package/scripts/validate-coordination-toggle-integration.cjs +501 -0
  255. package/scripts/validate-docker-infrastructure.sh +502 -0
  256. package/scripts/validate-entry-points.js +300 -0
  257. package/scripts/validate-stage3-performance.ts +377 -0
  258. package/scripts/validate-template-bundling.js +180 -0
  259. package/scripts/validation/README.md +33 -0
  260. package/scripts/validation/acl-security-validation.cjs +214 -0
  261. package/scripts/validation/acl-security-validation.js +402 -0
  262. package/scripts/validation/byzantine-verification.js +407 -0
  263. package/scripts/validation/final-phase-2-consensus.cjs +219 -0
  264. package/scripts/validation/final-security-validation.js +791 -0
  265. package/scripts/validation/final-wasm-validation.cjs +840 -0
  266. package/scripts/validation/integration-test-analysis.js +105 -0
  267. package/scripts/validation/phase-0-comprehensive-validation.js +474 -0
  268. package/scripts/validation/phase-0-consensus-report.js +139 -0
  269. package/scripts/validation/phase-0-final-report.js +112 -0
  270. package/scripts/validation/phase-0-redis-consensus-report.js +129 -0
  271. package/scripts/validation/phase-0-validation-improved.js +490 -0
  272. package/scripts/validation/phase-0-validation-test.js +65 -0
  273. package/scripts/validation/phase-1-consensus-report.cjs +342 -0
  274. package/scripts/validation/phase-1-consensus-validation.cjs +551 -0
  275. package/scripts/validation/phase-1-consensus-validation.js +551 -0
  276. package/scripts/validation/phase-2-consensus-report.cjs +186 -0
  277. package/scripts/validation/phase-2-validation.cjs +171 -0
  278. package/scripts/validation/phase-2-validation.js +171 -0
  279. package/scripts/validation/phase-4-consensus-report.js +181 -0
  280. package/scripts/validation/phase-4-final-validation.js +351 -0
  281. package/scripts/validation/phase-5-consensus-report.cjs +113 -0
  282. package/scripts/validation/phase-5-consensus-report.js +113 -0
  283. package/scripts/validation/security-analysis.js +49 -0
  284. package/scripts/validation/security-validation.js +492 -0
  285. package/scripts/validation/simple-security-validation.js +464 -0
  286. package/scripts/verify-installation.js +112 -0
  287. package/scripts/verify-mcp-server.js +86 -0
  288. package/scripts/verify-sdk-phase1.cjs +293 -0
@@ -0,0 +1,429 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Pre-Publish Validation Script
5
+ *
6
+ * Validates that the package is ready for NPM publication
7
+ * Enhanced with package size, coverage, and comprehensive checks
8
+ */
9
+
10
+ import fs from 'fs';
11
+ import path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+ import { execSync } from 'child_process';
14
+
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+ const projectRoot = path.resolve(__dirname, '..');
18
+
19
+ console.log('🔍 Running pre-publish validation...\n');
20
+
21
+ const MAX_PACKAGE_SIZE = 100 * 1024 * 1024; // 100MB
22
+ const MIN_COVERAGE_TARGET = 95; // 95% coverage target
23
+
24
+ const validations = [
25
+ {
26
+ name: 'Build output exists',
27
+ critical: true,
28
+ validate: () => {
29
+ const indexPath = path.join(projectRoot, '.claude-flow-novice/dist/src/index.js');
30
+ if (!fs.existsSync(indexPath)) {
31
+ throw new Error('Build output not found. Run "npm run build" first.');
32
+ }
33
+ return { passed: true, details: `Found: ${indexPath}` };
34
+ }
35
+ },
36
+ {
37
+ name: 'Type declarations exist',
38
+ critical: true,
39
+ validate: () => {
40
+ const typesPath = path.join(projectRoot, '.claude-flow-novice/dist/index.d.ts');
41
+ if (!fs.existsSync(typesPath)) {
42
+ throw new Error('Type declarations not found. Run "npm run build" first.');
43
+ }
44
+ return { passed: true, details: `Found: ${typesPath}` };
45
+ }
46
+ },
47
+ {
48
+ name: 'Package.json is valid',
49
+ critical: true,
50
+ validate: () => {
51
+ const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
52
+
53
+ if (!packageJson.name || !packageJson.version || !packageJson.main) {
54
+ throw new Error('package.json is missing required fields (name, version, main)');
55
+ }
56
+
57
+ if (!packageJson.types) {
58
+ throw new Error('package.json is missing "types" field');
59
+ }
60
+
61
+ return {
62
+ passed: true,
63
+ details: `${packageJson.name}@${packageJson.version}`
64
+ };
65
+ }
66
+ },
67
+ {
68
+ name: 'Entry points are valid',
69
+ critical: true,
70
+ validate: () => {
71
+ const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
72
+ const mainPath = path.join(projectRoot, packageJson.main);
73
+ const typesPath = path.join(projectRoot, packageJson.types);
74
+
75
+ if (!fs.existsSync(mainPath)) {
76
+ throw new Error(`Main entry point not found: ${mainPath}`);
77
+ }
78
+
79
+ if (!fs.existsSync(typesPath)) {
80
+ throw new Error(`Types entry point not found: ${typesPath}`);
81
+ }
82
+
83
+ // Validate exports
84
+ let exportCount = 0;
85
+ if (packageJson.exports) {
86
+ exportCount = Object.keys(packageJson.exports).length;
87
+ }
88
+
89
+ return {
90
+ passed: true,
91
+ details: `Main entry valid, ${exportCount} exports defined`
92
+ };
93
+ }
94
+ },
95
+ {
96
+ name: 'Binary files exist',
97
+ critical: true,
98
+ validate: () => {
99
+ const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
100
+ const binaries = [];
101
+
102
+ if (packageJson.bin) {
103
+ for (const [name, filePath] of Object.entries(packageJson.bin)) {
104
+ const fullPath = path.join(projectRoot, filePath);
105
+ if (!fs.existsSync(fullPath)) {
106
+ throw new Error(`Binary file not found: ${name} -> ${fullPath}`);
107
+ }
108
+ binaries.push(name);
109
+ }
110
+ }
111
+
112
+ return {
113
+ passed: true,
114
+ details: `${binaries.length} binaries validated: ${binaries.join(', ')}`
115
+ };
116
+ }
117
+ },
118
+ {
119
+ name: 'Package size validation',
120
+ critical: true,
121
+ validate: () => {
122
+ try {
123
+ // Create package tarball temporarily
124
+ execSync('npm pack', { cwd: projectRoot, stdio: 'pipe' });
125
+
126
+ // Find the tarball
127
+ const files = fs.readdirSync(projectRoot);
128
+ const tarball = files.find(f => f.startsWith('claude-flow-novice-') && f.endsWith('.tgz'));
129
+
130
+ if (!tarball) {
131
+ throw new Error('Package tarball not found');
132
+ }
133
+
134
+ const tarballPath = path.join(projectRoot, tarball);
135
+ const stats = fs.statSync(tarballPath);
136
+ const sizeMB = (stats.size / 1024 / 1024).toFixed(2);
137
+
138
+ // Clean up tarball
139
+ fs.unlinkSync(tarballPath);
140
+
141
+ if (stats.size > MAX_PACKAGE_SIZE) {
142
+ throw new Error(`Package size ${sizeMB}MB exceeds 100MB limit`);
143
+ }
144
+
145
+ return {
146
+ passed: true,
147
+ details: `Package size: ${sizeMB}MB (within 100MB limit)`
148
+ };
149
+ } catch (error) {
150
+ throw new Error(`Package size check failed: ${error.message}`);
151
+ }
152
+ }
153
+ },
154
+ {
155
+ name: 'Test coverage validation',
156
+ critical: false,
157
+ validate: () => {
158
+ const coveragePath = path.join(projectRoot, 'coverage/coverage-summary.json');
159
+
160
+ if (!fs.existsSync(coveragePath)) {
161
+ return {
162
+ passed: false,
163
+ details: 'Coverage report not found. Run tests with coverage first.'
164
+ };
165
+ }
166
+
167
+ const coverage = JSON.parse(fs.readFileSync(coveragePath, 'utf8'));
168
+ const total = coverage.total;
169
+
170
+ const avgCoverage = Math.round(
171
+ (total.lines.pct + total.statements.pct + total.functions.pct + total.branches.pct) / 4
172
+ );
173
+
174
+ if (avgCoverage < MIN_COVERAGE_TARGET) {
175
+ return {
176
+ passed: false,
177
+ details: `Coverage ${avgCoverage}% below ${MIN_COVERAGE_TARGET}% target (Lines: ${total.lines.pct}%, Statements: ${total.statements.pct}%, Functions: ${total.functions.pct}%, Branches: ${total.branches.pct}%)`
178
+ };
179
+ }
180
+
181
+ return {
182
+ passed: true,
183
+ details: `Coverage: ${avgCoverage}% (Lines: ${total.lines.pct}%, Statements: ${total.statements.pct}%, Functions: ${total.functions.pct}%, Branches: ${total.branches.pct}%)`
184
+ };
185
+ }
186
+ },
187
+ {
188
+ name: 'No source files in distribution',
189
+ critical: true,
190
+ validate: () => {
191
+ const npmignorePath = path.join(projectRoot, '.npmignore');
192
+
193
+ if (!fs.existsSync(npmignorePath)) {
194
+ throw new Error('.npmignore file not found');
195
+ }
196
+
197
+ const npmignore = fs.readFileSync(npmignorePath, 'utf8');
198
+ const excludedPatterns = ['src/', 'tests/', 'test/', '*.test.js', '*.test.ts'];
199
+ const missing = excludedPatterns.filter(pattern => !npmignore.includes(pattern));
200
+
201
+ if (missing.length > 0) {
202
+ throw new Error(`Missing exclusions in .npmignore: ${missing.join(', ')}`);
203
+ }
204
+
205
+ return {
206
+ passed: true,
207
+ details: 'Source files properly excluded from package'
208
+ };
209
+ }
210
+ },
211
+ {
212
+ name: 'Security audit passed',
213
+ critical: true,
214
+ validate: () => {
215
+ try {
216
+ const result = execSync('npm audit --audit-level moderate', {
217
+ encoding: 'utf8',
218
+ stdio: 'pipe',
219
+ cwd: projectRoot
220
+ });
221
+
222
+ if (result.includes('vulnerabilities')) {
223
+ const lines = result.split('\n');
224
+ const vulnLine = lines.find(line => line.includes('vulnerabilities'));
225
+ if (vulnLine && !vulnLine.includes('0 vulnerabilities')) {
226
+ throw new Error(`Security issues found: ${vulnLine.trim()}`);
227
+ }
228
+ }
229
+
230
+ return { passed: true, details: 'No security vulnerabilities detected' };
231
+ } catch (error) {
232
+ // npm audit returns non-zero exit code when vulnerabilities found
233
+ if (error.stdout && error.stdout.includes('vulnerabilities')) {
234
+ const lines = error.stdout.split('\n');
235
+ const vulnLine = lines.find(line => line.includes('vulnerabilities'));
236
+ if (vulnLine && !vulnLine.includes('0 vulnerabilities')) {
237
+ throw new Error(`Security issues: ${vulnLine.trim()}`);
238
+ }
239
+ }
240
+ throw new Error(`Security audit failed: ${error.message}`);
241
+ }
242
+ }
243
+ },
244
+ {
245
+ name: 'Dependencies are up to date',
246
+ critical: false,
247
+ validate: () => {
248
+ try {
249
+ const result = execSync('npm outdated --json', {
250
+ encoding: 'utf8',
251
+ stdio: 'pipe',
252
+ cwd: projectRoot
253
+ });
254
+
255
+ const outdated = result ? JSON.parse(result) : {};
256
+ const outdatedCount = Object.keys(outdated).length;
257
+
258
+ if (outdatedCount > 0) {
259
+ const majorUpdates = Object.entries(outdated)
260
+ .filter(([, info]) => {
261
+ const current = info.current.split('.')[0];
262
+ const wanted = info.wanted.split('.')[0];
263
+ return current !== wanted;
264
+ });
265
+
266
+ if (majorUpdates.length > 0) {
267
+ const packages = majorUpdates.map(([name]) => name).join(', ');
268
+ return {
269
+ passed: false,
270
+ details: `${majorUpdates.length} major updates available: ${packages}`
271
+ };
272
+ }
273
+ }
274
+
275
+ return {
276
+ passed: true,
277
+ details: outdatedCount === 0 ? 'All dependencies up to date' : `${outdatedCount} minor updates available`
278
+ };
279
+ } catch (error) {
280
+ // npm outdated returns non-zero when there are outdated packages
281
+ return { passed: true, details: 'Dependency check completed' };
282
+ }
283
+ }
284
+ },
285
+ {
286
+ name: 'Build artifacts integrity',
287
+ critical: true,
288
+ validate: () => {
289
+ const distDir = path.join(projectRoot, '.claude-flow-novice/dist');
290
+
291
+ if (!fs.existsSync(distDir)) {
292
+ throw new Error('Build directory not found');
293
+ }
294
+
295
+ // Check for essential files
296
+ const essentialFiles = [
297
+ 'src/index.js',
298
+ 'src/cli/index.js',
299
+ 'src/cli/main.js'
300
+ ];
301
+
302
+ const missing = essentialFiles.filter(file =>
303
+ !fs.existsSync(path.join(distDir, file))
304
+ );
305
+
306
+ if (missing.length > 0) {
307
+ throw new Error(`Missing build artifacts: ${missing.join(', ')}`);
308
+ }
309
+
310
+ // Count total files
311
+ const countFiles = (dir) => {
312
+ let count = 0;
313
+ const items = fs.readdirSync(dir);
314
+ items.forEach(item => {
315
+ const fullPath = path.join(dir, item);
316
+ if (fs.statSync(fullPath).isDirectory()) {
317
+ count += countFiles(fullPath);
318
+ } else {
319
+ count++;
320
+ }
321
+ });
322
+ return count;
323
+ };
324
+
325
+ const fileCount = countFiles(distDir);
326
+
327
+ return {
328
+ passed: true,
329
+ details: `${fileCount} files in build output`
330
+ };
331
+ }
332
+ }
333
+ ];
334
+
335
+ // Run validations
336
+ let criticalPassed = true;
337
+ let allPassed = true;
338
+ const results = [];
339
+
340
+ console.log('═'.repeat(60));
341
+ console.log('Critical Validations:');
342
+ console.log('═'.repeat(60));
343
+
344
+ validations.filter(v => v.critical).forEach(({ name, validate }) => {
345
+ try {
346
+ const result = validate();
347
+ console.log(`✅ ${name}`);
348
+ if (result.details) {
349
+ console.log(` ${result.details}`);
350
+ }
351
+ results.push({ name, passed: true, critical: true, details: result.details });
352
+ } catch (error) {
353
+ console.log(`❌ ${name}`);
354
+ console.log(` ${error.message}`);
355
+ criticalPassed = false;
356
+ allPassed = false;
357
+ results.push({ name, passed: false, critical: true, error: error.message });
358
+ }
359
+ });
360
+
361
+ console.log('\n' + '═'.repeat(60));
362
+ console.log('Optional Validations:');
363
+ console.log('═'.repeat(60));
364
+
365
+ validations.filter(v => !v.critical).forEach(({ name, validate }) => {
366
+ try {
367
+ const result = validate();
368
+ console.log(`${result.passed ? '✅' : '⚠️'} ${name}`);
369
+ if (result.details) {
370
+ console.log(` ${result.details}`);
371
+ }
372
+ results.push({ name, passed: result.passed, critical: false, details: result.details });
373
+ if (!result.passed) {
374
+ allPassed = false;
375
+ }
376
+ } catch (error) {
377
+ console.log(`⚠️ ${name}`);
378
+ console.log(` ${error.message}`);
379
+ results.push({ name, passed: false, critical: false, error: error.message });
380
+ allPassed = false;
381
+ }
382
+ });
383
+
384
+ // Generate summary report
385
+ console.log('\n' + '═'.repeat(60));
386
+ console.log('Validation Summary:');
387
+ console.log('═'.repeat(60));
388
+
389
+ const criticalCount = results.filter(r => r.critical).length;
390
+ const criticalPassedCount = results.filter(r => r.critical && r.passed).length;
391
+ const optionalCount = results.filter(r => !r.critical).length;
392
+ const optionalPassedCount = results.filter(r => !r.critical && r.passed).length;
393
+
394
+ console.log(`Critical: ${criticalPassedCount}/${criticalCount} passed`);
395
+ console.log(`Optional: ${optionalPassedCount}/${optionalCount} passed`);
396
+ console.log(`Total: ${criticalPassedCount + optionalPassedCount}/${results.length} passed`);
397
+
398
+ // Save detailed report
399
+ const reportPath = path.join(projectRoot, '.claude-flow-novice/pre-publish-validation-report.json');
400
+ fs.mkdirSync(path.dirname(reportPath), { recursive: true });
401
+ fs.writeFileSync(reportPath, JSON.stringify({
402
+ timestamp: new Date().toISOString(),
403
+ summary: {
404
+ total: results.length,
405
+ passed: criticalPassedCount + optionalPassedCount,
406
+ failed: results.length - (criticalPassedCount + optionalPassedCount),
407
+ criticalPassed: criticalPassedCount,
408
+ criticalTotal: criticalCount,
409
+ optionalPassed: optionalPassedCount,
410
+ optionalTotal: optionalCount
411
+ },
412
+ results
413
+ }, null, 2));
414
+
415
+ console.log(`\n📊 Detailed report saved: ${reportPath}`);
416
+
417
+ // Exit with appropriate code
418
+ if (!criticalPassed) {
419
+ console.log('\n❌ Critical validations failed. Package is NOT ready for publication.');
420
+ console.log(' Please fix critical issues before publishing.\n');
421
+ process.exit(1);
422
+ } else if (!allPassed) {
423
+ console.log('\n⚠️ All critical validations passed, but some optional checks failed.');
424
+ console.log(' Package can be published, but consider addressing warnings.\n');
425
+ process.exit(0);
426
+ } else {
427
+ console.log('\n🎉 All validations passed! Package is ready for publication.\n');
428
+ process.exit(0);
429
+ }
@@ -0,0 +1,198 @@
1
+ --[[
2
+ cleanup-blocking-coordination.lua
3
+
4
+ High-performance Redis Lua script for cleaning up stale blocking coordinator state.
5
+ Target: <5s for 10,000 coordinators (2,000 coordinators/sec)
6
+
7
+ Strategy:
8
+ 1. Single SCAN with high COUNT to minimize round trips
9
+ 2. Batch MGET to retrieve all heartbeat states in one operation
10
+ 3. Filter stale coordinators (startTime < current - 600s)
11
+ 4. Batch collection of all related keys (ACKs, signals, idempotency, activity)
12
+ 5. Batch DEL of all stale keys in one atomic operation
13
+
14
+ Safety:
15
+ - Uses SCAN (non-blocking) for key discovery
16
+ - TTL-based staleness check (10 minutes = 600 seconds)
17
+ - Preserves active coordinators
18
+ - Atomic execution prevents race conditions
19
+
20
+ Performance optimizations:
21
+ - Minimize network round trips (single SCAN, single MGET, single DEL)
22
+ - Lua execution is atomic and server-side
23
+ - No inter-command latency
24
+ - Batch processing reduces overhead
25
+
26
+ KEYS: None (discovers keys dynamically)
27
+ ARGV[1]: Stale threshold in seconds (default: 600)
28
+ ARGV[2]: Dry run flag (0 = production, 1 = dry run)
29
+
30
+ Returns: JSON string with cleanup metrics
31
+ {
32
+ "totalCoordinatorsChecked": 0,
33
+ "staleCoordinatorsFound": 0,
34
+ "keysDeleted": 0,
35
+ "executionTimeMs": 0,
36
+ "staleCoordinatorIds": []
37
+ }
38
+ ]]
39
+
40
+ local STALE_THRESHOLD_SECONDS = tonumber(ARGV[1]) or 600
41
+ local DRY_RUN = tonumber(ARGV[2]) or 0
42
+ local start_time = redis.call('TIME')
43
+ local start_time_ms = tonumber(start_time[1]) * 1000 + math.floor(tonumber(start_time[2]) / 1000)
44
+
45
+ -- Metrics tracking
46
+ local metrics = {
47
+ totalCoordinatorsChecked = 0,
48
+ staleCoordinatorsFound = 0,
49
+ keysDeleted = 0,
50
+ executionTimeMs = 0,
51
+ staleCoordinatorIds = {}
52
+ }
53
+
54
+ -- Helper: Get current timestamp in seconds
55
+ local function current_timestamp_seconds()
56
+ local time = redis.call('TIME')
57
+ return tonumber(time[1])
58
+ end
59
+
60
+ -- Helper: Extract coordinator ID from heartbeat key
61
+ local function extract_coordinator_id(heartbeat_key)
62
+ -- Format: blocking:heartbeat:{coordinatorId}
63
+ return string.match(heartbeat_key, "^blocking:heartbeat:(.+)$")
64
+ end
65
+
66
+ -- Helper: Parse JSON timestamp from heartbeat value
67
+ local function parse_heartbeat_timestamp(heartbeat_value)
68
+ -- Format: {"coordinatorId":"...","timestamp":1234567890123,...}
69
+ local timestamp_ms = string.match(heartbeat_value, '"timestamp":(%d+)')
70
+ if timestamp_ms then
71
+ return tonumber(timestamp_ms)
72
+ end
73
+ return nil
74
+ end
75
+
76
+ -- Helper: Check if coordinator is stale
77
+ local function is_stale(heartbeat_value, current_time_seconds)
78
+ local timestamp_ms = parse_heartbeat_timestamp(heartbeat_value)
79
+ if not timestamp_ms then
80
+ return false -- Invalid heartbeat, skip
81
+ end
82
+
83
+ local timestamp_seconds = math.floor(timestamp_ms / 1000)
84
+ local age_seconds = current_time_seconds - timestamp_seconds
85
+
86
+ return age_seconds > STALE_THRESHOLD_SECONDS
87
+ end
88
+
89
+ -- Helper: Collect all related keys for a coordinator
90
+ local function collect_coordinator_keys(coordinator_id)
91
+ local keys = {}
92
+
93
+ -- 1. Heartbeat key
94
+ table.insert(keys, "blocking:heartbeat:" .. coordinator_id)
95
+
96
+ -- 2. Signal ACK keys (blocking:ack:coordinatorId:*)
97
+ local ack_cursor = "0"
98
+ repeat
99
+ local ack_result = redis.call('SCAN', ack_cursor, 'MATCH', 'blocking:ack:' .. coordinator_id .. ':*', 'COUNT', 1000)
100
+ ack_cursor = ack_result[1]
101
+ for _, key in ipairs(ack_result[2]) do
102
+ table.insert(keys, key)
103
+ end
104
+ until ack_cursor == "0"
105
+
106
+ -- 3. Signal key
107
+ table.insert(keys, "blocking:signal:" .. coordinator_id)
108
+
109
+ -- 4. Idempotency keys (blocking:idempotency:*coordinatorId*)
110
+ local idemp_cursor = "0"
111
+ repeat
112
+ local idemp_result = redis.call('SCAN', idemp_cursor, 'MATCH', 'blocking:idempotency:*' .. coordinator_id .. '*', 'COUNT', 1000)
113
+ idemp_cursor = idemp_result[1]
114
+ for _, key in ipairs(idemp_result[2]) do
115
+ table.insert(keys, key)
116
+ end
117
+ until idemp_cursor == "0"
118
+
119
+ -- 5. Activity tracking key
120
+ table.insert(keys, "coordinator:activity:" .. coordinator_id)
121
+
122
+ return keys
123
+ end
124
+
125
+ -- Step 1: Scan for all heartbeat keys with high COUNT
126
+ local heartbeat_keys = {}
127
+ local cursor = "0"
128
+ repeat
129
+ -- Use COUNT 10000 to minimize SCAN iterations
130
+ local result = redis.call('SCAN', cursor, 'MATCH', 'blocking:heartbeat:*', 'COUNT', 10000)
131
+ cursor = result[1]
132
+ for _, key in ipairs(result[2]) do
133
+ table.insert(heartbeat_keys, key)
134
+ end
135
+ until cursor == "0"
136
+
137
+ -- Early exit if no coordinators found
138
+ if #heartbeat_keys == 0 then
139
+ metrics.executionTimeMs = 0
140
+ return cjson.encode(metrics)
141
+ end
142
+
143
+ metrics.totalCoordinatorsChecked = #heartbeat_keys
144
+
145
+ -- Step 2: Batch MGET all heartbeat values
146
+ local heartbeat_values = redis.call('MGET', unpack(heartbeat_keys))
147
+
148
+ -- Step 3: Filter stale coordinators and collect all keys to delete
149
+ local current_time_seconds = current_timestamp_seconds()
150
+ local keys_to_delete = {}
151
+ local stale_coordinator_ids = {}
152
+
153
+ for i, heartbeat_key in ipairs(heartbeat_keys) do
154
+ local heartbeat_value = heartbeat_values[i]
155
+
156
+ if heartbeat_value and is_stale(heartbeat_value, current_time_seconds) then
157
+ local coordinator_id = extract_coordinator_id(heartbeat_key)
158
+ if coordinator_id then
159
+ table.insert(stale_coordinator_ids, coordinator_id)
160
+
161
+ -- Collect all related keys for this stale coordinator
162
+ local coordinator_keys = collect_coordinator_keys(coordinator_id)
163
+ for _, key in ipairs(coordinator_keys) do
164
+ table.insert(keys_to_delete, key)
165
+ end
166
+ end
167
+ end
168
+ end
169
+
170
+ metrics.staleCoordinatorsFound = #stale_coordinator_ids
171
+ metrics.staleCoordinatorIds = stale_coordinator_ids
172
+
173
+ -- Step 4: Batch DEL all stale keys
174
+ if #keys_to_delete > 0 and DRY_RUN == 0 then
175
+ -- Redis DEL command accepts up to ~1M keys, but we'll batch in chunks of 10000 for safety
176
+ local batch_size = 10000
177
+ local deleted_count = 0
178
+
179
+ for i = 1, #keys_to_delete, batch_size do
180
+ local batch_end = math.min(i + batch_size - 1, #keys_to_delete)
181
+ local batch = {}
182
+ for j = i, batch_end do
183
+ table.insert(batch, keys_to_delete[j])
184
+ end
185
+ deleted_count = deleted_count + redis.call('DEL', unpack(batch))
186
+ end
187
+
188
+ metrics.keysDeleted = deleted_count
189
+ elseif DRY_RUN == 1 then
190
+ metrics.keysDeleted = #keys_to_delete -- Report what would be deleted
191
+ end
192
+
193
+ -- Calculate execution time
194
+ local end_time = redis.call('TIME')
195
+ local end_time_ms = tonumber(end_time[1]) * 1000 + math.floor(tonumber(end_time[2]) / 1000)
196
+ metrics.executionTimeMs = end_time_ms - start_time_ms
197
+
198
+ return cjson.encode(metrics)