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

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 (488) 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-file-read.js +1 -1
  8. package/dist/agent-file-read.js.map +1 -1
  9. package/dist/agent-workspace.d.ts +18 -2
  10. package/dist/agent-workspace.js +15 -4
  11. package/dist/agent-workspace.js.map +1 -1
  12. package/dist/auth-api.js +3 -1
  13. package/dist/auth-api.js.map +1 -1
  14. package/dist/backend/antigravity.js +8 -6
  15. package/dist/backend/antigravity.js.map +1 -1
  16. package/dist/backend/claude-code.js +17 -0
  17. package/dist/backend/claude-code.js.map +1 -1
  18. package/dist/backend/claude-usage-credits.d.ts +8 -0
  19. package/dist/backend/claude-usage-credits.js +121 -0
  20. package/dist/backend/claude-usage-credits.js.map +1 -0
  21. package/dist/backend/types.d.ts +30 -0
  22. package/dist/backend/types.js.map +1 -1
  23. package/dist/build-provenance.json +1 -1
  24. package/dist/channel/adapters/discord.js +7 -1
  25. package/dist/channel/adapters/discord.js.map +1 -1
  26. package/dist/channel/mcp-tools.js +1 -1
  27. package/dist/channel/mcp-tools.js.map +1 -1
  28. package/dist/channel/tool-router.js +1 -0
  29. package/dist/channel/tool-router.js.map +1 -1
  30. package/dist/cli-audited.js +9 -4
  31. package/dist/cli-audited.js.map +1 -1
  32. package/dist/cli.js +184 -21
  33. package/dist/cli.js.map +1 -1
  34. package/dist/config-validator.js +11 -1
  35. package/dist/config-validator.js.map +1 -1
  36. package/dist/config.js +2 -0
  37. package/dist/config.js.map +1 -1
  38. package/dist/contact-auth-store.d.ts +18 -0
  39. package/dist/contact-auth-store.js +55 -8
  40. package/dist/contact-auth-store.js.map +1 -1
  41. package/dist/contact-auth-types.d.ts +3 -0
  42. package/dist/contact-auth-types.js.map +1 -1
  43. package/dist/contact-change-proposals.d.ts +34 -0
  44. package/dist/contact-change-proposals.js +1 -1
  45. package/dist/contact-change-proposals.js.map +1 -1
  46. package/dist/cross-instance-notice.d.ts +1 -0
  47. package/dist/cross-instance-notice.js +9 -8
  48. package/dist/cross-instance-notice.js.map +1 -1
  49. package/dist/daemon.d.ts +35 -0
  50. package/dist/daemon.js +234 -19
  51. package/dist/daemon.js.map +1 -1
  52. package/dist/delivery-outbox.d.ts +42 -1
  53. package/dist/delivery-outbox.js +198 -21
  54. package/dist/delivery-outbox.js.map +1 -1
  55. package/dist/fleet-context.d.ts +8 -0
  56. package/dist/fleet-lock.d.ts +83 -2
  57. package/dist/fleet-lock.js +276 -2
  58. package/dist/fleet-lock.js.map +1 -1
  59. package/dist/fleet-manager.d.ts +183 -7
  60. package/dist/fleet-manager.js +1279 -78
  61. package/dist/fleet-manager.js.map +1 -1
  62. package/dist/fleet-windows-runtime.d.ts +20 -1
  63. package/dist/fleet-windows-runtime.js +98 -18
  64. package/dist/fleet-windows-runtime.js.map +1 -1
  65. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +13 -1
  66. package/dist/general-knowledge/skills/hub/SKILL.md +12 -1
  67. package/dist/general-knowledge/skills/web-appearance/SKILL.md +3 -1
  68. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +21 -4
  69. package/dist/home-update-lock.d.ts +35 -0
  70. package/dist/home-update-lock.js +81 -0
  71. package/dist/home-update-lock.js.map +1 -0
  72. package/dist/hub/client.js +7 -0
  73. package/dist/hub/client.js.map +1 -1
  74. package/dist/hub/compose/member.d.ts +5 -1
  75. package/dist/hub/compose/member.js +15 -6
  76. package/dist/hub/compose/member.js.map +1 -1
  77. package/dist/hub/compose/server.d.ts +1 -0
  78. package/dist/hub/compose/server.js +3 -2
  79. package/dist/hub/compose/server.js.map +1 -1
  80. package/dist/hub/http/compose.js +3 -2
  81. package/dist/hub/http/compose.js.map +1 -1
  82. package/dist/hub/http/deps.d.ts +1 -0
  83. package/dist/hub/member/room-ask.d.ts +12 -8
  84. package/dist/hub/member/room-ask.js +95 -29
  85. package/dist/hub/member/room-ask.js.map +1 -1
  86. package/dist/hub/member/room-mention-feedback.d.ts +2 -0
  87. package/dist/hub/member/room-mention-feedback.js +1 -1
  88. package/dist/hub/member/room-mention-feedback.js.map +1 -1
  89. package/dist/hub/member/room-post-answers.d.ts +2 -0
  90. package/dist/hub/member/room-post-answers.js +1 -1
  91. package/dist/hub/member/room-post-answers.js.map +1 -1
  92. package/dist/hub/member/room-post.d.ts +5 -0
  93. package/dist/hub/member/room-post.js +4 -1
  94. package/dist/hub/member/room-post.js.map +1 -1
  95. package/dist/hub/member/room-reaction-acks.d.ts +12 -0
  96. package/dist/hub/member/room-reaction-acks.js +44 -0
  97. package/dist/hub/member/room-reaction-acks.js.map +1 -0
  98. package/dist/hub/member/updates.d.ts +7 -1
  99. package/dist/hub/member/updates.js +7 -1
  100. package/dist/hub/member/updates.js.map +1 -1
  101. package/dist/hub/protocol.d.ts +4 -0
  102. package/dist/hub/protocol.js +2 -2
  103. package/dist/hub/protocol.js.map +1 -1
  104. package/dist/hub/representative.d.ts +7 -0
  105. package/dist/hub/representative.js +38 -5
  106. package/dist/hub/representative.js.map +1 -1
  107. package/dist/hub/roles/audit-details.d.ts +2 -0
  108. package/dist/hub/roles/audit-details.js +1 -1
  109. package/dist/hub/roles/audit-details.js.map +1 -1
  110. package/dist/hub/roles/authority.d.ts +8 -3
  111. package/dist/hub/roles/authority.js +144 -102
  112. package/dist/hub/roles/authority.js.map +1 -1
  113. package/dist/hub/roles/delegation.js +2 -2
  114. package/dist/hub/roles/delegation.js.map +1 -1
  115. package/dist/hub/roles/model.d.ts +5 -2
  116. package/dist/hub/roles/model.js +5 -4
  117. package/dist/hub/roles/model.js.map +1 -1
  118. package/dist/hub/roles/review.js +2 -2
  119. package/dist/hub/roles/review.js.map +1 -1
  120. package/dist/hub/room-react-ack-model.d.ts +2 -0
  121. package/dist/hub/room-react-ack-model.js +3 -0
  122. package/dist/hub/room-react-ack-model.js.map +1 -0
  123. package/dist/hub/rooms/admin.d.ts +6 -0
  124. package/dist/hub/rooms/admin.js +33 -0
  125. package/dist/hub/rooms/admin.js.map +1 -1
  126. package/dist/hub/rooms/agents.d.ts +2 -0
  127. package/dist/hub/rooms/agents.js +44 -3
  128. package/dist/hub/rooms/agents.js.map +1 -1
  129. package/dist/hub/rooms/service.d.ts +5 -1
  130. package/dist/hub/rooms/service.js +76 -24
  131. package/dist/hub/rooms/service.js.map +1 -1
  132. package/dist/hub/rooms/types.d.ts +2 -0
  133. package/dist/hub/server.js +6 -1
  134. package/dist/hub/server.js.map +1 -1
  135. package/dist/hub/types.d.ts +2 -0
  136. package/dist/install-lock.d.ts +15 -1
  137. package/dist/install-lock.js +16 -8
  138. package/dist/install-lock.js.map +1 -1
  139. package/dist/install-ownership.d.ts +165 -0
  140. package/dist/install-ownership.js +404 -0
  141. package/dist/install-ownership.js.map +1 -0
  142. package/dist/instance-config-impact.js +2 -0
  143. package/dist/instance-config-impact.js.map +1 -1
  144. package/dist/instructions.d.ts +4 -0
  145. package/dist/instructions.js +4 -0
  146. package/dist/instructions.js.map +1 -1
  147. package/dist/local-pane-endpoint.d.ts +4 -1
  148. package/dist/local-pane-endpoint.js +12 -2
  149. package/dist/local-pane-endpoint.js.map +1 -1
  150. package/dist/locale.js +162 -6
  151. package/dist/locale.js.map +1 -1
  152. package/dist/native-agent-admission.d.ts +7 -0
  153. package/dist/native-agent-admission.js +46 -3
  154. package/dist/native-agent-admission.js.map +1 -1
  155. package/dist/native-mcp.d.ts +16 -1
  156. package/dist/native-mcp.js +38 -5
  157. package/dist/native-mcp.js.map +1 -1
  158. package/dist/native-pane-lifecycle.d.ts +9 -0
  159. package/dist/native-pane-lifecycle.js +23 -0
  160. package/dist/native-pane-lifecycle.js.map +1 -1
  161. package/dist/native-pane-manager.d.ts +19 -6
  162. package/dist/native-pane-manager.js +79 -4
  163. package/dist/native-pane-manager.js.map +1 -1
  164. package/dist/needs-you.d.ts +8 -0
  165. package/dist/needs-you.js +1 -0
  166. package/dist/needs-you.js.map +1 -1
  167. package/dist/outbound-handlers.d.ts +12 -0
  168. package/dist/outbound-handlers.js +30 -2
  169. package/dist/outbound-handlers.js.map +1 -1
  170. package/dist/package-preimage.js +4 -0
  171. package/dist/package-preimage.js.map +1 -1
  172. package/dist/pane-port.d.ts +1 -0
  173. package/dist/plist-args.d.ts +9 -0
  174. package/dist/plist-args.js +22 -0
  175. package/dist/plist-args.js.map +1 -0
  176. package/dist/public-preview.d.ts +4 -6
  177. package/dist/public-preview.js +5 -2
  178. package/dist/public-preview.js.map +1 -1
  179. package/dist/public-web-gateway.js +10 -3
  180. package/dist/public-web-gateway.js.map +1 -1
  181. package/dist/public-web-link.d.ts +13 -1
  182. package/dist/public-web-link.js +28 -1
  183. package/dist/public-web-link.js.map +1 -1
  184. package/dist/recover.cjs +2638 -0
  185. package/dist/remote-card-prompt.d.ts +6 -2
  186. package/dist/remote-card-prompt.js +12 -3
  187. package/dist/remote-card-prompt.js.map +1 -1
  188. package/dist/reply-draft.d.ts +12 -0
  189. package/dist/reply-draft.js +81 -0
  190. package/dist/reply-draft.js.map +1 -0
  191. package/dist/request-contact-api.d.ts +15 -0
  192. package/dist/request-contact-api.js +120 -0
  193. package/dist/request-contact-api.js.map +1 -0
  194. package/dist/request-contact-card.d.ts +36 -0
  195. package/dist/request-contact-card.js +206 -0
  196. package/dist/request-contact-card.js.map +1 -0
  197. package/dist/request-contact-gate.d.ts +79 -0
  198. package/dist/request-contact-gate.js +262 -0
  199. package/dist/request-contact-gate.js.map +1 -0
  200. package/dist/request-contact-native.d.ts +52 -0
  201. package/dist/request-contact-native.js +87 -0
  202. package/dist/request-contact-native.js.map +1 -0
  203. package/dist/request-contact-types.d.ts +86 -0
  204. package/dist/request-contact-types.js +7 -0
  205. package/dist/request-contact-types.js.map +1 -0
  206. package/dist/request-context-call-protocol.d.ts +12 -0
  207. package/dist/request-context-call-protocol.js +14 -0
  208. package/dist/request-context-call-protocol.js.map +1 -0
  209. package/dist/request-context-call.d.ts +22 -0
  210. package/dist/request-context-call.js +35 -0
  211. package/dist/request-context-call.js.map +1 -0
  212. package/dist/request-context-drain.d.ts +39 -0
  213. package/dist/request-context-drain.js +159 -0
  214. package/dist/request-context-drain.js.map +1 -0
  215. package/dist/request-context-fence.d.ts +28 -0
  216. package/dist/request-context-fence.js +58 -0
  217. package/dist/request-context-fence.js.map +1 -0
  218. package/dist/request-context-migration.d.ts +64 -0
  219. package/dist/request-context-migration.js +158 -0
  220. package/dist/request-context-migration.js.map +1 -0
  221. package/dist/request-context-pane.d.ts +25 -0
  222. package/dist/request-context-pane.js +48 -0
  223. package/dist/request-context-pane.js.map +1 -0
  224. package/dist/request-context-policy.d.ts +74 -0
  225. package/dist/request-context-policy.js +116 -0
  226. package/dist/request-context-policy.js.map +1 -0
  227. package/dist/request-context-recovery.d.ts +14 -0
  228. package/dist/request-context-recovery.js +56 -0
  229. package/dist/request-context-recovery.js.map +1 -0
  230. package/dist/request-context-relay.d.ts +19 -0
  231. package/dist/request-context-relay.js +63 -0
  232. package/dist/request-context-relay.js.map +1 -0
  233. package/dist/request-context-returns.d.ts +67 -0
  234. package/dist/request-context-returns.js +211 -0
  235. package/dist/request-context-returns.js.map +1 -0
  236. package/dist/request-context-store.d.ts +2 -1
  237. package/dist/request-context-store.js +8 -1
  238. package/dist/request-context-store.js.map +1 -1
  239. package/dist/request-context-turns.d.ts +99 -0
  240. package/dist/request-context-turns.js +215 -0
  241. package/dist/request-context-turns.js.map +1 -0
  242. package/dist/request-context-view.d.ts +33 -0
  243. package/dist/request-context-view.js +36 -0
  244. package/dist/request-context-view.js.map +1 -0
  245. package/dist/request-hub-context.d.ts +130 -0
  246. package/dist/request-hub-context.js +89 -0
  247. package/dist/request-hub-context.js.map +1 -0
  248. package/dist/request-hub-output.d.ts +11 -0
  249. package/dist/request-hub-output.js +21 -0
  250. package/dist/request-hub-output.js.map +1 -0
  251. package/dist/runtime-cli-install.js +13 -11
  252. package/dist/runtime-cli-install.js.map +1 -1
  253. package/dist/runtime-client.d.ts +2 -0
  254. package/dist/runtime-client.js +17 -4
  255. package/dist/runtime-client.js.map +1 -1
  256. package/dist/runtime-coordinator.d.ts +4 -1
  257. package/dist/runtime-coordinator.js +10 -3
  258. package/dist/runtime-coordinator.js.map +1 -1
  259. package/dist/runtime-pane-assets.d.ts +1 -1
  260. package/dist/runtime-pane-assets.js +1 -1
  261. package/dist/runtime-pane-assets.js.map +1 -1
  262. package/dist/runtime-pane-host.d.ts +3 -0
  263. package/dist/runtime-pane-host.js +39 -21
  264. package/dist/runtime-pane-host.js.map +1 -1
  265. package/dist/runtime-pane-link.d.ts +6 -2
  266. package/dist/runtime-pane-link.js +17 -4
  267. package/dist/runtime-pane-link.js.map +1 -1
  268. package/dist/runtime-pane-mcp-relay.d.ts +11 -1
  269. package/dist/runtime-pane-mcp-relay.js +69 -3
  270. package/dist/runtime-pane-mcp-relay.js.map +1 -1
  271. package/dist/runtime-pane-mcp.d.ts +28 -1
  272. package/dist/runtime-pane-mcp.js +92 -15
  273. package/dist/runtime-pane-mcp.js.map +1 -1
  274. package/dist/runtime-pane-port.d.ts +6 -0
  275. package/dist/runtime-pane-port.js +23 -4
  276. package/dist/runtime-pane-port.js.map +1 -1
  277. package/dist/runtime-pane-protocol.d.ts +4 -0
  278. package/dist/runtime-pane-protocol.js +11 -4
  279. package/dist/runtime-pane-protocol.js.map +1 -1
  280. package/dist/runtime-pane-service.d.ts +1 -0
  281. package/dist/runtime-pane-service.js +25 -9
  282. package/dist/runtime-pane-service.js.map +1 -1
  283. package/dist/runtime-pane-stdio-protocol.d.ts +4 -0
  284. package/dist/runtime-pane-stdio-protocol.js +12 -5
  285. package/dist/runtime-pane-stdio-protocol.js.map +1 -1
  286. package/dist/runtime-pane-stdio.js +5 -5
  287. package/dist/runtime-pane-stdio.js.map +1 -1
  288. package/dist/runtime-protocol.d.ts +3 -0
  289. package/dist/runtime-protocol.js.map +1 -1
  290. package/dist/scheduler/scheduler.d.ts +15 -0
  291. package/dist/scheduler/scheduler.js +45 -1
  292. package/dist/scheduler/scheduler.js.map +1 -1
  293. package/dist/scheduler/scheduler.test.js +17 -0
  294. package/dist/scheduler/scheduler.test.js.map +1 -1
  295. package/dist/scheduler/task-board.d.ts +4 -0
  296. package/dist/scheduler/task-board.js +6 -0
  297. package/dist/scheduler/task-board.js.map +1 -1
  298. package/dist/scheduler/types.d.ts +1 -1
  299. package/dist/service-activation.js +3 -13
  300. package/dist/service-activation.js.map +1 -1
  301. package/dist/service-lock.d.ts +28 -0
  302. package/dist/service-lock.js +85 -0
  303. package/dist/service-lock.js.map +1 -0
  304. package/dist/settings-api.d.ts +6 -0
  305. package/dist/settings-api.js +107 -0
  306. package/dist/settings-api.js.map +1 -1
  307. package/dist/settings-change.js +14 -1
  308. package/dist/settings-change.js.map +1 -1
  309. package/dist/settings-effect.js +11 -1
  310. package/dist/settings-effect.js.map +1 -1
  311. package/dist/state-lease.d.ts +24 -0
  312. package/dist/state-lease.js +103 -0
  313. package/dist/state-lease.js.map +1 -0
  314. package/dist/tmux-binary.js +1 -1
  315. package/dist/tmux-binary.js.map +1 -1
  316. package/dist/tool-receipt-output.d.ts +2 -0
  317. package/dist/topic-commands.js +21 -1
  318. package/dist/topic-commands.js.map +1 -1
  319. package/dist/transcript-monitor.js +3 -0
  320. package/dist/transcript-monitor.js.map +1 -1
  321. package/dist/tunnel/named-link-test.d.ts +27 -0
  322. package/dist/tunnel/named-link-test.js +41 -0
  323. package/dist/tunnel/named-link-test.js.map +1 -1
  324. package/dist/types.d.ts +7 -0
  325. package/dist/ui/chat-store.js +5 -4
  326. package/dist/ui/contact-auth-strings.js +7 -2
  327. package/dist/ui/contact-permissions.js +10 -2
  328. package/dist/ui/fleet-office-card.js +15 -2
  329. package/dist/ui/fleet-office-pack.d.ts +2 -2
  330. package/dist/ui/fleet-office-pack.js +25 -8
  331. package/dist/ui/fleet-office-skin.js +33 -9
  332. package/dist/ui/fleet-office-vehicles.js +28 -11
  333. package/dist/ui/fleet-office-zones.js +10 -5
  334. package/dist/ui/fleet-office.js +158 -20
  335. package/dist/ui/fleet-task-files.js +1 -1
  336. package/dist/ui/hub-admin-rooms-strings.js +6 -2
  337. package/dist/ui/hub-admin-rooms.js +3 -1
  338. package/dist/ui/hub-group-search.js +2 -2
  339. package/dist/ui/hub-notify-keep.js +49 -0
  340. package/dist/ui/hub-role-view.js +1 -1
  341. package/dist/ui/hub-roles-strings.js +14 -10
  342. package/dist/ui/hub-roles.js +1 -1
  343. package/dist/ui/hub-room-notify.js +2 -1
  344. package/dist/ui/hub-room-strings.js +3 -3
  345. package/dist/ui/hub-room-thread.js +9 -4
  346. package/dist/ui/panel-chat.js +15 -2
  347. package/dist/ui/panel-hub.js +3 -2
  348. package/dist/ui/panel-needs.js +35 -7
  349. package/dist/ui/panel-settings.js +22 -8
  350. package/dist/ui/settings-preview-address.js +156 -0
  351. package/dist/ui/settings-registry.js +2 -0
  352. package/dist/ui/settings-strings.js +6 -6
  353. package/dist/ui/settings-update.js +13 -0
  354. package/dist/ui/shared/app-install.js +123 -0
  355. package/dist/ui/shared/app-shell.js +4 -2
  356. package/dist/ui/shared/app-update.js +16 -2
  357. package/dist/ui/shared/app.css +119 -2
  358. package/dist/ui/shared/app.js +3 -0
  359. package/dist/ui/shared/chat-strings.js +6 -2
  360. package/dist/ui/shared/chat-thread.js +7 -1
  361. package/dist/ui/shared/hub-chat.css +6 -0
  362. package/dist/ui/shared/preview-panel.js +1 -1
  363. package/dist/ui/shared/preview.js +11 -2
  364. package/dist/ui/shared/tokens.css +18 -3
  365. package/dist/ui/shared/ui-confirm.js +7 -5
  366. package/dist/ui/shared/ui-icons.js +2 -0
  367. package/dist/ui/shared/update-card-ui.js +419 -0
  368. package/dist/ui/shared/workspace.css +7 -0
  369. package/dist/ui/usage-credits-card.js +84 -0
  370. package/dist/ui/workspace-ignored-strings.js +16 -0
  371. package/dist/ui/workspace-panel.js +15 -6
  372. package/dist/update-abandon.d.ts +26 -0
  373. package/dist/update-abandon.js +111 -0
  374. package/dist/update-abandon.js.map +1 -0
  375. package/dist/update-card.d.ts +193 -0
  376. package/dist/update-card.js +620 -0
  377. package/dist/update-card.js.map +1 -0
  378. package/dist/update-dispatch.d.ts +16 -1
  379. package/dist/update-dispatch.js +12 -4
  380. package/dist/update-dispatch.js.map +1 -1
  381. package/dist/update-forward.d.ts +59 -0
  382. package/dist/update-forward.js +227 -0
  383. package/dist/update-forward.js.map +1 -0
  384. package/dist/update-goback.d.ts +90 -0
  385. package/dist/update-goback.js +260 -0
  386. package/dist/update-goback.js.map +1 -0
  387. package/dist/update-idle.d.ts +1 -0
  388. package/dist/update-idle.js +12 -3
  389. package/dist/update-idle.js.map +1 -1
  390. package/dist/update-install.d.ts +2 -1
  391. package/dist/update-install.js +18 -10
  392. package/dist/update-install.js.map +1 -1
  393. package/dist/update-journal.d.ts +359 -0
  394. package/dist/update-journal.js +723 -0
  395. package/dist/update-journal.js.map +1 -0
  396. package/dist/update-launch.js +1 -1
  397. package/dist/update-launch.js.map +1 -1
  398. package/dist/update-npm-env.d.ts +45 -12
  399. package/dist/update-npm-env.js +48 -0
  400. package/dist/update-npm-env.js.map +1 -1
  401. package/dist/update-package-restore.d.ts +84 -0
  402. package/dist/update-package-restore.js +329 -0
  403. package/dist/update-package-restore.js.map +1 -0
  404. package/dist/update-quiescence.d.ts +221 -0
  405. package/dist/update-quiescence.js +370 -0
  406. package/dist/update-quiescence.js.map +1 -0
  407. package/dist/update-readiness-host.d.ts +61 -0
  408. package/dist/update-readiness-host.js +297 -0
  409. package/dist/update-readiness-host.js.map +1 -0
  410. package/dist/update-readiness.d.ts +83 -0
  411. package/dist/update-readiness.js +459 -0
  412. package/dist/update-readiness.js.map +1 -0
  413. package/dist/update-recovery/kit.d.ts +35 -0
  414. package/dist/update-recovery/kit.js +99 -0
  415. package/dist/update-recovery/kit.js.map +1 -0
  416. package/dist/update-recovery/pre-start.d.ts +34 -0
  417. package/dist/update-recovery/pre-start.js +103 -0
  418. package/dist/update-recovery/pre-start.js.map +1 -0
  419. package/dist/update-recovery/recover-main.d.ts +1 -0
  420. package/dist/update-recovery/recover-main.js +4 -0
  421. package/dist/update-recovery/recover-main.js.map +1 -0
  422. package/dist/update-recovery/recover.d.ts +22 -0
  423. package/dist/update-recovery/recover.js +134 -0
  424. package/dist/update-recovery/recover.js.map +1 -0
  425. package/dist/update-recovery/route.d.ts +53 -0
  426. package/dist/update-recovery/route.js +262 -0
  427. package/dist/update-recovery/route.js.map +1 -0
  428. package/dist/update-recovery/runner.d.ts +62 -0
  429. package/dist/update-recovery/runner.js +229 -0
  430. package/dist/update-recovery/runner.js.map +1 -0
  431. package/dist/update-recovery/service-manager.d.ts +39 -0
  432. package/dist/update-recovery/service-manager.js +57 -0
  433. package/dist/update-recovery/service-manager.js.map +1 -0
  434. package/dist/update-restore.d.ts +50 -0
  435. package/dist/update-restore.js +360 -0
  436. package/dist/update-restore.js.map +1 -0
  437. package/dist/update-retained.d.ts +65 -0
  438. package/dist/update-retained.js +116 -0
  439. package/dist/update-retained.js.map +1 -0
  440. package/dist/update-rollback.d.ts +74 -0
  441. package/dist/update-rollback.js +221 -0
  442. package/dist/update-rollback.js.map +1 -0
  443. package/dist/update-settings.d.ts +63 -0
  444. package/dist/update-settings.js +162 -0
  445. package/dist/update-settings.js.map +1 -0
  446. package/dist/update-snapshot-manifest.d.ts +32 -0
  447. package/dist/update-snapshot-manifest.js +65 -0
  448. package/dist/update-snapshot-manifest.js.map +1 -0
  449. package/dist/update-snapshot-scope.d.ts +67 -0
  450. package/dist/update-snapshot-scope.js +173 -0
  451. package/dist/update-snapshot-scope.js.map +1 -0
  452. package/dist/update-snapshot.d.ts +34 -0
  453. package/dist/update-snapshot.js +246 -0
  454. package/dist/update-snapshot.js.map +1 -0
  455. package/dist/update-writers.d.ts +71 -0
  456. package/dist/update-writers.js +235 -0
  457. package/dist/update-writers.js.map +1 -0
  458. package/dist/web-api.d.ts +3 -0
  459. package/dist/web-api.js +43 -8
  460. package/dist/web-api.js.map +1 -1
  461. package/dist/web-chat-history.d.ts +7 -0
  462. package/dist/web-chat-history.js +15 -0
  463. package/dist/web-chat-history.js.map +1 -1
  464. package/dist/web-icons.d.ts +11 -0
  465. package/dist/web-icons.js +14 -2
  466. package/dist/web-icons.js.map +1 -1
  467. package/dist/web-mentions.d.ts +27 -8
  468. package/dist/web-mentions.js +108 -1
  469. package/dist/web-mentions.js.map +1 -1
  470. package/dist/web-office-acts.js +3 -0
  471. package/dist/web-office-acts.js.map +1 -1
  472. package/dist/web-preview.d.ts +5 -0
  473. package/dist/web-preview.js +1 -1
  474. package/dist/web-preview.js.map +1 -1
  475. package/dist/web-update.d.ts +6 -0
  476. package/dist/windows-agents.d.ts +12 -0
  477. package/dist/windows-agents.js +5 -0
  478. package/dist/windows-agents.js.map +1 -1
  479. package/launcher/agend +4 -1
  480. package/launcher/agend-agent +4 -1
  481. package/launcher/agend-install.cjs +16 -8
  482. package/launcher/install-admission.d.cts +8 -0
  483. package/launcher/npm-allow-scripts.cjs +72 -0
  484. package/launcher/npm-global-prefix.cjs +81 -0
  485. package/launcher/postinstall.cjs +9 -8
  486. package/launcher/runtime-select.cjs +8 -2
  487. package/package.json +4 -3
  488. package/scripts/preinstall-guard.cjs +1 -1
