@songsid/agend 2.4.0-beta.24 → 2.4.0-beta.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (395) hide show
  1. package/README.md +1 -1
  2. package/README.zh-TW.md +1 -1
  3. package/dist/agend-home.js +5 -5
  4. package/dist/agend-home.js.map +1 -1
  5. package/dist/agent-endpoint.js +10 -0
  6. package/dist/agent-endpoint.js.map +1 -1
  7. package/dist/agent-workspace.d.ts +18 -2
  8. package/dist/agent-workspace.js +15 -4
  9. package/dist/agent-workspace.js.map +1 -1
  10. package/dist/backend/antigravity.js +8 -6
  11. package/dist/backend/antigravity.js.map +1 -1
  12. package/dist/backend/claude-code.js +17 -0
  13. package/dist/backend/claude-code.js.map +1 -1
  14. package/dist/backend/claude-usage-credits.d.ts +8 -0
  15. package/dist/backend/claude-usage-credits.js +121 -0
  16. package/dist/backend/claude-usage-credits.js.map +1 -0
  17. package/dist/backend/types.d.ts +30 -0
  18. package/dist/backend/types.js.map +1 -1
  19. package/dist/build-provenance.json +1 -1
  20. package/dist/channel/adapters/discord.js +7 -1
  21. package/dist/channel/adapters/discord.js.map +1 -1
  22. package/dist/channel/tool-router.js +1 -0
  23. package/dist/channel/tool-router.js.map +1 -1
  24. package/dist/cli-audited.js +9 -4
  25. package/dist/cli-audited.js.map +1 -1
  26. package/dist/cli.js +184 -21
  27. package/dist/cli.js.map +1 -1
  28. package/dist/config-validator.js +11 -1
  29. package/dist/config-validator.js.map +1 -1
  30. package/dist/config.js +2 -0
  31. package/dist/config.js.map +1 -1
  32. package/dist/contact-auth-store.d.ts +18 -0
  33. package/dist/contact-auth-store.js +55 -8
  34. package/dist/contact-auth-store.js.map +1 -1
  35. package/dist/contact-auth-types.d.ts +3 -0
  36. package/dist/contact-auth-types.js.map +1 -1
  37. package/dist/contact-change-proposals.d.ts +34 -0
  38. package/dist/contact-change-proposals.js +1 -1
  39. package/dist/contact-change-proposals.js.map +1 -1
  40. package/dist/cross-instance-notice.d.ts +1 -0
  41. package/dist/cross-instance-notice.js +9 -8
  42. package/dist/cross-instance-notice.js.map +1 -1
  43. package/dist/daemon.d.ts +35 -0
  44. package/dist/daemon.js +234 -19
  45. package/dist/daemon.js.map +1 -1
  46. package/dist/delivery-outbox.d.ts +42 -1
  47. package/dist/delivery-outbox.js +194 -20
  48. package/dist/delivery-outbox.js.map +1 -1
  49. package/dist/fleet-context.d.ts +8 -0
  50. package/dist/fleet-lock.d.ts +67 -2
  51. package/dist/fleet-lock.js +236 -2
  52. package/dist/fleet-lock.js.map +1 -1
  53. package/dist/fleet-manager.d.ts +163 -6
  54. package/dist/fleet-manager.js +1136 -75
  55. package/dist/fleet-manager.js.map +1 -1
  56. package/dist/fleet-windows-runtime.d.ts +20 -1
  57. package/dist/fleet-windows-runtime.js +98 -18
  58. package/dist/fleet-windows-runtime.js.map +1 -1
  59. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +7 -0
  60. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +14 -4
  61. package/dist/home-update-lock.d.ts +35 -0
  62. package/dist/home-update-lock.js +81 -0
  63. package/dist/home-update-lock.js.map +1 -0
  64. package/dist/hub/compose/member.d.ts +5 -1
  65. package/dist/hub/compose/member.js +9 -5
  66. package/dist/hub/compose/member.js.map +1 -1
  67. package/dist/hub/member/room-ask.d.ts +5 -0
  68. package/dist/hub/member/room-ask.js +43 -16
  69. package/dist/hub/member/room-ask.js.map +1 -1
  70. package/dist/hub/member/room-mention-feedback.d.ts +2 -0
  71. package/dist/hub/member/room-mention-feedback.js +1 -1
  72. package/dist/hub/member/room-mention-feedback.js.map +1 -1
  73. package/dist/hub/member/room-post-answers.d.ts +2 -0
  74. package/dist/hub/member/room-post-answers.js +1 -1
  75. package/dist/hub/member/room-post-answers.js.map +1 -1
  76. package/dist/hub/member/room-post.d.ts +5 -0
  77. package/dist/hub/member/room-post.js +4 -1
  78. package/dist/hub/member/room-post.js.map +1 -1
  79. package/dist/hub/member/updates.d.ts +7 -1
  80. package/dist/hub/member/updates.js +7 -1
  81. package/dist/hub/member/updates.js.map +1 -1
  82. package/dist/hub/representative.d.ts +7 -0
  83. package/dist/hub/representative.js +38 -5
  84. package/dist/hub/representative.js.map +1 -1
  85. package/dist/install-lock.d.ts +15 -1
  86. package/dist/install-lock.js +16 -8
  87. package/dist/install-lock.js.map +1 -1
  88. package/dist/install-ownership.d.ts +165 -0
  89. package/dist/install-ownership.js +404 -0
  90. package/dist/install-ownership.js.map +1 -0
  91. package/dist/instance-config-impact.js +2 -0
  92. package/dist/instance-config-impact.js.map +1 -1
  93. package/dist/instructions.d.ts +4 -0
  94. package/dist/instructions.js +4 -0
  95. package/dist/instructions.js.map +1 -1
  96. package/dist/local-pane-endpoint.d.ts +4 -1
  97. package/dist/local-pane-endpoint.js +12 -2
  98. package/dist/local-pane-endpoint.js.map +1 -1
  99. package/dist/locale.js +160 -4
  100. package/dist/locale.js.map +1 -1
  101. package/dist/native-agent-admission.d.ts +7 -0
  102. package/dist/native-agent-admission.js +46 -3
  103. package/dist/native-agent-admission.js.map +1 -1
  104. package/dist/native-mcp.d.ts +16 -1
  105. package/dist/native-mcp.js +38 -5
  106. package/dist/native-mcp.js.map +1 -1
  107. package/dist/native-pane-lifecycle.d.ts +9 -0
  108. package/dist/native-pane-lifecycle.js +23 -0
  109. package/dist/native-pane-lifecycle.js.map +1 -1
  110. package/dist/native-pane-manager.d.ts +19 -6
  111. package/dist/native-pane-manager.js +79 -4
  112. package/dist/native-pane-manager.js.map +1 -1
  113. package/dist/needs-you.d.ts +8 -0
  114. package/dist/needs-you.js +1 -0
  115. package/dist/needs-you.js.map +1 -1
  116. package/dist/outbound-handlers.d.ts +12 -0
  117. package/dist/outbound-handlers.js +30 -2
  118. package/dist/outbound-handlers.js.map +1 -1
  119. package/dist/package-preimage.js +4 -0
  120. package/dist/package-preimage.js.map +1 -1
  121. package/dist/pane-port.d.ts +1 -0
  122. package/dist/plist-args.d.ts +9 -0
  123. package/dist/plist-args.js +22 -0
  124. package/dist/plist-args.js.map +1 -0
  125. package/dist/public-preview.d.ts +4 -6
  126. package/dist/public-preview.js +5 -2
  127. package/dist/public-preview.js.map +1 -1
  128. package/dist/public-web-gateway.js +8 -3
  129. package/dist/public-web-gateway.js.map +1 -1
  130. package/dist/public-web-link.d.ts +13 -1
  131. package/dist/public-web-link.js +28 -1
  132. package/dist/public-web-link.js.map +1 -1
  133. package/dist/recover.cjs +2452 -0
  134. package/dist/remote-card-prompt.d.ts +6 -2
  135. package/dist/remote-card-prompt.js +12 -3
  136. package/dist/remote-card-prompt.js.map +1 -1
  137. package/dist/reply-draft.d.ts +12 -0
  138. package/dist/reply-draft.js +81 -0
  139. package/dist/reply-draft.js.map +1 -0
  140. package/dist/request-contact-api.d.ts +15 -0
  141. package/dist/request-contact-api.js +120 -0
  142. package/dist/request-contact-api.js.map +1 -0
  143. package/dist/request-contact-card.d.ts +36 -0
  144. package/dist/request-contact-card.js +206 -0
  145. package/dist/request-contact-card.js.map +1 -0
  146. package/dist/request-contact-gate.d.ts +79 -0
  147. package/dist/request-contact-gate.js +262 -0
  148. package/dist/request-contact-gate.js.map +1 -0
  149. package/dist/request-contact-native.d.ts +52 -0
  150. package/dist/request-contact-native.js +83 -0
  151. package/dist/request-contact-native.js.map +1 -0
  152. package/dist/request-contact-types.d.ts +86 -0
  153. package/dist/request-contact-types.js +7 -0
  154. package/dist/request-contact-types.js.map +1 -0
  155. package/dist/request-context-call-protocol.d.ts +12 -0
  156. package/dist/request-context-call-protocol.js +14 -0
  157. package/dist/request-context-call-protocol.js.map +1 -0
  158. package/dist/request-context-call.d.ts +22 -0
  159. package/dist/request-context-call.js +35 -0
  160. package/dist/request-context-call.js.map +1 -0
  161. package/dist/request-context-drain.d.ts +39 -0
  162. package/dist/request-context-drain.js +159 -0
  163. package/dist/request-context-drain.js.map +1 -0
  164. package/dist/request-context-fence.d.ts +28 -0
  165. package/dist/request-context-fence.js +58 -0
  166. package/dist/request-context-fence.js.map +1 -0
  167. package/dist/request-context-migration.d.ts +64 -0
  168. package/dist/request-context-migration.js +158 -0
  169. package/dist/request-context-migration.js.map +1 -0
  170. package/dist/request-context-pane.d.ts +25 -0
  171. package/dist/request-context-pane.js +48 -0
  172. package/dist/request-context-pane.js.map +1 -0
  173. package/dist/request-context-policy.d.ts +74 -0
  174. package/dist/request-context-policy.js +116 -0
  175. package/dist/request-context-policy.js.map +1 -0
  176. package/dist/request-context-recovery.d.ts +14 -0
  177. package/dist/request-context-recovery.js +56 -0
  178. package/dist/request-context-recovery.js.map +1 -0
  179. package/dist/request-context-relay.d.ts +19 -0
  180. package/dist/request-context-relay.js +63 -0
  181. package/dist/request-context-relay.js.map +1 -0
  182. package/dist/request-context-returns.d.ts +67 -0
  183. package/dist/request-context-returns.js +211 -0
  184. package/dist/request-context-returns.js.map +1 -0
  185. package/dist/request-context-store.d.ts +2 -1
  186. package/dist/request-context-store.js +8 -1
  187. package/dist/request-context-store.js.map +1 -1
  188. package/dist/request-context-turns.d.ts +99 -0
  189. package/dist/request-context-turns.js +215 -0
  190. package/dist/request-context-turns.js.map +1 -0
  191. package/dist/request-context-view.d.ts +33 -0
  192. package/dist/request-context-view.js +36 -0
  193. package/dist/request-context-view.js.map +1 -0
  194. package/dist/request-hub-context.d.ts +130 -0
  195. package/dist/request-hub-context.js +89 -0
  196. package/dist/request-hub-context.js.map +1 -0
  197. package/dist/request-hub-output.d.ts +11 -0
  198. package/dist/request-hub-output.js +21 -0
  199. package/dist/request-hub-output.js.map +1 -0
  200. package/dist/runtime-cli-install.js +13 -11
  201. package/dist/runtime-cli-install.js.map +1 -1
  202. package/dist/runtime-client.d.ts +2 -0
  203. package/dist/runtime-client.js +17 -4
  204. package/dist/runtime-client.js.map +1 -1
  205. package/dist/runtime-coordinator.d.ts +4 -1
  206. package/dist/runtime-coordinator.js +10 -3
  207. package/dist/runtime-coordinator.js.map +1 -1
  208. package/dist/runtime-pane-assets.d.ts +1 -1
  209. package/dist/runtime-pane-assets.js +1 -1
  210. package/dist/runtime-pane-assets.js.map +1 -1
  211. package/dist/runtime-pane-host.d.ts +3 -0
  212. package/dist/runtime-pane-host.js +39 -21
  213. package/dist/runtime-pane-host.js.map +1 -1
  214. package/dist/runtime-pane-link.d.ts +6 -2
  215. package/dist/runtime-pane-link.js +17 -4
  216. package/dist/runtime-pane-link.js.map +1 -1
  217. package/dist/runtime-pane-mcp-relay.d.ts +11 -1
  218. package/dist/runtime-pane-mcp-relay.js +69 -3
  219. package/dist/runtime-pane-mcp-relay.js.map +1 -1
  220. package/dist/runtime-pane-mcp.d.ts +28 -1
  221. package/dist/runtime-pane-mcp.js +92 -15
  222. package/dist/runtime-pane-mcp.js.map +1 -1
  223. package/dist/runtime-pane-port.d.ts +6 -0
  224. package/dist/runtime-pane-port.js +23 -4
  225. package/dist/runtime-pane-port.js.map +1 -1
  226. package/dist/runtime-pane-protocol.d.ts +4 -0
  227. package/dist/runtime-pane-protocol.js +11 -4
  228. package/dist/runtime-pane-protocol.js.map +1 -1
  229. package/dist/runtime-pane-service.d.ts +1 -0
  230. package/dist/runtime-pane-service.js +25 -9
  231. package/dist/runtime-pane-service.js.map +1 -1
  232. package/dist/runtime-pane-stdio-protocol.d.ts +4 -0
  233. package/dist/runtime-pane-stdio-protocol.js +12 -5
  234. package/dist/runtime-pane-stdio-protocol.js.map +1 -1
  235. package/dist/runtime-pane-stdio.js +5 -5
  236. package/dist/runtime-pane-stdio.js.map +1 -1
  237. package/dist/runtime-protocol.d.ts +3 -0
  238. package/dist/runtime-protocol.js.map +1 -1
  239. package/dist/scheduler/scheduler.d.ts +6 -0
  240. package/dist/scheduler/scheduler.js +19 -1
  241. package/dist/scheduler/scheduler.js.map +1 -1
  242. package/dist/scheduler/task-board.d.ts +4 -0
  243. package/dist/scheduler/task-board.js +6 -0
  244. package/dist/scheduler/task-board.js.map +1 -1
  245. package/dist/scheduler/types.d.ts +1 -1
  246. package/dist/service-activation.js +3 -13
  247. package/dist/service-activation.js.map +1 -1
  248. package/dist/service-lock.d.ts +28 -0
  249. package/dist/service-lock.js +85 -0
  250. package/dist/service-lock.js.map +1 -0
  251. package/dist/settings-api.d.ts +6 -0
  252. package/dist/settings-api.js +35 -0
  253. package/dist/settings-api.js.map +1 -1
  254. package/dist/settings-change.js +1 -1
  255. package/dist/settings-change.js.map +1 -1
  256. package/dist/state-lease.d.ts +24 -0
  257. package/dist/state-lease.js +103 -0
  258. package/dist/state-lease.js.map +1 -0
  259. package/dist/tmux-binary.js +1 -1
  260. package/dist/tmux-binary.js.map +1 -1
  261. package/dist/tool-receipt-output.d.ts +2 -0
  262. package/dist/topic-commands.js +21 -1
  263. package/dist/topic-commands.js.map +1 -1
  264. package/dist/transcript-monitor.js +3 -0
  265. package/dist/transcript-monitor.js.map +1 -1
  266. package/dist/tunnel/named-link-test.d.ts +27 -0
  267. package/dist/tunnel/named-link-test.js +41 -0
  268. package/dist/tunnel/named-link-test.js.map +1 -1
  269. package/dist/types.d.ts +7 -0
  270. package/dist/ui/chat-store.js +5 -4
  271. package/dist/ui/fleet-office-card.js +15 -2
  272. package/dist/ui/fleet-office-skin.js +33 -9
  273. package/dist/ui/fleet-office-zones.js +8 -3
  274. package/dist/ui/fleet-office.js +136 -18
  275. package/dist/ui/fleet-task-files.js +1 -1
  276. package/dist/ui/panel-chat.js +15 -2
  277. package/dist/ui/panel-needs.js +22 -2
  278. package/dist/ui/panel-settings.js +22 -8
  279. package/dist/ui/settings-preview-address.js +156 -0
  280. package/dist/ui/settings-registry.js +2 -0
  281. package/dist/ui/settings-strings.js +6 -6
  282. package/dist/ui/shared/app.css +76 -2
  283. package/dist/ui/shared/chat-strings.js +6 -2
  284. package/dist/ui/shared/chat-thread.js +7 -1
  285. package/dist/ui/shared/preview-panel.js +1 -1
  286. package/dist/ui/shared/preview.js +11 -2
  287. package/dist/ui/shared/tokens.css +18 -3
  288. package/dist/ui/shared/ui-confirm.js +5 -4
  289. package/dist/ui/shared/workspace.css +7 -0
  290. package/dist/ui/usage-credits-card.js +84 -0
  291. package/dist/ui/workspace-ignored-strings.js +16 -0
  292. package/dist/ui/workspace-panel.js +15 -6
  293. package/dist/update-card.d.ts +193 -0
  294. package/dist/update-card.js +620 -0
  295. package/dist/update-card.js.map +1 -0
  296. package/dist/update-dispatch.d.ts +16 -1
  297. package/dist/update-dispatch.js +12 -4
  298. package/dist/update-dispatch.js.map +1 -1
  299. package/dist/update-forward.d.ts +73 -0
  300. package/dist/update-forward.js +283 -0
  301. package/dist/update-forward.js.map +1 -0
  302. package/dist/update-idle.d.ts +1 -0
  303. package/dist/update-idle.js +12 -3
  304. package/dist/update-idle.js.map +1 -1
  305. package/dist/update-install.d.ts +2 -1
  306. package/dist/update-install.js +18 -10
  307. package/dist/update-install.js.map +1 -1
  308. package/dist/update-journal.d.ts +351 -0
  309. package/dist/update-journal.js +717 -0
  310. package/dist/update-journal.js.map +1 -0
  311. package/dist/update-launch.js +1 -1
  312. package/dist/update-launch.js.map +1 -1
  313. package/dist/update-npm-env.d.ts +45 -12
  314. package/dist/update-npm-env.js +48 -0
  315. package/dist/update-npm-env.js.map +1 -1
  316. package/dist/update-package-restore.d.ts +75 -0
  317. package/dist/update-package-restore.js +318 -0
  318. package/dist/update-package-restore.js.map +1 -0
  319. package/dist/update-quiescence.d.ts +192 -0
  320. package/dist/update-quiescence.js +330 -0
  321. package/dist/update-quiescence.js.map +1 -0
  322. package/dist/update-readiness-host.d.ts +61 -0
  323. package/dist/update-readiness-host.js +297 -0
  324. package/dist/update-readiness-host.js.map +1 -0
  325. package/dist/update-readiness.d.ts +83 -0
  326. package/dist/update-readiness.js +459 -0
  327. package/dist/update-readiness.js.map +1 -0
  328. package/dist/update-recovery/kit.d.ts +35 -0
  329. package/dist/update-recovery/kit.js +99 -0
  330. package/dist/update-recovery/kit.js.map +1 -0
  331. package/dist/update-recovery/pre-start.d.ts +34 -0
  332. package/dist/update-recovery/pre-start.js +103 -0
  333. package/dist/update-recovery/pre-start.js.map +1 -0
  334. package/dist/update-recovery/recover-main.d.ts +1 -0
  335. package/dist/update-recovery/recover-main.js +4 -0
  336. package/dist/update-recovery/recover-main.js.map +1 -0
  337. package/dist/update-recovery/recover.d.ts +22 -0
  338. package/dist/update-recovery/recover.js +124 -0
  339. package/dist/update-recovery/recover.js.map +1 -0
  340. package/dist/update-recovery/route.d.ts +53 -0
  341. package/dist/update-recovery/route.js +262 -0
  342. package/dist/update-recovery/route.js.map +1 -0
  343. package/dist/update-recovery/runner.d.ts +58 -0
  344. package/dist/update-recovery/runner.js +196 -0
  345. package/dist/update-recovery/runner.js.map +1 -0
  346. package/dist/update-recovery/service-manager.d.ts +39 -0
  347. package/dist/update-recovery/service-manager.js +57 -0
  348. package/dist/update-recovery/service-manager.js.map +1 -0
  349. package/dist/update-restore.d.ts +44 -0
  350. package/dist/update-restore.js +355 -0
  351. package/dist/update-restore.js.map +1 -0
  352. package/dist/update-retained.d.ts +38 -0
  353. package/dist/update-retained.js +91 -0
  354. package/dist/update-retained.js.map +1 -0
  355. package/dist/update-rollback.d.ts +74 -0
  356. package/dist/update-rollback.js +221 -0
  357. package/dist/update-rollback.js.map +1 -0
  358. package/dist/update-settings.d.ts +36 -0
  359. package/dist/update-settings.js +122 -0
  360. package/dist/update-settings.js.map +1 -0
  361. package/dist/update-snapshot-manifest.d.ts +32 -0
  362. package/dist/update-snapshot-manifest.js +65 -0
  363. package/dist/update-snapshot-manifest.js.map +1 -0
  364. package/dist/update-snapshot-scope.d.ts +67 -0
  365. package/dist/update-snapshot-scope.js +172 -0
  366. package/dist/update-snapshot-scope.js.map +1 -0
  367. package/dist/update-snapshot.d.ts +34 -0
  368. package/dist/update-snapshot.js +246 -0
  369. package/dist/update-snapshot.js.map +1 -0
  370. package/dist/update-writers.d.ts +71 -0
  371. package/dist/update-writers.js +235 -0
  372. package/dist/update-writers.js.map +1 -0
  373. package/dist/web-api.d.ts +3 -0
  374. package/dist/web-api.js +43 -8
  375. package/dist/web-api.js.map +1 -1
  376. package/dist/web-chat-history.d.ts +7 -0
  377. package/dist/web-chat-history.js +15 -0
  378. package/dist/web-chat-history.js.map +1 -1
  379. package/dist/web-preview.d.ts +5 -0
  380. package/dist/web-preview.js +1 -1
  381. package/dist/web-preview.js.map +1 -1
  382. package/dist/web-update.d.ts +6 -0
  383. package/dist/windows-agents.d.ts +12 -0
  384. package/dist/windows-agents.js +5 -0
  385. package/dist/windows-agents.js.map +1 -1
  386. package/launcher/agend +4 -1
  387. package/launcher/agend-agent +4 -1
  388. package/launcher/agend-install.cjs +16 -8
  389. package/launcher/install-admission.d.cts +8 -0
  390. package/launcher/npm-allow-scripts.cjs +72 -0
  391. package/launcher/npm-global-prefix.cjs +81 -0
  392. package/launcher/postinstall.cjs +9 -8
  393. package/launcher/runtime-select.cjs +8 -2
  394. package/package.json +3 -2
  395. package/scripts/preinstall-guard.cjs +1 -1
