@namzu/sdk 68.0.1 → 69.1.0

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 (492) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/authorization/skill-grant.d.ts.map +1 -1
  6. package/dist/authorization/skill-grant.js +1 -0
  7. package/dist/authorization/skill-grant.js.map +1 -1
  8. package/dist/bridge/acp/permission.d.ts +10 -0
  9. package/dist/bridge/acp/permission.d.ts.map +1 -1
  10. package/dist/bridge/acp/permission.js.map +1 -1
  11. package/dist/bridge/acp/server.d.ts +12 -0
  12. package/dist/bridge/acp/server.d.ts.map +1 -1
  13. package/dist/bridge/acp/server.js +21 -0
  14. package/dist/bridge/acp/server.js.map +1 -1
  15. package/dist/compaction/context-window.d.ts +8 -0
  16. package/dist/compaction/context-window.d.ts.map +1 -1
  17. package/dist/compaction/context-window.js +14 -0
  18. package/dist/compaction/context-window.js.map +1 -1
  19. package/dist/compaction/loaded-skills.d.ts +10 -0
  20. package/dist/compaction/loaded-skills.d.ts.map +1 -1
  21. package/dist/compaction/loaded-skills.js +45 -1
  22. package/dist/compaction/loaded-skills.js.map +1 -1
  23. package/dist/compaction/manager.d.ts +8 -0
  24. package/dist/compaction/manager.d.ts.map +1 -1
  25. package/dist/compaction/manager.js +31 -0
  26. package/dist/compaction/manager.js.map +1 -1
  27. package/dist/compaction/manual.d.ts.map +1 -1
  28. package/dist/compaction/manual.js +7 -1
  29. package/dist/compaction/manual.js.map +1 -1
  30. package/dist/compaction/model-summary.js +2 -2
  31. package/dist/compaction/model-summary.js.map +1 -1
  32. package/dist/compaction/restore.d.ts +8 -0
  33. package/dist/compaction/restore.d.ts.map +1 -1
  34. package/dist/compaction/restore.js +65 -0
  35. package/dist/compaction/restore.js.map +1 -1
  36. package/dist/compaction/salience/working-set.d.ts.map +1 -1
  37. package/dist/compaction/salience/working-set.js +2 -2
  38. package/dist/compaction/salience/working-set.js.map +1 -1
  39. package/dist/compaction/tool-result-editing.d.ts +6 -0
  40. package/dist/compaction/tool-result-editing.d.ts.map +1 -1
  41. package/dist/compaction/tool-result-editing.js +7 -1
  42. package/dist/compaction/tool-result-editing.js.map +1 -1
  43. package/dist/compaction/types.d.ts +2 -0
  44. package/dist/compaction/types.d.ts.map +1 -1
  45. package/dist/compaction/wire.d.ts.map +1 -1
  46. package/dist/compaction/wire.js +4 -0
  47. package/dist/compaction/wire.js.map +1 -1
  48. package/dist/connector/index.d.ts +2 -2
  49. package/dist/connector/index.d.ts.map +1 -1
  50. package/dist/connector/index.js +1 -1
  51. package/dist/connector/index.js.map +1 -1
  52. package/dist/connector/mcp/client.d.ts +29 -0
  53. package/dist/connector/mcp/client.d.ts.map +1 -1
  54. package/dist/connector/mcp/client.js +59 -2
  55. package/dist/connector/mcp/client.js.map +1 -1
  56. package/dist/connector/mcp/errors.d.ts +7 -0
  57. package/dist/connector/mcp/errors.d.ts.map +1 -1
  58. package/dist/connector/mcp/errors.js +14 -0
  59. package/dist/connector/mcp/errors.js.map +1 -1
  60. package/dist/connector/mcp/index.d.ts +5 -1
  61. package/dist/connector/mcp/index.d.ts.map +1 -1
  62. package/dist/connector/mcp/index.js +3 -1
  63. package/dist/connector/mcp/index.js.map +1 -1
  64. package/dist/connector/mcp/skill-source.d.ts +144 -0
  65. package/dist/connector/mcp/skill-source.d.ts.map +1 -0
  66. package/dist/connector/mcp/skill-source.js +375 -0
  67. package/dist/connector/mcp/skill-source.js.map +1 -0
  68. package/dist/connector/mcp/skills.d.ts +137 -0
  69. package/dist/connector/mcp/skills.d.ts.map +1 -0
  70. package/dist/connector/mcp/skills.js +303 -0
  71. package/dist/connector/mcp/skills.js.map +1 -0
  72. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  73. package/dist/manager/session/turn-recorder.js +23 -1
  74. package/dist/manager/session/turn-recorder.js.map +1 -1
  75. package/dist/network/audit.d.ts +1 -1
  76. package/dist/network/audit.d.ts.map +1 -1
  77. package/dist/network/audit.js +2 -0
  78. package/dist/network/audit.js.map +1 -1
  79. package/dist/network/computer.d.ts +107 -0
  80. package/dist/network/computer.d.ts.map +1 -0
  81. package/dist/network/computer.js +250 -0
  82. package/dist/network/computer.js.map +1 -0
  83. package/dist/network/index.d.ts +2 -0
  84. package/dist/network/index.d.ts.map +1 -1
  85. package/dist/network/index.js +1 -0
  86. package/dist/network/index.js.map +1 -1
  87. package/dist/network/join.d.ts +13 -1
  88. package/dist/network/join.d.ts.map +1 -1
  89. package/dist/network/join.js +21 -3
  90. package/dist/network/join.js.map +1 -1
  91. package/dist/network/roster.d.ts +5 -0
  92. package/dist/network/roster.d.ts.map +1 -1
  93. package/dist/network/roster.js.map +1 -1
  94. package/dist/network/service.d.ts +12 -2
  95. package/dist/network/service.d.ts.map +1 -1
  96. package/dist/network/service.js +539 -60
  97. package/dist/network/service.js.map +1 -1
  98. package/dist/network/store.d.ts +33 -1
  99. package/dist/network/store.d.ts.map +1 -1
  100. package/dist/network/store.js +48 -4
  101. package/dist/network/store.js.map +1 -1
  102. package/dist/network/transport.d.ts +1 -1
  103. package/dist/network/transport.js +1 -1
  104. package/dist/network/wire.d.ts +14 -0
  105. package/dist/network/wire.d.ts.map +1 -1
  106. package/dist/network/wire.js +17 -1
  107. package/dist/network/wire.js.map +1 -1
  108. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  109. package/dist/plugin/shell-hook-tool-names.js +1 -0
  110. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  111. package/dist/plugin/shell-hook.d.ts +8 -3
  112. package/dist/plugin/shell-hook.d.ts.map +1 -1
  113. package/dist/plugin/shell-hook.js +132 -7
  114. package/dist/plugin/shell-hook.js.map +1 -1
  115. package/dist/prompt/coding-agent-doctrine.d.ts +4 -4
  116. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  117. package/dist/prompt/coding-agent-doctrine.js +7 -2
  118. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  119. package/dist/provider/fallback.d.ts.map +1 -1
  120. package/dist/provider/fallback.js +9 -0
  121. package/dist/provider/fallback.js.map +1 -1
  122. package/dist/provider/idle-timeout.d.ts.map +1 -1
  123. package/dist/provider/idle-timeout.js +8 -0
  124. package/dist/provider/idle-timeout.js.map +1 -1
  125. package/dist/provider/instrumentation.d.ts.map +1 -1
  126. package/dist/provider/instrumentation.js +10 -0
  127. package/dist/provider/instrumentation.js.map +1 -1
  128. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  129. package/dist/provider/model-window-suffix.js +2 -0
  130. package/dist/provider/model-window-suffix.js.map +1 -1
  131. package/dist/provider/retry.d.ts.map +1 -1
  132. package/dist/provider/retry.js +8 -0
  133. package/dist/provider/retry.js.map +1 -1
  134. package/dist/public-runtime.d.ts +10 -7
  135. package/dist/public-runtime.d.ts.map +1 -1
  136. package/dist/public-runtime.js +12 -5
  137. package/dist/public-runtime.js.map +1 -1
  138. package/dist/public-tools.d.ts +7 -4
  139. package/dist/public-tools.d.ts.map +1 -1
  140. package/dist/public-tools.js +9 -3
  141. package/dist/public-tools.js.map +1 -1
  142. package/dist/public-types.d.ts +4 -1
  143. package/dist/public-types.d.ts.map +1 -1
  144. package/dist/registry/tool/presentation.d.ts +8 -1
  145. package/dist/registry/tool/presentation.d.ts.map +1 -1
  146. package/dist/registry/tool/presentation.js +14 -5
  147. package/dist/registry/tool/presentation.js.map +1 -1
  148. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  149. package/dist/runtime/jobs/registry.js +2 -1
  150. package/dist/runtime/jobs/registry.js.map +1 -1
  151. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  152. package/dist/runtime/query/auto-review/classifier.js +19 -3
  153. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  154. package/dist/runtime/query/auto-review/failure.d.ts +12 -0
  155. package/dist/runtime/query/auto-review/failure.d.ts.map +1 -0
  156. package/dist/runtime/query/auto-review/failure.js +46 -0
  157. package/dist/runtime/query/auto-review/failure.js.map +1 -0
  158. package/dist/runtime/query/auto-review/index.d.ts +1 -0
  159. package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
  160. package/dist/runtime/query/auto-review/index.js +1 -0
  161. package/dist/runtime/query/auto-review/index.js.map +1 -1
  162. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  163. package/dist/runtime/query/executor/tool-call-admission.js +10 -1
  164. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  165. package/dist/runtime/query/executor.d.ts +12 -0
  166. package/dist/runtime/query/executor.d.ts.map +1 -1
  167. package/dist/runtime/query/executor.js +43 -9
  168. package/dist/runtime/query/executor.js.map +1 -1
  169. package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
  170. package/dist/runtime/query/file-evidence-replay.js +6 -6
  171. package/dist/runtime/query/file-evidence-replay.js.map +1 -1
  172. package/dist/runtime/query/index.d.ts +4 -0
  173. package/dist/runtime/query/index.d.ts.map +1 -1
  174. package/dist/runtime/query/index.js +40 -1
  175. package/dist/runtime/query/index.js.map +1 -1
  176. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  177. package/dist/runtime/query/iteration/index.js +2 -0
  178. package/dist/runtime/query/iteration/index.js.map +1 -1
  179. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  180. package/dist/runtime/query/iteration/phases/compaction.js +21 -3
  181. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  182. package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
  183. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  184. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  185. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +6 -2
  186. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
  187. package/dist/runtime/query/iteration/phases/per-call-review.js +24 -9
  188. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
  189. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  190. package/dist/runtime/query/iteration/step-shaping.js +4 -0
  191. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  192. package/dist/runtime/query/prepare-turn.d.ts +5 -1
  193. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  194. package/dist/runtime/query/prepare-turn.js +13 -3
  195. package/dist/runtime/query/prepare-turn.js.map +1 -1
  196. package/dist/runtime/query/review-policy.d.ts +15 -4
  197. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  198. package/dist/runtime/query/review-policy.js +15 -4
  199. package/dist/runtime/query/review-policy.js.map +1 -1
  200. package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
  201. package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
  202. package/dist/runtime/query/shell-line-escalation.js +38 -0
  203. package/dist/runtime/query/shell-line-escalation.js.map +1 -0
  204. package/dist/runtime/query/tooling.d.ts +7 -0
  205. package/dist/runtime/query/tooling.d.ts.map +1 -1
  206. package/dist/runtime/query/tooling.js +2 -0
  207. package/dist/runtime/query/tooling.js.map +1 -1
  208. package/dist/runtime/query/turn/outcome-ledger.d.ts +4 -0
  209. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  210. package/dist/runtime/query/turn/outcome-ledger.js +47 -1
  211. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  212. package/dist/sandbox/provider/local.d.ts.map +1 -1
  213. package/dist/sandbox/provider/local.js +3 -1
  214. package/dist/sandbox/provider/local.js.map +1 -1
  215. package/dist/scheduler/local.d.ts.map +1 -1
  216. package/dist/scheduler/local.js +3 -1
  217. package/dist/scheduler/local.js.map +1 -1
  218. package/dist/skills/index.d.ts +4 -0
  219. package/dist/skills/index.d.ts.map +1 -1
  220. package/dist/skills/index.js +2 -0
  221. package/dist/skills/index.js.map +1 -1
  222. package/dist/skills/inline-shell-host.d.ts +103 -0
  223. package/dist/skills/inline-shell-host.d.ts.map +1 -0
  224. package/dist/skills/inline-shell-host.js +238 -0
  225. package/dist/skills/inline-shell-host.js.map +1 -0
  226. package/dist/skills/inline-shell.d.ts +176 -0
  227. package/dist/skills/inline-shell.d.ts.map +1 -0
  228. package/dist/skills/inline-shell.js +646 -0
  229. package/dist/skills/inline-shell.js.map +1 -0
  230. package/dist/store/index.d.ts +2 -0
  231. package/dist/store/index.d.ts.map +1 -1
  232. package/dist/store/index.js +1 -0
  233. package/dist/store/index.js.map +1 -1
  234. package/dist/store/task/file.d.ts +124 -0
  235. package/dist/store/task/file.d.ts.map +1 -0
  236. package/dist/store/task/file.js +498 -0
  237. package/dist/store/task/file.js.map +1 -0
  238. package/dist/teams/backend.d.ts +28 -0
  239. package/dist/teams/backend.d.ts.map +1 -0
  240. package/dist/teams/backend.js +2 -0
  241. package/dist/teams/backend.js.map +1 -0
  242. package/dist/teams/fs-sync.d.ts +19 -0
  243. package/dist/teams/fs-sync.d.ts.map +1 -0
  244. package/dist/teams/fs-sync.js +81 -0
  245. package/dist/teams/fs-sync.js.map +1 -0
  246. package/dist/teams/index.d.ts +14 -0
  247. package/dist/teams/index.d.ts.map +1 -0
  248. package/dist/teams/index.js +11 -0
  249. package/dist/teams/index.js.map +1 -0
  250. package/dist/teams/names.d.ts +15 -0
  251. package/dist/teams/names.d.ts.map +1 -0
  252. package/dist/teams/names.js +43 -0
  253. package/dist/teams/names.js.map +1 -0
  254. package/dist/teams/store.d.ts +133 -0
  255. package/dist/teams/store.d.ts.map +1 -0
  256. package/dist/teams/store.js +536 -0
  257. package/dist/teams/store.js.map +1 -0
  258. package/dist/teams/types.d.ts +97 -0
  259. package/dist/teams/types.d.ts.map +1 -0
  260. package/dist/teams/types.js +70 -0
  261. package/dist/teams/types.js.map +1 -0
  262. package/dist/tools/admit-facts.d.ts.map +1 -1
  263. package/dist/tools/admit-facts.js +28 -0
  264. package/dist/tools/admit-facts.js.map +1 -1
  265. package/dist/tools/builtins/bash.d.ts.map +1 -1
  266. package/dist/tools/builtins/bash.js +5 -2
  267. package/dist/tools/builtins/bash.js.map +1 -1
  268. package/dist/tools/builtins/browser.js +1 -1
  269. package/dist/tools/builtins/browser.js.map +1 -1
  270. package/dist/tools/builtins/computer-use.d.ts +60 -2
  271. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  272. package/dist/tools/builtins/computer-use.js +695 -80
  273. package/dist/tools/builtins/computer-use.js.map +1 -1
  274. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  275. package/dist/tools/builtins/content-fingerprint.js +2 -1
  276. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  277. package/dist/tools/builtins/edit-apply.d.ts +1 -0
  278. package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
  279. package/dist/tools/builtins/edit-apply.js +108 -21
  280. package/dist/tools/builtins/edit-apply.js.map +1 -1
  281. package/dist/tools/builtins/edit-match.d.ts +37 -0
  282. package/dist/tools/builtins/edit-match.d.ts.map +1 -1
  283. package/dist/tools/builtins/edit-match.js +193 -0
  284. package/dist/tools/builtins/edit-match.js.map +1 -1
  285. package/dist/tools/builtins/edit.d.ts.map +1 -1
  286. package/dist/tools/builtins/edit.js +14 -7
  287. package/dist/tools/builtins/edit.js.map +1 -1
  288. package/dist/tools/builtins/exit-semantics.d.ts +8 -0
  289. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  290. package/dist/tools/builtins/exit-semantics.js +19 -0
  291. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  292. package/dist/tools/builtins/index.d.ts +3 -1
  293. package/dist/tools/builtins/index.d.ts.map +1 -1
  294. package/dist/tools/builtins/index.js +1 -0
  295. package/dist/tools/builtins/index.js.map +1 -1
  296. package/dist/tools/builtins/present-file.d.ts +24 -0
  297. package/dist/tools/builtins/present-file.d.ts.map +1 -0
  298. package/dist/tools/builtins/present-file.js +116 -0
  299. package/dist/tools/builtins/present-file.js.map +1 -0
  300. package/dist/tools/builtins/read-file.js +1 -1
  301. package/dist/tools/builtins/read-file.js.map +1 -1
  302. package/dist/tools/builtins/read-render.d.ts +12 -1
  303. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  304. package/dist/tools/builtins/read-render.js +16 -3
  305. package/dist/tools/builtins/read-render.js.map +1 -1
  306. package/dist/tools/builtins/search-tools.d.ts +10 -0
  307. package/dist/tools/builtins/search-tools.d.ts.map +1 -1
  308. package/dist/tools/builtins/search-tools.js +36 -2
  309. package/dist/tools/builtins/search-tools.js.map +1 -1
  310. package/dist/tools/builtins/skill.d.ts +31 -0
  311. package/dist/tools/builtins/skill.d.ts.map +1 -1
  312. package/dist/tools/builtins/skill.js +232 -88
  313. package/dist/tools/builtins/skill.js.map +1 -1
  314. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  315. package/dist/tools/builtins/wait-for-job.js +5 -0
  316. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  317. package/dist/tools/builtins/web.d.ts.map +1 -1
  318. package/dist/tools/builtins/web.js +13 -2
  319. package/dist/tools/builtins/web.js.map +1 -1
  320. package/dist/tools/task/create.d.ts.map +1 -1
  321. package/dist/tools/task/create.js +13 -4
  322. package/dist/tools/task/create.js.map +1 -1
  323. package/dist/tools/task/get.d.ts +8 -0
  324. package/dist/tools/task/get.d.ts.map +1 -0
  325. package/dist/tools/task/get.js +51 -0
  326. package/dist/tools/task/get.js.map +1 -0
  327. package/dist/tools/task/index.d.ts +7 -0
  328. package/dist/tools/task/index.d.ts.map +1 -1
  329. package/dist/tools/task/index.js +10 -2
  330. package/dist/tools/task/index.js.map +1 -1
  331. package/dist/tools/task/list.d.ts.map +1 -1
  332. package/dist/tools/task/list.js +10 -2
  333. package/dist/tools/task/list.js.map +1 -1
  334. package/dist/tools/task/number.d.ts +13 -0
  335. package/dist/tools/task/number.d.ts.map +1 -0
  336. package/dist/tools/task/number.js +30 -0
  337. package/dist/tools/task/number.js.map +1 -0
  338. package/dist/tools/task/present.d.ts.map +1 -1
  339. package/dist/tools/task/present.js +17 -3
  340. package/dist/tools/task/present.js.map +1 -1
  341. package/dist/tools/task/update.d.ts +2 -1
  342. package/dist/tools/task/update.d.ts.map +1 -1
  343. package/dist/tools/task/update.js +87 -20
  344. package/dist/tools/task/update.js.map +1 -1
  345. package/dist/types/acp/index.d.ts +10 -0
  346. package/dist/types/acp/index.d.ts.map +1 -1
  347. package/dist/types/agent/base.d.ts +4 -0
  348. package/dist/types/agent/base.d.ts.map +1 -1
  349. package/dist/types/agent/scheduler.d.ts +9 -0
  350. package/dist/types/agent/scheduler.d.ts.map +1 -1
  351. package/dist/types/computer-use/index.d.ts +7 -0
  352. package/dist/types/computer-use/index.d.ts.map +1 -1
  353. package/dist/types/computer-use/index.js.map +1 -1
  354. package/dist/types/connector/mcp.d.ts +10 -0
  355. package/dist/types/connector/mcp.d.ts.map +1 -1
  356. package/dist/types/permission/index.d.ts +20 -0
  357. package/dist/types/permission/index.d.ts.map +1 -1
  358. package/dist/types/permission/index.js +25 -0
  359. package/dist/types/permission/index.js.map +1 -1
  360. package/dist/types/plugin/index.d.ts +47 -3
  361. package/dist/types/plugin/index.d.ts.map +1 -1
  362. package/dist/types/plugin/index.js +4 -0
  363. package/dist/types/plugin/index.js.map +1 -1
  364. package/dist/types/provider/chat.d.ts +8 -0
  365. package/dist/types/provider/chat.d.ts.map +1 -1
  366. package/dist/types/provider/interface.d.ts +16 -0
  367. package/dist/types/provider/interface.d.ts.map +1 -1
  368. package/dist/types/provider/model.d.ts +6 -0
  369. package/dist/types/provider/model.d.ts.map +1 -1
  370. package/dist/types/provider/stream.d.ts +2 -0
  371. package/dist/types/provider/stream.d.ts.map +1 -1
  372. package/dist/types/tool/index.d.ts +28 -2
  373. package/dist/types/tool/index.d.ts.map +1 -1
  374. package/dist/types/tool/index.js.map +1 -1
  375. package/dist/types/tool/presentation.d.ts +15 -0
  376. package/dist/types/tool/presentation.d.ts.map +1 -1
  377. package/dist/utils/node-on-path.d.ts +27 -0
  378. package/dist/utils/node-on-path.d.ts.map +1 -0
  379. package/dist/utils/node-on-path.js +70 -0
  380. package/dist/utils/node-on-path.js.map +1 -0
  381. package/package.json +1 -1
  382. package/src/agents/QueryAgent.ts +2 -0
  383. package/src/authorization/skill-grant.ts +1 -0
  384. package/src/bridge/acp/permission.ts +11 -1
  385. package/src/bridge/acp/server.ts +26 -0
  386. package/src/compaction/context-window.ts +18 -0
  387. package/src/compaction/loaded-skills.ts +42 -1
  388. package/src/compaction/manager.ts +28 -0
  389. package/src/compaction/manual.ts +9 -1
  390. package/src/compaction/model-summary.ts +2 -2
  391. package/src/compaction/restore.ts +69 -0
  392. package/src/compaction/salience/working-set.ts +6 -2
  393. package/src/compaction/tool-result-editing.ts +8 -1
  394. package/src/compaction/types.ts +2 -0
  395. package/src/compaction/wire.ts +4 -0
  396. package/src/connector/index.ts +27 -0
  397. package/src/connector/mcp/client.ts +71 -2
  398. package/src/connector/mcp/errors.ts +14 -0
  399. package/src/connector/mcp/index.ts +36 -0
  400. package/src/connector/mcp/skill-source.ts +499 -0
  401. package/src/connector/mcp/skills.ts +367 -0
  402. package/src/manager/session/turn-recorder.ts +24 -1
  403. package/src/network/audit.ts +2 -0
  404. package/src/network/computer.ts +347 -0
  405. package/src/network/index.ts +20 -0
  406. package/src/network/join.ts +21 -2
  407. package/src/network/roster.ts +5 -0
  408. package/src/network/service.ts +674 -84
  409. package/src/network/store.ts +57 -4
  410. package/src/network/transport.ts +1 -1
  411. package/src/network/wire.ts +18 -1
  412. package/src/plugin/shell-hook-tool-names.ts +1 -0
  413. package/src/plugin/shell-hook.ts +144 -7
  414. package/src/prompt/coding-agent-doctrine.ts +7 -2
  415. package/src/provider/fallback.ts +10 -0
  416. package/src/provider/idle-timeout.ts +9 -0
  417. package/src/provider/instrumentation.ts +12 -0
  418. package/src/provider/model-window-suffix.ts +2 -0
  419. package/src/provider/retry.ts +9 -0
  420. package/src/public-runtime.ts +100 -0
  421. package/src/public-tools.ts +18 -0
  422. package/src/public-types.ts +29 -0
  423. package/src/registry/tool/presentation.ts +14 -4
  424. package/src/runtime/jobs/registry.ts +2 -1
  425. package/src/runtime/query/auto-review/classifier.ts +19 -3
  426. package/src/runtime/query/auto-review/failure.ts +50 -0
  427. package/src/runtime/query/auto-review/index.ts +1 -0
  428. package/src/runtime/query/executor/tool-call-admission.ts +10 -1
  429. package/src/runtime/query/executor.ts +57 -8
  430. package/src/runtime/query/file-evidence-replay.ts +6 -5
  431. package/src/runtime/query/index.ts +62 -0
  432. package/src/runtime/query/iteration/index.ts +2 -0
  433. package/src/runtime/query/iteration/phases/compaction.ts +25 -2
  434. package/src/runtime/query/iteration/phases/context.ts +4 -0
  435. package/src/runtime/query/iteration/phases/per-call-review.ts +24 -7
  436. package/src/runtime/query/iteration/step-shaping.ts +4 -0
  437. package/src/runtime/query/prepare-turn.ts +20 -2
  438. package/src/runtime/query/review-policy.ts +31 -5
  439. package/src/runtime/query/shell-line-escalation.ts +49 -0
  440. package/src/runtime/query/tooling.ts +6 -0
  441. package/src/runtime/query/turn/outcome-ledger.ts +56 -1
  442. package/src/sandbox/provider/local.ts +3 -1
  443. package/src/scheduler/local.ts +3 -1
  444. package/src/skills/index.ts +43 -0
  445. package/src/skills/inline-shell-host.ts +303 -0
  446. package/src/skills/inline-shell.ts +765 -0
  447. package/src/store/index.ts +8 -0
  448. package/src/store/task/file.ts +641 -0
  449. package/src/teams/backend.ts +29 -0
  450. package/src/teams/fs-sync.ts +91 -0
  451. package/src/teams/index.ts +47 -0
  452. package/src/teams/names.ts +49 -0
  453. package/src/teams/store.ts +607 -0
  454. package/src/teams/types.ts +102 -0
  455. package/src/tools/admit-facts.ts +26 -0
  456. package/src/tools/builtins/bash.ts +5 -2
  457. package/src/tools/builtins/browser.ts +1 -1
  458. package/src/tools/builtins/computer-use.ts +799 -86
  459. package/src/tools/builtins/content-fingerprint.ts +2 -1
  460. package/src/tools/builtins/edit-apply.ts +124 -24
  461. package/src/tools/builtins/edit-match.ts +200 -0
  462. package/src/tools/builtins/edit.ts +16 -7
  463. package/src/tools/builtins/exit-semantics.ts +23 -0
  464. package/src/tools/builtins/index.ts +3 -0
  465. package/src/tools/builtins/present-file.ts +127 -0
  466. package/src/tools/builtins/read-file.ts +1 -1
  467. package/src/tools/builtins/read-render.ts +18 -3
  468. package/src/tools/builtins/search-tools.ts +36 -2
  469. package/src/tools/builtins/skill.ts +291 -95
  470. package/src/tools/builtins/wait-for-job.ts +5 -0
  471. package/src/tools/builtins/web.ts +15 -2
  472. package/src/tools/task/create.ts +13 -4
  473. package/src/tools/task/get.ts +53 -0
  474. package/src/tools/task/index.ts +14 -2
  475. package/src/tools/task/list.ts +10 -2
  476. package/src/tools/task/number.ts +32 -0
  477. package/src/tools/task/present.ts +18 -3
  478. package/src/tools/task/update.ts +94 -20
  479. package/src/types/acp/index.ts +11 -1
  480. package/src/types/agent/base.ts +6 -0
  481. package/src/types/agent/scheduler.ts +9 -0
  482. package/src/types/computer-use/index.ts +7 -0
  483. package/src/types/connector/mcp.ts +10 -0
  484. package/src/types/permission/index.ts +29 -0
  485. package/src/types/plugin/index.ts +95 -39
  486. package/src/types/provider/chat.ts +9 -0
  487. package/src/types/provider/interface.ts +18 -0
  488. package/src/types/provider/model.ts +6 -0
  489. package/src/types/provider/stream.ts +2 -0
  490. package/src/types/tool/index.ts +23 -2
  491. package/src/types/tool/presentation.ts +14 -0
  492. package/src/utils/node-on-path.ts +81 -0
