@namzu/sdk 51.1.0 → 52.1.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 (395) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/agents/SupervisorAgent.d.ts +1 -1
  6. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  7. package/dist/agents/SupervisorAgent.js.map +1 -1
  8. package/dist/agents/examples/SupervisorAgent.d.ts +42 -0
  9. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
  10. package/dist/agents/examples/SupervisorAgent.js +80 -4
  11. package/dist/agents/examples/SupervisorAgent.js.map +1 -1
  12. package/dist/agents/index.d.ts +1 -1
  13. package/dist/agents/index.d.ts.map +1 -1
  14. package/dist/agents/index.js.map +1 -1
  15. package/dist/authorization/protected-paths.d.ts +36 -0
  16. package/dist/authorization/protected-paths.d.ts.map +1 -0
  17. package/dist/authorization/protected-paths.js +107 -0
  18. package/dist/authorization/protected-paths.js.map +1 -0
  19. package/dist/authorization/readonly-commands.d.ts +39 -0
  20. package/dist/authorization/readonly-commands.d.ts.map +1 -0
  21. package/dist/authorization/readonly-commands.js +797 -0
  22. package/dist/authorization/readonly-commands.js.map +1 -0
  23. package/dist/authorization/readonly-flags.d.ts +19 -0
  24. package/dist/authorization/readonly-flags.d.ts.map +1 -0
  25. package/dist/authorization/readonly-flags.js +178 -0
  26. package/dist/authorization/readonly-flags.js.map +1 -0
  27. package/dist/authorization/removal.d.ts +52 -0
  28. package/dist/authorization/removal.d.ts.map +1 -0
  29. package/dist/authorization/removal.js +283 -0
  30. package/dist/authorization/removal.js.map +1 -0
  31. package/dist/authorization/shell-paths.d.ts +66 -0
  32. package/dist/authorization/shell-paths.d.ts.map +1 -0
  33. package/dist/authorization/shell-paths.js +697 -0
  34. package/dist/authorization/shell-paths.js.map +1 -0
  35. package/dist/bridge/acp/update.d.ts.map +1 -1
  36. package/dist/bridge/acp/update.js +1 -0
  37. package/dist/bridge/acp/update.js.map +1 -1
  38. package/dist/compaction/context-window.d.ts +24 -0
  39. package/dist/compaction/context-window.d.ts.map +1 -1
  40. package/dist/compaction/context-window.js +34 -0
  41. package/dist/compaction/context-window.js.map +1 -1
  42. package/dist/compaction/manual.d.ts.map +1 -1
  43. package/dist/compaction/manual.js +10 -2
  44. package/dist/compaction/manual.js.map +1 -1
  45. package/dist/compaction/plan.d.ts +4 -0
  46. package/dist/compaction/plan.d.ts.map +1 -1
  47. package/dist/compaction/plan.js +6 -2
  48. package/dist/compaction/plan.js.map +1 -1
  49. package/dist/compaction/verifier.d.ts +11 -1
  50. package/dist/compaction/verifier.d.ts.map +1 -1
  51. package/dist/compaction/verifier.js +75 -23
  52. package/dist/compaction/verifier.js.map +1 -1
  53. package/dist/config/runtime.d.ts +55 -7
  54. package/dist/config/runtime.d.ts.map +1 -1
  55. package/dist/config/runtime.js +23 -2
  56. package/dist/config/runtime.js.map +1 -1
  57. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  58. package/dist/connector/web/guarded-fetch.js +24 -0
  59. package/dist/connector/web/guarded-fetch.js.map +1 -1
  60. package/dist/connector/web/index.d.ts +1 -1
  61. package/dist/connector/web/index.d.ts.map +1 -1
  62. package/dist/connector/web/page.d.ts +59 -0
  63. package/dist/connector/web/page.d.ts.map +1 -0
  64. package/dist/connector/web/page.js +112 -0
  65. package/dist/connector/web/page.js.map +1 -0
  66. package/dist/connector/web/types.d.ts +47 -0
  67. package/dist/connector/web/types.d.ts.map +1 -1
  68. package/dist/connector/web/types.js.map +1 -1
  69. package/dist/constants/continuation.d.ts +8 -0
  70. package/dist/constants/continuation.d.ts.map +1 -1
  71. package/dist/constants/continuation.js +8 -0
  72. package/dist/constants/continuation.js.map +1 -1
  73. package/dist/constants/plugin/index.d.ts +1 -1
  74. package/dist/constants/plugin/index.d.ts.map +1 -1
  75. package/dist/constants/plugin/index.js +1 -1
  76. package/dist/constants/plugin/index.js.map +1 -1
  77. package/dist/contracts/a2a.d.ts +2 -2
  78. package/dist/manager/agent/lifecycle.d.ts +7 -0
  79. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  80. package/dist/manager/agent/lifecycle.js +11 -2
  81. package/dist/manager/agent/lifecycle.js.map +1 -1
  82. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  83. package/dist/manager/session/turn-recorder.js +4 -2
  84. package/dist/manager/session/turn-recorder.js.map +1 -1
  85. package/dist/plugin/index.d.ts +1 -1
  86. package/dist/plugin/index.d.ts.map +1 -1
  87. package/dist/plugin/index.js +1 -1
  88. package/dist/plugin/index.js.map +1 -1
  89. package/dist/plugin/lifecycle.d.ts +6 -0
  90. package/dist/plugin/lifecycle.d.ts.map +1 -1
  91. package/dist/plugin/lifecycle.js +98 -114
  92. package/dist/plugin/lifecycle.js.map +1 -1
  93. package/dist/plugin/shell-hook.d.ts +90 -22
  94. package/dist/plugin/shell-hook.d.ts.map +1 -1
  95. package/dist/plugin/shell-hook.js +434 -41
  96. package/dist/plugin/shell-hook.js.map +1 -1
  97. package/dist/provider/capabilities.d.ts +9 -0
  98. package/dist/provider/capabilities.d.ts.map +1 -1
  99. package/dist/provider/capabilities.js +15 -0
  100. package/dist/provider/capabilities.js.map +1 -1
  101. package/dist/provider/errors.d.ts.map +1 -1
  102. package/dist/provider/errors.js +13 -0
  103. package/dist/provider/errors.js.map +1 -1
  104. package/dist/provider/fallback.d.ts.map +1 -1
  105. package/dist/provider/fallback.js +10 -0
  106. package/dist/provider/fallback.js.map +1 -1
  107. package/dist/provider/idle-timeout.d.ts.map +1 -1
  108. package/dist/provider/idle-timeout.js +5 -0
  109. package/dist/provider/idle-timeout.js.map +1 -1
  110. package/dist/provider/image-input-refusal.d.ts +9 -0
  111. package/dist/provider/image-input-refusal.d.ts.map +1 -0
  112. package/dist/provider/image-input-refusal.js +54 -0
  113. package/dist/provider/image-input-refusal.js.map +1 -0
  114. package/dist/provider/index.d.ts +2 -1
  115. package/dist/provider/index.d.ts.map +1 -1
  116. package/dist/provider/index.js +2 -1
  117. package/dist/provider/index.js.map +1 -1
  118. package/dist/provider/retry.d.ts +7 -2
  119. package/dist/provider/retry.d.ts.map +1 -1
  120. package/dist/provider/retry.js +38 -4
  121. package/dist/provider/retry.js.map +1 -1
  122. package/dist/public-runtime.d.ts +5 -2
  123. package/dist/public-runtime.d.ts.map +1 -1
  124. package/dist/public-runtime.js +5 -2
  125. package/dist/public-runtime.js.map +1 -1
  126. package/dist/public-types.d.ts +2 -2
  127. package/dist/public-types.d.ts.map +1 -1
  128. package/dist/runtime/jobs/registry.d.ts +21 -0
  129. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  130. package/dist/runtime/jobs/registry.js +15 -2
  131. package/dist/runtime/jobs/registry.js.map +1 -1
  132. package/dist/runtime/query/deferred-sandbox.d.ts +54 -0
  133. package/dist/runtime/query/deferred-sandbox.d.ts.map +1 -0
  134. package/dist/runtime/query/deferred-sandbox.js +75 -0
  135. package/dist/runtime/query/deferred-sandbox.js.map +1 -0
  136. package/dist/runtime/query/executor/tool-call-admission.d.ts +10 -0
  137. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  138. package/dist/runtime/query/executor/tool-call-admission.js +74 -13
  139. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  140. package/dist/runtime/query/executor.d.ts +51 -2
  141. package/dist/runtime/query/executor.d.ts.map +1 -1
  142. package/dist/runtime/query/executor.js +214 -9
  143. package/dist/runtime/query/executor.js.map +1 -1
  144. package/dist/runtime/query/finalize-turn.d.ts +6 -0
  145. package/dist/runtime/query/finalize-turn.d.ts.map +1 -1
  146. package/dist/runtime/query/finalize-turn.js +1 -1
  147. package/dist/runtime/query/finalize-turn.js.map +1 -1
  148. package/dist/runtime/query/index.d.ts +29 -0
  149. package/dist/runtime/query/index.d.ts.map +1 -1
  150. package/dist/runtime/query/index.js +108 -28
  151. package/dist/runtime/query/index.js.map +1 -1
  152. package/dist/runtime/query/iteration/index.d.ts +57 -0
  153. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  154. package/dist/runtime/query/iteration/index.js +380 -28
  155. package/dist/runtime/query/iteration/index.js.map +1 -1
  156. package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts +61 -0
  157. package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts.map +1 -0
  158. package/dist/runtime/query/iteration/phases/compaction-breaker.js +94 -0
  159. package/dist/runtime/query/iteration/phases/compaction-breaker.js.map +1 -0
  160. package/dist/runtime/query/iteration/phases/compaction.d.ts +42 -1
  161. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  162. package/dist/runtime/query/iteration/phases/compaction.js +203 -23
  163. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  164. package/dist/runtime/query/iteration/phases/context.d.ts +10 -0
  165. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  166. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  167. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  168. package/dist/runtime/query/iteration/phases/tool-review.js +165 -2
  169. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  170. package/dist/runtime/query/iteration/provider-rejected-image.d.ts +21 -1
  171. package/dist/runtime/query/iteration/provider-rejected-image.d.ts.map +1 -1
  172. package/dist/runtime/query/iteration/provider-rejected-image.js +53 -7
  173. package/dist/runtime/query/iteration/provider-rejected-image.js.map +1 -1
  174. package/dist/runtime/query/iteration/request-repair.d.ts +108 -0
  175. package/dist/runtime/query/iteration/request-repair.d.ts.map +1 -0
  176. package/dist/runtime/query/iteration/request-repair.js +593 -0
  177. package/dist/runtime/query/iteration/request-repair.js.map +1 -0
  178. package/dist/runtime/query/iteration/stream-turn.d.ts +6 -0
  179. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  180. package/dist/runtime/query/iteration/stream-turn.js +2 -2
  181. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  182. package/dist/runtime/query/path-escalation.d.ts +36 -0
  183. package/dist/runtime/query/path-escalation.d.ts.map +1 -0
  184. package/dist/runtime/query/path-escalation.js +184 -0
  185. package/dist/runtime/query/path-escalation.js.map +1 -0
  186. package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
  187. package/dist/runtime/query/plugin-hooks.js +8 -0
  188. package/dist/runtime/query/plugin-hooks.js.map +1 -1
  189. package/dist/runtime/query/reminders.d.ts +35 -0
  190. package/dist/runtime/query/reminders.d.ts.map +1 -0
  191. package/dist/runtime/query/reminders.js +7 -0
  192. package/dist/runtime/query/reminders.js.map +1 -0
  193. package/dist/runtime/query/request-rich-content.d.ts +5 -1
  194. package/dist/runtime/query/request-rich-content.d.ts.map +1 -1
  195. package/dist/runtime/query/request-rich-content.js +67 -25
  196. package/dist/runtime/query/request-rich-content.js.map +1 -1
  197. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  198. package/dist/runtime/query/resume-pending.js +26 -0
  199. package/dist/runtime/query/resume-pending.js.map +1 -1
  200. package/dist/runtime/query/review-policy.d.ts +26 -0
  201. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  202. package/dist/runtime/query/review-policy.js +79 -5
  203. package/dist/runtime/query/review-policy.js.map +1 -1
  204. package/dist/runtime/query/tool-output-budget.d.ts +46 -0
  205. package/dist/runtime/query/tool-output-budget.d.ts.map +1 -1
  206. package/dist/runtime/query/tool-output-budget.js +85 -1
  207. package/dist/runtime/query/tool-output-budget.js.map +1 -1
  208. package/dist/runtime/query/tooling.d.ts +1 -0
  209. package/dist/runtime/query/tooling.d.ts.map +1 -1
  210. package/dist/runtime/query/tooling.js +5 -0
  211. package/dist/runtime/query/tooling.js.map +1 -1
  212. package/dist/session/paths.d.ts +5 -1
  213. package/dist/session/paths.d.ts.map +1 -1
  214. package/dist/session/paths.js +8 -0
  215. package/dist/session/paths.js.map +1 -1
  216. package/dist/store/memory/disk.d.ts.map +1 -1
  217. package/dist/store/memory/disk.js +2 -2
  218. package/dist/store/memory/disk.js.map +1 -1
  219. package/dist/store/memory/markdown.d.ts.map +1 -1
  220. package/dist/store/memory/markdown.js +2 -2
  221. package/dist/store/memory/markdown.js.map +1 -1
  222. package/dist/store/memory/naming.d.ts +9 -0
  223. package/dist/store/memory/naming.d.ts.map +1 -1
  224. package/dist/store/memory/naming.js +12 -0
  225. package/dist/store/memory/naming.js.map +1 -1
  226. package/dist/tools/builtins/bash.d.ts +30 -1
  227. package/dist/tools/builtins/bash.d.ts.map +1 -1
  228. package/dist/tools/builtins/bash.js +170 -26
  229. package/dist/tools/builtins/bash.js.map +1 -1
  230. package/dist/tools/builtins/computer-use.d.ts +1 -1
  231. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  232. package/dist/tools/builtins/computer-use.js +12 -5
  233. package/dist/tools/builtins/computer-use.js.map +1 -1
  234. package/dist/tools/builtins/content-fingerprint.d.ts +2 -0
  235. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  236. package/dist/tools/builtins/content-fingerprint.js +4 -0
  237. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  238. package/dist/tools/builtins/edit.d.ts.map +1 -1
  239. package/dist/tools/builtins/edit.js +60 -18
  240. package/dist/tools/builtins/edit.js.map +1 -1
  241. package/dist/tools/builtins/grep.d.ts +8 -1
  242. package/dist/tools/builtins/grep.d.ts.map +1 -1
  243. package/dist/tools/builtins/grep.js +152 -33
  244. package/dist/tools/builtins/grep.js.map +1 -1
  245. package/dist/tools/builtins/read-file.d.ts +1 -0
  246. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  247. package/dist/tools/builtins/read-file.js +44 -5
  248. package/dist/tools/builtins/read-file.js.map +1 -1
  249. package/dist/tools/builtins/read-render.d.ts +52 -0
  250. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  251. package/dist/tools/builtins/read-render.js +143 -0
  252. package/dist/tools/builtins/read-render.js.map +1 -1
  253. package/dist/tools/builtins/web.d.ts +13 -2
  254. package/dist/tools/builtins/web.d.ts.map +1 -1
  255. package/dist/tools/builtins/web.js +225 -32
  256. package/dist/tools/builtins/web.js.map +1 -1
  257. package/dist/tools/coordinator/ask-user-question.d.ts +2 -0
  258. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  259. package/dist/tools/coordinator/ask-user-question.js +256 -92
  260. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  261. package/dist/tools/coordinator/question-options.d.ts +1 -0
  262. package/dist/tools/coordinator/question-options.d.ts.map +1 -1
  263. package/dist/tools/coordinator/question-options.js +6 -1
  264. package/dist/tools/coordinator/question-options.js.map +1 -1
  265. package/dist/tools/defineTool.d.ts +4 -1
  266. package/dist/tools/defineTool.d.ts.map +1 -1
  267. package/dist/tools/defineTool.js +6 -1
  268. package/dist/tools/defineTool.js.map +1 -1
  269. package/dist/tools/paths.d.ts +6 -0
  270. package/dist/tools/paths.d.ts.map +1 -1
  271. package/dist/tools/paths.js +1 -1
  272. package/dist/tools/paths.js.map +1 -1
  273. package/dist/types/agent/query.d.ts +3 -0
  274. package/dist/types/agent/query.d.ts.map +1 -1
  275. package/dist/types/errors/catalog.js +1 -1
  276. package/dist/types/errors/catalog.js.map +1 -1
  277. package/dist/types/hitl/index.d.ts +104 -0
  278. package/dist/types/hitl/index.d.ts.map +1 -1
  279. package/dist/types/hitl/index.js.map +1 -1
  280. package/dist/types/message/index.d.ts +1 -1
  281. package/dist/types/message/index.d.ts.map +1 -1
  282. package/dist/types/message/index.js +2 -0
  283. package/dist/types/message/index.js.map +1 -1
  284. package/dist/types/plugin/index.d.ts +93 -19
  285. package/dist/types/plugin/index.d.ts.map +1 -1
  286. package/dist/types/plugin/index.js +3 -0
  287. package/dist/types/plugin/index.js.map +1 -1
  288. package/dist/types/provider/errors.d.ts +19 -0
  289. package/dist/types/provider/errors.d.ts.map +1 -1
  290. package/dist/types/provider/errors.js +54 -5
  291. package/dist/types/provider/errors.js.map +1 -1
  292. package/dist/types/provider/interface.d.ts +12 -0
  293. package/dist/types/provider/interface.d.ts.map +1 -1
  294. package/dist/types/provider/stream.d.ts +1 -1
  295. package/dist/types/session/config.d.ts +14 -0
  296. package/dist/types/session/config.d.ts.map +1 -1
  297. package/dist/types/session/events.d.ts +27 -4
  298. package/dist/types/session/events.d.ts.map +1 -1
  299. package/dist/types/session/events.js.map +1 -1
  300. package/dist/types/session/records.d.ts +9 -9
  301. package/dist/types/session/records.d.ts.map +1 -1
  302. package/dist/types/session/records.js +1 -0
  303. package/dist/types/session/records.js.map +1 -1
  304. package/dist/types/session/stop-reason.d.ts +5 -0
  305. package/dist/types/session/stop-reason.d.ts.map +1 -1
  306. package/dist/types/tool/index.d.ts +52 -0
  307. package/dist/types/tool/index.d.ts.map +1 -1
  308. package/dist/types/tool/index.js.map +1 -1
  309. package/package.json +4 -2
  310. package/src/agents/QueryAgent.ts +5 -1
  311. package/src/agents/SupervisorAgent.ts +1 -1
  312. package/src/agents/examples/SupervisorAgent.ts +217 -106
  313. package/src/agents/index.ts +1 -1
  314. package/src/authorization/protected-paths.ts +110 -0
  315. package/src/authorization/readonly-commands.ts +771 -0
  316. package/src/authorization/readonly-flags.ts +196 -0
  317. package/src/authorization/removal.ts +326 -0
  318. package/src/authorization/shell-paths.ts +927 -0
  319. package/src/bridge/acp/update.ts +1 -0
  320. package/src/compaction/context-window.ts +41 -0
  321. package/src/compaction/manual.ts +10 -2
  322. package/src/compaction/plan.ts +11 -2
  323. package/src/compaction/verifier.ts +84 -22
  324. package/src/config/runtime.ts +23 -2
  325. package/src/connector/web/guarded-fetch.ts +26 -0
  326. package/src/connector/web/index.ts +3 -0
  327. package/src/connector/web/page.ts +130 -0
  328. package/src/connector/web/types.ts +47 -0
  329. package/src/constants/continuation.ts +10 -0
  330. package/src/constants/plugin/index.ts +1 -1
  331. package/src/manager/agent/lifecycle.ts +12 -4
  332. package/src/manager/session/turn-recorder.ts +10 -2
  333. package/src/plugin/index.ts +1 -0
  334. package/src/plugin/lifecycle.ts +107 -119
  335. package/src/plugin/shell-hook.ts +477 -43
  336. package/src/provider/capabilities.ts +17 -0
  337. package/src/provider/errors.ts +13 -0
  338. package/src/provider/fallback.ts +10 -0
  339. package/src/provider/idle-timeout.ts +5 -0
  340. package/src/provider/image-input-refusal.ts +54 -0
  341. package/src/provider/index.ts +2 -0
  342. package/src/provider/retry.ts +42 -4
  343. package/src/public-runtime.ts +11 -0
  344. package/src/public-types.ts +4 -0
  345. package/src/runtime/jobs/registry.ts +39 -2
  346. package/src/runtime/query/deferred-sandbox.ts +110 -0
  347. package/src/runtime/query/executor/tool-call-admission.ts +79 -13
  348. package/src/runtime/query/executor.ts +267 -11
  349. package/src/runtime/query/finalize-turn.ts +7 -1
  350. package/src/runtime/query/index.ts +169 -52
  351. package/src/runtime/query/iteration/index.ts +439 -35
  352. package/src/runtime/query/iteration/phases/compaction-breaker.ts +108 -0
  353. package/src/runtime/query/iteration/phases/compaction.ts +241 -38
  354. package/src/runtime/query/iteration/phases/context.ts +11 -0
  355. package/src/runtime/query/iteration/phases/tool-review.ts +177 -2
  356. package/src/runtime/query/iteration/provider-rejected-image.ts +71 -5
  357. package/src/runtime/query/iteration/request-repair.ts +743 -0
  358. package/src/runtime/query/iteration/stream-turn.ts +11 -1
  359. package/src/runtime/query/path-escalation.ts +204 -0
  360. package/src/runtime/query/plugin-hooks.ts +8 -0
  361. package/src/runtime/query/reminders.ts +45 -0
  362. package/src/runtime/query/request-rich-content.ts +77 -27
  363. package/src/runtime/query/resume-pending.ts +27 -0
  364. package/src/runtime/query/review-policy.ts +106 -5
  365. package/src/runtime/query/tool-output-budget.ts +115 -1
  366. package/src/runtime/query/tooling.ts +6 -0
  367. package/src/session/paths.ts +11 -1
  368. package/src/store/memory/disk.ts +2 -1
  369. package/src/store/memory/markdown.ts +2 -1
  370. package/src/store/memory/naming.ts +13 -0
  371. package/src/tools/builtins/bash.ts +203 -34
  372. package/src/tools/builtins/computer-use.ts +13 -4
  373. package/src/tools/builtins/content-fingerprint.ts +5 -0
  374. package/src/tools/builtins/edit.ts +69 -19
  375. package/src/tools/builtins/grep.ts +159 -38
  376. package/src/tools/builtins/read-file.ts +48 -5
  377. package/src/tools/builtins/read-render.ts +193 -0
  378. package/src/tools/builtins/web.ts +258 -33
  379. package/src/tools/coordinator/ask-user-question.ts +309 -103
  380. package/src/tools/coordinator/question-options.ts +8 -1
  381. package/src/tools/defineTool.ts +11 -2
  382. package/src/tools/paths.ts +1 -1
  383. package/src/types/agent/query.ts +3 -0
  384. package/src/types/errors/catalog.ts +1 -1
  385. package/src/types/hitl/index.ts +104 -0
  386. package/src/types/message/index.ts +2 -0
  387. package/src/types/plugin/index.ts +101 -18
  388. package/src/types/provider/errors.ts +66 -5
  389. package/src/types/provider/interface.ts +13 -0
  390. package/src/types/provider/stream.ts +1 -1
  391. package/src/types/session/config.ts +14 -0
  392. package/src/types/session/events.ts +32 -4
  393. package/src/types/session/records.ts +1 -0
  394. package/src/types/session/stop-reason.ts +5 -0
  395. package/src/types/tool/index.ts +53 -2
