@triedotdev/mcp 1.0.117 → 1.0.119

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getGuardian
3
- } from "./chunk-OMCEUJ5I.js";
3
+ } from "./chunk-5TQ7J7UI.js";
4
4
  import {
5
5
  LearningEngine,
6
6
  exportToJson,
@@ -526,12 +526,25 @@ function dashboardReducer(state, action) {
526
526
  (ni) => !existing.some((ei) => ei.message === ni.message && !ei.dismissed)
527
527
  );
528
528
  const merged = [...newOnes, ...existing].slice(0, 50);
529
+ console.error("[State] ADD_INSIGHTS:", {
530
+ newCount: newOnes.length,
531
+ existingCount: existing.length,
532
+ mergedCount: merged.length,
533
+ newInsights: newOnes.map((i) => ({ id: i.id, type: i.type, message: i.message.slice(0, 50) }))
534
+ });
529
535
  let s = { ...state, agentInsights: merged };
536
+ const newAlerts = newOnes.filter((i) => i.type === "warning" && !i.dismissed).length;
537
+ if (newAlerts > 0) {
538
+ s.unreadNudgesCount = state.unreadNudgesCount + newAlerts;
539
+ }
530
540
  if (newOnes.length > 0) {
531
541
  s = addActivity(s, `Trie Agent: ${newOnes.length} new insight${newOnes.length > 1 ? "s" : ""}`);
532
542
  }
533
543
  return s;
534
544
  }
545
+ case "MARK_NUDGES_READ": {
546
+ return { ...state, unreadNudgesCount: 0 };
547
+ }
535
548
  case "SET_AGENT_INITIALIZED":
536
549
  return { ...state, agentInitialized: action.initialized };
537
550
  case "SET_AGENCY_STATUS":
