agentic-qe 3.7.21 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/.claude/helpers/brain-checkpoint.cjs +4 -1
  2. package/.claude/helpers/statusline-v3.cjs +3 -1
  3. package/.claude/skills/skills-manifest.json +1 -1
  4. package/CHANGELOG.md +45 -0
  5. package/README.md +2 -14
  6. package/assets/helpers/statusline-v3.cjs +3 -1
  7. package/dist/cli/brain-commands.js +6 -10
  8. package/dist/cli/bundle.js +7441 -4327
  9. package/dist/cli/commands/audit.d.ts +43 -0
  10. package/dist/cli/commands/audit.js +125 -0
  11. package/dist/cli/commands/hooks.js +29 -6
  12. package/dist/cli/commands/init.js +1 -73
  13. package/dist/cli/commands/learning.js +270 -13
  14. package/dist/cli/commands/ruvector-commands.d.ts +15 -0
  15. package/dist/cli/commands/ruvector-commands.js +271 -0
  16. package/dist/cli/handlers/init-handler.d.ts +0 -1
  17. package/dist/cli/handlers/init-handler.js +0 -6
  18. package/dist/cli/index.js +4 -2
  19. package/dist/context/sources/defect-source.js +2 -2
  20. package/dist/context/sources/memory-source.js +2 -2
  21. package/dist/context/sources/requirements-source.js +2 -2
  22. package/dist/coordination/behavior-tree/decorators.d.ts +108 -0
  23. package/dist/coordination/behavior-tree/decorators.js +251 -0
  24. package/dist/coordination/behavior-tree/index.d.ts +12 -0
  25. package/dist/coordination/behavior-tree/index.js +15 -0
  26. package/dist/coordination/behavior-tree/nodes.d.ts +165 -0
  27. package/dist/coordination/behavior-tree/nodes.js +338 -0
  28. package/dist/coordination/behavior-tree/qe-trees.d.ts +105 -0
  29. package/dist/coordination/behavior-tree/qe-trees.js +181 -0
  30. package/dist/coordination/coherence-action-gate.d.ts +284 -0
  31. package/dist/coordination/coherence-action-gate.js +512 -0
  32. package/dist/coordination/index.d.ts +4 -0
  33. package/dist/coordination/index.js +8 -0
  34. package/dist/coordination/reasoning-qec.d.ts +315 -0
  35. package/dist/coordination/reasoning-qec.js +585 -0
  36. package/dist/coordination/task-executor.d.ts +16 -0
  37. package/dist/coordination/task-executor.js +99 -0
  38. package/dist/coordination/workflow-orchestrator.d.ts +29 -0
  39. package/dist/coordination/workflow-orchestrator.js +42 -0
  40. package/dist/domains/visual-accessibility/cnn-visual-regression.d.ts +135 -0
  41. package/dist/domains/visual-accessibility/cnn-visual-regression.js +327 -0
  42. package/dist/domains/visual-accessibility/index.d.ts +1 -0
  43. package/dist/domains/visual-accessibility/index.js +4 -0
  44. package/dist/governance/coherence-validator.d.ts +112 -0
  45. package/dist/governance/coherence-validator.js +180 -0
  46. package/dist/governance/index.d.ts +1 -0
  47. package/dist/governance/index.js +2 -0
  48. package/dist/governance/witness-chain.d.ts +311 -0
  49. package/dist/governance/witness-chain.js +509 -0
  50. package/dist/init/index.d.ts +0 -2
  51. package/dist/init/index.js +0 -1
  52. package/dist/init/init-wizard-steps.d.ts +10 -0
  53. package/dist/init/init-wizard-steps.js +87 -1
  54. package/dist/init/init-wizard.d.ts +1 -9
  55. package/dist/init/init-wizard.js +3 -69
  56. package/dist/init/orchestrator.js +0 -1
  57. package/dist/init/phases/01-detection.js +0 -27
  58. package/dist/init/phases/07-hooks.js +6 -4
  59. package/dist/init/phases/phase-interface.d.ts +0 -1
  60. package/dist/init/settings-merge.js +1 -1
  61. package/dist/integrations/browser/qe-dashboard/clustering.d.ts +48 -0
  62. package/dist/integrations/browser/qe-dashboard/clustering.js +183 -0
  63. package/dist/integrations/browser/qe-dashboard/index.d.ts +12 -0
  64. package/dist/integrations/browser/qe-dashboard/index.js +15 -0
  65. package/dist/integrations/browser/qe-dashboard/pattern-explorer.d.ts +165 -0
  66. package/dist/integrations/browser/qe-dashboard/pattern-explorer.js +260 -0
  67. package/dist/integrations/browser/qe-dashboard/wasm-vector-store.d.ts +144 -0
  68. package/dist/integrations/browser/qe-dashboard/wasm-vector-store.js +277 -0
  69. package/dist/integrations/ruvector/cognitive-container-codec.d.ts +51 -0
  70. package/dist/integrations/ruvector/cognitive-container-codec.js +180 -0
  71. package/dist/integrations/ruvector/cognitive-container.d.ts +125 -0
  72. package/dist/integrations/ruvector/cognitive-container.js +306 -0
  73. package/dist/integrations/ruvector/coherence-gate.d.ts +309 -0
  74. package/dist/integrations/ruvector/coherence-gate.js +631 -0
  75. package/dist/integrations/ruvector/compressed-hnsw-integration.d.ts +176 -0
  76. package/dist/integrations/ruvector/compressed-hnsw-integration.js +301 -0
  77. package/dist/integrations/ruvector/dither-adapter.d.ts +122 -0
  78. package/dist/integrations/ruvector/dither-adapter.js +295 -0
  79. package/dist/integrations/ruvector/domain-transfer.d.ts +129 -0
  80. package/dist/integrations/ruvector/domain-transfer.js +220 -0
  81. package/dist/integrations/ruvector/feature-flags.d.ts +214 -2
  82. package/dist/integrations/ruvector/feature-flags.js +167 -2
  83. package/dist/integrations/ruvector/filter-adapter.d.ts +71 -0
  84. package/dist/integrations/ruvector/filter-adapter.js +285 -0
  85. package/dist/integrations/ruvector/gnn-wrapper.d.ts +20 -0
  86. package/dist/integrations/ruvector/gnn-wrapper.js +40 -0
  87. package/dist/integrations/ruvector/hnsw-health-monitor.d.ts +237 -0
  88. package/dist/integrations/ruvector/hnsw-health-monitor.js +394 -0
  89. package/dist/integrations/ruvector/index.d.ts +8 -2
  90. package/dist/integrations/ruvector/index.js +18 -2
  91. package/dist/integrations/ruvector/interfaces.d.ts +40 -0
  92. package/dist/integrations/ruvector/sona-persistence.d.ts +54 -0
  93. package/dist/integrations/ruvector/sona-persistence.js +162 -0
  94. package/dist/integrations/ruvector/sona-three-loop.d.ts +392 -0
  95. package/dist/integrations/ruvector/sona-three-loop.js +814 -0
  96. package/dist/integrations/ruvector/sona-wrapper.d.ts +97 -0
  97. package/dist/integrations/ruvector/sona-wrapper.js +147 -3
  98. package/dist/integrations/ruvector/spectral-math.d.ts +101 -0
  99. package/dist/integrations/ruvector/spectral-math.js +254 -0
  100. package/dist/integrations/ruvector/temporal-compression.d.ts +163 -0
  101. package/dist/integrations/ruvector/temporal-compression.js +318 -0
  102. package/dist/integrations/ruvector/thompson-sampler.d.ts +61 -0
  103. package/dist/integrations/ruvector/thompson-sampler.js +118 -0
  104. package/dist/integrations/ruvector/transfer-coherence-stub.d.ts +80 -0
  105. package/dist/integrations/ruvector/transfer-coherence-stub.js +63 -0
  106. package/dist/integrations/ruvector/transfer-verification.d.ts +119 -0
  107. package/dist/integrations/ruvector/transfer-verification.js +115 -0
  108. package/dist/kernel/hnsw-adapter.d.ts +52 -1
  109. package/dist/kernel/hnsw-adapter.js +139 -4
  110. package/dist/kernel/hnsw-index-provider.d.ts +5 -0
  111. package/dist/kernel/native-hnsw-backend.d.ts +110 -0
  112. package/dist/kernel/native-hnsw-backend.js +408 -0
  113. package/dist/kernel/unified-memory.js +5 -6
  114. package/dist/learning/aqe-learning-engine.d.ts +2 -0
  115. package/dist/learning/aqe-learning-engine.js +65 -0
  116. package/dist/learning/experience-capture-middleware.js +20 -0
  117. package/dist/learning/experience-capture.d.ts +10 -0
  118. package/dist/learning/experience-capture.js +34 -0
  119. package/dist/learning/index.d.ts +2 -2
  120. package/dist/learning/index.js +4 -4
  121. package/dist/learning/metrics-tracker.d.ts +11 -0
  122. package/dist/learning/metrics-tracker.js +29 -13
  123. package/dist/learning/pattern-lifecycle.d.ts +30 -1
  124. package/dist/learning/pattern-lifecycle.js +92 -20
  125. package/dist/learning/pattern-store.d.ts +8 -0
  126. package/dist/learning/pattern-store.js +8 -2
  127. package/dist/learning/qe-unified-memory.js +1 -28
  128. package/dist/learning/regret-tracker.d.ts +201 -0
  129. package/dist/learning/regret-tracker.js +361 -0
  130. package/dist/mcp/bundle.js +5915 -474
  131. package/dist/routing/index.d.ts +4 -2
  132. package/dist/routing/index.js +3 -1
  133. package/dist/routing/neural-tiny-dancer-router.d.ts +268 -0
  134. package/dist/routing/neural-tiny-dancer-router.js +514 -0
  135. package/dist/routing/queen-integration.js +5 -5
  136. package/dist/routing/routing-config.d.ts +6 -0
  137. package/dist/routing/routing-config.js +1 -0
  138. package/dist/routing/simple-neural-router.d.ts +76 -0
  139. package/dist/routing/simple-neural-router.js +202 -0
  140. package/dist/routing/tiny-dancer-router.d.ts +20 -1
  141. package/dist/routing/tiny-dancer-router.js +21 -2
  142. package/dist/test-scheduling/dag-attention-scheduler.d.ts +81 -0
  143. package/dist/test-scheduling/dag-attention-scheduler.js +358 -0
  144. package/dist/test-scheduling/dag-attention-types.d.ts +81 -0
  145. package/dist/test-scheduling/dag-attention-types.js +10 -0
  146. package/dist/test-scheduling/index.d.ts +1 -0
  147. package/dist/test-scheduling/index.js +4 -0
  148. package/dist/test-scheduling/pipeline.d.ts +8 -0
  149. package/dist/test-scheduling/pipeline.js +28 -0
  150. package/package.json +6 -2
  151. package/dist/cli/commands/migrate.d.ts +0 -9
  152. package/dist/cli/commands/migrate.js +0 -566
  153. package/dist/init/init-wizard-migration.d.ts +0 -52
  154. package/dist/init/init-wizard-migration.js +0 -345
  155. package/dist/init/migration/config-migrator.d.ts +0 -31
  156. package/dist/init/migration/config-migrator.js +0 -149
  157. package/dist/init/migration/data-migrator.d.ts +0 -72
  158. package/dist/init/migration/data-migrator.js +0 -232
  159. package/dist/init/migration/detector.d.ts +0 -44
  160. package/dist/init/migration/detector.js +0 -105
  161. package/dist/init/migration/index.d.ts +0 -8
  162. package/dist/init/migration/index.js +0 -8
  163. package/dist/learning/v2-to-v3-migration.d.ts +0 -86
  164. package/dist/learning/v2-to-v3-migration.js +0 -529