@@ -0,0 +1,697 @@
1
+ /**
2
+ * The files a shell command line names, read before it runs.
3
+ *
4
+ * The file tools declare a `pathArgument`, so the kernel can see which path a
5
+ * call reaches. A shell command line has no such argument: `cat /etc/passwd`
6
+ * and `echo x > ~/.profile` carry their paths inside one string, and a
7
+ * boundary that only reads declared arguments let both through.
8
+ *
9
+ * This is the reference terminal's answer, ported: a table of the commands
10
+ * whose positional arguments are paths (its path-command table and
11
+ * per-command extractors, version 2.1.302), the kind of access each makes (read,
12
+ * write or create), and the output redirections of the line. It is a
13
+ * reading of the text, not a model of the shell:
14
+ *
15
+ * - a word that expands at runtime (`$VAR`, `$(...)`) has no path to read;
16
+ * it is reported with `unresolved` so the caller decides what an unreadable
17
+ * write target is worth (the reference asks);
18
+ * - a `cd` earlier in the line moves every relative path after it, which the
19
+ * reading does not follow, so the caller is told one happened;
20
+ * - a command that is not in the table contributes nothing.
21
+ *
22
+ * Nothing here touches the file system. The caller resolves the paths
23
+ * against the turn's roots and decides what is outside them or protected.
24
+ */
25
+ import { unwrapReexecChain } from './reexec-wrapper.js';
26
+ import { basename, lexShellCommandLine, } from './shell-lexer.js';
27
+ const EXEC_FLAGS = new Set(['-exec', '-execdir', '-ok', '-okdir']);
28
+ function invocationOf(words) {
29
+ if (words.length === 0)
30
+ return undefined;
31
+ const step = unwrapReexecChain(words);
32
+ if (!('rest' in step))
33
+ return undefined;
34
+ const [head, ...args] = step.rest;
35
+ if (head === undefined || head.expands)
36
+ return undefined;
37
+ return { program: basename(head.value), args };
38
+ }
39
+ /** Every program a line runs, and every redirection it carries. */
40
+ export function readShellLine(line, dialect) {
41
+ const lexed = lexShellCommandLine(line, { dialect });
42
+ const invocations = [];
43
+ for (const command of lexed.commands) {
44
+ const own = invocationOf(command.words.slice(command.assignments));
45
+ if (own === undefined)
46
+ continue;
47
+ invocations.push(own);
48
+ if (own.program !== 'find')
49
+ continue;
50
+ // `find … -exec CMD … ;` runs CMD on each match; its arguments up to the
51
+ // terminator are CMD's.
52
+ for (let i = 0; i < own.args.length; i += 1) {
53
+ const flag = own.args[i];
54
+ if (flag.expands || !EXEC_FLAGS.has(flag.value))
55
+ continue;
56
+ const clause = [];
57
+ for (let j = i + 1; j < own.args.length; j += 1) {
58
+ const word = own.args[j];
59
+ if (!word.expands && (word.value === ';' || word.value === '+'))
60
+ break;
61
+ clause.push(word);
62
+ }
63
+ const nested = invocationOf(clause);
64
+ if (nested !== undefined)
65
+ invocations.push(nested);
66
+ }
67
+ }
68
+ return {
69
+ invocations,
70
+ redirections: lexed.redirections,
71
+ complete: lexed.complete,
72
+ };
73
+ }
74
+ /** Devices a command may name without it being a file. */
75
+ const HARMLESS_TARGETS = new Set([
76
+ '/dev/null',
77
+ '/dev/stdin',
78
+ '/dev/stdout',
79
+ '/dev/stderr',
80
+ '/dev/tty',
81
+ ]);
82
+ function isHarmlessTarget(path) {
83
+ return (HARMLESS_TARGETS.has(path) ||
84
+ /^\/dev\/fd\/\d+$/.test(path) ||
85
+ /^\/proc\/self\/fd\/[0-2]$/.test(path));
86
+ }
87
+ /** Whether a word's value still holds an expansion the shell will perform. */
88
+ export function expandsAtRuntime(word) {
89
+ return word.expands && (/[$`]/.test(word.value) || word.substitutes);
90
+ }
91
+ /** Arguments that are not flags: everything after `--`, and everything from the first operand on. */
92
+ function operands(args) {
93
+ const out = [];
94
+ let afterDashes = false;
95
+ let started = false;
96
+ for (const arg of args) {
97
+ if (afterDashes || started)
98
+ out.push(arg);
99
+ else if (arg.value === '--')
100
+ afterDashes = true;
101
+ else if (arg.value === '-' || !arg.value.startsWith('-')) {
102
+ out.push(arg);
103
+ started = true;
104
+ }
105
+ }
106
+ return out;
107
+ }
108
+ /** Operands of a command whose flags are known: an unknown flag stops flag parsing, as in the reference. */
109
+ function operandsByTable(table) {
110
+ const kind = (flag) => {
111
+ if (flag.startsWith('--')) {
112
+ if (flag.includes('='))
113
+ return 'attached';
114
+ if (table.booleanLong.has(flag))
115
+ return 'boolean';
116
+ if (table.attachedLong?.has(flag))
117
+ return 'attached';
118
+ return table.valuedLong.has(flag) ? 'valued' : 'unknown';
119
+ }
120
+ if (/^-\d+$/.test(flag))
121
+ return 'attached';
122
+ for (let i = 1; i < flag.length; i += 1) {
123
+ const letter = flag[i];
124
+ if (table.booleanShort.includes(letter))
125
+ continue;
126
+ if (table.attachedShort?.includes(letter))
127
+ return 'attached';
128
+ if (!table.valuedShort.includes(letter))
129
+ return 'unknown';
130
+ return i === flag.length - 1 ? 'valued' : 'attached';
131
+ }
132
+ return 'boolean';
133
+ };
134
+ return (args) => {
135
+ const out = [];
136
+ let afterDashes = false;
137
+ let started = false;
138
+ let parsing = true;
139
+ for (let i = 0; i < args.length; i += 1) {
140
+ const arg = args[i];
141
+ if (afterDashes || started)
142
+ out.push(arg);
143
+ else if (arg.value === '--')
144
+ afterDashes = true;
145
+ else if (arg.value !== '-' && arg.value.startsWith('-')) {
146
+ if (!parsing)
147
+ continue;
148
+ const k = kind(arg.value);
149
+ if (k === 'valued')
150
+ i += 1;
151
+ else if (k === 'unknown')
152
+ parsing = false;
153
+ }
154
+ else {
155
+ out.push(arg);
156
+ started = true;
157
+ }
158
+ }
159
+ return out;
160
+ };
161
+ }
162
+ const set = (...names) => new Set(names);
163
+ /** Operands of `grep`-family and `rg`: the first operand is the pattern unless `-e`/`-f` gave one. */
164
+ function patternThenFiles(valued, fallback = []) {
165
+ const patternFlags = ['-e', '--regexp', '-f', '--file'];
166
+ const fileFlags = ['-f', '--file'];
167
+ const attachedValue = (flag, names) => {
168
+ if (!flag.startsWith('-'))
169
+ return undefined;
170
+ const eq = flag.indexOf('=');
171
+ if (eq >= 0)
172
+ return names.includes(flag.slice(0, eq)) ? flag.slice(eq + 1) : undefined;
173
+ for (const name of names) {
174
+ if (name.length === 2 && name[0] === '-' && flag.startsWith(name) && flag !== name) {
175
+ return flag.slice(2);
176
+ }
177
+ }
178
+ return undefined;
179
+ };
180
+ return (args) => {
181
+ const out = [];
182
+ let patternGiven = false;
183
+ let afterDashes = false;
184
+ let started = false;
185
+ const take = (value) => {
186
+ if (value)
187
+ out.push(word(value));
188
+ };
189
+ for (let i = 0; i < args.length; i += 1) {
190
+ const arg = args[i];
191
+ const text = arg.value;
192
+ if (!afterDashes && !started && text === '--') {
193
+ afterDashes = true;
194
+ continue;
195
+ }
196
+ if (!afterDashes && !started && text !== '-' && text.startsWith('-')) {
197
+ const eq = text.indexOf('=');
198
+ const name = eq >= 0 ? text.slice(0, eq) : text;
199
+ if (patternFlags.includes(name)) {
200
+ patternGiven = true;
201
+ if (name === '-f' || name === '--file') {
202
+ take(eq >= 0 ? text.slice(eq + 1) : args[i + 1]?.value);
203
+ }
204
+ }
205
+ if (/^-[a-zA-Z]*f$/.test(name) && name !== '-f' && eq < 0 && args[i + 1] !== undefined) {
206
+ patternGiven = true;
207
+ take(args[i + 1]?.value);
208
+ i += 1;
209
+ continue;
210
+ }
211
+ if (['--exclude-from', '--include-from', '--ignore-file'].includes(name)) {
212
+ take(eq >= 0 ? text.slice(eq + 1) : args[i + 1]?.value);
213
+ if (eq < 0)
214
+ i += 1;
215
+ continue;
216
+ }
217
+ if (eq < 0) {
218
+ const attachedFile = attachedValue(text, fileFlags);
219
+ if (attachedFile !== undefined) {
220
+ patternGiven = true;
221
+ take(attachedFile);
222
+ continue;
223
+ }
224
+ if (text.length > 2 && text.startsWith('-e')) {
225
+ patternGiven = true;
226
+ continue;
227
+ }
228
+ }
229
+ if (valued.has(name) && eq < 0)
230
+ i += 1;
231
+ continue;
232
+ }
233
+ if (started && !afterDashes) {
234
+ const attachedFile = attachedValue(text, fileFlags);
235
+ if (attachedFile !== undefined)
236
+ take(attachedFile);
237
+ }
238
+ started = true;
239
+ if (!patternGiven) {
240
+ patternGiven = true;
241
+ continue;
242
+ }
243
+ out.push(arg);
244
+ }
245
+ return out.length > 0 ? out : fallback.map(word);
246
+ };
247
+ }
248
+ /** A synthetic word for a path the extractor derived rather than read. */
249
+ function word(value) {
250
+ return {
251
+ text: value,
252
+ value,
253
+ expands: false,
254
+ quoted: false,
255
+ substitutes: false,
256
+ };
257
+ }
258
+ const grepOperands = (args) => {
259
+ const found = patternThenFiles(set('-e', '--regexp', '-f', '--file', '--exclude', '--include', '--exclude-dir', '--include-dir', '-m', '--max-count', '-A', '--after-context', '-B', '--before-context', '-C', '--context'))(args);
260
+ if (found.length === 0 && args.some((a) => ['-r', '-R', '--recursive'].includes(a.value))) {
261
+ return [word('.')];
262
+ }
263
+ return found;
264
+ };
265
+ const rgOperands = patternThenFiles(set('-e', '--regexp', '-f', '--file', '-t', '--type', '-T', '--type-not', '-g', '--glob', '-m', '--max-count', '--max-depth', '-r', '--replace', '-A', '--after-context', '-B', '--before-context', '-C', '--context'), ['.']);
266
+ function awkOperands(args) {
267
+ const valued = set('-F', '--field-separator', '-v', '--assign', '-e', '--source');
268
+ const files = ['-f', '--file', '-E', '--exec'];
269
+ const out = [];
270
+ let afterDashes = false;
271
+ let started = false;
272
+ let programGiven = false;
273
+ for (let i = 0; i < args.length; i += 1) {
274
+ const arg = args[i];
275
+ const text = arg.value;
276
+ if (!afterDashes && !started && text === '--') {
277
+ afterDashes = true;
278
+ continue;
279
+ }
280
+ if (!afterDashes && !started && text !== '-' && text.startsWith('-')) {
281
+ const eq = text.indexOf('=');
282
+ const name = eq >= 0 ? text.slice(0, eq) : text;
283
+ if (valued.has(name)) {
284
+ if (name === '-e' || name === '--source')
285
+ programGiven = true;
286
+ if (eq < 0)
287
+ i += 1;
288
+ continue;
289
+ }
290
+ if (files.includes(name)) {
291
+ programGiven = true;
292
+ if (eq >= 0)
293
+ out.push(word(text.slice(eq + 1)));
294
+ else if (args[i + 1] !== undefined) {
295
+ out.push(args[i + 1]);
296
+ i += 1;
297
+ }
298
+ continue;
299
+ }
300
+ continue;
301
+ }
302
+ started = true;
303
+ if (!programGiven) {
304
+ programGiven = true;
305
+ continue;
306
+ }
307
+ out.push(arg);
308
+ }
309
+ return out;
310
+ }
311
+ function sedOperands(args) {
312
+ const out = [];
313
+ let skipNext = false;
314
+ let scriptGiven = false;
315
+ let afterDashes = false;
316
+ let started = false;
317
+ for (let i = 0; i < args.length; i += 1) {
318
+ if (skipNext) {
319
+ skipNext = false;
320
+ continue;
321
+ }
322
+ const arg = args[i];
323
+ const text = arg.value;
324
+ if (!afterDashes && !started && text === '--') {
325
+ afterDashes = true;
326
+ continue;
327
+ }
328
+ if (!afterDashes && !started && text !== '-' && text.startsWith('-')) {
329
+ if (text === '-f' || text === '--file') {
330
+ const next = args[i + 1];
331
+ if (next !== undefined)
332
+ out.push(next);
333
+ skipNext = true;
334
+ scriptGiven = true;
335
+ }
336
+ else if (text === '-e' || text === '--expression') {
337
+ skipNext = true;
338
+ scriptGiven = true;
339
+ }
340
+ else if (!text.startsWith('--') && (text.includes('e') || text.includes('f'))) {
341
+ scriptGiven = true;
342
+ }
343
+ continue;
344
+ }
345
+ started = true;
346
+ if (!scriptGiven) {
347
+ scriptGiven = true;
348
+ continue;
349
+ }
350
+ out.push(arg);
351
+ }
352
+ return out;
353
+ }
354
+ function findOperands(args) {
355
+ const out = [];
356
+ const takesPath = new Set([
357
+ '-newer',
358
+ '-anewer',
359
+ '-cnewer',
360
+ '-mnewer',
361
+ '-samefile',
362
+ '-path',
363
+ '-wholename',
364
+ '-ilname',
365
+ '-lname',
366
+ '-ipath',
367
+ '-iwholename',
368
+ ]);
369
+ let expressionStarted = false;
370
+ let afterDashes = false;
371
+ for (let i = 0; i < args.length; i += 1) {
372
+ const arg = args[i];
373
+ if (!arg.value)
374
+ continue;
375
+ if (afterDashes) {
376
+ out.push(arg);
377
+ continue;
378
+ }
379
+ if (arg.value === '--') {
380
+ afterDashes = true;
381
+ continue;
382
+ }
383
+ if (arg.value.startsWith('-')) {
384
+ if (['-H', '-L', '-P'].includes(arg.value))
385
+ continue;
386
+ expressionStarted = true;
387
+ if (takesPath.has(arg.value) || /^-newer[acmBt][acmtB]$/.test(arg.value)) {
388
+ const next = args[i + 1];
389
+ if (next?.value) {
390
+ out.push(next);
391
+ i += 1;
392
+ }
393
+ }
394
+ continue;
395
+ }
396
+ if (!expressionStarted)
397
+ out.push(arg);
398
+ }
399
+ return out.length > 0 ? out : [word('.')];
400
+ }
401
+ function gitOperands(args) {
402
+ const valuedGlobals = new Set([
403
+ '-C',
404
+ '-c',
405
+ '--git-dir',
406
+ '--work-tree',
407
+ '--namespace',
408
+ '--super-prefix',
409
+ '--config-env',
410
+ '--attr-source',
411
+ '--shallow-file',
412
+ ]);
413
+ let index = 0;
414
+ let base = '';
415
+ const join = (value) => base === '' ? value : `${base.replace(/\/+$/, '')}/${value}`;
416
+ const absolute = (value) => value.startsWith('/') || value.startsWith('~');
417
+ const setBase = (value) => {
418
+ base = absolute(value) ? value : join(value);
419
+ };
420
+ while (index < args.length && args[index].value.startsWith('-')) {
421
+ const flag = args[index].value;
422
+ index += 1;
423
+ if (valuedGlobals.has(flag) && index < args.length) {
424
+ const value = args[index].value;
425
+ if (flag === '-C' || flag === '--work-tree')
426
+ setBase(value);
427
+ index += 1;
428
+ }
429
+ else if (flag.startsWith('--work-tree=')) {
430
+ setBase(flag.slice('--work-tree='.length));
431
+ }
432
+ }
433
+ const sub = args[index]?.value;
434
+ const rest = args.slice(index + 1);
435
+ const place = (value) => (base === '' || absolute(value) ? value : join(value));
436
+ if (sub === 'grep') {
437
+ const files = patternThenFiles(set('-e', '--regexp', '-f', '--file', '-A', '--after-context', '-B', '--before-context', '-C', '--context', '-m', '--max-count', '--max-depth', '--threads'))(rest);
438
+ return files.length > 0
439
+ ? files.map((f) => word(place(f.value)))
440
+ : [word(base === '' ? '.' : base)];
441
+ }
442
+ if (sub !== 'diff')
443
+ return [];
444
+ const out = [];
445
+ let afterDashes = false;
446
+ for (const arg of rest) {
447
+ if (!afterDashes && arg.value === '--')
448
+ afterDashes = true;
449
+ else if (afterDashes || arg.value === '-' || !arg.value.startsWith('-')) {
450
+ const path = place(arg.value);
451
+ if (!isHarmlessTarget(path))
452
+ out.push(word(path));
453
+ }
454
+ }
455
+ return out;
456
+ }
457
+ function manOperands(args) {
458
+ const local = args.some((a) => a.value === '--local-file' || (/^-[^-]/.test(a.value) && a.value.includes('l')));
459
+ const out = [];
460
+ args.forEach((arg, i) => {
461
+ const previous = args[i - 1]?.value;
462
+ if (i > 0 && (previous === '-C' || previous === '--config-file')) {
463
+ out.push(arg);
464
+ return;
465
+ }
466
+ const text = arg.value;
467
+ const found = [];
468
+ if (!text.startsWith('-'))
469
+ found.push(text);
470
+ else {
471
+ if (text.includes('='))
472
+ found.push(text.slice(text.indexOf('=') + 1));
473
+ if (text.length > 2 && !text.startsWith('--'))
474
+ found.push(text.slice(2));
475
+ const cut = text.search(/[\\/~]/);
476
+ if (cut > 0)
477
+ found.push(text.slice(cut));
478
+ }
479
+ for (const value of new Set(found)) {
480
+ if (value !== '' &&
481
+ (local || /[\\/]/.test(value) || value.startsWith('~') || value.startsWith('.'))) {
482
+ out.push(word(value));
483
+ }
484
+ }
485
+ });
486
+ return out;
487
+ }
488
+ function jqOperands(args) {
489
+ const valued = set('-e', '--expression', '--arg', '--argjson', '--args', '--jsonargs', '-L', '--library-path', '--indent', '--tab');
490
+ const out = [];
491
+ let afterDashes = false;
492
+ let filterGiven = false;
493
+ for (let i = 0; i < args.length; i += 1) {
494
+ const arg = args[i];
495
+ const text = arg.value;
496
+ if (!afterDashes && text === '--') {
497
+ afterDashes = true;
498
+ continue;
499
+ }
500
+ if (!afterDashes && text.startsWith('-')) {
501
+ const eq = text.indexOf('=');
502
+ const name = eq >= 0 ? text.slice(0, eq) : text;
503
+ if (name === '-e' || name === '--expression')
504
+ filterGiven = true;
505
+ if (name === '-f' || name === '--from-file') {
506
+ filterGiven = true;
507
+ if (eq >= 0)
508
+ out.push(word(text.slice(eq + 1)));
509
+ else if (args[i + 1] !== undefined) {
510
+ out.push(args[i + 1]);
511
+ i += 1;
512
+ }
513
+ continue;
514
+ }
515
+ if (name === '--slurpfile' || name === '--rawfile') {
516
+ const file = args[i + 2];
517
+ if (file !== undefined)
518
+ out.push(file);
519
+ i += 2;
520
+ continue;
521
+ }
522
+ if (valued.has(name) && eq < 0)
523
+ i += 1;
524
+ continue;
525
+ }
526
+ if (!filterGiven) {
527
+ filterGiven = true;
528
+ continue;
529
+ }
530
+ out.push(arg);
531
+ }
532
+ return out;
533
+ }
534
+ const trOperands = (args) => {
535
+ const deleting = args.some((a) => a.value === '-d' ||
536
+ a.value === '--delete' ||
537
+ (a.value.startsWith('-') && a.value.includes('d')));
538
+ return operands(args).slice(deleting ? 1 : 2);
539
+ };
540
+ const teeOperands = (args) => operands(args).filter((a) => !isHarmlessTarget(a.value));
541
+ const cdOperands = (args) => {
542
+ const found = operands(args);
543
+ if (found.length === 0)
544
+ return args[args.length - 1]?.value === '-' ? [word('-')] : [word('~')];
545
+ return [found[0]];
546
+ };
547
+ const lsOperands = (args) => {
548
+ const found = operands(args);
549
+ return found.length > 0 ? found : [word('.')];
550
+ };
551
+ const table = (booleanShort, valuedShort, booleanLong, valuedLong, attachedShort, attachedLong) => ({
552
+ booleanShort,
553
+ valuedShort,
554
+ booleanLong,
555
+ valuedLong,
556
+ attachedShort,
557
+ attachedLong,
558
+ });
559
+ const EXTRACTORS = {
560
+ cd: cdOperands,
561
+ ls: lsOperands,
562
+ find: findOperands,
563
+ mkdir: operands,
564
+ touch: operands,
565
+ rm: operands,
566
+ rmdir: operands,
567
+ mv: operands,
568
+ cp: operands,
569
+ cat: operands,
570
+ head: operands,
571
+ tail: operands,
572
+ sort: operands,
573
+ uniq: operands,
574
+ wc: operands,
575
+ cut: operandsByTable(table('nswz', 'bcdf', set('--complement', '--only-delimited', '--zero-terminated'), set('--bytes', '--characters', '--delimiter', '--fields', '--output-delimiter'))),
576
+ paste: operandsByTable(table('sz', 'd', set('--serial', '--zero-terminated'), set('--delimiters'))),
577
+ column: operandsByTable(table('txdemLJhV', 'cosNOClEHRTWrip', set('--table', '--fillrows', '--table-noheadings', '--table-header-repeat', '--table-maxout', '--keep-empty-lines', '--json'), set('--separator', '--output-separator', '--output-width', '--table-name', '--table-order', '--table-column', '--table-columns', '--table-columns-limit', '--table-noextreme', '--table-hide', '--table-right', '--table-truncate', '--table-wrap', '--tree', '--tree-id', '--tree-parent'))),
578
+ file: operands,
579
+ stat: operands,
580
+ diff: operands,
581
+ awk: awkOperands,
582
+ gawk: awkOperands,
583
+ mawk: awkOperands,
584
+ nawk: awkOperands,
585
+ strings: operands,
586
+ hexdump: operands,
587
+ od: operands,
588
+ base64: operands,
589
+ nl: operands,
590
+ sha256sum: operands,
591
+ sha1sum: operands,
592
+ md5sum: operands,
593
+ tee: teeOperands,
594
+ tr: trOperands,
595
+ grep: grepOperands,
596
+ egrep: grepOperands,
597
+ fgrep: grepOperands,
598
+ tac: operandsByTable(table('br', 's', set('--before', '--regex'), set('--separator'))),
599
+ rev: operands,
600
+ fold: operandsByTable(table('bs', 'w', set('--bytes', '--spaces'), set('--width'))),
601
+ expand: operandsByTable(table('i', 't', set('--initial'), set('--tabs'))),
602
+ unexpand: operandsByTable(table('af', 't', set('--all', '--first-only'), set('--tabs'))),
603
+ fmt: operandsByTable(table('csumn', 'wgdl', set('--crown-margin', '--split-only', '--tagged-paragraph', '--uniform-spacing'), set('--width', '--goal', '--prefix'))),
604
+ comm: operandsByTable(table('123iz', '', set('--check-order', '--nocheck-order', '--total', '--zero-terminated'), set('--output-delimiter'))),
605
+ cmp: operandsByTable(table('blsvxzh', '', set('--print-bytes', '--verbose', '--quiet', '--silent'), set('--ignore-initial', '--bytes'))),
606
+ pr: operandsByTable(table('acdFfJmprtTv', 'hlwWoND', set('--across', '--show-control-chars', '--double-space', '--form-feed', '--join-lines', '--merge', '--no-file-warnings', '--omit-header', '--omit-pagination', '--show-nonprinting'), set('--header', '--length', '--width', '--page-width', '--indent', '--first-line-number', '--date-format', '--columns'), 'einsS', set('--expand-tabs', '--output-tabs', '--number-lines', '--separator', '--sep-string'))),
607
+ numfmt: operandsByTable(table('z', 'd', set('--grouping', '--zero-terminated', '--debug'), set('--from', '--to', '--from-unit', '--to-unit', '--format', '--padding', '--delimiter', '--field', '--round', '--suffix', '--invalid'), undefined, set('--header'))),
608
+ tsort: operands,
609
+ man: manOperands,
610
+ rg: rgOperands,
611
+ sed: sedOperands,
612
+ jq: jqOperands,
613
+ git: gitOperands,
614
+ };
615
+ /** Commands that create or change what their operands name. `sed` is added per call when it edits in place. */
616
+ const WRITERS = new Set(['mkdir', 'touch', 'rm', 'rmdir', 'mv', 'cp', 'tee']);
617
+ const CD_PROGRAMS = new Set(['cd', 'pushd', 'popd', 'chdir']);
618
+ /** `sed -i`, `-i.bak`, `-ni`, `--in-place[=SUFFIX]`: the script's output replaces the file. */
619
+ function editsInPlace(args) {
620
+ return args.some((a) => {
621
+ const text = a.value;
622
+ if (text === '--')
623
+ return false;
624
+ if (text.startsWith('--'))
625
+ return text === '--in-place' || text.startsWith('--in-place=');
626
+ return /^-[A-Za-z]*i/.test(text);
627
+ });
628
+ }
629
+ /**
630
+ * The paths `reading` names: positional arguments of the commands in the
631
+ * table, and the targets of its redirections.
632
+ */
633
+ export function shellPathAccess(reading) {
634
+ const uses = [];
635
+ let changesDirectory = false;
636
+ for (const { program, args } of reading.invocations) {
637
+ if (CD_PROGRAMS.has(program))
638
+ changesDirectory = true;
639
+ const extract = EXTRACTORS[program];
640
+ if (extract === undefined)
641
+ continue;
642
+ const access = WRITERS.has(program) || (program === 'sed' && editsInPlace(args)) ? 'write' : 'read';
643
+ for (const arg of extract(args)) {
644
+ if (arg.value === '' || isHarmlessTarget(arg.value))
645
+ continue;
646
+ uses.push({
647
+ path: arg.value,
648
+ access,
649
+ via: program,
650
+ unresolved: expandsAtRuntime(arg),
651
+ });
652
+ }
653
+ }
654
+ for (const redirection of reading.redirections) {
655
+ const target = redirection.target;
656
+ if (target.value === '' || isHarmlessTarget(target.value))
657
+ continue;
658
+ switch (redirection.operator) {
659
+ case '>':
660
+ case '>>':
661
+ case '>|':
662
+ case '&>':
663
+ case '&>>':
664
+ case '<>':
665
+ uses.push({
666
+ path: target.value,
667
+ access: 'write',
668
+ via: 'redirect',
669
+ unresolved: expandsAtRuntime(target),
670
+ });
671
+ break;
672
+ case '>&':
673
+ // `>&2` and `>&-` duplicate or close a descriptor; any other word is a file.
674
+ if (!/^(?:\d+-?|-)$/.test(target.value)) {
675
+ uses.push({
676
+ path: target.value,
677
+ access: 'write',
678
+ via: 'redirect',
679
+ unresolved: expandsAtRuntime(target),
680
+ });
681
+ }
682
+ break;
683
+ case '<':
684
+ uses.push({
685
+ path: target.value,
686
+ access: 'read',
687
+ via: 'redirect',
688
+ unresolved: expandsAtRuntime(target),
689
+ });
690
+ break;
691
+ default:
692
+ break;
693
+ }
694
+ }
695
+ return { uses, changesDirectory };
696
+ }
697
+ //# sourceMappingURL=shell-paths.js.map