package/dist/cli.js CHANGED
@@ -19,12 +19,19 @@ import { Command, Option } from "commander";
19
19
  import { registerBuildInfoCommand } from "./build-provenance-cli.js";
20
20
  import { launchdServiceDomain } from "./launchd-service-domain.js";
21
21
  import { registerBugReportCommand } from "./bug-report-cli.js";
22
- import { join, dirname } from "node:path";
22
+ import { join, dirname, parse } from "node:path";
23
23
  import { SchedulerDb } from "./scheduler/db.js";
24
24
  import { Cron } from "croner";
25
25
  import { existsSync, readFileSync, writeFileSync, appendFileSync, unlinkSync, mkdirSync, chmodSync, readdirSync, rmSync, statSync, realpathSync, openSync, writeSync, closeSync, } from "node:fs";
26
26
  import { homedir, totalmem, freemem, userInfo } from "node:os";
27
27
  import { fileURLToPath } from "node:url";
28
+ import { createRequire } from "node:module";
29
+ import { randomBytes } from "node:crypto";
30
+ import { acquireHomeUpdateLock, admitFleetStart, installPrefixOf } from "./home-update-lock.js";
31
+ import { admitServiceCommand } from "./service-lock.js";
32
+ import { claimHandoff, fleetStartGate } from "./update-journal.js";
33
+ import { takeSharedLease } from "./state-lease.js";
34
+ import { ensureAgendHome } from "./agend-home.js";
28
35
  import { spawnSync, execSync, execFileSync } from "node:child_process";
