bincode-cli 1.0.1

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 (300) hide show
  1. package/AGENTS.md +27 -0
  2. package/README.md +15 -0
  3. package/bin/bincode +98 -0
  4. package/bunfig.toml +4 -0
  5. package/package.json +124 -0
  6. package/parsers-config.ts +239 -0
  7. package/script/build.ts +167 -0
  8. package/script/postinstall.mjs +206 -0
  9. package/script/publish.ts +99 -0
  10. package/script/schema.ts +47 -0
  11. package/src/acp/README.md +164 -0
  12. package/src/acp/agent.ts +1051 -0
  13. package/src/acp/session.ts +101 -0
  14. package/src/acp/types.ts +22 -0
  15. package/src/agent/agent.ts +398 -0
  16. package/src/agent/generate.txt +75 -0
  17. package/src/agent/prompt/compaction.txt +12 -0
  18. package/src/agent/prompt/explore.txt +18 -0
  19. package/src/agent/prompt/summary.txt +10 -0
  20. package/src/agent/prompt/title.txt +36 -0
  21. package/src/auth/bineric-login.ts +506 -0
  22. package/src/auth/index.ts +70 -0
  23. package/src/bun/index.ts +114 -0
  24. package/src/bus/bus-event.ts +43 -0
  25. package/src/bus/global.ts +10 -0
  26. package/src/bus/index.ts +105 -0
  27. package/src/cli/auth-check.ts +61 -0
  28. package/src/cli/bootstrap.ts +21 -0
  29. package/src/cli/cmd/acp.ts +88 -0
  30. package/src/cli/cmd/agent.ts +256 -0
  31. package/src/cli/cmd/auth.ts +436 -0
  32. package/src/cli/cmd/cmd.ts +7 -0
  33. package/src/cli/cmd/debug/config.ts +15 -0
  34. package/src/cli/cmd/debug/file.ts +91 -0
  35. package/src/cli/cmd/debug/index.ts +43 -0
  36. package/src/cli/cmd/debug/lsp.ts +48 -0
  37. package/src/cli/cmd/debug/ripgrep.ts +83 -0
  38. package/src/cli/cmd/debug/scrap.ts +15 -0
  39. package/src/cli/cmd/debug/skill.ts +15 -0
  40. package/src/cli/cmd/debug/snapshot.ts +48 -0
  41. package/src/cli/cmd/export.ts +88 -0
  42. package/src/cli/cmd/generate.ts +38 -0
  43. package/src/cli/cmd/github.ts +1399 -0
  44. package/src/cli/cmd/import.ts +98 -0
  45. package/src/cli/cmd/login.ts +112 -0
  46. package/src/cli/cmd/logout.ts +38 -0
  47. package/src/cli/cmd/mcp.ts +654 -0
  48. package/src/cli/cmd/models.ts +77 -0
  49. package/src/cli/cmd/pr.ts +112 -0
  50. package/src/cli/cmd/run.ts +368 -0
  51. package/src/cli/cmd/serve.ts +31 -0
  52. package/src/cli/cmd/session.ts +106 -0
  53. package/src/cli/cmd/stats.ts +298 -0
  54. package/src/cli/cmd/tui/app.tsx +669 -0
  55. package/src/cli/cmd/tui/attach.ts +30 -0
  56. package/src/cli/cmd/tui/component/border.tsx +21 -0
  57. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  58. package/src/cli/cmd/tui/component/dialog-command.tsx +123 -0
  59. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  60. package/src/cli/cmd/tui/component/dialog-model.tsx +223 -0
  61. package/src/cli/cmd/tui/component/dialog-provider.tsx +224 -0
  62. package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
  63. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  64. package/src/cli/cmd/tui/component/dialog-status.tsx +162 -0
  65. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  66. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  67. package/src/cli/cmd/tui/component/logo.tsx +32 -0
  68. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +560 -0
  69. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  70. package/src/cli/cmd/tui/component/prompt/index.tsx +1052 -0
  71. package/src/cli/cmd/tui/context/args.tsx +14 -0
  72. package/src/cli/cmd/tui/context/directory.ts +13 -0
  73. package/src/cli/cmd/tui/context/exit.tsx +23 -0
  74. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  75. package/src/cli/cmd/tui/context/keybind.tsx +101 -0
  76. package/src/cli/cmd/tui/context/kv.tsx +49 -0
  77. package/src/cli/cmd/tui/context/local.tsx +339 -0
  78. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  79. package/src/cli/cmd/tui/context/route.tsx +46 -0
  80. package/src/cli/cmd/tui/context/sdk.tsx +74 -0
  81. package/src/cli/cmd/tui/context/sync.tsx +372 -0
  82. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  83. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  84. package/src/cli/cmd/tui/context/theme/bincode.json +245 -0
  85. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  86. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  87. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  88. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  89. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  90. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  91. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  92. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  93. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  94. package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
  95. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  96. package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -0
  97. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  98. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  99. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  100. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  101. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  102. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  103. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  104. package/src/cli/cmd/tui/context/theme/orng.json +245 -0
  105. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  106. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  107. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  108. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  109. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  110. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  111. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  112. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  113. package/src/cli/cmd/tui/context/theme.tsx +1109 -0
  114. package/src/cli/cmd/tui/event.ts +40 -0
  115. package/src/cli/cmd/tui/routes/home.tsx +105 -0
  116. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  117. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  118. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  119. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  120. package/src/cli/cmd/tui/routes/session/footer.tsx +88 -0
  121. package/src/cli/cmd/tui/routes/session/header.tsx +141 -0
  122. package/src/cli/cmd/tui/routes/session/index.tsx +1888 -0
  123. package/src/cli/cmd/tui/routes/session/sidebar.tsx +321 -0
  124. package/src/cli/cmd/tui/spawn.ts +60 -0
  125. package/src/cli/cmd/tui/thread.ts +120 -0
  126. package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
  127. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
  128. package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
  129. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
  130. package/src/cli/cmd/tui/ui/dialog-select.tsx +330 -0
  131. package/src/cli/cmd/tui/ui/dialog.tsx +170 -0
  132. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  133. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  134. package/src/cli/cmd/tui/util/clipboard.ts +127 -0
  135. package/src/cli/cmd/tui/util/editor.ts +32 -0
  136. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  137. package/src/cli/cmd/tui/worker.ts +63 -0
  138. package/src/cli/cmd/uninstall.ts +344 -0
  139. package/src/cli/cmd/upgrade.ts +67 -0
  140. package/src/cli/cmd/web.ts +84 -0
  141. package/src/cli/error.ts +55 -0
  142. package/src/cli/ui.ts +84 -0
  143. package/src/cli/upgrade.ts +25 -0
  144. package/src/command/index.ts +80 -0
  145. package/src/command/template/initialize.txt +10 -0
  146. package/src/command/template/review.txt +97 -0
  147. package/src/config/config.ts +995 -0
  148. package/src/config/markdown.ts +41 -0
  149. package/src/env/index.ts +26 -0
  150. package/src/file/ignore.ts +83 -0
  151. package/src/file/index.ts +328 -0
  152. package/src/file/ripgrep.ts +393 -0
  153. package/src/file/time.ts +64 -0
  154. package/src/file/watcher.ts +103 -0
  155. package/src/flag/flag.ts +46 -0
  156. package/src/format/formatter.ts +315 -0
  157. package/src/format/index.ts +137 -0
  158. package/src/global/index.ts +52 -0
  159. package/src/id/id.ts +73 -0
  160. package/src/ide/index.ts +76 -0
  161. package/src/index.ts +217 -0
  162. package/src/installation/index.ts +196 -0
  163. package/src/lsp/client.ts +229 -0
  164. package/src/lsp/index.ts +485 -0
  165. package/src/lsp/language.ts +116 -0
  166. package/src/lsp/server.ts +1895 -0
  167. package/src/mcp/auth.ts +135 -0
  168. package/src/mcp/index.ts +654 -0
  169. package/src/mcp/oauth-callback.ts +200 -0
  170. package/src/mcp/oauth-provider.ts +154 -0
  171. package/src/patch/index.ts +622 -0
  172. package/src/permission/index.ts +199 -0
  173. package/src/plugin/index.ts +101 -0
  174. package/src/project/bootstrap.ts +31 -0
  175. package/src/project/instance.ts +78 -0
  176. package/src/project/project.ts +221 -0
  177. package/src/project/state.ts +65 -0
  178. package/src/project/vcs.ts +76 -0
  179. package/src/provider/auth.ts +143 -0
  180. package/src/provider/models-macro.ts +11 -0
  181. package/src/provider/models.ts +106 -0
  182. package/src/provider/provider.ts +1071 -0
  183. package/src/provider/sdk/openai-compatible/src/README.md +5 -0
  184. package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  185. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +101 -0
  186. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  187. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
  188. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  189. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  190. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  191. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
  192. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  193. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  194. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  195. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  196. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  197. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  198. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  199. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  200. package/src/provider/transform.ts +455 -0
  201. package/src/pty/index.ts +231 -0
  202. package/src/server/error.ts +36 -0
  203. package/src/server/project.ts +79 -0
  204. package/src/server/server.ts +2642 -0
  205. package/src/server/tui.ts +71 -0
  206. package/src/session/compaction.ts +223 -0
  207. package/src/session/index.ts +458 -0
  208. package/src/session/llm.ts +201 -0
  209. package/src/session/message-v2.ts +659 -0
  210. package/src/session/message.ts +189 -0
  211. package/src/session/processor.ts +409 -0
  212. package/src/session/prompt/anthropic-20250930.txt +166 -0
  213. package/src/session/prompt/anthropic.txt +104 -0
  214. package/src/session/prompt/anthropic_spoof.txt +1 -0
  215. package/src/session/prompt/beast.txt +147 -0
  216. package/src/session/prompt/build-switch.txt +5 -0
  217. package/src/session/prompt/codex.txt +318 -0
  218. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  219. package/src/session/prompt/gemini.txt +155 -0
  220. package/src/session/prompt/max-steps.txt +16 -0
  221. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  222. package/src/session/prompt/plan.txt +26 -0
  223. package/src/session/prompt/polaris.txt +106 -0
  224. package/src/session/prompt/qwen.txt +109 -0
  225. package/src/session/prompt.ts +1446 -0
  226. package/src/session/retry.ts +86 -0
  227. package/src/session/revert.ts +108 -0
  228. package/src/session/status.ts +76 -0
  229. package/src/session/summary.ts +194 -0
  230. package/src/session/system.ts +120 -0
  231. package/src/session/todo.ts +37 -0
  232. package/src/share/share-next.ts +194 -0
  233. package/src/share/share.ts +87 -0
  234. package/src/shell/shell.ts +67 -0
  235. package/src/skill/index.ts +1 -0
  236. package/src/skill/skill.ts +83 -0
  237. package/src/snapshot/index.ts +197 -0
  238. package/src/storage/storage.ts +226 -0
  239. package/src/tool/bash.ts +306 -0
  240. package/src/tool/bash.txt +158 -0
  241. package/src/tool/batch.ts +175 -0
  242. package/src/tool/batch.txt +24 -0
  243. package/src/tool/codesearch.ts +138 -0
  244. package/src/tool/codesearch.txt +12 -0
  245. package/src/tool/edit.ts +675 -0
  246. package/src/tool/edit.txt +10 -0
  247. package/src/tool/glob.ts +65 -0
  248. package/src/tool/glob.txt +6 -0
  249. package/src/tool/grep.ts +121 -0
  250. package/src/tool/grep.txt +8 -0
  251. package/src/tool/invalid.ts +17 -0
  252. package/src/tool/ls.ts +110 -0
  253. package/src/tool/ls.txt +1 -0
  254. package/src/tool/lsp-diagnostics.ts +26 -0
  255. package/src/tool/lsp-diagnostics.txt +1 -0
  256. package/src/tool/lsp-hover.ts +31 -0
  257. package/src/tool/lsp-hover.txt +1 -0
  258. package/src/tool/lsp.ts +87 -0
  259. package/src/tool/lsp.txt +19 -0
  260. package/src/tool/multiedit.ts +46 -0
  261. package/src/tool/multiedit.txt +41 -0
  262. package/src/tool/patch.ts +233 -0
  263. package/src/tool/patch.txt +1 -0
  264. package/src/tool/read.ts +219 -0
  265. package/src/tool/read.txt +12 -0
  266. package/src/tool/registry.ts +162 -0
  267. package/src/tool/skill.ts +100 -0
  268. package/src/tool/task.ts +136 -0
  269. package/src/tool/task.txt +60 -0
  270. package/src/tool/todo.ts +39 -0
  271. package/src/tool/todoread.txt +14 -0
  272. package/src/tool/todowrite.txt +167 -0
  273. package/src/tool/tool.ts +71 -0
  274. package/src/tool/webfetch.ts +187 -0
  275. package/src/tool/webfetch.txt +13 -0
  276. package/src/tool/websearch.ts +150 -0
  277. package/src/tool/websearch.txt +11 -0
  278. package/src/tool/write.ts +110 -0
  279. package/src/tool/write.txt +8 -0
  280. package/src/util/archive.ts +16 -0
  281. package/src/util/color.ts +19 -0
  282. package/src/util/context.ts +25 -0
  283. package/src/util/defer.ts +12 -0
  284. package/src/util/eventloop.ts +20 -0
  285. package/src/util/filesystem.ts +83 -0
  286. package/src/util/fn.ts +11 -0
  287. package/src/util/iife.ts +3 -0
  288. package/src/util/keybind.ts +102 -0
  289. package/src/util/lazy.ts +11 -0
  290. package/src/util/locale.ts +81 -0
  291. package/src/util/lock.ts +98 -0
  292. package/src/util/log.ts +180 -0
  293. package/src/util/queue.ts +32 -0
  294. package/src/util/rpc.ts +42 -0
  295. package/src/util/scrap.ts +10 -0
  296. package/src/util/signal.ts +12 -0
  297. package/src/util/timeout.ts +14 -0
  298. package/src/util/token.ts +7 -0
  299. package/src/util/wildcard.ts +54 -0
  300. package/tsconfig.json +16 -0
