@namzu/sdk 70.0.0 → 71.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (409) hide show
  1. package/CHANGELOG.md +123 -0
  2. package/dist/authorization/bare-repository.d.ts +21 -0
  3. package/dist/authorization/bare-repository.d.ts.map +1 -0
  4. package/dist/authorization/bare-repository.js +62 -0
  5. package/dist/authorization/bare-repository.js.map +1 -0
  6. package/dist/authorization/command-line.d.ts.map +1 -1
  7. package/dist/authorization/command-line.js +10 -3
  8. package/dist/authorization/command-line.js.map +1 -1
  9. package/dist/authorization/gate.d.ts +7 -0
  10. package/dist/authorization/gate.d.ts.map +1 -1
  11. package/dist/authorization/gate.js +4 -0
  12. package/dist/authorization/gate.js.map +1 -1
  13. package/dist/authorization/protected-paths.d.ts.map +1 -1
  14. package/dist/authorization/protected-paths.js +46 -1
  15. package/dist/authorization/protected-paths.js.map +1 -1
  16. package/dist/authorization/readonly-commands.d.ts +17 -5
  17. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  18. package/dist/authorization/readonly-commands.js +77 -6
  19. package/dist/authorization/readonly-commands.js.map +1 -1
  20. package/dist/authorization/readonly-flags.d.ts.map +1 -1
  21. package/dist/authorization/readonly-flags.js +98 -0
  22. package/dist/authorization/readonly-flags.js.map +1 -1
  23. package/dist/authorization/shell-lexer.d.ts +15 -0
  24. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  25. package/dist/authorization/shell-lexer.js +108 -3
  26. package/dist/authorization/shell-lexer.js.map +1 -1
  27. package/dist/authorization/shell-paths.d.ts.map +1 -1
  28. package/dist/authorization/shell-paths.js +276 -0
  29. package/dist/authorization/shell-paths.js.map +1 -1
  30. package/dist/authorization/shell-session-state.d.ts +47 -0
  31. package/dist/authorization/shell-session-state.d.ts.map +1 -0
  32. package/dist/authorization/shell-session-state.js +70 -0
  33. package/dist/authorization/shell-session-state.js.map +1 -0
  34. package/dist/authorization/shell-session.d.ts +9 -0
  35. package/dist/authorization/shell-session.d.ts.map +1 -0
  36. package/dist/authorization/shell-session.js +19 -0
  37. package/dist/authorization/shell-session.js.map +1 -0
  38. package/dist/authorization/skill-grant.d.ts.map +1 -1
  39. package/dist/authorization/skill-grant.js +1 -0
  40. package/dist/authorization/skill-grant.js.map +1 -1
  41. package/dist/compaction/extractor.d.ts.map +1 -1
  42. package/dist/compaction/extractor.js +2 -0
  43. package/dist/compaction/extractor.js.map +1 -1
  44. package/dist/compaction/hooks.d.ts +16 -0
  45. package/dist/compaction/hooks.d.ts.map +1 -1
  46. package/dist/compaction/hooks.js +26 -1
  47. package/dist/compaction/hooks.js.map +1 -1
  48. package/dist/compaction/manual.d.ts.map +1 -1
  49. package/dist/compaction/manual.js +6 -1
  50. package/dist/compaction/manual.js.map +1 -1
  51. package/dist/compaction/restore.d.ts.map +1 -1
  52. package/dist/compaction/restore.js +3 -2
  53. package/dist/compaction/restore.js.map +1 -1
  54. package/dist/config/runtime.d.ts +2 -0
  55. package/dist/config/runtime.d.ts.map +1 -1
  56. package/dist/config/runtime.js +7 -0
  57. package/dist/config/runtime.js.map +1 -1
  58. package/dist/connector/mcp/client.d.ts +7 -0
  59. package/dist/connector/mcp/client.d.ts.map +1 -1
  60. package/dist/connector/mcp/client.js +54 -4
  61. package/dist/connector/mcp/client.js.map +1 -1
  62. package/dist/connector/web/types.d.ts +8 -0
  63. package/dist/connector/web/types.d.ts.map +1 -1
  64. package/dist/constants/compaction/index.d.ts.map +1 -1
  65. package/dist/constants/compaction/index.js +1 -1
  66. package/dist/constants/compaction/index.js.map +1 -1
  67. package/dist/execution/code-runtime/worker-program.d.ts +1 -1
  68. package/dist/execution/code-runtime/worker-program.d.ts.map +1 -1
  69. package/dist/execution/code-runtime/worker-program.js +9 -5
  70. package/dist/execution/code-runtime/worker-program.js.map +1 -1
  71. package/dist/execution/local.d.ts.map +1 -1
  72. package/dist/execution/local.js +6 -1
  73. package/dist/execution/local.js.map +1 -1
  74. package/dist/peers/index.d.ts +2 -2
  75. package/dist/peers/index.d.ts.map +1 -1
  76. package/dist/peers/index.js +1 -1
  77. package/dist/peers/index.js.map +1 -1
  78. package/dist/peers/record.d.ts +74 -0
  79. package/dist/peers/record.d.ts.map +1 -1
  80. package/dist/peers/record.js +41 -1
  81. package/dist/peers/record.js.map +1 -1
  82. package/dist/peers/registry.d.ts.map +1 -1
  83. package/dist/peers/registry.js +20 -3
  84. package/dist/peers/registry.js.map +1 -1
  85. package/dist/plugin/bin-path.d.ts +41 -0
  86. package/dist/plugin/bin-path.d.ts.map +1 -0
  87. package/dist/plugin/bin-path.js +146 -0
  88. package/dist/plugin/bin-path.js.map +1 -0
  89. package/dist/plugin/common-layout/read.js +1 -1
  90. package/dist/plugin/common-layout/read.js.map +1 -1
  91. package/dist/plugin/common-layout-names.d.ts.map +1 -1
  92. package/dist/plugin/common-layout-names.js +0 -1
  93. package/dist/plugin/common-layout-names.js.map +1 -1
  94. package/dist/plugin/hook-module/scan.d.ts +16 -0
  95. package/dist/plugin/hook-module/scan.d.ts.map +1 -1
  96. package/dist/plugin/hook-module/scan.js +67 -2
  97. package/dist/plugin/hook-module/scan.js.map +1 -1
  98. package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
  99. package/dist/plugin/hook-module/worker-source.js +56 -0
  100. package/dist/plugin/hook-module/worker-source.js.map +1 -1
  101. package/dist/plugin/lifecycle.d.ts +21 -0
  102. package/dist/plugin/lifecycle.d.ts.map +1 -1
  103. package/dist/plugin/lifecycle.js +64 -0
  104. package/dist/plugin/lifecycle.js.map +1 -1
  105. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  106. package/dist/plugin/shell-hook-tool-names.js +1 -0
  107. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  108. package/dist/plugin/shell-hook.d.ts +1 -1
  109. package/dist/plugin/shell-hook.d.ts.map +1 -1
  110. package/dist/plugin/shell-hook.js +22 -4
  111. package/dist/plugin/shell-hook.js.map +1 -1
  112. package/dist/public-runtime.d.ts +8 -6
  113. package/dist/public-runtime.d.ts.map +1 -1
  114. package/dist/public-runtime.js +8 -5
  115. package/dist/public-runtime.js.map +1 -1
  116. package/dist/public-tools.d.ts +6 -2
  117. package/dist/public-tools.d.ts.map +1 -1
  118. package/dist/public-tools.js +6 -2
  119. package/dist/public-tools.js.map +1 -1
  120. package/dist/public-types.d.ts +2 -2
  121. package/dist/public-types.d.ts.map +1 -1
  122. package/dist/runtime/jobs/monitor-stream.d.ts +9 -1
  123. package/dist/runtime/jobs/monitor-stream.d.ts.map +1 -1
  124. package/dist/runtime/jobs/monitor-stream.js +13 -4
  125. package/dist/runtime/jobs/monitor-stream.js.map +1 -1
  126. package/dist/runtime/jobs/registry.d.ts +4 -0
  127. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  128. package/dist/runtime/jobs/registry.js +12 -2
  129. package/dist/runtime/jobs/registry.js.map +1 -1
  130. package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -1
  131. package/dist/runtime/query/auto-review/git-status.js +3 -2
  132. package/dist/runtime/query/auto-review/git-status.js.map +1 -1
  133. package/dist/runtime/query/executor.d.ts +16 -6
  134. package/dist/runtime/query/executor.d.ts.map +1 -1
  135. package/dist/runtime/query/executor.js +60 -5
  136. package/dist/runtime/query/executor.js.map +1 -1
  137. package/dist/runtime/query/index.d.ts.map +1 -1
  138. package/dist/runtime/query/index.js +2 -2
  139. package/dist/runtime/query/index.js.map +1 -1
  140. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  141. package/dist/runtime/query/iteration/outstanding-work.js +14 -4
  142. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  143. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  144. package/dist/runtime/query/iteration/phases/compaction.js +11 -1
  145. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  146. package/dist/runtime/query/iteration/phases/tool-review.d.ts +2 -0
  147. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  148. package/dist/runtime/query/iteration/phases/tool-review.js +19 -8
  149. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  150. package/dist/runtime/query/path-escalation.d.ts +6 -0
  151. package/dist/runtime/query/path-escalation.d.ts.map +1 -1
  152. package/dist/runtime/query/path-escalation.js +58 -4
  153. package/dist/runtime/query/path-escalation.js.map +1 -1
  154. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  155. package/dist/runtime/query/review-policy.js +4 -2
  156. package/dist/runtime/query/review-policy.js.map +1 -1
  157. package/dist/runtime/query/steering.d.ts +11 -2
  158. package/dist/runtime/query/steering.d.ts.map +1 -1
  159. package/dist/runtime/query/steering.js +18 -4
  160. package/dist/runtime/query/steering.js.map +1 -1
  161. package/dist/sandbox/provider/local.d.ts.map +1 -1
  162. package/dist/sandbox/provider/local.js +3 -1
  163. package/dist/sandbox/provider/local.js.map +1 -1
  164. package/dist/schedules/describe.d.ts.map +1 -1
  165. package/dist/schedules/describe.js +2 -0
  166. package/dist/schedules/describe.js.map +1 -1
  167. package/dist/schedules/evaluate.d.ts +4 -0
  168. package/dist/schedules/evaluate.d.ts.map +1 -1
  169. package/dist/schedules/evaluate.js +26 -1
  170. package/dist/schedules/evaluate.js.map +1 -1
  171. package/dist/schedules/index.d.ts +3 -1
  172. package/dist/schedules/index.d.ts.map +1 -1
  173. package/dist/schedules/index.js +2 -1
  174. package/dist/schedules/index.js.map +1 -1
  175. package/dist/schedules/next-fire.d.ts.map +1 -1
  176. package/dist/schedules/next-fire.js +10 -0
  177. package/dist/schedules/next-fire.js.map +1 -1
  178. package/dist/schedules/spec.d.ts +9 -0
  179. package/dist/schedules/spec.d.ts.map +1 -1
  180. package/dist/schedules/spec.js +33 -0
  181. package/dist/schedules/spec.js.map +1 -1
  182. package/dist/schedules/types.d.ts +32 -4
  183. package/dist/schedules/types.d.ts.map +1 -1
  184. package/dist/schedules/types.js +3 -2
  185. package/dist/schedules/types.js.map +1 -1
  186. package/dist/schedules/watch.d.ts +23 -0
  187. package/dist/schedules/watch.d.ts.map +1 -0
  188. package/dist/schedules/watch.js +46 -0
  189. package/dist/schedules/watch.js.map +1 -0
  190. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  191. package/dist/session/workspace/git-worktree.js +2 -1
  192. package/dist/session/workspace/git-worktree.js.map +1 -1
  193. package/dist/skills/arguments.d.ts +58 -0
  194. package/dist/skills/arguments.d.ts.map +1 -0
  195. package/dist/skills/arguments.js +208 -0
  196. package/dist/skills/arguments.js.map +1 -0
  197. package/dist/skills/index.d.ts +3 -1
  198. package/dist/skills/index.d.ts.map +1 -1
  199. package/dist/skills/index.js +1 -0
  200. package/dist/skills/index.js.map +1 -1
  201. package/dist/skills/inline-shell.d.ts +17 -0
  202. package/dist/skills/inline-shell.d.ts.map +1 -1
  203. package/dist/skills/inline-shell.js +1232 -14
  204. package/dist/skills/inline-shell.js.map +1 -1
  205. package/dist/store/session-index/index.d.ts +5 -0
  206. package/dist/store/session-index/index.d.ts.map +1 -1
  207. package/dist/store/session-index/index.js +5 -1
  208. package/dist/store/session-index/index.js.map +1 -1
  209. package/dist/store/session-index/rebuild.d.ts +18 -0
  210. package/dist/store/session-index/rebuild.d.ts.map +1 -1
  211. package/dist/store/session-index/rebuild.js +79 -5
  212. package/dist/store/session-index/rebuild.js.map +1 -1
  213. package/dist/store/session-index/sqlite.d.ts +8 -0
  214. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  215. package/dist/store/session-index/sqlite.js +23 -1
  216. package/dist/store/session-index/sqlite.js.map +1 -1
  217. package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
  218. package/dist/tools/builtins/bash-cwd.js +2 -0
  219. package/dist/tools/builtins/bash-cwd.js.map +1 -1
  220. package/dist/tools/builtins/bash.d.ts.map +1 -1
  221. package/dist/tools/builtins/bash.js +79 -11
  222. package/dist/tools/builtins/bash.js.map +1 -1
  223. package/dist/tools/builtins/exit-semantics.d.ts +6 -0
  224. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  225. package/dist/tools/builtins/exit-semantics.js +10 -0
  226. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  227. package/dist/tools/builtins/glob.d.ts.map +1 -1
  228. package/dist/tools/builtins/glob.js +68 -13
  229. package/dist/tools/builtins/glob.js.map +1 -1
  230. package/dist/tools/builtins/grep.d.ts.map +1 -1
  231. package/dist/tools/builtins/grep.js +37 -12
  232. package/dist/tools/builtins/grep.js.map +1 -1
  233. package/dist/tools/builtins/index.d.ts +11 -0
  234. package/dist/tools/builtins/index.d.ts.map +1 -1
  235. package/dist/tools/builtins/index.js +14 -0
  236. package/dist/tools/builtins/index.js.map +1 -1
  237. package/dist/tools/builtins/job.js +1 -1
  238. package/dist/tools/builtins/job.js.map +1 -1
  239. package/dist/tools/builtins/monitor.d.ts +1 -1
  240. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  241. package/dist/tools/builtins/monitor.js +4 -2
  242. package/dist/tools/builtins/monitor.js.map +1 -1
  243. package/dist/tools/builtins/notebook-cells.d.ts +31 -0
  244. package/dist/tools/builtins/notebook-cells.d.ts.map +1 -0
  245. package/dist/tools/builtins/notebook-cells.js +160 -0
  246. package/dist/tools/builtins/notebook-cells.js.map +1 -0
  247. package/dist/tools/builtins/notebook-edit.d.ts +8 -0
  248. package/dist/tools/builtins/notebook-edit.d.ts.map +1 -0
  249. package/dist/tools/builtins/notebook-edit.js +249 -0
  250. package/dist/tools/builtins/notebook-edit.js.map +1 -0
  251. package/dist/tools/builtins/notebook-guard.d.ts.map +1 -1
  252. package/dist/tools/builtins/notebook-guard.js +2 -1
  253. package/dist/tools/builtins/notebook-guard.js.map +1 -1
  254. package/dist/tools/builtins/push-notification.d.ts +49 -0
  255. package/dist/tools/builtins/push-notification.d.ts.map +1 -0
  256. package/dist/tools/builtins/push-notification.js +107 -0
  257. package/dist/tools/builtins/push-notification.js.map +1 -0
  258. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  259. package/dist/tools/builtins/read-file.js +8 -3
  260. package/dist/tools/builtins/read-file.js.map +1 -1
  261. package/dist/tools/builtins/read-media.d.ts.map +1 -1
  262. package/dist/tools/builtins/read-media.js +2 -1
  263. package/dist/tools/builtins/read-media.js.map +1 -1
  264. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  265. package/dist/tools/builtins/read-render.js +5 -3
  266. package/dist/tools/builtins/read-render.js.map +1 -1
  267. package/dist/tools/builtins/search-support.d.ts +6 -4
  268. package/dist/tools/builtins/search-support.d.ts.map +1 -1
  269. package/dist/tools/builtins/search-support.js +15 -3
  270. package/dist/tools/builtins/search-support.js.map +1 -1
  271. package/dist/tools/builtins/skill.d.ts.map +1 -1
  272. package/dist/tools/builtins/skill.js +28 -8
  273. package/dist/tools/builtins/skill.js.map +1 -1
  274. package/dist/tools/builtins/sleep-guard.d.ts +20 -0
  275. package/dist/tools/builtins/sleep-guard.d.ts.map +1 -1
  276. package/dist/tools/builtins/sleep-guard.js +125 -1
  277. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  278. package/dist/tools/builtins/wait-for-job.js +1 -1
  279. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  280. package/dist/tools/builtins/web.d.ts +2 -0
  281. package/dist/tools/builtins/web.d.ts.map +1 -1
  282. package/dist/tools/builtins/web.js +97 -3
  283. package/dist/tools/builtins/web.js.map +1 -1
  284. package/dist/tools/command-shell.d.ts +50 -0
  285. package/dist/tools/command-shell.d.ts.map +1 -1
  286. package/dist/tools/command-shell.js +145 -0
  287. package/dist/tools/command-shell.js.map +1 -1
  288. package/dist/tools/env-scrub.d.ts +2 -0
  289. package/dist/tools/env-scrub.d.ts.map +1 -1
  290. package/dist/tools/env-scrub.js +15 -1
  291. package/dist/tools/env-scrub.js.map +1 -1
  292. package/dist/tools/git-config-env.d.ts +55 -0
  293. package/dist/tools/git-config-env.d.ts.map +1 -0
  294. package/dist/tools/git-config-env.js +130 -0
  295. package/dist/tools/git-config-env.js.map +1 -0
  296. package/dist/tools/schedules/schedule-tool.d.ts +7 -0
  297. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  298. package/dist/tools/schedules/schedule-tool.js +72 -3
  299. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  300. package/dist/tools/schedules/types.d.ts +38 -2
  301. package/dist/tools/schedules/types.d.ts.map +1 -1
  302. package/dist/types/connector/mcp.d.ts +24 -0
  303. package/dist/types/connector/mcp.d.ts.map +1 -1
  304. package/dist/types/message/index.d.ts +21 -1
  305. package/dist/types/message/index.d.ts.map +1 -1
  306. package/dist/types/message/index.js +37 -2
  307. package/dist/types/message/index.js.map +1 -1
  308. package/dist/types/plugin/index.d.ts +10 -2
  309. package/dist/types/plugin/index.d.ts.map +1 -1
  310. package/dist/types/plugin/index.js.map +1 -1
  311. package/dist/types/tool/index.d.ts +6 -0
  312. package/dist/types/tool/index.d.ts.map +1 -1
  313. package/dist/types/tool/index.js.map +1 -1
  314. package/dist/utils/plain-terminal-text.d.ts +21 -0
  315. package/dist/utils/plain-terminal-text.d.ts.map +1 -0
  316. package/dist/utils/plain-terminal-text.js +156 -0
  317. package/dist/utils/plain-terminal-text.js.map +1 -0
  318. package/package.json +1 -1
  319. package/src/authorization/bare-repository.ts +70 -0
  320. package/src/authorization/command-line.ts +18 -4
  321. package/src/authorization/gate.ts +11 -0
  322. package/src/authorization/protected-paths.ts +45 -1
  323. package/src/authorization/readonly-commands.ts +75 -6
  324. package/src/authorization/readonly-flags.ts +103 -0
  325. package/src/authorization/shell-lexer.ts +126 -3
  326. package/src/authorization/shell-paths.ts +386 -0
  327. package/src/authorization/shell-session-state.ts +97 -0
  328. package/src/authorization/shell-session.ts +23 -0
  329. package/src/authorization/skill-grant.ts +1 -0
  330. package/src/compaction/extractor.ts +1 -0
  331. package/src/compaction/hooks.ts +43 -1
  332. package/src/compaction/manual.ts +6 -0
  333. package/src/compaction/restore.ts +3 -2
  334. package/src/config/runtime.ts +7 -0
  335. package/src/connector/mcp/client.ts +61 -4
  336. package/src/connector/web/types.ts +8 -0
  337. package/src/constants/compaction/index.ts +1 -1
  338. package/src/execution/code-runtime/worker-program.ts +9 -5
  339. package/src/execution/local.ts +6 -1
  340. package/src/peers/index.ts +8 -2
  341. package/src/peers/record.ts +45 -1
  342. package/src/peers/registry.ts +21 -5
  343. package/src/plugin/bin-path.ts +149 -0
  344. package/src/plugin/common-layout/read.ts +1 -1
  345. package/src/plugin/common-layout-names.ts +0 -1
  346. package/src/plugin/hook-module/scan.ts +74 -2
  347. package/src/plugin/hook-module/worker-source.ts +56 -0
  348. package/src/plugin/lifecycle.ts +67 -0
  349. package/src/plugin/shell-hook-tool-names.ts +1 -0
  350. package/src/plugin/shell-hook.ts +23 -4
  351. package/src/public-runtime.ts +21 -0
  352. package/src/public-tools.ts +32 -1
  353. package/src/public-types.ts +3 -1
  354. package/src/runtime/jobs/monitor-stream.ts +18 -4
  355. package/src/runtime/jobs/registry.ts +22 -2
  356. package/src/runtime/query/auto-review/git-status.ts +3 -2
  357. package/src/runtime/query/executor.ts +79 -5
  358. package/src/runtime/query/index.ts +5 -2
  359. package/src/runtime/query/iteration/outstanding-work.ts +22 -4
  360. package/src/runtime/query/iteration/phases/compaction.ts +14 -1
  361. package/src/runtime/query/iteration/phases/tool-review.ts +24 -7
  362. package/src/runtime/query/path-escalation.ts +52 -4
  363. package/src/runtime/query/review-policy.ts +5 -2
  364. package/src/runtime/query/steering.ts +32 -4
  365. package/src/sandbox/provider/local.ts +3 -1
  366. package/src/schedules/describe.ts +2 -0
  367. package/src/schedules/evaluate.ts +29 -1
  368. package/src/schedules/index.ts +9 -1
  369. package/src/schedules/next-fire.ts +9 -0
  370. package/src/schedules/spec.ts +42 -0
  371. package/src/schedules/types.ts +33 -3
  372. package/src/schedules/watch.ts +71 -0
  373. package/src/session/workspace/git-worktree.ts +3 -1
  374. package/src/skills/arguments.ts +250 -0
  375. package/src/skills/index.ts +10 -0
  376. package/src/skills/inline-shell.ts +1268 -14
  377. package/src/store/session-index/index.ts +10 -1
  378. package/src/store/session-index/rebuild.ts +81 -5
  379. package/src/store/session-index/sqlite.ts +30 -1
  380. package/src/tools/builtins/bash-cwd.ts +2 -0
  381. package/src/tools/builtins/bash.ts +93 -13
  382. package/src/tools/builtins/exit-semantics.ts +10 -0
  383. package/src/tools/builtins/glob.ts +79 -15
  384. package/src/tools/builtins/grep.ts +37 -10
  385. package/src/tools/builtins/index.ts +15 -0
  386. package/src/tools/builtins/job.ts +1 -1
  387. package/src/tools/builtins/monitor.ts +4 -2
  388. package/src/tools/builtins/notebook-cells.ts +196 -0
  389. package/src/tools/builtins/notebook-edit.ts +280 -0
  390. package/src/tools/builtins/notebook-guard.ts +2 -1
  391. package/src/tools/builtins/push-notification.ts +138 -0
  392. package/src/tools/builtins/read-file.ts +9 -3
  393. package/src/tools/builtins/read-media.ts +2 -1
  394. package/src/tools/builtins/read-render.ts +5 -3
  395. package/src/tools/builtins/search-support.ts +17 -3
  396. package/src/tools/builtins/skill.ts +27 -7
  397. package/src/tools/builtins/sleep-guard.ts +128 -1
  398. package/src/tools/builtins/wait-for-job.ts +1 -1
  399. package/src/tools/builtins/web.ts +100 -3
  400. package/src/tools/command-shell.ts +166 -0
  401. package/src/tools/env-scrub.ts +13 -1
  402. package/src/tools/git-config-env.ts +143 -0
  403. package/src/tools/schedules/schedule-tool.ts +79 -3
  404. package/src/tools/schedules/types.ts +47 -9
  405. package/src/types/connector/mcp.ts +25 -0
  406. package/src/types/message/index.ts +53 -1
  407. package/src/types/plugin/index.ts +10 -2
  408. package/src/types/tool/index.ts +6 -0
  409. package/src/utils/plain-terminal-text.ts +142 -0
