@namzu/sdk 69.4.0 → 71.0.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 (436) hide show
  1. package/CHANGELOG.md +161 -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 +24 -6
  14. package/dist/authorization/protected-paths.d.ts.map +1 -1
  15. package/dist/authorization/protected-paths.js +83 -10
  16. package/dist/authorization/protected-paths.js.map +1 -1
  17. package/dist/authorization/readonly-commands.d.ts +17 -5
  18. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  19. package/dist/authorization/readonly-commands.js +77 -6
  20. package/dist/authorization/readonly-commands.js.map +1 -1
  21. package/dist/authorization/readonly-flags.d.ts.map +1 -1
  22. package/dist/authorization/readonly-flags.js +98 -0
  23. package/dist/authorization/readonly-flags.js.map +1 -1
  24. package/dist/authorization/shell-lexer.d.ts +15 -0
  25. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  26. package/dist/authorization/shell-lexer.js +370 -2
  27. package/dist/authorization/shell-lexer.js.map +1 -1
  28. package/dist/authorization/shell-paths.d.ts.map +1 -1
  29. package/dist/authorization/shell-paths.js +276 -0
  30. package/dist/authorization/shell-paths.js.map +1 -1
  31. package/dist/authorization/shell-session-state.d.ts +47 -0
  32. package/dist/authorization/shell-session-state.d.ts.map +1 -0
  33. package/dist/authorization/shell-session-state.js +70 -0
  34. package/dist/authorization/shell-session-state.js.map +1 -0
  35. package/dist/authorization/shell-session.d.ts +9 -0
  36. package/dist/authorization/shell-session.d.ts.map +1 -0
  37. package/dist/authorization/shell-session.js +19 -0
  38. package/dist/authorization/shell-session.js.map +1 -0
  39. package/dist/authorization/skill-grant.d.ts.map +1 -1
  40. package/dist/authorization/skill-grant.js +1 -0
  41. package/dist/authorization/skill-grant.js.map +1 -1
  42. package/dist/compaction/extractor.d.ts.map +1 -1
  43. package/dist/compaction/extractor.js +2 -0
  44. package/dist/compaction/extractor.js.map +1 -1
  45. package/dist/compaction/hooks.d.ts +16 -0
  46. package/dist/compaction/hooks.d.ts.map +1 -1
  47. package/dist/compaction/hooks.js +26 -1
  48. package/dist/compaction/hooks.js.map +1 -1
  49. package/dist/compaction/manual.d.ts.map +1 -1
  50. package/dist/compaction/manual.js +6 -1
  51. package/dist/compaction/manual.js.map +1 -1
  52. package/dist/compaction/restore.d.ts.map +1 -1
  53. package/dist/compaction/restore.js +3 -2
  54. package/dist/compaction/restore.js.map +1 -1
  55. package/dist/config/runtime.d.ts +2 -0
  56. package/dist/config/runtime.d.ts.map +1 -1
  57. package/dist/config/runtime.js +7 -0
  58. package/dist/config/runtime.js.map +1 -1
  59. package/dist/connector/mcp/client.d.ts +7 -0
  60. package/dist/connector/mcp/client.d.ts.map +1 -1
  61. package/dist/connector/mcp/client.js +54 -4
  62. package/dist/connector/mcp/client.js.map +1 -1
  63. package/dist/connector/web/guarded-fetch.d.ts +30 -0
  64. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  65. package/dist/connector/web/guarded-fetch.js +85 -0
  66. package/dist/connector/web/guarded-fetch.js.map +1 -1
  67. package/dist/connector/web/index.d.ts +1 -1
  68. package/dist/connector/web/index.d.ts.map +1 -1
  69. package/dist/connector/web/index.js +1 -1
  70. package/dist/connector/web/index.js.map +1 -1
  71. package/dist/connector/web/types.d.ts +8 -0
  72. package/dist/connector/web/types.d.ts.map +1 -1
  73. package/dist/constants/compaction/index.d.ts.map +1 -1
  74. package/dist/constants/compaction/index.js +1 -1
  75. package/dist/constants/compaction/index.js.map +1 -1
  76. package/dist/execution/code-runtime/worker-program.d.ts +1 -1
  77. package/dist/execution/code-runtime/worker-program.d.ts.map +1 -1
  78. package/dist/execution/code-runtime/worker-program.js +9 -5
  79. package/dist/execution/code-runtime/worker-program.js.map +1 -1
  80. package/dist/execution/local.d.ts.map +1 -1
  81. package/dist/execution/local.js +6 -1
  82. package/dist/execution/local.js.map +1 -1
  83. package/dist/peers/index.d.ts +2 -2
  84. package/dist/peers/index.d.ts.map +1 -1
  85. package/dist/peers/index.js +1 -1
  86. package/dist/peers/index.js.map +1 -1
  87. package/dist/peers/record.d.ts +74 -0
  88. package/dist/peers/record.d.ts.map +1 -1
  89. package/dist/peers/record.js +41 -1
  90. package/dist/peers/record.js.map +1 -1
  91. package/dist/peers/registry.d.ts.map +1 -1
  92. package/dist/peers/registry.js +20 -3
  93. package/dist/peers/registry.js.map +1 -1
  94. package/dist/plugin/bin-path.d.ts +41 -0
  95. package/dist/plugin/bin-path.d.ts.map +1 -0
  96. package/dist/plugin/bin-path.js +146 -0
  97. package/dist/plugin/bin-path.js.map +1 -0
  98. package/dist/plugin/common-layout/read.js +3 -3
  99. package/dist/plugin/common-layout/read.js.map +1 -1
  100. package/dist/plugin/common-layout-names.d.ts.map +1 -1
  101. package/dist/plugin/common-layout-names.js +0 -1
  102. package/dist/plugin/common-layout-names.js.map +1 -1
  103. package/dist/plugin/hook-module/capabilities.d.ts +12 -0
  104. package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
  105. package/dist/plugin/hook-module/capabilities.js +82 -10
  106. package/dist/plugin/hook-module/capabilities.js.map +1 -1
  107. package/dist/plugin/hook-module/consent.d.ts +11 -0
  108. package/dist/plugin/hook-module/consent.d.ts.map +1 -1
  109. package/dist/plugin/hook-module/consent.js +31 -0
  110. package/dist/plugin/hook-module/consent.js.map +1 -1
  111. package/dist/plugin/hook-module/host.d.ts.map +1 -1
  112. package/dist/plugin/hook-module/host.js +69 -23
  113. package/dist/plugin/hook-module/host.js.map +1 -1
  114. package/dist/plugin/hook-module/index.d.ts +1 -1
  115. package/dist/plugin/hook-module/index.d.ts.map +1 -1
  116. package/dist/plugin/hook-module/index.js +1 -1
  117. package/dist/plugin/hook-module/index.js.map +1 -1
  118. package/dist/plugin/hook-module/scan.d.ts +16 -0
  119. package/dist/plugin/hook-module/scan.d.ts.map +1 -1
  120. package/dist/plugin/hook-module/scan.js +68 -3
  121. package/dist/plugin/hook-module/scan.js.map +1 -1
  122. package/dist/plugin/hook-module/worker-source.d.ts +5 -4
  123. package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
  124. package/dist/plugin/hook-module/worker-source.js +254 -28
  125. package/dist/plugin/hook-module/worker-source.js.map +1 -1
  126. package/dist/plugin/lifecycle.d.ts +21 -0
  127. package/dist/plugin/lifecycle.d.ts.map +1 -1
  128. package/dist/plugin/lifecycle.js +64 -0
  129. package/dist/plugin/lifecycle.js.map +1 -1
  130. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  131. package/dist/plugin/shell-hook-tool-names.js +1 -0
  132. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  133. package/dist/plugin/shell-hook.d.ts +1 -1
  134. package/dist/plugin/shell-hook.d.ts.map +1 -1
  135. package/dist/plugin/shell-hook.js +22 -4
  136. package/dist/plugin/shell-hook.js.map +1 -1
  137. package/dist/public-runtime.d.ts +11 -9
  138. package/dist/public-runtime.d.ts.map +1 -1
  139. package/dist/public-runtime.js +11 -8
  140. package/dist/public-runtime.js.map +1 -1
  141. package/dist/public-tools.d.ts +7 -3
  142. package/dist/public-tools.d.ts.map +1 -1
  143. package/dist/public-tools.js +7 -3
  144. package/dist/public-tools.js.map +1 -1
  145. package/dist/public-types.d.ts +2 -2
  146. package/dist/public-types.d.ts.map +1 -1
  147. package/dist/runtime/jobs/monitor-stream.d.ts +9 -1
  148. package/dist/runtime/jobs/monitor-stream.d.ts.map +1 -1
  149. package/dist/runtime/jobs/monitor-stream.js +13 -4
  150. package/dist/runtime/jobs/monitor-stream.js.map +1 -1
  151. package/dist/runtime/jobs/registry.d.ts +4 -0
  152. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  153. package/dist/runtime/jobs/registry.js +12 -2
  154. package/dist/runtime/jobs/registry.js.map +1 -1
  155. package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -1
  156. package/dist/runtime/query/auto-review/git-status.js +3 -2
  157. package/dist/runtime/query/auto-review/git-status.js.map +1 -1
  158. package/dist/runtime/query/executor.d.ts +16 -6
  159. package/dist/runtime/query/executor.d.ts.map +1 -1
  160. package/dist/runtime/query/executor.js +135 -15
  161. package/dist/runtime/query/executor.js.map +1 -1
  162. package/dist/runtime/query/index.d.ts.map +1 -1
  163. package/dist/runtime/query/index.js +2 -2
  164. package/dist/runtime/query/index.js.map +1 -1
  165. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  166. package/dist/runtime/query/iteration/outstanding-work.js +14 -4
  167. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  168. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  169. package/dist/runtime/query/iteration/phases/compaction.js +11 -1
  170. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  171. package/dist/runtime/query/iteration/phases/tool-review.d.ts +2 -0
  172. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  173. package/dist/runtime/query/iteration/phases/tool-review.js +19 -8
  174. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  175. package/dist/runtime/query/path-escalation.d.ts +6 -0
  176. package/dist/runtime/query/path-escalation.d.ts.map +1 -1
  177. package/dist/runtime/query/path-escalation.js +58 -4
  178. package/dist/runtime/query/path-escalation.js.map +1 -1
  179. package/dist/runtime/query/review-policy.d.ts +21 -3
  180. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  181. package/dist/runtime/query/review-policy.js +39 -21
  182. package/dist/runtime/query/review-policy.js.map +1 -1
  183. package/dist/runtime/query/steering.d.ts +11 -2
  184. package/dist/runtime/query/steering.d.ts.map +1 -1
  185. package/dist/runtime/query/steering.js +18 -4
  186. package/dist/runtime/query/steering.js.map +1 -1
  187. package/dist/sandbox/provider/local.d.ts.map +1 -1
  188. package/dist/sandbox/provider/local.js +3 -1
  189. package/dist/sandbox/provider/local.js.map +1 -1
  190. package/dist/schedules/describe.d.ts.map +1 -1
  191. package/dist/schedules/describe.js +2 -0
  192. package/dist/schedules/describe.js.map +1 -1
  193. package/dist/schedules/evaluate.d.ts +4 -0
  194. package/dist/schedules/evaluate.d.ts.map +1 -1
  195. package/dist/schedules/evaluate.js +26 -1
  196. package/dist/schedules/evaluate.js.map +1 -1
  197. package/dist/schedules/index.d.ts +3 -1
  198. package/dist/schedules/index.d.ts.map +1 -1
  199. package/dist/schedules/index.js +2 -1
  200. package/dist/schedules/index.js.map +1 -1
  201. package/dist/schedules/next-fire.d.ts.map +1 -1
  202. package/dist/schedules/next-fire.js +10 -0
  203. package/dist/schedules/next-fire.js.map +1 -1
  204. package/dist/schedules/spec.d.ts +9 -0
  205. package/dist/schedules/spec.d.ts.map +1 -1
  206. package/dist/schedules/spec.js +33 -0
  207. package/dist/schedules/spec.js.map +1 -1
  208. package/dist/schedules/types.d.ts +32 -4
  209. package/dist/schedules/types.d.ts.map +1 -1
  210. package/dist/schedules/types.js +3 -2
  211. package/dist/schedules/types.js.map +1 -1
  212. package/dist/schedules/watch.d.ts +23 -0
  213. package/dist/schedules/watch.d.ts.map +1 -0
  214. package/dist/schedules/watch.js +46 -0
  215. package/dist/schedules/watch.js.map +1 -0
  216. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  217. package/dist/session/workspace/git-worktree.js +2 -1
  218. package/dist/session/workspace/git-worktree.js.map +1 -1
  219. package/dist/skills/arguments.d.ts +58 -0
  220. package/dist/skills/arguments.d.ts.map +1 -0
  221. package/dist/skills/arguments.js +208 -0
  222. package/dist/skills/arguments.js.map +1 -0
  223. package/dist/skills/index.d.ts +3 -1
  224. package/dist/skills/index.d.ts.map +1 -1
  225. package/dist/skills/index.js +1 -0
  226. package/dist/skills/index.js.map +1 -1
  227. package/dist/skills/inline-shell-host.d.ts +6 -0
  228. package/dist/skills/inline-shell-host.d.ts.map +1 -1
  229. package/dist/skills/inline-shell-host.js +8 -0
  230. package/dist/skills/inline-shell-host.js.map +1 -1
  231. package/dist/skills/inline-shell.d.ts +26 -1
  232. package/dist/skills/inline-shell.d.ts.map +1 -1
  233. package/dist/skills/inline-shell.js +1308 -22
  234. package/dist/skills/inline-shell.js.map +1 -1
  235. package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
  236. package/dist/tools/builtins/bash-cwd.js +2 -0
  237. package/dist/tools/builtins/bash-cwd.js.map +1 -1
  238. package/dist/tools/builtins/bash.d.ts.map +1 -1
  239. package/dist/tools/builtins/bash.js +79 -11
  240. package/dist/tools/builtins/bash.js.map +1 -1
  241. package/dist/tools/builtins/exit-semantics.d.ts +6 -0
  242. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  243. package/dist/tools/builtins/exit-semantics.js +10 -0
  244. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  245. package/dist/tools/builtins/glob.d.ts.map +1 -1
  246. package/dist/tools/builtins/glob.js +68 -13
  247. package/dist/tools/builtins/glob.js.map +1 -1
  248. package/dist/tools/builtins/grep.d.ts.map +1 -1
  249. package/dist/tools/builtins/grep.js +37 -12
  250. package/dist/tools/builtins/grep.js.map +1 -1
  251. package/dist/tools/builtins/index.d.ts +11 -0
  252. package/dist/tools/builtins/index.d.ts.map +1 -1
  253. package/dist/tools/builtins/index.js +14 -0
  254. package/dist/tools/builtins/index.js.map +1 -1
  255. package/dist/tools/builtins/job.js +1 -1
  256. package/dist/tools/builtins/job.js.map +1 -1
  257. package/dist/tools/builtins/monitor.d.ts +1 -1
  258. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  259. package/dist/tools/builtins/monitor.js +4 -2
  260. package/dist/tools/builtins/monitor.js.map +1 -1
  261. package/dist/tools/builtins/notebook-cells.d.ts +31 -0
  262. package/dist/tools/builtins/notebook-cells.d.ts.map +1 -0
  263. package/dist/tools/builtins/notebook-cells.js +160 -0
  264. package/dist/tools/builtins/notebook-cells.js.map +1 -0
  265. package/dist/tools/builtins/notebook-edit.d.ts +8 -0
  266. package/dist/tools/builtins/notebook-edit.d.ts.map +1 -0
  267. package/dist/tools/builtins/notebook-edit.js +249 -0
  268. package/dist/tools/builtins/notebook-edit.js.map +1 -0
  269. package/dist/tools/builtins/notebook-guard.d.ts.map +1 -1
  270. package/dist/tools/builtins/notebook-guard.js +2 -1
  271. package/dist/tools/builtins/notebook-guard.js.map +1 -1
  272. package/dist/tools/builtins/push-notification.d.ts +49 -0
  273. package/dist/tools/builtins/push-notification.d.ts.map +1 -0
  274. package/dist/tools/builtins/push-notification.js +107 -0
  275. package/dist/tools/builtins/push-notification.js.map +1 -0
  276. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  277. package/dist/tools/builtins/read-file.js +8 -3
  278. package/dist/tools/builtins/read-file.js.map +1 -1
  279. package/dist/tools/builtins/read-media.d.ts.map +1 -1
  280. package/dist/tools/builtins/read-media.js +2 -1
  281. package/dist/tools/builtins/read-media.js.map +1 -1
  282. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  283. package/dist/tools/builtins/read-render.js +5 -3
  284. package/dist/tools/builtins/read-render.js.map +1 -1
  285. package/dist/tools/builtins/search-support.d.ts +6 -4
  286. package/dist/tools/builtins/search-support.d.ts.map +1 -1
  287. package/dist/tools/builtins/search-support.js +15 -3
  288. package/dist/tools/builtins/search-support.js.map +1 -1
  289. package/dist/tools/builtins/skill.d.ts.map +1 -1
  290. package/dist/tools/builtins/skill.js +30 -8
  291. package/dist/tools/builtins/skill.js.map +1 -1
  292. package/dist/tools/builtins/sleep-guard.d.ts +20 -0
  293. package/dist/tools/builtins/sleep-guard.d.ts.map +1 -1
  294. package/dist/tools/builtins/sleep-guard.js +125 -1
  295. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  296. package/dist/tools/builtins/wait-for-job.js +1 -1
  297. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  298. package/dist/tools/builtins/web.d.ts +2 -0
  299. package/dist/tools/builtins/web.d.ts.map +1 -1
  300. package/dist/tools/builtins/web.js +97 -3
  301. package/dist/tools/builtins/web.js.map +1 -1
  302. package/dist/tools/command-shell.d.ts +50 -0
  303. package/dist/tools/command-shell.d.ts.map +1 -1
  304. package/dist/tools/command-shell.js +145 -0
  305. package/dist/tools/command-shell.js.map +1 -1
  306. package/dist/tools/env-scrub.d.ts +2 -0
  307. package/dist/tools/env-scrub.d.ts.map +1 -1
  308. package/dist/tools/env-scrub.js +15 -1
  309. package/dist/tools/env-scrub.js.map +1 -1
  310. package/dist/tools/git-config-env.d.ts +55 -0
  311. package/dist/tools/git-config-env.d.ts.map +1 -0
  312. package/dist/tools/git-config-env.js +130 -0
  313. package/dist/tools/git-config-env.js.map +1 -0
  314. package/dist/tools/schedules/schedule-tool.d.ts +7 -0
  315. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  316. package/dist/tools/schedules/schedule-tool.js +72 -3
  317. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  318. package/dist/tools/schedules/types.d.ts +38 -2
  319. package/dist/tools/schedules/types.d.ts.map +1 -1
  320. package/dist/types/connector/mcp.d.ts +24 -0
  321. package/dist/types/connector/mcp.d.ts.map +1 -1
  322. package/dist/types/message/index.d.ts +21 -1
  323. package/dist/types/message/index.d.ts.map +1 -1
  324. package/dist/types/message/index.js +37 -2
  325. package/dist/types/message/index.js.map +1 -1
  326. package/dist/types/permission/index.d.ts +11 -2
  327. package/dist/types/permission/index.d.ts.map +1 -1
  328. package/dist/types/permission/index.js +12 -2
  329. package/dist/types/permission/index.js.map +1 -1
  330. package/dist/types/plugin/index.d.ts +10 -2
  331. package/dist/types/plugin/index.d.ts.map +1 -1
  332. package/dist/types/plugin/index.js.map +1 -1
  333. package/dist/types/tool/index.d.ts +13 -0
  334. package/dist/types/tool/index.d.ts.map +1 -1
  335. package/dist/types/tool/index.js.map +1 -1
  336. package/dist/utils/plain-terminal-text.d.ts +21 -0
  337. package/dist/utils/plain-terminal-text.d.ts.map +1 -0
  338. package/dist/utils/plain-terminal-text.js +156 -0
  339. package/dist/utils/plain-terminal-text.js.map +1 -0
  340. package/package.json +1 -1
  341. package/src/authorization/bare-repository.ts +70 -0
  342. package/src/authorization/command-line.ts +18 -4
  343. package/src/authorization/gate.ts +11 -0
  344. package/src/authorization/protected-paths.ts +89 -10
  345. package/src/authorization/readonly-commands.ts +75 -6
  346. package/src/authorization/readonly-flags.ts +103 -0
  347. package/src/authorization/shell-lexer.ts +367 -2
  348. package/src/authorization/shell-paths.ts +386 -0
  349. package/src/authorization/shell-session-state.ts +97 -0
  350. package/src/authorization/shell-session.ts +23 -0
  351. package/src/authorization/skill-grant.ts +1 -0
  352. package/src/compaction/extractor.ts +1 -0
  353. package/src/compaction/hooks.ts +43 -1
  354. package/src/compaction/manual.ts +6 -0
  355. package/src/compaction/restore.ts +3 -2
  356. package/src/config/runtime.ts +7 -0
  357. package/src/connector/mcp/client.ts +61 -4
  358. package/src/connector/web/guarded-fetch.ts +92 -0
  359. package/src/connector/web/index.ts +6 -1
  360. package/src/connector/web/types.ts +8 -0
  361. package/src/constants/compaction/index.ts +1 -1
  362. package/src/execution/code-runtime/worker-program.ts +9 -5
  363. package/src/execution/local.ts +6 -1
  364. package/src/peers/index.ts +8 -2
  365. package/src/peers/record.ts +45 -1
  366. package/src/peers/registry.ts +21 -5
  367. package/src/plugin/bin-path.ts +149 -0
  368. package/src/plugin/common-layout/read.ts +3 -3
  369. package/src/plugin/common-layout-names.ts +0 -1
  370. package/src/plugin/hook-module/capabilities.ts +94 -10
  371. package/src/plugin/hook-module/consent.ts +36 -0
  372. package/src/plugin/hook-module/host.ts +72 -21
  373. package/src/plugin/hook-module/index.ts +2 -0
  374. package/src/plugin/hook-module/scan.ts +76 -4
  375. package/src/plugin/hook-module/worker-source.ts +255 -28
  376. package/src/plugin/lifecycle.ts +67 -0
  377. package/src/plugin/shell-hook-tool-names.ts +1 -0
  378. package/src/plugin/shell-hook.ts +23 -4
  379. package/src/public-runtime.ts +27 -0
  380. package/src/public-tools.ts +36 -2
  381. package/src/public-types.ts +3 -1
  382. package/src/runtime/jobs/monitor-stream.ts +18 -4
  383. package/src/runtime/jobs/registry.ts +22 -2
  384. package/src/runtime/query/auto-review/git-status.ts +3 -2
  385. package/src/runtime/query/executor.ts +153 -12
  386. package/src/runtime/query/index.ts +5 -2
  387. package/src/runtime/query/iteration/outstanding-work.ts +22 -4
  388. package/src/runtime/query/iteration/phases/compaction.ts +14 -1
  389. package/src/runtime/query/iteration/phases/tool-review.ts +24 -7
  390. package/src/runtime/query/path-escalation.ts +52 -4
  391. package/src/runtime/query/review-policy.ts +47 -15
  392. package/src/runtime/query/steering.ts +32 -4
  393. package/src/sandbox/provider/local.ts +3 -1
  394. package/src/schedules/describe.ts +2 -0
  395. package/src/schedules/evaluate.ts +29 -1
  396. package/src/schedules/index.ts +9 -1
  397. package/src/schedules/next-fire.ts +9 -0
  398. package/src/schedules/spec.ts +42 -0
  399. package/src/schedules/types.ts +33 -3
  400. package/src/schedules/watch.ts +71 -0
  401. package/src/session/workspace/git-worktree.ts +3 -1
  402. package/src/skills/arguments.ts +250 -0
  403. package/src/skills/index.ts +10 -0
  404. package/src/skills/inline-shell-host.ts +16 -0
  405. package/src/skills/inline-shell.ts +1358 -22
  406. package/src/tools/builtins/bash-cwd.ts +2 -0
  407. package/src/tools/builtins/bash.ts +93 -13
  408. package/src/tools/builtins/exit-semantics.ts +10 -0
  409. package/src/tools/builtins/glob.ts +79 -15
  410. package/src/tools/builtins/grep.ts +37 -10
  411. package/src/tools/builtins/index.ts +15 -0
  412. package/src/tools/builtins/job.ts +1 -1
  413. package/src/tools/builtins/monitor.ts +4 -2
  414. package/src/tools/builtins/notebook-cells.ts +196 -0
  415. package/src/tools/builtins/notebook-edit.ts +280 -0
  416. package/src/tools/builtins/notebook-guard.ts +2 -1
  417. package/src/tools/builtins/push-notification.ts +138 -0
  418. package/src/tools/builtins/read-file.ts +9 -3
  419. package/src/tools/builtins/read-media.ts +2 -1
  420. package/src/tools/builtins/read-render.ts +5 -3
  421. package/src/tools/builtins/search-support.ts +17 -3
  422. package/src/tools/builtins/skill.ts +29 -7
  423. package/src/tools/builtins/sleep-guard.ts +128 -1
  424. package/src/tools/builtins/wait-for-job.ts +1 -1
  425. package/src/tools/builtins/web.ts +100 -3
  426. package/src/tools/command-shell.ts +166 -0
  427. package/src/tools/env-scrub.ts +13 -1
  428. package/src/tools/git-config-env.ts +143 -0
  429. package/src/tools/schedules/schedule-tool.ts +79 -3
  430. package/src/tools/schedules/types.ts +47 -9
  431. package/src/types/connector/mcp.ts +25 -0
  432. package/src/types/message/index.ts +53 -1
  433. package/src/types/permission/index.ts +20 -3
  434. package/src/types/plugin/index.ts +10 -2
  435. package/src/types/tool/index.ts +13 -0
  436. package/src/utils/plain-terminal-text.ts +142 -0
