@triedotdev/mcp 1.0.115 → 1.0.117

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 (65) hide show
  1. package/dist/{autonomy-config-JXB7WCZ2.js → autonomy-config-QA6ATWLJ.js} +3 -3
  2. package/dist/{chunk-R4AAPFXC.js → chunk-45Y5TLQZ.js} +2 -2
  3. package/dist/{chunk-R4AAPFXC.js.map → chunk-45Y5TLQZ.js.map} +1 -1
  4. package/dist/{chunk-KRH642MT.js → chunk-4BGAVEO6.js} +2 -2
  5. package/dist/{chunk-NS2MSZMB.js → chunk-55CBWOEZ.js} +2 -2
  6. package/dist/{chunk-YR4BMGYO.js → chunk-7Q6I2CB4.js} +2 -2
  7. package/dist/{chunk-TKMV7JKN.js → chunk-DFHMB44X.js} +2 -2
  8. package/dist/{chunk-ZYKEILVK.js → chunk-EWVU7QUG.js} +464 -88
  9. package/dist/chunk-EWVU7QUG.js.map +1 -0
  10. package/dist/{chunk-D3EXBJE2.js → chunk-FNW7Z7ZS.js} +5 -5
  11. package/dist/{chunk-DZREHOGW.js → chunk-I7XKF5XD.js} +5 -5
  12. package/dist/{chunk-2SIFK7OW.js → chunk-IQBHPTV7.js} +4 -4
  13. package/dist/{chunk-AOFYU6T3.js → chunk-OMCEUJ5I.js} +12 -12
  14. package/dist/{chunk-MVNJPJBK.js → chunk-PPZYVTUO.js} +71 -5
  15. package/dist/{chunk-MVNJPJBK.js.map → chunk-PPZYVTUO.js.map} +1 -1
  16. package/dist/{chunk-55DOQNHJ.js → chunk-PRFHN2X6.js} +4 -4
  17. package/dist/{chunk-2GIAROBF.js → chunk-WHIQAGB7.js} +2 -2
  18. package/dist/{chunk-SWSK7ANT.js → chunk-WRGSH5RT.js} +2 -2
  19. package/dist/{chunk-6LXSA2OZ.js → chunk-Y52SNUW5.js} +3 -3
  20. package/dist/{chunk-I2GFI3AM.js → chunk-ZEXMMTIQ.js} +2 -2
  21. package/dist/cli/create-agent.js +1 -1
  22. package/dist/cli/main.js +66 -32
  23. package/dist/cli/main.js.map +1 -1
  24. package/dist/cli/yolo-daemon.js +14 -14
  25. package/dist/{client-7XZHCMD3.js → client-PMKE26IV.js} +3 -3
  26. package/dist/{goal-manager-LMS6ZJB7.js → goal-manager-JKTNFJQE.js} +7 -7
  27. package/dist/goal-validator-YSNN23D4.js +62 -0
  28. package/dist/goal-validator-YSNN23D4.js.map +1 -0
  29. package/dist/{graph-U5JWSAB5.js → graph-PAUZ5EMP.js} +3 -3
  30. package/dist/guardian-agent-UY2G56FT.js +25 -0
  31. package/dist/{hypothesis-KGC3P54C.js → hypothesis-RUCJ74X7.js} +7 -7
  32. package/dist/{incident-index-PNIVT47T.js → incident-index-ZCDSJ42L.js} +3 -3
  33. package/dist/index.js +215 -128
  34. package/dist/index.js.map +1 -1
  35. package/dist/{ledger-SR6OEBLO.js → ledger-JMPGJGLB.js} +3 -3
  36. package/package.json +1 -1
  37. package/dist/auto-fix-apply-PCAHWLXF.js +0 -10
  38. package/dist/chunk-DJ2YAGHK.js +0 -50
  39. package/dist/chunk-DJ2YAGHK.js.map +0 -1
  40. package/dist/chunk-ZYKEILVK.js.map +0 -1
  41. package/dist/goal-validator-T5HEYBC5.js +0 -186
  42. package/dist/goal-validator-T5HEYBC5.js.map +0 -1
  43. package/dist/guardian-agent-EXP7APLC.js +0 -25
  44. package/dist/ledger-SR6OEBLO.js.map +0 -1
  45. /package/dist/{auto-fix-apply-PCAHWLXF.js.map → autonomy-config-QA6ATWLJ.js.map} +0 -0
  46. /package/dist/{chunk-KRH642MT.js.map → chunk-4BGAVEO6.js.map} +0 -0
  47. /package/dist/{chunk-NS2MSZMB.js.map → chunk-55CBWOEZ.js.map} +0 -0
  48. /package/dist/{chunk-YR4BMGYO.js.map → chunk-7Q6I2CB4.js.map} +0 -0
  49. /package/dist/{chunk-TKMV7JKN.js.map → chunk-DFHMB44X.js.map} +0 -0
  50. /package/dist/{chunk-D3EXBJE2.js.map → chunk-FNW7Z7ZS.js.map} +0 -0
  51. /package/dist/{chunk-DZREHOGW.js.map → chunk-I7XKF5XD.js.map} +0 -0
  52. /package/dist/{chunk-2SIFK7OW.js.map → chunk-IQBHPTV7.js.map} +0 -0
  53. /package/dist/{chunk-AOFYU6T3.js.map → chunk-OMCEUJ5I.js.map} +0 -0
  54. /package/dist/{chunk-55DOQNHJ.js.map → chunk-PRFHN2X6.js.map} +0 -0
  55. /package/dist/{chunk-2GIAROBF.js.map → chunk-WHIQAGB7.js.map} +0 -0
  56. /package/dist/{chunk-SWSK7ANT.js.map → chunk-WRGSH5RT.js.map} +0 -0
  57. /package/dist/{chunk-6LXSA2OZ.js.map → chunk-Y52SNUW5.js.map} +0 -0
  58. /package/dist/{chunk-I2GFI3AM.js.map → chunk-ZEXMMTIQ.js.map} +0 -0
  59. /package/dist/{autonomy-config-JXB7WCZ2.js.map → client-PMKE26IV.js.map} +0 -0
  60. /package/dist/{client-7XZHCMD3.js.map → goal-manager-JKTNFJQE.js.map} +0 -0
  61. /package/dist/{goal-manager-LMS6ZJB7.js.map → graph-PAUZ5EMP.js.map} +0 -0
  62. /package/dist/{graph-U5JWSAB5.js.map → guardian-agent-UY2G56FT.js.map} +0 -0
  63. /package/dist/{guardian-agent-EXP7APLC.js.map → hypothesis-RUCJ74X7.js.map} +0 -0
  64. /package/dist/{hypothesis-KGC3P54C.js.map → incident-index-ZCDSJ42L.js.map} +0 -0
  65. /package/dist/{incident-index-PNIVT47T.js.map → ledger-JMPGJGLB.js.map} +0 -0
