claude-flow-novice 2.0.3 → 2.0.4

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 (272) hide show
  1. package/dist/src/cli/commands/guidance.js +487 -668
  2. package/dist/src/cli/commands/index-validate.js +18 -29
  3. package/dist/src/cli/commands/mcp-troubleshoot.js +230 -282
  4. package/dist/src/cli/commands/neural-goal-init.js +92 -125
  5. package/dist/src/cli/commands/swarm-exec.js +317 -393
  6. package/dist/src/cli/commands/swarm.js +1 -1
  7. package/dist/src/cli/commands/validate-framework.js +983 -1100
  8. package/dist/src/cli/commands/validate.js +144 -223
  9. package/dist/src/cli/simple-commands/__tests__/agent.test.js +265 -277
  10. package/dist/src/cli/simple-commands/__tests__/memory.test.js +6 -7
  11. package/dist/src/cli/simple-commands/__tests__/swarm.test.js +373 -356
  12. package/dist/src/cli/simple-commands/__tests__/task.test.js +6 -7
  13. package/dist/src/cli/simple-commands/agent.js +157 -193
  14. package/dist/src/cli/simple-commands/analysis.js +336 -446
  15. package/dist/src/cli/simple-commands/automation-executor.js +1095 -1339
  16. package/dist/src/cli/simple-commands/automation.js +481 -469
  17. package/dist/src/cli/simple-commands/batch-manager.js +261 -313
  18. package/dist/src/cli/simple-commands/claude-telemetry.js +241 -267
  19. package/dist/src/cli/simple-commands/claude-track.js +68 -90
  20. package/dist/src/cli/simple-commands/concurrent-display.js +266 -320
  21. package/dist/src/cli/simple-commands/config.js +245 -290
  22. package/dist/src/cli/simple-commands/coordination.js +182 -234
  23. package/dist/src/cli/simple-commands/enhanced-ui-views.js +812 -615
  24. package/dist/src/cli/simple-commands/enhanced-webui-complete.js +922 -981
  25. package/dist/src/cli/simple-commands/fix-hook-variables.js +274 -294
  26. package/dist/src/cli/simple-commands/github/gh-coordinator.js +378 -457
  27. package/dist/src/cli/simple-commands/github/github-api.js +535 -574
  28. package/dist/src/cli/simple-commands/github/init.js +276 -303
  29. package/dist/src/cli/simple-commands/github.js +222 -247
  30. package/dist/src/cli/simple-commands/goal.js +51 -63
  31. package/dist/src/cli/simple-commands/hive-mind/auto-save-middleware.js +208 -278
  32. package/dist/src/cli/simple-commands/hive-mind/communication.js +601 -696
  33. package/dist/src/cli/simple-commands/hive-mind/core.js +907 -979
  34. package/dist/src/cli/simple-commands/hive-mind/db-optimizer.js +406 -655
  35. package/dist/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1125 -1245
  36. package/dist/src/cli/simple-commands/hive-mind/memory.js +854 -1090
  37. package/dist/src/cli/simple-commands/hive-mind/performance-optimizer.js +459 -574
  38. package/dist/src/cli/simple-commands/hive-mind/performance-test.js +263 -347
  39. package/dist/src/cli/simple-commands/hive-mind/queen.js +727 -768
  40. package/dist/src/cli/simple-commands/hive-mind/session-manager.js +745 -1049
  41. package/dist/src/cli/simple-commands/hive-mind-optimize.js +227 -283
  42. package/dist/src/cli/simple-commands/hive-mind-wizard.js +174 -217
  43. package/dist/src/cli/simple-commands/hive-mind.js +1842 -2283
  44. package/dist/src/cli/simple-commands/hive.js +90 -79
  45. package/dist/src/cli/simple-commands/hook-safety.js +431 -521
  46. package/dist/src/cli/simple-commands/hooks/session-start-soul.js +203 -254
  47. package/dist/src/cli/simple-commands/hooks.js +1064 -1204
  48. package/dist/src/cli/simple-commands/init/agent-copier.js +294 -319
  49. package/dist/src/cli/simple-commands/init/batch-init.js +496 -562
  50. package/dist/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +13 -19
  51. package/dist/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +13 -19
  52. package/dist/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +61 -88
  53. package/dist/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +125 -150
  54. package/dist/src/cli/simple-commands/init/claude-commands/slash-commands.js +42 -49
  55. package/dist/src/cli/simple-commands/init/claude-commands/sparc-commands.js +43 -61
  56. package/dist/src/cli/simple-commands/init/copy-revised-templates.js +141 -147
  57. package/dist/src/cli/simple-commands/init/executable-wrapper.js +31 -44
  58. package/dist/src/cli/simple-commands/init/gitignore-updater.js +64 -90
  59. package/dist/src/cli/simple-commands/init/help.js +104 -107
  60. package/dist/src/cli/simple-commands/init/hive-mind-init.js +509 -528
  61. package/dist/src/cli/simple-commands/init/index.js +1510 -1759
  62. package/dist/src/cli/simple-commands/init/performance-monitor.js +234 -317
  63. package/dist/src/cli/simple-commands/init/rollback/backup-manager.js +441 -504
  64. package/dist/src/cli/simple-commands/init/rollback/index.js +289 -364
  65. package/dist/src/cli/simple-commands/init/rollback/recovery-manager.js +652 -728
  66. package/dist/src/cli/simple-commands/init/rollback/rollback-executor.js +416 -481
  67. package/dist/src/cli/simple-commands/init/rollback/state-tracker.js +369 -448
  68. package/dist/src/cli/simple-commands/init/sparc/roo-readme.js +1 -2
  69. package/dist/src/cli/simple-commands/init/sparc/roomodes-config.js +122 -99
  70. package/dist/src/cli/simple-commands/init/sparc/workflows.js +32 -37
  71. package/dist/src/cli/simple-commands/init/sparc-structure.js +55 -62
  72. package/dist/src/cli/simple-commands/init/template-copier.js +421 -533
  73. package/dist/src/cli/simple-commands/init/templates/coordination-md.js +3 -6
  74. package/dist/src/cli/simple-commands/init/templates/enhanced-templates.js +344 -318
  75. package/dist/src/cli/simple-commands/init/templates/github-safe-enhanced.js +173 -218
  76. package/dist/src/cli/simple-commands/init/templates/github-safe.js +65 -75
  77. package/dist/src/cli/simple-commands/init/templates/memory-bank-md.js +3 -6
  78. package/dist/src/cli/simple-commands/init/templates/readme-files.js +2 -4
  79. package/dist/src/cli/simple-commands/init/templates/safe-hook-patterns.js +187 -230
  80. package/dist/src/cli/simple-commands/init/templates/sparc-modes.js +53 -80
  81. package/dist/src/cli/simple-commands/init/templates/verification-claude-md.js +101 -85
  82. package/dist/src/cli/simple-commands/init/validation/config-validator.js +283 -330
  83. package/dist/src/cli/simple-commands/init/validation/health-checker.js +495 -561
  84. package/dist/src/cli/simple-commands/init/validation/index.js +302 -358
  85. package/dist/src/cli/simple-commands/init/validation/mode-validator.js +308 -359
  86. package/dist/src/cli/simple-commands/init/validation/post-init-validator.js +389 -366
  87. package/dist/src/cli/simple-commands/init/validation/pre-init-validator.js +270 -268
  88. package/dist/src/cli/simple-commands/init/validation/test-runner.js +427 -447
  89. package/dist/src/cli/simple-commands/init.js +1 -2
  90. package/dist/src/cli/simple-commands/mcp-health.js +131 -158
  91. package/dist/src/cli/simple-commands/mcp-integration-layer.js +533 -634
  92. package/dist/src/cli/simple-commands/mcp.js +345 -400
  93. package/dist/src/cli/simple-commands/memory-consolidation.js +426 -537
  94. package/dist/src/cli/simple-commands/memory.js +247 -311
  95. package/dist/src/cli/simple-commands/migrate-hooks.js +39 -46
  96. package/dist/src/cli/simple-commands/monitor.js +294 -363
  97. package/dist/src/cli/simple-commands/neural.js +51 -65
  98. package/dist/src/cli/simple-commands/pair-autofix-only.js +538 -662
  99. package/dist/src/cli/simple-commands/pair-basic.js +528 -656
  100. package/dist/src/cli/simple-commands/pair-old.js +430 -543
  101. package/dist/src/cli/simple-commands/pair-working.js +615 -751
  102. package/dist/src/cli/simple-commands/pair.js +615 -751
  103. package/dist/src/cli/simple-commands/performance-hooks.js +83 -111
  104. package/dist/src/cli/simple-commands/performance-metrics.js +348 -433
  105. package/dist/src/cli/simple-commands/process-ui-enhanced.js +708 -787
  106. package/dist/src/cli/simple-commands/process-ui.js +230 -254
  107. package/dist/src/cli/simple-commands/realtime-update-system.js +525 -611
  108. package/dist/src/cli/simple-commands/sparc/architecture.js +1704 -1530
  109. package/dist/src/cli/simple-commands/sparc/commands.js +438 -516
  110. package/dist/src/cli/simple-commands/sparc/completion.js +1224 -1481
  111. package/dist/src/cli/simple-commands/sparc/coordinator.js +913 -978
  112. package/dist/src/cli/simple-commands/sparc/index.js +241 -298
  113. package/dist/src/cli/simple-commands/sparc/phase-base.js +314 -390
  114. package/dist/src/cli/simple-commands/sparc/pseudocode.js +965 -869
  115. package/dist/src/cli/simple-commands/sparc/refinement.js +980 -1273
  116. package/dist/src/cli/simple-commands/sparc/specification.js +559 -645
  117. package/dist/src/cli/simple-commands/sparc-modes/architect.js +1 -1
  118. package/dist/src/cli/simple-commands/sparc-modes/ask.js +1 -1
  119. package/dist/src/cli/simple-commands/sparc-modes/code.js +1 -1
  120. package/dist/src/cli/simple-commands/sparc-modes/debug.js +1 -1
  121. package/dist/src/cli/simple-commands/sparc-modes/devops.js +1 -1
  122. package/dist/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
  123. package/dist/src/cli/simple-commands/sparc-modes/generic.js +1 -1
  124. package/dist/src/cli/simple-commands/sparc-modes/index.js +47 -55
  125. package/dist/src/cli/simple-commands/sparc-modes/integration.js +1 -1
  126. package/dist/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
  127. package/dist/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
  128. package/dist/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
  129. package/dist/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
  130. package/dist/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
  131. package/dist/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
  132. package/dist/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
  133. package/dist/src/cli/simple-commands/sparc-modes/swarm.js +101 -87
  134. package/dist/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
  135. package/dist/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
  136. package/dist/src/cli/simple-commands/sparc.js +465 -493
  137. package/dist/src/cli/simple-commands/start-ui.js +108 -132
  138. package/dist/src/cli/simple-commands/start-wrapper.js +240 -268
  139. package/dist/src/cli/simple-commands/start.js +1 -1
  140. package/dist/src/cli/simple-commands/status.js +254 -275
  141. package/dist/src/cli/simple-commands/stream-chain-clean.js +128 -171
  142. package/dist/src/cli/simple-commands/stream-chain-fixed.js +61 -82
  143. package/dist/src/cli/simple-commands/stream-chain-real.js +267 -331
  144. package/dist/src/cli/simple-commands/stream-chain-working.js +211 -263
  145. package/dist/src/cli/simple-commands/stream-chain.js +260 -318
  146. package/dist/src/cli/simple-commands/stream-processor.js +290 -315
  147. package/dist/src/cli/simple-commands/swarm-executor.js +189 -222
  148. package/dist/src/cli/simple-commands/swarm-metrics-integration.js +208 -300
  149. package/dist/src/cli/simple-commands/swarm-ui.js +623 -703
  150. package/dist/src/cli/simple-commands/swarm-webui-integration.js +258 -286
  151. package/dist/src/cli/simple-commands/swarm.js +887 -1082
  152. package/dist/src/cli/simple-commands/task.js +161 -206
  153. package/dist/src/cli/simple-commands/timestamp-fix.js +59 -89
  154. package/dist/src/cli/simple-commands/token-tracker.js +258 -316
  155. package/dist/src/cli/simple-commands/tool-execution-framework.js +433 -519
  156. package/dist/src/cli/simple-commands/train-and-stream.js +275 -331
  157. package/dist/src/cli/simple-commands/training-pipeline.js +619 -725
  158. package/dist/src/cli/simple-commands/training.js +170 -227
  159. package/dist/src/cli/simple-commands/verification-hooks.js +261 -284
  160. package/dist/src/cli/simple-commands/verification-integration.js +389 -417
  161. package/dist/src/cli/simple-commands/verification-training-integration.js +486 -606
  162. package/dist/src/cli/simple-commands/verification.js +493 -513
  163. package/dist/src/cli/simple-commands/web-server.js +766 -836
  164. package/dist/src/cli/simple-commands/webui-validator.js +106 -124
  165. package/dist/src/coordination/event-bus/demo-wasm-integration.js +212 -251
  166. package/dist/src/coordination/event-bus/qe-event-bus.js +608 -748
  167. package/dist/src/coordination/event-bus/qe-event-bus.test.js +379 -454
  168. package/dist/src/coordination/iteration-tracker.js +363 -454
  169. package/dist/src/enterprise/analytics-manager.js +1135 -0
  170. package/dist/src/enterprise/audit-manager.js +1115 -0
  171. package/dist/src/enterprise/cloud-manager.js +891 -0
  172. package/dist/src/enterprise/deployment-manager.js +966 -0
  173. package/dist/src/enterprise/index.js +6 -0
  174. package/dist/src/enterprise/project-manager.js +584 -0
  175. package/dist/src/enterprise/security-manager.js +991 -0
  176. package/dist/src/index.js +1 -1
  177. package/dist/src/mcp/DEPRECATED.js +46 -60
  178. package/dist/src/mcp/fixes/mcp-error-fixes.js +115 -134
  179. package/dist/src/mcp/implementations/agent-tracker.js +114 -128
  180. package/dist/src/mcp/implementations/daa-tools.js +292 -350
  181. package/dist/src/mcp/implementations/workflow-tools.js +329 -361
  182. package/dist/src/mcp/mcp-config-manager.js +1183 -1331
  183. package/dist/src/mcp/mcp-server-novice-simplified.js +11 -17
  184. package/dist/src/mcp/mcp-server-novice.js +11 -17
  185. package/dist/src/mcp/mcp-server-sdk.js +11 -17
  186. package/dist/src/mcp/mcp-server.js +1620 -1484
  187. package/dist/src/mcp/ruv-swarm-wrapper.js +209 -239
  188. package/dist/src/memory/advanced-serializer.js +609 -589
  189. package/dist/src/memory/enhanced-examples.js +220 -305
  190. package/dist/src/memory/enhanced-memory.js +295 -336
  191. package/dist/src/memory/enhanced-session-serializer.js +408 -492
  192. package/dist/src/memory/fallback-memory-system.js +900 -1021
  193. package/dist/src/memory/fallback-store.js +93 -131
  194. package/dist/src/memory/high-performance-serialization.js +592 -730
  195. package/dist/src/memory/in-memory-store.js +161 -213
  196. package/dist/src/memory/index.js +123 -157
  197. package/dist/src/memory/lock-free-structures.js +578 -764
  198. package/dist/src/memory/memory-mapped-persistence.js +585 -766
  199. package/dist/src/memory/memory-pressure-manager.js +569 -707
  200. package/dist/src/memory/migration.js +358 -445
  201. package/dist/src/memory/shared-memory.js +641 -768
  202. package/dist/src/memory/sqlite-store.js +245 -325
  203. package/dist/src/memory/sqlite-wrapper.js +122 -151
  204. package/dist/src/memory/swarm-memory.js +470 -603
  205. package/dist/src/memory/test-example.js +126 -134
  206. package/dist/src/memory/ultra-fast-memory-store.js +622 -821
  207. package/dist/src/memory/unified-memory-manager.js +356 -437
  208. package/dist/src/migration/index.js +92 -0
  209. package/dist/src/migration/logger.js +121 -0
  210. package/dist/src/migration/migration-analyzer.js +268 -0
  211. package/dist/src/migration/migration-runner.js +522 -0
  212. package/dist/src/migration/migration-validator.js +285 -0
  213. package/dist/src/migration/progress-reporter.js +150 -0
  214. package/dist/src/migration/rollback-manager.js +321 -0
  215. package/dist/src/migration/tests/migration-system.test.js +7 -0
  216. package/dist/src/migration/types.js +3 -0
  217. package/dist/src/swarm/CodeRefactoringSwarm.js +777 -952
  218. package/dist/src/swarm/__tests__/integration.test.js +227 -0
  219. package/dist/src/swarm/__tests__/prompt-copier.test.js +344 -0
  220. package/dist/src/swarm/advanced-orchestrator.js +1095 -0
  221. package/dist/src/swarm/claude-code-interface.js +961 -0
  222. package/dist/src/swarm/claude-flow-executor.js +229 -0
  223. package/dist/src/swarm/consensus-coordinator.js +475 -0
  224. package/dist/src/swarm/coordinator.js +2993 -0
  225. package/dist/src/swarm/direct-executor.js +1180 -0
  226. package/dist/src/swarm/error-recovery/advanced-error-detection.js +691 -0
  227. package/dist/src/swarm/error-recovery/automated-recovery-workflows.js +998 -0
  228. package/dist/src/swarm/error-recovery/error-recovery-coordinator.js +1197 -0
  229. package/dist/src/swarm/error-recovery/recovery-monitoring.js +772 -0
  230. package/dist/src/swarm/error-recovery/resilience-architecture.js +714 -0
  231. package/dist/src/swarm/error-recovery/self-healing-mechanisms.js +1319 -0
  232. package/dist/src/swarm/error-recovery/test-error-recovery-effectiveness.js +808 -0
  233. package/dist/src/swarm/executor-v2.js +322 -0
  234. package/dist/src/swarm/executor.js +815 -0
  235. package/dist/src/swarm/hive-mind-integration.js +703 -0
  236. package/dist/src/swarm/index.js +41 -0
  237. package/dist/src/swarm/json-output-aggregator.js +267 -0
  238. package/dist/src/swarm/large-scale-coordinator.js +542 -0
  239. package/dist/src/swarm/mcp-integration-wrapper.js +628 -0
  240. package/dist/src/swarm/memory.js +1117 -0
  241. package/dist/src/swarm/optimizations/__tests__/optimization.test.js +348 -0
  242. package/dist/src/swarm/optimizations/async-file-manager.js +285 -0
  243. package/dist/src/swarm/optimizations/circular-buffer.js +162 -0
  244. package/dist/src/swarm/optimizations/connection-pool.js +244 -0
  245. package/dist/src/swarm/optimizations/index.js +28 -0
  246. package/dist/src/swarm/optimizations/optimized-executor.js +320 -0
  247. package/dist/src/swarm/optimizations/ttl-map.js +234 -0
  248. package/dist/src/swarm/prompt-cli.js +200 -0
  249. package/dist/src/swarm/prompt-copier-enhanced.js +202 -0
  250. package/dist/src/swarm/prompt-copier.js +381 -0
  251. package/dist/src/swarm/prompt-manager.js +295 -0
  252. package/dist/src/swarm/prompt-utils.js +310 -0
  253. package/dist/src/swarm/result-aggregator.js +718 -0
  254. package/dist/src/swarm/sparc-executor.js +1568 -0
  255. package/dist/src/swarm/strategies/auto.js +758 -0
  256. package/dist/src/swarm/strategies/base.js +128 -0
  257. package/dist/src/swarm/strategies/research.js +914 -0
  258. package/dist/src/swarm/strategies/strategy-metrics-patch.js +2 -0
  259. package/dist/src/swarm/types.js +52 -0
  260. package/dist/src/swarm/workers/copy-worker.js +56 -0
  261. package/dist/src/utils/__tests__/github-cli-safety-wrapper.test.js +332 -400
  262. package/dist/src/utils/github-cli-safe.js +56 -64
  263. package/dist/src/utils/github-cli-safety-wrapper.js +451 -546
  264. package/dist/src/utils/npx-isolated-cache.js +104 -119
  265. package/dist/src/utils/preference-manager.js +622 -652
  266. package/dist/src/utils/timezone-utils.js +86 -105
  267. package/dist/src/validators/epic-config-schema.js +214 -0
  268. package/dist/src/validators/index.js +10 -0
  269. package/dist/src/validators/swarm-init-validator.js +259 -0
  270. package/dist/src/validators/todowrite-batching-validator.js +215 -0
  271. package/dist/src/validators/todowrite-integration.js +187 -0
  272. package/package.json +2 -2
