@triedotdev/mcp 1.0.20 → 1.0.22

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.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  listCustomAgents,
4
4
  loadAgentConfig,
5
5
  parseDocument
6
- } from "./chunk-EYNAGEQK.js";
6
+ } from "./chunk-R5VBDDAD.js";
7
7
  import {
8
8
  CRITICAL_REVIEW_CHECKLIST,
9
9
  SuperReviewerAgent,
@@ -12,11 +12,14 @@ import {
12
12
  getAgentRegistry,
13
13
  getPrompt,
14
14
  getSystemPrompt
15
- } from "./chunk-NZ67PJ6E.js";
15
+ } from "./chunk-NETSKBGJ.js";
16
16
  import "./chunk-3CS6Z2SL.js";
17
17
  import "./chunk-MR755QGT.js";
18
18
  import "./chunk-6NLHFIYA.js";
19
- import "./chunk-EEVALBHC.js";
19
+ import {
20
+ getWorkingDirectory
21
+ } from "./chunk-7QBNXROW.js";
22
+ import "./chunk-3MYJUGCZ.js";
20
23
  import "./chunk-DGUM43GV.js";
21
24
 
22
25
  // src/index.ts
@@ -28,7 +31,7 @@ import {
28
31
  ListResourcesRequestSchema,
29
32
  ReadResourceRequestSchema
30
33
  } from "@modelcontextprotocol/sdk/types.js";
31
- import { readdir as readdir2, readFile as readFile7 } from "fs/promises";
34
+ import { readdir as readdir2, readFile as readFile6 } from "fs/promises";
32
35
  import { join as join7 } from "path";
33
36
 
34
37
  // src/tools/explain.ts