@@ -13,14 +13,15 @@ import { Command } from 'commander';
13
13
  import chalk from 'chalk';
14
14
  import path from 'node:path';
15
15
  import { findProjectRoot } from '../../kernel/unified-memory.js';
16
- import { existsSync, writeFileSync, readFileSync, mkdirSync, copyFileSync } from 'node:fs';
16
+ import { existsSync, writeFileSync, readFileSync, mkdirSync, copyFileSync, renameSync } from 'node:fs';
17
17
  import { safeJsonParse } from '../../shared/safe-json.js';
18
18
  import { stat, unlink } from 'node:fs/promises';
19
19
  import { QE_DOMAIN_LIST } from '../../learning/qe-patterns.js';
20
20
  import { createLearningMetricsTracker, } from '../../learning/metrics-tracker.js';
21
+ import { createRegretTracker, } from '../../learning/regret-tracker.js';
21
22
  import { openDatabase } from '../../shared/safe-db.js';
22
23
  // Extracted helpers
23
- import { initializeLearningSystem, printJson, printSuccess, printError, printInfo, displayDashboard, getDbPath, compressFile, decompressFile, verifyDatabaseIntegrity, getSchemaVersion, EXPORT_FORMAT_VERSION, DOMAIN_MAPPING, PATTERN_TYPE_MAPPING, } from './learning-helpers.js';
24
+ import { initializeLearningSystem, printJson, printSuccess, printError, printInfo, displayDashboard, getDbPath, compressFile, decompressFile, verifyDatabaseIntegrity, getSchemaVersion, padRight, EXPORT_FORMAT_VERSION, DOMAIN_MAPPING, PATTERN_TYPE_MAPPING, } from './learning-helpers.js';
24
25
  // ============================================================================