@@ -784,6 +797,7 @@ function createInitialState() {
784
797
  agencyStatus: null,
785
798
  selectedInsight: 0,
786
799
  expandedInsight: null,
800
+ unreadNudgesCount: 0,
787
801
  agentConfig: {
788
802
  agentSmith: {
789
803
  aiEnhancement: true,
@@ -887,16 +901,16 @@ var VIEW_SHORT = {
887
901
  };
888
902
  var TAB_VIEWS = ["overview", "memory", "goals", "hypotheses", "agent", "chat"];
889
903
  var CONTEXT_HINTS = {
890
- goals: "j/k nav \xB7 a add \xB7 enter complete \xB7 d delete",
891
- hypotheses: "j/k nav \xB7 a add \xB7 v validate \xB7 x invalidate",
904
+ goals: "j/k nav \xB7 a add \xB7 s scan \xB7 enter complete \xB7 d delete \xB7 c clear achieved",
905
+ hypotheses: "j/k nav \xB7 a add \xB7 t test \xB7 v validate \xB7 x invalidate",
892
906
  agent: "j/k nav \xB7 enter expand \xB7 d dismiss",
893
907
  memory: "j/k nav \xB7 enter expand",
894
908
  chat: "type to ask \xB7 enter send \xB7 esc clear",
895
909
  rawlog: "n/p pages \xB7 b back"
896
910
  };
897
911
  var CONTEXT_HINTS_SHORT = {
898
- goals: "j/k a d",
899
- hypotheses: "j/k a v x",
912
+ goals: "j/k a s d c",
913
+ hypotheses: "j/k a t v x",
900
914
  agent: "j/k enter d",
901
915
  memory: "j/k enter",
902
916
  chat: "enter esc",
@@ -904,12 +918,13 @@ var CONTEXT_HINTS_SHORT = {
904
918
  };
905
919
  function Footer() {
906
920
  const { state } = useDashboard();
907
- const { view, goalsPanel, hypothesesPanel } = state;
921
+ const { view, goalsPanel, hypothesesPanel, unreadNudgesCount } = state;
908
922
  const { stdout } = useStdout2();
909
923
  const cols = stdout?.columns || 80;
910
924
  const narrow = cols < 60;
911
925
  const veryNarrow = cols < 40;
912
926
  const labels = narrow ? VIEW_SHORT : VIEW_LABELS;
927
+ const hasUnreadNudges = unreadNudgesCount > 0;
913
928
  let hints;
914
929
  if (view === "goals" && goalsPanel.inputMode === "add") {
915
930
  hints = narrow ? "enter esc" : "enter save \xB7 esc cancel";
@@ -921,7 +936,22 @@ function Footer() {
921
936
  }
922
937
  if (veryNarrow) {
923
938
  return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", paddingX: 1, children: [
924
- /* @__PURE__ */ jsx3(Box2, { gap: 1, children: TAB_VIEWS.map((v) => v === view ? /* @__PURE__ */ jsx3(Text2, { color: "green", bold: true, children: labels[v] }, v) : /* @__PURE__ */ jsx3(Text2, { dimColor: true, children: labels[v] }, v)) }),
939
+ /* @__PURE__ */ jsx3(Box2, { gap: 1, children: TAB_VIEWS.map((v) => {
940
+ const isAgent = v === "agent";
941
+ const isCurrent = v === view;
942
+ if (isCurrent) {
943
+ return /* @__PURE__ */ jsx3(Text2, { color: "green", bold: true, children: labels[v] }, v);
944
+ } else if (isAgent && hasUnreadNudges) {
945
+ return /* @__PURE__ */ jsxs2(Text2, { color: "yellow", bold: true, children: [
946
+ labels[v],
947
+ " (",
948
+ unreadNudgesCount,
949
+ ")"
950
+ ] }, v);
951
+ } else {
952
+ return /* @__PURE__ */ jsx3(Text2, { dimColor: true, children: labels[v] }, v);
953
+ }
954
+ }) }),
925
955
  /* @__PURE__ */ jsxs2(Text2, { dimColor: true, children: [
926
956
  hints,
927
957
  " \xB7 q quit"
@@ -929,7 +959,22 @@ function Footer() {
929
959
  ] });
930
960
  }
931
961
  return /* @__PURE__ */ jsxs2(Box2, { paddingX: 1, justifyContent: "space-between", children: [
932
- /* @__PURE__ */ jsx3(Box2, { gap: 1, children: TAB_VIEWS.map((v) => v === view ? /* @__PURE__ */ jsx3(Text2, { color: "green", bold: true, children: labels[v] }, v) : /* @__PURE__ */ jsx3(Text2, { dimColor: true, children: labels[v] }, v)) }),
962
+ /* @__PURE__ */ jsx3(Box2, { gap: 1, children: TAB_VIEWS.map((v) => {
963
+ const isAgent = v === "agent";
964
+ const isCurrent = v === view;
965
+ if (isCurrent) {
966
+ return /* @__PURE__ */ jsx3(Text2, { color: "green", bold: true, children: labels[v] }, v);
967
+ } else if (isAgent && hasUnreadNudges) {
968
+ return /* @__PURE__ */ jsxs2(Text2, { color: "yellow", bold: true, children: [
969
+ labels[v],
970
+ " (",
971
+ unreadNudgesCount,
972
+ ")"
973
+ ] }, v);
974
+ } else {
975
+ return /* @__PURE__ */ jsx3(Text2, { dimColor: true, children: labels[v] }, v);
976
+ }
977
+ }) }),
933
978
  /* @__PURE__ */ jsxs2(Text2, { dimColor: true, children: [
934
979
  hints,
935
980
  " \xB7 q quit"
@@ -1387,6 +1432,17 @@ function AgentView() {
1387
1432
  const visibleInsights = getVisibleInsights(state);
1388
1433
  const alerts = visibleInsights.filter((i) => i.type === "warning");
1389
1434
  const { decisions, patterns, loaded } = agentBrain;
1435
+ useEffect(() => {
1436
+ if (agentInsights.length > 0 || visibleInsights.length > 0) {
1437
+ console.error("[AgentView Debug]", {
1438
+ totalInsights: agentInsights.length,
1439
+ visibleInsights: visibleInsights.length,
1440
+ alerts: alerts.length,
1441
+ insightTypes: agentInsights.map((i) => i.type),
1442
+ visibleTypes: visibleInsights.map((i) => i.type)
1443
+ });
1444
+ }
1445
+ }, [agentInsights, visibleInsights, alerts]);
1390
1446
  const loadBrain = useCallback(async () => {
1391
1447
  try {
1392
1448
  const workDir = getWorkingDirectory(void 0, true);
@@ -1407,6 +1463,11 @@ function AgentView() {
1407
1463
  void loadBrain();
1408
1464
  }
1409
1465
  }, [loaded, loadBrain]);
1466
+ useEffect(() => {
1467
+ if (state.unreadNudgesCount > 0) {
1468
+ dispatch({ type: "MARK_NUDGES_READ" });
1469
+ }
1470
+ }, [dispatch, state.unreadNudgesCount]);
1410
1471
  useInput3((input, key) => {
1411
1472
  if (key.upArrow || input === "k") dispatch({ type: "NAVIGATE_UP" });
1412
1473
  else if (key.downArrow || input === "j") dispatch({ type: "NAVIGATE_DOWN" });
@@ -1627,6 +1688,55 @@ function GoalsView() {
1627
1688
  } catch {
1628
1689
  }
1629
1690
  }, [dispatch, refreshGoals]);
1691
+ const clearAchievedGoals = useCallback2(async () => {
1692
+ try {
1693
+ const workDir = getWorkingDirectory(void 0, true);
1694
+ const agentState = getGuardianState(workDir);
1695
+ await agentState.load();
1696
+ const achieved = goalsPanel.goals.filter((g) => g.status === "achieved");
1697
+ if (achieved.length === 0) {
1698
+ dispatch({ type: "ADD_ACTIVITY", message: "No achieved goals to clear" });
1699
+ return;
1700
+ }
1701
+ for (const goal of achieved) {
1702
+ await agentState.deleteGoal(goal.id);
1703
+ }
1704
+ dispatch({ type: "ADD_ACTIVITY", message: `Cleared ${achieved.length} achieved goal${achieved.length > 1 ? "s" : ""}` });
1705
+ await refreshGoals();
1706
+ } catch {
1707
+ }
1708
+ }, [dispatch, refreshGoals, goalsPanel.goals]);
1709
+ const checkGoalNow = useCallback2(async (goalId) => {
1710
+ try {
1711
+ const workDir = getWorkingDirectory(void 0, true);
1712
+ const goal = goalsPanel.goals.find((g) => g.id === goalId);
1713
+ if (!goal) return;
1714
+ dispatch({ type: "ADD_ACTIVITY", message: `Checking goal: ${goal.description.slice(0, 30)}...` });
1715
+ dispatch({ type: "SHOW_NOTIFICATION", message: `Scanning files for goal violations...`, severity: "info", autoHideMs: 3e3 });
1716
+ const { checkFilesForGoalViolations } = await import("./goal-validator-P67RNO2U.js");
1717
+ const violations = await checkFilesForGoalViolations([goal], workDir);
1718
+ if (violations.length === 0) {
1719
+ dispatch({ type: "SHOW_NOTIFICATION", message: `\u2713 No violations found for: ${goal.description.slice(0, 40)}`, severity: "info", autoHideMs: 5e3 });
1720
+ dispatch({ type: "ADD_ACTIVITY", message: `No violations found` });
1721
+ } else {
1722
+ dispatch({ type: "SHOW_NOTIFICATION", message: `Found ${violations.length} violation(s) for: ${goal.description.slice(0, 30)}`, severity: "warning", autoHideMs: 5e3 });
1723
+ dispatch({ type: "ADD_ACTIVITY", message: `Found ${violations.length} violation(s)` });
1724
+ for (const violation of violations) {
1725
+ dispatch({ type: "ADD_INSIGHTS", insights: [{
1726
+ message: violation.message,
1727
+ severity: violation.severity,
1728
+ timestamp: Date.now(),
1729
+ category: "goal",
1730
+ dismissed: false,
1731
+ priority: "high",
1732
+ file: violation.file
1733
+ }] });
1734
+ }
1735
+ }
1736
+ } catch (error) {
1737
+ dispatch({ type: "ADD_ACTIVITY", message: `Check failed: ${error instanceof Error ? error.message : "unknown"}` });
1738
+ }
1739
+ }, [dispatch, goalsPanel.goals]);
1630
1740
  useInput4((_input, key) => {
1631
1741
  if (goalsPanel.inputMode === "add") {
1632
1742
  if (key.escape) {
@@ -1644,12 +1754,17 @@ function GoalsView() {
1644
1754
  if (_input === "a") dispatch({ type: "SET_GOALS_INPUT_MODE", mode: "add" });
1645
1755
  else if (key.upArrow || _input === "k") dispatch({ type: "SELECT_GOAL", index: Math.max(0, goalsPanel.selectedIndex - 1) });
1646
1756
  else if (key.downArrow || _input === "j") dispatch({ type: "SELECT_GOAL", index: Math.min(activeGoals.length - 1, goalsPanel.selectedIndex + 1) });
1647
- else if (key.return) {
1757
+ else if (_input === "s") {
1758
+ const selected = activeGoals[goalsPanel.selectedIndex];
1759
+ if (selected) void checkGoalNow(selected.id);
1760
+ } else if (key.return) {
1648
1761
  const selected = activeGoals[goalsPanel.selectedIndex];
1649
1762
  if (selected) void completeGoal(selected.id);
1650
1763
  } else if (_input === "d") {
1651
1764
  const selected = activeGoals[goalsPanel.selectedIndex];
1652
1765
  if (selected) void deleteGoal(selected.id);
1766
+ } else if (_input === "c") {
1767
+ void clearAchievedGoals();
1653
1768
  } else if (_input === "x") {
1654
1769
  const completed = goalsPanel.goals.filter((g) => g.status === "achieved" || g.status === "failed");
1655
1770
  if (completed[0]) void deleteGoal(completed[0].id);
@@ -1788,6 +1903,29 @@ function HypothesesView() {
1788
1903
  } catch {
1789
1904
  }
1790
1905
  }, [dispatch, refreshHypotheses]);
1906
+ const checkHypothesisNow = useCallback3(async (hypoId) => {
1907
+ try {
1908
+ const workDir = getWorkingDirectory(void 0, true);
1909
+ const hypo = hypothesesPanel.hypotheses.find((h) => h.id === hypoId);
1910
+ if (!hypo) return;
1911
+ dispatch({ type: "ADD_ACTIVITY", message: `Testing hypothesis: ${hypo.statement.slice(0, 30)}...` });
1912
+ dispatch({ type: "SHOW_NOTIFICATION", message: `Gathering evidence for hypothesis...`, severity: "info", autoHideMs: 3e3 });
1913
+ const { gatherEvidenceForHypothesis } = await import("./hypothesis-PEVD2IJR.js");
1914
+ const evidence = await gatherEvidenceForHypothesis(hypoId, workDir);
1915
+ if (evidence.length === 0) {
1916
+ dispatch({ type: "SHOW_NOTIFICATION", message: `No evidence found for: ${hypo.statement.slice(0, 40)}`, severity: "info", autoHideMs: 5e3 });
1917
+ dispatch({ type: "ADD_ACTIVITY", message: `No evidence found` });
1918
+ } else {
1919
+ const supporting = evidence.filter((e) => e.supports).length;
1920
+ const against = evidence.length - supporting;
1921
+ dispatch({ type: "SHOW_NOTIFICATION", message: `Found ${evidence.length} evidence (${supporting} for, ${against} against)`, severity: "info", autoHideMs: 5e3 });
1922
+ dispatch({ type: "ADD_ACTIVITY", message: `Found ${evidence.length} evidence items` });
1923
+ await refreshHypotheses();
1924
+ }
1925
+ } catch (error) {
1926
+ dispatch({ type: "ADD_ACTIVITY", message: `Check failed: ${error instanceof Error ? error.message : "unknown"}` });
1927
+ }
1928
+ }, [dispatch, hypothesesPanel.hypotheses, refreshHypotheses]);
1791
1929
  useInput5((_input, key) => {
1792
1930
  if (hypothesesPanel.inputMode === "add") {
1793
1931
  if (key.escape) {
@@ -1805,7 +1943,10 @@ function HypothesesView() {
1805
1943
  if (_input === "a") dispatch({ type: "SET_HYPOTHESES_INPUT_MODE", mode: "add" });
1806
1944
  else if (key.upArrow || _input === "k") dispatch({ type: "SELECT_HYPOTHESIS", index: Math.max(0, hypothesesPanel.selectedIndex - 1) });
1807
1945
  else if (key.downArrow || _input === "j") dispatch({ type: "SELECT_HYPOTHESIS", index: Math.min(testing.length - 1, hypothesesPanel.selectedIndex + 1) });
1808
- else if (_input === "v") {
1946
+ else if (_input === "t") {
1947
+ const selected = testing[hypothesesPanel.selectedIndex];
1948
+ if (selected) void checkHypothesisNow(selected.id);
1949
+ } else if (_input === "v") {
1809
1950
  const selected = testing[hypothesesPanel.selectedIndex];
1810
1951
  if (selected) void updateHypothesis(selected.id, "validate");
1811
1952
  } else if (_input === "x") {
@@ -4482,98 +4623,6 @@ ${checkpoint.files.length > 0 ? `**Files:** ${checkpoint.files.join(", ")}` : ""
4482
4623
 
4483
4624
  // src/cli/dashboard/chat-tools.ts
4484
4625
  import { createHash } from "crypto";
4485
-
4486
- // src/utils/terminal-spawn.ts
4487
- import { exec } from "child_process";
4488
- import { promisify } from "util";
4489
- import { platform } from "os";
4490
- var execAsync = promisify(exec);
4491
- async function spawnTerminal(options) {
4492
- const { command, cwd, title, keepOpen = true } = options;
4493
- const os = platform();
4494
- if (os === "darwin") {
4495
- await spawnMacOSTerminal(command, cwd, title, keepOpen);
4496
- } else if (os === "linux") {
4497
- await spawnLinuxTerminal(command, cwd, title, keepOpen);
4498
- } else {
4499
- throw new Error(`Terminal spawning not supported on ${os}`);
4500
- }
4501
- }
4502
- async function spawnMacOSTerminal(command, cwd, title, keepOpen) {
4503
- const escapedCommand = command.replace(/'/g, `'"'"'`);
4504
- const escapedCwd = cwd?.replace(/'/g, `'"'"'`) || process.cwd();
4505
- const escapedTitle = title?.replace(/'/g, `'"'"'`) || "Trie Agent";
4506
- const fullCommand = cwd ? `cd '${escapedCwd}' && ${command}` : command;
4507
- const escapedFullCommand = fullCommand.replace(/'/g, `'"'"'`);
4508
- const script = `
4509
- tell application "Terminal"
4510
- activate
4511
- set newTab to do script "${escapedFullCommand}"
4512
- set custom title of newTab to "${escapedTitle}"
4513
- end tell
4514
- `.trim();
4515
- try {
4516
- await execAsync(`osascript -e '${script.replace(/'/g, `'"'"'`)}'`);
4517
- } catch (error) {
4518
- console.error("Terminal.app spawn failed, trying fallback...");
4519
- const shellCmd = keepOpen ? `${fullCommand}; exec bash` : fullCommand;
4520
- await execAsync(`open -a Terminal "${escapedCwd}" --args -e "${shellCmd}"`);
4521
- }
4522
- }
4523
- async function spawnLinuxTerminal(command, cwd, title, keepOpen) {
4524
- const workDir = cwd || process.cwd();
4525
- const termTitle = title || "Trie Agent";
4526
- const shellCmd = keepOpen ? `${command}; exec bash` : command;
4527
- const terminals = [
4528
- // GNOME Terminal
4529
- {
4530
- command: "gnome-terminal",
4531
- args: `--working-directory="${workDir}" --title="${termTitle}" -- bash -c "${shellCmd}"`
4532
- },
4533
- // Konsole (KDE)
4534
- {
4535
- command: "konsole",
4536
- args: `--workdir "${workDir}" --title "${termTitle}" -e bash -c "${shellCmd}"`
4537
- },
4538
- // xterm (fallback)
4539
- {
4540
- command: "xterm",
4541
- args: `-T "${termTitle}" -e "cd '${workDir}' && ${shellCmd}"`
4542
- }
4543
- ];
4544
- for (const term of terminals) {
4545
- try {
4546
- await execAsync(`which ${term.command}`);
4547
- await execAsync(`${term.command} ${term.args} &`);
4548
- return;
4549
- } catch {
4550
- continue;
4551
- }
4552
- }
4553
- throw new Error("No supported terminal emulator found (tried: gnome-terminal, konsole, xterm)");
4554
- }
4555
- async function spawnClaudeCodeFix(options) {
4556
- const { file, goal, violation, suggestedFix, cwd } = options;
4557
- const prompt = `Fix this goal violation:
4558
-
4559
- Goal: ${goal}
4560
- File: ${file}
4561
- Violation: ${violation}
4562
- ${suggestedFix ? `Suggested fix: ${suggestedFix}` : ""}
4563
-
4564
- Please review the file and fix the violation while preserving functionality.`;
4565
- const escapedPrompt = prompt.replace(/"/g, '\\"').replace(/\n/g, "\\n");
4566
- const escapedFile = file.replace(/"/g, '\\"');
4567
- const command = `echo "${escapedPrompt}" | claude --file="${escapedFile}"`;
4568
- await spawnTerminal({
4569
- command,
4570
- cwd,
4571
- title: `Fixing: ${file}`,
4572
- keepOpen: true
4573
- });
4574
- }
4575
-
4576
- // src/cli/dashboard/chat-tools.ts
4577
4626
  function textFromResult(result) {
4578
4627
  return result.content.map((c) => c.text).join("\n");
4579
4628
  }
@@ -4725,8 +4774,8 @@ var CHAT_TOOLS = [
4725
4774
  }
4726
4775
  },
4727
4776
  {
4728
- name: "trie_fix_goal_violation",
4729
- description: "Spawn Claude Code in a new terminal to fix a goal violation. Use when the user wants to auto-fix a goal violation detected by the watcher.",
4777
+ name: "trie_propose_fix",
4778
+ description: "Propose a fix for a goal violation. This will ask the user for confirmation before spawning Claude Code. Use when the user wants to fix a goal violation.",
4730
4779
  input_schema: {
4731
4780
  type: "object",
4732
4781
  properties: {
@@ -4737,6 +4786,28 @@ var CHAT_TOOLS = [
4737
4786
  },
4738
4787
  required: ["file", "goal", "violation"]
4739
4788
  }
4789
+ },
4790
+ {
4791
+ name: "trie_search_files",
4792
+ description: "Search source code files for text patterns, emojis, or code patterns. Use when the user asks about code content that might not be in recent nudges.",
4793
+ input_schema: {
4794
+ type: "object",
4795
+ properties: {
4796
+ pattern: {
4797
+ type: "string",
4798
+ description: 'Text or regex pattern to search for. For emojis, use patterns like "[\u{1F300}-\u{1F9FF}]" or specific emoji characters.'
4799
+ },
4800
+ filePattern: {
4801
+ type: "string",
4802
+ description: 'Glob pattern for files to search (e.g., "*.tsx", "*.ts", "src/**/*.js"). Omit to search all files.'
4803
+ },
4804
+ contextLines: {
4805
+ type: "number",
4806
+ description: "Number of context lines to show around matches (default 2)"
4807
+ }
4808
+ },
4809
+ required: ["pattern"]
4810
+ }
4740
4811
  }
4741
4812
  ];
4742
4813
  async function executeTool(name, input) {
@@ -4886,7 +4957,7 @@ async function executeTool(name, input) {
4886
4957
  });
4887
4958
  return `Decision recorded [${hash}]: "${dec}"`;
4888
4959
  }
4889
- case "trie_fix_goal_violation": {
4960
+ case "trie_propose_fix": {
4890
4961
  const file = String(input.file || "").trim();
4891
4962
  const goal = String(input.goal || "").trim();
4892
4963
  const violation = String(input.violation || "").trim();
@@ -4894,25 +4965,84 @@ async function executeTool(name, input) {
4894
4965
  if (!file) return "File path is required.";
4895
4966
  if (!goal) return "Goal description is required.";
4896
4967
  if (!violation) return "Violation description is required.";
4968
+ const fixProposal = {
4969
+ file,
4970
+ goal,
4971
+ violation,
4972
+ suggestedFix,
4973
+ directory
4974
+ };
4975
+ return `I found a violation to fix:
4976
+
4977
+ \u{1F4C1} File: ${file}
4978
+ \u{1F3AF} Goal: ${goal}
4979
+ \u26A0\uFE0F Violation: ${violation}
4980
+ ${suggestedFix ? `\u{1F4A1} Suggested fix: ${suggestedFix}
4981
+ ` : ""}
4982
+ Would you like me to spawn Claude Code to fix this?
4983
+
4984
+ Type "yes" to proceed, or "no" to cancel.
4985
+
4986
+ [PENDING_FIX:${JSON.stringify(fixProposal)}]`;
4987
+ }
4988
+ case "trie_search_files": {
4989
+ const pattern = String(input.pattern || "").trim();
4990
+ const filePattern = input.filePattern ? String(input.filePattern).trim() : void 0;
4991
+ const contextLines = typeof input.contextLines === "number" ? input.contextLines : 2;
4992
+ if (!pattern) return "Search pattern is required.";
4993
+ const { execSync } = await import("child_process");
4897
4994
  try {
4898
- await spawnClaudeCodeFix({
4899
- file,
4900
- goal,
4901
- violation,
4902
- suggestedFix,
4903
- cwd: directory
4995
+ const rgArgs = [
4996
+ "rg",
4997
+ "--context",
4998
+ String(contextLines),
4999
+ "--heading",
5000
+ "--line-number",
5001
+ "--color=never",
5002
+ "--max-count",
5003
+ "50"
5004
+ // Limit matches per file
5005
+ ];
5006
+ if (filePattern) {
5007
+ rgArgs.push("--glob", filePattern);
5008
+ }
5009
+ rgArgs.push(
5010
+ "--glob",
5011
+ "!node_modules/**",
5012
+ "--glob",
5013
+ "!.git/**",
5014
+ "--glob",
5015
+ "!dist/**",
5016
+ "--glob",
5017
+ "!build/**",
5018
+ "--glob",
5019
+ "!coverage/**"
5020
+ );
5021
+ rgArgs.push(pattern, directory);
5022
+ const result = execSync(rgArgs.join(" "), {
5023
+ encoding: "utf-8",
5024
+ maxBuffer: 10 * 1024 * 1024
5025
+ // 10MB
4904
5026
  });
4905
- return `\u2713 Spawned Claude Code in a new terminal to fix "${file}".
5027
+ if (!result.trim()) {
5028
+ return `No matches found for pattern: ${pattern}`;
5029
+ }
5030
+ const maxLength = 5e3;
5031
+ const truncated = result.length > maxLength ? result.slice(0, maxLength) + `
4906
5032
 
4907
- Claude Code will:
4908
- 1. Review the file
4909
- 2. Understand the goal: "${goal}"
4910
- 3. Fix the violation: "${violation}"
4911
- 4. Preserve all functionality
5033
+ ... (truncated, ${result.length - maxLength} more characters)` : result;
5034
+ const matchCount = (result.match(/^\d+:/gm) || []).length;
5035
+ return `Found ${matchCount} match(es) for "${pattern}":
4912
5036
 
4913
- Check the new terminal window to see the fix in progress.`;
5037
+ ${truncated}`;
4914
5038
  } catch (error) {
4915
- return `Failed to spawn Claude Code: ${error instanceof Error ? error.message : "unknown error"}`;
5039
+ if (error.status === 1) {
5040
+ return `No matches found for pattern: ${pattern}`;
5041
+ }
5042
+ if (error.status === 2) {
5043
+ return `Error: ripgrep not found. Please install ripgrep (brew install ripgrep)`;
5044
+ }
5045
+ return `Search failed: ${error.message}`;
4916
5046
  }
4917
5047
  }
4918
5048
  default:
@@ -4922,8 +5052,22 @@ Check the new terminal window to see the fix in progress.`;
4922
5052
 
4923
5053
  // src/cli/dashboard/views/ChatView.tsx
4924
5054
  import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
4925
- async function buildContext(workDir) {
5055
+ async function buildContext(workDir, dashboardState) {
4926
5056
  const parts = [];
5057
+ if (dashboardState?.agentInsights) {
5058
+ const recentNudges = dashboardState.agentInsights.filter((i) => i.type === "warning" && i.category === "quality" && !i.dismissed).slice(0, 5);
5059
+ if (recentNudges.length > 0) {
5060
+ parts.push("Recent goal violations (nudges):\n" + recentNudges.map((n) => {
5061
+ const fileMatch = n.message.match(/in ([^:]+):/);
5062
+ const goalMatch = n.message.match(/Goal "([^"]+)"/);
5063
+ const violationMatch = n.message.match(/: (.+?) \[/);
5064
+ return `- File: ${fileMatch?.[1] || "unknown"}
5065
+ Goal: ${goalMatch?.[1] || "unknown"}
5066
+ Violation: ${violationMatch?.[1] || n.message}
5067
+ Priority: ${n.priority}`;
5068
+ }).join("\n"));
5069
+ }
5070
+ }
4927
5071
  try {
4928
5072
  const guardianState = getGuardianState(workDir);
4929
5073
  await guardianState.load();
@@ -5001,15 +5145,33 @@ function chatHistoryToMessages(history) {
5001
5145
  }));
5002
5146
  }
5003
5147
  var SYSTEM_PROMPT = `You are Trie, a code guardian assistant embedded in a terminal TUI.
5004
- You have tools to take actions on the user's codebase \u2014 use them when the user asks you to check files, record incidents, give feedback, query decisions, or save checkpoints.
5005
-
5006
- When the user mentions a goal violation or asks you to fix something detected by the watcher:
5007
- 1. Extract the file path, goal description, and violation details from context
5008
- 2. Use trie_fix_goal_violation to spawn Claude Code in a new terminal
5009
- 3. Claude Code will automatically fix the violation
5010
5148
 
5011
- Answer concisely. Reference specific files, decisions, and patterns when relevant.
5012
- When you use a tool, briefly summarize what you did and what the result was.`;
5149
+ **What you CAN do:**
5150
+ - Check recent goal violations (nudges) in the provided project context
5151
+ - Search source code files using trie_search_files (uses ripgrep)
5152
+ - Record incidents, decisions, and feedback about the codebase
5153
+ - Query stored decisions, blockers, facts, and questions from the decision ledger
5154
+ - Create and manage goals and hypotheses
5155
+ - Propose fixes for goal violations (requires user confirmation before spawning Claude Code)
5156
+ - Save work checkpoints
5157
+
5158
+ **When user asks about code content:**
5159
+ 1. First check the "Recent goal violations (nudges)" section in project context
5160
+ 2. If not found in nudges, use trie_search_files to search source code directly
5161
+ 3. For emojis specifically, search for common emoji patterns or unicode ranges
5162
+
5163
+ **When user asks to fix violations:**
5164
+ 1. Look in "Recent goal violations (nudges)" section of project context
5165
+ 2. Extract: file path, goal description, and violation details
5166
+ 3. Use trie_propose_fix to propose the fix - this will ASK THE USER for confirmation
5167
+ 4. Do NOT assume the user wants to proceed - always get confirmation first
5168
+
5169
+ Examples:
5170
+ - User: "do we have emojis?" \u2192 Check nudges first. If none, use trie_search_files to search for emoji patterns.
5171
+ - User: "fix the emoji violation" \u2192 Find emoji violation in nudges, call trie_propose_fix (will ask user to confirm)
5172
+ - User: "search for TODO comments" \u2192 Use trie_search_files with pattern "TODO|FIXME"
5173
+
5174
+ Answer concisely. Reference specific files, decisions, and patterns when relevant.`;
5013
5175
  function ChatView() {
5014
5176
  const { state, dispatch } = useDashboard();
5015
5177
  const { chatState } = state;
@@ -5023,7 +5185,51 @@ function ChatView() {
5023
5185
  dispatch({ type: "SET_CHAT_LOADING", loading: true });
5024
5186
  try {
5025
5187
  const workDir = getWorkingDirectory(void 0, true);
5026
- const contextBlock = await buildContext(workDir);
5188
+ const lastMessage = messages[messages.length - 1];
5189
+ if (lastMessage?.role === "assistant" && lastMessage.pendingFix) {
5190
+ const response = question.trim().toLowerCase();
5191
+ if (response === "yes" || response === "y") {
5192
+ const { spawnClaudeCodeFix } = await import("./terminal-spawn-2GU5KLPS.js");
5193
+ try {
5194
+ await spawnClaudeCodeFix(lastMessage.pendingFix);
5195
+ dispatch({
5196
+ type: "ADD_CHAT_MESSAGE",
5197
+ role: "assistant",
5198
+ content: `\u2713 Spawned Claude Code in a new terminal to fix "${lastMessage.pendingFix.file}".
5199
+
5200
+ Claude Code will:
5201
+ 1. Review the file
5202
+ 2. Understand the goal: "${lastMessage.pendingFix.goal}"
5203
+ 3. Fix the violation: "${lastMessage.pendingFix.violation}"
5204
+ 4. Preserve all functionality
5205
+
5206
+ Check the new terminal window to see the fix in progress.`
5207
+ });
5208
+ dispatch({ type: "SET_CHAT_LOADING", loading: false });
5209
+ loadingRef.current = false;
5210
+ return;
5211
+ } catch (error) {
5212
+ dispatch({
5213
+ type: "ADD_CHAT_MESSAGE",
5214
+ role: "assistant",
5215
+ content: `Failed to spawn Claude Code: ${error instanceof Error ? error.message : "unknown error"}`
5216
+ });
5217
+ dispatch({ type: "SET_CHAT_LOADING", loading: false });
5218
+ loadingRef.current = false;
5219
+ return;
5220
+ }
5221
+ } else if (response === "no" || response === "n") {
5222
+ dispatch({
5223
+ type: "ADD_CHAT_MESSAGE",
5224
+ role: "assistant",
5225
+ content: "Fix cancelled. Let me know if you need anything else!"
5226
+ });
5227
+ dispatch({ type: "SET_CHAT_LOADING", loading: false });
5228
+ loadingRef.current = false;
5229
+ return;
5230
+ }
5231
+ }
5232
+ const contextBlock = await buildContext(workDir, state);
5027
5233
  const fullSystem = `${SYSTEM_PROMPT}
5028
5234
 
5029
5235
  Project context:
@@ -5046,6 +5252,15 @@ ${contextBlock}`;
5046
5252
  role: "assistant",
5047
5253
  content: result.content
5048
5254
  };
5255
+ const pendingFixMatch = result.content.match(/\[PENDING_FIX:(.+?)\]/);
5256
+ if (pendingFixMatch) {
5257
+ try {
5258
+ const fixData = JSON.parse(pendingFixMatch[1]);
5259
+ action.pendingFix = fixData;
5260
+ action.content = result.content.replace(/\[PENDING_FIX:.+?\]/, "").trim();
5261
+ } catch {
5262
+ }
5263
+ }
5049
5264
  if (result.toolCalls && result.toolCalls.length > 0) {
5050
5265
  action.toolCalls = result.toolCalls;
5051
5266
  const toolNames = new Set(result.toolCalls.map((tc) => tc.name));
@@ -5095,7 +5310,7 @@ ${contextBlock}`;
5095
5310
  dispatch({ type: "SET_CHAT_LOADING", loading: false });
5096
5311
  loadingRef.current = false;
5097
5312
  }
5098
- }, [dispatch, messages]);
5313
+ }, [dispatch, messages, state]);
5099
5314
  useInput8((input, key) => {
5100
5315
  if (loading) return;
5101
5316
  if (key.return && inputBuffer.trim().length > 0) {
@@ -5114,33 +5329,34 @@ ${contextBlock}`;
5114
5329
  /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " AI is not available. Press s to open settings and add your Anthropic API key." })
5115
5330
  ] });
5116
5331
  }
5117
- return /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", paddingX: 1, children: [
5332
+ return /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", paddingX: 1, flexGrow: 1, children: [
5118
5333
  /* @__PURE__ */ jsx12(Text11, { bold: true, children: "Chat" }),
5119
- messages.length === 0 && !loading && /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " Ask about your codebase, decisions, patterns, or risks." }),
5120
- messages.map((msg, idx) => /* @__PURE__ */ jsx12(Box11, { flexDirection: "column", marginTop: idx === 0 ? 1 : 0, marginBottom: 1, children: msg.role === "user" ? /* @__PURE__ */ jsxs11(Text11, { children: [
5121
- " ",
5122
- /* @__PURE__ */ jsx12(Text11, { bold: true, color: "green", children: "You:" }),
5123
- " ",
5124
- msg.content
5125
- ] }) : /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", children: [
5126
- msg.toolCalls && msg.toolCalls.length > 0 && msg.toolCalls.map((tc, ti) => /* @__PURE__ */ jsxs11(Text11, { dimColor: true, children: [
5334
+ /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", flexGrow: 1, overflow: "hidden", marginTop: 1, children: [
5335
+ messages.length === 0 && !loading && /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " Ask about your codebase, decisions, patterns, or risks." }),
5336
+ messages.map((msg, idx) => /* @__PURE__ */ jsx12(Box11, { flexDirection: "column", marginTop: idx === 0 ? 0 : 1, marginBottom: 1, children: msg.role === "user" ? /* @__PURE__ */ jsxs11(Text11, { children: [
5127
5337
  " ",
5128
- /* @__PURE__ */ jsxs11(Text11, { color: "yellow", children: [
5129
- "[",
5130
- tc.name,
5131
- "]"
5132
- ] }),
5338
+ /* @__PURE__ */ jsx12(Text11, { bold: true, color: "green", children: "You:" }),
5133
5339
  " ",
5134
- formatToolInput(tc.input)
5135
- ] }, ti)),
5136
- msg.content.split("\n").map((line, li) => /* @__PURE__ */ jsxs11(Text11, { children: [
5137
- li === 0 ? " Trie: " : " ",
5138
- line
5139
- ] }, li))
5140
- ] }) }, idx)),
5141
- loading && /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " Thinking..." }),
5142
- /* @__PURE__ */ jsx12(Box11, { flexGrow: 1 }),
5143
- /* @__PURE__ */ jsx12(Box11, { borderStyle: "single", borderColor: "green", paddingX: 1, children: /* @__PURE__ */ jsxs11(Text11, { children: [
5340
+ msg.content
5341
+ ] }) : /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", children: [
5342
+ msg.toolCalls && msg.toolCalls.length > 0 && msg.toolCalls.map((tc, ti) => /* @__PURE__ */ jsxs11(Text11, { dimColor: true, children: [
5343
+ " ",
5344
+ /* @__PURE__ */ jsxs11(Text11, { color: "yellow", children: [
5345
+ "[",
5346
+ tc.name,
5347
+ "]"
5348
+ ] }),
5349
+ " ",
5350
+ formatToolInput(tc.input)
5351
+ ] }, ti)),
5352
+ msg.content.split("\n").map((line, li) => /* @__PURE__ */ jsxs11(Text11, { children: [
5353
+ li === 0 ? " Trie: " : " ",
5354
+ line
5355
+ ] }, li))
5356
+ ] }) }, idx)),
5357
+ loading && /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " Thinking..." })
5358
+ ] }),
5359
+ /* @__PURE__ */ jsx12(Box11, { borderStyle: "single", borderColor: "green", paddingX: 1, flexShrink: 0, children: /* @__PURE__ */ jsxs11(Text11, { children: [
5144
5360
  inputBuffer || /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: "Ask a question..." }),
5145
5361
  /* @__PURE__ */ jsx12(Text11, { bold: true, color: "green", children: "|" })
5146
5362
  ] }) })
@@ -5196,7 +5412,7 @@ ${content}
5196
5412
  fixedContent = fixedContent.replace(/^```\w*\n?/, "").replace(/\n?```$/, "");
5197
5413
  }
5198
5414
  await writeFile(fullPath, fixedContent, "utf-8");
5199
- const { recordGoalViolationFixed, getActiveGoals } = await import("./goal-validator-YSNN23D4.js");
5415
+ const { recordGoalViolationFixed, getActiveGoals } = await import("./goal-validator-P67RNO2U.js");
5200
5416
  const goals = await getActiveGoals(projectPath);
5201
5417
  const matchedGoal = goals.find((g) => g.description === fix.goalDescription);
5202
5418
  if (matchedGoal) {
@@ -5312,6 +5528,7 @@ function DashboardApp({ onReady }) {
5312
5528
  dispatchRef.current({ type: "STREAM_UPDATE", update: { type: "raw_log", data: { time, level, message }, timestamp: Date.now() } });
5313
5529
  },
5314
5530
  onNudge: (nudge) => {
5531
+ console.error("[Dashboard] onNudge called:", { message: nudge.message, severity: nudge.severity, file: nudge.file });
5315
5532
  const action = { type: "SHOW_NOTIFICATION", message: nudge.message, severity: nudge.severity };
5316
5533
  if (nudge.file !== void 0) action.file = nudge.file;
5317
5534
  if (nudge.autoHideMs !== void 0) action.autoHideMs = nudge.autoHideMs;
@@ -5328,6 +5545,7 @@ function DashboardApp({ onReady }) {
5328
5545
  relatedIssues: [],
5329
5546
  dismissed: false
5330
5547
  };
5548
+ console.error("[Dashboard] Adding insight:", { id: insight.id, type: insight.type, category: insight.category, priority: insight.priority });
5331
5549
  dispatchRef.current({ type: "ADD_INSIGHTS", insights: [insight] });
5332
5550
  }
5333
5551
  }
@@ -5515,4 +5733,4 @@ export {
5515
5733
  handleCheckpointTool,
5516
5734
  InteractiveDashboard
5517
5735
  };
5518
- //# sourceMappingURL=chunk-EWVU7QUG.js.map
5736
+ //# sourceMappingURL=chunk-GSYMJLZY.js.map