@diffra-ai/durable 0.0.0-stage → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (411) hide show
  1. package/CHANGELOG.md +442 -0
  2. package/README.md +1153 -2
  3. package/dist/codemode/codemode.d.ts +174 -0
  4. package/dist/codemode/codemode.d.ts.map +1 -0
  5. package/dist/codemode/codemode.js +884 -0
  6. package/dist/codemode/codemode.js.map +1 -0
  7. package/dist/codemode/describe.d.ts +38 -0
  8. package/dist/codemode/describe.d.ts.map +1 -0
  9. package/dist/codemode/describe.js +127 -0
  10. package/dist/codemode/describe.js.map +1 -0
  11. package/dist/codemode/index.d.ts +3 -0
  12. package/dist/codemode/index.d.ts.map +1 -0
  13. package/dist/codemode/index.js +3 -0
  14. package/dist/codemode/index.js.map +1 -0
  15. package/dist/codemode/models.d.ts +29 -0
  16. package/dist/codemode/models.d.ts.map +1 -0
  17. package/dist/codemode/models.js +242 -0
  18. package/dist/codemode/models.js.map +1 -0
  19. package/dist/codemode/output.d.ts +43 -0
  20. package/dist/codemode/output.d.ts.map +1 -0
  21. package/dist/codemode/output.js +168 -0
  22. package/dist/codemode/output.js.map +1 -0
  23. package/dist/documents.d.ts +66 -0
  24. package/dist/documents.d.ts.map +1 -0
  25. package/dist/documents.js +98 -0
  26. package/dist/documents.js.map +1 -0
  27. package/dist/entries.d.ts +31 -0
  28. package/dist/entries.d.ts.map +1 -0
  29. package/dist/entries.js +31 -0
  30. package/dist/entries.js.map +1 -0
  31. package/dist/env/decode.d.ts +16 -0
  32. package/dist/env/decode.d.ts.map +1 -0
  33. package/dist/env/decode.js +28 -0
  34. package/dist/env/decode.js.map +1 -0
  35. package/dist/env/index.d.ts +308 -0
  36. package/dist/env/index.d.ts.map +1 -0
  37. package/dist/env/index.js +49 -0
  38. package/dist/env/index.js.map +1 -0
  39. package/dist/env/line-scan.d.ts +13 -0
  40. package/dist/env/line-scan.d.ts.map +1 -0
  41. package/dist/env/line-scan.js +147 -0
  42. package/dist/env/line-scan.js.map +1 -0
  43. package/dist/env/node-watch.d.ts +29 -0
  44. package/dist/env/node-watch.d.ts.map +1 -0
  45. package/dist/env/node-watch.js +487 -0
  46. package/dist/env/node-watch.js.map +1 -0
  47. package/dist/env/node.d.ts +56 -0
  48. package/dist/env/node.d.ts.map +1 -0
  49. package/dist/env/node.js +1185 -0
  50. package/dist/env/node.js.map +1 -0
  51. package/dist/errors.d.ts +48 -0
  52. package/dist/errors.d.ts.map +1 -0
  53. package/dist/errors.js +76 -0
  54. package/dist/errors.js.map +1 -0
  55. package/dist/harness/agent.d.ts +46 -0
  56. package/dist/harness/agent.d.ts.map +1 -0
  57. package/dist/harness/agent.js +334 -0
  58. package/dist/harness/agent.js.map +1 -0
  59. package/dist/harness/compaction.d.ts +68 -0
  60. package/dist/harness/compaction.d.ts.map +1 -0
  61. package/dist/harness/compaction.js +431 -0
  62. package/dist/harness/compaction.js.map +1 -0
  63. package/dist/harness/context.d.ts +84 -0
  64. package/dist/harness/context.d.ts.map +1 -0
  65. package/dist/harness/context.js +301 -0
  66. package/dist/harness/context.js.map +1 -0
  67. package/dist/harness/define.d.ts +25 -0
  68. package/dist/harness/define.d.ts.map +1 -0
  69. package/dist/harness/define.js +32 -0
  70. package/dist/harness/define.js.map +1 -0
  71. package/dist/harness/generation.d.ts +117 -0
  72. package/dist/harness/generation.d.ts.map +1 -0
  73. package/dist/harness/generation.js +1098 -0
  74. package/dist/harness/generation.js.map +1 -0
  75. package/dist/harness/harness.d.ts +22 -0
  76. package/dist/harness/harness.d.ts.map +1 -0
  77. package/dist/harness/harness.js +438 -0
  78. package/dist/harness/harness.js.map +1 -0
  79. package/dist/harness/inbox.d.ts +84 -0
  80. package/dist/harness/inbox.d.ts.map +1 -0
  81. package/dist/harness/inbox.js +135 -0
  82. package/dist/harness/inbox.js.map +1 -0
  83. package/dist/harness/json.d.ts +26 -0
  84. package/dist/harness/json.d.ts.map +1 -0
  85. package/dist/harness/json.js +51 -0
  86. package/dist/harness/json.js.map +1 -0
  87. package/dist/harness/live.d.ts +285 -0
  88. package/dist/harness/live.d.ts.map +1 -0
  89. package/dist/harness/live.js +257 -0
  90. package/dist/harness/live.js.map +1 -0
  91. package/dist/harness/parks.d.ts +23 -0
  92. package/dist/harness/parks.d.ts.map +1 -0
  93. package/dist/harness/parks.js +52 -0
  94. package/dist/harness/parks.js.map +1 -0
  95. package/dist/harness/partial-changes.d.ts +54 -0
  96. package/dist/harness/partial-changes.d.ts.map +1 -0
  97. package/dist/harness/partial-changes.js +163 -0
  98. package/dist/harness/partial-changes.js.map +1 -0
  99. package/dist/harness/prompt.d.ts +27 -0
  100. package/dist/harness/prompt.d.ts.map +1 -0
  101. package/dist/harness/prompt.js +131 -0
  102. package/dist/harness/prompt.js.map +1 -0
  103. package/dist/harness/provider.d.ts +16 -0
  104. package/dist/harness/provider.d.ts.map +1 -0
  105. package/dist/harness/provider.js +33 -0
  106. package/dist/harness/provider.js.map +1 -0
  107. package/dist/harness/registry-reader.d.ts +11 -0
  108. package/dist/harness/registry-reader.d.ts.map +1 -0
  109. package/dist/harness/registry-reader.js +25 -0
  110. package/dist/harness/registry-reader.js.map +1 -0
  111. package/dist/harness/registry.d.ts +6 -0
  112. package/dist/harness/registry.d.ts.map +1 -0
  113. package/dist/harness/registry.js +101 -0
  114. package/dist/harness/registry.js.map +1 -0
  115. package/dist/harness/scheduler.d.ts +195 -0
  116. package/dist/harness/scheduler.d.ts.map +1 -0
  117. package/dist/harness/scheduler.js +3073 -0
  118. package/dist/harness/scheduler.js.map +1 -0
  119. package/dist/harness/submissions.d.ts +44 -0
  120. package/dist/harness/submissions.d.ts.map +1 -0
  121. package/dist/harness/submissions.js +265 -0
  122. package/dist/harness/submissions.js.map +1 -0
  123. package/dist/harness/task-graph.d.ts +75 -0
  124. package/dist/harness/task-graph.d.ts.map +1 -0
  125. package/dist/harness/task-graph.js +224 -0
  126. package/dist/harness/task-graph.js.map +1 -0
  127. package/dist/harness/telemetry.d.ts +307 -0
  128. package/dist/harness/telemetry.d.ts.map +1 -0
  129. package/dist/harness/telemetry.js +140 -0
  130. package/dist/harness/telemetry.js.map +1 -0
  131. package/dist/harness/tool.d.ts +106 -0
  132. package/dist/harness/tool.d.ts.map +1 -0
  133. package/dist/harness/tool.js +1182 -0
  134. package/dist/harness/tool.js.map +1 -0
  135. package/dist/harness/transcript.d.ts +72 -0
  136. package/dist/harness/transcript.d.ts.map +1 -0
  137. package/dist/harness/transcript.js +264 -0
  138. package/dist/harness/transcript.js.map +1 -0
  139. package/dist/harness/types.d.ts +1146 -0
  140. package/dist/harness/types.d.ts.map +1 -0
  141. package/dist/harness/types.js +2 -0
  142. package/dist/harness/types.js.map +1 -0
  143. package/dist/harness/usage.d.ts +19 -0
  144. package/dist/harness/usage.d.ts.map +1 -0
  145. package/dist/harness/usage.js +57 -0
  146. package/dist/harness/usage.js.map +1 -0
  147. package/dist/harness/util.d.ts +25 -0
  148. package/dist/harness/util.d.ts.map +1 -0
  149. package/dist/harness/util.js +76 -0
  150. package/dist/harness/util.js.map +1 -0
  151. package/dist/harness/view.d.ts +69 -0
  152. package/dist/harness/view.d.ts.map +1 -0
  153. package/dist/harness/view.js +265 -0
  154. package/dist/harness/view.js.map +1 -0
  155. package/dist/ids.d.ts +6 -0
  156. package/dist/ids.d.ts.map +1 -0
  157. package/dist/ids.js +9 -0
  158. package/dist/ids.js.map +1 -0
  159. package/dist/images/cloudflare.d.ts +4 -0
  160. package/dist/images/cloudflare.d.ts.map +1 -0
  161. package/dist/images/cloudflare.js +9 -0
  162. package/dist/images/cloudflare.js.map +1 -0
  163. package/dist/images/exif.d.ts +3 -0
  164. package/dist/images/exif.d.ts.map +1 -0
  165. package/dist/images/exif.js +71 -0
  166. package/dist/images/exif.js.map +1 -0
  167. package/dist/images/fit.d.ts +41 -0
  168. package/dist/images/fit.d.ts.map +1 -0
  169. package/dist/images/fit.js +108 -0
  170. package/dist/images/fit.js.map +1 -0
  171. package/dist/images/index.d.ts +18 -0
  172. package/dist/images/index.d.ts.map +1 -0
  173. package/dist/images/index.js +125 -0
  174. package/dist/images/index.js.map +1 -0
  175. package/dist/images/node-worker.d.ts +19 -0
  176. package/dist/images/node-worker.d.ts.map +1 -0
  177. package/dist/images/node-worker.js +17 -0
  178. package/dist/images/node-worker.js.map +1 -0
  179. package/dist/images/node.d.ts +21 -0
  180. package/dist/images/node.d.ts.map +1 -0
  181. package/dist/images/node.js +121 -0
  182. package/dist/images/node.js.map +1 -0
  183. package/dist/index.d.ts +29 -0
  184. package/dist/index.d.ts.map +1 -0
  185. package/dist/index.js +23 -0
  186. package/dist/index.js.map +1 -0
  187. package/dist/search.d.ts +29 -0
  188. package/dist/search.d.ts.map +1 -0
  189. package/dist/search.js +148 -0
  190. package/dist/search.js.map +1 -0
  191. package/dist/session/cached-storage.d.ts +72 -0
  192. package/dist/session/cached-storage.d.ts.map +1 -0
  193. package/dist/session/cached-storage.js +269 -0
  194. package/dist/session/cached-storage.js.map +1 -0
  195. package/dist/session/conversation-tails.d.ts +33 -0
  196. package/dist/session/conversation-tails.d.ts.map +1 -0
  197. package/dist/session/conversation-tails.js +101 -0
  198. package/dist/session/conversation-tails.js.map +1 -0
  199. package/dist/session/forks.d.ts +10 -0
  200. package/dist/session/forks.d.ts.map +1 -0
  201. package/dist/session/forks.js +42 -0
  202. package/dist/session/forks.js.map +1 -0
  203. package/dist/session/keys.d.ts +69 -0
  204. package/dist/session/keys.d.ts.map +1 -0
  205. package/dist/session/keys.js +161 -0
  206. package/dist/session/keys.js.map +1 -0
  207. package/dist/session/session.d.ts +287 -0
  208. package/dist/session/session.d.ts.map +1 -0
  209. package/dist/session/session.js +1701 -0
  210. package/dist/session/session.js.map +1 -0
  211. package/dist/session/transaction.d.ts +205 -0
  212. package/dist/session/transaction.d.ts.map +1 -0
  213. package/dist/session/transaction.js +1059 -0
  214. package/dist/session/transaction.js.map +1 -0
  215. package/dist/session/writer.d.ts +74 -0
  216. package/dist/session/writer.d.ts.map +1 -0
  217. package/dist/session/writer.js +294 -0
  218. package/dist/session/writer.js.map +1 -0
  219. package/dist/signals.d.ts +180 -0
  220. package/dist/signals.d.ts.map +1 -0
  221. package/dist/signals.js +236 -0
  222. package/dist/signals.js.map +1 -0
  223. package/dist/storage/indexeddb.d.ts +69 -0
  224. package/dist/storage/indexeddb.d.ts.map +1 -0
  225. package/dist/storage/indexeddb.js +883 -0
  226. package/dist/storage/indexeddb.js.map +1 -0
  227. package/dist/storage/jsonl/index.d.ts +2 -0
  228. package/dist/storage/jsonl/index.d.ts.map +1 -0
  229. package/dist/storage/jsonl/index.js +2 -0
  230. package/dist/storage/jsonl/index.js.map +1 -0
  231. package/dist/storage/jsonl/node.d.ts +6 -0
  232. package/dist/storage/jsonl/node.d.ts.map +1 -0
  233. package/dist/storage/jsonl/node.js +8 -0
  234. package/dist/storage/jsonl/node.js.map +1 -0
  235. package/dist/storage/jsonl/storage.d.ts +206 -0
  236. package/dist/storage/jsonl/storage.d.ts.map +1 -0
  237. package/dist/storage/jsonl/storage.js +799 -0
  238. package/dist/storage/jsonl/storage.js.map +1 -0
  239. package/dist/storage/memory.d.ts +68 -0
  240. package/dist/storage/memory.d.ts.map +1 -0
  241. package/dist/storage/memory.js +761 -0
  242. package/dist/storage/memory.js.map +1 -0
  243. package/dist/storage/scan.d.ts +18 -0
  244. package/dist/storage/scan.d.ts.map +1 -0
  245. package/dist/storage/scan.js +29 -0
  246. package/dist/storage/scan.js.map +1 -0
  247. package/dist/storage/sqlite/cloudflare.d.ts +9 -0
  248. package/dist/storage/sqlite/cloudflare.d.ts.map +1 -0
  249. package/dist/storage/sqlite/cloudflare.js +11 -0
  250. package/dist/storage/sqlite/cloudflare.js.map +1 -0
  251. package/dist/storage/sqlite/commit.d.ts +52 -0
  252. package/dist/storage/sqlite/commit.d.ts.map +1 -0
  253. package/dist/storage/sqlite/commit.js +371 -0
  254. package/dist/storage/sqlite/commit.js.map +1 -0
  255. package/dist/storage/sqlite/database.d.ts +2 -0
  256. package/dist/storage/sqlite/database.d.ts.map +1 -0
  257. package/dist/storage/sqlite/database.js +2 -0
  258. package/dist/storage/sqlite/database.js.map +1 -0
  259. package/dist/storage/sqlite/index.d.ts +4 -0
  260. package/dist/storage/sqlite/index.d.ts.map +1 -0
  261. package/dist/storage/sqlite/index.js +3 -0
  262. package/dist/storage/sqlite/index.js.map +1 -0
  263. package/dist/storage/sqlite/migrations.d.ts +12 -0
  264. package/dist/storage/sqlite/migrations.d.ts.map +1 -0
  265. package/dist/storage/sqlite/migrations.js +121 -0
  266. package/dist/storage/sqlite/migrations.js.map +1 -0
  267. package/dist/storage/sqlite/node.d.ts +8 -0
  268. package/dist/storage/sqlite/node.d.ts.map +1 -0
  269. package/dist/storage/sqlite/node.js +12 -0
  270. package/dist/storage/sqlite/node.js.map +1 -0
  271. package/dist/storage/sqlite/rows.d.ts +33 -0
  272. package/dist/storage/sqlite/rows.d.ts.map +1 -0
  273. package/dist/storage/sqlite/rows.js +53 -0
  274. package/dist/storage/sqlite/rows.js.map +1 -0
  275. package/dist/storage/sqlite/schema.d.ts +45 -0
  276. package/dist/storage/sqlite/schema.d.ts.map +1 -0
  277. package/dist/storage/sqlite/schema.js +50 -0
  278. package/dist/storage/sqlite/schema.js.map +1 -0
  279. package/dist/storage/sqlite/statements.d.ts +13 -0
  280. package/dist/storage/sqlite/statements.d.ts.map +1 -0
  281. package/dist/storage/sqlite/statements.js +88 -0
  282. package/dist/storage/sqlite/statements.js.map +1 -0
  283. package/dist/storage/sqlite/storage.d.ts +86 -0
  284. package/dist/storage/sqlite/storage.d.ts.map +1 -0
  285. package/dist/storage/sqlite/storage.js +534 -0
  286. package/dist/storage/sqlite/storage.js.map +1 -0
  287. package/dist/storage/store/commit.d.ts +33 -0
  288. package/dist/storage/store/commit.d.ts.map +1 -0
  289. package/dist/storage/store/commit.js +286 -0
  290. package/dist/storage/store/commit.js.map +1 -0
  291. package/dist/storage/store/documents.d.ts +43 -0
  292. package/dist/storage/store/documents.d.ts.map +1 -0
  293. package/dist/storage/store/documents.js +102 -0
  294. package/dist/storage/store/documents.js.map +1 -0
  295. package/dist/storage/store/index.d.ts +2 -0
  296. package/dist/storage/store/index.d.ts.map +1 -0
  297. package/dist/storage/store/index.js +2 -0
  298. package/dist/storage/store/index.js.map +1 -0
  299. package/dist/storage/store/queries.d.ts +49 -0
  300. package/dist/storage/store/queries.d.ts.map +1 -0
  301. package/dist/storage/store/queries.js +93 -0
  302. package/dist/storage/store/queries.js.map +1 -0
  303. package/dist/storage/store/storage.d.ts +60 -0
  304. package/dist/storage/store/storage.d.ts.map +1 -0
  305. package/dist/storage/store/storage.js +438 -0
  306. package/dist/storage/store/storage.js.map +1 -0
  307. package/dist/storage/store/tables.d.ts +54 -0
  308. package/dist/storage/store/tables.d.ts.map +1 -0
  309. package/dist/storage/store/tables.js +108 -0
  310. package/dist/storage/store/tables.js.map +1 -0
  311. package/dist/tasks.d.ts +6 -0
  312. package/dist/tasks.d.ts.map +1 -0
  313. package/dist/tasks.js +5 -0
  314. package/dist/tasks.js.map +1 -0
  315. package/dist/testing/assertions.d.ts +5 -0
  316. package/dist/testing/assertions.d.ts.map +1 -0
  317. package/dist/testing/assertions.js +25 -0
  318. package/dist/testing/assertions.js.map +1 -0
  319. package/dist/testing/commit-writes.d.ts +5 -0
  320. package/dist/testing/commit-writes.d.ts.map +1 -0
  321. package/dist/testing/commit-writes.js +12 -0
  322. package/dist/testing/commit-writes.js.map +1 -0
  323. package/dist/testing/env-conformance.d.ts +7 -0
  324. package/dist/testing/env-conformance.d.ts.map +1 -0
  325. package/dist/testing/env-conformance.js +531 -0
  326. package/dist/testing/env-conformance.js.map +1 -0
  327. package/dist/testing/index.d.ts +8 -0
  328. package/dist/testing/index.d.ts.map +1 -0
  329. package/dist/testing/index.js +7 -0
  330. package/dist/testing/index.js.map +1 -0
  331. package/dist/testing/runner.d.ts +12 -0
  332. package/dist/testing/runner.d.ts.map +1 -0
  333. package/dist/testing/runner.js +23 -0
  334. package/dist/testing/runner.js.map +1 -0
  335. package/dist/testing/storage-benchmark.d.ts +41 -0
  336. package/dist/testing/storage-benchmark.d.ts.map +1 -0
  337. package/dist/testing/storage-benchmark.js +351 -0
  338. package/dist/testing/storage-benchmark.js.map +1 -0
  339. package/dist/testing/storage-conformance.d.ts +4 -0
  340. package/dist/testing/storage-conformance.d.ts.map +1 -0
  341. package/dist/testing/storage-conformance.js +1554 -0
  342. package/dist/testing/storage-conformance.js.map +1 -0
  343. package/dist/testing/types.d.ts +39 -0
  344. package/dist/testing/types.d.ts.map +1 -0
  345. package/dist/testing/types.js +2 -0
  346. package/dist/testing/types.js.map +1 -0
  347. package/dist/timers.d.ts +21 -0
  348. package/dist/timers.d.ts.map +1 -0
  349. package/dist/timers.js +72 -0
  350. package/dist/timers.js.map +1 -0
  351. package/dist/tool-search/index.d.ts +2 -0
  352. package/dist/tool-search/index.d.ts.map +1 -0
  353. package/dist/tool-search/index.js +2 -0
  354. package/dist/tool-search/index.js.map +1 -0
  355. package/dist/tool-search/tool-search.d.ts +17 -0
  356. package/dist/tool-search/tool-search.d.ts.map +1 -0
  357. package/dist/tool-search/tool-search.js +96 -0
  358. package/dist/tool-search/tool-search.js.map +1 -0
  359. package/dist/tools/bash.d.ts +55 -0
  360. package/dist/tools/bash.d.ts.map +1 -0
  361. package/dist/tools/bash.js +139 -0
  362. package/dist/tools/bash.js.map +1 -0
  363. package/dist/tools/edit-diff.d.ts +89 -0
  364. package/dist/tools/edit-diff.d.ts.map +1 -0
  365. package/dist/tools/edit-diff.js +386 -0
  366. package/dist/tools/edit-diff.js.map +1 -0
  367. package/dist/tools/edit.d.ts +18 -0
  368. package/dist/tools/edit.d.ts.map +1 -0
  369. package/dist/tools/edit.js +117 -0
  370. package/dist/tools/edit.js.map +1 -0
  371. package/dist/tools/env.d.ts +5 -0
  372. package/dist/tools/env.d.ts.map +1 -0
  373. package/dist/tools/env.js +7 -0
  374. package/dist/tools/env.js.map +1 -0
  375. package/dist/tools/file-mutation-queue.d.ts +9 -0
  376. package/dist/tools/file-mutation-queue.d.ts.map +1 -0
  377. package/dist/tools/file-mutation-queue.js +52 -0
  378. package/dist/tools/file-mutation-queue.js.map +1 -0
  379. package/dist/tools/image-processor.d.ts +57 -0
  380. package/dist/tools/image-processor.d.ts.map +1 -0
  381. package/dist/tools/image-processor.js +49 -0
  382. package/dist/tools/image-processor.js.map +1 -0
  383. package/dist/tools/image.d.ts +20 -0
  384. package/dist/tools/image.d.ts.map +1 -0
  385. package/dist/tools/image.js +178 -0
  386. package/dist/tools/image.js.map +1 -0
  387. package/dist/tools/index.d.ts +46 -0
  388. package/dist/tools/index.d.ts.map +1 -0
  389. package/dist/tools/index.js +23 -0
  390. package/dist/tools/index.js.map +1 -0
  391. package/dist/tools/path-utils.d.ts +5 -0
  392. package/dist/tools/path-utils.d.ts.map +1 -0
  393. package/dist/tools/path-utils.js +26 -0
  394. package/dist/tools/path-utils.js.map +1 -0
  395. package/dist/tools/read.d.ts +30 -0
  396. package/dist/tools/read.d.ts.map +1 -0
  397. package/dist/tools/read.js +239 -0
  398. package/dist/tools/read.js.map +1 -0
  399. package/dist/tools/write.d.ts +10 -0
  400. package/dist/tools/write.d.ts.map +1 -0
  401. package/dist/tools/write.js +31 -0
  402. package/dist/tools/write.js.map +1 -0
  403. package/dist/truncate.d.ts +65 -0
  404. package/dist/truncate.d.ts.map +1 -0
  405. package/dist/truncate.js +124 -0
  406. package/dist/truncate.js.map +1 -0
  407. package/dist/types.d.ts +1244 -0
  408. package/dist/types.d.ts.map +1 -0
  409. package/dist/types.js +3 -0
  410. package/dist/types.js.map +1 -0
  411. package/package.json +179 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool-search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,yBAAyB,EACzB,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,GAErB,MAAM,kBAAkB,CAAC","sourcesContent":["export {\n\tcreateToolSearchExtension,\n\tcreateToolSearchTool,\n\tDEFAULT_TOOL_SEARCH_LIMIT,\n\tTOOL_SEARCH_TOOL_NAME,\n\ttype ToolSearchToolDetails,\n} from \"./tool-search.ts\";\n"]}
