@triedotdev/mcp 1.0.136 → 1.0.138

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 (105) hide show
  1. package/README.md +6 -6
  2. package/dist/{autonomy-config-QA6ATWLJ.js → autonomy-config-TZ6HF4FA.js} +3 -3
  3. package/dist/{chat-store-HFOOWZYN.js → chat-store-OJLJCJFI.js} +3 -3
  4. package/dist/{chunk-DFPVUMVE.js → chunk-23RJT5WT.js} +5 -4
  5. package/dist/chunk-23RJT5WT.js.map +1 -0
  6. package/dist/{chunk-4YJ6KLGI.js → chunk-3MUCUZ46.js} +8 -8
  7. package/dist/chunk-3MUCUZ46.js.map +1 -0
  8. package/dist/{chunk-6VIMBFUZ.js → chunk-3RRXWX3V.js} +21 -17
  9. package/dist/chunk-3RRXWX3V.js.map +1 -0
  10. package/dist/{chunk-WHIQAGB7.js → chunk-4C67GV3O.js} +2 -2
  11. package/dist/{chunk-WS6OA7H6.js → chunk-4MJ52WBH.js} +2 -3
  12. package/dist/chunk-4MJ52WBH.js.map +1 -0
  13. package/dist/{chunk-AJ34GCMD.js → chunk-67GSG2ST.js} +41 -38
  14. package/dist/chunk-67GSG2ST.js.map +1 -0
  15. package/dist/{chunk-UHX4462X.js → chunk-6LLH3TBZ.js} +24 -25
  16. package/dist/chunk-6LLH3TBZ.js.map +1 -0
  17. package/dist/{chunk-DFHMB44X.js → chunk-D3AS5LY7.js} +6 -10
  18. package/dist/chunk-D3AS5LY7.js.map +1 -0
  19. package/dist/{chunk-6OUWNVLX.js → chunk-EDDT4ZIH.js} +8 -8
  20. package/dist/chunk-EDDT4ZIH.js.map +1 -0
  21. package/dist/{chunk-Z4DN527J.js → chunk-FG467PDD.js} +156 -39
  22. package/dist/chunk-FG467PDD.js.map +1 -0
  23. package/dist/{chunk-T4THB2OR.js → chunk-FOCXXIXY.js} +49 -28
  24. package/dist/chunk-FOCXXIXY.js.map +1 -0
  25. package/dist/{goal-validator-PDKYZSNP.js → chunk-GFFUDJMK.js} +97 -40
  26. package/dist/chunk-GFFUDJMK.js.map +1 -0
  27. package/dist/{chunk-ZEXMMTIQ.js → chunk-J5EMP4XW.js} +2 -2
  28. package/dist/{chunk-UHMMANC2.js → chunk-LT6VUZG2.js} +21 -18
  29. package/dist/chunk-LT6VUZG2.js.map +1 -0
  30. package/dist/{chunk-55CBWOEZ.js → chunk-QSWUPSLK.js} +2 -2
  31. package/dist/{chunk-45Y5TLQZ.js → chunk-SH7H3WRU.js} +3 -6
  32. package/dist/chunk-SH7H3WRU.js.map +1 -0
  33. package/dist/{chunk-VRLMTOB6.js → chunk-TIMIKBY2.js} +1 -1
  34. package/dist/chunk-TIMIKBY2.js.map +1 -0
  35. package/dist/{chunk-POHBQUG7.js → chunk-X3F5QDER.js} +1224 -448
  36. package/dist/chunk-X3F5QDER.js.map +1 -0
  37. package/dist/{chunk-O6OTJI3W.js → chunk-Y32FM3MR.js} +2 -2
  38. package/dist/{chunk-G5PRBQIQ.js → chunk-YOKQ25IW.js} +102 -82
  39. package/dist/chunk-YOKQ25IW.js.map +1 -0
  40. package/dist/{chunk-JAKMZI5S.js → chunk-Z2P4WST6.js} +291 -180
  41. package/dist/chunk-Z2P4WST6.js.map +1 -0
  42. package/dist/cli/create-agent.js +1 -1
  43. package/dist/cli/main.js +113 -86
  44. package/dist/cli/main.js.map +1 -1
  45. package/dist/cli/yolo-daemon.js +19 -19
  46. package/dist/cli/yolo-daemon.js.map +1 -1
  47. package/dist/{client-BZHI675W.js → client-JTU5TRLB.js} +3 -3
  48. package/dist/{codebase-index-CR6Q2HEI.js → codebase-index-FNJ4GCBE.js} +3 -3
  49. package/dist/{goal-manager-FAK7H4RR.js → goal-manager-6BJQ36AH.js} +7 -8
  50. package/dist/goal-validator-GISXYANK.js +22 -0
  51. package/dist/{graph-PAUZ5EMP.js → graph-X2FMRQLG.js} +3 -3
  52. package/dist/{hypothesis-L5446W36.js → hypothesis-K3KQJOXJ.js} +7 -8
  53. package/dist/{incident-index-ZCDSJ42L.js → incident-index-BWW2UEY7.js} +3 -3
  54. package/dist/index.js +343 -288
  55. package/dist/index.js.map +1 -1
  56. package/dist/{insight-store-F5KDBY5Y.js → insight-store-A5XXMFD6.js} +6 -6
  57. package/dist/issue-store-BO5OWLJW.js +32 -0
  58. package/dist/{output-manager-BOTMXSND.js → output-manager-DZO5LGSG.js} +2 -2
  59. package/dist/{tiered-storage-QW2G7GSG.js → tiered-storage-VZL7KK64.js} +3 -3
  60. package/dist/trie-agent-XMSGMD7E.js +26 -0
  61. package/dist/trie-agent-XMSGMD7E.js.map +1 -0
  62. package/dist/ui/chat.html +260 -67
  63. package/dist/ui/goals.html +246 -3
  64. package/dist/ui/hypotheses.html +248 -5
  65. package/dist/ui/ledger.html +252 -9
  66. package/dist/ui/nudges.html +244 -1
  67. package/package.json +1 -1
  68. package/dist/chunk-45Y5TLQZ.js.map +0 -1
  69. package/dist/chunk-4YJ6KLGI.js.map +0 -1
  70. package/dist/chunk-6OUWNVLX.js.map +0 -1
  71. package/dist/chunk-6VIMBFUZ.js.map +0 -1
  72. package/dist/chunk-AJ34GCMD.js.map +0 -1
  73. package/dist/chunk-DFHMB44X.js.map +0 -1
  74. package/dist/chunk-DFPVUMVE.js.map +0 -1
  75. package/dist/chunk-G5PRBQIQ.js.map +0 -1
  76. package/dist/chunk-JAKMZI5S.js.map +0 -1
  77. package/dist/chunk-PEJEYWVR.js +0 -135
  78. package/dist/chunk-PEJEYWVR.js.map +0 -1
  79. package/dist/chunk-POHBQUG7.js.map +0 -1
  80. package/dist/chunk-T4THB2OR.js.map +0 -1
  81. package/dist/chunk-UHMMANC2.js.map +0 -1
  82. package/dist/chunk-UHX4462X.js.map +0 -1
  83. package/dist/chunk-VRLMTOB6.js.map +0 -1
  84. package/dist/chunk-WS6OA7H6.js.map +0 -1
  85. package/dist/chunk-Z4DN527J.js.map +0 -1
  86. package/dist/goal-validator-PDKYZSNP.js.map +0 -1
  87. package/dist/guardian-agent-4RHGIXUD.js +0 -27
  88. package/dist/ledger-WKVJWHBX.js +0 -17
  89. /package/dist/{autonomy-config-QA6ATWLJ.js.map → autonomy-config-TZ6HF4FA.js.map} +0 -0
  90. /package/dist/{chat-store-HFOOWZYN.js.map → chat-store-OJLJCJFI.js.map} +0 -0
  91. /package/dist/{chunk-WHIQAGB7.js.map → chunk-4C67GV3O.js.map} +0 -0
  92. /package/dist/{chunk-ZEXMMTIQ.js.map → chunk-J5EMP4XW.js.map} +0 -0
  93. /package/dist/{chunk-55CBWOEZ.js.map → chunk-QSWUPSLK.js.map} +0 -0
  94. /package/dist/{chunk-O6OTJI3W.js.map → chunk-Y32FM3MR.js.map} +0 -0
  95. /package/dist/{client-BZHI675W.js.map → client-JTU5TRLB.js.map} +0 -0
  96. /package/dist/{codebase-index-CR6Q2HEI.js.map → codebase-index-FNJ4GCBE.js.map} +0 -0
  97. /package/dist/{goal-manager-FAK7H4RR.js.map → goal-manager-6BJQ36AH.js.map} +0 -0
  98. /package/dist/{graph-PAUZ5EMP.js.map → goal-validator-GISXYANK.js.map} +0 -0
  99. /package/dist/{guardian-agent-4RHGIXUD.js.map → graph-X2FMRQLG.js.map} +0 -0
  100. /package/dist/{hypothesis-L5446W36.js.map → hypothesis-K3KQJOXJ.js.map} +0 -0
  101. /package/dist/{incident-index-ZCDSJ42L.js.map → incident-index-BWW2UEY7.js.map} +0 -0
  102. /package/dist/{insight-store-F5KDBY5Y.js.map → insight-store-A5XXMFD6.js.map} +0 -0
  103. /package/dist/{ledger-WKVJWHBX.js.map → issue-store-BO5OWLJW.js.map} +0 -0
  104. /package/dist/{output-manager-BOTMXSND.js.map → output-manager-DZO5LGSG.js.map} +0 -0
  105. /package/dist/{tiered-storage-QW2G7GSG.js.map → tiered-storage-VZL7KK64.js.map} +0 -0
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CodebaseIndex
4
- } from "./chunk-6VIMBFUZ.js";
4
+ } from "./chunk-3RRXWX3V.js";
5
5
  import {
6
6
  LinearIngester,
7
7
  appendToSection,
@@ -21,10 +21,10 @@ import {
21
21
  needsBootstrap,
22
22
  projectInfoExists,
23
23
  updateProjectSection
24
- } from "./chunk-DFHMB44X.js";
24
+ } from "./chunk-D3AS5LY7.js";
25
25
  import {
26
26
  getAutonomyConfig
27
- } from "./chunk-ZEXMMTIQ.js";
27
+ } from "./chunk-J5EMP4XW.js";
28
28
  import {
29
29
  ExtractionPipeline,
30
30
  InteractiveDashboard,
@@ -34,19 +34,21 @@ import {
34
34
  TrieFeedbackTool,
35
35
  TrieGetBlockersTool,
36
36
  TrieGetDecisionsTool,
37
+ TrieGetGovernanceTool,
37
38
  TrieGetRelatedDecisionsTool,
39
+ TrieGetRelatedGovernanceTool,
38
40
  TrieQueryContextTool,
39
41
  TrieScanTool,
40
42
  TrieTellTool,
41
43
  getPrompt,
42
44
  getSystemPrompt,
43
45
  handleCheckpointTool
44
- } from "./chunk-POHBQUG7.js";
45
- import "./chunk-G5PRBQIQ.js";
46
- import "./chunk-DFPVUMVE.js";
47
- import "./chunk-T4THB2OR.js";
48
- import "./chunk-AJ34GCMD.js";
49
- import "./chunk-4YJ6KLGI.js";
46
+ } from "./chunk-X3F5QDER.js";
47
+ import "./chunk-YOKQ25IW.js";
48
+ import "./chunk-23RJT5WT.js";
49
+ import "./chunk-FOCXXIXY.js";
50
+ import "./chunk-67GSG2ST.js";
51
+ import "./chunk-3MUCUZ46.js";
50
52
  import {
51
53
  exportToJson,
52
54
  formatFriendlyError,
@@ -55,50 +57,51 @@ import {
55
57
  importFromJson,
56
58
  isTrieInitialized,
57
59
  runShellCommandSync
58
- } from "./chunk-6OUWNVLX.js";
59
- import "./chunk-WHIQAGB7.js";
60
+ } from "./chunk-EDDT4ZIH.js";
61
+ import "./chunk-4C67GV3O.js";
60
62
  import "./chunk-ZV2K6M7T.js";
