@di-code/coding-agent 0.1.7 → 0.1.9

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 (333) hide show
  1. package/README.md +54 -567
  2. package/compositions/base.yml +54 -0
  3. package/compositions/interactive.yml +14 -0
  4. package/compositions/json.yml +6 -0
  5. package/compositions/print.yml +5 -0
  6. package/compositions/rpc.yml +12 -0
  7. package/compositions/webui.yml +9 -0
  8. package/dist/cli.d.ts +22 -1
  9. package/dist/cli.d.ts.map +1 -1
  10. package/dist/cli.js +97 -3
  11. package/dist/cli.js.map +1 -1
  12. package/dist/composition-loader-entry.d.ts +11 -0
  13. package/dist/composition-loader-entry.d.ts.map +1 -0
  14. package/dist/composition-loader-entry.js +12 -0
  15. package/dist/composition-loader-entry.js.map +1 -0
  16. package/dist/compositions.d.ts +32 -0
  17. package/dist/compositions.d.ts.map +1 -0
  18. package/dist/compositions.js +173 -0
  19. package/dist/compositions.js.map +1 -0
  20. package/dist/core/session/session-manager.d.ts +9 -2
  21. package/dist/core/session/session-manager.d.ts.map +1 -1
  22. package/dist/core/session/session-manager.js +28 -0
  23. package/dist/core/session/session-manager.js.map +1 -1
  24. package/dist/core/session/session-storage.d.ts.map +1 -1
  25. package/dist/core/session/session-storage.js +20 -3
  26. package/dist/core/session/session-storage.js.map +1 -1
  27. package/dist/core/session/types.d.ts +11 -2
  28. package/dist/core/session/types.d.ts.map +1 -1
  29. package/dist/core/session/types.js.map +1 -1
  30. package/dist/core/session-tools.d.ts +5 -0
  31. package/dist/core/session-tools.d.ts.map +1 -0
  32. package/dist/core/session-tools.js +17 -0
  33. package/dist/core/session-tools.js.map +1 -0
  34. package/dist/core/session.d.ts +19 -7
  35. package/dist/core/session.d.ts.map +1 -1
  36. package/dist/core/session.js +71 -39
  37. package/dist/core/session.js.map +1 -1
  38. package/dist/core/tools/bash.d.ts +1 -38
  39. package/dist/core/tools/bash.d.ts.map +1 -1
  40. package/dist/core/tools/bash.js +1 -207
  41. package/dist/core/tools/bash.js.map +1 -1
  42. package/dist/core/tools/edit-diff.d.ts +1 -24
  43. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  44. package/dist/core/tools/edit-diff.js +1 -135
  45. package/dist/core/tools/edit-diff.js.map +1 -1
  46. package/dist/core/tools/edit.d.ts +1 -26
  47. package/dist/core/tools/edit.d.ts.map +1 -1
  48. package/dist/core/tools/edit.js +1 -140
  49. package/dist/core/tools/edit.js.map +1 -1
  50. package/dist/core/tools/file-mutation-queue.d.ts +1 -1
  51. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  52. package/dist/core/tools/file-mutation-queue.js +1 -23
  53. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  54. package/dist/core/tools/file-search.d.ts +1 -13
  55. package/dist/core/tools/file-search.d.ts.map +1 -1
  56. package/dist/core/tools/file-search.js +1 -98
  57. package/dist/core/tools/file-search.js.map +1 -1
  58. package/dist/core/tools/glob.d.ts +1 -10
  59. package/dist/core/tools/glob.d.ts.map +1 -1
  60. package/dist/core/tools/glob.js +1 -43
  61. package/dist/core/tools/glob.js.map +1 -1
  62. package/dist/core/tools/grep.d.ts +1 -12
  63. package/dist/core/tools/grep.d.ts.map +1 -1
  64. package/dist/core/tools/grep.js +1 -66
  65. package/dist/core/tools/grep.js.map +1 -1
  66. package/dist/core/tools/load-skill.d.ts +1 -9
  67. package/dist/core/tools/load-skill.d.ts.map +1 -1
  68. package/dist/core/tools/load-skill.js +1 -21
  69. package/dist/core/tools/load-skill.js.map +1 -1
  70. package/dist/core/tools/path-boundary.d.ts +1 -4
  71. package/dist/core/tools/path-boundary.d.ts.map +1 -1
  72. package/dist/core/tools/path-boundary.js +1 -65
  73. package/dist/core/tools/path-boundary.js.map +1 -1
  74. package/dist/core/tools/read.d.ts +1 -16
  75. package/dist/core/tools/read.d.ts.map +1 -1
  76. package/dist/core/tools/read.js +1 -131
  77. package/dist/core/tools/read.js.map +1 -1
  78. package/dist/core/tools/write.d.ts +1 -16
  79. package/dist/core/tools/write.d.ts.map +1 -1
  80. package/dist/core/tools/write.js +1 -44
  81. package/dist/core/tools/write.js.map +1 -1
  82. package/dist/entry.js +30 -28
  83. package/dist/entry.js.map +1 -1
  84. package/dist/index.d.ts +6 -3
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +6 -3
  87. package/dist/index.js.map +1 -1
  88. package/dist/interactive/builtin.d.ts +17 -0
  89. package/dist/interactive/builtin.d.ts.map +1 -0
  90. package/dist/interactive/builtin.js +47 -0
  91. package/dist/interactive/builtin.js.map +1 -0
  92. package/dist/interactive/controller.d.ts +85 -0
  93. package/dist/interactive/controller.d.ts.map +1 -0
  94. package/dist/interactive/controller.js +211 -0
  95. package/dist/interactive/controller.js.map +1 -0
  96. package/dist/interactive/index.d.ts +3 -0
  97. package/dist/interactive/index.d.ts.map +1 -0
  98. package/dist/interactive/index.js +3 -0
  99. package/dist/interactive/index.js.map +1 -0
  100. package/dist/interactive-host-entry.d.ts +7 -0
  101. package/dist/interactive-host-entry.d.ts.map +1 -0
  102. package/dist/interactive-host-entry.js +123 -0
  103. package/dist/interactive-host-entry.js.map +1 -0
  104. package/dist/interactive-profile.d.ts +18 -0
  105. package/dist/interactive-profile.d.ts.map +1 -0
  106. package/dist/interactive-profile.js +290 -0
  107. package/dist/interactive-profile.js.map +1 -0
  108. package/dist/interactive-resources-entry.d.ts +7 -0
  109. package/dist/interactive-resources-entry.d.ts.map +1 -0
  110. package/dist/interactive-resources-entry.js +42 -0
  111. package/dist/interactive-resources-entry.js.map +1 -0
  112. package/dist/legacy-main.d.ts +39 -0
  113. package/dist/legacy-main.d.ts.map +1 -0
  114. package/dist/legacy-main.js +611 -0
  115. package/dist/legacy-main.js.map +1 -0
  116. package/dist/main.d.ts +15 -34
  117. package/dist/main.d.ts.map +1 -1
  118. package/dist/main.js +130 -518
  119. package/dist/main.js.map +1 -1
  120. package/dist/mcp/entries.d.ts +42 -0
  121. package/dist/mcp/entries.d.ts.map +1 -0
  122. package/dist/mcp/entries.js +98 -0
  123. package/dist/mcp/entries.js.map +1 -0
  124. package/dist/mcp-client-entry.d.ts +5 -0
  125. package/dist/mcp-client-entry.d.ts.map +1 -0
  126. package/dist/mcp-client-entry.js +6 -0
  127. package/dist/mcp-client-entry.js.map +1 -0
  128. package/dist/mcp-config-entry.d.ts +5 -0
  129. package/dist/mcp-config-entry.d.ts.map +1 -0
  130. package/dist/mcp-config-entry.js +6 -0
  131. package/dist/mcp-config-entry.js.map +1 -0
  132. package/dist/mcp-tools-entry.d.ts +5 -0
  133. package/dist/mcp-tools-entry.d.ts.map +1 -0
  134. package/dist/mcp-tools-entry.js +6 -0
  135. package/dist/mcp-tools-entry.js.map +1 -0
  136. package/dist/mcp-transport-entry.d.ts +5 -0
  137. package/dist/mcp-transport-entry.d.ts.map +1 -0
  138. package/dist/mcp-transport-entry.js +6 -0
  139. package/dist/mcp-transport-entry.js.map +1 -0
  140. package/dist/modes/interactive-entry.d.ts +18 -0
  141. package/dist/modes/interactive-entry.d.ts.map +1 -0
  142. package/dist/modes/interactive-entry.js +21 -0
  143. package/dist/modes/interactive-entry.js.map +1 -0
  144. package/dist/modes/interactive.d.ts +16 -6
  145. package/dist/modes/interactive.d.ts.map +1 -1
  146. package/dist/modes/interactive.js +81 -32
  147. package/dist/modes/interactive.js.map +1 -1
  148. package/dist/modes/json-entry.d.ts +13 -0
  149. package/dist/modes/json-entry.d.ts.map +1 -0
  150. package/dist/modes/json-entry.js +14 -0
  151. package/dist/modes/json-entry.js.map +1 -0
  152. package/dist/modes/json.d.ts +4 -1
  153. package/dist/modes/json.d.ts.map +1 -1
  154. package/dist/modes/json.js +3 -3
  155. package/dist/modes/json.js.map +1 -1
  156. package/dist/modes/print-entry.d.ts +10 -0
  157. package/dist/modes/print-entry.d.ts.map +1 -0
  158. package/dist/modes/print-entry.js +11 -0
  159. package/dist/modes/print-entry.js.map +1 -0
  160. package/dist/modes/tree-selector.d.ts.map +1 -1
  161. package/dist/modes/tree-selector.js +4 -0
  162. package/dist/modes/tree-selector.js.map +1 -1
  163. package/dist/plugin-dump-composition.d.ts +6 -0
  164. package/dist/plugin-dump-composition.d.ts.map +1 -0
  165. package/dist/plugin-dump-composition.js +7 -0
  166. package/dist/plugin-dump-composition.js.map +1 -0
  167. package/dist/plugin-inventory.d.ts +7 -0
  168. package/dist/plugin-inventory.d.ts.map +1 -0
  169. package/dist/plugin-inventory.js +8 -0
  170. package/dist/plugin-inventory.js.map +1 -0
  171. package/dist/plugin-manager.d.ts +6 -0
  172. package/dist/plugin-manager.d.ts.map +1 -0
  173. package/dist/plugin-manager.js +7 -0
  174. package/dist/plugin-manager.js.map +1 -0
  175. package/dist/plugin-trace.d.ts +6 -0
  176. package/dist/plugin-trace.d.ts.map +1 -0
  177. package/dist/plugin-trace.js +7 -0
  178. package/dist/plugin-trace.js.map +1 -0
  179. package/dist/plugins/dynamic-broker.d.ts +76 -0
  180. package/dist/plugins/dynamic-broker.d.ts.map +1 -0
  181. package/dist/plugins/dynamic-broker.js +852 -0
  182. package/dist/plugins/dynamic-broker.js.map +1 -0
  183. package/dist/plugins/profile.d.ts +15 -0
  184. package/dist/plugins/profile.d.ts.map +1 -0
  185. package/dist/plugins/profile.js +34 -0
  186. package/dist/plugins/profile.js.map +1 -0
  187. package/dist/plugins/runtime-host.d.ts +37 -0
  188. package/dist/plugins/runtime-host.d.ts.map +1 -0
  189. package/dist/plugins/runtime-host.js +95 -0
  190. package/dist/plugins/runtime-host.js.map +1 -0
  191. package/dist/plugins/trust.d.ts +8 -0
  192. package/dist/plugins/trust.d.ts.map +1 -0
  193. package/dist/plugins/trust.js +59 -0
  194. package/dist/plugins/trust.js.map +1 -0
  195. package/dist/project-trust-entry.d.ts +15 -0
  196. package/dist/project-trust-entry.d.ts.map +1 -0
  197. package/dist/project-trust-entry.js +15 -0
  198. package/dist/project-trust-entry.js.map +1 -0
  199. package/dist/rpc/client.d.ts +78 -6
  200. package/dist/rpc/client.d.ts.map +1 -1
  201. package/dist/rpc/client.js +172 -4
  202. package/dist/rpc/client.js.map +1 -1
  203. package/dist/rpc/dispatcher.d.ts +121 -0
  204. package/dist/rpc/dispatcher.d.ts.map +1 -0
  205. package/dist/rpc/dispatcher.js +994 -0
  206. package/dist/rpc/dispatcher.js.map +1 -0
  207. package/dist/rpc/index.d.ts +2 -0
  208. package/dist/rpc/index.d.ts.map +1 -1
  209. package/dist/rpc/index.js +2 -0
  210. package/dist/rpc/index.js.map +1 -1
  211. package/dist/rpc/lifecycle.d.ts +6 -0
  212. package/dist/rpc/lifecycle.d.ts.map +1 -0
  213. package/dist/rpc/lifecycle.js +24 -0
  214. package/dist/rpc/lifecycle.js.map +1 -0
  215. package/dist/rpc/protocol.d.ts +112 -31
  216. package/dist/rpc/protocol.d.ts.map +1 -1
  217. package/dist/rpc/protocol.js +569 -117
  218. package/dist/rpc/protocol.js.map +1 -1
  219. package/dist/rpc/server-service.d.ts +7 -0
  220. package/dist/rpc/server-service.d.ts.map +1 -0
  221. package/dist/rpc/server-service.js +3 -0
  222. package/dist/rpc/server-service.js.map +1 -0
  223. package/dist/rpc/server.d.ts +16 -19
  224. package/dist/rpc/server.d.ts.map +1 -1
  225. package/dist/rpc/server.js +59 -115
  226. package/dist/rpc/server.js.map +1 -1
  227. package/dist/rpc-client-sdk-entry.d.ts +12 -0
  228. package/dist/rpc-client-sdk-entry.d.ts.map +1 -0
  229. package/dist/rpc-client-sdk-entry.js +11 -0
  230. package/dist/rpc-client-sdk-entry.js.map +1 -0
  231. package/dist/rpc-entry.js +50 -18
  232. package/dist/rpc-entry.js.map +1 -1
  233. package/dist/rpc-server-entry.d.ts +8 -0
  234. package/dist/rpc-server-entry.d.ts.map +1 -0
  235. package/dist/rpc-server-entry.js +67 -0
  236. package/dist/rpc-server-entry.js.map +1 -0
  237. package/dist/runtime/attachment-store.d.ts +13 -0
  238. package/dist/runtime/attachment-store.d.ts.map +1 -0
  239. package/dist/runtime/attachment-store.js +93 -0
  240. package/dist/runtime/attachment-store.js.map +1 -0
  241. package/dist/runtime/bootstrap.d.ts +14 -0
  242. package/dist/runtime/bootstrap.d.ts.map +1 -0
  243. package/dist/runtime/bootstrap.js +29 -0
  244. package/dist/runtime/bootstrap.js.map +1 -0
  245. package/dist/runtime/interactive-host-service.d.ts +22 -0
  246. package/dist/runtime/interactive-host-service.d.ts.map +1 -0
  247. package/dist/runtime/interactive-host-service.js +2 -0
  248. package/dist/runtime/interactive-host-service.js.map +1 -0
  249. package/dist/runtime/interactive-resource-service.d.ts +11 -0
  250. package/dist/runtime/interactive-resource-service.d.ts.map +1 -0
  251. package/dist/runtime/interactive-resource-service.js +3 -0
  252. package/dist/runtime/interactive-resource-service.js.map +1 -0
  253. package/dist/runtime/plugin-inventory-entry.d.ts +5 -0
  254. package/dist/runtime/plugin-inventory-entry.d.ts.map +1 -0
  255. package/dist/runtime/plugin-inventory-entry.js +18 -0
  256. package/dist/runtime/plugin-inventory-entry.js.map +1 -0
  257. package/dist/runtime/plugin-inventory-service.d.ts +8 -0
  258. package/dist/runtime/plugin-inventory-service.d.ts.map +1 -0
  259. package/dist/runtime/plugin-inventory-service.js +3 -0
  260. package/dist/runtime/plugin-inventory-service.js.map +1 -0
  261. package/dist/runtime/plugin-manager-entry.d.ts +20 -0
  262. package/dist/runtime/plugin-manager-entry.d.ts.map +1 -0
  263. package/dist/runtime/plugin-manager-entry.js +96 -0
  264. package/dist/runtime/plugin-manager-entry.js.map +1 -0
  265. package/dist/runtime/plugin-observability-entry.d.ts +12 -0
  266. package/dist/runtime/plugin-observability-entry.d.ts.map +1 -0
  267. package/dist/runtime/plugin-observability-entry.js +73 -0
  268. package/dist/runtime/plugin-observability-entry.js.map +1 -0
  269. package/dist/runtime/product-host.d.ts +91 -0
  270. package/dist/runtime/product-host.d.ts.map +1 -0
  271. package/dist/runtime/product-host.js +529 -0
  272. package/dist/runtime/product-host.js.map +1 -0
  273. package/dist/runtime/session-factory.d.ts +17 -0
  274. package/dist/runtime/session-factory.d.ts.map +1 -0
  275. package/dist/runtime/session-factory.js +75 -0
  276. package/dist/runtime/session-factory.js.map +1 -0
  277. package/dist/runtime/session-host.d.ts +152 -0
  278. package/dist/runtime/session-host.d.ts.map +1 -0
  279. package/dist/runtime/session-host.js +895 -0
  280. package/dist/runtime/session-host.js.map +1 -0
  281. package/dist/runtime-core-entry.d.ts +11 -0
  282. package/dist/runtime-core-entry.d.ts.map +1 -0
  283. package/dist/runtime-core-entry.js +9 -0
  284. package/dist/runtime-core-entry.js.map +1 -0
  285. package/dist/session-factory-entry.d.ts +7 -0
  286. package/dist/session-factory-entry.d.ts.map +1 -0
  287. package/dist/session-factory-entry.js +9 -0
  288. package/dist/session-factory-entry.js.map +1 -0
  289. package/dist/session-store-jsonl-entry.d.ts +7 -0
  290. package/dist/session-store-jsonl-entry.d.ts.map +1 -0
  291. package/dist/session-store-jsonl-entry.js +33 -0
  292. package/dist/session-store-jsonl-entry.js.map +1 -0
  293. package/dist/startup.d.ts +12 -1
  294. package/dist/startup.d.ts.map +1 -1
  295. package/dist/startup.js +106 -15
  296. package/dist/startup.js.map +1 -1
  297. package/dist/subagents/index.d.ts +2 -0
  298. package/dist/subagents/index.d.ts.map +1 -0
  299. package/dist/subagents/index.js +2 -0
  300. package/dist/subagents/index.js.map +1 -0
  301. package/dist/subagents/service.d.ts +50 -0
  302. package/dist/subagents/service.d.ts.map +1 -0
  303. package/dist/subagents/service.js +521 -0
  304. package/dist/subagents/service.js.map +1 -0
  305. package/dist/ui-host.d.ts +125 -0
  306. package/dist/ui-host.d.ts.map +1 -0
  307. package/dist/ui-host.js +275 -0
  308. package/dist/ui-host.js.map +1 -0
  309. package/dist/web/assets/index-BwfuGMvv.css +1 -0
  310. package/dist/web/assets/index-DPUaJqFJ.js +41 -0
  311. package/dist/web/assets/index-DPUaJqFJ.js.map +1 -0
  312. package/dist/web/index.html +14 -0
  313. package/dist/web-command.d.ts +11 -0
  314. package/dist/web-command.d.ts.map +1 -0
  315. package/dist/web-command.js +114 -0
  316. package/dist/web-command.js.map +1 -0
  317. package/dist/web-frontend.d.ts +73 -0
  318. package/dist/web-frontend.d.ts.map +1 -0
  319. package/dist/web-frontend.js +249 -0
  320. package/dist/web-frontend.js.map +1 -0
  321. package/dist/web.d.ts +254 -0
  322. package/dist/web.d.ts.map +1 -0
  323. package/dist/web.js +740 -0
  324. package/dist/web.js.map +1 -0
  325. package/dist/webui-entry.d.ts +3 -0
  326. package/dist/webui-entry.d.ts.map +1 -0
  327. package/dist/webui-entry.js +73 -0
  328. package/dist/webui-entry.js.map +1 -0
  329. package/dist/webui.d.ts +91 -0
  330. package/dist/webui.d.ts.map +1 -0
  331. package/dist/webui.js +882 -0
  332. package/dist/webui.js.map +1 -0
  333. package/package.json +89 -8