@@ -0,0 +1,620 @@
1
+ /**
2
+ * One durable update offer per fleet (design #4480 §3.1, slice 1.1).
3
+ * Banner, Settings, chat `/update`, the Hub request and a scheduled time all read this object.
4
+ * Phase 1 changes words and timing only: today's updater still installs. Pre-flight is a seam
5
+ * for slice 1.2 — absent, nothing is refused with 412. `updates.mode: auto-when-idle` is stored
6
+ * and does not queue anything.
7
+ */
8
+ import { randomUUID } from "node:crypto";
9
+ import { mkdirSync, readFileSync, unlinkSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import Database from "better-sqlite3";
12
+ import { atomicWriteFileSync } from "./atomic-write.js";
13
+ import { IdleUpdateQueue, IDLE_UPDATE_MIGRATION } from "./update-idle.js";
14
+ import { installedChannel } from "./update-check.js";
15
+ import { readUpdateProgress } from "./update-marker.js";
16
+ import { inUpdatePause, resolveUpdates } from "./update-settings.js";
17
+ export const NOT_NOW_MS = 7 * 24 * 60 * 60_000;
18
+ export const PICK_WITHIN_MS = NOT_NOW_MS;
19
+ /** Same cadence as the Hub member's update tick: look again while a local row is waiting. */
20
+ const IDLE_POLL_MS = 5_000;
21
+ const CARD_FILE = "update-card.json";
22
+ const QUEUE_FILE = "update-idle.sqlite";
23
+ /** Progress-marker name for one local idle launch. The Hub uses its own prefix. */
24
+ export function idleUpdateMessageId(id) {
25
+ return `idle-update:${id}`;
26
+ }
27
+ /**
28
+ * What a leftover `updating` row became. `marker` is already this row's marker, or null.
29
+ * The running version means the install landed. A marker that reached the restart means it was rolled back.
30
+ */
31
+ export function idleClaimOutcome(version, current, marker) {
32
+ if (current && current.replace(/^v/, "") === version.replace(/^v/, ""))
33
+ return "done";
34
+ const stage = marker?.progress.stage;
35
+ const reachedRestart = stage === "installed" || stage === "stopping" || stage === "starting" || stage === "complete"
36
+ || (stage === "failed" && (marker?.progress.failedStage === "starting" || marker?.progress.failedStage === "stopping"));
37
+ return reachedRestart ? "rolled-back" : "failed";
38
+ }
39
+ /** A display label for lastAnswer.by. A bare id is never stored. */
40
+ export function updateAnswerLabel(label) {
41
+ const text = (label ?? "").trim().slice(0, 80);
42
+ if (!text || /^[0-9a-f-]{32,}$/i.test(text) || /^\d{6,}$/.test(text))
43
+ return "admin";
44
+ return text;
45
+ }
46
+ function stamp(ms) {
47
+ if (ms === undefined || !Number.isFinite(ms))
48
+ return "";
49
+ const d = new Date(ms);
50
+ const p = (n) => String(n).padStart(2, "0");
51
+ return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
52
+ }
53
+ /** Which chat line `/update` (not `/update now`) replies with. */
54
+ export function updateOfferReply(card, current, pinned) {
55
+ if (pinned)
56
+ return { key: "update.offer.pinned", args: [] };
57
+ const have = current ? `v${current}` : "AgEnD";
58
+ if (!card)
59
+ return { key: "update.offer.none", args: [have] };
60
+ const version = `v${card.version}`;
61
+ if (!card.installable)
62
+ return { key: "update.offer.stable", args: [version, have] };
63
+ switch (card.state) {
64
+ case "not-now": return { key: "update.offer.not_now", args: [version, have, stamp(card.notNowUntil)] };
65
+ case "waiting-idle": return { key: "update.offer.waiting", args: [version] };
66
+ case "scheduled": return { key: "update.offer.scheduled", args: [version, stamp(card.scheduledAt)] };
67
+ case "updating": return { key: "update.offer.updating", args: [version] };
68
+ case "done": return { key: "update.offer.done", args: [version] };
69
+ case "failed": return { key: "update.offer.failed", args: [version] };
70
+ case "cant": return { key: "update.offer.cant", args: [version] };
71
+ default: return { key: "update.offer.ready", args: [version, have] };
72
+ }
73
+ }
74
+ export class UpdateOfferCard {
75
+ deps;
76
+ db;
77
+ queue;
78
+ stored = null;
79
+ stopped = false;
80
+ /** Cancel/retarget notifies the queue; ignore that echo so it cannot overwrite the card mid-update. */
81
+ quiet = 0;
82
+ timer;
83
+ answers = new Map();
84
+ constructor(deps) {
85
+ this.deps = deps;
86
+ mkdirSync(deps.dataDir, { recursive: true });
87
+ this.db = new Database(join(deps.dataDir, QUEUE_FILE));
88
+ this.db.pragma("busy_timeout = 5000");
89
+ const exists = this.db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='fleet_idle_updates'").get();
90
+ if (!exists)
91
+ IDLE_UPDATE_MIGRATION.up(this.db);
92
+ this.queue = new IdleUpdateQueue({
93
+ db: this.db,
94
+ now: () => this.deps.now(),
95
+ current: () => !this.stopped,
96
+ // Pause and pin must not cancel the row. allowed() false is permission-revoked.
97
+ allowed: () => true,
98
+ idle: () => this.idle(),
99
+ launch: (row, control) => this.deps.launchIdle(row.version, control, row.id),
100
+ changed: row => this.mirrorLocal(row),
101
+ });
102
+ this.stored = this.read();
103
+ this.reconcileIdleClaim();
104
+ }
105
+ close() {
106
+ this.stopped = true;
107
+ clearTimeout(this.timer);
108
+ this.queue.close();
109
+ this.db.close();
110
+ }
111
+ /** Drop an offer the latest check no longer makes. Leaves a wait or an update alone. */
112
+ clearQuietOffer() {
113
+ if (!this.stored)
114
+ return;
115
+ if (this.stored.state !== "offered" && this.stored.state !== "not-now")
116
+ return;
117
+ this.stored = null;
118
+ this.save();
119
+ }
120
+ noteOffer(offer) {
121
+ if (this.stopped)
122
+ return;
123
+ const prev = this.stored;
124
+ if (prev?.owner === "hub" && (prev.state === "waiting-idle" || prev.state === "updating"))
125
+ return;
126
+ if (prev?.state === "updating")
127
+ return;
128
+ const next = {
129
+ ...(prev ?? { state: "offered" }),
130
+ version: offer.version,
131
+ channel: offer.channel,
132
+ installable: offer.installable,
133
+ ...(offer.notes ? { notes: offer.notes } : {}),
134
+ };
135
+ if (!offer.notes)
136
+ delete next.notes;
137
+ if (!prev || prev.state === "done" || prev.state === "failed" || prev.state === "cant")
138
+ next.state = "offered";
139
+ if (prev?.state === "not-now" && this.deps.now() >= (prev.notNowUntil ?? 0)) {
140
+ next.state = "offered";
141
+ delete next.notNowUntil;
142
+ }
143
+ this.stored = next;
144
+ if (next.state === "waiting-idle" && next.owner !== "hub")
145
+ this.retarget(offer.version);
146
+ this.save();
147
+ this.arm();
148
+ }
149
+ /** The immediate path has claimed the machine. Does not overwrite lastAnswer. */
150
+ beginRun(version) {
151
+ if (this.stopped)
152
+ return;
153
+ if (this.stored && this.stored.state !== "updating")
154
+ this.stopWait(this.stored);
155
+ const prev = this.stored;
156
+ this.stored = {
157
+ version: version || prev?.version || "",
158
+ channel: prev?.channel ?? "stable",
159
+ installable: prev?.installable ?? true,
160
+ ...(prev?.notes ? { notes: prev.notes } : {}),
161
+ state: "updating",
162
+ owner: "local",
163
+ runAt: this.deps.now(),
164
+ ...(prev?.lastAnswer ? { lastAnswer: prev.lastAnswer } : {}),
165
+ };
166
+ this.save();
167
+ }
168
+ /**
169
+ * A progress marker for this run. A marker that started before the run, or names another version, is left alone.
170
+ * Null (no marker) does not settle.
171
+ */
172
+ noteMarker(marker) {
173
+ if (!marker || marker.operation === "full-restart")
174
+ return;
175
+ if (marker.stage !== "complete" && marker.stage !== "failed")
176
+ return;
177
+ const card = this.stored;
178
+ if (card?.state !== "updating")
179
+ return;
180
+ if (card.runAt !== undefined && marker.startedAt + 2_000 < card.runAt)
181
+ return;
182
+ if (marker.version && card.version && marker.version !== card.version)
183
+ return;
184
+ this.settleRunning(marker.stage === "complete"
185
+ ? { state: "done" }
186
+ : { state: "failed", cause: marker.cause ?? "other", rolledBack: false });
187
+ }
188
+ settleRunning(outcome) {
189
+ if (this.stored?.state !== "updating")
190
+ return;
191
+ this.stored = outcome.state === "done"
192
+ ? { ...this.stored, state: "done", owner: "local" }
193
+ : { ...this.stored, state: "failed", owner: "local", failed: { cause: outcome.cause ?? "other", rolledBack: outcome.rolledBack === true } };
194
+ delete this.stored.queueId;
195
+ delete this.stored.waitingSince;
196
+ this.save();
197
+ }
198
+ /** A Hub admission is the same card. It does not open a second local queue row. */
199
+ observeHub(row) {
200
+ if (this.stopped)
201
+ return;
202
+ const active = row.state === "waiting" || row.state === "starting" || row.state === "updating";
203
+ if (active) {
204
+ if (this.stored?.state === "updating" && this.stored.owner !== "hub")
205
+ return;
206
+ const local = this.queue.pending();
207
+ if (local && local.id !== row.id && local.state !== "updating")
208
+ this.queue.cancel(local.id, "owner");
209
+ const prev = this.stored;
210
+ const channel = installedChannel(row.version);
211
+ this.stored = {
212
+ version: row.version,
213
+ channel: channel === "latest" ? "stable" : channel,
214
+ installable: true,
215
+ state: row.state === "updating" ? "updating" : "waiting-idle",
216
+ queueId: row.id,
217
+ waitingSince: row.createdAt,
218
+ owner: "hub",
219
+ ...(prev?.lastAnswer ? { lastAnswer: prev.lastAnswer } : {}),
220
+ };
221
+ this.save();
222
+ return;
223
+ }
224
+ if (this.stored?.owner !== "hub" || this.stored.queueId !== row.id)
225
+ return;
226
+ if (row.state === "done")
227
+ this.stored = { ...this.stored, state: "done" };
228
+ else if (row.state === "failed" || row.state === "rolled-back")
229
+ this.stored = { ...this.stored, state: "failed", failed: { cause: "other", rolledBack: row.state === "rolled-back" } };
230
+ else
231
+ this.stored = { ...this.stored, state: "offered" };
232
+ delete this.stored.queueId;
233
+ delete this.stored.waitingSince;
234
+ delete this.stored.owner;
235
+ this.save();
236
+ }
237
+ /** Local scheduled / waiting / updating blocks a second admission. A Hub-owned row does not block itself. */
238
+ blocksAdmission() {
239
+ const card = this.stored;
240
+ if (!card || card.owner === "hub")
241
+ return false;
242
+ return card.state === "scheduled" || card.state === "waiting-idle" || card.state === "updating";
243
+ }
244
+ view() {
245
+ this.promote();
246
+ if (this.settings().pin)
247
+ return null;
248
+ return this.toView();
249
+ }
250
+ tick() {
251
+ this.promote();
252
+ void this.queue.pump();
253
+ this.arm();
254
+ }
255
+ async answer(key, by, body, stillAllowed = () => true) {
256
+ const known = this.answers.get(key);
257
+ if (known)
258
+ return known;
259
+ const result = this.apply(updateAnswerLabel(by), body, stillAllowed);
260
+ this.answers.set(key, result);
261
+ while (this.answers.size > 32)
262
+ this.answers.delete(this.answers.keys().next().value);
263
+ return result;
264
+ }
265
+ /** The queue row for one idle launch finished. The card follows the row. */
266
+ settleLocal(id, state) {
267
+ if (this.stopped)
268
+ return;
269
+ this.queue.settle(id, state, "interrupted");
270
+ if (this.stored?.state === "updating" && this.stored.owner !== "hub" && (this.stored.queueId === id || this.stored.queueId === undefined)) {
271
+ this.settleRunning(state === "done" ? { state: "done" } : { state: "failed", cause: "other", rolledBack: state === "rolled-back" });
272
+ }
273
+ }
274
+ async apply(by, body, stillAllowed) {
275
+ const action = body.action;
276
+ if (action !== "when-idle" && action !== "now" && action !== "pick-time" && action !== "not-now" && action !== "cancel") {
277
+ return { ok: false, status: 400, body: { error: 'action must be "when-idle", "now", "pick-time", "not-now", or "cancel"' } };
278
+ }
279
+ if (this.settings().pin)
280
+ return { ok: false, status: 409, body: { key: "card_changed", error: "pinned" } };
281
+ this.promote();
282
+ const card = this.stored;
283
+ if (!card)
284
+ return { ok: false, status: 409, body: { key: "card_changed", error: "nothing_offered" } };
285
+ if (action === "now" && body.confirm !== "update-agend")
286
+ return { ok: false, status: 400, body: { error: 'confirm must be the literal "update-agend"' } };
287
+ const blocked = this.deps.preflight?.(action);
288
+ if (blocked)
289
+ return { ok: false, status: 412, body: { key: "preflight", preflight: blocked.preflight } };
290
+ if ((action === "when-idle" || action === "now" || action === "pick-time") && !card.installable) {
291
+ return { ok: false, status: 409, body: { key: "card_changed", error: "not_installable" } };
292
+ }
293
+ if (card.state === "updating" && action !== "cancel")
294
+ return { ok: false, status: 409, body: { key: "update_running" } };
295
+ if (action === "cancel")
296
+ return this.cancel(card, by);
297
+ if (action === "not-now")
298
+ return this.notNow(card, by);
299
+ if (action === "pick-time")
300
+ return this.pickTime(card, by, body.at);
301
+ if (action === "when-idle")
302
+ return this.whenIdle(card, by);
303
+ return this.now(card, by, stillAllowed);
304
+ }
305
+ cancel(card, by) {
306
+ if (card.state === "updating")
307
+ return { ok: false, status: 409, body: { key: "update_running" } };
308
+ if (card.state !== "waiting-idle" && card.state !== "scheduled")
309
+ return { ok: false, status: 409, body: { key: "card_changed" } };
310
+ this.stopWait(card);
311
+ this.stored = { ...card, state: "offered", lastAnswer: { action: "cancel", at: this.deps.now(), by } };
312
+ delete this.stored.scheduledAt;
313
+ delete this.stored.queueId;
314
+ delete this.stored.waitingSince;
315
+ delete this.stored.owner;
316
+ this.save();
317
+ return this.ok();
318
+ }
319
+ notNow(card, by) {
320
+ if (card.state === "updating")
321
+ return { ok: false, status: 409, body: { key: "update_running" } };
322
+ this.stopWait(card);
323
+ const at = this.deps.now();
324
+ this.stored = { ...card, state: "not-now", notNowUntil: at + NOT_NOW_MS, lastAnswer: { action: "not-now", at, by } };
325
+ delete this.stored.scheduledAt;
326
+ delete this.stored.queueId;
327
+ delete this.stored.waitingSince;
328
+ delete this.stored.owner;
329
+ this.save();
330
+ this.arm();
331
+ return this.ok();
332
+ }
333
+ pickTime(card, by, at) {
334
+ if (typeof at !== "number" || !Number.isSafeInteger(at))
335
+ return { ok: false, status: 400, body: { error: "at must be a millisecond timestamp" } };
336
+ const now = this.deps.now();
337
+ if (at <= now)
338
+ return { ok: false, status: 400, body: { error: "pick-time must be in the future" } };
339
+ if (at > now + PICK_WITHIN_MS)
340
+ return { ok: false, status: 400, body: { error: "pick-time must be within 7 days" } };
341
+ this.stopWait(card);
342
+ this.stored = { ...card, state: "scheduled", scheduledAt: at, owner: "local", lastAnswer: { action: "pick-time", at: now, by } };
343
+ delete this.stored.queueId;
344
+ delete this.stored.waitingSince;
345
+ delete this.stored.notNowUntil;
346
+ this.save();
347
+ this.arm();
348
+ return this.ok();
349
+ }
350
+ whenIdle(card, by) {
351
+ if (card.state === "waiting-idle")
352
+ return this.ok();
353
+ if (this.deps.externalBusy() || this.queue.pending())
354
+ return { ok: false, status: 409, body: { key: "update_running" } };
355
+ const id = randomUUID();
356
+ try {
357
+ this.queue.request({ id, version: card.version, waitMs: this.waitMs() });
358
+ }
359
+ catch {
360
+ return { ok: false, status: 409, body: { key: "update_running" } };
361
+ }
362
+ this.stored = { ...card, state: "waiting-idle", queueId: id, waitingSince: this.deps.now(), owner: "local", lastAnswer: { action: "when-idle", at: this.deps.now(), by } };
363
+ delete this.stored.scheduledAt;
364
+ delete this.stored.notNowUntil;
365
+ this.save();
366
+ void this.queue.pump();
367
+ return this.ok();
368
+ }
369
+ async now(card, by, stillAllowed) {
370
+ if (this.deps.externalBusy() && card.owner !== "hub")
371
+ return { ok: false, status: 409, body: { key: "update_running" } };
372
+ if (card.owner === "hub" && card.queueId && this.deps.launchHubNow) {
373
+ const hub = await this.deps.launchHubNow(card.queueId, stillAllowed);
374
+ if (!hub.ok)
375
+ return this.launchError(hub.status, hub.error);
376
+ this.remember("now", by);
377
+ return this.ok();
378
+ }
379
+ const localWait = card.owner !== "hub" && !!card.queueId;
380
+ this.stopWait(card);
381
+ const launched = await this.deps.launchNow(by, stillAllowed);
382
+ if (!launched.ok) {
383
+ // stopWait is quiet, so a cancelled local row would otherwise leave the card waiting with nothing behind it.
384
+ if (localWait && this.stored && (this.stored.state === "waiting-idle" || this.stored.state === "scheduled")) {
385
+ this.stored = { ...this.stored, state: "offered" };
386
+ delete this.stored.queueId;
387
+ delete this.stored.waitingSince;
388
+ delete this.stored.owner;
389
+ this.save();
390
+ }
391
+ return this.launchError(launched.status, launched.error);
392
+ }
393
+ this.remember("now", by);
394
+ return this.ok();
395
+ }
396
+ launchError(status, error) {
397
+ if (status === 409 && (error === "update_running" || error === "stopping" || error === "update_not_started")) {
398
+ return { ok: false, status: 409, body: { key: "update_running", error } };
399
+ }
400
+ if (status === 409)
401
+ return { ok: false, status: 409, body: { key: "card_changed", error } };
402
+ return { ok: false, status, body: { error } };
403
+ }
404
+ remember(action, by) {
405
+ if (!this.stored)
406
+ return;
407
+ this.stored = { ...this.stored, lastAnswer: { action, at: this.deps.now(), by } };
408
+ this.save();
409
+ }
410
+ stopWait(card) {
411
+ this.quiet++;
412
+ try {
413
+ if (card.owner === "hub" && card.queueId) {
414
+ try {
415
+ this.deps.cancelHub?.(card.queueId);
416
+ }
417
+ catch { /* the card still leaves the wait */ }
418
+ return;
419
+ }
420
+ if (!card.queueId)
421
+ return;
422
+ const row = this.queue.get(card.queueId);
423
+ if (row && (row.state === "waiting" || row.state === "starting"))
424
+ this.queue.cancel(card.queueId, "owner");
425
+ }
426
+ finally {
427
+ this.quiet--;
428
+ }
429
+ }
430
+ retarget(version) {
431
+ const card = this.stored;
432
+ if (!card?.queueId || card.owner === "hub")
433
+ return;
434
+ const row = this.queue.get(card.queueId);
435
+ if (!row || row.version === version || (row.state !== "waiting" && row.state !== "starting"))
436
+ return;
437
+ const id = randomUUID();
438
+ this.quiet++;
439
+ try {
440
+ this.queue.cancel(card.queueId, "owner");
441
+ this.queue.request({ id, version, waitMs: this.waitMs() });
442
+ card.queueId = id;
443
+ card.owner = "local";
444
+ }
445
+ finally {
446
+ this.quiet--;
447
+ }
448
+ }
449
+ promote() {
450
+ const card = this.stored;
451
+ if (!card || this.stopped)
452
+ return;
453
+ const now = this.deps.now();
454
+ if (card.state === "not-now" && now >= (card.notNowUntil ?? 0)) {
455
+ this.stored = { ...card, state: "offered" };
456
+ delete this.stored.notNowUntil;
457
+ this.save();
458
+ }
459
+ else if (card.state === "scheduled" && card.scheduledAt !== undefined && now >= card.scheduledAt) {
460
+ if (this.deps.externalBusy() || (this.queue.pending() && this.queue.pending()?.id !== card.queueId))
461
+ return;
462
+ const id = card.queueId ?? randomUUID();
463
+ try {
464
+ if (!this.queue.get(id))
465
+ this.queue.request({ id, version: card.version, waitMs: this.waitMs() });
466
+ }
467
+ catch {
468
+ return;
469
+ }
470
+ this.stored = { ...card, state: "waiting-idle", queueId: id, waitingSince: now, owner: "local" };
471
+ delete this.stored.scheduledAt;
472
+ this.save();
473
+ void this.queue.pump();
474
+ }
475
+ this.arm();
476
+ }
477
+ mirrorLocal(row) {
478
+ const card = this.stored;
479
+ if (this.quiet || !card || card.owner === "hub" || card.queueId !== row.id)
480
+ return;
481
+ if (row.state === "waiting" || row.state === "starting") {
482
+ this.stored = { ...card, state: "waiting-idle", waitingSince: card.waitingSince ?? row.createdAt };
483
+ }
484
+ else if (row.state === "updating") {
485
+ this.stored = { ...card, state: "updating", runAt: card.runAt ?? this.deps.now() };
486
+ }
487
+ else if (row.state === "done") {
488
+ this.stored = { ...card, state: "done" };
489
+ delete this.stored.queueId;
490
+ }
491
+ else if (row.state === "failed" || row.state === "rolled-back") {
492
+ this.stored = { ...card, state: "failed", failed: { cause: "other", rolledBack: row.state === "rolled-back" } };
493
+ delete this.stored.queueId;
494
+ }
495
+ else if (card.state === "waiting-idle" || card.state === "updating") {
496
+ // Expired or cancelled by the queue itself: the offer comes back. Update now stays available.
497
+ this.stored = { ...card, state: "offered" };
498
+ delete this.stored.queueId;
499
+ delete this.stored.waitingSince;
500
+ }
501
+ else
502
+ return;
503
+ this.save();
504
+ }
505
+ /** A previous process left an `updating` row. This process did not launch it, so settle it before anyone reads the card. */
506
+ reconcileIdleClaim() {
507
+ const row = this.queue.pending();
508
+ if (row?.state !== "updating")
509
+ return;
510
+ let current = null;
511
+ try {
512
+ current = this.deps.currentVersion() ?? null;
513
+ }
514
+ catch {
515
+ current = null;
516
+ }
517
+ const state = idleClaimOutcome(row.version, current, this.idleMarker(row.id, row.version));
518
+ this.settleLocal(row.id, state);
519
+ }
520
+ idleMarker(id, version) {
521
+ const messageId = idleUpdateMessageId(id);
522
+ const matches = (marker) => !!marker
523
+ && marker.progress.target.messageId === messageId
524
+ && (marker.progress.version === undefined || marker.progress.version === version);
525
+ try {
526
+ const live = readUpdateProgress(this.deps.dataDir);
527
+ if (matches(live))
528
+ return live;
529
+ }
530
+ catch { /* a missing marker is not this launch */ }
531
+ try {
532
+ const boot = this.deps.bootMarker?.() ?? null;
533
+ if (matches(boot))
534
+ return boot;
535
+ }
536
+ catch { /* the boot snapshot is optional */ }
537
+ return null;
538
+ }
539
+ idle() {
540
+ const settings = this.settings();
541
+ if (settings.pin || inUpdatePause(settings.pause, new Date(this.deps.now())))
542
+ return false;
543
+ try {
544
+ return this.deps.agentsIdle() === true;
545
+ }
546
+ catch {
547
+ return false;
548
+ }
549
+ }
550
+ settings() {
551
+ return resolveUpdates(this.deps.settings());
552
+ }
553
+ waitMs() {
554
+ return this.settings().maxIdleWait * 60 * 60_000;
555
+ }
556
+ ok() {
557
+ return { ok: true, status: 200, card: this.view() };
558
+ }
559
+ toView() {
560
+ const card = this.stored;
561
+ if (!card)
562
+ return null;
563
+ const waiting = card.state === "waiting-idle" ? this.deps.busyNames().filter(name => name.trim()) : [];
564
+ return {
565
+ version: card.version,
566
+ channel: card.channel,
567
+ installable: card.installable,
568
+ ...(card.notes ? { notes: card.notes } : {}),
569
+ state: card.state,
570
+ ...(card.state === "not-now" && card.notNowUntil !== undefined ? { notNowUntil: card.notNowUntil } : {}),
571
+ ...(card.state === "scheduled" && card.scheduledAt !== undefined ? { scheduledAt: card.scheduledAt } : {}),
572
+ ...(waiting.length ? { waitingFor: waiting } : {}),
573
+ ...(card.state === "waiting-idle" && card.waitingSince !== undefined ? { waitingSince: card.waitingSince } : {}),
574
+ ...(card.lastAnswer ? { lastAnswer: card.lastAnswer } : {}),
575
+ ...(card.state === "failed" && card.failed ? { failed: card.failed } : {}),
576
+ };
577
+ }
578
+ arm() {
579
+ clearTimeout(this.timer);
580
+ this.timer = undefined;
581
+ if (this.stopped || !this.stored)
582
+ return;
583
+ // A waiting row has no due time of its own. Poll until it launches, is cancelled, or the queue expires it.
584
+ if (this.stored.state === "waiting-idle") {
585
+ this.timer = setTimeout(() => { this.timer = undefined; this.tick(); }, IDLE_POLL_MS);
586
+ this.timer.unref?.();
587
+ return;
588
+ }
589
+ const due = this.stored.state === "scheduled" ? this.stored.scheduledAt
590
+ : this.stored.state === "not-now" ? this.stored.notNowUntil : undefined;
591
+ if (due === undefined)
592
+ return;
593
+ const delay = Math.max(0, Math.min(due - this.deps.now(), 2_147_000_000));
594
+ this.timer = setTimeout(() => { this.timer = undefined; this.tick(); }, delay);
595
+ this.timer.unref?.();
596
+ }
597
+ path() { return join(this.deps.dataDir, CARD_FILE); }
598
+ read() {
599
+ try {
600
+ const parsed = JSON.parse(readFileSync(this.path(), "utf8"));
601
+ if (!parsed || typeof parsed.version !== "string" || typeof parsed.state !== "string")
602
+ return null;
603
+ return parsed;
604
+ }
605
+ catch {
606
+ return null;
607
+ }
608
+ }
609
+ save() {
610
+ if (!this.stored) {
611
+ try {
612
+ unlinkSync(this.path());
613
+ }
614
+ catch { /* already gone */ }
615
+ return;
616
+ }
617
+ atomicWriteFileSync(this.path(), JSON.stringify(this.stored) + "\n", { mode: 0o600 });
618
+ }
619
+ }
620
+ //# sourceMappingURL=update-card.js.map