61
63
  import {
62
64
  findCrossProjectPatterns,
63
65
  getGlobalMemoryStats,
64
66
  listTrackedProjects,
65
67
  searchGlobalPatterns
66
- } from "./chunk-UHX4462X.js";
68
+ } from "./chunk-6LLH3TBZ.js";
69
+ import "./chunk-GFFUDJMK.js";
67
70
  import {
68
71
  isAIAvailable,
69
72
  runAIAnalysis
70
- } from "./chunk-O6OTJI3W.js";
71
- import {
72
- findSimilarIssues,
73
- getMemoryStats,
74
- getRecentIssues,
75
- markIssueResolved,
76
- purgeIssues,
77
- searchIssues
78
- } from "./chunk-JAKMZI5S.js";
79
- import "./chunk-UHMMANC2.js";
80
- import "./chunk-WS6OA7H6.js";
73
+ } from "./chunk-Y32FM3MR.js";
74
+ import "./chunk-LT6VUZG2.js";
81
75
  import "./chunk-F4NJ4CBP.js";
82
76
  import "./chunk-IXO4G4D3.js";
83
77
  import "./chunk-6NLHFIYA.js";
84
78
  import {
85
79
  getStorage
86
- } from "./chunk-Z4DN527J.js";
80
+ } from "./chunk-FG467PDD.js";
87
81
  import {
88
82
  ContextGraph
89
- } from "./chunk-55CBWOEZ.js";
83
+ } from "./chunk-QSWUPSLK.js";
90
84
  import {
91
85
  getSkillRegistry
92
86
  } from "./chunk-G76DYVGX.js";
93
87
  import {
94
88
  getOutputManager
95
- } from "./chunk-VRLMTOB6.js";
96
- import "./chunk-PEJEYWVR.js";
89
+ } from "./chunk-TIMIKBY2.js";
90
+ import {
91
+ findSimilarIssues,
92
+ getMemoryStats,
93
+ getRecentIssues,
94
+ markIssueResolved,
95
+ purgeIssues,
96
+ searchIssues,
97
+ storeIssues
98
+ } from "./chunk-Z2P4WST6.js";
99
+ import "./chunk-4MJ52WBH.js";
97
100
  import "./chunk-43X6JBEM.js";
98
101
  import {
99
102
  getTrieDirectory,
100
103
  getWorkingDirectory
101
- } from "./chunk-45Y5TLQZ.js";
104
+ } from "./chunk-SH7H3WRU.js";
102
105
  import {
103
106
  isInteractiveMode
104
107
  } from "./chunk-APMV77PU.js";