@@ -1,4 +1,5 @@
1
1
  import { createHash } from 'node:crypto'
2
+ import { linePrefix } from './read-render.js'
2
3
 
3
4
  /**
4
5
  * A short, stable fingerprint of a file body.
@@ -50,7 +51,7 @@ export function unreadEditShownError(path: string, content: string): string | un
50
51
  const lines = content.split('\n')
51
52
  if (lines.length > 1 && lines[lines.length - 1] === '') lines.pop()
52
53
  if (lines.length > UNREAD_EDIT_SHOWN_MAX_LINES) return undefined
53
- const numbered = lines.map((line, i) => `${i + 1}\t${line}`).join('\n')
54
+ const numbered = lines.map((line, i) => `${linePrefix(i + 1)}${line}`).join('\n')
54
55
  return `${path} had not been read in this session, so this edit was not applied. It has now been read for you; its current contents follow. Repeat the edit against them, without reading the file again. Nothing was written.\n\n${numbered}`
55
56
  }
56
57
 
@@ -1,4 +1,11 @@
1
- import { reconcileNewString, resolveOldString } from './edit-match.js'
1
+ import {
2
+ describeIndent,
3
+ indentedMatchStarts,
4
+ reconcileNewString,
5
+ resolveIndentedMatch,
6
+ resolveOldString,
7
+ showWhitespace,
8
+ } from './edit-match.js'
2
9
  import type { EditInput } from './edit.js'
3
10
 
4
11
  /**
@@ -156,30 +163,50 @@ export type EditApplyFailure = {
156
163
  export function applyEdit(
157
164
  content: string,
158
165
  operations: readonly NormalizedEditInput[],
159
- ): { success: true; content: string; replacements: number } | EditApplyFailure {
166
+ ): { success: true; content: string; replacements: number; notes: string[] } | EditApplyFailure {
160
167
  let current = content
161
168
  let replacements = 0
162
-
169
+ const notes: string[] = []
170
+ const failures: string[] = []
171
+ let reason: EditApplyFailure['reason']
172
+
173
+ // Every hunk is tried, so one reply names every one that does not apply
174
+ // rather than the first. A failed hunk leaves the content as it was, so
175
+ // the ones after it are judged against the file without it; the write
176
+ // stays all-or-nothing either way.
163
177
  for (const [index, operation] of operations.entries()) {
164
- const result = applyOne(current, operation)
178
+ const result = applyOne(current, operation, index < FULL_EXCERPT_HUNKS)
165
179
  if (!result.success) {
166
- return {
167
- success: false,
168
- error: framedError(result.error, index, operations.length),
169
- ...(result.reason ? { reason: result.reason } : {}),
170
- }
180
+ failures.push(framedFailure(result.error, index, operations.length))
181
+ reason ??= result.reason
182
+ continue
171
183
  }
172
184
  current = result.content
173
185
  replacements += result.replacements
186
+ if (result.note !== undefined) {
187
+ notes.push(operations.length === 1 ? result.note : `edits[${index}]: ${result.note}`)
188
+ }
189
+ }
190
+
191
+ if (failures.length > 0) {
192
+ return {
193
+ success: false,
194
+ error:
195
+ operations.length === 1
196
+ ? (failures[0] as string)
197
+ : `${capBatchError(failures.join('\n'))}\nNothing was written — the whole batch is refused, so the file is exactly as it was.`,
198
+ ...(reason ? { reason } : {}),
199
+ }
174
200
  }
175
201
 
176
- return { success: true, content: current, replacements }
202
+ return { success: true, content: current, replacements, notes }
177
203
  }
178
204
 
179
205
  function applyOne(
180
206
  content: string,
181
207
  input: NormalizedEditInput,
182
- ): { success: true; content: string; replacements: number } | EditApplyFailure {
208
+ fullExcerpt = true,
209
+ ): { success: true; content: string; replacements: number; note?: string } | EditApplyFailure {
183
210
  if (input.operation === 'insert') {
184
211
  return applyLineInsert(content, input)
185
212
  }
@@ -194,22 +221,30 @@ function applyOne(
194
221
  // replacement so it fits where it lands. See `edit-match.ts`.
195
222
  let oldString = replacement.oldString
196
223
  let newString = replacement.newString
224
+ let note: string | undefined
197
225
  if (!content.includes(oldString)) {
198
226
  const resolved = resolveOldString(content, oldString)
199
- if (resolved === null) {
200
- const near = nearLine(content, oldString)
201
- return {
202
- success: false,
203
- reason: 'text_not_found',
204
- error: `old_string/oldStr not found in file. Make sure the string matches exactly, including whitespace and indentation. ${
205
- near === undefined
206
- ? 'Read the lines you mean to change again and copy them as they are.'
207
- : `A line that matches its first line apart from spacing is at line ${near}; read around it again and copy it as it is.`
208
- }`,
227
+ if (resolved !== null) {
228
+ newString = reconcileNewString(oldString, resolved, newString)
229
+ oldString = resolved
230
+ } else {
231
+ // Last resort, and only for one place: the same lines with different
232
+ // leading whitespace. `replace_all` names no single place, so it never
233
+ // takes this road.
234
+ const indented = replacement.replace_all
235
+ ? null
236
+ : resolveIndentedMatch(content, oldString, newString)
237
+ if (indented === null) {
238
+ return {
239
+ success: false,
240
+ reason: 'text_not_found',
241
+ error: notFoundError(content, oldString, fullExcerpt),
242
+ }
209
243
  }
244
+ oldString = indented.span
245
+ newString = indented.newString
246
+ note = INDENT_NOTE
210
247
  }
211
- newString = reconcileNewString(oldString, resolved, newString)
212
- oldString = resolved
213
248
  }
214
249
 
215
250
  // A deletion takes the line's trailing newline with it, so removing a whole
@@ -248,9 +283,68 @@ function applyOne(
248
283
  content:
249
284
  content.slice(0, firstIndex) + newString + content.slice(firstIndex + oldString.length),
250
285
  replacements: 1,
286
+ ...(note === undefined ? {} : { note }),
251
287
  }
252
288
  }
253
289
 
290
+ /** Said once when an edit applied although the indentation of old_string was not the file's. */
291
+ const INDENT_NOTE =
292
+ 'matched with adjusted indentation (old_string was indented differently from the file; new_string was re-indented to fit). Copy leading whitespace as it is after the arrow in read output.'
293
+
294
+ const CONTEXT_LINES = 12
295
+ /** Failing hunks of one batch that get the file's lines; the rest get index, reason and line number. */
296
+ const FULL_EXCERPT_HUNKS = 3
297
+ /** The most characters one batch's failure text may run to. */
298
+ const BATCH_ERROR_MAX_CHARS = 6000
299
+
300
+ function capBatchError(text: string): string {
301
+ if (text.length <= BATCH_ERROR_MAX_CHARS) return text
302
+ return `${text.slice(0, BATCH_ERROR_MAX_CHARS)}…\n(more failing hunks follow; fix these and run again)`
303
+ }
304
+ const CONTEXT_LINE_MAX_CHARS = 160
305
+
306
+ /**
307
+ * The not-found refusal. When a line of the file matches the first line of
308
+ * old_string apart from spacing, the file's own lines there are shown with
309
+ * their whitespace made visible, so the model can copy them without a read.
310
+ */
311
+ function notFoundError(content: string, oldString: string, fullExcerpt = true): string {
312
+ const head =
313
+ 'old_string/oldStr not found in file. Make sure the string matches exactly, including whitespace and indentation.'
314
+ const near = nearLine(content, oldString)
315
+ const starts = indentedMatchStarts(content, oldString)
316
+ if (starts.length > 1) {
317
+ const where = starts
318
+ .slice(0, 5)
319
+ .map((at) => at + 1)
320
+ .join(', ')
321
+ return `${head} Its lines appear in ${starts.length} places once indentation is ignored (starting at lines ${where}), so none was chosen; include more surrounding lines, or copy the indentation of the one you mean exactly.`
322
+ }
323
+ if (near === undefined) {
324
+ return `${head} Read the lines you mean to change again and copy them as they are.`
325
+ }
326
+ if (!fullExcerpt) {
327
+ return `${head} A line that matches its first line apart from spacing is at line ${near}; read around it and copy it as it is.`
328
+ }
329
+ const lines = content.split('\n')
330
+ const wanted = oldString.split('\n')
331
+ const firstWanted = wanted.find((line) => line.trim() !== '') ?? ''
332
+ const count = Math.min(Math.max(wanted.length, 3) + 1, CONTEXT_LINES)
333
+ const from = Math.max(1, near - 1)
334
+ const to = Math.min(lines.length, near - 1 + count)
335
+ const shown: string[] = []
336
+ for (let n = from; n <= to; n++) {
337
+ // The empty piece after a final newline is not a line of the file.
338
+ if (n === lines.length && lines[n - 1] === '') break
339
+ const raw = (lines[n - 1] ?? '').replace(/\r$/, '')
340
+ const visible = showWhitespace(raw)
341
+ shown.push(
342
+ `${String(n).padStart(6)}| ${visible.length > CONTEXT_LINE_MAX_CHARS ? `${visible.slice(0, CONTEXT_LINE_MAX_CHARS)}…` : visible}`,
343
+ )
344
+ }
345
+ return `${head} A line that matches its first line apart from spacing is at line ${near}: the file has ${describeIndent(lines[near - 1] ?? '')} there, your old_string has ${describeIndent(firstWanted)}. The file's lines, with → for a tab and · for a space (the numbers and | are not part of the file):\n${shown.join('\n')}\nCopy the text after the | exactly, turning → back into a tab and · into a space.`
346
+ }
347
+
254
348
  const NEAR_LINE_MIN_CHARS = 8
