@cursor/july 0.1.103 → 0.1.105

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 (264) hide show
  1. package/dist/channels/change-monitors/change-monitors-channel.d.ts +5 -0
  2. package/dist/channels/change-monitors/change-monitors-channel.d.ts.map +1 -0
  3. package/dist/channels/change-monitors/change-monitors-channel.js +41 -0
  4. package/dist/channels/change-monitors/index.d.ts +4 -0
  5. package/dist/channels/change-monitors/index.d.ts.map +1 -0
  6. package/dist/channels/change-monitors/index.js +2 -0
  7. package/dist/channels/change-monitors/types.d.ts +39 -0
  8. package/dist/channels/change-monitors/types.d.ts.map +1 -0
  9. package/dist/channels/change-monitors/types.js +1 -0
  10. package/dist/channels/deployments/deployments-channel.d.ts.map +1 -1
  11. package/dist/channels/deployments/deployments-channel.js +1 -0
  12. package/dist/channels/deployments/types.d.ts +2 -0
  13. package/dist/channels/deployments/types.d.ts.map +1 -1
  14. package/dist/channels/github/defaults.d.ts.map +1 -1
  15. package/dist/channels/github/defaults.js +4 -0
  16. package/dist/channels/github/progress.d.ts +22 -0
  17. package/dist/channels/github/progress.d.ts.map +1 -1
  18. package/dist/channels/github/progress.js +32 -5
  19. package/dist/channels/issues/index.d.ts +4 -0
  20. package/dist/channels/issues/index.d.ts.map +1 -0
  21. package/dist/channels/issues/index.js +2 -0
  22. package/dist/channels/issues/issues-channel.d.ts +5 -0
  23. package/dist/channels/issues/issues-channel.d.ts.map +1 -0
  24. package/dist/channels/issues/issues-channel.js +37 -0
  25. package/dist/channels/issues/types.d.ts +33 -0
  26. package/dist/channels/issues/types.d.ts.map +1 -0
  27. package/dist/channels/issues/types.js +1 -0
  28. package/dist/docs/404.html +2 -2
  29. package/dist/docs/ab.html +4 -4
  30. package/dist/docs/assets/{app.DW9pXkpL.js → app.BVwaffdK.js} +1 -1
  31. package/dist/docs/assets/chunks/@localSearchIndexroot.CJxMklAy.js +1 -0
  32. package/dist/docs/assets/chunks/{VPLocalSearchBox.CdEIUwDg.js → VPLocalSearchBox.WuWTZ1x8.js} +1 -1
  33. package/dist/docs/assets/chunks/{theme.YZMHgPgg.js → theme.BYdI_6sF.js} +2 -2
  34. package/dist/docs/assets/{guides_github.md.DKYiT9do.js → guides_github.md.c0gdGJ-D.js} +1 -1
  35. package/dist/docs/assets/{guides_github.md.DKYiT9do.lean.js → guides_github.md.c0gdGJ-D.lean.js} +1 -1
  36. package/dist/docs/assets/guides_grokbot-agents.md.DVqdhBKb.js +9 -0
  37. package/dist/docs/assets/guides_grokbot-agents.md.DVqdhBKb.lean.js +1 -0
  38. package/dist/docs/assets/index.md.BW_6tOgR.js +5 -0
  39. package/dist/docs/assets/index.md.BW_6tOgR.lean.js +1 -0
  40. package/dist/docs/assets/{reference_channels.md.Dz8Cnudp.js → reference_channels.md.DBGcaB7m.js} +2 -2
  41. package/dist/docs/assets/{reference_channels.md.Dz8Cnudp.lean.js → reference_channels.md.DBGcaB7m.lean.js} +1 -1
  42. package/dist/docs/assets/{reference_cli.md.CJNc_xYK.js → reference_cli.md.C6Lo8SEd.js} +2 -1
  43. package/dist/docs/assets/{reference_extensions.md.DykHW3qL.js → reference_extensions.md.CGmMLblt.js} +1 -1
  44. package/dist/docs/assets/templates_grokbot-agents.md.c1s6Flp9.js +3 -0
  45. package/dist/docs/assets/templates_grokbot-agents.md.c1s6Flp9.lean.js +1 -0
  46. package/dist/docs/building-with-agents.html +4 -4
  47. package/dist/docs/concepts.html +4 -4
  48. package/dist/docs/deployment.html +4 -4
  49. package/dist/docs/design/filesystem.md +376 -0
  50. package/dist/docs/evals.html +4 -4
  51. package/dist/docs/guides/agent-to-agent.html +4 -4
  52. package/dist/docs/guides/cloud-agents.html +5 -5
  53. package/dist/docs/guides/convert-automation.html +4 -4
  54. package/dist/docs/guides/github.html +6 -6
  55. package/dist/docs/guides/github.md +5 -0
  56. package/dist/docs/guides/grokbot-agents.html +35 -0
  57. package/dist/docs/guides/grokbot-agents.md +88 -0
  58. package/dist/docs/guides/human-in-the-loop.html +4 -4
  59. package/dist/docs/guides/mcp-oauth.html +4 -4
  60. package/dist/docs/guides/opentelemetry.html +5 -5
  61. package/dist/docs/guides/slack.html +4 -4
  62. package/dist/docs/guides/webhooks.html +4 -4
  63. package/dist/docs/hashmap.json +1 -1
  64. package/dist/docs/hillclimbing.html +4 -4
  65. package/dist/docs/index.html +6 -6
  66. package/dist/docs/index.md +6 -1
  67. package/dist/docs/llms-full.txt +562 -2
  68. package/dist/docs/llms.txt +3 -0
  69. package/dist/docs/quickstart.html +4 -4
  70. package/dist/docs/reference/agent-config.html +4 -4
  71. package/dist/docs/reference/artifacts.html +4 -4
  72. package/dist/docs/reference/channels.html +6 -6
  73. package/dist/docs/reference/channels.md +20 -0
  74. package/dist/docs/reference/cli.html +7 -6
  75. package/dist/docs/reference/cli.md +2 -1
  76. package/dist/docs/reference/connections.html +4 -4
  77. package/dist/docs/reference/extensions.html +6 -6
  78. package/dist/docs/reference/extensions.md +2 -0
  79. package/dist/docs/reference/hooks.html +4 -4
  80. package/dist/docs/reference/http-api.html +4 -4
  81. package/dist/docs/reference/instructions.html +4 -4
  82. package/dist/docs/reference/playground.html +4 -4
  83. package/dist/docs/reference/project-layout.html +4 -4
  84. package/dist/docs/reference/prompt.html +4 -4
  85. package/dist/docs/reference/result.html +4 -4
  86. package/dist/docs/reference/schedules.html +4 -4
  87. package/dist/docs/reference/sessions.html +4 -4
  88. package/dist/docs/reference/skills.html +4 -4
  89. package/dist/docs/reference/subagents.html +4 -4
  90. package/dist/docs/reference/tools.html +4 -4
  91. package/dist/docs/scaffolding-agents.html +4 -4
  92. package/dist/docs/skills/ab.html +4 -4
  93. package/dist/docs/skills/create-agent.html +4 -4
  94. package/dist/docs/skills/debug.html +4 -4
  95. package/dist/docs/skills/evals.html +4 -4
  96. package/dist/docs/skills/framework-map.html +4 -4
  97. package/dist/docs/skills/github.html +4 -4
  98. package/dist/docs/skills/hillclimb.html +4 -4
  99. package/dist/docs/skills/index.html +4 -4
  100. package/dist/docs/skills/mcp-auth.html +4 -4
  101. package/dist/docs/skills/otel.html +4 -4
  102. package/dist/docs/skills/setup-slack.html +4 -4
  103. package/dist/docs/storage.html +4 -4
  104. package/dist/docs/templates/agentic-owners.html +4 -4
  105. package/dist/docs/templates/agents-md.html +4 -4
  106. package/dist/docs/templates/code-wiki.html +5 -5
  107. package/dist/docs/templates/demo.html +5 -5
  108. package/dist/docs/templates/grokbot-agents.html +29 -0
  109. package/dist/docs/templates/grokbot-agents.md +48 -0
  110. package/dist/docs/templates/pr-autofixer.html +4 -4
  111. package/dist/docs/templates/security-help.html +4 -4
  112. package/dist/docs/templates/security-reviewer.html +4 -4
  113. package/dist/docs/templates/triage.html +4 -4
  114. package/dist/docs/troubleshooting.html +4 -4
  115. package/dist/files.d.ts +7 -2
  116. package/dist/files.d.ts.map +1 -1
  117. package/dist/files.js +7 -2
  118. package/dist/filesystem.d.ts +440 -0
  119. package/dist/filesystem.d.ts.map +1 -0
  120. package/dist/filesystem.js +1694 -0
  121. package/dist/index.d.ts +2 -0
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +1 -0
  124. package/dist/internal/continuation-channel.d.ts +4 -2
  125. package/dist/internal/continuation-channel.d.ts.map +1 -1
  126. package/dist/internal/continuation-channel.js +21 -12
  127. package/dist/internal/continuation-identity.d.ts +13 -5
  128. package/dist/internal/continuation-identity.d.ts.map +1 -1
  129. package/dist/internal/continuation-identity.js +74 -35
  130. package/dist/internal/cursor-agent-template.d.ts +1 -1
  131. package/dist/internal/cursor-agent-template.d.ts.map +1 -1
  132. package/dist/internal/cursor-agent-template.js +1 -0
  133. package/dist/internal/discovery/agent.d.ts.map +1 -1
  134. package/dist/internal/discovery/agent.js +80 -8
  135. package/dist/internal/discovery/info.d.ts.map +1 -1
  136. package/dist/internal/discovery/info.js +3 -0
  137. package/dist/internal/factory-resource-channel.d.ts +33 -0
  138. package/dist/internal/factory-resource-channel.d.ts.map +1 -0
  139. package/dist/internal/factory-resource-channel.js +77 -0
  140. package/dist/internal/filesystem/errors.d.ts +64 -0
  141. package/dist/internal/filesystem/errors.d.ts.map +1 -0
  142. package/dist/internal/filesystem/errors.js +175 -0
  143. package/dist/internal/filesystem/format.d.ts +28 -0
  144. package/dist/internal/filesystem/format.d.ts.map +1 -0
  145. package/dist/internal/filesystem/format.js +213 -0
  146. package/dist/internal/filesystem/merge.d.ts +34 -0
  147. package/dist/internal/filesystem/merge.d.ts.map +1 -0
  148. package/dist/internal/filesystem/merge.js +196 -0
  149. package/dist/internal/filesystem/scratch.d.ts +59 -0
  150. package/dist/internal/filesystem/scratch.d.ts.map +1 -0
  151. package/dist/internal/filesystem/scratch.js +212 -0
  152. package/dist/internal/filesystem/sdk-schemas.d.ts +29 -0
  153. package/dist/internal/filesystem/sdk-schemas.d.ts.map +1 -0
  154. package/dist/internal/filesystem/sdk-schemas.js +153 -0
  155. package/dist/internal/filesystem/tools.d.ts +42 -0
  156. package/dist/internal/filesystem/tools.d.ts.map +1 -0
  157. package/dist/internal/filesystem/tools.js +618 -0
  158. package/dist/internal/filesystem/walk.d.ts +74 -0
  159. package/dist/internal/filesystem/walk.d.ts.map +1 -0
  160. package/dist/internal/filesystem/walk.js +339 -0
  161. package/dist/internal/framework-file-storage.d.ts +3 -1
  162. package/dist/internal/framework-file-storage.d.ts.map +1 -1
  163. package/dist/internal/framework-file-storage.js +3 -1
  164. package/dist/internal/guest-network.d.ts +5 -2
  165. package/dist/internal/guest-network.d.ts.map +1 -1
  166. package/dist/internal/guest-network.js +7 -2
  167. package/dist/internal/hosted-delivery.d.ts +7 -0
  168. package/dist/internal/hosted-delivery.d.ts.map +1 -1
  169. package/dist/internal/hosted-delivery.js +41 -3
  170. package/dist/internal/hosted-managed-automation.d.ts.map +1 -1
  171. package/dist/internal/hosted-managed-automation.js +27 -2
  172. package/dist/internal/init-project.d.ts.map +1 -1
  173. package/dist/internal/init-project.js +4 -1
  174. package/dist/internal/sdk-runner.d.ts +13 -1
  175. package/dist/internal/sdk-runner.d.ts.map +1 -1
  176. package/dist/internal/sdk-runner.js +21 -1
  177. package/dist/internal/server.d.ts.map +1 -1
  178. package/dist/internal/server.js +11 -3
  179. package/dist/internal/session-engine.d.ts +30 -0
  180. package/dist/internal/session-engine.d.ts.map +1 -1
  181. package/dist/internal/session-engine.js +484 -82
  182. package/dist/internal/store-mirror.d.ts +2 -2
  183. package/dist/internal/store-mirror.js +2 -2
  184. package/dist/internal/tenant-slack/relay.d.ts +2 -0
  185. package/dist/internal/tenant-slack/relay.d.ts.map +1 -1
  186. package/dist/internal/tenant-slack/relay.js +18 -8
  187. package/dist/internal/testing/factory-resource-fixtures.d.ts +48 -0
  188. package/dist/internal/testing/factory-resource-fixtures.d.ts.map +1 -0
  189. package/dist/internal/testing/factory-resource-fixtures.js +41 -0
  190. package/dist/internal/workspace-sync.d.ts +31 -6
  191. package/dist/internal/workspace-sync.d.ts.map +1 -1
  192. package/dist/internal/workspace-sync.js +67 -12
  193. package/dist/internal/workspace.d.ts +9 -0
  194. package/dist/internal/workspace.d.ts.map +1 -1
  195. package/dist/internal/workspace.js +16 -0
  196. package/dist/playground/assets/{index-59KvgREd.js → index-BaQzjaNK.js} +40 -40
  197. package/dist/playground/assets/index-CceqnLTX.css +1 -0
  198. package/dist/playground/index.html +2 -2
  199. package/dist/types.d.ts +60 -11
  200. package/dist/types.d.ts.map +1 -1
  201. package/docs/README.md +6 -1
  202. package/docs/design/filesystem.md +376 -0
  203. package/docs/guides/github.md +5 -0
  204. package/docs/guides/grokbot-agents.md +93 -0
  205. package/docs/reference/channels.md +20 -0
  206. package/docs/reference/cli.md +2 -1
  207. package/docs/reference/extensions.md +2 -0
  208. package/docs/templates/grokbot-agents.md +53 -0
  209. package/package.json +25 -2
  210. package/src/channels/change-monitors/change-monitors-channel.ts +62 -0
  211. package/src/channels/change-monitors/index.ts +8 -0
  212. package/src/channels/change-monitors/types.ts +44 -0
  213. package/src/channels/deployments/deployments-channel.ts +1 -0
  214. package/src/channels/deployments/types.ts +2 -0
  215. package/src/channels/github/defaults.ts +4 -0
  216. package/src/channels/github/progress.ts +76 -10
  217. package/src/channels/issues/index.ts +9 -0
  218. package/src/channels/issues/issues-channel.ts +51 -0
  219. package/src/channels/issues/types.ts +41 -0
  220. package/src/files.ts +9 -2
  221. package/src/filesystem.ts +2074 -0
  222. package/src/index.ts +28 -0
  223. package/src/internal/continuation-channel.ts +29 -12
  224. package/src/internal/continuation-identity.ts +122 -37
  225. package/src/internal/cursor-agent-template.ts +1 -0
  226. package/src/internal/discovery/agent.ts +87 -1
  227. package/src/internal/discovery/info.ts +3 -0
  228. package/src/internal/factory-resource-channel.ts +122 -0
  229. package/src/internal/filesystem/errors.ts +220 -0
  230. package/src/internal/filesystem/format.ts +276 -0
  231. package/src/internal/filesystem/merge.ts +195 -0
  232. package/src/internal/filesystem/scratch.ts +255 -0
  233. package/src/internal/filesystem/sdk-schemas.ts +204 -0
  234. package/src/internal/filesystem/tools.ts +821 -0
  235. package/src/internal/filesystem/walk.ts +369 -0
  236. package/src/internal/framework-file-storage.ts +3 -1
  237. package/src/internal/guest-network.ts +8 -2
  238. package/src/internal/hosted-delivery.ts +71 -2
  239. package/src/internal/hosted-managed-automation.ts +49 -5
  240. package/src/internal/init-project.ts +4 -1
  241. package/src/internal/sdk-runner.ts +23 -0
  242. package/src/internal/server.ts +16 -0
  243. package/src/internal/session-engine.ts +595 -73
  244. package/src/internal/store-mirror.ts +2 -2
  245. package/src/internal/tenant-slack/relay.ts +28 -4
  246. package/src/internal/testing/factory-resource-fixtures.ts +85 -0
  247. package/src/internal/workspace-sync.ts +84 -12
  248. package/src/internal/workspace.ts +20 -0
  249. package/src/types.ts +58 -11
  250. package/templates/grokbot-agents/README.md +26 -0
  251. package/templates/grokbot-agents/agent/agent.ts +6 -0
  252. package/templates/grokbot-agents/agent/extensions/grokbot.ts +5 -0
  253. package/templates/grokbot-agents/agent/instructions.md +7 -0
  254. package/templates/grokbot-agents/evals/evals.config.ts +5 -0
  255. package/templates/grokbot-agents/evals/grokbot-agents.eval.ts +18 -0
  256. package/templates/grokbot-agents/init.json +18 -0
  257. package/templates/grokbot-agents/package.json +17 -0
  258. package/templates/grokbot-agents/tsconfig.json +12 -0
  259. package/dist/docs/assets/chunks/@localSearchIndexroot.nrl1ifBq.js +0 -1
  260. package/dist/docs/assets/index.md.D75GWhPl.js +0 -5
  261. package/dist/docs/assets/index.md.D75GWhPl.lean.js +0 -1
  262. package/dist/playground/assets/index-MbMxXg-y.css +0 -1
  263. /package/dist/docs/assets/{reference_cli.md.CJNc_xYK.lean.js → reference_cli.md.C6Lo8SEd.lean.js} +0 -0
  264. /package/dist/docs/assets/{reference_extensions.md.DykHW3qL.lean.js → reference_extensions.md.CGmMLblt.lean.js} +0 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Native file tools synthesized from a bound {@link FileSystem}.