@@ -1253,7 +1256,7 @@ var TrieWatchTool = class _TrieWatchTool {
1253
1256
  console.error("TRIE AGENT - NOW WATCHING");
1254
1257
  console.error("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n");
1255
1258
  console.error("Your Trie agent is now watching over your codebase.");
1256
- console.error("Signal extraction: ENABLED (building decision ledger)");
1259
+ console.error("Signal extraction: ENABLED (building governance ledger)");
1257
1260
  console.error(`Watching: ${directory}`);
1258
1261
  console.error(`Debounce: ${debounceMs}ms`);
1259
1262
  console.error("");
@@ -1298,12 +1301,12 @@ Your Trie agent is now autonomously watching and learning from your codebase.
1298
1301
  ### How the agent works:
1299
1302
  1. You write/edit code
1300
1303
  2. Agent detects the change
1301
- 3. Extracts decisions, facts, blockers -> stores in ledger
1304
+ 3. Extracts governance, facts, blockers -> stores in ledger
1302
1305
  4. Predicts risks based on historical patterns
1303
1306
  5. Nudges you if something looks risky
1304
1307
 
1305
1308
  ### The agent learns:
1306
- - Every commit builds the decision ledger
1309
+ - Every commit builds the governance ledger
1307
1310
  - \`trie gotcha\` queries the ledger for predictions
1308
1311
  - \`trie ok\` / \`trie bad\` teach the agent what matters
1309
1312
 
@@ -1342,6 +1345,8 @@ Your Trie agent is now autonomously watching and learning from your codebase.
1342
1345
  if (!isInteractiveMode()) {
1343
1346
  console.error(`[!] Watcher error: ${err.message}`);
1344
1347
  }
1348
+ watcher.close();
1349
+ this.watchers.delete(dir);
1345
1350
  });
1346
1351
  this.watchers.set(dir, watcher);
1347
1352
  if (this.streamingManager) {
@@ -1394,13 +1399,14 @@ ${f.content.slice(0, 1e3)}`
1394
1399
  sourceType: "file",
1395
1400
  sourceId: `watch-${Date.now()}`
1396
1401
  });