@@ -0,0 +1,17 @@
1
+ import type { ToolRegistration } from "../harness/types.ts";
2
+ export declare const TOOL_SEARCH_TOOL_NAME = "tool_search";
3
+ export declare const DEFAULT_TOOL_SEARCH_LIMIT = 8;
4
+ /** `tool_search` result details: the tools it loaded. */
5
+ export type ToolSearchToolDetails = {
6
+ loaded: string[];
7
+ };
8
+ export declare function createToolSearchTool(): ToolRegistration<import("@diffra-ai/schema").Schema<{
9
+ query: string;
10
+ limit?: number | undefined;
11
+ }>, import("@diffra-ai/chord/json").JsonValue, import("@diffra-ai/chord/json").JsonValue>;
12
+ /** The `tool_search` extension: install it and select it where the model should find deferred tools. */
13
+ export declare function createToolSearchExtension(): import("../harness/types.ts").Extension<ToolRegistration<import("@diffra-ai/schema").Schema<{
14
+ query: string;
15
+ limit?: number | undefined;
16
+ }>, import("@diffra-ai/chord/json").JsonValue, import("@diffra-ai/chord/json").JsonValue>>;
17
+ //# sourceMappingURL=tool-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-search.d.ts","sourceRoot":"","sources":["../../src/tool-search/tool-search.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AACnD,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAa3C,yDAAyD;AACzD,MAAM,MAAM,qBAAqB,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAyCzD,wBAAgB,oBAAoB;;;0FAgCnC;AAED,wGAAwG;AACxG,wBAAgB,yBAAyB;;;2FAExC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The `tool_search` tool, a copy of the coding agent's: the model searches the deferred tools it is not offered yet,
3
+ * and the matches are loaded with `control.addTools`, so the next request offers them. Loading writes the
4
+ * conversation's `modelTools` (its `add`), so loaded tools stay offered on that branch, also after a compaction.
5
+ */
6
+ import { resolveSchemaRef } from "@diffra-ai/codemode/declarations";
7
+ import { num, obj, opt, str } from "@diffra-ai/schema";
8
+ import { defineExtension, defineTool } from "../harness/define.js";
9
+ import { rankDocuments } from "../search.js";
10
+ export const TOOL_SEARCH_TOOL_NAME = "tool_search";
11
+ export const DEFAULT_TOOL_SEARCH_LIMIT = 8;
12
+ /** Fixed, so it does not change while deferred tools are registered, for example as MCP servers connect. */
13
+ const TOOL_SEARCH_DESCRIPTION = `# Tool discovery\n\nSearches over deferred tool metadata with BM25 and exposes matching tools for the next model call.\n\nSome of the tools, such as tools of MCP servers, may not have been provided to you upfront, and you should use this tool (\`${TOOL_SEARCH_TOOL_NAME}\`) to search for the required tools. For MCP tool discovery, always use \`${TOOL_SEARCH_TOOL_NAME}\`.`;
14
+ const toolSearchSchema = obj({
15
+ query: str({ description: "Search query for deferred tools." }),
16
+ limit: opt(num({ description: `Maximum number of tools to return. Defaults to ${DEFAULT_TOOL_SEARCH_LIMIT}.` })),
17
+ }, { open: true });
18
+ function isObject(value) {
19
+ return typeof value === "object" && value !== null && !Array.isArray(value);
20
+ }
21
+ /**
22
+ * Schema descriptions and property names, recursively, following local `$ref`s into `root`. `seen` holds the
23
+ * subschemas already reached through a reference, so recursive and shared definitions are read once, and
24
+ * definitions no property references are not read.
25
+ */
26
+ function schemaText(schema, root, parts, seen) {
27
+ if (!isObject(schema))
28
+ return;
29
+ if (typeof schema.$ref === "string") {
30
+ const target = resolveSchemaRef(schema.$ref, root);
31
+ if (isObject(target) && !seen.has(target)) {
32
+ seen.add(target);
33
+ schemaText(target, root, parts, seen);
34
+ }
35
+ }
36
+ if (typeof schema.description === "string")
37
+ parts.push(schema.description);
38
+ if (isObject(schema.properties)) {
39
+ for (const [name, property] of Object.entries(schema.properties)) {
40
+ parts.push(name);
41
+ schemaText(property, root, parts, seen);
42
+ }
43
+ }
44
+ schemaText(schema.items, root, parts, seen);
45
+ for (const key of ["anyOf", "oneOf", "allOf"]) {
46
+ const variants = schema[key];
47
+ if (Array.isArray(variants))
48
+ for (const variant of variants)
49
+ schemaText(variant, root, parts, seen);
50
+ }
51
+ }
52
+ /** Search text of a tool: its description and its parameters' names and descriptions; the ranker reads the name. */
53
+ function searchText(tool) {
54
+ const parts = [tool.description];
55
+ schemaText(tool.parameters, tool.parameters, parts, new Set([tool.parameters]));
56
+ return parts.filter((part) => part.trim() !== "").join(" ");
57
+ }
58
+ export function createToolSearchTool() {
59
+ return defineTool({
60
+ name: TOOL_SEARCH_TOOL_NAME,
61
+ description: TOOL_SEARCH_DESCRIPTION,
62
+ parameters: toolSearchSchema,
63
+ // Searching changes what the model is offered; scripts have their own `searchTools()`.
64
+ callers: ["model"],
65
+ replay: "safe",
66
+ async execute({ query, limit }, api, context) {
67
+ if (query.trim() === "")
68
+ throw new Error("query must not be empty");
69
+ const max = limit ?? DEFAULT_TOOL_SEARCH_LIMIT;
70
+ if (!Number.isInteger(max) || max <= 0)
71
+ throw new Error("limit must be a positive integer");
72
+ const candidates = (await api.agent(context)).deferred;
73
+ const documents = candidates.map((tool) => ({ name: tool.name, text: searchText(tool) }));
74
+ const loaded = rankDocuments(query, documents, max);
75
+ const text = loaded.length === 0
76
+ ? "No matching tools found."
77
+ : `Loaded ${loaded.length} tool${loaded.length === 1 ? "" : "s"}. They are available from your next call:\n${loaded
78
+ .map((name) => {
79
+ const description = candidates.find((tool) => tool.name === name)?.description ?? "";
80
+ return `- ${name}: ${description.trim().split(/\r?\n/)[0]}`;
81
+ })
82
+ .join("\n")}`;
83
+ const details = { loaded };
84
+ return {
85
+ output: [{ type: "text", text }],
86
+ details,
87
+ ...(loaded.length === 0 ? {} : { control: { addTools: loaded } }),
88
+ };
89
+ },
90
+ });
91
+ }
92
+ /** The `tool_search` extension: install it and select it where the model should find deferred tools. */
93
+ export function createToolSearchExtension() {
94
+ return defineExtension({ name: "tool-search", tools: [createToolSearchTool()] });
95
+ }
96
+ //# sourceMappingURL=tool-search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-search.js","sourceRoot":"","sources":["../../src/tool-search/tool-search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC;AACnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,4GAA4G;AAC5G,MAAM,uBAAuB,GAAG,yPAAyP,qBAAqB,8EAA8E,qBAAqB,KAAK,CAAC;AAEvZ,MAAM,gBAAgB,GAAG,GAAG,CAC3B;IACC,KAAK,EAAE,GAAG,CAAC,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;IAC/D,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,kDAAkD,yBAAyB,GAAG,EAAE,CAAC,CAAC;CAChH,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACd,CAAC;AAKF,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,MAAe,EAAE,IAAa,EAAE,KAAe,EAAE,IAAkB;IACtF,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO;IAC9B,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ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aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;YACpD,MAAM,IAAI,GACT,MAAM,CAAC,MAAM,KAAK,CAAC;gBAClB,CAAC,CAAC,0BAA0B;gBAC5B,CAAC,CAAC,UAAU,MAAM,CAAC,MAAM,QAAQ,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,8CAA8C,MAAM;qBAChH,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;oBACb,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,WAAW,IAAI,EAAE,CAAC;oBACrF,OAAO,KAAK,IAAI,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC7D,CAAC,CAAC;qBACD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAClB,MAAM,OAAO,GAA0B,EAAE,MAAM,EAAE,CAAC;YAClD,OAAO;gBACN,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;gBAChC,OAAO;gBACP,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC;aACjE,CAAC;QACH,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,yBAAyB;IACxC,OAAO,eAAe,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,oBAAoB,EAAE,CAAC,EAAE,CAAC,CAAC;AAClF,CAAC","sourcesContent":["/**\n * The `tool_search` tool, a copy of the coding agent's: the model searches the deferred tools it is not offered yet,\n * and the matches are loaded with `control.addTools`, so the next request offers them. Loading writes the\n * conversation's `modelTools` (its `add`), so loaded tools stay offered on that branch, also after a compaction.\n */\nimport { resolveSchemaRef } from \"@diffra-ai/codemode/declarations\";\nimport { num, obj, opt, str } from \"@diffra-ai/schema\";\nimport { defineExtension, defineTool } from \"../harness/define.ts\";\nimport type { ToolRegistration } from \"../harness/types.ts\";\nimport { rankDocuments } from \"../search.ts\";\n\nexport const TOOL_SEARCH_TOOL_NAME = \"tool_search\";\nexport const DEFAULT_TOOL_SEARCH_LIMIT = 8;\n\n/** Fixed, so it does not change while deferred tools are registered, for example as MCP servers connect. */\nconst TOOL_SEARCH_DESCRIPTION = `# Tool discovery\\n\\nSearches over deferred tool metadata with BM25 and exposes matching tools for the next model call.\\n\\nSome of the tools, such as tools of MCP servers, may not have been provided to you upfront, and you should use this tool (\\`${TOOL_SEARCH_TOOL_NAME}\\`) to search for the required tools. For MCP tool discovery, always use \\`${TOOL_SEARCH_TOOL_NAME}\\`.`;\n\nconst toolSearchSchema = obj(\n\t{\n\t\tquery: str({ description: \"Search query for deferred tools.\" }),\n\t\tlimit: opt(num({ description: `Maximum number of tools to return. Defaults to ${DEFAULT_TOOL_SEARCH_LIMIT}.` })),\n\t},\n\t{ open: true },\n);\n\n/** `tool_search` result details: the tools it loaded. */\nexport type ToolSearchToolDetails = { loaded: string[] };\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Schema descriptions and property names, recursively, following local `$ref`s into `root`. `seen` holds the\n * subschemas already reached through a reference, so recursive and shared definitions are read once, and\n * definitions no property references are not read.\n */\nfunction schemaText(schema: unknown, root: unknown, parts: string[], seen: Set<unknown>): void {\n\tif (!isObject(schema)) return;\n\tif (typeof schema.$ref === \"string\") {\n\t\tconst target = resolveSchemaRef(schema.$ref, root);\n\t\tif (isObject(target) && !seen.has(target)) {\n\t\t\tseen.add(target);\n\t\t\tschemaText(target, root, parts, seen);\n\t\t}\n\t}\n\tif (typeof schema.description === \"string\") parts.push(schema.description);\n\tif (isObject(schema.properties)) {\n\t\tfor (const [name, property] of Object.entries(schema.properties)) {\n\t\t\tparts.push(name);\n\t\t\tschemaText(property, root, parts, seen);\n\t\t}\n\t}\n\tschemaText(schema.items, root, parts, seen);\n\tfor (const key of [\"anyOf\", \"oneOf\", \"allOf\"]) {\n\t\tconst variants = schema[key];\n\t\tif (Array.isArray(variants)) for (const variant of variants) schemaText(variant, root, parts, seen);\n\t}\n}\n\n/** Search text of a tool: its description and its parameters' names and descriptions; the ranker reads the name. */\nfunction searchText(tool: ToolRegistration): string {\n\tconst parts = [tool.description];\n\tschemaText(tool.parameters, tool.parameters, parts, new Set([tool.parameters]));\n\treturn parts.filter((part) => part.trim() !== \"\").join(\" \");\n}\n\nexport function createToolSearchTool() {\n\treturn defineTool({\n\t\tname: TOOL_SEARCH_TOOL_NAME,\n\t\tdescription: TOOL_SEARCH_DESCRIPTION,\n\t\tparameters: toolSearchSchema,\n\t\t// Searching changes what the model is offered; scripts have their own `searchTools()`.\n\t\tcallers: [\"model\"],\n\t\treplay: \"safe\",\n\t\tasync execute({ query, limit }, api, context) {\n\t\t\tif (query.trim() === \"\") throw new Error(\"query must not be empty\");\n\t\t\tconst max = limit ?? DEFAULT_TOOL_SEARCH_LIMIT;\n\t\t\tif (!Number.isInteger(max) || max <= 0) throw new Error(\"limit must be a positive integer\");\n\t\t\tconst candidates = (await api.agent(context)).deferred;\n\t\t\tconst documents = candidates.map((tool) => ({ name: tool.name, text: searchText(tool) }));\n\t\t\tconst loaded = rankDocuments(query, documents, max);\n\t\t\tconst text =\n\t\t\t\tloaded.length === 0\n\t\t\t\t\t? \"No matching tools found.\"\n\t\t\t\t\t: `Loaded ${loaded.length} tool${loaded.length === 1 ? \"\" : \"s\"}. They are available from your next call:\\n${loaded\n\t\t\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\t\t\tconst description = candidates.find((tool) => tool.name === name)?.description ?? \"\";\n\t\t\t\t\t\t\t\treturn `- ${name}: ${description.trim().split(/\\r?\\n/)[0]}`;\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join(\"\\n\")}`;\n\t\t\tconst details: ToolSearchToolDetails = { loaded };\n\t\t\treturn {\n\t\t\t\toutput: [{ type: \"text\", text }],\n\t\t\t\tdetails,\n\t\t\t\t...(loaded.length === 0 ? {} : { control: { addTools: loaded } }),\n\t\t\t};\n\t\t},\n\t});\n}\n\n/** The `tool_search` extension: install it and select it where the model should find deferred tools. */\nexport function createToolSearchExtension() {\n\treturn defineExtension({ name: \"tool-search\", tools: [createToolSearchTool()] });\n}\n"]}
@@ -0,0 +1,55 @@
1
+ import type { Context } from "@diffra-ai/chord/context";
2
+ import { type Static } from "@diffra-ai/schema";
3
+ import type { ToolExecutionApi, ToolRegistration } from "../harness/types.ts";
4
+ declare const bashSchema: import("@diffra-ai/schema").Schema<{
5
+ command: string;
6
+ timeout?: number | undefined;
7
+ }>;
8
+ declare const powershellSchema: import("@diffra-ai/schema").Schema<{
9
+ command: string;
10
+ timeout?: number | undefined;
11
+ }>;
12
+ /** What a program that calls `bash` or `powershell` receives. */
13
+ declare const shellStructuredOutputSchema: import("@diffra-ai/schema").Schema<{
14
+ output: string;
15
+ truncated: boolean;
16
+ fullOutputPath?: string | undefined;
17
+ exitCode: number;
18
+ }>;
19
+ export type BashToolInput = Static<typeof bashSchema>;
20
+ export type PowerShellToolInput = Static<typeof powershellSchema>;
21
+ export type ShellStructuredOutput = Static<typeof shellStructuredOutputSchema>;
22
+ /** A command about to run, which `prepare` may change: the script, its working directory and environment. */
23
+ export interface BashExecution {
24
+ command: string;
25
+ cwd: string;
26
+ env: Record<string, string>;
27
+ inheritEnv: boolean;
28
+ }
29
+ export type BashPrepare = (execution: BashExecution, api: ToolExecutionApi, context: Context) => void | Promise<void>;
30
+ export interface BashToolOptions {
31
+ commandPrefix?: string;
32
+ prepare?: BashPrepare;
33
+ }
34
+ export interface PowerShellToolOptions {
35
+ /** Lines run before each command. */
36
+ commandPrefix?: string;
37
+ prepare?: BashPrepare;
38
+ /** PowerShell programs to try in order; default `pwsh`, then `powershell`. A program that cannot start is skipped. */
39
+ programs?: readonly string[];
40
+ }
41
+ /**
42
+ * Runs a command through the environment's shell. Its output streams to `api.output()`, where the Harness keeps the
43
+ * tail within the default limits; the result content is that retained output. The retained window goes to the
44
+ * environment, which may omit output outside it and report how much it omitted, so dropped counts stay exact. Output
45
+ * beyond the limits is spilled to a file whose path is reported as a diagnostic. A nonzero exit is an error result with
46
+ * the exit code; a timeout throws, which makes an error result that still carries the output and diagnostics.
47
+ */
48
+ export declare function createBashTool(options?: BashToolOptions): ToolRegistration<typeof bashSchema>;
49
+ /**
50
+ * Runs a PowerShell command, like `bash` but through PowerShell instead of the environment's shell: `pwsh` (PowerShell
51
+ * 7), else Windows PowerShell, started directly with the command as an argument, so no other shell parses it.
52
+ */
53
+ export declare function createPowerShellTool(options?: PowerShellToolOptions): ToolRegistration<typeof powershellSchema>;
54
+ export {};
55
+ //# sourceMappingURL=bash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../src/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAuB,KAAK,MAAM,EAAO,MAAM,mBAAmB,CAAC;AAE1E,OAAO,KAAK,EAAE,gBAAgB,EAAuB,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAOnG,QAAA,MAAM,UAAU;;;EAMf,CAAC;AAEF,QAAA,MAAM,gBAAgB;;;EAMrB,CAAC;AAEF,iEAAiE;AACjE,QAAA,MAAM,2BAA2B;;;;;EAQhC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAClE,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAE/E,6GAA6G;AAC7G,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtH,MAAM,WAAW,eAAe;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACrC,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,sHAAsH;IACtH,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAqFD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,gBAAgB,CAAC,OAAO,UAAU,CAAC,CAa7F;AAMD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,gBAAgB,CAAC,OAAO,gBAAgB,CAAC,CAgB/G"}
@@ -0,0 +1,139 @@
1
+ import { bool, num, obj, opt, str } from "@diffra-ai/schema";
2
+ import { defineTool } from "../harness/define.js";
3
+ import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES } from "../truncate.js";
4
+ import { requireEnv } from "./env.js";
5
+ const MAX_TIMEOUT_SECONDS = 2_147_483_647 / 1000;
6
+ // Open objects, as the tools accepted extra arguments when their schemas were TypeBox's.
7
+ const bashSchema = obj({
8
+ command: str({ description: "Bash command to execute" }),
9
+ timeout: opt(num({ description: "Timeout in seconds (optional, no default timeout)" })),
10
+ }, { open: true });
11
+ const powershellSchema = obj({
12
+ command: str({ description: "PowerShell command to execute" }),
13
+ timeout: opt(num({ description: "Timeout in seconds (optional, no default timeout)" })),
14
+ }, { open: true });
15
+ /** What a program that calls `bash` or `powershell` receives. */
16
+ const shellStructuredOutputSchema = obj({
17
+ output: str({ description: "Combined stdout and stderr: the retained tail, as the model sees it" }),
18
+ truncated: bool({ description: "Whether earlier output was dropped" }),
19
+ fullOutputPath: opt(str({ description: "File with the complete output, when it was spilled" })),
20
+ exitCode: num(),
21
+ }, { open: true });
22
+ function validateTimeout(timeout) {
23
+ if (timeout === undefined)
24
+ return;
25
+ if (!Number.isFinite(timeout) || timeout <= 0) {
26
+ throw new Error("Invalid timeout: must be a finite number of seconds");
27
+ }
28
+ if (timeout > MAX_TIMEOUT_SECONDS) {
29
+ throw new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);
30
+ }
31
+ }
32
+ /** The execution of one call: the command with its prefix, in the environment's working directory, then `prepare`. */
33
+ async function prepareExecution(command, options, api, context) {
34
+ const execution = {
35
+ command: options?.commandPrefix ? `${options.commandPrefix}\n${command}` : command,
36
+ cwd: requireEnv(api).cwd,
37
+ env: {},
38
+ inheritEnv: true,
39
+ };
40
+ await options?.prepare?.(execution, api, context);
41
+ return execution;
42
+ }
43
+ /**
44
+ * Run each command form in turn until one starts, streaming output to `api.output()` within the retained window, and
45
+ * turn the result into the tool's result: a spill diagnostic, an error result for a nonzero exit, and a thrown error for
46
+ * a failure such as a timeout. The structured output repeats the retained output with the exit code.
47
+ */
48
+ async function runCommand(commands, execution, timeout, api, context) {
49
+ const env = requireEnv(api);
50
+ let result;
51
+ for (const command of commands) {
52
+ result = await env.exec(command, {
53
+ cwd: execution.cwd,
54
+ env: execution.env,
55
+ inheritEnv: execution.inheritEnv,
56
+ ...(timeout === undefined ? {} : { timeout }),
57
+ onOutput: (text, _context, info) => api.output(text, info.skipped),
58
+ spill: { afterBytes: DEFAULT_MAX_BYTES, afterLines: DEFAULT_MAX_LINES },
59
+ // An environment may then omit output outside the retained tail and report the omission.
60
+ ...(api.outputWindow === undefined ? {} : { window: api.outputWindow }),
61
+ }, context);
62
+ // A program that could not start produced no output; the next form may.
63
+ if (result.ok || result.error.code !== "spawn_error")
64
+ break;
65
+ }
66
+ if (result === undefined)
67
+ throw new Error("No command to run");
68
+ const spillPath = result.ok ? result.value.spillPath : result.error.spillPath;
69
+ if (spillPath !== undefined) {
70
+ api.diagnostic({ severity: "info", code: "full_output", message: `Full output: ${spillPath}` });
71
+ }
72
+ if (!result.ok) {
73
+ if (result.error.code === "aborted" && context.abortSignal?.aborted)
74
+ throw result.error;
75
+ if (result.error.code === "timeout")
76
+ throw new Error(`Command timed out after ${timeout} seconds`);
77
+ if (result.error.code === "aborted")
78
+ throw new Error("Command aborted");
79
+ throw result.error;
80
+ }
81
+ const exitCode = result.value.exitCode;
82
+ const retained = api.retainedOutput();
83
+ const structuredOutput = {
84
+ output: retained.text,
85
+ truncated: retained.truncated,
86
+ ...(spillPath === undefined ? {} : { fullOutputPath: spillPath }),
87
+ exitCode,
88
+ };
89
+ if (exitCode === 0)
90
+ return { structuredOutput };
91
+ const exited = { severity: "error", code: "exit_code", message: `Command exited with code ${exitCode}` };
92
+ return { structuredOutput, isError: true, diagnostics: [exited] };
93
+ }
94
+ /**
95
+ * Runs a command through the environment's shell. Its output streams to `api.output()`, where the Harness keeps the
96
+ * tail within the default limits; the result content is that retained output. The retained window goes to the
97
+ * environment, which may omit output outside it and report how much it omitted, so dropped counts stay exact. Output
98
+ * beyond the limits is spilled to a file whose path is reported as a diagnostic. A nonzero exit is an error result with
99
+ * the exit code; a timeout throws, which makes an error result that still carries the output and diagnostics.
100
+ */
101
+ export function createBashTool(options) {
102
+ return defineTool({
103
+ name: "bash",
104
+ description: `Execute a bash command in the current working directory. Returns combined stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,
105
+ parameters: bashSchema,
106
+ structuredOutputSchema: shellStructuredOutputSchema,
107
+ outputLimits: { retain: "tail" },
108
+ async execute(args, api, context) {
109
+ validateTimeout(args.timeout);
110
+ const execution = await prepareExecution(args.command, options, api, context);
111
+ return runCommand([execution.command], execution, args.timeout, api, context);
112
+ },
113
+ });
114
+ }
115
+ /** Output in UTF-8 whatever the console's code page, as the coding agent's `powershell` tool does. */
116
+ const UTF8_OUTPUT = "try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}";
117
+ const POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command"];
118
+ /**
119
+ * Runs a PowerShell command, like `bash` but through PowerShell instead of the environment's shell: `pwsh` (PowerShell
120
+ * 7), else Windows PowerShell, started directly with the command as an argument, so no other shell parses it.
121
+ */
122
+ export function createPowerShellTool(options) {
123
+ const programs = options?.programs ?? ["pwsh", "powershell"];
124
+ return defineTool({
125
+ name: "powershell",
126
+ description: `Execute a PowerShell command in the current working directory. Returns combined stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,
127
+ parameters: powershellSchema,
128
+ structuredOutputSchema: shellStructuredOutputSchema,
129
+ outputLimits: { retain: "tail" },
130
+ async execute(args, api, context) {
131
+ validateTimeout(args.timeout);
132
+ const execution = await prepareExecution(args.command, options, api, context);
133
+ const script = `${UTF8_OUTPUT}\n${execution.command}`;
134
+ const commands = programs.map((program) => [program, ...POWERSHELL_ARGS, script]);
135
+ return runCommand(commands, execution, args.timeout, api, context);
136
+ },
137
+ });
138
+ }
139
+ //# sourceMappingURL=bash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../src/tools/b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,EAAE,MAAM,CAAC,CAAC,CAAC;YAClF,OAAO,UAAU,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;QACpE,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Context } from \"@diffra-ai/chord/context\";\nimport { bool, num, obj, opt, type Static, str } from \"@diffra-ai/schema\";\nimport { defineTool } from \"../harness/define.ts\";\nimport type { ToolExecutionApi, ToolExecutionResult, ToolRegistration } from \"../harness/types.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES } from \"../truncate.ts\";\nimport { requireEnv } from \"./env.ts\";\n\nconst MAX_TIMEOUT_SECONDS = 2_147_483_647 / 1000;\n\n// Open objects, as the tools accepted extra arguments when their schemas were TypeBox's.\nconst bashSchema = obj(\n\t{\n\t\tcommand: str({ description: \"Bash command to execute\" }),\n\t\ttimeout: opt(num({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n\t},\n\t{ open: true },\n);\n\nconst powershellSchema = obj(\n\t{\n\t\tcommand: str({ description: \"PowerShell command to execute\" }),\n\t\ttimeout: opt(num({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n\t},\n\t{ open: true },\n);\n\n/** What a program that calls `bash` or `powershell` receives. */\nconst shellStructuredOutputSchema = obj(\n\t{\n\t\toutput: str({ description: \"Combined stdout and stderr: the retained tail, as the model sees it\" }),\n\t\ttruncated: bool({ description: \"Whether earlier output was dropped\" }),\n\t\tfullOutputPath: opt(str({ description: \"File with the complete output, when it was spilled\" })),\n\t\texitCode: num(),\n\t},\n\t{ open: true },\n);\n\nexport type BashToolInput = Static<typeof bashSchema>;\nexport type PowerShellToolInput = Static<typeof powershellSchema>;\nexport type ShellStructuredOutput = Static<typeof shellStructuredOutputSchema>;\n\n/** A command about to run, which `prepare` may change: the script, its working directory and environment. */\nexport interface BashExecution {\n\tcommand: string;\n\tcwd: string;\n\tenv: Record<string, string>;\n\tinheritEnv: boolean;\n}\n\nexport type BashPrepare = (execution: BashExecution, api: ToolExecutionApi, context: Context) => void | Promise<void>;\n\nexport interface BashToolOptions {\n\tcommandPrefix?: string;\n\tprepare?: BashPrepare;\n}\n\nexport interface PowerShellToolOptions {\n\t/** Lines run before each command. */\n\tcommandPrefix?: string;\n\tprepare?: BashPrepare;\n\t/** PowerShell programs to try in order; default `pwsh`, then `powershell`. A program that cannot start is skipped. */\n\tprograms?: readonly string[];\n}\n\nfunction validateTimeout(timeout: number | undefined): void {\n\tif (timeout === undefined) return;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\tif (timeout > MAX_TIMEOUT_SECONDS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n}\n\n/** The execution of one call: the command with its prefix, in the environment's working directory, then `prepare`. */\nasync function prepareExecution(\n\tcommand: string,\n\toptions: { commandPrefix?: string; prepare?: BashPrepare } | undefined,\n\tapi: ToolExecutionApi,\n\tcontext: Context,\n): Promise<BashExecution> {\n\tconst execution: BashExecution = {\n\t\tcommand: options?.commandPrefix ? `${options.commandPrefix}\\n${command}` : command,\n\t\tcwd: requireEnv(api).cwd,\n\t\tenv: {},\n\t\tinheritEnv: true,\n\t};\n\tawait options?.prepare?.(execution, api, context);\n\treturn execution;\n}\n\n/**\n * Run each command form in turn until one starts, streaming output to `api.output()` within the retained window, and\n * turn the result into the tool's result: a spill diagnostic, an error result for a nonzero exit, and a thrown error for\n * a failure such as a timeout. The structured output repeats the retained output with the exit code.\n */\nasync function runCommand(\n\tcommands: readonly (string | readonly string[])[],\n\texecution: BashExecution,\n\ttimeout: number | undefined,\n\tapi: ToolExecutionApi,\n\tcontext: Context,\n): Promise<ToolExecutionResult> {\n\tconst env = requireEnv(api);\n\tlet result: Awaited<ReturnType<typeof env.exec>> | undefined;\n\tfor (const command of commands) {\n\t\tresult = await env.exec(\n\t\t\tcommand,\n\t\t\t{\n\t\t\t\tcwd: execution.cwd,\n\t\t\t\tenv: execution.env,\n\t\t\t\tinheritEnv: execution.inheritEnv,\n\t\t\t\t...(timeout === undefined ? {} : { timeout }),\n\t\t\t\tonOutput: (text, _context, info) => api.output(text, info.skipped),\n\t\t\t\tspill: { afterBytes: DEFAULT_MAX_BYTES, afterLines: DEFAULT_MAX_LINES },\n\t\t\t\t// An environment may then omit output outside the retained tail and report the omission.\n\t\t\t\t...(api.outputWindow === undefined ? {} : { window: api.outputWindow }),\n\t\t\t},\n\t\t\tcontext,\n\t\t);\n\t\t// A program that could not start produced no output; the next form may.\n\t\tif (result.ok || result.error.code !== \"spawn_error\") break;\n\t}\n\tif (result === undefined) throw new Error(\"No command to run\");\n\tconst spillPath = result.ok ? result.value.spillPath : result.error.spillPath;\n\tif (spillPath !== undefined) {\n\t\tapi.diagnostic({ severity: \"info\", code: \"full_output\", message: `Full output: ${spillPath}` });\n\t}\n\tif (!result.ok) {\n\t\tif (result.error.code === \"aborted\" && context.abortSignal?.aborted) throw result.error;\n\t\tif (result.error.code === \"timeout\") throw new Error(`Command timed out after ${timeout} seconds`);\n\t\tif (result.error.code === \"aborted\") throw new Error(\"Command aborted\");\n\t\tthrow result.error;\n\t}\n\tconst exitCode = result.value.exitCode;\n\tconst retained = api.retainedOutput();\n\tconst structuredOutput: ShellStructuredOutput = {\n\t\toutput: retained.text,\n\t\ttruncated: retained.truncated,\n\t\t...(spillPath === undefined ? {} : { fullOutputPath: spillPath }),\n\t\texitCode,\n\t};\n\tif (exitCode === 0) return { structuredOutput };\n\tconst exited = { severity: \"error\", code: \"exit_code\", message: `Command exited with code ${exitCode}` } as const;\n\treturn { structuredOutput, isError: true, diagnostics: [exited] };\n}\n\n/**\n * Runs a command through the environment's shell. Its output streams to `api.output()`, where the Harness keeps the\n * tail within the default limits; the result content is that retained output. The retained window goes to the\n * environment, which may omit output outside it and report how much it omitted, so dropped counts stay exact. Output\n * beyond the limits is spilled to a file whose path is reported as a diagnostic. A nonzero exit is an error result with\n * the exit code; a timeout throws, which makes an error result that still carries the output and diagnostics.\n */\nexport function createBashTool(options?: BashToolOptions): ToolRegistration<typeof bashSchema> {\n\treturn defineTool({\n\t\tname: \"bash\",\n\t\tdescription: `Execute a bash command in the current working directory. Returns combined stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tparameters: bashSchema,\n\t\tstructuredOutputSchema: shellStructuredOutputSchema,\n\t\toutputLimits: { retain: \"tail\" },\n\t\tasync execute(args, api, context) {\n\t\t\tvalidateTimeout(args.timeout);\n\t\t\tconst execution = await prepareExecution(args.command, options, api, context);\n\t\t\treturn runCommand([execution.command], execution, args.timeout, api, context);\n\t\t},\n\t});\n}\n\n/** Output in UTF-8 whatever the console's code page, as the coding agent's `powershell` tool does. */\nconst UTF8_OUTPUT = \"try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\";\nconst POWERSHELL_ARGS = [\"-NoProfile\", \"-NonInteractive\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\"] as const;\n\n/**\n * Runs a PowerShell command, like `bash` but through PowerShell instead of the environment's shell: `pwsh` (PowerShell\n * 7), else Windows PowerShell, started directly with the command as an argument, so no other shell parses it.\n */\nexport function createPowerShellTool(options?: PowerShellToolOptions): ToolRegistration<typeof powershellSchema> {\n\tconst programs = options?.programs ?? [\"pwsh\", \"powershell\"];\n\treturn defineTool({\n\t\tname: \"powershell\",\n\t\tdescription: `Execute a PowerShell command in the current working directory. Returns combined stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tparameters: powershellSchema,\n\t\tstructuredOutputSchema: shellStructuredOutputSchema,\n\t\toutputLimits: { retain: \"tail\" },\n\t\tasync execute(args, api, context) {\n\t\t\tvalidateTimeout(args.timeout);\n\t\t\tconst execution = await prepareExecution(args.command, options, api, context);\n\t\t\tconst script = `${UTF8_OUTPUT}\\n${execution.command}`;\n\t\t\tconst commands = programs.map((program) => [program, ...POWERSHELL_ARGS, script]);\n\t\t\treturn runCommand(commands, execution, args.timeout, api, context);\n\t\t},\n\t});\n}\n"]}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Shared diff computation utilities for the edit and similar tools.
3
+ */
4
+ export declare function detectLineEnding(content: string): "\r\n" | "\n";
5
+ export declare function normalizeToLF(text: string): string;
6
+ export declare function restoreLineEndings(text: string, ending: "\r\n" | "\n"): string;
7
+ /**
8
+ * Normalize text for fuzzy matching. Applies progressive transformations:
9
+ * - Strip trailing whitespace from each line
10
+ * - Normalize smart quotes to ASCII equivalents
11
+ * - Normalize Unicode dashes/hyphens to ASCII hyphen
12
+ * - Normalize special Unicode spaces to regular space
13
+ */
14
+ export declare function normalizeForFuzzyMatch(text: string): string;
15
+ interface MatchedEdit {
16
+ editIndex: number;
17
+ matchIndex: number;
18
+ matchLength: number;
19
+ newText: string;
20
+ }
21
+ type TextReplacement = Pick<MatchedEdit, "matchIndex" | "matchLength" | "newText">;
22
+ /**
23
+ * Apply replacements matched against `baseContent` to `originalContent` while
24
+ * preserving unchanged line blocks from the original.
25
+ *
26
+ * This is useful when `baseContent` is a normalized view of the original. Each
27
+ * replacement is widened to the lines it actually touches, those touched lines
28
+ * are rewritten from the normalized base, and all other lines are copied back
29
+ * from `originalContent`. The actual replacement ranges drive preservation so
30
+ * duplicate normalized lines cannot be aligned to the wrong occurrence.
31
+ */
32
+ export declare function applyReplacementsPreservingUnchangedLines(originalContent: string, baseContent: string, replacements: TextReplacement[]): string;
33
+ export interface FuzzyMatchResult {
34
+ /** Whether a match was found */
35
+ found: boolean;
36
+ /** The index where the match starts (in the content that should be used for replacement) */
37
+ index: number;
38
+ /** Length of the matched text */
39
+ matchLength: number;
40
+ /** Whether fuzzy matching was used (false = exact match) */
41
+ usedFuzzyMatch: boolean;
42
+ /**
43
+ * The content to use for replacement operations.
44
+ * When exact match: original content. When fuzzy match: normalized content.
45
+ */
46
+ contentForReplacement: string;
47
+ }
48
+ export interface Edit {
49
+ oldText: string;
50
+ newText: string;
51
+ }
52
+ export interface AppliedEditsResult {
53
+ baseContent: string;
54
+ newContent: string;
55
+ }
56
+ /**
57
+ * Find oldText in content, trying exact match first, then fuzzy match.
58
+ * When fuzzy matching is used, the returned contentForReplacement is the
59
+ * fuzzy-normalized version of the content (trailing whitespace stripped,
60
+ * Unicode quotes/dashes normalized to ASCII).
61
+ */
62
+ export declare function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult;
63
+ /** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */
64
+ export declare function stripBom(content: string): {
65
+ bom: string;
66
+ text: string;
67
+ };
68
+ /**
69
+ * Apply one or more exact-text replacements to LF-normalized content.
70
+ *
71
+ * All edits are matched against the same original content. Replacements are
72
+ * then applied in reverse order so offsets remain stable. If any edit needs
73
+ * fuzzy matching, the operation runs in fuzzy-normalized content space and then
74
+ * overlays those line-level changes onto the original content so unchanged line
75
+ * blocks keep their original bytes.
76
+ */
77
+ export declare function applyEditsToNormalizedContent(normalizedContent: string, edits: Edit[], path: string): AppliedEditsResult;
78
+ /** Generate a standard unified patch. */
79
+ export declare function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines?: number): string;
80
+ /**
81
+ * Generate a display-oriented diff string with line numbers and context.
82
+ * Returns both the diff string and the first changed line number (in the new file).
83
+ */
84
+ export declare function generateDiffString(oldContent: string, newContent: string, contextLines?: number): {
85
+ diff: string;
86
+ firstChangedLine: number | undefined;
87
+ };
88
+ export {};
89
+ //# sourceMappingURL=edit-diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-diff.d.ts","sourceRoot":"","sources":["../../src/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,wBAAg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