package/dist/index.js CHANGED
@@ -18,10 +18,10 @@ import {
18
18
  needsBootstrap,
19
19
  projectInfoExists,
20
20
  updateProjectSection
21
- } from "./chunk-TKMV7JKN.js";
21
+ } from "./chunk-DFHMB44X.js";
22
22
  import {
23
23
  getAutonomyConfig
24
- } from "./chunk-I2GFI3AM.js";
24
+ } from "./chunk-ZEXMMTIQ.js";
25
25
  import {
26
26
  ExtractionPipeline,
27
27
  InteractiveDashboard,
@@ -38,28 +38,30 @@ import {
38
38
  getPrompt,
39
39
  getSystemPrompt,
40
40
  handleCheckpointTool
41
- } from "./chunk-ZYKEILVK.js";
42
- import "./chunk-AOFYU6T3.js";
43
- import "./chunk-2SIFK7OW.js";
44
- import "./chunk-DZREHOGW.js";
45
- import "./chunk-6LXSA2OZ.js";
41
+ } from "./chunk-EWVU7QUG.js";
42
+ import "./chunk-OMCEUJ5I.js";
43
+ import "./chunk-IQBHPTV7.js";
44
+ import "./chunk-I7XKF5XD.js";
45
+ import "./chunk-Y52SNUW5.js";
46
46
  import {
47
47
  exportToJson,
48
48
  formatFriendlyError,
49
+ getChangedFilesSinceTimestamp,
50
+ getGitChangedFiles,
49
51
  importFromJson,
50
52
  isTrieInitialized,
51
53
  runShellCommandSync
52
- } from "./chunk-MVNJPJBK.js";
54
+ } from "./chunk-PPZYVTUO.js";
53
55
  import {
54
56
  findCrossProjectPatterns,
55
57
  getGlobalMemoryStats,
56
58
  listTrackedProjects,
57
59
  searchGlobalPatterns
58
- } from "./chunk-D3EXBJE2.js";
60
+ } from "./chunk-FNW7Z7ZS.js";
59
61
  import {
60
62
  isAIAvailable,
61
63
  runAIAnalysis
62
- } from "./chunk-SWSK7ANT.js";
64
+ } from "./chunk-WRGSH5RT.js";
63
65
  import {
64
66
  findSimilarIssues,
65
67
  getMemoryStats,
@@ -67,14 +69,14 @@ import {
67
69
  markIssueResolved,
68
70
  purgeIssues,
69
71
  searchIssues
70
- } from "./chunk-55DOQNHJ.js";
71
- import "./chunk-KRH642MT.js";
72
+ } from "./chunk-PRFHN2X6.js";
73
+ import "./chunk-4BGAVEO6.js";
72
74
  import "./chunk-F4NJ4CBP.js";