1397
- if (signal.decisions.length > 0 || signal.facts.length > 0 || signal.blockers.length > 0) {
1402
+ if (signal.governance.length > 0 || signal.facts.length > 0 || signal.blockers.length > 0) {
1403
+ const govCount = signal.governance.length;
1398
1404
  if (!isInteractiveMode()) {
1399
- console.error(` [+] Extracted: ${signal.decisions.length} decisions, ${signal.facts.length} facts, ${signal.blockers.length} blockers`);
1405
+ console.error(` [+] Extracted: ${govCount} governance, ${signal.facts.length} facts, ${signal.blockers.length} blockers`);
1400
1406
  }
1401
1407
  if (this.streamingManager) {
1402
1408
  this.streamingManager.reportSignalExtraction({
1403
- decisions: signal.decisions.length,
1409
+ governance: govCount,
1404
1410
  facts: signal.facts.length,
1405
1411
  blockers: signal.blockers.length,
1406
1412
  questions: signal.questions.length
@@ -1414,7 +1420,9 @@ ${f.content.slice(0, 1e3)}`
1414
1420
  }
1415
1421
  }
1416
1422
  }
1417
- this.autoScanFiles(files);
1423
+ void this.autoScanFiles(files).catch((err) => {
1424
+ getOutputManager().log("warn", `Auto scan failed: ${err}`);
1425
+ });
1418
1426
  await this.discoverPatternsFromIssues(projectPath);
1419
1427
  const now = Date.now();
1420
1428
  if (now - this.lastHypothesisCheck > _TrieWatchTool.HYPOTHESIS_CHECK_INTERVAL_MS) {
@@ -1465,8 +1473,8 @@ ${f.content.slice(0, 1e3)}`
1465
1473
  async checkAndGenerateHypotheses(projectPath) {
1466
1474
  if (!isAIAvailable()) return;
1467
1475
  try {
1468
- const { getHypothesisEngine } = await import("./hypothesis-L5446W36.js");
1469
- const { getOutputManager: getOutputManager2 } = await import("./output-manager-BOTMXSND.js");
1476
+ const { getHypothesisEngine } = await import("./hypothesis-K3KQJOXJ.js");
1477
+ const { getOutputManager: getOutputManager2 } = await import("./output-manager-DZO5LGSG.js");
1470
1478
  const hypothesisEngine = getHypothesisEngine(projectPath);
1471
1479
  const recentIssues = Array.from(this.state.issueCache.values()).flat();
1472
1480
  const patterns = [];
@@ -1507,7 +1515,7 @@ ${f.content.slice(0, 1e3)}`
1507
1515
  }
1508
1516
  if (this.streamingManager) {
1509
1517
  this.streamingManager.reportSignalExtraction({
1510
- decisions: 0,
1518
+ governance: 0,
1511
1519
  facts: 0,
1512
1520
  blockers: 0,
1513
1521
  questions: 1
@@ -1532,8 +1540,8 @@ ${f.content.slice(0, 1e3)}`
1532
1540
  const totalIssues = Array.from(this.state.issueCache.values()).flat().length;
1533
1541
  if (totalIssues < 5) return;
1534
1542
  try {
1535
- const { ContextGraph: ContextGraph2 } = await import("./graph-PAUZ5EMP.js");
1536
- const { IncidentIndex } = await import("./incident-index-ZCDSJ42L.js");
1543
+ const { ContextGraph: ContextGraph2 } = await import("./graph-X2FMRQLG.js");
1544
+ const { IncidentIndex } = await import("./incident-index-BWW2UEY7.js");
1537
1545
  const { TriePatternDiscovery } = await import("./pattern-discovery-F7LU5K6E.js");
1538
1546
  const graph = new ContextGraph2(projectPath);
1539
1547
  const incidentIndex = await IncidentIndex.build(graph, projectPath);
@@ -1561,7 +1569,7 @@ ${f.content.slice(0, 1e3)}`
1561
1569
  }
1562
1570
  if (this.streamingManager) {
1563
1571
  this.streamingManager.reportSignalExtraction({
1564
- decisions: 0,
1572
+ governance: 0,
1565
1573
  facts: 1,
1566
1574
  // Patterns are facts about the codebase
1567
1575
  blockers: 0,
@@ -1656,87 +1664,87 @@ ${f.content.slice(0, 1e3)}`
1656
1664
  if (this.state.autoScanInProgress) return;
1657
1665
  const now = Date.now();
1658
1666
  if (now - this.state.lastAutoScan < this.aiWatcherCooldownMs) return;
1659
- const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
1660
- try {
1661
- const config = await getAutonomyConfig(projectPath);
1662
- const wc = config.aiWatcher;
1663
- if (!wc.enabled) return;
1664
- this.state.tokenBudget.hourlyLimit = wc.hourlyTokenLimit;
1665
- this.aiWatcherCooldownMs = wc.scanCooldownSec * 1e3;
1666
- this.cleanFileCooldownMs = wc.cleanFileCooldownSec * 1e3;
1667
- this.maxFilesPerScan = wc.maxFilesPerScan;
1668
- this.maxCharsPerFile = wc.maxCharsPerFile;
1669
- } catch {
1670
- }
1671
- const remaining = this.getRemainingBudget();
1672
- if (remaining < 500) return;
1673
1667
  this.state.autoScanInProgress = true;
1674
1668
  this.state.lastAutoScan = now;
1669
+ const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
1675
1670
  try {
1676
- const graph = new ContextGraph(projectPath);
1677
- const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-PDKYZSNP.js");
1678
- const { appendIssuesToLedger } = await import("./ledger-WKVJWHBX.js");
1679
- console.debug("[AI Watcher] Loading active goals...");
1680
- const activeGoals = await getActiveGoals(projectPath);
1681
- const hasGoals = activeGoals.length > 0;
1682
- console.debug("[AI Watcher] Goals loaded:", {
1683
- totalGoals: activeGoals.length,
1684
- hasGoals,
1685
- goals: activeGoals.map((g) => ({ id: g.id, description: g.description, status: g.status }))
1686
- });
1687
- if (this.isQuiet() && !hasGoals) return;
1688
- const scored = [];
1689
- for (const file of files) {
1690
- const relativePath = file.replace(projectPath + "/", "");
1691
- const score = await this.scoreScanPriority(relativePath, graph, projectPath);
1692
- if (hasGoals || score > 0) {
1693
- scored.push({ file, relativePath, score: Math.max(score, hasGoals ? 1 : 0) });
1694
- } else {
1695
- this.state.tokenBudget.scansSaved++;
1696
- }
1671
+ try {
1672
+ const config = await getAutonomyConfig(projectPath);
1673
+ const wc = config.aiWatcher;
1674
+ if (!wc.enabled) return;
1675
+ this.state.tokenBudget.hourlyLimit = wc.hourlyTokenLimit;
1676
+ this.aiWatcherCooldownMs = wc.scanCooldownSec * 1e3;
1677
+ this.cleanFileCooldownMs = wc.cleanFileCooldownSec * 1e3;
1678
+ this.maxFilesPerScan = wc.maxFilesPerScan;
1679
+ this.maxCharsPerFile = wc.maxCharsPerFile;
1680
+ } catch {
1697
1681
  }
1698
- if (scored.length === 0) return;
1699
- scored.sort((a, b) => b.score - a.score);
1700
- const budgetScale = remaining > 2e4 ? 1 : remaining > 1e4 ? 0.6 : 0.4;
1701
- const maxFiles = Math.max(1, Math.round(this.maxFilesPerScan * budgetScale));
1702
- const filesToScan = scored.slice(0, maxFiles);
1703
- const charLimit = Math.round(this.maxCharsPerFile * (remaining > 15e3 ? 1 : 0.5));
1704
- const fileContents = await Promise.all(
1705
- filesToScan.map(async ({ file, relativePath }) => {
1706
- try {
1707
- const content = await readFile3(file, "utf-8");
1708
- return { path: relativePath, content: content.slice(0, charLimit) };
1709
- } catch {
1710
- return null;
1682
+ const remaining = this.getRemainingBudget();
1683
+ if (remaining < 500) return;
1684
+ try {
1685
+ const graph = new ContextGraph(projectPath);
1686
+ const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-GISXYANK.js");
1687
+ console.debug("[AI Watcher] Loading active goals...");
1688
+ const activeGoals = await getActiveGoals(projectPath);
1689
+ const hasGoals = activeGoals.length > 0;
1690
+ console.debug("[AI Watcher] Goals loaded:", {
1691
+ totalGoals: activeGoals.length,
1692
+ hasGoals,
1693
+ goals: activeGoals.map((g) => ({ id: g.id, description: g.description, status: g.status }))
1694
+ });
1695
+ if (this.isQuiet() && !hasGoals) return;
1696
+ const scored = [];
1697
+ for (const file of files) {
1698
+ const relativePath = file.replace(projectPath + "/", "");
1699
+ const score = await this.scoreScanPriority(relativePath, graph, projectPath);
1700
+ if (hasGoals || score > 0) {
1701
+ scored.push({ file, relativePath, score: Math.max(score, hasGoals ? 1 : 0) });
1702
+ } else {
1703
+ this.state.tokenBudget.scansSaved++;
1711
1704
  }
1712
- })
1713
- );
1714
- const valid = fileContents.filter(Boolean);
1715
- if (valid.length === 0) return;
1716
- const filesBlock = valid.map(
1717
- (f) => `### ${f.path}
1705
+ }
1706
+ if (scored.length === 0) return;
1707
+ scored.sort((a, b) => b.score - a.score);
1708
+ const budgetScale = remaining > 2e4 ? 1 : remaining > 1e4 ? 0.6 : 0.4;
1709
+ const maxFiles = Math.max(1, Math.round(this.maxFilesPerScan * budgetScale));
1710
+ const filesToScan = scored.slice(0, maxFiles);
1711
+ const charLimit = Math.round(this.maxCharsPerFile * (remaining > 15e3 ? 1 : 0.5));
1712
+ const fileContents = await Promise.all(
1713
+ filesToScan.map(async ({ file, relativePath }) => {
1714
+ try {
1715
+ const content = await readFile3(file, "utf-8");
1716
+ return { path: relativePath, content: content.slice(0, charLimit) };
1717
+ } catch {
1718
+ return null;
1719
+ }
1720
+ })
1721
+ );
1722
+ const valid = fileContents.filter(Boolean);
1723
+ if (valid.length === 0) return;
1724
+ const filesBlock = valid.map(
1725
+ (f) => `### ${f.path}
1718
1726
  \`\`\`
1719
1727
  ${f.content}
1720
1728
  \`\`\``
1721
- ).join("\n\n");
1722
- let goalsSection = "";
1723
- if (hasGoals) {
1724
- goalsSection = `
1729
+ ).join("\n\n");
1730
+ let goalsSection = "";
1731
+ if (hasGoals) {
1732
+ goalsSection = `
1725
1733
  USER-DEFINED GOALS (IMPORTANT - check EVERY file against ALL goals):
1726
1734
  ${activeGoals.map((g, i) => ` ${i + 1}. "${g.description}"`).join("\n")}
1727
1735
 
1728
1736
  Goal violations are HIGH PRIORITY. If a file violates any goal, you MUST report it.
1729
1737
  `;
1730
- }
1731
- console.debug("[AI Watcher] Sending files to AI analysis:", {
1732
- fileCount: valid.length,
1733
- hasGoals,
1734
- goalsIncluded: hasGoals,
1735
- filePaths: valid.map((f) => f.path),
1736
- goalsSection: goalsSection.slice(0, 200) + (goalsSection.length > 200 ? "..." : "")
1737
- });
1738
- const result = await runAIAnalysis({
1739
- systemPrompt: `You are a code quality watcher. You review code for two things:
1738
+ }
1739
+ console.debug("[AI Watcher] Sending files to AI analysis:", {
1740
+ fileCount: valid.length,
1741
+ hasGoals,
1742
+ goalsIncluded: hasGoals,
1743
+ filePaths: valid.map((f) => f.path),
1744
+ goalsSection: goalsSection.slice(0, 200) + (goalsSection.length > 200 ? "..." : "")
1745
+ });
1746
+ const result = await runAIAnalysis({
1747
+ systemPrompt: `You are a code quality watcher. You review code for two things:
1740
1748
 
1741
1749
  1. CODE ISSUES: bugs, security vulnerabilities, logic errors, risky patterns
1742
1750
  2. GOAL VIOLATIONS: check every file against the user's quality goals
@@ -1754,163 +1762,161 @@ Be thorough with goal checking. If a goal says "no emojis" and you see an emoji
1754
1762
 
1755
1763
  If no issues or violations found, reply with: []
1756
1764
  Output ONLY the JSON array, no markdown fences, no commentary.`,
1757
- userPrompt: `Review these changed files:
1765
+ userPrompt: `Review these changed files:
1758
1766
 
1759
1767
  ${filesBlock}`,
1760
- maxTokens: 2048,
1761
- temperature: 0.1
1762
- });
1763
- if (result.tokensUsed) {
1764
- this.recordTokenUsage(result.tokensUsed.input + result.tokensUsed.output);
1765
- }
1766
- console.debug("[AI Watcher] AI analysis result:", {
1767
- success: result.success,
1768
- contentLength: result.content ? result.content.length : 0,
1769
- tokensUsed: result.tokensUsed,
1770
- contentPreview: result.content ? result.content.slice(0, 500) : "null"
1771
- });
1772
- if (!result.success || !result.content.trim()) {
1773
- console.debug("[AI Watcher] AI analysis failed or returned empty content");
1774
- return;
1775
- }
1776
- let issues = [];
1777
- try {
1778
- const cleaned = result.content.replace(/```json?\n?|\n?```/g, "").trim();
1779
- console.debug("[AI Watcher] Parsing AI response:", { cleanedContent: cleaned.slice(0, 300) });
1780
- issues = JSON.parse(cleaned);
1781
- if (!Array.isArray(issues)) issues = [];
1782
- console.debug("[AI Watcher] Parsed issues:", {
1783
- totalIssues: issues.length,
1784
- goalViolations: issues.filter((i) => i.isGoalViolation).length,
1785
- issueTypes: issues.map((i) => ({ file: i.file, isGoalViolation: i.isGoalViolation, goalIndex: i.goalIndex }))
1768
+ maxTokens: 2048,
1769
+ temperature: 0.1
1786
1770
  });
1787
- } catch (error) {
1788
- console.debug("[AI Watcher] Failed to parse AI response:", error);
1789
- return;
1790
- }
1791
- const issuedFiles = new Set(issues.map((i) => i.file));
1792
- for (const { relativePath } of filesToScan) {
1793
- if (!issuedFiles.has(relativePath)) {
1794
- this.state.cleanFiles.set(relativePath, Date.now());
1771
+ if (result.tokensUsed) {
1772
+ this.recordTokenUsage(result.tokensUsed.input + result.tokensUsed.output);
1795
1773
  }
1796
- }
1797
- if (issues.length === 0) return;
1798
- for (const issue of issues.slice(0, 10)) {
1799
- const severity = issue.severity === "critical" ? "critical" : issue.severity === "major" ? "major" : "minor";
1800
- if (issue.isGoalViolation && issue.goalIndex != null && issue.goalIndex >= 0 && issue.goalIndex < activeGoals.length) {
1801
- const goal = activeGoals[issue.goalIndex];
1802
- const confidence = Math.min(100, Math.max(0, issue.confidence ?? 80));
1803
- const fixId = `fix-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
1804
- console.debug("[AI Watcher] Goal violation detected:", {
1805
- goalDescription: goal.description,
1806
- file: issue.file,
1807
- violation: issue.description,
1808
- confidence,
1809
- goalIndex: issue.goalIndex,
1810
- totalActiveGoals: activeGoals.length
1811
- });
1812
- const ledgerIssue = {
1813
- id: fixId,
1814
- hash: "",
1815
- file: issue.file,
1816
- line: void 0,
1817
- agent: "ai-watcher",
1818
- severity: severity === "critical" ? "critical" : severity === "major" ? "high" : "medium",
1819
- issue: `Goal "${goal.description}" violated: ${issue.description}`,
1820
- fix: issue.suggestedFix || "Review and fix",
1821
- category: "goal-violation",
1822
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1823
- project: basename2(projectPath),
1824
- resolved: false,
1825
- resolvedAt: void 0
1826
- };
1827
- await appendIssuesToLedger([ledgerIssue], projectPath);
1828
- await recordGoalViolationCaught(goal, issue.file, projectPath);
1829
- const confidenceStr = `${confidence}%`;
1830
- const nudgeMsg = `Goal "${goal.description}" violated in ${issue.file}: ${issue.description} [${confidenceStr} confidence]`;
1831
- console.debug("[AI Watcher] Sending nudge:", {
1832
- message: nudgeMsg,
1833
- file: issue.file,
1834
- severity: "warning"
1835
- });
1836
- getOutputManager().nudge(nudgeMsg, "warning", issue.file);
1837
- await this.persistNudge({
1838
- message: nudgeMsg,
1839
- severity: "warning",
1840
- file: issue.file,
1841
- category: "quality",
1842
- goalId: goal.id,
1843
- priority: 7,
1844
- suggestedAction: issue.suggestedFix || "Review and fix manually",
1845
- relatedIssues: [fixId]
1774
+ console.debug("[AI Watcher] AI analysis result:", {
1775
+ success: result.success,
1776
+ contentLength: result.content ? result.content.length : 0,
1777
+ tokensUsed: result.tokensUsed,
1778
+ contentPreview: result.content ? result.content.slice(0, 500) : "null"
1779
+ });
1780
+ if (!result.success || !result.content.trim()) {
1781
+ console.debug("[AI Watcher] AI analysis failed or returned empty content");
1782
+ return;
1783
+ }
1784
+ let issues = [];
1785
+ try {
1786
+ const cleaned = result.content.replace(/```json?\n?|\n?```/g, "").trim();
1787
+ console.debug("[AI Watcher] Parsing AI response:", { cleanedContent: cleaned.slice(0, 300) });
1788
+ issues = JSON.parse(cleaned);
1789
+ if (!Array.isArray(issues)) issues = [];
1790
+ console.debug("[AI Watcher] Parsed issues:", {
1791
+ totalIssues: issues.length,
1792
+ goalViolations: issues.filter((i) => i.isGoalViolation).length,
1793
+ issueTypes: issues.map((i) => ({ file: i.file, isGoalViolation: i.isGoalViolation, goalIndex: i.goalIndex }))
1846
1794
  });
1847
- if (this.streamingManager) {
1848
- this.streamingManager.reportPendingFix({
1795
+ } catch (error) {
1796
+ console.debug("[AI Watcher] Failed to parse AI response:", error);
1797
+ return;
1798
+ }
1799
+ const issuedFiles = new Set(issues.map((i) => i.file));
1800
+ for (const { relativePath } of filesToScan) {
1801
+ if (!issuedFiles.has(relativePath)) {
1802
+ this.state.cleanFiles.set(relativePath, Date.now());
1803
+ }
1804
+ }
1805
+ if (issues.length === 0) return;
1806
+ for (const issue of issues.slice(0, 10)) {
1807
+ const severity = issue.severity === "critical" ? "critical" : issue.severity === "major" ? "major" : "minor";
1808
+ if (issue.isGoalViolation && issue.goalIndex != null && issue.goalIndex >= 0 && issue.goalIndex < activeGoals.length) {
1809
+ const goal = activeGoals[issue.goalIndex];
1810
+ if (!goal) continue;
1811
+ const confidence = Math.min(100, Math.max(0, issue.confidence ?? 80));
1812
+ const fixId = `fix-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
1813
+ console.debug("[AI Watcher] Goal violation detected:", {
1814
+ goalDescription: goal.description,
1815
+ file: issue.file,
1816
+ violation: issue.description,
1817
+ confidence,
1818
+ goalIndex: issue.goalIndex,
1819
+ totalActiveGoals: activeGoals.length
1820
+ });
1821
+ const goalViolationIssue = {
1849
1822
  id: fixId,
1850
1823
  file: issue.file,
1851
- description: issue.description,
1852
- goalDescription: goal.description,
1824
+ agent: "goal-violation",
1825
+ severity: severity === "critical" ? "critical" : severity === "major" ? "serious" : "moderate",
1826
+ issue: `Goal "${goal.description}" violated: ${issue.description}`,
1827
+ fix: issue.suggestedFix || "Review and fix",
1828
+ category: "goal-violation",
1853
1829
  confidence,
1854
- severity: issue.severity,
1855
- suggestedFix: issue.suggestedFix || "Remove the violating code"
1830
+ autoFixable: true
1831
+ };
1832
+ await storeIssues([goalViolationIssue], basename2(projectPath), projectPath);
1833
+ await recordGoalViolationCaught(goal, issue.file, projectPath);
1834
+ const confidenceStr = `${confidence}%`;
1835
+ const nudgeMsg = `Goal "${goal.description}" violated in ${issue.file}: ${issue.description} [${confidenceStr} confidence]`;
1836
+ console.debug("[AI Watcher] Sending nudge:", {
1837
+ message: nudgeMsg,
1838
+ file: issue.file,
1839
+ severity: "warning"
1856
1840
  });
1841
+ getOutputManager().nudge(nudgeMsg, "warning", issue.file);
1842
+ await this.persistNudge({
1843
+ message: nudgeMsg,
1844
+ severity: "warning",
1845
+ file: issue.file,
1846
+ category: "quality",
1847
+ goalId: goal.id,
1848
+ priority: 7,
1849
+ suggestedAction: issue.suggestedFix || "Review and fix manually",
1850
+ relatedIssues: [fixId]
1851
+ });
1852
+ if (this.streamingManager) {
1853
+ this.streamingManager.reportPendingFix({
1854
+ id: fixId,
1855
+ file: issue.file,
1856
+ description: issue.description,
1857
+ goalDescription: goal.description,
1858
+ confidence,
1859
+ severity: issue.severity,
1860
+ suggestedFix: issue.suggestedFix || "Remove the violating code"
1861
+ });
1862
+ }
1863
+ if (!isInteractiveMode()) {
1864
+ console.error(` [!] Goal violation (${confidenceStr}): ${issue.description}`);
1865
+ console.error(` Fix: ${issue.suggestedFix || "Review and fix manually"}`);
1866
+ }
1867
+ continue;
1857
1868
  }
1858
- if (!isInteractiveMode()) {
1859
- console.error(` [!] Goal violation (${confidenceStr}): ${issue.description}`);
1860
- console.error(` Fix: ${issue.suggestedFix || "Review and fix manually"}`);
1861
- }
1862
- continue;
1863
- }
1864
- const incident = await graph.addNode("incident", {
1865
- description: issue.description,
1866
- severity,
1867
- affectedUsers: null,
1868
- duration: null,
1869
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1870
- resolved: false,
1871
- resolution: null,
1872
- fixChangeId: null,
1873
- reportedVia: "detected"
1874
- });
1875
- const filePath = join2(projectPath, issue.file);
1876
- const fileNode = await graph.getNode("file", filePath);
1877
- if (fileNode) {
1878
- await graph.addEdge(fileNode.id, incident.id, "affects");
1879
- const data = fileNode.data;
1880
- const newRisk = severity === "critical" ? "critical" : severity === "major" ? "high" : data.riskLevel === "low" ? "medium" : data.riskLevel;
1881
- await graph.updateNode("file", fileNode.id, {
1882
- incidentCount: (data.incidentCount ?? 0) + 1,
1883
- riskLevel: newRisk
1869
+ const incident = await graph.addNode("incident", {
1870
+ description: issue.description,
1871
+ severity,
1872
+ affectedUsers: null,
1873
+ duration: null,
1874
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1875
+ resolved: false,
1876
+ resolution: null,
1877
+ fixChangeId: null,
1878
+ reportedVia: "detected"
1884
1879
  });
1880
+ const filePath = join2(projectPath, issue.file);
1881
+ const fileNode = await graph.getNode("file", filePath);
1882
+ if (fileNode) {
1883
+ await graph.addEdge(fileNode.id, incident.id, "affects");
1884
+ const data = fileNode.data;
1885
+ const newRisk = severity === "critical" ? "critical" : severity === "major" ? "high" : data.riskLevel === "low" ? "medium" : data.riskLevel;
1886
+ await graph.updateNode("file", fileNode.id, {
1887
+ incidentCount: (data.incidentCount ?? 0) + 1,
1888
+ riskLevel: newRisk
1889
+ });
1890
+ }
1891
+ this.state.totalIssuesFound++;
1892
+ if (severity !== "minor") {
1893
+ getOutputManager().nudge(
1894
+ `${issue.description}`,
1895
+ severity === "critical" ? "critical" : "warning",
1896
+ issue.file,
1897
+ severity === "critical" ? void 0 : 15e3
1898
+ );
1899
+ await this.persistNudge({
1900
+ message: issue.description,
1901
+ severity: severity === "critical" ? "critical" : "warning",
1902
+ file: issue.file,
1903
+ category: "quality",
1904
+ priority: severity === "critical" ? 9 : 6,
1905
+ ...issue.suggestedFix && { suggestedAction: issue.suggestedFix }
1906
+ });
1907
+ }
1885
1908
  }
1886
- this.state.totalIssuesFound++;
1887
- if (severity !== "minor") {
1888
- getOutputManager().nudge(
1889
- `${issue.description}`,
1890
- severity === "critical" ? "critical" : "warning",
1891
- issue.file,
1892
- severity === "critical" ? void 0 : 15e3
1893
- );
1894
- await this.persistNudge({
1895
- message: issue.description,
1896
- severity: severity === "critical" ? "critical" : "warning",
1897
- file: issue.file,
1898
- category: "quality",
1899
- priority: severity === "critical" ? 9 : 6,
1900
- ...issue.suggestedFix && { suggestedAction: issue.suggestedFix }
1909
+ if (this.streamingManager && issues.length > 0) {
1910
+ this.streamingManager.reportSignalExtraction({
1911
+ governance: 0,
1912
+ facts: 0,
1913
+ blockers: issues.length,
1914
+ questions: 0
1901
1915
  });
1902
1916
  }
1917
+ } catch (error) {
1918
+ getOutputManager().log("warn", `AI watcher error: ${error}`);
1903
1919
  }
1904
- if (this.streamingManager && issues.length > 0) {
1905
- this.streamingManager.reportSignalExtraction({
1906
- decisions: 0,
1907
- facts: 0,
1908
- blockers: issues.length,
1909
- questions: 0
1910
- });
1911
- }
1912
- } catch (error) {
1913
- getOutputManager().log("warn", `AI watcher error: ${error}`);
1914
1920
  } finally {
1915
1921
  this.state.autoScanInProgress = false;
1916
1922
  }
@@ -1929,7 +1935,7 @@ ${filesBlock}`,
1929
1935
  const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
1930
1936
  console.debug("[Initial Hypothesis] Starting initial hypothesis generation", { projectPath });
1931
1937
  try {
1932
- const { getHypothesisEngine } = await import("./hypothesis-L5446W36.js");
1938
+ const { getHypothesisEngine } = await import("./hypothesis-K3KQJOXJ.js");
1933
1939
  const hypothesisEngine = getHypothesisEngine(projectPath);
1934
1940
  console.debug("[Initial Hypothesis] Running AI-powered hypothesis generation...");
1935
1941
  const generated = await hypothesisEngine.generateHypothesesWithAI({
@@ -1943,7 +1949,7 @@ ${filesBlock}`,
1943
1949
  hypotheses: generated.map((h) => ({ statement: h.statement, confidence: h.confidence }))
1944
1950
  });
1945
1951
  if (generated.length > 0) {
1946
- const { getOutputManager: getOutputManager2 } = await import("./output-manager-BOTMXSND.js");
1952
+ const { getOutputManager: getOutputManager2 } = await import("./output-manager-DZO5LGSG.js");
1947
1953
  const outputManager = getOutputManager2();
1948
1954
  for (const hypothesis of generated.slice(0, 2)) {
1949
1955
  const message = `[Initial Hypothesis] "${hypothesis.statement}" (${Math.round(hypothesis.confidence * 100)}% confidence)`;
@@ -1954,7 +1960,7 @@ ${filesBlock}`,
1954
1960
  }
1955
1961
  if (this.streamingManager) {
1956
1962
  this.streamingManager.reportSignalExtraction({
1957
- decisions: 0,
1963
+ governance: 0,
1958
1964
  facts: 0,
1959
1965
  blockers: 0,
1960
1966
  questions: generated.length
@@ -1987,7 +1993,7 @@ ${filesBlock}`,
1987
1993
  const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
1988
1994
  console.debug("[Initial Scan] Starting initial goal compliance scan", { projectPath });
1989
1995
  try {
1990
- const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-PDKYZSNP.js");
1996
+ const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-GISXYANK.js");
1991
1997
  const activeGoals = await getActiveGoals(projectPath);
1992
1998
  console.debug("[Initial Scan] Loaded goals for initial scan:", {
1993
1999
  goalCount: activeGoals.length,
@@ -2089,22 +2095,26 @@ ${filesBlock}`,
2089
2095
  } catch {
2090
2096
  return;
2091
2097
  }
2092
- const { appendIssuesToLedger } = await import("./ledger-WKVJWHBX.js");
2093
- const issuesForLedger = [];
2098
+ const issuesToStore = [];
2094
2099
  let violationsFound = 0;
2095
2100
  for (const issue of issues) {
2096
2101
  if (!issue.isGoalViolation || issue.confidence < 40) continue;
2097
2102
  violationsFound++;
2098
- issuesForLedger.push({
2099
- file: issue.file,
2100
- message: issue.description,
2101
- severity: issue.severity,
2102
- confidence: issue.confidence,
2103
- category: "goal-violation",
2104
- suggestedFix: issue.suggestedFix
2105
- });
2106
2103
  if (issue.goalIndex != null && issue.goalIndex >= 0 && issue.goalIndex < activeGoals.length) {
2107
2104
  const goal = activeGoals[issue.goalIndex];
2105
+ if (!goal) continue;
2106
+ const fixId = `fix-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
2107
+ issuesToStore.push({
2108
+ id: fixId,
2109
+ file: issue.file,
2110
+ agent: "goal-violation",
2111
+ severity: issue.severity === "critical" ? "critical" : issue.severity === "major" ? "serious" : "moderate",
2112
+ issue: `Goal "${goal.description}" violated: ${issue.description}`,
2113
+ fix: issue.suggestedFix || "Review and fix",
2114
+ category: "goal-violation",
2115
+ confidence: issue.confidence,
2116
+ autoFixable: true
2117
+ });
2108
2118
  await recordGoalViolationCaught(goal, issue.file, projectPath);
2109
2119
  const confidenceStr = issue.confidence >= 80 ? "high" : issue.confidence >= 60 ? "medium" : "low";
2110
2120
  const nudgeMsg = `Goal "${goal.description}" violated in ${issue.file}: ${issue.description} [${confidenceStr} confidence]`;
@@ -2120,8 +2130,8 @@ ${filesBlock}`,
2120
2130
  });
2121
2131
  }
2122
2132
  }
2123
- if (issuesForLedger.length > 0) {
2124
- await appendIssuesToLedger(issuesForLedger, projectPath);
2133
+ if (issuesToStore.length > 0) {
2134
+ await storeIssues(issuesToStore, basename2(projectPath), projectPath);
2125
2135
  }
2126
2136
  if (!isInteractiveMode()) {
2127
2137
  if (violationsFound > 0) {
@@ -2145,7 +2155,7 @@ ${filesBlock}`,
2145
2155
  }]
2146
2156
  };
2147
2157
  }
2148
- for (const [_dir, watcher] of this.watchers) {
2158
+ for (const watcher of this.watchers.values()) {
2149
2159
  watcher.close();
2150
2160
  }
2151
2161
  this.watchers.clear();
@@ -2186,7 +2196,7 @@ ${filesBlock}`,
2186
2196
  - Issues found: ${this.state.totalIssuesFound}
2187
2197
  - Tokens used: ${tokensK}k / ${(budget.hourlyLimit / 1e3).toFixed(0)}k hourly limit
2188
2198
  - Scans skipped (trie-throttled): ${budget.scansSaved}
2189
- - Decision ledger: Updated continuously
2199
+ - Governance ledger: Updated continuously
2190
2200
 
2191
2201
  Use \`trie_watch start\` to resume.`
2192
2202
  }]
@@ -2212,8 +2222,8 @@ Use \`trie_watch start\` to begin autonomous scanning.`
2212
2222
  ).join("\n");
2213
2223
  let agencyStatus = "";
2214
2224
  try {
2215
- const { getGuardian } = await import("./guardian-agent-4RHGIXUD.js");
2216
- const trieAgent = getGuardian(this.watchedDirectory || getWorkingDirectory(void 0, true));
2225
+ const { getTrieAgent } = await import("./trie-agent-XMSGMD7E.js");
2226
+ const trieAgent = getTrieAgent(this.watchedDirectory || getWorkingDirectory(void 0, true));
2217
2227
  await trieAgent.initialize();
2218
2228
  const status = await trieAgent.getAgencyStatus();
2219
2229
  agencyStatus = `
@@ -3313,9 +3323,9 @@ var TrieMemorySearchTool = class {
3313
3323
  }
3314
3324
  }
3315
3325
  if (projects.length > 0) {
3316
- lines.push("## Recent Projects", "", "| Project | Health | Issues |", "|---------|--------|--------|");
3326
+ lines.push("## Recent Projects", "", "| Project | Issues |", "|---------|--------|");
3317
3327
  for (const p of projects.slice(0, 5)) {
3318
- lines.push(`| ${p.name} | ${p.healthScore}% | ${p.totalIssues} |`);
3328
+ lines.push(`| ${p.name} | ${p.totalIssues} |`);
3319
3329
  }
3320
3330
  }
3321
3331
  return lines.join("\n");
@@ -3491,6 +3501,21 @@ var TrieIndexTool = class {
3491
3501
  const codebaseIndex = new CodebaseIndex(workDir);
3492
3502
  if (action === "status") {
3493
3503
  const stats2 = codebaseIndex.getStats();
3504
+ let lastUpdatedStr = "Never";
3505
+ if (stats2.lastUpdated) {
3506
+ try {
3507
+ const date = new Date(stats2.lastUpdated);
3508
+ lastUpdatedStr = date.toLocaleString("en-US", {
3509
+ year: "numeric",
3510
+ month: "short",
3511
+ day: "numeric",
3512
+ hour: "numeric",
3513
+ minute: "2-digit"
3514
+ });
3515
+ } catch {
3516
+ lastUpdatedStr = "Unknown";
3517
+ }
3518
+ }
3494
3519
  return [
3495
3520
  "# Codebase Index Status",
3496
3521
  "",
@@ -3498,6 +3523,7 @@ var TrieIndexTool = class {
3498
3523
  `**Total size:** ${(stats2.totalSize / 1024 / 1024).toFixed(2)} MB`,
3499
3524
  `**Files scanned for goals:** ${stats2.scannedFiles}`,
3500
3525
  `**Files with violations:** ${stats2.filesWithViolations}`,
3526
+ `**Last updated:** ${lastUpdatedStr}`,
3501
3527
  "",
3502
3528
  "## Files by Type",
3503
3529
  "",
@@ -3608,8 +3634,10 @@ var ToolRegistry = class {
3608
3634
  this.tools.set("bad", new TrieFeedbackTool());
3609
3635
  this.tools.set("linear_sync", new LinearSyncTool());
3610
3636
  this.tools.set("index", new TrieIndexTool());
3637
+ this.tools.set("get_governance", new TrieGetGovernanceTool());
3611
3638
  this.tools.set("get_decisions", new TrieGetDecisionsTool());
3612
3639
  this.tools.set("get_blockers", new TrieGetBlockersTool());
3640
+ this.tools.set("get_related_governance", new TrieGetRelatedGovernanceTool());
3613
3641
  this.tools.set("get_related_decisions", new TrieGetRelatedDecisionsTool());
3614
3642
  this.tools.set("query_context", new TrieQueryContextTool());
3615
3643
  }
@@ -4090,13 +4118,27 @@ var ToolRegistry = class {
4090
4118
  }
4091
4119
  }
4092
4120
  },
4121
+ {
4122
+ name: "trie_get_governance",
4123
+ description: "Query governance records (architectural decisions, standards, team agreements) from governance ledger with targeted retrieval. Prevents context pollution by returning only relevant records.",
4124
+ inputSchema: {
4125
+ type: "object",
4126
+ properties: {
4127
+ relatedTo: { type: "string", description: "File path or topic to find related governance" },
4128
+ tags: { type: "array", items: { type: "string" }, description: "Filter by tags" },
4129
+ since: { type: "string", description: 'Time filter: ISO date or "7d", "30d", "90d"' },
4130
+ limit: { type: "number", description: "Max results (default 10)" },
4131
+ directory: { type: "string", description: "Working directory" }
4132
+ }
4133
+ }
4134
+ },
4093
4135
  {
4094
4136
  name: "trie_get_decisions",
4095
- description: "Query decisions from decision ledger with targeted retrieval. Prevents context pollution by returning only relevant decisions.",
4137
+ description: "[DEPRECATED - use trie_get_governance] Query governance records from ledger. Backward compatibility alias.",
4096
4138
  inputSchema: {
4097
4139
  type: "object",
4098
4140
  properties: {
4099
- relatedTo: { type: "string", description: "File path or topic to find related decisions" },
4141
+ relatedTo: { type: "string", description: "File path or topic to find related governance" },
4100
4142
  tags: { type: "array", items: { type: "string" }, description: "Filter by tags" },
4101
4143
  since: { type: "string", description: 'Time filter: ISO date or "7d", "30d", "90d"' },
4102
4144
  limit: { type: "number", description: "Max results (default 10)" },
@@ -4106,7 +4148,7 @@ var ToolRegistry = class {
4106
4148
  },
4107
4149
  {
4108
4150
  name: "trie_get_blockers",
4109
- description: "Get active blockers from decision ledger. Returns only unresolved blockers to avoid noise.",
4151
+ description: "Get active blockers from governance ledger. Returns only unresolved blockers to avoid noise.",
4110
4152
  inputSchema: {
4111
4153
  type: "object",
4112
4154
  properties: {
@@ -4116,15 +4158,29 @@ var ToolRegistry = class {
4116
4158
  }
4117
4159
  }
4118
4160
  },
4161
+ {
4162
+ name: "trie_get_related_governance",
4163
+ description: "Find governance records related to a specific governance record, file, or topic. Targeted context retrieval.",
4164
+ inputSchema: {
4165
+ type: "object",
4166
+ properties: {
4167
+ governanceId: { type: "string", description: "Governance ID to find related records" },
4168
+ file: { type: "string", description: "File path to find related governance" },
4169
+ topic: { type: "string", description: "Topic to find related governance" },
4170
+ limit: { type: "number", description: "Max results (default 5)" },
4171
+ directory: { type: "string", description: "Working directory" }
4172
+ }
4173
+ }
4174
+ },
4119
4175
  {
4120
4176
  name: "trie_get_related_decisions",
4121
- description: "Find decisions related to a specific decision, file, or topic. Targeted context retrieval.",
4177
+ description: "[DEPRECATED - use trie_get_related_governance] Find related governance records. Backward compatibility alias.",
4122
4178
  inputSchema: {
4123
4179
  type: "object",
4124
4180
  properties: {
4125
- decisionId: { type: "string", description: "Decision ID to find related decisions" },
4126
- file: { type: "string", description: "File path to find related decisions" },
4127
- topic: { type: "string", description: "Topic to find related decisions" },
4181
+ decisionId: { type: "string", description: "Decision ID to find related records" },
4182
+ file: { type: "string", description: "File path to find related governance" },
4183
+ topic: { type: "string", description: "Topic to find related governance" },
4128
4184
  limit: { type: "number", description: "Max results (default 5)" },
4129
4185
  directory: { type: "string", description: "Working directory" }
4130
4186
  }
@@ -4132,17 +4188,17 @@ var ToolRegistry = class {
4132
4188
  },
4133
4189
  {
4134
4190
  name: "trie_query_context",
4135
- description: "Query decision ledger with natural language. Returns targeted signal, not full dump.",
4191
+ description: 'Natural-language search across ALL Trie context: goals, hypotheses, nudges (goal violations), governance, blockers. Use for "what are my goals", "show hypotheses", "any nudges", "recent governance", etc.',
4136
4192
  inputSchema: {
4137
4193
  type: "object",
4138
4194
  properties: {
4139
- query: { type: "string", description: "Natural language query" },
4195
+ query: { type: "string", description: "Natural language query (e.g. goals, hypotheses, nudges, governance)" },
4140
4196
  type: {
4141
4197
  type: "string",
4142
- enum: ["decisions", "blockers", "facts", "questions", "all"],
4143
- description: "Type of context to query (default: all)"
4198
+ enum: ["goals", "hypotheses", "nudges", "governance", "decisions", "blockers", "facts", "questions", "all"],
4199
+ description: 'Type of context to query (default: all). "decisions" is deprecated, use "governance"'
4144
4200
  },
4145
- limit: { type: "number", description: "Max results per type (default 5)" },
4201
+ limit: { type: "number", description: "Max results per type (default 10)" },
4146
4202
  directory: { type: "string", description: "Working directory" }
4147
4203
  },
4148
4204
  required: ["query"]
@@ -4251,7 +4307,7 @@ var ResourceManager = class {
4251
4307
  {
4252
4308
  uri: "trie://skills/installed",
4253
4309
  name: "Installed Skills",
4254
- description: "External skills installed from skills.sh that the guardian can apply",
4310
+ description: "External skills installed from skills.sh that Trie can apply",
4255
4311
  mimeType: "application/json"
4256
4312
  },
4257
4313
  {
@@ -4524,7 +4580,6 @@ var ResourceManager = class {
4524
4580
  "",
4525
4581
  `| Metric | Value |`,
4526
4582
  `|--------|-------|`,
4527
- `| Health Score | ${state.healthScore}% |`,
4528
4583
  `| Last Scan | ${state.lastScan ? new Date(state.lastScan.timestamp).toLocaleDateString() : "Never"} |`,
4529
4584
  `| Critical Issues | ${state.lastScan?.issues.critical ?? 0} |`,
4530
4585
  `| Total Issues | ${state.lastScan?.issues.total ?? 0} |`,
@@ -5558,7 +5613,7 @@ var MCPServer = class {
5558
5613
  \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D
5559
5614
  \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
5560
5615
  \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D
5561
- Your central registry for the guardian and its skills
5616
+ Your central registry for Trie and its skills
5562
5617
 
5563
5618
  by Louis Kishfy
5564
5619