255
349
 
256
350
  /** The line of `content` that matches the first non-blank line of `needle` apart from spacing, 1-based. */
@@ -336,7 +430,13 @@ function normalizeLineEndings(
336
430
  /** The batch framing an operation's own error is reported under. */
337
431
  function framedError(error: string, index: number, total: number): string {
338
432
  if (total === 1) return error
339
- return `edits[${index}] of ${total}: ${error} Nothing was written — the whole batch is refused, so the file is exactly as it was.`
433
+ return `${framedFailure(error, index, total)} Nothing was written — the whole batch is refused, so the file is exactly as it was.`
434
+ }
435
+
436
+ /** One failing hunk of a batch, named by its index. */
437
+ function framedFailure(error: string, index: number, total: number): string {
438
+ if (total === 1) return error
439
+ return `edits[${index}] of ${total}: ${error}`
340
440
  }
341
441
 
342
442
  /**
@@ -271,3 +271,203 @@ export function reconcileNewString(oldString: string, resolved: string, newStrin
271
271
  if (hasCurlySingle) reconciled = curlifySingleQuotes(reconciled)
272
272
  return reconciled
273
273
  }
274
+
275
+ /** Spaces a tab stands for when indentation of different styles is compared. */
276
+ const TAB_WIDTHS = [4, 2, 8] as const
277
+
278
+ /** The result of finding `old_string` again by its content alone, ignoring how it was indented. */
279
+ export interface IndentedMatch {
280
+ /** The real span of the file the lines occupy. */
281
+ readonly span: string
282
+ /** `new_string`, re-indented by the difference the match found. */
283
+ readonly newString: string
284
+ }
285
+
286
+ function leadingWhitespace(line: string): string {
287
+ let end = 0
288
+ while (end < line.length && (line[end] === ' ' || line[end] === '\t')) end++
289
+ return line.slice(0, end)
290
+ }
291
+
292
+ function indentWidth(indent: string, tab: number): number {
293
+ let width = 0
294
+ for (const ch of indent) width += ch === '\t' ? tab : 1
295
+ return width
296
+ }
297
+
298
+ /** The smallest space-only indent (2 or more) among the lines, or 0. */
299
+ function spaceIndentUnit(lines: readonly string[]): number {
300
+ let unit = 0
301
+ for (const line of lines) {
302
+ if (line.trim() === '') continue
303
+ const indent = leadingWhitespace(line)
304
+ if (indent.length < 2 || indent.includes('\t')) continue
305
+ if (unit === 0 || indent.length < unit) unit = indent.length
306
+ }
307
+ return unit
308
+ }
309
+
310
+ function isBlank(line: string): boolean {
311
+ return line.trim() === ''
312
+ }
313
+
314
+ /** The text of a line apart from its indentation and trailing whitespace. */
315
+ function lineKey(line: string): string {
316
+ return line.trim()
317
+ }
318
+
319
+ /**
320
+ * Where, 0-based, the lines of `oldString` appear in `content` once leading
321
+ * and trailing whitespace is ignored. More than one entry means the text
322
+ * names several places and needs more context.
323
+ */
324
+ export function indentedMatchStarts(content: string, oldString: string): number[] {
325
+ const wanted = oldString.split('\n')
326
+ const endsWithNewline = wanted.length > 1 && wanted[wanted.length - 1] === ''
327
+ if (endsWithNewline) wanted.pop()
328
+ if (wanted.every(isBlank)) return []
329
+ const wantedKeys = wanted.map(lineKey)
330
+ const lines = content.split('\n')
331
+ const keys = lines.map(lineKey)
332
+ const first = wantedKeys.findIndex((key) => key !== '')
333
+ const starts: number[] = []
334
+ for (let at = 0; at + wanted.length <= lines.length; at++) {
335
+ // biome-ignore lint/style/noNonNullAssertion: index < length
336
+ if (keys[at + first]! !== wantedKeys[first]!) continue
337
+ let same = true
338
+ for (let i = 0; i < wanted.length; i++) {
339
+ if (keys[at + i] !== wantedKeys[i]) {
340
+ same = false
341
+ break
342
+ }
343
+ }
344
+ if (same) starts.push(at)
345
+ }
346
+ return starts
347
+ }
348
+
349
+ /**
350
+ * Find `oldString` in `content` by comparing lines with their leading and
351
+ * trailing whitespace ignored, for the case where the model copied the right
352
+ * lines with the wrong indentation (the usual cause: one level short, because
353
+ * the first tab of an indented line was taken for a separator).
354
+ *
355
+ * Applies only when ALL of these hold, and otherwise answers null:
356
+ *
357
+ * - exactly one run of lines in the file matches (a second place is
358
+ * ambiguous, and nothing is guessed);
359
+ * - the indentation differs by the same amount on every non-blank line
360
+ * (the model's text is the file's text shifted, not a different shape);
361
+ * - at least one line is not blank.
362
+ *
363
+ * The shift is measured in columns with a tab counted as 4, 2 or 8 spaces
364
+ * (the first that makes the shift constant), and `newString` is moved by the
365
+ * same number of columns in the file's own style, so a tab-indented file stays
366
+ * tab-indented. Only leading whitespace is ever changed.
367
+ */
368
+ export function resolveIndentedMatch(
369
+ content: string,
370
+ oldString: string,
371
+ newString: string,
372
+ ): IndentedMatch | null {
373
+ const starts = indentedMatchStarts(content, oldString)
374
+ if (starts.length !== 1) return null
375
+ const found = starts[0] as number
376
+ const wanted = oldString.split('\n')
377
+ const endsWithNewline = wanted.length > 1 && wanted[wanted.length - 1] === ''
378
+ if (endsWithNewline) wanted.pop()
379
+ const lines = content.split('\n')
380
+
381
+ // Trailing whitespace on a matched line is compared away but the replaced
382
+ // span keeps it nowhere: new_string has none, so applying would silently
383
+ // delete it (a Markdown hard break, say). Refuse; the not-found error
384
+ // shows the whitespace.
385
+ for (let i = 0; i < wanted.length; i++) {
386
+ // biome-ignore lint/style/noNonNullAssertion: index < length
387
+ const fileLine = lines[found + i]!.replace(/\r$/, '')
388
+ if (fileLine !== fileLine.trimEnd()) return null
389
+ }
390
+
391
+ const pairs: { file: string; model: string }[] = []
392
+ for (let i = 0; i < wanted.length; i++) {
393
+ // biome-ignore lint/style/noNonNullAssertion: index < length
394
+ const model = wanted[i]!
395
+ if (isBlank(model)) continue
396
+ // biome-ignore lint/style/noNonNullAssertion: index < length
397
+ pairs.push({ file: leadingWhitespace(lines[found + i]!), model: leadingWhitespace(model) })
398
+ }
399
+
400
+ let tab = 0
401
+ let delta = 0
402
+ const modelTabs = pairs.some((p) => p.model.includes('\t'))
403
+ const fileTabs = pairs.some((p) => p.file.includes('\t'))
404
+ // A model writing tabs into a space-indented file means the file's own
405
+ // indent unit per tab; guess 4 and a 2-space file gets the wrong nesting.
406
+ const unit = modelTabs && !fileTabs ? spaceIndentUnit(lines) : 0
407
+ const widths = unit > 0 ? [unit, ...TAB_WIDTHS.filter((w) => w !== unit)] : TAB_WIDTHS
408
+ for (const candidate of widths) {
409
+ const [head, ...rest] = pairs
410
+ if (head === undefined) return null
411
+ const shift = indentWidth(head.file, candidate) - indentWidth(head.model, candidate)
412
+ if (
413
+ rest.every((p) => indentWidth(p.file, candidate) - indentWidth(p.model, candidate) === shift)
414
+ ) {
415
+ tab = candidate
416
+ delta = shift
417
+ break
418
+ }
419
+ }
420
+ if (tab === 0) return null
421
+
422
+ const fileUsesTabs = pairs.some((p) => p.file.includes('\t'))
423
+ const render = (width: number): string => {
424
+ if (!fileUsesTabs) return ' '.repeat(width)
425
+ return '\t'.repeat(Math.floor(width / tab)) + ' '.repeat(width % tab)
426
+ }
427
+ const modelUsesTabs = pairs.some((p) => p.model.includes('\t'))
428
+ const shifted =
429
+ delta === 0 && fileUsesTabs === modelUsesTabs
430
+ ? newString
431
+ : newString
432
+ .split('\n')
433
+ .map((line) => {
434
+ if (isBlank(line)) return line
435
+ const indent = leadingWhitespace(line)
436
+ const width = Math.max(0, indentWidth(indent, tab) + delta)
437
+ return render(width) + line.slice(indent.length)
438
+ })
439
+ .join('\n')
440
+
441
+ let start = 0
442
+ for (let i = 0; i < found; i++) start += (lines[i] as string).length + 1
443
+ let end = start
444
+ for (let i = 0; i < wanted.length; i++)
445
+ end += (lines[found + i] as string).length + (i < wanted.length - 1 ? 1 : 0)
446
+ if (endsWithNewline) {
447
+ if (content[end] === '\n') end += 1
448
+ } else if (content[end - 1] === '\r') {
449
+ end -= 1
450
+ }
451
+ return { span: content.slice(start, end), newString: shifted }
452
+ }
453
+
454
+ /** How a line's indentation reads, for a message: "2 tabs", "4 spaces", "none". */
455
+ export function describeIndent(line: string): string {
456
+ const indent = leadingWhitespace(line)
457
+ if (indent === '') return 'no indentation'
458
+ const tabs = [...indent].filter((c) => c === '\t').length
459
+ const spaces = indent.length - tabs
460
+ const parts: string[] = []
461
+ if (tabs > 0) parts.push(`${tabs} ${tabs === 1 ? 'tab' : 'tabs'}`)
462
+ if (spaces > 0) parts.push(`${spaces} ${spaces === 1 ? 'space' : 'spaces'}`)
463
+ return parts.join(' and ')
464
+ }
465
+
466
+ /** A line with its indentation and trailing whitespace made visible: `→` is a tab, `·` a space. */
467
+ export function showWhitespace(line: string): string {
468
+ const indent = leadingWhitespace(line)
469
+ const body = line.slice(indent.length).replace(/[ \t\r]+$/, (tail) => {
470
+ return tail.replaceAll('\t', '→').replaceAll(' ', '·').replaceAll('\r', '⏎')
471
+ })
472
+ return indent.replaceAll('\t', '→').replaceAll(' ', '·') + body
473
+ }
@@ -267,7 +267,7 @@ const modelInputSchema: Record<string, unknown> = {
267
267
  old_string: {
268
268
  type: 'string',
269
269
  description:
270
- 'For a single change: exact unique text from the file, without read-tool line-number prefixes. Must not be empty. Do not send together with edits.',
270
+ 'For a single change: exact unique text from the file, without the line number and arrow that read puts in front of each line. Must not be empty. Do not send together with edits.',
271
271
  },
272
272
  new_string: {
273
273
  type: 'string',
@@ -329,7 +329,8 @@ const modelInputSchema: Record<string, unknown> = {
329
329
  properties: {
330
330
  old_string: {
331
331
  type: 'string',
332
- description: 'Exact text from the file at this point in the sequence.',
332
+ description:
333
+ 'Exact text from the file at this point in the sequence, without the line number and arrow from read.',
333
334
  },
334
335
  new_string: {
335
336
  type: 'string',
@@ -411,6 +412,11 @@ type EditAdmission =
411
412
  | { success: false; output: ''; error: string; facts: ToolFacts }
412
413
  | { success: true; result: ReturnType<typeof applyEdit>; unreadNote?: string }
413
414
 
415
+ /** The reply line for an edit that applied after its indentation was adjusted; empty otherwise. */
416
+ function adjustedNote(notes: readonly string[]): string {
417
+ return notes.length === 0 ? '' : ` Note: ${notes.join(' ')}`
418
+ }
419
+
414
420
  /** Appended to the result of an edit that was applied to a file the session had not read. */
415
421
  const UNREAD_APPLIED_NOTE = '(file was not read before; the edit matched exactly and was applied)'
416
422
 
@@ -444,7 +450,9 @@ function admitAgainstRead(
444
450
  if (tracker && !tracker.hasRead(key)) {
445
451
  if (!content.includes('\u0000') && operations.every((op) => op.operation === 'replace')) {
446
452
  const applied = applyEdit(content, operations)
447
- if (applied.success) {
453
+ // Only an exact match counts for a file nobody read; a match found by
454
+ // adjusting indentation is not the model knowing the text.
455
+ if (applied.success && applied.notes.length === 0) {
448
456
  tracker.recordRead(key, content)
449
457
  return { success: true, result: applied, unreadNote: UNREAD_APPLIED_NOTE }
450
458
  }
@@ -558,7 +566,8 @@ async function refuseEditBeforeReview(
558
566
  !content.includes('\u0000') &&
559
567
  normalized.operations.every((op) => op.operation === 'replace')
560
568
  ) {
561
- if (applyEdit(content, normalized.operations).success) return undefined
569
+ const exact = applyEdit(content, normalized.operations)
570
+ if (exact.success && exact.notes.length === 0) return undefined
562
571
  }
563
572
  const shown = unreadEditShownError(key, content)
564
573
  if (shown !== undefined) tracker.recordRead(key, content)
@@ -584,7 +593,7 @@ async function refuseEditBeforeReview(
584
593
  export const EditTool = defineTool({
585
594
  name: 'edit',
586
595
  description:
587
- 'Makes targeted edits to a file using exact string find-and-replace or line insertion. To change an existing file, use `edit`: `write` overwrites the whole body and discards earlier work on partial failure, while `edit` keeps the rest of the file byte-for-byte intact and is recoverable: if a single edit fails (old_string/oldStr ambiguous, broader restructuring needed), follow up with another `edit` instead of re-emitting the entire file via `write`. The old_string/oldStr must be unique in the file unless replace_all is true. For insertions, pass insertLine plus new_string/newStr; use insertLine: "end" to extend a file at the end. Keep new_string/newStr under 12000 characters, because a longer payload can be cut off mid-call and fail; use repeated bounded edits for long sections. Preserves file formatting and indentation. To make several changes to one file that only make sense together, send them as `edits` (and then no top-level old_string/new_string; for a single change leave `edits` out): a list of {old_string, new_string} applied in order and committed as one write — if any of them does not apply, nothing is written and the reply names which one, so the file is never left half-changed. An edit that would leave a `.ipynb` file as invalid notebook JSON is refused and the file is unchanged.',
596
+ 'Makes targeted edits to a file using exact string find-and-replace or line insertion. Read the file with `read` first (a shell read does not count); a successful edit result is the confirmation, so do not read the file back. To change an existing file, use `edit`: `write` overwrites the whole body and discards earlier work on partial failure, while `edit` keeps the rest of the file byte-for-byte intact and is recoverable: if a single edit fails (old_string/oldStr ambiguous, broader restructuring needed), follow up with another `edit` instead of re-emitting the entire file via `write`. The old_string/oldStr must be unique in the file unless replace_all is true. For insertions, pass insertLine plus new_string/newStr; use insertLine: "end" to extend a file at the end. Keep new_string/newStr under 12000 characters, because a longer payload can be cut off mid-call and fail; use repeated bounded edits for long sections. Preserves file formatting and indentation. Copy old_string from read output after the arrow (→) and keep the tabs and spaces that follow it. If only the indentation is off and the lines match in exactly one place, the edit is applied with the indentation adjusted and the reply says so. To make several changes to one file that only make sense together, send them as `edits` (and then no top-level old_string/new_string; for a single change leave `edits` out): a list of {old_string, new_string} applied in order and committed as one write — if any of them does not apply, nothing is written and the reply names every one that failed, so the file is never left half-changed. An edit that would leave a `.ipynb` file as invalid notebook JSON is refused and the file is unchanged.',
588
597
  inputSchema,
589
598
  modelInputSchema,
590
599
  enforceModelInput: true,
@@ -725,7 +734,7 @@ export const EditTool = defineTool({
725
734
  const changed = editFacts(parsed.data.path, result.replacements, content, result.content)
726
735
  return {
727
736
  success: true as const,
728
- output: `Edited ${parsed.data.path}: ${result.replacements} replacement(s) (+${changed.diff.added} -${changed.diff.removed}) [sandboxed]${admitted.unreadNote ? ` ${admitted.unreadNote}` : ''}. ${CURRENT_ON_DISK}`,
737
+ output: `Edited ${parsed.data.path}: ${result.replacements} replacement(s) (+${changed.diff.added} -${changed.diff.removed}) [sandboxed]${admitted.unreadNote ? ` ${admitted.unreadNote}` : ''}. ${CURRENT_ON_DISK}${adjustedNote(result.notes)}`,
729
738
  data: {
730
739
  path: parsed.data.path,
731
740
  replacements: result.replacements,
@@ -756,7 +765,7 @@ export const EditTool = defineTool({
756
765
  const changed = editFacts(hostPath, result.replacements, content, result.content)
757
766
  return {
758
767
  success: true as const,
759
- output: `Edited ${hostPath}: ${result.replacements} replacement(s) (+${changed.diff.added} -${changed.diff.removed})${admitted.unreadNote ? ` ${admitted.unreadNote}` : ''}. ${CURRENT_ON_DISK}`,
768
+ output: `Edited ${hostPath}: ${result.replacements} replacement(s) (+${changed.diff.added} -${changed.diff.removed})${admitted.unreadNote ? ` ${admitted.unreadNote}` : ''}. ${CURRENT_ON_DISK}${adjustedNote(result.notes)}`,
760
769
  data: { path: hostPath, replacements: result.replacements },
761
770
  facts: changed.facts,
762
771
  }
@@ -196,3 +196,26 @@ export function judgeExit(command: string, exitCode: number): ExitJudgement {
196
196
  const note = questionNote(parsed.segments[parsed.segments.length - 1] as string)
197
197
  return note === undefined ? PLAIN_FAILURE : { isError: false, note }
198
198
  }
199
+
200
+ const RUNTIME_PROGRAMS = ['node', 'npm', 'npx', 'pnpm', 'python', 'python3', 'cargo', 'rustc']
201
+
202
+ /**
203
+ * A short next step for a command the shell could not find (exit 127).
204
+ *
205
+ * Only a runtime the model is likely to want again is named; any other missing
206
+ * command keeps the plain failure. The hint points at one lookup and at keeping
207
+ * the working command, so the next attempts do not probe the machine again.
208
+ */
209
+ export function commandNotFoundHint(
210
+ exitCode: number | undefined,
211
+ stderr: string,
212
+ ): string | undefined {
213
+ if (exitCode !== 127) return undefined
214
+ for (const program of RUNTIME_PROGRAMS) {
215
+ const found = new RegExp(`(?:^|[\\s:])${program}: (?:command )?not found`, 'm')
216
+ if (found.test(stderr)) {
217
+ return `[${program} is not on this shell's PATH. Look it up once (command -v ${program}, or the tool's usual install folder) and call it by that full path. On WSL a Windows install is ${program}.exe and takes Windows paths (wslpath -w). Keep the command that works and reuse it.]`
218
+ }
219
+ }
220
+ return undefined
221
+ }
@@ -24,6 +24,7 @@ export type {
24
24
  SkillDirectoryRequest,
25
25
  SkillDirectoryResolver,
26
26
  SkillToolOptions,
27
+ SkillToolShellOptions,
27
28
  } from './skill.js'
28
29
  export {
29
30
  WEB_FETCH_TOOL_NAME,
@@ -36,6 +37,8 @@ export { RUN_CODE_TOOL_NAME, buildRunCodeTool } from './run-code.js'
36
37
  export { LsTool } from './ls.js'
37
38
  export { SearchToolsTool } from './search-tools.js'
38
39
  export { VerifyOutputsTool } from './verify-outputs.js'
40
+ export { PresentFileTool, MAX_PRESENTED_FILES } from './present-file.js'
41
+ export type { PresentedFile } from './present-file.js'
39
42
  export { ViewImageTool, createViewImageTool } from './view-image.js'
40
43
  export type { ViewImageToolOptions } from './view-image.js'
41
44
  export { createStructuredOutputTool, STRUCTURED_OUTPUT_TOOL_NAME } from './structuredOutput.js'
@@ -0,0 +1,127 @@
1
+ import { constants } from 'node:fs'
2
+ import { access, stat } from 'node:fs/promises'
3
+ import { basename, resolve } from 'node:path'
4
+ import { z } from 'zod'
5
+ import type { ToolDefinition } from '../../types/tool/index.js'
6
+ import { defineTool } from '../defineTool.js'
7
+ import { resolveWithinAnyReal, toolRoots } from '../paths.js'
8
+
9
+ /** How many files one call may hand over. */
10
+ export const MAX_PRESENTED_FILES = 10
11
+
12
+ const inputSchema = z.object({
13
+ paths: z
14
+ .array(z.string().min(1))
15
+ .min(1)
16
+ .max(MAX_PRESENTED_FILES)
17
+ .describe('Paths of finished files to hand over. Each is one file, not a folder.'),
18
+ caption: z
19
+ .string()
20
+ .max(300)
21
+ .optional()
22
+ .describe('One short line saying what the files are, shown beside them.'),
23
+ })
24
+
25
+ export interface PresentedFile {
26
+ readonly path: string
27
+ /** The file the path led to when it was checked, links followed. */
28
+ readonly real: string
29
+ readonly bytes: number
30
+ }
31
+
32
+ async function check(
33
+ roots: readonly string[],
34
+ requested: string,
35
+ ): Promise<{ file: PresentedFile } | { refused: string }> {
36
+ let real: string
37
+ try {
38
+ real = await resolveWithinAnyReal(roots, requested)
39
+ } catch (error) {
40
+ const detail = error instanceof Error ? error.message : String(error)
41
+ return {
42
+ refused: /escapes the working directory/.test(detail)
43
+ ? `${requested}: outside the folders this session may reach. Ask the person to add the folder, or copy the file into the work folder.`
44
+ : `${requested}: ${detail}`,
45
+ }
46
+ }
47
+ let info: Awaited<ReturnType<typeof stat>>
48
+ try {
49
+ info = await stat(real)
50
+ } catch {
51
+ return { refused: `${requested}: no such file.` }
52
+ }
53
+ if (info.isDirectory())
54
+ return { refused: `${requested}: a folder, not a file. Name the files inside it.` }
55
+ if (!info.isFile()) return { refused: `${requested}: not a regular file.` }
56
+ try {
57
+ await access(real, constants.R_OK)
58
+ } catch {
59
+ return { refused: `${requested}: the file cannot be read.` }
60
+ }
61
+ // The path the person would know (before links are followed), and where it led now: the host
62
+ // shows the first and refuses the file if the second changes.
63
+ return { file: { path: resolve(roots[0] as string, requested), real, bytes: info.size } }
64
+ }
65
+
66
+ /**
67
+ * Hands finished files to the person. The call checks that each path is one
68
+ * regular, readable file inside the folders the session reaches (a link that
69
+ * leads out is judged by where it ends), then reports them as a `shared`
70
+ * fact that a host draws as its own row or card. It copies nothing and
71
+ * returns no bytes to the model.
72
+ */
73
+ export const PresentFileTool: ToolDefinition<z.infer<typeof inputSchema>> = defineTool({
74
+ name: 'present_file',
75
+ description:
76
+ "Show a file to the person: from the scratch folder or to open now; one already there, say its path. A file you wrote in the person's own folder is already there. Each path must be a regular file, not a folder.",
77
+ inputSchema,
78
+ category: 'filesystem',
79
+ permissions: ['file_read'],
80
+ readOnly: true,
81
+ destructive: false,
82
+ concurrencySafe: true,
83
+ presentCall: (input) => ({
84
+ kind: 'generic',
85
+ label: `Share ${input.paths.map((path) => basename(path)).join(', ')}`,
86
+ presentation: 'activity',
87
+ }),
88
+ async execute(input, context) {
89
+ if (context.sandbox) {
90
+ const message =
91
+ "present_file is not available in a sandboxed run: the files are not on the person's machine. Say where they are instead."
92
+ return { success: false, output: message, error: message }
93
+ }
94
+ const roots = toolRoots(context)
95
+ const files: PresentedFile[] = []
96
+ const refused: string[] = []
97
+ const seen = new Set<string>()
98
+ for (const requested of input.paths) {
99
+ const result = await check(roots, requested)
100
+ if ('refused' in result) {
101
+ refused.push(result.refused)
102
+ continue
103
+ }
104
+ if (seen.has(result.file.path)) continue
105
+ seen.add(result.file.path)
106
+ files.push(result.file)
107
+ }
108
+ if (files.length === 0) {
109
+ const message = `Nothing was shared.\n${refused.join('\n')}`
110
+ return { success: false, output: message, error: message }
111
+ }
112
+ const lines = [
113
+ `Shared ${files.map((file) => file.path).join(', ')}.`,
114
+ ...(refused.length > 0 ? [`Not shared:\n${refused.join('\n')}`] : []),
115
+ ]
116
+ return {
117
+ success: true,
118
+ output: lines.join('\n'),
119
+ facts: {
120
+ kind: 'shared',
121
+ files,
122
+ ...(input.caption ? { caption: input.caption } : {}),
123
+ },
124
+ data: { files, ...(input.caption ? { caption: input.caption } : {}) },
125
+ }
126
+ },
127
+ })