29
36
  import { spawn } from "./child-process.js";
30
37
  import { getAgendHome, isDefaultAgendHome, realDefaultAgendHome } from "./paths.js";
@@ -34,7 +41,7 @@ import { COMPLETION_SHELLS, completionScript } from "./completion.js";
34
41
  import { getUpdateSelector, isExactVersion, isUnrequestedDowngrade, downgradeRefusal, lookupTargetVersion, reportUpdateRestart, shouldSkipUpdate, runningFleetPredatesInstall, fleetProvenStopped, readFleetPidEvidence, pidAlive, processStartMs, } from "./update-check.js";
35
42
  import { clearUpdateMarker, markUpdateInProgress, readUpdateProgress, setUpdateProgressStage } from "./update-marker.js";
36
43
  import { describeSignalSource, forceAllowed, gateFleetControl, recordInstanceControl, withOrigin } from "./fleet-control-audit.js";
37
- import { dropUpdateNpmBounds, withoutUpdateNpmBounds } from "./update-npm-env.js";
44
+ import { dropUpdateNpmBounds, npmAllowScripts, npmGlobalPrefix, withoutUpdateNpmBounds } from "./update-npm-env.js";
38
45
  import { FLEET_STOP_TIMEOUT_MS, stopDetachedOwner, systemdStopTimeoutMs, detachedProcessStart, detachedProcessExited } from "./fleet-stop-budget.js";