@@ -1,551 +1,531 @@
1
1
  /**
2
2
  * Verification and Truth Enforcement System
3
3
  * Implements mandatory verification for multi-agent operations
4
- */
5
-
6
- import { exec } from 'child_process';
7
- import { promisify } from 'util';
8
- import fs from 'fs/promises';
9
- import path from 'path';
10
- import crypto from 'crypto';
11
-
4
+ */ import { exec } from "child_process";
5
+ import { promisify } from "util";
6
+ import fs from "node:fs/promises";
7
+ import path from "path";
12
8
  const execAsync = promisify(exec);
13
-
14
9
  // Verification modes
15
10
  const VERIFICATION_MODES = {
16
- strict: { threshold: 0.95, autoRollback: true, requireConsensus: true },
17
- moderate: { threshold: 0.85, autoRollback: false, requireConsensus: true },
18
- development: { threshold: 0.75, autoRollback: false, requireConsensus: false },
11
+ strict: {
12
+ threshold: 0.95,
13
+ autoRollback: true,
14
+ requireConsensus: true
15
+ },
16
+ moderate: {
17
+ threshold: 0.85,
18
+ autoRollback: false,
19
+ requireConsensus: true
20
+ },
21
+ development: {
22
+ threshold: 0.75,
23
+ autoRollback: false,
24
+ requireConsensus: false
25
+ }
19
26
  };
