@triedotdev/mcp 1.0.118 → 1.0.120

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,
@@ -901,16 +901,16 @@ var VIEW_SHORT = {
901
901
  };
902
902
  var TAB_VIEWS = ["overview", "memory", "goals", "hypotheses", "agent", "chat"];
903
903
  var CONTEXT_HINTS = {
904
- goals: "j/k nav \xB7 a add \xB7 enter complete \xB7 d delete \xB7 c clear achieved",
905
- hypotheses: "j/k nav \xB7 a add \xB7 v validate \xB7 x invalidate",
904
+ goals: "j/k nav \xB7 a add \xB7 r run check \xB7 enter complete \xB7 d delete \xB7 x clear achieved",
905
+ hypotheses: "j/k nav \xB7 a add \xB7 r run check \xB7 v validate \xB7 x invalidate",
906
906
  agent: "j/k nav \xB7 enter expand \xB7 d dismiss",
907
907
  memory: "j/k nav \xB7 enter expand",
908
908
  chat: "type to ask \xB7 enter send \xB7 esc clear",
909
909
  rawlog: "n/p pages \xB7 b back"
910
910
  };
911
911
  var CONTEXT_HINTS_SHORT = {
912
- goals: "j/k a d c",
913
- hypotheses: "j/k a v x",
912
+ goals: "j/k a r d x",
913
+ hypotheses: "j/k a r v x",
914
914
  agent: "j/k enter d",
915
915
  memory: "j/k enter",
916
916
  chat: "enter esc",
@@ -1706,6 +1706,42 @@ function GoalsView() {
1706
1706
  } catch {
1707
1707
  }
1708
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 violations...`, severity: "info", autoHideMs: 3e3 });
1716
+ const { checkFilesForGoalViolations } = await import("./goal-validator-RD6QBQJB.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) - check Nudges tab`, 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
+ id: `scan-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
1727
+ message: violation.message,
1728
+ severity: violation.severity,
1729
+ timestamp: Date.now(),
1730
+ category: "goal",
1731
+ type: "warning",
1732
+ dismissed: false,
1733
+ priority: violation.severity === "critical" ? 9 : 6,
1734
+ file: violation.file,
1735
+ relatedIssues: []
1736
+ }] });
1737
+ }
1738
+ }
1739
+ } catch (error) {
1740
+ const errorMsg = error instanceof Error ? error.message : "unknown error";
1741
+ dispatch({ type: "SHOW_NOTIFICATION", message: `Check failed: ${errorMsg}`, severity: "warning", autoHideMs: 5e3 });
1742
+ dispatch({ type: "ADD_ACTIVITY", message: `Check failed: ${errorMsg}` });
1743
+ }
1744
+ }, [dispatch, goalsPanel.goals]);
1709
1745
  useInput4((_input, key) => {
1710
1746
  if (goalsPanel.inputMode === "add") {
1711
1747
  if (key.escape) {
@@ -1723,17 +1759,17 @@ function GoalsView() {
1723
1759
  if (_input === "a") dispatch({ type: "SET_GOALS_INPUT_MODE", mode: "add" });
1724
1760
  else if (key.upArrow || _input === "k") dispatch({ type: "SELECT_GOAL", index: Math.max(0, goalsPanel.selectedIndex - 1) });
1725
1761
  else if (key.downArrow || _input === "j") dispatch({ type: "SELECT_GOAL", index: Math.min(activeGoals.length - 1, goalsPanel.selectedIndex + 1) });
1726
- else if (key.return) {
1762
+ else if (_input === "r") {
1763
+ const selected = activeGoals[goalsPanel.selectedIndex];
1764
+ if (selected) void checkGoalNow(selected.id);
1765
+ } else if (key.return) {
1727
1766
  const selected = activeGoals[goalsPanel.selectedIndex];
1728
1767
  if (selected) void completeGoal(selected.id);
1729
1768
  } else if (_input === "d") {
1730
1769
  const selected = activeGoals[goalsPanel.selectedIndex];
1731
1770
  if (selected) void deleteGoal(selected.id);
1732
- } else if (_input === "c") {
1733
- void clearAchievedGoals();
1734
1771
  } else if (_input === "x") {
1735
- const completed = goalsPanel.goals.filter((g) => g.status === "achieved" || g.status === "failed");
1736
- if (completed[0]) void deleteGoal(completed[0].id);
1772
+ void clearAchievedGoals();
1737
1773
  } else if (_input === "u") {
1738
1774
  const recent = goalsPanel.goals.filter((g) => g.status === "achieved").sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
1739
1775
  if (recent[0]) void reactivateGoal(recent[0].id);
@@ -1869,6 +1905,29 @@ function HypothesesView() {
1869
1905
  } catch {
1870
1906
  }
1871
1907
  }, [dispatch, refreshHypotheses]);
1908
+ const checkHypothesisNow = useCallback3(async (hypoId) => {
1909
+ try {
1910
+ const workDir = getWorkingDirectory(void 0, true);
1911
+ const hypo = hypothesesPanel.hypotheses.find((h) => h.id === hypoId);
1912
+ if (!hypo) return;
1913
+ dispatch({ type: "ADD_ACTIVITY", message: `Testing hypothesis: ${hypo.statement.slice(0, 30)}...` });
1914
+ dispatch({ type: "SHOW_NOTIFICATION", message: `Gathering evidence for hypothesis...`, severity: "info", autoHideMs: 3e3 });
1915
+ const { gatherEvidenceForHypothesis } = await import("./hypothesis-PEVD2IJR.js");
1916
+ const evidence = await gatherEvidenceForHypothesis(hypoId, workDir);
1917
+ if (evidence.length === 0) {
1918
+ dispatch({ type: "SHOW_NOTIFICATION", message: `No evidence found for: ${hypo.statement.slice(0, 40)}`, severity: "info", autoHideMs: 5e3 });
1919
+ dispatch({ type: "ADD_ACTIVITY", message: `No evidence found` });
1920
+ } else {
1921
+ const supporting = evidence.filter((e) => e.supports).length;
1922
+ const against = evidence.length - supporting;
1923
+ dispatch({ type: "SHOW_NOTIFICATION", message: `Found ${evidence.length} evidence (${supporting} for, ${against} against)`, severity: "info", autoHideMs: 5e3 });
1924
+ dispatch({ type: "ADD_ACTIVITY", message: `Found ${evidence.length} evidence items` });
1925
+ await refreshHypotheses();
1926
+ }
1927
+ } catch (error) {
1928
+ dispatch({ type: "ADD_ACTIVITY", message: `Check failed: ${error instanceof Error ? error.message : "unknown"}` });
1929
+ }
1930
+ }, [dispatch, hypothesesPanel.hypotheses, refreshHypotheses]);
1872
1931
  useInput5((_input, key) => {
1873
1932
  if (hypothesesPanel.inputMode === "add") {
1874
1933
  if (key.escape) {
@@ -1886,7 +1945,10 @@ function HypothesesView() {
1886
1945
  if (_input === "a") dispatch({ type: "SET_HYPOTHESES_INPUT_MODE", mode: "add" });
1887
1946
  else if (key.upArrow || _input === "k") dispatch({ type: "SELECT_HYPOTHESIS", index: Math.max(0, hypothesesPanel.selectedIndex - 1) });
1888
1947
  else if (key.downArrow || _input === "j") dispatch({ type: "SELECT_HYPOTHESIS", index: Math.min(testing.length - 1, hypothesesPanel.selectedIndex + 1) });
1889
- else if (_input === "v") {
1948
+ else if (_input === "r") {
1949
+ const selected = testing[hypothesesPanel.selectedIndex];
1950
+ if (selected) void checkHypothesisNow(selected.id);
1951
+ } else if (_input === "v") {
1890
1952
  const selected = testing[hypothesesPanel.selectedIndex];
1891
1953
  if (selected) void updateHypothesis(selected.id, "validate");
1892
1954
  } else if (_input === "x") {
@@ -4563,197 +4625,6 @@ ${checkpoint.files.length > 0 ? `**Files:** ${checkpoint.files.join(", ")}` : ""
4563
4625
 
4564
4626
  // src/cli/dashboard/chat-tools.ts
4565
4627
  import { createHash } from "crypto";
4566
-
4567
- // src/utils/terminal-spawn.ts
4568
- import { exec } from "child_process";
4569
- import { promisify } from "util";
4570
- import { platform } from "os";
4571
- var execAsync = promisify(exec);
4572
- async function spawnTerminal(options) {
4573
- const { command, cwd, title, keepOpen = true } = options;
4574
- const os = platform();
4575
- if (os === "darwin") {
4576
- await spawnMacOSTerminal(command, cwd, title, keepOpen);
4577
- } else if (os === "linux") {
4578
- await spawnLinuxTerminal(command, cwd, title, keepOpen);
4579
- } else {
4580
- throw new Error(`Terminal spawning not supported on ${os}`);
4581
- }
4582
- }
4583
- async function spawnMacOSTerminal(command, cwd, title, keepOpen) {
4584
- const escapedCommand = command.replace(/'/g, `'"'"'`);
4585
- const escapedCwd = cwd?.replace(/'/g, `'"'"'`) || process.cwd();
4586
- const escapedTitle = title?.replace(/'/g, `'"'"'`) || "Trie Agent";
4587
- const fullCommand = cwd ? `cd '${escapedCwd}' && ${command}` : command;
4588
- const escapedFullCommand = fullCommand.replace(/'/g, `'"'"'`);
4589
- const script = `
4590
- tell application "Terminal"
4591
- activate
4592
- set newTab to do script "${escapedFullCommand}"
4593
- set custom title of newTab to "${escapedTitle}"
4594
- end tell
4595
- `.trim();
4596
- try {
4597
- await execAsync(`osascript -e '${script.replace(/'/g, `'"'"'`)}'`);
4598
- } catch (error) {
4599
- console.error("Terminal.app spawn failed, trying fallback...");
4600
- const shellCmd = keepOpen ? `${fullCommand}; exec bash` : fullCommand;
4601
- await execAsync(`open -a Terminal "${escapedCwd}" --args -e "${shellCmd}"`);
4602
- }
4603
- }
4604
- async function spawnLinuxTerminal(command, cwd, title, keepOpen) {
4605
- const workDir = cwd || process.cwd();
4606
- const termTitle = title || "Trie Agent";
4607
- const shellCmd = keepOpen ? `${command}; exec bash` : command;
4608
- const terminals = [
4609
- // GNOME Terminal
4610
- {
4611
- command: "gnome-terminal",
4612
- args: `--working-directory="${workDir}" --title="${termTitle}" -- bash -c "${shellCmd}"`
4613
- },
4614
- // Konsole (KDE)
4615
- {
4616
- command: "konsole",
4617
- args: `--workdir "${workDir}" --title "${termTitle}" -e bash -c "${shellCmd}"`
4618
- },
4619
- // xterm (fallback)
4620
- {
4621
- command: "xterm",
4622
- args: `-T "${termTitle}" -e "cd '${workDir}' && ${shellCmd}"`
4623
- }
4624
- ];
4625
- for (const term of terminals) {
4626
- try {
4627
- await execAsync(`which ${term.command}`);
4628
- await execAsync(`${term.command} ${term.args} &`);
4629
- return;
4630
- } catch {
4631
- continue;
4632
- }
4633
- }
4634
- throw new Error("No supported terminal emulator found (tried: gnome-terminal, konsole, xterm)");
4635
- }
4636
- async function spawnClaudeCodeFix(options) {
4637
- const { file, goal, violation, suggestedFix, cwd } = options;
4638
- const fixScript = `
4639
- #!/bin/bash
4640
- set -e
4641
-
4642
- echo "\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\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"
4643
- echo "\u{1F527} Trie Agent - Automated Fix"
4644
- echo "\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\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"
4645
- echo ""
4646
- echo "File: ${file}"
4647
- echo "Goal: ${goal}"
4648
- echo "Violation: ${violation}"
4649
- ${suggestedFix ? `echo "Suggested: ${suggestedFix}"` : ""}
4650
- echo ""
4651
- echo "\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\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"
4652
- echo ""
4653
-
4654
- # Check if file exists
4655
- if [ ! -f "${file}" ]; then
4656
- echo "\u274C Error: File not found: ${file}"
4657
- exit 1
4658
- fi
4659
-
4660
- # Check if ANTHROPIC_API_KEY is set
4661
- if [ -z "\${ANTHROPIC_API_KEY}" ]; then
4662
- echo "\u274C Error: ANTHROPIC_API_KEY not set"
4663
- echo ""
4664
- echo "Please set your API key:"
4665
- echo " export ANTHROPIC_API_KEY=sk-ant-api03-..."
4666
- echo ""
4667
- exit 1
4668
- fi
4669
-
4670
- echo "\u{1F4D6} Reading file..."
4671
- FILE_CONTENT=$(cat "${file}")
4672
-
4673
- echo "\u{1F916} Analyzing with Claude..."
4674
- echo ""
4675
-
4676
- # Create the fix prompt
4677
- PROMPT="You are fixing a code quality violation.
4678
-
4679
- Goal: ${goal}
4680
- Violation: ${violation}
4681
- ${suggestedFix ? `Suggested fix: ${suggestedFix}` : ""}
4682
-
4683
- File: ${file}
4684
-
4685
- Current content:
4686
- $FILE_CONTENT
4687
-
4688
- Please fix the violation while:
4689
- 1. Preserving all functionality
4690
- 2. Maintaining code style
4691
- 3. Not breaking anything
4692
- 4. Following the goal exactly
4693
-
4694
- Output ONLY the fixed file content, no explanations or markdown fences."
4695
-
4696
- # Call Claude API to generate fix
4697
- # Using npx to run a simple Node script
4698
- FIXED_CONTENT=$(npx --yes -q tsx -e "
4699
- import Anthropic from '@anthropic-ai/sdk';
4700
- const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
4701
- const msg = await client.messages.create({
4702
- model: 'claude-3-5-sonnet-20241022',
4703
- max_tokens: 8000,
4704
- messages: [{ role: 'user', content: \\\`\${PROMPT}\\\` }]
4705
- });
4706
- const text = msg.content.find(c => c.type === 'text');
4707
- console.log(text ? text.text : '');
4708
- ")
4709
-
4710
- if [ -z "$FIXED_CONTENT" ]; then
4711
- echo "\u274C Error: Claude did not generate a fix"
4712
- exit 1
4713
- fi
4714
-
4715
- echo "\u2705 Fix generated!"
4716
- echo ""
4717
-
4718
- # Show diff
4719
- echo "\u{1F4CA} Changes:"
4720
- echo ""
4721
- diff -u "${file}" <(echo "$FIXED_CONTENT") || true
4722
- echo ""
4723
-
4724
- # Prompt for confirmation
4725
- read -p "Apply this fix? [y/N] " -n 1 -r
4726
- echo ""
4727
-
4728
- if [[ $REPLY =~ ^[Yy]$ ]]; then
4729
- echo "$FIXED_CONTENT" > "${file}"
4730
- echo "\u2705 Fix applied to ${file}"
4731
- echo ""
4732
- echo "\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\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"
4733
- echo "\u2728 Done! File has been fixed."
4734
- echo "\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\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"
4735
- else
4736
- echo "\u274C Fix cancelled"
4737
- fi
4738
-
4739
- echo ""
4740
- read -p "Press Enter to close..."
4741
- `.trim();
4742
- const { writeFile: writeFile2, chmod, unlink } = await import("fs/promises");
4743
- const { tmpdir } = await import("os");
4744
- const { join: join3 } = await import("path");
4745
- const scriptPath = join3(tmpdir(), `trie-fix-${Date.now()}.sh`);
4746
- await writeFile2(scriptPath, fixScript, "utf-8");
4747
- await chmod(scriptPath, 493);
4748
- await spawnTerminal({
4749
- command: `bash "${scriptPath}" && rm "${scriptPath}"`,
4750
- cwd,
4751
- title: `Fixing: ${file}`,
4752
- keepOpen: true
4753
- });
4754
- }
4755
-
4756
- // src/cli/dashboard/chat-tools.ts
4757
4628
  function textFromResult(result) {
4758
4629
  return result.content.map((c) => c.text).join("\n");
4759
4630
  }
@@ -4905,8 +4776,8 @@ var CHAT_TOOLS = [
4905
4776
  }
4906
4777
  },
4907
4778
  {
4908
- name: "trie_fix_goal_violation",
4909
- 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.",
4779
+ name: "trie_propose_fix",
4780
+ 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.",
4910
4781
  input_schema: {
4911
4782
  type: "object",
4912
4783
  properties: {
@@ -4917,6 +4788,28 @@ var CHAT_TOOLS = [
4917
4788
  },
4918
4789
  required: ["file", "goal", "violation"]
4919
4790
  }
4791
+ },
4792
+ {
4793
+ name: "trie_search_files",
4794
+ 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.",
4795
+ input_schema: {
4796
+ type: "object",
4797
+ properties: {
4798
+ pattern: {
4799
+ type: "string",
4800
+ description: 'Text or regex pattern to search for. For emojis, use patterns like "[\u{1F300}-\u{1F9FF}]" or specific emoji characters.'
4801
+ },
4802
+ filePattern: {
4803
+ type: "string",
4804
+ description: 'Glob pattern for files to search (e.g., "*.tsx", "*.ts", "src/**/*.js"). Omit to search all files.'
4805
+ },
4806
+ contextLines: {
4807
+ type: "number",
4808
+ description: "Number of context lines to show around matches (default 2)"
4809
+ }
4810
+ },
4811
+ required: ["pattern"]
4812
+ }
4920
4813
  }
4921
4814
  ];
4922
4815
  async function executeTool(name, input) {
@@ -5066,7 +4959,7 @@ async function executeTool(name, input) {
5066
4959
  });
5067
4960
  return `Decision recorded [${hash}]: "${dec}"`;
5068
4961
  }
5069
- case "trie_fix_goal_violation": {
4962
+ case "trie_propose_fix": {
5070
4963
  const file = String(input.file || "").trim();
5071
4964
  const goal = String(input.goal || "").trim();
5072
4965
  const violation = String(input.violation || "").trim();
@@ -5074,25 +4967,91 @@ async function executeTool(name, input) {
5074
4967
  if (!file) return "File path is required.";
5075
4968
  if (!goal) return "Goal description is required.";
5076
4969
  if (!violation) return "Violation description is required.";
4970
+ const fixProposal = {
4971
+ file,
4972
+ goal,
4973
+ violation,
4974
+ suggestedFix,
4975
+ directory
4976
+ };
4977
+ return `I found a violation to fix:
4978
+
4979
+ \u{1F4C1} File: ${file}
4980
+ \u{1F3AF} Goal: ${goal}
4981
+ \u26A0\uFE0F Violation: ${violation}
4982
+ ${suggestedFix ? `\u{1F4A1} Suggested fix: ${suggestedFix}
4983
+ ` : ""}
4984
+ Would you like me to spawn Claude Code to fix this?
4985
+
4986
+ Type "yes" to proceed, or "no" to cancel.
4987
+
4988
+ [PENDING_FIX:${JSON.stringify(fixProposal)}]`;
4989
+ }
4990
+ case "trie_search_files": {
4991
+ const pattern = String(input.pattern || "").trim();
4992
+ const filePattern = input.filePattern ? String(input.filePattern).trim() : void 0;
4993
+ const contextLines = typeof input.contextLines === "number" ? input.contextLines : 2;
4994
+ if (!pattern) return "Search pattern is required.";
4995
+ const { spawnSync } = await import("child_process");
5077
4996
  try {
5078
- await spawnClaudeCodeFix({
5079
- file,
5080
- goal,
5081
- violation,
5082
- suggestedFix,
4997
+ const rgArgs = [
4998
+ "--context",
4999
+ String(contextLines),
5000
+ "--heading",
5001
+ "--line-number",
5002
+ "--color=never",
5003
+ "--max-count",
5004
+ "50"
5005
+ // Limit matches per file
5006
+ ];
5007
+ if (filePattern) {
5008
+ rgArgs.push("--glob", filePattern);
5009
+ }
5010
+ rgArgs.push(
5011
+ "--glob",
5012
+ "!node_modules/**",
5013
+ "--glob",
5014
+ "!.git/**",
5015
+ "--glob",
5016
+ "!dist/**",
5017
+ "--glob",
5018
+ "!build/**",
5019
+ "--glob",
5020
+ "!coverage/**"
5021
+ );
5022
+ rgArgs.push(pattern, directory);
5023
+ const result = spawnSync("rg", rgArgs, {
5024
+ encoding: "utf-8",
5025
+ maxBuffer: 10 * 1024 * 1024,
5026
+ // 10MB
5083
5027
  cwd: directory
5084
5028
  });
5085
- return `\u2713 Spawned Claude Code in a new terminal to fix "${file}".
5029
+ if (result.error) {
5030
+ if (result.error.code === "ENOENT") {
5031
+ return `Error: ripgrep (rg) not found. Please install it:
5032
+ brew install ripgrep (macOS)
5033
+ apt install ripgrep (Ubuntu)
5034
+ Or search files using the AI-powered goal scan instead.`;
5035
+ }
5036
+ return `Search failed: ${result.error.message}`;
5037
+ }
5038
+ if (result.status === 1 || !result.stdout || !result.stdout.trim()) {
5039
+ return `No matches found for pattern: ${pattern}`;
5040
+ }
5041
+ if (result.status === 2) {
5042
+ return `Search error: ${result.stderr || "Unknown error"}`;
5043
+ }
5044
+ const maxLength = 5e3;
5045
+ const output = result.stdout;
5046
+ const truncated = output.length > maxLength ? output.slice(0, maxLength) + `
5086
5047
 
5087
- Claude Code will:
5088
- 1. Review the file
5089
- 2. Understand the goal: "${goal}"
5090
- 3. Fix the violation: "${violation}"
5091
- 4. Preserve all functionality
5048
+ ... (truncated, ${output.length - maxLength} more characters)` : output;
5049
+ const matchCount = (output.match(/^\d+:/gm) || []).length;
5050
+ return `Found ${matchCount} match(es) for "${pattern}":
5092
5051
 
5093
- Check the new terminal window to see the fix in progress.`;
5052
+ ${truncated}`;
5094
5053
  } catch (error) {
5095
- return `Failed to spawn Claude Code: ${error instanceof Error ? error.message : "unknown error"}`;
5054
+ return `Search failed: ${error.message}`;
5096
5055
  }
5097
5056
  }
5098
5057
  default:
@@ -5195,22 +5154,40 @@ function chatHistoryToMessages(history) {
5195
5154
  }));
5196
5155
  }
5197
5156
  var SYSTEM_PROMPT = `You are Trie, a code guardian assistant embedded in a terminal TUI.
5198
- 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.
5199
5157
 
5200
- **IMPORTANT: When the user asks to "fix" or "remove" something related to goal violations:**
5201
- 1. Check the "Recent goal violations (nudges)" section in the project context
5158
+ **What you CAN do:**
5159
+ - Check recent goal violations (nudges) in the provided project context
5160
+ - Record incidents, decisions, and feedback about the codebase
5161
+ - Query stored decisions, blockers, facts, and questions from the decision ledger
5162
+ - Create and manage goals and hypotheses
5163
+ - Propose fixes for goal violations (requires user confirmation before spawning Claude Code)
5164
+ - Save work checkpoints
5165
+
5166
+ **IMPORTANT - File Searching:**
5167
+ - You have a trie_search_files tool but it requires ripgrep to be installed
5168
+ - For searching code patterns (like emojis, TODO comments, etc.), use the provided project context first
5169
+ - If the user asks about emojis or goal violations, check the "Recent goal violations (nudges)" section
5170
+ - DO NOT use regex Unicode ranges in search patterns - they don't work reliably
5171
+ - Instead, suggest the user press 'r' in Goals view to run an AI-powered scan
5172
+
5173
+ **When user asks about code content:**
5174
+ 1. First check the "Recent goal violations (nudges)" section in project context
5175
+ 2. If found, report what you see
5176
+ 3. If not found, suggest: "Press 'r' in Goals view to run an AI-powered scan"
5177
+ 4. Do NOT attempt manual file searches for emoji detection
5178
+
5179
+ **When user asks to fix violations:**
5180
+ 1. Look in "Recent goal violations (nudges)" section of project context
5202
5181
  2. Extract: file path, goal description, and violation details
5203
- 3. IMMEDIATELY use trie_fix_goal_violation to spawn Claude Code in a new terminal
5204
- 4. Do NOT ask for clarification if the context has the violation details
5205
- 5. Do NOT try to search for files - use the violation info from nudges
5182
+ 3. Use trie_propose_fix to propose the fix - this will ASK THE USER for confirmation
5183
+ 4. Do NOT assume the user wants to proceed - always get confirmation first
5206
5184
 
5207
5185
  Examples:
5208
- - User: "fix the emoji violation" \u2192 Look for emoji violations in nudges, call trie_fix_goal_violation
5209
- - User: "remove emojis from this project" \u2192 Check nudges for emoji violations, call trie_fix_goal_violation
5210
- - User: "can you fix Dashboard.tsx" \u2192 Check if Dashboard.tsx has violations in nudges, call trie_fix_goal_violation
5186
+ - User: "do we have emojis?" \u2192 Check nudges first. If none: "I don't see emoji violations in recent nudges. Press 'r' in Goals view to run a scan."
5187
+ - User: "fix the emoji violation" \u2192 Find emoji violation in nudges, call trie_propose_fix (will ask user to confirm)
5188
+ - User: "search for TODO comments" \u2192 "The file search tool requires ripgrep. I recommend checking recent nudges or running a goal scan."
5211
5189
 
5212
- Answer concisely. Reference specific files, decisions, and patterns when relevant.
5213
- When you use a tool, briefly summarize what you did and what the result was.`;
5190
+ Answer concisely. Reference specific files, decisions, and patterns when relevant.`;
5214
5191
  function ChatView() {
5215
5192
  const { state, dispatch } = useDashboard();
5216
5193
  const { chatState } = state;
@@ -5224,6 +5201,50 @@ function ChatView() {
5224
5201
  dispatch({ type: "SET_CHAT_LOADING", loading: true });
5225
5202
  try {
5226
5203
  const workDir = getWorkingDirectory(void 0, true);
5204
+ const lastMessage = messages[messages.length - 1];
5205
+ if (lastMessage?.role === "assistant" && lastMessage.pendingFix) {
5206
+ const response = question.trim().toLowerCase();
5207
+ if (response === "yes" || response === "y") {
5208
+ const { spawnClaudeCodeFix } = await import("./terminal-spawn-2GU5KLPS.js");
5209
+ try {
5210
+ await spawnClaudeCodeFix(lastMessage.pendingFix);
5211
+ dispatch({
5212
+ type: "ADD_CHAT_MESSAGE",
5213
+ role: "assistant",
5214
+ content: `\u2713 Spawned Claude Code in a new terminal to fix "${lastMessage.pendingFix.file}".
5215
+
5216
+ Claude Code will:
5217
+ 1. Review the file
5218
+ 2. Understand the goal: "${lastMessage.pendingFix.goal}"
5219
+ 3. Fix the violation: "${lastMessage.pendingFix.violation}"
5220
+ 4. Preserve all functionality
5221
+
5222
+ Check the new terminal window to see the fix in progress.`
5223
+ });
5224
+ dispatch({ type: "SET_CHAT_LOADING", loading: false });
5225
+ loadingRef.current = false;
5226
+ return;
5227
+ } catch (error) {
5228
+ dispatch({
5229
+ type: "ADD_CHAT_MESSAGE",
5230
+ role: "assistant",
5231
+ content: `Failed to spawn Claude Code: ${error instanceof Error ? error.message : "unknown error"}`
5232
+ });
5233
+ dispatch({ type: "SET_CHAT_LOADING", loading: false });
5234
+ loadingRef.current = false;
5235
+ return;
5236
+ }
5237
+ } else if (response === "no" || response === "n") {
5238
+ dispatch({
5239
+ type: "ADD_CHAT_MESSAGE",
5240
+ role: "assistant",
5241
+ content: "Fix cancelled. Let me know if you need anything else!"
5242
+ });
5243
+ dispatch({ type: "SET_CHAT_LOADING", loading: false });
5244
+ loadingRef.current = false;
5245
+ return;
5246
+ }
5247
+ }
5227
5248
  const contextBlock = await buildContext(workDir, state);
5228
5249
  const fullSystem = `${SYSTEM_PROMPT}
5229
5250
 
@@ -5247,6 +5268,15 @@ ${contextBlock}`;
5247
5268
  role: "assistant",
5248
5269
  content: result.content
5249
5270
  };
5271
+ const pendingFixMatch = result.content.match(/\[PENDING_FIX:(.+?)\]/);
5272
+ if (pendingFixMatch) {
5273
+ try {
5274
+ const fixData = JSON.parse(pendingFixMatch[1]);
5275
+ action.pendingFix = fixData;
5276
+ action.content = result.content.replace(/\[PENDING_FIX:.+?\]/, "").trim();
5277
+ } catch {
5278
+ }
5279
+ }
5250
5280
  if (result.toolCalls && result.toolCalls.length > 0) {
5251
5281
  action.toolCalls = result.toolCalls;
5252
5282
  const toolNames = new Set(result.toolCalls.map((tc) => tc.name));
@@ -5315,33 +5345,34 @@ ${contextBlock}`;
5315
5345
  /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " AI is not available. Press s to open settings and add your Anthropic API key." })
5316
5346
  ] });