39
46
  import { fleetServiceOwner } from "./fleet-service-owner.js";
40
47
  import { acquireFleetLock, isFleetStartCommandLine, readProcessCommandLine, releaseProcessFleetLock, setProcessFleetLock } from "./fleet-lock.js";
@@ -170,9 +177,105 @@ program.hook("preAction", async (_hooked, action) => {
170
177
  }
171
178
  catch { /* the banner never stands in a command's way */ }
172
179
  });
180
+ /**
181
+ * M-3770 (#4480 §4.2): before claiming fleet.lock, take the home update lock: another install's update in progress on
182
+ * this home keeps this fleet from starting (its own update's restart goes through). Sync, like the claim it guards.
183
+ */
184
+ function admitAgainstHomeUpdate() {
185
+ try {
186
+ ensureAgendHome(DATA_DIR); // as acquireFleetLock does next: the lock lives in it
187
+ const admission = createRequire(import.meta.url)("../launcher/install-admission.cjs");
188
+ const ownPrefix = installPrefixOf(fileURLToPath(new URL("..", import.meta.url)));
189
+ const admitted = admitFleetStart(DATA_DIR, ownPrefix, {
190
+ pid: process.pid, processStart: admission.processStart, startTicks: admission.startTicks, bootId: admission.bootId,
191
+ newToken: () => randomBytes(16).toString("hex"), now: () => new Date(), log: message => console.log(message),
192
+ });
193
+ if (!admitted.ok) {
194
+ console.error(admitted.reason);
195
+ process.exitCode = 1;
196
+ return { ok: false };
197
+ }
198
+ if (admitted.note)
199
+ console.log(` Home update lock: ${admitted.note}.`);
200
+ return { ok: true, release: admitted.release };
201
+ }
202
+ catch (err) {
203
+ // The lock's own failure never keeps a fleet down: fleet.lock still keeps one fleet per home.
204
+ console.log(` Home update lock not checked (${err.message}).`);
205
+ return { ok: true, release: () => { } };
206
+ }
207
+ }
208
+ /**
209
+ * M-3770 (design update-transaction §3.4): a service command takes the service lock for its run, and is refused at once
210
+ * while a live update holds it (admitted only with the updater's token). Released when this process exits.
211
+ */
212
+ function guardServiceCommand(command) {
213
+ try {
214
+ const admission = createRequire(import.meta.url)("../launcher/install-admission.cjs");
215
+ const admitted = admitServiceCommand(DATA_DIR, command, {
216
+ pid: process.pid, processStart: admission.processStart, startTicks: admission.startTicks, bootId: admission.bootId,
217
+ newToken: () => randomBytes(16).toString("hex"), now: () => new Date(), log: message => console.log(message),
218
+ });
219
+ if (!admitted.ok) {
220
+ console.error(admitted.reason);
221
+ process.exitCode = 1;
222
+ return false;
223
+ }
224
+ process.once("exit", () => admitted.release());
225
+ return true;
226
+ }
227
+ catch (err) {
228
+ console.error(`\`agend ${command}\` is refused: the service lock could not be checked (${err.message}).`);
229
+ process.exitCode = 1;
230
+ return false;
231
+ }
232
+ }
233
+ /**
234
+ * M-3770 (design update-transaction §4.2 step 3): a state-writing command holds the state lease for its whole run, and
235
+ * is refused while an update is in progress. Released when this process exits.
236
+ */
237
+ function holdStateLease(command) {
238
+ const taken = takeSharedLease(DATA_DIR, command);
239
+ if (!taken.ok) {
240
+ console.error(taken.reason);
241
+ process.exit(1);
242
+ }
243
+ process.once("exit", () => taken.lease.release());
244
+ }
245
+ /** The CLI's only way to open scheduler.db (it migrates on open, so even a read writes): under the state lease. */
246
+ function openCliSchedulerDb() {
247
+ holdStateLease("schedule");
248
+ return new SchedulerDb(join(DATA_DIR, "scheduler.db"));
249
+ }
173
250
  function claimFleetSingleton() {
251
+ const home = admitAgainstHomeUpdate();
252
+ if (!home.ok)
253
+ return false;
174
254
  try {
175
- setProcessFleetLock(acquireFleetLock(DATA_DIR));
255
+ // M-3770 §4.3, §7: the journal first — an open, unknown or manual attempt refuses every start but the attempt's own
256
+ // (its planned nonce, AGEND_UPDATE_HANDOFF, while its updater lives). That start then takes the fence over by the
257
+ // journal's single-use claim.
258
+ const admission = createRequire(import.meta.url)("../launcher/install-admission.cjs");
259
+ const liveness = { processStart: admission.processStart, startTicks: admission.startTicks, bootId: admission.bootId };
260
+ const gate = fleetStartGate(DATA_DIR, process.env.AGEND_UPDATE_HANDOFF ?? null, liveness);
261
+ if (!gate.ok)
262
+ throw new Error(gate.reason);
263
+ // §7 (rev 13; Fable #4533): an interrupted commit is this start's to finish with the fleet's commit hands
264
+ // (`resumeCommitting`). Until those hands exist, it is refused, never admitted as a plain start that leaves the attempt
265
+ // committing for good. The `agend update` wiring replaces this refusal with the resumeCommitting(...) call.
266
+ if (gate.resumeCommitting)
267
+ throw new Error(`This fleet start is refused: update attempt ${gate.resumeCommitting} is committing, and this build can't finish it yet. Run \`agend update --resolve\`.`);
268
+ setProcessFleetLock(acquireFleetLock(DATA_DIR, {
269
+ claimHandoff: (attemptId, nonce, pid) => {
270
+ const processStart = admission.processStart(pid);
271
+ if (!processStart)
272
+ return false;
273
+ const ticks = admission.startTicks(pid), boot = admission.bootId();
274
+ const start = { processStart, ...(ticks !== null && boot !== null ? { startTicks: ticks, bootId: boot } : {}) };
275
+ return claimHandoff(DATA_DIR, attemptId, nonce, { pid, start }, liveness);
276
+ },
277
+ }));
278
+ home.release();
176
279
  process.once("exit", () => { releaseProcessFleetLock(); });
177
280
  // Before anything is spawned, so a tmux server the fleet starts inherits it
178
281
  // (each CLI launch also sets it in its pane: coredumpFilterLaunchPrefix).
@@ -180,6 +283,7 @@ function claimFleetSingleton() {
180
283
  return true;
181
284
  }
182
285
  catch (err) {
286
+ home.release();
183
287
  console.error(err.message);
184
288
  process.exitCode = 1;
185
289
  return false;
@@ -1270,6 +1374,7 @@ topic
1270
1374
  console.error(`Instance "${instance}" not found in fleet config`);
1271
1375
  process.exit(1);
1272
1376
  }
1377
+ holdStateLease("topic");
1273
1378
  applyFleetYamlPatches(FLEET_CONFIG_PATH, [{ path: ["instances", instance, "topic_id"], value: topicId }]);
1274
1379
  console.log(`Bound ${instance} \u2192 topic #${topicId}`);
1275
1380
  });
