@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,90 @@
1
+ /**
2
+ * Format Document Tool
3
+ * Uses LSP to format an entire file according to language server formatting rules.
4
+ */
5
+ import { coreLsp } from "../../library/lsp/coreLsp.js";
6
+ import fs from "fs/promises";
7
+ const formatDocumentTool = {
8
+ name: "formatDocument",
9
+ description: `Format an entire file using the language server's formatting provider.
10
+ Applies consistent formatting rules such as indentation, spacing, and line endings.
11
+
12
+ Use this when you need to:
13
+ - Clean up code formatting after edits
14
+ - Ensure a file follows project style conventions
15
+ - Normalise whitespace, indentation, or brace placement`,
16
+ parameters: {
17
+ type: "object",
18
+ properties: {
19
+ filePath: {
20
+ type: "string",
21
+ description: "Absolute path to the file to format",
22
+ },
23
+ tabSize: {
24
+ type: "number",
25
+ description: "Number of spaces per indentation level (default: 2)",
26
+ },
27
+ insertSpaces: {
28
+ type: "boolean",
29
+ description: "Use spaces instead of tabs (default: true)",
30
+ },
31
+ trimTrailingWhitespace: {
32
+ type: "boolean",
33
+ description: "Remove trailing whitespace from each line (default: true)",
34
+ },
35
+ insertFinalNewline: {
36
+ type: "boolean",
37
+ description: "Ensure file ends with a newline (default: true)",
38
+ },
39
+ trimFinalNewlines: {
40
+ type: "boolean",
41
+ description: "Remove extra blank lines at end of file (default: true)",
42
+ },
43
+ },
44
+ required: ["filePath"],
45
+ },
46
+ async execute({ filePath, tabSize = 2, insertSpaces = true, trimTrailingWhitespace = true, insertFinalNewline = true, trimFinalNewlines = true, }) {
47
+ try {
48
+ await fs.access(filePath);
49
+ const result = (await coreLsp.formatDocument(filePath, {
50
+ tabSize,
51
+ insertSpaces,
52
+ trimTrailingWhitespace,
53
+ insertFinalNewline,
54
+ trimFinalNewlines,
55
+ }));
56
+ if (!result || result.length === 0) {
57
+ return {
58
+ success: true,
59
+ filePath,
60
+ editCount: 0,
61
+ edits: [],
62
+ summary: "No formatting changes required",
63
+ };
64
+ }
65
+ const edits = result.map((edit) => ({
66
+ startLine: (edit.range?.start?.line ?? 0) + 1,
67
+ startCharacter: (edit.range?.start?.character ?? 0) + 1,
68
+ endLine: (edit.range?.end?.line ?? 0) + 1,
69
+ endCharacter: (edit.range?.end?.character ?? 0) + 1,
70
+ newText: edit.newText ?? "",
71
+ }));
72
+ return {
73
+ success: true,
74
+ filePath,
75
+ editCount: edits.length,
76
+ edits,
77
+ summary: `${edits.length} formatting edit${edits.length === 1 ? "" : "s"} produced`,
78
+ };
79
+ }
80
+ catch (error) {
81
+ const err = error;
82
+ return {
83
+ success: false,
84
+ error: err.message,
85
+ filePath,
86
+ };
87
+ }
88
+ },
89
+ };
90
+ export default formatDocumentTool;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Get Code Actions Tool
3
+ * Uses LSP to retrieve available code actions (quick fixes, refactors) for a range.
4
+ */
5
+ type GetCodeActionsParams = {
6
+ filePath: string;
7
+ startLine: number;
8
+ startCharacter: number;
9
+ endLine?: number;
10
+ endCharacter?: number;
11
+ only?: string[];
12
+ };
13
+ type ParsedCodeAction = {
14
+ title: string;
15
+ kind: string;
16
+ isPreferred: boolean;
17
+ hasEdit: boolean;
18
+ hasCommand: boolean;
19
+ };
20
+ type GetCodeActionsResult = {
21
+ success: true;
22
+ filePath: string;
23
+ range: {
24
+ startLine: number;
25
+ startCharacter: number;
26
+ endLine: number;
27
+ endCharacter: number;
28
+ };
29
+ count: number;
30
+ actions: ParsedCodeAction[];
31
+ quickFixes: ParsedCodeAction[];
32
+ refactors: ParsedCodeAction[];
33
+ } | {
34
+ success: false;
35
+ message?: string;
36
+ error?: string;
37
+ filePath: string;
38
+ };
39
+ declare const getCodeActionsTool: {
40
+ name: string;
41
+ description: string;
42
+ parameters: {
43
+ type: string;
44
+ properties: {
45
+ filePath: {
46
+ type: string;
47
+ description: string;
48
+ };
49
+ startLine: {
50
+ type: string;
51
+ description: string;
52
+ };
53
+ startCharacter: {
54
+ type: string;
55
+ description: string;
56
+ };
57
+ endLine: {
58
+ type: string;
59
+ description: string;
60
+ };
61
+ endCharacter: {
62
+ type: string;
63
+ description: string;
64
+ };
65
+ only: {
66
+ type: string;
67
+ items: {
68
+ type: string;
69
+ };
70
+ description: string;
71
+ };
72
+ };
73
+ required: string[];
74
+ };
75
+ execute({ filePath, startLine, startCharacter, endLine, endCharacter, only, }: GetCodeActionsParams): Promise<GetCodeActionsResult>;
76
+ };
77
+ export default getCodeActionsTool;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Get Code Actions Tool
3
+ * Uses LSP to retrieve available code actions (quick fixes, refactors) for a range.
4
+ */
5
+ import { coreLsp } from "../../library/lsp/coreLsp.js";
6
+ import fs from "fs/promises";
7
+ const getCodeActionsTool = {
8
+ name: "getCodeActions",
9
+ description: `Get available code actions (quick fixes, refactors, source actions) for a range in a file.
10
+ Returns actionable suggestions provided by the language server such as:
11
+ - Quick fixes for errors and warnings
12
+ - Refactoring options (extract function, rename, etc.)
13
+ - Import organization
14
+ - Code generation
15
+
16
+ Use this when you need to:
17
+ - See what quick fixes are available for a diagnostic
18
+ - Find refactoring opportunities
19
+ - Organise imports
20
+ - Apply suggested code improvements`,
21
+ parameters: {
22
+ type: "object",
23
+ properties: {
24
+ filePath: {
25
+ type: "string",
26
+ description: "Absolute path to the file",
27
+ },
28
+ startLine: {
29
+ type: "number",
30
+ description: "Start line number (1-based) of the selection or cursor",
31
+ },
32
+ startCharacter: {
33
+ type: "number",
34
+ description: "Start character (1-based) of the selection",
35
+ },
36
+ endLine: {
37
+ type: "number",
38
+ description: "End line number (1-based, defaults to startLine)",
39
+ },
40
+ endCharacter: {
41
+ type: "number",
42
+ description: "End character (1-based, defaults to startCharacter)",
43
+ },
44
+ only: {
45
+ type: "array",
46
+ items: { type: "string" },
47
+ description: "Optional list of code action kinds to request e.g. [\"quickfix\", \"refactor\"]",
48
+ },
49
+ },
50
+ required: ["filePath", "startLine", "startCharacter"],
51
+ },
52
+ async execute({ filePath, startLine, startCharacter, endLine, endCharacter, only, }) {
53
+ try {
54
+ await fs.access(filePath);
55
+ const resolvedEndLine = endLine ?? startLine;
56
+ const resolvedEndCharacter = endCharacter ?? startCharacter;
57
+ const result = (await coreLsp.getCodeActions(filePath, startLine, startCharacter, resolvedEndLine, resolvedEndCharacter, only ? { only } : {}));
58
+ if (!result || result.length === 0) {
59
+ return {
60
+ success: false,
61
+ message: `No code actions available at ${filePath}:${startLine}:${startCharacter}`,
62
+ filePath,
63
+ };
64
+ }
65
+ const parsed = result.map((action) => ({
66
+ title: action.title ?? "Unnamed action",
67
+ kind: action.kind ?? "unknown",
68
+ isPreferred: action.isPreferred ?? false,
69
+ hasEdit: !!(action.edit?.changes || action.edit?.documentChanges),
70
+ hasCommand: !!action.command,
71
+ }));
72
+ return {
73
+ success: true,
74
+ filePath,
75
+ range: {
76
+ startLine,
77
+ startCharacter,
78
+ endLine: resolvedEndLine,
79
+ endCharacter: resolvedEndCharacter,
80
+ },
81
+ count: parsed.length,
82
+ actions: parsed,
83
+ quickFixes: parsed.filter((a) => a.kind.startsWith("quickfix")),
84
+ refactors: parsed.filter((a) => a.kind.startsWith("refactor")),
85
+ };
86
+ }
87
+ catch (error) {
88
+ const err = error;
89
+ return {
90
+ success: false,
91
+ error: err.message,
92
+ filePath,
93
+ };
94
+ }
95
+ },
96
+ };
97
+ export default getCodeActionsTool;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Get Code Completion Tool
3
+ * Uses LSP to provide intelligent code completion suggestions
4
+ */
5
+ type ParsedCompletionItem = {
6
+ label: string;
7
+ kind: string;
8
+ detail?: string;
9
+ documentation?: string;
10
+ insertText: string;
11
+ sortText: string;
12
+ filterText: string;
13
+ deprecated: boolean;
14
+ preselect: boolean;
15
+ };
16
+ type GetCodeCompletionParams = {
17
+ filePath: string;
18
+ line: number;
19
+ character: number;
20
+ triggerCharacter?: string;
21
+ };
22
+ type GetCodeCompletionResult = {
23
+ success: true;
24
+ filePath: string;
25
+ position: {
26
+ line: number;
27
+ character: number;
28
+ };
29
+ triggerCharacter?: string;
30
+ totalItems: number;
31
+ itemsReturned: number;
32
+ isIncomplete: boolean;
33
+ topSuggestions: ParsedCompletionItem[];
34
+ allSuggestions: ParsedCompletionItem[];
35
+ byKind: Record<string, ParsedCompletionItem[]>;
36
+ summary: Array<{
37
+ kind: string;
38
+ count: number;
39
+ }>;
40
+ } | {
41
+ success: false;
42
+ message?: string;
43
+ error?: string;
44
+ filePath: string;
45
+ position: {
46
+ line: number;
47
+ character: number;
48
+ };
49
+ };
50
+ declare const getCodeCompletionTool: {
51
+ name: string;
52
+ description: string;
53
+ parameters: {
54
+ type: string;
55
+ properties: {
56
+ filePath: {
57
+ type: string;
58
+ description: string;
59
+ };
60
+ line: {
61
+ type: string;
62
+ description: string;
63
+ };
64
+ character: {
65
+ type: string;
66
+ description: string;
67
+ };
68
+ triggerCharacter: {
69
+ type: string;
70
+ description: string;
71
+ };
72
+ };
73
+ required: string[];
74
+ };
75
+ execute({ filePath, line, character, triggerCharacter, }: GetCodeCompletionParams): Promise<GetCodeCompletionResult>;
76
+ };
77
+ export default getCodeCompletionTool;
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Get Code Completion Tool
3
+ * Uses LSP to provide intelligent code completion suggestions
4
+ */
5
+ import { coreLsp } from "../../library/lsp/coreLsp.js";
6
+ import fs from "fs/promises";
7
+ const getCodeCompletionTool = {
8
+ name: "getCodeCompletion",
9
+ description: `Get intelligent code completion suggestions at a specific position in a file.
10
+ Provides context-aware suggestions including:
11
+ - Variable names and properties
12
+ - Function names and parameters
13
+ - Type suggestions
14
+ - Import suggestions
15
+ - Snippet completions
16
+
17
+ Use this when you need to:
18
+ - Autocomplete code while writing
19
+ - Discover available methods/properties
20
+ - Find correct function signatures
21
+ - Get import suggestions`,
22
+ parameters: {
23
+ type: "object",
24
+ properties: {
25
+ filePath: {
26
+ type: "string",
27
+ description: "Absolute path to the file",
28
+ },
29
+ line: {
30
+ type: "number",
31
+ description: "Line number (1-based) where completion is needed",
32
+ },
33
+ character: {
34
+ type: "number",
35
+ description: "Character position (1-based) within the line",
36
+ },
37
+ triggerCharacter: {
38
+ type: "string",
39
+ description: "Optional trigger character like '.', '(' that initiated completion",
40
+ },
41
+ },
42
+ required: ["filePath", "line", "character"],
43
+ },
44
+ async execute({ filePath, line, character, triggerCharacter, }) {
45
+ try {
46
+ // Verify file exists
47
+ await fs.access(filePath);
48
+ // Get completion from LSP
49
+ const completionResult = (await coreLsp.getCompletion(filePath, line, character));
50
+ if (!completionResult) {
51
+ return {
52
+ success: false,
53
+ message: `No completions available at ${filePath}:${line}:${character}`,
54
+ filePath,
55
+ position: { line, character },
56
+ };
57
+ }
58
+ // Handle both CompletionList and CompletionItem[] formats
59
+ let items = [];
60
+ let isIncomplete = false;
61
+ if (Array.isArray(completionResult)) {
62
+ items = completionResult;
63
+ }
64
+ else if (completionResult.items) {
65
+ items = completionResult.items;
66
+ isIncomplete = completionResult.isIncomplete || false;
67
+ }
68
+ if (items.length === 0) {
69
+ return {
70
+ success: false,
71
+ message: `No completion suggestions at ${filePath}:${line}:${character}`,
72
+ filePath,
73
+ position: { line, character },
74
+ };
75
+ }
76
+ // Parse completion items
77
+ const completionKindNames = {
78
+ 1: "Text",
79
+ 2: "Method",
80
+ 3: "Function",
81
+ 4: "Constructor",
82
+ 5: "Field",
83
+ 6: "Variable",
84
+ 7: "Class",
85
+ 8: "Interface",
86
+ 9: "Module",
87
+ 10: "Property",
88
+ 11: "Unit",
89
+ 12: "Value",
90
+ 13: "Enum",
91
+ 14: "Keyword",
92
+ 15: "Snippet",
93
+ 16: "Color",
94
+ 17: "File",
95
+ 18: "Reference",
96
+ 19: "Folder",
97
+ 20: "EnumMember",
98
+ 21: "Constant",
99
+ 22: "Struct",
100
+ 23: "Event",
101
+ 24: "Operator",
102
+ 25: "TypeParameter",
103
+ };
104
+ const parsedItems = items.slice(0, 50).map((item) => {
105
+ // Extract text to insert
106
+ let insertText = item.insertText || item.label;
107
+ let textEdit = null;
108
+ if (item.textEdit) {
109
+ textEdit = {
110
+ newText: item.textEdit.newText || item.textEdit.insert?.newText,
111
+ range: item.textEdit.range || item.textEdit.insert?.range,
112
+ };
113
+ insertText = textEdit.newText ?? insertText;
114
+ }
115
+ return {
116
+ label: item.label,
117
+ kind: item.kind !== undefined
118
+ ? completionKindNames[item.kind] || "Unknown"
119
+ : "Unknown",
120
+ detail: item.detail || undefined,
121
+ documentation: typeof item.documentation === "string"
122
+ ? item.documentation
123
+ : item.documentation?.value || undefined,
124
+ insertText,
125
+ sortText: item.sortText || item.label,
126
+ filterText: item.filterText || item.label,
127
+ deprecated: item.deprecated || false,
128
+ preselect: item.preselect || false,
129
+ };
130
+ });
131
+ // Group by kind for easier consumption
132
+ const byKind = {};
133
+ parsedItems.forEach((item) => {
134
+ if (!byKind[item.kind]) {
135
+ byKind[item.kind] = [];
136
+ }
137
+ byKind[item.kind].push(item);
138
+ });
139
+ // Top suggestions (preselected or first 10)
140
+ const topSuggestions = parsedItems
141
+ .filter((item) => item.preselect)
142
+ .slice(0, 5);
143
+ if (topSuggestions.length === 0) {
144
+ topSuggestions.push(...parsedItems.slice(0, 10));
145
+ }
146
+ return {
147
+ success: true,
148
+ filePath,
149
+ position: { line, character },
150
+ triggerCharacter,
151
+ totalItems: items.length,
152
+ itemsReturned: parsedItems.length,
153
+ isIncomplete,
154
+ topSuggestions,
155
+ allSuggestions: parsedItems,
156
+ byKind,
157
+ summary: Object.keys(byKind).map((kind) => ({
158
+ kind,
159
+ count: byKind[kind].length,
160
+ })),
161
+ };
162
+ }
163
+ catch (error) {
164
+ const err = error;
165
+ return {
166
+ success: false,
167
+ error: err.message,
168
+ filePath,
169
+ position: { line, character },
170
+ };
171
+ }
172
+ },
173
+ };
174
+ export default getCodeCompletionTool;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * getCodeContext tool - Fetches relevant code snippets for answering questions
3
+ * Similar to how VS Code Copilot finds and references code
4
+ */
5
+ declare const getCodeContextTool: import("@mastra/core/tools").Tool<{
6
+ cwd?: string;
7
+ query?: string;
8
+ maxResults?: number;
9
+ symbols?: string[];
10
+ targetFiles?: string[];
11
+ includeDefinitions?: boolean;
12
+ includeUsages?: boolean;
13
+ }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "getCodeContext", unknown>;
14
+ export default getCodeContextTool;