@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
package/src/tools/edit.ts DELETED
@@ -1,74 +0,0 @@
1
- /**
2
- * FileEditTool - Precise string replacement in files
3
- */
4
-
5
- import { readFile, writeFile } from 'fs/promises'
6
- import { resolve } from 'path'
7
- import { defineTool } from './types.js'
8
-
9
- export const FileEditTool = defineTool({
10
- name: 'Edit',
11
- description: 'Perform exact string replacements in files. The old_string must match exactly (including whitespace and indentation). Use replace_all to change every occurrence.',
12
- inputSchema: {
13
- type: 'object',
14
- properties: {
15
- file_path: {
16
- type: 'string',
17
- description: 'The absolute path to the file to modify',
18
- },
19
- old_string: {
20
- type: 'string',
21
- description: 'The exact text to find and replace',
22
- },
23
- new_string: {
24
- type: 'string',
25
- description: 'The replacement text',
26
- },
27
- replace_all: {
28
- type: 'boolean',
29
- description: 'Replace all occurrences (default false)',
30
- },
31
- },
32
- required: ['file_path', 'old_string', 'new_string'],
33
- },
34
- isReadOnly: false,
35
- isConcurrencySafe: false,
36
- async call(input, context) {
37
- const filePath = resolve(context.cwd, input.file_path)
38
- const { old_string, new_string, replace_all } = input
39
-
40
- if (old_string === new_string) {
41
- return { data: 'Error: old_string and new_string are identical', is_error: true }
42
- }
43
-
44
- try {
45
- let content = await readFile(filePath, 'utf-8')
46
-
47
- if (!content.includes(old_string)) {
48
- return { data: `Error: old_string not found in ${filePath}. Make sure it matches exactly including whitespace.`, is_error: true }
49
- }
50
-
51
- if (!replace_all) {
52
- // Check uniqueness
53
- const count = content.split(old_string).length - 1
54
- if (count > 1) {
55
- return {
56
- data: `Error: old_string appears ${count} times in the file. Provide more context to make it unique, or set replace_all: true.`,
57
- is_error: true,
58
- }
59
- }
60
- content = content.replace(old_string, new_string)
61
- } else {
62
- content = content.split(old_string).join(new_string)
63
- }
64
-
65
- await writeFile(filePath, content, 'utf-8')
66
- return `File edited: ${filePath}`
67
- } catch (err: any) {
68
- if (err.code === 'ENOENT') {
69
- return { data: `Error: File not found: ${filePath}`, is_error: true }
70
- }
71
- return { data: `Error editing file: ${err.message}`, is_error: true }
72
- }
73
- },
74
- })
package/src/tools/glob.ts DELETED
@@ -1,77 +0,0 @@
1
- /**
2
- * GlobTool - File pattern matching
3
- */
4
-
5
- import { resolve } from 'path'
6
- import { defineTool } from './types.js'
7
-
8
- export const GlobTool = defineTool({
9
- name: 'Glob',
10
- description: 'Find files matching a glob pattern. Returns matching file paths sorted by modification time. Supports patterns like "**/*.ts", "src/**/*.js".',
11
- inputSchema: {
12
- type: 'object',
13
- properties: {
14
- pattern: {
15
- type: 'string',
16
- description: 'The glob pattern to match files against',
17
- },
18
- path: {
19
- type: 'string',
20
- description: 'The directory to search in (defaults to cwd)',
21
- },
22
- },
23
- required: ['pattern'],
24
- },
25
- isReadOnly: true,
26
- isConcurrencySafe: true,
27
- async call(input, context) {
28
- const searchDir = input.path ? resolve(context.cwd, input.path) : context.cwd
29
- const { pattern } = input
30
-
31
- try {
32
- // Use Node.js glob (available in Node 22+) or fall back to bash find
33
- const { glob } = await import('fs/promises')
34
-
35
- // @ts-ignore - glob is available in Node 22+
36
- if (typeof glob === 'function') {
37
- const matches: string[] = []
38
- // @ts-ignore
39
- for await (const entry of glob(pattern, { cwd: searchDir })) {
40
- matches.push(entry)
41
- if (matches.length >= 500) break
42
- }
43
- if (matches.length === 0) {
44
- return `No files matching pattern "${pattern}" in ${searchDir}`
45
- }
46
- return matches.join('\n')
47
- }
48
- } catch {
49
- // Fall through to bash-based approach
50
- }
51
-
52
- // Fallback: use bash find/glob
53
- const { spawn } = await import('child_process')
54
- return new Promise<string>((resolvePromise) => {
55
- // Use bash glob expansion or find
56
- const cmd = `shopt -s globstar nullglob 2>/dev/null; cd ${JSON.stringify(searchDir)} && ls -1d ${pattern} 2>/dev/null | head -500`
57
- const proc = spawn('bash', ['-c', cmd], {
58
- cwd: searchDir,
59
- timeout: 30000,
60
- })
61
-
62
- const chunks: Buffer[] = []
63
- proc.stdout?.on('data', (d: Buffer) => chunks.push(d))
64
- proc.on('close', () => {
65
- const result = Buffer.concat(chunks).toString('utf-8').trim()
66
- if (!result) {
67
- resolvePromise(`No files matching pattern "${pattern}" in ${searchDir}`)
68
- } else {
69
- resolvePromise(result)
70
- }
71
- })
72
- proc.on('error', () => {
73
- resolvePromise(`Error searching for files with pattern "${pattern}"`)
74
- })
75
- })
76
- },
77
- })
package/src/tools/grep.ts DELETED
@@ -1,168 +0,0 @@
1
- /**
2
- * GrepTool - Search file contents using regex
3
- */
4
-
5
- import { spawn } from 'child_process'
6
- import { resolve } from 'path'
7
- import { defineTool } from './types.js'
8
-
9
- export const GrepTool = defineTool({
10
- name: 'Grep',
11
- description: 'Search file contents using regex patterns. Uses ripgrep (rg) if available, falls back to grep. Supports file type filtering and context lines.',
12
- inputSchema: {
13
- type: 'object',
14
- properties: {
15
- pattern: {
16
- type: 'string',
17
- description: 'The regex pattern to search for',
18
- },
19
- path: {
20
- type: 'string',
21
- description: 'File or directory to search in (defaults to cwd)',
22
- },
23
- glob: {
24
- type: 'string',
25
- description: 'Glob pattern to filter files (e.g., "*.ts", "*.{js,jsx}")',
26
- },
27
- type: {
28
- type: 'string',
29
- description: 'File type filter (e.g., "ts", "py", "js")',
30
- },
31
- output_mode: {
32
- type: 'string',
33
- enum: ['content', 'files_with_matches', 'count'],
34
- description: 'Output mode (default: files_with_matches)',
35
- },
36
- '-i': {
37
- type: 'boolean',
38
- description: 'Case insensitive search',
39
- },
40
- '-n': {
41
- type: 'boolean',
42
- description: 'Show line numbers (default: true)',
43
- },
44
- '-A': { type: 'number', description: 'Lines after match' },
45
- '-B': { type: 'number', description: 'Lines before match' },
46
- '-C': { type: 'number', description: 'Context lines' },
47
- context: { type: 'number', description: 'Context lines (alias for -C)' },
48
- head_limit: { type: 'number', description: 'Limit output entries (default: 250)' },
49
- },
50
- required: ['pattern'],
51
- },
52
- isReadOnly: true,
53
- isConcurrencySafe: true,
54
- async call(input, context) {
55
- const searchPath = input.path ? resolve(context.cwd, input.path) : context.cwd
56
- const outputMode = input.output_mode || 'files_with_matches'
57
- const headLimit = input.head_limit ?? 250
58
-
59
- // Build rg command (fall back to grep if rg unavailable)
60
- const args: string[] = []
61
-
62
- // Try ripgrep first
63
- let cmd = 'rg'
64
-
65
- if (outputMode === 'files_with_matches') {
66
- args.push('--files-with-matches')
67
- } else if (outputMode === 'count') {
68
- args.push('--count')
69
- } else {
70
- // content mode
71
- if (input['-n'] !== false) args.push('--line-number')
72
- }
73
-
74
- if (input['-i']) args.push('--ignore-case')
75
- if (input['-A']) args.push('-A', String(input['-A']))
76
- if (input['-B']) args.push('-B', String(input['-B']))
77
- const ctx = input['-C'] ?? input.context
78
- if (ctx) args.push('-C', String(ctx))
79
- if (input.glob) args.push('--glob', input.glob)
80
- if (input.type) args.push('--type', input.type)
81
-
82
- args.push('--', input.pattern, searchPath)
83
-
84
- return new Promise<string>((resolvePromise) => {
85
- const proc = spawn(cmd, args, {
86
- cwd: context.cwd,
87
- timeout: 30000,
88
- })
89
-
90
- const chunks: Buffer[] = []
91
- const errChunks: Buffer[] = []
92
- proc.stdout?.on('data', (d: Buffer) => chunks.push(d))
93
- proc.stderr?.on('data', (d: Buffer) => errChunks.push(d))
94
-
95
- proc.on('close', (code) => {
96
- let result = Buffer.concat(chunks).toString('utf-8').trim()
97
-
98
- if (!result && code !== 0) {
99
- // Try fallback to grep
100
- const grepArgs = ['-r']
101
- if (input['-i']) grepArgs.push('-i')
102
- if (outputMode === 'files_with_matches') grepArgs.push('-l')
103
- if (outputMode === 'count') grepArgs.push('-c')
104
- if (outputMode === 'content' && input['-n'] !== false) grepArgs.push('-n')
105
- if (input.glob) grepArgs.push('--include', input.glob)
106
- grepArgs.push('--', input.pattern, searchPath)
107
-
108
- const grepProc = spawn('grep', grepArgs, {
109
- cwd: context.cwd,
110
- timeout: 30000,
111
- })
112
-
113
- const grepChunks: Buffer[] = []
114
- grepProc.stdout?.on('data', (d: Buffer) => grepChunks.push(d))
115
- grepProc.on('close', () => {
116
- const grepResult = Buffer.concat(grepChunks).toString('utf-8').trim()
117
- if (!grepResult) {
118
- resolvePromise(`No matches found for pattern "${input.pattern}"`)
119
- } else {
120
- // Apply head limit
121
- const lines = grepResult.split('\n')
122
- if (headLimit > 0 && lines.length > headLimit) {
123
- resolvePromise(lines.slice(0, headLimit).join('\n') + `\n... (${lines.length - headLimit} more)`)
124
- } else {
125
- resolvePromise(grepResult)
126
- }
127
- }
128
- })
129
- grepProc.on('error', () => {
130
- resolvePromise(`No matches found for pattern "${input.pattern}"`)
131
- })
132
- return
133
- }
134
-
135
- if (!result) {
136
- resolvePromise(`No matches found for pattern "${input.pattern}"`)
137
- return
138
- }
139
-
140
- // Apply head limit
141
- const lines = result.split('\n')
142
- if (headLimit > 0 && lines.length > headLimit) {
143
- result = lines.slice(0, headLimit).join('\n') + `\n... (${lines.length - headLimit} more)`
144
- }
145
-
146
- resolvePromise(result)
147
- })
148
-
149
- proc.on('error', () => {
150
- // rg not found, try grep directly
151
- const grepArgs = ['-r', '-n', '--', input.pattern, searchPath]
152
- const grepProc = spawn('grep', grepArgs, {
153
- cwd: context.cwd,
154
- timeout: 30000,
155
- })
156
- const grepChunks: Buffer[] = []
157
- grepProc.stdout?.on('data', (d: Buffer) => grepChunks.push(d))
158
- grepProc.on('close', () => {
159
- const grepResult = Buffer.concat(grepChunks).toString('utf-8').trim()
160
- resolvePromise(grepResult || `No matches found for pattern "${input.pattern}"`)
161
- })
162
- grepProc.on('error', () => {
163
- resolvePromise(`Error: neither rg nor grep available`)
164
- })
165
- })
166
- })
167
- },
168
- })
@@ -1,240 +0,0 @@
1
- /**
2
- * Tool Registry - All built-in tool definitions
3
- *
4
- * 30+ tools covering file I/O, execution, search, web, agents,
5
- * tasks, teams, messaging, worktree, planning, scheduling, and more.
6
- */
7
-
8
- import type { ToolDefinition } from '../types.js'
9
-
10
- // File I/O
11
- import { BashTool } from './bash.js'
12
- import { FileReadTool } from './read.js'
13
- import { FileWriteTool } from './write.js'
14
- import { FileEditTool } from './edit.js'
15
- import { GlobTool } from './glob.js'
16
- import { GrepTool } from './grep.js'
17
- import { NotebookEditTool } from './notebook-edit.js'
18
-
19
- // Web
20
- import { WebFetchTool } from './web-fetch.js'
21
- import { WebSearchTool } from './web-search.js'
22
-
23
- // Agent & Multi-agent
24
- import { AgentTool } from './agent-tool.js'
25
- import { SendMessageTool } from './send-message.js'
26
- import { TeamCreateTool, TeamDeleteTool } from './team-tools.js'
27
-
28
- // Tasks
29
- import {
30
- TaskCreateTool,
31
- TaskListTool,
32
- TaskUpdateTool,
33
- TaskGetTool,
34
- TaskStopTool,
35
- TaskOutputTool,
36
- } from './task-tools.js'
37
-
38
- // Worktree
39
- import { EnterWorktreeTool, ExitWorktreeTool } from './worktree-tools.js'
40
-
41
- // Planning
42
- import { EnterPlanModeTool, ExitPlanModeTool } from './plan-tools.js'
43
-
44
- // User interaction
45
- import { AskUserQuestionTool } from './ask-user.js'
46
-
47
- // Discovery
48
- import { ToolSearchTool } from './tool-search.js'
49
-
50
- // MCP Resources
51
- import { ListMcpResourcesTool, ReadMcpResourceTool } from './mcp-resource-tools.js'
52
-
53
- // Scheduling
54
- import { CronCreateTool, CronDeleteTool, CronListTool, RemoteTriggerTool } from './cron-tools.js'
55
-
56
- // LSP
57
- import { LSPTool } from './lsp-tool.js'
58
-
59
- // Config
60
- import { ConfigTool } from './config-tool.js'
61
-
62
- // Todo
63
- import { TodoWriteTool } from './todo-tool.js'
64
-
65
- // Skill
66
- import { SkillTool } from './skill-tool.js'
67
-
68
- /**
69
- * All built-in tools (30+).
70
- */
71
- const ALL_TOOLS: ToolDefinition[] = [
72
- // Core file I/O & execution
73
- BashTool,
74
- FileReadTool,
75
- FileWriteTool,
76
- FileEditTool,
77
- GlobTool,
78
- GrepTool,
79
- NotebookEditTool,
80
-
81
- // Web
82
- WebFetchTool,
83
- WebSearchTool,
84
-
85
- // Agent & Multi-agent
86
- AgentTool,
87
- SendMessageTool,
88
- TeamCreateTool,
89
- TeamDeleteTool,
90
-
91
- // Tasks
92
- TaskCreateTool,
93
- TaskListTool,
94
- TaskUpdateTool,
95
- TaskGetTool,
96
- TaskStopTool,
97
- TaskOutputTool,
98
-
99
- // Worktree
100
- EnterWorktreeTool,
101
- ExitWorktreeTool,
102
-
103
- // Planning
104
- EnterPlanModeTool,
105
- ExitPlanModeTool,
106
-
107
- // User interaction
108
- AskUserQuestionTool,
109
-
110
- // Discovery
111
- ToolSearchTool,
112
-
113
- // MCP Resources
114
- ListMcpResourcesTool,
115
- ReadMcpResourceTool,
116
-
117
- // Scheduling
118
- CronCreateTool,
119
- CronDeleteTool,
120
- CronListTool,
121
- RemoteTriggerTool,
122
-
123
- // LSP
124
- LSPTool,
125
-
126
- // Config
127
- ConfigTool,
128
-
129
- // Todo
130
- TodoWriteTool,
131
-
132
- // Skill
133
- SkillTool,
134
- ]
135
-
136
- /**
137
- * Get all built-in tools.
138
- */
139
- export function getAllBaseTools(): ToolDefinition[] {
140
- return [...ALL_TOOLS]
141
- }
142
-
143
- /**
144
- * Filter tools by allowed/disallowed lists.
145
- */
146
- export function filterTools(
147
- tools: ToolDefinition[],
148
- allowedTools?: string[],
149
- disallowedTools?: string[],
150
- ): ToolDefinition[] {
151
- let filtered = tools
152
-
153
- if (allowedTools && allowedTools.length > 0) {
154
- const allowed = new Set(allowedTools)
155
- filtered = filtered.filter((t) => allowed.has(t.name))
156
- }
157
-
158
- if (disallowedTools && disallowedTools.length > 0) {
159
- const disallowed = new Set(disallowedTools)
160
- filtered = filtered.filter((t) => !disallowed.has(t.name))
161
- }
162
-
163
- return filtered
164
- }
165
-
166
- /**
167
- * Assemble tool pool: base tools + MCP tools, with deduplication.
168
- */
169
- export function assembleToolPool(
170
- baseTools: ToolDefinition[],
171
- mcpTools: ToolDefinition[] = [],
172
- allowedTools?: string[],
173
- disallowedTools?: string[],
174
- ): ToolDefinition[] {
175
- const combined = [...baseTools, ...mcpTools]
176
-
177
- // Deduplicate by name (later definitions override)
178
- const byName = new Map<string, ToolDefinition>()
179
- for (const tool of combined) {
180
- byName.set(tool.name, tool)
181
- }
182
-
183
- let tools = Array.from(byName.values())
184
- return filterTools(tools, allowedTools, disallowedTools)
185
- }
186
-
187
- // Re-export individual tools
188
- export {
189
- // Core
190
- BashTool,
191
- FileReadTool,
192
- FileWriteTool,
193
- FileEditTool,
194
- GlobTool,
195
- GrepTool,
196
- NotebookEditTool,
197
- WebFetchTool,
198
- WebSearchTool,
199
- // Agent
200
- AgentTool,
201
- SendMessageTool,
202
- TeamCreateTool,
203
- TeamDeleteTool,
204
- // Tasks
205
- TaskCreateTool,
206
- TaskListTool,
207
- TaskUpdateTool,
208
- TaskGetTool,
209
- TaskStopTool,
210
- TaskOutputTool,
211
- // Worktree
212
- EnterWorktreeTool,
213
- ExitWorktreeTool,
214
- // Planning
215
- EnterPlanModeTool,
216
- ExitPlanModeTool,
217
- // User
218
- AskUserQuestionTool,
219
- // Discovery
220
- ToolSearchTool,
221
- // MCP
222
- ListMcpResourcesTool,
223
- ReadMcpResourceTool,
224
- // Scheduling
225
- CronCreateTool,
226
- CronDeleteTool,
227
- CronListTool,
228
- RemoteTriggerTool,
229
- // LSP
230
- LSPTool,
231
- // Config
232
- ConfigTool,
233
- // Todo
234
- TodoWriteTool,
235
- // Skill
236
- SkillTool,
237
- }
238
-
239
- // Re-export helpers
240
- export { defineTool, toApiTool } from './types.js'