@@ -1 +1 @@
1
- {"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/core/tools/glob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAuC,IAAI,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,+BAA+B,EAC/B,0BAA0B,EAC1B,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACtC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IAClD,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;CACvD,CAAC,CAAC;AAKH,MAAM,UAAU,cAAc,CAAC,WAAmB;IACjD,OAAO;QACN,IAAI,EAAE,MAAM;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AAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;YAC7E,IAAI,SAAS;gBAAE,KAAK,CAAC,IAAI,CAAC,yBAAyB,UAAU,sBAAsB,CAAC,CAAC;YACrF,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnD,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { matchesGlob } from \"node:path\";\nimport type { AgentTool } from \"@di-code/agent\";\nimport { type Static, type ToolResultContent, Type } from \"@di-code/ai\";\nimport {\n\tappendBoundedLine,\n\tassertSearchLimit,\n\tDEFAULT_SEARCH_MAX_OUTPUT_BYTES,\n\tDEFAULT_SEARCH_MAX_RESULTS,\n\tnormalizeSearchPattern,\n\tresolveSearchRoot,\n\twalkSearchFiles,\n} from \"./file-search.ts\";\n\nexport const globParameters = Type.Object({\n\tpattern: Type.String({ minLength: 1 }),\n\tpath: Type.Optional(Type.String({ minLength: 1 })),\n\tmaxResults: Type.Optional(Type.Integer({ minimum: 1 })),\n});\n\nexport type GlobParameters = Static<typeof globParameters>;\nexport type GlobTool = AgentTool<typeof globParameters, ToolResultContent[]>;\n\nexport function createGlobTool(allowedRoot: string): GlobTool {\n\treturn {\n\t\tname: \"glob\",\n\t\tdescription:\n\t\t\t\"Find files inside the allowed root using a glob pattern such as **/*.ts. Returns sorted relative paths; symlinks are skipped.\",\n\t\tparameters: globParameters,\n\t\tasync execute(_toolCallId, parameters, signal): Promise<ToolResultContent[]> {\n\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\tif (parameters.path !== undefined && parameters.path.length === 0) throw new Error(\"path must not be empty\");\n\t\t\tconst pattern = normalizeSearchPattern(parameters.pattern);\n\t\t\tconst maxResults = parameters.maxResults ?? DEFAULT_SEARCH_MAX_RESULTS;\n\t\t\tassertSearchLimit(\"maxResults\", maxResults);\n\t\t\tconst root = await resolveSearchRoot(parameters.path, allowedRoot);\n\t\t\tconst displayRoot = await resolveSearchRoot(undefined, allowedRoot);\n\t\t\tconst lines: string[] = [];\n\t\t\tlet matched = 0;\n\t\t\tlet truncated = false;\n\t\t\tfor await (const file of walkSearchFiles(root, signal, displayRoot)) {\n\t\t\t\tif (!matchesGlob(file.searchPath, pattern)) continue;\n\t\t\t\tmatched++;\n\t\t\t\tif (matched > maxResults || !appendBoundedLine(lines, file.relativePath, DEFAULT_SEARCH_MAX_OUTPUT_BYTES)) {\n\t\t\t\t\ttruncated = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (lines.length === 0) return [{ type: \"text\", text: \"No files matched.\" }];\n\t\t\tif (truncated) lines.push(`[Results truncated at ${maxResults} matches or 50 KiB.]`);\n\t\t\treturn [{ type: \"text\", text: lines.join(\"\\n\") }];\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/core/tools/glob.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"@di-code/builtins\";\n"]}
@@ -1,13 +1,2 @@
1
- import type { AgentTool } from "@di-code/agent";
2
- import { type Static, type ToolResultContent, Type } from "@di-code/ai";
3
- export declare const grepParameters: Type.TObject<{
4
- pattern: Type.TString;
5
- path: Type.TOptional<Type.TString>;
6
- include: Type.TOptional<Type.TString>;
7
- caseSensitive: Type.TOptional<Type.TBoolean>;
8
- maxResults: Type.TOptional<Type.TInteger>;
9
- }>;
10
- export type GrepParameters = Static<typeof grepParameters>;
11
- export type GrepTool = AgentTool<typeof grepParameters, ToolResultContent[]>;
12
- export declare function createGrepTool(allowedRoot: string): GrepTool;
1
+ export * from "@di-code/builtins";
13
2
  //# sourceMappingURL=grep.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../../src/core/tools/grep.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAYxE,eAAO,MAAM,cAAc;;;;;;EAMzB,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAC3D,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,cAAc,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAE7E,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CA6C5D"}
