@namzu/sdk 69.4.0 → 71.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/dist/authorization/bare-repository.d.ts +21 -0
  3. package/dist/authorization/bare-repository.d.ts.map +1 -0
  4. package/dist/authorization/bare-repository.js +62 -0
  5. package/dist/authorization/bare-repository.js.map +1 -0
  6. package/dist/authorization/command-line.d.ts.map +1 -1
  7. package/dist/authorization/command-line.js +10 -3
  8. package/dist/authorization/command-line.js.map +1 -1
  9. package/dist/authorization/gate.d.ts +7 -0
  10. package/dist/authorization/gate.d.ts.map +1 -1
  11. package/dist/authorization/gate.js +4 -0
  12. package/dist/authorization/gate.js.map +1 -1
  13. package/dist/authorization/protected-paths.d.ts +24 -6
  14. package/dist/authorization/protected-paths.d.ts.map +1 -1
  15. package/dist/authorization/protected-paths.js +83 -10
  16. package/dist/authorization/protected-paths.js.map +1 -1
  17. package/dist/authorization/readonly-commands.d.ts +17 -5
  18. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  19. package/dist/authorization/readonly-commands.js +77 -6
  20. package/dist/authorization/readonly-commands.js.map +1 -1
  21. package/dist/authorization/readonly-flags.d.ts.map +1 -1
  22. package/dist/authorization/readonly-flags.js +98 -0
  23. package/dist/authorization/readonly-flags.js.map +1 -1
  24. package/dist/authorization/shell-lexer.d.ts +15 -0
  25. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  26. package/dist/authorization/shell-lexer.js +370 -2
  27. package/dist/authorization/shell-lexer.js.map +1 -1
  28. package/dist/authorization/shell-paths.d.ts.map +1 -1
  29. package/dist/authorization/shell-paths.js +276 -0
  30. package/dist/authorization/shell-paths.js.map +1 -1
  31. package/dist/authorization/shell-session-state.d.ts +47 -0
  32. package/dist/authorization/shell-session-state.d.ts.map +1 -0
  33. package/dist/authorization/shell-session-state.js +70 -0
  34. package/dist/authorization/shell-session-state.js.map +1 -0
  35. package/dist/authorization/shell-session.d.ts +9 -0
  36. package/dist/authorization/shell-session.d.ts.map +1 -0
  37. package/dist/authorization/shell-session.js +19 -0
  38. package/dist/authorization/shell-session.js.map +1 -0
  39. package/dist/authorization/skill-grant.d.ts.map +1 -1
  40. package/dist/authorization/skill-grant.js +1 -0
  41. package/dist/authorization/skill-grant.js.map +1 -1
  42. package/dist/compaction/extractor.d.ts.map +1 -1
  43. package/dist/compaction/extractor.js +2 -0
  44. package/dist/compaction/extractor.js.map +1 -1
  45. package/dist/compaction/hooks.d.ts +16 -0
  46. package/dist/compaction/hooks.d.ts.map +1 -1
  47. package/dist/compaction/hooks.js +26 -1
  48. package/dist/compaction/hooks.js.map +1 -1
  49. package/dist/compaction/manual.d.ts.map +1 -1
  50. package/dist/compaction/manual.js +6 -1
  51. package/dist/compaction/manual.js.map +1 -1
  52. package/dist/compaction/restore.d.ts.map +1 -1
  53. package/dist/compaction/restore.js +3 -2
  54. package/dist/compaction/restore.js.map +1 -1
  55. package/dist/config/runtime.d.ts +2 -0
  56. package/dist/config/runtime.d.ts.map +1 -1
  57. package/dist/config/runtime.js +7 -0
  58. package/dist/config/runtime.js.map +1 -1
  59. package/dist/connector/mcp/client.d.ts +7 -0
  60. package/dist/connector/mcp/client.d.ts.map +1 -1
  61. package/dist/connector/mcp/client.js +54 -4
  62. package/dist/connector/mcp/client.js.map +1 -1
  63. package/dist/connector/web/guarded-fetch.d.ts +30 -0
  64. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  65. package/dist/connector/web/guarded-fetch.js +85 -0
  66. package/dist/connector/web/guarded-fetch.js.map +1 -1
  67. package/dist/connector/web/index.d.ts +1 -1
  68. package/dist/connector/web/index.d.ts.map +1 -1
  69. package/dist/connector/web/index.js +1 -1
  70. package/dist/connector/web/index.js.map +1 -1
  71. package/dist/connector/web/types.d.ts +8 -0
  72. package/dist/connector/web/types.d.ts.map +1 -1
  73. package/dist/constants/compaction/index.d.ts.map +1 -1
  74. package/dist/constants/compaction/index.js +1 -1
  75. package/dist/constants/compaction/index.js.map +1 -1
  76. package/dist/execution/code-runtime/worker-program.d.ts +1 -1
  77. package/dist/execution/code-runtime/worker-program.d.ts.map +1 -1
  78. package/dist/execution/code-runtime/worker-program.js +9 -5
  79. package/dist/execution/code-runtime/worker-program.js.map +1 -1
  80. package/dist/execution/local.d.ts.map +1 -1
  81. package/dist/execution/local.js +6 -1
  82. package/dist/execution/local.js.map +1 -1
  83. package/dist/peers/index.d.ts +2 -2
  84. package/dist/peers/index.d.ts.map +1 -1
  85. package/dist/peers/index.js +1 -1
  86. package/dist/peers/index.js.map +1 -1
  87. package/dist/peers/record.d.ts +74 -0
  88. package/dist/peers/record.d.ts.map +1 -1
  89. package/dist/peers/record.js +41 -1
  90. package/dist/peers/record.js.map +1 -1
  91. package/dist/peers/registry.d.ts.map +1 -1
  92. package/dist/peers/registry.js +20 -3
  93. package/dist/peers/registry.js.map +1 -1
  94. package/dist/plugin/bin-path.d.ts +41 -0
  95. package/dist/plugin/bin-path.d.ts.map +1 -0
  96. package/dist/plugin/bin-path.js +146 -0
  97. package/dist/plugin/bin-path.js.map +1 -0
  98. package/dist/plugin/common-layout/read.js +3 -3
  99. package/dist/plugin/common-layout/read.js.map +1 -1
  100. package/dist/plugin/common-layout-names.d.ts.map +1 -1
  101. package/dist/plugin/common-layout-names.js +0 -1
  102. package/dist/plugin/common-layout-names.js.map +1 -1
  103. package/dist/plugin/hook-module/capabilities.d.ts +12 -0
  104. package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
  105. package/dist/plugin/hook-module/capabilities.js +82 -10
  106. package/dist/plugin/hook-module/capabilities.js.map +1 -1
  107. package/dist/plugin/hook-module/consent.d.ts +11 -0
  108. package/dist/plugin/hook-module/consent.d.ts.map +1 -1
  109. package/dist/plugin/hook-module/consent.js +31 -0
  110. package/dist/plugin/hook-module/consent.js.map +1 -1
  111. package/dist/plugin/hook-module/host.d.ts.map +1 -1
  112. package/dist/plugin/hook-module/host.js +69 -23
  113. package/dist/plugin/hook-module/host.js.map +1 -1
  114. package/dist/plugin/hook-module/index.d.ts +1 -1
  115. package/dist/plugin/hook-module/index.d.ts.map +1 -1
  116. package/dist/plugin/hook-module/index.js +1 -1
  117. package/dist/plugin/hook-module/index.js.map +1 -1
  118. package/dist/plugin/hook-module/scan.d.ts +16 -0
  119. package/dist/plugin/hook-module/scan.d.ts.map +1 -1
  120. package/dist/plugin/hook-module/scan.js +68 -3
  121. package/dist/plugin/hook-module/scan.js.map +1 -1
  122. package/dist/plugin/hook-module/worker-source.d.ts +5 -4
  123. package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
  124. package/dist/plugin/hook-module/worker-source.js +254 -28
  125. package/dist/plugin/hook-module/worker-source.js.map +1 -1
  126. package/dist/plugin/lifecycle.d.ts +21 -0
  127. package/dist/plugin/lifecycle.d.ts.map +1 -1
  128. package/dist/plugin/lifecycle.js +64 -0
  129. package/dist/plugin/lifecycle.js.map +1 -1
  130. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  131. package/dist/plugin/shell-hook-tool-names.js +1 -0
  132. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  133. package/dist/plugin/shell-hook.d.ts +1 -1
  134. package/dist/plugin/shell-hook.d.ts.map +1 -1
  135. package/dist/plugin/shell-hook.js +22 -4
  136. package/dist/plugin/shell-hook.js.map +1 -1
  137. package/dist/public-runtime.d.ts +11 -9
  138. package/dist/public-runtime.d.ts.map +1 -1
  139. package/dist/public-runtime.js +11 -8
  140. package/dist/public-runtime.js.map +1 -1
  141. package/dist/public-tools.d.ts +7 -3
  142. package/dist/public-tools.d.ts.map +1 -1
  143. package/dist/public-tools.js +7 -3
  144. package/dist/public-tools.js.map +1 -1
  145. package/dist/public-types.d.ts +2 -2
  146. package/dist/public-types.d.ts.map +1 -1
  147. package/dist/runtime/jobs/monitor-stream.d.ts +9 -1
  148. package/dist/runtime/jobs/monitor-stream.d.ts.map +1 -1
  149. package/dist/runtime/jobs/monitor-stream.js +13 -4
  150. package/dist/runtime/jobs/monitor-stream.js.map +1 -1
  151. package/dist/runtime/jobs/registry.d.ts +4 -0
  152. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  153. package/dist/runtime/jobs/registry.js +12 -2
  154. package/dist/runtime/jobs/registry.js.map +1 -1
  155. package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -1
  156. package/dist/runtime/query/auto-review/git-status.js +3 -2
  157. package/dist/runtime/query/auto-review/git-status.js.map +1 -1
  158. package/dist/runtime/query/executor.d.ts +16 -6
  159. package/dist/runtime/query/executor.d.ts.map +1 -1
  160. package/dist/runtime/query/executor.js +135 -15
  161. package/dist/runtime/query/executor.js.map +1 -1
  162. package/dist/runtime/query/index.d.ts.map +1 -1
  163. package/dist/runtime/query/index.js +2 -2
  164. package/dist/runtime/query/index.js.map +1 -1
  165. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  166. package/dist/runtime/query/iteration/outstanding-work.js +14 -4
  167. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  168. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  169. package/dist/runtime/query/iteration/phases/compaction.js +11 -1
  170. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  171. package/dist/runtime/query/iteration/phases/tool-review.d.ts +2 -0
  172. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  173. package/dist/runtime/query/iteration/phases/tool-review.js +19 -8
  174. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  175. package/dist/runtime/query/path-escalation.d.ts +6 -0
  176. package/dist/runtime/query/path-escalation.d.ts.map +1 -1
  177. package/dist/runtime/query/path-escalation.js +58 -4
  178. package/dist/runtime/query/path-escalation.js.map +1 -1
  179. package/dist/runtime/query/review-policy.d.ts +21 -3
  180. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  181. package/dist/runtime/query/review-policy.js +39 -21
  182. package/dist/runtime/query/review-policy.js.map +1 -1
  183. package/dist/runtime/query/steering.d.ts +11 -2
  184. package/dist/runtime/query/steering.d.ts.map +1 -1
  185. package/dist/runtime/query/steering.js +18 -4
  186. package/dist/runtime/query/steering.js.map +1 -1
  187. package/dist/sandbox/provider/local.d.ts.map +1 -1
  188. package/dist/sandbox/provider/local.js +3 -1
  189. package/dist/sandbox/provider/local.js.map +1 -1
  190. package/dist/schedules/describe.d.ts.map +1 -1
  191. package/dist/schedules/describe.js +2 -0
  192. package/dist/schedules/describe.js.map +1 -1
  193. package/dist/schedules/evaluate.d.ts +4 -0
  194. package/dist/schedules/evaluate.d.ts.map +1 -1
  195. package/dist/schedules/evaluate.js +26 -1
  196. package/dist/schedules/evaluate.js.map +1 -1
  197. package/dist/schedules/index.d.ts +3 -1
  198. package/dist/schedules/index.d.ts.map +1 -1
  199. package/dist/schedules/index.js +2 -1
  200. package/dist/schedules/index.js.map +1 -1
  201. package/dist/schedules/next-fire.d.ts.map +1 -1
  202. package/dist/schedules/next-fire.js +10 -0
  203. package/dist/schedules/next-fire.js.map +1 -1
  204. package/dist/schedules/spec.d.ts +9 -0
  205. package/dist/schedules/spec.d.ts.map +1 -1
  206. package/dist/schedules/spec.js +33 -0
  207. package/dist/schedules/spec.js.map +1 -1
  208. package/dist/schedules/types.d.ts +32 -4
  209. package/dist/schedules/types.d.ts.map +1 -1
  210. package/dist/schedules/types.js +3 -2
  211. package/dist/schedules/types.js.map +1 -1
  212. package/dist/schedules/watch.d.ts +23 -0
  213. package/dist/schedules/watch.d.ts.map +1 -0
  214. package/dist/schedules/watch.js +46 -0
  215. package/dist/schedules/watch.js.map +1 -0
  216. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  217. package/dist/session/workspace/git-worktree.js +2 -1
  218. package/dist/session/workspace/git-worktree.js.map +1 -1
  219. package/dist/skills/arguments.d.ts +58 -0
  220. package/dist/skills/arguments.d.ts.map +1 -0
  221. package/dist/skills/arguments.js +208 -0
  222. package/dist/skills/arguments.js.map +1 -0
  223. package/dist/skills/index.d.ts +3 -1
  224. package/dist/skills/index.d.ts.map +1 -1
  225. package/dist/skills/index.js +1 -0
  226. package/dist/skills/index.js.map +1 -1
  227. package/dist/skills/inline-shell-host.d.ts +6 -0
  228. package/dist/skills/inline-shell-host.d.ts.map +1 -1
  229. package/dist/skills/inline-shell-host.js +8 -0
  230. package/dist/skills/inline-shell-host.js.map +1 -1
  231. package/dist/skills/inline-shell.d.ts +26 -1
  232. package/dist/skills/inline-shell.d.ts.map +1 -1
  233. package/dist/skills/inline-shell.js +1308 -22
  234. package/dist/skills/inline-shell.js.map +1 -1
  235. package/dist/tools/builtins/bash-cwd.d.ts.map +1 -1
  236. package/dist/tools/builtins/bash-cwd.js +2 -0
  237. package/dist/tools/builtins/bash-cwd.js.map +1 -1
  238. package/dist/tools/builtins/bash.d.ts.map +1 -1
  239. package/dist/tools/builtins/bash.js +79 -11
  240. package/dist/tools/builtins/bash.js.map +1 -1
  241. package/dist/tools/builtins/exit-semantics.d.ts +6 -0
  242. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  243. package/dist/tools/builtins/exit-semantics.js +10 -0
  244. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  245. package/dist/tools/builtins/glob.d.ts.map +1 -1
  246. package/dist/tools/builtins/glob.js +68 -13
  247. package/dist/tools/builtins/glob.js.map +1 -1
  248. package/dist/tools/builtins/grep.d.ts.map +1 -1
  249. package/dist/tools/builtins/grep.js +37 -12
  250. package/dist/tools/builtins/grep.js.map +1 -1
  251. package/dist/tools/builtins/index.d.ts +11 -0
  252. package/dist/tools/builtins/index.d.ts.map +1 -1
  253. package/dist/tools/builtins/index.js +14 -0
  254. package/dist/tools/builtins/index.js.map +1 -1
  255. package/dist/tools/builtins/job.js +1 -1
  256. package/dist/tools/builtins/job.js.map +1 -1
  257. package/dist/tools/builtins/monitor.d.ts +1 -1
  258. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  259. package/dist/tools/builtins/monitor.js +4 -2
  260. package/dist/tools/builtins/monitor.js.map +1 -1
  261. package/dist/tools/builtins/notebook-cells.d.ts +31 -0
  262. package/dist/tools/builtins/notebook-cells.d.ts.map +1 -0
  263. package/dist/tools/builtins/notebook-cells.js +160 -0
  264. package/dist/tools/builtins/notebook-cells.js.map +1 -0
  265. package/dist/tools/builtins/notebook-edit.d.ts +8 -0
  266. package/dist/tools/builtins/notebook-edit.d.ts.map +1 -0
  267. package/dist/tools/builtins/notebook-edit.js +249 -0
  268. package/dist/tools/builtins/notebook-edit.js.map +1 -0
  269. package/dist/tools/builtins/notebook-guard.d.ts.map +1 -1
  270. package/dist/tools/builtins/notebook-guard.js +2 -1
  271. package/dist/tools/builtins/notebook-guard.js.map +1 -1
  272. package/dist/tools/builtins/push-notification.d.ts +49 -0
  273. package/dist/tools/builtins/push-notification.d.ts.map +1 -0
  274. package/dist/tools/builtins/push-notification.js +107 -0
  275. package/dist/tools/builtins/push-notification.js.map +1 -0
  276. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  277. package/dist/tools/builtins/read-file.js +8 -3
  278. package/dist/tools/builtins/read-file.js.map +1 -1
  279. package/dist/tools/builtins/read-media.d.ts.map +1 -1
  280. package/dist/tools/builtins/read-media.js +2 -1
  281. package/dist/tools/builtins/read-media.js.map +1 -1
  282. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  283. package/dist/tools/builtins/read-render.js +5 -3
  284. package/dist/tools/builtins/read-render.js.map +1 -1
  285. package/dist/tools/builtins/search-support.d.ts +6 -4
  286. package/dist/tools/builtins/search-support.d.ts.map +1 -1
  287. package/dist/tools/builtins/search-support.js +15 -3
  288. package/dist/tools/builtins/search-support.js.map +1 -1
  289. package/dist/tools/builtins/skill.d.ts.map +1 -1
  290. package/dist/tools/builtins/skill.js +30 -8
  291. package/dist/tools/builtins/skill.js.map +1 -1
  292. package/dist/tools/builtins/sleep-guard.d.ts +20 -0
  293. package/dist/tools/builtins/sleep-guard.d.ts.map +1 -1
  294. package/dist/tools/builtins/sleep-guard.js +125 -1
  295. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  296. package/dist/tools/builtins/wait-for-job.js +1 -1
  297. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  298. package/dist/tools/builtins/web.d.ts +2 -0
  299. package/dist/tools/builtins/web.d.ts.map +1 -1
  300. package/dist/tools/builtins/web.js +97 -3
  301. package/dist/tools/builtins/web.js.map +1 -1
  302. package/dist/tools/command-shell.d.ts +50 -0
  303. package/dist/tools/command-shell.d.ts.map +1 -1
  304. package/dist/tools/command-shell.js +145 -0
  305. package/dist/tools/command-shell.js.map +1 -1
  306. package/dist/tools/env-scrub.d.ts +2 -0
  307. package/dist/tools/env-scrub.d.ts.map +1 -1
  308. package/dist/tools/env-scrub.js +15 -1
  309. package/dist/tools/env-scrub.js.map +1 -1
  310. package/dist/tools/git-config-env.d.ts +55 -0
  311. package/dist/tools/git-config-env.d.ts.map +1 -0
  312. package/dist/tools/git-config-env.js +130 -0
  313. package/dist/tools/git-config-env.js.map +1 -0
  314. package/dist/tools/schedules/schedule-tool.d.ts +7 -0
  315. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  316. package/dist/tools/schedules/schedule-tool.js +72 -3
  317. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  318. package/dist/tools/schedules/types.d.ts +38 -2
  319. package/dist/tools/schedules/types.d.ts.map +1 -1
  320. package/dist/types/connector/mcp.d.ts +24 -0
  321. package/dist/types/connector/mcp.d.ts.map +1 -1
  322. package/dist/types/message/index.d.ts +21 -1
  323. package/dist/types/message/index.d.ts.map +1 -1
  324. package/dist/types/message/index.js +37 -2
  325. package/dist/types/message/index.js.map +1 -1
  326. package/dist/types/permission/index.d.ts +11 -2
  327. package/dist/types/permission/index.d.ts.map +1 -1
  328. package/dist/types/permission/index.js +12 -2
  329. package/dist/types/permission/index.js.map +1 -1
  330. package/dist/types/plugin/index.d.ts +10 -2
  331. package/dist/types/plugin/index.d.ts.map +1 -1
  332. package/dist/types/plugin/index.js.map +1 -1
  333. package/dist/types/tool/index.d.ts +13 -0
  334. package/dist/types/tool/index.d.ts.map +1 -1
  335. package/dist/types/tool/index.js.map +1 -1
  336. package/dist/utils/plain-terminal-text.d.ts +21 -0
  337. package/dist/utils/plain-terminal-text.d.ts.map +1 -0
  338. package/dist/utils/plain-terminal-text.js +156 -0
  339. package/dist/utils/plain-terminal-text.js.map +1 -0
  340. package/package.json +1 -1
  341. package/src/authorization/bare-repository.ts +70 -0
  342. package/src/authorization/command-line.ts +18 -4
  343. package/src/authorization/gate.ts +11 -0
  344. package/src/authorization/protected-paths.ts +89 -10
  345. package/src/authorization/readonly-commands.ts +75 -6
  346. package/src/authorization/readonly-flags.ts +103 -0
  347. package/src/authorization/shell-lexer.ts +367 -2
  348. package/src/authorization/shell-paths.ts +386 -0
  349. package/src/authorization/shell-session-state.ts +97 -0
  350. package/src/authorization/shell-session.ts +23 -0
  351. package/src/authorization/skill-grant.ts +1 -0
  352. package/src/compaction/extractor.ts +1 -0
  353. package/src/compaction/hooks.ts +43 -1
  354. package/src/compaction/manual.ts +6 -0
  355. package/src/compaction/restore.ts +3 -2
  356. package/src/config/runtime.ts +7 -0
  357. package/src/connector/mcp/client.ts +61 -4
  358. package/src/connector/web/guarded-fetch.ts +92 -0
  359. package/src/connector/web/index.ts +6 -1
  360. package/src/connector/web/types.ts +8 -0
  361. package/src/constants/compaction/index.ts +1 -1
  362. package/src/execution/code-runtime/worker-program.ts +9 -5
  363. package/src/execution/local.ts +6 -1
  364. package/src/peers/index.ts +8 -2
  365. package/src/peers/record.ts +45 -1
  366. package/src/peers/registry.ts +21 -5
  367. package/src/plugin/bin-path.ts +149 -0
  368. package/src/plugin/common-layout/read.ts +3 -3
  369. package/src/plugin/common-layout-names.ts +0 -1
  370. package/src/plugin/hook-module/capabilities.ts +94 -10
  371. package/src/plugin/hook-module/consent.ts +36 -0
  372. package/src/plugin/hook-module/host.ts +72 -21
  373. package/src/plugin/hook-module/index.ts +2 -0
  374. package/src/plugin/hook-module/scan.ts +76 -4
  375. package/src/plugin/hook-module/worker-source.ts +255 -28
  376. package/src/plugin/lifecycle.ts +67 -0
  377. package/src/plugin/shell-hook-tool-names.ts +1 -0
  378. package/src/plugin/shell-hook.ts +23 -4
  379. package/src/public-runtime.ts +27 -0
  380. package/src/public-tools.ts +36 -2
  381. package/src/public-types.ts +3 -1
  382. package/src/runtime/jobs/monitor-stream.ts +18 -4
  383. package/src/runtime/jobs/registry.ts +22 -2
  384. package/src/runtime/query/auto-review/git-status.ts +3 -2
  385. package/src/runtime/query/executor.ts +153 -12
  386. package/src/runtime/query/index.ts +5 -2
  387. package/src/runtime/query/iteration/outstanding-work.ts +22 -4
  388. package/src/runtime/query/iteration/phases/compaction.ts +14 -1
  389. package/src/runtime/query/iteration/phases/tool-review.ts +24 -7
  390. package/src/runtime/query/path-escalation.ts +52 -4
  391. package/src/runtime/query/review-policy.ts +47 -15
  392. package/src/runtime/query/steering.ts +32 -4
  393. package/src/sandbox/provider/local.ts +3 -1
  394. package/src/schedules/describe.ts +2 -0
  395. package/src/schedules/evaluate.ts +29 -1
  396. package/src/schedules/index.ts +9 -1
  397. package/src/schedules/next-fire.ts +9 -0
  398. package/src/schedules/spec.ts +42 -0
  399. package/src/schedules/types.ts +33 -3
  400. package/src/schedules/watch.ts +71 -0
  401. package/src/session/workspace/git-worktree.ts +3 -1
  402. package/src/skills/arguments.ts +250 -0
  403. package/src/skills/index.ts +10 -0
  404. package/src/skills/inline-shell-host.ts +16 -0
  405. package/src/skills/inline-shell.ts +1358 -22
  406. package/src/tools/builtins/bash-cwd.ts +2 -0
  407. package/src/tools/builtins/bash.ts +93 -13
  408. package/src/tools/builtins/exit-semantics.ts +10 -0
  409. package/src/tools/builtins/glob.ts +79 -15
  410. package/src/tools/builtins/grep.ts +37 -10
  411. package/src/tools/builtins/index.ts +15 -0
  412. package/src/tools/builtins/job.ts +1 -1
  413. package/src/tools/builtins/monitor.ts +4 -2
  414. package/src/tools/builtins/notebook-cells.ts +196 -0
  415. package/src/tools/builtins/notebook-edit.ts +280 -0
  416. package/src/tools/builtins/notebook-guard.ts +2 -1
  417. package/src/tools/builtins/push-notification.ts +138 -0
  418. package/src/tools/builtins/read-file.ts +9 -3
  419. package/src/tools/builtins/read-media.ts +2 -1
  420. package/src/tools/builtins/read-render.ts +5 -3
  421. package/src/tools/builtins/search-support.ts +17 -3
  422. package/src/tools/builtins/skill.ts +29 -7
  423. package/src/tools/builtins/sleep-guard.ts +128 -1
  424. package/src/tools/builtins/wait-for-job.ts +1 -1
  425. package/src/tools/builtins/web.ts +100 -3
  426. package/src/tools/command-shell.ts +166 -0
  427. package/src/tools/env-scrub.ts +13 -1
  428. package/src/tools/git-config-env.ts +143 -0
  429. package/src/tools/schedules/schedule-tool.ts +79 -3
  430. package/src/tools/schedules/types.ts +47 -9
  431. package/src/types/connector/mcp.ts +25 -0
  432. package/src/types/message/index.ts +53 -1
  433. package/src/types/permission/index.ts +20 -3
  434. package/src/types/plugin/index.ts +10 -2
  435. package/src/types/tool/index.ts +13 -0
  436. package/src/utils/plain-terminal-text.ts +142 -0
