@namzu/sdk 70.0.0 → 71.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (409) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/dist/authorization/bare-repository.d.ts +21 -0
  3. package/dist/authorization/bare-repository.d.ts.map +1 -0
  4. package/dist/authorization/bare-repository.js +62 -0
  5. package/dist/authorization/bare-repository.js.map +1 -0
  6. package/dist/authorization/command-line.d.ts.map +1 -1
  7. package/dist/authorization/command-line.js +10 -3
  8. package/dist/authorization/command-line.js.map +1 -1
  9. package/dist/authorization/gate.d.ts +7 -0
  10. package/dist/authorization/gate.d.ts.map +1 -1
  11. package/dist/authorization/gate.js +4 -0
  12. package/dist/authorization/gate.js.map +1 -1
  13. package/dist/authorization/protected-paths.d.ts.map +1 -1
  14. package/dist/authorization/protected-paths.js +46 -1
  15. package/dist/authorization/protected-paths.js.map +1 -1
  16. package/dist/authorization/readonly-commands.d.ts +17 -5
  17. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  18. package/dist/authorization/readonly-commands.js +77 -6
  19. package/dist/authorization/readonly-commands.js.map +1 -1
  20. package/dist/authorization/readonly-flags.d.ts.map +1 -1
  21. package/dist/authorization/readonly-flags.js +98 -0
  22. package/dist/authorization/readonly-flags.js.map +1 -1
  23. package/dist/authorization/shell-lexer.d.ts +15 -0
  24. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  25. package/dist/authorization/shell-lexer.js +108 -3
  26. package/dist/authorization/shell-lexer.js.map +1 -1
  27. package/dist/authorization/shell-paths.d.ts.map +1 -1
  28. package/dist/authorization/shell-paths.js +276 -0
  29. package/dist/authorization/shell-paths.js.map +1 -1
  30. package/dist/authorization/shell-session-state.d.ts +47 -0
  31. package/dist/authorization/shell-session-state.d.ts.map +1 -0
  32. package/dist/authorization/shell-session-state.js +70 -0
  33. package/dist/authorization/shell-session-state.js.map +1 -0
  34. package/dist/authorization/shell-session.d.ts +9 -0
  35. package/dist/authorization/shell-session.d.ts.map +1 -0
  36. package/dist/authorization/shell-session.js +19 -0
  37. package/dist/authorization/shell-session.js.map +1 -0
  38. package/dist/authorization/skill-grant.d.ts.map +1 -1
  39. package/dist/authorization/skill-grant.js +1 -0
  40. package/dist/authorization/skill-grant.js.map +1 -1
  41. package/dist/compaction/extractor.d.ts.map +1 -1
  42. package/dist/compaction/extractor.js +2 -0
  43. package/dist/compaction/extractor.js.map +1 -1
  44. package/dist/compaction/hooks.d.ts +16 -0
  45. package/dist/compaction/hooks.d.ts.map +1 -1
  46. package/dist/compaction/hooks.js +26 -1
  47. package/dist/compaction/hooks.js.map +1 -1
  48. package/dist/compaction/manual.d.ts.map +1 -1
  49. package/dist/compaction/manual.js +6 -1
  50. package/dist/compaction/manual.js.map +1 -1
  51. package/dist/compaction/restore.d.ts.map +1 -1
  52. package/dist/compaction/restore.js +3 -2
  53. package/dist/compaction/restore.js.map +1 -1
  54. package/dist/config/runtime.d.ts +2 -0
  55. package/dist/config/runtime.d.ts.map +1 -1
  56. package/dist/config/runtime.js +7 -0
  57. package/dist/config/runtime.js.map +1 -1
  58. package/dist/connector/mcp/client.d.ts +7 -0
  59. package/dist/connector/mcp/client.d.ts.map +1 -1
  60. package/dist/connector/mcp/client.js +54 -4
  61. package/dist/connector/mcp/client.js.map +1 -1
  62. package/dist/connector/web/types.d.ts +8 -0
  63. package/dist/connector/web/types.d.ts.map +1 -1
  64. package/dist/constants/compaction/index.d.ts.map +1 -1
  65. package/dist/constants/compaction/index.js +1 -1
  66. package/dist/constants/compaction/index.js.map +1 -1
  67. package/dist/execution/code-runtime/worker-program.d.ts +1 -1
  68. package/dist/execution/code-runtime/worker-program.d.ts.map +1 -1
  69. package/dist/execution/code-runtime/worker-program.js +9 -5
  70. package/dist/execution/code-runtime/worker-program.js.map +1 -1
  71. package/dist/execution/local.d.ts.map +1 -1
  72. package/dist/execution/local.js +6 -1
  73. package/dist/execution/local.js.map +1 -1
  74. package/dist/peers/index.d.ts +2 -2
  75. package/dist/peers/index.d.ts.map +1 -1
  76. package/dist/peers/index.js +1 -1
  77. package/dist/peers/index.js.map +1 -1
  78. package/dist/peers/record.d.ts +74 -0
  79. package/dist/peers/record.d.ts.map +1 -1
  80. package/dist/peers/record.js +41 -1
  81. package/dist/peers/record.js.map +1 -1
  82. package/dist/peers/registry.d.ts.map +1 -1
  83. package/dist/peers/registry.js +20 -3
  84. package/dist/peers/registry.js.map +1 -1
  85. package/dist/plugin/bin-path.d.ts +41 -0
  86. package/dist/plugin/bin-path.d.ts.map +1 -0
  87. package/dist/plugin/bin-path.js +146 -0
  88. package/dist/plugin/bin-path.js.map +1 -0
  89. package/dist/plugin/common-layout/read.js +1 -1
  90. package/dist/plugin/common-layout/read.js.map +1 -1
  91. package/dist/plugin/common-layout-names.d.ts.map +1 -1
  92. package/dist/plugin/common-layout-names.js +0 -1
  93. package/dist/plugin/common-layout-names.js.map +1 -1
  94. package/dist/plugin/hook-module/scan.d.ts +16 -0
  95. package/dist/plugin/hook-module/scan.d.ts.map +1 -1
  96. package/dist/plugin/hook-module/scan.js +67 -2
  97. package/dist/plugin/hook-module/scan.js.map +1 -1
  98. package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
  99. package/dist/plugin/hook-module/worker-source.js +56 -0
  100. package/dist/plugin/hook-module/worker-source.js.map +1 -1
  101. package/dist/plugin/lifecycle.d.ts +21 -0
  102. package/dist/plugin/lifecycle.d.ts.map +1 -1
  103. package/dist/plugin/lifecycle.js +64 -0
  104. package/dist/plugin/lifecycle.js.map +1 -1
  105. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  106. package/dist/plugin/shell-hook-tool-names.js +1 -0
  107. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  108. package/dist/plugin/shell-hook.d.ts +1 -1
  109. package/dist/plugin/shell-hook.d.ts.map +1 -1
  110. package/dist/plugin/shell-hook.js +22 -4
  111. package/dist/plugin/shell-hook.js.map +1 -1
  112. package/dist/public-runtime.d.ts +8 -6
  113. package/dist/public-runtime.d.ts.map +1 -1
  114. package/dist/public-runtime.js +8 -5
  115. package/dist/public-runtime.js.map +1 -1
  116. package/dist/public-tools.d.ts +6 -2
  117. package/dist/public-tools.d.ts.map +1 -1
  118. package/dist/public-tools.js +6 -2
  119. package/dist/public-tools.js.map +1 -1
  120. package/dist/public-types.d.ts +2 -2
  121. package/dist/public-types.d.ts.map +1 -1
  122. package/dist/runtime/jobs/monitor-stream.d.ts +9 -1
  123. package/dist/runtime/jobs/monitor-stream.d.ts.map +1 -1
  124. package/dist/runtime/jobs/monitor-stream.js +13 -4
  125. package/dist/runtime/jobs/monitor-stream.js.map +1 -1
  126. package/dist/runtime/jobs/registry.d.ts +4 -0
  127. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  128. package/dist/runtime/jobs/registry.js +12 -2
  129. package/dist/runtime/jobs/registry.js.map +1 -1
  130. package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -1
  131. package/dist/runtime/query/auto-review/git-status.js +3 -2
  132. package/dist/runtime/query/auto-review/git-status.js.map +1 -1
  133. package/dist/runtime/query/executor.d.ts +16 -6
  134. package/dist/runtime/query/executor.d.ts.map +1 -1
  135. package/dist/runtime/query/executor.js +60 -5
  136. package/dist/runtime/query/executor.js.map +1 -1
  137. package/dist/runtime/query/index.d.ts.map +1 -1
  138. package/dist/runtime/query/index.js +2 -2
  139. package/dist/runtime/query/index.js.map +1 -1
  140. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  141. package/dist/runtime/query/iteration/outstanding-work.js +14 -4
  142. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  143. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  144. package/dist/runtime/query/iteration/phases/compaction.js +11 -1
  145. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  146. package/dist/runtime/query/iteration/phases/tool-review.d.ts +2 -0
  147. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  148. package/dist/runtime/query/iteration/phases/tool-review.js +19 -8
  149. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  150. package/dist/runtime/query/path-escalation.d.ts +6 -0
  151. package/dist/runtime/query/path-escalation.d.ts.map +1 -1
  152. package/dist/runtime/query/path-escalation.js +58 -4
  153. package/dist/runtime/query/path-escalation.js.map +1 -1
  154. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  155. package/dist/runtime/query/review-policy.js +4 -2
  156. package/dist/runtime/query/review-policy.js.map +1 -1
  157. package/dist/runtime/query/steering.d.ts +11 -2
  158. package/dist/runtime/query/steering.d.ts.map +1 -1
  159. package/dist/runtime/query/steering.js +18 -4
  160. package/dist/runtime/query/steering.js.map +1 -1
  161. package/dist/sandbox/provider/local.d.ts.map +1 -1
  162. package/dist/sandbox/provider/local.js +3 -1
  163. package/dist/sandbox/provider/local.js.map +1 -1
  164. package/dist/schedules/describe.d.ts.map +1 -1
  165. package/dist/schedules/describe.js +2 -0
  166. package/dist/schedules/describe.js.map +1 -1
  167. package/dist/schedules/evaluate.d.ts +4 -0
  168. package/dist/schedules/evaluate.d.ts.map +1 -1
  169. package/dist/schedules/evaluate.js +26 -1
  170. package/dist/schedules/evaluate.js.map +1 -1
  171. package/dist/schedules/index.d.ts +3 -1
  172. package/dist/schedules/index.d.ts.map +1 -1
  173. package/dist/schedules/index.js +2 -1
  174. package/dist/schedules/index.js.map +1 -1
  175. package/dist/schedules/next-fire.d.ts.map +1 -1
  176. package/dist/schedules/next-fire.js +10 -0
  177. package/dist/schedules/next-fire.js.map +1 -1
  178. package/dist/schedules/spec.d.ts +9 -0
  179. package/dist/schedules/spec.d.ts.map +1 -1
  180. package/dist/schedules/spec.js +33 -0
  181. package/dist/schedules/spec.js.map +1 -1
  182. package/dist/schedules/types.d.ts +32 -4
  183. package/dist/schedules/types.d.ts.map +1 -1
  184. package/dist/schedules/types.js +3 -2
  185. package/dist/schedules/types.js.map +1 -1
  186. package/dist/schedules/watch.d.ts +23 -0
  187. package/dist/schedules/watch.d.ts.map +1 -0
  188. package/dist/schedules/watch.js +46 -0
  189. package/dist/schedules/watch.js.map +1 -0
  190. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  191. package/dist/session/workspace/git-worktree.js +2 -1
  192. package/dist/session/workspace/git-worktree.js.map +1 -1
  193. package/dist/skills/arguments.d.ts +58 -0
  194. package/dist/skills/arguments.d.ts.map +1 -0
  195. package/dist/skills/arguments.js +208 -0
  196. package/dist/skills/arguments.js.map +1 -0
  197. package/dist/skills/index.d.ts +3 -1
  198. package/dist/skills/index.d.ts.map +1 -1
  199. package/dist/skills/index.js +1 -0
  200. package/dist/skills/index.js.map +1 -1
  201. package/dist/skills/inline-shell.d.ts +17 -0
  202. package/dist/skills/inline-shell.d.ts.map +1 -1
  203. package/dist/skills/inline-shell.js +1232 -14
  204. package/dist/skills/inline-shell.js.map +1 -1
  205. package/dist/store/session-index/index.d.ts +5 -0
  206. package/dist/store/session-index/index.d.ts.map +1 -1
  207. package/dist/store/session-index/index.js +5 -1
  208. package/dist/store/session-index/index.js.map +1 -1
  209. package/dist/store/session-index/rebuild.d.ts +18 -0
  210. package/dist/store/session-index/rebuild.d.ts.map +1 -1
  211. package/dist/store/session-index/rebuild.js +79 -5
  212. package/dist/store/session-index/rebuild.js.map +1 -1
  213. package/dist/store/session-index/sqlite.d.ts +8 -0
  214. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  215. package/dist/store/session-index/sqlite.js +23 -1
  216. package/dist/store/session-index/sqlite.js.map +1 -1
  217. package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
  218. package/dist/tools/builtins/bash-cwd.js +2 -0
  219. package/dist/tools/builtins/bash-cwd.js.map +1 -1
  220. package/dist/tools/builtins/bash.d.ts.map +1 -1
  221. package/dist/tools/builtins/bash.js +79 -11
  222. package/dist/tools/builtins/bash.js.map +1 -1
  223. package/dist/tools/builtins/exit-semantics.d.ts +6 -0
  224. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  225. package/dist/tools/builtins/exit-semantics.js +10 -0
  226. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  227. package/dist/tools/builtins/glob.d.ts.map +1 -1
  228. package/dist/tools/builtins/glob.js +68 -13
  229. package/dist/tools/builtins/glob.js.map +1 -1
  230. package/dist/tools/builtins/grep.d.ts.map +1 -1
  231. package/dist/tools/builtins/grep.js +37 -12
  232. package/dist/tools/builtins/grep.js.map +1 -1
  233. package/dist/tools/builtins/index.d.ts +11 -0
  234. package/dist/tools/builtins/index.d.ts.map +1 -1
  235. package/dist/tools/builtins/index.js +14 -0
  236. package/dist/tools/builtins/index.js.map +1 -1
  237. package/dist/tools/builtins/job.js +1 -1
  238. package/dist/tools/builtins/job.js.map +1 -1
  239. package/dist/tools/builtins/monitor.d.ts +1 -1
  240. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  241. package/dist/tools/builtins/monitor.js +4 -2
  242. package/dist/tools/builtins/monitor.js.map +1 -1
  243. package/dist/tools/builtins/notebook-cells.d.ts +31 -0
  244. package/dist/tools/builtins/notebook-cells.d.ts.map +1 -0
  245. package/dist/tools/builtins/notebook-cells.js +160 -0
  246. package/dist/tools/builtins/notebook-cells.js.map +1 -0
  247. package/dist/tools/builtins/notebook-edit.d.ts +8 -0
  248. package/dist/tools/builtins/notebook-edit.d.ts.map +1 -0
  249. package/dist/tools/builtins/notebook-edit.js +249 -0
  250. package/dist/tools/builtins/notebook-edit.js.map +1 -0
  251. package/dist/tools/builtins/notebook-guard.d.ts.map +1 -1
  252. package/dist/tools/builtins/notebook-guard.js +2 -1
  253. package/dist/tools/builtins/notebook-guard.js.map +1 -1
  254. package/dist/tools/builtins/push-notification.d.ts +49 -0
  255. package/dist/tools/builtins/push-notification.d.ts.map +1 -0
  256. package/dist/tools/builtins/push-notification.js +107 -0
  257. package/dist/tools/builtins/push-notification.js.map +1 -0
  258. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  259. package/dist/tools/builtins/read-file.js +8 -3
  260. package/dist/tools/builtins/read-file.js.map +1 -1
  261. package/dist/tools/builtins/read-media.d.ts.map +1 -1
  262. package/dist/tools/builtins/read-media.js +2 -1
  263. package/dist/tools/builtins/read-media.js.map +1 -1
  264. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  265. package/dist/tools/builtins/read-render.js +5 -3
  266. package/dist/tools/builtins/read-render.js.map +1 -1
  267. package/dist/tools/builtins/search-support.d.ts +6 -4
  268. package/dist/tools/builtins/search-support.d.ts.map +1 -1
  269. package/dist/tools/builtins/search-support.js +15 -3
  270. package/dist/tools/builtins/search-support.js.map +1 -1
  271. package/dist/tools/builtins/skill.d.ts.map +1 -1
  272. package/dist/tools/builtins/skill.js +28 -8
  273. package/dist/tools/builtins/skill.js.map +1 -1
  274. package/dist/tools/builtins/sleep-guard.d.ts +20 -0
  275. package/dist/tools/builtins/sleep-guard.d.ts.map +1 -1
  276. package/dist/tools/builtins/sleep-guard.js +125 -1
  277. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  278. package/dist/tools/builtins/wait-for-job.js +1 -1
  279. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  280. package/dist/tools/builtins/web.d.ts +2 -0
  281. package/dist/tools/builtins/web.d.ts.map +1 -1
  282. package/dist/tools/builtins/web.js +97 -3
  283. package/dist/tools/builtins/web.js.map +1 -1
  284. package/dist/tools/command-shell.d.ts +50 -0
  285. package/dist/tools/command-shell.d.ts.map +1 -1
  286. package/dist/tools/command-shell.js +145 -0
  287. package/dist/tools/command-shell.js.map +1 -1
  288. package/dist/tools/env-scrub.d.ts +2 -0
  289. package/dist/tools/env-scrub.d.ts.map +1 -1
  290. package/dist/tools/env-scrub.js +15 -1
  291. package/dist/tools/env-scrub.js.map +1 -1
  292. package/dist/tools/git-config-env.d.ts +55 -0
  293. package/dist/tools/git-config-env.d.ts.map +1 -0
  294. package/dist/tools/git-config-env.js +130 -0
  295. package/dist/tools/git-config-env.js.map +1 -0
  296. package/dist/tools/schedules/schedule-tool.d.ts +7 -0
  297. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  298. package/dist/tools/schedules/schedule-tool.js +72 -3
  299. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  300. package/dist/tools/schedules/types.d.ts +38 -2
  301. package/dist/tools/schedules/types.d.ts.map +1 -1
  302. package/dist/types/connector/mcp.d.ts +24 -0
  303. package/dist/types/connector/mcp.d.ts.map +1 -1
  304. package/dist/types/message/index.d.ts +21 -1
  305. package/dist/types/message/index.d.ts.map +1 -1
  306. package/dist/types/message/index.js +37 -2
  307. package/dist/types/message/index.js.map +1 -1
  308. package/dist/types/plugin/index.d.ts +10 -2
  309. package/dist/types/plugin/index.d.ts.map +1 -1
  310. package/dist/types/plugin/index.js.map +1 -1
  311. package/dist/types/tool/index.d.ts +6 -0
  312. package/dist/types/tool/index.d.ts.map +1 -1
  313. package/dist/types/tool/index.js.map +1 -1
  314. package/dist/utils/plain-terminal-text.d.ts +21 -0
  315. package/dist/utils/plain-terminal-text.d.ts.map +1 -0
  316. package/dist/utils/plain-terminal-text.js +156 -0
  317. package/dist/utils/plain-terminal-text.js.map +1 -0
  318. package/package.json +1 -1
  319. package/src/authorization/bare-repository.ts +70 -0
  320. package/src/authorization/command-line.ts +18 -4
  321. package/src/authorization/gate.ts +11 -0
  322. package/src/authorization/protected-paths.ts +45 -1
  323. package/src/authorization/readonly-commands.ts +75 -6
  324. package/src/authorization/readonly-flags.ts +103 -0
  325. package/src/authorization/shell-lexer.ts +126 -3
  326. package/src/authorization/shell-paths.ts +386 -0
  327. package/src/authorization/shell-session-state.ts +97 -0
  328. package/src/authorization/shell-session.ts +23 -0
  329. package/src/authorization/skill-grant.ts +1 -0
  330. package/src/compaction/extractor.ts +1 -0
  331. package/src/compaction/hooks.ts +43 -1
  332. package/src/compaction/manual.ts +6 -0
  333. package/src/compaction/restore.ts +3 -2
  334. package/src/config/runtime.ts +7 -0
  335. package/src/connector/mcp/client.ts +61 -4
  336. package/src/connector/web/types.ts +8 -0
  337. package/src/constants/compaction/index.ts +1 -1
  338. package/src/execution/code-runtime/worker-program.ts +9 -5
  339. package/src/execution/local.ts +6 -1
  340. package/src/peers/index.ts +8 -2
  341. package/src/peers/record.ts +45 -1
  342. package/src/peers/registry.ts +21 -5
  343. package/src/plugin/bin-path.ts +149 -0
  344. package/src/plugin/common-layout/read.ts +1 -1
  345. package/src/plugin/common-layout-names.ts +0 -1
  346. package/src/plugin/hook-module/scan.ts +74 -2
  347. package/src/plugin/hook-module/worker-source.ts +56 -0
  348. package/src/plugin/lifecycle.ts +67 -0
  349. package/src/plugin/shell-hook-tool-names.ts +1 -0
  350. package/src/plugin/shell-hook.ts +23 -4
  351. package/src/public-runtime.ts +21 -0
  352. package/src/public-tools.ts +32 -1
  353. package/src/public-types.ts +3 -1
  354. package/src/runtime/jobs/monitor-stream.ts +18 -4
  355. package/src/runtime/jobs/registry.ts +22 -2
  356. package/src/runtime/query/auto-review/git-status.ts +3 -2
  357. package/src/runtime/query/executor.ts +79 -5
  358. package/src/runtime/query/index.ts +5 -2
  359. package/src/runtime/query/iteration/outstanding-work.ts +22 -4
  360. package/src/runtime/query/iteration/phases/compaction.ts +14 -1
  361. package/src/runtime/query/iteration/phases/tool-review.ts +24 -7
  362. package/src/runtime/query/path-escalation.ts +52 -4
  363. package/src/runtime/query/review-policy.ts +5 -2
  364. package/src/runtime/query/steering.ts +32 -4
  365. package/src/sandbox/provider/local.ts +3 -1
  366. package/src/schedules/describe.ts +2 -0
  367. package/src/schedules/evaluate.ts +29 -1
  368. package/src/schedules/index.ts +9 -1
  369. package/src/schedules/next-fire.ts +9 -0
  370. package/src/schedules/spec.ts +42 -0
  371. package/src/schedules/types.ts +33 -3
  372. package/src/schedules/watch.ts +71 -0
  373. package/src/session/workspace/git-worktree.ts +3 -1
  374. package/src/skills/arguments.ts +250 -0
  375. package/src/skills/index.ts +10 -0
  376. package/src/skills/inline-shell.ts +1268 -14
  377. package/src/store/session-index/index.ts +10 -1
  378. package/src/store/session-index/rebuild.ts +81 -5
  379. package/src/store/session-index/sqlite.ts +30 -1
  380. package/src/tools/builtins/bash-cwd.ts +2 -0
  381. package/src/tools/builtins/bash.ts +93 -13
  382. package/src/tools/builtins/exit-semantics.ts +10 -0
  383. package/src/tools/builtins/glob.ts +79 -15
  384. package/src/tools/builtins/grep.ts +37 -10
  385. package/src/tools/builtins/index.ts +15 -0
  386. package/src/tools/builtins/job.ts +1 -1
  387. package/src/tools/builtins/monitor.ts +4 -2
  388. package/src/tools/builtins/notebook-cells.ts +196 -0
  389. package/src/tools/builtins/notebook-edit.ts +280 -0
  390. package/src/tools/builtins/notebook-guard.ts +2 -1
  391. package/src/tools/builtins/push-notification.ts +138 -0
  392. package/src/tools/builtins/read-file.ts +9 -3
  393. package/src/tools/builtins/read-media.ts +2 -1
  394. package/src/tools/builtins/read-render.ts +5 -3
  395. package/src/tools/builtins/search-support.ts +17 -3
  396. package/src/tools/builtins/skill.ts +27 -7
  397. package/src/tools/builtins/sleep-guard.ts +128 -1
  398. package/src/tools/builtins/wait-for-job.ts +1 -1
  399. package/src/tools/builtins/web.ts +100 -3
  400. package/src/tools/command-shell.ts +166 -0
  401. package/src/tools/env-scrub.ts +13 -1
  402. package/src/tools/git-config-env.ts +143 -0
  403. package/src/tools/schedules/schedule-tool.ts +79 -3
  404. package/src/tools/schedules/types.ts +47 -9
  405. package/src/types/connector/mcp.ts +25 -0
  406. package/src/types/message/index.ts +53 -1
  407. package/src/types/plugin/index.ts +10 -2
  408. package/src/types/tool/index.ts +6 -0
  409. package/src/utils/plain-terminal-text.ts +142 -0