@@ -19,6 +19,7 @@ import { randomUUID } from 'node:crypto'
19
19
  import { realpathSync, statSync } from 'node:fs'
20
20
  import { rm } from 'node:fs/promises'
21
21
 
22
+ import { forgetAllShellSessions } from '../../authorization/shell-session-state.js'
22
23
  import { tempFilePath } from '../../utils/temp.js'
23
24
  import { type CommandShell, hostCommandShell } from '../command-shell.js'
24
25
  import { pathOutsideRoots, toolRoots } from '../paths.js'
@@ -152,6 +153,7 @@ function sameFolder(a: string, b: string): boolean {
152
153
  /** For tests: forget every session. */
153
154
  export function forgetCarriedDirectories(): void {
154
155
  carried.clear()
156
+ forgetAllShellSessions()
155
157
  }
156
158
 
157
159
  // Enumerable symbol crosses the executor's context copies, never the model's
@@ -2,7 +2,9 @@ import { rm } from 'node:fs/promises'
2
2
  import { z } from 'zod'
3
3
  import { findDangerousCommand } from '../../authorization/dangerous-commands.js'
4
4
  import { isReadOnlyCommandLine } from '../../authorization/readonly-commands.js'
5
+ import { recordShellCommand } from '../../authorization/shell-session.js'
5
6
  import { SANDBOX_KILL_GRACE_MS } from '../../constants/sandbox/index.js'
7
+ import { appendDirsToPath } from '../../plugin/bin-path.js'
6
8
  import { killTree } from '../../process/kill-tree.js'
7
9
  import { genericLabel } from '../../registry/tool/presentation.js'
8
10
  import { cancelCauseOf } from '../../types/session/cancel-cause.js'
@@ -24,6 +26,7 @@ import {
24
26
  } from '../command-shell.js'
25
27
  import { defineTool } from '../defineTool.js'
26
28
  import { scrubInheritedEnv, withheldEnvNoticeText } from '../env-scrub.js'
29
+ import { withSafeGitConfig } from '../git-config-env.js'
27
30
  import { createHostOutputDecoder } from '../host-output.js'
28
31
  import { looksBinary, windowText } from '../text-window.js'
29
32
  import {
@@ -32,10 +35,16 @@ import {
32
35
  recordDirectory,
33
36
  withCwdCapture,
34
37
  } from './bash-cwd.js'
35
- import { commandNotFoundHint, judgeExit } from './exit-semantics.js'
38
+ import { bareRepositoryHint, commandNotFoundHint, judgeExit } from './exit-semantics.js'
36
39
  import { jsonStringEscapes } from './json-string-hint.js'
37
40
  import { creditShellReads } from './shell-read-credit.js'
38
- import { leadingLongSleep, longSleepRefusal } from './sleep-guard.js'
41
+ import {
42
+ cappedSignIn,
43
+ cappedSignInRefusal,
44
+ chainedSleeps,
45
+ leadingLongSleep,
46
+ longSleepRefusal,
47
+ } from './sleep-guard.js'
39
48
 
40
49
  // Namzu owns its own bash timeout knob — `NAMZU_BASH_TIMEOUT_MS` — and
41
50
  // reads no consumer's env name. A consumer that wants one knob aliases
@@ -152,7 +161,7 @@ const inputSchema = z.object({
152
161
  .transform((ms) => Math.min(ms, MAX_BASH_TIMEOUT_MS)),
153
162
  )
154
163
  .describe(
155
- `Command timeout in milliseconds. Default: ${DEFAULT_BASH_TIMEOUT_MS}, maximum: ${MAX_BASH_TIMEOUT_MS}. For work that legitimately runs longer than the maximum, set run_in_background and await it with \`wait_for_job\`, rather than holding the turn open. A foreground command still running when the timeout elapses is moved to a background job (and reported as such) instead of being stopped, where the host has background jobs.`,
164
+ `Command timeout in milliseconds. Default: ${DEFAULT_BASH_TIMEOUT_MS}, maximum: ${MAX_BASH_TIMEOUT_MS}. For work that legitimately runs longer than the maximum, set run_in_background and end your turn; you are told when it exits. A foreground command still running when the timeout elapses is moved to a background job (and reported as such) instead of being stopped, where the host has background jobs.`,
156
165
  ),
157
166
  description: z
158
167
  .string()
@@ -165,7 +174,7 @@ const inputSchema = z.object({
165
174
  .boolean()
166
175
  .optional()
167
176
  .describe(
168
- 'Start the command as a background job and return its id immediately. For a finite build, await completion with `wait_for_job`. For a persistent server, use `wait_for_job` with output_contains and optional output_stream to observe its literal readiness marker without waiting for exit; verify health separately. Use `job` action "read" for incremental output or after a wait times out. Background a command with this parameter, since `cmd &` is not a registered job: strict execution ownership can retire the allocation when the launcher exits with live descendants. An interactive application may belong to a dedicated computer only when that computer explicitly supports application lifetime; its launch result is not a registered job or proof the application has finished.',
177
+ 'Start the command as a background job and return its id at once. You are told when it exits: end your turn or keep working, and do not poll or wait for it. A command that waits for a person (it prints a sign-in URL) goes here too, with no `timeout` wrapper: tell them the step and end your turn. For a persistent server, `wait_for_job` with output_contains observes its readiness marker; verify health separately. Use `job` action "read" for output. Background a command with this parameter, since `cmd &` is not a registered job: strict execution ownership can retire the allocation when the launcher exits with live descendants. An interactive application may belong to a dedicated computer only when that computer explicitly supports application lifetime; its launch result is not a registered job or proof the application has finished.',
169
178
  ),
170
179
  dangerously_disable_sandbox: z
171
180
  .boolean()
@@ -194,10 +203,49 @@ function bashInputIsReadOnly(input: BashInput | undefined): boolean {
194
203
 
195
204
  const MAX_SHELL_PROGRESS_CHARS = 160
196
205
 
206
+ /**
207
+ * The last `max` characters of `text`, moved back to the start of an escape
208
+ * sequence the cut would land inside: a progress line is shown as text, and the
209
+ * tail of `ESC [ 38;2;255;106;0 m` is not a colour but `;2;255;106;0m`.
210
+ */
211
+ function tailWhole(text: string, max: number): string {
212
+ if (text.length <= max) return text
213
+ let from = text.length - max
214
+ const esc = text.lastIndexOf('\u001b', from)
215
+ if (esc >= 0 && from - esc <= 64) {
216
+ const kind = text.charCodeAt(esc + 1)
217
+ let open = false
218
+ if (kind === 0x5b) {
219
+ // CSI: parameter and intermediate bytes (0x20-0x3f), then a final byte.
220
+ open = true
221
+ for (let i = esc + 2; i < from; i++) {
222
+ const code = text.charCodeAt(i)
223
+ if (code < 0x20 || code > 0x3f) {
224
+ open = false
225
+ break
226
+ }
227
+ }
228
+ } else if (kind === 0x5d) {
229
+ // OSC: open until BEL or ST.
230
+ open = true
231
+ for (let i = esc + 2; i < from; i++) {
232
+ const code = text.charCodeAt(i)
233
+ if (code === 0x07 || code === 0x9c || (code === 0x1b && text.charCodeAt(i + 1) === 0x5c)) {
234
+ open = false
235
+ break
236
+ }
237
+ }
238
+ }
239
+ if (open) from = esc
240
+ }
241
+ return text.slice(from)
242
+ }
243
+
197
244
  /** Keep a bounded tail even when a process never writes a newline. */
198
245
  function appendProgressTail(previous: string, chunk: string, start: number, end: number): string {
199
- return (previous + chunk.slice(Math.max(start, end - MAX_SHELL_PROGRESS_CHARS), end)).slice(
200
- -MAX_SHELL_PROGRESS_CHARS,
246
+ return tailWhole(
247
+ previous + tailWhole(chunk.slice(start, end), MAX_SHELL_PROGRESS_CHARS),
248
+ MAX_SHELL_PROGRESS_CHARS,
201
249
  )
202
250
  }
203
251
 
@@ -600,11 +648,15 @@ const BashToolBase = defineTool({
600
648
  // ways to wait. The same answer is given here, before a person is asked to
601
649
  // approve a command that would be blocked the moment they said yes.
602
650
  refuseBeforeReview: async (input: BashInput, context) => {
603
- if (input.run_in_background || !context.backgroundJobs || backgroundTasksDisabled()) {
604
- return undefined
651
+ if (!context.backgroundJobs || backgroundTasksDisabled()) return undefined
652
+ if (input.run_in_background) {
653
+ const cappedBg = cappedSignIn(input.command)
654
+ return cappedBg === null ? undefined : { error: cappedSignInRefusal(cappedBg, true) }
605
655
  }
606
- const longSleep = leadingLongSleep(input.command)
607
- return longSleep === null ? undefined : { error: longSleepRefusal(longSleep) }
656
+ const longSleep = leadingLongSleep(input.command) ?? chainedSleeps(input.command)
657
+ if (longSleep !== null) return { error: longSleepRefusal(longSleep) }
658
+ const capped = cappedSignIn(input.command)
659
+ return capped === null ? undefined : { error: cappedSignInRefusal(capped) }
608
660
  },
609
661
  permissions: ['shell_execute'],
610
662
  // A line made only of vetted read-only commands (`ls`, `cat`, `git status`,
@@ -633,6 +685,12 @@ const BashToolBase = defineTool({
633
685
 
634
686
  async execute(input, context) {
635
687
  const startDirectory = bashWorkingDirectoryForExecution(context)
688
+ // Names this line gives the integer attribute to are remembered for the
689
+ // session: a later line that stores a subscript into one is arithmetic.
690
+ recordShellCommand(
691
+ typeof context.sessionId === 'string' ? context.sessionId : undefined,
692
+ input.command,
693
+ )
636
694
  const refused = dangerousCommandReason(input.command)
637
695
  if (refused !== undefined) {
638
696
  return {
@@ -648,13 +706,24 @@ const BashToolBase = defineTool({
648
706
  }
649
707
  }
650
708
 
709
+ if (input.run_in_background && context.backgroundJobs && !backgroundTasksDisabled()) {
710
+ const cappedBg = cappedSignIn(input.command)
711
+ if (cappedBg !== null) {
712
+ return { success: false, output: '', error: cappedSignInRefusal(cappedBg, true) }
713
+ }
714
+ }
715
+
651
716
  // Where a job registry exists to wait on, a long leading sleep only
652
717
  // holds the turn; it is refused with the better ways to wait.
653
718
  if (!input.run_in_background && context.backgroundJobs && !backgroundTasksDisabled()) {
654
- const longSleep = leadingLongSleep(input.command)
719
+ const longSleep = leadingLongSleep(input.command) ?? chainedSleeps(input.command)
655
720
  if (longSleep !== null) {
656
721
  return { success: false, output: '', error: longSleepRefusal(longSleep) }
657
722
  }
723
+ const capped = cappedSignIn(input.command)
724
+ if (capped !== null) {
725
+ return { success: false, output: '', error: cappedSignInRefusal(capped) }
726
+ }
658
727
  }
659
728
 
660
729
  // Asked to leave the sandbox. Honoured only on the executor's word that
@@ -739,7 +808,7 @@ const BashToolBase = defineTool({
739
808
  output: `Started background job ${job.id}; state: running.${
740
809
  job.outputFile === undefined
741
810
  ? ''
742
- : ` Its output is saved to ${job.outputFile}; do not redirect it into a file of your own. Use wait_for_job to wait for it to finish and job to read it.`
811
+ : ` Its output is saved to ${job.outputFile}; do not redirect it into a file of your own. You will be notified when it exits: end your turn or keep working, do not poll or wait for it. Read it with job.`
743
812
  }`,
744
813
  data: {
745
814
  jobId: job.id,
@@ -747,6 +816,8 @@ const BashToolBase = defineTool({
747
816
  ...(job.outputFile === undefined ? {} : { outputFile: job.outputFile }),
748
817
  },
749
818
  facts: { kind: 'command', command: input.command, background: true, jobId: job.id },
819
+ // Only started: what the job does is told by its own exit notice.
820
+ launched: true,
750
821
  }
751
822
  } catch (err) {
752
823
  // The per-owner cap, most likely. A refusal that names the limit
@@ -814,6 +885,7 @@ const BashToolBase = defineTool({
814
885
  : '',
815
886
  result.attribution ? `[${result.attribution.message}]` : '',
816
887
  commandNotFoundHint(result.exitCode, result.stderr) ?? '',
888
+ bareRepositoryHint(result.stderr) ?? '',
817
889
  ]
818
890
  .filter(Boolean)
819
891
  .join('\n\n')
@@ -911,7 +983,14 @@ const BashToolBase = defineTool({
911
983
  {
912
984
  cwd: startDirectory,
913
985
  timeout: input.timeout,
914
- env: withNodeOnPath({ ...inherited.env, ...context.env }),
986
+ // Last: a folder the model wrote that looks like a repository must not
987
+ // get git to run the program its config names (see git-config-env.ts).
988
+ env: withSafeGitConfig(
989
+ appendDirsToPath(
990
+ withNodeOnPath({ ...inherited.env, ...context.env }),
991
+ context.pluginBinDirs?.() ?? [],
992
+ ),
993
+ ),
915
994
  maxBuffer: DEFAULT_BASH_MAX_BUFFER_BYTES,
916
995
  signal: context.abortSignal,
917
996
  onOutput,
@@ -1027,6 +1106,7 @@ const BashToolBase = defineTool({
1027
1106
  ? `[${clipped.join(' and ')} ${clipped.length === 1 ? 'was' : 'were'} truncated by the host output cap. The omitted output is unavailable in this result.]`
1028
1107
  : '',
1029
1108
  commandNotFoundHint(exitCode, failure.stderr ?? '') ?? '',
1109
+ bareRepositoryHint(failure.stderr ?? '') ?? '',
1030
1110
  ]
1031
1111
  .filter(Boolean)
1032
1112
  .join('\n\n')
@@ -219,3 +219,13 @@ export function commandNotFoundHint(
219
219
  }
220
220
  return undefined
221
221
  }
222
+
223
+ /**
224
+ * What to tell the model when git refused to read the folder it ran in as a
225
+ * repository because the folder only looks like a bare one (every command a
226
+ * session starts carries `safe.bareRepository=explicit`).
227
+ */
228
+ export function bareRepositoryHint(stderr: string): string | undefined {
229
+ if (!/safe\.bareRepository is 'explicit'/.test(stderr)) return undefined
230
+ return '[git did not treat this folder as a repository: it only looks like a bare one (HEAD, objects and refs outside a .git folder), and git here reads a bare repository only when it is named. For a real bare repository, name it: git --git-dir=. <command>. For a normal checkout, run git from inside the working tree.]'
231
+ }
@@ -1,3 +1,4 @@
1
+ import { stat } from 'node:fs/promises'
1
2
  import { isAbsolute, join, relative, sep } from 'node:path'
2
3
  import { z } from 'zod'
3
4
  import { walkFilesLocally } from '../../sandbox/file-walk.js'
@@ -7,6 +8,7 @@ import { resolveWithin, resolveWithinAny, resolveWithinAnyReal, toolRoots } from
7
8
  import { relativePosix, resolveWithinPosix } from '../posix-path.js'
8
9
  import {
9
10
  SEARCH_BUDGET_MS,
11
+ SEARCH_TOOL_TIMEOUT_MS,
10
12
  hostDisplayPath,
11
13
  ignoredHint,
12
14
  isEntryLimit,
@@ -19,6 +21,12 @@ import {
19
21
 
20
22
  const MAX_GLOB_RESULTS = 500
21
23
 
24
+ /**
25
+ * Matches a host search collects before it sorts them newest first. Every one is
26
+ * stat'ed, so this bounds that pass; past it the notice says "at least".
27
+ */
28
+ const MAX_GLOB_COLLECTED = 10_000
29
+
22
30
  const inputSchema = z.object({
23
31
  pattern: z
24
32
  .string()
@@ -68,7 +76,7 @@ function relativePattern(pattern: string, root: string, sandboxed: boolean): str
68
76
  export const GlobTool = defineTool({
69
77
  name: 'glob',
70
78
  description:
71
- 'Finds regular files by glob pattern in a bounded search. "*" searches one directory; use "**" explicitly for recursive discovery. Skips files that .gitignore and .ignore rules exclude unless include_ignored is set, and files the read rules of the session deny. Returns at most 500 paths and says when a result is limited or a search stopped early. Does not follow symlinks. To search inside files, use grep.',
79
+ 'Finds regular files by glob pattern in a bounded search. "*" searches one directory; use "**" explicitly for recursive discovery. Skips files that .gitignore and .ignore rules exclude unless include_ignored is set, and files the read rules of the session deny. Returns at most 500 paths, newest first, and says how many matched when a result is limited or a search stopped early. Does not follow symlinks. To search inside files, use grep.',
72
80
  inputSchema,
73
81
  category: 'filesystem',
74
82
  // Declared so a path outside the turn's roots can be reviewed before the
@@ -78,7 +86,7 @@ export const GlobTool = defineTool({
78
86
  readOnly: true,
79
87
  destructive: false,
80
88
  concurrencySafe: true,
81
- timeoutMs: 15_000,
89
+ timeoutMs: SEARCH_TOOL_TIMEOUT_MS,
82
90
 
83
91
  presentCall(input) {
84
92
  if (typeof input.pattern !== 'string') return undefined
@@ -117,7 +125,9 @@ export const GlobTool = defineTool({
117
125
  const options: SandboxWalkFilesOptions = {
118
126
  pattern,
119
127
  signal: budget.signal,
120
- maxEntries: MAX_GLOB_RESULTS + 1,
128
+ // On the host every match is collected (up to the file bound), so the cap keeps
129
+ // the newest files; a sandbox reports no times, so it stops at the cap.
130
+ maxEntries: sandbox ? MAX_GLOB_RESULTS + 1 : MAX_GLOB_COLLECTED + 1,
121
131
  includeHidden: input.include_hidden ?? true,
122
132
  respectIgnore: input.include_ignored !== true,
123
133
  onSummary: (value) => {
@@ -125,7 +135,7 @@ export const GlobTool = defineTool({
125
135
  },
126
136
  }
127
137
  const entries = walkSandbox ? walkSandbox(root, options) : walkFilesLocally(root, options)
128
- const files: string[] = []
138
+ const found: { shown: string; host?: string }[] = []
129
139
  let capped = false
130
140
  let timedOut = false
131
141
  let legacyEntryLimit = false
@@ -137,20 +147,23 @@ export const GlobTool = defineTool({
137
147
  ? resolveWithinPosix(root, entry.path)
138
148
  : resolveWithin(root, entry.path)
139
149
  if (isReadDenied(context, absolute, sandbox?.rootDir)) continue
140
- if (files.length === MAX_GLOB_RESULTS) {
150
+ if (found.length === (sandbox ? MAX_GLOB_RESULTS : MAX_GLOB_COLLECTED)) {
141
151
  capped = true
142
152
  break
143
153
  }
144
154
  // Readers resolve relative input against the original working path,
145
155
  // which may be a symlink. Project back through the selected alias
146
156
  // before relativizing so added directories remain reachable.
147
- files.push(
157
+ found.push(
148
158
  sandbox
149
- ? relativePosix(sandbox.rootDir, absolute)
150
- : hostDisplayPath(
151
- context.workingDirectory,
152
- join(lexicalRoot, relative(root, absolute)),
153
- ),
159
+ ? { shown: relativePosix(sandbox.rootDir, absolute) }
160
+ : {
161
+ shown: hostDisplayPath(
162
+ context.workingDirectory,
163
+ join(lexicalRoot, relative(root, absolute)),
164
+ ),
165
+ host: absolute,
166
+ },
154
167
  )
155
168
  }
156
169
  } catch (error) {
@@ -161,6 +174,17 @@ export const GlobTool = defineTool({
161
174
  } finally {
162
175
  budget.close()
163
176
  }
177
+ const totalFound = found.length
178
+ let files: string[]
179
+ if (sandbox) {
180
+ files = found.map((entry) => entry.shown)
181
+ } else {
182
+ // A timed-out search is already over; sorting what it found must not
183
+ // be cancelled by the same spent budget, only by the caller.
184
+ files = (await sortNewestFirst(found, context.abortSignal)).map((entry) => entry.shown)
185
+ }
186
+ const overCap = files.length > MAX_GLOB_RESULTS
187
+ if (overCap) files = files.slice(0, MAX_GLOB_RESULTS)
164
188
  const endState = summary as SandboxWalkSummary | undefined
165
189
  const entryLimit = endState?.stopped === 'entry-limit' || legacyEntryLimit
166
190
  const incomplete = timedOut || entryLimit
@@ -172,11 +196,16 @@ export const GlobTool = defineTool({
172
196
  }
173
197
  }
174
198
  const notices = [
175
- ...(capped
199
+ ...(sandbox && capped
176
200
  ? [
177
201
  `(Showing the first ${plural(MAX_GLOB_RESULTS, 'matching file')}; more match. Narrow the pattern or path to see the rest.)`,
178
202
  ]
179
203
  : []),
204
+ ...(!sandbox && overCap
205
+ ? [
206
+ `(Showing the ${plural(MAX_GLOB_RESULTS, 'newest matching file')} of ${capped || incomplete ? 'at least ' : ''}${totalFound.toLocaleString('en-US')} that matched. Narrow the pattern or path to see the rest.)`,
207
+ ]
208
+ : []),
180
209
  ...(incomplete ? [stoppedNotice(timedOut ? 'time' : 'entries', endState?.visited)] : []),
181
210
  ...(failure ? [`[Search incomplete: ${failure}]`] : []),
182
211
  ]
@@ -188,8 +217,9 @@ export const GlobTool = defineTool({
188
217
  output: [...files.map(quoteControlPath), ...notices].join('\n') || empty,
189
218
  data: {
190
219
  count: files.length,
220
+ total: totalFound,
191
221
  files,
192
- truncated: capped || incomplete,
222
+ truncated: capped || overCap || incomplete,
193
223
  ...(sandbox ? { sandboxed: true } : {}),
194
224
  },
195
225
  facts: {
@@ -197,11 +227,45 @@ export const GlobTool = defineTool({
197
227
  pattern: input.pattern,
198
228
  ...(input.path !== undefined ? { path: input.path } : {}),
199
229
  count: files.length,
200
- truncated: capped || incomplete,
201
- ...(capped ? { limited: true } : {}),
230
+ truncated: capped || overCap || incomplete,
231
+ ...(capped || overCap ? { limited: true } : {}),
202
232
  ...(incomplete ? { incomplete: true } : {}),
203
233
  },
204
234
  ...(failure ? { error: failure } : {}),
205
235
  }
206
236
  },
207
237
  })
238
+
239
+ /**
240
+ * Newest modification first; ties by path. A file that cannot be stat'ed sorts
241
+ * as oldest. Stats run in small batches so a cancelled call stops promptly.
242
+ */
243
+ async function sortNewestFirst<T extends { shown: string; host?: string }>(
244
+ files: readonly T[],
245
+ signal?: AbortSignal,
246
+ ): Promise<T[]> {
247
+ const stamped: { file: T; mtime: number }[] = []
248
+ for (let i = 0; i < files.length; i += 256) {
249
+ signal?.throwIfAborted()
250
+ const batch = files.slice(i, i + 256)
251
+ stamped.push(
252
+ ...(await Promise.all(
253
+ batch.map(async (file) => {
254
+ if (file.host === undefined) return { file, mtime: 0 }
255
+ try {
256
+ return { file, mtime: (await stat(file.host)).mtimeMs }
257
+ } catch {
258
+ return { file, mtime: 0 }
259
+ }
260
+ }),
261
+ )),
262
+ )
263
+ }
264
+ return stamped
265
+ .sort(
266
+ (a, b) =>
267
+ b.mtime - a.mtime ||
268
+ (a.file.shown < b.file.shown ? -1 : a.file.shown > b.file.shown ? 1 : 0),
269
+ )
270
+ .map((entry) => entry.file)
271
+ }
@@ -25,6 +25,7 @@ import {
25
25
  import {
26
26
  MAX_FILES_SEARCHED,
27
27
  SEARCH_BUDGET_MS,
28
+ SEARCH_TOOL_TIMEOUT_MS,
28
29
  hostDisplayPath,
29
30
  ignoredHint,
30
31
  isEntryLimit,
@@ -334,7 +335,7 @@ function isBinaryContent(buffer: Buffer): boolean {
334
335
  export const GrepTool = defineTool({
335
336
  name: 'grep',
336
337
  description:
337
- 'Searches file contents using a regular expression. By default returns the paths of matching files, newest first; output_mode "content" returns matching lines with file paths, line numbers and optional context lines, and "count" returns the number of matching lines per file. Set multiline for a pattern that spans lines and type (js, py, rust, ...) to search one kind of file. In content mode, before_context and after_context override symmetric context_lines; only_matching returns matched substrings without context. Results are paged: head_limit (default 250, 0 for none) and offset. A line over 500 characters is replaced by a notice. Searches hidden files unless include_hidden is false. Skips files that .gitignore and .ignore rules exclude unless include_ignored is set, and files the read rules of the session deny. Says when a result is limited or a search stopped early. Skips binary files, files over 5 MB, and symlinks. Choose the narrowest relevant directory. To find files by name, use glob.',
338
+ 'Searches file contents using a regular expression. By default returns the paths of matching files, newest first; output_mode "content" returns matching lines with file paths, line numbers and optional context lines, and "count" returns the number of matching lines per file. Set multiline for a pattern that spans lines and type (js, py, rust, ...) to search one kind of file. In content mode, before_context and after_context override symmetric context_lines; only_matching returns matched substrings without context. Content and count rows are ordered by file path. Results are paged: head_limit (default 250, 0 for none) and offset. A line over 500 characters is replaced by a notice. Searches hidden files unless include_hidden is false. Skips files that .gitignore and .ignore rules exclude unless include_ignored is set, and files the read rules of the session deny. Says when a result is limited or a search stopped early. Skips binary files, files over 5 MB, and symlinks. Choose the narrowest relevant directory. To find files by name, use glob.',
338
339
  inputSchema,
339
340
  category: 'analysis',
340
341
  // Declared so a path outside the turn's roots can be reviewed before the
@@ -359,7 +360,7 @@ export const GrepTool = defineTool({
359
360
  },
360
361
  }
361
362
  },
362
- timeoutMs: 15_000,
363
+ timeoutMs: SEARCH_TOOL_TIMEOUT_MS,
363
364
 
364
365
  async execute(input, context) {
365
366
  context.abortSignal?.throwIfAborted()
@@ -429,7 +430,8 @@ export const GrepTool = defineTool({
429
430
  const afterContext = input.after_context ?? input.context_lines ?? 0
430
431
  // Content lines in output order. Only content mode uses them as the
431
432
  // result; the other modes build from `matchedFiles`.
432
- const results: string[] = []
433
+ let results: string[] = []
434
+ const contentFiles: { relPath: string; lines: string[] }[] = []
433
435
  const matchedFiles: { relPath: string; host?: string; count: number }[] = []
434
436
  let totalMatches = 0
435
437
  let filesSearched = 0
@@ -441,8 +443,9 @@ export const GrepTool = defineTool({
441
443
  let timedOut = false
442
444
  let legacyEntryLimit = false
443
445
  let fileLimit = false
444
- // A file list is ordered newest first, so the walk cannot stop at the
445
- // first page: it reads a generous multiple of it, then sorts and pages.
446
+ // A file list is ordered newest first and content and count rows by path,
447
+ // so the walk cannot stop at the first page: it reads a generous multiple
448
+ // of it, then sorts and pages.
446
449
  // The count includes the offset, so every page the model is told to ask
447
450
  // for can be served.
448
451
  const filesToCollect =
@@ -514,6 +517,7 @@ export const GrepTool = defineTool({
514
517
  : (walked?.displayName(filePath) ??
515
518
  hostDisplayPath(context.workingDirectory, join(lexicalRoot, relative(root, filePath))))
516
519
 
520
+ results = []
517
521
  if (mode === 'content' && input.only_matching) {
518
522
  for (const fragment of matchingFragments(content, regex, multiline)) {
519
523
  signal?.throwIfAborted()
@@ -525,7 +529,11 @@ export const GrepTool = defineTool({
525
529
  break
526
530
  }
527
531
  }
528
- if (pageHasMore) break
532
+ if (results.length > 0) contentFiles.push({ relPath, lines: results })
533
+ if (contentFiles.length >= filesToCollect) {
534
+ enough = true
535
+ break
536
+ }
529
537
  continue
530
538
  }
531
539
 
@@ -574,7 +582,13 @@ export const GrepTool = defineTool({
574
582
  count: fileMatches,
575
583
  })
576
584
  }
577
- if (pageHasMore) break
585
+ if (mode === 'content' && results.length > 0) {
586
+ contentFiles.push({ relPath, lines: results })
587
+ if (contentFiles.length >= filesToCollect) {
588
+ enough = true
589
+ break
590
+ }
591
+ }
578
592
  if (mode === 'files_with_matches' && matchedFiles.length >= filesToCollect) {
579
593
  enough = true
580
594
  break
@@ -605,9 +619,17 @@ export const GrepTool = defineTool({
605
619
  // Entries as the model will page through them.
606
620
  let entriesOut: string[]
607
621
  if (mode === 'content') {
608
- entriesOut = results
622
+ // By file path, so a page asked for later is the same on every run:
623
+ // the walk's own order is whatever the file system lists.
624
+ entriesOut = []
625
+ for (const file of [...contentFiles].sort((a, b) => byPath(a.relPath, b.relPath))) {
626
+ if ((beforeContext > 0 || afterContext > 0) && entriesOut.length > 0) entriesOut.push('--')
627
+ entriesOut.push(...file.lines)
628
+ }
609
629
  } else if (mode === 'count') {
610
- entriesOut = matchedFiles.map((f) => `${f.relPath}:${f.count}`)
630
+ entriesOut = [...matchedFiles]
631
+ .sort((a, b) => byPath(a.relPath, b.relPath))
632
+ .map((f) => `${f.relPath}:${f.count}`)
611
633
  } else {
612
634
  entriesOut = (await sortByNewest(matchedFiles)).map((f) => f.relPath)
613
635
  }
@@ -647,7 +669,7 @@ export const GrepTool = defineTool({
647
669
  const notices = [
648
670
  ...(moreRemain
649
671
  ? [
650
- `[More results are available: pass offset: ${offset + headLimit} to continue, or narrow the path or pattern.${enough ? ` Files are ordered newest first among the first ${filesToCollect.toLocaleString('en-US')} that matched.` : ''}]`,
672
+ `[More results are available: pass offset: ${offset + headLimit} to continue, or narrow the path or pattern.${enough ? ` Files are ordered ${mode === 'files_with_matches' ? 'newest first' : 'by path'} among the first ${filesToCollect.toLocaleString('en-US')} that matched.` : ''}]`,
651
673
  ]
652
674
  : []),
653
675
  ...(stoppedEarly
@@ -694,6 +716,11 @@ function clipLine(line: string, kind: 'matching' | 'context'): string {
694
716
  return line.length > MAX_LINE_COLUMNS ? `[Omitted long ${kind} line]` : line
695
717
  }
696
718
 
719
+ /** Code-unit order, the same on every machine and locale. */
720
+ function byPath(a: string, b: string): number {
721
+ return a < b ? -1 : a > b ? 1 : 0
722
+ }
723
+
697
724
  /**
698
725
  * Newest modification first; ties by path. A file that cannot be stat'ed, and
699
726
  * every file in a sandbox (which reports no modification time), sorts as
@@ -1,6 +1,7 @@
1
1
  export { ReadFileTool } from './read-file.js'
2
2
  export { WriteFileTool } from './write-file.js'
3
3
  export { EditTool } from './edit.js'
4
+ export { NotebookEditTool } from './notebook-edit.js'
4
5
  export { BashTool } from './bash.js'
5
6
  export { GlobTool } from './glob.js'
6
7
  export {
@@ -50,6 +51,7 @@ import { EditTool } from './edit.js'
50
51
  import { GlobTool } from './glob.js'
51
52
  import { GrepTool } from './grep.js'
52
53
  import { JobTool } from './job.js'
54
+ import { NotebookEditTool } from './notebook-edit.js'
53
55
  import { ReadFileTool } from './read-file.js'
54
56
  import { VerifyOutputsTool } from './verify-outputs.js'
55
57
  import { WaitForJobTool } from './wait-for-job.js'
@@ -66,6 +68,19 @@ import { WriteFileTool } from './write-file.js'
66
68
  // `Append` tool is gone.
67
69
  // Hosts that genuinely want LS/search can still register them explicitly.
68
70
 
71
+ /**
72
+ * The notebook tool, for a host that loads it on demand.
73
+ *
74
+ * Not in `getBuiltinTools()`: its schema is about two kilobytes on every
75
+ * request and most turns never touch a notebook. A host mounts it deferred, so
76
+ * the model finds it through `search_tools` from the first line of its
77
+ * description (which names Jupyter notebooks and .ipynb cells), and mounts it
78
+ * plainly when it loads every tool up front.
79
+ */
80
+ export function getNotebookTools(): ToolDefinition[] {
81
+ return [NotebookEditTool]
82
+ }
83
+
69
84
  export function getBuiltinTools(): ToolDefinition[] {
70
85
  // `job` ships alongside `bash` rather than being opt-in, because the two
71
86
  // are one capability. `bash run_in_background` returns an id, and an id
@@ -49,7 +49,7 @@ type JobInput = z.infer<typeof inputSchema>
49
49
  export const JobTool = defineTool({
50
50
  name: 'job',
51
51
  description:
52
- 'Reads, lists and stops background jobs started by bash with run_in_background, and monitors started by monitor (whose stderr, which is not an event, is read here). To find out whether a job finished, use wait_for_job: it blocks until the job ends (or goes quiet, or runs long) and returns the output in one call, while repeated "read" calls spend turns checking. Use "read" to see output while a job keeps running, or to pick up after a wait_for_job call gave up, passing the previous call\'s next_offset to see only new output.',
52
+ 'Reads, lists and stops background jobs started by bash with run_in_background, and monitors started by monitor (whose stderr, which is not an event, is read here). You are told when a job exits: do not poll it. Use "read" for its output, passing the previous call\'s next_offset to see only new output.',
53
53
  inputSchema,
54
54
  category: 'shell',
55
55
  permissions: ['shell_execute'],
@@ -136,10 +136,10 @@ export const MONITOR_TOOL_NAME = 'monitor'
136
136
  * rule: the watch is never run on the host to get around the sandbox.
137
137
  */
138
138
  export const MONITOR_CANNOT_DETACH =
139
- 'monitor is unavailable: this sandbox cannot start a detached process, and the watch will not be run on the host to get around it. Run the command in the foreground with bash, with a timeout.'
139
+ 'monitor is unavailable: this sandbox cannot start a detached process, and the watch will not be run on the host to get around it. Run the command in the foreground with bash.'
140
140
 
141
141
  const MONITOR_DESCRIPTION =
142
- 'Starts a command and tells you about each line it prints to stdout, as it prints it, while you keep working. Lines that arrive within 200 ms come together as one event. Use it to watch a log, a test or deploy run, a status endpoint — anything where you must react to something happening INSIDE a long-running command. For ONE notification when something finishes, do not use this: run bash with run_in_background and wait_for_job. Every stage of a pipe must flush per line or events arrive late or never (grep --line-buffered, awk with fflush(), sed -u; `head` cannot). Make the filter match failure as well as success (crash, Traceback, Error, FAILED, Killed…): silence from a monitor is not success. Poll a remote API no faster than every 30 seconds. stderr is not an event; read it with job. A monitor that prints too much is stopped, so filter at the source. It expires after the timeout (default 5 minutes, at most 30) and you get one notice; start it again if you still need it. Stop one early with job {"action":"kill","id":"<id>"}. ' +
142
+ 'Starts a command and tells you about each line it prints to stdout, as it prints it, while you keep working. Lines that arrive within 200 ms come together as one event. Use it to watch a log, a test or deploy run, a status endpoint — anything where you must react to something happening INSIDE a long-running command. For one finish, do not use this: run bash with run_in_background and end your turn, you are told when it exits. Each event wakes you, also while you wait for the person; an event is not their reply. Every stage of a pipe must flush per line or events arrive late or never (grep --line-buffered, awk with fflush(), sed -u; `head` cannot). Make the filter match failure as well as success (crash, Traceback, Error, FAILED, Killed…): silence from a monitor is not success. Poll a remote API no faster than every 30 seconds. stderr is not an event; read it with job. A monitor that prints too much is stopped, so filter at the source. It expires after the timeout (default 5 minutes, at most 30) and you get one notice. A long watch sets the maximum and starts again on that notice. Stop one early with job {"action":"kill","id":"<id>"}. ' +
143
143
  'To watch a service that PUSHES events (a CI or log stream, a change feed) give ws instead of command: { "url": "wss://…", "protocols": [...] }. Each line of each text frame becomes an event, binary frames are only counted, and the watch ends when the server closes the connection. Use it for a push stream, not for request and response. It connects from this machine, so private and local addresses are refused, and you are asked before it connects.'
144
144
 
145
145
  /** What a host can tune about the WebSocket source; for tests only, see {@link WebSocketVetOptions}. */
@@ -343,12 +343,14 @@ export function createMonitorTool(options: MonitorToolOptions = {}) {
343
343
  success: true,
344
344
  output: `WebSocket monitor started (job ${job.id}, expires in ${formatMonitorDuration(timeoutMs)} unless the server closes the connection first; you get one notice at expiry — start it again if you still need the watch). Each line of each text frame the server sends reaches you as an event while you keep working; binary frames are only counted. The connection opens in the background: if it fails you are told in an event. Do not poll or sleep. Stop it with job {"action":"kill","id":"${job.id}"}. An event may arrive while you are waiting for the user — it is not their reply.`,
345
345
  data: { jobId: job.id, monitor: true, timeoutMs, transport: 'websocket' },
346
+ launched: true,
346
347
  }
347
348
  }
348
349
  return {
349
350
  success: true,
350
351
  output: `Monitor started (job ${job.id}, expires in ${formatMonitorDuration(timeoutMs)} unless the command ends first; you get one notice at expiry — start it again if you still need the watch). Each line the command prints to stdout reaches you as an event while you keep working; do not poll or sleep. Stop it with job {"action":"kill","id":"${job.id}"}. An event may arrive while you are waiting for the user — it is not their reply.`,
351
352
  data: { jobId: job.id, monitor: true, timeoutMs },
353
+ launched: true,
352
354
  facts: {
353
355
  kind: 'command',
354
356
  command: input.command as string,