@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,211 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { glob } from "glob";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { escapeRegExp } from "../../library/regexEscape.js";
|
|
6
|
+
const isProbablyBinary = (data) => {
|
|
7
|
+
if (data.length === 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
// Null bytes are a strong signal for binary data.
|
|
11
|
+
if (data.includes(0)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
const sampleLength = Math.min(data.length, 1024);
|
|
15
|
+
let suspiciousBytes = 0;
|
|
16
|
+
for (let i = 0; i < sampleLength; i++) {
|
|
17
|
+
const byte = data[i];
|
|
18
|
+
const isTab = byte === 9;
|
|
19
|
+
const isNewline = byte === 10;
|
|
20
|
+
const isCarriageReturn = byte === 13;
|
|
21
|
+
const isPrintableAscii = byte >= 32 && byte <= 126;
|
|
22
|
+
if (!isTab && !isNewline && !isCarriageReturn && !isPrintableAscii) {
|
|
23
|
+
suspiciousBytes += 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return suspiciousBytes / sampleLength > 0.3;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Tool for searching text content across files (like grep)
|
|
30
|
+
* @param {Object} params - The parameters for grep search
|
|
31
|
+
* @param {string} params.searchText - The text to search for
|
|
32
|
+
* @param {string} [params.filePattern] - Glob pattern for files to search
|
|
33
|
+
* @param {string} [params.cwd] - Current working directory for search
|
|
34
|
+
* @param {boolean} [params.caseSensitive] - Whether search is case sensitive
|
|
35
|
+
* @param {boolean} [params.regex] - Whether searchText is a regex pattern
|
|
36
|
+
* @param {boolean} [params.includeLineNumbers] - Whether to include line numbers
|
|
37
|
+
* @param {number} [params.contextLines] - Number of context lines to show before/after match
|
|
38
|
+
* @param {number} [params.maxResults] - Maximum number of results to return
|
|
39
|
+
* @returns {Promise<Object>} Object containing success status and search results or error
|
|
40
|
+
*/
|
|
41
|
+
export async function grepSearch({ searchText, filePattern = "**/*", cwd = process.cwd(), caseSensitive = false, regex = false, includeLineNumbers = true, contextLines = 0, maxResults = 100, }) {
|
|
42
|
+
try {
|
|
43
|
+
void includeLineNumbers;
|
|
44
|
+
// Validate input
|
|
45
|
+
if (!searchText) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: "Search text is required",
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Create search pattern
|
|
52
|
+
let searchPattern;
|
|
53
|
+
let note;
|
|
54
|
+
if (regex) {
|
|
55
|
+
try {
|
|
56
|
+
searchPattern = new RegExp(searchText, caseSensitive ? "g" : "gi");
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
void err;
|
|
60
|
+
searchPattern = new RegExp(escapeRegExp(searchText), caseSensitive ? "g" : "gi");
|
|
61
|
+
note =
|
|
62
|
+
"Search text treated as literal text (invalid regex). Use JavaScript regex syntax for regex search.";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const escapedText = escapeRegExp(searchText);
|
|
67
|
+
searchPattern = new RegExp(escapedText, caseSensitive ? "g" : "gi");
|
|
68
|
+
}
|
|
69
|
+
// Find matching files
|
|
70
|
+
const files = await glob(filePattern, {
|
|
71
|
+
cwd,
|
|
72
|
+
absolute: true,
|
|
73
|
+
nodir: true,
|
|
74
|
+
ignore: [
|
|
75
|
+
"**/node_modules/**",
|
|
76
|
+
"**/dist/**",
|
|
77
|
+
"**/build/**",
|
|
78
|
+
"**/.git/**",
|
|
79
|
+
"**/coverage/**",
|
|
80
|
+
"**/.next/**",
|
|
81
|
+
"**/out/**",
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
const results = [];
|
|
85
|
+
let totalMatches = 0;
|
|
86
|
+
let skippedBinaryFiles = 0;
|
|
87
|
+
// Search through each file
|
|
88
|
+
for (const file of files) {
|
|
89
|
+
if (totalMatches >= maxResults)
|
|
90
|
+
break;
|
|
91
|
+
try {
|
|
92
|
+
const rawContent = await fs.readFile(file);
|
|
93
|
+
if (isProbablyBinary(rawContent)) {
|
|
94
|
+
skippedBinaryFiles += 1;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const content = rawContent.toString("utf8");
|
|
98
|
+
const lines = content.split("\n");
|
|
99
|
+
const fileMatches = [];
|
|
100
|
+
for (let i = 0; i < lines.length; i++) {
|
|
101
|
+
if (totalMatches >= maxResults)
|
|
102
|
+
break;
|
|
103
|
+
const line = lines[i];
|
|
104
|
+
const matches = [...line.matchAll(searchPattern)];
|
|
105
|
+
if (matches.length > 0) {
|
|
106
|
+
const match = {
|
|
107
|
+
lineNumber: i + 1,
|
|
108
|
+
line: line,
|
|
109
|
+
matches: matches.map((m) => ({
|
|
110
|
+
text: m[0],
|
|
111
|
+
index: m.index ?? 0,
|
|
112
|
+
})),
|
|
113
|
+
};
|
|
114
|
+
// Add context lines if requested
|
|
115
|
+
if (contextLines > 0) {
|
|
116
|
+
match.before = [];
|
|
117
|
+
match.after = [];
|
|
118
|
+
for (let j = 1; j <= contextLines; j++) {
|
|
119
|
+
if (i - j >= 0) {
|
|
120
|
+
match.before.unshift({
|
|
121
|
+
lineNumber: i - j + 1,
|
|
122
|
+
line: lines[i - j],
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (i + j < lines.length) {
|
|
126
|
+
match.after.push({
|
|
127
|
+
lineNumber: i + j + 1,
|
|
128
|
+
line: lines[i + j],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
fileMatches.push(match);
|
|
134
|
+
totalMatches++;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (fileMatches.length > 0) {
|
|
138
|
+
results.push({
|
|
139
|
+
file: file,
|
|
140
|
+
relativePath: path.relative(cwd, file),
|
|
141
|
+
matchCount: fileMatches.length,
|
|
142
|
+
matches: fileMatches,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
// Skip files that can't be read (binary, etc.)
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
success: true,
|
|
153
|
+
searchText,
|
|
154
|
+
pattern: filePattern,
|
|
155
|
+
caseSensitive,
|
|
156
|
+
regex,
|
|
157
|
+
...(note ? { note } : {}),
|
|
158
|
+
totalFiles: files.length,
|
|
159
|
+
filesWithMatches: results.length,
|
|
160
|
+
totalMatches,
|
|
161
|
+
skippedBinaryFiles,
|
|
162
|
+
results,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
const err = error;
|
|
167
|
+
return {
|
|
168
|
+
success: false,
|
|
169
|
+
error: err.message,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Tool metadata for agent system
|
|
175
|
+
*/
|
|
176
|
+
export const grepSearchTool = {
|
|
177
|
+
description: "Search for text content across files (like grep)",
|
|
178
|
+
parameters: z.object({
|
|
179
|
+
searchText: z.string().describe("The text to search for"),
|
|
180
|
+
filePattern: z
|
|
181
|
+
.string()
|
|
182
|
+
.default("**/*")
|
|
183
|
+
.describe("Glob pattern for files to search"),
|
|
184
|
+
cwd: z
|
|
185
|
+
.string()
|
|
186
|
+
.default(process.cwd())
|
|
187
|
+
.describe("Current working directory for search"),
|
|
188
|
+
caseSensitive: z
|
|
189
|
+
.boolean()
|
|
190
|
+
.default(false)
|
|
191
|
+
.describe("Whether search is case sensitive"),
|
|
192
|
+
regex: z
|
|
193
|
+
.boolean()
|
|
194
|
+
.default(false)
|
|
195
|
+
.describe("Whether searchText is a regex pattern"),
|
|
196
|
+
includeLineNumbers: z
|
|
197
|
+
.boolean()
|
|
198
|
+
.default(true)
|
|
199
|
+
.describe("Whether to include line numbers"),
|
|
200
|
+
contextLines: z
|
|
201
|
+
.number()
|
|
202
|
+
.default(0)
|
|
203
|
+
.describe("Number of context lines to show before/after match"),
|
|
204
|
+
maxResults: z
|
|
205
|
+
.number()
|
|
206
|
+
.default(100)
|
|
207
|
+
.describe("Maximum number of results to return"),
|
|
208
|
+
}),
|
|
209
|
+
execute: grepSearch,
|
|
210
|
+
};
|
|
211
|
+
export default grepSearchTool;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language Model Tools Integration
|
|
3
|
+
* Initializes and manages the language model tools system for Iris
|
|
4
|
+
*/
|
|
5
|
+
import type { McpServerConfig } from "../../library/mcpSettings.js";
|
|
6
|
+
/**
|
|
7
|
+
* Initialize language model tools system
|
|
8
|
+
*/
|
|
9
|
+
export declare function initializeLanguageModelTools(mcpServers: McpServerConfig[], workspacePath: string | null): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Get all available tools
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAvailableTools(): Promise<import("../../library/languageModelTools.js").LanguageModelToolInformation[]>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language Model Tools Integration
|
|
3
|
+
* Initializes and manages the language model tools system for Iris
|
|
4
|
+
*/
|
|
5
|
+
import { languageModelTools } from "../../library/languageModelTools.js";
|
|
6
|
+
import { createDefaultProvider } from "../../library/mcpServerProvider.js";
|
|
7
|
+
/**
|
|
8
|
+
* Initialize language model tools system
|
|
9
|
+
*/
|
|
10
|
+
export async function initializeLanguageModelTools(mcpServers, workspacePath) {
|
|
11
|
+
// Set workspace path
|
|
12
|
+
languageModelTools.setWorkspacePath(workspacePath);
|
|
13
|
+
// Register MCP server provider
|
|
14
|
+
const mcpProvider = createDefaultProvider(mcpServers);
|
|
15
|
+
languageModelTools.registerMcpServerDefinitionProvider("iris.default", mcpProvider);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get all available tools
|
|
19
|
+
*/
|
|
20
|
+
export async function getAvailableTools() {
|
|
21
|
+
return languageModelTools.getAvailableTools();
|
|
22
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
type ListDirectoryParams = {
|
|
3
|
+
dirPath: string;
|
|
4
|
+
recursive?: boolean;
|
|
5
|
+
includeHidden?: boolean;
|
|
6
|
+
maxDepth?: number;
|
|
7
|
+
};
|
|
8
|
+
type DirectoryItem = {
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
relativePath: string;
|
|
12
|
+
type: "directory" | "file";
|
|
13
|
+
size: number;
|
|
14
|
+
modified: Date;
|
|
15
|
+
created: Date;
|
|
16
|
+
depth: number;
|
|
17
|
+
};
|
|
18
|
+
type ListDirectorySuccessResult = {
|
|
19
|
+
success: true;
|
|
20
|
+
dirPath: string;
|
|
21
|
+
totalItems: number;
|
|
22
|
+
fileCount: number;
|
|
23
|
+
directoryCount: number;
|
|
24
|
+
contents: DirectoryItem[];
|
|
25
|
+
files: DirectoryItem[];
|
|
26
|
+
directories: DirectoryItem[];
|
|
27
|
+
};
|
|
28
|
+
type ListDirectoryErrorResult = {
|
|
29
|
+
success: false;
|
|
30
|
+
error: string;
|
|
31
|
+
};
|
|
32
|
+
type ListDirectoryResult = ListDirectorySuccessResult | ListDirectoryErrorResult;
|
|
33
|
+
/**
|
|
34
|
+
* Tool for listing directory contents
|
|
35
|
+
* @param {Object} params - The parameters for listing a directory
|
|
36
|
+
* @param {string} params.dirPath - The path to the directory to list
|
|
37
|
+
* @param {boolean} [params.recursive=false] - Whether to list recursively
|
|
38
|
+
* @param {boolean} [params.includeHidden=false] - Whether to include hidden files
|
|
39
|
+
* @param {number} [params.maxDepth=3] - Maximum depth for recursive listing
|
|
40
|
+
* @returns {Promise<Object>} Object containing success status and directory contents or error
|
|
41
|
+
*/
|
|
42
|
+
export declare function listDirectory({ dirPath, recursive, includeHidden, maxDepth, }: ListDirectoryParams): Promise<ListDirectoryResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Tool metadata for agent system
|
|
45
|
+
*/
|
|
46
|
+
export declare const listDirectoryTool: {
|
|
47
|
+
description: string;
|
|
48
|
+
parameters: z.ZodObject<{
|
|
49
|
+
dirPath: z.ZodString;
|
|
50
|
+
recursive: z.ZodDefault<z.ZodBoolean>;
|
|
51
|
+
includeHidden: z.ZodDefault<z.ZodBoolean>;
|
|
52
|
+
maxDepth: z.ZodDefault<z.ZodNumber>;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
maxDepth?: number;
|
|
55
|
+
recursive?: boolean;
|
|
56
|
+
dirPath?: string;
|
|
57
|
+
includeHidden?: boolean;
|
|
58
|
+
}, {
|
|
59
|
+
maxDepth?: number;
|
|
60
|
+
recursive?: boolean;
|
|
61
|
+
dirPath?: string;
|
|
62
|
+
includeHidden?: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
execute: typeof listDirectory;
|
|
65
|
+
};
|
|
66
|
+
export default listDirectoryTool;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/**
|
|
5
|
+
* Tool for listing directory contents
|
|
6
|
+
* @param {Object} params - The parameters for listing a directory
|
|
7
|
+
* @param {string} params.dirPath - The path to the directory to list
|
|
8
|
+
* @param {boolean} [params.recursive=false] - Whether to list recursively
|
|
9
|
+
* @param {boolean} [params.includeHidden=false] - Whether to include hidden files
|
|
10
|
+
* @param {number} [params.maxDepth=3] - Maximum depth for recursive listing
|
|
11
|
+
* @returns {Promise<Object>} Object containing success status and directory contents or error
|
|
12
|
+
*/
|
|
13
|
+
export async function listDirectory({ dirPath, recursive = false, includeHidden = false, maxDepth = 3, }) {
|
|
14
|
+
try {
|
|
15
|
+
// Validate input
|
|
16
|
+
if (!dirPath) {
|
|
17
|
+
return {
|
|
18
|
+
success: false,
|
|
19
|
+
error: "Directory path is required",
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
// Resolve to absolute path
|
|
23
|
+
const absolutePath = path.resolve(dirPath);
|
|
24
|
+
// Check if directory exists
|
|
25
|
+
try {
|
|
26
|
+
await fs.access(absolutePath, fs.constants.R_OK);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
return {
|
|
30
|
+
success: false,
|
|
31
|
+
error: `Directory not found or not readable: ${dirPath}`,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// Check if it's a directory
|
|
35
|
+
const stats = await fs.stat(absolutePath);
|
|
36
|
+
if (!stats.isDirectory()) {
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
error: `Path is not a directory: ${dirPath}`,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// List directory contents using BFS for better performance
|
|
43
|
+
const listDir = async () => {
|
|
44
|
+
if (!recursive) {
|
|
45
|
+
// Non-recursive: simple single-level listing
|
|
46
|
+
const entries = await fs.readdir(absolutePath, { withFileTypes: true });
|
|
47
|
+
const items = [];
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
if (!includeHidden && entry.name.startsWith(".")) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const fullPath = path.join(absolutePath, entry.name);
|
|
53
|
+
const relativePath = path.relative(absolutePath, fullPath);
|
|
54
|
+
const itemStats = await fs.stat(fullPath);
|
|
55
|
+
items.push({
|
|
56
|
+
name: entry.name,
|
|
57
|
+
path: fullPath,
|
|
58
|
+
relativePath,
|
|
59
|
+
type: entry.isDirectory() ? "directory" : "file",
|
|
60
|
+
size: itemStats.size,
|
|
61
|
+
modified: itemStats.mtime,
|
|
62
|
+
created: itemStats.birthtime,
|
|
63
|
+
depth: 0,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return items;
|
|
67
|
+
}
|
|
68
|
+
// Recursive: use BFS with queue (more efficient than DFS recursion)
|
|
69
|
+
const items = [];
|
|
70
|
+
const queue = [[absolutePath, 0]]; // [path, depth]
|
|
71
|
+
while (queue.length > 0) {
|
|
72
|
+
const next = queue.shift();
|
|
73
|
+
if (!next) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const [currentPath, currentDepth] = next;
|
|
77
|
+
// Stop if max depth reached
|
|
78
|
+
if (currentDepth > maxDepth)
|
|
79
|
+
continue;
|
|
80
|
+
try {
|
|
81
|
+
const entries = await fs.readdir(currentPath, {
|
|
82
|
+
withFileTypes: true,
|
|
83
|
+
});
|
|
84
|
+
for (const entry of entries) {
|
|
85
|
+
if (!includeHidden && entry.name.startsWith(".")) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const fullPath = path.join(currentPath, entry.name);
|
|
89
|
+
const relativePath = path.relative(absolutePath, fullPath);
|
|
90
|
+
const itemStats = await fs.stat(fullPath);
|
|
91
|
+
const item = {
|
|
92
|
+
name: entry.name,
|
|
93
|
+
path: fullPath,
|
|
94
|
+
relativePath,
|
|
95
|
+
type: entry.isDirectory() ? "directory" : "file",
|
|
96
|
+
size: itemStats.size,
|
|
97
|
+
modified: itemStats.mtime,
|
|
98
|
+
created: itemStats.birthtime,
|
|
99
|
+
depth: currentDepth,
|
|
100
|
+
};
|
|
101
|
+
items.push(item);
|
|
102
|
+
// Add subdirectories to queue for exploration
|
|
103
|
+
if (entry.isDirectory()) {
|
|
104
|
+
queue.push([fullPath, currentDepth + 1]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
const error = err;
|
|
110
|
+
// Skip directories we can't read
|
|
111
|
+
console.error(`Cannot read directory ${currentPath}:`, error.message || String(err) || "Unknown error");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return items;
|
|
115
|
+
};
|
|
116
|
+
const contents = await listDir();
|
|
117
|
+
// Separate files and directories
|
|
118
|
+
const files = contents.filter((item) => item.type === "file");
|
|
119
|
+
const directories = contents.filter((item) => item.type === "directory");
|
|
120
|
+
return {
|
|
121
|
+
success: true,
|
|
122
|
+
dirPath: absolutePath,
|
|
123
|
+
totalItems: contents.length,
|
|
124
|
+
fileCount: files.length,
|
|
125
|
+
directoryCount: directories.length,
|
|
126
|
+
contents,
|
|
127
|
+
files,
|
|
128
|
+
directories,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
const err = error;
|
|
133
|
+
return {
|
|
134
|
+
success: false,
|
|
135
|
+
error: err.message,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Tool metadata for agent system
|
|
141
|
+
*/
|
|
142
|
+
export const listDirectoryTool = {
|
|
143
|
+
description: "List the contents of a directory, optionally recursively",
|
|
144
|
+
parameters: z.object({
|
|
145
|
+
dirPath: z.string().describe("The path to the directory to list"),
|
|
146
|
+
recursive: z
|
|
147
|
+
.boolean()
|
|
148
|
+
.default(false)
|
|
149
|
+
.describe("Whether to list recursively"),
|
|
150
|
+
includeHidden: z
|
|
151
|
+
.boolean()
|
|
152
|
+
.default(false)
|
|
153
|
+
.describe("Whether to include hidden files (starting with .)"),
|
|
154
|
+
maxDepth: z
|
|
155
|
+
.number()
|
|
156
|
+
.default(3)
|
|
157
|
+
.describe("Maximum depth for recursive listing"),
|
|
158
|
+
}),
|
|
159
|
+
execute: listDirectory,
|
|
160
|
+
};
|
|
161
|
+
export default listDirectoryTool;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { McpServerConfig } from "../../library/mcpSettings.js";
|
|
2
|
+
type McpToolDefinition = {
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
inputSchema?: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
export type McpToolSummary = {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const toMcpToolKey: (serverName: string, toolName: string) => string;
|
|
12
|
+
export declare const validateMcpToolInput: (toolName: string, inputSchema: Record<string, unknown> | undefined, params: Record<string, unknown>) => string | null;
|
|
13
|
+
export declare const summarizeMcpToolError: (result: {
|
|
14
|
+
isError?: boolean;
|
|
15
|
+
content?: unknown;
|
|
16
|
+
structuredContent?: unknown;
|
|
17
|
+
}) => string | undefined;
|
|
18
|
+
export declare const listMcpServerTools: (server: McpServerConfig, workspacePath: string) => Promise<McpToolDefinition[]>;
|
|
19
|
+
export declare const executeMcpToolByKey: (servers: McpServerConfig[], workspacePath: string, toolKey: string, input: Record<string, unknown>) => Promise<{
|
|
20
|
+
success: boolean;
|
|
21
|
+
server: string;
|
|
22
|
+
tool: string;
|
|
23
|
+
isError: boolean;
|
|
24
|
+
content: unknown;
|
|
25
|
+
structuredContent: unknown;
|
|
26
|
+
error: string;
|
|
27
|
+
} | {
|
|
28
|
+
success: boolean;
|
|
29
|
+
server: string;
|
|
30
|
+
tool: string;
|
|
31
|
+
isError: boolean;
|
|
32
|
+
error: string;
|
|
33
|
+
content?: undefined;
|
|
34
|
+
structuredContent?: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
success: boolean;
|
|
37
|
+
isError: boolean;
|
|
38
|
+
error: string;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Generate MCP tools documentation for persistence in knowledge base.
|
|
42
|
+
* Only includes servers that are connected and available.
|
|
43
|
+
* Returns tool metadata that can be stored in the workspace for semantic search.
|
|
44
|
+
* Returns null if no connected servers with tools are available.
|
|
45
|
+
*/
|
|
46
|
+
export declare const generateMcpToolsDocs: (servers: McpServerConfig[], workspacePath: string) => Promise<string | null>;
|
|
47
|
+
export declare const buildMcpTools: (servers: McpServerConfig[], workspacePath: string) => Promise<Record<string, unknown>>;
|
|
48
|
+
export {};
|