@@ -1 +1 @@
1
- {"version":3,"file":"shell-lexer.d.ts","sourceRoot":"","sources":["../../src/authorization/shell-lexer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACzB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB;;;;;;OAMG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;CAC7B;AAED,6DAA6D;AAC7D,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,QAA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AAE,MAAM,GAAG,MAAM,CAG7C"}
@@ -114,6 +114,7 @@ const MAX_SHELL_DEPTH = 4;
114
114
  /** How deep compound commands and expansions may nest before it gives up. */
115
115
  const MAX_NESTING = 100;
116
116
  import { PLAIN_SHELL_NAMES, REEXEC_WRAPPER_NAMES, shellDashC, shellInvocation, unwrapReexecChain, } from './reexec-wrapper.js';
117
+ import { currentShellAttributes } from './shell-session-state.js';
117
118
  export function lexShellCommandLine(line, options = {}) {
118
119
  // CMD does not give single quotes or backslashes POSIX semantics.
119
120
  // A partial POSIX reading could approve commands it never saw.
@@ -125,9 +126,11 @@ export function lexShellCommandLine(line, options = {}) {
125
126
  opaque: true,
126
127
  complete: false,
127
128
  reasons: ['native CMD command parsing is unavailable'],
129
+ integerNames: [],
130
+ integerNamesUnknown: false,
128
131
  };
129
132
  }
130
- const context = new Context(line.length);
133
+ const context = new Context(line.length, options.attributes ?? currentShellAttributes());
131
134
  context.setDialect(line, options.dialect ?? 'bash');
132
135
  try {
133
136
  lexInto(line, context, 'line', 0);
@@ -145,9 +148,12 @@ export function lexShellCommandLine(line, options = {}) {
145
148
  opaque: context.reasons.size > 0,
146
149
  complete: context.complete,
147
150
  reasons: [...context.reasons],
151
+ integerNames: [...context.declaredNames],
152
+ integerNamesUnknown: context.declaredUnknown,
148
153
  };
149
154
  }
150
155
  class Context {
156
+ prior;
151
157
  commands = [];
152
158
  redirections = [];
153
159
  compoundWords = [];
@@ -159,12 +165,51 @@ class Context {
159
165
  * the lexer quadratic. Past the budget the line is opaque.
160
166
  */
161
167
  rescans;
162
- constructor(length) {
168
+ constructor(length, prior = undefined) {
169
+ this.prior = prior;
163
170
  this.rescans = 4 * length + 4096;
164
171
  }
172
+ /** Names this line gives the integer attribute to, and whether it may give it to more. */
173
+ declaredNames = new Set();
174
+ declaredUnknown = false;
175
+ /**
176
+ * A value that may hold a subscript or an expansion is stored into `name`.
177
+ * If an earlier line of the session gave `name` the integer attribute, or
178
+ * may have given it to any name, bash evaluates the value as arithmetic.
179
+ * `undefined` is a name the lexer cannot read.
180
+ */
181
+ storedInto(name) {
182
+ if (this.prior === undefined)
183
+ return;
184
+ if (this.prior.unknown || name === undefined || this.prior.integers.has(name))
185
+ this.opaque('arithmetic');
186
+ }
165
187
  opaque(reason) {
166
188
  this.reasons.add(reason);
167
189
  }
190
+ /**
191
+ * A name declared `-i` or `-n` evaluates what is later assigned to it as
192
+ * arithmetic, and an assigned value that holds a subscript runs the
193
+ * command inside it. The lexer keeps no variables, so when one line does
194
+ * both, in either order, it is opaque.
195
+ */
196
+ integerDeclared = false;
197
+ bracketSeen = false;
198
+ declaredArithmetic() {
199
+ this.integerDeclared = true;
200
+ if (this.bracketSeen)
201
+ this.opaque('arithmetic');
202
+ }
203
+ /**
204
+ * A value that may hold a subscript was stored: a literal one, an
205
+ * expanding one, or one a `read`, `mapfile`, `printf -v`, `getopts` or
206
+ * loop variable stores. The lexer cannot see what they hold.
207
+ */
208
+ bracketAssigned() {
209
+ this.bracketSeen = true;
210
+ if (this.integerDeclared)
211
+ this.opaque('arithmetic');
212
+ }
168
213
  dialects = new Map();
169
214
  /** The dialect a string is read in. A string read two ways gets the stricter. */
170
215
  setDialect(src, dialect) {
@@ -272,6 +317,35 @@ const RESERVED = new Set([
272
317
  const COMPOUND_AFTER = /^(?:\(|(?:\{|if|while|until|for|select|case|\[\[)(?=[\s;&|()<>]|$))/;
273
318
  /** Builtins whose arguments may be array assignments. */
274
319
  const ASSIGNMENT_BUILTINS = new Set(['declare', 'typeset', 'local', 'export', 'readonly']);
320
+ /** A `let` argument that evaluates nothing but numbers and an assignment of one. */
321
+ const PLAIN_ARITHMETIC = /^(?:[A-Za-z_][A-Za-z0-9_]*=)?[0-9\s+\-*/%()<>=!&|^~?:,]*$/;
322
+ /** A `declare -i` argument: a bare name, or a name given a plain number. */
323
+ /** A name word that carries a subscript, or one that expands into something that might. */
324
+ function subscriptOrExpands(word) {
325
+ return word.value.includes('[') || word.expands;
326
+ }
327
+ /** A subscript beside something that expands, quoted or not: `a[$(cmd)]`. */
328
+ function subscriptWithExpansion(word) {
329
+ return word.value.includes('[') && (word.expands || /[$`]/.test(word.value));
330
+ }
331
+ /** The variable a `NAME`, `NAME[sub]` or `NAME+` operand stores into; undefined when it is not a plain name. */
332
+ function plainName(text) {
333
+ const match = /^([A-Za-z_][A-Za-z0-9_]*)(?:\[.*\])?\+?$/s.exec(text);
334
+ return match === null ? undefined : match[1];
335
+ }
336
+ /**
337
+ * Text with a letter or underscore in it. Stored into an integer name, a bare
338
+ * word like that is read as a variable and its value evaluated again, so
339
+ * `x=y` runs what an earlier call stored in `y`.
340
+ */
341
+ const NAMES_A_VARIABLE = /[A-Za-z_]/;
342
+ /** `NAME=`, `NAME+=` or `NAME[sub]=` at the start of a word. */
343
+ const ASSIGNMENT_NAME = /^([A-Za-z_][A-Za-z0-9_]*)(?:\[[^\]]*\])?\+?=/;
344
+ /** A parameter expansion that assigns: `${NAME:=word}`, `${NAME=word}`. */
345
+ const ASSIGNING_EXPANSION = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?:\[[^\]]*\])?:?=/g;
346
+ /** Text that hands a name the integer or name-reference attribute when read as a line. */
347
+ const DECLARES_INTEGER = /\b(?:declare|typeset|local)\b[^;&|\n]*\s-[A-Za-z]*[in]/;
348
+ const PLAIN_INTEGER_ARGUMENT = /^[A-Za-z_][A-Za-z0-9_]*(?:=[0-9\s+\-*/%()<>=!&|^~?:,]*)?$/;
275
349
  const WORD_BREAK = new Set([' ', '\t', '\n', ';', '&', '|', '(', ')', '<', '>']);
276
350
  const NAME_START = /[A-Za-z_]/;
277
351
  const NAME_CHAR = /[A-Za-z0-9_]/;
@@ -698,6 +772,9 @@ class Parser {
698
772
  if (name.kind !== 'word')
699
773
  throw this.unexpected(name);
700
774
  this.context.compoundWords.push(name.word);
775
+ // The loop variable takes whatever the list holds.
776
+ this.context.bracketAssigned();
777
+ let listHoldsBracket = false;
701
778
  this.newlines();
702
779
  token = this.peek();
703
780
  if (token.kind === 'word' && !token.word.quoted && token.word.value === 'in') {
@@ -715,6 +792,10 @@ class Parser {
715
792
  token = this.takePlainWord();
716
793
  if (token.kind === 'word') {
717
794
  this.context.compoundWords.push(token.word);
795
+ if (token.word.value.includes('[') ||
796
+ token.word.expands ||
797
+ NAMES_A_VARIABLE.test(token.word.value))
798
+ listHoldsBracket = true;
718
799
  continue;
719
800
  }
720
801
  if (token.kind === 'newline' || (token.kind === 'op' && token.op === ';'))
@@ -727,6 +808,8 @@ class Parser {
727
808
  this.take();
728
809
  this.newlines();
729
810
  }
811
+ if (listHoldsBracket)
812
+ this.context.storedInto(plainName(name.word.value));
730
813
  this.loopBody();
731
814
  }
732
815
  /** `do list done`, or bash's `{ list }` in its place. */
@@ -1067,6 +1150,7 @@ class Parser {
1067
1150
  this.context.opaque('parser setting');
1068
1151
  }
1069
1152
  }
1153
+ this.inspectArithmeticBuiltin(command);
1070
1154
  const head = command.words[command.assignments];
1071
1155
  if (head === undefined || head.expands)
1072
1156
  return;
@@ -1105,6 +1189,290 @@ class Parser {
1105
1189
  }
1106
1190
  this.nestedShell(nested.shell, nested.payload);
1107
1191
  }
1192
+ /**
1193
+ * `unset` evaluates a subscript in a name operand, `unset 'a[$(cmd)]'`,
1194
+ * and runs `cmd`. `--` and the options `-v`, `-n` and `-f` (also
1195
+ * clustered, `-fv`) are read; the last of `-f` and `-v` decides, and with
1196
+ * `-f` the operands are function names, which evaluate nothing. Any other
1197
+ * word that holds a `[` or expands, a fused `-v'a[$(cmd)]'` included, is
1198
+ * opaque.
1199
+ */
1200
+ inspectUnset(args) {
1201
+ let functions = false;
1202
+ let options = true;
1203
+ for (const word of args) {
1204
+ if (options && !word.expands && word.value === '--') {
1205
+ options = false;
1206
+ continue;
1207
+ }
1208
+ if (options && !word.expands && /^-[fvn]+$/.test(word.value)) {
1209
+ const last = word.value.replace(/[^fv]/g, '').slice(-1);
1210
+ if (last === 'f')
1211
+ functions = true;
1212
+ else if (last === 'v')
1213
+ functions = false;
1214
+ continue;
1215
+ }
1216
+ if (functions && !word.expands)
1217
+ continue;
1218
+ if (subscriptOrExpands(word)) {
1219
+ this.context.opaque('arithmetic');
1220
+ return;
1221
+ }
1222
+ }
1223
+ }
1224
+ /**
1225
+ * Bash evaluates a name that carries a subscript, `a[$(cmd)]`, as
1226
+ * arithmetic and runs `cmd`, quoted or not. Where that happens: each
1227
+ * `let` argument; `declare -i` (also `typeset`, `local`, clustered flags
1228
+ * such as `-ia`) for each `NAME=value`; the name given to `declare`,
1229
+ * `typeset` or `local` with any flags, to `printf -v` and to `read`; the
1230
+ * operand of `-v` or `-R` in `test` and `[`; and a later plain assignment
1231
+ * to a name declared `-i` or `-n` in the same line. A word that is not
1232
+ * plainly safe is opaque: the line asks instead of showing a command with
1233
+ * no inner one.
1234
+ */
1235
+ inspectArithmeticBuiltin(command) {
1236
+ for (let i = 0; i < command.assignments; i += 1)
1237
+ this.noteBracketAssignment(command.words[i]);
1238
+ for (const word of command.words) {
1239
+ for (const match of word.value.matchAll(ASSIGNING_EXPANSION))
1240
+ this.context.storedInto(match[1]);
1241
+ }
1242
+ let at = command.assignments;
1243
+ for (;;) {
1244
+ const word = command.words[at];
1245
+ if (word === undefined)
1246
+ return;
1247
+ if (word.expands) {
1248
+ // The head may name any builtin: with a subscript that expands in a
1249
+ // later word, the line asks.
1250
+ if (command.words.slice(at + 1).some(subscriptWithExpansion))
1251
+ this.context.opaque('arithmetic');
1252
+ // A command name held in a variable may be `declare`: flags that
1253
+ // give the integer or name-reference attribute then name a name the
1254
+ // lexer cannot read.
1255
+ if (command.words
1256
+ .slice(at + 1)
1257
+ .some((arg) => !arg.expands && /^-[A-Za-z]*[in]/.test(arg.value))) {
1258
+ this.context.declaredUnknown = true;
1259
+ this.context.declaredArithmetic();
1260
+ }
1261
+ return;
1262
+ }
1263
+ if ((word.value === 'builtin' || word.value === 'command') && command.words[at + 1]) {
1264
+ let next = at + 1;
1265
+ // `--` and `-p` only step over; `-v` and `-V` run nothing; any
1266
+ // other option is not understood, so the line asks.
1267
+ for (;;) {
1268
+ const option = command.words[next];
1269
+ if (option === undefined || option.expands || !option.value.startsWith('-'))
1270
+ break;
1271
+ if (option.value === '--') {
1272
+ next += 1;
1273
+ break;
1274
+ }
1275
+ if (option.value === '-p') {
1276
+ next += 1;
1277
+ continue;
1278
+ }
1279
+ if (word.value === 'command' && (option.value === '-v' || option.value === '-V'))
1280
+ return;
1281
+ this.context.opaque('arithmetic');
1282
+ return;
1283
+ }
1284
+ const target = command.words[next];
1285
+ if (target === undefined || target.expands)
1286
+ return;
1287
+ at = next;
1288
+ continue;
1289
+ }
1290
+ break;
1291
+ }
1292
+ const name = command.words[at].value;
1293
+ const args = command.words.slice(at + 1);
1294
+ if (name === 'eval') {
1295
+ // eval reads its words as a line again, where a name with a subscript
1296
+ // and an expansion can reach `unset` or `declare -i`.
1297
+ if (args.some(subscriptWithExpansion))
1298
+ this.context.opaque('arithmetic');
1299
+ // What it runs may give the attribute to any name.
1300
+ if (args.some((word) => word.expands || DECLARES_INTEGER.test(word.value)))
1301
+ this.context.declaredUnknown = true;
1302
+ return;
1303
+ }
1304
+ if (name === 'source' || name === '.') {
1305
+ // A file read into the shell may declare anything.
1306
+ this.context.declaredUnknown = true;
1307
+ return;
1308
+ }
1309
+ if (name === 'let') {
1310
+ if (args.some((word) => !PLAIN_ARITHMETIC.test(word.value)))
1311
+ this.context.opaque('arithmetic');
1312
+ return;
1313
+ }
1314
+ if (name === 'printf') {
1315
+ for (let i = 0; i < args.length; i += 1) {
1316
+ const value = args[i].value;
1317
+ if (value === '--')
1318
+ break;
1319
+ if (!value.startsWith('-'))
1320
+ break;
1321
+ // The last -v wins, so every leading option is read.
1322
+ if (value === '-v') {
1323
+ this.context.bracketAssigned();
1324
+ const target = args[i + 1];
1325
+ if (target !== undefined && subscriptOrExpands(target))
1326
+ this.context.opaque('arithmetic');
1327
+ // The formatted text is stored: whatever its arguments hold.
1328
+ this.context.storedInto(target === undefined ? undefined : plainName(target.value));
1329
+ i += 1;
1330
+ continue;
1331
+ }
1332
+ if (value.startsWith('-v')) {
1333
+ this.context.bracketAssigned();
1334
+ if (subscriptOrExpands(args[i]))
1335
+ this.context.opaque('arithmetic');
1336
+ this.context.storedInto(plainName(value.slice(2)));
1337
+ }
1338
+ }
1339
+ return;
1340
+ }
1341
+ if (name === 'read') {
1342
+ this.context.bracketAssigned();
1343
+ this.inspectRead(args);
1344
+ return;
1345
+ }
1346
+ if (name === 'unset') {
1347
+ this.inspectUnset(args);
1348
+ return;
1349
+ }
1350
+ if (name === 'mapfile' || name === 'readarray' || name === 'getopts') {
1351
+ this.context.bracketAssigned();
1352
+ if (args.some((word) => subscriptOrExpands(word)))
1353
+ this.context.opaque('arithmetic');
1354
+ // Input stores into the named array (default MAPFILE); getopts into its name.
1355
+ const operands = args.filter((word) => !word.value.startsWith('-'));
1356
+ if (name !== 'getopts' && operands.length === 0)
1357
+ this.context.storedInto('MAPFILE');
1358
+ for (const word of operands)
1359
+ this.context.storedInto(plainName(word.value));
1360
+ return;
1361
+ }
1362
+ if (name === 'test' || name === '[') {
1363
+ for (let i = 0; i < args.length - 1; i += 1) {
1364
+ const value = args[i].value;
1365
+ if ((value === '-v' || value === '-R') && subscriptOrExpands(args[i + 1]))
1366
+ this.context.opaque('arithmetic');
1367
+ }
1368
+ return;
1369
+ }
1370
+ if (name === 'export' || name === 'readonly') {
1371
+ for (const word of args)
1372
+ this.noteBracketAssignment(word);
1373
+ return;
1374
+ }
1375
+ if (name !== 'declare' && name !== 'typeset' && name !== 'local')
1376
+ return;
1377
+ let integer = false;
1378
+ let nameref = false;
1379
+ let flags = true;
1380
+ for (const word of args) {
1381
+ if (flags && word.value === '--')
1382
+ flags = false;
1383
+ else if (flags && /^-[A-Za-z]*i/.test(word.value))
1384
+ integer = true;
1385
+ // A word that expands may be the flag itself.
1386
+ else if (flags && word.expands && !word.value.includes('='))
1387
+ integer = true;
1388
+ if (flags && /^-[A-Za-z]*n/.test(word.value))
1389
+ nameref = true;
1390
+ }
1391
+ if (integer || nameref)
1392
+ this.context.declaredArithmetic();
1393
+ flags = true;
1394
+ for (const word of args) {
1395
+ if (flags && word.value === '--') {
1396
+ flags = false;
1397
+ continue;
1398
+ }
1399
+ if (flags && word.value.startsWith('-') && !word.expands)
1400
+ continue;
1401
+ const equals = word.value.indexOf('=');
1402
+ const nameFor = equals < 0 ? word.value : word.value.slice(0, equals);
1403
+ if (integer || nameref) {
1404
+ const declared = plainName(nameFor);
1405
+ if (declared === undefined)
1406
+ this.context.declaredUnknown = true;
1407
+ else
1408
+ this.context.declaredNames.add(declared);
1409
+ }
1410
+ if (nameFor.includes('[') || (word.expands && /[$`]/.test(nameFor)))
1411
+ this.context.opaque('arithmetic');
1412
+ else if (nameref && word.value.slice(equals + 1).includes('[') && equals >= 0)
1413
+ this.context.opaque('arithmetic');
1414
+ else if (integer && !PLAIN_INTEGER_ARGUMENT.test(word.value))
1415
+ this.context.opaque('arithmetic');
1416
+ else
1417
+ this.noteBracketAssignment(word);
1418
+ }
1419
+ }
1420
+ /** The names `read` stores into, minus the arguments of its options. */
1421
+ inspectRead(args) {
1422
+ let options = true;
1423
+ let targets = 0;
1424
+ for (let i = 0; i < args.length; i += 1) {
1425
+ const value = args[i].value;
1426
+ if (options && value === '--') {
1427
+ options = false;
1428
+ continue;
1429
+ }
1430
+ if (options && value.startsWith('-') && value.length > 1) {
1431
+ for (let k = 1; k < value.length; k += 1) {
1432
+ const letter = value[k];
1433
+ if ('dinNptu'.includes(letter) || letter === 'a') {
1434
+ const rest = value.slice(k + 1);
1435
+ const operand = rest.length > 0 ? rest : (args[i + 1]?.value ?? '');
1436
+ if (rest.length === 0)
1437
+ i += 1;
1438
+ if (letter === 'a' && operand.includes('['))
1439
+ this.context.opaque('arithmetic');
1440
+ if (letter === 'a') {
1441
+ this.context.storedInto(plainName(operand));
1442
+ targets += 1;
1443
+ }
1444
+ break;
1445
+ }
1446
+ }
1447
+ continue;
1448
+ }
1449
+ if (subscriptOrExpands(args[i]))
1450
+ this.context.opaque('arithmetic');
1451
+ this.context.storedInto(plainName(value));
1452
+ targets += 1;
1453
+ }
1454
+ if (targets === 0)
1455
+ this.context.storedInto('REPLY');
1456
+ }
1457
+ /** A plain `NAME=value` whose value holds a subscript: dangerous once NAME is `-i` or `-n`. */
1458
+ noteBracketAssignment(word) {
1459
+ if (word === undefined)
1460
+ return;
1461
+ const equals = word.value.indexOf('=');
1462
+ if (equals <= 0)
1463
+ return;
1464
+ const value = word.value.slice(equals + 1);
1465
+ if (value.includes('[') || (word.expands && /[$`]/.test(value))) {
1466
+ this.context.bracketAssigned();
1467
+ const named = ASSIGNMENT_NAME.exec(word.value);
1468
+ this.context.storedInto(named === null ? undefined : named[1]);
1469
+ }
1470
+ else if (NAMES_A_VARIABLE.test(value)) {
1471
+ // A name holds whatever an earlier call stored in it.
1472
+ const named = ASSIGNMENT_NAME.exec(word.value);
1473
+ this.context.storedInto(named === null ? undefined : named[1]);
1474
+ }
1475
+ }
1108
1476
  /** Read the payload of `bash -c payload` as a command line of its own. */
1109
1477
  nestedShell(shell, payload) {
1110
1478
  if (this.depth + 1 >= MAX_SHELL_DEPTH) {