@namzu/sdk 70.0.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 (394) hide show
  1. package/CHANGELOG.md +117 -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/tools/builtins/bash-cwd.d.ts.map +1 -1
  206. package/dist/tools/builtins/bash-cwd.js +2 -0
  207. package/dist/tools/builtins/bash-cwd.js.map +1 -1
  208. package/dist/tools/builtins/bash.d.ts.map +1 -1
  209. package/dist/tools/builtins/bash.js +79 -11
  210. package/dist/tools/builtins/bash.js.map +1 -1
  211. package/dist/tools/builtins/exit-semantics.d.ts +6 -0
  212. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  213. package/dist/tools/builtins/exit-semantics.js +10 -0
  214. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  215. package/dist/tools/builtins/glob.d.ts.map +1 -1
  216. package/dist/tools/builtins/glob.js +68 -13
  217. package/dist/tools/builtins/glob.js.map +1 -1
  218. package/dist/tools/builtins/grep.d.ts.map +1 -1
  219. package/dist/tools/builtins/grep.js +37 -12
  220. package/dist/tools/builtins/grep.js.map +1 -1
  221. package/dist/tools/builtins/index.d.ts +11 -0
  222. package/dist/tools/builtins/index.d.ts.map +1 -1
  223. package/dist/tools/builtins/index.js +14 -0
  224. package/dist/tools/builtins/index.js.map +1 -1
  225. package/dist/tools/builtins/job.js +1 -1
  226. package/dist/tools/builtins/job.js.map +1 -1
  227. package/dist/tools/builtins/monitor.d.ts +1 -1
  228. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  229. package/dist/tools/builtins/monitor.js +4 -2
  230. package/dist/tools/builtins/monitor.js.map +1 -1
  231. package/dist/tools/builtins/notebook-cells.d.ts +31 -0
  232. package/dist/tools/builtins/notebook-cells.d.ts.map +1 -0
  233. package/dist/tools/builtins/notebook-cells.js +160 -0
  234. package/dist/tools/builtins/notebook-cells.js.map +1 -0
  235. package/dist/tools/builtins/notebook-edit.d.ts +8 -0
  236. package/dist/tools/builtins/notebook-edit.d.ts.map +1 -0
  237. package/dist/tools/builtins/notebook-edit.js +249 -0
  238. package/dist/tools/builtins/notebook-edit.js.map +1 -0
  239. package/dist/tools/builtins/notebook-guard.d.ts.map +1 -1
  240. package/dist/tools/builtins/notebook-guard.js +2 -1
  241. package/dist/tools/builtins/notebook-guard.js.map +1 -1
  242. package/dist/tools/builtins/push-notification.d.ts +49 -0
  243. package/dist/tools/builtins/push-notification.d.ts.map +1 -0
  244. package/dist/tools/builtins/push-notification.js +107 -0
  245. package/dist/tools/builtins/push-notification.js.map +1 -0
  246. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  247. package/dist/tools/builtins/read-file.js +8 -3
  248. package/dist/tools/builtins/read-file.js.map +1 -1
  249. package/dist/tools/builtins/read-media.d.ts.map +1 -1
  250. package/dist/tools/builtins/read-media.js +2 -1
  251. package/dist/tools/builtins/read-media.js.map +1 -1
  252. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  253. package/dist/tools/builtins/read-render.js +5 -3
  254. package/dist/tools/builtins/read-render.js.map +1 -1
  255. package/dist/tools/builtins/search-support.d.ts +6 -4
  256. package/dist/tools/builtins/search-support.d.ts.map +1 -1
  257. package/dist/tools/builtins/search-support.js +15 -3
  258. package/dist/tools/builtins/search-support.js.map +1 -1
  259. package/dist/tools/builtins/skill.d.ts.map +1 -1
  260. package/dist/tools/builtins/skill.js +28 -8
  261. package/dist/tools/builtins/skill.js.map +1 -1
  262. package/dist/tools/builtins/sleep-guard.d.ts +20 -0
  263. package/dist/tools/builtins/sleep-guard.d.ts.map +1 -1
  264. package/dist/tools/builtins/sleep-guard.js +125 -1
  265. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  266. package/dist/tools/builtins/wait-for-job.js +1 -1
  267. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  268. package/dist/tools/builtins/web.d.ts +2 -0
  269. package/dist/tools/builtins/web.d.ts.map +1 -1
  270. package/dist/tools/builtins/web.js +97 -3
  271. package/dist/tools/builtins/web.js.map +1 -1
  272. package/dist/tools/command-shell.d.ts +50 -0
  273. package/dist/tools/command-shell.d.ts.map +1 -1
  274. package/dist/tools/command-shell.js +145 -0
  275. package/dist/tools/command-shell.js.map +1 -1
  276. package/dist/tools/env-scrub.d.ts +2 -0
  277. package/dist/tools/env-scrub.d.ts.map +1 -1
  278. package/dist/tools/env-scrub.js +15 -1
  279. package/dist/tools/env-scrub.js.map +1 -1
  280. package/dist/tools/git-config-env.d.ts +55 -0
  281. package/dist/tools/git-config-env.d.ts.map +1 -0
  282. package/dist/tools/git-config-env.js +130 -0
  283. package/dist/tools/git-config-env.js.map +1 -0
  284. package/dist/tools/schedules/schedule-tool.d.ts +7 -0
  285. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  286. package/dist/tools/schedules/schedule-tool.js +72 -3
  287. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  288. package/dist/tools/schedules/types.d.ts +38 -2
  289. package/dist/tools/schedules/types.d.ts.map +1 -1
  290. package/dist/types/connector/mcp.d.ts +24 -0
  291. package/dist/types/connector/mcp.d.ts.map +1 -1
  292. package/dist/types/message/index.d.ts +21 -1
  293. package/dist/types/message/index.d.ts.map +1 -1
  294. package/dist/types/message/index.js +37 -2
  295. package/dist/types/message/index.js.map +1 -1
  296. package/dist/types/plugin/index.d.ts +10 -2
  297. package/dist/types/plugin/index.d.ts.map +1 -1
  298. package/dist/types/plugin/index.js.map +1 -1
  299. package/dist/types/tool/index.d.ts +6 -0
  300. package/dist/types/tool/index.d.ts.map +1 -1
  301. package/dist/types/tool/index.js.map +1 -1
  302. package/dist/utils/plain-terminal-text.d.ts +21 -0
  303. package/dist/utils/plain-terminal-text.d.ts.map +1 -0
  304. package/dist/utils/plain-terminal-text.js +156 -0
  305. package/dist/utils/plain-terminal-text.js.map +1 -0
  306. package/package.json +1 -1
  307. package/src/authorization/bare-repository.ts +70 -0
  308. package/src/authorization/command-line.ts +18 -4
  309. package/src/authorization/gate.ts +11 -0
  310. package/src/authorization/protected-paths.ts +45 -1
  311. package/src/authorization/readonly-commands.ts +75 -6
  312. package/src/authorization/readonly-flags.ts +103 -0
  313. package/src/authorization/shell-lexer.ts +126 -3
  314. package/src/authorization/shell-paths.ts +386 -0
  315. package/src/authorization/shell-session-state.ts +97 -0
  316. package/src/authorization/shell-session.ts +23 -0
  317. package/src/authorization/skill-grant.ts +1 -0
  318. package/src/compaction/extractor.ts +1 -0
  319. package/src/compaction/hooks.ts +43 -1
  320. package/src/compaction/manual.ts +6 -0
  321. package/src/compaction/restore.ts +3 -2
  322. package/src/config/runtime.ts +7 -0
  323. package/src/connector/mcp/client.ts +61 -4
  324. package/src/connector/web/types.ts +8 -0
  325. package/src/constants/compaction/index.ts +1 -1
  326. package/src/execution/code-runtime/worker-program.ts +9 -5
  327. package/src/execution/local.ts +6 -1
  328. package/src/peers/index.ts +8 -2
  329. package/src/peers/record.ts +45 -1
  330. package/src/peers/registry.ts +21 -5
  331. package/src/plugin/bin-path.ts +149 -0
  332. package/src/plugin/common-layout/read.ts +1 -1
  333. package/src/plugin/common-layout-names.ts +0 -1
  334. package/src/plugin/hook-module/scan.ts +74 -2
  335. package/src/plugin/hook-module/worker-source.ts +56 -0
  336. package/src/plugin/lifecycle.ts +67 -0
  337. package/src/plugin/shell-hook-tool-names.ts +1 -0
  338. package/src/plugin/shell-hook.ts +23 -4
  339. package/src/public-runtime.ts +21 -0
  340. package/src/public-tools.ts +32 -1
  341. package/src/public-types.ts +3 -1
  342. package/src/runtime/jobs/monitor-stream.ts +18 -4
  343. package/src/runtime/jobs/registry.ts +22 -2
  344. package/src/runtime/query/auto-review/git-status.ts +3 -2
  345. package/src/runtime/query/executor.ts +79 -5
  346. package/src/runtime/query/index.ts +5 -2
  347. package/src/runtime/query/iteration/outstanding-work.ts +22 -4
  348. package/src/runtime/query/iteration/phases/compaction.ts +14 -1
  349. package/src/runtime/query/iteration/phases/tool-review.ts +24 -7
  350. package/src/runtime/query/path-escalation.ts +52 -4
  351. package/src/runtime/query/review-policy.ts +5 -2
  352. package/src/runtime/query/steering.ts +32 -4
  353. package/src/sandbox/provider/local.ts +3 -1
  354. package/src/schedules/describe.ts +2 -0
  355. package/src/schedules/evaluate.ts +29 -1
  356. package/src/schedules/index.ts +9 -1
  357. package/src/schedules/next-fire.ts +9 -0
  358. package/src/schedules/spec.ts +42 -0
  359. package/src/schedules/types.ts +33 -3
  360. package/src/schedules/watch.ts +71 -0
  361. package/src/session/workspace/git-worktree.ts +3 -1
  362. package/src/skills/arguments.ts +250 -0
  363. package/src/skills/index.ts +10 -0
  364. package/src/skills/inline-shell.ts +1268 -14
  365. package/src/tools/builtins/bash-cwd.ts +2 -0
  366. package/src/tools/builtins/bash.ts +93 -13
  367. package/src/tools/builtins/exit-semantics.ts +10 -0
  368. package/src/tools/builtins/glob.ts +79 -15
  369. package/src/tools/builtins/grep.ts +37 -10
  370. package/src/tools/builtins/index.ts +15 -0
  371. package/src/tools/builtins/job.ts +1 -1
  372. package/src/tools/builtins/monitor.ts +4 -2
  373. package/src/tools/builtins/notebook-cells.ts +196 -0
  374. package/src/tools/builtins/notebook-edit.ts +280 -0
  375. package/src/tools/builtins/notebook-guard.ts +2 -1
  376. package/src/tools/builtins/push-notification.ts +138 -0
  377. package/src/tools/builtins/read-file.ts +9 -3
  378. package/src/tools/builtins/read-media.ts +2 -1
  379. package/src/tools/builtins/read-render.ts +5 -3
  380. package/src/tools/builtins/search-support.ts +17 -3
  381. package/src/tools/builtins/skill.ts +27 -7
  382. package/src/tools/builtins/sleep-guard.ts +128 -1
  383. package/src/tools/builtins/wait-for-job.ts +1 -1
  384. package/src/tools/builtins/web.ts +100 -3
  385. package/src/tools/command-shell.ts +166 -0
  386. package/src/tools/env-scrub.ts +13 -1
  387. package/src/tools/git-config-env.ts +143 -0
  388. package/src/tools/schedules/schedule-tool.ts +79 -3
  389. package/src/tools/schedules/types.ts +47 -9
  390. package/src/types/connector/mcp.ts +25 -0
  391. package/src/types/message/index.ts +53 -1
  392. package/src/types/plugin/index.ts +10 -2
  393. package/src/types/tool/index.ts +6 -0
  394. package/src/utils/plain-terminal-text.ts +142 -0