@@ -68,10 +71,11 @@ var TrieExplainTool = class {
68
71
  let code;
69
72
  let filePath;
70
73
  let language;
71
- const resolvedPath = isAbsolute(target) ? target : resolve(process.cwd(), target);
74
+ const workDir = getWorkingDirectory(void 0, true);
75
+ const resolvedPath = isAbsolute(target) ? target : resolve(workDir, target);
72
76
  if (existsSync(resolvedPath)) {
73
77
  code = await readFile(resolvedPath, "utf-8");
74
- filePath = relative(process.cwd(), resolvedPath);
78
+ filePath = relative(workDir, resolvedPath);
75
79
  language = this.detectLanguage(resolvedPath);
76
80
  } else {
77
81
  code = target;
@@ -281,7 +285,8 @@ ${"\u2501".repeat(60)}
281
285
  return { content: [{ type: "text", text: output }] };
282
286
  }
283
287
  async explainRisk(target, context) {
284
- const resolvedPath = isAbsolute(target) ? target : resolve(process.cwd(), target);
288
+ const workDir = getWorkingDirectory(void 0, true);
289
+ const resolvedPath = isAbsolute(target) ? target : resolve(workDir, target);
285
290
  let output = `
286
291
  ${"\u2501".repeat(60)}
287
292
  `;
@@ -292,7 +297,7 @@ ${"\u2501".repeat(60)}
292
297
  `;
293
298
  if (existsSync(resolvedPath)) {
294
299
  const code = await readFile(resolvedPath, "utf-8");
295
- const filePath = relative(process.cwd(), resolvedPath);
300
+ const filePath = relative(workDir, resolvedPath);
296
301
  const riskIndicators = this.detectRiskIndicators(code);
297
302
  output += `## \u{1F4C2} Target
298
303
 
@@ -568,9 +573,10 @@ ${"\u2501".repeat(60)}
568
573
  output += `- **Files:** ${files.length}
569
574
 
570
575
  `;
576
+ const workDir = getWorkingDirectory(void 0, true);
571
577
  const allUnits = [];
572
578
  for (const file of files) {
573
- const resolvedPath = isAbsolute2(file) ? file : resolve2(process.cwd(), file);
579
+ const resolvedPath = isAbsolute2(file) ? file : resolve2(workDir, file);
574
580
  if (!existsSync2(resolvedPath)) {
575
581
  output += `\u26A0\uFE0F File not found: ${file}
576
582
  `;
@@ -578,7 +584,7 @@ ${"\u2501".repeat(60)}
578
584
  }
579
585
  const code = await readFile2(resolvedPath, "utf-8");
580
586
  const language = this.detectLanguage(resolvedPath);
581
- const relativePath = relative2(process.cwd(), resolvedPath);
587
+ const relativePath = relative2(workDir, resolvedPath);
582
588
  const units = this.extractTestableUnits(code, language);
583
589
  allUnits.push({ file: relativePath, units });
584
590
  output += `### \u{1F4C4} ${relativePath}
@@ -609,7 +615,7 @@ ${"\u2501".repeat(60)}
609
615
  `;
610
616
  for (const { file, units } of allUnits) {
611
617
  if (units.length === 0) continue;
612
- const code = await readFile2(resolve2(process.cwd(), file), "utf-8");
618
+ const code = await readFile2(resolve2(workDir, file), "utf-8");
613
619
  const language = this.detectLanguage(file);
614
620
  const prompt = getPrompt("test", "generate", {
615
621
  code,
@@ -652,8 +658,9 @@ ${"\u2501".repeat(60)}
652
658
  output += `${"\u2501".repeat(60)}
653
659
 
654
660
  `;
661
+ const workDir = getWorkingDirectory(void 0, true);
655
662
  for (const file of files) {
656
- const resolvedPath = isAbsolute2(file) ? file : resolve2(process.cwd(), file);
663
+ const resolvedPath = isAbsolute2(file) ? file : resolve2(workDir, file);
657
664
  if (!existsSync2(resolvedPath)) {
658
665
  output += `\u26A0\uFE0F File not found: ${file}
659
666
  `;
@@ -661,7 +668,7 @@ ${"\u2501".repeat(60)}
661
668
  }
662
669
  const code = await readFile2(resolvedPath, "utf-8");
663
670
  const language = this.detectLanguage(resolvedPath);
664
- const relativePath = relative2(process.cwd(), resolvedPath);
671
+ const relativePath = relative2(workDir, resolvedPath);
665
672
  const units = this.extractTestableUnits(code, language);
666
673
  const testFile = await this.findTestFile(resolvedPath);
667
674
  let testCode = "";
@@ -678,7 +685,7 @@ ${"\u2501".repeat(60)}
678
685
  output += `**Coverage:** ${coverageIcon} ${coverage}% (${testedUnits.length}/${units.length} units)
679
686
  `;
680
687
  if (testFile) {
681
- output += `**Test file:** \`${relative2(process.cwd(), testFile)}\`
688
+ output += `**Test file:** \`${relative2(workDir, testFile)}\`
682
689
  `;
683
690
  } else {
684
691
  output += `**Test file:** \u274C Not found
@@ -733,15 +740,16 @@ ${"\u2501".repeat(60)}
733
740
  output += `${"\u2501".repeat(60)}
734
741
 
735
742
  `;
743
+ const workDir = getWorkingDirectory(void 0, true);
736
744
  for (const file of files) {
737
- const resolvedPath = isAbsolute2(file) ? file : resolve2(process.cwd(), file);
745
+ const resolvedPath = isAbsolute2(file) ? file : resolve2(workDir, file);
738
746
  if (!existsSync2(resolvedPath)) {
739
747
  output += `\u26A0\uFE0F File not found: ${file}
740
748
  `;
741
749
  continue;
742
750
  }
743
751
  const code = await readFile2(resolvedPath, "utf-8");
744
- const relativePath = relative2(process.cwd(), resolvedPath);
752
+ const relativePath = relative2(workDir, resolvedPath);
745
753
  const patterns = this.detectTestablePatterns(code);
746
754
  output += `### \u{1F4C4} ${relativePath}
747
755
 
@@ -1041,7 +1049,8 @@ ${"\u2501".repeat(60)}
1041
1049
  return patterns;
1042
1050
  }
1043
1051
  async detectTestFramework() {
1044
- const packagePath = resolve2(process.cwd(), "package.json");
1052
+ const workDir = getWorkingDirectory(void 0, true);
1053
+ const packagePath = resolve2(workDir, "package.json");
1045
1054
  if (existsSync2(packagePath)) {
1046
1055
  try {
1047
1056
  const pkg = JSON.parse(await readFile2(packagePath, "utf-8"));
@@ -1052,7 +1061,7 @@ ${"\u2501".repeat(60)}
1052
1061
  } catch {
1053
1062
  }
1054
1063
  }
1055
- if (existsSync2(resolve2(process.cwd(), "pytest.ini")) || existsSync2(resolve2(process.cwd(), "pyproject.toml"))) {
1064
+ if (existsSync2(resolve2(workDir, "pytest.ini")) || existsSync2(resolve2(workDir, "pyproject.toml"))) {
1056
1065
  return "pytest";
1057
1066
  }
1058
1067
  return "jest";
@@ -1175,7 +1184,7 @@ var TrieWatchTool = class {
1175
1184
  const { action, directory, debounceMs = 1e3, yolo = false } = args;
1176
1185
  switch (action) {
1177
1186
  case "start":
1178
- return this.startWatching(directory || process.cwd(), debounceMs, yolo);
1187
+ return this.startWatching(getWorkingDirectory(directory), debounceMs, yolo);
1179
1188
  case "stop":
1180
1189
  return this.stopWatching();
1181
1190
  case "status":
@@ -1514,252 +1523,9 @@ To get a full report, run \`trie_scan\` on your codebase.`
1514
1523
  };
1515
1524
 
1516
1525
  // src/tools/agent.ts
1517
- import { readdir, readFile as readFile4 } from "fs/promises";
1526
+ import { readdir, readFile as readFile3 } from "fs/promises";
1518
1527
  import { existsSync as existsSync4 } from "fs";
1519
- import { join as join3, extname as extname5, isAbsolute as isAbsolute3, resolve as resolve3, basename as basename4 } from "path";
1520
-
1521
- // src/ai/engine.ts
1522
- import { readFile as readFile3 } from "fs/promises";
1523
- import { extname as extname4, relative as relative3, basename as basename3 } from "path";
1524
- function detectLanguage(filePath) {
1525
- const ext = extname4(filePath).toLowerCase();
1526
- const langMap = {
1527
- ".ts": "typescript",
1528
- ".tsx": "tsx",
1529
- ".js": "javascript",
1530
- ".jsx": "jsx",
1531
- ".py": "python",
1532
- ".go": "go",
1533
- ".rs": "rust",
1534
- ".java": "java",
1535
- ".rb": "ruby",
1536
- ".php": "php",
1537
- ".vue": "vue",
1538
- ".svelte": "svelte",
1539
- ".sql": "sql",
1540
- ".json": "json",
1541
- ".yaml": "yaml",
1542
- ".yml": "yaml",
1543
- ".md": "markdown",
1544
- ".html": "html",
1545
- ".css": "css",
1546
- ".scss": "scss"
1547
- };
1548
- return langMap[ext] || "plaintext";
1549
- }
1550
- function analyzeFileContext(content, _filePath) {
1551
- const summary = {
1552
- hasAuth: false,
1553
- hasDatabase: false,
1554
- hasUserInput: false,
1555
- hasFileOps: false,
1556
- hasCrypto: false,
1557
- hasExternalAPIs: false,
1558
- exports: [],
1559
- imports: []
1560
- };
1561
- if (/auth|login|session|jwt|token|password|credential|oauth/i.test(content)) {
1562
- summary.hasAuth = true;
1563
- }
1564
- if (/prisma|sequelize|knex|mongodb|sql|query|database|postgres|mysql|sqlite/i.test(content)) {
1565
- summary.hasDatabase = true;
1566
- }
1567
- if (/req\.body|req\.params|req\.query|formData|input|textarea|userinput/i.test(content)) {
1568
- summary.hasUserInput = true;
1569
- }
1570
- if (/readFile|writeFile|createReadStream|createWriteStream|fs\.|multer|upload/i.test(content)) {
1571
- summary.hasFileOps = true;
1572
- }
1573
- if (/crypto|bcrypt|argon|scrypt|encrypt|decrypt|hash|sign|verify/i.test(content)) {
1574
- summary.hasCrypto = true;
1575
- }
1576
- if (/fetch\(|axios|http\.|https\.|request\(|got\(|api\//i.test(content)) {
1577
- summary.hasExternalAPIs = true;
1578
- }
1579
- if (/from\s+['"]react['"]|import\s+React/i.test(content)) {
1580
- summary.framework = "React";
1581
- } else if (/from\s+['"]next|NextRequest|getServerSideProps/i.test(content)) {
1582
- summary.framework = "Next.js";
1583
- } else if (/from\s+['"]express['"]|express\(\)/i.test(content)) {
1584
- summary.framework = "Express";
1585
- } else if (/from\s+['"]fastify['"]|fastify\(\)/i.test(content)) {
1586
- summary.framework = "Fastify";
1587
- } else if (/from\s+['"]vue['"]|defineComponent/i.test(content)) {
1588
- summary.framework = "Vue";
1589
- }
1590
- const exportMatches = content.match(/export\s+(const|function|class|interface|type)\s+(\w+)/g) || [];
1591
- summary.exports = exportMatches.map((m) => m.split(/\s+/).pop() || "").filter(Boolean).slice(0, 10);
1592
- const importMatches = content.match(/import\s+.*from\s+['"]([^'"]+)['"]/g) || [];
1593
- summary.imports = importMatches.map((m) => {
1594
- const match = m.match(/from\s+['"]([^'"]+)['"]/);
1595
- return match ? match[1] : "";
1596
- }).filter((s) => Boolean(s)).slice(0, 10);
1597
- return summary;
1598
- }
1599
- function buildPromptContext(contexts, agent) {
1600
- let contextSummary = "";
1601
- const hasAuth = contexts.some((c) => c.summary?.hasAuth);
1602
- const hasDatabase = contexts.some((c) => c.summary?.hasDatabase);
1603
- const hasUserInput = contexts.some((c) => c.summary?.hasUserInput);
1604
- const hasFileOps = contexts.some((c) => c.summary?.hasFileOps);
1605
- const hasCrypto = contexts.some((c) => c.summary?.hasCrypto);
1606
- const hasExternalAPIs = contexts.some((c) => c.summary?.hasExternalAPIs);
1607
- const frameworks = [...new Set(contexts.map((c) => c.summary?.framework).filter(Boolean))];
1608
- contextSummary += "## Code Context Summary\n\n";
1609
- contextSummary += `**Files analyzed:** ${contexts.length}
1610
- `;
1611
- contextSummary += `**Total lines:** ${contexts.reduce((sum, c) => sum + c.lineCount, 0)}
1612
- `;
1613
- if (frameworks.length > 0) {
1614
- contextSummary += `**Frameworks detected:** ${frameworks.join(", ")}
1615
- `;
1616
- }
1617
- const features = [];
1618
- if (hasAuth) features.push("Authentication/Authorization");
1619
- if (hasDatabase) features.push("Database operations");
1620
- if (hasUserInput) features.push("User input handling");
1621
- if (hasFileOps) features.push("File operations");
1622
- if (hasCrypto) features.push("Cryptography");
1623
- if (hasExternalAPIs) features.push("External API calls");
1624
- if (features.length > 0) {
1625
- contextSummary += `**Key features:** ${features.join(", ")}
1626
- `;
1627
- }
1628
- contextSummary += "\n";
1629
- if (agent === "security") {
1630
- if (hasAuth) contextSummary += "\u26A0\uFE0F **Auth code detected** - Review authentication flows carefully\n";
1631
- if (hasDatabase) contextSummary += "\u26A0\uFE0F **Database ops detected** - Check for injection vulnerabilities\n";
1632
- if (hasUserInput) contextSummary += "\u26A0\uFE0F **User input detected** - Verify input validation\n";
1633
- } else if (agent === "privacy") {
1634
- if (hasAuth) contextSummary += "\u26A0\uFE0F **Auth code detected** - Review credential handling\n";
1635
- if (hasDatabase) contextSummary += "\u26A0\uFE0F **Database ops detected** - Check PII storage\n";
1636
- } else if (agent === "bugs") {
1637
- if (hasExternalAPIs) contextSummary += "\u26A0\uFE0F **External APIs detected** - Check error handling\n";
1638
- if (hasFileOps) contextSummary += "\u26A0\uFE0F **File ops detected** - Verify error handling and cleanup\n";
1639
- }
1640
- return contextSummary;
1641
- }
1642
- async function buildAnalysis(request) {
1643
- const { agent, files, context = {}, depth = "standard" } = request;
1644
- const codeContexts = [];
1645
- console.error(`\u{1F52C} AI Engine: Preparing ${agent} analysis for ${files.length} files...`);
1646
- for (const filePath of files) {
1647
- try {
1648
- const content = await readFile3(filePath, "utf-8");
1649
- const language = detectLanguage(filePath);
1650
- const summary = analyzeFileContext(content, filePath);
1651
- console.error(` \u{1F4C4} ${basename3(filePath)} - ${content.split("\n").length} lines`);
1652
- codeContexts.push({
1653
- filePath,
1654
- relativePath: relative3(process.cwd(), filePath),
1655
- language,
1656
- content: depth === "quick" && content.length > 5e3 ? content.substring(0, 5e3) + "\n\n... (truncated for quick analysis)" : content,
1657
- lineCount: content.split("\n").length,
1658
- summary
1659
- });
1660
- } catch (error) {
1661
- console.error(` \u26A0\uFE0F Error reading ${filePath}:`, error);
1662
- }
1663
- }
1664
- const codeBlocks = codeContexts.map(
1665
- (ctx) => `### File: ${ctx.relativePath}
1666
- \`\`\`${ctx.language}
1667
- ${ctx.content}
1668
- \`\`\``
1669
- ).join("\n\n");
1670
- const promptContext = buildPromptContext(codeContexts, agent);
1671
- const variables = {
1672
- ...context,
1673
- code: codeBlocks,
1674
- language: codeContexts[0]?.language || "unknown",
1675
- filePath: codeContexts.map((c) => c.relativePath).join(", ")
1676
- };
1677
- const analysisPrompt = getPrompt(agent, "analysis", variables);
1678
- const systemPrompt = getSystemPrompt(agent);
1679
- const suggestedFollowUps = [];
1680
- if (codeContexts.some((c) => c.summary?.hasAuth)) {
1681
- suggestedFollowUps.push("\u{1F510} Review authentication implementation");
1682
- }
1683
- if (codeContexts.some((c) => c.summary?.hasDatabase)) {
1684
- suggestedFollowUps.push("\u{1F5C4}\uFE0F Check database query security");
1685
- }
1686
- if (codeContexts.some((c) => c.summary?.hasUserInput)) {
1687
- suggestedFollowUps.push("\u{1F4DD} Verify input validation");
1688
- }
1689
- const filesSummary = codeContexts.map((c) => {
1690
- const features = [];
1691
- if (c.summary?.hasAuth) features.push("auth");
1692
- if (c.summary?.hasDatabase) features.push("db");
1693
- if (c.summary?.hasUserInput) features.push("input");
1694
- if (c.summary?.framework) features.push(c.summary.framework);
1695
- const featureStr = features.length > 0 ? ` [${features.join(", ")}]` : "";
1696
- return `\`${c.relativePath}\` (${c.lineCount} lines)${featureStr}`;
1697
- }).join("\n");
1698
- console.error(`\u{1F9E0} AI Engine: Analysis prepared - ready for Claude`);
1699
- return {
1700
- agent,
1701
- systemPrompt,
1702
- prompt: promptContext + "\n" + analysisPrompt,
1703
- codeContext: codeContexts,
1704
- suggestedFollowUps,
1705
- filesSummary
1706
- };
1707
- }
1708
- function formatAnalysisResponse(result, options = {}) {
1709
- const { agent, systemPrompt, prompt, codeContext, suggestedFollowUps, filesSummary } = result;
1710
- const includePrompt = options.includePrompt ?? true;
1711
- let output = "";
1712
- output += `
1713
- ${"\u2501".repeat(60)}
1714
- `;
1715
- output += `\u{1F9E0} ${agent.toUpperCase()} AGENT - AI ANALYSIS
1716
- `;
1717
- output += `${"\u2501".repeat(60)}
1718
-
1719
- `;
1720
- output += `## \u{1F4C2} Files for Analysis
1721
-
1722
- `;
1723
- output += filesSummary + "\n\n";
1724
- if (suggestedFollowUps.length > 0) {
1725
- output += `## \u{1F3AF} Focus Areas
1726
-
1727
- `;
1728
- for (const followUp of suggestedFollowUps) {
1729
- output += `- ${followUp}
1730
- `;
1731
- }
1732
- output += "\n";
1733
- }
1734
- output += `${"\u2500".repeat(60)}
1735
- `;
1736
- output += `## \u{1F9E0} Analysis Request for Claude
1737
-
1738
- `;
1739
- if (includePrompt) {
1740
- output += `**Role:** ${systemPrompt.split("\n")[0]}
1741
-
1742
- `;
1743
- output += `---
1744
-
1745
- `;
1746
- output += prompt;
1747
- output += `
1748
-
1749
- ${"\u2500".repeat(60)}
1750
- `;
1751
- } else {
1752
- output += `*Run with \`output: "full"\` to see the complete analysis prompt.*
1753
-
1754
- `;
1755
- output += `**Summary:** ${codeContext.length} files ready for ${agent} analysis
1756
- `;
1757
- }
1758
- output += `
1759
- **Claude:** Please analyze the code above according to the ${agent} analysis instructions and provide your findings.
1760
- `;
1761
- return output;
1762
- }
1528
+ import { join as join3, extname as extname4, isAbsolute as isAbsolute3, resolve as resolve3, basename as basename3 } from "path";
1763
1529
 
1764
1530
  // src/knowledge/index.ts
1765
1531
  var SECURITY_SOURCES = [
@@ -2065,27 +1831,6 @@ var SKIP_DIRS2 = /* @__PURE__ */ new Set([
2065
1831
  ".turbo",
2066
1832
  ".cache"
2067
1833
  ]);
2068
- var AGENT_TO_AI_TYPE = {
2069
- "security": "security",
2070
- "privacy": "privacy",
2071
- "legal": "legal",
2072
- "accessibility": "accessibility",
2073
- "design-engineer": "design-engineer",
2074
- "software-architect": "architecture",
2075
- "bug-finding": "bugs",
2076
- "user-testing": "ux",
2077
- "typecheck": "types",
2078
- "devops": "devops",
2079
- "comprehension": "explain",
2080
- "test": "test",
2081
- "trie_clean": "vibe",
2082
- "super-reviewer": "pr_review",
2083
- "agent-smith": "agent-smith",
2084
- "performance": "performance",
2085
- "e2e": "e2e",
2086
- "visual-qa": "visual_qa",
2087
- "data-flow": "data_flow"
2088
- };
2089
1834
  var TrieAgentTool = class {
2090
1835
  agentRegistry = getAgentRegistry();
2091
1836
  customAgentsLoaded = false;
@@ -2099,7 +1844,7 @@ var TrieAgentTool = class {
2099
1844
  }
2100
1845
  }
2101
1846
  async execute(args) {
2102
- const { agent, files, directory, depth = "standard", lookup, output = "full" } = args;
1847
+ const { agent, files, directory, depth: _depth = "standard", lookup, output = "full" } = args;
2103
1848
  if (lookup) {
2104
1849
  return this.handleKnowledgeLookup(lookup);
2105
1850
  }
@@ -2119,17 +1864,17 @@ ${this.agentRegistry.getAgentNames().map((n) => `- ${n}`).join("\n")}`
2119
1864
  }]
2120
1865
  };
2121
1866
  }
1867
+ const workDir = getWorkingDirectory(directory);
2122
1868
  let filesToScan = files || [];
2123
1869
  if (!filesToScan.length) {
2124
- const scanDir = directory || process.cwd();
2125
1870
  console.error(`
2126
- \u{1F50D} Discovering files in: ${scanDir}`);
2127
- filesToScan = await this.discoverFiles(scanDir);
1871
+ \u{1F50D} Discovering files in: ${workDir}`);
1872
+ filesToScan = await this.discoverFiles(workDir);
2128
1873
  console.error(` Found ${filesToScan.length} files
2129
1874
  `);
2130
1875
  } else {
2131
1876
  filesToScan = filesToScan.map(
2132
- (f) => isAbsolute3(f) ? f : resolve3(process.cwd(), f)
1877
+ (f) => isAbsolute3(f) ? f : resolve3(workDir, f)
2133
1878
  );
2134
1879
  }
2135
1880
  const validFiles = filesToScan.filter((f) => existsSync4(f));
@@ -2142,76 +1887,29 @@ ${this.agentRegistry.getAgentNames().map((n) => `- ${n}`).join("\n")}`
2142
1887
  };
2143
1888
  }
2144
1889
  const startTime = Date.now();
2145
- const aiAgentType = AGENT_TO_AI_TYPE[agent];
2146
- if (aiAgentType) {
2147
- return this.runAIAnalysis(
2148
- aiAgentType,
2149
- validFiles,
2150
- agentInstance.name,
2151
- agentInstance.description,
2152
- depth,
2153
- output
2154
- );
2155
- } else {
2156
- return this.runStaticAnalysis(agentInstance, validFiles, startTime);
2157
- }
1890
+ return this.runAgentScan(agentInstance, validFiles, startTime, output);
2158
1891
  }
2159
- async runAIAnalysis(agentType, files, agentName, agentDescription, depth, outputMode) {
2160
- const startTime = Date.now();
2161
- console.error(`
2162
- \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`);
2163
- console.error(`\u{1F9E0} Running AI-POWERED ${agentName.toUpperCase()} analysis`);
2164
- console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
2165
- `);
2166
- console.error(`\u{1F4C4} ${agentDescription}`);
2167
- console.error(`\u{1F4C2} Analyzing ${files.length} files (${depth} depth)...
2168
- `);
2169
- try {
2170
- const analysis = await buildAnalysis({
2171
- agent: agentType,
2172
- files,
2173
- depth
2174
- });
2175
- const executionTime = Date.now() - startTime;
2176
- const includePrompt = outputMode === "full";
2177
- let output = formatAnalysisResponse(analysis, { includePrompt });
2178
- if (analysis.suggestedFollowUps.length > 0) {
2179
- output += this.generateKnowledgeSuggestions(analysis.suggestedFollowUps, agentType);
2180
- }
2181
- output += `
2182
- *Analysis completed in ${(executionTime / 1e3).toFixed(2)}s*
2183
- `;
2184
- return {
2185
- content: [{
2186
- type: "text",
2187
- text: output
2188
- }]
2189
- };
2190
- } catch (error) {
2191
- return {
2192
- content: [{
2193
- type: "text",
2194
- text: `\u274C Analysis error: ${error instanceof Error ? error.message : String(error)}`
2195
- }]
2196
- };
2197
- }
2198
- }
2199
- async runStaticAnalysis(agentInstance, files, startTime) {
1892
+ /**
1893
+ * Run agent scan using the new hybrid AI system
1894
+ * All agents now use scan() which has pattern detection + optional AI enhancement
1895
+ */
1896
+ async runAgentScan(agentInstance, files, startTime, _outputMode) {
2200
1897
  console.error(`
2201
1898
  \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`);
2202
- console.error(`\u{1F50D} Running ${agentInstance.name.toUpperCase()} static analysis`);
1899
+ console.error(`\u{1F50D} Running ${agentInstance.name.toUpperCase()} analysis`);
2203
1900
  console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
2204
1901
  `);
2205
1902
  console.error(`\u{1F4C4} ${agentInstance.description}`);
2206
- console.error(`\u{1F4C2} Scanning ${files.length} files...
1903
+ console.error(`\u{1F4C2} Scanning ${files.length} files...`);
1904
+ console.error(` (Pattern detection + AI enhancement if API key is set)
2207
1905
  `);
2208
1906
  try {
2209
- const result = await agentInstance.scan(files, { workingDir: process.cwd() });
1907
+ const result = await agentInstance.scan(files, { workingDir: getWorkingDirectory(void 0, true) });
2210
1908
  const executionTime = Date.now() - startTime;
2211
1909
  return {
2212
1910
  content: [{
2213
1911
  type: "text",
2214
- text: await this.formatStaticResult(agentInstance.name, result.issues, files, executionTime)
1912
+ text: await this.formatAgentResult(agentInstance.name, result.issues, files, executionTime)
2215
1913
  }]
2216
1914
  };
2217
1915
  } catch (error) {
@@ -2223,7 +1921,8 @@ ${this.agentRegistry.getAgentNames().map((n) => `- ${n}`).join("\n")}`
2223
1921
  };
2224
1922
  }
2225
1923
  }
2226
- generateKnowledgeSuggestions(followUps, agentType) {
1924
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1925
+ _generateKnowledgeSuggestions(followUps, agentName) {
2227
1926
  if (followUps.length === 0) {
2228
1927
  return "";
2229
1928
  }
@@ -2235,7 +1934,7 @@ ${this.agentRegistry.getAgentNames().map((n) => `- ${n}`).join("\n")}`
2235
1934
  output += `- ${followUp}
2236
1935
  `;
2237
1936
  }
2238
- if (agentType === "security") {
1937
+ if (agentName === "security") {
2239
1938
  output += `- **CVE Check**: Run \`trie_security lookup:"cve" query:"[library-name]"\` to check for vulnerabilities
2240
1939
  `;
2241
1940
  }
@@ -2258,8 +1957,7 @@ ${this.agentRegistry.getAgentNames().map((n) => `- ${n}`).join("\n")}`
2258
1957
  const agents = this.agentRegistry.getAgentDescriptions();
2259
1958
  const agentList = agents.map((a) => {
2260
1959
  const command = this.getAgentCommand(a.name);
2261
- const aiPowered = AGENT_TO_AI_TYPE[a.name] ? "\u{1F9E0}" : "\u{1F50D}";
2262
- return `| \`${command}\` | ${aiPowered} ${a.name} | ${a.description} |`;
1960
+ return `| \`${command}\` | \u{1F50D}\u{1F916} ${a.name} | ${a.description} |`;
2263
1961
  }).join("\n");
2264
1962
  return {
2265
1963
  content: [{
@@ -2270,7 +1968,7 @@ ${this.agentRegistry.getAgentNames().map((n) => `- ${n}`).join("\n")}`
2270
1968
  |---------|-------|-------------|
2271
1969
  ${agentList}
2272
1970
 
2273
- **Legend:** \u{1F9E0} = AI-powered deep analysis, \u{1F50D} = Static pattern matching
1971
+ **Legend:** \u{1F50D}\u{1F916} = Pattern detection + AI enhancement (if ANTHROPIC_API_KEY is set)
2274
1972
 
2275
1973
  ## Usage
2276
1974
 
@@ -2322,7 +2020,7 @@ trie_scan # Full scan with smart triaging
2322
2020
  };
2323
2021
  return commandMap[agentName] || `trie_scan --agent ${agentName}`;
2324
2022
  }
2325
- async formatStaticResult(agentName, issues, files, executionTime) {
2023
+ async formatAgentResult(agentName, issues, files, executionTime) {
2326
2024
  const critical = issues.filter((i) => i.severity === "critical").length;
2327
2025
  const serious = issues.filter((i) => i.severity === "serious").length;
2328
2026
  const moderate = issues.filter((i) => i.severity === "moderate").length;
@@ -2393,7 +2091,7 @@ ${snippet}
2393
2091
 
2394
2092
  `;
2395
2093
  output += `\`\`\`
2396
- Fix the ${issue.issue.toLowerCase()} in ${basename4(issue.file)}${issue.line ? ` at line ${issue.line}` : ""}.
2094
+ Fix the ${issue.issue.toLowerCase()} in ${basename3(issue.file)}${issue.line ? ` at line ${issue.line}` : ""}.
2397
2095
 
2398
2096
  ${issue.fix}
2399
2097
  \`\`\`
@@ -2415,7 +2113,7 @@ ${issue.fix}
2415
2113
  async getCodeSnippet(filePath, line) {
2416
2114
  if (!line || !existsSync4(filePath)) return null;
2417
2115
  try {
2418
- const content = await readFile4(filePath, "utf-8");
2116
+ const content = await readFile3(filePath, "utf-8");
2419
2117
  const lines = content.split("\n");
2420
2118
  const start = Math.max(0, line - 3);
2421
2119
  const end = Math.min(lines.length, line + 2);
@@ -2459,7 +2157,7 @@ ${issue.fix}
2459
2157
  await walk(fullPath);
2460
2158
  }
2461
2159
  } else if (entry.isFile()) {
2462
- const ext = extname5(entry.name).toLowerCase();
2160
+ const ext = extname4(entry.name).toLowerCase();
2463
2161
  if (SCANNABLE_EXTENSIONS.has(ext)) {
2464
2162
  files.push(fullPath);
2465
2163
  }
@@ -2476,7 +2174,7 @@ ${issue.fix}
2476
2174
  // src/tools/create-agent.ts
2477
2175
  import { existsSync as existsSync5 } from "fs";
2478
2176
  import { mkdir, writeFile } from "fs/promises";
2479
- import { join as join4, basename as basename5, extname as extname6 } from "path";
2177
+ import { join as join4, basename as basename4, extname as extname5 } from "path";
2480
2178
  var TrieCreateAgentTool = class {
2481
2179
  async execute(args) {
2482
2180
  const { filePath, documentContent, agentName, displayName, description, category } = args;
@@ -2505,7 +2203,7 @@ Supported types: .pdf, .txt, .md, .rtf`
2505
2203
  }
2506
2204
  const document = await parseDocument(filePath);
2507
2205
  rawText = document.rawText;
2508
- title = document.metadata.title || basename5(filePath, extname6(filePath));
2206
+ title = document.metadata.title || basename4(filePath, extname5(filePath));
2509
2207
  wordCount = document.metadata.wordCount;
2510
2208
  } else {
2511
2209
  rawText = documentContent;
@@ -2871,7 +2569,7 @@ var TrieSaveAgentTool = class {
2871
2569
  };
2872
2570
  }
2873
2571
  async saveAgentConfig(config) {
2874
- const trieDir = join4(process.cwd(), ".trie", "agents");
2572
+ const trieDir = join4(getWorkingDirectory(void 0, true), ".trie", "agents");
2875
2573
  await mkdir(trieDir, { recursive: true });
2876
2574
  const configPath = join4(trieDir, `${config.name}.json`);
2877
2575
  await writeFile(configPath, JSON.stringify(config, null, 2));
@@ -3033,9 +2731,9 @@ var TrieListAgentsTool = class {
3033
2731
  };
3034
2732
 
3035
2733
  // src/tools/pr-review.ts
3036
- import { readFile as readFile5 } from "fs/promises";
2734
+ import { readFile as readFile4 } from "fs/promises";
3037
2735
  import { existsSync as existsSync6 } from "fs";
3038
- import { join as join5, basename as basename6, resolve as resolve4, isAbsolute as isAbsolute4 } from "path";
2736
+ import { join as join5, basename as basename5, resolve as resolve4, isAbsolute as isAbsolute4 } from "path";
3039
2737
  import { execSync } from "child_process";
3040
2738
  var TriePRReviewTool = class {
3041
2739
  agent = new SuperReviewerAgent();
@@ -3106,7 +2804,7 @@ Usage:
3106
2804
  */
3107
2805
  async getPRInfo(pr, worktree) {
3108
2806
  if (worktree) {
3109
- const worktreePath = isAbsolute4(worktree) ? worktree : resolve4(process.cwd(), worktree);
2807
+ const worktreePath = isAbsolute4(worktree) ? worktree : resolve4(getWorkingDirectory(void 0, true), worktree);
3110
2808
  if (!existsSync6(worktreePath)) {
3111
2809
  return { success: false, error: `Worktree not found: ${worktreePath}` };
3112
2810
  }
@@ -3114,7 +2812,7 @@ Usage:
3114
2812
  success: true,
3115
2813
  type: "worktree",
3116
2814
  path: worktreePath,
3117
- title: `Local changes in ${basename6(worktreePath)}`,
2815
+ title: `Local changes in ${basename5(worktreePath)}`,
3118
2816
  author: this.getGitUser(),
3119
2817
  baseBranch: "HEAD~1",
3120
2818
  headBranch: "HEAD"
@@ -3243,7 +2941,7 @@ Usage:
3243
2941
  */
3244
2942
  async findDesignDocs(files, prInfo) {
3245
2943
  const designDocs = [];
3246
- const cwd = prInfo.path || process.cwd();
2944
+ const cwd = prInfo.path || getWorkingDirectory(void 0, true);
3247
2945
  for (const file of files) {
3248
2946
  if (file.path.includes("design_docs/") || file.path.includes("docs/design/") || file.path.includes("rfcs/")) {
3249
2947
  designDocs.push(file.path);
@@ -3267,12 +2965,12 @@ Usage:
3267
2965
  */
3268
2966
  async preloadFiles(filePaths) {
3269
2967
  const contents = /* @__PURE__ */ new Map();
3270
- const cwd = process.cwd();
2968
+ const cwd = getWorkingDirectory(void 0, true);
3271
2969
  await Promise.all(filePaths.map(async (filePath) => {
3272
2970
  try {
3273
2971
  const fullPath = isAbsolute4(filePath) ? filePath : join5(cwd, filePath);
3274
2972
  if (existsSync6(fullPath)) {
3275
- const content = await readFile5(fullPath, "utf-8");
2973
+ const content = await readFile4(fullPath, "utf-8");
3276
2974
  contents.set(filePath, content);
3277
2975
  }
3278
2976
  } catch {
@@ -3729,7 +3427,7 @@ function detectAITool() {
3729
3427
  }
3730
3428
 
3731
3429
  // src/config/loader.ts
3732
- import { readFile as readFile6 } from "fs/promises";
3430
+ import { readFile as readFile5 } from "fs/promises";
3733
3431
  import { join as join6 } from "path";
3734
3432
 
3735
3433
  // src/config/defaults.ts
@@ -3785,8 +3483,8 @@ var DEFAULT_CONFIG = {
3785
3483
  // src/config/loader.ts
3786
3484
  async function loadConfig() {
3787
3485
  try {
3788
- const configPath = join6(process.cwd(), ".trie", "config.json");
3789
- const configFile = await readFile6(configPath, "utf-8");
3486
+ const configPath = join6(getWorkingDirectory(void 0, true), ".trie", "config.json");
3487
+ const configFile = await readFile5(configPath, "utf-8");
3790
3488
  const userConfig = JSON.parse(configFile);
3791
3489
  return mergeConfig(DEFAULT_CONFIG, userConfig);
3792
3490
  } catch (error) {
@@ -4485,7 +4183,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4485
4183
  case "smith": {
4486
4184
  const smithArgs = args;
4487
4185
  if (smithArgs.clear_memory) {
4488
- const { AgentSmithAgent } = await import("./agent-smith-BKHHC4G6.js");
4186
+ const { AgentSmithAgent } = await import("./agent-smith-MAOXWVIS.js");
4489
4187
  const smith = new AgentSmithAgent();
4490
4188
  const result = await smith.clearMemory();
4491
4189
  return {
@@ -4493,7 +4191,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4493
4191
  };
4494
4192
  }
4495
4193
  if (smithArgs.show_stats) {
4496
- const { AgentSmithAgent } = await import("./agent-smith-BKHHC4G6.js");
4194
+ const { AgentSmithAgent } = await import("./agent-smith-MAOXWVIS.js");
4497
4195
  const smith = new AgentSmithAgent();
4498
4196
  const stats = await smith.getMemoryStats();
4499
4197
  return {
@@ -4513,7 +4211,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
4513
4211
  }]
4514
4212
  };
4515
4213
  }
4516
- const { runAgentSmith } = await import("./agent-smith-runner-WZDDYQGK.js");
4214
+ const { runAgentSmith } = await import("./agent-smith-runner-KYOVKE6C.js");
4517
4215
  return await runAgentSmith(smithArgs);
4518
4216
  }
4519
4217
  default:
@@ -4558,7 +4256,7 @@ async function getAvailableResources() {
4558
4256
  mimeType: "application/json"
4559
4257
  });
4560
4258
  try {
4561
- const reportsDir = join7(process.cwd(), "trie-reports");
4259
+ const reportsDir = join7(getWorkingDirectory(void 0, true), "trie-reports");
4562
4260
  const files = await readdir2(reportsDir);
4563
4261
  const reportFiles = files.filter((f) => f.endsWith(".txt") || f.endsWith(".json"));
4564
4262
  for (const file of reportFiles.slice(0, 10)) {
@@ -4635,8 +4333,8 @@ async function readResourceContent(uri) {
4635
4333
  }
4636
4334
  if (parsedUri === "cache/stats") {
4637
4335
  try {
4638
- const cachePath = join7(process.cwd(), ".trie", ".trie-cache.json");
4639
- const cacheContent = await readFile7(cachePath, "utf-8");
4336
+ const cachePath = join7(getWorkingDirectory(void 0, true), ".trie", ".trie-cache.json");
4337
+ const cacheContent = await readFile6(cachePath, "utf-8");
4640
4338
  const cache = JSON.parse(cacheContent);
4641
4339
  const fileCount = Object.keys(cache.files || {}).length;
4642
4340
  const totalVulns = Object.values(cache.files || {}).reduce((acc, file) => {
@@ -4688,9 +4386,9 @@ async function readResourceContent(uri) {
4688
4386
  }
4689
4387
  if (parsedUri.startsWith("reports/")) {
4690
4388
  const fileName = parsedUri.replace("reports/", "");
4691
- const reportPath = join7(process.cwd(), "trie-reports", fileName);
4389
+ const reportPath = join7(getWorkingDirectory(void 0, true), "trie-reports", fileName);
4692
4390
  try {
4693
- const content = await readFile7(reportPath, "utf-8");
4391
+ const content = await readFile6(reportPath, "utf-8");
4694
4392
  return {
4695
4393
  contents: [{
4696
4394
  uri,