@@ -0,0 +1,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
  /**
@@ -21,6 +21,7 @@ import type {
21
21
  MCPRequestOptions,
22
22
  MCPResource,
23
23
  MCPResourceTemplate,
24
+ MCPRoot,
24
25
  MCPServerCapabilities,
25
26
  MCPToolDefinition,
26
27
  MCPToolResult,
@@ -381,7 +382,29 @@ export class MCPClient {
381
382
  * to avoid cutting a call this client would have kept alive.
382
383
  */
383
384
  getToolCallWindowMs(): number | undefined {
384
- return this.resetTimeoutOnProgress ? this.maxTotalTimeoutMs : undefined
385
+ const fixed = this.config.toolCallTimeoutMs
386
+ if (!this.resetTimeoutOnProgress) return fixed
387
+ return fixed === undefined ? this.maxTotalTimeoutMs : Math.max(fixed, this.maxTotalTimeoutMs)
388
+ }
389
+
390
+ /** The deadline a request of this method holds, when nothing extends it. */
391
+ private fixedDeadlineMs(method: string): number {
392
+ return method === 'tools/call' && this.config.toolCallTimeoutMs !== undefined
393
+ ? this.config.toolCallTimeoutMs
394
+ : this.requestTimeoutMs
395
+ }
396
+
397
+ /**
398
+ * Tell the server its roots changed. A no-op until connected, on a modern
399
+ * connection (which has no such notification) or when no `roots` were given.
400
+ */
401
+ notifyRootsChanged(): void {
402
+ if (!this.config.roots || !this.isConnected() || this.era?.kind !== 'legacy') return
403
+ void this.notify('notifications/roots/list_changed', {}).catch((err) => {
404
+ this.log.debug('Failed to send roots/list_changed', {
405
+ 'exception.message': toErrorMessage(err),
406
+ })
407
+ })
385
408
  }