@@ -1285,6 +1390,7 @@ topic
1285
1390
  console.error(`Instance "${instance}" not found in fleet config`);
1286
1391
  process.exit(1);
1287
1392
  }
1393
+ holdStateLease("topic");
1288
1394
  applyFleetYamlPatches(FLEET_CONFIG_PATH, [{ path: ["instances", instance, "topic_id"], remove: true }]);
1289
1395
  console.log(`Unbound ${instance} from topic`);
1290
1396
  });
@@ -1418,10 +1524,19 @@ program
1418
1524
  // and its `npm install -g`) gives up on a silent connection instead of waiting minutes per try — set once, in this
1419
1525
  // process's environment, for each key nobody set (a person's .npmrc, variable or flag is kept, whatever its value).
1420
1526
  {
1421
- const { applyUpdateNpmBounds, npmConfigQuery, parseNpmConfigLs, registryStop, updateRegistry } = await import("./update-npm-env.js");
1527
+ const { applyUpdateAllowScripts, applyUpdateNpmBounds, npmConfigQuery, parseNpmConfigLs, registryStop, scriptsIgnoredStop, updateRegistry, updateScriptsIgnored } = await import("./update-npm-env.js");
1422
1528
  const listed = spawnSync("npm", npmConfigQuery(), { encoding: "utf-8", timeout: 15_000, stdio: ["ignore", "pipe", "ignore"] });
1423
1529
  const explicit = listed.status === 0 ? parseNpmConfigLs(listed.stdout ?? "") : null;
1530
+ // M-3805: npm set to skip install scripts would install a release that cannot start: stop before anything changes.
1531
+ if (updateScriptsIgnored(process.env, explicit)) {
1532
+ const stop = scriptsIgnoredStop();
1533
+ console.error(`\n${stop}\n`);
1534
+ setUpdateProgressStage(DATA_DIR, "failed", { error: stop.trim() });
1535
+ process.exitCode = 1;
1536
+ return;
1537
+ }
1424
1538
  applyUpdateNpmBounds(process.env, explicit);
1539
+ applyUpdateAllowScripts(process.env, explicit); // M-3805: npm 12 runs AgEnD's install scripts only when allowed
1425
1540
  // With the network gone npm answers the version lookup from its stale cache, and the install then fails as a version
1426
1541
  // that does not exist. Ask the registry AgEnD comes from (the @songsid scope's, never a cache) first: unreachable →
1427
1542
  // stop here, nothing changed. Its config unreadable: nothing is asked, the update goes on as before.
@@ -1677,13 +1792,13 @@ program
1677
1792
  const { verifyInstalledPackage } = await import("./update-install.js");
1678
1793
  const verified = verifyInstalledPackage({ pkg: `@songsid/agend@${pkgVersion}`, targetVersion: pkgVersion, viaNvm: false, nvmSh }, {
1679
1794
  run: (command, args, options = {}) => {
1680
- const result = spawnSync(command, args, { encoding: "utf-8", timeout: options.timeoutMs, stdio: ["ignore", "pipe", "pipe"] });
1795
+ const result = spawnSync(command, args, { encoding: "utf-8", timeout: options.timeoutMs, stdio: ["ignore", "pipe", "pipe"], ...(options.cwd ? { cwd: options.cwd } : {}) });
1681
1796
  return { status: result.status, signal: result.signal, stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
1682
1797
  },
1683
1798
  log: message => console.log(message),
1684
1799
  });
1685
1800
  if (!verified.ok) {
1686
- const message = `${verified.message}\n Not restarting the fleet onto it. Reinstall a working version: npm install -g @songsid/agend@<version>`;
1801
+ const message = `${verified.message}\n Not restarting the fleet onto it. Reinstall a working version: npm install -g --allow-scripts=@songsid/agend @songsid/agend@<version>`;
1687
1802
  console.error(message);
1688
1803
  setUpdateProgressStage(DATA_DIR, "failed", { error: message.trim() });
1689
1804
  process.exitCode = 1;
@@ -1739,7 +1854,22 @@ program
1739
1854
  // ── Check if npm global needs sudo (read-only; decides the nvm path the preflight judges) ──
1740
1855
  let needsSudo = false;
1741
1856
  try {
1742
- const prefix = execSync("npm config get prefix", { encoding: "utf-8" }).trim();
1857
+ // M-3806: for a UUID in the path, `npm config get prefix` refuses (npm 10–12): read `npm prefix -g`, which npm
1858
+ // 11/12 print with `***`; that is asked the way npm tells a child, from the filesystem root (Fable #4526 F2).
1859
+ // No answer at all: as before, assume no sudo.
1860
+ const quiet = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
1861
+ const said = (command, cwd) => { try {
1862
+ return execSync(command, cwd ? { ...quiet, cwd } : quiet);
1863
+ }
1864
+ catch {
1865
+ return "";
1866
+ } };
1867
+ let configured = said("npm config get prefix");
1868
+ if (!npmGlobalPrefix.lastLine(configured) || npmGlobalPrefix.masked(configured))
1869
+ configured = said("npm prefix -g");
1870
+ const prefix = npmGlobalPrefix.resolve(configured, undefined, () => said(`npm ${npmGlobalPrefix.ASK.slice(0, 2).join(" ")} "${npmGlobalPrefix.ASK[2]}"`, npmGlobalPrefix.neutralCwd())).prefix;
1871
+ if (!prefix)
1872
+ throw new Error("npm did not say where it installs global packages");
1743
1873
  const { accessSync, constants } = await import("node:fs");
1744
1874
  try {
1745
1875
  accessSync(prefix, constants.W_OK);
@@ -1800,8 +1930,11 @@ program
1800
1930
  markUpdateInProgress(DATA_DIR);
1801
1931
  setUpdateProgressStage(DATA_DIR, "downloading", { version: targetVersion });
1802
1932
  // AGEND_UPDATE_OWNER_PID: the marker this process just wrote is the installer's to carry on (and no one else's).
1933
+ // M-3812: from the filesystem (drive) root, never the folder `agend update` was started in. Inside a project npm
1934
+ // exec puts its node_modules/.bin first on PATH, and the installer would run on that project's own `node`. `pkg`
1935
+ // is a registry spec (an exact version), so it does not depend on the folder.
1803
1936
  const installer = spawnSync("npm", ["exec", "--yes", "--package", pkg, "--", "agend-install", "--upgrade", "--target", targetVersion], {
1804
- stdio: "inherit", env: { ...withOrigin("agend-update"), AGEND_UPDATE_OWNER_PID: String(process.pid) },
1937
+ stdio: "inherit", cwd: parse(process.cwd()).root, env: { ...withOrigin("agend-update"), AGEND_UPDATE_OWNER_PID: String(process.pid) },
1805
1938
  });
1806
1939
  if (installer.status === 0 || installer.status === 75) {
1807
1940
  process.exitCode = installer.status ?? 0;
@@ -1871,13 +2004,34 @@ program
1871
2004
  ? { preflight: preflight.installPreflight(pkg, targetVersion, "the Node 22 nvm selected", { log: m => console.log(m), error: m => console.error(m) }) }
1872
2005
  : {}),
1873
2006
  lock: prefix => {
1874
- const lock = acquireInstallLock(prefix, { spec: pkg, agendHome: DATA_DIR }, {
2007
+ const lockDeps = {
1875
2008
  pid: process.pid, processStart: admission.processStart, startTicks: admission.startTicks, bootId: admission.bootId, newToken: () => randomBytes(16).toString("hex"),
1876
- now: () => new Date(), log: message => console.log(message),
1877
- });
1878
- if (!lock.ok)
2009
+ now: () => new Date(), log: (message) => console.log(message),
2010
+ };
2011
+ // M-3770 (#4480 §4.2): the home first — another install updating this home (a second prefix the prefix lock
2012
+ // never sees) refuses this one — then the prefix. Both are held until this process exits.
2013
+ let installPrefix = prefix;
2014
+ try {
2015
+ installPrefix = realpathSync(prefix);
2016
+ }
2017
+ catch { /* the prefix lock below says so */ }
2018
+ // A home no fleet has made yet (an update right after a fresh install) is made here, privately, as the fleet
2019
+ // lock makes it: the lock lives in it, and a missing home is no reason to refuse.
2020
+ try {
2021
+ ensureAgendHome(DATA_DIR);
2022
+ }
2023
+ catch (err) {
2024
+ return { ok: false, path: DATA_DIR, reason: `the AgEnD home ${DATA_DIR} could not be made (${err.message})` };
2025
+ }
2026
+ const home = acquireHomeUpdateLock(DATA_DIR, { spec: pkg, installPrefix }, lockDeps);
2027
+ if (!home.ok)
2028
+ return home;
2029
+ const lock = acquireInstallLock(prefix, { spec: pkg, agendHome: DATA_DIR }, lockDeps);
2030
+ if (!lock.ok) {
2031
+ home.release();
1879
2032
  return lock;
1880
- releaseLock = lock.release;
2033
+ }
2034
+ releaseLock = () => { lock.release(); home.release(); };
1881
2035
  return { ok: true, token: lock.token };
1882
2036
  },
1883
2037
  }, {
@@ -1889,6 +2043,7 @@ program
1889
2043
  timeout: options.timeoutMs,
1890
2044
  stdio: options.inherit ? "inherit" : ["ignore", "pipe", "pipe"],
1891
2045
  ...(options.env ? { env: { ...process.env, ...options.env } } : {}),
2046
+ ...(options.cwd ? { cwd: options.cwd } : {}),
1892
2047
  });
1893
2048
  return { status: result.status, signal: result.signal, stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
1894
2049
  },
@@ -1930,6 +2085,8 @@ program
1930
2085
  .addOption(new Option("--activate").hideHelp())
1931
2086
  .option("--no-activate", "Write the service file without activating it")
1932
2087
  .action(async (opts) => {
2088
+ if (!guardServiceCommand("install"))
2089
+ return; // M-3770: not while an update owns the service
1933
2090
  if (process.argv.includes("--activate")) {
1934
2091
  console.error(t("cli.install_activate_removed"));
1935
2092
  }
@@ -2155,6 +2312,8 @@ program
2155
2312
  .action(async (opts) => {
2156
2313
  if (!gateFleetControl(DATA_DIR, "stop", { yes: opts.yes }))
2157
2314
  process.exit(1);
2315
+ if (!guardServiceCommand("stop"))
2316
+ return; // M-3770: not while an update owns the service
2158
2317
  // #2481: a deliberate stop — the start attempts so far are not a crash loop.
2159
2318
  {
2160
2319
  const { clearStartAttempts } = await import("./start-failure.js");
@@ -2217,6 +2376,8 @@ program
2217
2376
  .command("start")
2218
2377
  .description("Start the AgEnD service, or start a detached fleet if no service is installed")
2219
2378
  .action(async () => {
2379
+ if (!guardServiceCommand("start"))
2380
+ return; // M-3770: not while an update owns the service
2220
2381
  const { getServicePath, getSystemServicePath, startService, startSystemService } = await import("./service-installer.js");
2221
2382
  const userServicePath = getServicePath();
2222
2383
  const systemServicePath = getSystemServicePath();
@@ -2316,6 +2477,8 @@ program
2316
2477
  .option("-y, --yes", "Confirm when run from a fleet agent session (this affects every instance)")
2317
2478
  .option("--force", "Restart even when the loaded service does not start this install on its selected Node (operators only)")
2318
2479
  .action(async (instance, opts) => {
2480
+ if (!instance && !guardServiceCommand("restart"))
2481
+ return; // M-3770: the whole service, not while an update owns it
2319
2482
  if (instance) {
2320
2483
  if (opts.force) {
2321
2484
  console.error(t("cli.force_whole_service"));
@@ -3103,7 +3266,7 @@ schedule
3103
3266
  .option("--target <instance>", "Filter by target instance")
3104
3267
  .option("--json", "Output as JSON")
3105
3268
  .action((opts) => {
3106
- const db = new SchedulerDb(join(DATA_DIR, "scheduler.db"));
3269
+ const db = openCliSchedulerDb();
3107
3270
  try {
3108
3271
  const schedules = db.list(opts.target);
3109
3272
  if (opts.json) {
@@ -3140,7 +3303,7 @@ schedule
3140
3303
  console.error(`Invalid cron expression: ${err.message}`);
3141
3304
  process.exit(1);
3142
3305
  }
3143
- const db = new SchedulerDb(join(DATA_DIR, "scheduler.db"));
3306
+ const db = openCliSchedulerDb();
3144
3307
  try {
3145
3308
  const s = db.create({
3146
3309
  cron: opts.cron,
@@ -3170,7 +3333,7 @@ schedule
3170
3333
  .option("--timezone <tz>", "New timezone")
3171
3334
  .option("--enabled <bool>", "Enable/disable (true/false)")
3172
3335
  .action((id, opts) => {
3173
- const db = new SchedulerDb(join(DATA_DIR, "scheduler.db"));
3336
+ const db = openCliSchedulerDb();
3174
3337
  try {
3175
3338
  const params = {};
3176
3339
  if (opts.cron)
@@ -3198,7 +3361,7 @@ schedule
3198
3361
  .description("Delete a schedule")
3199
3362
  .argument("<id>", "Schedule ID")
3200
3363
  .action((id) => {
3201
- const db = new SchedulerDb(join(DATA_DIR, "scheduler.db"));
3364
+ const db = openCliSchedulerDb();
3202
3365
  try {
3203
3366
  db.delete(id);
3204
3367
  console.log(`Deleted schedule ${id}`);
@@ -3213,7 +3376,7 @@ schedule
3213
3376
  .description("Enable a schedule")
3214
3377
  .argument("<id>", "Schedule ID")
3215
3378
  .action((id) => {
3216
- const db = new SchedulerDb(join(DATA_DIR, "scheduler.db"));
3379
+ const db = openCliSchedulerDb();
3217
3380
  try {
3218
3381
  db.update(id, { enabled: true });
3219
3382
  console.log(`Enabled schedule ${id}`);
@@ -3228,7 +3391,7 @@ schedule
3228
3391
  .description("Disable a schedule")
3229
3392
  .argument("<id>", "Schedule ID")
3230
3393
  .action((id) => {
3231
- const db = new SchedulerDb(join(DATA_DIR, "scheduler.db"));
3394
+ const db = openCliSchedulerDb();
3232
3395
  try {
3233
3396
  db.update(id, { enabled: false });
3234
3397
  console.log(`Disabled schedule ${id}`);
@@ -3244,7 +3407,7 @@ schedule
3244
3407
  .argument("<id>", "Schedule ID")
3245
3408
  .option("--limit <n>", "Number of runs to show", "20")
3246
3409
  .action((id, opts) => {
3247
- const db = new SchedulerDb(join(DATA_DIR, "scheduler.db"));
3410
+ const db = openCliSchedulerDb();
3248
3411
  try {
3249
3412
  const runs = db.getRuns(id, parseInt(opts.limit, 10));
3250
3413
  if (runs.length === 0) {
@@ -4100,7 +4263,7 @@ program
4100
4263
  }
4101
4264
  return false;
4102
4265
  },
4103
- async install(v) { const r = spawnSync("npm", ["install", "-g", opts.package ?? `@songsid/agend@${v}`], { stdio: "inherit" }); return { ok: r.status === 0, detail: `npm exited ${r.status ?? r.signal}` }; },
4266
+ async install(v) { const spec = opts.package ?? `@songsid/agend@${v}`; const r = spawnSync("npm", ["install", "-g", spec, npmAllowScripts.flagFor(spec)], { stdio: "inherit" }); return { ok: r.status === 0, detail: `npm exited ${r.status ?? r.signal}` }; },
4104
4267
  // The newly installed version's own `agend start` (the one now on PATH), never this process's code.
4105
4268
  async startService() {
4106
4269
  if (opts.start === false)