@codeany/open-agent-sdk 0.2.2 → 0.2.3

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 (280) hide show
  1. package/dist/agent.d.ts +113 -0
  2. package/dist/agent.d.ts.map +1 -0
  3. package/dist/agent.js +446 -0
  4. package/dist/agent.js.map +1 -0
  5. package/dist/engine.d.ts +62 -0
  6. package/dist/engine.d.ts.map +1 -0
  7. package/dist/engine.js +496 -0
  8. package/dist/engine.js.map +1 -0
  9. package/dist/hooks.d.ts +111 -0
  10. package/dist/hooks.d.ts.map +1 -0
  11. package/dist/hooks.js +179 -0
  12. package/dist/hooks.js.map +1 -0
  13. package/dist/index.d.ts +66 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +133 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/mcp/client.d.ts +19 -0
  18. package/dist/mcp/client.d.ts.map +1 -0
  19. package/dist/mcp/client.js +126 -0
  20. package/dist/mcp/client.js.map +1 -0
  21. package/dist/providers/anthropic.d.ts +17 -0
  22. package/dist/providers/anthropic.d.ts.map +1 -0
  23. package/dist/providers/anthropic.js +47 -0
  24. package/dist/providers/anthropic.js.map +1 -0
  25. package/dist/providers/index.d.ts +20 -0
  26. package/dist/providers/index.d.ts.map +1 -0
  27. package/dist/providers/index.js +26 -0
  28. package/dist/providers/index.js.map +1 -0
  29. package/dist/providers/openai.d.ts +26 -0
  30. package/dist/providers/openai.d.ts.map +1 -0
  31. package/dist/providers/openai.js +212 -0
  32. package/dist/providers/openai.js.map +1 -0
  33. package/dist/providers/types.d.ts +84 -0
  34. package/dist/providers/types.d.ts.map +1 -0
  35. package/dist/providers/types.js +11 -0
  36. package/dist/providers/types.js.map +1 -0
  37. package/dist/sdk-mcp-server.d.ts +52 -0
  38. package/dist/sdk-mcp-server.d.ts.map +1 -0
  39. package/dist/sdk-mcp-server.js +57 -0
  40. package/dist/sdk-mcp-server.js.map +1 -0
  41. package/dist/session.d.ts +73 -0
  42. package/dist/session.d.ts.map +1 -0
  43. package/dist/session.js +159 -0
  44. package/dist/session.js.map +1 -0
  45. package/dist/skills/bundled/commit.d.ts +7 -0
  46. package/dist/skills/bundled/commit.d.ts.map +1 -0
  47. package/dist/skills/bundled/commit.js +35 -0
  48. package/dist/skills/bundled/commit.js.map +1 -0
  49. package/dist/skills/bundled/debug.d.ts +7 -0
  50. package/dist/skills/bundled/debug.d.ts.map +1 -0
  51. package/{src/skills/bundled/debug.ts → dist/skills/bundled/debug.js} +20 -22
  52. package/dist/skills/bundled/debug.js.map +1 -0
  53. package/dist/skills/bundled/index.d.ts +11 -0
  54. package/dist/skills/bundled/index.d.ts.map +1 -0
  55. package/dist/skills/bundled/index.js +26 -0
  56. package/dist/skills/bundled/index.js.map +1 -0
  57. package/dist/skills/bundled/review.d.ts +7 -0
  58. package/dist/skills/bundled/review.d.ts.map +1 -0
  59. package/{src/skills/bundled/review.ts → dist/skills/bundled/review.js} +18 -21
  60. package/dist/skills/bundled/review.js.map +1 -0
  61. package/dist/skills/bundled/simplify.d.ts +8 -0
  62. package/dist/skills/bundled/simplify.d.ts.map +1 -0
  63. package/{src/skills/bundled/simplify.ts → dist/skills/bundled/simplify.js} +16 -19
  64. package/dist/skills/bundled/simplify.js.map +1 -0
  65. package/dist/skills/bundled/test.d.ts +7 -0
  66. package/dist/skills/bundled/test.d.ts.map +1 -0
  67. package/{src/skills/bundled/test.ts → dist/skills/bundled/test.js} +18 -21
  68. package/dist/skills/bundled/test.js.map +1 -0
  69. package/dist/skills/index.d.ts +7 -0
  70. package/dist/skills/index.d.ts.map +1 -0
  71. package/dist/skills/index.js +8 -0
  72. package/dist/skills/index.js.map +1 -0
  73. package/dist/skills/registry.d.ts +43 -0
  74. package/dist/skills/registry.d.ts.map +1 -0
  75. package/dist/skills/registry.js +111 -0
  76. package/dist/skills/registry.js.map +1 -0
  77. package/dist/skills/types.d.ts +83 -0
  78. package/dist/skills/types.d.ts.map +1 -0
  79. package/dist/skills/types.js +8 -0
  80. package/dist/skills/types.js.map +1 -0
  81. package/dist/tool-helper.d.ts +73 -0
  82. package/dist/tool-helper.d.ts.map +1 -0
  83. package/dist/tool-helper.js +86 -0
  84. package/dist/tool-helper.js.map +1 -0
  85. package/dist/tools/agent-tool.d.ts +17 -0
  86. package/dist/tools/agent-tool.d.ts.map +1 -0
  87. package/dist/tools/agent-tool.js +146 -0
  88. package/dist/tools/agent-tool.js.map +1 -0
  89. package/dist/tools/ask-user.d.ts +18 -0
  90. package/dist/tools/ask-user.d.ts.map +1 -0
  91. package/dist/tools/ask-user.js +72 -0
  92. package/dist/tools/ask-user.js.map +1 -0
  93. package/dist/tools/bash.d.ts +5 -0
  94. package/dist/tools/bash.d.ts.map +1 -0
  95. package/dist/tools/bash.js +67 -0
  96. package/dist/tools/bash.js.map +1 -0
  97. package/dist/tools/config-tool.d.ts +20 -0
  98. package/dist/tools/config-tool.d.ts.map +1 -0
  99. package/dist/tools/config-tool.js +83 -0
  100. package/dist/tools/config-tool.js.map +1 -0
  101. package/dist/tools/cron-tools.d.ts +33 -0
  102. package/dist/tools/cron-tools.d.ts.map +1 -0
  103. package/dist/tools/cron-tools.js +128 -0
  104. package/dist/tools/cron-tools.js.map +1 -0
  105. package/dist/tools/edit.d.ts +5 -0
  106. package/dist/tools/edit.d.ts.map +1 -0
  107. package/dist/tools/edit.js +70 -0
  108. package/dist/tools/edit.js.map +1 -0
  109. package/dist/tools/glob.d.ts +5 -0
  110. package/dist/tools/glob.d.ts.map +1 -0
  111. package/dist/tools/glob.js +75 -0
  112. package/dist/tools/glob.js.map +1 -0
  113. package/dist/tools/grep.d.ts +5 -0
  114. package/dist/tools/grep.d.ts.map +1 -0
  115. package/dist/tools/grep.js +168 -0
  116. package/dist/tools/grep.js.map +1 -0
  117. package/dist/tools/index.d.ts +45 -0
  118. package/dist/tools/index.d.ts.map +1 -0
  119. package/dist/tools/index.js +162 -0
  120. package/dist/tools/index.js.map +1 -0
  121. package/dist/tools/lsp-tool.d.ts +9 -0
  122. package/dist/tools/lsp-tool.d.ts.map +1 -0
  123. package/dist/tools/lsp-tool.js +137 -0
  124. package/dist/tools/lsp-tool.js.map +1 -0
  125. package/dist/tools/mcp-resource-tools.d.ts +14 -0
  126. package/dist/tools/mcp-resource-tools.d.ts.map +1 -0
  127. package/dist/tools/mcp-resource-tools.js +117 -0
  128. package/dist/tools/mcp-resource-tools.js.map +1 -0
  129. package/dist/tools/notebook-edit.d.ts +5 -0
  130. package/dist/tools/notebook-edit.d.ts.map +1 -0
  131. package/dist/tools/notebook-edit.js +85 -0
  132. package/dist/tools/notebook-edit.js.map +1 -0
  133. package/dist/tools/plan-tools.d.ts +12 -0
  134. package/dist/tools/plan-tools.d.ts.map +1 -0
  135. package/dist/tools/plan-tools.js +77 -0
  136. package/dist/tools/plan-tools.js.map +1 -0
  137. package/dist/tools/read.d.ts +5 -0
  138. package/dist/tools/read.d.ts.map +1 -0
  139. package/dist/tools/read.js +66 -0
  140. package/dist/tools/read.js.map +1 -0
  141. package/dist/tools/send-message.d.ts +31 -0
  142. package/dist/tools/send-message.d.ts.map +1 -0
  143. package/dist/tools/send-message.js +77 -0
  144. package/dist/tools/send-message.js.map +1 -0
  145. package/dist/tools/skill-tool.d.ts +9 -0
  146. package/dist/tools/skill-tool.d.ts.map +1 -0
  147. package/dist/tools/skill-tool.js +115 -0
  148. package/dist/tools/skill-tool.js.map +1 -0
  149. package/dist/tools/task-tools.d.ts +48 -0
  150. package/dist/tools/task-tools.d.ts.map +1 -0
  151. package/dist/tools/task-tools.js +242 -0
  152. package/dist/tools/task-tools.js.map +1 -0
  153. package/dist/tools/team-tools.d.ts +34 -0
  154. package/dist/tools/team-tools.d.ts.map +1 -0
  155. package/dist/tools/team-tools.js +103 -0
  156. package/dist/tools/team-tools.js.map +1 -0
  157. package/dist/tools/todo-tool.d.ts +22 -0
  158. package/dist/tools/todo-tool.d.ts.map +1 -0
  159. package/dist/tools/todo-tool.js +93 -0
  160. package/dist/tools/todo-tool.js.map +1 -0
  161. package/dist/tools/tool-search.d.ts +13 -0
  162. package/dist/tools/tool-search.d.ts.map +1 -0
  163. package/dist/tools/tool-search.js +76 -0
  164. package/dist/tools/tool-search.js.map +1 -0
  165. package/dist/tools/types.d.ts +29 -0
  166. package/dist/tools/types.d.ts.map +1 -0
  167. package/dist/tools/types.js +52 -0
  168. package/dist/tools/types.js.map +1 -0
  169. package/dist/tools/web-fetch.d.ts +5 -0
  170. package/dist/tools/web-fetch.d.ts.map +1 -0
  171. package/dist/tools/web-fetch.js +60 -0
  172. package/dist/tools/web-fetch.js.map +1 -0
  173. package/dist/tools/web-search.d.ts +5 -0
  174. package/dist/tools/web-search.d.ts.map +1 -0
  175. package/dist/tools/web-search.js +77 -0
  176. package/dist/tools/web-search.js.map +1 -0
  177. package/dist/tools/worktree-tools.d.ts +10 -0
  178. package/dist/tools/worktree-tools.d.ts.map +1 -0
  179. package/dist/tools/worktree-tools.js +130 -0
  180. package/dist/tools/worktree-tools.js.map +1 -0
  181. package/dist/tools/write.d.ts +5 -0
  182. package/dist/tools/write.d.ts.map +1 -0
  183. package/dist/tools/write.js +40 -0
  184. package/dist/tools/write.js.map +1 -0
  185. package/dist/types.d.ts +423 -0
  186. package/dist/types.d.ts.map +1 -0
  187. package/dist/types.js +5 -0
  188. package/dist/types.js.map +1 -0
  189. package/dist/utils/compact.d.ts +44 -0
  190. package/dist/utils/compact.d.ts.map +1 -0
  191. package/dist/utils/compact.js +162 -0
  192. package/dist/utils/compact.js.map +1 -0
  193. package/dist/utils/context.d.ts +35 -0
  194. package/dist/utils/context.d.ts.map +1 -0
  195. package/dist/utils/context.js +174 -0
  196. package/dist/utils/context.js.map +1 -0
  197. package/dist/utils/fileCache.d.ts +64 -0
  198. package/dist/utils/fileCache.d.ts.map +1 -0
  199. package/dist/utils/fileCache.js +117 -0
  200. package/dist/utils/fileCache.js.map +1 -0
  201. package/dist/utils/messages.d.ts +57 -0
  202. package/dist/utils/messages.d.ts.map +1 -0
  203. package/dist/utils/messages.js +152 -0
  204. package/dist/utils/messages.js.map +1 -0
  205. package/dist/utils/retry.d.ts +48 -0
  206. package/dist/utils/retry.d.ts.map +1 -0
  207. package/dist/utils/retry.js +111 -0
  208. package/dist/utils/retry.js.map +1 -0
  209. package/dist/utils/tokens.d.ts +57 -0
  210. package/dist/utils/tokens.d.ts.map +1 -0
  211. package/dist/utils/tokens.js +134 -0
  212. package/dist/utils/tokens.js.map +1 -0
  213. package/package.json +6 -1
  214. package/.env.example +0 -8
  215. package/examples/01-simple-query.ts +0 -43
  216. package/examples/02-multi-tool.ts +0 -44
  217. package/examples/03-multi-turn.ts +0 -39
  218. package/examples/04-prompt-api.ts +0 -29
  219. package/examples/05-custom-system-prompt.ts +0 -26
  220. package/examples/06-mcp-server.ts +0 -49
  221. package/examples/07-custom-tools.ts +0 -87
  222. package/examples/08-official-api-compat.ts +0 -38
  223. package/examples/09-subagents.ts +0 -48
  224. package/examples/10-permissions.ts +0 -40
  225. package/examples/11-custom-mcp-tools.ts +0 -101
  226. package/examples/12-skills.ts +0 -88
  227. package/examples/13-hooks.ts +0 -88
  228. package/examples/14-openai-compat.ts +0 -71
  229. package/examples/web/index.html +0 -365
  230. package/examples/web/server.ts +0 -157
  231. package/src/agent.ts +0 -516
  232. package/src/engine.ts +0 -633
  233. package/src/hooks.ts +0 -261
  234. package/src/index.ts +0 -426
  235. package/src/mcp/client.ts +0 -150
  236. package/src/providers/anthropic.ts +0 -60
  237. package/src/providers/index.ts +0 -34
  238. package/src/providers/openai.ts +0 -315
  239. package/src/providers/types.ts +0 -85
  240. package/src/sdk-mcp-server.ts +0 -78
  241. package/src/session.ts +0 -227
  242. package/src/skills/bundled/commit.ts +0 -38
  243. package/src/skills/bundled/index.ts +0 -28
  244. package/src/skills/index.ts +0 -25
  245. package/src/skills/registry.ts +0 -133
  246. package/src/skills/types.ts +0 -99
  247. package/src/tool-helper.ts +0 -127
  248. package/src/tools/agent-tool.ts +0 -164
  249. package/src/tools/ask-user.ts +0 -79
  250. package/src/tools/bash.ts +0 -75
  251. package/src/tools/config-tool.ts +0 -89
  252. package/src/tools/cron-tools.ts +0 -153
  253. package/src/tools/edit.ts +0 -74
  254. package/src/tools/glob.ts +0 -77
  255. package/src/tools/grep.ts +0 -168
  256. package/src/tools/index.ts +0 -240
  257. package/src/tools/lsp-tool.ts +0 -163
  258. package/src/tools/mcp-resource-tools.ts +0 -125
  259. package/src/tools/notebook-edit.ts +0 -93
  260. package/src/tools/plan-tools.ts +0 -88
  261. package/src/tools/read.ts +0 -73
  262. package/src/tools/send-message.ts +0 -96
  263. package/src/tools/skill-tool.ts +0 -133
  264. package/src/tools/task-tools.ts +0 -290
  265. package/src/tools/team-tools.ts +0 -128
  266. package/src/tools/todo-tool.ts +0 -112
  267. package/src/tools/tool-search.ts +0 -87
  268. package/src/tools/types.ts +0 -66
  269. package/src/tools/web-fetch.ts +0 -66
  270. package/src/tools/web-search.ts +0 -86
  271. package/src/tools/worktree-tools.ts +0 -140
  272. package/src/tools/write.ts +0 -42
  273. package/src/types.ts +0 -486
  274. package/src/utils/compact.ts +0 -207
  275. package/src/utils/context.ts +0 -191
  276. package/src/utils/fileCache.ts +0 -148
  277. package/src/utils/messages.ts +0 -195
  278. package/src/utils/retry.ts +0 -140
  279. package/src/utils/tokens.ts +0 -145
  280. package/tsconfig.json +0 -19
