@namzu/cli 29.0.1 → 30.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 (413) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +20 -0
  3. package/dist/browser/commands.d.ts +29 -0
  4. package/dist/browser/commands.d.ts.map +1 -0
  5. package/dist/browser/commands.js +361 -0
  6. package/dist/browser/commands.js.map +1 -0
  7. package/dist/browser/control.d.ts +79 -0
  8. package/dist/browser/control.d.ts.map +1 -0
  9. package/dist/browser/control.js +140 -0
  10. package/dist/browser/control.js.map +1 -0
  11. package/dist/browser/describe.d.ts +12 -0
  12. package/dist/browser/describe.d.ts.map +1 -0
  13. package/dist/browser/describe.js +27 -0
  14. package/dist/browser/describe.js.map +1 -0
  15. package/dist/cli.d.ts.map +1 -1
  16. package/dist/cli.js +29 -2
  17. package/dist/cli.js.map +1 -1
  18. package/dist/commands/acp.d.ts.map +1 -1
  19. package/dist/commands/acp.js +1 -0
  20. package/dist/commands/acp.js.map +1 -1
  21. package/dist/commands/browser.d.ts +7 -0
  22. package/dist/commands/browser.d.ts.map +1 -0
  23. package/dist/commands/browser.js +16 -0
  24. package/dist/commands/browser.js.map +1 -0
  25. package/dist/commands/drain.d.ts +2 -1
  26. package/dist/commands/drain.d.ts.map +1 -1
  27. package/dist/commands/drain.js +6 -3
  28. package/dist/commands/drain.js.map +1 -1
  29. package/dist/commands/exec-flags.d.ts +2 -1
  30. package/dist/commands/exec-flags.d.ts.map +1 -1
  31. package/dist/commands/exec-flags.js +6 -3
  32. package/dist/commands/exec-flags.js.map +1 -1
  33. package/dist/commands/exec-json.d.ts.map +1 -1
  34. package/dist/commands/exec-json.js +2 -1
  35. package/dist/commands/exec-json.js.map +1 -1
  36. package/dist/commands/exec.d.ts.map +1 -1
  37. package/dist/commands/exec.js +5 -1
  38. package/dist/commands/exec.js.map +1 -1
  39. package/dist/commands/host-queries.d.ts.map +1 -1
  40. package/dist/commands/host-queries.js +10 -3
  41. package/dist/commands/host-queries.js.map +1 -1
  42. package/dist/commands/schedule.d.ts +9 -0
  43. package/dist/commands/schedule.d.ts.map +1 -0
  44. package/dist/commands/schedule.js +126 -0
  45. package/dist/commands/schedule.js.map +1 -0
  46. package/dist/commands/serve.d.ts +3 -1
  47. package/dist/commands/serve.d.ts.map +1 -1
  48. package/dist/commands/serve.js +5 -3
  49. package/dist/commands/serve.js.map +1 -1
  50. package/dist/commands/skills.d.ts +10 -0
  51. package/dist/commands/skills.d.ts.map +1 -1
  52. package/dist/commands/skills.js +23 -7
  53. package/dist/commands/skills.js.map +1 -1
  54. package/dist/commands/upgrade.d.ts +5 -0
  55. package/dist/commands/upgrade.d.ts.map +1 -1
  56. package/dist/commands/upgrade.js +11 -0
  57. package/dist/commands/upgrade.js.map +1 -1
  58. package/dist/config/load.d.ts +39 -0
  59. package/dist/config/load.d.ts.map +1 -1
  60. package/dist/config/load.js +232 -1
  61. package/dist/config/load.js.map +1 -1
  62. package/dist/config/schema.d.ts +78 -0
  63. package/dist/config/schema.d.ts.map +1 -1
  64. package/dist/config/schema.js.map +1 -1
  65. package/dist/config/user-config.d.ts +23 -0
  66. package/dist/config/user-config.d.ts.map +1 -0
  67. package/dist/config/user-config.js +48 -0
  68. package/dist/config/user-config.js.map +1 -0
  69. package/dist/context/capabilities.d.ts +1 -1
  70. package/dist/context/capabilities.d.ts.map +1 -1
  71. package/dist/context/capabilities.js +1 -0
  72. package/dist/context/capabilities.js.map +1 -1
  73. package/dist/context/environment.d.ts +26 -3
  74. package/dist/context/environment.d.ts.map +1 -1
  75. package/dist/context/environment.js +68 -9
  76. package/dist/context/environment.js.map +1 -1
  77. package/dist/doctor/checks/browser.d.ts +15 -0
  78. package/dist/doctor/checks/browser.d.ts.map +1 -0
  79. package/dist/doctor/checks/browser.js +63 -0
  80. package/dist/doctor/checks/browser.js.map +1 -0
  81. package/dist/doctor/checks/index.d.ts +4 -1
  82. package/dist/doctor/checks/index.d.ts.map +1 -1
  83. package/dist/doctor/checks/index.js +8 -1
  84. package/dist/doctor/checks/index.js.map +1 -1
  85. package/dist/doctor/checks/scheduler.d.ts +10 -0
  86. package/dist/doctor/checks/scheduler.d.ts.map +1 -0
  87. package/dist/doctor/checks/scheduler.js +74 -0
  88. package/dist/doctor/checks/scheduler.js.map +1 -0
  89. package/dist/index.d.ts +1 -1
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +1 -1
  92. package/dist/index.js.map +1 -1
  93. package/dist/integrations/notifications/desktop/freedesktop.d.ts +10 -0
  94. package/dist/integrations/notifications/desktop/freedesktop.d.ts.map +1 -0
  95. package/dist/integrations/notifications/desktop/freedesktop.js +33 -0
  96. package/dist/integrations/notifications/desktop/freedesktop.js.map +1 -0
  97. package/dist/integrations/notifications/desktop/macos.d.ts +6 -0
  98. package/dist/integrations/notifications/desktop/macos.d.ts.map +1 -0
  99. package/dist/integrations/notifications/desktop/macos.js +17 -0
  100. package/dist/integrations/notifications/desktop/macos.js.map +1 -0
  101. package/dist/integrations/notifications/desktop/sanitize.d.ts +16 -0
  102. package/dist/integrations/notifications/desktop/sanitize.d.ts.map +1 -0
  103. package/dist/integrations/notifications/desktop/sanitize.js +49 -0
  104. package/dist/integrations/notifications/desktop/sanitize.js.map +1 -0
  105. package/dist/integrations/notifications/desktop/throttle.d.ts +10 -0
  106. package/dist/integrations/notifications/desktop/throttle.d.ts.map +1 -0
  107. package/dist/integrations/notifications/desktop/throttle.js +39 -0
  108. package/dist/integrations/notifications/desktop/throttle.js.map +1 -0
  109. package/dist/integrations/notifications/desktop/windows-toast.d.ts +23 -0
  110. package/dist/integrations/notifications/desktop/windows-toast.d.ts.map +1 -0
  111. package/dist/integrations/notifications/desktop/windows-toast.js +56 -0
  112. package/dist/integrations/notifications/desktop/windows-toast.js.map +1 -0
  113. package/dist/integrations/notifications/desktop.d.ts +84 -0
  114. package/dist/integrations/notifications/desktop.d.ts.map +1 -0
  115. package/dist/integrations/notifications/desktop.js +199 -0
  116. package/dist/integrations/notifications/desktop.js.map +1 -0
  117. package/dist/integrations/plugins/runtime.d.ts +8 -2
  118. package/dist/integrations/plugins/runtime.d.ts.map +1 -1
  119. package/dist/integrations/plugins/runtime.js +14 -8
  120. package/dist/integrations/plugins/runtime.js.map +1 -1
  121. package/dist/integrations/providers/harness-credentials.d.ts +9 -4
  122. package/dist/integrations/providers/harness-credentials.d.ts.map +1 -1
  123. package/dist/integrations/providers/harness-credentials.js +16 -8
  124. package/dist/integrations/providers/harness-credentials.js.map +1 -1
  125. package/dist/integrations/resident/session-step.d.ts.map +1 -1
  126. package/dist/integrations/resident/session-step.js +1 -0
  127. package/dist/integrations/resident/session-step.js.map +1 -1
  128. package/dist/integrations/subagents/runtime.d.ts +6 -0
  129. package/dist/integrations/subagents/runtime.d.ts.map +1 -1
  130. package/dist/integrations/subagents/runtime.js +14 -5
  131. package/dist/integrations/subagents/runtime.js.map +1 -1
  132. package/dist/integrations/web/open-url.d.ts +24 -0
  133. package/dist/integrations/web/open-url.d.ts.map +1 -0
  134. package/dist/integrations/web/open-url.js +73 -0
  135. package/dist/integrations/web/open-url.js.map +1 -0
  136. package/dist/permissions/browser-sites.d.ts +95 -0
  137. package/dist/permissions/browser-sites.d.ts.map +1 -0
  138. package/dist/permissions/browser-sites.js +270 -0
  139. package/dist/permissions/browser-sites.js.map +1 -0
  140. package/dist/schedule/build.d.ts +86 -0
  141. package/dist/schedule/build.d.ts.map +1 -0
  142. package/dist/schedule/build.js +267 -0
  143. package/dist/schedule/build.js.map +1 -0
  144. package/dist/schedule/changes.d.ts +28 -0
  145. package/dist/schedule/changes.d.ts.map +1 -0
  146. package/dist/schedule/changes.js +65 -0
  147. package/dist/schedule/changes.js.map +1 -0
  148. package/dist/schedule/commands/add.d.ts +24 -0
  149. package/dist/schedule/commands/add.d.ts.map +1 -0
  150. package/dist/schedule/commands/add.js +447 -0
  151. package/dist/schedule/commands/add.js.map +1 -0
  152. package/dist/schedule/commands/args.d.ts +22 -0
  153. package/dist/schedule/commands/args.d.ts.map +1 -0
  154. package/dist/schedule/commands/args.js +80 -0
  155. package/dist/schedule/commands/args.js.map +1 -0
  156. package/dist/schedule/commands/confirm-prompt.d.ts +6 -0
  157. package/dist/schedule/commands/confirm-prompt.d.ts.map +1 -0
  158. package/dist/schedule/commands/confirm-prompt.js +21 -0
  159. package/dist/schedule/commands/confirm-prompt.js.map +1 -0
  160. package/dist/schedule/commands/lifecycle.d.ts +39 -0
  161. package/dist/schedule/commands/lifecycle.d.ts.map +1 -0
  162. package/dist/schedule/commands/lifecycle.js +586 -0
  163. package/dist/schedule/commands/lifecycle.js.map +1 -0
  164. package/dist/schedule/commands/list.d.ts +33 -0
  165. package/dist/schedule/commands/list.d.ts.map +1 -0
  166. package/dist/schedule/commands/list.js +206 -0
  167. package/dist/schedule/commands/list.js.map +1 -0
  168. package/dist/schedule/commands/logs.d.ts +7 -0
  169. package/dist/schedule/commands/logs.d.ts.map +1 -0
  170. package/dist/schedule/commands/logs.js +106 -0
  171. package/dist/schedule/commands/logs.js.map +1 -0
  172. package/dist/schedule/commands/service.d.ts +16 -0
  173. package/dist/schedule/commands/service.d.ts.map +1 -0
  174. package/dist/schedule/commands/service.js +458 -0
  175. package/dist/schedule/commands/service.js.map +1 -0
  176. package/dist/schedule/daemon/daemon.d.ts +156 -0
  177. package/dist/schedule/daemon/daemon.d.ts.map +1 -0
  178. package/dist/schedule/daemon/daemon.js +1253 -0
  179. package/dist/schedule/daemon/daemon.js.map +1 -0
  180. package/dist/schedule/daemon/endpoint.d.ts +38 -0
  181. package/dist/schedule/daemon/endpoint.d.ts.map +1 -0
  182. package/dist/schedule/daemon/endpoint.js +158 -0
  183. package/dist/schedule/daemon/endpoint.js.map +1 -0
  184. package/dist/schedule/daemon/exit.d.ts +8 -0
  185. package/dist/schedule/daemon/exit.d.ts.map +1 -0
  186. package/dist/schedule/daemon/exit.js +8 -0
  187. package/dist/schedule/daemon/exit.js.map +1 -0
  188. package/dist/schedule/daemon/log.d.ts +12 -0
  189. package/dist/schedule/daemon/log.d.ts.map +1 -0
  190. package/dist/schedule/daemon/log.js +53 -0
  191. package/dist/schedule/daemon/log.js.map +1 -0
  192. package/dist/schedule/daemon/notify.d.ts +38 -0
  193. package/dist/schedule/daemon/notify.d.ts.map +1 -0
  194. package/dist/schedule/daemon/notify.js +115 -0
  195. package/dist/schedule/daemon/notify.js.map +1 -0
  196. package/dist/schedule/daemon/retention.d.ts +16 -0
  197. package/dist/schedule/daemon/retention.d.ts.map +1 -0
  198. package/dist/schedule/daemon/retention.js +46 -0
  199. package/dist/schedule/daemon/retention.js.map +1 -0
  200. package/dist/schedule/daemon/sessions.d.ts +23 -0
  201. package/dist/schedule/daemon/sessions.d.ts.map +1 -0
  202. package/dist/schedule/daemon/sessions.js +52 -0
  203. package/dist/schedule/daemon/sessions.js.map +1 -0
  204. package/dist/schedule/env.d.ts +32 -0
  205. package/dist/schedule/env.d.ts.map +1 -0
  206. package/dist/schedule/env.js +106 -0
  207. package/dist/schedule/env.js.map +1 -0
  208. package/dist/schedule/fire/browser-preflight.d.ts +41 -0
  209. package/dist/schedule/fire/browser-preflight.d.ts.map +1 -0
  210. package/dist/schedule/fire/browser-preflight.js +73 -0
  211. package/dist/schedule/fire/browser-preflight.js.map +1 -0
  212. package/dist/schedule/fire/calls.d.ts +49 -0
  213. package/dist/schedule/fire/calls.d.ts.map +1 -0
  214. package/dist/schedule/fire/calls.js +114 -0
  215. package/dist/schedule/fire/calls.js.map +1 -0
  216. package/dist/schedule/fire/fire.d.ts +78 -0
  217. package/dist/schedule/fire/fire.d.ts.map +1 -0
  218. package/dist/schedule/fire/fire.js +490 -0
  219. package/dist/schedule/fire/fire.js.map +1 -0
  220. package/dist/schedule/fire/result.d.ts +13 -0
  221. package/dist/schedule/fire/result.d.ts.map +1 -0
  222. package/dist/schedule/fire/result.js +18 -0
  223. package/dist/schedule/fire/result.js.map +1 -0
  224. package/dist/schedule/fire/unattended-note.d.ts +22 -0
  225. package/dist/schedule/fire/unattended-note.d.ts.map +1 -0
  226. package/dist/schedule/fire/unattended-note.js +46 -0
  227. package/dist/schedule/fire/unattended-note.js.map +1 -0
  228. package/dist/schedule/floor.d.ts +136 -0
  229. package/dist/schedule/floor.d.ts.map +1 -0
  230. package/dist/schedule/floor.js +1289 -0
  231. package/dist/schedule/floor.js.map +1 -0
  232. package/dist/schedule/folder.d.ts +34 -0
  233. package/dist/schedule/folder.d.ts.map +1 -0
  234. package/dist/schedule/folder.js +84 -0
  235. package/dist/schedule/folder.js.map +1 -0
  236. package/dist/schedule/paths.d.ts +49 -0
  237. package/dist/schedule/paths.d.ts.map +1 -0
  238. package/dist/schedule/paths.js +53 -0
  239. package/dist/schedule/paths.js.map +1 -0
  240. package/dist/schedule/policy.d.ts +141 -0
  241. package/dist/schedule/policy.d.ts.map +1 -0
  242. package/dist/schedule/policy.js +378 -0
  243. package/dist/schedule/policy.js.map +1 -0
  244. package/dist/schedule/resume-command.d.ts +36 -0
  245. package/dist/schedule/resume-command.d.ts.map +1 -0
  246. package/dist/schedule/resume-command.js +72 -0
  247. package/dist/schedule/resume-command.js.map +1 -0
  248. package/dist/schedule/service/detect.d.ts +22 -0
  249. package/dist/schedule/service/detect.d.ts.map +1 -0
  250. package/dist/schedule/service/detect.js +29 -0
  251. package/dist/schedule/service/detect.js.map +1 -0
  252. package/dist/schedule/service/index.d.ts +48 -0
  253. package/dist/schedule/service/index.d.ts.map +1 -0
  254. package/dist/schedule/service/index.js +361 -0
  255. package/dist/schedule/service/index.js.map +1 -0
  256. package/dist/schedule/service/launchd.d.ts +24 -0
  257. package/dist/schedule/service/launchd.d.ts.map +1 -0
  258. package/dist/schedule/service/launchd.js +84 -0
  259. package/dist/schedule/service/launchd.js.map +1 -0
  260. package/dist/schedule/service/manifest.d.ts +44 -0
  261. package/dist/schedule/service/manifest.d.ts.map +1 -0
  262. package/dist/schedule/service/manifest.js +16 -0
  263. package/dist/schedule/service/manifest.js.map +1 -0
  264. package/dist/schedule/service/names.d.ts +9 -0
  265. package/dist/schedule/service/names.d.ts.map +1 -0
  266. package/dist/schedule/service/names.js +22 -0
  267. package/dist/schedule/service/names.js.map +1 -0
  268. package/dist/schedule/service/quote.d.ts +24 -0
  269. package/dist/schedule/service/quote.d.ts.map +1 -0
  270. package/dist/schedule/service/quote.js +64 -0
  271. package/dist/schedule/service/quote.js.map +1 -0
  272. package/dist/schedule/service/runner.d.ts +17 -0
  273. package/dist/schedule/service/runner.d.ts.map +1 -0
  274. package/dist/schedule/service/runner.js +31 -0
  275. package/dist/schedule/service/runner.js.map +1 -0
  276. package/dist/schedule/service/systemd.d.ts +37 -0
  277. package/dist/schedule/service/systemd.d.ts.map +1 -0
  278. package/dist/schedule/service/systemd.js +96 -0
  279. package/dist/schedule/service/systemd.js.map +1 -0
  280. package/dist/schedule/service/windows-task.d.ts +58 -0
  281. package/dist/schedule/service/windows-task.d.ts.map +1 -0
  282. package/dist/schedule/service/windows-task.js +199 -0
  283. package/dist/schedule/service/windows-task.js.map +1 -0
  284. package/dist/schedule/service/wsl.d.ts +69 -0
  285. package/dist/schedule/service/wsl.d.ts.map +1 -0
  286. package/dist/schedule/service/wsl.js +121 -0
  287. package/dist/schedule/service/wsl.js.map +1 -0
  288. package/dist/schedule/store/atomic.d.ts +43 -0
  289. package/dist/schedule/store/atomic.d.ts.map +1 -0
  290. package/dist/schedule/store/atomic.js +135 -0
  291. package/dist/schedule/store/atomic.js.map +1 -0
  292. package/dist/schedule/store/claims.d.ts +26 -0
  293. package/dist/schedule/store/claims.d.ts.map +1 -0
  294. package/dist/schedule/store/claims.js +57 -0
  295. package/dist/schedule/store/claims.js.map +1 -0
  296. package/dist/schedule/store/digest.d.ts +18 -0
  297. package/dist/schedule/store/digest.d.ts.map +1 -0
  298. package/dist/schedule/store/digest.js +139 -0
  299. package/dist/schedule/store/digest.js.map +1 -0
  300. package/dist/schedule/store/history.d.ts +21 -0
  301. package/dist/schedule/store/history.d.ts.map +1 -0
  302. package/dist/schedule/store/history.js +114 -0
  303. package/dist/schedule/store/history.js.map +1 -0
  304. package/dist/schedule/store/jobs.d.ts +61 -0
  305. package/dist/schedule/store/jobs.d.ts.map +1 -0
  306. package/dist/schedule/store/jobs.js +210 -0
  307. package/dist/schedule/store/jobs.js.map +1 -0
  308. package/dist/schedule/store/state.d.ts +19 -0
  309. package/dist/schedule/store/state.d.ts.map +1 -0
  310. package/dist/schedule/store/state.js +38 -0
  311. package/dist/schedule/store/state.js.map +1 -0
  312. package/dist/schedule/types.d.ts +283 -0
  313. package/dist/schedule/types.d.ts.map +1 -0
  314. package/dist/schedule/types.js +9 -0
  315. package/dist/schedule/types.js.map +1 -0
  316. package/dist/skills/catalog.d.ts +96 -0
  317. package/dist/skills/catalog.d.ts.map +1 -0
  318. package/dist/skills/catalog.js +226 -0
  319. package/dist/skills/catalog.js.map +1 -0
  320. package/dist/skills/directory.d.ts +38 -0
  321. package/dist/skills/directory.d.ts.map +1 -0
  322. package/dist/skills/directory.js +51 -0
  323. package/dist/skills/directory.js.map +1 -0
  324. package/dist/skills/save.d.ts +148 -0
  325. package/dist/skills/save.d.ts.map +1 -0
  326. package/dist/skills/save.js +344 -0
  327. package/dist/skills/save.js.map +1 -0
  328. package/dist/skills/store.d.ts +103 -16
  329. package/dist/skills/store.d.ts.map +1 -1
  330. package/dist/skills/store.js +227 -30
  331. package/dist/skills/store.js.map +1 -1
  332. package/dist/tui/App.d.ts.map +1 -1
  333. package/dist/tui/App.js +609 -74
  334. package/dist/tui/App.js.map +1 -1
  335. package/dist/tui/LiveActivity.d.ts +8 -1
  336. package/dist/tui/LiveActivity.d.ts.map +1 -1
  337. package/dist/tui/LiveActivity.js +20 -4
  338. package/dist/tui/LiveActivity.js.map +1 -1
  339. package/dist/tui/PermissionOverlay.d.ts +36 -4
  340. package/dist/tui/PermissionOverlay.d.ts.map +1 -1
  341. package/dist/tui/PermissionOverlay.js +135 -15
  342. package/dist/tui/PermissionOverlay.js.map +1 -1
  343. package/dist/tui/SaveSkillOverlay.d.ts +33 -0
  344. package/dist/tui/SaveSkillOverlay.d.ts.map +1 -0
  345. package/dist/tui/SaveSkillOverlay.js +118 -0
  346. package/dist/tui/SaveSkillOverlay.js.map +1 -0
  347. package/dist/tui/agent.d.ts +208 -6
  348. package/dist/tui/agent.d.ts.map +1 -1
  349. package/dist/tui/agent.js +371 -58
  350. package/dist/tui/agent.js.map +1 -1
  351. package/dist/tui/browser-notices.d.ts +33 -0
  352. package/dist/tui/browser-notices.d.ts.map +1 -0
  353. package/dist/tui/browser-notices.js +102 -0
  354. package/dist/tui/browser-notices.js.map +1 -0
  355. package/dist/tui/open-browser.d.ts +29 -1
  356. package/dist/tui/open-browser.d.ts.map +1 -1
  357. package/dist/tui/open-browser.js +83 -11
  358. package/dist/tui/open-browser.js.map +1 -1
  359. package/dist/tui/permission-review.d.ts +10 -1
  360. package/dist/tui/permission-review.d.ts.map +1 -1
  361. package/dist/tui/permission-review.js +228 -22
  362. package/dist/tui/permission-review.js.map +1 -1
  363. package/dist/tui/schedule/host-commands.d.ts +34 -0
  364. package/dist/tui/schedule/host-commands.d.ts.map +1 -0
  365. package/dist/tui/schedule/host-commands.js +310 -0
  366. package/dist/tui/schedule/host-commands.js.map +1 -0
  367. package/dist/tui/schedule/integration.d.ts +62 -0
  368. package/dist/tui/schedule/integration.d.ts.map +1 -0
  369. package/dist/tui/schedule/integration.js +145 -0
  370. package/dist/tui/schedule/integration.js.map +1 -0
  371. package/dist/tui/schedule/loop-host.d.ts +42 -0
  372. package/dist/tui/schedule/loop-host.d.ts.map +1 -0
  373. package/dist/tui/schedule/loop-host.js +153 -0
  374. package/dist/tui/schedule/loop-host.js.map +1 -0
  375. package/dist/tui/schedule/resume.d.ts +122 -0
  376. package/dist/tui/schedule/resume.d.ts.map +1 -0
  377. package/dist/tui/schedule/resume.js +324 -0
  378. package/dist/tui/schedule/resume.js.map +1 -0
  379. package/dist/tui/schedule/startup.d.ts +11 -0
  380. package/dist/tui/schedule/startup.d.ts.map +1 -0
  381. package/dist/tui/schedule/startup.js +121 -0
  382. package/dist/tui/schedule/startup.js.map +1 -0
  383. package/dist/tui/schedule/tool-host.d.ts +58 -0
  384. package/dist/tui/schedule/tool-host.d.ts.map +1 -0
  385. package/dist/tui/schedule/tool-host.js +479 -0
  386. package/dist/tui/schedule/tool-host.js.map +1 -0
  387. package/dist/tui/skills/learning.d.ts +74 -0
  388. package/dist/tui/skills/learning.d.ts.map +1 -0
  389. package/dist/tui/skills/learning.js +131 -0
  390. package/dist/tui/skills/learning.js.map +1 -0
  391. package/dist/tui/skills/suggest-setting.d.ts +22 -0
  392. package/dist/tui/skills/suggest-setting.d.ts.map +1 -0
  393. package/dist/tui/skills/suggest-setting.js +55 -0
  394. package/dist/tui/skills/suggest-setting.js.map +1 -0
  395. package/dist/tui/skills/suggestion-ledger.d.ts +35 -0
  396. package/dist/tui/skills/suggestion-ledger.d.ts.map +1 -0
  397. package/dist/tui/skills/suggestion-ledger.js +52 -0
  398. package/dist/tui/skills/suggestion-ledger.js.map +1 -0
  399. package/dist/tui/slashCommands.d.ts +20 -0
  400. package/dist/tui/slashCommands.d.ts.map +1 -1
  401. package/dist/tui/slashCommands.js +76 -2
  402. package/dist/tui/slashCommands.js.map +1 -1
  403. package/dist/tui/turn-interruption.d.ts +20 -1
  404. package/dist/tui/turn-interruption.d.ts.map +1 -1
  405. package/dist/tui/turn-interruption.js +43 -0
  406. package/dist/tui/turn-interruption.js.map +1 -1
  407. package/dist/tui/types.d.ts +9 -1
  408. package/dist/tui/types.d.ts.map +1 -1
  409. package/package.json +7 -5
  410. package/skills/README.md +20 -0
  411. package/skills/browser-automation/SKILL.md +84 -0
  412. package/skills/schedule-task/SKILL.md +146 -0
  413. package/skills/skill-creator/SKILL.md +101 -0
