@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
@@ -42,6 +42,10 @@ import {
42
42
  import { type IterationContext, awaitDecisionDurably } from './context.js'
43
43
  import { PerCallReview } from './per-call-review.js'
44
44
 
45
+ /** Added to a refusal a `permission_denied` hook said may be tried again. */
46
+ export const PERMISSION_DENIED_RETRY_NOTE =
47
+ 'The permission_denied hook indicated you may retry this tool call.'
48
+
45
49
  interface VerificationAwareContext extends IterationContext {
46
50
  readonly verificationGate?: AuthorizationGate
47
51
  }
@@ -305,14 +309,17 @@ export async function* runToolReview(
305
309
  * a hook's answer changes nothing; one that throws is logged, not allowed to
306
310
  * fail the step.
307
311
  */
308
- const announceRefusals = async (denials?: ToolCallDenials): Promise<void> => {
309
- if (!ctx.pluginManager || !denials || denials.size === 0) return
312
+ const announceRefusals = async (
313
+ denials?: ToolCallDenials,
314
+ ): Promise<ToolCallDenials | undefined> => {
315
+ if (!ctx.pluginManager || !denials || denials.size === 0) return denials
316
+ let told: Map<string, string> | undefined
310
317
  for (const summary of toolCallSummaries) {
311
318
  const reason = denials.get(summary.id)
312
319
  if (reason === undefined || declines?.has(summary.id)) continue
313
- if (ctx.abortController.signal.aborted) return
320
+ if (ctx.abortController.signal.aborted) return told ?? denials
314
321
  try {
315
- await ctx.pluginManager.executeHooks(
322
+ const results = await ctx.pluginManager.executeHooks(
316
323
  'permission_denied',
317
324
  {
318
325
  sessionId: ctx.recorder.sessionId,
@@ -325,13 +332,18 @@ export async function* runToolReview(
325
332
  },
326
333
  ctx.emitEvent,
327
334
  )
335
+ if (results.some((result) => result.action === 'continue' && result.retryable === true)) {
336
+ told ??= new Map(denials)
337
+ told.set(summary.id, `${reason}\n\n${PERMISSION_DENIED_RETRY_NOTE}`)
338
+ }
328
339
  } catch (error) {
329
- if (ctx.abortController.signal.aborted) return
340
+ if (ctx.abortController.signal.aborted) return told ?? denials
330
341
  ctx.log.warn('A permission_denied hook failed', {
331
342
  'exception.message': error instanceof Error ? error.message : String(error),
332
343
  })
333
344
  }
334
345
  }
346
+ return told ?? denials
335
347
  }
336
348
 
337
349
  /**
@@ -374,14 +386,14 @@ export async function* runToolReview(
374
386
  denials?: ToolCallDenials,
375
387
  review?: ReviewedExecution,
376
388
  ): Promise<void> => {
377
- await announceRefusals(denials)
389
+ const told = await announceRefusals(denials)
378
390
  const startedAt = Date.now()
379
391
  const watch = watchForOperator(ctx, startedAt)
380
392
  let batch: Awaited<ReturnType<typeof ctx.toolExecutor.executeBatch>>
381
393
  try {
382
394
  batch = await ctx.toolExecutor.executeBatch(
383
395
  response,
384
- withRepeatRefusals(denials),
396
+ withRepeatRefusals(told),
385
397
  undefined,
386
398
  preparedBatch,
387
399
  declines,
@@ -448,6 +460,7 @@ export async function* runToolReview(
448
460
  ctx.awaitedJobs?.noticesDelivered()
449
461
  jobNoticeDelivered = true
450
462
  },
463
+ 'job-exit',
451
464
  )
452
465
  if (jobNotice) ctx.recorder.pushMessage(jobNotice)
453
466
  const monitorNotice = takeNoticeMessage(
@@ -460,6 +473,7 @@ export async function* runToolReview(
460
473
  ctx.awaitedJobs?.monitorNoticesDelivered()
461
474
  monitorNoticeDelivered = true
462
475
  },
476
+ 'job-event',
463
477
  )
464
478
  if (monitorNotice) ctx.recorder.pushMessage(monitorNotice)
465
479
  const lateResults = takeLateResults(ctx)
@@ -657,6 +671,7 @@ export async function* runToolReview(
657
671
  toolDef: ctx.tools.get(tc.name),
658
672
  ...dialectFor(tc.name),
659
673
  ...sourceFor(tc.name),
674
+ sessionId: ctx.recorder.sessionId,
660
675
  }),
661
676
  }))
662
677
  for (const gr of gateResults) {
@@ -1065,6 +1080,7 @@ export async function* runToolReview(
1065
1080
  toolDef: ctx.tools.get(tc.name),
1066
1081
  ...dialectFor(tc.name),
1067
1082
  ...sourceFor(tc.name),
1083
+ sessionId: ctx.recorder.sessionId,
1068
1084
  }).decision,
1069
1085
  })
1070
1086
  try {
@@ -1188,6 +1204,7 @@ export async function* runToolReview(
1188
1204
  toolDef: ctx.tools.get(summary.name),
1189
1205
  ...dialectFor(summary.name),
1190
1206
  ...sourceFor(summary.name),
1207
+ sessionId: ctx.recorder.sessionId,
1191
1208
  })
1192
1209
  if (gateResult.decision === 'allow') continue
1193
1210
  const reason =
@@ -19,7 +19,7 @@
19
19
  */
20
20
 
21
21
  import { homedir } from 'node:os'
22
- import { isAbsolute, relative, resolve, sep } from 'node:path'
22
+ import { dirname, isAbsolute, relative, resolve, sep } from 'node:path'
23
23
 
24
24
  import { isProtectedPath } from '../../authorization/protected-paths.js'
25
25
  import { dangerousRemoval } from '../../authorization/removal.js'
@@ -29,6 +29,7 @@ import {
29
29
  topLevelEntriesOfMovers,
30
30
  topLevelEntryChange,
31
31
  } from '../../authorization/top-level-entries.js'
32
+ import { resolveNamzuHome } from '../../session/home.js'
32
33
  import { canonicalize, pathOutsideRoots } from '../../tools/paths.js'
33
34
 
34
35
  /** What the escalation records carry. */
@@ -59,20 +60,56 @@ export interface PathEscalationContext {
59
60
  readonly scratchpadDirectory?: string
60
61
  }
61
62
 
63
+ /**
64
+ * Whether `base` is a managed worktree root, or a folder inside one:
65
+ * `<home>/projects/<slug>/worktrees/<name>[/...]` where `<home>` is the Namzu
66
+ * home itself (compared as resolved paths, never by its name). Only that shape
67
+ * is excused when a root's own path is protected: the checkout of delegated
68
+ * work lies under the home by construction. The folders above the home must be
69
+ * unprotected, and what lies below the worktree must hold no protected name, so
70
+ * a root that is the worktree's own `.git` or `.namzu` stays protected.
71
+ */
72
+ function isManagedWorktreeRoot(base: string): boolean {
73
+ let home: string
74
+ try {
75
+ home = resolveNamzuHome()
76
+ } catch {
77
+ return false
78
+ }
79
+ const parts = base.split(/[\\/]+/)
80
+ for (let i = 1; i + 3 < parts.length; i += 1) {
81
+ if (parts[i] !== 'projects' || parts[i + 2] !== 'worktrees') continue
82
+ if (!parts[i + 1] || !parts[i + 3]) continue
83
+ if (isProtectedPath(`x/${parts[i + 1]}`) || isProtectedPath(`x/${parts[i + 3]}`)) continue
84
+ if (resolve(parts.slice(0, i).join(sep) || sep) !== home) continue
85
+ if (isProtectedPath(dirname(home))) continue
86
+ const below = parts.slice(i + 4).join('/')
87
+ if (below !== '' && isProtectedPath(`x/${below}`)) continue
88
+ return true
89
+ }
90
+ return false
91
+ }
92
+
62
93
  /**
63
94
  * The part of `absolute` that protected names are looked for in.
64
95
  *
65
96
  * Inside a root (the working directory or an added directory) that is the part
66
97
  * below the root, not the whole path: the root is where the turn was put, and
67
- * a root that itself sits under a protected name is not a reason to ask about
68
- * every file in it. The case that matters is the managed worktree a sub-agent
98
+ * a root whose path happens to carry a name like `/work/.vscode-tools` is not a
99
+ * reason to ask about every file in it. Two kinds of root are not stripped:
100
+ * a root that is itself protected (the Namzu home, a `.git` folder, a project
101
+ * `.namzu`) is exactly what the protection is for, so adding it must not
102
+ * switch the protection off for everything below it, and the same holds when it
103
+ * is the working directory. The one excuse is the managed worktree a sub-agent
69
104
  * runs in, `~/.namzu/projects/<slug>/worktrees/<name>`, which lies under
70
- * `.namzu` by construction. A path in no root is looked at whole.
105
+ * `.namzu` by construction; its own `.git` and `.namzu` stay protected. A path
106
+ * in no usable root is looked at whole.
71
107
  */
72
108
  function protectedScope(absolute: string, roots: readonly string[]): string {
73
109
  let best: string | undefined
74
110
  for (const root of roots) {
75
111
  const base = resolve(root)
112
+ if (isProtectedPath(base) && !isManagedWorktreeRoot(base)) continue
76
113
  const below = relative(base, absolute)
77
114
  if (below === '' || below.startsWith('..') || isAbsolute(below)) continue
78
115
  if (best === undefined || below.length < best.length) best = below
@@ -80,6 +117,17 @@ function protectedScope(absolute: string, roots: readonly string[]): string {
80
117
  return best ?? absolute
81
118
  }
82
119
 
120
+ /**
121
+ * The directories among `roots` whose own path is protected, other than a
122
+ * managed worktree. Writes inside them are asked about whole-path, so a session
123
+ * that adds one gets a notice once, rather than a surprise question per file.
124
+ */
125
+ export function protectedRoots(roots: readonly string[]): string[] {
126
+ return roots
127
+ .map((root) => resolve(root))
128
+ .filter((base) => isProtectedPath(base) && !isManagedWorktreeRoot(base))
129
+ }
130
+
83
131
  /** A write is protected when its spelling, or the place a link leads to, is. */
84
132
  async function isProtectedWrite(
85
133
  spelled: string,
@@ -24,6 +24,7 @@
24
24
  import { homedir } from 'node:os'
25
25
  import { dirname, parse } from 'node:path'
26
26
 
27
+ import { allowRuleScope } from '../../authorization/gate.js'
27
28
  import { unknownProgramInLine } from '../../authorization/program.js'
28
29
  import type { ShellWord } from '../../authorization/shell-lexer.js'
29
30
  import {
@@ -31,10 +32,12 @@ import {
31
32
  readShellLine,
32
33
  shellPathAccess,
33
34
  } from '../../authorization/shell-paths.js'
35
+ import { withShellSession } from '../../authorization/shell-session-state.js'
34
36
  import { effectiveBashWorkingDirectory } from '../../tools/builtins/bash-cwd.js'
35
37
  import { BashTool } from '../../tools/builtins/bash.js'
36
38
  import { isTrustedReadOnly } from '../../tools/trusted-read-only.js'
37
39
  import type { ToolManager } from '../../toolsets/manager.js'
40
+ import type { AuthorizationRule } from '../../types/authorization/index.js'
38
41
  import type {
39
42
  HITLResumeDecision,
40
43
  LaunchedScript,
@@ -47,11 +50,13 @@ import type {
47
50
  import type { ApprovalPolicy } from '../../types/hitl/policy.js'
48
51
  import type { SessionId, TurnId } from '../../types/ids/index.js'
49
52
  import {
53
+ CLASSIFY_NESTED_REFUSAL,
50
54
  PLAN_MODE_REFUSAL,
51
55
  PLAN_MODE_REFUSAL_WITH_PLAN_FILE,
52
56
  STRICT_MODE_REFUSAL,
53
57
  nestedCallModeRefusal,
54
58
  } from '../../types/permission/index.js'
59
+ import type { ToolDefinition } from '../../types/tool/index.js'
55
60
  import type { AutoReviewClassifier, AutoReviewDecision } from './auto-review/classifier.js'
56
61
  import {
57
62
  autoReviewBlockedFeedback,
@@ -151,6 +156,7 @@ export function isReviewMode(value: unknown): value is ReviewMode {
151
156
  }
152
157
 
153
158
  export {
159
+ CLASSIFY_NESTED_REFUSAL,
154
160
  PLAN_MODE_REFUSAL,
155
161
  PLAN_MODE_REFUSAL_WITH_PLAN_FILE,
156
162
  STRICT_MODE_REFUSAL,
@@ -158,7 +164,7 @@ export {
158
164
  }
159
165
 
160
166
  /** The tools `accept-edits` approves without asking. Everything else prompts. */
161
- export const ACCEPT_EDITS_TOOLS: ReadonlySet<string> = new Set(['edit', 'write'])
167
+ export const ACCEPT_EDITS_TOOLS: ReadonlySet<string> = new Set(['edit', 'write', 'notebook_edit'])
162
168
 
163
169
  /**
164
170
  * `write` declares every call destructive (its input cannot say whether the
@@ -530,6 +536,32 @@ const CLASSIFIER_DELEGATION_TOOLS: ReadonlySet<string> = new Set([
530
536
  'continue_task',
531
537
  ])
532
538
 
539
+ /**
540
+ * Whether an allow rule is one `classify` should not defer to for this call: the
541
+ * rule covers a whole shell tool, the line starts an interpreter or a launcher
542
+ * that runs whatever it is given, or the tool starts other agents. Judged on the
543
+ * call as well as the rule because a rule that names a program ("python") is a
544
+ * rule about a program that can run anything. A nested call is judged the same
545
+ * way, so a skill's command is held to what a direct one is.
546
+ */
547
+ export function allowedCallTooWide(call: {
548
+ readonly name: string
549
+ readonly tool: Pick<ToolDefinition, 'commandArgument' | 'commandDialect'> | undefined
550
+ readonly input: unknown
551
+ readonly allowScope?: 'tool' | 'pattern' | undefined
552
+ /** The rule that allowed it, when the caller has the gate's verdict and not the scope. */
553
+ readonly allowRule?: AuthorizationRule | null
554
+ }): boolean {
555
+ if (CLASSIFIER_DELEGATION_TOOLS.has(call.name.toLowerCase())) return true
556
+ const argument = call.tool?.commandArgument
557
+ if (call.tool === undefined || argument === undefined) return false
558
+ if ((call.allowScope ?? allowRuleScope(call.allowRule ?? null)) === 'tool') return true
559
+ const line = (call.input as Record<string, unknown> | null)?.[argument]
560
+ if (typeof line !== 'string') return true
561
+ const reading = readShellLine(line, call.tool.commandDialect?.({ sandboxed: false }) ?? 'sh')
562
+ return !reading.complete || reading.invocations.some(launchesCode)
563
+ }
564
+
533
565
  /** The shell commands `accept-edits` also approves, when every path they name is inside the roots. */
534
566
  export const ACCEPT_EDITS_SHELL_COMMANDS: ReadonlySet<string> = new Set([
535
567
  'mkdir',
@@ -546,7 +578,7 @@ export const ACCEPT_EDITS_SHELL_COMMANDS: ReadonlySet<string> = new Set([
546
578
  * the first time in a session and nobody can be asked.
547
579
  */
548
580
  export const SCREEN_CONSENT_UNATTENDED_REFUSAL =
549
- "Refused: this call would send what is on the user's screen to the model provider, which a person agrees to once per session, and nobody can be asked in this session. Nothing in this batch ran. Tell the user computer use needs their consent in an interactive session."
581
+ "Refused: this call would send what is on the user's screen to the model provider, which a person agrees to once per session, and nobody can be asked in this session. Nothing in this batch ran. Do not try again in this run, and do not reach the screen another way. Tell the user computer use needs their consent in an interactive session, or a rule that allows this call by name."
550
582
 
551
583
  /** What the model is told when the operator declines to share the screen. */
552
584
  export const SCREEN_CONSENT_DECLINED_FEEDBACK =
@@ -1090,7 +1122,9 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
1090
1122
  * path, a path in a variable, a program nobody can name or a `sed` script
1091
1123
  * that can run something is not that.
1092
1124
  */
1093
- const shellFileCommandsInRoots = async (
1125
+ const shellFileCommandsInRoots = (tc: ToolCallSummary, sessionId?: string): Promise<boolean> =>
1126
+ withShellSession(sessionId, () => shellFileCommandsInRootsIn(tc, sessionId))
1127
+ const shellFileCommandsInRootsIn = async (
1094
1128
  tc: ToolCallSummary,
1095
1129
  sessionId?: string,
1096
1130
  ): Promise<boolean> => {
@@ -1161,17 +1195,13 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
1161
1195
  * Judged on the call as well as the rule because a rule that names a
1162
1196
  * program ("python") is a rule about a program that can run anything.
1163
1197
  */
1164
- const allowRuleTooWide = (tc: ToolCallSummary): boolean => {
1165
- if (CLASSIFIER_DELEGATION_TOOLS.has(tc.name.toLowerCase())) return true
1166
- const tool = toolOf(tc.name)
1167
- const argument = tool?.commandArgument
1168
- if (tool === undefined || argument === undefined) return false
1169
- if (tc.authorization?.allowScope === 'tool') return true
1170
- const line = (tc.input as Record<string, unknown> | null)?.[argument]
1171
- if (typeof line !== 'string') return true
1172
- const reading = readShellLine(line, tool.commandDialect?.({ sandboxed: false }) ?? 'sh')
1173
- return !reading.complete || reading.invocations.some(launchesCode)
1174
- }
1198
+ const allowRuleTooWide = (tc: ToolCallSummary): boolean =>
1199
+ allowedCallTooWide({
1200
+ name: tc.name,
1201
+ tool: toolOf(tc.name),
1202
+ input: tc.input,
1203
+ allowScope: tc.authorization?.allowScope,
1204
+ })
1175
1205
 
1176
1206
  /** Whether `classify` decides this call without the classifier: it would not be asked, or is plainly safe. */
1177
1207
  const neverSent = async (tc: ToolCallSummary, sessionId?: string): Promise<boolean> => {
@@ -1241,7 +1271,9 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
1241
1271
  const sessionKey = String(request.sessionId ?? '')
1242
1272
  if (
1243
1273
  consent &&
1244
- mode !== 'auto' &&
1274
+ // `auto` answers for a person who is there; with nobody to ask it cannot
1275
+ // answer for them, so the first look is refused in every mode.
1276
+ (mode !== 'auto' || !prompt) &&
1245
1277
  !consent.sessions.has(sessionKey) &&
1246
1278
  request.toolCalls.some(
1247
1279
  (tc) =>
@@ -1,11 +1,15 @@
1
1
  import { withheldEnvNoticeText } from '../../tools/env-scrub.js'
2
- import { createRuntimeContextMessage } from '../../types/message/index.js'
2
+ import {
3
+ type RuntimeContextOriginKind,
4
+ createRuntimeContextMessage,
5
+ } from '../../types/message/index.js'
3
6
  import type { Message, UserMessage } from '../../types/message/index.js'
4
7
  import { NOTICE_TAG, frameNotice, readOperatorNotice } from '../../types/message/notice-frame.js'
5
8
  import {
6
9
  MONITOR_EVENT_CONTENT_MAX_CHARS,
7
10
  MONITOR_NOTIFICATION_MAX_CHARS,
8
11
  } from '../jobs/monitor-stream.js'
12
+ import { formatMonitorDuration } from '../jobs/monitor-stream.js'
9
13
  import { type BackgroundJob, type MonitorEvent, describeMonitorEnd } from '../jobs/registry.js'
10
14
  import { formatSystemEvent, oneMetadataLine } from '../system-events.js'
11
15
 
@@ -55,6 +59,11 @@ export interface SteeringChannel {
55
59
  * not send a blank message.
56
60
  */
57
61
  steer(text: string): void
62
+ /**
63
+ * What the undelivered text is about (the ids it was queued under), taken
64
+ * without draining. Optional: a host's own channel need not say.
65
+ */
66
+ keys?(): readonly string[]
58
67
 
59
68
  /** Take everything queued, leaving the channel empty. */
60
69
  drain(): string | undefined
@@ -86,6 +95,12 @@ export class SteeringBinding implements SteeringChannel {
86
95
  return this.queued.length !== before
87
96
  }
88
97
 
98
+ keys(): readonly string[] {
99
+ return [
100
+ ...new Set(this.queued.flatMap((entry) => (entry.key === undefined ? [] : [entry.key]))),
101
+ ]
102
+ }
103
+
89
104
  drain(): string | undefined {
90
105
  if (this.queued.length === 0) return undefined
91
106
  const joined = this.queued.map((entry) => entry.text).join('\n')
@@ -113,7 +128,7 @@ export const JOB_NOTICE_INLINE_OUTPUT_MAX_BYTES = 2048
113
128
  */
114
129
  export function formatJobExitNotice(
115
130
  job: Pick<BackgroundJob, 'id' | 'command' | 'status' | 'exitCode' | 'signal'> &
116
- Partial<Pick<BackgroundJob, 'exitedAt'>>,
131
+ Partial<Pick<BackgroundJob, 'exitedAt' | 'startedAt' | 'outputFile'>>,
117
132
  output?: {
118
133
  readonly chunk: string
119
134
  readonly nextOffset: number
@@ -125,7 +140,12 @@ export function formatJobExitNotice(
125
140
  ? 'was stopped'
126
141
  : `exited with code ${job.exitCode ?? 'unknown'}${job.signal ? ` (${job.signal})` : ''}`
127
142
  const endedAt = job.exitedAt === undefined ? '' : ` at ${new Date(job.exitedAt).toISOString()}`
128
- const head = `Background job ${job.id} (${job.command}) ${outcome}${endedAt}.`
143
+ const ran =
144
+ job.exitedAt !== undefined && job.startedAt !== undefined
145
+ ? ` after ${formatMonitorDuration(Math.max(0, job.exitedAt - job.startedAt))}`
146
+ : ''
147
+ const saved = job.outputFile === undefined ? '' : ` Its output is saved to ${job.outputFile}.`
148
+ const head = `Background job ${job.id} (${job.command}) ${outcome}${endedAt}${ran}.${saved}`
129
149
  if (
130
150
  output === undefined ||
131
151
  output.chunk.length === 0 ||
@@ -399,12 +419,20 @@ export function takeNoticeMessage(
399
419
  * here, and a premature drop would strand the exit.
400
420
  */
401
421
  onDelivered?: () => void,
422
+ /** The typed origin the recorded message carries: which kind of news, and the jobs it names. */
423
+ originKind?: RuntimeContextOriginKind,
402
424
  ): UserMessage | undefined {
403
425
  if (!channel?.pending || !hasToolResult(messages)) return undefined
426
+ // Read before the drain empties the queue.
427
+ const jobIds = originKind ? (channel.keys?.() ?? []) : []
404
428
  const text = channel.drain()
405
429
  if (text === undefined) return undefined
406
430
  onDelivered?.()
407
- return createRuntimeContextMessage(format(text), 'job-exit')
431
+ return createRuntimeContextMessage(
432
+ format(text),
433
+ 'job-exit',
434
+ originKind ? [{ kind: originKind, jobIds }] : undefined,
435
+ )
408
436
  }
409
437
 
410
438
  /**
@@ -28,6 +28,7 @@ import {
28
28
  // every bug the original's comment was written to record.
29
29
  import { killTree } from '../../process/kill-tree.js'
30
30
  import { SESSION_CHILD_ENV } from '../../process/session-child.js'
31
+ import { withSafeGitConfig } from '../../tools/git-config-env.js'
31
32
  import { resolveWithinAny, resolveWithinAnyReal } from '../../tools/paths.js'
32
33
  import type { SandboxId } from '../../types/ids/index.js'
33
34
  import type {
@@ -605,7 +606,8 @@ export function buildSafeEnv(
605
606
  setEnvironmentEntry(env, SESSION_CHILD_ENV, '1')
606
607
 
607
608
  // A shell inside the sandbox can run `node` when the user's PATH has none.
608
- return withNodeOnPath(env)
609
+ // And git inside it ignores a folder that only looks like a repository.
610
+ return withSafeGitConfig(withNodeOnPath(env))
609
611
  }
610
612
 
611
613
  /**
@@ -125,6 +125,8 @@ export function describeSchedule(
125
125
  return `once at ${formatWall(Date.parse(spec.at), tz)} (${tz})`
126
126
  case 'every':
127
127
  return describeInterval(spec.everyMs)
128
+ case 'watch':
129
+ return `when ${spec.uri} changes on the tool server ${spec.server} (at most one run every ${describeInterval(spec.minIntervalMs).replace(/^every /, '')}; paused past ${spec.maxEventsPerHour} updates an hour)`
128
130
  case 'cron': {
129
131
  let e: CronExpression
130
132
  try {
@@ -24,6 +24,10 @@
24
24
  * `missed` record; older than the window, nothing fires.
25
25
  * 5. An unfinished run of the same job skips what came due meanwhile.
26
26
  * 6. A provider quota hold skips what comes due before the hold ends.
27
+ * 7. A job with `expiresAt` never fires an occurrence at or after it. The
28
+ * first evaluation at or after that instant expires the job, in any
29
+ * state, and records what came due before it as one `job-expired` skip:
30
+ * a job past its time box does not run, not even to catch up.
27
31
  */
28
32
 
29
33
  import { countOccurrences, nextFireTime, previousFireTime } from './next-fire.js'
@@ -64,11 +68,15 @@ export function evaluateJob(input: ScheduleEvaluationInput): ScheduleDecision {
64
68
  if (state.jobRevision !== undefined && state.jobRevision !== job.revision) {
65
69
  baseMs = Math.max(baseMs, Date.parse(job.updatedAt))
66
70
  }
71
+ const expiresMs = job.expiresAt === undefined ? Number.NaN : Date.parse(job.expiresAt)
72
+ const timeBoxed = Number.isFinite(expiresMs)
67
73
  const nextState = (evaluatedMs: number): ScheduleDecision['nextState'] => {
68
74
  const next = nextFireTime(job.spec, new Date(evaluatedMs))
75
+ // A time at or after the time box is not a next run.
76
+ const within = next && !(timeBoxed && next.getTime() >= expiresMs)
69
77
  return {
70
78
  lastEvaluatedAt: new Date(evaluatedMs),
71
- ...(next ? { nextFireAt: next } : {}),
79
+ ...(within ? { nextFireAt: next } : {}),
72
80
  jobRevision: job.revision,
73
81
  }
74
82
  }
@@ -82,6 +90,26 @@ export function evaluateJob(input: ScheduleEvaluationInput): ScheduleDecision {
82
90
  // Rule 2: a clock that went backwards decides nothing new.
83
91
  if (nowMs <= baseMs) return { skip: [], nextState: nextState(baseMs) }
84
92
 
93
+ // Rule 7: past the time box nothing fires, and the job is done.
94
+ if (timeBoxed && nowMs >= expiresMs) {
95
+ // Occurrences strictly before the box closed (ranges count `(from, to]`).
96
+ const before =
97
+ expiresMs - 1 > baseMs
98
+ ? countOccurrences(job.spec, new Date(baseMs), new Date(expiresMs - 1))
99
+ : undefined
100
+ return {
101
+ skip:
102
+ before && before.count > 0 && before.latest
103
+ ? [{ scheduledFor: before.latest, reason: 'job-expired', count: before.count }]
104
+ : [],
105
+ jobTransition: 'expired',
106
+ nextState: {
107
+ lastEvaluatedAt: new Date(nowMs),
108
+ jobRevision: job.revision,
109
+ },
110
+ }
111
+ }
112
+
85
113
  const due = countOccurrences(job.spec, new Date(baseMs), now)
86
114
  if (due.count === 0 || !due.latest) {
87
115
  if (job.spec.kind === 'at' && Date.parse(job.spec.at) <= baseMs && job.state !== 'active') {
@@ -12,7 +12,15 @@ export {
12
12
  nextFireTime,
13
13
  previousFireTime,
14
14
  } from './next-fire.js'
15
- export { parseDuration, parseScheduleSpec, upcomingFireTimes } from './spec.js'
15
+ export { parseDuration, parseScheduleExpiry, parseScheduleSpec, upcomingFireTimes } from './spec.js'
16
16
  export type { ParseScheduleOptions } from './spec.js'
17
17
  export { hostTimeZone, validateTimeZone } from './tz.js'
18
+ export {
19
+ SCHEDULE_WATCH_DEFAULT_INTERVAL_MS,
20
+ SCHEDULE_WATCH_DEFAULT_MAX_EVENTS_PER_HOUR,
21
+ SCHEDULE_WATCH_MAX_EVENTS_PER_HOUR,
22
+ SCHEDULE_WATCH_MIN_INTERVAL_MS,
23
+ parseWatchSpec,
24
+ } from './watch.js'
25
+ export type { ParseWatchOptions } from './watch.js'
18
26
  export type * from './types.js'
@@ -117,6 +117,9 @@ export function nextFireTime(spec: ScheduleSpec, afterExclusive: Date): Date | n
117
117
  const at = Date.parse(spec.at)
118
118
  return Number.isFinite(at) && at > after ? new Date(at) : null
119
119
  }
120
+ // A watch has no times: the host's subscription starts its runs.
121
+ case 'watch':
122
+ return null
120
123
  case 'every': {
121
124
  const anchor = validEvery(spec)
122
125
  const k = after < anchor ? 1 : Math.floor((after - anchor) / spec.everyMs) + 1
@@ -147,6 +150,8 @@ export function previousFireTime(spec: ScheduleSpec, atOrBefore: Date): Date | n
147
150
  const at = Date.parse(spec.at)
148
151
  return Number.isFinite(at) && at <= before ? new Date(at) : null
149
152
  }
153
+ case 'watch':
154
+ return null
150
155
  case 'every': {
151
156
  const anchor = validEvery(spec)
152
157
  const k = Math.floor((before - anchor) / spec.everyMs)
@@ -189,6 +194,8 @@ export function countOccurrences(
189
194
  ? { count: 1, capped: false, first: new Date(at), latest: new Date(at) }
190
195
  : { count: 0, capped: false }
191
196
  }
197
+ case 'watch':
198
+ return { count: 0, capped: false }
192
199
  case 'every': {
193
200
  const anchor = validEvery(spec)
194
201
  const firstK = from < anchor ? 1 : Math.floor((from - anchor) / spec.everyMs) + 1
@@ -242,6 +249,8 @@ export function countOccurrences(
242
249
 
243
250
  /** Validate a spec as a whole: its zone, its expression, and that it can ever fire after `now`. */
244
251
  export function assertSpecFires(spec: ScheduleSpec, now: Date): void {
252
+ // A watch fires on an event, not on a time; its fields are checked by `parseWatchSpec`.
253
+ if (spec.kind === 'watch') return
245
254
  if (spec.kind === 'cron') {
246
255
  validateTimeZone(spec.tz)
247
256
  cronOf(spec.expr)
@@ -208,3 +208,45 @@ export function upcomingFireTimes(spec: ScheduleSpec, after: Date, count = 3): D
208
208
  }
209
209
  return out
210
210
  }
211
+
212
+ /**
213
+ * Turn the words for a job's time box into one absolute instant (ISO-8601
214
+ * UTC), written down at creation so `in 7d` means seven days from now and not
215
+ * from every later read. The words are a time: `in 7d`, `at 2026-12-31 17:00`
216
+ * (read in `tz`), a bare `2026-12-31 17:00` or an ISO instant. A repeating
217
+ * schedule is refused. The instant must be after the spec's first run, or the
218
+ * job would end before it ran once.
219
+ */
220
+ export function parseScheduleExpiry(
221
+ input: string,
222
+ spec: ScheduleSpec,
223
+ options: ParseScheduleOptions = {},
224
+ ): string {
225
+ const now = options.now ?? new Date()
226
+ const text = input.trim()
227
+ if (text === '') throw new ScheduleValidationError('expires needs a time', '')
228
+ const lower = text.toLowerCase()
229
+ const words = lower.startsWith('in ') || lower.startsWith('at ') ? text : `at ${text}`
230
+ let parsed: ScheduleSpec
231
+ try {
232
+ parsed = parseScheduleSpec(words, options)
233
+ } catch (error) {
234
+ if (error instanceof ScheduleValidationError)
235
+ throw new ScheduleValidationError(`expires: ${error.message}`, error.token)
236
+ throw error
237
+ }
238
+ if (parsed.kind !== 'at') {
239
+ throw new ScheduleValidationError(
240
+ 'expires is a time (in 7d, at 2026-12-31 17:00), not a repeating schedule',
241
+ text,
242
+ )
243
+ }
244
+ const first = nextFireTime(spec, now)
245
+ if (first && Date.parse(parsed.at) <= first.getTime()) {
246
+ throw new ScheduleValidationError(
247
+ `expires ${parsed.at} is not after the first run (${first.toISOString()}); the job would end before it ran`,
248
+ text,
249
+ )
250
+ }
251
+ return parsed.at
252
+ }
@@ -4,8 +4,9 @@
4
4
  * The SDK owns WHEN something is due and nothing about how a host stores a
5
5
  * job or runs it: the CLI keeps its job files, claims and history records to
6
6
  * itself, so its on-disk format is not SDK API. The unions exported here
7
- * (`ScheduleDecision`, `ScheduleSkipReason`, `ScheduleMissedReason`) may grow
8
- * in a minor release; switch over them with a `default:` branch.
7
+ * (`ScheduleSpec`, `ScheduleDecision`, `ScheduleSkipReason`,
8
+ * `ScheduleMissedReason`) may grow in a minor release; switch over them with
9
+ * a `default:` branch.
9
10
  */
10
11
 
11
12
  /** A single instant (ISO-8601 UTC). */
@@ -34,7 +35,29 @@ export interface ScheduleCronSpec {
34
35
  readonly tz: string
35
36
  }
36
37
 
37
- export type ScheduleSpec = ScheduleAtSpec | ScheduleEverySpec | ScheduleCronSpec
38
+ /**
39
+ * Not a time: the job wakes when one resource of one tool server changes.
40
+ * The evaluator never finds an occurrence for it (the host's watch is what
41
+ * starts a run), so the time engine reports no next run and a time box, a
42
+ * pause or a pending confirmation still apply as for any job.
43
+ */
44
+ export interface ScheduleWatchSpec {
45
+ readonly kind: 'watch'
46
+ /** The tool server's configured name. */
47
+ readonly server: string
48
+ /** The resource's address, exactly as the server lists it. */
49
+ readonly uri: string
50
+ /**
51
+ * At least this long between two runs; updates that arrive meanwhile
52
+ * collapse into the next run. Whole seconds, at least
53
+ * {@link SCHEDULE_WATCH_MIN_INTERVAL_MS}.
54
+ */
55
+ readonly minIntervalMs: number
56
+ /** More updates than this in one hour pause the job. A positive whole number. */
57
+ readonly maxEventsPerHour: number
58
+ }
59
+
60
+ export type ScheduleSpec = ScheduleAtSpec | ScheduleEverySpec | ScheduleCronSpec | ScheduleWatchSpec
38
61
 
39
62
  /** A parsed cron expression: each field as the sorted set of values it allows. */
40
63
  export interface CronExpression {
@@ -67,6 +90,7 @@ export type ScheduleSkipReason =
67
90
  | 'beyond-catch-up-window'
68
91
  | 'one-shot-expired'
69
92
  | 'quota-hold'
93
+ | 'job-expired'
70
94
 
71
95
  /** Why occurrences were missed. Best effort; may grow in a minor release. */
72
96
  export type ScheduleMissedReason = 'daemon-not-running' | 'machine-asleep' | 'clock-jumped-forward'
@@ -89,6 +113,12 @@ export interface ScheduleEvaluationJob {
89
113
  readonly updatedAt: string
90
114
  /** Bumped on every definition change. */
91
115
  readonly revision: number
116
+ /**
117
+ * The job's time box, ISO-8601 UTC. An occurrence at or after this instant
118
+ * never fires, and the first evaluation at or after it ends the job
119
+ * (`jobTransition: 'expired'`), whatever state it was in.
120
+ */
121
+ readonly expiresAt?: string
92
122
  }
93
123
 
94
124
  /** What the host remembers between evaluations of one job. */