386
409
 
387
410
  constructor(config: MCPClientConfig) {
@@ -390,6 +413,9 @@ export class MCPClient {
390
413
  config.requestTimeoutMs ?? DEFAULT_MCP_REQUEST_TIMEOUT_MS,
391
414
  'MCPClient requestTimeoutMs',
392
415
  )
416
+ if (config.toolCallTimeoutMs !== undefined) {
417
+ validateConnectorTimeoutMs(config.toolCallTimeoutMs, 'MCPClient toolCallTimeoutMs')
418
+ }
393
419
  this.resetTimeoutOnProgress = config.resetTimeoutOnProgress === true
394
420
  const maxTotal = validateConnectorTimeoutMs(
395
421
  config.maxTotalTimeoutMs ??
@@ -523,6 +549,7 @@ export class MCPClient {
523
549
  capabilities: {
524
550
  ...(this.config.capabilities ?? {}),
525
551
  ...(this.config.onElicitation ? { elicitation: {} } : {}),
552
+ ...(this.config.roots ? { roots: { listChanged: true } } : {}),
526
553
  },
527
554
  clientInfo: this.config.clientInfo ?? NAMZU_CLIENT_INFO,
528
555
  })) as MCPInitializeResult
@@ -1224,7 +1251,8 @@ export class MCPClient {
1224
1251
  this.taskWaits.add(wait)
1225
1252
  const extendable = this.resetTimeoutOnProgress && options?.onProgress !== undefined
1226
1253
  const started = Date.now()
1227
- const totalDeadline = started + (extendable ? this.maxTotalTimeoutMs : this.requestTimeoutMs)
1254
+ const totalDeadline =
1255
+ started + (extendable ? this.maxTotalTimeoutMs : this.fixedDeadlineMs('tools/call'))
1228
1256
  let lastChange = started
1229
1257
  let reports = 0
1230
1258
  let seen: string | undefined
@@ -1903,7 +1931,12 @@ export class MCPClient {
1903
1931
 
1904
1932
  this.pendingRequests.set(id, entry)
1905
1933
  const expire = (deadline: 'request' | 'idle' | 'total_cap'): void => {
1906
- const limit = deadline === 'total_cap' ? this.maxTotalTimeoutMs : this.requestTimeoutMs
1934
+ const limit =
1935
+ deadline === 'total_cap'
1936
+ ? this.maxTotalTimeoutMs
1937
+ : deadline === 'request'
1938
+ ? this.fixedDeadlineMs(method)
1939
+ : this.requestTimeoutMs
1907
1940
  const what =
1908
1941
  deadline === 'request'
1909
1942
  ? `timed out after ${limit}ms`
@@ -1922,7 +1955,10 @@ export class MCPClient {
1922
1955
  }
1923
1956
  const armIdle = (): void => {
1924
1957
  clearTimeout(idleTimer)
1925
- idleTimer = setTimeout(() => expire(extendable ? 'idle' : 'request'), this.requestTimeoutMs)
1958
+ idleTimer = setTimeout(
1959
+ () => expire(extendable ? 'idle' : 'request'),
1960
+ extendable ? this.requestTimeoutMs : this.fixedDeadlineMs(method),
1961
+ )
1926
1962
  }
1927
1963
  if (progressToken !== undefined && options?.onProgress) {
1928
1964
  this.progressRequests.set(progressToken, {
@@ -2219,6 +2255,27 @@ export class MCPClient {
2219
2255
  })
2220
2256
  return
2221
2257
  }
2258
+ if (
2259
+ message.method === 'roots/list' &&
2260
+ message.id !== undefined &&
2261
+ this.config.roots &&
2262
+ this.era?.kind === 'legacy'
2263
+ ) {
2264
+ let roots: readonly MCPRoot[] = []
2265
+ try {
2266
+ roots = this.config.roots()
2267
+ } catch (err) {
2268
+ this.log.debug('Roots provider failed', { 'exception.message': toErrorMessage(err) })
2269
+ }
2270
+ void this.transport
2271
+ .send({ jsonrpc: '2.0', id: message.id, result: { roots: [...roots] } })
2272
+ .catch((err) => {
2273
+ this.log.debug('Failed to send roots/list reply', {
2274
+ 'exception.message': toErrorMessage(err),
2275
+ })
2276
+ })
2277
+ return
2278
+ }
2222
2279
  if (message.method && message.id !== undefined) {
2223
2280
  this.log.warn('Declining unsupported server-initiated MCP request', {
2224
2281
  'namzu.connector.server': this.config.serverName,
@@ -112,6 +112,14 @@ export interface WebContentExtractor {
112
112
  export interface WebSearchRequest {
113
113
  readonly query: string
114
114
  readonly limit?: number
115
+ /**
116
+ * Only results from these domains (a domain also covers its subdomains).
117
+ * `web_search` filters the hits itself as well, so a backend that cannot
118
+ * filter may ignore this; one that can saves a round of over-fetching.
119
+ */
120
+ readonly allowedDomains?: readonly string[]
121
+ /** Never results from these domains (a domain also covers its subdomains). Same contract as `allowedDomains`. */
122
+ readonly blockedDomains?: readonly string[]
115
123
  readonly signal?: AbortSignal
116
124
  }
117
125
 
@@ -5,7 +5,7 @@
5
5
  // because both mutate file content.
6
6
  export const READ_TOOLS = new Set(['read'])
7
7
 
8
- export const EDIT_TOOLS = new Set(['write', 'edit'])
8
+ export const EDIT_TOOLS = new Set(['write', 'edit', 'notebook_edit'])
9
9
 
10
10
  export const SHELL_TOOLS = new Set(['bash'])
11
11
 
@@ -27,21 +27,25 @@ async function main() {
27
27
  let sliceStart = 0
28
28
  let cpuUsed = 0
29
29
  let interrupted = false
30
+ // Slices are timed on the monotonic sub-millisecond clock. Date.now() is
31
+ // whole milliseconds: a slice of 32 microtasks lasts a few microseconds, so
32
+ // its start and end read the same value and add 0 to the total, and a loop
33
+ // of such slices can run forever without the total ever growing.
34
+ const clock = () => performance.now()
30
35
  function inSlice(fn) {
31
36
  if (!cpu) return fn()
32
- if (sliceDepth === 0) sliceStart = Date.now()
37
+ if (sliceDepth === 0) sliceStart = clock()
33
38
  sliceDepth++
34
39
  try { return fn() }
35
40
  finally {
36
41
  sliceDepth--
37
- if (sliceDepth === 0) cpuUsed += Date.now() - sliceStart
42
+ if (sliceDepth === 0) cpuUsed += clock() - sliceStart
38
43
  }
39
44
  }
40
45
  runtime.setInterruptHandler(() => {
41
- const now = Date.now()
42
46
  const stop = cpu
43
- ? sliceDepth > 0 && (now - sliceStart >= cpu.sliceMs || cpuUsed + (now - sliceStart) >= cpu.totalMs)
44
- : now >= workerData.deadline
47
+ ? sliceDepth > 0 && (clock() - sliceStart >= cpu.sliceMs || cpuUsed + (clock() - sliceStart) >= cpu.totalMs)
48
+ : Date.now() >= workerData.deadline
45
49
  if (stop) interrupted = true
46
50
  return stop
47
51
  })
@@ -3,6 +3,7 @@ import { existsSync } from 'node:fs'
3
3
  import { resolve } from 'node:path'
4
4
  import { killTree } from '../process/kill-tree.js'
5
5
  import { withSessionChildMarker } from '../process/session-child.js'
6
+ import { isGitProgram, withHostGitConfig, withSafeGitConfig } from '../tools/git-config-env.js'
6
7
  import type { LocalExecutionContextConfig } from '../types/connector/index.js'
7
8
  import type {
8
9
  CommandExecutor,
@@ -162,7 +163,11 @@ export class LocalExecutionContext extends BaseExecutionContext implements Comma
162
163
  }
163
164
 
164
165
  const cwd = options?.cwd ? resolve(this.cwd, options.cwd) : this.cwd
165
- const env = withSessionChildMarker({ ...process.env, ...this.envVars, ...options?.env })
166
+ // Git the host starts itself gets the full hardening; any other command only
167
+ // the part that keeps a git it starts from reading a folder that merely looks
168
+ // like a repository. Applied last so a caller's own entries are appended to.
169
+ const merged = withSessionChildMarker({ ...process.env, ...this.envVars, ...options?.env })
170
+ const env = isGitProgram(command) ? withHostGitConfig(merged) : withSafeGitConfig(merged)
166
171
  const timeoutMs = options?.timeoutMs ?? LOCAL_COMMAND_DEFAULT_TIMEOUT_MS
167
172
  if (!Number.isInteger(timeoutMs) || timeoutMs < 0) {
168
173
  throw new RangeError(
@@ -25,8 +25,14 @@ export {
25
25
  } from './dir.js'
26
26
  export type { HardenPeerDirectory, PeerRuntimeDir, ResolvePeerRuntimeDirOptions } from './dir.js'
27
27
 
28
- export { derivePeerRef, PEER_RECORD_VERSION, PEER_TRAIL_MAX, PeerRecordSchema } from './record.js'
29
- export type { PeerExchange, PeerRecord } from './record.js'
28
+ export {
29
+ derivePeerRef,
30
+ PEER_AGENTS_MAX,
31
+ PEER_RECORD_VERSION,
32
+ PEER_TRAIL_MAX,
33
+ PeerRecordSchema,
34
+ } from './record.js'
35
+ export type { PeerAgentNode, PeerExchange, PeerRecord } from './record.js'
30
36
 
31
37
  export {
32
38
  isPeerRecordLive,
@@ -41,6 +41,31 @@ export type PeerExchange = z.infer<typeof PeerExchangeSchema>
41
41
  /** The most recent exchanges a record keeps, newest last. A burst between two reads of a record is not lost for four or fewer. */
42
42
  export const PEER_TRAIL_MAX = 4
43
43
 
44
+ /** The most agent rows a record carries; a session with more says nothing about the rest. */
45
+ export const PEER_AGENTS_MAX = 40
46
+
47
+ /**
48
+ * One row of a session's own agents: a workflow, an agent, a teammate or a background shell
49
+ * task, flat with the id of its parent (a workflow's agents name the workflow). A host that
50
+ * draws the tree needs a state, a name, one line of detail and a start time and nothing else:
51
+ * never a prompt, a transcript or a command's output.
52
+ */
53
+ export const PeerAgentNodeSchema = z
54
+ .object({
55
+ id: z.string().min(1).max(64),
56
+ /** Absent for a row directly under the session. */
57
+ parent: z.string().min(1).max(64).optional(),
58
+ kind: z.enum(['workflow', 'agent', 'teammate', 'task']),
59
+ state: z.enum(['needs-you', 'working', 'finished', 'idle', 'failed', 'stopped']),
60
+ name: z.string().max(80),
61
+ detail: z.string().max(160).optional(),
62
+ /** When it started or last changed state (epoch ms); the host shows its age. */
63
+ since: z.number().int().nonnegative(),
64
+ })
65
+ .strict()
66
+
67
+ export type PeerAgentNode = z.infer<typeof PeerAgentNodeSchema>
68
+
44
69
  export const PeerRecordSchema = z
45
70
  .object({
46
71
  v: z.literal(PEER_RECORD_VERSION),
@@ -73,6 +98,10 @@ export const PeerRecordSchema = z
73
98
  limitedUntil: z.number().int().positive().optional(),
74
99
  /** The latest exchanges with other terminals, newest last; absent for a terminal that has had none or does not report them. */
75
100
  trail: z.array(PeerExchangeSchema).max(PEER_TRAIL_MAX).optional(),
101
+ /** The session's own agents, workflows, teammates and background tasks, for a host that draws them as a tree; written inside a workspaces host, or in a plain terminal after its first left arrow, at most once a second. */
102
+ agents: z.array(PeerAgentNodeSchema).max(PEER_AGENTS_MAX).optional(),
103
+ /** One line of what the session is on: the question it waits on, else the last line of its latest reply; at most 160 characters, never the prompt. Written where `agents` is. */
104
+ detail: z.string().max(160).optional(),
76
105
  /** A role another machine (or the person) set for this session; descriptive only, never a permission. */
77
106
  role: z.string().min(1).max(500).optional(),
78
107
  /** The name of the machine that set the role. */
@@ -87,7 +116,22 @@ export const PeerRecordSchema = z
87
116
  * a newer build (extra optional fields) stays visible to an older reader.
88
117
  * Writers keep using the strict `PeerRecordSchema`.
89
118
  */
90
- export const PeerRecordReaderSchema = PeerRecordSchema.strip()
119
+ export const PeerRecordReaderSchema = PeerRecordSchema.extend({
120
+ // A list that does not fit its schema drops only the list, never the whole session.
121
+ agents: z
122
+ .preprocess((value) => {
123
+ const parsed = z.array(PeerAgentNodeSchema).max(PEER_AGENTS_MAX).safeParse(value)
124
+ return parsed.success ? parsed.data : undefined
125
+ }, z.array(PeerAgentNodeSchema).max(PEER_AGENTS_MAX).optional())
126
+ .optional(),
127
+ // A line that does not fit (too long, not a string) drops only the line, never the whole session.
128
+ detail: z
129
+ .preprocess((value) => {
130
+ const parsed = z.string().max(160).safeParse(value)
131
+ return parsed.success ? parsed.data : undefined
132
+ }, z.string().max(160).optional())
133
+ .optional(),
134
+ }).strip()
91
135
 
92
136
  export type PeerRecord = z.infer<typeof PeerRecordSchema>
93
137
 
@@ -68,6 +68,21 @@ export function writePeerRecord(sessionsDir: string, record: PeerRecord): void {
68
68
  }
69
69
  }
70
70
 
71
+ /** A record is a few KiB; a file far beyond that is not one, and is not read. */
72
+ const RECORD_MAX_BYTES = 256 * 1024
73
+
74
+ /**
75
+ * The text of a record file, or `undefined` when the path is not a regular file this user owns
76
+ * (a link, a device, another user's file) or is over the size cap. A missing file throws ENOENT.
77
+ */
78
+ function readRecordFile(path: string): string | undefined {
79
+ const info = lstatSync(path)
80
+ if (!info.isFile() || info.size > RECORD_MAX_BYTES) return undefined
81
+ const uid = typeof process.getuid === 'function' ? process.getuid() : undefined
82
+ if (uid !== undefined && info.uid !== uid) return undefined
83
+ return readFileSync(path, 'utf8')
84
+ }
85
+
71
86
  function parseRecordText(text: string): PeerRecord | undefined {
72
87
  let parsed: unknown
73
88
  try {
@@ -81,14 +96,14 @@ function parseRecordText(text: string): PeerRecord | undefined {
81
96
 
82
97
  /** One session's record, or `undefined` if it has none or its file does not parse. */
83
98
  export function readPeerRecord(sessionsDir: string, sessionId: string): PeerRecord | undefined {
84
- let text: string
99
+ let text: string | undefined
85
100
  try {
86
- text = readFileSync(recordPath(sessionsDir, sessionId), 'utf8')
101
+ text = readRecordFile(recordPath(sessionsDir, sessionId))
87
102
  } catch (error) {
88
103
  if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined
89
104
  throw error
90
105
  }
91
- return parseRecordText(text)
106
+ return text === undefined ? undefined : parseRecordText(text)
92
107
  }
93
108
 
94
109
  /**
@@ -109,12 +124,13 @@ export function readPeerRecords(sessionsDir: string): PeerRecord[] {
109
124
  const records: PeerRecord[] = []
110
125
  for (const entry of entries) {
111
126
  if (!entry.endsWith('.json')) continue
112
- let text: string
127
+ let text: string | undefined
113
128
  try {
114
- text = readFileSync(join(sessionsDir, entry), 'utf8')
129
+ text = readRecordFile(join(sessionsDir, entry))
115
130
  } catch {
116
131
  continue // Vanished between readdir and read; not this reader's concern.
117
132
  }
133
+ if (text === undefined) continue
118
134
  const record = parseRecordText(text)
119
135
  if (record) records.push(record)
120
136
  }