@@ -1,163 +0,0 @@
1
- /**
2
- * LSPTool - Language Server Protocol integration
3
- *
4
- * Provides code intelligence: go-to-definition, find-references,
5
- * hover, document symbols, workspace symbols, etc.
6
- */
7
-
8
- import { execSync } from 'child_process'
9
- import type { ToolDefinition, ToolResult } from '../types.js'
10
-
11
- export const LSPTool: ToolDefinition = {
12
- name: 'LSP',
13
- description: 'Language Server Protocol operations for code intelligence. Supports go-to-definition, find-references, hover, and symbol lookup.',
14
- inputSchema: {
15
- type: 'object',
16
- properties: {
17
- operation: {
18
- type: 'string',
19
- enum: [
20
- 'goToDefinition',
21
- 'findReferences',
22
- 'hover',
23
- 'documentSymbol',
24
- 'workspaceSymbol',
25
- 'goToImplementation',
26
- 'prepareCallHierarchy',
27
- 'incomingCalls',
28
- 'outgoingCalls',
29
- ],
30
- description: 'LSP operation to perform',
31
- },
32
- file_path: { type: 'string', description: 'File path for the operation' },
33
- line: { type: 'number', description: 'Line number (0-based)' },
34
- character: { type: 'number', description: 'Character position (0-based)' },
35
- query: { type: 'string', description: 'Symbol name (for workspace symbol search)' },
36
- },
37
- required: ['operation'],
38
- },
39
- isReadOnly: () => true,
40
- isConcurrencySafe: () => true,
41
- isEnabled: () => true,
42
- async prompt() { return 'Code intelligence via Language Server Protocol.' },
43
- async call(input: any, context: { cwd: string }): Promise<ToolResult> {
44
- const { operation, file_path, line, character, query } = input
45
-
46
- // LSP requires a running language server. In standalone mode,
47
- // we fall back to basic grep/ripgrep-based symbol lookup.
48
- try {
49
- switch (operation) {
50
- case 'goToDefinition':
51
- case 'goToImplementation': {
52
- if (!file_path || line === undefined) {
53
- return { type: 'tool_result', tool_use_id: '', content: 'file_path and line required', is_error: true }
54
- }
55
- // Use grep to find definition
56
- const symbol = await getSymbolAtPosition(file_path, line, character || 0, context.cwd)
57
- if (!symbol) {
58
- return { type: 'tool_result', tool_use_id: '', content: 'Could not identify symbol at position' }
59
- }
60
- const results = execSync(
61
- `rg -n "(?:function|class|interface|type|const|let|var|export)\\s+${symbol}" --type-add 'src:*.{ts,tsx,js,jsx,py,go,rs,java}' -t src ${context.cwd} 2>/dev/null || grep -rn "(?:function|class|interface|type|const|let|var|export)\\s*${symbol}" ${context.cwd} --include='*.ts' --include='*.js' 2>/dev/null`,
62
- { encoding: 'utf-8', timeout: 10000 },
63
- ).trim()
64
- return { type: 'tool_result', tool_use_id: '', content: results || `No definition found for "${symbol}"` }
65
- }
66
-
67
- case 'findReferences': {
68
- if (!file_path || line === undefined) {
69
- return { type: 'tool_result', tool_use_id: '', content: 'file_path and line required', is_error: true }
70
- }
71
- const sym = await getSymbolAtPosition(file_path, line, character || 0, context.cwd)
72
- if (!sym) {
73
- return { type: 'tool_result', tool_use_id: '', content: 'Could not identify symbol at position' }
74
- }
75
- const refs = execSync(
76
- `rg -n "${sym}" ${context.cwd} --type-add 'src:*.{ts,tsx,js,jsx,py,go,rs,java}' -t src 2>/dev/null | head -50`,
77
- { encoding: 'utf-8', timeout: 10000 },
78
- ).trim()
79
- return { type: 'tool_result', tool_use_id: '', content: refs || `No references found for "${sym}"` }
80
- }
81
-
82
- case 'hover': {
83
- return {
84
- type: 'tool_result',
85
- tool_use_id: '',
86
- content: 'Hover information requires a running language server. Use Read tool to examine the file content.',
87
- }
88
- }
89
-
90
- case 'documentSymbol': {
91
- if (!file_path) {
92
- return { type: 'tool_result', tool_use_id: '', content: 'file_path required', is_error: true }
93
- }
94
- const symbols = execSync(
95
- `rg -n "^\\s*(export\\s+)?(function|class|interface|type|const|let|var|enum)\\s+" ${JSON.stringify(file_path)} 2>/dev/null || grep -n "^\\s*\\(export\\s\\+\\)\\?\\(function\\|class\\|interface\\|type\\|const\\|let\\|var\\|enum\\)\\s" ${JSON.stringify(file_path)} 2>/dev/null`,
96
- { encoding: 'utf-8', cwd: context.cwd, timeout: 10000 },
97
- ).trim()
98
- return { type: 'tool_result', tool_use_id: '', content: symbols || 'No symbols found' }
99
- }
100
-
101
- case 'workspaceSymbol': {
102
- if (!query) {
103
- return { type: 'tool_result', tool_use_id: '', content: 'query required', is_error: true }
104
- }
105
- const wsSymbols = execSync(
106
- `rg -n "${query}" ${context.cwd} --type-add 'src:*.{ts,tsx,js,jsx,py,go,rs,java}' -t src 2>/dev/null | head -30`,
107
- { encoding: 'utf-8', timeout: 10000 },
108
- ).trim()
109
- return { type: 'tool_result', tool_use_id: '', content: wsSymbols || `No symbols found for "${query}"` }
110
- }
111
-
112
- default:
113
- return {
114
- type: 'tool_result',
115
- tool_use_id: '',
116
- content: `LSP operation "${operation}" requires a running language server.`,
117
- }
118
- }
119
- } catch (err: any) {
120
- return {
121
- type: 'tool_result',
122
- tool_use_id: '',
123
- content: `LSP error: ${err.message}`,
124
- is_error: true,
125
- }
126
- }
127
- },
128
- }
129
-
130
- /**
131
- * Get the symbol at a given position in a file.
132
- */
133
- async function getSymbolAtPosition(
134
- filePath: string,
135
- line: number,
136
- character: number,
137
- cwd: string,
138
- ): Promise<string | null> {
139
- try {
140
- const { readFile } = await import('fs/promises')
141
- const { resolve } = await import('path')
142
- const content = await readFile(resolve(cwd, filePath), 'utf-8')
143
- const lines = content.split('\n')
144
-
145
- if (line >= lines.length) return null
146
-
147
- const lineText = lines[line]
148
- if (!lineText || character >= lineText.length) return null
149
-
150
- // Extract word at position
151
- const wordMatch = /\b\w+\b/g
152
- let match
153
- while ((match = wordMatch.exec(lineText)) !== null) {
154
- if (match.index <= character && match.index + match[0].length >= character) {
155
- return match[0]
156
- }
157
- }
158
-
159
- return null
160
- } catch {
161
- return null
162
- }
163
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * MCP Resource Tools
3
- *
4
- * ListMcpResources / ReadMcpResource - Access resources from MCP servers.
5
- */
6
-
7
- import type { ToolDefinition, ToolResult } from '../types.js'
8
- import type { MCPConnection } from '../mcp/client.js'
9
-
10
- // Registry of MCP connections (set by the agent)
11
- let mcpConnections: MCPConnection[] = []
12
-
13
- /**
14
- * Set MCP connections for resource access.
15
- */
16
- export function setMcpConnections(connections: MCPConnection[]): void {
17
- mcpConnections = connections
18
- }
19
-
20
- export const ListMcpResourcesTool: ToolDefinition = {
21
- name: 'ListMcpResources',
22
- description: 'List available resources from connected MCP servers. Resources can include files, databases, and other data sources.',
23
- inputSchema: {
24
- type: 'object',
25
- properties: {
26
- server: { type: 'string', description: 'Filter by MCP server name' },
27
- },
28
- },
29
- isReadOnly: () => true,
30
- isConcurrencySafe: () => true,
31
- isEnabled: () => true,
32
- async prompt() { return 'List MCP resources.' },
33
- async call(input: any): Promise<ToolResult> {
34
- const connections = input.server
35
- ? mcpConnections.filter(c => c.name === input.server)
36
- : mcpConnections
37
-
38
- if (connections.length === 0) {
39
- return {
40
- type: 'tool_result',
41
- tool_use_id: '',
42
- content: 'No MCP servers connected.',
43
- }
44
- }
45
-
46
- const results: string[] = []
47
-
48
- for (const conn of connections) {
49
- if (conn.status !== 'connected') continue
50
-
51
- try {
52
- // Access the underlying client to list resources
53
- const resources = (conn as any)._client?.listResources?.()
54
- if (resources) {
55
- results.push(`Server: ${conn.name}`)
56
- for (const r of resources) {
57
- results.push(` - ${r.name}: ${r.description || r.uri || ''}`)
58
- }
59
- } else {
60
- results.push(`Server: ${conn.name} (${conn.tools.length} tools available)`)
61
- }
62
- } catch {
63
- results.push(`Server: ${conn.name} (resource listing not supported)`)
64
- }
65
- }
66
-
67
- return {
68
- type: 'tool_result',
69
- tool_use_id: '',
70
- content: results.join('\n') || 'No resources found.',
71
- }
72
- },
73
- }
74
-
75
- export const ReadMcpResourceTool: ToolDefinition = {
76
- name: 'ReadMcpResource',
77
- description: 'Read a specific resource from an MCP server.',
78
- inputSchema: {
79
- type: 'object',
80
- properties: {
81
- server: { type: 'string', description: 'MCP server name' },
82
- uri: { type: 'string', description: 'Resource URI to read' },
83
- },
84
- required: ['server', 'uri'],
85
- },
86
- isReadOnly: () => true,
87
- isConcurrencySafe: () => true,
88
- isEnabled: () => true,
89
- async prompt() { return 'Read an MCP resource.' },
90
- async call(input: any): Promise<ToolResult> {
91
- const conn = mcpConnections.find(c => c.name === input.server)
92
- if (!conn) {
93
- return {
94
- type: 'tool_result',
95
- tool_use_id: '',
96
- content: `MCP server not found: ${input.server}`,
97
- is_error: true,
98
- }
99
- }
100
-
101
- try {
102
- const result = await (conn as any)._client?.readResource?.({ uri: input.uri })
103
- if (result?.contents) {
104
- const texts = result.contents.map((c: any) => c.text || JSON.stringify(c)).join('\n')
105
- return {
106
- type: 'tool_result',
107
- tool_use_id: '',
108
- content: texts,
109
- }
110
- }
111
- return {
112
- type: 'tool_result',
113
- tool_use_id: '',
114
- content: 'Resource read returned no content.',
115
- }
116
- } catch (err: any) {
117
- return {
118
- type: 'tool_result',
119
- tool_use_id: '',
120
- content: `Error reading resource: ${err.message}`,
121
- is_error: true,
122
- }
123
- }
124
- },
125
- }
@@ -1,93 +0,0 @@
1
- /**
2
- * NotebookEditTool - Edit Jupyter notebooks
3
- */
4
-
5
- import { readFile, writeFile } from 'fs/promises'
6
- import { resolve } from 'path'
7
- import { defineTool } from './types.js'
8
-
9
- export const NotebookEditTool = defineTool({
10
- name: 'NotebookEdit',
11
- description: 'Edit Jupyter notebook (.ipynb) cells. Can insert, replace, or delete cells.',
12
- inputSchema: {
13
- type: 'object',
14
- properties: {
15
- file_path: {
16
- type: 'string',
17
- description: 'Path to the .ipynb file',
18
- },
19
- command: {
20
- type: 'string',
21
- enum: ['insert', 'replace', 'delete'],
22
- description: 'The edit operation to perform',
23
- },
24
- cell_number: {
25
- type: 'number',
26
- description: 'Cell index (0-based) to operate on',
27
- },
28
- cell_type: {
29
- type: 'string',
30
- enum: ['code', 'markdown'],
31
- description: 'Type of cell (for insert/replace)',
32
- },
33
- source: {
34
- type: 'string',
35
- description: 'Cell content (for insert/replace)',
36
- },
37
- },
38
- required: ['file_path', 'command', 'cell_number'],
39
- },
40
- isReadOnly: false,
41
- isConcurrencySafe: false,
42
- async call(input, context) {
43
- const filePath = resolve(context.cwd, input.file_path)
44
-
45
- try {
46
- const content = await readFile(filePath, 'utf-8')
47
- const notebook = JSON.parse(content)
48
-
49
- if (!notebook.cells || !Array.isArray(notebook.cells)) {
50
- return { data: 'Error: Invalid notebook format', is_error: true }
51
- }
52
-
53
- const { command, cell_number, cell_type, source } = input
54
-
55
- switch (command) {
56
- case 'insert': {
57
- const newCell = {
58
- cell_type: cell_type || 'code',
59
- source: (source || '').split('\n').map((l: string, i: number, arr: string[]) =>
60
- i < arr.length - 1 ? l + '\n' : l
61
- ),
62
- metadata: {},
63
- ...(cell_type !== 'markdown' ? { outputs: [], execution_count: null } : {}),
64
- }
65
- notebook.cells.splice(cell_number, 0, newCell)
66
- break
67
- }
68
- case 'replace': {
69
- if (cell_number >= notebook.cells.length) {
70
- return { data: `Error: Cell ${cell_number} does not exist`, is_error: true }
71
- }
72
- notebook.cells[cell_number].source = (source || '').split('\n').map(
73
- (l: string, i: number, arr: string[]) => i < arr.length - 1 ? l + '\n' : l
74
- )
75
- if (cell_type) notebook.cells[cell_number].cell_type = cell_type
76
- break
77
- }
78
- case 'delete': {
79
- if (cell_number >= notebook.cells.length) {
80
- return { data: `Error: Cell ${cell_number} does not exist`, is_error: true }
81
- }
82
- notebook.cells.splice(cell_number, 1)
83
- break
84
- }
85
- }
86
-
87
- await writeFile(filePath, JSON.stringify(notebook, null, 1), 'utf-8')
88
- return `Notebook ${command}: cell ${cell_number} in ${filePath}`
89
- } catch (err: any) {
90
- return { data: `Error: ${err.message}`, is_error: true }
91
- }
92
- },
93
- })
@@ -1,88 +0,0 @@
1
- /**
2
- * Plan Mode Tools
3
- *
4
- * EnterPlanMode / ExitPlanMode - Structured planning workflow.
5
- * Allows the agent to enter a design/planning phase before execution.
6
- */
7
-
8
- import type { ToolDefinition, ToolResult } from '../types.js'
9
-
10
- // Track plan mode state
11
- let planModeActive = false
12
- let currentPlan: string | null = null
13
-
14
- export function isPlanModeActive(): boolean {
15
- return planModeActive
16
- }
17
-
18
- export function getCurrentPlan(): string | null {
19
- return currentPlan
20
- }
21
-
22
- export const EnterPlanModeTool: ToolDefinition = {
23
- name: 'EnterPlanMode',
24
- description: 'Enter plan/design mode for complex tasks. In plan mode, the agent focuses on designing the approach before executing.',
25
- inputSchema: {
26
- type: 'object',
27
- properties: {},
28
- },
29
- isReadOnly: () => false,
30
- isConcurrencySafe: () => false,
31
- isEnabled: () => true,
32
- async prompt() { return 'Enter plan mode for structured planning.' },
33
- async call(): Promise<ToolResult> {
34
- if (planModeActive) {
35
- return {
36
- type: 'tool_result',
37
- tool_use_id: '',
38
- content: 'Already in plan mode.',
39
- }
40
- }
41
-
42
- planModeActive = true
43
- currentPlan = null
44
-
45
- return {
46
- type: 'tool_result',
47
- tool_use_id: '',
48
- content: 'Entered plan mode. Design your approach before executing. Use ExitPlanMode when the plan is ready.',
49
- }
50
- },
51
- }
52
-
53
- export const ExitPlanModeTool: ToolDefinition = {
54
- name: 'ExitPlanMode',
55
- description: 'Exit plan mode with a completed plan. The plan will be recorded and execution can proceed.',
56
- inputSchema: {
57
- type: 'object',
58
- properties: {
59
- plan: { type: 'string', description: 'The completed plan' },
60
- approved: { type: 'boolean', description: 'Whether the plan is approved for execution' },
61
- },
62
- },
63
- isReadOnly: () => false,
64
- isConcurrencySafe: () => false,
65
- isEnabled: () => true,
66
- async prompt() { return 'Exit plan mode with a completed plan.' },
67
- async call(input: any): Promise<ToolResult> {
68
- if (!planModeActive) {
69
- return {
70
- type: 'tool_result',
71
- tool_use_id: '',
72
- content: 'Not in plan mode.',
73
- is_error: true,
74
- }
75
- }
76
-
77
- planModeActive = false
78
- currentPlan = input.plan || null
79
-
80
- const status = input.approved !== false ? 'approved' : 'pending approval'
81
-
82
- return {
83
- type: 'tool_result',
84
- tool_use_id: '',
85
- content: `Plan mode exited. Plan status: ${status}.${currentPlan ? `\n\nPlan:\n${currentPlan}` : ''}`,
86
- }
87
- },
88
- }
package/src/tools/read.ts DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * FileReadTool - Read file contents with line numbers
3
- */
4
-
5
- import { readFile, stat } from 'fs/promises'
6
- import { resolve } from 'path'
7
- import { defineTool } from './types.js'
8
-
9
- export const FileReadTool = defineTool({
10
- name: 'Read',
11
- description: 'Read a file from the filesystem. Returns content with line numbers. Supports text files, images (returns visual content), and PDFs.',
12
- inputSchema: {
13
- type: 'object',
14
- properties: {
15
- file_path: {
16
- type: 'string',
17
- description: 'The absolute path to the file to read',
18
- },
19
- offset: {
20
- type: 'number',
21
- description: 'Line number to start reading from (0-based)',
22
- },
23
- limit: {
24
- type: 'number',
25
- description: 'Maximum number of lines to read',
26
- },
27
- },
28
- required: ['file_path'],
29
- },
30
- isReadOnly: true,
31
- isConcurrencySafe: true,
32
- async call(input, context) {
33
- const filePath = resolve(context.cwd, input.file_path)
34
-
35
- try {
36
- const fileStat = await stat(filePath)
37
- if (fileStat.isDirectory()) {
38
- return { data: `Error: ${filePath} is a directory, not a file. Use Bash with 'ls' to list directory contents.`, is_error: true }
39
- }
40
-
41
- // Check for binary/image files
42
- const ext = filePath.split('.').pop()?.toLowerCase()
43
- if (['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg'].includes(ext || '')) {
44
- return `[Image file: ${filePath} (${fileStat.size} bytes)]`
45
- }
46
-
47
- const content = await readFile(filePath, 'utf-8')
48
- const lines = content.split('\n')
49
-
50
- const offset = input.offset || 0
51
- const limit = input.limit || 2000
52
- const selectedLines = lines.slice(offset, offset + limit)
53
-
54
- // Format with line numbers (cat -n style)
55
- const numbered = selectedLines.map((line: string, i: number) => {
56
- const lineNum = offset + i + 1
57
- return `${lineNum}\t${line}`
58
- }).join('\n')
59
-
60
- let result = numbered
61
- if (lines.length > offset + limit) {
62
- result += `\n\n(${lines.length - offset - limit} more lines not shown)`
63
- }
64
-
65
- return result || '(empty file)'
66
- } catch (err: any) {
67
- if (err.code === 'ENOENT') {
68
- return { data: `Error: File not found: ${filePath}`, is_error: true }
69
- }
70
- return { data: `Error reading file: ${err.message}`, is_error: true }
71
- }
72
- },
73
- })
@@ -1,96 +0,0 @@
1
- /**
2
- * SendMessageTool - Inter-agent messaging
3
- *
4
- * Supports plain text and structured protocol messages
5
- * between teammates in a multi-agent setup.
6
- */
7
-
8
- import type { ToolDefinition, ToolResult } from '../types.js'
9
-
10
- /**
11
- * Message inbox for inter-agent communication.
12
- */
13
- export interface AgentMessage {
14
- from: string
15
- to: string
16
- content: string
17
- timestamp: string
18
- type: 'text' | 'shutdown_request' | 'shutdown_response' | 'plan_approval_response'
19
- }
20
-
21
- const mailboxes = new Map<string, AgentMessage[]>()
22
-
23
- /**
24
- * Read messages from a mailbox.
25
- */
26
- export function readMailbox(agentName: string): AgentMessage[] {
27
- const messages = mailboxes.get(agentName) || []
28
- mailboxes.set(agentName, []) // Clear after reading
29
- return messages
30
- }
31
-
32
- /**
33
- * Write to a mailbox.
34
- */
35
- export function writeToMailbox(agentName: string, message: AgentMessage): void {
36
- const messages = mailboxes.get(agentName) || []
37
- messages.push(message)
38
- mailboxes.set(agentName, messages)
39
- }
40
-
41
- /**
42
- * Clear all mailboxes.
43
- */
44
- export function clearMailboxes(): void {
45
- mailboxes.clear()
46
- }
47
-
48
- export const SendMessageTool: ToolDefinition = {
49
- name: 'SendMessage',
50
- description: 'Send a message to another agent or teammate. Supports plain text and structured protocol messages.',
51
- inputSchema: {
52
- type: 'object',
53
- properties: {
54
- to: { type: 'string', description: 'Recipient agent name or ID. Use "*" for broadcast.' },
55
- content: { type: 'string', description: 'Message content' },
56
- type: {
57
- type: 'string',
58
- enum: ['text', 'shutdown_request', 'shutdown_response', 'plan_approval_response'],
59
- description: 'Message type (default: text)',
60
- },
61
- },
62
- required: ['to', 'content'],
63
- },
64
- isReadOnly: () => false,
65
- isConcurrencySafe: () => true,
66
- isEnabled: () => true,
67
- async prompt() { return 'Send a message to another agent.' },
68
- async call(input: any): Promise<ToolResult> {
69
- const message: AgentMessage = {
70
- from: 'self',
71
- to: input.to,
72
- content: input.content,
73
- timestamp: new Date().toISOString(),
74
- type: input.type || 'text',
75
- }
76
-
77
- if (input.to === '*') {
78
- // Broadcast to all known mailboxes
79
- for (const [name] of mailboxes) {
80
- writeToMailbox(name, { ...message, to: name })
81
- }
82
- return {
83
- type: 'tool_result',
84
- tool_use_id: '',
85
- content: `Message broadcast to all agents`,
86
- }
87
- }
88
-
89
- writeToMailbox(input.to, message)
90
- return {
91
- type: 'tool_result',
92
- tool_use_id: '',
93
- content: `Message sent to ${input.to}`,
94
- }
95
- },
96
- }