@@ -0,0 +1,1289 @@
1
+ /**
2
+ * The scheduled-run floor: what no scheduled run may do, whatever its rules
3
+ * say.
4
+ *
5
+ * A scheduled run must not reach its own scheduler — stop, disable or remove
6
+ * the service, or run a `namzu schedule` subcommand that changes something —
7
+ * and must not name `NAMZU_HOME`, where its job, its history, the daemon's
8
+ * endpoint token and the credentials beside them live, nor the Windows
9
+ * browser's profile folder (`%LOCALAPPDATA%\namzu`), where namzu keeps the
10
+ * profiles it drives from WSL with the cookies of every site the operator
11
+ * signed in to.
12
+ *
13
+ * ## Why this is code and not patterns
14
+ *
15
+ * The floor used to be regular expressions over the command line's text.
16
+ * A pattern about what a line RUNS has to re-implement the shell's quoting to
17
+ * see through `'sched'ule`, `$'\x73'chedule`, `sche\<newline>dule` and
18
+ * `namzu --add-dir ';' schedule stop`, and each review round found another
19
+ * form it missed, plus a pattern that backtracked quadratically. The SDK
20
+ * reads a command line once, with the lexer the gate itself uses
21
+ * (`lexShellCommandLine`, checked against real bash), and this module decides
22
+ * on what that lexer reports: the words bash will pass to each simple
23
+ * command, after quote removal and `$'…'` decoding, the payload of a nested
24
+ * `bash -c`, every redirection target, and the words of `for` lists and
25
+ * `case` statements. Quoting is the lexer's business; this file never
26
+ * mentions a quote character except in the tripwire below.
27
+ *
28
+ * ## What is decided, and how
29
+ *
30
+ * - **Scheduler commands**, on each simple command's words in order,
31
+ * anywhere in the command, so `sudo`, `env`, `nohup` or `timeout` in front
32
+ * changes nothing: `systemctl` + a stopping verb + a unit naming namzu (or
33
+ * a glob), `launchctl` + a removing verb + a namzu label, `schtasks` with a
34
+ * `/delete`, `/change` or `/end` switch and a namzu task in any order,
35
+ * `pkill`/`killall` with a pattern that could match the daemon,
36
+ * `busctl`/`dbus-send`/`gdbus` naming namzu, and the CLI (`namzu` or a path
37
+ * to it, `@namzu/cli`, a `bin.js`, or a JavaScript runtime) with `schedule`
38
+ * followed by anything but a read-only verb. A word that expands at
39
+ * runtime (`$V`) stands for any word in any of those places; one whose only
40
+ * expansion is locale quoting (`$"stop"`) is read as its text.
41
+ * - **NAMZU_HOME**, on every word, redirection target, `for` list and `case`
42
+ * word: `~` (where bash expands it), `$HOME`, `${HOME}`, `$NAMZU_HOME` and
43
+ * `$PWD` are expanded here from known values, as are variables the line
44
+ * itself assigns; `..` and `.` are resolved; a relative path is resolved
45
+ * against the job's folder and every directory a `cd` before it names.
46
+ * Where a word still holds an unknown expansion or a glob, it is denied
47
+ * when the known part before it could lead into NAMZU_HOME (`~/.nam*`,
48
+ * `~/$X`, `/$X`), or the text after it names NAMZU_HOME's last segment. An
49
+ * assignment standing alone reaches no program and is judged where the
50
+ * variable is used; one that is exported is judged where it stands.
51
+ * - **What the lexer cannot account for** — an opaque line (a command
52
+ * substitution, `eval`-like constructs, a syntax error, a construct it does
53
+ * not model), a command whose name expands, or a program that runs text as
54
+ * code (`sh` reading its input, `sudo bash -c`, `powershell`, `python`,
55
+ * `xargs`, `watch` …) — is denied when the line's text holds something that
56
+ * could reach what the floor protects (see {@link Floor.tripwire}): a
57
+ * `schedule` subcommand that changes something with the CLI or an
58
+ * expansion in reach, the scheduler service's name, a service tool with a
59
+ * namzu name, a process killer, `NAMZU_HOME` by name or path, or the
60
+ * Windows browser's profile folder. That is the tripwire, deliberately
61
+ * textual and cheap. The product's name on its own is not in that list: a
62
+ * message box saying "Namzu: scheduled job running" reaches nothing, and a
63
+ * run that showed one was refused for it. Text such a program may run — an
64
+ * argument, a here-string, a here-document's body — is also read as a
65
+ * command line of its own, so an escape only the inner shell undoes does
66
+ * not hide it.
67
+
68
+ * - **The Windows browser's profiles**, on the same words, spellings and
69
+ * directories: a path whose segments run `AppData/Local/namzu` (any user,
70
+ * any drive, `/mnt/c/Users/<you>/…` or `C:\Users\<you>\…`, either slash,
71
+ * any letter case), with `%LOCALAPPDATA%`, `$env:LOCALAPPDATA` and
72
+ * `$LOCALAPPDATA` spelled out. The user folder above it is not known here,
73
+ * so the three segments are what is matched. Where a word holds an unknown
74
+ * expansion or a glob, it is denied when its segments could still read
75
+ * `AppData/Local/namzu` and one of them is spelled out, or when an unknown
76
+ * expansion is followed by a `namzu` segment.
77
+
78
+ * Every other tool's arguments are strings, not shell: each is searched for
79
+ * NAMZU_HOME and the browser's profiles by path, in any letter case, with
80
+ * `~`, `$HOME`, `$NAMZU_HOME` and `%LOCALAPPDATA%` spelled out, and once more
81
+ * with shell quotes and backslashes dropped, in case the tool hands it to a
82
+ * shell.
83
+ *
84
+ * Everything here is linear in the input.
85
+ */
86
+ import { builtinCommandArguments, commandArgumentOf, lexShellCommandLine, nestedShellCommand, } from '@namzu/sdk';
87
+ /** Scheduler verbs a run may use: they read, they change nothing. */
88
+ export const READ_ONLY_VERBS = ['list', 'show', 'status', 'history', 'logs'];
89
+ /** The floor's reason for denying a call, or null: what the rule below decides on. */
90
+ export function scheduledRunFloorVerdict(options) {
91
+ const floor = new Floor(options);
92
+ return (call) => floor.find(call)?.reason ?? null;
93
+ }
94
+ /** The floor's finding for a call, or null: the reason and what matched. */
95
+ export function scheduledRunFloorFinding(options) {
96
+ const floor = new Floor(options);
97
+ return (call) => floor.find(call);
98
+ }
99
+ /** What a refusal says: the rule that matched, and that another wording will not help. */
100
+ export function floorRefusal(finding) {
101
+ return `the scheduled-run floor refused this call: ${finding.detail}. It holds for every scheduled run, so rewording the call will not help`;
102
+ }
103
+ /**
104
+ * Rules this module made, which decide `deny` or nothing: a rule here never
105
+ * lets a call through, so a tool it covers may still be withheld from a run.
106
+ */
107
+ const DENY_ONLY = new WeakSet();
108
+ /** Whether `rule` is the floor's, and so can only deny. */
109
+ export function isFloorRule(rule) {
110
+ return DENY_ONLY.has(rule);
111
+ }
112
+ /** The floor as one gate rule. */
113
+ export function scheduledRunFloorRule(options) {
114
+ const floor = new Floor(options);
115
+ const rule = {
116
+ type: 'predicate',
117
+ description: `the scheduled-run floor: a scheduled run may not stop, disable or remove the scheduler, run a \`namzu schedule\` subcommand other than ${READ_ONLY_VERBS.join(', ')}, or name NAMZU_HOME (${options.namzuHome}) or the Windows browser's profile folder (%LOCALAPPDATA%\\namzu) in any argument. It holds for every scheduled run, so rewording the call will not help`,
118
+ decide: (call) => (floor.find(call) === null ? null : 'deny'),
119
+ // Asked only after `decide` denied, so the reading is done twice for a
120
+ // refused call and once for every other.
121
+ describe: (call) => {
122
+ const finding = floor.find(call);
123
+ return finding ? floorRefusal(finding) : null;
124
+ },
125
+ };
126
+ DENY_ONLY.add(rule);
127
+ return rule;
128
+ }
129
+ // ---------------------------------------------------------------------------
130
+ // Words
131
+ const SYSTEMCTL_VERBS_WITH_UNIT = new Set([
132
+ 'stop',
133
+ 'disable',
134
+ 'mask',
135
+ 'edit',
136
+ 'kill',
137
+ 'revert',
138
+ 'freeze',
139
+ 'set-property',
140
+ 'clean',
141
+ ]);
142
+ /** Verbs that stop units without naming them. */
143
+ const SYSTEMCTL_VERBS_ALONE = new Set(['isolate', 'exit']);
144
+ const LAUNCHCTL_VERBS = new Set(['bootout', 'unload', 'remove', 'disable', 'kill', 'stop']);
145
+ const SCHTASKS_SWITCH = /^[/-](?:delete|change|end)$/;
146
+ const DBUS_TOOLS = new Set(['busctl', 'dbus-send', 'gdbus']);
147
+ /** Runtimes the CLI can be started through without its name in the line. */
148
+ const JS_RUNTIMES = new Set([
149
+ 'node',
150
+ 'nodejs',
151
+ 'npx',
152
+ 'pnpx',
153
+ 'bunx',
154
+ 'bun',
155
+ 'deno',
156
+ 'tsx',
157
+ 'ts-node',
158
+ 'npm',
159
+ 'pnpm',
160
+ 'yarn',
161
+ ]);
162
+ const CLI_ENTRY = /^bin(?:\.[cm]?js)?$/;
163
+ /** Shells: a payload the lexer did not follow (stdin, a script, `sudo bash -c`) is text it never read. */
164
+ const SHELLS = new Set([
165
+ 'sh',
166
+ 'bash',
167
+ 'dash',
168
+ 'zsh',
169
+ 'ksh',
170
+ 'ash',
171
+ 'mksh',
172
+ 'busybox',
173
+ 'fish',
174
+ 'csh',
175
+ 'tcsh',
176
+ 'pwsh',
177
+ 'powershell',
178
+ 'cmd',
179
+ 'wsl',
180
+ ]);
181
+ /** Programs that run a string, a file or their input as code or as a command. */
182
+ const INTERPRETERS = /^(?:python[0-9.]*|pypy[0-9.]*|node|nodejs|deno|bun|perl[0-9.]*|ruby|php[0-9.]*|lua[0-9.]*|luajit|osascript|awk|gawk|mawk|nawk|sed|gsed|tclsh|wish|expect|eval|source|xargs|parallel|watch|su|runuser|ssh|script|flock|at|batch|crontab)$/;
183
+ /** Options that make `sudo` or `env` run a string rather than an argv. */
184
+ const STRING_OPTIONS = {
185
+ sudo: /^-(?:[a-z]*[si][a-z]*|-shell|-login)$/,
186
+ env: /^-(?:[a-z]*s[a-z]*|-split-string(?:=.*)?)$/i,
187
+ };
188
+ /** What a refusal says about a `schedule` verb that is not read-only. */
189
+ const NOT_READ_ONLY = `a \`namzu schedule\` subcommand other than ${READ_ONLY_VERBS.join(', ')}`;
190
+ const NAME_CHAR = /[a-z0-9._-]/;
191
+ function lower(text) {
192
+ return text.toLowerCase();
193
+ }
194
+ /** The last path segment, lower-cased, with `.exe` dropped. */
195
+ function commandName(value) {
196
+ const cut = Math.max(value.lastIndexOf('/'), value.lastIndexOf('\\'));
197
+ const base = lower(cut < 0 ? value : value.slice(cut + 1));
198
+ return base.endsWith('.exe') ? base.slice(0, -4) : base;
199
+ }
200
+ /** Text as a refusal quotes it: on one line, cut to `max` characters, in backticks. */
201
+ function shown(text, max = 80) {
202
+ const flat = text.replace(/\s*\n\s*/g, ' ⏎ ');
203
+ const cut = [...flat].length > max ? `${[...flat].slice(0, max - 1).join('')}…` : flat;
204
+ return cut.includes('`') ? `\`\` ${cut} \`\`` : `\`${cut}\``;
205
+ }
206
+ /**
207
+ * `$"…"` read as its text. The lexer leaves locale quoting as written and
208
+ * flags the word, because a translation catalogue could change it; the text
209
+ * itself is what a C locale passes.
210
+ */
211
+ function unlocale(value) {
212
+ return value.includes('$"')
213
+ ? value.replace(/\$"((?:[^"\\]|\\.)*)"/g, (_, inner) => inner.replace(/\\([$`"\\\n])/g, '$1'))
214
+ : value;
215
+ }
216
+ /**
217
+ * A word whose only expansion is locale quoting, read as its C-locale text,
218
+ * unless the line can choose a translation catalogue (`TEXTDOMAIN`,
219
+ * `TEXTDOMAINDIR`), which could turn `$"status"` into anything.
220
+ */
221
+ function localeOnly(value, catalogue) {
222
+ return !catalogue && value.includes('$"') && !/[$`*?[{~]/.test(unlocale(value));
223
+ }
224
+ function wordsOf(command, catalogue) {
225
+ return command.words.map((w) => {
226
+ const text = w.expands ? unlocale(w.value) : w.value;
227
+ return { text: lower(text), wild: w.expands && !localeOnly(w.value, catalogue) };
228
+ });
229
+ }
230
+ // ---------------------------------------------------------------------------
231
+ // Scheduler commands
232
+ /**
233
+ * Whether one command's words, in order, reach the scheduler, and if so what
234
+ * they do, in words. Each role is taken at its first place after the one
235
+ * before; for a question of "is there such a subsequence" that loses
236
+ * nothing, and it is one pass.
237
+ */
238
+ function reachesScheduler(words, daemonCommandLine) {
239
+ const n = words.length;
240
+ const find = (from, test) => {
241
+ for (let i = from; i < n; i++)
242
+ if (test(words[i]))
243
+ return i;
244
+ return -1;
245
+ };
246
+ const named = (name) => (w) => w.wild ? w.text.includes(name) : commandName(w.text) === name;
247
+ const namesNamzu = (w) => w.wild || w.text.includes('namzu');
248
+ // systemctl <verb> <unit>
249
+ const systemctl = find(0, named('systemctl'));
250
+ if (systemctl >= 0) {
251
+ if (find(systemctl + 1, (w) => !w.wild && SYSTEMCTL_VERBS_ALONE.has(w.text)) >= 0)
252
+ return 'stops every service, the scheduler with them';
253
+ const verb = find(systemctl + 1, (w) => w.wild || SYSTEMCTL_VERBS_WITH_UNIT.has(w.text));
254
+ // systemctl matches unit names against a glob.
255
+ if (verb >= 0 && find(verb + 1, (u) => namesNamzu(u) || /[*?[]/.test(u.text)) >= 0)
256
+ return "stops or disables the scheduler's service";
257
+ }
258
+ // launchctl <verb> <label or plist>
259
+ const launchctl = find(0, named('launchctl'));
260
+ if (launchctl >= 0) {
261
+ const verb = find(launchctl + 1, (w) => w.wild || LAUNCHCTL_VERBS.has(w.text));
262
+ if (verb >= 0 && find(verb + 1, namesNamzu) >= 0)
263
+ return "removes the scheduler's launchd agent";
264
+ }
265
+ // schtasks, whose switches come in any order.
266
+ const schtasks = find(0, named('schtasks'));
267
+ if (schtasks >= 0) {
268
+ const rest = words.slice(schtasks + 1);
269
+ if (rest.some((w) => w.wild || SCHTASKS_SWITCH.test(w.text)) && rest.some(namesNamzu))
270
+ return "deletes, changes or ends the scheduler's task";
271
+ }
272
+ // pkill / killall: a pattern that could match the daemon's process.
273
+ const killer = find(0, (w) => named('pkill')(w) || named('killall')(w));
274
+ if (killer >= 0) {
275
+ const kills = "has a pattern that could match the scheduler's process";
276
+ const full = words
277
+ .slice(killer + 1)
278
+ .some((w) => /^-[a-z]*f/.test(w.text) || w.text === '--full');
279
+ for (let i = killer + 1; i < n; i++) {
280
+ const w = words[i];
281
+ if (w.wild)
282
+ return kills;
283
+ if (w.text.startsWith('-'))
284
+ continue;
285
+ if (/[.*+?^$|()[\]{}\\]/.test(w.text))
286
+ return kills;
287
+ if (w.text.includes('namzu') || w.text.includes('schedul'))
288
+ return kills;
289
+ if ('node'.includes(w.text) || (full && daemonCommandLine.includes(w.text)))
290
+ return kills;
291
+ }
292
+ }
293
+ // A D-Bus call to systemd naming the unit.
294
+ const dbus = find(0, (w) => DBUS_TOOLS.has(commandName(w.text)));
295
+ if (dbus >= 0 && find(dbus + 1, namesNamzu) >= 0)
296
+ return 'calls systemd about a namzu unit';
297
+ // The CLI, by name (`namzu`, a path to it, `npx @namzu/cli`) or through
298
+ // its entry script or a JavaScript runtime: `schedule` and then anything
299
+ // but a read-only verb.
300
+ const strong = find(0, (w) => commandName(w.text) === 'namzu' || w.text.includes('@namzu/cli'));
301
+ const weak = find(0, (w) => CLI_ENTRY.test(commandName(w.text)) || JS_RUNTIMES.has(commandName(w.text)));
302
+ // After the CLI's own name, a word that expands may be `schedule stop`.
303
+ if (strong >= 0 && find(strong + 1, (w) => w.wild) >= 0)
304
+ return 'passes the CLI a word that expands at runtime, which could be a `schedule` subcommand';
305
+ const cli = strong < 0 ? weak : weak < 0 ? strong : Math.min(strong, weak);
306
+ if (cli >= 0) {
307
+ for (let i = cli + 1; i < n; i++) {
308
+ if (words[i].text !== 'schedule' || words[i].wild)
309
+ continue;
310
+ const verb = words[i + 1];
311
+ if (verb === undefined)
312
+ continue;
313
+ if (verb.wild)
314
+ return 'runs a `schedule` subcommand that expands at runtime';
315
+ if (!READ_ONLY_VERBS.includes(verb.text))
316
+ return `runs \`schedule ${verb.text}\`, ${NOT_READ_ONLY}`;
317
+ }
318
+ }
319
+ return null;
320
+ }
321
+ /**
322
+ * Whether a command runs text the lexer did not read as commands — a shell
323
+ * the lexer did not follow, an interpreter, `xargs`, `sudo -s`, `env -S` —
324
+ * and if so which, in words.
325
+ */
326
+ function runsUnreadText(command) {
327
+ const words = command.words;
328
+ const head = command.assignments;
329
+ const names = words.map((w) => (w.expands ? '' : commandName(w.value)));
330
+ // The shell at the head whose `-c` payload the lexer read, and `busybox`
331
+ // in front of it: exactly the lexer's own decision. Any other shell —
332
+ // `powershell -c`, `fish -c`, `bash.exe -c`, one given a script — runs
333
+ // text the lexer never read, whatever its options look like.
334
+ const nested = nestedShellCommand(words.slice(head));
335
+ const readTo = nested !== null && 'payload' in nested
336
+ ? head + (commandName(words[head].value) === 'busybox' ? 1 : 0)
337
+ : -1;
338
+ for (let i = 0; i < words.length; i++) {
339
+ const name = names[i];
340
+ if (name === '')
341
+ continue;
342
+ const program = shown(words[i].value);
343
+ if (INTERPRETERS.test(name))
344
+ return `${program} runs text as code`;
345
+ if (i === head && name === '.')
346
+ return '`.` runs a file as commands';
347
+ if (SHELLS.has(name) && !(i >= head && i <= readTo))
348
+ return `${program} runs commands the floor does not read`;
349
+ }
350
+ for (const [program, option] of Object.entries(STRING_OPTIONS)) {
351
+ const flag = words.find((w) => !w.expands && option.test(w.value));
352
+ if (names.includes(program) && flag !== undefined)
353
+ return `\`${program} ${flag.value}\` runs a string as commands`;
354
+ }
355
+ return null;
356
+ }
357
+ // ---------------------------------------------------------------------------
358
+ // Paths
359
+ /**
360
+ * `text` with `\` read as `/`, empty and `.` segments dropped and `..`
361
+ * applied, the way the kernel resolves a path (symbolic links aside). Applied
362
+ * to any text, not only a path: a segment that is not a path's is kept.
363
+ */
364
+ function normalize(text) {
365
+ const out = [];
366
+ const parts = text.replace(/\\/g, '/').split('/');
367
+ for (let i = 0; i < parts.length; i++) {
368
+ const part = parts[i];
369
+ if (part === '' && i > 0)
370
+ continue;
371
+ if (part === '.')
372
+ continue;
373
+ if (part === '..') {
374
+ const last = out.at(-1);
375
+ if (last === '')
376
+ continue; // at the root
377
+ if (last !== undefined && last !== '..') {
378
+ out.pop();
379
+ continue;
380
+ }
381
+ }
382
+ out.push(part);
383
+ }
384
+ if (out.length === 1 && out[0] === '')
385
+ return '/';
386
+ return out.join('/');
387
+ }
388
+ function isAbsolute(path) {
389
+ return path.startsWith('/') || path.startsWith('\\') || /^[a-z]:[\\/]/.test(path);
390
+ }
391
+ function join(dir, rel) {
392
+ return normalize(`${dir}/${rel}`);
393
+ }
394
+ /** Linear-time search for `home` in normalized `text`, as a whole path. */
395
+ function containsPath(text, home) {
396
+ let at = text.indexOf(home);
397
+ while (at >= 0) {
398
+ const before = at === 0 ? '' : text[at - 1];
399
+ const after = text[at + home.length] ?? '';
400
+ if (!NAME_CHAR.test(before) && !NAME_CHAR.test(after))
401
+ return true;
402
+ at = text.indexOf(home, at + 1);
403
+ }
404
+ return false;
405
+ }
406
+ /** No directory known: a relative path is checked against none. */
407
+ const NOWHERE = { dirs: [], unknown: true };
408
+ const UNKNOWN = { values: [], unknown: true };
409
+ /** How many ways a word may be spelled out before the floor stops trying and denies. */
410
+ const MAX_ALTERNATIVES = 64;
411
+ class TooMany extends Error {
412
+ }
413
+ // ---------------------------------------------------------------------------
414
+ // The Windows browser's profiles
415
+ /**
416
+ * The segments that end the path of the Windows browser's profile root,
417
+ * `%LOCALAPPDATA%\namzu`. The user folder above them is not known here (a
418
+ * run may name any user's), so these are what a path is matched on.
419
+ */
420
+ const PROFILE_SEGMENTS = ['appdata', 'local', 'namzu'];
421
+ const PROFILE_TAIL = PROFILE_SEGMENTS.join('/');
422
+ /** What `%LOCALAPPDATA%` and `$LOCALAPPDATA` stand for in the checks below. */
423
+ const LOCAL_APP_DATA = 'c:/users/%username%/appdata/local';
424
+ /**
425
+ * Lower-cased `text` with `%LOCALAPPDATA%`, `$env:LOCALAPPDATA`,
426
+ * `${env:LOCALAPPDATA}`, `$LOCALAPPDATA` and `${LOCALAPPDATA}` spelled out.
427
+ */
428
+ function spellLocalAppData(text) {
429
+ return text.includes('localappdata')
430
+ ? text.replace(/%localappdata%|\$\{?(?:env:)?localappdata(?![a-z0-9_])\}?/g, LOCAL_APP_DATA)
431
+ : text;
432
+ }
433
+ /** Whether normalized, lower-cased text names the profile root or a path in it. */
434
+ function namesProfile(text) {
435
+ return containsPath(text, PROFILE_TAIL);
436
+ }
437
+ /** Characters that stand for text the floor does not know: a glob or an expansion. */
438
+ const WILD = /[*?[$`{]/;
439
+ const WILD_RUN = /\$\{[^}]*\}?|\$[a-z0-9_]*|`[^`]*`?|\[[^\]]*\]?|[*?{}]/;
440
+ /** Whether one path segment with wildcards in it could be `name`: its literal pieces, in order. */
441
+ function mayBe(segment, name) {
442
+ if (!WILD.test(segment))
443
+ return segment === name;
444
+ const pieces = segment.split(WILD_RUN);
445
+ const first = pieces[0];
446
+ const last = pieces.at(-1);
447
+ if (!name.startsWith(first) || !name.endsWith(last))
448
+ return false;
449
+ let at = first.length;
450
+ for (const piece of pieces.slice(1, -1)) {
451
+ const found = name.indexOf(piece, at);
452
+ if (found < 0)
453
+ return false;
454
+ at = found + piece.length;
455
+ }
456
+ return at <= name.length - last.length;
457
+ }
458
+ /**
459
+ * Whether a normalized path with wildcards in it could run through
460
+ * `appdata/local/namzu`. Three segments of nothing but wildcards are not
461
+ * enough: `ls` of three globbed levels in a project is not a way into a Windows profile.
462
+ */
463
+ function mayNameProfile(text) {
464
+ const segments = text.split('/');
465
+ for (let i = 0; i + PROFILE_SEGMENTS.length <= segments.length; i++) {
466
+ const run = segments.slice(i, i + PROFILE_SEGMENTS.length);
467
+ if (!run.every((segment, k) => mayBe(segment, PROFILE_SEGMENTS[k])))
468
+ continue;
469
+ if (run.some((segment) => segment.split(WILD_RUN).some((piece) => piece !== '')))
470
+ return true;
471
+ }
472
+ return false;
473
+ }
474
+ /**
475
+ * Whether a path stops short inside the profile root's last name
476
+ * (`…/AppData/Local/nam`), to be finished by an expansion elsewhere.
477
+ */
478
+ function endsShortOfProfile(path) {
479
+ const segments = path.split('/');
480
+ const n = segments.length;
481
+ const last = segments[n - 1];
482
+ return (n >= 3 &&
483
+ segments[n - 3] === 'appdata' &&
484
+ segments[n - 2] === 'local' &&
485
+ last !== '' &&
486
+ last !== 'namzu' &&
487
+ 'namzu'.startsWith(last));
488
+ }
489
+ /** `schedule` as a command word: not a path segment, not a longer word (`scheduled`). */
490
+ const SCHEDULE_WORD = /(?:^|[\s,;([{|&=])schedule(?=$|[\s,;)\]}|&])/g;
491
+ /** The CLI, the runtimes it can be started through, or its entry script, as a word. */
492
+ const CLI_IN_TEXT = /namzu|bin\.[cm]?js|(?:^|[^a-z0-9_-])(?:node|nodejs|npx|pnpx|bunx|bun|deno|tsx|ts-node|npm|pnpm|yarn)(?![a-z0-9_-])/;
493
+ /** An expansion that could hold the CLI's name or path: `$X`, a backtick, `%X%`. */
494
+ const EXPANSION_IN_TEXT = /[$`]|%[a-z_][a-z0-9_]*%/;
495
+ /** The scheduler service's names: the unit and task (`namzu-scheduler…`), the launchd label. */
496
+ const SERVICE_NAME_IN_TEXT = /namzu-scheduler[a-z0-9._-]*|com\.namzu\.[a-z0-9._-]*/;
497
+ /** Tools that stop, change or remove a service or a scheduled task. */
498
+ const SERVICE_TOOL_IN_TEXT = /(?:^|[^a-z0-9_-])(systemctl|launchctl|schtasks|busctl|dbus-send|gdbus|(?:stop|disable|unregister|set)-scheduledtask|schedule\.service)(?![a-z0-9_-])/;
499
+ /** `pkill` and `killall` match a process by pattern, and the scheduler is a `node` process. */
500
+ const PROCESS_KILLER_IN_TEXT = /(?:^|[^a-z0-9_-])(pkill|killall)(?![a-z0-9_-])/;
501
+ /** `NAMZU_HOME` by name, in any shell's or language's spelling of a variable. */
502
+ const HOME_VARIABLE_IN_TEXT = /(?:^|[^a-z0-9_])namzu_home(?![a-z0-9_])/;
503
+ /** The Windows profile root's parent, spelled as a variable or a known-folder name. */
504
+ const LOCAL_APP_DATA_IN_TEXT = /localappdata|localapplicationdata|(?:^|[^a-z0-9])appdata(?![a-z0-9])/;
505
+ /** `namzu` as a path segment or a string of its own. */
506
+ const NAMZU_SEGMENT = /(?:^|[^a-z0-9_.-])namzu(?![a-z0-9_.-])/;
507
+ function escapeRegExp(text) {
508
+ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
509
+ }
510
+ /** A `schedule` subcommand that is not read-only, in one text, or null. */
511
+ function scheduleSubcommand(text) {
512
+ for (const match of text.matchAll(SCHEDULE_WORD)) {
513
+ const after = text.slice((match.index ?? 0) + match[0].length);
514
+ const verb = /^[\s,]*([a-z0-9][a-z0-9_-]*)/.exec(after)?.[1];
515
+ if (verb !== undefined && READ_ONLY_VERBS.includes(verb))
516
+ continue;
517
+ return verb === undefined ? 'schedule' : `schedule ${verb}`;
518
+ }
519
+ return null;
520
+ }
521
+ class Floor {
522
+ home;
523
+ /** NAMZU_HOME as the operator wrote it, for a refusal. */
524
+ homeShown;
525
+ homeCore;
526
+ /** NAMZU_HOME's last segment, and the default's (`.namzu`), as path segments in text. */
527
+ homeSegments;
528
+ userHome;
529
+ folders;
530
+ daemonCommandLine;
531
+ builtinCommands;
532
+ constructor(options) {
533
+ this.home = normalize(lower(options.namzuHome));
534
+ this.homeShown = options.namzuHome;
535
+ this.userHome = normalize(lower(options.userHome));
536
+ this.folders = (options.folders ?? []).map((f) => normalize(lower(f)));
537
+ const last = this.home.split('/').at(-1) ?? '';
538
+ this.homeCore = last.replace(/^\.+/, '');
539
+ // A dotted name (`.namzu`) is a path segment wherever it stands; an
540
+ // undotted one only after a slash, or the product's name would be one.
541
+ this.homeSegments = [...new Set(['.namzu', last])]
542
+ .filter((name) => name.replace(/^\.+/, '').length >= 3)
543
+ .map((name) => ({
544
+ name,
545
+ pattern: name.startsWith('.')
546
+ ? new RegExp(`(?:^|[^a-z0-9_.-])${escapeRegExp(name)}(?![a-z0-9_.-])`)
547
+ : new RegExp(`[/\\\\]${escapeRegExp(name)}(?![a-z0-9_.-])`),
548
+ }));
549
+ this.builtinCommands = builtinCommandArguments();
550
+ this.daemonCommandLine = lower(options.daemonCommandLine ?? `${process.execPath} ${process.argv[1] ?? ''} schedule daemon`);
551
+ }
552
+ /** What the floor protects, as a refusal names it. */
553
+ protectedWords(what) {
554
+ return what === 'NAMZU_HOME'
555
+ ? `NAMZU_HOME (${this.homeShown})`
556
+ : "the Windows browser's profile folder (%LOCALAPPDATA%\\namzu)";
557
+ }
558
+ /** Why the floor denies the call and what matched, or null when it does not. */
559
+ find(call) {
560
+ const argument = call.toolDef
561
+ ? commandArgumentOf(call.toolDef)
562
+ : this.builtinCommands.get(call.toolName);
563
+ const input = call.toolInput;
564
+ let line;
565
+ if (argument !== undefined && typeof input === 'object' && input !== null) {
566
+ const value = input[argument];
567
+ if (typeof value === 'string')
568
+ line = value;
569
+ }
570
+ try {
571
+ const named = this.stringsName(input, line);
572
+ if (named !== null)
573
+ return {
574
+ reason: `names ${named.what}`,
575
+ detail: `${named.where} names ${this.protectedWords(named.what)}`,
576
+ };
577
+ if (line !== undefined)
578
+ return this.lineVerdict(line, call.commandDialect);
579
+ return null;
580
+ }
581
+ catch (error) {
582
+ if (error instanceof TooMany)
583
+ return {
584
+ reason: 'too many spellings',
585
+ detail: `a word in the command can be spelled more than ${MAX_ALTERNATIVES} ways once its variables are filled in, and the floor refuses rather than try them all`,
586
+ };
587
+ throw error;
588
+ }
589
+ }
590
+ // ---- any tool -----------------------------------------------------------
591
+ /** Every string in the input but the command line, searched as text. */
592
+ stringsName(input, line) {
593
+ const stack = [
594
+ { value: input, at: '' },
595
+ ];
596
+ let skipped = false;
597
+ while (stack.length > 0) {
598
+ const { value, at, key } = stack.pop();
599
+ if (typeof value === 'string') {
600
+ if (!skipped && value === line) {
601
+ skipped = true;
602
+ continue;
603
+ }
604
+ const where = key
605
+ ? `the argument name ${shown(value)}`
606
+ : at === ''
607
+ ? 'the input'
608
+ : `the \`${at}\` argument`;
609
+ if (this.textNamesHome(value))
610
+ return { what: 'NAMZU_HOME', where };
611
+ if (textNamesProfile(value))
612
+ return { what: 'the browser profiles', where };
613
+ }
614
+ else if (Array.isArray(value)) {
615
+ value.forEach((each, i) => stack.push({ value: each, at: `${at}[${i}]` }));
616
+ }
617
+ else if (value !== null && typeof value === 'object') {
618
+ for (const [name, each] of Object.entries(value)) {
619
+ const path = at === '' ? name : `${at}.${name}`;
620
+ stack.push({ value: name, at: path, key: true }, { value: each, at: path });
621
+ }
622
+ }
623
+ }
624
+ return null;
625
+ }
626
+ /**
627
+ * NAMZU_HOME in free text: as a path, through `~`, `$HOME`, `${HOME}` or
628
+ * `$NAMZU_HOME`, in any letter case; and again with quotes and
629
+ * backslashes dropped, as a shell would drop them.
630
+ */
631
+ textNamesHome(text) {
632
+ const plain = lower(text);
633
+ const unquoted = plain
634
+ .replace(/\\\n/g, '')
635
+ .replace(/\$(?=["'])/g, '')
636
+ .replace(/["'\\]/g, '');
637
+ for (const variant of [plain, unquoted]) {
638
+ if (/\$\{?[!#]?namzu_home(?![a-z0-9_])/.test(variant))
639
+ return true;
640
+ const spelled = variant
641
+ .replace(/\$\{home\}|\$home(?![a-z0-9_])/g, this.userHome)
642
+ .replace(/(^|[\s"'=:(<>|;&,`])~[a-z0-9._-]*(?=[/\\]|$|[\s"'])/g, `$1${this.userHome}`);
643
+ if (containsPath(normalize(spelled), this.home))
644
+ return true;
645
+ }
646
+ return false;
647
+ }
648
+ // ---- a command line -----------------------------------------------------
649
+ lineVerdict(line, dialect, depth = 0) {
650
+ // A line for a shell that may be bash or a POSIX shell is read both
651
+ // ways, and denied if either reading denies it.
652
+ const readings = dialect === 'bash'
653
+ ? [lexShellCommandLine(line, { dialect: 'bash' })]
654
+ : [
655
+ lexShellCommandLine(line, { dialect: 'sh' }),
656
+ lexShellCommandLine(line, { dialect: 'bash' }),
657
+ ];
658
+ const catalogue = /textdomain/i.test(line);
659
+ const loops = /\b(?:while|until|for|select)\b/.test(line);
660
+ let unaccounted = null;
661
+ for (const reading of readings) {
662
+ const finding = this.readingVerdict(reading, catalogue, loops);
663
+ if (finding !== null)
664
+ return finding;
665
+ if (reading.opaque) {
666
+ unaccounted ??= {
667
+ reason: 'opaque line mentions a protected name',
668
+ why: `the floor cannot read the line (${reading.reasons[0] ?? 'a construct it does not model'})`,
669
+ };
670
+ continue;
671
+ }
672
+ for (const command of reading.commands) {
673
+ const unread = unreadCommand(command);
674
+ if (unread === null)
675
+ continue;
676
+ unaccounted ??= { reason: 'unread text mentions a protected name', why: unread };
677
+ break;
678
+ }
679
+ }
680
+ if (unaccounted === null)
681
+ return null;
682
+ const trip = this.tripwire(line, readings);
683
+ if (trip !== null)
684
+ return {
685
+ reason: unaccounted.reason,
686
+ detail: `${unaccounted.why}, and it holds ${shown(trip.token)} (${trip.what})${whereIn(readings, trip.pattern ?? trip.token)}`,
687
+ };
688
+ // Text a program may run as a command line — an argument (`echo '…' |
689
+ // sh`, `sudo bash -c '…'`), a here-string, a here-document's body —
690
+ // is read as one, decoded, so what the tripwire looks for cannot hide
691
+ // behind escapes that only the inner shell undoes.
692
+ if (depth < MAX_TEXT_DEPTH)
693
+ for (const text of fedTexts(readings)) {
694
+ const inner = this.lineVerdict(text, 'bash', depth + 1);
695
+ if (inner !== null)
696
+ return {
697
+ reason: unaccounted.reason,
698
+ detail: `${unaccounted.why}, and read as a command line, ${shown(text)}: ${inner.detail}`,
699
+ };
700
+ }
701
+ return null;
702
+ }
703
+ /**
704
+ * The tripwire, for a line the lexer could not account for: something in
705
+ * its text that can reach what the floor protects, or null. Read in the
706
+ * line as written, with quotes and expansion marks dropped (and once more
707
+ * with backslashes dropped too), and in every word the lexer decoded:
708
+ *
709
+ * - `NAMZU_HOME` by name (`$NAMZU_HOME`, `%NAMZU_HOME%`,
710
+ * `os.environ['NAMZU_HOME']`), its last segment as a path segment
711
+ * (`.namzu`, always), or a path into it;
712
+ * - the Windows browser's profile folder, as a path, or `LOCALAPPDATA` (or
713
+ * `AppData`) with `namzu` as a segment or a string of its own;
714
+ * - the scheduler service's name (`namzu-scheduler…`, `com.namzu.…`);
715
+ * - a service tool (`systemctl`, `launchctl`, `schtasks`, the D-Bus tools,
716
+ * PowerShell's `*-ScheduledTask`) with `namzu` or a glob in the text,
717
+ * `systemctl isolate` or `exit`; `pkill` or `killall` anywhere, because
718
+ * a pattern can match the scheduler's `node` process without naming it;
719
+ * - `schedule` as a command word followed by anything but a read-only
720
+ * verb, when the text also names the CLI (`namzu`, `@namzu/cli`,
721
+ * `bin.js`, a JavaScript runtime) or holds an expansion that could.
722
+ *
723
+ * Nothing else: the product's name in a string (`MessageBox::Show('Namzu:
724
+ * scheduled job running')`) reaches none of them.
725
+ */
726
+ tripwire(line, readings) {
727
+ const plain = lower(line).replace(/\\\n/g, '');
728
+ const unquoted = plain.replace(/["'$`]/g, '');
729
+ const squashed = unquoted.replace(/\\/g, '');
730
+ const decoded = readings
731
+ .flatMap((r) => r.commands.flatMap((c) => c.words.map((w) => lower(w.value))))
732
+ .join(' ');
733
+ const texts = [squashed, unquoted, decoded];
734
+ const first = (pattern) => {
735
+ for (const text of texts) {
736
+ const match = pattern.exec(text);
737
+ if (match)
738
+ return match[1] ?? match[0].replace(/^[^a-z0-9%.]+/, '');
739
+ }
740
+ return null;
741
+ };
742
+ // NAMZU_HOME.
743
+ if (HOME_VARIABLE_IN_TEXT.test(plain) || first(HOME_VARIABLE_IN_TEXT) !== null)
744
+ return { token: 'NAMZU_HOME', what: 'the NAMZU_HOME variable' };
745
+ for (const { name, pattern } of this.homeSegments)
746
+ if (texts.some((text) => pattern.test(text)))
747
+ return { token: name, what: "NAMZU_HOME's folder name", pattern };
748
+ if (this.textNamesHome(line) || this.textNamesHome(decoded))
749
+ return { token: this.homeShown, what: 'a path into NAMZU_HOME' };
750
+ // The Windows browser's profiles.
751
+ if (textNamesProfile(line) || textNamesProfile(decoded))
752
+ return {
753
+ token: '%LOCALAPPDATA%\\namzu',
754
+ what: "a path into the Windows browser's profile folder",
755
+ };
756
+ const appData = first(LOCAL_APP_DATA_IN_TEXT);
757
+ if (appData !== null && texts.some((text) => NAMZU_SEGMENT.test(text)))
758
+ return {
759
+ token: `${appData} … namzu`,
760
+ what: "together, the Windows browser's profile folder",
761
+ };
762
+ // The service.
763
+ const service = first(SERVICE_NAME_IN_TEXT);
764
+ if (service !== null)
765
+ return { token: service, what: "the scheduler service's name" };
766
+ const tool = first(SERVICE_TOOL_IN_TEXT);
767
+ if (tool !== null) {
768
+ if (texts.some((text) => text.includes('namzu')))
769
+ return { token: `${tool} … namzu`, what: 'a service tool with a namzu name' };
770
+ if (plain.includes('*'))
771
+ return { token: `${tool} … *`, what: 'a service tool with a pattern that can match it' };
772
+ if (tool === 'systemctl') {
773
+ const all = first(/(?:^|\s)(isolate|exit)(?![a-z0-9_-])/);
774
+ if (all !== null)
775
+ return { token: `systemctl ${all}`, what: 'which stops every service' };
776
+ }
777
+ }
778
+ const killer = first(PROCESS_KILLER_IN_TEXT);
779
+ if (killer !== null)
780
+ return {
781
+ token: killer,
782
+ what: 'which kills by pattern, and the scheduler is a node process a pattern can match',
783
+ };
784
+ // The CLI's `schedule` subcommands.
785
+ // `$'…'` and `$"…"` are quotes, not expansions.
786
+ const cli = texts.some((text) => CLI_IN_TEXT.test(text)) ||
787
+ EXPANSION_IN_TEXT.test(plain.replace(/\$(?=['"])/g, ''));
788
+ if (cli)
789
+ for (const text of [squashed, decoded]) {
790
+ const subcommand = scheduleSubcommand(text);
791
+ if (subcommand !== null)
792
+ return { token: subcommand, what: NOT_READ_ONLY };
793
+ }
794
+ return null;
795
+ }
796
+ readingVerdict(reading, catalogue, loops) {
797
+ for (const command of reading.commands) {
798
+ const does = reachesScheduler(wordsOf(command, catalogue), this.daemonCommandLine);
799
+ if (does !== null)
800
+ return {
801
+ reason: 'scheduler command',
802
+ detail: `${shown(command.words.map((w) => w.text).join(' '))} ${does}`,
803
+ };
804
+ }
805
+ const variables = this.assignments(reading);
806
+ const expanding = (w) => w.expands && !localeOnly(w.value, catalogue);
807
+ const expands = reading.commands.some((c) => c.words.some(expanding)) ||
808
+ reading.redirections.some((r) => expanding(r.target)) ||
809
+ reading.compoundWords.some(expanding);
810
+ // An assignment on its own reaches no program, and every use of the
811
+ // variable is spelled out with its value. One that is exported, or
812
+ // could be, is checked where it stands.
813
+ const exported = reading.commands.some((c) => c.words.some((w) => !w.expands && EXPORTING.has(commandName(w.value))));
814
+ const names = (what) => `names ${this.protectedWords(what)}`;
815
+ const cwd = new Directories(this.folders);
816
+ // In a loop, a `cd` late in the body applies to the next pass's first
817
+ // command: every command gets every directory the line can reach.
818
+ if (loops)
819
+ for (const command of reading.commands)
820
+ cwd.after(command, (target) => this.spell(target, variables, cwd.current()), this.userHome);
821
+ const seen = new Set();
822
+ for (const command of reading.commands) {
823
+ const here = cwd.current();
824
+ const check = (word) => this.wordNames(word, variables, here, expands);
825
+ const standalone = command.words.length === command.assignments && !exported;
826
+ for (const [i, word] of command.words.entries()) {
827
+ if (standalone && i < command.assignments)
828
+ continue;
829
+ const named = check(word);
830
+ if (named !== null)
831
+ return {
832
+ reason: `word names ${named}`,
833
+ detail: `the argument ${shown(word.text)} ${names(named)}`,
834
+ };
835
+ // `X=~/.namzu` as an argument, or exported: the value on its own.
836
+ const assigned = assignedValue(word);
837
+ const value = assigned ? check(assigned.word) : null;
838
+ if (value !== null)
839
+ return {
840
+ reason: `assigned value names ${value}`,
841
+ detail: `the value assigned in ${shown(word.text)} ${names(value)}`,
842
+ };
843
+ }
844
+ for (const redirection of command.redirections) {
845
+ seen.add(redirection);
846
+ const named = redirectsTo(redirection) ? check(redirection.target) : null;
847
+ if (named !== null)
848
+ return {
849
+ reason: `redirection names ${named}`,
850
+ detail: `the redirection ${shown(`${redirection.operator} ${redirection.target.text}`)} ${names(named)}`,
851
+ };
852
+ }
853
+ cwd.after(command, (target) => this.spell(target, variables, cwd.current()), this.userHome);
854
+ }
855
+ // A compound command's redirections and words belong to no one
856
+ // command: every directory the line can be in applies.
857
+ const anywhere = cwd.current();
858
+ const check = (word) => this.wordNames(word, variables, anywhere, expands);
859
+ for (const redirection of reading.redirections) {
860
+ if (seen.has(redirection) || !redirectsTo(redirection))
861
+ continue;
862
+ const named = check(redirection.target);
863
+ if (named !== null)
864
+ return {
865
+ reason: `redirection names ${named}`,
866
+ detail: `the redirection ${shown(`${redirection.operator} ${redirection.target.text}`)} ${names(named)}`,
867
+ };
868
+ }
869
+ for (const word of reading.compoundWords) {
870
+ const named = check(word);
871
+ if (named !== null)
872
+ return {
873
+ reason: `loop or case word names ${named}`,
874
+ detail: `the loop or case word ${shown(word.text)} ${names(named)}`,
875
+ };
876
+ }
877
+ return null;
878
+ }
879
+ /** Literal values the line assigns to each variable (`X=…`, `export X=…`). */
880
+ assignments(reading) {
881
+ const found = new Map();
882
+ const unknown = new Set();
883
+ const record = (word) => {
884
+ const value = assignedValue(word);
885
+ if (value === null)
886
+ return;
887
+ const { name, append } = value;
888
+ const spellings = append ? [] : this.spell(value.word, new Map(), NOWHERE);
889
+ if (spellings.length === 0 || spellings.some((s) => s.stop !== 'end')) {
890
+ unknown.add(name);
891
+ return;
892
+ }
893
+ const values = found.get(name) ?? new Set();
894
+ for (const s of spellings)
895
+ values.add(s.known);
896
+ found.set(name, values);
897
+ };
898
+ for (const command of reading.commands) {
899
+ command.words.slice(0, command.assignments).forEach(record);
900
+ const head = command.words[command.assignments];
901
+ if (head &&
902
+ !head.expands &&
903
+ ['export', 'declare', 'typeset', 'local', 'readonly'].includes(head.value))
904
+ command.words.slice(command.assignments + 1).forEach(record);
905
+ }
906
+ const out = new Map();
907
+ for (const [name, values] of found) {
908
+ if (values.size > 8)
909
+ throw new TooMany();
910
+ // The environment's value is possible too: a use may come before the assignment.
911
+ out.set(name, { values: [...values], unknown: true });
912
+ }
913
+ for (const name of unknown)
914
+ if (!out.has(name))
915
+ out.set(name, UNKNOWN);
916
+ return out;
917
+ }
918
+ /**
919
+ * A word's value with `~`, `$HOME`, `${HOME}`, `$NAMZU_HOME`, `$PWD` and
920
+ * the line's own literal assignments spelled out, one spelling per
921
+ * combination of the values each may hold.
922
+ */
923
+ spell(word, variables, cwd) {
924
+ if (!word.expands)
925
+ return [{ known: lower(word.value), stop: 'end', rest: '' }];
926
+ const value = unlocale(word.value.replace(/\\\n/g, ''));
927
+ // Bash expands a tilde only when nothing between it and the first
928
+ // unquoted `/` is quoted: `~/x` does, `"~"/x`, `~"/x"` and `~\/x` do not.
929
+ const raw = word.text.replace(/\\\n/g, '');
930
+ const tildeFirst = /^~[A-Za-z0-9._-]*(?:\/|$)/.test(raw);
931
+ const tildeAssigned = /^[A-Za-z_][A-Za-z0-9_]*\+?=/.test(raw) && /[=:]~[A-Za-z0-9._-]*(?:[/:]|$)/.test(raw);
932
+ let open = [''];
933
+ const out = [];
934
+ const stopAll = (stop, from) => {
935
+ const rest = lower(value.slice(from));
936
+ for (const known of open)
937
+ out.push({ known: lower(known), stop, rest });
938
+ };
939
+ let i = 0;
940
+ while (i < value.length && open.length > 0) {
941
+ const c = value[i];
942
+ if (c === '~' &&
943
+ ((i === 0 && tildeFirst) ||
944
+ ((value[i - 1] === '=' || value[i - 1] === ':') && tildeAssigned))) {
945
+ let j = i + 1;
946
+ while (j < value.length && NAME_CHAR.test(lower(value[j])))
947
+ j++;
948
+ if (j === value.length || value[j] === '/') {
949
+ open = open.map((known) => known + this.userHome);
950
+ i = j;
951
+ continue;
952
+ }
953
+ }
954
+ if (c === '$') {
955
+ const simple = /^\$(?:([A-Za-z_][A-Za-z0-9_]*)|\{([A-Za-z_][A-Za-z0-9_]*)\})/.exec(value.slice(i, i + 256));
956
+ if (simple) {
957
+ const name = (simple[1] ?? simple[2]);
958
+ const alternatives = name === 'HOME'
959
+ ? { values: [this.userHome], unknown: false }
960
+ : name === 'NAMZU_HOME'
961
+ ? { values: [this.home], unknown: false }
962
+ : name === 'PWD'
963
+ ? { values: cwd.dirs, unknown: cwd.unknown }
964
+ : name === 'LOCALAPPDATA'
965
+ ? localAppData(variables.get(name))
966
+ : (variables.get(name) ?? UNKNOWN);
967
+ i += simple[0].length;
968
+ // An unknown value ends every spelling here; a known one
969
+ // continues each, once per value.
970
+ if (alternatives.unknown)
971
+ stopAll('unknown', i);
972
+ const next = [];
973
+ for (const known of open)
974
+ for (const v of alternatives.values)
975
+ next.push(known + v);
976
+ if (next.length + out.length > MAX_ALTERNATIVES)
977
+ throw new TooMany();
978
+ open = next;
979
+ continue;
980
+ }
981
+ if (i + 1 < value.length) {
982
+ stopAll('unknown', i + 1);
983
+ return out;
984
+ }
985
+ }
986
+ if (c === '`' || c === '{') {
987
+ stopAll('unknown', i + 1);
988
+ return out;
989
+ }
990
+ if (c === '*' || c === '?' || c === '[') {
991
+ stopAll('glob', i);
992
+ return out;
993
+ }
994
+ open = open.map((known) => known + c);
995
+ i++;
996
+ }
997
+ stopAll('end', value.length);
998
+ return out;
999
+ }
1000
+ inside(path) {
1001
+ return path === this.home || path.startsWith(this.home === '/' ? '/' : `${this.home}/`);
1002
+ }
1003
+ /** The home segment right below `dir`, when `dir` is an ancestor of NAMZU_HOME. */
1004
+ belowAncestor(dir) {
1005
+ const prefix = dir === '/' ? '/' : `${dir}/`;
1006
+ if (!this.home.startsWith(prefix))
1007
+ return null;
1008
+ return this.home.slice(prefix.length).split('/')[0] ?? '';
1009
+ }
1010
+ /** What a word names that the floor protects, or null. */
1011
+ wordNames(word, variables, cwd, lineExpands) {
1012
+ if (this.wordNamesHome(word, variables, cwd, lineExpands))
1013
+ return 'NAMZU_HOME';
1014
+ if (this.wordNamesProfile(word, variables, cwd, lineExpands))
1015
+ return 'the browser profiles';
1016
+ return null;
1017
+ }
1018
+ /**
1019
+ * The Windows browser's profiles in a word, on the same spellings and
1020
+ * directories as NAMZU_HOME. The root is known only by its last three
1021
+ * segments, so a word with an unknown part is denied when its segments
1022
+ * could still read `appdata/local/namzu` and one of them is spelled out,
1023
+ * or when an unknown expansion is followed by a `namzu` segment.
1024
+ */
1025
+ wordNamesProfile(word, variables, cwd, lineExpands) {
1026
+ for (const spelling of this.spell(word, variables, cwd)) {
1027
+ const known = spellLocalAppData(spelling.known);
1028
+ const rest = spellLocalAppData(spelling.rest);
1029
+ // Anywhere in the word, and as a relative path from each directory.
1030
+ const bases = isAbsolute(known) ? [''] : ['', ...cwd.dirs];
1031
+ // A word with none of the root's names, no `..` and nothing unknown
1032
+ // in it cannot lead into the root from a directory outside it:
1033
+ // only a directory already inside it matters then, and joining the
1034
+ // word to every directory a line of `cd`s names is the cost.
1035
+ const inert = !/namzu|local|appdata|\.\.|[*?[$`{]/.test(known + rest);
1036
+ for (const base of bases) {
1037
+ if (inert && base !== '') {
1038
+ if (namesProfile(base))
1039
+ return true;
1040
+ continue;
1041
+ }
1042
+ const at = (text) => (base === '' ? normalize(text) : join(base, text));
1043
+ if (spelling.stop === 'end') {
1044
+ const path = at(known);
1045
+ if (namesProfile(path))
1046
+ return true;
1047
+ if (lineExpands && endsShortOfProfile(path))
1048
+ return true;
1049
+ continue;
1050
+ }
1051
+ // The unknown part stands for any text: `*` does, as a segment's wildcard.
1052
+ if (mayNameProfile(at(`${known}*${rest}`)))
1053
+ return true;
1054
+ }
1055
+ // An expansion may hold slashes, and so the whole path above `namzu`.
1056
+ if (spelling.stop === 'unknown' && /(?:^|\/)namzu(?:\/|$)/.test(normalize(rest)))
1057
+ return true;
1058
+ }
1059
+ return false;
1060
+ }
1061
+ /** Whether text after an unknown expansion holds NAMZU_HOME's last segment as a path segment. */
1062
+ restNamesHome(rest) {
1063
+ let at = rest.indexOf(this.homeCore);
1064
+ while (at >= 0) {
1065
+ const before = at === 0 ? '' : rest[at - 1];
1066
+ const after = rest[at + this.homeCore.length] ?? '';
1067
+ if (/^[./\\]?$/.test(before) && !NAME_CHAR.test(after))
1068
+ return true;
1069
+ at = rest.indexOf(this.homeCore, at + 1);
1070
+ }
1071
+ return false;
1072
+ }
1073
+ wordNamesHome(word, variables, cwd, lineExpands) {
1074
+ if (word.expands && /\$\{?[!#]?namzu_home(?![a-z0-9_])/i.test(word.value))
1075
+ return true;
1076
+ for (const spelling of this.spell(word, variables, cwd)) {
1077
+ const { known } = spelling;
1078
+ // Anywhere in the word: `--config=/…/.namzu/x`, `-f/…`.
1079
+ if (containsPath(normalize(known), this.home))
1080
+ return true;
1081
+ const bases = isAbsolute(known) ? [''] : cwd.dirs;
1082
+ for (const base of bases) {
1083
+ const path = base === '' ? normalize(known) : join(base, known);
1084
+ if (spelling.stop === 'end') {
1085
+ if (this.inside(path))
1086
+ return true;
1087
+ // A piece of the path, to be finished by an expansion elsewhere
1088
+ // in the line: `for p in ~/.nam; do ls ${p}zu; done`.
1089
+ if (lineExpands &&
1090
+ path !== '/' &&
1091
+ this.home.startsWith(path) &&
1092
+ this.home[path.length] !== '/')
1093
+ return true;
1094
+ continue;
1095
+ }
1096
+ // Stopped at an unknown: does the known part lead into NAMZU_HOME?
1097
+ const slash = known.lastIndexOf('/');
1098
+ const partial = known.slice(slash + 1);
1099
+ const dir = slash < 0
1100
+ ? base === ''
1101
+ ? null
1102
+ : base
1103
+ : base === ''
1104
+ ? normalize(known.slice(0, slash + 1) || '/')
1105
+ : join(base, known.slice(0, slash + 1));
1106
+ if (dir === null)
1107
+ continue;
1108
+ if (this.inside(dir))
1109
+ return true;
1110
+ const next = this.belowAncestor(dir);
1111
+ if (next === null)
1112
+ continue;
1113
+ if (partial === '') {
1114
+ // A glob does not match a leading dot unless it spells one.
1115
+ if (spelling.stop === 'glob' && next.startsWith('.'))
1116
+ continue;
1117
+ return true;
1118
+ }
1119
+ if (next.startsWith(partial))
1120
+ return true;
1121
+ }
1122
+ // After the unknown part, NAMZU_HOME's last segment as a path
1123
+ // segment: right after the expansion (`${X}namzu`, where X may end
1124
+ // in `/.`), or after a `.`, `/` or `\` (`$X/.namzu/x`). The name
1125
+ // inside other text (`$(echo namzu)`, `"$USER: namzu done"`) is not
1126
+ // a path.
1127
+ if (spelling.stop !== 'end' && this.homeCore.length >= 3 && this.restNamesHome(spelling.rest))
1128
+ return true;
1129
+ }
1130
+ return false;
1131
+ }
1132
+ }
1133
+ /** `NAME=value`, `NAME+=value` or `--opt=value`: the value as a word of its own. */
1134
+ function assignedValue(word) {
1135
+ // An assignment's name and `=` are never quoted, so both spellings start
1136
+ // with them.
1137
+ const text = word.text.replace(/\\\n/g, '');
1138
+ const match = /^([A-Za-z_][A-Za-z0-9_]*)(\+?)=/.exec(text);
1139
+ if (!match || !word.value.startsWith(match[0]))
1140
+ return null;
1141
+ return {
1142
+ name: match[1],
1143
+ append: match[2] === '+',
1144
+ word: {
1145
+ text: text.slice(match[0].length),
1146
+ value: word.value.slice(match[0].length),
1147
+ expands: word.expands,
1148
+ quoted: word.quoted,
1149
+ },
1150
+ };
1151
+ }
1152
+ /** `$LOCALAPPDATA`'s values: the profile root's parent, and whatever the line assigns it. */
1153
+ function localAppData(assigned) {
1154
+ return {
1155
+ values: [LOCAL_APP_DATA, ...(assigned?.values ?? [])],
1156
+ unknown: assigned?.unknown ?? false,
1157
+ };
1158
+ }
1159
+ /**
1160
+ * The Windows browser's profiles in free text: a path through
1161
+ * `AppData/Local/namzu` or `%LOCALAPPDATA%\namzu`, in any letter case, either
1162
+ * slash; and again with quotes and backslashes dropped, as a shell would.
1163
+ */
1164
+ export function textNamesProfile(text) {
1165
+ const plain = lower(text);
1166
+ const unquoted = plain
1167
+ .replace(/\\\n/g, '')
1168
+ .replace(/\$(?=["'])/g, '')
1169
+ .replace(/["']/g, '');
1170
+ for (const variant of [plain, unquoted])
1171
+ if (namesProfile(normalize(spellLocalAppData(variant))))
1172
+ return true;
1173
+ return false;
1174
+ }
1175
+ /** Commands that export a variable, or print the environment. */
1176
+ const EXPORTING = new Set([
1177
+ 'export',
1178
+ 'declare',
1179
+ 'typeset',
1180
+ 'local',
1181
+ 'readonly',
1182
+ 'set',
1183
+ 'env',
1184
+ 'printenv',
1185
+ ]);
1186
+ /** Whether a redirection names a file: not a here-document's delimiter. */
1187
+ function redirectsTo(redirection) {
1188
+ return redirection.operator !== '<<' && redirection.operator !== '<<-';
1189
+ }
1190
+ /**
1191
+ * Where a relative path may start, command by command: the job's folder and
1192
+ * every directory a `cd` or `pushd` earlier in the line names, from any of
1193
+ * those (a `cd` in a subshell or a pipeline is counted too: broader, never
1194
+ * narrower). Unknown once a `cd` goes somewhere the line does not spell out.
1195
+ */
1196
+ class Directories {
1197
+ dirs;
1198
+ unknown = false;
1199
+ constructor(folders) {
1200
+ this.dirs = new Set(folders);
1201
+ }
1202
+ /** Every directory known to be possible, and whether others are. */
1203
+ current() {
1204
+ return { dirs: [...this.dirs], unknown: this.unknown };
1205
+ }
1206
+ after(command, spell, userHome) {
1207
+ const words = command.words.slice(command.assignments);
1208
+ let at = 0;
1209
+ while (at < words.length &&
1210
+ !words[at]?.expands &&
1211
+ ['builtin', 'command'].includes(words[at]?.value ?? ''))
1212
+ at++;
1213
+ const head = words[at];
1214
+ if (!head || head.expands)
1215
+ return;
1216
+ if (head.value === 'popd') {
1217
+ this.unknown = true;
1218
+ return;
1219
+ }
1220
+ if (head.value !== 'cd' && head.value !== 'pushd')
1221
+ return;
1222
+ let target = words.slice(at + 1).find((w) => w.expands || !/^-[LPe@]+$/.test(w.value));
1223
+ if (target && !target.expands && target.value === '--')
1224
+ target = words[words.indexOf(target) + 1];
1225
+ if (!target) {
1226
+ this.dirs.add(userHome);
1227
+ return;
1228
+ }
1229
+ if (!target.expands && (target.value === '-' || /^[+-]\d+$/.test(target.value))) {
1230
+ this.unknown = true;
1231
+ return;
1232
+ }
1233
+ const from = [...this.dirs];
1234
+ for (const spelling of spell(target)) {
1235
+ if (spelling.stop !== 'end') {
1236
+ this.unknown = true;
1237
+ continue;
1238
+ }
1239
+ for (const dir of isAbsolute(spelling.known) ? ['/'] : from) {
1240
+ if (this.dirs.size >= 16) {
1241
+ this.unknown = true;
1242
+ return;
1243
+ }
1244
+ this.dirs.add(join(dir, spelling.known));
1245
+ }
1246
+ }
1247
+ }
1248
+ }
1249
+ /** How many levels of text-inside-text the tripwire reads. */
1250
+ const MAX_TEXT_DEPTH = 3;
1251
+ /** Every string in the line a program could run as a command line. */
1252
+ function fedTexts(readings) {
1253
+ const out = new Set();
1254
+ for (const reading of readings) {
1255
+ for (const command of reading.commands)
1256
+ for (const word of command.words) {
1257
+ const text = word.expands ? unlocale(word.value) : word.value;
1258
+ if (/\s|;|&|\|/.test(text))
1259
+ out.add(text);
1260
+ }
1261
+ for (const redirection of reading.redirections) {
1262
+ if (redirection.body !== undefined)
1263
+ out.add(redirection.body);
1264
+ if (redirection.operator === '<<<')
1265
+ out.add(redirection.target.value);
1266
+ }
1267
+ }
1268
+ return [...out];
1269
+ }
1270
+ /** A command the lexer listed whose name or payload it could not read, in words, or null. */
1271
+ function unreadCommand(command) {
1272
+ const head = command.words[command.assignments];
1273
+ if (head?.expands)
1274
+ return `the command's name ${shown(head.text)} expands at runtime`;
1275
+ return runsUnreadText(command);
1276
+ }
1277
+ /** `, in the argument …` for the first word that holds `token`, or nothing. */
1278
+ function whereIn(readings, token) {
1279
+ const holds = typeof token === 'string'
1280
+ ? (text) => text.includes(lower(token))
1281
+ : (text) => token.test(text);
1282
+ for (const reading of readings)
1283
+ for (const command of reading.commands)
1284
+ for (const word of command.words)
1285
+ if (holds(lower(word.value)))
1286
+ return `, in the argument ${shown(word.value)}`;
1287
+ return '';
1288
+ }
1289
+ //# sourceMappingURL=floor.js.map