@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
@@ -997,6 +997,382 @@ function touchOperands(args: Args): ShellWord[] {
997
997
  return out
998
998
  }
999
999
 
1000
+ /** The value of a flag that may be attached (`-oX`, `--output=X`) or separate (`-o X`). */
1001
+ function flagValues(args: Args, short: string, long: readonly string[]): ShellWord[] {
1002
+ const out: ShellWord[] = []
1003
+ for (let i = 0; i < args.length; i += 1) {
1004
+ const arg = args[i] as ShellWord
1005
+ const text = arg.value
1006
+ if (text === '--') break
1007
+ if (text.startsWith('--')) {
1008
+ const eq = text.indexOf('=')
1009
+ const name = eq >= 0 ? text.slice(0, eq) : text
1010
+ if (!long.includes(name)) continue
1011
+ if (eq >= 0) out.push(derived(arg, text.slice(eq + 1)))
1012
+ else if (args[i + 1] !== undefined) out.push(args[i + 1] as ShellWord)
1013
+ continue
1014
+ }
1015
+ if (text.startsWith('-') && text.length > 1 && short !== '') {
1016
+ const at = text.indexOf(short, 1)
1017
+ if (at < 0) continue
1018
+ const rest = text.slice(at + 1)
1019
+ if (rest !== '') out.push(derived(arg, rest))
1020
+ else if (args[i + 1] !== undefined) out.push(args[i + 1] as ShellWord)
1021
+ }
1022
+ }
1023
+ return out
1024
+ }
1025
+
1026
+ /** Whether any short flag cluster holds one of `letters` (`-xf`, `-x`). */
1027
+ function hasShort(args: Args, letters: string): boolean {
1028
+ return args.some(
1029
+ (a) =>
1030
+ !a.value.startsWith('--') &&
1031
+ a.value.startsWith('-') &&
1032
+ [...letters].some((l) => a.value.slice(1).includes(l)),
1033
+ )
1034
+ }
1035
+
1036
+ /**
1037
+ * Positional arguments once the value of every option that takes one is
1038
+ * skipped. `valuedLong` are `--name VALUE` options (`--name=VALUE` is one
1039
+ * word and never needs skipping); `valuedShort` letters take the rest of the
1040
+ * cluster or, when last, the next word. An option not named here is a switch.
1041
+ */
1042
+ function operandsSkippingValues(
1043
+ args: Args,
1044
+ valuedLong: ReadonlySet<string>,
1045
+ valuedShort: string,
1046
+ ): ShellWord[] {
1047
+ const out: ShellWord[] = []
1048
+ for (let i = 0; i < args.length; i += 1) {
1049
+ const arg = args[i] as ShellWord
1050
+ const text = arg.value
1051
+ if (text === '--') {
1052
+ out.push(...args.slice(i + 1))
1053
+ break
1054
+ }
1055
+ if (text === '-' || !text.startsWith('-')) {
1056
+ out.push(arg)
1057
+ } else if (text.startsWith('--')) {
1058
+ if (!text.includes('=') && valuedLong.has(text)) i += 1
1059
+ } else {
1060
+ for (let j = 1; j < text.length; j += 1) {
1061
+ if (valuedShort.includes(text[j] as string)) {
1062
+ if (j === text.length - 1) i += 1
1063
+ break
1064
+ }
1065
+ }
1066
+ }
1067
+ }
1068
+ return out
1069
+ }
1070
+
1071
+ const GIT_CLONE_VALUED = set(
1072
+ '--depth',
1073
+ '--branch',
1074
+ '--origin',
1075
+ '--config',
1076
+ '--template',
1077
+ '--reference',
1078
+ '--reference-if-able',
1079
+ '--separate-git-dir',
1080
+ '--jobs',
1081
+ '--filter',
1082
+ '--upload-pack',
1083
+ '--server-option',
1084
+ '--shallow-since',
1085
+ '--shallow-exclude',
1086
+ '--bundle-uri',
1087
+ '--ref-format',
1088
+ '--object-format',
1089
+ '--revision',
1090
+ )
1091
+ const GIT_INIT_VALUED = set(
1092
+ '--template',
1093
+ '--initial-branch',
1094
+ '--object-format',
1095
+ '--separate-git-dir',
1096
+ '--ref-format',
1097
+ )
1098
+ const RSYNC_VALUED = set(
1099
+ '--exclude',
1100
+ '--include',
1101
+ '--filter',
1102
+ '--exclude-from',
1103
+ '--include-from',
1104
+ '--rsh',
1105
+ '--rsync-path',
1106
+ '--log-file',
1107
+ '--backup-dir',
1108
+ '--partial-dir',
1109
+ '--temp-dir',
1110
+ '--files-from',
1111
+ '--port',
1112
+ '--bwlimit',
1113
+ '--max-size',
1114
+ '--min-size',
1115
+ '--timeout',
1116
+ '--compare-dest',
1117
+ '--copy-dest',
1118
+ '--link-dest',
1119
+ '--suffix',
1120
+ '--chmod',
1121
+ '--chown',
1122
+ '--usermap',
1123
+ '--groupmap',
1124
+ '--block-size',
1125
+ '--compress-level',
1126
+ '--skip-compress',
1127
+ '--address',
1128
+ '--sockopts',
1129
+ '--out-format',
1130
+ '--info',
1131
+ '--debug',
1132
+ '--read-batch',
1133
+ '--write-batch',
1134
+ '--only-write-batch',
1135
+ '--password-file',
1136
+ '--protocol',
1137
+ '--iconv',
1138
+ '--max-delete',
1139
+ '--modify-window',
1140
+ '--checksum-seed',
1141
+ '--stop-after',
1142
+ '--stop-at',
1143
+ '--early-input',
1144
+ '--outbuf',
1145
+ )
1146
+
1147
+ /**
1148
+ * The places a program writes through an output flag or a destination operand,
1149
+ * for the programs that download, copy or unpack. None of them is in the
1150
+ * reading table, and each can plant a file at a path the line names. One that
1151
+ * downloads or unpacks into the current directory when it is given no
1152
+ * destination reports `.`.
1153
+ */
1154
+ function outputTargets(program: string, args: Args): ShellWord[] {
1155
+ const dot = word('.')
1156
+ switch (program) {
1157
+ case 'curl': {
1158
+ const out = flagValues(args, 'o', ['--output'])
1159
+ out.push(...flagValues(args, 'D', ['--dump-header']))
1160
+ out.push(...flagValues(args, 'c', ['--cookie-jar']))
1161
+ out.push(...flagValues(args, '', ['--output-dir', '--trace', '--trace-ascii', '--stderr']))
1162
+ if (hasShort(args, 'O') || args.some((a) => a.value === '--remote-name')) out.push(dot)
1163
+ return out
1164
+ }
1165
+ case 'wget': {
1166
+ const document = flagValues(args, 'O', ['--output-document'])
1167
+ const out = [...document]
1168
+ out.push(...flagValues(args, 'P', ['--directory-prefix']))
1169
+ out.push(...flagValues(args, 'o', ['--output-file']))
1170
+ out.push(...flagValues(args, 'a', ['--append-output']))
1171
+ out.push(...flagValues(args, '', ['--save-cookies']))
1172
+ if (document.length === 0) out.push(dot)
1173
+ return out
1174
+ }
1175
+ case 'dd':
1176
+ return args.filter((a) => a.value.startsWith('of=')).map((a) => derived(a, a.value.slice(3)))
1177
+ case 'install':
1178
+ return [...copyOperands(args), ...(hasShort(args, 'd') ? operands(args) : [])]
1179
+ case 'rsync': {
1180
+ const rest = operandsSkippingValues(args, RSYNC_VALUED, 'eTBMfgp'.replace(/[gp]/g, ''))
1181
+ return rest.length > 1 ? [rest[rest.length - 1] as ShellWord] : []
1182
+ }
1183
+ case 'tar': {
1184
+ const out = [...flagValues(args, 'C', ['--directory'])]
1185
+ const first = args[0]?.value ?? ''
1186
+ const old = !first.startsWith('-') && /^[A-Za-z]+$/.test(first) ? first : ''
1187
+ const has = (letter: string): boolean => old.includes(letter) || hasShort(args, letter)
1188
+ const extracts = has('x') || args.some((a) => a.value === '--extract' || a.value === '--get')
1189
+ const creates = has('c') || args.some((a) => a.value === '--create')
1190
+ if (extracts && out.length === 0) out.push(dot)
1191
+ const rewrites =
1192
+ has('r') ||
1193
+ has('u') ||
1194
+ has('A') ||
1195
+ args.some((a) => /^--(?:append|update|catenate|concatenate|delete)$/.test(a.value))
1196
+ if (creates || rewrites) {
1197
+ out.push(...flagValues(args, 'f', ['--file']))
1198
+ const named = args[1]
1199
+ if (old.includes('f') && named !== undefined) out.push(named)
1200
+ }
1201
+ return out
1202
+ }
1203
+ case 'unzip': {
1204
+ const lists = args.some((a) => {
1205
+ if (a.value.startsWith('--') || !a.value.startsWith('-')) return false
1206
+ for (const letter of a.value.slice(1)) {
1207
+ if ('dxP'.includes(letter)) return false
1208
+ if ('lptvZ'.includes(letter)) return true
1209
+ }
1210
+ return false
1211
+ })
1212
+ if (lists) return []
1213
+ const out = flagValues(args, 'd', [])
1214
+ return out.length > 0 ? out : [dot]
1215
+ }
1216
+ case 'git': {
1217
+ const valued = new Set(['-C', '-c', '--git-dir', '--work-tree', '--namespace'])
1218
+ let index = 0
1219
+ let base = ''
1220
+ const hooked: ShellWord[] = []
1221
+ while (index < args.length && (args[index] as ShellWord).value.startsWith('-')) {
1222
+ const flag = (args[index] as ShellWord).value
1223
+ index += 1
1224
+ if (valued.has(flag) && index < args.length) {
1225
+ if (flag === '-C') base = (args[index] as ShellWord).value
1226
+ if (
1227
+ flag === '-c' &&
1228
+ /^core\.(?:hookspath|fsmonitor|sshcommand|pager|editor)=/i.test(
1229
+ (args[index] as ShellWord).value,
1230
+ )
1231
+ ) {
1232
+ hooked.push(word('.git/hooks'))
1233
+ }
1234
+ index += 1
1235
+ }
1236
+ }
1237
+ const sub = args[index]?.value
1238
+ const place = (target: ShellWord | undefined): ShellWord => {
1239
+ const value = target?.value ?? '.'
1240
+ const placed =
1241
+ base === '' || value.startsWith('/') || value.startsWith('~')
1242
+ ? value
1243
+ : `${base.replace(/\/+$/, '')}/${value}`
1244
+ return target === undefined ? word(placed) : derived(target, placed)
1245
+ }
1246
+ const tail = args.slice(index + 1)
1247
+ if (sub === 'clone' || sub === 'init') {
1248
+ const rest = operandsSkippingValues(
1249
+ tail,
1250
+ sub === 'clone' ? GIT_CLONE_VALUED : GIT_INIT_VALUED,
1251
+ sub === 'clone' ? 'bocju' : 'b',
1252
+ )
1253
+ // A clone names its destination last; one operand is only the source.
1254
+ const target =
1255
+ sub === 'clone' ? (rest.length > 1 ? rest[rest.length - 1] : undefined) : rest[0]
1256
+ return [...hooked, place(target)]
1257
+ }
1258
+ if (sub === 'config') {
1259
+ const file = flagValues(tail, 'f', ['--file'])
1260
+ if (file.length > 0) return [...hooked, ...file.map((f) => place(f))]
1261
+ const reads = tail.some((a) =>
1262
+ /^(?:--get|--get-all|--get-regexp|--get-urlmatch|--list|-l|--show-origin|--show-scope|--name-only)$/.test(
1263
+ a.value,
1264
+ ),
1265
+ )
1266
+ const given = operandsSkippingValues(
1267
+ tail,
1268
+ set('--file', '--blob', '--type', '--default'),
1269
+ 'f',
1270
+ )
1271
+ const writes = tail.some((a) =>
1272
+ /^(?:--add|--unset|--unset-all|--replace-all|--edit|-e|--rename-section|--remove-section)$/.test(
1273
+ a.value,
1274
+ ),
1275
+ )
1276
+ const risky =
1277
+ /^(?:core|alias|credential|filter|include|includeif|url|protocol|gpg|diff|merge|pager|sequence|uploadpack|receive|http|ssh|safe|submodule)\./i.test(
1278
+ given[0]?.value ?? '',
1279
+ ) ||
1280
+ /\.(?:command|cmd|driver|textconv|program|sshcommand|helper|path)$/i.test(
1281
+ given[0]?.value ?? '',
1282
+ )
1283
+ if (!reads && (writes || given.length >= 2) && risky) {
1284
+ return [...hooked, place(word('.git/config'))]
1285
+ }
1286
+ return hooked
1287
+ }
1288
+ if (sub === 'archive')
1289
+ return [...hooked, ...flagValues(tail, 'o', ['--output']).map((f) => place(f))]
1290
+ if (sub === 'bundle' && tail[0]?.value === 'create' && tail[1] !== undefined) {
1291
+ return [...hooked, place(tail[1])]
1292
+ }
1293
+ if (sub === 'worktree' && tail[0]?.value === 'add') {
1294
+ const dest = operandsSkippingValues(tail.slice(1), set('--reason'), 'bB')[0]
1295
+ return [...hooked, ...(dest !== undefined ? [place(dest)] : [])]
1296
+ }
1297
+ return hooked
1298
+ }
1299
+ case 'ln': {
1300
+ const into = flagValues(args, 't', ['--target-directory'])
1301
+ if (into.length > 0) return into
1302
+ const rest = operandsSkippingValues(args, set('--suffix'), 'S')
1303
+ return rest.length > 0 ? [rest.length > 1 ? (rest[rest.length - 1] as ShellWord) : dot] : []
1304
+ }
1305
+ case 'zip': {
1306
+ const out = flagValues(args, 'O', ['--output-file'])
1307
+ if (out.length > 0) return out
1308
+ const first = operandsSkippingValues(
1309
+ args,
1310
+ set('--temp-path', '--password'),
1311
+ 'btnPpdf'.replace(/[pdf]/g, ''),
1312
+ )[0]
1313
+ return first === undefined ? [] : [first]
1314
+ }
1315
+ case 'patch': {
1316
+ const out = flagValues(args, 'o', ['--output'])
1317
+ if (out.length > 0) return out
1318
+ const first = operandsSkippingValues(
1319
+ args,
1320
+ set(
1321
+ '--strip',
1322
+ '--input',
1323
+ '--directory',
1324
+ '--reject-file',
1325
+ '--backup-prefix',
1326
+ '--suffix',
1327
+ '--basename-prefix',
1328
+ '--fuzz',
1329
+ '--version-control',
1330
+ ),
1331
+ 'pidDrBVYzF',
1332
+ )[0]
1333
+ return first === undefined ? [] : [first]
1334
+ }
1335
+ case 'truncate':
1336
+ return operandsSkippingValues(args, set('--size', '--reference', '--io-blocks'), 'sr')
1337
+ case 'perl': {
1338
+ const inPlace = args.some((a) => /^-[A-Za-z0-9]*i/.test(a.value) && !a.value.startsWith('--'))
1339
+ if (!inPlace) return []
1340
+ const script = args.some(
1341
+ (a) => /^-[A-Za-z0-9]*[eE]/.test(a.value) && !a.value.startsWith('--'),
1342
+ )
1343
+ const files = operandsSkippingValues(args, set(), 'eEIMmxCl'.replace(/[Cl]/g, ''))
1344
+ return script ? files : files.slice(1)
1345
+ }
1346
+ case 'sort':
1347
+ return flagValues(args, 'o', ['--output'])
1348
+ case 'openssl':
1349
+ return args.flatMap((a, i) =>
1350
+ ['-out', '-keyout', '-outform'].includes(a.value) &&
1351
+ a.value !== '-outform' &&
1352
+ args[i + 1] !== undefined
1353
+ ? [args[i + 1] as ShellWord]
1354
+ : [],
1355
+ )
1356
+ case 'ssh-keygen': {
1357
+ const key = flagValues(args, 'f', [])
1358
+ return key.flatMap((k) => [k, derived(k, `${k.value}.pub`)])
1359
+ }
1360
+ case 'find':
1361
+ return args.flatMap((a, i) =>
1362
+ /^-f(?:print|print0|printf|ls)$/.test(a.value) && args[i + 1] !== undefined
1363
+ ? [args[i + 1] as ShellWord]
1364
+ : [],
1365
+ )
1366
+ case 'aria2c':
1367
+ return [
1368
+ ...flagValues(args, 'd', ['--dir']),
1369
+ ...flagValues(args, '', ['--out', '--log', '--save-cookies', '--save-session']),
1370
+ ]
1371
+ default:
1372
+ return []
1373
+ }
1374
+ }
1375
+
1000
1376
  /** Commands that create or change what their operands name. `sed` is added per call when it edits in place. */