25
26
  // Learning Command
26
27
  // ============================================================================
@@ -62,6 +63,8 @@ Examples:
62
63
  registerExportFullCommand(learning);
63
64
  registerImportMergeCommand(learning);
64
65
  registerDreamCommand(learning);
66
+ registerRepairCommand(learning);
67
+ registerHealthCommand(learning);
65
68
  return learning;
66
69
  }
67
70
  // ============================================================================
@@ -372,15 +375,19 @@ function registerExtractCommand(learning) {
372
375
  console.log(` Min occurrences: ${minCount}\n`);
373
376
  const db = openDatabase(dbPath, { readonly: true });
374
377
  const experiences = db.prepare(`
375
- SELECT task_type, COUNT(*) as count, AVG(reward) as avg_reward, MAX(reward) as max_reward,
376
- MIN(reward) as min_reward, GROUP_CONCAT(DISTINCT action) as actions
377
- FROM learning_experiences WHERE reward >= ? GROUP BY task_type HAVING COUNT(*) >= ? ORDER BY avg_reward DESC
378
+ SELECT domain as task_type, COUNT(*) as count, AVG(quality) as avg_reward, MAX(quality) as max_reward,
379
+ MIN(quality) as min_reward, GROUP_CONCAT(DISTINCT agent) as actions
380
+ FROM captured_experiences WHERE quality >= ? AND agent != 'cli-hook' GROUP BY domain HAVING COUNT(*) >= ? ORDER BY avg_reward DESC
378
381
  `).all(minReward, minCount);
379
- const memoryPatterns = db.prepare(`
380
- SELECT substr(key, 1, 40) as key_prefix, COUNT(*) as count
381
- FROM memory_entries WHERE key LIKE 'phase2/learning/%'
382
- GROUP BY substr(key, 1, 40) HAVING COUNT(*) >= ? ORDER BY COUNT(*) DESC LIMIT 20
383
- `).all(minCount);
382
+ let memoryPatterns = [];
383
+ try {
384
+ memoryPatterns = db.prepare(`
385
+ SELECT substr(key, 1, 40) as key_prefix, COUNT(*) as count
386
+ FROM memory_entries WHERE key LIKE 'phase2/learning/%'
387
+ GROUP BY substr(key, 1, 40) HAVING COUNT(*) >= ? ORDER BY COUNT(*) DESC LIMIT 20
388
+ `).all(minCount);
389
+ }
390
+ catch { /* memory_entries table may not exist */ }
384
391
  db.close();
385
392
  const extractedPatterns = [];
386
393
  for (const exp of experiences) {
@@ -689,7 +696,7 @@ function registerVerifyCommand(learning) {
689
696
  let tableCounts = {};
690
697
  try {
691
698
  const db = openDatabase(dbPath, { readonly: true });
692
- for (const table of ['qe_patterns', 'qe_trajectories', 'learning_experiences', 'kv_store', 'vectors']) {
699
+ for (const table of ['qe_patterns', 'qe_trajectories', 'captured_experiences', 'kv_store', 'vectors']) {
693
700
  try {
694
701
  const r = db.prepare(`SELECT COUNT(*) as count FROM ${table}`).get();
695
702
  tableCounts[table] = r.count;
@@ -770,9 +777,9 @@ function registerExportFullCommand(learning) {
770
777
  if (options.includeExperiences) {
771
778
  try {
772
779
  const db = openDatabase(dbPath, { readonly: true });
773
- const experiences = db.prepare(`SELECT task_type, action, AVG(reward) as avg_reward, COUNT(*) as count FROM learning_experiences GROUP BY task_type, action ORDER BY count DESC LIMIT 500`).all();
780
+ const experiences = db.prepare(`SELECT domain as task_type, agent as action, AVG(quality) as avg_reward, COUNT(*) as count FROM captured_experiences WHERE agent != 'cli-hook' GROUP BY domain, agent ORDER BY count DESC LIMIT 500`).all();
774
781
  exportData.experiences = experiences.map(e => ({ taskType: e.task_type, action: e.action, reward: e.avg_reward, count: e.count }));
775
- const metaRow = db.prepare(`SELECT COUNT(*) as total, AVG(reward) as avg_reward FROM learning_experiences`).get();
782
+ const metaRow = db.prepare(`SELECT COUNT(*) as total, AVG(quality) as avg_reward FROM captured_experiences WHERE agent != 'cli-hook'`).get();
776
783
  exportData.metadata = { totalExperiences: metaRow.total, avgReward: metaRow.avg_reward };
777
784
  db.close();
778
785
  }
@@ -1136,6 +1143,256 @@ function registerDreamCommand(learning) {
1136
1143
  });
1137
1144
  }
1138
1145
  // ============================================================================
1146
+ // Subcommand: repair
1147
+ // ============================================================================
1148
+ function registerRepairCommand(learning) {
1149
+ learning
1150
+ .command('repair')
1151
+ .description('Repair a corrupted learning database (dump + reimport to rebuild indexes)')
1152
+ .option('-f, --file <path>', 'Database file to repair (defaults to current project)')
1153
+ .option('--dry-run', 'Show what would be done without modifying files')
1154
+ .option('--json', 'Output as JSON')
1155
+ .action(async (options) => {
1156
+ try {
1157
+ const dbPath = options.file ? path.resolve(options.file) : getDbPath();
1158
+ if (!existsSync(dbPath))
1159
+ throw new Error(`Database file not found: ${dbPath}`);
1160
+ // Step 1: Check integrity first
1161
+ const integrityResult = await verifyDatabaseIntegrity(dbPath);
1162
+ if (integrityResult.valid) {
1163
+ if (options.json) {
1164
+ printJson({ status: 'healthy', message: 'Database is already healthy, no repair needed', path: dbPath });
1165
+ }
1166
+ else {
1167
+ printSuccess('Database integrity check passed — no repair needed.');
1168
+ }
1169
+ process.exit(0);
1170
+ }
1171
+ printInfo(`Corruption detected: ${integrityResult.message}`);
1172
+ // Step 2: Count rows before repair
1173
+ let rowCountsBefore = {};
1174
+ try {
1175
+ const db = openDatabase(dbPath, { readonly: true });
1176
+ const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'").all();
1177
+ for (const t of tables) {
1178
+ try {
1179
+ const r = db.prepare(`SELECT COUNT(*) as count FROM "${t.name}"`).get();
1180
+ rowCountsBefore[t.name] = r.count;
1181
+ }
1182
+ catch { /* corrupted table, count what we can */ }
1183
+ }
1184
+ db.close();
1185
+ }
1186
+ catch { /* ignore count failures */ }
1187
+ const totalBefore = Object.values(rowCountsBefore).reduce((a, b) => a + b, 0);
1188
+ printInfo(`Found ${Object.keys(rowCountsBefore).length} tables, ~${totalBefore} total rows`);
1189
+ if (options.dryRun) {
1190
+ if (options.json) {
1191
+ printJson({ status: 'dry-run', corruptionDetected: true, message: integrityResult.message, tables: rowCountsBefore, totalRows: totalBefore });
1192
+ }
1193
+ else {
1194
+ console.log(chalk.bold('\nDry run — would perform these steps:'));
1195
+ console.log(' 1. Backup corrupted DB');
1196
+ console.log(' 2. Dump all data via .dump');
1197
+ console.log(' 3. Reimport into fresh DB (rebuilds all indexes)');
1198
+ console.log(' 4. Verify integrity of repaired DB');
1199
+ console.log(' 5. Verify row counts match');
1200
+ console.log(' 6. Swap repaired DB into place');
1201
+ console.log('');
1202
+ }
1203
+ process.exit(0);
1204
+ }
1205
+ // Step 3: Backup
1206
+ const backupPath = `${dbPath}.bak-${Date.now()}`;
1207
+ copyFileSync(dbPath, backupPath);
1208
+ printInfo(`Backup created: ${backupPath}`);
1209
+ // Step 4: Remove stale WAL/SHM
1210
+ for (const suffix of ['-wal', '-shm']) {
1211
+ const walFile = dbPath + suffix;
1212
+ if (existsSync(walFile)) {
1213
+ await unlink(walFile);
1214
+ }
1215
+ }
1216
+ // Step 5: Dump and reimport using sqlite3 CLI
1217
+ const { execSync } = await import('node:child_process');
1218
+ const repairedPath = `${dbPath}.repaired`;
1219
+ const dumpPath = `${dbPath}.dump.sql`;
1220
+ try {
1221
+ // Dump all data
1222
+ execSync(`sqlite3 "${dbPath}" ".dump" > "${dumpPath}"`, { stdio: 'pipe', timeout: 120000 });
1223
+ // Reimport into fresh DB
1224
+ execSync(`sqlite3 "${repairedPath}" < "${dumpPath}"`, { stdio: 'pipe', timeout: 120000 });
1225
+ // Enable WAL on repaired DB
1226
+ execSync(`sqlite3 "${repairedPath}" "PRAGMA journal_mode=WAL;"`, { stdio: 'pipe' });
1227
+ }
1228
+ catch (dumpError) {
1229
+ // Clean up partial files
1230
+ if (existsSync(repairedPath))
1231
+ await unlink(repairedPath);
1232
+ if (existsSync(dumpPath))
1233
+ await unlink(dumpPath);
1234
+ throw new Error(`sqlite3 dump/reimport failed: ${dumpError instanceof Error ? dumpError.message : 'unknown'}. Is sqlite3 installed?`);
1235
+ }
1236
+ // Step 6: Verify repaired DB
1237
+ const repairedIntegrity = await verifyDatabaseIntegrity(repairedPath);
1238
+ if (!repairedIntegrity.valid) {
1239
+ if (existsSync(dumpPath))
1240
+ await unlink(dumpPath);
1241
+ throw new Error(`Repaired DB still has integrity issues: ${repairedIntegrity.message}. Backup preserved at ${backupPath}`);
1242
+ }
1243
+ // Step 7: Verify row counts
1244
+ let rowCountsAfter = {};
1245
+ const repairedDb = openDatabase(repairedPath, { readonly: true });
1246
+ const repairedTables = repairedDb.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'").all();
1247
+ for (const t of repairedTables) {
1248
+ try {
1249
+ const r = repairedDb.prepare(`SELECT COUNT(*) as count FROM "${t.name}"`).get();
1250
+ rowCountsAfter[t.name] = r.count;
1251
+ }
1252
+ catch { /* skip */ }
1253
+ }
1254
+ repairedDb.close();
1255
+ const totalAfter = Object.values(rowCountsAfter).reduce((a, b) => a + b, 0);
1256
+ // Step 8: Swap
1257
+ renameSync(dbPath, `${dbPath}.pre-repair`);
1258
+ renameSync(repairedPath, dbPath);
1259
+ // Clean up dump file
1260
+ if (existsSync(dumpPath))
1261
+ await unlink(dumpPath);
1262
+ if (options.json) {
1263
+ printJson({
1264
+ status: 'repaired',
1265
+ backupPath,
1266
+ rowsBefore: totalBefore,
1267
+ rowsAfter: totalAfter,
1268
+ tablesRepaired: Object.keys(rowCountsAfter).length,
1269
+ rowCounts: rowCountsAfter,
1270
+ });
1271
+ }
1272
+ else {
1273
+ printSuccess('Database repaired successfully!');
1274
+ console.log(` Backup: ${backupPath}`);
1275
+ console.log(` Rows before: ${totalBefore}`);
1276
+ console.log(` Rows after: ${totalAfter}`);
1277
+ if (totalAfter < totalBefore) {
1278
+ console.log(chalk.yellow(` Warning: ${totalBefore - totalAfter} rows may have been lost due to data page corruption`));
1279
+ }
1280
+ console.log(` Tables: ${Object.keys(rowCountsAfter).length}`);
1281
+ console.log(` Integrity: ${chalk.green('OK')}`);
1282
+ console.log('');
1283
+ }
1284
+ process.exit(0);
1285
+ }
1286
+ catch (error) {
1287
+ printError(`repair failed: ${error instanceof Error ? error.message : 'unknown'}`);
1288
+ process.exit(1);
1289
+ }
1290
+ });
1291
+ }
1292
+ // ============================================================================
1293
+ // Subcommand: health (Task 2.4 - Regret Tracking & Learning Health)
1294
+ // ============================================================================
1295
+ /**
1296
+ * Get trend arrow and label for a growth rate classification
1297
+ */
1298
+ function growthRateDisplay(rate) {
1299
+ switch (rate) {
1300
+ case 'sublinear':
1301
+ return { arrow: '\u25B2', label: 'Sublinear (learning)', color: chalk.green };
1302
+ case 'linear':
1303
+ return { arrow: '\u2192', label: 'Linear (stagnating)', color: chalk.yellow };
1304
+ case 'superlinear':
1305
+ return { arrow: '\u25BC', label: 'Superlinear (degrading)', color: chalk.red };
1306
+ case 'insufficient_data':
1307
+ default:
1308
+ return { arrow: '?', label: 'Insufficient data', color: chalk.dim };
1309
+ }
1310
+ }
1311
+ function registerHealthCommand(learning) {
1312
+ learning
1313
+ .command('health')
1314
+ .description('Display per-domain learning health based on regret tracking')
1315
+ .option('--json', 'Output as JSON')
1316
+ .option('--domain <domain>', 'Filter to a specific domain')
1317
+ .action(async (options) => {
1318
+ try {
1319
+ const projectRoot = findProjectRoot();
1320
+ const dbPath = path.join(projectRoot, '.agentic-qe', 'memory.db');
1321
+ if (!existsSync(dbPath)) {
1322
+ printError('Database not found. Run "aqe init --auto" first.');
1323
+ process.exit(1);
1324
+ }
1325
+ // Build regret data from captured experiences per domain
1326
+ const tracker = createRegretTracker();
1327
+ const db = openDatabase(dbPath, { readonly: true });
1328
+ // Check for captured_experiences table
1329
+ const tableExists = db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='captured_experiences'`).get();
1330
+ if (tableExists) {
1331
+ // Query experiences grouped by domain, ordered by time
1332
+ const domainFilter = options.domain
1333
+ ? `AND domain = ?` : '';
1334
+ const params = [];
1335
+ if (options.domain)
1336
+ params.push(options.domain);
1337
+ const rows = db.prepare(`
1338
+ SELECT domain, quality, success, started_at
1339
+ FROM captured_experiences
1340
+ WHERE agent != 'cli-hook'
1341
+ AND domain IS NOT NULL
1342
+ AND domain != ''
1343
+ ${domainFilter}
1344
+ ORDER BY started_at ASC
1345
+ `).all(...params);
1346
+ for (const row of rows) {
1347
+ const reward = row.quality ?? (row.success ? 1.0 : 0.0);
1348
+ const optimalReward = 1.0;
1349
+ tracker.recordDecision(row.domain, reward, optimalReward);
1350
+ }
1351
+ }
1352
+ db.close();
1353
+ const healthSummary = tracker.getHealthSummary();
1354
+ if (options.json) {
1355
+ printJson(healthSummary);
1356
+ process.exit(0);
1357
+ }
1358
+ // Display health dashboard
1359
+ console.log('');
1360
+ console.log(chalk.bold('Learning Health Dashboard:'));
1361
+ if (healthSummary.length === 0) {
1362
+ console.log(chalk.dim(' No domain data available. Run some QE tasks to generate learning data.'));
1363
+ console.log('');
1364
+ process.exit(0);
1365
+ }
1366
+ // Find the longest domain name for alignment
1367
+ const maxDomainLen = Math.max(...healthSummary.map(s => s.domain.length), 20);
1368
+ for (const summary of healthSummary) {
1369
+ const { arrow, label, color } = growthRateDisplay(summary.growthRate);
1370
+ const domainName = padRight(summary.domain + ':', maxDomainLen + 1);
1371
+ const statusStr = color(`${arrow} ${padRight(label, 26)}`);
1372
+ const regretStr = `regret: ${summary.cumulativeRegret.toFixed(1)}`;
1373
+ const decisionsStr = `decisions: ${summary.totalDecisions}`;
1374
+ console.log(` ${domainName} ${statusStr} ${regretStr} ${decisionsStr}`);
1375
+ }
1376
+ // Show summary line
1377
+ const stagnating = healthSummary.filter(s => s.stagnating);
1378
+ if (stagnating.length > 0) {
1379
+ console.log('');
1380
+ console.log(chalk.yellow(` Warning: ${stagnating.length} domain(s) showing stagnation: ${stagnating.map(s => s.domain).join(', ')}`));
1381
+ }
1382
+ const learning = healthSummary.filter(s => s.growthRate === 'sublinear');
1383
+ if (learning.length > 0) {
1384
+ console.log(chalk.green(` ${learning.length} domain(s) actively learning`));
1385
+ }
1386
+ console.log('');
1387
+ process.exit(0);
1388
+ }
1389
+ catch (error) {
1390
+ printError(`health check failed: ${error instanceof Error ? error.message : 'unknown'}`);
1391
+ process.exit(1);
1392
+ }
1393
+ });
1394
+ }
1395
+ // ============================================================================
1139
1396
  // Exports
1140
1397
  // ============================================================================
1141
1398
  export { initializeLearningSystem } from './learning-helpers.js';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Agentic QE v3 - RuVector CLI Commands
3
+ * Manage RuVector feature flags and native package status.
4
+ *
5
+ * Subcommands:
6
+ * status - Show native package availability and flag status
7
+ * flags - List, set, or apply profiles to feature flags
8
+ */
9
+ import { Command } from 'commander';
10
+ /**
11
+ * Create the ruvector command group
12
+ */
13
+ export declare function createRuVectorCommand(): Command;
14
+ export default createRuVectorCommand;
15
+ //# sourceMappingURL=ruvector-commands.d.ts.map
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Agentic QE v3 - RuVector CLI Commands
3
+ * Manage RuVector feature flags and native package status.
4
+ *
5
+ * Subcommands:
6
+ * status - Show native package availability and flag status
7
+ * flags - List, set, or apply profiles to feature flags
8
+ */
9
+ import { Command } from 'commander';
10
+ import chalk from 'chalk';
11
+ import { getRuVectorFeatureFlags, setRuVectorFeatureFlags, DEFAULT_FEATURE_FLAGS, } from '../../integrations/ruvector/feature-flags.js';
12
+ // ============================================================================
13
+ // Constants
14
+ // ============================================================================
15
+ const NATIVE_PACKAGES = [
16
+ {
17
+ name: '@ruvector/router',
18
+ flag: 'useNativeHNSW',
19
+ fallback: 'ProgressiveHnswBackend',
20
+ },
21
+ {
22
+ name: 'prime-radiant-advanced-wasm',
23
+ flag: 'useCoherenceGate',
24
+ fallback: 'Word-frequency heuristics',
25
+ },
26
+ {
27
+ name: '@ruvector/sona',
28
+ flag: 'useSONAThreeLoop',
29
+ fallback: 'TypeScript MicroLoRA/EWC++',
30
+ },
31
+ ];
32
+ const FLAG_DESCRIPTIONS = {
33
+ useQESONA: 'Self-Optimizing Neural Architecture',
34
+ useQEFlashAttention: 'SIMD-accelerated attention computation',
35
+ useQEGNNIndex: 'Differentiable search and HNSW indexing',
36
+ logMigrationMetrics: 'Log migration metrics during rollout',
37
+ useNativeHNSW: 'Rust-based HNSW backend (@ruvector/router VectorDb)',
38
+ useTemporalCompression: 'Temporal tensor compression (ADR-085)',
39
+ useMetadataFiltering: 'SIMD-accelerated metadata filtering',
40
+ useDeterministicDither: 'Cross-platform deterministic dithering',
41
+ useNeuralRouting: 'Neural model routing via FastGRNN (ADR-082)',
42
+ useSONAThreeLoop: 'SONA Three-Loop Engine (Task 2.2)',
43
+ useCrossDomainTransfer: 'Cross-domain transfer learning (ADR-084)',
44
+ useHnswHealthMonitor: 'HNSW health monitor (Task 3.4)',
45
+ useRegretTracking: 'Regret tracking & learning health (Task 2.4)',
46
+ useCoherenceGate: 'Sheaf-gated coherence validation (ADR-083, Task 3.1)',
47
+ useWitnessChain: 'Blake3 hash-chained witness records (Task 3.1)',
48
+ useCNNVisualRegression: 'CNN visual regression testing (Task 4.3)',
49
+ useDAGAttention: 'DAG attention for test scheduling (Task 4.2)',
50
+ useCoherenceActionGate: 'Coherence-gated agent actions (ADR-083, Task 3.2)',
51
+ useReasoningQEC: 'Reasoning QEC error correction (Task 4.5)',
52
+ };
53
+ const PROFILES = {
54
+ performance: {
55
+ useNativeHNSW: true,
56
+ useTemporalCompression: true,
57
+ useDeterministicDither: true,
58
+ },
59
+ experimental: {
60
+ useQESONA: true,
61
+ useQEFlashAttention: true,
62
+ useQEGNNIndex: true,
63
+ logMigrationMetrics: true,
64
+ useNativeHNSW: true,
65
+ useTemporalCompression: true,
66
+ useMetadataFiltering: true,
67
+ useDeterministicDither: true,
68
+ useNeuralRouting: true,
69
+ },
70
+ safe: {
71
+ useQESONA: true,
72
+ useQEFlashAttention: true,
73
+ useQEGNNIndex: true,
74
+ logMigrationMetrics: true,
75
+ useNativeHNSW: false,
76
+ useTemporalCompression: false,
77
+ useMetadataFiltering: false,
78
+ useDeterministicDither: false,
79
+ useNeuralRouting: false,
80
+ },
81
+ };
82
+ const VALID_FLAG_NAMES = Object.keys(DEFAULT_FEATURE_FLAGS);
83
+ // ============================================================================
84
+ // Helpers
85
+ // ============================================================================
86
+ /**
87
+ * Check whether a native package is installed.
88
+ * Returns true if the package can be resolved, false otherwise.
89
+ */
90
+ function isNativePackageInstalled(packageName) {
91
+ try {
92
+ require.resolve(packageName);
93
+ return true;
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
99
+ function isDefaultValue(flag, value) {
100
+ return DEFAULT_FEATURE_FLAGS[flag] === value;
101
+ }
102
+ function padRight(str, length) {
103
+ return str.padEnd(length);
104
+ }
105
+ function isValidFlagName(name) {
106
+ return VALID_FLAG_NAMES.includes(name);
107
+ }
108
+ function isValidProfile(name) {
109
+ return name in PROFILES;
110
+ }
111
+ // ============================================================================
112
+ // Command: ruvector status
113
+ // ============================================================================
114
+ function executeStatus() {
115
+ const flags = getRuVectorFeatureFlags();
116
+ console.log('');
117
+ console.log(chalk.bold.blue('RuVector Integration Status:'));
118
+ // Native packages section
119
+ console.log(chalk.cyan(' Native Packages:'));
120
+ for (const pkg of NATIVE_PACKAGES) {
121
+ const installed = isNativePackageInstalled(pkg.name);
122
+ const statusText = installed
123
+ ? chalk.green('installed')
124
+ : chalk.gray(`not installed (fallback: ${pkg.fallback})`);
125
+ console.log(` ${padRight(pkg.name + ':', 30)} ${statusText}`);
126
+ }
127
+ // Feature flags section
128
+ console.log('');
129
+ console.log(chalk.cyan(' Feature Flags:'));
130
+ for (const flagName of VALID_FLAG_NAMES) {
131
+ const value = flags[flagName];
132
+ const isDefault = isDefaultValue(flagName, value);
133
+ const valueText = value ? chalk.green('true') : chalk.gray('false');
134
+ const suffix = isDefault ? chalk.gray(' (default)') : chalk.yellow(' (modified)');
135
+ console.log(` ${padRight(flagName + ':', 30)} ${valueText}${suffix}`);
136
+ }
137
+ // Memory info when compression is enabled
138
+ if (flags.useTemporalCompression) {
139
+ console.log('');
140
+ console.log(chalk.cyan(' Temporal Compression:'));
141
+ console.log(chalk.gray(' Hot tier: 8-bit quantization (frequently accessed patterns)'));
142
+ console.log(chalk.gray(' Warm tier: 5-bit quantization (moderately accessed patterns)'));
143
+ console.log(chalk.gray(' Cold tier: 3-bit quantization (rarely accessed patterns)'));
144
+ console.log(chalk.gray(' Estimated memory savings: 40-60% for cold patterns'));
145
+ }
146
+ console.log('');
147
+ }
148
+ // ============================================================================
149
+ // Command: ruvector flags
150
+ // ============================================================================
151
+ function executeFlags(options) {
152
+ // Handle --profile
153
+ if (options.profile) {
154
+ if (!isValidProfile(options.profile)) {
155
+ console.log('');
156
+ console.log(chalk.red(` Unknown profile: ${options.profile}`));
157
+ console.log(chalk.gray(` Valid profiles: ${Object.keys(PROFILES).join(', ')}`));
158
+ console.log('');
159
+ process.exit(1);
160
+ return;
161
+ }
162
+ const profileFlags = PROFILES[options.profile];
163
+ setRuVectorFeatureFlags(profileFlags);
164
+ console.log('');
165
+ console.log(chalk.bold.blue(`Setting ${options.profile} profile:`));
166
+ for (const [key, value] of Object.entries(profileFlags)) {
167
+ const valueText = value ? chalk.green('true') : chalk.gray('false');
168
+ console.log(` ${padRight(key + ':', 30)} ${valueText}`);
169
+ }
170
+ console.log('');
171
+ return;
172
+ }
173
+ // Handle --set
174
+ if (options.set) {
175
+ const eqIdx = options.set.indexOf('=');
176
+ if (eqIdx <= 0) {
177
+ console.log('');
178
+ console.log(chalk.red(' Invalid format. Use: --set flagName=true|false'));
179
+ console.log('');
180
+ process.exit(1);
181
+ return;
182
+ }
183
+ const flagName = options.set.substring(0, eqIdx);
184
+ const flagValue = options.set.substring(eqIdx + 1);
185
+ if (!isValidFlagName(flagName)) {
186
+ console.log('');
187
+ console.log(chalk.red(` Unknown flag: ${flagName}`));
188
+ console.log(chalk.gray(` Valid flags: ${VALID_FLAG_NAMES.join(', ')}`));
189
+ console.log('');
190
+ process.exit(1);
191
+ return;
192
+ }
193
+ if (flagValue !== 'true' && flagValue !== 'false') {
194
+ console.log('');
195
+ console.log(chalk.red(` Invalid value: ${flagValue}. Use true or false.`));
196
+ console.log('');
197
+ process.exit(1);
198
+ return;
199
+ }
200
+ const boolValue = flagValue === 'true';
201
+ setRuVectorFeatureFlags({ [flagName]: boolValue });
202
+ const valueText = boolValue ? chalk.green('true') : chalk.gray('false');
203
+ console.log('');
204
+ console.log(chalk.green(` Set ${flagName} = ${valueText}`));
205
+ console.log('');
206
+ return;
207
+ }
208
+ // Default: list all flags
209
+ const flags = getRuVectorFeatureFlags();
210
+ console.log('');
211
+ console.log(chalk.bold.blue('RuVector Feature Flags:'));
212
+ console.log('');
213
+ console.log(chalk.bold(' ' + padRight('Flag', 28) + padRight('Value', 10) + 'Description'));
214
+ console.log(chalk.gray(' ' + '-'.repeat(78)));
215
+ for (const flagName of VALID_FLAG_NAMES) {
216
+ const value = flags[flagName];
217
+ const isDefault = isDefaultValue(flagName, value);
218
+ const valueText = value ? chalk.green('true') : chalk.gray('false');
219
+ const suffix = isDefault ? '' : chalk.yellow(' *');
220
+ const description = FLAG_DESCRIPTIONS[flagName];
221
+ console.log(' ' +
222
+ padRight(flagName, 28) +
223
+ padRight(String(value), 10) +
224
+ chalk.gray(description) +
225
+ suffix);
226
+ }
227
+ console.log('');
228
+ console.log(chalk.gray(' * = modified from default'));
229
+ console.log('');
230
+ console.log(chalk.gray(' Profiles: performance, experimental, safe'));
231
+ console.log(chalk.gray(' Usage:'));
232
+ console.log(chalk.gray(' aqe ruvector flags --set useNativeHNSW=true'));
233
+ console.log(chalk.gray(' aqe ruvector flags --profile=performance'));
234
+ console.log('');
235
+ }
236
+ // ============================================================================
237
+ // Command Factory
238
+ // ============================================================================
239
+ /**
240
+ * Create the ruvector command group
241
+ */
242
+ export function createRuVectorCommand() {
243
+ const ruvectorCmd = new Command('ruvector')
244
+ .description('RuVector integration management')
245
+ .addHelpText('after', `
246
+ Examples:
247
+ $ aqe ruvector status Show native packages and flags
248
+ $ aqe ruvector flags List all feature flags
249
+ $ aqe ruvector flags --set useNativeHNSW=true Toggle a flag
250
+ $ aqe ruvector flags --profile=performance Apply a preset profile
251
+ `);
252
+ // ruvector status
253
+ ruvectorCmd
254
+ .command('status')
255
+ .description('Show native package availability and feature flag status')
256
+ .action(() => {
257
+ executeStatus();
258
+ });
259
+ // ruvector flags
260
+ ruvectorCmd
261
+ .command('flags')
262
+ .description('List, set, or apply profiles to feature flags')
263
+ .option('-s, --set <flag=value>', 'Set a feature flag (e.g., useNativeHNSW=true)')
264
+ .option('-p, --profile <name>', 'Apply a preset profile (performance|experimental|safe)')
265
+ .action((options) => {
266
+ executeFlags(options);
267
+ });
268
+ return ruvectorCmd;
269
+ }
270
+ export default createRuVectorCommand;
271
+ //# sourceMappingURL=ruvector-commands.js.map
@@ -40,7 +40,6 @@ interface InitOptions {
40
40
  withWindsurf?: boolean;
41
41
  withContinuedev?: boolean;
42
42
  withAllPlatforms?: boolean;
43
- autoMigrate?: boolean;
44
43
  withClaudeFlow?: boolean;
45
44
  skipClaudeFlow?: boolean;
46
45
  noGovernance?: boolean;
@@ -72,10 +72,6 @@ export class InitHandler {
72
72
  options.withWindsurf = true;
73
73
  options.withContinuedev = true;
74
74
  }
75
- // --auto-migrate implies --auto (must use orchestrator for migration)
76
- if (options.autoMigrate && !options.auto && !options.wizard) {
77
- options.auto = true;
78
- }
79
75
  // --upgrade implies --auto (must use modular orchestrator to overwrite files)
80
76
  if (options.upgrade && !options.auto && !options.wizard) {
81
77
  options.auto = true;
@@ -118,7 +114,6 @@ export class InitHandler {
118
114
  withCodex: options.withCodex,
119
115
  withWindsurf: options.withWindsurf,
120
116
  withContinueDev: options.withContinuedev,
121
- autoMigrate: options.autoMigrate,
122
117
  noGovernance: options.noGovernance,
123
118
  });
124
119
  console.log(chalk.white(' Analyzing project...\n'));
@@ -192,7 +187,6 @@ export class InitHandler {
192
187
  minimal: options.minimal,
193
188
  skipPatterns: options.skipPatterns,
194
189
  withN8n: options.withN8n,
195
- autoMigrate: options.autoMigrate,
196
190
  };
197
191
  const orchestrator = new InitOrchestrator(orchestratorOptions);
198
192
  if (options.wizard) {