3
+ *
4
+ * Advertised name / input / output match `@cursor/sdk` tool-call types.
5
+ * Each tool is a `defineTool` whose runtime `inputSchema` accepts those
6
+ * fields plus the native aliases the harness still sends.
7
+ */
8
+ import { type FileSystem, type FileSystemToolName } from "../../filesystem.js";
9
+ import type { DiscoveredTool } from "../../types.js";
10
+ export declare const SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES: readonly ["Read", "LS", "Glob", "Grep", "Write", "StrReplace", "Delete", "SemanticSearch"];
11
+ export type SynthesizedFileSystemToolName = (typeof SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES)[number];
12
+ export declare function isSynthesizedFileSystemToolName(name: string): boolean;
13
+ export declare function rootFileToolsFromAuthored(tools: readonly string[] | undefined): FileSystemToolName[] | undefined;
14
+ /**
15
+ * Host-default file-tool filter. Omitted `tools` keeps the default
16
+ * seven-tool set (`undefined`). A listed allowlist is closed: names that
17
+ * are not FileSystem methods synthesize nothing, so agents that already
18
+ * replaced natives with authored VFS tools (`tools: ["updateTodos"]` plus
19
+ * `agent/tools/Delete.ts`) do not also get host-disk Delete.
20
+ *
21
+ * Authored `root` still uses {@link rootFileToolsFromAuthored}, where a
22
+ * no-file-name allowlist means the default-on file layer.
23
+ */
24
+ export declare function hostFileToolsFromAuthored(tools: readonly string[] | undefined): FileSystemToolName[] | undefined;
25
+ /**
26
+ * Names July will actually synthesize for this agent. Discovery reserves
27
+ * only this set, not every FileSystem alias.
28
+ */
29
+ export declare function synthesizedFileSystemToolNames(options: {
30
+ hasRoot: boolean;
31
+ tools?: readonly string[];
32
+ }): readonly SynthesizedFileSystemToolName[];
33
+ /**
34
+ * Look up the `defineTool` factory for a native or allowlist name.
35
+ * The only name that still inspects `input` is legacy `edit`:
36
+ * `fileText` / `contents` selects Write, otherwise StrReplace.
37
+ */
38
+ export declare function fileSystemTool(root: FileSystem, name: string, input?: Record<string, unknown>): DiscoveredTool | undefined;
39
+ /** Validate and run the same tool a turn or `callTool` would. */
40
+ export declare function runFileSystemTool(root: FileSystem, name: string, input?: Record<string, unknown>): Promise<unknown>;
41
+ export declare function synthesizeFileSystemTools(root: FileSystem, filter?: readonly FileSystemToolName[]): DiscoveredTool[];
42
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/internal/filesystem/tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,kBAAkB,EAWxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,gBAAgB,CAAC;AAmCrE,eAAO,MAAM,kCAAkC,YAC7C,MAAM,EACN,IAAI,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,gBAAgB,CACR,CAAC;AAEX,MAAM,MAAM,6BAA6B,GACvC,CAAC,OAAO,kCAAkC,CAAC,CAAC,MAAM,CAAC,CAAC;AAMtD,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMrE;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACnC,kBAAkB,EAAE,GAAG,SAAS,CAmBlC;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACnC,kBAAkB,EAAE,GAAG,SAAS,CAKlC;AAOD;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B,GAAG,SAAS,6BAA6B,EAAE,CAW3C;AAomBD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAClC,cAAc,GAAG,SAAS,CAW5B;AAED,iEAAiE;AACjE,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAClC,OAAO,CAAC,OAAO,CAAC,CAclB;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,UAAU,EAChB,MAAM,CAAC,EAAE,SAAS,kBAAkB,EAAE,GACrC,cAAc,EAAE,CAQlB"}
@@ -0,0 +1,618 @@
1
+ /**
2
+ * Native file tools synthesized from a bound {@link FileSystem}.
3
+ *
4
+ * Advertised name / input / output match `@cursor/sdk` tool-call types.
5
+ * Each tool is a `defineTool` whose runtime `inputSchema` accepts those
6
+ * fields plus the native aliases the harness still sends.
7
+ */
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
18
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
19
+ var m = o[Symbol.asyncIterator], i;
20
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
21
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
22
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
23
+ };
24
+ import { Buffer } from "node:buffer";
25
+ import { minimatch } from "minimatch";
26
+ import { z } from "zod";
27
+ import { canonicalizeFileSystemToolName, collectGrepMatches, fileSystemImage, fileSystemText, InvalidGrepPatternError, shapeGrepUnion, sliceReadContent, strReplaceOnFileSystem, } from "../../filesystem.js";
28
+ import { defineTool } from "../../tools.js";
29
+ import { toolInputJsonSchema, toolOutputJsonSchema, validateToolInput, } from "../json-schema.js";
30
+ import { formatGlobOutput, formatGrepOutput, formatLsTree, formatNumberedLines, formatStrReplaceOutput, formatWriteOutput, slicedReadStartLine, } from "./format.js";
31
+ import { sdkDeleteArgs, sdkDeleteResult, sdkEditResult, sdkGlobArgs, sdkGlobResult, sdkGrepArgs, sdkGrepResult, sdkLsArgs, sdkLsResult, sdkReadArgs, sdkReadResult, sdkSemSearchArgs, sdkSemSearchResult, sdkStrReplaceArgs, sdkWriteArgs, sdkWriteResult, } from "./sdk-schemas.js";
32
+ import { collectGlob, collectListOrStat, lsFromList } from "./walk.js";
33
+ export const SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES = [
34
+ "Read",
35
+ "LS",
36
+ "Glob",
37
+ "Grep",
38
+ "Write",
39
+ "StrReplace",
40
+ "Delete",
41
+ "SemanticSearch",
42
+ ];
43
+ const SYNTHESIZED_NAME_SET = new Set(SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES);
44
+ export function isSynthesizedFileSystemToolName(name) {
45
+ if (SYNTHESIZED_NAME_SET.has(name)) {
46
+ return true;
47
+ }
48
+ const canonical = canonicalizeFileSystemToolName(name);
49
+ return canonical !== undefined && SYNTHESIZED_NAME_SET.has(canonical);
50
+ }
51
+ export function rootFileToolsFromAuthored(tools) {
52
+ if (tools === undefined) {
53
+ return undefined;
54
+ }
55
+ if (tools.length === 0) {
56
+ return [];
57
+ }
58
+ const files = [];
59
+ for (const name of tools) {
60
+ if (name === "edit") {
61
+ files.push("Write", "StrReplace");
62
+ continue;
63
+ }
64
+ const canonical = canonicalizeFileSystemToolName(name);
65
+ if (canonical !== undefined) {
66
+ files.push(canonical);
67
+ }
68
+ }
69
+ return files.length === 0 ? undefined : [...new Set(files)];
70
+ }
71
+ /**
72
+ * Host-default file-tool filter. Omitted `tools` keeps the default
73
+ * seven-tool set (`undefined`). A listed allowlist is closed: names that
74
+ * are not FileSystem methods synthesize nothing, so agents that already
75
+ * replaced natives with authored VFS tools (`tools: ["updateTodos"]` plus
76
+ * `agent/tools/Delete.ts`) do not also get host-disk Delete.
77
+ *
78
+ * Authored `root` still uses {@link rootFileToolsFromAuthored}, where a
79
+ * no-file-name allowlist means the default-on file layer.
80
+ */
81
+ export function hostFileToolsFromAuthored(tools) {
82
+ var _a;
83
+ if (tools === undefined) {
84
+ return undefined;
85
+ }
86
+ return (_a = rootFileToolsFromAuthored(tools)) !== null && _a !== void 0 ? _a : [];
87
+ }
88
+ const HOST_DEFAULT_SYNTHESIZED_NAMES = SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES.filter((name) => name !== "SemanticSearch");
89
+ /**
90
+ * Names July will actually synthesize for this agent. Discovery reserves
91
+ * only this set, not every FileSystem alias.
92
+ */
93
+ export function synthesizedFileSystemToolNames(options) {
94
+ const filter = options.hasRoot
95
+ ? rootFileToolsFromAuthored(options.tools)
96
+ : hostFileToolsFromAuthored(options.tools);
97
+ const catalog = options.hasRoot
98
+ ? SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES
99
+ : HOST_DEFAULT_SYNTHESIZED_NAMES;
100
+ if (filter === undefined) {
101
+ return catalog;
102
+ }
103
+ return catalog.filter((name) => filter.includes(name));
104
+ }
105
+ function wantsTool(filter, name) {
106
+ return filter === undefined || filter.includes(name);
107
+ }
108
+ /**
109
+ * Copy native aliases onto the canonical SDK field when the canonical
110
+ * field is absent. Zod sees the SDK shape; callers can still send
111
+ * `contents` / `old_string` / `output_mode`.
112
+ */
113
+ function aliasKeys(aliases) {
114
+ return (raw) => {
115
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
116
+ return raw;
117
+ }
118
+ const input = Object.assign({}, raw);
119
+ for (const [from, to] of Object.entries(aliases)) {
120
+ if (input[to] === undefined && input[from] !== undefined) {
121
+ input[to] = input[from];
122
+ }
123
+ }
124
+ return input;
125
+ };
126
+ }
127
+ function lineCount(content) {
128
+ return content === "" ? 0 : content.split("\n").length;
129
+ }
130
+ function parseGrepOutputMode(value) {
131
+ if (value === "files" || value === "files_with_matches") {
132
+ return "files_with_matches";
133
+ }
134
+ if (value === "count") {
135
+ return "count";
136
+ }
137
+ return "content";
138
+ }
139
+ function contextLineCount(specific, both) {
140
+ const value = specific !== null && specific !== void 0 ? specific : both;
141
+ if (value === undefined || !Number.isFinite(value)) {
142
+ return 0;
143
+ }
144
+ return Math.max(0, Math.floor(value));
145
+ }
146
+ function compileToolGrepPattern(pattern, options) {
147
+ try {
148
+ const flags = `${options.caseInsensitive === true ? "i" : ""}${options.multiline === true ? "s" : ""}`;
149
+ return new RegExp(pattern, flags === "" ? undefined : flags);
150
+ }
151
+ catch (_a) {
152
+ throw new InvalidGrepPatternError(pattern);
153
+ }
154
+ }
155
+ /**
156
+ * File discovery for multiline Grep. A file `path` is that file (the
157
+ * caller spelling, so host-default relative paths stay relative). A
158
+ * directory or omitted path uses `FileSystem.glob`, which applies the
159
+ * mount's own root. Slash-free globs are recursive, matching line grep.
160
+ */
161
+ function collectMultilineGrepFiles(root, input) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ var _a;
164
+ const listed = yield collectListOrStat(root, input.path);
165
+ if (listed.kind === "file") {
166
+ const filePath = (_a = input.path) !== null && _a !== void 0 ? _a : "";
167
+ if (input.glob !== undefined &&
168
+ !fileMatchesGrepGlob(filePath, input.glob)) {
169
+ return [];
170
+ }
171
+ return [filePath];
172
+ }
173
+ if (listed.kind === "missing") {
174
+ return [];
175
+ }
176
+ const entries = yield collectGlob(root, Object.assign({ pattern: recursiveGrepGlob(input.glob) }, (input.path === undefined ? {} : { dir: input.path })));
177
+ return entries.map((entry) => entry.path);
178
+ });
179
+ }
180
+ function recursiveGrepGlob(glob) {
181
+ if (glob === undefined || glob.length === 0) {
182
+ return "**/*";
183
+ }
184
+ if (glob.startsWith("**/") || glob.includes("/")) {
185
+ return glob;
186
+ }
187
+ return `**/${glob}`;
188
+ }
189
+ function fileMatchesGrepGlob(filePath, globPattern) {
190
+ const relative = filePath.replace(/^\//, "");
191
+ if (minimatch(relative, globPattern, { dot: true }) ||
192
+ minimatch(filePath, globPattern, { dot: true })) {
193
+ return true;
194
+ }
195
+ if (!globPattern.includes("/")) {
196
+ const slash = Math.max(relative.lastIndexOf("/"), relative.lastIndexOf("\\"));
197
+ const base = slash === -1 ? relative : relative.slice(slash + 1);
198
+ return minimatch(base, globPattern, { dot: true });
199
+ }
200
+ return false;
201
+ }
202
+ function multilineHitsInContent(path, content, regex) {
203
+ var _a;
204
+ const global = new RegExp(regex.source, regex.flags.includes("g") ? regex.flags : `${regex.flags}g`);
205
+ const hits = [];
206
+ let match = global.exec(content);
207
+ while (match !== null) {
208
+ hits.push({
209
+ path,
210
+ lineNumber: content.slice(0, match.index).split("\n").length,
211
+ line: (_a = content.slice(match.index).split("\n")[0]) !== null && _a !== void 0 ? _a : "",
212
+ });
213
+ if (match[0].length === 0) {
214
+ global.lastIndex += 1;
215
+ }
216
+ match = global.exec(content);
217
+ }
218
+ return hits;
219
+ }
220
+ function collectMultilineGrepMatches(root, input, opts) {
221
+ return __awaiter(this, void 0, void 0, function* () {
222
+ const regex = compileToolGrepPattern(input.pattern, {
223
+ caseInsensitive: input.caseInsensitive,
224
+ multiline: true,
225
+ });
226
+ const files = yield collectMultilineGrepFiles(root, input);
227
+ const matches = [];
228
+ const offset = opts.offset !== undefined && opts.offset > 0 ? opts.offset : 0;
229
+ const headLimit = opts.headLimit !== undefined && opts.headLimit > 0
230
+ ? opts.headLimit
231
+ : undefined;
232
+ let skippedItems = 0;
233
+ let takenItems = 0;
234
+ for (const filePath of files) {
235
+ let content;
236
+ try {
237
+ content = yield root.read(filePath);
238
+ }
239
+ catch (_a) {
240
+ continue;
241
+ }
242
+ if (typeof content !== "string") {
243
+ continue;
244
+ }
245
+ const hits = multilineHitsInContent(filePath, content, regex);
246
+ if (hits.length === 0) {
247
+ continue;
248
+ }
249
+ if (opts.outputMode === "content") {
250
+ for (const hit of hits) {
251
+ if (skippedItems < offset) {
252
+ skippedItems++;
253
+ continue;
254
+ }
255
+ matches.push(hit);
256
+ takenItems++;
257
+ if (headLimit !== undefined && takenItems >= headLimit) {
258
+ return matches;
259
+ }
260
+ }
261
+ continue;
262
+ }
263
+ if (skippedItems < offset) {
264
+ skippedItems++;
265
+ continue;
266
+ }
267
+ if (headLimit !== undefined && takenItems >= headLimit) {
268
+ break;
269
+ }
270
+ matches.push(...hits);
271
+ takenItems++;
272
+ }
273
+ return matches;
274
+ });
275
+ }
276
+ function attachGrepContext(root, matches, context) {
277
+ return __awaiter(this, void 0, void 0, function* () {
278
+ if (context.before === 0 && context.after === 0) {
279
+ return matches;
280
+ }
281
+ const linesByPath = new Map();
282
+ const hits = [];
283
+ for (const match of matches) {
284
+ let lines = linesByPath.get(match.path);
285
+ if (lines === undefined) {
286
+ try {
287
+ const content = yield root.read(match.path);
288
+ lines = typeof content === "string" ? content.split("\n") : [];
289
+ }
290
+ catch (_a) {
291
+ lines = [];
292
+ }
293
+ linesByPath.set(match.path, lines);
294
+ }
295
+ const index = match.lineNumber - 1;
296
+ hits.push(Object.assign(Object.assign(Object.assign({}, match), (context.before > 0
297
+ ? {
298
+ beforeContext: lines.slice(Math.max(0, index - context.before), Math.max(0, index)),
299
+ }
300
+ : {})), (context.after > 0
301
+ ? { afterContext: lines.slice(index + 1, index + 1 + context.after) }
302
+ : {})));
303
+ }
304
+ return hits;
305
+ });
306
+ }
307
+ function discovered(name, definition, contract) {
308
+ const effect = typeof definition.effect === "function" ? "dynamic" : definition.effect;
309
+ return Object.assign(Object.assign({ name, description: definition.description, inputSchema: toolInputJsonSchema(contract.input), outputSchema: toolOutputJsonSchema(contract.output), execution: "server", needsApproval: false }, (effect === undefined ? {} : { effect })), { definition });
310
+ }
311
+ const readInputSchema = z.preprocess(aliasKeys({}), z.object({
312
+ path: z.string(),
313
+ offset: z.number().int().optional(),
314
+ limit: z.number().int().optional(),
315
+ }));
316
+ function readTool(root) {
317
+ return discovered("Read", defineTool({
318
+ description: "Reads a file from the local filesystem. This tool can also read image files when called with the appropriate path. Formats supported: jpeg/jpg, png, gif, webp.",
319
+ inputSchema: readInputSchema,
320
+ effect: "read",
321
+ execute(_a) {
322
+ return __awaiter(this, arguments, void 0, function* ({ path, offset, limit }) {
323
+ const content = yield root.read(path);
324
+ const image = fileSystemImage(content, path);
325
+ if (image !== undefined) {
326
+ return {
327
+ content: [
328
+ { type: "text", text: `Read image file: ${path}` },
329
+ {
330
+ type: "image",
331
+ data: Buffer.from(image.bytes).toString("base64"),
332
+ mimeType: image.mimeType,
333
+ },
334
+ ],
335
+ };
336
+ }
337
+ const text = fileSystemText(content);
338
+ const totalLines = lineCount(text);
339
+ return formatNumberedLines(sliceReadContent(text, offset, limit), {
340
+ startLine: slicedReadStartLine(totalLines, offset),
341
+ totalLines,
342
+ });
343
+ });
344
+ },
345
+ }), { input: sdkReadArgs, output: sdkReadResult });
346
+ }
347
+ const lsInputSchema = z.preprocess(aliasKeys({ target_directory: "path", ignore_globs: "ignore" }), z.object({
348
+ path: z.string(),
349
+ ignore: z.array(z.string()).optional(),
350
+ }));
351
+ function lsTool(root) {
352
+ return discovered("LS", defineTool({
353
+ description: `Lists files and directories in a given path.
354
+ The 'path' parameter must be an absolute path.
355
+ You can optionally provide an array of glob patterns to ignore with the "ignore" parameter.
356
+
357
+ Other details:
358
+ - The result does not display dot-files and dot-directories.`,
359
+ inputSchema: lsInputSchema,
360
+ effect: "read",
361
+ execute(_a) {
362
+ return __awaiter(this, arguments, void 0, function* ({ path, ignore }) {
363
+ const listed = yield lsFromList(root, path, ignore);
364
+ if (listed.status === "error") {
365
+ throw new Error(`Error listing directory: ${listed.error.message}`);
366
+ }
367
+ return formatLsTree(listed.value.directoryTreeRoot);
368
+ });
369
+ },
370
+ }), { input: sdkLsArgs, output: sdkLsResult });
371
+ }
372
+ const globInputSchema = z.preprocess(aliasKeys({
373
+ glob_pattern: "globPattern",
374
+ target_directory: "targetDirectory",
375
+ path: "targetDirectory",
376
+ }), z.object({
377
+ targetDirectory: z.string().optional(),
378
+ globPattern: z.string(),
379
+ }));
380
+ function globTool(root) {
381
+ return discovered("Glob", defineTool({
382
+ description: `
383
+ Tool to search for files matching a glob pattern
384
+
385
+ - Works fast with codebases of any size
386
+ - Returns matching file paths sorted by modification time
387
+ - Use this tool when you need to find files by name patterns
388
+ - You have the capability to call multiple tools in a single response. It is always better to speculatively perform multiple searches that are potentially useful as a batch.
389
+ `,
390
+ inputSchema: globInputSchema,
391
+ effect: "read",
392
+ execute(_a) {
393
+ return __awaiter(this, arguments, void 0, function* ({ globPattern, targetDirectory }) {
394
+ const dir = targetDirectory !== null && targetDirectory !== void 0 ? targetDirectory : "/";
395
+ const files = (yield collectGlob(root, Object.assign({ pattern: globPattern }, (targetDirectory === undefined ? {} : { dir: targetDirectory })))).map((entry) => entry.path);
396
+ return formatGlobOutput(dir, files);
397
+ });
398
+ },
399
+ }), { input: sdkGlobArgs, output: sdkGlobResult });
400
+ }
401
+ const grepInputSchema = z.preprocess((raw) => {
402
+ const aliased = aliasKeys({
403
+ output_mode: "outputMode",
404
+ head_limit: "headLimit",
405
+ "-i": "caseInsensitive",
406
+ "-A": "contextAfter",
407
+ "-B": "contextBefore",
408
+ "-C": "context",
409
+ })(raw);
410
+ if (aliased !== null &&
411
+ typeof aliased === "object" &&
412
+ !Array.isArray(aliased)) {
413
+ const input = aliased;
414
+ if (input.outputMode === "files") {
415
+ input.outputMode = "files_with_matches";
416
+ }
417
+ }
418
+ return aliased;
419
+ }, z.object({
420
+ pattern: z.string(),
421
+ path: z.string().optional(),
422
+ glob: z.string().optional(),
423
+ outputMode: z.string().optional(),
424
+ contextBefore: z.number().optional(),
425
+ contextAfter: z.number().optional(),
426
+ context: z.number().optional(),
427
+ caseInsensitive: z.boolean().optional(),
428
+ type: z.string().optional(),
429
+ headLimit: z.number().optional(),
430
+ offset: z.number().optional(),
431
+ multiline: z.boolean().optional(),
432
+ sort: z.string().optional(),
433
+ sortAscending: z.boolean().optional(),
434
+ }));
435
+ function grepTool(root) {
436
+ return discovered("Grep", defineTool({
437
+ description: `A search tool built on ripgrep. Results are capped to several thousand output lines for responsiveness; when truncation occurs, the results report "at least" counts, but are otherwise accurate.`,
438
+ inputSchema: grepInputSchema,
439
+ effect: "read",
440
+ execute(input) {
441
+ return __awaiter(this, void 0, void 0, function* () {
442
+ const outputMode = parseGrepOutputMode(input.outputMode);
443
+ const query = Object.assign(Object.assign(Object.assign({ pattern: input.pattern }, (input.path === undefined ? {} : { path: input.path })), (input.glob === undefined ? {} : { glob: input.glob })), { caseInsensitive: input.caseInsensitive === true });
444
+ const page = Object.assign(Object.assign({ outputMode }, (input.headLimit === undefined
445
+ ? {}
446
+ : { headLimit: input.headLimit })), (input.offset === undefined ? {} : { offset: input.offset }));
447
+ const matches = input.multiline === true
448
+ ? yield collectMultilineGrepMatches(root, query, page)
449
+ : yield collectGrepMatches(root, query, page);
450
+ const before = contextLineCount(input.contextBefore, input.context);
451
+ const after = contextLineCount(input.contextAfter, input.context);
452
+ const hits = outputMode === "content"
453
+ ? yield attachGrepContext(root, matches, { before, after })
454
+ : matches;
455
+ return formatGrepOutput(shapeGrepUnion(hits, outputMode));
456
+ });
457
+ },
458
+ }), { input: sdkGrepArgs, output: sdkGrepResult });
459
+ }
460
+ const writeInputSchema = z.preprocess(aliasKeys({ contents: "fileText" }), z.object({
461
+ path: z.string(),
462
+ fileText: z.string(),
463
+ returnFileContentAfterWrite: z.boolean().optional(),
464
+ }));
465
+ function writeTool(root) {
466
+ return discovered("Write", defineTool({
467
+ description: "Writes a file to the local filesystem.",
468
+ inputSchema: writeInputSchema,
469
+ effect: "write",
470
+ execute(_a) {
471
+ return __awaiter(this, arguments, void 0, function* ({ path, fileText }) {
472
+ yield root.write(path, fileText);
473
+ return formatWriteOutput(path);
474
+ });
475
+ },
476
+ }), { input: sdkWriteArgs, output: sdkWriteResult });
477
+ }
478
+ const strReplaceInputSchema = z.preprocess(aliasKeys({
479
+ old_string: "oldText",
480
+ new_string: "newText",
481
+ replace_all: "replaceAll",
482
+ }), z.object({
483
+ path: z.string(),
484
+ oldText: z.string(),
485
+ newText: z.string(),
486
+ replaceAll: z.boolean().optional(),
487
+ }));
488
+ function strReplaceTool(root) {
489
+ return discovered("StrReplace", defineTool({
490
+ description: "Performs exact string replacements in files.",
491
+ inputSchema: strReplaceInputSchema,
492
+ effect: "write",
493
+ execute(_a) {
494
+ return __awaiter(this, arguments, void 0, function* ({ path, oldText, newText, replaceAll }) {
495
+ const { occurrencesModified } = yield strReplaceOnFileSystem(root, Object.assign({ path,
496
+ oldText,
497
+ newText }, (replaceAll === undefined ? {} : { replaceAll })));
498
+ return formatStrReplaceOutput({
499
+ path,
500
+ replaceAll: replaceAll === true,
501
+ occurrencesModified,
502
+ });
503
+ });
504
+ },
505
+ }), { input: sdkStrReplaceArgs, output: sdkEditResult });
506
+ }
507
+ const deleteInputSchema = z.object({
508
+ path: z.string(),
509
+ });
510
+ function deleteTool(root) {
511
+ return discovered("Delete", defineTool({
512
+ description: `Deletes a file at the specified path. The operation will fail gracefully if:
513
+ - The file doesn't exist
514
+ - The operation is rejected for security reasons
515
+ - The file cannot be deleted`,
516
+ inputSchema: deleteInputSchema,
517
+ effect: "write",
518
+ execute(_a) {
519
+ return __awaiter(this, arguments, void 0, function* ({ path }) {
520
+ yield root.delete(path);
521
+ return "";
522
+ });
523
+ },
524
+ }), { input: sdkDeleteArgs, output: sdkDeleteResult });
525
+ }
526
+ const semanticSearchInputSchema = z.preprocess(aliasKeys({ num_results: "numResults" }), z.object({
527
+ query: z.string(),
528
+ targetDirectories: z.array(z.string()).optional(),
529
+ explanation: z.string().optional(),
530
+ numResults: z.number().optional(),
531
+ }));
532
+ function semanticSearchTool(root) {
533
+ return discovered("SemanticSearch", defineTool({
534
+ description: "`SemanticSearch`: semantic search that finds code by meaning, not exact text",
535
+ inputSchema: semanticSearchInputSchema,
536
+ effect: "read",
537
+ execute(_a) {
538
+ return __awaiter(this, arguments, void 0, function* ({ query, targetDirectories, numResults }) {
539
+ var _b, e_1, _c, _d;
540
+ const cap = numResults !== undefined && numResults > 0 ? numResults : undefined;
541
+ const hits = [];
542
+ try {
543
+ for (var _e = true, _f = __asyncValues(root.search(Object.assign(Object.assign({ query }, (targetDirectories === undefined ? {} : { targetDirectories })), (cap === undefined ? {} : { maxResults: cap })))), _g; _g = yield _f.next(), _b = _g.done, !_b; _e = true) {
544
+ _d = _g.value;
545
+ _e = false;
546
+ const hit = _d;
547
+ hits.push(hit);
548
+ if (cap !== undefined && hits.length >= cap) {
549
+ break;
550
+ }
551
+ }
552
+ }
553
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
554
+ finally {
555
+ try {
556
+ if (!_e && !_b && (_c = _f.return)) yield _c.call(_f);
557
+ }
558
+ finally { if (e_1) throw e_1.error; }
559
+ }
560
+ return hits.map((hit) => `${hit.path}: ${hit.snippet}`).join("\n");
561
+ });
562
+ },
563
+ }), { input: sdkSemSearchArgs, output: sdkSemSearchResult });
564
+ }
565
+ const FILE_SYSTEM_TOOL_FACTORIES = {
566
+ Read: readTool,
567
+ LS: lsTool,
568
+ Glob: globTool,
569
+ Grep: grepTool,
570
+ Write: writeTool,
571
+ StrReplace: strReplaceTool,
572
+ Delete: deleteTool,
573
+ SemanticSearch: semanticSearchTool,
574
+ };
575
+ /**
576
+ * Look up the `defineTool` factory for a native or allowlist name.
577
+ * The only name that still inspects `input` is legacy `edit`:
578
+ * `fileText` / `contents` selects Write, otherwise StrReplace.
579
+ */
580
+ export function fileSystemTool(root, name, input = {}) {
581
+ if (name === "edit") {
582
+ return "fileText" in input || "contents" in input
583
+ ? writeTool(root)
584
+ : strReplaceTool(root);
585
+ }
586
+ const canonical = canonicalizeFileSystemToolName(name);
587
+ if (canonical === undefined) {
588
+ return undefined;
589
+ }
590
+ return FILE_SYSTEM_TOOL_FACTORIES[canonical](root);
591
+ }
592
+ /** Validate and run the same tool a turn or `callTool` would. */
593
+ export function runFileSystemTool(root_1, name_1) {
594
+ return __awaiter(this, arguments, void 0, function* (root, name, input = {}) {
595
+ const tool = fileSystemTool(root, name, input);
596
+ if (tool === undefined) {
597
+ throw new Error(`Unknown file system tool: ${name}`);
598
+ }
599
+ const execute = tool.definition.execute;
600
+ if (typeof execute !== "function") {
601
+ throw new Error(`File system tool ${name} has no execute`);
602
+ }
603
+ const validation = validateToolInput(tool.definition.inputSchema, input);
604
+ if (!validation.ok) {
605
+ throw new Error(validation.message);
606
+ }
607
+ return execute(validation.value, {});
608
+ });
609
+ }
610
+ export function synthesizeFileSystemTools(root, filter) {
611
+ const tools = [];
612
+ for (const name of SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES) {
613
+ if (wantsTool(filter, name)) {
614
+ tools.push(FILE_SYSTEM_TOOL_FACTORIES[name](root));
615
+ }
616
+ }
617
+ return tools;
618
+ }