@@ -0,0 +1,65 @@
1
+ import z from "zod"
2
+ import path from "path"
3
+ import { Tool } from "./tool"
4
+ import DESCRIPTION from "./glob.txt"
5
+ import { Ripgrep } from "../file/ripgrep"
6
+ import { Instance } from "../project/instance"
7
+
8
+ export const GlobTool = Tool.define("glob", {
9
+ description: DESCRIPTION,
10
+ parameters: z.object({
11
+ pattern: z.string().describe("The glob pattern to match files against"),
12
+ path: z
13
+ .string()
14
+ .optional()
15
+ .describe(
16
+ `The directory to search in. If not specified, the current working directory will be used. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Must be a valid directory path if provided.`,
17
+ ),
18
+ }),
19
+ async execute(params) {
20
+ let search = params.path ?? Instance.directory
21
+ search = path.isAbsolute(search) ? search : path.resolve(Instance.directory, search)
22
+
23
+ const limit = 100
24
+ const files = []
25
+ let truncated = false
26
+ for await (const file of Ripgrep.files({
27
+ cwd: search,
28
+ glob: [params.pattern],
29
+ })) {
30
+ if (files.length >= limit) {
31
+ truncated = true
32
+ break
33
+ }
34
+ const full = path.resolve(search, file)
35
+ const stats = await Bun.file(full)
36
+ .stat()
37
+ .then((x) => x.mtime.getTime())
38
+ .catch(() => 0)
39
+ files.push({
40
+ path: full,
41
+ mtime: stats,
42
+ })
43
+ }
44
+ files.sort((a, b) => b.mtime - a.mtime)
45
+
46
+ const output = []
47
+ if (files.length === 0) output.push("No files found")
48
+ if (files.length > 0) {
49
+ output.push(...files.map((f) => f.path))
50
+ if (truncated) {
51
+ output.push("")
52
+ output.push("(Results are truncated. Consider using a more specific path or pattern.)")
53
+ }
54
+ }
55
+
56
+ return {
57
+ title: path.relative(Instance.worktree, search),
58
+ metadata: {
59
+ count: files.length,
60
+ truncated,
61
+ },
62
+ output: output.join("\n"),
63
+ }
64
+ },
65
+ })
@@ -0,0 +1,6 @@
1
+ - Fast file pattern matching tool that works with any codebase size
2
+ - Supports glob patterns like "**/*.js" or "src/**/*.ts"
3
+ - Returns matching file paths sorted by modification time
4
+ - Use this tool when you need to find files by name patterns
5
+ - When you are doing an open ended search that may require multiple rounds of globbing and grepping, use the Task tool instead
6
+ - You have the capability to call multiple tools in a single response. It is always better to speculatively perform multiple searches as a batch that are potentially useful.
@@ -0,0 +1,121 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+ import { Ripgrep } from "../file/ripgrep"
4
+
5
+ import DESCRIPTION from "./grep.txt"
6
+ import { Instance } from "../project/instance"
7
+
8
+ const MAX_LINE_LENGTH = 2000
9
+
10
+ export const GrepTool = Tool.define("grep", {
11
+ description: DESCRIPTION,
12
+ parameters: z.object({
13
+ pattern: z.string().describe("The regex pattern to search for in file contents"),
14
+ path: z.string().optional().describe("The directory to search in. Defaults to the current working directory."),
15
+ include: z.string().optional().describe('File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")'),
16
+ }),
17
+ async execute(params) {
18
+ if (!params.pattern) {
19
+ throw new Error("pattern is required")
20
+ }
21
+
22
+ const searchPath = params.path || Instance.directory
23
+
24
+ const rgPath = await Ripgrep.filepath()
25
+ const args = ["-nH", "--field-match-separator=|", "--regexp", params.pattern]
26
+ if (params.include) {
27
+ args.push("--glob", params.include)
28
+ }
29
+ args.push(searchPath)
30
+
31
+ const proc = Bun.spawn([rgPath, ...args], {
32
+ stdout: "pipe",
33
+ stderr: "pipe",
34
+ })
35
+
36
+ const output = await new Response(proc.stdout).text()
37
+ const errorOutput = await new Response(proc.stderr).text()
38
+ const exitCode = await proc.exited
39
+
40
+ if (exitCode === 1) {
41
+ return {
42
+ title: params.pattern,
43
+ metadata: { matches: 0, truncated: false },
44
+ output: "No files found",
45
+ }
46
+ }
47
+
48
+ if (exitCode !== 0) {
49
+ throw new Error(`ripgrep failed: ${errorOutput}`)
50
+ }
51
+
52
+ // Handle both Unix (\n) and Windows (\r\n) line endings
53
+ const lines = output.trim().split(/\r?\n/)
54
+ const matches = []
55
+
56
+ for (const line of lines) {
57
+ if (!line) continue
58
+
59
+ const [filePath, lineNumStr, ...lineTextParts] = line.split("|")
60
+ if (!filePath || !lineNumStr || lineTextParts.length === 0) continue
61
+
62
+ const lineNum = parseInt(lineNumStr, 10)
63
+ const lineText = lineTextParts.join("|")
64
+
65
+ const file = Bun.file(filePath)
66
+ const stats = await file.stat().catch(() => null)
67
+ if (!stats) continue
68
+
69
+ matches.push({
70
+ path: filePath,
71
+ modTime: stats.mtime.getTime(),
72
+ lineNum,
73
+ lineText,
74
+ })
75
+ }
76
+
77
+ matches.sort((a, b) => b.modTime - a.modTime)
78
+
79
+ const limit = 100
80
+ const truncated = matches.length > limit
81
+ const finalMatches = truncated ? matches.slice(0, limit) : matches
82
+
83
+ if (finalMatches.length === 0) {
84
+ return {
85
+ title: params.pattern,
86
+ metadata: { matches: 0, truncated: false },
87
+ output: "No files found",
88
+ }
89
+ }
90
+
91
+ const outputLines = [`Found ${finalMatches.length} matches`]
92
+
93
+ let currentFile = ""
94
+ for (const match of finalMatches) {
95
+ if (currentFile !== match.path) {
96
+ if (currentFile !== "") {
97
+ outputLines.push("")
98
+ }
99
+ currentFile = match.path
100
+ outputLines.push(`${match.path}:`)
101
+ }
102
+ const truncatedLineText =
103
+ match.lineText.length > MAX_LINE_LENGTH ? match.lineText.substring(0, MAX_LINE_LENGTH) + "..." : match.lineText
104
+ outputLines.push(` Line ${match.lineNum}: ${truncatedLineText}`)
105
+ }
106
+
107
+ if (truncated) {
108
+ outputLines.push("")
109
+ outputLines.push("(Results are truncated. Consider using a more specific path or pattern.)")
110
+ }
111
+
112
+ return {
113
+ title: params.pattern,
114
+ metadata: {
115
+ matches: finalMatches.length,
116
+ truncated,
117
+ },
118
+ output: outputLines.join("\n"),
119
+ }
120
+ },
121
+ })
@@ -0,0 +1,8 @@
1
+ - Fast content search tool that works with any codebase size
2
+ - Searches file contents using regular expressions
3
+ - Supports full regex syntax (eg. "log.*Error", "function\s+\w+", etc.)
4
+ - Filter files by pattern with the include parameter (eg. "*.js", "*.{ts,tsx}")
5
+ - Returns file paths and line numbers with at least one match sorted by modification time
6
+ - Use this tool when you need to find files containing specific patterns
7
+ - If you need to identify/count the number of matches within files, use the Bash tool with `rg` (ripgrep) directly. Do NOT use `grep`.
8
+ - When you are doing an open ended search that may require multiple rounds of globbing and grepping, use the Task tool instead
@@ -0,0 +1,17 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+
4
+ export const InvalidTool = Tool.define("invalid", {
5
+ description: "Do not use",
6
+ parameters: z.object({
7
+ tool: z.string(),
8
+ error: z.string(),
9
+ }),
10
+ async execute(params) {
11
+ return {
12
+ title: "Invalid Tool",
13
+ output: `The arguments provided to the tool are invalid: ${params.error}`,
14
+ metadata: {},
15
+ }
16
+ },
17
+ })
package/src/tool/ls.ts ADDED
@@ -0,0 +1,110 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+ import * as path from "path"
4
+ import DESCRIPTION from "./ls.txt"
5
+ import { Instance } from "../project/instance"
6
+ import { Ripgrep } from "../file/ripgrep"
7
+
8
+ export const IGNORE_PATTERNS = [
9
+ "node_modules/",
10
+ "__pycache__/",
11
+ ".git/",
12
+ "dist/",
13
+ "build/",
14
+ "target/",
15
+ "vendor/",
16
+ "bin/",
17
+ "obj/",
18
+ ".idea/",
19
+ ".vscode/",
20
+ ".zig-cache/",
21
+ "zig-out",
22
+ ".coverage",
23
+ "coverage/",
24
+ "vendor/",
25
+ "tmp/",
26
+ "temp/",
27
+ ".cache/",
28
+ "cache/",
29
+ "logs/",
30
+ ".venv/",
31
+ "venv/",
32
+ "env/",
33
+ ]
34
+
35
+ const LIMIT = 100
36
+
37
+ export const ListTool = Tool.define("list", {
38
+ description: DESCRIPTION,
39
+ parameters: z.object({
40
+ path: z.string().describe("The absolute path to the directory to list (must be absolute, not relative)").optional(),
41
+ ignore: z.array(z.string()).describe("List of glob patterns to ignore").optional(),
42
+ }),
43
+ async execute(params) {
44
+ const searchPath = path.resolve(Instance.directory, params.path || ".")
45
+
46
+ const ignoreGlobs = IGNORE_PATTERNS.map((p) => `!${p}*`).concat(params.ignore?.map((p) => `!${p}`) || [])
47
+ const files = []
48
+ for await (const file of Ripgrep.files({ cwd: searchPath, glob: ignoreGlobs })) {
49
+ files.push(file)
50
+ if (files.length >= LIMIT) break
51
+ }
52
+
53
+ // Build directory structure
54
+ const dirs = new Set<string>()
55
+ const filesByDir = new Map<string, string[]>()
56
+
57
+ for (const file of files) {
58
+ const dir = path.dirname(file)
59
+ const parts = dir === "." ? [] : dir.split("/")
60
+
61
+ // Add all parent directories
62
+ for (let i = 0; i <= parts.length; i++) {
63
+ const dirPath = i === 0 ? "." : parts.slice(0, i).join("/")
64
+ dirs.add(dirPath)
65
+ }
66
+
67
+ // Add file to its directory
68
+ if (!filesByDir.has(dir)) filesByDir.set(dir, [])
69
+ filesByDir.get(dir)!.push(path.basename(file))
70
+ }
71
+
72
+ function renderDir(dirPath: string, depth: number): string {
73
+ const indent = " ".repeat(depth)
74
+ let output = ""
75
+
76
+ if (depth > 0) {
77
+ output += `${indent}${path.basename(dirPath)}/\n`
78
+ }
79
+
80
+ const childIndent = " ".repeat(depth + 1)
81
+ const children = Array.from(dirs)
82
+ .filter((d) => path.dirname(d) === dirPath && d !== dirPath)
83
+ .sort()
84
+
85
+ // Render subdirectories first
86
+ for (const child of children) {
87
+ output += renderDir(child, depth + 1)
88
+ }
89
+
90
+ // Render files
91
+ const files = filesByDir.get(dirPath) || []
92
+ for (const file of files.sort()) {
93
+ output += `${childIndent}${file}\n`
94
+ }
95
+
96
+ return output
97
+ }
98
+
99
+ const output = `${searchPath}/\n` + renderDir(".", 0)
100
+
101
+ return {
102
+ title: path.relative(Instance.worktree, searchPath),
103
+ metadata: {
104
+ count: files.length,
105
+ truncated: files.length >= LIMIT,
106
+ },
107
+ output,
108
+ }
109
+ },
110
+ })
@@ -0,0 +1 @@
1
+ Lists files and directories in a given path. The path parameter must be absolute; omit it to use the current workspace directory. You can optionally provide an array of glob patterns to ignore with the ignore parameter. You should generally prefer the Glob and Grep tools, if you know which directories to search.
@@ -0,0 +1,26 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+ import path from "path"
4
+ import { LSP } from "../lsp"
5
+ import DESCRIPTION from "./lsp-diagnostics.txt"
6
+ import { Instance } from "../project/instance"
7
+
8
+ export const LspDiagnosticTool = Tool.define("lsp_diagnostics", {
9
+ description: DESCRIPTION,
10
+ parameters: z.object({
11
+ path: z.string().describe("The path to the file to get diagnostics."),
12
+ }),
13
+ execute: async (args) => {
14
+ const normalized = path.isAbsolute(args.path) ? args.path : path.join(Instance.directory, args.path)
15
+ await LSP.touchFile(normalized, true)
16
+ const diagnostics = await LSP.diagnostics()
17
+ const file = diagnostics[normalized]
18
+ return {
19
+ title: path.relative(Instance.worktree, normalized),
20
+ metadata: {
21
+ diagnostics,
22
+ },
23
+ output: file?.length ? file.map(LSP.Diagnostic.pretty).join("\n") : "No errors found",
24
+ }
25
+ },
26
+ })
@@ -0,0 +1 @@
1
+ do not use
@@ -0,0 +1,31 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+ import path from "path"
4
+ import { LSP } from "../lsp"
5
+ import DESCRIPTION from "./lsp-hover.txt"
6
+ import { Instance } from "../project/instance"
7
+
8
+ export const LspHoverTool = Tool.define("lsp_hover", {
9
+ description: DESCRIPTION,
10
+ parameters: z.object({
11
+ file: z.string().describe("The path to the file to get diagnostics."),
12
+ line: z.number().describe("The line number to get diagnostics."),
13
+ character: z.number().describe("The character number to get diagnostics."),
14
+ }),
15
+ execute: async (args) => {
16
+ const file = path.isAbsolute(args.file) ? args.file : path.join(Instance.directory, args.file)
17
+ await LSP.touchFile(file, true)
18
+ const result = await LSP.hover({
19
+ ...args,
20
+ file,
21
+ })
22
+
23
+ return {
24
+ title: path.relative(Instance.worktree, file) + ":" + args.line + ":" + args.character,
25
+ metadata: {
26
+ result,
27
+ },
28
+ output: JSON.stringify(result, null, 2),
29
+ }
30
+ },
31
+ })
@@ -0,0 +1 @@
1
+ do not use
@@ -0,0 +1,87 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+ import path from "path"
4
+ import { LSP } from "../lsp"
5
+ import DESCRIPTION from "./lsp.txt"
6
+ import { Instance } from "../project/instance"
7
+ import { pathToFileURL } from "url"
8
+
9
+ const operations = [
10
+ "goToDefinition",
11
+ "findReferences",
12
+ "hover",
13
+ "documentSymbol",
14
+ "workspaceSymbol",
15
+ "goToImplementation",
16
+ "prepareCallHierarchy",
17
+ "incomingCalls",
18
+ "outgoingCalls",
19
+ ] as const
20
+
21
+ export const LspTool = Tool.define("lsp", {
22
+ description: DESCRIPTION,
23
+ parameters: z.object({
24
+ operation: z.enum(operations).describe("The LSP operation to perform"),
25
+ filePath: z.string().describe("The absolute or relative path to the file"),
26
+ line: z.number().int().min(1).describe("The line number (1-based, as shown in editors)"),
27
+ character: z.number().int().min(1).describe("The character offset (1-based, as shown in editors)"),
28
+ }),
29
+ execute: async (args) => {
30
+ const file = path.isAbsolute(args.filePath) ? args.filePath : path.join(Instance.directory, args.filePath)
31
+ const uri = pathToFileURL(file).href
32
+ const position = {
33
+ file,
34
+ line: args.line - 1,
35
+ character: args.character - 1,
36
+ }
37
+
38
+ const relPath = path.relative(Instance.worktree, file)
39
+ const title = `${args.operation} ${relPath}:${args.line}:${args.character}`
40
+
41
+ const exists = await Bun.file(file).exists()
42
+ if (!exists) {
43
+ throw new Error(`File not found: ${file}`)
44
+ }
45
+
46
+ const available = await LSP.hasClients(file)
47
+ if (!available) {
48
+ throw new Error("No LSP server available for this file type.")
49
+ }
50
+
51
+ await LSP.touchFile(file, true)
52
+
53
+ const result: unknown[] = await (async () => {
54
+ switch (args.operation) {
55
+ case "goToDefinition":
56
+ return LSP.definition(position)
57
+ case "findReferences":
58
+ return LSP.references(position)
59
+ case "hover":
60
+ return LSP.hover(position)
61
+ case "documentSymbol":
62
+ return LSP.documentSymbol(uri)
63
+ case "workspaceSymbol":
64
+ return LSP.workspaceSymbol("")
65
+ case "goToImplementation":
66
+ return LSP.implementation(position)
67
+ case "prepareCallHierarchy":
68
+ return LSP.prepareCallHierarchy(position)
69
+ case "incomingCalls":
70
+ return LSP.incomingCalls(position)
71
+ case "outgoingCalls":
72
+ return LSP.outgoingCalls(position)
73
+ }
74
+ })()
75
+
76
+ const output = (() => {
77
+ if (result.length === 0) return `No results found for ${args.operation}`
78
+ return JSON.stringify(result, null, 2)
79
+ })()
80
+
81
+ return {
82
+ title,
83
+ metadata: { result },
84
+ output,
85
+ }
86
+ },
87
+ })
@@ -0,0 +1,19 @@
1
+ Interact with Language Server Protocol (LSP) servers to get code intelligence features.
2
+
3
+ Supported operations:
4
+ - goToDefinition: Find where a symbol is defined
5
+ - findReferences: Find all references to a symbol
6
+ - hover: Get hover information (documentation, type info) for a symbol
7
+ - documentSymbol: Get all symbols (functions, classes, variables) in a document
8
+ - workspaceSymbol: Search for symbols across the entire workspace
9
+ - goToImplementation: Find implementations of an interface or abstract method
10
+ - prepareCallHierarchy: Get call hierarchy item at a position (functions/methods)
11
+ - incomingCalls: Find all functions/methods that call the function at a position
12
+ - outgoingCalls: Find all functions/methods called by the function at a position
13
+
14
+ All operations require:
15
+ - filePath: The file to operate on
16
+ - line: The line number (1-based, as shown in editors)
17
+ - character: The character offset (1-based, as shown in editors)
18
+
19
+ Note: LSP servers must be configured for the file type. If no server is available, an error will be returned.
@@ -0,0 +1,46 @@
1
+ import z from "zod"
2
+ import { Tool } from "./tool"
3
+ import { EditTool } from "./edit"
4
+ import DESCRIPTION from "./multiedit.txt"
5
+ import path from "path"
6
+ import { Instance } from "../project/instance"
7
+
8
+ export const MultiEditTool = Tool.define("multiedit", {
9
+ description: DESCRIPTION,
10
+ parameters: z.object({
11
+ filePath: z.string().describe("The absolute path to the file to modify"),
12
+ edits: z
13
+ .array(
14
+ z.object({
15
+ filePath: z.string().describe("The absolute path to the file to modify"),
16
+ oldString: z.string().describe("The text to replace"),
17
+ newString: z.string().describe("The text to replace it with (must be different from oldString)"),
18
+ replaceAll: z.boolean().optional().describe("Replace all occurrences of oldString (default false)"),
19
+ }),
20
+ )
21
+ .describe("Array of edit operations to perform sequentially on the file"),
22
+ }),
23
+ async execute(params, ctx) {
24
+ const tool = await EditTool.init()
25
+ const results = []
26
+ for (const [, edit] of params.edits.entries()) {
27
+ const result = await tool.execute(
28
+ {
29
+ filePath: params.filePath,
30
+ oldString: edit.oldString,
31
+ newString: edit.newString,
32
+ replaceAll: edit.replaceAll,
33
+ },
34
+ ctx,
35
+ )
36
+ results.push(result)
37
+ }
38
+ return {
39
+ title: path.relative(Instance.worktree, params.filePath),
40
+ metadata: {
41
+ results: results.map((r) => r.metadata),
42
+ },
43
+ output: results.at(-1)!.output,
44
+ }
45
+ },
46
+ })
@@ -0,0 +1,41 @@
1
+ This is a tool for making multiple edits to a single file in one operation. It is built on top of the Edit tool and allows you to perform multiple find-and-replace operations efficiently. Prefer this tool over the Edit tool when you need to make multiple edits to the same file.
2
+
3
+ Before using this tool:
4
+
5
+ 1. Use the Read tool to understand the file's contents and context
6
+ 2. Verify the directory path is correct
7
+
8
+ To make multiple file edits, provide the following:
9
+ 1. file_path: The absolute path to the file to modify (must be absolute, not relative)
10
+ 2. edits: An array of edit operations to perform, where each edit contains:
11
+ - oldString: The text to replace (must match the file contents exactly, including all whitespace and indentation)
12
+ - newString: The edited text to replace the oldString
13
+ - replaceAll: Replace all occurrences of oldString. This parameter is optional and defaults to false.
14
+
15
+ IMPORTANT:
16
+ - All edits are applied in sequence, in the order they are provided
17
+ - Each edit operates on the result of the previous edit
18
+ - All edits must be valid for the operation to succeed - if any edit fails, none will be applied
19
+ - This tool is ideal when you need to make several changes to different parts of the same file
20
+
21
+ CRITICAL REQUIREMENTS:
22
+ 1. All edits follow the same requirements as the single Edit tool
23
+ 2. The edits are atomic - either all succeed or none are applied
24
+ 3. Plan your edits carefully to avoid conflicts between sequential operations
25
+
26
+ WARNING:
27
+ - The tool will fail if edits.oldString doesn't match the file contents exactly (including whitespace)
28
+ - The tool will fail if edits.oldString and edits.newString are the same
29
+ - Since edits are applied in sequence, ensure that earlier edits don't affect the text that later edits are trying to find
30
+
31
+ When making edits:
32
+ - Ensure all edits result in idiomatic, correct code
33
+ - Do not leave the code in a broken state
34
+ - Always use absolute file paths (starting with /)
35
+ - Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
36
+ - Use replaceAll for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.
37
+
38
+ If you want to create a new file, use:
39
+ - A new file path, including dir name if needed
40
+ - First edit: empty oldString and the new file's contents as newString
41
+ - Subsequent edits: normal edit operations on the created content