1001
1377
  const WRITERS = new Set(['mkdir', 'touch', 'rm', 'rmdir', 'mv', 'cp', 'tee'])
1002
1378
 
@@ -1063,6 +1439,16 @@ export function shellPathAccess(reading: ShellReading): ShellPathAccess {
1063
1439
  })
1064
1440
  }
1065
1441
  }
1442
+ for (const arg of outputTargets(program, args)) {
1443
+ if (arg.value === '' || arg.value === '-' || isHarmlessTarget(arg.value)) continue
1444
+ uses.push({
1445
+ path: arg.value,
1446
+ access: 'write',
1447
+ via: program,
1448
+ unresolved: expandsAtRuntime(arg),
1449
+ ...(directory !== undefined ? { directory } : {}),
1450
+ })
1451
+ }
1066
1452
  if (program === 'touch') {
1067
1453
  for (const arg of touchReferences(args)) {
1068
1454
  if (arg.value === '' || isHarmlessTarget(arg.value)) continue
@@ -0,0 +1,97 @@
1
+ /**
2
+ * What one shell session has been told about its variables, kept between the
3
+ * lines the session runs.
4
+ *
5
+ * Once a name has the integer attribute (`declare -i`, `typeset -i`,
6
+ * `local -i`, also `-n`), bash evaluates every later value stored into it as
7
+ * arithmetic, and a value such as `a[$(cmd)]` runs `cmd`. The lexer reads one
8
+ * line at a time, so a later line that stores such a value looks harmless on
9
+ * its own. This module keeps the names, and whether the set of names is
10
+ * known at all, for the session; the lexer reads them back (see
11
+ * {@link currentShellAttributes}) and the `bash` tool records into them.
12
+ */
13
+
14
+ import { AsyncLocalStorage } from 'node:async_hooks'
15
+
16
+ /** An immutable view of one session's attributes. A new object replaces it on every change. */
17
+ export interface ShellAttributes {
18
+ /** Names given the integer (or name-reference) attribute by an earlier line. */
19
+ readonly integers: ReadonlySet<string>
20
+ /**
21
+ * An earlier line gave the attribute to a name that cannot be known
22
+ * (`declare -i "$v"`, `declare -i $(…)`, `eval`, `source`): any later
23
+ * stored value that may hold a subscript is then opaque.
24
+ */
25
+ readonly unknown: boolean
26
+ }
27
+
28
+ /** Sessions remembered; the oldest is forgotten first. */
29
+ const MAX_SESSIONS = 256
30
+ const sessions = new Map<string, ShellAttributes>()
31
+ interface ShellScope {
32
+ readonly sessionId: string
33
+ /** The host folder the session's next command starts in, when known. */
34
+ readonly directory: string | undefined
35
+ }
36
+ const scope = new AsyncLocalStorage<ShellScope>()
37
+
38
+ /**
39
+ * Runs `fn` with `sessionId`'s attributes visible to every line read inside
40
+ * it, however deep the async calls go. Without a session id it runs as is.
41
+ *
42
+ * `directory` is the host folder the session's next command starts in. A
43
+ * read-only decision about a `git` line needs it, because git decides what to
44
+ * trust from the folder it starts in, not from the line. A nested call for the
45
+ * same session that names none keeps the outer one's.
46
+ */
47
+ export function withShellSession<T>(
48
+ sessionId: string | undefined,
49
+ fn: () => T,
50
+ directory?: string,
51
+ ): T {
52
+ if (sessionId === undefined) return fn()
53
+ const outer = scope.getStore()
54
+ const kept = directory ?? (outer?.sessionId === sessionId ? outer.directory : undefined)
55
+ return scope.run({ sessionId, directory: kept }, fn)
56
+ }
57
+
58
+ /** The attributes of the session the caller runs in, or undefined when it has recorded none. */
59
+ export function currentShellAttributes(): ShellAttributes | undefined {
60
+ const id = scope.getStore()?.sessionId
61
+ return id === undefined ? undefined : sessions.get(id)
62
+ }
63
+
64
+ /** The host folder the running session's next command starts in, or undefined when not known. */
65
+ export function currentShellDirectory(): string | undefined {
66
+ return scope.getStore()?.directory
67
+ }
68
+
69
+ /** Adds what a line declared to the session's attributes. */
70
+ export function noteShellAttributes(
71
+ sessionId: string,
72
+ declared: { readonly integers: readonly string[]; readonly unknown: boolean },
73
+ ): void {
74
+ if (declared.integers.length === 0 && !declared.unknown) return
75
+ const before = sessions.get(sessionId)
76
+ const integers = new Set(before?.integers)
77
+ for (const name of declared.integers) integers.add(name)
78
+ sessions.delete(sessionId)
79
+ sessions.set(sessionId, {
80
+ integers,
81
+ unknown: (before?.unknown ?? false) || declared.unknown,
82
+ })
83
+ if (sessions.size > MAX_SESSIONS) {
84
+ const oldest = sessions.keys().next().value
85
+ if (oldest !== undefined) sessions.delete(oldest)
86
+ }
87
+ }
88
+
89
+ /** A restarted shell session starts with no attributes. */
90
+ export function forgetShellSession(sessionId: string): void {
91
+ sessions.delete(sessionId)
92
+ }
93
+
94
+ /** For tests: forget every session. */
95
+ export function forgetAllShellSessions(): void {
96
+ sessions.clear()
97
+ }
@@ -0,0 +1,23 @@
1
+ import type { ShellDialect } from '../types/tool/index.js'
2
+ import { lexShellCommandLine } from './shell-lexer.js'
3
+ import { noteShellAttributes } from './shell-session-state.js'
4
+
5
+ /**
6
+ * Records what `line` gives the integer attribute to, for the session that is
7
+ * about to run it. Called by the `bash` tool before the line runs: a line that
8
+ * fails half way may still have declared a name. The line is read without the
9
+ * session's earlier attributes, which only add to what it declares.
10
+ */
11
+ export function recordShellCommand(
12
+ sessionId: string | undefined,
13
+ line: string,
14
+ dialect: ShellDialect = 'bash',
15
+ ): void {
16
+ if (sessionId === undefined) return
17
+ const lexed = lexShellCommandLine(line, { dialect })
18
+ noteShellAttributes(sessionId, {
19
+ integers: lexed.integerNames,
20
+ // A line that cannot be read to the end may declare anything.
21
+ unknown: lexed.integerNamesUnknown || !lexed.complete,
22
+ })
23
+ }
@@ -91,6 +91,7 @@ export const SKILL_TOOL_NAME_ALIASES: Readonly<Record<string, string>> = Object.
91
91
  write: 'write',
92
92
  edit: 'edit',
93
93
  multiedit: 'edit',
94
+ notebookedit: 'notebook_edit',
94
95
  bash: 'bash',
95
96
  grep: 'grep',
96
97
  glob: 'glob',
@@ -15,6 +15,7 @@ function tryParseJson(raw: string): Record<string, unknown> | null {
15
15
  function extractFilePath(args: Record<string, unknown>): string | null {
16
16
  if (typeof args.path === 'string') return args.path
17
17
  if (typeof args.file_path === 'string') return args.file_path
18
+ if (typeof args.notebook_path === 'string') return args.notebook_path
18
19
  if (typeof args.filePath === 'string') return args.filePath
19
20
  return null
20
21
  }
@@ -1,4 +1,8 @@
1
- import { boundCompactionSummary, compactionHookInstructions } from '../plugin/hook-context.js'
1
+ import {
2
+ boundCompactionSummary,
3
+ compactionHookInstructions,
4
+ sessionStartHookContext,
5
+ } from '../plugin/hook-context.js'
2
6
  import { applyLifecycleHookResults } from '../runtime/query/plugin-hooks.js'
3
7
  import type { SessionId, TurnId } from '../types/ids/index.js'
4
8
  import type {
@@ -20,6 +24,8 @@ export interface CompactionHookHost {
20
24
  context: Omit<PluginHookContext, 'pluginId' | 'event'>,
21
25
  emitSessionEvent?: (event: SessionEvent) => Promise<void>,
22
26
  ): Promise<PluginHookResult[]>
27
+ /** Keeps what the `session_start` hooks said after the pass; a manager that has no place for it omits this. */
28
+ noteCompactionContext?(sessionId: SessionId, text: string): void
23
29
  }
24
30
 
25
31
  /**
@@ -102,3 +108,39 @@ export function postCompactSummary(summary: string | undefined): { summary?: str
102
108
  export function messageText(content: unknown): string | undefined {
103
109
  return typeof content === 'string' ? content : undefined
104
110
  }
111
+
112
+ /**
113
+ * Run the `session_start` hooks with source `compact` after a pass and a
114
+ * `post_compact` run, so a hook can say again what the model must not lose.
115
+ * Its answer is bounded text kept on the host (`noteCompactionContext`) for the
116
+ * next turn; nothing else in the answer is read, and a hook that fails does not
117
+ * undo a pass that is already made.
118
+ */
119
+ export async function startAfterCompaction(
120
+ host: CompactionHookHost,
121
+ base: {
122
+ readonly sessionId: SessionId
123
+ readonly turnId?: TurnId
124
+ readonly iteration?: number
125
+ readonly signal?: AbortSignal
126
+ readonly emitEvent?: (event: SessionEvent) => Promise<void>
127
+ },
128
+ ): Promise<void> {
129
+ try {
130
+ const results = await host.executeHooks(
131
+ 'session_start',
132
+ {
133
+ sessionId: base.sessionId,
134
+ source: 'compact',
135
+ ...(base.turnId !== undefined ? { turnId: base.turnId } : {}),
136
+ ...(base.iteration !== undefined ? { iteration: base.iteration } : {}),
137
+ ...(base.signal ? { signal: base.signal } : {}),
138
+ },
139
+ base.emitEvent,
140
+ )
141
+ const text = sessionStartHookContext(results)
142
+ if (text !== undefined) host.noteCompactionContext?.(base.sessionId, text)
143
+ } catch (error) {
144
+ if (base.signal?.aborted) throw error
145
+ }
146
+ }
@@ -21,6 +21,7 @@ import {
21
21
  askPreCompact,
22
22
  messageText,
23
23
  postCompactSummary,
24
+ startAfterCompaction,
24
25
  } from './hooks.js'
25
26
  import { adoptableSkills, handledSkillNames } from './loaded-skills.js'
26
27
  import { WorkingStateManager } from './manager.js'
@@ -186,6 +187,11 @@ async function afterPass(
186
187
  } catch (error) {
187
188
  if (input.signal?.aborted) throw error
188
189
  }
190
+ await startAfterCompaction(hooks.manager, {
191
+ sessionId: hooks.sessionId,
192
+ ...(input.signal ? { signal: input.signal } : {}),
193
+ ...(hooks.emitEvent ? { emitEvent: hooks.emitEvent } : {}),
194
+ })
189
195
  }
190
196
 
191
197
  async function publishManualCompaction(
@@ -106,8 +106,9 @@ export function recordRestorable(
106
106
  manager.recordFileText(resolveAgainst(path, call.workingDirectory), call.output)
107
107
  return
108
108
  }
109
- if (call.toolName === 'write' || call.toolName === 'edit') {
110
- const path = typeof input.path === 'string' ? input.path : undefined
109
+ if (call.toolName === 'write' || call.toolName === 'edit' || call.toolName === 'notebook_edit') {
110
+ const named = call.toolName === 'notebook_edit' ? input.notebook_path : input.path
111
+ const path = typeof named === 'string' ? named : undefined
111
112
  // The body a read showed is behind the file now.
112
113
  if (path && call.success) manager.forgetFileText(resolveAgainst(path, call.workingDirectory))
113
114
  }
@@ -65,6 +65,13 @@ export const CompactionConfigSchema = z.object({
65
65
  * to a flat `0.7`; pass that to keep the earlier behaviour.
66
66
  */
67
67
  triggerThreshold: z.number().min(0).max(1).optional(),
68
+ /**
69
+ * `false` stops the pass the context size starts (summary trigger and the
70
+ * salience soft target). A pass a provider overflow forces, and a
71
+ * host-requested compaction, still run. Absent or `true` keeps automatic
72
+ * compaction on.
73
+ */
74
+ autoCompact: z.boolean().optional(),
68
75
  /** Optional automatic-summary window; capped to the actual model window. */
69
76
  autoCompactWindowTokens: z.number().int().positive().safe().optional(),
70
77
  /**