@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.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -0
  3. package/dist/api/acp/acpServer.d.ts +23 -0
  4. package/dist/api/acp/acpServer.js +814 -0
  5. package/dist/api/acp/index.d.ts +2 -0
  6. package/dist/api/acp/index.js +2 -0
  7. package/dist/api/acp/irisClient.d.ts +58 -0
  8. package/dist/api/acp/irisClient.js +214 -0
  9. package/dist/api/agent.d.ts +14 -0
  10. package/dist/api/agent.js +4171 -0
  11. package/dist/api/backendService.d.ts +4 -0
  12. package/dist/api/backendService.js +14 -0
  13. package/dist/api/core/agent/host/AgentContract.d.ts +82 -0
  14. package/dist/api/core/agent/host/AgentContract.js +1 -0
  15. package/dist/api/core/agent/host/AgentRegistry.d.ts +24 -0
  16. package/dist/api/core/agent/host/AgentRegistry.js +125 -0
  17. package/dist/api/core/agent/host/defaultRegistry.d.ts +15 -0
  18. package/dist/api/core/agent/host/defaultRegistry.js +46 -0
  19. package/dist/api/core/agent/host/externalAgentLifecycle.d.ts +65 -0
  20. package/dist/api/core/agent/host/externalAgentLifecycle.js +117 -0
  21. package/dist/api/core/agent/host/hostSessionManager.d.ts +111 -0
  22. package/dist/api/core/agent/host/hostSessionManager.js +352 -0
  23. package/dist/api/core/agent/host/index.d.ts +5 -0
  24. package/dist/api/core/agent/host/index.js +5 -0
  25. package/dist/api/core/agent/index.d.ts +87 -0
  26. package/dist/api/core/agent/index.js +1024 -0
  27. package/dist/api/core/agent/publicContracts.d.ts +35 -0
  28. package/dist/api/core/agent/publicContracts.js +103 -0
  29. package/dist/api/core/agent/tools/applyDiff.d.ts +51 -0
  30. package/dist/api/core/agent/tools/applyDiff.js +131 -0
  31. package/dist/api/core/agent/tools/backgroundTasks.d.ts +240 -0
  32. package/dist/api/core/agent/tools/backgroundTasks.js +313 -0
  33. package/dist/api/core/agent/tools/createDirectory.d.ts +43 -0
  34. package/dist/api/core/agent/tools/createDirectory.js +77 -0
  35. package/dist/api/core/agent/tools/deleteFile.d.ts +37 -0
  36. package/dist/api/core/agent/tools/deleteFile.js +66 -0
  37. package/dist/api/core/agent/tools/editFile.d.ts +73 -0
  38. package/dist/api/core/agent/tools/editFile.js +173 -0
  39. package/dist/api/core/agent/tools/executeCommand.d.ts +59 -0
  40. package/dist/api/core/agent/tools/executeCommand.js +250 -0
  41. package/dist/api/core/agent/tools/fileContent.d.ts +54 -0
  42. package/dist/api/core/agent/tools/fileContent.js +227 -0
  43. package/dist/api/core/agent/tools/findDefinition.d.ts +72 -0
  44. package/dist/api/core/agent/tools/findDefinition.js +109 -0
  45. package/dist/api/core/agent/tools/findReferences.d.ts +86 -0
  46. package/dist/api/core/agent/tools/findReferences.js +135 -0
  47. package/dist/api/core/agent/tools/formatDocument.d.ts +67 -0
  48. package/dist/api/core/agent/tools/formatDocument.js +90 -0
  49. package/dist/api/core/agent/tools/getCodeActions.d.ts +77 -0
  50. package/dist/api/core/agent/tools/getCodeActions.js +97 -0
  51. package/dist/api/core/agent/tools/getCodeCompletion.d.ts +77 -0
  52. package/dist/api/core/agent/tools/getCodeCompletion.js +174 -0
  53. package/dist/api/core/agent/tools/getCodeContext.d.ts +14 -0
  54. package/dist/api/core/agent/tools/getCodeContext.js +282 -0
  55. package/dist/api/core/agent/tools/getSignatureHelp.d.ts +61 -0
  56. package/dist/api/core/agent/tools/getSignatureHelp.js +85 -0
  57. package/dist/api/core/agent/tools/getSymbols.d.ts +50 -0
  58. package/dist/api/core/agent/tools/getSymbols.js +164 -0
  59. package/dist/api/core/agent/tools/getSymbolsLSP.d.ts +58 -0
  60. package/dist/api/core/agent/tools/getSymbolsLSP.js +147 -0
  61. package/dist/api/core/agent/tools/getTypeInfo.d.ts +70 -0
  62. package/dist/api/core/agent/tools/getTypeInfo.js +84 -0
  63. package/dist/api/core/agent/tools/getWorkspaceInfo.d.ts +80 -0
  64. package/dist/api/core/agent/tools/getWorkspaceInfo.js +281 -0
  65. package/dist/api/core/agent/tools/getWorkspaceSymbols.d.ts +53 -0
  66. package/dist/api/core/agent/tools/getWorkspaceSymbols.js +97 -0
  67. package/dist/api/core/agent/tools/grepSearch.d.ts +100 -0
  68. package/dist/api/core/agent/tools/grepSearch.js +211 -0
  69. package/dist/api/core/agent/tools/languageModelToolsIntegration.d.ts +13 -0
  70. package/dist/api/core/agent/tools/languageModelToolsIntegration.js +22 -0
  71. package/dist/api/core/agent/tools/listDirectory.d.ts +66 -0
  72. package/dist/api/core/agent/tools/listDirectory.js +161 -0
  73. package/dist/api/core/agent/tools/mcpTools.d.ts +48 -0
  74. package/dist/api/core/agent/tools/mcpTools.js +442 -0
  75. package/dist/api/core/agent/tools/queryKnowledgeGraph.d.ts +120 -0
  76. package/dist/api/core/agent/tools/queryKnowledgeGraph.js +306 -0
  77. package/dist/api/core/agent/tools/readFile.d.ts +92 -0
  78. package/dist/api/core/agent/tools/readFile.js +337 -0
  79. package/dist/api/core/agent/tools/renameFile.d.ts +49 -0
  80. package/dist/api/core/agent/tools/renameFile.js +86 -0
  81. package/dist/api/core/agent/tools/renameSymbol.d.ts +70 -0
  82. package/dist/api/core/agent/tools/renameSymbol.js +106 -0
  83. package/dist/api/core/agent/tools/runTerminalCommand.d.ts +72 -0
  84. package/dist/api/core/agent/tools/runTerminalCommand.js +69 -0
  85. package/dist/api/core/agent/tools/searchFiles.d.ts +82 -0
  86. package/dist/api/core/agent/tools/searchFiles.js +280 -0
  87. package/dist/api/core/agent/tools/terminalAutoApprove.d.ts +3 -0
  88. package/dist/api/core/agent/tools/terminalAutoApprove.js +676 -0
  89. package/dist/api/core/agent/tools/treeTraversal.d.ts +60 -0
  90. package/dist/api/core/agent/tools/treeTraversal.js +217 -0
  91. package/dist/api/core/agent/tools/webSearch.d.ts +37 -0
  92. package/dist/api/core/agent/tools/webSearch.js +80 -0
  93. package/dist/api/core/agent/tools/writeFile.d.ts +59 -0
  94. package/dist/api/core/agent/tools/writeFile.js +97 -0
  95. package/dist/api/core/agent/utils/capturedWorkspaceMutationBridge.d.ts +12 -0
  96. package/dist/api/core/agent/utils/capturedWorkspaceMutationBridge.js +67 -0
  97. package/dist/api/core/agent/utils/diffUtils.d.ts +14 -0
  98. package/dist/api/core/agent/utils/diffUtils.js +39 -0
  99. package/dist/api/core/agent/utils/environmentSnapshot.d.ts +42 -0
  100. package/dist/api/core/agent/utils/environmentSnapshot.js +213 -0
  101. package/dist/api/core/agent/utils/errorRecovery.d.ts +49 -0
  102. package/dist/api/core/agent/utils/errorRecovery.js +229 -0
  103. package/dist/api/core/agent/utils/multimodalTokenLimiter.d.ts +8 -0
  104. package/dist/api/core/agent/utils/multimodalTokenLimiter.js +238 -0
  105. package/dist/api/core/agent/utils/openRouterModelSettings.d.ts +12 -0
  106. package/dist/api/core/agent/utils/openRouterModelSettings.js +34 -0
  107. package/dist/api/core/agent/utils/pathRecovery.d.ts +1 -0
  108. package/dist/api/core/agent/utils/pathRecovery.js +29 -0
  109. package/dist/api/core/agent/utils/repoMapIndex.d.ts +3 -0
  110. package/dist/api/core/agent/utils/repoMapIndex.js +197 -0
  111. package/dist/api/core/agent/utils/skillsDiscovery.d.ts +10 -0
  112. package/dist/api/core/agent/utils/skillsDiscovery.js +50 -0
  113. package/dist/api/core/agent/utils/toolCallBudget.d.ts +9 -0
  114. package/dist/api/core/agent/utils/toolCallBudget.js +55 -0
  115. package/dist/api/core/agent/utils/toolLifecycle.d.ts +30 -0
  116. package/dist/api/core/agent/utils/toolLifecycle.js +361 -0
  117. package/dist/api/core/agent/utils/toolResultSafetyProcessor.d.ts +12 -0
  118. package/dist/api/core/agent/utils/toolResultSafetyProcessor.js +57 -0
  119. package/dist/api/core/agent/utils/workspaceMutationBridge.d.ts +13 -0
  120. package/dist/api/core/agent/utils/workspaceMutationBridge.js +149 -0
  121. package/dist/api/core/agent/utils/workspacePathGuard.d.ts +7 -0
  122. package/dist/api/core/agent/utils/workspacePathGuard.js +79 -0
  123. package/dist/api/core/containers/chat/toolResultSerialization.d.ts +8 -0
  124. package/dist/api/core/containers/chat/toolResultSerialization.js +71 -0
  125. package/dist/api/core/library/BrowserManager.d.ts +11 -0
  126. package/dist/api/core/library/BrowserManager.js +66 -0
  127. package/dist/api/core/library/desktopWorkspace.d.ts +1 -0
  128. package/dist/api/core/library/desktopWorkspace.js +3 -0
  129. package/dist/api/core/library/extensionManager.d.ts +10 -0
  130. package/dist/api/core/library/extensionManager.js +27 -0
  131. package/dist/api/core/library/knowledgeGraph.d.ts +268 -0
  132. package/dist/api/core/library/knowledgeGraph.js +989 -0
  133. package/dist/api/core/library/languageModelTools.d.ts +141 -0
  134. package/dist/api/core/library/languageModelTools.js +207 -0
  135. package/dist/api/core/library/localRuntime.d.ts +23 -0
  136. package/dist/api/core/library/localRuntime.js +144 -0
  137. package/dist/api/core/library/lsp/coreLsp.d.ts +367 -0
  138. package/dist/api/core/library/lsp/coreLsp.js +2076 -0
  139. package/dist/api/core/library/lsp/protocol.d.ts +25 -0
  140. package/dist/api/core/library/lsp/protocol.js +1 -0
  141. package/dist/api/core/library/lsp/serverManager.d.ts +37 -0
  142. package/dist/api/core/library/lsp/serverManager.js +427 -0
  143. package/dist/api/core/library/mcpServerProvider.d.ts +69 -0
  144. package/dist/api/core/library/mcpServerProvider.js +152 -0
  145. package/dist/api/core/library/mcpSettings.d.ts +20 -0
  146. package/dist/api/core/library/mcpSettings.js +131 -0
  147. package/dist/api/core/library/patternMatcher.d.ts +66 -0
  148. package/dist/api/core/library/patternMatcher.js +284 -0
  149. package/dist/api/core/library/regexEscape.d.ts +4 -0
  150. package/dist/api/core/library/regexEscape.js +4 -0
  151. package/dist/api/core/library/runtimeEventBus.d.ts +27 -0
  152. package/dist/api/core/library/runtimeEventBus.js +78 -0
  153. package/dist/api/core/library/safetyMiddleware.d.ts +98 -0
  154. package/dist/api/core/library/safetyMiddleware.js +215 -0
  155. package/dist/api/core/library/tauri.d.ts +71 -0
  156. package/dist/api/core/library/tauri.js +222 -0
  157. package/dist/api/core/library/tauriImport.d.ts +5 -0
  158. package/dist/api/core/library/tauriImport.js +7 -0
  159. package/dist/api/core/library/terminalAutoApproveSettings.d.ts +32 -0
  160. package/dist/api/core/library/terminalAutoApproveSettings.js +529 -0
  161. package/dist/api/core/library/workspaceIdentity.d.ts +10 -0
  162. package/dist/api/core/library/workspaceIdentity.js +49 -0
  163. package/dist/api/core/library/workspaceSummary.d.ts +19 -0
  164. package/dist/api/core/library/workspaceSummary.js +35 -0
  165. package/dist/api/core/skills/agent-customization/SKILL.md +27 -0
  166. package/dist/api/core/skills/bug-fix/SKILL.md +21 -0
  167. package/dist/api/core/skills/create-pr/SKILL.md +32 -0
  168. package/dist/api/core/skills/dev-server/SKILL.md +20 -0
  169. package/dist/api/core/skills/fix-suggestions/SKILL.md +21 -0
  170. package/dist/api/core/skills/github-search/SKILL.md +21 -0
  171. package/dist/api/core/skills/github-summary/SKILL.md +25 -0
  172. package/dist/api/core/skills/integration-tests/SKILL.md +29 -0
  173. package/dist/api/core/skills/pr-comments/SKILL.md +23 -0
  174. package/dist/api/core/skills/project-setup/SKILL.md +20 -0
  175. package/dist/api/core/skills/search-integration/SKILL.md +19 -0
  176. package/dist/api/core/skills/search-results/SKILL.md +19 -0
  177. package/dist/api/core/skills/typescript-upgrade/SKILL.md +21 -0
  178. package/dist/api/data/runStore.d.ts +46 -0
  179. package/dist/api/data/runStore.js +244 -0
  180. package/dist/api/helpers/agentUtils.d.ts +11 -0
  181. package/dist/api/helpers/agentUtils.js +23 -0
  182. package/dist/api/helpers/modelTokenLimits.d.ts +2 -0
  183. package/dist/api/helpers/modelTokenLimits.js +158 -0
  184. package/dist/api/helpers/observationalMemory.d.ts +10 -0
  185. package/dist/api/helpers/observationalMemory.js +36 -0
  186. package/dist/api/helpers/promptBudget.d.ts +30 -0
  187. package/dist/api/helpers/promptBudget.js +216 -0
  188. package/dist/api/helpers/resolveImageMessageParts.d.ts +9 -0
  189. package/dist/api/helpers/resolveImageMessageParts.js +140 -0
  190. package/dist/api/helpers/slashCommands.d.ts +31 -0
  191. package/dist/api/helpers/slashCommands.js +129 -0
  192. package/dist/api/helpers/tokenUsage.d.ts +19 -0
  193. package/dist/api/helpers/tokenUsage.js +81 -0
  194. package/dist/api/routes/fileRoutes.d.ts +2 -0
  195. package/dist/api/routes/fileRoutes.js +108 -0
  196. package/dist/api/routes/lspDocumentRoutes.d.ts +4 -0
  197. package/dist/api/routes/lspDocumentRoutes.js +84 -0
  198. package/dist/api/routes/lspHierarchyRoutes.d.ts +4 -0
  199. package/dist/api/routes/lspHierarchyRoutes.js +122 -0
  200. package/dist/api/routes/lspPositionRoutes.d.ts +4 -0
  201. package/dist/api/routes/lspPositionRoutes.js +263 -0
  202. package/dist/api/routes/lspQueryRoutes.d.ts +4 -0
  203. package/dist/api/routes/lspQueryRoutes.js +679 -0
  204. package/dist/api/routes/lspResolveRoutes.d.ts +4 -0
  205. package/dist/api/routes/lspResolveRoutes.js +143 -0
  206. package/dist/api/routes/lspSemanticDocumentRoutes.d.ts +4 -0
  207. package/dist/api/routes/lspSemanticDocumentRoutes.js +98 -0
  208. package/dist/api/routes/semanticRoutes.d.ts +2 -0
  209. package/dist/api/routes/semanticRoutes.js +126 -0
  210. package/dist/cli.d.ts +8 -0
  211. package/dist/cli.js +160 -0
  212. package/dist/index.d.ts +1 -0
  213. package/dist/index.js +1 -0
  214. package/dist/server.d.ts +2 -0
  215. package/dist/server.js +38 -0
  216. package/package.json +100 -0