@@ -146,6 +146,15 @@ export interface ShellLexResult {
146
146
  readonly complete: boolean
147
147
  /** Why the line is opaque, for diagnostics. Empty when it is not. */
148
148
  readonly reasons: readonly string[]
149
+ /**
150
+ * Names the line gives the integer (or name-reference) attribute to, with
151
+ * `declare`, `typeset` or `local`: a later value stored into one is
152
+ * evaluated as arithmetic. A host that keeps a shell session records them
153
+ * (see `shell-session.ts`).
154
+ */
155
+ readonly integerNames: readonly string[]
156
+ /** The line gives the attribute to names it does not spell out, or may do so through `eval` or `source`. */
157
+ readonly integerNamesUnknown: boolean
149
158
  }
150
159
 
151
160
  /**
@@ -232,12 +241,18 @@ import {
232
241
  shellInvocation,
233
242
  unwrapReexecChain,
234
243
  } from './reexec-wrapper.js'
244
+ import { type ShellAttributes, currentShellAttributes } from './shell-session-state.js'
235
245
 
236
246
  export type { ShellDialect }
237
247
 
238
248
  export interface ShellLexOptions {
239
249
  /** Default `bash`. */
240
250
  readonly dialect?: ShellDialect
251
+ /**
252
+ * What earlier lines of the same shell session gave the integer attribute
253
+ * to. Default: the session the caller runs in (`withShellSession`), if any.
254
+ */
255
+ readonly attributes?: ShellAttributes
241
256
  }