20
-
21
27
  // Agent-specific verification requirements
22
28
  const AGENT_VERIFICATION = {
23
- coder: ['compile', 'test', 'lint', 'typecheck'],
24
- reviewer: ['code-analysis', 'security-scan', 'performance-check'],
25
- tester: ['unit-tests', 'integration-tests', 'coverage-check'],
26
- planner: ['task-decomposition', 'dependency-check', 'feasibility'],
27
- architect: ['design-validation', 'scalability-check', 'pattern-compliance'],
29
+ coder: [
30
+ 'compile',
31
+ 'test',
32
+ 'lint',
33
+ 'typecheck'
34
+ ],
35
+ reviewer: [
36
+ 'code-analysis',
37
+ 'security-scan',
38
+ 'performance-check'
39
+ ],
40
+ tester: [
41
+ 'unit-tests',
42
+ 'integration-tests',
43
+ 'coverage-check'
44
+ ],
45
+ planner: [
46
+ 'task-decomposition',
47
+ 'dependency-check',
48
+ 'feasibility'
49
+ ],
50
+ architect: [
51
+ 'design-validation',
52
+ 'scalability-check',
53
+ 'pattern-compliance'
54
+ ]
28
55
  };
29
-
30
- class VerificationSystem {
31
- constructor() {
32
- this.mode = 'moderate';
33
- this.scores = new Map();
34
- this.verificationHistory = [];
35
- this.memoryPath = '.swarm/verification-memory.json';
36
- }
37
-
38
- async initialize(mode = 'moderate') {
39
- this.mode = mode;
40
- await this.loadMemory();
41
- console.log(`āœ… Verification system initialized in ${mode} mode`);
42
- console.log(` Threshold: ${VERIFICATION_MODES[mode].threshold}`);
43
- console.log(` Auto-rollback: ${VERIFICATION_MODES[mode].autoRollback}`);
44
- console.log(` Consensus required: ${VERIFICATION_MODES[mode].requireConsensus}`);
45
- }
46
-
47
- async loadMemory() {
48
- try {
49
- const data = await fs.readFile(this.memoryPath, 'utf8');
50
- const memory = JSON.parse(data);
51
- this.scores = new Map(memory.scores);
52
- this.verificationHistory = memory.history || [];
53
- } catch (error) {
54
- // Initialize empty memory if file doesn't exist
55
- this.scores = new Map();
56
- this.verificationHistory = [];
56
+ let VerificationSystem = class VerificationSystem {
57
+ async initialize(mode = 'moderate') {
58
+ this.mode = mode;
59
+ await this.loadMemory();
60
+ console.log(`āœ… Verification system initialized in ${mode} mode`);
61
+ console.log(` Threshold: ${VERIFICATION_MODES[mode].threshold}`);
62
+ console.log(` Auto-rollback: ${VERIFICATION_MODES[mode].autoRollback}`);
63
+ console.log(` Consensus required: ${VERIFICATION_MODES[mode].requireConsensus}`);
57
64
  }
58
- }
59
-
60
- async saveMemory() {
61
- const memory = {
62
- scores: Array.from(this.scores.entries()),
63
- history: this.verificationHistory,
64
- timestamp: new Date().toISOString(),
65
- };
66
-
67
- await fs.mkdir(path.dirname(this.memoryPath), { recursive: true });
68
- await fs.writeFile(this.memoryPath, JSON.stringify(memory, null, 2));
69
- }
70
-
71
- async verifyTask(taskId, agentType, claims) {
72
- console.log(`\nšŸ” Verifying task ${taskId} (Agent: ${agentType})`);
73
-
74
- const requirements = AGENT_VERIFICATION[agentType] || ['basic-check'];
75
- const results = [];
76
- let totalScore = 0;
77
-
78
- for (const check of requirements) {
79
- const result = await this.runVerification(check, claims);
80
- results.push(result);
81
- totalScore += result.score;
82
-
83
- console.log(` ${result.passed ? 'āœ…' : 'āŒ'} ${check}: ${result.score.toFixed(2)}`);
65
+ async loadMemory() {
66
+ try {
67
+ const data = await fs.readFile(this.memoryPath, 'utf8');
68
+ const memory = JSON.parse(data);
69
+ this.scores = new Map(memory.scores);
70
+ this.verificationHistory = memory.history || [];
71
+ } catch (error) {
72
+ // Initialize empty memory if file doesn't exist
73
+ this.scores = new Map();
74
+ this.verificationHistory = [];
75
+ }
84
76
  }
85
-
86
- const averageScore = totalScore / requirements.length;
87
- const threshold = VERIFICATION_MODES[this.mode].threshold;
88
- const passed = averageScore >= threshold;
89
-
90
- const verification = {
91
- taskId,
92
- agentType,
93
- score: averageScore,
94
- passed,
95
- threshold,
96
- timestamp: new Date().toISOString(),
97
- results,
98
- };
99
-
100
- this.verificationHistory.push(verification);
101
- await this.saveMemory();
102
-
103
- console.log(`\nšŸ“Š Verification Score: ${averageScore.toFixed(2)}/${threshold}`);
104
- console.log(` Status: ${passed ? 'āœ… PASSED' : 'āŒ FAILED'}`);
105
-
106
- if (!passed && VERIFICATION_MODES[this.mode].autoRollback) {
107
- console.log('\nšŸ”„ Auto-rollback triggered due to verification failure');
108
- await this.triggerRollback(taskId);
77
+ async saveMemory() {
78
+ const memory = {
79
+ scores: Array.from(this.scores.entries()),
80
+ history: this.verificationHistory,
81
+ timestamp: new Date().toISOString()
82
+ };
83
+ await fs.mkdir(path.dirname(this.memoryPath), {
84
+ recursive: true
85
+ });
86
+ await fs.writeFile(this.memoryPath, JSON.stringify(memory, null, 2));
109
87
  }
110
-
111
- return verification;
112
- }
113
-
114
- async runVerification(checkType, claims) {
115
- // Simulate different verification checks
116
- const verificationChecks = {
117
- compile: async () => {
118
- try {
119
- const { stdout } = await execAsync('npm run typecheck 2>&1 || true');
120
- return { score: stdout.includes('error') ? 0.5 : 1.0, passed: !stdout.includes('error') };
121
- } catch {
122
- return { score: 0.5, passed: false };
88
+ async verifyTask(taskId, agentType, claims) {
89
+ console.log(`\nšŸ” Verifying task ${taskId} (Agent: ${agentType})`);
90
+ const requirements = AGENT_VERIFICATION[agentType] || [
91
+ 'basic-check'
92
+ ];
93
+ const results = [];
94
+ let totalScore = 0;
95
+ for (const check of requirements){
96
+ const result = await this.runVerification(check, claims);
97
+ results.push(result);
98
+ totalScore += result.score;
99
+ console.log(` ${result.passed ? 'āœ…' : 'āŒ'} ${check}: ${result.score.toFixed(2)}`);
123
100
  }
124
- },
125
- test: async () => {
126
- try {
127
- const { stdout } = await execAsync('npm test 2>&1 || true');
128
- return { score: stdout.includes('PASS') ? 1.0 : 0.6, passed: stdout.includes('PASS') };
129
- } catch {
130
- return { score: 0.6, passed: false };
101
+ const averageScore = totalScore / requirements.length;
102
+ const threshold = VERIFICATION_MODES[this.mode].threshold;
103
+ const passed = averageScore >= threshold;
104
+ const verification = {
105
+ taskId,
106
+ agentType,
107
+ score: averageScore,
108
+ passed,
109
+ threshold,
110
+ timestamp: new Date().toISOString(),
111
+ results
112
+ };
113
+ this.verificationHistory.push(verification);
114
+ await this.saveMemory();
115
+ console.log(`\nšŸ“Š Verification Score: ${averageScore.toFixed(2)}/${threshold}`);
116
+ console.log(` Status: ${passed ? 'āœ… PASSED' : 'āŒ FAILED'}`);
117
+ if (!passed && VERIFICATION_MODES[this.mode].autoRollback) {
118
+ console.log('\nšŸ”„ Auto-rollback triggered due to verification failure');
119
+ await this.triggerRollback(taskId);
131
120
  }
132
- },
133
- lint: async () => {
134
- try {
135
- const { stdout } = await execAsync('npm run lint 2>&1 || true');
136
- return { score: stdout.includes('warning') ? 0.8 : 1.0, passed: true };
137
- } catch {
138
- return { score: 0.7, passed: false };
121
+ return verification;
122
+ }
123
+ async runVerification(checkType, claims) {
124
+ // Simulate different verification checks
125
+ const verificationChecks = {
126
+ compile: async ()=>{
127
+ try {
128
+ const { stdout } = await execAsync('npm run typecheck 2>&1 || true');
129
+ return {
130
+ score: stdout.includes('error') ? 0.5 : 1.0,
131
+ passed: !stdout.includes('error')
132
+ };
133
+ } catch {
134
+ return {
135
+ score: 0.5,
136
+ passed: false
137
+ };
138
+ }
139
+ },
140
+ test: async ()=>{
141
+ try {
142
+ const { stdout } = await execAsync('npm test 2>&1 || true');
143
+ return {
144
+ score: stdout.includes('PASS') ? 1.0 : 0.6,
145
+ passed: stdout.includes('PASS')
146
+ };
147
+ } catch {
148
+ return {
149
+ score: 0.6,
150
+ passed: false
151
+ };
152
+ }
153
+ },
154
+ lint: async ()=>{
155
+ try {
156
+ const { stdout } = await execAsync('npm run lint 2>&1 || true');
157
+ return {
158
+ score: stdout.includes('warning') ? 0.8 : 1.0,
159
+ passed: true
160
+ };
161
+ } catch {
162
+ return {
163
+ score: 0.7,
164
+ passed: false
165
+ };
166
+ }
167
+ },
168
+ typecheck: async ()=>{
169
+ try {
170
+ const { stdout } = await execAsync('npm run typecheck 2>&1 || true');
171
+ return {
172
+ score: stdout.includes('error') ? 0.6 : 1.0,
173
+ passed: !stdout.includes('error')
174
+ };
175
+ } catch {
176
+ return {
177
+ score: 0.6,
178
+ passed: false
179
+ };
180
+ }
181
+ },
182
+ default: async ()=>{
183
+ // Simulate verification based on claims
184
+ const claimScore = claims && claims.success ? 0.85 : 0.65;
185
+ return {
186
+ score: claimScore,
187
+ passed: claimScore >= 0.75
188
+ };
189
+ }
190
+ };
191
+ const check = verificationChecks[checkType] || verificationChecks.default;
192
+ return await check();
193
+ }
194
+ async triggerRollback(taskId) {
195
+ console.log(`šŸ”„ Rolling back task ${taskId}...`);
196
+ // Simulate rollback process
197
+ await new Promise((resolve)=>setTimeout(resolve, 1000));
198
+ console.log(`āœ… Rollback completed for task ${taskId}`);
199
+ }
200
+ async getAgentReliability(agentId) {
201
+ const agentHistory = this.verificationHistory.filter((v)=>v.agentType === agentId);
202
+ if (agentHistory.length === 0) return 1.0;
203
+ const totalScore = agentHistory.reduce((sum, v)=>sum + v.score, 0);
204
+ return totalScore / agentHistory.length;
205
+ }
206
+ async generateTruthReport() {
207
+ const report = {
208
+ mode: this.mode,
209
+ threshold: VERIFICATION_MODES[this.mode].threshold,
210
+ totalVerifications: this.verificationHistory.length,
211
+ passedVerifications: this.verificationHistory.filter((v)=>v.passed).length,
212
+ averageScore: 0,
213
+ agentReliability: {},
214
+ timestamp: new Date().toISOString()
215
+ };
216
+ if (this.verificationHistory.length > 0) {
217
+ const totalScore = this.verificationHistory.reduce((sum, v)=>sum + v.score, 0);
218
+ report.averageScore = totalScore / this.verificationHistory.length;
139
219
  }
140
- },
141
- typecheck: async () => {
142
- try {
143
- const { stdout } = await execAsync('npm run typecheck 2>&1 || true');
144
- return { score: stdout.includes('error') ? 0.6 : 1.0, passed: !stdout.includes('error') };
145
- } catch {
146
- return { score: 0.6, passed: false };
220
+ // Calculate per-agent reliability
221
+ const agentTypes = [
222
+ ...new Set(this.verificationHistory.map((v)=>v.agentType))
223
+ ];
224
+ for (const agent of agentTypes){
225
+ report.agentReliability[agent] = await this.getAgentReliability(agent);
147
226
  }
148
- },
149
- default: async () => {
150
- // Simulate verification based on claims
151
- const claimScore = claims && claims.success ? 0.85 : 0.65;
152
- return { score: claimScore, passed: claimScore >= 0.75 };
153
- },
154
- };
155
-
156
- const check = verificationChecks[checkType] || verificationChecks.default;
157
- return await check();
158
- }
159
-
160
- async triggerRollback(taskId) {
161
- console.log(`šŸ”„ Rolling back task ${taskId}...`);
162
- // Simulate rollback process
163
- await new Promise((resolve) => setTimeout(resolve, 1000));
164
- console.log(`āœ… Rollback completed for task ${taskId}`);
165
- }
166
-
167
- async getAgentReliability(agentId) {
168
- const agentHistory = this.verificationHistory.filter((v) => v.agentType === agentId);
169
- if (agentHistory.length === 0) return 1.0;
170
-
171
- const totalScore = agentHistory.reduce((sum, v) => sum + v.score, 0);
172
- return totalScore / agentHistory.length;
173
- }
174
-
175
- async generateTruthReport() {
176
- const report = {
177
- mode: this.mode,
178
- threshold: VERIFICATION_MODES[this.mode].threshold,
179
- totalVerifications: this.verificationHistory.length,
180
- passedVerifications: this.verificationHistory.filter((v) => v.passed).length,
181
- averageScore: 0,
182
- agentReliability: {},
183
- timestamp: new Date().toISOString(),
184
- };
185
-
186
- if (this.verificationHistory.length > 0) {
187
- const totalScore = this.verificationHistory.reduce((sum, v) => sum + v.score, 0);
188
- report.averageScore = totalScore / this.verificationHistory.length;
227
+ return report;
189
228
  }
190
-
191
- // Calculate per-agent reliability
192
- const agentTypes = [...new Set(this.verificationHistory.map((v) => v.agentType))];
193
- for (const agent of agentTypes) {
194
- report.agentReliability[agent] = await this.getAgentReliability(agent);
229
+ constructor(){
230
+ this.mode = 'moderate';
231
+ this.scores = new Map();
232
+ this.verificationHistory = [];
233
+ this.memoryPath = '.swarm/verification-memory.json';
195
234
  }
196
-
197
- return report;
198
- }
199
- }
200
-
235
+ };
201
236
  // Helper function to generate filtered report for specific agent
202
237
  async function generateFilteredReport(system, filteredHistory, agentType) {
203
- const report = {
204
- mode: system.mode,
205
- threshold: VERIFICATION_MODES[system.mode].threshold,
206
- totalVerifications: filteredHistory.length,
207
- passedVerifications: filteredHistory.filter((v) => v.passed).length,
208
- averageScore: 0,
209
- agentReliability: {},
210
- timestamp: new Date().toISOString(),
211
- };
212
-
213
- if (filteredHistory.length > 0) {
214
- const totalScore = filteredHistory.reduce((sum, v) => sum + v.score, 0);
215
- report.averageScore = totalScore / filteredHistory.length;
216
- report.agentReliability[agentType] = report.averageScore;
217
- }
218
-
219
- return report;
238
+ const report = {
239
+ mode: system.mode,
240
+ threshold: VERIFICATION_MODES[system.mode].threshold,
241
+ totalVerifications: filteredHistory.length,
242
+ passedVerifications: filteredHistory.filter((v)=>v.passed).length,
243
+ averageScore: 0,
244
+ agentReliability: {},
245
+ timestamp: new Date().toISOString()
246
+ };
247
+ if (filteredHistory.length > 0) {
248
+ const totalScore = filteredHistory.reduce((sum, v)=>sum + v.score, 0);
249
+ report.averageScore = totalScore / filteredHistory.length;
250
+ report.agentReliability[agentType] = report.averageScore;
251
+ }
252
+ return report;
220
253
  }
221
-
222
254
  // CLI command handlers
223
255
  export async function verificationCommand(args, flags) {
224
- const system = new VerificationSystem();
225
- const subcommand = args[0] || 'status';
226
-
227
- // Handle help flag
228
- if (flags.help || subcommand === '--help' || subcommand === 'help') {
229
- const { COMMAND_HELP } = await import('../help-text.js');
230
- console.log(COMMAND_HELP.verify);
231
- return;
232
- }
233
-
234
- switch (subcommand) {
235
- case 'init':
236
- const mode = args[1] || flags.mode || 'moderate';
237
- await system.initialize(mode);
238
- break;
239
-
240
- case 'verify':
241
- const taskId = args[1] || flags.taskId || `task-${Date.now()}`;
242
- const agentType = flags.agent || 'coder';
243
- const claims = { success: flags.success !== false };
244
- await system.verifyTask(taskId, agentType, claims);
245
- break;
246
-
247
- case 'truth':
248
- case 'score':
249
- await system.loadMemory();
250
-
251
- // Filter by agent if specified
252
- let filteredHistory = system.verificationHistory;
253
- if (flags.agent) {
254
- filteredHistory = system.verificationHistory.filter((v) => v.agentType === flags.agent);
255
- if (filteredHistory.length === 0) {
256
- console.log(`\nāš ļø No verification history found for agent: ${flags.agent}`);
257
- return;
258
- }
259
- }
260
-
261
- // Filter by taskId if specified
262
- if (flags.taskId) {
263
- filteredHistory = filteredHistory.filter((v) => v.taskId === flags.taskId);
264
- if (filteredHistory.length === 0) {
265
- console.log(`\nāš ļø No verification history found for task: ${flags.taskId}`);
266
- return;
267
- }
268
- }
269
-
270
- // Filter by threshold if specified
271
- if (flags.threshold) {
272
- const threshold = parseFloat(flags.threshold);
273
- filteredHistory = filteredHistory.filter((v) => v.score < threshold);
274
- if (filteredHistory.length === 0) {
275
- console.log(`\nāœ… All verifications meet or exceed threshold: ${threshold}`);
276
- return;
277
- }
278
- }
279
-
280
- // Generate report (with filtered data if agent specified)
281
- const report = flags.agent
282
- ? await generateFilteredReport(system, filteredHistory, flags.agent)
283
- : await system.generateTruthReport();
284
-
285
- // JSON output only mode
286
- if (flags.json) {
287
- console.log(JSON.stringify(report, null, 2));
256
+ const system = new VerificationSystem();
257
+ const subcommand = args[0] || 'status';
258
+ // Handle help flag
259
+ if (flags.help || subcommand === '--help' || subcommand === 'help') {
260
+ const { COMMAND_HELP } = await import("../help-text.js");
261
+ console.log(COMMAND_HELP.verify);
288
262
  return;
289
- }
290
-
291
- // Basic report (shown when not in JSON mode)
292
- console.log('\nšŸ“Š Truth Scoring Report' + (flags.agent ? ` - Agent: ${flags.agent}` : ''));
293
- console.log('━'.repeat(50));
294
- console.log(`Mode: ${report.mode || system.mode}`);
295
- console.log(`Threshold: ${report.threshold || VERIFICATION_MODES[system.mode].threshold}`);
296
- console.log(`Total Verifications: ${report.totalVerifications}`);
297
- console.log(`Passed: ${report.passedVerifications}`);
298
- console.log(`Average Score: ${report.averageScore.toFixed(3)}`);
299
-
300
- if (flags.agent) {
301
- // Show detailed info for specific agent
302
- console.log(`\nšŸ¤– ${flags.agent} Agent Details:`);
303
- console.log(` Reliability: ${(report.agentReliability[flags.agent] * 100).toFixed(1)}%`);
304
- console.log(` Total Tasks: ${filteredHistory.length}`);
305
- console.log(` Passed: ${filteredHistory.filter((v) => v.passed).length}`);
306
- console.log(` Failed: ${filteredHistory.filter((v) => !v.passed).length}`);
307
-
308
- if (flags.detailed || flags.detail) {
309
- console.log('\nšŸ“‹ Verification History:');
310
- const recentAgent = filteredHistory.slice(-10);
311
- for (const v of recentAgent) {
312
- const time = new Date(v.timestamp).toLocaleTimeString();
313
- console.log(
314
- ` ${v.passed ? 'āœ…' : 'āŒ'} [${time}] ${v.taskId}: ${v.score.toFixed(3)}`,
315
- );
316
- if (v.results && flags.verbose) {
317
- for (const [check, result] of Object.entries(v.results)) {
318
- console.log(
319
- ` • ${check}: ${result.passed ? 'āœ“' : 'āœ—'} (${result.score.toFixed(2)})`,
320
- );
321
- }
263
+ }
264
+ switch(subcommand){
265
+ case 'init':
266
+ const mode = args[1] || flags.mode || 'moderate';
267
+ await system.initialize(mode);
268
+ break;
269
+ case 'verify':
270
+ const taskId = args[1] || flags.taskId || `task-${Date.now()}`;
271
+ const agentType = flags.agent || 'coder';
272
+ const claims = {
273
+ success: flags.success !== false
274
+ };
275
+ await system.verifyTask(taskId, agentType, claims);
276
+ break;
277
+ case 'truth':
278
+ case 'score':
279
+ await system.loadMemory();
280
+ // Filter by agent if specified
281
+ let filteredHistory = system.verificationHistory;
282
+ if (flags.agent) {
283
+ filteredHistory = system.verificationHistory.filter((v)=>v.agentType === flags.agent);
284
+ if (filteredHistory.length === 0) {
285
+ console.log(`\nāš ļø No verification history found for agent: ${flags.agent}`);
286
+ return;
287
+ }
288
+ }
289
+ // Filter by taskId if specified
290
+ if (flags.taskId) {
291
+ filteredHistory = filteredHistory.filter((v)=>v.taskId === flags.taskId);
292
+ if (filteredHistory.length === 0) {
293
+ console.log(`\nāš ļø No verification history found for task: ${flags.taskId}`);
294
+ return;
295
+ }
296
+ }
297
+ // Filter by threshold if specified
298
+ if (flags.threshold) {
299
+ const threshold = parseFloat(flags.threshold);
300
+ filteredHistory = filteredHistory.filter((v)=>v.score < threshold);
301
+ if (filteredHistory.length === 0) {
302
+ console.log(`\nāœ… All verifications meet or exceed threshold: ${threshold}`);
303
+ return;
304
+ }
322
305
  }
323
- }
324
-
325
- // Score distribution
326
- const scores = filteredHistory.map((v) => v.score);
327
- const minScore = Math.min(...scores);
328
- const maxScore = Math.max(...scores);
329
- console.log('\nšŸ“Š Score Distribution:');
330
- console.log(` Min Score: ${minScore.toFixed(3)}`);
331
- console.log(` Max Score: ${maxScore.toFixed(3)}`);
332
- console.log(` Average: ${report.averageScore.toFixed(3)}`);
333
-
334
- // Performance trend
335
- if (filteredHistory.length > 5) {
336
- const recent5 = filteredHistory.slice(-5);
337
- const older5 = filteredHistory.slice(-10, -5);
338
- const recentAvg = recent5.reduce((sum, v) => sum + v.score, 0) / recent5.length;
339
- const olderAvg =
340
- older5.length > 0 ? older5.reduce((sum, v) => sum + v.score, 0) / older5.length : 0;
341
-
342
- console.log('\nšŸ“ˆ Performance Trend:');
343
- if (olderAvg > 0) {
344
- const trend = recentAvg - olderAvg;
345
- const trendSymbol = trend > 0 ? '↑' : trend < 0 ? '↓' : '→';
346
- console.log(` Recent Average: ${recentAvg.toFixed(3)} ${trendSymbol}`);
347
- console.log(` Previous Average: ${olderAvg.toFixed(3)}`);
348
- console.log(` Change: ${trend >= 0 ? '+' : ''}${(trend * 100).toFixed(1)}%`);
306
+ // Generate report (with filtered data if agent specified)
307
+ const report = flags.agent ? await generateFilteredReport(system, filteredHistory, flags.agent) : await system.generateTruthReport();
308
+ // JSON output only mode
309
+ if (flags.json) {
310
+ console.log(JSON.stringify(report, null, 2));
311
+ return;
312
+ }
313
+ // Basic report (shown when not in JSON mode)
314
+ console.log('\nšŸ“Š Truth Scoring Report' + (flags.agent ? ` - Agent: ${flags.agent}` : ''));
315
+ console.log('━'.repeat(50));
316
+ console.log(`Mode: ${report.mode || system.mode}`);
317
+ console.log(`Threshold: ${report.threshold || VERIFICATION_MODES[system.mode].threshold}`);
318
+ console.log(`Total Verifications: ${report.totalVerifications}`);
319
+ console.log(`Passed: ${report.passedVerifications}`);
320
+ console.log(`Average Score: ${report.averageScore.toFixed(3)}`);
321
+ if (flags.agent) {
322
+ // Show detailed info for specific agent
323
+ console.log(`\nšŸ¤– ${flags.agent} Agent Details:`);
324
+ console.log(` Reliability: ${(report.agentReliability[flags.agent] * 100).toFixed(1)}%`);
325
+ console.log(` Total Tasks: ${filteredHistory.length}`);
326
+ console.log(` Passed: ${filteredHistory.filter((v)=>v.passed).length}`);
327
+ console.log(` Failed: ${filteredHistory.filter((v)=>!v.passed).length}`);
328
+ if (flags.detailed || flags.detail) {
329
+ console.log('\nšŸ“‹ Verification History:');
330
+ const recentAgent = filteredHistory.slice(-10);
331
+ for (const v of recentAgent){
332
+ const time = new Date(v.timestamp).toLocaleTimeString();
333
+ console.log(` ${v.passed ? 'āœ…' : 'āŒ'} [${time}] ${v.taskId}: ${v.score.toFixed(3)}`);
334
+ if (v.results && flags.verbose) {
335
+ for (const [check, result] of Object.entries(v.results)){
336
+ console.log(` • ${check}: ${result.passed ? 'āœ“' : 'āœ—'} (${result.score.toFixed(2)})`);
337
+ }
338
+ }
339
+ }
340
+ // Score distribution
341
+ const scores = filteredHistory.map((v)=>v.score);
342
+ const minScore = Math.min(...scores);
343
+ const maxScore = Math.max(...scores);
344
+ console.log('\nšŸ“Š Score Distribution:');
345
+ console.log(` Min Score: ${minScore.toFixed(3)}`);
346
+ console.log(` Max Score: ${maxScore.toFixed(3)}`);
347
+ console.log(` Average: ${report.averageScore.toFixed(3)}`);
348
+ // Performance trend
349
+ if (filteredHistory.length > 5) {
350
+ const recent5 = filteredHistory.slice(-5);
351
+ const older5 = filteredHistory.slice(-10, -5);
352
+ const recentAvg = recent5.reduce((sum, v)=>sum + v.score, 0) / recent5.length;
353
+ const olderAvg = older5.length > 0 ? older5.reduce((sum, v)=>sum + v.score, 0) / older5.length : 0;
354
+ console.log('\nšŸ“ˆ Performance Trend:');
355
+ if (olderAvg > 0) {
356
+ const trend = recentAvg - olderAvg;
357
+ const trendSymbol = trend > 0 ? '↑' : trend < 0 ? '↓' : '→';
358
+ console.log(` Recent Average: ${recentAvg.toFixed(3)} ${trendSymbol}`);
359
+ console.log(` Previous Average: ${olderAvg.toFixed(3)}`);
360
+ console.log(` Change: ${trend >= 0 ? '+' : ''}${(trend * 100).toFixed(1)}%`);
361
+ } else {
362
+ console.log(` Recent Average: ${recentAvg.toFixed(3)}`);
363
+ }
364
+ }
365
+ }
349
366
  } else {
350
- console.log(` Recent Average: ${recentAvg.toFixed(3)}`);
367
+ console.log('\nšŸ¤– Agent Reliability:');
368
+ for (const [agent, reliability] of Object.entries(report.agentReliability)){
369
+ console.log(` ${agent}: ${(reliability * 100).toFixed(1)}%`);
370
+ }
351
371
  }
352
- }
353
- }
354
- } else {
355
- console.log('\nšŸ¤– Agent Reliability:');
356
- for (const [agent, reliability] of Object.entries(report.agentReliability)) {
357
- console.log(` ${agent}: ${(reliability * 100).toFixed(1)}%`);
358
- }
359
- }
360
-
361
- // Detailed report with --report flag
362
- if (flags.report) {
363
- console.log('\nšŸ“ˆ Detailed Verification Breakdown:');
364
- console.log(
365
- ` Pass Rate: ${((report.passedVerifications / report.totalVerifications) * 100).toFixed(1)}%`,
366
- );
367
- console.log(
368
- ` Failure Rate: ${(((report.totalVerifications - report.passedVerifications) / report.totalVerifications) * 100).toFixed(1)}%`,
369
- );
370
-
371
- // Show recent history
372
- if (system.verificationHistory.length > 0) {
373
- console.log('\nšŸ“œ Last 10 Verifications:');
374
- const recent = system.verificationHistory.slice(-10);
375
- for (const v of recent) {
376
- const time = new Date(v.timestamp).toLocaleTimeString();
377
- console.log(
378
- ` ${v.passed ? 'āœ…' : 'āŒ'} [${time}] ${v.taskId} (${v.agentType}): ${v.score.toFixed(3)}`,
379
- );
380
- }
381
- }
382
-
383
- // Performance metrics
384
- console.log('\nšŸŽÆ Target Metrics Comparison:');
385
- console.log(
386
- ` Truth Accuracy: ${report.averageScore >= 0.95 ? 'āœ…' : 'āŒ'} ${(report.averageScore * 100).toFixed(1)}% (target: 95%)`,
387
- );
388
- console.log(
389
- ` Pass Rate: ${report.passedVerifications / report.totalVerifications >= 0.9 ? 'āœ…' : 'āŒ'} ${((report.passedVerifications / report.totalVerifications) * 100).toFixed(1)}% (target: 90%)`,
390
- );
391
- }
392
-
393
- // Failure analysis with --analyze flag
394
- if (flags.analyze) {
395
- console.log('\nšŸ” Failure Pattern Analysis:');
396
-
397
- // Analyze failures by agent
398
- const failures = system.verificationHistory.filter((v) => !v.passed);
399
- if (failures.length > 0) {
400
- const failuresByAgent = {};
401
- for (const f of failures) {
402
- failuresByAgent[f.agentType] = (failuresByAgent[f.agentType] || 0) + 1;
403
- }
404
-
405
- console.log(' Failures by Agent:');
406
- for (const [agent, count] of Object.entries(failuresByAgent)) {
407
- const percentage = ((count / failures.length) * 100).toFixed(1);
408
- console.log(` • ${agent}: ${count} failures (${percentage}%)`);
409
- }
410
-
411
- // Common failure scores
412
- const failureScores = failures.map((f) => f.score);
413
- const avgFailureScore = failureScores.reduce((a, b) => a + b, 0) / failureScores.length;
414
- console.log(`\n Average Failure Score: ${avgFailureScore.toFixed(3)}`);
415
- console.log(
416
- ` Score Gap to Threshold: ${(report.threshold - avgFailureScore).toFixed(3)}`,
417
- );
418
-
419
- // Recommendations
420
- console.log('\nšŸ’” Recommendations:');
421
- if (avgFailureScore < 0.5) {
422
- console.log(' • Critical: Major quality issues detected');
423
- console.log(' • Consider switching to development mode for debugging');
424
- console.log(' • Review agent configurations and requirements');
425
- } else if (avgFailureScore < report.threshold) {
426
- console.log(' • Moderate: Close to threshold but needs improvement');
427
- console.log(' • Focus on failing agents: ' + Object.keys(failuresByAgent).join(', '));
428
- console.log(' • Consider adjusting verification requirements');
429
- }
430
- } else {
431
- console.log(' āœ… No failures detected!');
432
- }
433
- }
434
-
435
- // Export to file with --export flag
436
- if (flags.export) {
437
- const exportPath =
438
- typeof flags.export === 'string' ? flags.export : `truth-report-${Date.now()}.json`;
439
- const exportData = {
440
- report,
441
- filteredHistory,
442
- metadata: {
443
- exported: new Date().toISOString(),
444
- filters: {
445
- agent: flags.agent || null,
446
- taskId: flags.taskId || null,
447
- threshold: flags.threshold || null,
448
- },
449
- command: 'truth',
450
- version: '2.0.0-alpha.89',
451
- },
452
- };
453
-
454
- try {
455
- await fs.writeFile(exportPath, JSON.stringify(exportData, null, 2));
456
- console.log(`\nšŸ“ Report exported to: ${exportPath}`);
457
- } catch (error) {
458
- console.error(`\nāŒ Failed to export report: ${error.message}`);
459
- }
460
- }
461
- break;
462
-
463
- case 'status':
464
- default:
465
- await system.loadMemory();
466
- console.log('\nšŸ” Verification System Status');
467
- console.log('━'.repeat(50));
468
- console.log(`Mode: ${system.mode}`);
469
- console.log(`Verifications: ${system.verificationHistory.length}`);
470
- console.log(`Recent: ${system.verificationHistory.slice(-5).length} verifications`);
471
-
472
- if (system.verificationHistory.length > 0) {
473
- const recent = system.verificationHistory.slice(-5);
474
- console.log('\nšŸ“œ Recent Verifications:');
475
- for (const v of recent) {
476
- console.log(
477
- ` ${v.passed ? 'āœ…' : 'āŒ'} ${v.taskId} (${v.agentType}): ${v.score.toFixed(2)}`,
478
- );
479
- }
480
- }
481
-
482
- console.log('\nšŸ’” Commands:');
483
- console.log(' verify init [mode] - Initialize system');
484
- console.log(' verify verify [taskId] - Verify a task');
485
- console.log(' verify truth - Show truth scores');
486
- console.log(' verify status - Show system status');
487
- break;
488
- }
372
+ // Detailed report with --report flag
373
+ if (flags.report) {
374
+ console.log('\nšŸ“ˆ Detailed Verification Breakdown:');
375
+ console.log(` Pass Rate: ${(report.passedVerifications / report.totalVerifications * 100).toFixed(1)}%`);
376
+ console.log(` Failure Rate: ${((report.totalVerifications - report.passedVerifications) / report.totalVerifications * 100).toFixed(1)}%`);
377
+ // Show recent history
378
+ if (system.verificationHistory.length > 0) {
379
+ console.log('\nšŸ“œ Last 10 Verifications:');
380
+ const recent = system.verificationHistory.slice(-10);
381
+ for (const v of recent){
382
+ const time = new Date(v.timestamp).toLocaleTimeString();
383
+ console.log(` ${v.passed ? 'āœ…' : 'āŒ'} [${time}] ${v.taskId} (${v.agentType}): ${v.score.toFixed(3)}`);
384
+ }
385
+ }
386
+ // Performance metrics
387
+ console.log('\nšŸŽÆ Target Metrics Comparison:');
388
+ console.log(` Truth Accuracy: ${report.averageScore >= 0.95 ? 'āœ…' : 'āŒ'} ${(report.averageScore * 100).toFixed(1)}% (target: 95%)`);
389
+ console.log(` Pass Rate: ${report.passedVerifications / report.totalVerifications >= 0.9 ? 'āœ…' : 'āŒ'} ${(report.passedVerifications / report.totalVerifications * 100).toFixed(1)}% (target: 90%)`);
390
+ }
391
+ // Failure analysis with --analyze flag
392
+ if (flags.analyze) {
393
+ console.log('\nšŸ” Failure Pattern Analysis:');
394
+ // Analyze failures by agent
395
+ const failures = system.verificationHistory.filter((v)=>!v.passed);
396
+ if (failures.length > 0) {
397
+ const failuresByAgent = {};
398
+ for (const f of failures){
399
+ failuresByAgent[f.agentType] = (failuresByAgent[f.agentType] || 0) + 1;
400
+ }
401
+ console.log(' Failures by Agent:');
402
+ for (const [agent, count] of Object.entries(failuresByAgent)){
403
+ const percentage = (count / failures.length * 100).toFixed(1);
404
+ console.log(` • ${agent}: ${count} failures (${percentage}%)`);
405
+ }
406
+ // Common failure scores
407
+ const failureScores = failures.map((f)=>f.score);
408
+ const avgFailureScore = failureScores.reduce((a, b)=>a + b, 0) / failureScores.length;
409
+ console.log(`\n Average Failure Score: ${avgFailureScore.toFixed(3)}`);
410
+ console.log(` Score Gap to Threshold: ${(report.threshold - avgFailureScore).toFixed(3)}`);
411
+ // Recommendations
412
+ console.log('\nšŸ’” Recommendations:');
413
+ if (avgFailureScore < 0.5) {
414
+ console.log(' • Critical: Major quality issues detected');
415
+ console.log(' • Consider switching to development mode for debugging');
416
+ console.log(' • Review agent configurations and requirements');
417
+ } else if (avgFailureScore < report.threshold) {
418
+ console.log(' • Moderate: Close to threshold but needs improvement');
419
+ console.log(' • Focus on failing agents: ' + Object.keys(failuresByAgent).join(', '));
420
+ console.log(' • Consider adjusting verification requirements');
421
+ }
422
+ } else {
423
+ console.log(' āœ… No failures detected!');
424
+ }
425
+ }
426
+ // Export to file with --export flag
427
+ if (flags.export) {
428
+ const exportPath = typeof flags.export === 'string' ? flags.export : `truth-report-${Date.now()}.json`;
429
+ const exportData = {
430
+ report,
431
+ filteredHistory,
432
+ metadata: {
433
+ exported: new Date().toISOString(),
434
+ filters: {
435
+ agent: flags.agent || null,
436
+ taskId: flags.taskId || null,
437
+ threshold: flags.threshold || null
438
+ },
439
+ command: 'truth',
440
+ version: '2.0.0-alpha.89'
441
+ }
442
+ };
443
+ try {
444
+ await fs.writeFile(exportPath, JSON.stringify(exportData, null, 2));
445
+ console.log(`\nšŸ“ Report exported to: ${exportPath}`);
446
+ } catch (error) {
447
+ console.error(`\nāŒ Failed to export report: ${error.message}`);
448
+ }
449
+ }
450
+ break;
451
+ case 'status':
452
+ default:
453
+ await system.loadMemory();
454
+ console.log('\nšŸ” Verification System Status');
455
+ console.log('━'.repeat(50));
456
+ console.log(`Mode: ${system.mode}`);
457
+ console.log(`Verifications: ${system.verificationHistory.length}`);
458
+ console.log(`Recent: ${system.verificationHistory.slice(-5).length} verifications`);
459
+ if (system.verificationHistory.length > 0) {
460
+ const recent = system.verificationHistory.slice(-5);
461
+ console.log('\nšŸ“œ Recent Verifications:');
462
+ for (const v of recent){
463
+ console.log(` ${v.passed ? 'āœ…' : 'āŒ'} ${v.taskId} (${v.agentType}): ${v.score.toFixed(2)}`);
464
+ }
465
+ }
466
+ console.log('\nšŸ’” Commands:');
467
+ console.log(' verify init [mode] - Initialize system');
468
+ console.log(' verify verify [taskId] - Verify a task');
469
+ console.log(' verify truth - Show truth scores');
470
+ console.log(' verify status - Show system status');
471
+ break;
472
+ }
489
473
  }
490
-
491
474
  // Truth command shortcut
492
475
  export async function truthCommand(args, flags) {
493
- // Handle help flag
494
- if (flags.help || args[0] === '--help' || args[0] === 'help') {
495
- const { COMMAND_HELP } = await import('../help-text.js');
496
- console.log(COMMAND_HELP.truth);
497
- return;
498
- }
499
- return verificationCommand(['truth', ...args], flags);
476
+ // Handle help flag
477
+ if (flags.help || args[0] === '--help' || args[0] === 'help') {
478
+ const { COMMAND_HELP } = await import("../help-text.js");
479
+ console.log(COMMAND_HELP.truth);
480
+ return;
481
+ }
482
+ return verificationCommand([
483
+ 'truth',
484
+ ...args
485
+ ], flags);
500
486
  }
501
-
502
487
  // Pair programming command
503
488
  export async function pairCommand(args, flags) {
504
- // Handle help flag
505
- if (flags.help || args[0] === '--help' || args[0] === 'help') {
506
- const { COMMAND_HELP } = await import('../help-text.js');
507
- console.log(COMMAND_HELP.pair);
508
- return;
509
- }
510
- console.log('\nšŸ‘„ Pair Programming with Verification');
511
- console.log('━'.repeat(50));
512
-
513
- const system = new VerificationSystem();
514
- await system.initialize('strict');
515
-
516
- console.log('\nšŸŽÆ Verification-First Development Mode Activated');
517
- console.log(' • All changes require verification');
518
- console.log(' • Truth threshold: 0.95');
519
- console.log(' • Real-time validation enabled');
520
- console.log(' • Auto-rollback on failures');
521
-
522
- if (flags.start) {
523
- console.log('\nšŸš€ Starting pair programming session...');
524
- console.log(' Monitoring file changes...');
525
- console.log(' Running continuous verification...');
526
-
527
- // Simulate monitoring
528
- let iteration = 0;
529
- const interval = setInterval(async () => {
530
- iteration++;
531
- console.log(`\n[${new Date().toISOString()}] Verification cycle ${iteration}`);
532
-
533
- const taskId = `pair-${Date.now()}`;
534
- const result = await system.verifyTask(taskId, 'coder', { success: Math.random() > 0.3 });
535
-
536
- if (iteration >= 3 || !result.passed) {
537
- clearInterval(interval);
538
- console.log('\n✨ Pair programming session complete');
539
- }
540
- }, 3000);
541
- } else {
542
- console.log('\nšŸ’” Use --start to begin a pair programming session');
543
- }
489
+ // Handle help flag
490
+ if (flags.help || args[0] === '--help' || args[0] === 'help') {
491
+ const { COMMAND_HELP } = await import("../help-text.js");
492
+ console.log(COMMAND_HELP.pair);
493
+ return;
494
+ }
495
+ console.log('\nšŸ‘„ Pair Programming with Verification');
496
+ console.log('━'.repeat(50));
497
+ const system = new VerificationSystem();
498
+ await system.initialize('strict');
499
+ console.log('\nšŸŽÆ Verification-First Development Mode Activated');
500
+ console.log(' • All changes require verification');
501
+ console.log(' • Truth threshold: 0.95');
502
+ console.log(' • Real-time validation enabled');
503
+ console.log(' • Auto-rollback on failures');
504
+ if (flags.start) {
505
+ console.log('\nšŸš€ Starting pair programming session...');
506
+ console.log(' Monitoring file changes...');
507
+ console.log(' Running continuous verification...');
508
+ // Simulate monitoring
509
+ let iteration = 0;
510
+ const interval = setInterval(async ()=>{
511
+ iteration++;
512
+ console.log(`\n[${new Date().toISOString()}] Verification cycle ${iteration}`);
513
+ const taskId = `pair-${Date.now()}`;
514
+ const result = await system.verifyTask(taskId, 'coder', {
515
+ success: Math.random() > 0.3
516
+ });
517
+ if (iteration >= 3 || !result.passed) {
518
+ clearInterval(interval);
519
+ console.log('\n✨ Pair programming session complete');
520
+ }
521
+ }, 3000);
522
+ } else {
523
+ console.log('\nšŸ’” Use --start to begin a pair programming session');
524
+ }
544
525
  }
545
-
546
526
  // Export for use in command registry
547
527
  export default {
548
- verificationCommand,
549
- truthCommand,
550
- pairCommand,
528
+ verificationCommand,
529
+ truthCommand,
530
+ pairCommand
551
531
  };