5317
5347
  }
5318
- return /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", paddingX: 1, children: [
5348
+ return /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", paddingX: 1, flexGrow: 1, children: [
5319
5349
  /* @__PURE__ */ jsx12(Text11, { bold: true, children: "Chat" }),
5320
- messages.length === 0 && !loading && /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " Ask about your codebase, decisions, patterns, or risks." }),
5321
- messages.map((msg, idx) => /* @__PURE__ */ jsx12(Box11, { flexDirection: "column", marginTop: idx === 0 ? 1 : 0, marginBottom: 1, children: msg.role === "user" ? /* @__PURE__ */ jsxs11(Text11, { children: [
5322
- " ",
5323
- /* @__PURE__ */ jsx12(Text11, { bold: true, color: "green", children: "You:" }),
5324
- " ",
5325
- msg.content
5326
- ] }) : /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", children: [
5327
- msg.toolCalls && msg.toolCalls.length > 0 && msg.toolCalls.map((tc, ti) => /* @__PURE__ */ jsxs11(Text11, { dimColor: true, children: [
5350
+ /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", flexGrow: 1, overflow: "hidden", marginTop: 1, children: [
5351
+ messages.length === 0 && !loading && /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " Ask about your codebase, decisions, patterns, or risks." }),
5352
+ messages.map((msg, idx) => /* @__PURE__ */ jsx12(Box11, { flexDirection: "column", marginTop: idx === 0 ? 0 : 1, marginBottom: 1, children: msg.role === "user" ? /* @__PURE__ */ jsxs11(Text11, { children: [
5328
5353
  " ",
5329
- /* @__PURE__ */ jsxs11(Text11, { color: "yellow", children: [
5330
- "[",
5331
- tc.name,
5332
- "]"
5333
- ] }),
5354
+ /* @__PURE__ */ jsx12(Text11, { bold: true, color: "green", children: "You:" }),
5334
5355
  " ",
5335
- formatToolInput(tc.input)
5336
- ] }, ti)),
5337
- msg.content.split("\n").map((line, li) => /* @__PURE__ */ jsxs11(Text11, { children: [
5338
- li === 0 ? " Trie: " : " ",
5339
- line
5340
- ] }, li))
5341
- ] }) }, idx)),
5342
- loading && /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " Thinking..." }),
5343
- /* @__PURE__ */ jsx12(Box11, { flexGrow: 1 }),
5344
- /* @__PURE__ */ jsx12(Box11, { borderStyle: "single", borderColor: "green", paddingX: 1, children: /* @__PURE__ */ jsxs11(Text11, { children: [
5356
+ msg.content
5357
+ ] }) : /* @__PURE__ */ jsxs11(Box11, { flexDirection: "column", children: [
5358
+ msg.toolCalls && msg.toolCalls.length > 0 && msg.toolCalls.map((tc, ti) => /* @__PURE__ */ jsxs11(Text11, { dimColor: true, children: [
5359
+ " ",
5360
+ /* @__PURE__ */ jsxs11(Text11, { color: "yellow", children: [
5361
+ "[",
5362
+ tc.name,
5363
+ "]"
5364
+ ] }),
5365
+ " ",
5366
+ formatToolInput(tc.input)
5367
+ ] }, ti)),
5368
+ msg.content.split("\n").map((line, li) => /* @__PURE__ */ jsxs11(Text11, { children: [
5369
+ li === 0 ? " Trie: " : " ",
5370
+ line
5371
+ ] }, li))
5372
+ ] }) }, idx)),
5373
+ loading && /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: " Thinking..." })
5374
+ ] }),
5375
+ /* @__PURE__ */ jsx12(Box11, { borderStyle: "single", borderColor: "green", paddingX: 1, flexShrink: 0, children: /* @__PURE__ */ jsxs11(Text11, { children: [
5345
5376
  inputBuffer || /* @__PURE__ */ jsx12(Text11, { dimColor: true, children: "Ask a question..." }),
5346
5377
  /* @__PURE__ */ jsx12(Text11, { bold: true, color: "green", children: "|" })
5347
5378
  ] }) })