1
+ {"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../../src/core/tools/grep.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1,67 +1,2 @@
1
- import { matchesGlob } from "node:path";
2
- import { Type } from "@di-code/ai";
3
- import { appendBoundedLine, assertSearchLimit, DEFAULT_SEARCH_MAX_OUTPUT_BYTES, DEFAULT_SEARCH_MAX_RESULTS, normalizeSearchPattern, readSearchText, resolveSearchRoot, walkSearchFiles, } from "./file-search.js";
4
- export const grepParameters = Type.Object({
5
- pattern: Type.String({ minLength: 1, maxLength: 1_000 }),
6
- path: Type.Optional(Type.String({ minLength: 1 })),
7
- include: Type.Optional(Type.String({ minLength: 1 })),
8
- caseSensitive: Type.Optional(Type.Boolean()),
9
- maxResults: Type.Optional(Type.Integer({ minimum: 1 })),
10
- });
11
- export function createGrepTool(allowedRoot) {
12
- return {
13
- name: "grep",
14
- description: "Search UTF-8 text files inside the allowed root for a literal string. Returns sorted path:line matches; binary files and symlinks are skipped.",
15
- parameters: grepParameters,
16
- async execute(_toolCallId, parameters, signal) {
17
- if (signal?.aborted)
18
- throw new Error("Operation aborted");
19
- if (parameters.pattern.length === 0)
20
- throw new Error("pattern must not be empty");
21
- if (parameters.pattern.length > 1_000)
22
- throw new Error("pattern must not exceed 1000 characters");
23
- if (parameters.path !== undefined && parameters.path.length === 0)
24
- throw new Error("path must not be empty");
25
- const include = parameters.include === undefined ? undefined : normalizeSearchPattern(parameters.include);
26
- const maxResults = parameters.maxResults ?? DEFAULT_SEARCH_MAX_RESULTS;
27
- assertSearchLimit("maxResults", maxResults);
28
- const root = await resolveSearchRoot(parameters.path, allowedRoot);
29
- const displayRoot = await resolveSearchRoot(undefined, allowedRoot);
30
- const needle = parameters.caseSensitive === false ? parameters.pattern.toLocaleLowerCase() : parameters.pattern;
31
- const lines = [];
32
- let matched = 0;
33
- let truncated = false;
34
- for await (const file of walkSearchFiles(root, signal, displayRoot)) {
35
- if (include !== undefined && !matchesInclude(file.searchPath, include))
36
- continue;
37
- const text = await readSearchText(file, allowedRoot, signal);
38
- if (text === undefined)
39
- continue;
40
- const fileLines = text.split("\n");
41
- for (let index = 0; index < fileLines.length; index++) {
42
- const line = fileLines[index] ?? "";
43
- const haystack = parameters.caseSensitive === false ? line.toLocaleLowerCase() : line;
44
- if (!haystack.includes(needle))
45
- continue;
46
- matched++;
47
- if (matched > maxResults ||
48
- !appendBoundedLine(lines, `${file.relativePath}:${index + 1}: ${line}`, DEFAULT_SEARCH_MAX_OUTPUT_BYTES)) {
49
- truncated = true;
50
- break;
51
- }
52
- }
53
- if (truncated)
54
- break;
55
- }
56
- if (lines.length === 0)
57
- return [{ type: "text", text: "No matches found." }];
58
- if (truncated)
59
- lines.push(`[Results truncated at ${maxResults} matches or 50 KiB.]`);
60
- return [{ type: "text", text: lines.join("\n") }];
61
- },
62
- };
63
- }
64
- function matchesInclude(relativePath, pattern) {
65
- return matchesGlob(relativePath, pattern);
66
- }
1
+ export * from "@di-code/builtins";
67
2
  //# sourceMappingURL=grep.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../src/core/tools/grep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAuC,IAAI,EAA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BACnC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;oBACvD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;oBACpC,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;oBACtF,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;wBAAE,SAAS;oBACzC,OAAO,EAAE,CAAC;oBACV,IACC,OAAO,GAAG,UAAU;wBACpB,CAAC,iBAAiB,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,YAAY,IAAI,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,EAAE,+BAA+B,CAAC,EACvG,CAAC;wBACF,SAAS,GAAG,IAAI,CAAC;wBACjB,MAAM;oBACP,CAAC;gBACF,CAAC;gBACD,IAAI,SAAS;oBAAE,MAAM;YACtB,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;YAC7E,IAAI,SAAS;gBAAE,KAAK,CAAC,IAAI,CAAC,yBAAyB,UAAU,sBAAsB,CAAC,CAAC;YACrF,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnD,CAAC;KACD,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,YAAoB,EAAE,OAAe;IAC5D,OAAO,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { matchesGlob } from \"node:path\";\nimport type { AgentTool } from \"@di-code/agent\";\nimport { type Static, type ToolResultContent, Type } from \"@di-code/ai\";\nimport {\n\tappendBoundedLine,\n\tassertSearchLimit,\n\tDEFAULT_SEARCH_MAX_OUTPUT_BYTES,\n\tDEFAULT_SEARCH_MAX_RESULTS,\n\tnormalizeSearchPattern,\n\treadSearchText,\n\tresolveSearchRoot,\n\twalkSearchFiles,\n} from \"./file-search.ts\";\n\nexport const grepParameters = Type.Object({\n\tpattern: Type.String({ minLength: 1, maxLength: 1_000 }),\n\tpath: Type.Optional(Type.String({ minLength: 1 })),\n\tinclude: Type.Optional(Type.String({ minLength: 1 })),\n\tcaseSensitive: Type.Optional(Type.Boolean()),\n\tmaxResults: Type.Optional(Type.Integer({ minimum: 1 })),\n});\n\nexport type GrepParameters = Static<typeof grepParameters>;\nexport type GrepTool = AgentTool<typeof grepParameters, ToolResultContent[]>;\n\nexport function createGrepTool(allowedRoot: string): GrepTool {\n\treturn {\n\t\tname: \"grep\",\n\t\tdescription:\n\t\t\t\"Search UTF-8 text files inside the allowed root for a literal string. Returns sorted path:line matches; binary files and symlinks are skipped.\",\n\t\tparameters: grepParameters,\n\t\tasync execute(_toolCallId, parameters, signal): Promise<ToolResultContent[]> {\n\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\tif (parameters.pattern.length === 0) throw new Error(\"pattern must not be empty\");\n\t\t\tif (parameters.pattern.length > 1_000) throw new Error(\"pattern must not exceed 1000 characters\");\n\t\t\tif (parameters.path !== undefined && parameters.path.length === 0) throw new Error(\"path must not be empty\");\n\t\t\tconst include = parameters.include === undefined ? undefined : normalizeSearchPattern(parameters.include);\n\t\t\tconst maxResults = parameters.maxResults ?? DEFAULT_SEARCH_MAX_RESULTS;\n\t\t\tassertSearchLimit(\"maxResults\", maxResults);\n\t\t\tconst root = await resolveSearchRoot(parameters.path, allowedRoot);\n\t\t\tconst displayRoot = await resolveSearchRoot(undefined, allowedRoot);\n\t\t\tconst needle = parameters.caseSensitive === false ? parameters.pattern.toLocaleLowerCase() : parameters.pattern;\n\t\t\tconst lines: string[] = [];\n\t\t\tlet matched = 0;\n\t\t\tlet truncated = false;\n\t\t\tfor await (const file of walkSearchFiles(root, signal, displayRoot)) {\n\t\t\t\tif (include !== undefined && !matchesInclude(file.searchPath, include)) continue;\n\t\t\t\tconst text = await readSearchText(file, allowedRoot, signal);\n\t\t\t\tif (text === undefined) continue;\n\t\t\t\tconst fileLines = text.split(\"\\n\");\n\t\t\t\tfor (let index = 0; index < fileLines.length; index++) {\n\t\t\t\t\tconst line = fileLines[index] ?? \"\";\n\t\t\t\t\tconst haystack = parameters.caseSensitive === false ? line.toLocaleLowerCase() : line;\n\t\t\t\t\tif (!haystack.includes(needle)) continue;\n\t\t\t\t\tmatched++;\n\t\t\t\t\tif (\n\t\t\t\t\t\tmatched > maxResults ||\n\t\t\t\t\t\t!appendBoundedLine(lines, `${file.relativePath}:${index + 1}: ${line}`, DEFAULT_SEARCH_MAX_OUTPUT_BYTES)\n\t\t\t\t\t) {\n\t\t\t\t\t\ttruncated = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (truncated) break;\n\t\t\t}\n\t\t\tif (lines.length === 0) return [{ type: \"text\", text: \"No matches found.\" }];\n\t\t\tif (truncated) lines.push(`[Results truncated at ${maxResults} matches or 50 KiB.]`);\n\t\t\treturn [{ type: \"text\", text: lines.join(\"\\n\") }];\n\t\t},\n\t};\n}\n\nfunction matchesInclude(relativePath: string, pattern: string): boolean {\n\treturn matchesGlob(relativePath, pattern);\n}\n"]}
1
+ {"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../src/core/tools/grep.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"@di-code/builtins\";\n"]}
@@ -1,10 +1,2 @@
1
- import type { AgentTool } from "@di-code/agent";
2
- import { type Static, type ToolResultContent, Type } from "@di-code/ai";
3
- import type { SkillCatalog } from "@di-code/skills";
4
- export declare const loadSkillParameters: Type.TObject<{
5
- name: Type.TString;
6
- }>;
7
- export type LoadSkillParameters = Static<typeof loadSkillParameters>;
8
- export type LoadSkillTool = AgentTool<typeof loadSkillParameters, ToolResultContent[]>;
9
- export declare function createLoadSkillTool(catalog: SkillCatalog): LoadSkillTool;
1
+ export * from "@di-code/builtins";
10
2
  //# sourceMappingURL=load-skill.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load-skill.d.ts","sourceRoot":"","sources":["../../../src/core/tools/load-skill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,eAAO,MAAM,mBAAmB;;EAE9B,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACrE,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,mBAAmB,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAEvF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,CAaxE"}