@@ -0,0 +1,280 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import { z } from 'zod'
3
+ import type { ToolContext, ToolResult } from '../../types/tool/index.js'
4
+ import type { ToolFacts } from '../../types/tool/presentation.js'
5
+ import { defineTool } from '../defineTool.js'
6
+ import { resolveWithinAnyReal, toolRoots } from '../paths.js'
7
+ import { atomicWriteFile } from './atomic-write-file.js'
8
+ import { clip } from './classifier-input.js'
9
+ import { CURRENT_ON_DISK, movedSinceRead, staleFileError } from './content-fingerprint.js'
10
+ import { withFileMutationLock } from './file-mutation-lock.js'
11
+ import { lineDiff } from './line-diff.js'
12
+ import { applyNotebookEdit } from './notebook-cells.js'
13
+ import { isNotebookPath, notebookRefusal } from './notebook-guard.js'
14
+ import { NOTEBOOK_MAX_BYTES } from './read-media.js'
15
+
16
+ const inputSchema = z
17
+ .object({
18
+ notebook_path: z
19
+ .string()
20
+ .min(1)
21
+ .refine((value) => value.trim().length > 0, 'notebook_path must not be empty.')
22
+ .describe('The path of the Jupyter notebook (.ipynb) to edit.'),
23
+ cell_id: z
24
+ .string()
25
+ .optional()
26
+ .describe(
27
+ 'The ID of the cell to edit. When inserting, the new cell goes after the cell with this ID, or at the beginning when it is not given.',
28
+ ),
29
+ new_source: z
30
+ .string()
31
+ .optional()
32
+ .describe('The new source for the cell. Not needed to delete.'),
33
+ cell_type: z
34
+ .enum(['code', 'markdown'])
35
+ .optional()
36
+ .describe(
37
+ 'The type of the cell (code or markdown). When left out, a replaced cell keeps its type. Required when inserting.',
38
+ ),
39
+ edit_mode: z
40
+ .enum(['replace', 'insert', 'delete'])
41
+ .optional()
42
+ .describe('The kind of edit (replace, insert or delete). Defaults to replace.'),
43
+ })
44
+ .strict()
45
+
46
+ type NotebookEditInput = z.infer<typeof inputSchema>
47
+
48
+ const modelInputSchema: Record<string, unknown> = {
49
+ type: 'object',
50
+ properties: {
51
+ notebook_path: {
52
+ type: 'string',
53
+ description: 'The path of the Jupyter notebook (.ipynb) to edit.',
54
+ },
55
+ cell_id: {
56
+ type: 'string',
57
+ description:
58
+ 'The ID of the cell to edit. When inserting, the new cell goes after the cell with this ID, or at the beginning when it is not given.',
59
+ },
60
+ new_source: {
61
+ type: 'string',
62
+ description: 'The new source for the cell. Not needed to delete.',
63
+ },
64
+ cell_type: {
65
+ type: 'string',
66
+ enum: ['code', 'markdown'],
67
+ description:
68
+ 'The type of the cell (code or markdown). When left out, a replaced cell keeps its type. Required when inserting.',
69
+ },
70
+ edit_mode: {
71
+ type: 'string',
72
+ enum: ['replace', 'insert', 'delete'],
73
+ description: 'The kind of edit (replace, insert or delete). Defaults to replace.',
74
+ },
75
+ },
76
+ required: ['notebook_path'],
77
+ additionalProperties: false,
78
+ }
79
+
80
+ const SHAPES =
81
+ 'Replace: {"notebook_path":"a.ipynb","cell_id":"<id>","new_source":"print(1)"}. Insert after a cell: {"notebook_path":"a.ipynb","cell_id":"<id>","new_source":"# Title","cell_type":"markdown","edit_mode":"insert"} (leave out cell_id to insert at the top; cell_type is required). Delete: {"notebook_path":"a.ipynb","cell_id":"<id>","edit_mode":"delete"}.'
82
+
83
+ type Failure = { success: false; output: ''; error: string; facts?: ToolFacts }
84
+
85
+ function failure(error: string, facts?: ToolFacts): Failure {
86
+ return { success: false, output: '', error, ...(facts ? { facts } : {}) }
87
+ }
88
+
89
+ /** Why the notebook cannot be edited from what the session has read, or `undefined` when it can. */
90
+ function freshnessProblem(context: ToolContext, key: string, current: string): Failure | undefined {
91
+ const tracker = context.fileReadTracker
92
+ if (!tracker) return undefined
93
+ if (!tracker.hasRead(key)) {
94
+ return failure(
95
+ `${key} has not been read in this conversation, so no cell was changed. Read the notebook with the \`read\` tool (it shows each cell with its id), then call \`notebook_edit\` again.`,
96
+ { kind: 'failure', reason: 'not_read', subject: key },
97
+ )
98
+ }
99
+ if (movedSinceRead(tracker, key, current)) {
100
+ tracker.recordDriftObserved?.(key)
101
+ return failure(staleFileError(key), {
102
+ kind: 'failure',
103
+ reason: 'changed_on_disk',
104
+ subject: key,
105
+ })
106
+ }
107
+ return undefined
108
+ }
109
+
110
+ function record(context: ToolContext, key: string, content: string): void {
111
+ const tracker = context.fileReadTracker
112
+ if (!tracker) return
113
+ if (tracker.recordEdit && context.toolUseId) {
114
+ tracker.recordEdit(key, content, context.toolUseId)
115
+ return
116
+ }
117
+ tracker.recordRead(key, content)
118
+ }
119
+
120
+ async function readHost(path: string): Promise<string | undefined> {
121
+ try {
122
+ return await readFile(path, 'utf-8')
123
+ } catch (error) {
124
+ if ((error as { code?: unknown } | null)?.code === 'ENOENT') return undefined
125
+ throw error
126
+ }
127
+ }
128
+
129
+ /**
130
+ * What can be refused before a person is asked: arguments that cannot work, a
131
+ * notebook the session never read, one that moved since it was read. The text
132
+ * is the one `execute` gives.
133
+ */
134
+ async function refuseBeforeReview(
135
+ input: NotebookEditInput,
136
+ context: ToolContext,
137
+ ): Promise<{ readonly error: string; readonly facts?: ToolFacts } | undefined> {
138
+ const parsed = inputSchema.safeParse(input)
139
+ if (!parsed.success) return undefined
140
+ const path = parsed.data.notebook_path
141
+ if (!isNotebookPath(path)) return { error: NOT_A_NOTEBOOK }
142
+ if (context.sandbox) return undefined
143
+ let key: string
144
+ let current: string | undefined
145
+ try {
146
+ key = await resolveWithinAnyReal(toolRoots(context), path)
147
+ current = await readHost(key)
148
+ } catch {
149
+ return undefined
150
+ }
151
+ if (current === undefined) return undefined
152
+ const problem = freshnessProblem(context, key, current)
153
+ return problem
154
+ ? { error: problem.error, ...(problem.facts ? { facts: problem.facts } : {}) }
155
+ : undefined
156
+ }
157
+
158
+ const NOT_A_NOTEBOOK =
159
+ 'notebook_path must name a Jupyter notebook (a .ipynb file). To change any other file use `edit`.'
160
+
161
+ export const NotebookEditTool = defineTool({
162
+ name: 'notebook_edit',
163
+ description:
164
+ 'Replaces, inserts or deletes a single cell in a Jupyter notebook (.ipynb file). Everything else in the notebook (other cells, metadata, format) is kept as it was (the file is saved as JSON with the indent it had, so number spellings such as `1.0` may become `1`; a notebook that cannot be rewritten exactly is refused).\n\nUsage:\n- You must use the `read` tool on the notebook in this conversation before editing; this tool fails otherwise, and also when the notebook changed on disk since you read it.\n- `cell_id` is the `id` shown in the `<cell id="...">` rows of the `read` output. It is required for `replace` and `delete`.\n- `edit_mode` defaults to `replace`, which sets the cell\'s source (and clears the output and run count of a code cell, which belonged to the old code). `insert` adds a new cell after the cell with the given `cell_id`, or at the beginning of the notebook when `cell_id` is left out; `cell_type` is required when inserting. `delete` removes the cell.\n- A notebook change that is not a single cell (the notebook\'s metadata, several cells at once) is a job for `edit`; use this tool for cell text.',
165
+ inputSchema,
166
+ modelInputSchema,
167
+ enforceModelInput: true,
168
+ validationErrorHint: SHAPES,
169
+ malformedInputHint: `${SHAPES} Inside new_source, a newline is \\n and a quote is \\".`,
170
+ category: 'filesystem',
171
+ // Declared so a path outside the turn's roots is reviewed before the call
172
+ // runs. See `ToolDefinition.pathArgument`.
173
+ pathArgument: 'notebook_path',
174
+ refuseBeforeReview,
175
+ classifierInput: (input: NotebookEditInput) =>
176
+ clip(
177
+ `${input.notebook_path}: ${input.edit_mode ?? 'replace'} cell ${input.cell_id ?? '(start)'}${input.new_source !== undefined ? `, ${input.new_source.length} characters` : ''}`,
178
+ 500,
179
+ ),
180
+ permissions: ['file_write'],
181
+ readOnly: false,
182
+ destructive: false,
183
+ concurrencySafe: false,
184
+
185
+ presentCall(input: NotebookEditInput) {
186
+ return { kind: 'generic' as const, label: input.notebook_path }
187
+ },
188
+
189
+ presentResult(_input: NotebookEditInput, result: ToolResult) {
190
+ return { kind: 'generic' as const, label: result.output?.split('\n')[0] ?? '' }
191
+ },
192
+
193
+ async execute(input: NotebookEditInput, context) {
194
+ const parsed = inputSchema.safeParse(input)
195
+ if (!parsed.success) {
196
+ return failure(
197
+ `Invalid notebook_edit input: ${parsed.error.issues.map((issue) => issue.message).join('; ')}`,
198
+ )
199
+ }
200
+ const valid = parsed.data
201
+ if (!isNotebookPath(valid.notebook_path)) return failure(NOT_A_NOTEBOOK)
202
+ const edit = {
203
+ cellId: valid.cell_id,
204
+ newSource: valid.new_source,
205
+ cellType: valid.cell_type,
206
+ editMode: valid.edit_mode ?? 'replace',
207
+ } as const
208
+
209
+ const hostPath = context.sandbox
210
+ ? undefined
211
+ : await resolveWithinAnyReal(toolRoots(context), valid.notebook_path)
212
+ const key = hostPath ?? valid.notebook_path
213
+ const lockKey = context.sandbox ? `sandbox:${key}` : `local:${key}`
214
+
215
+ return withFileMutationLock(lockKey, async () => {
216
+ let before: string | undefined
217
+ if (context.sandbox) {
218
+ try {
219
+ before = (await context.sandbox.readFile(key)).toString('utf-8')
220
+ } catch {
221
+ before = undefined
222
+ }
223
+ } else {
224
+ before = await readHost(key)
225
+ }
226
+ if (before === undefined) return failure(`Notebook file does not exist: ${key}.`)
227
+ if (Buffer.byteLength(before) > NOTEBOOK_MAX_BYTES) {
228
+ return failure(
229
+ `${key} is larger than this tool reads. Change it with \`edit\` or a shell command. The file was not changed.`,
230
+ )
231
+ }
232
+ const stale = freshnessProblem(context, key, before)
233
+ if (stale) return stale
234
+
235
+ const outcome = applyNotebookEdit(before, edit)
236
+ if (!outcome.ok) return failure(outcome.error)
237
+ // The same check `edit` and `write` make: whatever was done, the file must still open.
238
+ const refusal = notebookRefusal(key, outcome.content, before)
239
+ if (refusal) return failure(refusal)
240
+ if (Buffer.byteLength(outcome.content) > NOTEBOOK_MAX_BYTES) {
241
+ return failure(
242
+ 'The updated notebook would be larger than this tool can read. The file was not changed.',
243
+ )
244
+ }
245
+
246
+ if (context.sandbox) await context.sandbox.writeFile(key, outcome.content)
247
+ else await atomicWriteFile(key, outcome.content)
248
+ record(context, key, outcome.content)
249
+
250
+ const diff = lineDiff(before, outcome.content)
251
+ const named = outcome.cellId ? `cell ${outcome.cellId}` : 'a new cell'
252
+ const done =
253
+ outcome.editMode === 'replace'
254
+ ? `Updated cell ${outcome.cellId}`
255
+ : outcome.editMode === 'insert'
256
+ ? `Inserted ${named}`
257
+ : `Deleted cell ${outcome.cellId}`
258
+ return {
259
+ success: true as const,
260
+ output: `${done} in ${key} (+${diff.added} -${diff.removed})${context.sandbox ? ' [sandboxed]' : ''}. ${CURRENT_ON_DISK}`,
261
+ data: {
262
+ notebook_path: key,
263
+ edit_mode: outcome.editMode,
264
+ cell_type: outcome.cellType,
265
+ ...(outcome.cellId ? { cell_id: outcome.cellId } : {}),
266
+ ...(outcome.oldSource !== undefined ? { old_source: outcome.oldSource } : {}),
267
+ },
268
+ facts: {
269
+ kind: 'edit' as const,
270
+ path: key,
271
+ replacements: 1,
272
+ added: diff.added,
273
+ removed: diff.removed,
274
+ ...(diff.hunks.length > 0 ? { hunks: diff.hunks } : {}),
275
+ ...(diff.truncated ? { hunksTruncated: true as const } : {}),
276
+ },
277
+ }
278
+ })
279
+ },
280
+ })
@@ -43,7 +43,8 @@ function shapeProblem(parsed: unknown): string | undefined {
43
43
  function bodyProblem(content: string): string | undefined {
44
44
  let parsed: unknown
45
45
  try {
46
- parsed = JSON.parse(content)
46
+ // A byte-order mark is how some editors save a notebook that opens fine.
47
+ parsed = JSON.parse(content.replace(/^\uFEFF/u, ''))
47
48
  } catch (error) {
48
49
  const reason = error instanceof Error ? error.message : String(error)
49
50
  return `it is not valid JSON (${reason})`
@@ -0,0 +1,138 @@
1
+ import { z } from 'zod'
2
+ import type { ToolDefinition } from '../../types/tool/index.js'
3
+ import { defineTool } from '../defineTool.js'
4
+
5
+ export const PUSH_NOTIFICATION_TOOL_NAME = 'push_notification'
6
+
7
+ /** The longest message one notification carries; the rest is cut. */
8
+ export const PUSH_NOTIFICATION_MAX_CHARS = 200
9
+
10
+ /** The least time between two notifications from one session. */
11
+ export const PUSH_NOTIFICATION_MIN_INTERVAL_MS = 60_000
12
+
13
+ const inputSchema = z.object({
14
+ message: z
15
+ .string()
16
+ .min(1)
17
+ .describe(
18
+ `The notification text. One short line, under ${PUSH_NOTIFICATION_MAX_CHARS} characters; a longer one is cut. Say what finished or what you need. Never put a secret, a token or file contents in it.`,
19
+ ),
20
+ })
21
+
22
+ /** What the host did with one request. */
23
+ export type PushNotificationOutcome =
24
+ | { readonly status: 'sent' }
25
+ /** The person is at the terminal already, so a notification would repeat what they see. */
26
+ | { readonly status: 'user-present' }
27
+ /** The person turned notifications from the model off. */
28
+ | { readonly status: 'disabled' }
29
+ | { readonly status: 'unavailable'; readonly detail: string }
30
+
31
+ export interface PushNotificationToolOptions {
32
+ /** Raise one notification. The message is already one safe line. */
33
+ readonly notify: (message: string) => PushNotificationOutcome | Promise<PushNotificationOutcome>
34
+ /** The clock, in milliseconds; a test hands its own. */
35
+ readonly now?: () => number
36
+ /** Overrides {@link PUSH_NOTIFICATION_MIN_INTERVAL_MS}. */
37
+ readonly minIntervalMs?: number
38
+ }
39
+
40
+ function isStripped(code: number): boolean {
41
+ return (
42
+ code <= 0x1f ||
43
+ (code >= 0x7f && code <= 0x9f) ||
44
+ code === 0xad ||
45
+ code === 0x061c ||
46
+ code === 0x180e ||
47
+ (code >= 0x200b && code <= 0x200f) ||
48
+ (code >= 0x2028 && code <= 0x202e) ||
49
+ (code >= 0x2060 && code <= 0x206f) ||
50
+ code === 0xfeff ||
51
+ (code >= 0xfff9 && code <= 0xfffb)
52
+ )
53
+ }
54
+
55
+ /**
56
+ * One safe line: control, format and bidirectional characters removed (a
57
+ * terminal reads escape sequences in what it is shown), whitespace runs
58
+ * collapsed, cut at the cap with an ellipsis.
59
+ */
60
+ export function pushNotificationLine(text: string): string {
61
+ let out = ''
62
+ for (const ch of text) {
63
+ const code = ch.codePointAt(0) ?? 0
64
+ if (code === 0x09 || code === 0x0a || code === 0x0d) out += ' '
65
+ else if (!isStripped(code)) out += ch
66
+ }
67
+ out = out.replace(/\s+/g, ' ').trim()
68
+ const chars = [...out]
69
+ return chars.length > PUSH_NOTIFICATION_MAX_CHARS
70
+ ? `${chars.slice(0, PUSH_NOTIFICATION_MAX_CHARS - 1).join('')}…`
71
+ : out
72
+ }
73
+
74
+ const DESCRIPTION = `Send a desktop notification to the person's terminal, to pull their attention back. Use it only when a long task has finished or you need a decision and they have probably walked away, or they asked for notifications. Do not use it for routine progress, for a quick task, or while they are in the conversation: it is not sent when they are at the terminal, and at most one goes out a minute. One short line; never a secret.`
75
+
76
+ /**
77
+ * Raises a notification through the host. The host owns delivery (the tool
78
+ * knows no terminal); the tool owns the message (one cleaned line, capped) and
79
+ * the pace (one a minute per session, counted only for notifications sent).
80
+ * Build it only where a person can see a notification; a host with nobody to
81
+ * notify does not offer it.
82
+ */
83
+ export function createPushNotificationTool(
84
+ options: PushNotificationToolOptions,
85
+ ): ToolDefinition<z.infer<typeof inputSchema>> {
86
+ const now = options.now ?? Date.now
87
+ const interval = options.minIntervalMs ?? PUSH_NOTIFICATION_MIN_INTERVAL_MS
88
+ let lastSentAt: number | undefined
89
+ return defineTool({
90
+ name: PUSH_NOTIFICATION_TOOL_NAME,
91
+ description: DESCRIPTION,
92
+ inputSchema,
93
+ category: 'custom',
94
+ permissions: [],
95
+ readOnly: true,
96
+ destructive: false,
97
+ concurrencySafe: false,
98
+ presentCall: (input) => ({
99
+ kind: 'generic',
100
+ label: `Notify · ${pushNotificationLine(input.message)}`,
101
+ presentation: 'activity',
102
+ }),
103
+ async execute(input) {
104
+ const message = pushNotificationLine(input.message)
105
+ if (message === '') {
106
+ const text = 'Not sent: the message is empty once control characters are removed.'
107
+ return { success: false, output: text, error: text }
108
+ }
109
+ const at = now()
110
+ if (lastSentAt !== undefined && at - lastSentAt < interval) {
111
+ const wait = Math.ceil((interval - (at - lastSentAt)) / 1000)
112
+ return {
113
+ success: true,
114
+ output: `Not sent: a notification went out a moment ago (one a minute). Try again in ${wait}s only if it still matters.`,
115
+ }
116
+ }
117
+ const outcome = await options.notify(message)
118
+ switch (outcome.status) {
119
+ case 'sent':
120
+ lastSentAt = at
121
+ return { success: true, output: 'Notification sent.', data: { message } }
122
+ case 'user-present':
123
+ return {
124
+ success: true,
125
+ output:
126
+ 'Not sent: the person is at the terminal, so your reply here already reaches them.',
127
+ }
128
+ case 'disabled':
129
+ return {
130
+ success: true,
131
+ output: 'Not sent: the person has turned notifications from the model off.',
132
+ }
133
+ case 'unavailable':
134
+ return { success: true, output: `Not sent: ${outcome.detail}` }
135
+ }
136
+ },
137
+ })
138
+ }
@@ -42,7 +42,9 @@ const inputSchema = z.object({
42
42
  .int()
43
43
  .min(0)
44
44
  .optional()
45
- .describe('Starting line number (0-indexed). Defaults to 0 (beginning of file).'),
45
+ .describe(
46
+ 'Line number to start from, counted from 1 (offset 100 is line 100, as grep reports it). Defaults to 1; 0 is read as 1.',
47
+ ),
46
48
  limit: z.coerce.number().optional().describe('Maximum number of lines to read'),
47
49
  pages: z
48
50
  .string()
@@ -61,7 +63,7 @@ const inputSchema = z.object({
61
63
  export const ReadFileTool = defineTool({
62
64
  name: 'read',
63
65
  description:
64
- 'Reads a file and returns its contents with line numbers: a right-aligned number, an arrow (→) and the line as it is in the file. The number and arrow are not file text; the tabs and spaces after the arrow are. Also reads images (PNG, JPEG, WebP), which come back as pictures; PDFs, whose pages come back as images (pass pages, for example "1-5", at most 20 pages per request; a PDF of more than 10 pages needs it); and Jupyter notebooks (.ipynb), which come back as cells with their outputs. Supports readRange ([start,end], 1-indexed inclusive) or offset/limit for large files. Without a window it returns the first 2000 lines and says so — pass offset/limit to continue. A file over 256 KiB is refused unless a window is named, and a result over about 25,000 tokens is cut to a first page that names the next call; pass allow_large only when you need all of it.',
66
+ 'Reads a file and returns its contents with line numbers: a right-aligned number, an arrow (→) and the line as it is in the file. The number and arrow are not file text; the tabs and spaces after the arrow are. Also reads images (PNG, JPEG, WebP), which come back as pictures; PDFs, whose pages come back as images (pass pages, for example "1-5", at most 20 pages per request; a PDF of more than 10 pages needs it); and Jupyter notebooks (.ipynb), which come back as cells with their outputs. Supports readRange ([start,end], 1-indexed inclusive) or offset (a line number from 1)/limit for large files. Without a window it returns the first 2000 lines and says so — pass offset/limit to continue. A file over 256 KiB is refused unless a window is named, and a result over about 25,000 tokens is cut to a first page that names the next call; pass allow_large only when you need all of it.',
65
67
  inputSchema,
66
68
  category: 'filesystem',
67
69
  // Declared so a path outside the turn's roots can be reviewed before the
@@ -292,6 +294,10 @@ async function readMediaFile(
292
294
  ? await readPdfPages(buffer, input.pages, path, context.abortSignal)
293
295
  : readNotebook(buffer, path)
294
296
  if (!media.ok) return mediaFailure(path, buffer.length, media.message, sandboxed)
297
+ // A notebook shown whole is a read like any other: the body is what a later
298
+ // edit of it is checked against, and `notebook_edit` refuses a notebook the
299
+ // session has not read.
300
+ if (kind === 'notebook') context.fileReadTracker?.recordRead(path, buffer.toString('utf-8'))
295
301
  const text = media.parts
296
302
  .filter((part) => part.type === 'text')
297
303
  .map((part) => part.text)
@@ -422,7 +428,7 @@ function windowKey(input: ReadWindowInput): string {
422
428
  const range = input.readRange
423
429
  const lines = range
424
430
  ? `r${range[0]}-${range[1]}`
425
- : `o${input.offset ?? 0}l${input.limit === undefined ? 'all' : input.limit}`
431
+ : `o${Math.max(1, input.offset ?? 1)}l${input.limit === undefined ? 'all' : input.limit}`
426
432
  return input.allow_large === true ? `${lines}+large` : lines
427
433
  }
428
434
 
@@ -414,7 +414,8 @@ export function readNotebook(bytes: Buffer, label: string): MediaRead {
414
414
  }
415
415
  let parsed: unknown
416
416
  try {
417
- parsed = JSON.parse(bytes.toString('utf-8'))
417
+ // A byte-order mark is part of how some editors save a notebook, not of its JSON.
418
+ parsed = JSON.parse(bytes.toString('utf-8').replace(/^\uFEFF/u, ''))
418
419
  } catch (error) {
419
420
  return {
420
421
  ok: false,
@@ -129,7 +129,7 @@ function partialViewNotice(
129
129
  '',
130
130
  '',
131
131
  `[PARTIAL view — lines ${start + 1}-${shownTo} of ${total}.`,
132
- `Continue with read({ offset: ${shownTo}, limit: N }), or narrow with grep.]`,
132
+ `Continue with read({ offset: ${shownTo + 1}, limit: N }), or narrow with grep.]`,
133
133
  ].join('\n')
134
134
  }
135
135
 
@@ -150,7 +150,9 @@ export function resolveReadWindow(
150
150
  const end = Math.min(totalLines, Math.max(start, last))
151
151
  return { start, end }
152
152
  }
153
- const start = Math.max(0, input.offset ?? 0)
153
+ // `offset` is a line number counted from 1, like `readRange`; 0 and a missing
154
+ // offset both mean the first line.
155
+ const start = Math.max(0, (input.offset ?? 1) - 1)
154
156
  // A bare `read({ path })` used to return the entire file, so a 2 MB
155
157
  // lockfile became ~500k tokens in one tool_result. Default to a window
156
158
  // and say so in the output; the model asks for more when it needs it.
@@ -341,7 +343,7 @@ function trimFirstPage(
341
343
  }
342
344
 
343
345
  return {
344
- output: `${numbered(selected.slice(0, keep))}\n\n[Truncated: PARTIAL view — ${path}: showing lines 1-${keep} of ${totalLines} total (${tokens} tokens, cap ${maxTokens}). Call read with offset=${keep} limit=${keep} for the next page, or grep to find a specific section. ${tail}`,
346
+ output: `${numbered(selected.slice(0, keep))}\n\n[Truncated: PARTIAL view — ${path}: showing lines 1-${keep} of ${totalLines} total (${tokens} tokens, cap ${maxTokens}). Call read with offset=${keep + 1} limit=${keep} for the next page, or grep to find a specific section. ${tail}`,
345
347
  totalLines,
346
348
  returnedLines: keep,
347
349
  partial: true,
@@ -1,13 +1,27 @@
1
1
  import { isAbsolute, join as joinPath, posix, relative, sep } from 'node:path'
2
2
 
3
3
  import { subscribeToAbort } from '../../utils/abort.js'
4
+ import { readPositiveIntEnv } from '../../utils/env.js'
4
5
 
5
6
  /**
6
7
  * How long grep and glob search before they return what they have. The tool
7
- * deadline (15 s) cancels a call outright and discards its output; a search
8
- * that ends itself a little earlier can still hand back its matches.
8
+ * deadline (budget + 3 s) cancels a call outright and discards its output; a
9
+ * search that ends itself a little earlier can still hand back its matches.
10
+ * A value above 600 s falls back to the default: a timer past 2^31 ms
11
+ * overflows and fires at once.
9
12
  */
10
- export const SEARCH_BUDGET_MS = 12_000
13
+ const MAX_SEARCH_SECONDS = 600
14
+ const configuredSeconds = readPositiveIntEnv('NAMZU_SEARCH_TIMEOUT_SECONDS', 12)
15
+ export const SEARCH_BUDGET_MS =
16
+ (configuredSeconds > MAX_SEARCH_SECONDS ? 12 : configuredSeconds) * 1000
17
+
18
+ /**
19
+ * The deadline glob and grep declare to the executor: always a few seconds
20
+ * past the budget, so a search that ends itself can still return its matches.
21
+ * `NAMZU_SEARCH_TIMEOUT_SECONDS` sets the budget (default 12); both are read
22
+ * once, when the module loads.
23
+ */
24
+ export const SEARCH_TOOL_TIMEOUT_MS = SEARCH_BUDGET_MS + 3_000
11
25
 
12
26
  /** Matching files a search reads at most; past it the search ends with what it has. */
13
27
  export const MAX_FILES_SEARCHED = 50_000
@@ -3,6 +3,7 @@ import { z } from 'zod'
3
3
 
4
4
  import { parseAllowedTools } from '../../authorization/skill-grant.js'
5
5
  import { forkedSkillReportNote } from '../../compaction/loaded-skills.js'
6
+ import { fillArguments, takesSkillArguments } from '../../skills/arguments.js'
6
7
  import {
7
8
  type SkillShellHookOptions,
8
9
  createSkillShellHook,
@@ -14,7 +15,6 @@ import {
14
15
  InlineShellError,
15
16
  expandInlineShell,
16
17
  findInlineShell,
17
- substituteEscaped,
18
18
  } from '../../skills/inline-shell.js'
19
19
  import type { PluginSkillShellInvoker } from '../../types/plugin/index.js'
20
20
  import type { Sandbox } from '../../types/sandbox/index.js'
@@ -395,10 +395,24 @@ export function createSkillTool(options: SkillToolOptions = {}) {
395
395
  readonly reuse: boolean
396
396
  }): Promise<string> => {
397
397
  const shell = options.shell
398
- if (shell === undefined || findInlineShell(input.body).length === 0) return input.body
399
398
  const key = `${input.name}\u0000${input.body}`
400
399
  const kept = input.reuse ? expanded.get(key) : undefined
401
400
  if (kept !== undefined) return kept
401
+ if (shell === undefined || findInlineShell(input.body).length === 0) {
402
+ // No command to run: the arguments go into the text as plain text, with nothing to
403
+ // escape for. A call that carries no arguments at all leaves the body as written.
404
+ // The first load's text is kept for the pages a continuation asks for, whatever
405
+ // arguments that continuation repeats, so every page is cut from the same text.
406
+ const filled =
407
+ input.args === undefined
408
+ ? input.body
409
+ : fillArguments(input.body, input.args, { append: false, escape: false })
410
+ if (!input.reuse) {
411
+ if (expanded.size >= 8) expanded.delete(expanded.keys().next().value as string)
412
+ expanded.set(key, filled)
413
+ }
414
+ return filled
415
+ }
402
416
  const where = shell.sourceOf?.(input.name)
403
417
  // A host that answers where skills come from, and has no answer for this one, has not
404
418
  // placed it: its commands do not run.
@@ -408,12 +422,14 @@ export function createSkillTool(options: SkillToolOptions = {}) {
408
422
  : shell.sourceOf !== undefined && where === undefined
409
423
  ? 'remote'
410
424
  : where?.block
411
- const values: Record<string, string> = { $ARGUMENTS: input.args?.trim() ?? '' }
425
+ const variables: Record<string, string> = {}
412
426
  if (input.directory !== undefined) {
413
- values['${CLAUDE_SKILL_DIR}'] = input.directory
414
- values['${NAMZU_SKILL_DIR}'] = input.directory
427
+ variables['${CLAUDE_SKILL_DIR}'] = input.directory
428
+ variables['${NAMZU_SKILL_DIR}'] = input.directory
415
429
  }
416
- const text = substituteEscaped(input.body, values)
430
+ // Arguments no placeholder takes reach the model in the `Arguments:` line of the load,
431
+ // not appended here.
432
+ const text = fillArguments(input.body, input.args, { variables, append: false })
417
433
  const hook = createSkillShellHook({
418
434
  manager: shell.hooks?.(),
419
435
  sessionId: shell.sessionId?.() ?? String(input.context.sessionId),
@@ -611,8 +627,12 @@ export function createSkillTool(options: SkillToolOptions = {}) {
611
627
  }
612
628
  }
613
629
 
630
+ // Arguments that a placeholder in the body takes are in the text already; the rest
631
+ // are put first, so a long skill's later pages do not hide them.
614
632
  const argsLine =
615
- input.args !== undefined && input.args.trim() !== ''
633
+ input.args !== undefined &&
634
+ input.args.trim() !== '' &&
635
+ !takesSkillArguments(skill.body ?? '', input.args)
616
636
  ? `Arguments: ${input.args.trim()}\n\n`
617
637
  : ''
618
638