@@ -5397,7 +5428,7 @@ ${content}
5397
5428
  fixedContent = fixedContent.replace(/^```\w*\n?/, "").replace(/\n?```$/, "");
5398
5429
  }
5399
5430
  await writeFile(fullPath, fixedContent, "utf-8");
5400
- const { recordGoalViolationFixed, getActiveGoals } = await import("./goal-validator-YSNN23D4.js");
5431
+ const { recordGoalViolationFixed, getActiveGoals } = await import("./goal-validator-RD6QBQJB.js");
5401
5432
  const goals = await getActiveGoals(projectPath);
5402
5433
  const matchedGoal = goals.find((g) => g.description === fix.goalDescription);
5403
5434
  if (matchedGoal) {
@@ -5591,6 +5622,9 @@ function DashboardApp({ onReady }) {
5591
5622
  dispatch({ type: "SET_VIEW", view: MAIN_VIEWS[nextIndex] || "overview" });
5592
5623
  return;
5593
5624
  }
5625
+ if (state.view === "goals" || state.view === "hypotheses") {
5626
+ return;
5627
+ }
5594
5628
  if (input === "s") {
5595
5629
  setShowConfig(true);
5596
5630
  return;
@@ -5654,7 +5688,7 @@ function DashboardApp({ onReady }) {
5654
5688
  }
5655
5689
  return /* @__PURE__ */ jsxs12(Box12, { flexDirection: "column", height: process.stdout.rows || 40, children: [
5656
5690
  /* @__PURE__ */ jsx13(Header, {}),
5657
- /* @__PURE__ */ jsx13(Notification, {}),
5691
+ !showConfig && /* @__PURE__ */ jsx13(Notification, {}),
5658
5692
  /* @__PURE__ */ jsx13(Box12, { flexGrow: 1, flexDirection: "column", overflow: "hidden", children: showConfig ? /* @__PURE__ */ jsx13(ConfigDialog, { onClose: () => {
5659
5693
  setShowConfig(false);
5660
5694
  void persistConfig();
@@ -5718,4 +5752,4 @@ export {
5718
5752
  handleCheckpointTool,
5719
5753
  InteractiveDashboard
5720
5754
  };
5721
- //# sourceMappingURL=chunk-OZGDXRLD.js.map
5755
+ //# sourceMappingURL=chunk-XNAVAA52.js.map