1
+ {"version":3,"file":"load-skill.d.ts","sourceRoot":"","sources":["../../../src/core/tools/load-skill.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1,22 +1,2 @@
1
- import { Type } from "@di-code/ai";
2
- import { readSkillContent } from "@di-code/skills";
3
- export const loadSkillParameters = Type.Object({
4
- name: Type.String({ minLength: 1 }),
5
- });
6
- export function createLoadSkillTool(catalog) {
7
- return {
8
- name: "load_skill",
9
- description: "Load the untrusted instructions for a registered skill by name.",
10
- parameters: loadSkillParameters,
11
- async execute(_toolCallId, parameters, signal) {
12
- if (signal?.aborted)
13
- throw new Error("Operation aborted");
14
- const skill = catalog.resolve(parameters.name);
15
- if (!skill || skill.disableModelInvocation)
16
- throw new Error(`Unknown or unavailable skill "${parameters.name}".`);
17
- const content = await readSkillContent(skill, signal);
18
- return [{ type: "text", text: `<skill name="${skill.name}" source="${skill.source}">\n${content}\n</skill>` }];
19
- },
20
- };
21
- }
1
+ export * from "@di-code/builtins";
22
2
  //# sourceMappingURL=load-skill.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"load-skill.js","sourceRoot":"","sources":["../../../src/core/tools/load-skill.ts"],"names":[],"mappings":"AACA,OAAO,EAAuC,IAAI,EAAE,MAAM,aAAa,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;CACnC,CAAC,CAAC;AAKH,MAAM,UAAU,mBAAmB,CAAC,OAAqB;IACxD,OAAO;QACN,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,iEAAiE;QAC9E,UAAU,EAAE,mBAAmB;QAC/B,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM;YAC5C,IAAI,MAAM,EAAE,OAAO;gBAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC1D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,sBAAsB;gBAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,UAAU,CAAC,IAAI,IAAI,CAAC,CAAC;YAClH,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACtD,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,MAAM,OAAO,OAAO,YAAY,EAAE,CAAC,CAAC;QAChH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { AgentTool } from \"@di-code/agent\";\nimport { type Static, type ToolResultContent, Type } from \"@di-code/ai\";\nimport type { SkillCatalog } from \"@di-code/skills\";\nimport { readSkillContent } from \"@di-code/skills\";\n\nexport const loadSkillParameters = Type.Object({\n\tname: Type.String({ minLength: 1 }),\n});\n\nexport type LoadSkillParameters = Static<typeof loadSkillParameters>;\nexport type LoadSkillTool = AgentTool<typeof loadSkillParameters, ToolResultContent[]>;\n\nexport function createLoadSkillTool(catalog: SkillCatalog): LoadSkillTool {\n\treturn {\n\t\tname: \"load_skill\",\n\t\tdescription: \"Load the untrusted instructions for a registered skill by name.\",\n\t\tparameters: loadSkillParameters,\n\t\tasync execute(_toolCallId, parameters, signal): Promise<ToolResultContent[]> {\n\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\tconst skill = catalog.resolve(parameters.name);\n\t\t\tif (!skill || skill.disableModelInvocation) throw new Error(`Unknown or unavailable skill \"${parameters.name}\".`);\n\t\t\tconst content = await readSkillContent(skill, signal);\n\t\t\treturn [{ type: \"text\", text: `<skill name=\"${skill.name}\" source=\"${skill.source}\">\\n${content}\\n</skill>` }];\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"load-skill.js","sourceRoot":"","sources":["../../../src/core/tools/load-skill.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"@di-code/builtins\";\n"]}
@@ -1,5 +1,2 @@
1
- export declare function resolveAllowedMutationPath(inputPath: string, allowedRoot: string): Promise<string>;
2
- export declare function resolveAllowedFilePath(inputPath: string, allowedRoot: string): Promise<string>;
3
- /** Resolve an existing file or directory while enforcing the realpath root boundary. */
4
- export declare function resolveAllowedExistingPath(inputPath: string, allowedRoot: string): Promise<string>;
1
+ export * from "@di-code/builtins";
5
2
  //# sourceMappingURL=path-boundary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"path-boundary.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-boundary.ts"],"names":[],"mappings":"AAoBA,wBAAsB,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgCxG;AAED,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEpG;AAED,wFAAwF;AACxF,wBAAsB,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxG"}
1
+ {"version":3,"file":"path-boundary.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-boundary.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1,66 +1,2 @@
1
- import { lstat, realpath } from "node:fs/promises";
2
- import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
3
- function assertInsideRoot(root, target) {
4
- const fromRoot = relative(root, target);
5
- if (fromRoot === "" || (fromRoot !== ".." && !fromRoot.startsWith(`..${sep}`) && !isAbsolute(fromRoot))) {
6
- return;
7
- }
8
- throw new Error("Path is outside the allowed root");
9
- }
10
- function isMissingPathError(error) {
11
- return (typeof error === "object" &&
12
- error !== null &&
13
- "code" in error &&
14
- (error.code === "ENOENT" || error.code === "ENOTDIR"));
15
- }
16
- export async function resolveAllowedMutationPath(inputPath, allowedRoot) {
17
- const rootReal = await realpath(allowedRoot);
18
- const candidate = resolve(rootReal, inputPath);
19
- assertInsideRoot(rootReal, candidate);
20
- const missingSegments = [];
21
- let current = candidate;
22
- while (true) {
23
- try {
24
- const currentReal = await realpath(current);
25
- assertInsideRoot(rootReal, currentReal);
26
- const target = resolve(currentReal, ...missingSegments.reverse());
27
- assertInsideRoot(rootReal, target);
28
- return target;
29
- }
30
- catch (error) {
31
- if (!isMissingPathError(error))
32
- throw error;
33
- let entryExists = false;
34
- try {
35
- const entry = await lstat(current);
36
- if (entry.isSymbolicLink())
37
- throw new Error("Path is outside the allowed root");
38
- entryExists = true;
39
- }
40
- catch (entryError) {
41
- if (!isMissingPathError(entryError))
42
- throw entryError;
43
- }
44
- if (entryExists)
45
- continue;
46
- const parent = dirname(current);
47
- if (parent === current)
48
- throw error;
49
- missingSegments.push(basename(current));
50
- current = parent;
51
- }
52
- }
53
- }
54
- export async function resolveAllowedFilePath(inputPath, allowedRoot) {
55
- return resolveAllowedExistingPath(inputPath, allowedRoot);
56
- }
57
- /** Resolve an existing file or directory while enforcing the realpath root boundary. */
58
- export async function resolveAllowedExistingPath(inputPath, allowedRoot) {
59
- const rootReal = await realpath(allowedRoot);
60
- const candidate = resolve(rootReal, inputPath);
61
- assertInsideRoot(rootReal, candidate);
62
- const targetReal = await realpath(candidate);
63
- assertInsideRoot(rootReal, targetReal);
64
- return targetReal;
65
- }
1
+ export * from "@di-code/builtins";
66
2
  //# sourceMappingURL=path-boundary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"path-boundary.js","sourceRoot":"","sources":["../../../src/core/tools/path-boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAElF,SAAS,gBAAgB,CAAC,IAAY,EAAE,MAAc;IACrD,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,QAAQ,KAAK,EAAE,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QACzG,OAAO;IACR,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAA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CAAC;YACpB,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC;oBAAE,MAAM,UAAU,CAAC;YACvD,CAAC;YACD,IAAI,WAAW;gBAAE,SAAS;YAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;YAChC,IAAI,MAAM,KAAK,OAAO;gBAAE,MAAM,KAAK,CAAC;YACpC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YACxC,OAAO,GAAG,MAAM,CAAC;QAClB,CAAC;IACF,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,SAAiB,EAAE,WAAmB;IAClF,OAAO,0BAA0B,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAC3D,CAAC;AAED,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,SAAiB,EAAE,WAAmB;IACtF,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC/C,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC7C,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACvC,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import { lstat, realpath } from \"node:fs/promises\";\nimport { basename, dirname, isAbsolute, relative, resolve, sep } from \"node:path\";\n\nfunction assertInsideRoot(root: string, target: string): void {\n\tconst fromRoot = relative(root, target);\n\tif (fromRoot === \"\" || (fromRoot !== \"..\" && !fromRoot.startsWith(`..${sep}`) && !isAbsolute(fromRoot))) {\n\t\treturn;\n\t}\n\tthrow new Error(\"Path is outside the allowed root\");\n}\n\nfunction isMissingPathError(error: unknown): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"code\" in error &&\n\t\t(error.code === \"ENOENT\" || error.code === \"ENOTDIR\")\n\t);\n}\n\nexport async function resolveAllowedMutationPath(inputPath: string, allowedRoot: string): Promise<string> {\n\tconst rootReal = await realpath(allowedRoot);\n\tconst candidate = resolve(rootReal, inputPath);\n\tassertInsideRoot(rootReal, candidate);\n\n\tconst missingSegments: string[] = [];\n\tlet current = candidate;\n\n\twhile (true) {\n\t\ttry {\n\t\t\tconst currentReal = await realpath(current);\n\t\t\tassertInsideRoot(rootReal, currentReal);\n\t\t\tconst target = resolve(currentReal, ...missingSegments.reverse());\n\t\t\tassertInsideRoot(rootReal, target);\n\t\t\treturn target;\n\t\t} catch (error) {\n\t\t\tif (!isMissingPathError(error)) throw error;\n\t\t\tlet entryExists = false;\n\t\t\ttry {\n\t\t\t\tconst entry = await lstat(current);\n\t\t\t\tif (entry.isSymbolicLink()) throw new Error(\"Path is outside the allowed root\");\n\t\t\t\tentryExists = true;\n\t\t\t} catch (entryError) {\n\t\t\t\tif (!isMissingPathError(entryError)) throw entryError;\n\t\t\t}\n\t\t\tif (entryExists) continue;\n\t\t\tconst parent = dirname(current);\n\t\t\tif (parent === current) throw error;\n\t\t\tmissingSegments.push(basename(current));\n\t\t\tcurrent = parent;\n\t\t}\n\t}\n}\n\nexport async function resolveAllowedFilePath(inputPath: string, allowedRoot: string): Promise<string> {\n\treturn resolveAllowedExistingPath(inputPath, allowedRoot);\n}\n\n/** Resolve an existing file or directory while enforcing the realpath root boundary. */\nexport async function resolveAllowedExistingPath(inputPath: string, allowedRoot: string): Promise<string> {\n\tconst rootReal = await realpath(allowedRoot);\n\tconst candidate = resolve(rootReal, inputPath);\n\tassertInsideRoot(rootReal, candidate);\n\tconst targetReal = await realpath(candidate);\n\tassertInsideRoot(rootReal, targetReal);\n\treturn targetReal;\n}\n"]}
1
+ {"version":3,"file":"path-boundary.js","sourceRoot":"","sources":["../../../src/core/tools/path-boundary.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"@di-code/builtins\";\n"]}
@@ -1,17 +1,2 @@
1
- import type { AgentTool } from "@di-code/agent";
2
- import { type Static, type ToolResultContent, Type } from "@di-code/ai";
3
- export declare const DEFAULT_READ_MAX_LINES = 2000;
4
- export declare const DEFAULT_READ_MAX_BYTES: number;
5
- export declare const readParameters: Type.TObject<{
6
- path: Type.TString;
7
- offset: Type.TOptional<Type.TInteger>;
8
- limit: Type.TOptional<Type.TInteger>;
9
- }>;
10
- export type ReadParameters = Static<typeof readParameters>;
11
- export interface ReadToolOptions {
12
- readonly maxLines?: number;
13
- readonly maxBytes?: number;
14
- }
15
- export type ReadTool = AgentTool<typeof readParameters, ToolResultContent[]>;
16
- export declare function createReadTool(allowedRoot: string, options?: ReadToolOptions): ReadTool;
1
+ export * from "@di-code/builtins";
17
2
  //# sourceMappingURL=read.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGxE,eAAO,MAAM,sBAAsB,OAAQ,CAAC;AAC5C,eAAO,MAAM,sBAAsB,QAAY,CAAC;AAEhD,eAAO,MAAM,cAAc;;;;EAIzB,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAE3D,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,cAAc,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAuG7E,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CA8B3F"}
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1,132 +1,2 @@
1
- import { readFile } from "node:fs/promises";
2
- import { Type } from "@di-code/ai";
3
- import { resolveAllowedFilePath } from "./path-boundary.js";
4
- export const DEFAULT_READ_MAX_LINES = 2_000;
5
- export const DEFAULT_READ_MAX_BYTES = 50 * 1024;
6
- export const readParameters = Type.Object({
7
- path: Type.String({ minLength: 1 }),
8
- offset: Type.Optional(Type.Integer({ minimum: 1 })),
9
- limit: Type.Optional(Type.Integer({ minimum: 1 })),
10
- });
11
- function assertPositiveInteger(name, value) {
12
- if (value !== undefined && (!Number.isInteger(value) || value < 1)) {
13
- throw new Error(`${name} must be a positive integer`);
14
- }
15
- }
16
- function splitLines(text) {
17
- if (text.length === 0)
18
- return [];
19
- const lines = text.split("\n");
20
- if (text.endsWith("\n"))
21
- lines.pop();
22
- return lines;
23
- }
24
- function selectUserWindow(lines, offset, limit) {
25
- if (lines.length === 0) {
26
- if (offset > 1)
27
- throw new Error(`Offset ${offset} is beyond end of file (0 lines total)`);
28
- return { content: "", startLine: 1, endLine: 0, totalLines: 0, truncatedBy: null };
29
- }
30
- const startIndex = offset - 1;
31
- if (startIndex >= lines.length) {
32
- throw new Error(`Offset ${offset} is beyond end of file (${lines.length} lines total)`);
33
- }
34
- const available = lines.slice(startIndex);
35
- const selected = limit === undefined ? available : available.slice(0, limit);
36
- const endLine = offset + selected.length - 1;
37
- return {
38
- content: selected.join("\n"),
39
- startLine: offset,
40
- endLine,
41
- totalLines: lines.length,
42
- truncatedBy: limit !== undefined && selected.length < available.length ? "limit" : null,
43
- };
44
- }
45
- function applyOutputLimits(window, maxLines, maxBytes) {
46
- if (window.content === "")
47
- return window;
48
- const lines = window.content.split("\n");
49
- const selected = [];
50
- let bytes = 0;
51
- let truncatedBy = null;
52
- for (const line of lines) {
53
- if (selected.length >= maxLines) {
54
- truncatedBy = "lines";
55
- break;
56
- }
57
- const separatorBytes = selected.length === 0 ? 0 : 1;
58
- const nextBytes = bytes + separatorBytes + Buffer.byteLength(line, "utf8");
59
- if (nextBytes > maxBytes) {
60
- if (selected.length === 0)
61
- throw new Error("A single line exceeds the read byte limit");
62
- truncatedBy = "bytes";
63
- break;
64
- }
65
- selected.push(line);
66
- bytes = nextBytes;
67
- }
68
- if (truncatedBy === null && selected.length < lines.length)
69
- truncatedBy = "lines";
70
- if (truncatedBy === null)
71
- return window;
72
- return {
73
- ...window,
74
- content: selected.join("\n"),
75
- endLine: window.startLine + selected.length - 1,
76
- truncatedBy,
77
- };
78
- }
79
- function formatByteLimit(maxBytes) {
80
- if (maxBytes % 1024 === 0)
81
- return `${maxBytes / 1024} KiB`;
82
- return `${maxBytes} bytes`;
83
- }
84
- function appendContinuation(window, maxBytes) {
85
- if (window.truncatedBy === null)
86
- return window.content;
87
- const nextOffset = window.endLine + 1;
88
- if (window.truncatedBy === "limit") {
89
- const remaining = window.totalLines - window.endLine;
90
- return `${window.content}\n\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;
91
- }
92
- const reason = window.truncatedBy === "bytes" ? ` (${formatByteLimit(maxBytes)} limit)` : "";
93
- return `${window.content}\n\n[Showing lines ${window.startLine}-${window.endLine} of ${window.totalLines}${reason}. Use offset=${nextOffset} to continue.]`;
94
- }
95
- function containsNulByte(buffer) {
96
- const sampleLength = Math.min(buffer.length, 8 * 1024);
97
- for (let index = 0; index < sampleLength; index++) {
98
- if (buffer[index] === 0)
99
- return true;
100
- }
101
- return false;
102
- }
103
- export function createReadTool(allowedRoot, options = {}) {
104
- const maxLines = options.maxLines ?? DEFAULT_READ_MAX_LINES;
105
- const maxBytes = options.maxBytes ?? DEFAULT_READ_MAX_BYTES;
106
- assertPositiveInteger("maxLines", maxLines);
107
- assertPositiveInteger("maxBytes", maxBytes);
108
- return {
109
- name: "read",
110
- description: "Read a UTF-8 text file inside the allowed root. Use offset and limit for large files.",
111
- parameters: readParameters,
112
- async execute(_toolCallId, parameters, signal) {
113
- if (signal?.aborted)
114
- throw new Error("Operation aborted");
115
- if (parameters.path.length === 0)
116
- throw new Error("path must not be empty");
117
- assertPositiveInteger("offset", parameters.offset);
118
- assertPositiveInteger("limit", parameters.limit);
119
- const absolutePath = await resolveAllowedFilePath(parameters.path, allowedRoot);
120
- if (signal?.aborted)
121
- throw new Error("Operation aborted");
122
- const buffer = await readFile(absolutePath);
123
- if (containsNulByte(buffer)) {
124
- throw new Error("Binary files are not supported by read");
125
- }
126
- const userWindow = selectUserWindow(splitLines(buffer.toString("utf8")), parameters.offset ?? 1, parameters.limit);
127
- const boundedWindow = applyOutputLimits(userWindow, maxLines, maxBytes);
128
- return [{ type: "text", text: appendContinuation(boundedWindow, maxBytes) }];
129
- },
130
- };
131
- }
1
+ export * from "@di-code/builtins";
132
2
  //# sourceMappingURL=read.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAuC,IAAI,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAC5C,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACnC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,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UAAU,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;YAC5E,qBAAqB,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;YACnD,qBAAqB,CAAC,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;YACjD,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;YAChF,IAAI,MAAM,EAAE,OAAO;gBAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;YAC1D,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC5C,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC3D,CAAC;YACD,MAAM,UAAU,GAAG,gBAAgB,CAClC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EACnC,UAAU,CAAC,MAAM,IAAI,CAAC,EACtB,UAAU,CAAC,KAAK,CAChB,CAAC;YACF,MAAM,aAAa,GAAG,iBAAiB,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACxE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9E,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport type { AgentTool } from \"@di-code/agent\";\nimport { type Static, type ToolResultContent, Type } from \"@di-code/ai\";\nimport { resolveAllowedFilePath } from \"./path-boundary.ts\";\n\nexport const DEFAULT_READ_MAX_LINES = 2_000;\nexport const DEFAULT_READ_MAX_BYTES = 50 * 1024;\n\nexport const readParameters = Type.Object({\n\tpath: Type.String({ minLength: 1 }),\n\toffset: Type.Optional(Type.Integer({ minimum: 1 })),\n\tlimit: Type.Optional(Type.Integer({ minimum: 1 })),\n});\n\nexport type ReadParameters = Static<typeof readParameters>;\n\nexport interface ReadToolOptions {\n\treadonly maxLines?: number;\n\treadonly maxBytes?: number;\n}\n\nexport type ReadTool = AgentTool<typeof readParameters, ToolResultContent[]>;\n\ninterface TextWindow {\n\treadonly content: string;\n\treadonly startLine: number;\n\treadonly endLine: number;\n\treadonly totalLines: number;\n\treadonly truncatedBy: \"limit\" | \"lines\" | \"bytes\" | null;\n}\n\nfunction assertPositiveInteger(name: string, value: number | undefined): void {\n\tif (value !== undefined && (!Number.isInteger(value) || value < 1)) {\n\t\tthrow new Error(`${name} must be a positive integer`);\n\t}\n}\n\nfunction splitLines(text: string): string[] {\n\tif (text.length === 0) return [];\n\tconst lines = text.split(\"\\n\");\n\tif (text.endsWith(\"\\n\")) lines.pop();\n\treturn lines;\n}\n\nfunction selectUserWindow(lines: readonly string[], offset: number, limit: number | undefined): TextWindow {\n\tif (lines.length === 0) {\n\t\tif (offset > 1) throw new Error(`Offset ${offset} is beyond end of file (0 lines total)`);\n\t\treturn { content: \"\", startLine: 1, endLine: 0, totalLines: 0, truncatedBy: null };\n\t}\n\n\tconst startIndex = offset - 1;\n\tif (startIndex >= lines.length) {\n\t\tthrow new Error(`Offset ${offset} is beyond end of file (${lines.length} lines total)`);\n\t}\n\n\tconst available = lines.slice(startIndex);\n\tconst selected = limit === undefined ? available : available.slice(0, limit);\n\tconst endLine = offset + selected.length - 1;\n\treturn {\n\t\tcontent: selected.join(\"\\n\"),\n\t\tstartLine: offset,\n\t\tendLine,\n\t\ttotalLines: lines.length,\n\t\ttruncatedBy: limit !== undefined && selected.length < available.length ? \"limit\" : null,\n\t};\n}\n\nfunction applyOutputLimits(window: TextWindow, maxLines: number, maxBytes: number): TextWindow {\n\tif (window.content === \"\") return window;\n\tconst lines = window.content.split(\"\\n\");\n\tconst selected: string[] = [];\n\tlet bytes = 0;\n\tlet truncatedBy: \"lines\" | \"bytes\" | null = null;\n\n\tfor (const line of lines) {\n\t\tif (selected.length >= maxLines) {\n\t\t\ttruncatedBy = \"lines\";\n\t\t\tbreak;\n\t\t}\n\t\tconst separatorBytes = selected.length === 0 ? 0 : 1;\n\t\tconst nextBytes = bytes + separatorBytes + Buffer.byteLength(line, \"utf8\");\n\t\tif (nextBytes > maxBytes) {\n\t\t\tif (selected.length === 0) throw new Error(\"A single line exceeds the read byte limit\");\n\t\t\ttruncatedBy = \"bytes\";\n\t\t\tbreak;\n\t\t}\n\t\tselected.push(line);\n\t\tbytes = nextBytes;\n\t}\n\n\tif (truncatedBy === null && selected.length < lines.length) truncatedBy = \"lines\";\n\tif (truncatedBy === null) return window;\n\treturn {\n\t\t...window,\n\t\tcontent: selected.join(\"\\n\"),\n\t\tendLine: window.startLine + selected.length - 1,\n\t\ttruncatedBy,\n\t};\n}\n\nfunction formatByteLimit(maxBytes: number): string {\n\tif (maxBytes % 1024 === 0) return `${maxBytes / 1024} KiB`;\n\treturn `${maxBytes} bytes`;\n}\n\nfunction appendContinuation(window: TextWindow, maxBytes: number): string {\n\tif (window.truncatedBy === null) return window.content;\n\tconst nextOffset = window.endLine + 1;\n\tif (window.truncatedBy === \"limit\") {\n\t\tconst remaining = window.totalLines - window.endLine;\n\t\treturn `${window.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t}\n\tconst reason = window.truncatedBy === \"bytes\" ? ` (${formatByteLimit(maxBytes)} limit)` : \"\";\n\treturn `${window.content}\\n\\n[Showing lines ${window.startLine}-${window.endLine} of ${window.totalLines}${reason}. Use offset=${nextOffset} to continue.]`;\n}\n\nfunction containsNulByte(buffer: Buffer): boolean {\n\tconst sampleLength = Math.min(buffer.length, 8 * 1024);\n\tfor (let index = 0; index < sampleLength; index++) {\n\t\tif (buffer[index] === 0) return true;\n\t}\n\treturn false;\n}\n\nexport function createReadTool(allowedRoot: string, options: ReadToolOptions = {}): ReadTool {\n\tconst maxLines = options.maxLines ?? DEFAULT_READ_MAX_LINES;\n\tconst maxBytes = options.maxBytes ?? DEFAULT_READ_MAX_BYTES;\n\tassertPositiveInteger(\"maxLines\", maxLines);\n\tassertPositiveInteger(\"maxBytes\", maxBytes);\n\n\treturn {\n\t\tname: \"read\",\n\t\tdescription: \"Read a UTF-8 text file inside the allowed root. Use offset and limit for large files.\",\n\t\tparameters: readParameters,\n\t\tasync execute(_toolCallId, parameters, signal): Promise<ToolResultContent[]> {\n\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\tif (parameters.path.length === 0) throw new Error(\"path must not be empty\");\n\t\t\tassertPositiveInteger(\"offset\", parameters.offset);\n\t\t\tassertPositiveInteger(\"limit\", parameters.limit);\n\t\t\tconst absolutePath = await resolveAllowedFilePath(parameters.path, allowedRoot);\n\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\tconst buffer = await readFile(absolutePath);\n\t\t\tif (containsNulByte(buffer)) {\n\t\t\t\tthrow new Error(\"Binary files are not supported by read\");\n\t\t\t}\n\t\t\tconst userWindow = selectUserWindow(\n\t\t\t\tsplitLines(buffer.toString(\"utf8\")),\n\t\t\t\tparameters.offset ?? 1,\n\t\t\t\tparameters.limit,\n\t\t\t);\n\t\t\tconst boundedWindow = applyOutputLimits(userWindow, maxLines, maxBytes);\n\t\t\treturn [{ type: \"text\", text: appendContinuation(boundedWindow, maxBytes) }];\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"@di-code/builtins\";\n"]}
@@ -1,17 +1,2 @@
1
- import type { AgentTool } from "@di-code/agent";
2
- import { type Static, type ToolResultContent, Type } from "@di-code/ai";
3
- export declare const writeParameters: Type.TObject<{
4
- path: Type.TString;
5
- content: Type.TString;
6
- }>;
7
- export type WriteParameters = Static<typeof writeParameters>;
8
- export interface WriteOperations {
9
- mkdir(directory: string): Promise<void>;
10
- writeFile(filePath: string, content: string): Promise<void>;
11
- }
12
- export interface WriteToolOptions {
13
- readonly operations?: WriteOperations;
14
- }
15
- export type WriteTool = AgentTool<typeof writeParameters, ToolResultContent[]>;
16
- export declare function createWriteTool(allowedRoot: string, options?: WriteToolOptions): WriteTool;
1
+ export * from "@di-code/builtins";
17
2
  //# sourceMappingURL=write.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAIxE,eAAO,MAAM,eAAe;;;EAG1B,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE7D,MAAM,WAAW,eAAe;IAC/B,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,eAAe,CAAC;CACtC;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,eAAe,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAe/E,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAwB9F"}
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1,45 +1,2 @@
1
- import { mkdir as fsMkdir, writeFile as fsWriteFile } from "node:fs/promises";
2
- import { dirname } from "node:path";
3
- import { Type } from "@di-code/ai";
4
- import { withFileMutationQueue } from "./file-mutation-queue.js";
5
- import { resolveAllowedMutationPath } from "./path-boundary.js";
6
- export const writeParameters = Type.Object({
7
- path: Type.String({ minLength: 1 }),
8
- content: Type.String(),
9
- });
10
- const defaultWriteOperations = {
11
- async mkdir(directory) {
12
- await fsMkdir(directory, { recursive: true });
13
- },
14
- async writeFile(filePath, content) {
15
- await fsWriteFile(filePath, content, "utf8");
16
- },
17
- };
18
- function throwIfAborted(signal) {
19
- if (signal?.aborted)
20
- throw new Error("Operation aborted");
21
- }
22
- export function createWriteTool(allowedRoot, options = {}) {
23
- const operations = options.operations ?? defaultWriteOperations;
24
- return {
25
- name: "write",
26
- description: "Create or completely overwrite a UTF-8 text file inside the allowed root.",
27
- parameters: writeParameters,
28
- async execute(_toolCallId, parameters, signal) {
29
- throwIfAborted(signal);
30
- if (parameters.path.length === 0)
31
- throw new Error("path must not be empty");
32
- const absolutePath = await resolveAllowedMutationPath(parameters.path, allowedRoot);
33
- return withFileMutationQueue(absolutePath, async () => {
34
- throwIfAborted(signal);
35
- await operations.mkdir(dirname(absolutePath));
36
- throwIfAborted(signal);
37
- await operations.writeFile(absolutePath, parameters.content);
38
- throwIfAborted(signal);
39
- const bytes = Buffer.byteLength(parameters.content, "utf8");
40
- return [{ type: "text", text: `Successfully wrote ${bytes} bytes to ${parameters.path}` }];
41
- });
42
- },
43
- };
44
- }
1
+ export * from "@di-code/builtins";
45
2
  //# sourceMappingURL=write.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAuC,IAAI,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,E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CAAC,YAAY,EAAE,KAAK,IAAI,EAAE;gBACrD,cAAc,CAAC,MAAM,CAAC,CAAC;gBACvB,MAAM,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;gBAC9C,cAAc,CAAC,MAAM,CAAC,CAAC;gBACvB,MAAM,UAAU,CAAC,SAAS,CAAC,YAAY,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;gBAC7D,cAAc,CAAC,MAAM,CAAC,CAAC;gBAEvB,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAC5D,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAsB,KAAK,aAAa,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC5F,CAAC,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { mkdir as fsMkdir, writeFile as fsWriteFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\nimport type { AgentTool } from \"@di-code/agent\";\nimport { type Static, type ToolResultContent, Type } from \"@di-code/ai\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveAllowedMutationPath } from \"./path-boundary.ts\";\n\nexport const writeParameters = Type.Object({\n\tpath: Type.String({ minLength: 1 }),\n\tcontent: Type.String(),\n});\n\nexport type WriteParameters = Static<typeof writeParameters>;\n\nexport interface WriteOperations {\n\tmkdir(directory: string): Promise<void>;\n\twriteFile(filePath: string, content: string): Promise<void>;\n}\n\nexport interface WriteToolOptions {\n\treadonly operations?: WriteOperations;\n}\n\nexport type WriteTool = AgentTool<typeof writeParameters, ToolResultContent[]>;\n\nconst defaultWriteOperations: WriteOperations = {\n\tasync mkdir(directory) {\n\t\tawait fsMkdir(directory, { recursive: true });\n\t},\n\tasync writeFile(filePath, content) {\n\t\tawait fsWriteFile(filePath, content, \"utf8\");\n\t},\n};\n\nfunction throwIfAborted(signal: AbortSignal | undefined): void {\n\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n}\n\nexport function createWriteTool(allowedRoot: string, options: WriteToolOptions = {}): WriteTool {\n\tconst operations = options.operations ?? defaultWriteOperations;\n\n\treturn {\n\t\tname: \"write\",\n\t\tdescription: \"Create or completely overwrite a UTF-8 text file inside the allowed root.\",\n\t\tparameters: writeParameters,\n\t\tasync execute(_toolCallId, parameters, signal): Promise<ToolResultContent[]> {\n\t\t\tthrowIfAborted(signal);\n\t\t\tif (parameters.path.length === 0) throw new Error(\"path must not be empty\");\n\t\t\tconst absolutePath = await resolveAllowedMutationPath(parameters.path, allowedRoot);\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tawait operations.mkdir(dirname(absolutePath));\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tawait operations.writeFile(absolutePath, parameters.content);\n\t\t\t\tthrowIfAborted(signal);\n\n\t\t\t\tconst bytes = Buffer.byteLength(parameters.content, \"utf8\");\n\t\t\t\treturn [{ type: \"text\", text: `Successfully wrote ${bytes} bytes to ${parameters.path}` }];\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"@di-code/builtins\";\n"]}
package/dist/entry.js CHANGED
@@ -1,16 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
2
  import { createInterface } from "node:readline/promises";
5
- import { ProcessTerminal } from "@di-code/tui";
3
+ import { redactSensitiveText } from "@di-code/plugin-runtime";
6
4
  import packageMetadata from "../package.json" with { type: "json" };
7
- import { runMain } from "./main.js";
8
- import { runProviderOnboarding, shouldStartProviderOnboarding } from "./provider-onboarding.js";
9
- import { loadStartupConfiguration, resolveStartupArgs, resolveStartupRuntime } from "./startup.js";
5
+ import { parseCliArgs } from "./cli.js";
6
+ import { runMinimalProfile } from "./main.js";
7
+ import { resolveStartupArgs } from "./startup.js";
8
+ import { runWebCommand } from "./web-command.js";
10
9
  async function promptProjectTrust(cwd) {
11
10
  const readline = createInterface({ input: process.stdin, output: process.stdout });
12
11
  try {
13
- const answer = await readline.question(`Trust project-local Skills, plugins, and extensions in ${cwd}? [y/N] `);
12
+ const answer = await readline.question(`Trust project-local Skills and MCP configuration in ${cwd}? [y/N] `);
14
13
  return /^(?:y|yes)$/i.test(answer.trim());
15
14
  }
16
15
  finally {
@@ -18,29 +17,32 @@ async function promptProjectTrust(cwd) {
18
17
  }
19
18
  }
20
19
  try {
21
- const configuration = await loadStartupConfiguration(process.cwd());
22
- process.exitCode = await runMain(resolveStartupArgs(process.argv.slice(2)), {
23
- version: packageMetadata.version,
24
- createRuntime: (command) => {
25
- const isInteractiveTerminal = Boolean(process.stdin.isTTY && process.stdout.isTTY);
26
- if (shouldStartProviderOnboarding(command, isInteractiveTerminal, configuration)) {
27
- return runProviderOnboarding({
28
- configuration,
29
- terminal: new ProcessTerminal(),
30
- agentDir: join(homedir(), ".di-code"),
31
- });
32
- }
33
- return resolveStartupRuntime(configuration.environment, configuration.providers, configuration.defaults);
34
- },
35
- startupConfiguration: configuration,
36
- isInteractiveTerminal: Boolean(process.stdin.isTTY && process.stdout.isTTY),
37
- promptProjectTrust,
38
- stdout: (text) => process.stdout.write(text),
39
- stderr: (text) => process.stderr.write(text),
40
- });
20
+ const rawArgs = process.argv.slice(2);
21
+ const args = resolveStartupArgs(rawArgs);
22
+ const command = parseCliArgs(args);
23
+ if (command.kind === "web") {
24
+ process.exitCode = await runWebCommand(command);
25
+ }
26
+ else {
27
+ const isInteractiveTerminal = Boolean(process.stdin.isTTY && process.stdout.isTTY);
28
+ process.exitCode = await runMinimalProfile(args, {
29
+ version: packageMetadata.version,
30
+ stdout: (text) => process.stdout.write(text),
31
+ stderr: (text) => process.stderr.write(text),
32
+ interactive: { isInteractiveTerminal, promptProjectTrust },
33
+ onRuntimeEvent: (event) => {
34
+ if (process.env.DI_CODE_TRACE_PLUGINS === "1")
35
+ process.stderr.write(`${JSON.stringify(event)}\n`);
36
+ },
37
+ onSessionDisposed: () => {
38
+ if (process.env.DI_CODE_TRACE_PLUGINS === "1")
39
+ process.stderr.write('{"type":"session_dispose"}\n');
40
+ },
41
+ });
42
+ }
41
43
  }
42
44
  catch (cause) {
43
- const message = cause instanceof Error ? cause.message : "Unknown startup error";
45
+ const message = redactSensitiveText(cause instanceof Error ? cause.message : "Unknown startup error");
44
46
  process.stderr.write(`${message}\n`);
45
47
  process.exitCode = 1;
46
48
  }