@@ -0,0 +1,306 @@
1
+ import { z } from "zod";
2
+ import { knowledgeGraph, } from "../../library/knowledgeGraph.js";
3
+ const getNodeDisplayName = (id, name) => name ?? id.split(":").pop() ?? id;
4
+ /**
5
+ * Query the knowledge graph for code insights
6
+ * @param {Object} params
7
+ * @param {string} params.filePath - The file path to query
8
+ * @param {string} [params.queryType] - Type of query: 'summary', 'relationships', 'components', 'related-files'
9
+ * @returns {Promise<Object>} Query results from knowledge graph
10
+ */
11
+ export async function queryKnowledgeGraph({ filePath, queryType = "summary", question, maxDepth = 2, maxTokens = 4000, }) {
12
+ try {
13
+ if (queryType === "stats") {
14
+ return {
15
+ success: true,
16
+ filePath: "<graph>",
17
+ queryType,
18
+ data: knowledgeGraph.getStatistics(),
19
+ };
20
+ }
21
+ if (queryType === "question") {
22
+ if (!question) {
23
+ return {
24
+ success: false,
25
+ error: "Question is required when queryType is 'question'",
26
+ };
27
+ }
28
+ const context = knowledgeGraph.queryByQuestion({
29
+ question,
30
+ anchorId: filePath,
31
+ maxDepth,
32
+ maxTokens,
33
+ });
34
+ const anchorNodeIds = context.retrieval?.anchorNodeIds || [];
35
+ const anchorNodes = anchorNodeIds
36
+ .map((id) => knowledgeGraph.nodes.get(id))
37
+ .filter((node) => Boolean(node))
38
+ .map((node) => ({
39
+ id: node.id,
40
+ type: node.type,
41
+ name: getNodeDisplayName(node.id, node.metadata.name),
42
+ }));
43
+ return {
44
+ success: true,
45
+ filePath: filePath || "<question>",
46
+ queryType,
47
+ data: {
48
+ question,
49
+ matchedTerms: context.retrieval?.matchedTerms || [],
50
+ anchorNodes,
51
+ nodeCount: context.nodes.length,
52
+ tokenCount: context.tokenCount,
53
+ contextPreview: context.contextText.slice(0, 2000),
54
+ },
55
+ };
56
+ }
57
+ if (!filePath) {
58
+ return {
59
+ success: false,
60
+ error: "File path is required for this query type",
61
+ };
62
+ }
63
+ const node = knowledgeGraph.nodes.get(filePath);
64
+ if (!node) {
65
+ return {
66
+ success: false,
67
+ error: `File not found in knowledge graph: ${filePath}. Make sure to read the file first.`,
68
+ };
69
+ }
70
+ let result;
71
+ switch (queryType) {
72
+ case "summary":
73
+ result = getFileSummary(filePath, node);
74
+ break;
75
+ case "relationships":
76
+ result = getRelationships(filePath, node);
77
+ break;
78
+ case "components":
79
+ result = getComponents(filePath);
80
+ break;
81
+ case "related-files":
82
+ result = getRelatedFiles(filePath, node);
83
+ break;
84
+ default:
85
+ result = getFileSummary(filePath, node);
86
+ }
87
+ return {
88
+ success: true,
89
+ filePath,
90
+ queryType,
91
+ data: result,
92
+ };
93
+ }
94
+ catch (error) {
95
+ const err = error;
96
+ return {
97
+ success: false,
98
+ error: err.message,
99
+ };
100
+ }
101
+ }
102
+ /**
103
+ * Get file summary with basic info
104
+ */
105
+ function getFileSummary(filePath, node) {
106
+ const components = [];
107
+ knowledgeGraph.nodes.forEach((n) => {
108
+ if (n.metadata.filePath === filePath && n.id !== filePath) {
109
+ components.push({
110
+ type: n.type,
111
+ name: String(getNodeDisplayName(n.id, n.metadata.name)),
112
+ line: n.metadata.startLine,
113
+ tokenCount: n.tokenCount,
114
+ });
115
+ }
116
+ });
117
+ return {
118
+ fileName: node.metadata.name,
119
+ language: node.metadata.language,
120
+ tokenCount: node.tokenCount,
121
+ accessCount: node.accessCount,
122
+ lastAccessed: new Date(node.lastAccessed).toLocaleString(),
123
+ componentCount: components.length,
124
+ components,
125
+ relationshipCount: node.relationships.size,
126
+ };
127
+ }
128
+ /**
129
+ * Get all relationships for a file
130
+ */
131
+ function getRelationships(filePath, node) {
132
+ const relationships = {
133
+ imports: [],
134
+ exports: [],
135
+ calls: [],
136
+ usedBy: [],
137
+ contains: [],
138
+ };
139
+ // Direct relationships
140
+ node.relationships.forEach(({ nodeId, type, metadata }) => {
141
+ const relNode = knowledgeGraph.nodes.get(nodeId);
142
+ const relInfo = {
143
+ nodeId,
144
+ type,
145
+ name: String(getNodeDisplayName(nodeId, relNode?.metadata?.name)),
146
+ metadata,
147
+ };
148
+ if (type === "imports") {
149
+ relationships.imports.push(relInfo);
150
+ }
151
+ else if (type === "contains") {
152
+ relationships.contains.push(relInfo);
153
+ }
154
+ else if (type === "calls") {
155
+ relationships.calls.push(relInfo);
156
+ }
157
+ });
158
+ // Reverse relationships (files that import this)
159
+ knowledgeGraph.nodes.forEach((n) => {
160
+ n.relationships.forEach(({ nodeId, type }) => {
161
+ if (nodeId === filePath) {
162
+ relationships.usedBy.push({
163
+ nodeId: n.id,
164
+ type,
165
+ name: String(getNodeDisplayName(n.id, n.metadata.name)),
166
+ });
167
+ }
168
+ });
169
+ });
170
+ return relationships;
171
+ }
172
+ /**
173
+ * Get all components in a file
174
+ */
175
+ function getComponents(filePath) {
176
+ const components = {
177
+ functions: [],
178
+ classes: [],
179
+ imports: [],
180
+ methods: [],
181
+ other: [],
182
+ };
183
+ knowledgeGraph.nodes.forEach((node) => {
184
+ if (node.metadata.filePath === filePath && node.id !== filePath) {
185
+ const component = {
186
+ name: getNodeDisplayName(node.id, node.metadata.name),
187
+ type: node.type,
188
+ line: node.metadata.startLine,
189
+ tokenCount: node.tokenCount,
190
+ metadata: node.metadata,
191
+ relationships: Array.from(node.relationships).map((rel) => ({
192
+ type: rel.type,
193
+ target: rel.nodeId.split(":").pop() || rel.nodeId,
194
+ })),
195
+ };
196
+ switch (node.type) {
197
+ case "function":
198
+ components.functions.push(component);
199
+ break;
200
+ case "class":
201
+ components.classes.push(component);
202
+ break;
203
+ case "import":
204
+ components.imports.push(component);
205
+ break;
206
+ case "method":
207
+ components.methods.push(component);
208
+ break;
209
+ default:
210
+ components.other.push(component);
211
+ }
212
+ }
213
+ });
214
+ return components;
215
+ }
216
+ /**
217
+ * Get files related to this file
218
+ */
219
+ function getRelatedFiles(filePath, node) {
220
+ const related = {
221
+ imports: [],
222
+ importedBy: [],
223
+ dependencies: new Set(),
224
+ };
225
+ // Files this file imports
226
+ node.relationships.forEach(({ nodeId, type }) => {
227
+ if (type === "imports") {
228
+ const importNode = knowledgeGraph.nodes.get(nodeId);
229
+ const importedPath = importNode
230
+ ? importNode.type === "file"
231
+ ? importNode.id
232
+ : importNode.metadata.filePath
233
+ : undefined;
234
+ if (importedPath) {
235
+ related.imports.push(importedPath);
236
+ related.dependencies.add(importedPath);
237
+ }
238
+ }
239
+ });
240
+ // Files that import this file
241
+ knowledgeGraph.nodes.forEach((n) => {
242
+ if (n.type === "file" && n.id !== filePath) {
243
+ n.relationships.forEach(({ nodeId }) => {
244
+ // Check if this node imports anything from our file
245
+ const targetNode = knowledgeGraph.nodes.get(nodeId);
246
+ const targetFilePath = targetNode
247
+ ? targetNode.type === "file"
248
+ ? targetNode.id
249
+ : targetNode.metadata.filePath
250
+ : undefined;
251
+ if (targetFilePath === filePath) {
252
+ related.importedBy.push(n.id);
253
+ related.dependencies.add(n.id);
254
+ }
255
+ });
256
+ }
257
+ });
258
+ return {
259
+ imports: related.imports,
260
+ importedBy: related.importedBy,
261
+ allDependencies: Array.from(related.dependencies),
262
+ };
263
+ }
264
+ /**
265
+ * Tool metadata for agent system
266
+ */
267
+ export const queryKnowledgeGraphTool = {
268
+ description: "Query the knowledge graph for code insights, relationships, and component analysis. The file must be read first before querying.",
269
+ parameters: z.object({
270
+ filePath: z
271
+ .string()
272
+ .optional()
273
+ .describe("The path to the file to query in the knowledge graph"),
274
+ queryType: z
275
+ .enum([
276
+ "summary",
277
+ "relationships",
278
+ "components",
279
+ "related-files",
280
+ "stats",
281
+ "question",
282
+ ])
283
+ .default("summary")
284
+ .describe("Type of query: 'summary' (basic file info), 'relationships' (imports/exports/calls), 'components' (functions/classes), 'related-files' (dependencies), 'stats' (graph statistics), 'question' (question-aware multi-hop retrieval)"),
285
+ question: z
286
+ .string()
287
+ .optional()
288
+ .describe("Natural language question to resolve against graph entities and relationships. Required when queryType is 'question'."),
289
+ maxDepth: z
290
+ .number()
291
+ .int()
292
+ .min(1)
293
+ .max(4)
294
+ .default(2)
295
+ .describe("Maximum graph traversal depth for question queries"),
296
+ maxTokens: z
297
+ .number()
298
+ .int()
299
+ .min(200)
300
+ .max(12000)
301
+ .default(4000)
302
+ .describe("Token budget for the assembled context"),
303
+ }),
304
+ execute: queryKnowledgeGraph,
305
+ };
306
+ export default queryKnowledgeGraphTool;
@@ -0,0 +1,92 @@
1
+ import { z } from "zod";
2
+ type ReadFileParams = {
3
+ filePath: string;
4
+ workspaceRoot?: string;
5
+ encoding?: BufferEncoding;
6
+ parseWithKnowledgeGraph?: boolean;
7
+ startLine?: number;
8
+ endLine?: number;
9
+ withLineNumbers?: boolean;
10
+ };
11
+ type ReadFileErrorResult = {
12
+ success: false;
13
+ error: string;
14
+ attemptedPath?: string;
15
+ };
16
+ type ReadFileComponent = {
17
+ type: string;
18
+ name: string;
19
+ line: number | undefined;
20
+ };
21
+ type KnowledgeGraphParseResult = {
22
+ parsed: true;
23
+ language: string;
24
+ components: ReadFileComponent[];
25
+ tokenCount: number;
26
+ relationships: Array<{
27
+ type: string;
28
+ target: string;
29
+ }>;
30
+ } | {
31
+ parsed: false;
32
+ error: string;
33
+ };
34
+ type ReadFileSuccessResult = {
35
+ success: true;
36
+ filePath: string;
37
+ resolvedBy: "direct" | "repo_map" | "terminal_find";
38
+ content: string;
39
+ startLine?: number;
40
+ endLine?: number;
41
+ totalLines?: number;
42
+ hasMore?: boolean;
43
+ nextStartLine?: number;
44
+ nextEndLine?: number;
45
+ size: number;
46
+ lastModified: Date;
47
+ knowledgeGraph: KnowledgeGraphParseResult | null;
48
+ };
49
+ type ReadFileResult = ReadFileSuccessResult | ReadFileErrorResult;
50
+ /**
51
+ * Tool for reading file contents
52
+ * @param {Object} params - The parameters for reading a file
53
+ * @param {string} params.filePath - The path to the file to read
54
+ * @param {string} [params.encoding='utf8'] - The encoding to use when reading the file
55
+ * @param {boolean} [params.parseWithKnowledgeGraph=true] - Whether to parse file with knowledge graph
56
+ * @returns {Promise<Object>} Object containing success status and file content or error
57
+ */
58
+ export declare function readFile({ filePath, workspaceRoot, encoding, parseWithKnowledgeGraph, startLine, endLine, withLineNumbers, }: ReadFileParams): Promise<ReadFileResult>;
59
+ /**
60
+ * Tool metadata for agent system
61
+ */
62
+ export declare const readFileTool: {
63
+ name: string;
64
+ description: string;
65
+ parameters: z.ZodObject<{
66
+ filePath: z.ZodString;
67
+ workspaceRoot: z.ZodOptional<z.ZodString>;
68
+ encoding: z.ZodDefault<z.ZodEnum<["utf8", "ascii", "base64", "binary", "hex"]>>;
69
+ startLine: z.ZodOptional<z.ZodNumber>;
70
+ endLine: z.ZodOptional<z.ZodNumber>;
71
+ withLineNumbers: z.ZodOptional<z.ZodBoolean>;
72
+ parseWithKnowledgeGraph: z.ZodDefault<z.ZodBoolean>;
73
+ }, "strip", z.ZodTypeAny, {
74
+ workspaceRoot?: string;
75
+ encoding?: "ascii" | "utf8" | "base64" | "binary" | "hex";
76
+ filePath?: string;
77
+ startLine?: number;
78
+ endLine?: number;
79
+ parseWithKnowledgeGraph?: boolean;
80
+ withLineNumbers?: boolean;
81
+ }, {
82
+ workspaceRoot?: string;
83
+ encoding?: "ascii" | "utf8" | "base64" | "binary" | "hex";
84
+ filePath?: string;
85
+ startLine?: number;
86
+ endLine?: number;
87
+ parseWithKnowledgeGraph?: boolean;
88
+ withLineNumbers?: boolean;
89
+ }>;
90
+ execute: typeof readFile;
91
+ };
92
+ export default readFileTool;