@4onstudios/iris-agent 0.1.0
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/LICENSE +21 -0
- package/README.md +690 -0
- package/dist/api/acp/acpServer.d.ts +23 -0
- package/dist/api/acp/acpServer.js +814 -0
- package/dist/api/acp/index.d.ts +2 -0
- package/dist/api/acp/index.js +2 -0
- package/dist/api/acp/irisClient.d.ts +58 -0
- package/dist/api/acp/irisClient.js +214 -0
- package/dist/api/agent.d.ts +14 -0
- package/dist/api/agent.js +4171 -0
- package/dist/api/backendService.d.ts +4 -0
- package/dist/api/backendService.js +14 -0
- package/dist/api/core/agent/host/AgentContract.d.ts +82 -0
- package/dist/api/core/agent/host/AgentContract.js +1 -0
- package/dist/api/core/agent/host/AgentRegistry.d.ts +24 -0
- package/dist/api/core/agent/host/AgentRegistry.js +125 -0
- package/dist/api/core/agent/host/defaultRegistry.d.ts +15 -0
- package/dist/api/core/agent/host/defaultRegistry.js +46 -0
- package/dist/api/core/agent/host/externalAgentLifecycle.d.ts +65 -0
- package/dist/api/core/agent/host/externalAgentLifecycle.js +117 -0
- package/dist/api/core/agent/host/hostSessionManager.d.ts +111 -0
- package/dist/api/core/agent/host/hostSessionManager.js +352 -0
- package/dist/api/core/agent/host/index.d.ts +5 -0
- package/dist/api/core/agent/host/index.js +5 -0
- package/dist/api/core/agent/index.d.ts +87 -0
- package/dist/api/core/agent/index.js +1024 -0
- package/dist/api/core/agent/publicContracts.d.ts +35 -0
- package/dist/api/core/agent/publicContracts.js +103 -0
- package/dist/api/core/agent/tools/applyDiff.d.ts +51 -0
- package/dist/api/core/agent/tools/applyDiff.js +131 -0
- package/dist/api/core/agent/tools/backgroundTasks.d.ts +240 -0
- package/dist/api/core/agent/tools/backgroundTasks.js +313 -0
- package/dist/api/core/agent/tools/createDirectory.d.ts +43 -0
- package/dist/api/core/agent/tools/createDirectory.js +77 -0
- package/dist/api/core/agent/tools/deleteFile.d.ts +37 -0
- package/dist/api/core/agent/tools/deleteFile.js +66 -0
- package/dist/api/core/agent/tools/editFile.d.ts +73 -0
- package/dist/api/core/agent/tools/editFile.js +173 -0
- package/dist/api/core/agent/tools/executeCommand.d.ts +59 -0
- package/dist/api/core/agent/tools/executeCommand.js +250 -0
- package/dist/api/core/agent/tools/fileContent.d.ts +54 -0
- package/dist/api/core/agent/tools/fileContent.js +227 -0
- package/dist/api/core/agent/tools/findDefinition.d.ts +72 -0
- package/dist/api/core/agent/tools/findDefinition.js +109 -0
- package/dist/api/core/agent/tools/findReferences.d.ts +86 -0
- package/dist/api/core/agent/tools/findReferences.js +135 -0
- package/dist/api/core/agent/tools/formatDocument.d.ts +67 -0
- package/dist/api/core/agent/tools/formatDocument.js +90 -0
- package/dist/api/core/agent/tools/getCodeActions.d.ts +77 -0
- package/dist/api/core/agent/tools/getCodeActions.js +97 -0
- package/dist/api/core/agent/tools/getCodeCompletion.d.ts +77 -0
- package/dist/api/core/agent/tools/getCodeCompletion.js +174 -0
- package/dist/api/core/agent/tools/getCodeContext.d.ts +14 -0
- package/dist/api/core/agent/tools/getCodeContext.js +282 -0
- package/dist/api/core/agent/tools/getSignatureHelp.d.ts +61 -0
- package/dist/api/core/agent/tools/getSignatureHelp.js +85 -0
- package/dist/api/core/agent/tools/getSymbols.d.ts +50 -0
- package/dist/api/core/agent/tools/getSymbols.js +164 -0
- package/dist/api/core/agent/tools/getSymbolsLSP.d.ts +58 -0
- package/dist/api/core/agent/tools/getSymbolsLSP.js +147 -0
- package/dist/api/core/agent/tools/getTypeInfo.d.ts +70 -0
- package/dist/api/core/agent/tools/getTypeInfo.js +84 -0
- package/dist/api/core/agent/tools/getWorkspaceInfo.d.ts +80 -0
- package/dist/api/core/agent/tools/getWorkspaceInfo.js +281 -0
- package/dist/api/core/agent/tools/getWorkspaceSymbols.d.ts +53 -0
- package/dist/api/core/agent/tools/getWorkspaceSymbols.js +97 -0
- package/dist/api/core/agent/tools/grepSearch.d.ts +100 -0
- package/dist/api/core/agent/tools/grepSearch.js +211 -0
- package/dist/api/core/agent/tools/languageModelToolsIntegration.d.ts +13 -0
- package/dist/api/core/agent/tools/languageModelToolsIntegration.js +22 -0
- package/dist/api/core/agent/tools/listDirectory.d.ts +66 -0
- package/dist/api/core/agent/tools/listDirectory.js +161 -0
- package/dist/api/core/agent/tools/mcpTools.d.ts +48 -0
- package/dist/api/core/agent/tools/mcpTools.js +442 -0
- package/dist/api/core/agent/tools/queryKnowledgeGraph.d.ts +120 -0
- package/dist/api/core/agent/tools/queryKnowledgeGraph.js +306 -0
- package/dist/api/core/agent/tools/readFile.d.ts +92 -0
- package/dist/api/core/agent/tools/readFile.js +337 -0
- package/dist/api/core/agent/tools/renameFile.d.ts +49 -0
- package/dist/api/core/agent/tools/renameFile.js +86 -0
- package/dist/api/core/agent/tools/renameSymbol.d.ts +70 -0
- package/dist/api/core/agent/tools/renameSymbol.js +106 -0
- package/dist/api/core/agent/tools/runTerminalCommand.d.ts +72 -0
- package/dist/api/core/agent/tools/runTerminalCommand.js +69 -0
- package/dist/api/core/agent/tools/searchFiles.d.ts +82 -0
- package/dist/api/core/agent/tools/searchFiles.js +280 -0
- package/dist/api/core/agent/tools/terminalAutoApprove.d.ts +3 -0
- package/dist/api/core/agent/tools/terminalAutoApprove.js +676 -0
- package/dist/api/core/agent/tools/treeTraversal.d.ts +60 -0
- package/dist/api/core/agent/tools/treeTraversal.js +217 -0
- package/dist/api/core/agent/tools/webSearch.d.ts +37 -0
- package/dist/api/core/agent/tools/webSearch.js +80 -0
- package/dist/api/core/agent/tools/writeFile.d.ts +59 -0
- package/dist/api/core/agent/tools/writeFile.js +97 -0
- package/dist/api/core/agent/utils/capturedWorkspaceMutationBridge.d.ts +12 -0
- package/dist/api/core/agent/utils/capturedWorkspaceMutationBridge.js +67 -0
- package/dist/api/core/agent/utils/diffUtils.d.ts +14 -0
- package/dist/api/core/agent/utils/diffUtils.js +39 -0
- package/dist/api/core/agent/utils/environmentSnapshot.d.ts +42 -0
- package/dist/api/core/agent/utils/environmentSnapshot.js +213 -0
- package/dist/api/core/agent/utils/errorRecovery.d.ts +49 -0
- package/dist/api/core/agent/utils/errorRecovery.js +229 -0
- package/dist/api/core/agent/utils/multimodalTokenLimiter.d.ts +8 -0
- package/dist/api/core/agent/utils/multimodalTokenLimiter.js +238 -0
- package/dist/api/core/agent/utils/openRouterModelSettings.d.ts +12 -0
- package/dist/api/core/agent/utils/openRouterModelSettings.js +34 -0
- package/dist/api/core/agent/utils/pathRecovery.d.ts +1 -0
- package/dist/api/core/agent/utils/pathRecovery.js +29 -0
- package/dist/api/core/agent/utils/repoMapIndex.d.ts +3 -0
- package/dist/api/core/agent/utils/repoMapIndex.js +197 -0
- package/dist/api/core/agent/utils/skillsDiscovery.d.ts +10 -0
- package/dist/api/core/agent/utils/skillsDiscovery.js +50 -0
- package/dist/api/core/agent/utils/toolCallBudget.d.ts +9 -0
- package/dist/api/core/agent/utils/toolCallBudget.js +55 -0
- package/dist/api/core/agent/utils/toolLifecycle.d.ts +30 -0
- package/dist/api/core/agent/utils/toolLifecycle.js +361 -0
- package/dist/api/core/agent/utils/toolResultSafetyProcessor.d.ts +12 -0
- package/dist/api/core/agent/utils/toolResultSafetyProcessor.js +57 -0
- package/dist/api/core/agent/utils/workspaceMutationBridge.d.ts +13 -0
- package/dist/api/core/agent/utils/workspaceMutationBridge.js +149 -0
- package/dist/api/core/agent/utils/workspacePathGuard.d.ts +7 -0
- package/dist/api/core/agent/utils/workspacePathGuard.js +79 -0
- package/dist/api/core/containers/chat/toolResultSerialization.d.ts +8 -0
- package/dist/api/core/containers/chat/toolResultSerialization.js +71 -0
- package/dist/api/core/library/BrowserManager.d.ts +11 -0
- package/dist/api/core/library/BrowserManager.js +66 -0
- package/dist/api/core/library/desktopWorkspace.d.ts +1 -0
- package/dist/api/core/library/desktopWorkspace.js +3 -0
- package/dist/api/core/library/extensionManager.d.ts +10 -0
- package/dist/api/core/library/extensionManager.js +27 -0
- package/dist/api/core/library/knowledgeGraph.d.ts +268 -0
- package/dist/api/core/library/knowledgeGraph.js +989 -0
- package/dist/api/core/library/languageModelTools.d.ts +141 -0
- package/dist/api/core/library/languageModelTools.js +207 -0
- package/dist/api/core/library/localRuntime.d.ts +23 -0
- package/dist/api/core/library/localRuntime.js +144 -0
- package/dist/api/core/library/lsp/coreLsp.d.ts +367 -0
- package/dist/api/core/library/lsp/coreLsp.js +2076 -0
- package/dist/api/core/library/lsp/protocol.d.ts +25 -0
- package/dist/api/core/library/lsp/protocol.js +1 -0
- package/dist/api/core/library/lsp/serverManager.d.ts +37 -0
- package/dist/api/core/library/lsp/serverManager.js +427 -0
- package/dist/api/core/library/mcpServerProvider.d.ts +69 -0
- package/dist/api/core/library/mcpServerProvider.js +152 -0
- package/dist/api/core/library/mcpSettings.d.ts +20 -0
- package/dist/api/core/library/mcpSettings.js +131 -0
- package/dist/api/core/library/patternMatcher.d.ts +66 -0
- package/dist/api/core/library/patternMatcher.js +284 -0
- package/dist/api/core/library/regexEscape.d.ts +4 -0
- package/dist/api/core/library/regexEscape.js +4 -0
- package/dist/api/core/library/runtimeEventBus.d.ts +27 -0
- package/dist/api/core/library/runtimeEventBus.js +78 -0
- package/dist/api/core/library/safetyMiddleware.d.ts +98 -0
- package/dist/api/core/library/safetyMiddleware.js +215 -0
- package/dist/api/core/library/tauri.d.ts +71 -0
- package/dist/api/core/library/tauri.js +222 -0
- package/dist/api/core/library/tauriImport.d.ts +5 -0
- package/dist/api/core/library/tauriImport.js +7 -0
- package/dist/api/core/library/terminalAutoApproveSettings.d.ts +32 -0
- package/dist/api/core/library/terminalAutoApproveSettings.js +529 -0
- package/dist/api/core/library/workspaceIdentity.d.ts +10 -0
- package/dist/api/core/library/workspaceIdentity.js +49 -0
- package/dist/api/core/library/workspaceSummary.d.ts +19 -0
- package/dist/api/core/library/workspaceSummary.js +35 -0
- package/dist/api/core/skills/agent-customization/SKILL.md +27 -0
- package/dist/api/core/skills/bug-fix/SKILL.md +21 -0
- package/dist/api/core/skills/create-pr/SKILL.md +32 -0
- package/dist/api/core/skills/dev-server/SKILL.md +20 -0
- package/dist/api/core/skills/fix-suggestions/SKILL.md +21 -0
- package/dist/api/core/skills/github-search/SKILL.md +21 -0
- package/dist/api/core/skills/github-summary/SKILL.md +25 -0
- package/dist/api/core/skills/integration-tests/SKILL.md +29 -0
- package/dist/api/core/skills/pr-comments/SKILL.md +23 -0
- package/dist/api/core/skills/project-setup/SKILL.md +20 -0
- package/dist/api/core/skills/search-integration/SKILL.md +19 -0
- package/dist/api/core/skills/search-results/SKILL.md +19 -0
- package/dist/api/core/skills/typescript-upgrade/SKILL.md +21 -0
- package/dist/api/data/runStore.d.ts +46 -0
- package/dist/api/data/runStore.js +244 -0
- package/dist/api/helpers/agentUtils.d.ts +11 -0
- package/dist/api/helpers/agentUtils.js +23 -0
- package/dist/api/helpers/modelTokenLimits.d.ts +2 -0
- package/dist/api/helpers/modelTokenLimits.js +158 -0
- package/dist/api/helpers/observationalMemory.d.ts +10 -0
- package/dist/api/helpers/observationalMemory.js +36 -0
- package/dist/api/helpers/promptBudget.d.ts +30 -0
- package/dist/api/helpers/promptBudget.js +216 -0
- package/dist/api/helpers/resolveImageMessageParts.d.ts +9 -0
- package/dist/api/helpers/resolveImageMessageParts.js +140 -0
- package/dist/api/helpers/slashCommands.d.ts +31 -0
- package/dist/api/helpers/slashCommands.js +129 -0
- package/dist/api/helpers/tokenUsage.d.ts +19 -0
- package/dist/api/helpers/tokenUsage.js +81 -0
- package/dist/api/routes/fileRoutes.d.ts +2 -0
- package/dist/api/routes/fileRoutes.js +108 -0
- package/dist/api/routes/lspDocumentRoutes.d.ts +4 -0
- package/dist/api/routes/lspDocumentRoutes.js +84 -0
- package/dist/api/routes/lspHierarchyRoutes.d.ts +4 -0
- package/dist/api/routes/lspHierarchyRoutes.js +122 -0
- package/dist/api/routes/lspPositionRoutes.d.ts +4 -0
- package/dist/api/routes/lspPositionRoutes.js +263 -0
- package/dist/api/routes/lspQueryRoutes.d.ts +4 -0
- package/dist/api/routes/lspQueryRoutes.js +679 -0
- package/dist/api/routes/lspResolveRoutes.d.ts +4 -0
- package/dist/api/routes/lspResolveRoutes.js +143 -0
- package/dist/api/routes/lspSemanticDocumentRoutes.d.ts +4 -0
- package/dist/api/routes/lspSemanticDocumentRoutes.js +98 -0
- package/dist/api/routes/semanticRoutes.d.ts +2 -0
- package/dist/api/routes/semanticRoutes.js +126 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +160 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +38 -0
- package/package.json +100 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { createTool } from "@mastra/core/tools";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import path from "path";
|
|
5
|
+
/**
|
|
6
|
+
* getCodeContext tool - Fetches relevant code snippets for answering questions
|
|
7
|
+
* Similar to how VS Code Copilot finds and references code
|
|
8
|
+
*/
|
|
9
|
+
const getCodeContextTool = createTool({
|
|
10
|
+
id: "getCodeContext",
|
|
11
|
+
description: `Get code context and snippets relevant to a user's question. Use this tool when:
|
|
12
|
+
- User asks about how code works or what it does
|
|
13
|
+
- User wants to understand a specific function, class, or variable
|
|
14
|
+
- User asks about connections between different parts of the code
|
|
15
|
+
- User needs context about a specific file or feature
|
|
16
|
+
|
|
17
|
+
This tool searches for relevant code and returns snippets with file paths and line numbers,
|
|
18
|
+
formatted for display with proper code references (like VS Code Copilot style).`,
|
|
19
|
+
inputSchema: z.object({
|
|
20
|
+
query: z
|
|
21
|
+
.string()
|
|
22
|
+
.describe("The question or topic to find code context for (e.g., 'how does authentication work', 'where is the API called')"),
|
|
23
|
+
targetFiles: z
|
|
24
|
+
.array(z.string())
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("Specific files to search in (relative paths)"),
|
|
27
|
+
symbols: z
|
|
28
|
+
.array(z.string())
|
|
29
|
+
.optional()
|
|
30
|
+
.describe("Specific symbol names to look for (function names, class names, variables)"),
|
|
31
|
+
includeDefinitions: z
|
|
32
|
+
.boolean()
|
|
33
|
+
.optional()
|
|
34
|
+
.default(true)
|
|
35
|
+
.describe("Whether to include symbol definitions"),
|
|
36
|
+
includeUsages: z
|
|
37
|
+
.boolean()
|
|
38
|
+
.optional()
|
|
39
|
+
.default(true)
|
|
40
|
+
.describe("Whether to include where symbols are used"),
|
|
41
|
+
maxResults: z
|
|
42
|
+
.number()
|
|
43
|
+
.optional()
|
|
44
|
+
.default(5)
|
|
45
|
+
.describe("Maximum number of code snippets to return"),
|
|
46
|
+
cwd: z.string().optional().describe("Working directory (workspace root)"),
|
|
47
|
+
}),
|
|
48
|
+
execute: async ({ query, targetFiles, symbols, includeDefinitions = true, includeUsages = true, maxResults = 5, cwd, }) => {
|
|
49
|
+
const workspacePath = cwd || process.cwd();
|
|
50
|
+
const results = {
|
|
51
|
+
success: true,
|
|
52
|
+
query,
|
|
53
|
+
codeReferences: [],
|
|
54
|
+
summary: "",
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
// Helper to read file and extract snippet around a line
|
|
58
|
+
const extractSnippet = async (filePath, targetLine, contextLines = 5) => {
|
|
59
|
+
try {
|
|
60
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
61
|
+
? filePath
|
|
62
|
+
: path.join(workspacePath, filePath);
|
|
63
|
+
const content = await fs.readFile(absolutePath, "utf-8");
|
|
64
|
+
const lines = content.split("\n");
|
|
65
|
+
const startLine = Math.max(0, targetLine - contextLines - 1);
|
|
66
|
+
const endLine = Math.min(lines.length - 1, targetLine + contextLines - 1);
|
|
67
|
+
return {
|
|
68
|
+
code: lines.slice(startLine, endLine + 1).join("\n"),
|
|
69
|
+
startLine: startLine + 1,
|
|
70
|
+
endLine: endLine + 1,
|
|
71
|
+
totalLines: lines.length,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
// Helper to find symbol definitions in a file
|
|
79
|
+
const findSymbolInFile = async (filePath, symbolName) => {
|
|
80
|
+
try {
|
|
81
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
82
|
+
? filePath
|
|
83
|
+
: path.join(workspacePath, filePath);
|
|
84
|
+
const content = await fs.readFile(absolutePath, "utf-8");
|
|
85
|
+
const lines = content.split("\n");
|
|
86
|
+
const matches = [];
|
|
87
|
+
// Patterns for different types of definitions
|
|
88
|
+
const patterns = [
|
|
89
|
+
// Function declarations
|
|
90
|
+
new RegExp(`^\\s*(async\\s+)?function\\s+${symbolName}\\s*\\(`, "m"),
|
|
91
|
+
// Arrow functions and const/let/var declarations
|
|
92
|
+
new RegExp(`^\\s*(export\\s+)?(const|let|var)\\s+${symbolName}\\s*=`, "m"),
|
|
93
|
+
// Class declarations
|
|
94
|
+
new RegExp(`^\\s*(export\\s+)?class\\s+${symbolName}\\b`, "m"),
|
|
95
|
+
// Method definitions in classes
|
|
96
|
+
new RegExp(`^\\s*(async\\s+)?${symbolName}\\s*\\([^)]*\\)\\s*{`, "m"),
|
|
97
|
+
// TypeScript interface/type
|
|
98
|
+
new RegExp(`^\\s*(export\\s+)?(interface|type)\\s+${symbolName}\\b`, "m"),
|
|
99
|
+
// Object property (for enums, etc.)
|
|
100
|
+
new RegExp(`\\b${symbolName}\\s*[:=]\\s*`, "m"),
|
|
101
|
+
];
|
|
102
|
+
lines.forEach((line, index) => {
|
|
103
|
+
for (const pattern of patterns) {
|
|
104
|
+
if (pattern.test(line)) {
|
|
105
|
+
matches.push({
|
|
106
|
+
line: index + 1,
|
|
107
|
+
type: "definition",
|
|
108
|
+
text: line.trim(),
|
|
109
|
+
});
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return matches;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
// Helper to find symbol usages in a file
|
|
121
|
+
const findUsagesInFile = async (filePath, symbolName) => {
|
|
122
|
+
try {
|
|
123
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
124
|
+
? filePath
|
|
125
|
+
: path.join(workspacePath, filePath);
|
|
126
|
+
const content = await fs.readFile(absolutePath, "utf-8");
|
|
127
|
+
const lines = content.split("\n");
|
|
128
|
+
const usages = [];
|
|
129
|
+
const usagePattern = new RegExp(`\\b${symbolName}\\b`, "g");
|
|
130
|
+
lines.forEach((line, index) => {
|
|
131
|
+
if (usagePattern.test(line)) {
|
|
132
|
+
// Skip if it's an import statement
|
|
133
|
+
if (!line.trim().startsWith("import ")) {
|
|
134
|
+
usages.push({
|
|
135
|
+
line: index + 1,
|
|
136
|
+
type: "usage",
|
|
137
|
+
text: line.trim(),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return usages;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
// Get list of files to search
|
|
149
|
+
let filesToSearch = targetFiles || [];
|
|
150
|
+
// If no specific files, get relevant files from workspace
|
|
151
|
+
if (filesToSearch.length === 0) {
|
|
152
|
+
try {
|
|
153
|
+
const { glob } = await import("glob");
|
|
154
|
+
const pattern = "**/*.{js,jsx,ts,tsx,py,java,swift,kt,go,rs,c,cpp,cs}";
|
|
155
|
+
const files = await glob(pattern, {
|
|
156
|
+
cwd: workspacePath,
|
|
157
|
+
ignore: [
|
|
158
|
+
"**/node_modules/**",
|
|
159
|
+
"**/dist/**",
|
|
160
|
+
"**/build/**",
|
|
161
|
+
"**/.git/**",
|
|
162
|
+
],
|
|
163
|
+
nodir: true,
|
|
164
|
+
});
|
|
165
|
+
filesToSearch = files.slice(0, 20); // Limit to 20 files for performance
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
console.error("Error globbing files:", e);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Search for symbols if provided
|
|
172
|
+
if (symbols && symbols.length > 0) {
|
|
173
|
+
for (const symbol of symbols) {
|
|
174
|
+
for (const file of filesToSearch) {
|
|
175
|
+
// Find definitions
|
|
176
|
+
if (includeDefinitions) {
|
|
177
|
+
const definitions = await findSymbolInFile(file, symbol);
|
|
178
|
+
for (const def of definitions) {
|
|
179
|
+
const snippet = await extractSnippet(file, def.line, 8);
|
|
180
|
+
if (snippet) {
|
|
181
|
+
results.codeReferences.push({
|
|
182
|
+
filePath: file,
|
|
183
|
+
code: snippet.code,
|
|
184
|
+
startLine: snippet.startLine,
|
|
185
|
+
endLine: snippet.endLine,
|
|
186
|
+
description: `Definition of \`${symbol}\``,
|
|
187
|
+
symbol,
|
|
188
|
+
type: "definition",
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// Find usages
|
|
194
|
+
if (includeUsages) {
|
|
195
|
+
const usages = await findUsagesInFile(file, symbol);
|
|
196
|
+
// Limit usages per file
|
|
197
|
+
for (const usage of usages.slice(0, 3)) {
|
|
198
|
+
const snippet = await extractSnippet(file, usage.line, 3);
|
|
199
|
+
if (snippet) {
|
|
200
|
+
results.codeReferences.push({
|
|
201
|
+
filePath: file,
|
|
202
|
+
code: snippet.code,
|
|
203
|
+
startLine: snippet.startLine,
|
|
204
|
+
endLine: snippet.endLine,
|
|
205
|
+
description: `Usage of \`${symbol}\``,
|
|
206
|
+
symbol,
|
|
207
|
+
type: "usage",
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// If query contains code snippet, search for it
|
|
216
|
+
const codePatterns = query.match(/`([^`]+)`/g);
|
|
217
|
+
if (codePatterns) {
|
|
218
|
+
for (const pattern of codePatterns) {
|
|
219
|
+
const searchTerm = pattern.replace(/`/g, "");
|
|
220
|
+
for (const file of filesToSearch) {
|
|
221
|
+
try {
|
|
222
|
+
const absolutePath = path.isAbsolute(file)
|
|
223
|
+
? file
|
|
224
|
+
: path.join(workspacePath, file);
|
|
225
|
+
const content = await fs.readFile(absolutePath, "utf-8");
|
|
226
|
+
if (content.includes(searchTerm)) {
|
|
227
|
+
const lines = content.split("\n");
|
|
228
|
+
const lineIndex = lines.findIndex((l) => l.includes(searchTerm));
|
|
229
|
+
if (lineIndex >= 0) {
|
|
230
|
+
const snippet = await extractSnippet(file, lineIndex + 1, 5);
|
|
231
|
+
if (snippet) {
|
|
232
|
+
results.codeReferences.push({
|
|
233
|
+
filePath: file,
|
|
234
|
+
code: snippet.code,
|
|
235
|
+
startLine: snippet.startLine,
|
|
236
|
+
endLine: snippet.endLine,
|
|
237
|
+
description: `Contains \`${searchTerm}\``,
|
|
238
|
+
type: "match",
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// Skip files that can't be read
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// Limit results
|
|
251
|
+
results.codeReferences = results.codeReferences.slice(0, maxResults);
|
|
252
|
+
// Generate summary
|
|
253
|
+
if (results.codeReferences.length > 0) {
|
|
254
|
+
const defCount = results.codeReferences.filter((r) => r.type === "definition").length;
|
|
255
|
+
const usageCount = results.codeReferences.filter((r) => r.type === "usage").length;
|
|
256
|
+
const matchCount = results.codeReferences.filter((r) => r.type === "match").length;
|
|
257
|
+
const parts = [];
|
|
258
|
+
if (defCount > 0)
|
|
259
|
+
parts.push(`${defCount} definition(s)`);
|
|
260
|
+
if (usageCount > 0)
|
|
261
|
+
parts.push(`${usageCount} usage(s)`);
|
|
262
|
+
if (matchCount > 0)
|
|
263
|
+
parts.push(`${matchCount} match(es)`);
|
|
264
|
+
results.summary = `Found ${parts.join(", ")} across ${new Set(results.codeReferences.map((r) => r.filePath)).size} file(s)`;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
results.summary = "No relevant code found for the query";
|
|
268
|
+
}
|
|
269
|
+
return results;
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
const err = error;
|
|
273
|
+
return {
|
|
274
|
+
success: false,
|
|
275
|
+
error: err.message,
|
|
276
|
+
query,
|
|
277
|
+
codeReferences: [],
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
export default getCodeContextTool;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get Signature Help Tool
|
|
3
|
+
* Uses LSP to provide parameter hints when calling functions or methods.
|
|
4
|
+
*/
|
|
5
|
+
type GetSignatureHelpParams = {
|
|
6
|
+
filePath: string;
|
|
7
|
+
line: number;
|
|
8
|
+
character: number;
|
|
9
|
+
};
|
|
10
|
+
type GetSignatureHelpResult = {
|
|
11
|
+
success: true;
|
|
12
|
+
filePath: string;
|
|
13
|
+
position: {
|
|
14
|
+
line: number;
|
|
15
|
+
character: number;
|
|
16
|
+
};
|
|
17
|
+
activeSignature: number;
|
|
18
|
+
activeParameter: number;
|
|
19
|
+
signatures: Array<{
|
|
20
|
+
label: string;
|
|
21
|
+
documentation: string;
|
|
22
|
+
parameters: Array<{
|
|
23
|
+
label: string;
|
|
24
|
+
documentation: string;
|
|
25
|
+
}>;
|
|
26
|
+
}>;
|
|
27
|
+
activeSignatureLabel: string;
|
|
28
|
+
} | {
|
|
29
|
+
success: false;
|
|
30
|
+
message?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
filePath: string;
|
|
33
|
+
position: {
|
|
34
|
+
line: number;
|
|
35
|
+
character: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
declare const getSignatureHelpTool: {
|
|
39
|
+
name: string;
|
|
40
|
+
description: string;
|
|
41
|
+
parameters: {
|
|
42
|
+
type: string;
|
|
43
|
+
properties: {
|
|
44
|
+
filePath: {
|
|
45
|
+
type: string;
|
|
46
|
+
description: string;
|
|
47
|
+
};
|
|
48
|
+
line: {
|
|
49
|
+
type: string;
|
|
50
|
+
description: string;
|
|
51
|
+
};
|
|
52
|
+
character: {
|
|
53
|
+
type: string;
|
|
54
|
+
description: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
required: string[];
|
|
58
|
+
};
|
|
59
|
+
execute({ filePath, line, character }: GetSignatureHelpParams): Promise<GetSignatureHelpResult>;
|
|
60
|
+
};
|
|
61
|
+
export default getSignatureHelpTool;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get Signature Help Tool
|
|
3
|
+
* Uses LSP to provide parameter hints when calling functions or methods.
|
|
4
|
+
*/
|
|
5
|
+
import { coreLsp } from "../../library/lsp/coreLsp.js";
|
|
6
|
+
import fs from "fs/promises";
|
|
7
|
+
const getSignatureHelpTool = {
|
|
8
|
+
name: "getSignatureHelp",
|
|
9
|
+
description: `Get function/method signature help and parameter hints at a specific position.
|
|
10
|
+
Shows available overloads, parameter names, types, and documentation while typing a function call.
|
|
11
|
+
|
|
12
|
+
Use this when you need to:
|
|
13
|
+
- See what parameters a function accepts
|
|
14
|
+
- Understand parameter order and types
|
|
15
|
+
- Get documentation for a specific parameter
|
|
16
|
+
- Check all available overloads for a method`,
|
|
17
|
+
parameters: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
filePath: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Absolute path to the file",
|
|
23
|
+
},
|
|
24
|
+
line: {
|
|
25
|
+
type: "number",
|
|
26
|
+
description: "Line number (1-based) inside a function call",
|
|
27
|
+
},
|
|
28
|
+
character: {
|
|
29
|
+
type: "number",
|
|
30
|
+
description: "Character position (1-based) inside the argument list",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
required: ["filePath", "line", "character"],
|
|
34
|
+
},
|
|
35
|
+
async execute({ filePath, line, character }) {
|
|
36
|
+
try {
|
|
37
|
+
await fs.access(filePath);
|
|
38
|
+
const result = (await coreLsp.getSignatureHelp(filePath, line, character));
|
|
39
|
+
if (!result || !result.signatures || result.signatures.length === 0) {
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
message: `No signature help available at ${filePath}:${line}:${character}`,
|
|
43
|
+
filePath,
|
|
44
|
+
position: { line, character },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const extractDoc = (doc) => {
|
|
48
|
+
if (!doc)
|
|
49
|
+
return "";
|
|
50
|
+
if (typeof doc === "string")
|
|
51
|
+
return doc;
|
|
52
|
+
return doc.value || "";
|
|
53
|
+
};
|
|
54
|
+
const signatures = result.signatures.map((sig) => ({
|
|
55
|
+
label: sig.label,
|
|
56
|
+
documentation: extractDoc(sig.documentation),
|
|
57
|
+
parameters: (sig.parameters || []).map((param) => ({
|
|
58
|
+
label: typeof param.label === "string" ? param.label : sig.label.slice(param.label[0], param.label[1]),
|
|
59
|
+
documentation: extractDoc(param.documentation),
|
|
60
|
+
})),
|
|
61
|
+
}));
|
|
62
|
+
const activeIndex = result.activeSignature ?? 0;
|
|
63
|
+
const activeSig = signatures[activeIndex] ?? signatures[0];
|
|
64
|
+
return {
|
|
65
|
+
success: true,
|
|
66
|
+
filePath,
|
|
67
|
+
position: { line, character },
|
|
68
|
+
activeSignature: activeIndex,
|
|
69
|
+
activeParameter: result.activeParameter ?? 0,
|
|
70
|
+
signatures,
|
|
71
|
+
activeSignatureLabel: activeSig?.label ?? "",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
const err = error;
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
error: err.message,
|
|
79
|
+
filePath,
|
|
80
|
+
position: { line, character },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
export default getSignatureHelpTool;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
type SupportedLanguage = "javascript" | "typescript" | "python" | "java";
|
|
3
|
+
type SymbolKind = "all" | "function" | "class" | "method" | "variable" | "interface" | "type" | "import" | "export";
|
|
4
|
+
type SymbolMatch = {
|
|
5
|
+
name: string;
|
|
6
|
+
line: number;
|
|
7
|
+
text: string;
|
|
8
|
+
type: string;
|
|
9
|
+
};
|
|
10
|
+
type GetSymbolsParams = {
|
|
11
|
+
filePath: string;
|
|
12
|
+
symbolType?: SymbolKind;
|
|
13
|
+
};
|
|
14
|
+
type GetSymbolsResult = {
|
|
15
|
+
success: true;
|
|
16
|
+
filePath: string;
|
|
17
|
+
language: SupportedLanguage;
|
|
18
|
+
symbolType: SymbolKind;
|
|
19
|
+
totalSymbols: number;
|
|
20
|
+
symbols: Partial<Record<Exclude<SymbolKind, "all">, SymbolMatch[]>>;
|
|
21
|
+
} | {
|
|
22
|
+
success: false;
|
|
23
|
+
error: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Tool for getting symbols (functions, classes, methods, variables) from a file
|
|
27
|
+
* @param {Object} params - The parameters for getting symbols
|
|
28
|
+
* @param {string} params.filePath - The path to the file to analyze
|
|
29
|
+
* @param {string} [params.symbolType] - Type of symbols to find (function, class, method, variable, all)
|
|
30
|
+
* @returns {Promise<Object>} Object containing symbols found or error
|
|
31
|
+
*/
|
|
32
|
+
export declare function getSymbols({ filePath, symbolType, }: GetSymbolsParams): Promise<GetSymbolsResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Tool metadata for agent system
|
|
35
|
+
*/
|
|
36
|
+
export declare const getSymbolsTool: {
|
|
37
|
+
description: string;
|
|
38
|
+
parameters: z.ZodObject<{
|
|
39
|
+
filePath: z.ZodString;
|
|
40
|
+
symbolType: z.ZodDefault<z.ZodEnum<["all", "function", "class", "method", "variable", "interface", "type", "import", "export"]>>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
filePath?: string;
|
|
43
|
+
symbolType?: "function" | "type" | "method" | "class" | "interface" | "variable" | "import" | "export" | "all";
|
|
44
|
+
}, {
|
|
45
|
+
filePath?: string;
|
|
46
|
+
symbolType?: "function" | "type" | "method" | "class" | "interface" | "variable" | "import" | "export" | "all";
|
|
47
|
+
}>;
|
|
48
|
+
execute: typeof getSymbols;
|
|
49
|
+
};
|
|
50
|
+
export default getSymbolsTool;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// Simple code parser for common languages
|
|
5
|
+
const LANGUAGE_PATTERNS = {
|
|
6
|
+
javascript: {
|
|
7
|
+
function: /(?:async\s+)?function\s+(\w+)\s*\(|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s+)?\([^)]*\)\s*=>/g,
|
|
8
|
+
class: /class\s+(\w+)/g,
|
|
9
|
+
method: /(\w+)\s*\([^)]*\)\s*{/g,
|
|
10
|
+
variable: /(?:const|let|var)\s+(\w+)\s*=/g,
|
|
11
|
+
import: /import\s+.*\s+from\s+['"]([^'"]+)['"]/g,
|
|
12
|
+
export: /export\s+(?:default\s+)?(?:class|function|const|let|var)\s+(\w+)/g,
|
|
13
|
+
},
|
|
14
|
+
typescript: {
|
|
15
|
+
function: /(?:async\s+)?function\s+(\w+)\s*\(|(?:const|let|var)\s+(\w+)\s*:\s*\([^)]*\)\s*=>/g,
|
|
16
|
+
class: /class\s+(\w+)/g,
|
|
17
|
+
interface: /interface\s+(\w+)/g,
|
|
18
|
+
type: /type\s+(\w+)\s*=/g,
|
|
19
|
+
method: /(\w+)\s*\([^)]*\)\s*:\s*\w+\s*{/g,
|
|
20
|
+
variable: /(?:const|let|var)\s+(\w+)\s*:/g,
|
|
21
|
+
import: /import\s+.*\s+from\s+['"]([^'"]+)['"]/g,
|
|
22
|
+
export: /export\s+(?:default\s+)?(?:class|function|const|let|var|interface|type)\s+(\w+)/g,
|
|
23
|
+
},
|
|
24
|
+
python: {
|
|
25
|
+
function: /def\s+(\w+)\s*\(/g,
|
|
26
|
+
class: /class\s+(\w+)/g,
|
|
27
|
+
method: /def\s+(\w+)\s*\(self/g,
|
|
28
|
+
import: /(?:from\s+(\S+)\s+)?import\s+(\w+)/g,
|
|
29
|
+
variable: /^(\w+)\s*=/gm,
|
|
30
|
+
},
|
|
31
|
+
java: {
|
|
32
|
+
class: /(?:public\s+)?class\s+(\w+)/g,
|
|
33
|
+
interface: /(?:public\s+)?interface\s+(\w+)/g,
|
|
34
|
+
method: /(?:public|private|protected)\s+(?:\w+\s+)?(\w+)\s*\([^)]*\)\s*{/g,
|
|
35
|
+
import: /import\s+([\w.]+);/g,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Tool for getting symbols (functions, classes, methods, variables) from a file
|
|
40
|
+
* @param {Object} params - The parameters for getting symbols
|
|
41
|
+
* @param {string} params.filePath - The path to the file to analyze
|
|
42
|
+
* @param {string} [params.symbolType] - Type of symbols to find (function, class, method, variable, all)
|
|
43
|
+
* @returns {Promise<Object>} Object containing symbols found or error
|
|
44
|
+
*/
|
|
45
|
+
export async function getSymbols({ filePath, symbolType = "all", }) {
|
|
46
|
+
try {
|
|
47
|
+
// Validate input
|
|
48
|
+
if (!filePath) {
|
|
49
|
+
return {
|
|
50
|
+
success: false,
|
|
51
|
+
error: "File path is required",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Resolve to absolute path
|
|
55
|
+
const absolutePath = path.resolve(filePath);
|
|
56
|
+
// Check if file exists
|
|
57
|
+
try {
|
|
58
|
+
await fs.access(absolutePath, fs.constants.R_OK);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
error: `File not found or not readable: ${filePath}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Detect language from file extension
|
|
67
|
+
const ext = path.extname(absolutePath).slice(1).toLowerCase();
|
|
68
|
+
const languageMap = {
|
|
69
|
+
js: "javascript",
|
|
70
|
+
jsx: "javascript",
|
|
71
|
+
ts: "typescript",
|
|
72
|
+
tsx: "typescript",
|
|
73
|
+
py: "python",
|
|
74
|
+
java: "java",
|
|
75
|
+
// Add more mappings as needed
|
|
76
|
+
};
|
|
77
|
+
const language = languageMap[ext];
|
|
78
|
+
if (!language) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
error: `Unsupported file type: ${ext}. Supported: ${Object.keys(languageMap).join(", ")}`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// Read file content
|
|
85
|
+
const content = await fs.readFile(absolutePath, "utf8");
|
|
86
|
+
const lines = content.split("\n");
|
|
87
|
+
// Get patterns for detected language
|
|
88
|
+
const patterns = LANGUAGE_PATTERNS[language];
|
|
89
|
+
const symbols = {};
|
|
90
|
+
// Extract symbols based on type
|
|
91
|
+
const typesToExtract = symbolType === "all"
|
|
92
|
+
? Object.keys(patterns)
|
|
93
|
+
: [symbolType];
|
|
94
|
+
for (const type of typesToExtract) {
|
|
95
|
+
if (!patterns[type])
|
|
96
|
+
continue;
|
|
97
|
+
const pattern = patterns[type];
|
|
98
|
+
if (!pattern)
|
|
99
|
+
continue;
|
|
100
|
+
const matches = [];
|
|
101
|
+
let match;
|
|
102
|
+
// Reset regex state
|
|
103
|
+
pattern.lastIndex = 0;
|
|
104
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
105
|
+
// Find line number
|
|
106
|
+
const position = match.index;
|
|
107
|
+
const lineNumber = content.substring(0, position).split("\n").length;
|
|
108
|
+
// Get the symbol name (could be in different capture groups)
|
|
109
|
+
const symbolName = match[1] || match[2] || "unknown";
|
|
110
|
+
matches.push({
|
|
111
|
+
name: symbolName,
|
|
112
|
+
line: lineNumber,
|
|
113
|
+
text: lines[lineNumber - 1]?.trim() || "",
|
|
114
|
+
type,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (matches.length > 0) {
|
|
118
|
+
symbols[type] = matches;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Count total symbols
|
|
122
|
+
const totalSymbols = Object.values(symbols).reduce((sum, arr) => sum + arr.length, 0);
|
|
123
|
+
return {
|
|
124
|
+
success: true,
|
|
125
|
+
filePath: absolutePath,
|
|
126
|
+
language,
|
|
127
|
+
symbolType,
|
|
128
|
+
totalSymbols,
|
|
129
|
+
symbols,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
const err = error;
|
|
134
|
+
return {
|
|
135
|
+
success: false,
|
|
136
|
+
error: err.message,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Tool metadata for agent system
|
|
142
|
+
*/
|
|
143
|
+
export const getSymbolsTool = {
|
|
144
|
+
description: "Get symbols (functions, classes, methods, variables) from a code file",
|
|
145
|
+
parameters: z.object({
|
|
146
|
+
filePath: z.string().describe("The path to the file to analyze"),
|
|
147
|
+
symbolType: z
|
|
148
|
+
.enum([
|
|
149
|
+
"all",
|
|
150
|
+
"function",
|
|
151
|
+
"class",
|
|
152
|
+
"method",
|
|
153
|
+
"variable",
|
|
154
|
+
"interface",
|
|
155
|
+
"type",
|
|
156
|
+
"import",
|
|
157
|
+
"export",
|
|
158
|
+
])
|
|
159
|
+
.default("all")
|
|
160
|
+
.describe("Type of symbols to find"),
|
|
161
|
+
}),
|
|
162
|
+
execute: getSymbols,
|
|
163
|
+
};
|
|
164
|
+
export default getSymbolsTool;
|