73
75
  import "./chunk-IXO4G4D3.js";
74
76
  import {
75
77
  ContextGraph
76
- } from "./chunk-NS2MSZMB.js";
77
- import "./chunk-2GIAROBF.js";
78
+ } from "./chunk-55CBWOEZ.js";
79
+ import "./chunk-WHIQAGB7.js";
78
80
  import "./chunk-6NLHFIYA.js";
79
81
  import "./chunk-ZV2K6M7T.js";
80
82
  import {
@@ -83,12 +85,12 @@ import {
83
85
  import {
84
86
  getOutputManager
85
87
  } from "./chunk-VRLMTOB6.js";
86
- import "./chunk-YR4BMGYO.js";
88
+ import "./chunk-7Q6I2CB4.js";
87
89
  import "./chunk-43X6JBEM.js";
88
90
  import {
89
91
  getTrieDirectory,
90
92
  getWorkingDirectory
91
- } from "./chunk-R4AAPFXC.js";
93
+ } from "./chunk-45Y5TLQZ.js";
92
94
  import {
93
95
  isInteractiveMode
94
96
  } from "./chunk-APMV77PU.js";
@@ -1136,6 +1138,7 @@ var SKIP_DIRS = /* @__PURE__ */ new Set([
1136
1138
  ]);
1137
1139
  var TrieWatchTool = class _TrieWatchTool {
1138
1140
  extractionPipeline = null;
1141
+ watchedDirectory = "";
1139
1142
  state = {
1140
1143
  isRunning: false,
1141
1144
  lastScan: /* @__PURE__ */ new Map(),
@@ -1210,6 +1213,7 @@ var TrieWatchTool = class _TrieWatchTool {
1210
1213
  await this.extractionPipeline.initialize();
1211
1214
  }
1212
1215
  this.state.isRunning = true;
1216
+ this.watchedDirectory = directory;
1213
1217
  this.state.issueCache.clear();
1214
1218
  this.state.totalIssuesFound = 0;
1215
1219
  this.state.filesScanned = 0;
@@ -1245,6 +1249,7 @@ var TrieWatchTool = class _TrieWatchTool {
1245
1249
  debounceMs
1246
1250
  });
1247
1251
  }
1252
+ void this.initialGoalComplianceScan();
1248
1253
  return {
1249
1254
  content: [{
1250
1255
  type: "text",
@@ -1254,14 +1259,14 @@ Your Trie agent is now autonomously watching and learning from your codebase.
1254
1259
 
1255
1260
  **Watching:** \`${directory}\`
1256
1261
  **Debounce:** ${debounceMs}ms (waits for you to stop typing)
1257
- **Signal Extraction:** ${process.env.ANTHROPIC_API_KEY ? "\u2713 ENABLED" : "\u26A0\uFE0F LIMITED (set ANTHROPIC_API_KEY for full extraction)"}
1262
+ **Signal Extraction:** ${process.env.ANTHROPIC_API_KEY ? "ENABLED" : "LIMITED (set ANTHROPIC_API_KEY for full extraction)"}
1258
1263
 
1259
1264
  ### How the agent works:
1260
- 1. [*] You write/edit code
1261
- 2. [#] Agent detects the change
1262
- 3. [\u{1F9E0}] Extracts decisions, facts, blockers \u2192 stores in ledger
1263
- 4. [?] Predicts risks based on historical patterns
1264
- 5. [>] Nudges you in plain English if something looks risky
1265
+ 1. You write/edit code
1266
+ 2. Agent detects the change
1267
+ 3. Extracts decisions, facts, blockers -> stores in ledger
1268
+ 4. Predicts risks based on historical patterns
1269
+ 5. Nudges you if something looks risky
1265
1270
 
1266
1271
  ### The agent learns:
1267
1272
  - Every commit builds the decision ledger
@@ -1327,8 +1332,7 @@ Detected changes in ${files.length} file(s):`);
1327
1332
  console.error("");
1328
1333
  }
1329
1334
  try {
1330
- const projectPath = getWorkingDirectory(void 0, true);
1331
- await this.checkGoalViolations(files, projectPath);
1335
+ const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
1332
1336
  if (this.extractionPipeline) {
1333
1337
  try {
1334
1338
  const fileContents = await Promise.all(
@@ -1383,8 +1387,12 @@ ${f.content.slice(0, 1e3)}`
1383
1387
  this.lastHypothesisCheck = now;
1384
1388
  }
1385
1389
  if (this.streamingManager) {
1390
+ const now2 = Date.now();
1386
1391
  for (const file of files) {
1387
- this.streamingManager.reportWatchChange(file);
1392
+ const lastReport = this.state.lastScan.get(file) || 0;
1393
+ if (now2 - lastReport > 2e3) {
1394
+ this.streamingManager.reportWatchChange(file);
1395
+ }
1388
1396
  }
1389
1397
  }
1390
1398
  this.state.filesScanned += files.length;
@@ -1398,7 +1406,7 @@ ${f.content.slice(0, 1e3)}`
1398
1406
  }
1399
1407
  }
1400
1408
  isQuiet() {
1401
- const projectPath = getWorkingDirectory(void 0, true);
1409
+ const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
1402
1410
  const quietPath = join2(getTrieDirectory(projectPath), "quiet.json");
1403
1411
  try {
1404
1412
  const raw = readFileSync(quietPath, "utf-8");
@@ -1409,90 +1417,6 @@ ${f.content.slice(0, 1e3)}`
1409
1417
  return false;
1410
1418
  }
1411
1419
  }
1412
- /**
1413
- * Check file changes against active user goals
1414
- * If violations found: record to ledger, nudge user, auto-fix if enabled
1415
- */
1416
- async checkGoalViolations(files, projectPath) {
1417
- try {
1418
- const { validateAgainstGoals, recordGoalViolationCaught, recordGoalViolationFixed } = await import("./goal-validator-T5HEYBC5.js");
1419
- const { appendIssuesToLedger } = await import("./ledger-SR6OEBLO.js");
1420
- const { getAutonomyConfig: getAutonomyConfig2 } = await import("./autonomy-config-JXB7WCZ2.js");
1421
- const { applyAutoFix } = await import("./auto-fix-apply-PCAHWLXF.js");
1422
- const config = await getAutonomyConfig2(projectPath);
1423
- const outputMgr = getOutputManager();
1424
- for (const file of files) {
1425
- try {
1426
- const content = await readFile3(file, "utf-8");
1427
- const result = await validateAgainstGoals(file, content, projectPath);
1428
- if (result.violations.length === 0) {
1429
- continue;
1430
- }
1431
- for (const violation of result.violations) {
1432
- const relativePath = file.replace(projectPath + "/", "");
1433
- const issue = {
1434
- id: `goal-violation-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
1435
- hash: "",
1436
- file: relativePath,
1437
- line: violation.line,
1438
- agent: "goal-validator",
1439
- severity: violation.severity,
1440
- issue: violation.description,
1441
- fix: violation.autoFixable ? "Auto-fixable" : "Manual fix required",
1442
- category: "goal-violation",
1443
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1444
- project: basename2(projectPath),
1445
- resolved: false,
1446
- resolvedAt: void 0
1447
- };
1448
- await appendIssuesToLedger([issue], projectPath);
1449
- await recordGoalViolationCaught(violation.goal, relativePath, projectPath);
1450
- const nudgeMessage = `Goal "${violation.goal.description}" violated: ${violation.violation} in ${basename2(file)}:${violation.line || "?"}`;
1451
- outputMgr.nudge(
1452
- nudgeMessage,
1453
- violation.severity === "critical" ? "critical" : "warning",
1454
- relativePath
1455
- );
1456
- this.state.nudges.push({
1457
- file: basename2(file),
1458
- message: nudgeMessage,
1459
- severity: violation.severity === "critical" ? "critical" : "high",
1460
- timestamp: (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false })
1461
- });
1462
- if (!isInteractiveMode()) {
1463
- console.error(` [!] Goal violation: ${violation.description}`);
1464
- }
1465
- if (config.autoFix.enabled && violation.autoFixable && violation.fixAction) {
1466
- if (!isInteractiveMode()) {
1467
- console.error(` [*] Auto-fixing...`);
1468
- }
1469
- const fixed = await applyAutoFix(violation.fixAction);
1470
- if (fixed) {
1471
- await recordGoalViolationFixed(violation.goal, relativePath, projectPath);
1472
- const fixMessage = `Auto-fixed: ${violation.goal.description} violation in ${basename2(file)}`;
1473
- outputMgr.nudge(fixMessage, "info", relativePath, 5e3);
1474
- if (!isInteractiveMode()) {
1475
- console.error(` [+] Fixed automatically`);
1476
- }
1477
- }
1478
- }
1479
- }
1480
- if (this.streamingManager && result.violations.length > 0) {
1481
- this.streamingManager.reportSignalExtraction({
1482
- decisions: 0,
1483
- facts: 0,
1484
- blockers: result.violations.length,
1485
- questions: 0
1486
- });
1487
- }
1488
- } catch (error) {
1489
- outputMgr.log("warn", `Could not validate ${basename2(file)}: ${error}`);
1490
- }
1491
- }
1492
- } catch (error) {
1493
- getOutputManager().log("warn", `Goal validation error: ${error}`);
1494
- }
1495
- }
1496
1420
  /**
1497
1421
  * Check and generate hypotheses autonomously
1498
1422
  * Claude observes patterns and creates new hypotheses to test
@@ -1500,7 +1424,7 @@ ${f.content.slice(0, 1e3)}`
1500
1424
  async checkAndGenerateHypotheses(projectPath) {
1501
1425
  if (!isAIAvailable()) return;
1502
1426
  try {
1503
- const { getHypothesisEngine } = await import("./hypothesis-KGC3P54C.js");
1427
+ const { getHypothesisEngine } = await import("./hypothesis-RUCJ74X7.js");
1504
1428
  const { getOutputManager: getOutputManager2 } = await import("./output-manager-BOTMXSND.js");
1505
1429
  const hypothesisEngine = getHypothesisEngine(projectPath);
1506
1430
  const recentIssues = Array.from(this.state.issueCache.values()).flat();
@@ -1567,8 +1491,8 @@ ${f.content.slice(0, 1e3)}`
1567
1491
  const totalIssues = Array.from(this.state.issueCache.values()).flat().length;
1568
1492
  if (totalIssues < 5) return;
1569
1493
  try {
1570
- const { ContextGraph: ContextGraph2 } = await import("./graph-U5JWSAB5.js");
1571
- const { IncidentIndex } = await import("./incident-index-PNIVT47T.js");
1494
+ const { ContextGraph: ContextGraph2 } = await import("./graph-PAUZ5EMP.js");
1495
+ const { IncidentIndex } = await import("./incident-index-ZCDSJ42L.js");
1572
1496
  const { TriePatternDiscovery } = await import("./pattern-discovery-F7LU5K6E.js");
1573
1497
  const graph = new ContextGraph2(projectPath);
1574
1498
  const incidentIndex = await IncidentIndex.build(graph, projectPath);
@@ -1691,8 +1615,8 @@ ${f.content.slice(0, 1e3)}`
1691
1615
  if (this.state.autoScanInProgress) return;
1692
1616
  const now = Date.now();
1693
1617
  if (now - this.state.lastAutoScan < this.aiWatcherCooldownMs) return;
1618
+ const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
1694
1619
  try {
1695
- const projectPath = getWorkingDirectory(void 0, true);
1696
1620
  const config = await getAutonomyConfig(projectPath);
1697
1621
  const wc = config.aiWatcher;
1698
1622
  if (!wc.enabled) return;
@@ -1708,10 +1632,9 @@ ${f.content.slice(0, 1e3)}`
1708
1632
  this.state.autoScanInProgress = true;
1709
1633
  this.state.lastAutoScan = now;
1710
1634
  try {
1711
- const projectPath = getWorkingDirectory(void 0, true);
1712
1635
  const graph = new ContextGraph(projectPath);
1713
- const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-T5HEYBC5.js");
1714
- const { appendIssuesToLedger } = await import("./ledger-SR6OEBLO.js");
1636
+ const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-YSNN23D4.js");
1637
+ const { appendIssuesToLedger } = await import("./ledger-JMPGJGLB.js");
1715
1638
  const activeGoals = await getActiveGoals(projectPath);
1716
1639
  const hasGoals = activeGoals.length > 0;
1717
1640
  if (this.isQuiet() && !hasGoals) return;
@@ -1719,8 +1642,8 @@ ${f.content.slice(0, 1e3)}`
1719
1642
  for (const file of files) {
1720
1643
  const relativePath = file.replace(projectPath + "/", "");
1721
1644
  const score = await this.scoreScanPriority(relativePath, graph, projectPath);
1722
- if (score > 0) {
1723
- scored.push({ file, relativePath, score });
1645
+ if (hasGoals || score > 0) {
1646
+ scored.push({ file, relativePath, score: Math.max(score, hasGoals ? 1 : 0) });
1724
1647
  } else {
1725
1648
  this.state.tokenBudget.scansSaved++;
1726
1649
  }
@@ -1767,11 +1690,13 @@ ${goalsSection}
1767
1690
  Reply ONLY with a JSON array. Each element must have:
1768
1691
  - "file": relative file path
1769
1692
  - "severity": "critical" | "major" | "minor"
1770
- - "description": 1-sentence description
1693
+ - "description": 1-sentence description of what you found
1694
+ - "confidence": number 0-100, how confident you are this is a real issue
1695
+ - "suggestedFix": 1-sentence description of what should change to fix it
1771
1696
  - "isGoalViolation": true if this violates a user goal, false otherwise
1772
1697
  - "goalIndex": 0-based index of the violated goal (only if isGoalViolation is true)
1773
1698
 
1774
- Be thorough with goal checking. If a goal says "no emojis" and you see an emoji anywhere in the file, report it. If a goal says "no inline styles" and you see a style attribute, report it.
1699
+ Be thorough with goal checking. If a goal says "no emojis" and you see an emoji anywhere in the file, report it with the exact location. If a goal says "no inline styles" and you see a style attribute, report it.
1775
1700
 
1776
1701
  If no issues or violations found, reply with: []
1777
1702
  Output ONLY the JSON array, no markdown fences, no commentary.`,
@@ -1804,16 +1729,17 @@ ${filesBlock}`,
1804
1729
  const severity = issue.severity === "critical" ? "critical" : issue.severity === "major" ? "major" : "minor";
1805
1730
  if (issue.isGoalViolation && issue.goalIndex != null && issue.goalIndex >= 0 && issue.goalIndex < activeGoals.length) {
1806
1731
  const goal = activeGoals[issue.goalIndex];
1807
- const nudgeMsg = `Goal "${goal.description}" violated in ${issue.file}: ${issue.description}`;
1732
+ const confidence = Math.min(100, Math.max(0, issue.confidence ?? 80));
1733
+ const fixId = `fix-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
1808
1734
  const ledgerIssue = {
1809
- id: `goal-ai-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
1735
+ id: fixId,
1810
1736
  hash: "",
1811
1737
  file: issue.file,
1812
1738
  line: void 0,
1813
1739
  agent: "ai-watcher",
1814
1740
  severity: severity === "critical" ? "critical" : severity === "major" ? "high" : "medium",
1815
- issue: nudgeMsg,
1816
- fix: "Review and fix",
1741
+ issue: `Goal "${goal.description}" violated: ${issue.description}`,
1742
+ fix: issue.suggestedFix || "Review and fix",
1817
1743
  category: "goal-violation",
1818
1744
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1819
1745
  project: basename2(projectPath),
@@ -1822,6 +1748,8 @@ ${filesBlock}`,
1822
1748
  };
1823
1749
  await appendIssuesToLedger([ledgerIssue], projectPath);
1824
1750
  await recordGoalViolationCaught(goal, issue.file, projectPath);
1751
+ const confidenceStr = `${confidence}%`;
1752
+ const nudgeMsg = `Goal "${goal.description}" violated in ${issue.file}: ${issue.description} [${confidenceStr} confidence]`;
1825
1753
  getOutputManager().nudge(nudgeMsg, "warning", issue.file);
1826
1754
  this.state.nudges.push({
1827
1755
  file: basename2(issue.file),
@@ -1829,8 +1757,20 @@ ${filesBlock}`,
1829
1757
  severity: "high",
1830
1758
  timestamp: (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false })
1831
1759
  });
1760
+ if (this.streamingManager) {
1761
+ this.streamingManager.reportPendingFix({
1762
+ id: fixId,
1763
+ file: issue.file,
1764
+ description: issue.description,
1765
+ goalDescription: goal.description,
1766
+ confidence,
1767
+ severity: issue.severity,
1768
+ suggestedFix: issue.suggestedFix || "Remove the violating code"
1769
+ });
1770
+ }
1832
1771
  if (!isInteractiveMode()) {
1833
- console.error(` [!] Goal violation: ${nudgeMsg}`);
1772
+ console.error(` [!] Goal violation (${confidenceStr}): ${issue.description}`);
1773
+ console.error(` Fix: ${issue.suggestedFix || "Review and fix manually"}`);
1834
1774
  }
1835
1775
  continue;
1836
1776
  }
@@ -1886,6 +1826,153 @@ ${filesBlock}`,
1886
1826
  this.state.autoScanInProgress = false;
1887
1827
  }
1888
1828
  }
1829
+ /**
1830
+ * Initial goal compliance scan when watch starts.
1831
+ *
1832
+ * This checks recently modified files against active goals so the user
1833
+ * gets immediate feedback about goal violations without waiting for files
1834
+ * to be changed.
1835
+ *
1836
+ * Strategy:
1837
+ * 1. Check if there are any active goals - if not, skip
1838
+ * 2. Find recently modified files (last 24 hours OR uncommitted changes)
1839
+ * 3. Filter to watched file types
1840
+ * 4. Run a quick AI scan focused only on goal violations
1841
+ * 5. Nudge the user about any violations found
1842
+ */
1843
+ async initialGoalComplianceScan() {
1844
+ if (!isAIAvailable()) return;
1845
+ const projectPath = this.watchedDirectory || getWorkingDirectory(void 0, true);
1846
+ try {
1847
+ const { getActiveGoals, recordGoalViolationCaught } = await import("./goal-validator-YSNN23D4.js");
1848
+ const activeGoals = await getActiveGoals(projectPath);
1849
+ if (activeGoals.length === 0) return;
1850
+ if (!isInteractiveMode()) {
1851
+ console.error("[*] Checking recent files against active goals...");
1852
+ }
1853
+ const recentFiles = /* @__PURE__ */ new Set();
1854
+ const uncommittedFiles = await getGitChangedFiles(projectPath);
1855
+ if (uncommittedFiles) {
1856
+ uncommittedFiles.forEach((f) => recentFiles.add(join2(projectPath, f)));
1857
+ }
1858
+ const oneDayAgo = Date.now() - 24 * 60 * 60 * 1e3;
1859
+ const recentChanges = await getChangedFilesSinceTimestamp(projectPath, oneDayAgo);
1860
+ if (recentChanges) {
1861
+ recentChanges.forEach((f) => recentFiles.add(f));
1862
+ }
1863
+ const filesToCheck = Array.from(recentFiles).filter((file) => {
1864
+ const ext = extname3(file).toLowerCase();
1865
+ return WATCH_EXTENSIONS.has(ext) && existsSync3(file);
1866
+ });
1867
+ if (filesToCheck.length === 0) return;
1868
+ const maxInitialFiles = 10;
1869
+ const filesToScan = filesToCheck.slice(0, maxInitialFiles);
1870
+ if (!isInteractiveMode()) {
1871
+ console.error(` Scanning ${filesToScan.length} recent file(s) against ${activeGoals.length} goal(s)...`);
1872
+ }
1873
+ const maxCharsPerFile = 3e3;
1874
+ const fileContents = await Promise.all(
1875
+ filesToScan.map(async (file) => {
1876
+ try {
1877
+ const content = await readFile3(file, "utf-8");
1878
+ const relativePath = file.replace(projectPath + "/", "");
1879
+ return { path: relativePath, content: content.slice(0, maxCharsPerFile) };
1880
+ } catch {
1881
+ return null;
1882
+ }
1883
+ })
1884
+ );
1885
+ const valid = fileContents.filter(Boolean);
1886
+ if (valid.length === 0) return;
1887
+ const filesBlock = valid.map(
1888
+ (f) => `### ${f.path}
1889
+ \`\`\`
1890
+ ${f.content}
1891
+ \`\`\``
1892
+ ).join("\n\n");
1893
+ const goalsSection = `
1894
+ USER-DEFINED GOALS (check EVERY file against ALL goals):
1895
+ ${activeGoals.map((g, i) => ` ${i + 1}. "${g.description}"`).join("\n")}
1896
+
1897
+ This is an INITIAL SCAN at watch startup. Report ALL goal violations you find.
1898
+ `;
1899
+ const result = await runAIAnalysis({
1900
+ systemPrompt: `You are checking code for GOAL VIOLATIONS ONLY.
1901
+ ${goalsSection}
1902
+ Reply ONLY with a JSON array. Each element must have:
1903
+ - "file": relative file path
1904
+ - "severity": "critical" | "major" | "minor"
1905
+ - "description": 1-sentence description of the goal violation
1906
+ - "confidence": number 0-100, how confident you are this is a violation
1907
+ - "suggestedFix": 1-sentence description of what should change
1908
+ - "isGoalViolation": true (always true for this scan)
1909
+ - "goalIndex": 0-based index of the violated goal
1910
+
1911
+ Be thorough. If a goal says "no emojis" and you see ANY emoji in the file, report it. If a goal says "no console.log" and you see console.log, report it.
1912
+
1913
+ If no violations found, reply with: []
1914
+ Output ONLY the JSON array, no markdown fences, no commentary.`,
1915
+ userPrompt: `Check these files for goal violations:
1916
+
1917
+ ${filesBlock}`,
1918
+ maxTokens: 2048,
1919
+ temperature: 0.1
1920
+ });
1921
+ if (result.tokensUsed) {
1922
+ this.recordTokenUsage(result.tokensUsed.input + result.tokensUsed.output);
1923
+ }
1924
+ if (!result.success || !result.content.trim()) return;
1925
+ let issues = [];
1926
+ try {
1927
+ const parsed = JSON.parse(result.content.trim());
1928
+ issues = Array.isArray(parsed) ? parsed : [];
1929
+ } catch {
1930
+ return;
1931
+ }
1932
+ const { appendIssuesToLedger } = await import("./ledger-JMPGJGLB.js");
1933
+ const issuesForLedger = [];
1934
+ let violationsFound = 0;
1935
+ for (const issue of issues) {
1936
+ if (!issue.isGoalViolation || issue.confidence < 40) continue;
1937
+ violationsFound++;
1938
+ issuesForLedger.push({
1939
+ file: issue.file,
1940
+ message: issue.description,
1941
+ severity: issue.severity,
1942
+ confidence: issue.confidence,
1943
+ category: "goal-violation",
1944
+ suggestedFix: issue.suggestedFix
1945
+ });
1946
+ if (issue.goalIndex != null && issue.goalIndex >= 0 && issue.goalIndex < activeGoals.length) {
1947
+ const goal = activeGoals[issue.goalIndex];
1948
+ await recordGoalViolationCaught(goal, issue.file, projectPath);
1949
+ const confidenceStr = issue.confidence >= 80 ? "high" : issue.confidence >= 60 ? "medium" : "low";
1950
+ const nudgeMsg = `Goal "${goal.description}" violated in ${issue.file}: ${issue.description} [${confidenceStr} confidence]`;
1951
+ getOutputManager().nudge(nudgeMsg, "warning", issue.file);
1952
+ this.state.nudges.push({
1953
+ file: basename2(issue.file),
1954
+ message: nudgeMsg,
1955
+ severity: "high",
1956
+ timestamp: (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false })
1957
+ });
1958
+ }
1959
+ }
1960
+ if (issuesForLedger.length > 0) {
1961
+ await appendIssuesToLedger(issuesForLedger, projectPath);
1962
+ }
1963
+ if (!isInteractiveMode()) {
1964
+ if (violationsFound > 0) {
1965
+ console.error(` [!] Found ${violationsFound} goal violation(s) in recent files`);
1966
+ } else {
1967
+ console.error(` [\u2713] No goal violations found in recent files`);
1968
+ }
1969
+ }
1970
+ } catch (error) {
1971
+ if (!isInteractiveMode()) {
1972
+ console.error(` [!] Initial goal scan error: ${error}`);
1973
+ }
1974
+ }
1975
+ }
1889
1976
  stopWatching() {
1890
1977
  if (!this.state.isRunning) {
1891
1978
  return {
@@ -1958,8 +2045,8 @@ Use \`trie_watch start\` to begin autonomous scanning.`
1958
2045
  ).join("\n");
1959
2046
  let agencyStatus = "";
1960
2047
  try {
1961
- const { getGuardian } = await import("./guardian-agent-EXP7APLC.js");
1962
- const trieAgent = getGuardian(getWorkingDirectory(void 0, true));
2048
+ const { getGuardian } = await import("./guardian-agent-UY2G56FT.js");
2049
+ const trieAgent = getGuardian(this.watchedDirectory || getWorkingDirectory(void 0, true));
1963
2050
  await trieAgent.initialize();
1964
2051
  const status = await trieAgent.getAgencyStatus();
1965
2052
  agencyStatus = `