242
257
 
243
258
  export function lexShellCommandLine(line: string, options: ShellLexOptions = {}): ShellLexResult {
@@ -251,9 +266,11 @@ export function lexShellCommandLine(line: string, options: ShellLexOptions = {})
251
266
  opaque: true,
252
267
  complete: false,
253
268
  reasons: ['native CMD command parsing is unavailable'],
269
+ integerNames: [],
270
+ integerNamesUnknown: false,
254
271
  }
255
272
  }
256
- const context = new Context(line.length)
273
+ const context = new Context(line.length, options.attributes ?? currentShellAttributes())
257
274
  context.setDialect(line, options.dialect ?? 'bash')
258
275
  try {
259
276
  lexInto(line, context, 'line', 0)
@@ -270,6 +287,8 @@ export function lexShellCommandLine(line: string, options: ShellLexOptions = {})
270
287
  opaque: context.reasons.size > 0,
271
288
  complete: context.complete,
272
289
  reasons: [...context.reasons],
290
+ integerNames: [...context.declaredNames],
291
+ integerNamesUnknown: context.declaredUnknown,
273
292
  }
274
293
  }
275
294
 
@@ -286,10 +305,29 @@ class Context {
286
305
  */
287
306
  private rescans: number
288
307
 
289
- constructor(length: number) {
308
+ constructor(
309
+ length: number,
310
+ private readonly prior: ShellAttributes | undefined = undefined,
311
+ ) {
290
312
  this.rescans = 4 * length + 4096
291
313
  }
292
314
 
315
+ /** Names this line gives the integer attribute to, and whether it may give it to more. */
316
+ readonly declaredNames = new Set<string>()
317
+ declaredUnknown = false
318
+
319
+ /**
320
+ * A value that may hold a subscript or an expansion is stored into `name`.
321
+ * If an earlier line of the session gave `name` the integer attribute, or
322
+ * may have given it to any name, bash evaluates the value as arithmetic.
323
+ * `undefined` is a name the lexer cannot read.
324
+ */
325
+ storedInto(name: string | undefined): void {
326
+ if (this.prior === undefined) return
327
+ if (this.prior.unknown || name === undefined || this.prior.integers.has(name))
328
+ this.opaque('arithmetic')
329
+ }
330
+
293
331
  opaque(reason: string): void {
294
332
  this.reasons.add(reason)
295
333
  }
@@ -484,6 +522,28 @@ function subscriptWithExpansion(word: ShellWord): boolean {
484
522
  return word.value.includes('[') && (word.expands || /[$`]/.test(word.value))
485
523
  }
486
524
 
525
+ /** The variable a `NAME`, `NAME[sub]` or `NAME+` operand stores into; undefined when it is not a plain name. */
526
+ function plainName(text: string): string | undefined {
527
+ const match = /^([A-Za-z_][A-Za-z0-9_]*)(?:\[.*\])?\+?$/s.exec(text)
528
+ return match === null ? undefined : (match[1] as string)
529
+ }
530
+
531
+ /**
532
+ * Text with a letter or underscore in it. Stored into an integer name, a bare
533
+ * word like that is read as a variable and its value evaluated again, so
534
+ * `x=y` runs what an earlier call stored in `y`.
535
+ */
536
+ const NAMES_A_VARIABLE = /[A-Za-z_]/
537
+
538
+ /** `NAME=`, `NAME+=` or `NAME[sub]=` at the start of a word. */
539
+ const ASSIGNMENT_NAME = /^([A-Za-z_][A-Za-z0-9_]*)(?:\[[^\]]*\])?\+?=/
540
+
541
+ /** A parameter expansion that assigns: `${NAME:=word}`, `${NAME=word}`. */
542
+ const ASSIGNING_EXPANSION = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?:\[[^\]]*\])?:?=/g
543
+
544
+ /** Text that hands a name the integer or name-reference attribute when read as a line. */
545
+ const DECLARES_INTEGER = /\b(?:declare|typeset|local)\b[^;&|\n]*\s-[A-Za-z]*[in]/
546
+
487
547
  const PLAIN_INTEGER_ARGUMENT = /^[A-Za-z_][A-Za-z0-9_]*(?:=[0-9\s+\-*/%()<>=!&|^~?:,]*)?$/
488
548
 
489
549
  const WORD_BREAK = new Set([' ', '\t', '\n', ';', '&', '|', '(', ')', '<', '>'])
@@ -947,6 +1007,7 @@ class Parser {
947
1007
  this.context.compoundWords.push(name.word)
948
1008
  // The loop variable takes whatever the list holds.
949
1009
  this.context.bracketAssigned()
1010
+ let listHoldsBracket = false
950
1011
  this.newlines()
951
1012
  token = this.peek()
952
1013
  if (token.kind === 'word' && !token.word.quoted && token.word.value === 'in') {
@@ -966,6 +1027,12 @@ class Parser {
966
1027
  token = this.takePlainWord()
967
1028
  if (token.kind === 'word') {
968
1029
  this.context.compoundWords.push(token.word)
1030
+ if (
1031
+ token.word.value.includes('[') ||
1032
+ token.word.expands ||
1033
+ NAMES_A_VARIABLE.test(token.word.value)
1034
+ )
1035
+ listHoldsBracket = true
969
1036
  continue
970
1037
  }
971
1038
  if (token.kind === 'newline' || (token.kind === 'op' && token.op === ';')) break
@@ -976,6 +1043,7 @@ class Parser {
976
1043
  this.take()
977
1044
  this.newlines()
978
1045
  }
1046
+ if (listHoldsBracket) this.context.storedInto(plainName(name.word.value))
979
1047
  this.loopBody()
980
1048
  }
981
1049
 
@@ -1409,6 +1477,10 @@ class Parser {
1409
1477
  */
1410
1478
  private inspectArithmeticBuiltin(command: ShellCommand): void {
1411
1479
  for (let i = 0; i < command.assignments; i += 1) this.noteBracketAssignment(command.words[i])
1480
+ for (const word of command.words) {
1481
+ for (const match of word.value.matchAll(ASSIGNING_EXPANSION))
1482
+ this.context.storedInto(match[1])
1483
+ }
1412
1484
  let at = command.assignments
1413
1485
  for (;;) {
1414
1486
  const word = command.words[at]
@@ -1418,6 +1490,17 @@ class Parser {
1418
1490
  // later word, the line asks.
1419
1491
  if (command.words.slice(at + 1).some(subscriptWithExpansion))
1420
1492
  this.context.opaque('arithmetic')
1493
+ // A command name held in a variable may be `declare`: flags that
1494
+ // give the integer or name-reference attribute then name a name the
1495
+ // lexer cannot read.
1496
+ if (
1497
+ command.words
1498
+ .slice(at + 1)
1499
+ .some((arg) => !arg.expands && /^-[A-Za-z]*[in]/.test(arg.value))
1500
+ ) {
1501
+ this.context.declaredUnknown = true
1502
+ this.context.declaredArithmetic()
1503
+ }
1421
1504
  return
1422
1505
  }
1423
1506
  if ((word.value === 'builtin' || word.value === 'command') && command.words[at + 1]) {
@@ -1452,6 +1535,14 @@ class Parser {
1452
1535
  // eval reads its words as a line again, where a name with a subscript
1453
1536
  // and an expansion can reach `unset` or `declare -i`.
1454
1537
  if (args.some(subscriptWithExpansion)) this.context.opaque('arithmetic')
1538
+ // What it runs may give the attribute to any name.
1539
+ if (args.some((word) => word.expands || DECLARES_INTEGER.test(word.value)))
1540
+ this.context.declaredUnknown = true
1541
+ return
1542
+ }
1543
+ if (name === 'source' || name === '.') {
1544
+ // A file read into the shell may declare anything.
1545
+ this.context.declaredUnknown = true
1455
1546
  return
1456
1547
  }
1457
1548
  if (name === 'let') {
@@ -1468,12 +1559,15 @@ class Parser {
1468
1559
  this.context.bracketAssigned()
1469
1560
  const target = args[i + 1]
1470
1561
  if (target !== undefined && subscriptOrExpands(target)) this.context.opaque('arithmetic')
1562
+ // The formatted text is stored: whatever its arguments hold.
1563
+ this.context.storedInto(target === undefined ? undefined : plainName(target.value))
1471
1564
  i += 1
1472
1565
  continue
1473
1566
  }
1474
1567
  if (value.startsWith('-v')) {
1475
1568
  this.context.bracketAssigned()
1476
1569
  if (subscriptOrExpands(args[i] as ShellWord)) this.context.opaque('arithmetic')
1570
+ this.context.storedInto(plainName(value.slice(2)))
1477
1571
  }
1478
1572
  }
1479
1573
  return
@@ -1490,6 +1584,10 @@ class Parser {
1490
1584
  if (name === 'mapfile' || name === 'readarray' || name === 'getopts') {
1491
1585
  this.context.bracketAssigned()
1492
1586
  if (args.some((word) => subscriptOrExpands(word))) this.context.opaque('arithmetic')
1587
+ // Input stores into the named array (default MAPFILE); getopts into its name.
1588
+ const operands = args.filter((word) => !word.value.startsWith('-'))
1589
+ if (name !== 'getopts' && operands.length === 0) this.context.storedInto('MAPFILE')
1590
+ for (const word of operands) this.context.storedInto(plainName(word.value))
1493
1591
  return
1494
1592
  }
1495
1593
  if (name === 'test' || name === '[') {
@@ -1500,6 +1598,10 @@ class Parser {
1500
1598
  }
1501
1599
  return
1502
1600
  }
1601
+ if (name === 'export' || name === 'readonly') {
1602
+ for (const word of args) this.noteBracketAssignment(word)
1603
+ return
1604
+ }
1503
1605
  if (name !== 'declare' && name !== 'typeset' && name !== 'local') return
1504
1606
  let integer = false
1505
1607
  let nameref = false
@@ -1521,6 +1623,11 @@ class Parser {
1521
1623
  if (flags && word.value.startsWith('-') && !word.expands) continue
1522
1624
  const equals = word.value.indexOf('=')
1523
1625
  const nameFor = equals < 0 ? word.value : word.value.slice(0, equals)
1626
+ if (integer || nameref) {
1627
+ const declared = plainName(nameFor)
1628
+ if (declared === undefined) this.context.declaredUnknown = true
1629
+ else this.context.declaredNames.add(declared)
1630
+ }
1524
1631
  if (nameFor.includes('[') || (word.expands && /[$`]/.test(nameFor)))
1525
1632
  this.context.opaque('arithmetic')
1526
1633
  else if (nameref && word.value.slice(equals + 1).includes('[') && equals >= 0)
@@ -1534,6 +1641,7 @@ class Parser {
1534
1641
  /** The names `read` stores into, minus the arguments of its options. */
1535
1642
  private inspectRead(args: ShellWord[]): void {
1536
1643
  let options = true
1644
+ let targets = 0
1537
1645
  for (let i = 0; i < args.length; i += 1) {
1538
1646
  const value = (args[i] as ShellWord).value
1539
1647
  if (options && value === '--') {
@@ -1548,13 +1656,20 @@ class Parser {
1548
1656
  const operand = rest.length > 0 ? rest : (args[i + 1]?.value ?? '')
1549
1657
  if (rest.length === 0) i += 1
1550
1658
  if (letter === 'a' && operand.includes('[')) this.context.opaque('arithmetic')
1659
+ if (letter === 'a') {
1660
+ this.context.storedInto(plainName(operand))
1661
+ targets += 1
1662
+ }
1551
1663
  break
1552
1664
  }
1553
1665
  }
1554
1666
  continue
1555
1667
  }
1556
1668
  if (subscriptOrExpands(args[i] as ShellWord)) this.context.opaque('arithmetic')
1669
+ this.context.storedInto(plainName(value))
1670
+ targets += 1
1557
1671
  }
1672
+ if (targets === 0) this.context.storedInto('REPLY')
1558
1673
  }
1559
1674
 
1560
1675
  /** A plain `NAME=value` whose value holds a subscript: dangerous once NAME is `-i` or `-n`. */
@@ -1563,7 +1678,15 @@ class Parser {
1563
1678
  const equals = word.value.indexOf('=')
1564
1679
  if (equals <= 0) return
1565
1680
  const value = word.value.slice(equals + 1)
1566
- if (value.includes('[') || (word.expands && /[$`]/.test(value))) this.context.bracketAssigned()
1681
+ if (value.includes('[') || (word.expands && /[$`]/.test(value))) {
1682
+ this.context.bracketAssigned()
1683
+ const named = ASSIGNMENT_NAME.exec(word.value)
1684
+ this.context.storedInto(named === null ? undefined : named[1])
1685
+ } else if (NAMES_A_VARIABLE.test(value)) {
1686
+ // A name holds whatever an earlier call stored in it.
1687
+ const named = ASSIGNMENT_NAME.exec(word.value)
1688
+ this.context.storedInto(named === null ? undefined : named[1])
1689
+ }
1567
1690
  }
1568
1691
 
1569
1692
  /** Read the payload of `bash -c payload` as a command line of its own. */
@@ -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