@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.
- package/README.md +1 -1
- package/README.zh-TW.md +1 -1
- package/dist/agend-home.js +5 -5
- package/dist/agend-home.js.map +1 -1
- package/dist/agent-endpoint.js +10 -0
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/agent-file-read.js +1 -1
- package/dist/agent-file-read.js.map +1 -1
- package/dist/agent-workspace.d.ts +18 -2
- package/dist/agent-workspace.js +15 -4
- package/dist/agent-workspace.js.map +1 -1
- package/dist/auth-api.js +3 -1
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/antigravity.js +8 -6
- package/dist/backend/antigravity.js.map +1 -1
- package/dist/backend/claude-code.js +17 -0
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/claude-usage-credits.d.ts +8 -0
- package/dist/backend/claude-usage-credits.js +121 -0
- package/dist/backend/claude-usage-credits.js.map +1 -0
- package/dist/backend/types.d.ts +30 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/channel/adapters/discord.js +7 -1
- package/dist/channel/adapters/discord.js.map +1 -1
- package/dist/channel/mcp-tools.js +1 -1
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/channel/tool-router.js +1 -0
- package/dist/channel/tool-router.js.map +1 -1
- package/dist/cli-audited.js +9 -4
- package/dist/cli-audited.js.map +1 -1
- package/dist/cli.js +184 -21
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.js +11 -1
- package/dist/config-validator.js.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/contact-auth-store.d.ts +18 -0
- package/dist/contact-auth-store.js +55 -8
- package/dist/contact-auth-store.js.map +1 -1
- package/dist/contact-auth-types.d.ts +3 -0
- package/dist/contact-auth-types.js.map +1 -1
- package/dist/contact-change-proposals.d.ts +34 -0
- package/dist/contact-change-proposals.js +1 -1
- package/dist/contact-change-proposals.js.map +1 -1
- package/dist/cross-instance-notice.d.ts +1 -0
- package/dist/cross-instance-notice.js +9 -8
- package/dist/cross-instance-notice.js.map +1 -1
- package/dist/daemon.d.ts +35 -0
- package/dist/daemon.js +234 -19
- package/dist/daemon.js.map +1 -1
- package/dist/delivery-outbox.d.ts +42 -1
- package/dist/delivery-outbox.js +198 -21
- package/dist/delivery-outbox.js.map +1 -1
- package/dist/fleet-context.d.ts +8 -0
- package/dist/fleet-lock.d.ts +83 -2
- package/dist/fleet-lock.js +276 -2
- package/dist/fleet-lock.js.map +1 -1
- package/dist/fleet-manager.d.ts +183 -7
- package/dist/fleet-manager.js +1279 -78
- package/dist/fleet-manager.js.map +1 -1
- package/dist/fleet-windows-runtime.d.ts +20 -1
- package/dist/fleet-windows-runtime.js +98 -18
- package/dist/fleet-windows-runtime.js.map +1 -1
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +13 -1
- package/dist/general-knowledge/skills/hub/SKILL.md +12 -1
- package/dist/general-knowledge/skills/web-appearance/SKILL.md +3 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +21 -4
- package/dist/home-update-lock.d.ts +35 -0
- package/dist/home-update-lock.js +81 -0
- package/dist/home-update-lock.js.map +1 -0
- package/dist/hub/client.js +7 -0
- package/dist/hub/client.js.map +1 -1
- package/dist/hub/compose/member.d.ts +5 -1
- package/dist/hub/compose/member.js +15 -6
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/compose/server.d.ts +1 -0
- package/dist/hub/compose/server.js +3 -2
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/http/compose.js +3 -2
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/http/deps.d.ts +1 -0
- package/dist/hub/member/room-ask.d.ts +12 -8
- package/dist/hub/member/room-ask.js +95 -29
- package/dist/hub/member/room-ask.js.map +1 -1
- package/dist/hub/member/room-mention-feedback.d.ts +2 -0
- package/dist/hub/member/room-mention-feedback.js +1 -1
- package/dist/hub/member/room-mention-feedback.js.map +1 -1
- package/dist/hub/member/room-post-answers.d.ts +2 -0
- package/dist/hub/member/room-post-answers.js +1 -1
- package/dist/hub/member/room-post-answers.js.map +1 -1
- package/dist/hub/member/room-post.d.ts +5 -0
- package/dist/hub/member/room-post.js +4 -1
- package/dist/hub/member/room-post.js.map +1 -1
- package/dist/hub/member/room-reaction-acks.d.ts +12 -0
- package/dist/hub/member/room-reaction-acks.js +44 -0
- package/dist/hub/member/room-reaction-acks.js.map +1 -0
- package/dist/hub/member/updates.d.ts +7 -1
- package/dist/hub/member/updates.js +7 -1
- package/dist/hub/member/updates.js.map +1 -1
- package/dist/hub/protocol.d.ts +4 -0
- package/dist/hub/protocol.js +2 -2
- package/dist/hub/protocol.js.map +1 -1
- package/dist/hub/representative.d.ts +7 -0
- package/dist/hub/representative.js +38 -5
- package/dist/hub/representative.js.map +1 -1
- package/dist/hub/roles/audit-details.d.ts +2 -0
- package/dist/hub/roles/audit-details.js +1 -1
- package/dist/hub/roles/audit-details.js.map +1 -1
- package/dist/hub/roles/authority.d.ts +8 -3
- package/dist/hub/roles/authority.js +144 -102
- package/dist/hub/roles/authority.js.map +1 -1
- package/dist/hub/roles/delegation.js +2 -2
- package/dist/hub/roles/delegation.js.map +1 -1
- package/dist/hub/roles/model.d.ts +5 -2
- package/dist/hub/roles/model.js +5 -4
- package/dist/hub/roles/model.js.map +1 -1
- package/dist/hub/roles/review.js +2 -2
- package/dist/hub/roles/review.js.map +1 -1
- package/dist/hub/room-react-ack-model.d.ts +2 -0
- package/dist/hub/room-react-ack-model.js +3 -0
- package/dist/hub/room-react-ack-model.js.map +1 -0
- package/dist/hub/rooms/admin.d.ts +6 -0
- package/dist/hub/rooms/admin.js +33 -0
- package/dist/hub/rooms/admin.js.map +1 -1
- package/dist/hub/rooms/agents.d.ts +2 -0
- package/dist/hub/rooms/agents.js +44 -3
- package/dist/hub/rooms/agents.js.map +1 -1
- package/dist/hub/rooms/service.d.ts +5 -1
- package/dist/hub/rooms/service.js +76 -24
- package/dist/hub/rooms/service.js.map +1 -1
- package/dist/hub/rooms/types.d.ts +2 -0
- package/dist/hub/server.js +6 -1
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/types.d.ts +2 -0
- package/dist/install-lock.d.ts +15 -1
- package/dist/install-lock.js +16 -8
- package/dist/install-lock.js.map +1 -1
- package/dist/install-ownership.d.ts +165 -0
- package/dist/install-ownership.js +404 -0
- package/dist/install-ownership.js.map +1 -0
- package/dist/instance-config-impact.js +2 -0
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instructions.d.ts +4 -0
- package/dist/instructions.js +4 -0
- package/dist/instructions.js.map +1 -1
- package/dist/local-pane-endpoint.d.ts +4 -1
- package/dist/local-pane-endpoint.js +12 -2
- package/dist/local-pane-endpoint.js.map +1 -1
- package/dist/locale.js +162 -6
- package/dist/locale.js.map +1 -1
- package/dist/native-agent-admission.d.ts +7 -0
- package/dist/native-agent-admission.js +46 -3
- package/dist/native-agent-admission.js.map +1 -1
- package/dist/native-mcp.d.ts +16 -1
- package/dist/native-mcp.js +38 -5
- package/dist/native-mcp.js.map +1 -1
- package/dist/native-pane-lifecycle.d.ts +9 -0
- package/dist/native-pane-lifecycle.js +23 -0
- package/dist/native-pane-lifecycle.js.map +1 -1
- package/dist/native-pane-manager.d.ts +19 -6
- package/dist/native-pane-manager.js +79 -4
- package/dist/native-pane-manager.js.map +1 -1
- package/dist/needs-you.d.ts +8 -0
- package/dist/needs-you.js +1 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/outbound-handlers.d.ts +12 -0
- package/dist/outbound-handlers.js +30 -2
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/package-preimage.js +4 -0
- package/dist/package-preimage.js.map +1 -1
- package/dist/pane-port.d.ts +1 -0
- package/dist/plist-args.d.ts +9 -0
- package/dist/plist-args.js +22 -0
- package/dist/plist-args.js.map +1 -0
- package/dist/public-preview.d.ts +4 -6
- package/dist/public-preview.js +5 -2
- package/dist/public-preview.js.map +1 -1
- package/dist/public-web-gateway.js +10 -3
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/public-web-link.d.ts +13 -1
- package/dist/public-web-link.js +28 -1
- package/dist/public-web-link.js.map +1 -1
- package/dist/recover.cjs +2638 -0
- package/dist/remote-card-prompt.d.ts +6 -2
- package/dist/remote-card-prompt.js +12 -3
- package/dist/remote-card-prompt.js.map +1 -1
- package/dist/reply-draft.d.ts +12 -0
- package/dist/reply-draft.js +81 -0
- package/dist/reply-draft.js.map +1 -0
- package/dist/request-contact-api.d.ts +15 -0
- package/dist/request-contact-api.js +120 -0
- package/dist/request-contact-api.js.map +1 -0
- package/dist/request-contact-card.d.ts +36 -0
- package/dist/request-contact-card.js +206 -0
- package/dist/request-contact-card.js.map +1 -0
- package/dist/request-contact-gate.d.ts +79 -0
- package/dist/request-contact-gate.js +262 -0
- package/dist/request-contact-gate.js.map +1 -0
- package/dist/request-contact-native.d.ts +52 -0
- package/dist/request-contact-native.js +87 -0
- package/dist/request-contact-native.js.map +1 -0
- package/dist/request-contact-types.d.ts +86 -0
- package/dist/request-contact-types.js +7 -0
- package/dist/request-contact-types.js.map +1 -0
- package/dist/request-context-call-protocol.d.ts +12 -0
- package/dist/request-context-call-protocol.js +14 -0
- package/dist/request-context-call-protocol.js.map +1 -0
- package/dist/request-context-call.d.ts +22 -0
- package/dist/request-context-call.js +35 -0
- package/dist/request-context-call.js.map +1 -0
- package/dist/request-context-drain.d.ts +39 -0
- package/dist/request-context-drain.js +159 -0
- package/dist/request-context-drain.js.map +1 -0
- package/dist/request-context-fence.d.ts +28 -0
- package/dist/request-context-fence.js +58 -0
- package/dist/request-context-fence.js.map +1 -0
- package/dist/request-context-migration.d.ts +64 -0
- package/dist/request-context-migration.js +158 -0
- package/dist/request-context-migration.js.map +1 -0
- package/dist/request-context-pane.d.ts +25 -0
- package/dist/request-context-pane.js +48 -0
- package/dist/request-context-pane.js.map +1 -0
- package/dist/request-context-policy.d.ts +74 -0
- package/dist/request-context-policy.js +116 -0
- package/dist/request-context-policy.js.map +1 -0
- package/dist/request-context-recovery.d.ts +14 -0
- package/dist/request-context-recovery.js +56 -0
- package/dist/request-context-recovery.js.map +1 -0
- package/dist/request-context-relay.d.ts +19 -0
- package/dist/request-context-relay.js +63 -0
- package/dist/request-context-relay.js.map +1 -0
- package/dist/request-context-returns.d.ts +67 -0
- package/dist/request-context-returns.js +211 -0
- package/dist/request-context-returns.js.map +1 -0
- package/dist/request-context-store.d.ts +2 -1
- package/dist/request-context-store.js +8 -1
- package/dist/request-context-store.js.map +1 -1
- package/dist/request-context-turns.d.ts +99 -0
- package/dist/request-context-turns.js +215 -0
- package/dist/request-context-turns.js.map +1 -0
- package/dist/request-context-view.d.ts +33 -0
- package/dist/request-context-view.js +36 -0
- package/dist/request-context-view.js.map +1 -0
- package/dist/request-hub-context.d.ts +130 -0
- package/dist/request-hub-context.js +89 -0
- package/dist/request-hub-context.js.map +1 -0
- package/dist/request-hub-output.d.ts +11 -0
- package/dist/request-hub-output.js +21 -0
- package/dist/request-hub-output.js.map +1 -0
- package/dist/runtime-cli-install.js +13 -11
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/runtime-client.d.ts +2 -0
- package/dist/runtime-client.js +17 -4
- package/dist/runtime-client.js.map +1 -1
- package/dist/runtime-coordinator.d.ts +4 -1
- package/dist/runtime-coordinator.js +10 -3
- package/dist/runtime-coordinator.js.map +1 -1
- package/dist/runtime-pane-assets.d.ts +1 -1
- package/dist/runtime-pane-assets.js +1 -1
- package/dist/runtime-pane-assets.js.map +1 -1
- package/dist/runtime-pane-host.d.ts +3 -0
- package/dist/runtime-pane-host.js +39 -21
- package/dist/runtime-pane-host.js.map +1 -1
- package/dist/runtime-pane-link.d.ts +6 -2
- package/dist/runtime-pane-link.js +17 -4
- package/dist/runtime-pane-link.js.map +1 -1
- package/dist/runtime-pane-mcp-relay.d.ts +11 -1
- package/dist/runtime-pane-mcp-relay.js +69 -3
- package/dist/runtime-pane-mcp-relay.js.map +1 -1
- package/dist/runtime-pane-mcp.d.ts +28 -1
- package/dist/runtime-pane-mcp.js +92 -15
- package/dist/runtime-pane-mcp.js.map +1 -1
- package/dist/runtime-pane-port.d.ts +6 -0
- package/dist/runtime-pane-port.js +23 -4
- package/dist/runtime-pane-port.js.map +1 -1
- package/dist/runtime-pane-protocol.d.ts +4 -0
- package/dist/runtime-pane-protocol.js +11 -4
- package/dist/runtime-pane-protocol.js.map +1 -1
- package/dist/runtime-pane-service.d.ts +1 -0
- package/dist/runtime-pane-service.js +25 -9
- package/dist/runtime-pane-service.js.map +1 -1
- package/dist/runtime-pane-stdio-protocol.d.ts +4 -0
- package/dist/runtime-pane-stdio-protocol.js +12 -5
- package/dist/runtime-pane-stdio-protocol.js.map +1 -1
- package/dist/runtime-pane-stdio.js +5 -5
- package/dist/runtime-pane-stdio.js.map +1 -1
- package/dist/runtime-protocol.d.ts +3 -0
- package/dist/runtime-protocol.js.map +1 -1
- package/dist/scheduler/scheduler.d.ts +15 -0
- package/dist/scheduler/scheduler.js +45 -1
- package/dist/scheduler/scheduler.js.map +1 -1
- package/dist/scheduler/scheduler.test.js +17 -0
- package/dist/scheduler/scheduler.test.js.map +1 -1
- package/dist/scheduler/task-board.d.ts +4 -0
- package/dist/scheduler/task-board.js +6 -0
- package/dist/scheduler/task-board.js.map +1 -1
- package/dist/scheduler/types.d.ts +1 -1
- package/dist/service-activation.js +3 -13
- package/dist/service-activation.js.map +1 -1
- package/dist/service-lock.d.ts +28 -0
- package/dist/service-lock.js +85 -0
- package/dist/service-lock.js.map +1 -0
- package/dist/settings-api.d.ts +6 -0
- package/dist/settings-api.js +107 -0
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +14 -1
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.js +11 -1
- package/dist/settings-effect.js.map +1 -1
- package/dist/state-lease.d.ts +24 -0
- package/dist/state-lease.js +103 -0
- package/dist/state-lease.js.map +1 -0
- package/dist/tmux-binary.js +1 -1
- package/dist/tmux-binary.js.map +1 -1
- package/dist/tool-receipt-output.d.ts +2 -0
- package/dist/topic-commands.js +21 -1
- package/dist/topic-commands.js.map +1 -1
- package/dist/transcript-monitor.js +3 -0
- package/dist/transcript-monitor.js.map +1 -1
- package/dist/tunnel/named-link-test.d.ts +27 -0
- package/dist/tunnel/named-link-test.js +41 -0
- package/dist/tunnel/named-link-test.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/ui/chat-store.js +5 -4
- package/dist/ui/contact-auth-strings.js +7 -2
- package/dist/ui/contact-permissions.js +10 -2
- package/dist/ui/fleet-office-card.js +15 -2
- package/dist/ui/fleet-office-pack.d.ts +2 -2
- package/dist/ui/fleet-office-pack.js +25 -8
- package/dist/ui/fleet-office-skin.js +33 -9
- package/dist/ui/fleet-office-vehicles.js +28 -11
- package/dist/ui/fleet-office-zones.js +10 -5
- package/dist/ui/fleet-office.js +158 -20
- package/dist/ui/fleet-task-files.js +1 -1
- package/dist/ui/hub-admin-rooms-strings.js +6 -2
- package/dist/ui/hub-admin-rooms.js +3 -1
- package/dist/ui/hub-group-search.js +2 -2
- package/dist/ui/hub-notify-keep.js +49 -0
- package/dist/ui/hub-role-view.js +1 -1
- package/dist/ui/hub-roles-strings.js +14 -10
- package/dist/ui/hub-roles.js +1 -1
- package/dist/ui/hub-room-notify.js +2 -1
- package/dist/ui/hub-room-strings.js +3 -3
- package/dist/ui/hub-room-thread.js +9 -4
- package/dist/ui/panel-chat.js +15 -2
- package/dist/ui/panel-hub.js +3 -2
- package/dist/ui/panel-needs.js +35 -7
- package/dist/ui/panel-settings.js +22 -8
- package/dist/ui/settings-preview-address.js +156 -0
- package/dist/ui/settings-registry.js +2 -0
- package/dist/ui/settings-strings.js +6 -6
- package/dist/ui/settings-update.js +13 -0
- package/dist/ui/shared/app-install.js +123 -0
- package/dist/ui/shared/app-shell.js +4 -2
- package/dist/ui/shared/app-update.js +16 -2
- package/dist/ui/shared/app.css +119 -2
- package/dist/ui/shared/app.js +3 -0
- package/dist/ui/shared/chat-strings.js +6 -2
- package/dist/ui/shared/chat-thread.js +7 -1
- package/dist/ui/shared/hub-chat.css +6 -0
- package/dist/ui/shared/preview-panel.js +1 -1
- package/dist/ui/shared/preview.js +11 -2
- package/dist/ui/shared/tokens.css +18 -3
- package/dist/ui/shared/ui-confirm.js +7 -5
- package/dist/ui/shared/ui-icons.js +2 -0
- package/dist/ui/shared/update-card-ui.js +419 -0
- package/dist/ui/shared/workspace.css +7 -0
- package/dist/ui/usage-credits-card.js +84 -0
- package/dist/ui/workspace-ignored-strings.js +16 -0
- package/dist/ui/workspace-panel.js +15 -6
- package/dist/update-abandon.d.ts +26 -0
- package/dist/update-abandon.js +111 -0
- package/dist/update-abandon.js.map +1 -0
- package/dist/update-card.d.ts +193 -0
- package/dist/update-card.js +620 -0
- package/dist/update-card.js.map +1 -0
- package/dist/update-dispatch.d.ts +16 -1
- package/dist/update-dispatch.js +12 -4
- package/dist/update-dispatch.js.map +1 -1
- package/dist/update-forward.d.ts +59 -0
- package/dist/update-forward.js +227 -0
- package/dist/update-forward.js.map +1 -0
- package/dist/update-goback.d.ts +90 -0
- package/dist/update-goback.js +260 -0
- package/dist/update-goback.js.map +1 -0
- package/dist/update-idle.d.ts +1 -0
- package/dist/update-idle.js +12 -3
- package/dist/update-idle.js.map +1 -1
- package/dist/update-install.d.ts +2 -1
- package/dist/update-install.js +18 -10
- package/dist/update-install.js.map +1 -1
- package/dist/update-journal.d.ts +359 -0
- package/dist/update-journal.js +723 -0
- package/dist/update-journal.js.map +1 -0
- package/dist/update-launch.js +1 -1
- package/dist/update-launch.js.map +1 -1
- package/dist/update-npm-env.d.ts +45 -12
- package/dist/update-npm-env.js +48 -0
- package/dist/update-npm-env.js.map +1 -1
- package/dist/update-package-restore.d.ts +84 -0
- package/dist/update-package-restore.js +329 -0
- package/dist/update-package-restore.js.map +1 -0
- package/dist/update-quiescence.d.ts +221 -0
- package/dist/update-quiescence.js +370 -0
- package/dist/update-quiescence.js.map +1 -0
- package/dist/update-readiness-host.d.ts +61 -0
- package/dist/update-readiness-host.js +297 -0
- package/dist/update-readiness-host.js.map +1 -0
- package/dist/update-readiness.d.ts +83 -0
- package/dist/update-readiness.js +459 -0
- package/dist/update-readiness.js.map +1 -0
- package/dist/update-recovery/kit.d.ts +35 -0
- package/dist/update-recovery/kit.js +99 -0
- package/dist/update-recovery/kit.js.map +1 -0
- package/dist/update-recovery/pre-start.d.ts +34 -0
- package/dist/update-recovery/pre-start.js +103 -0
- package/dist/update-recovery/pre-start.js.map +1 -0
- package/dist/update-recovery/recover-main.d.ts +1 -0
- package/dist/update-recovery/recover-main.js +4 -0
- package/dist/update-recovery/recover-main.js.map +1 -0
- package/dist/update-recovery/recover.d.ts +22 -0
- package/dist/update-recovery/recover.js +134 -0
- package/dist/update-recovery/recover.js.map +1 -0
- package/dist/update-recovery/route.d.ts +53 -0
- package/dist/update-recovery/route.js +262 -0
- package/dist/update-recovery/route.js.map +1 -0
- package/dist/update-recovery/runner.d.ts +62 -0
- package/dist/update-recovery/runner.js +229 -0
- package/dist/update-recovery/runner.js.map +1 -0
- package/dist/update-recovery/service-manager.d.ts +39 -0
- package/dist/update-recovery/service-manager.js +57 -0
- package/dist/update-recovery/service-manager.js.map +1 -0
- package/dist/update-restore.d.ts +50 -0
- package/dist/update-restore.js +360 -0
- package/dist/update-restore.js.map +1 -0
- package/dist/update-retained.d.ts +65 -0
- package/dist/update-retained.js +116 -0
- package/dist/update-retained.js.map +1 -0
- package/dist/update-rollback.d.ts +74 -0
- package/dist/update-rollback.js +221 -0
- package/dist/update-rollback.js.map +1 -0
- package/dist/update-settings.d.ts +63 -0
- package/dist/update-settings.js +162 -0
- package/dist/update-settings.js.map +1 -0
- package/dist/update-snapshot-manifest.d.ts +32 -0
- package/dist/update-snapshot-manifest.js +65 -0
- package/dist/update-snapshot-manifest.js.map +1 -0
- package/dist/update-snapshot-scope.d.ts +67 -0
- package/dist/update-snapshot-scope.js +173 -0
- package/dist/update-snapshot-scope.js.map +1 -0
- package/dist/update-snapshot.d.ts +34 -0
- package/dist/update-snapshot.js +246 -0
- package/dist/update-snapshot.js.map +1 -0
- package/dist/update-writers.d.ts +71 -0
- package/dist/update-writers.js +235 -0
- package/dist/update-writers.js.map +1 -0
- package/dist/web-api.d.ts +3 -0
- package/dist/web-api.js +43 -8
- package/dist/web-api.js.map +1 -1
- package/dist/web-chat-history.d.ts +7 -0
- package/dist/web-chat-history.js +15 -0
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-icons.d.ts +11 -0
- package/dist/web-icons.js +14 -2
- package/dist/web-icons.js.map +1 -1
- package/dist/web-mentions.d.ts +27 -8
- package/dist/web-mentions.js +108 -1
- package/dist/web-mentions.js.map +1 -1
- package/dist/web-office-acts.js +3 -0
- package/dist/web-office-acts.js.map +1 -1
- package/dist/web-preview.d.ts +5 -0
- package/dist/web-preview.js +1 -1
- package/dist/web-preview.js.map +1 -1
- package/dist/web-update.d.ts +6 -0
- package/dist/windows-agents.d.ts +12 -0
- package/dist/windows-agents.js +5 -0
- package/dist/windows-agents.js.map +1 -1
- package/launcher/agend +4 -1
- package/launcher/agend-agent +4 -1
- package/launcher/agend-install.cjs +16 -8
- package/launcher/install-admission.d.cts +8 -0
- package/launcher/npm-allow-scripts.cjs +72 -0
- package/launcher/npm-global-prefix.cjs +81 -0
- package/launcher/postinstall.cjs +9 -8
- package/launcher/runtime-select.cjs +8 -2
- package/package.json +4 -3
- package/scripts/preinstall-guard.cjs +1 -1
|
@@ -0,0 +1,723 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M-3770 slice 2.1a (design `docs/design/update-transaction-m3770.md` §2, §2.6, §7): the update attempt journal.
|
|
3
|
+
*
|
|
4
|
+
* <home>/.update-journal/
|
|
5
|
+
* current the open attempt's id — THE authority for "an attempt is open" (§2.4/2.5)
|
|
6
|
+
* attempts/<id>/attempt.json the record, replaced atomically
|
|
7
|
+
* attempts/<id>/inbox|deferred|cancel the fleet's files (§2.6)
|
|
8
|
+
* marks.json append-only: versions that rolled back here
|
|
9
|
+
*
|
|
10
|
+
* Publication order (§2.4): an attempt's record is durable before `current` names it; a terminal record is durable
|
|
11
|
+
* (and a rollback's mark before it) before `current` is cleared. Readers (§2.5): only an absent `current` is "none";
|
|
12
|
+
* anything present but unreadable is "unknown", which blocks. Every durable step goes through `JournalIo.step`, so a
|
|
13
|
+
* test can crash the writer after any one of them.
|
|
14
|
+
*
|
|
15
|
+
* Synchronous on purpose: the updater and a fleet start read and write it before anything else runs.
|
|
16
|
+
*/
|
|
17
|
+
import { closeSync, fsyncSync, linkSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, unlinkSync, writeSync } from "node:fs";
|
|
18
|
+
import { basename, dirname, join } from "node:path";
|
|
19
|
+
import { holderState } from "./install-lock.js";
|
|
20
|
+
export const TERMINAL = new Set(["committed", "rolled-back", "abandoned", "manual-recovery"]);
|
|
21
|
+
/** §2.3: the allowed transitions. `manual-recovery` is reachable from any non-terminal stage. */
|
|
22
|
+
const NEXT = {
|
|
23
|
+
opened: ["barrier", "abandoning"],
|
|
24
|
+
barrier: ["stopping", "abandoning"],
|
|
25
|
+
stopping: ["snapshotted", "abandoning"],
|
|
26
|
+
abandoning: ["abandoned"],
|
|
27
|
+
snapshotted: ["installing", "rolling-back"],
|
|
28
|
+
installing: ["trial", "rolling-back"],
|
|
29
|
+
trial: ["proving", "rolling-back"],
|
|
30
|
+
proving: ["committing", "rolling-back"],
|
|
31
|
+
committing: ["committed"],
|
|
32
|
+
"rolling-back": ["rolled-back"],
|
|
33
|
+
abandoned: [], committed: [], "rolled-back": [], "manual-recovery": [],
|
|
34
|
+
};
|
|
35
|
+
export function canAdvance(from, to) {
|
|
36
|
+
if (TERMINAL.has(from))
|
|
37
|
+
return false;
|
|
38
|
+
return to === "manual-recovery" || NEXT[from].includes(to);
|
|
39
|
+
}
|
|
40
|
+
const fsyncDirReal = (dir) => { const fd = openSync(dir, "r"); try {
|
|
41
|
+
fsyncSync(fd);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
closeSync(fd);
|
|
45
|
+
} };
|
|
46
|
+
export const defaultJournalIo = {
|
|
47
|
+
now: () => new Date(),
|
|
48
|
+
writeSynced: (path, data) => { const fd = openSync(path, "wx", 0o600); try {
|
|
49
|
+
writeSync(fd, data);
|
|
50
|
+
fsyncSync(fd);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
closeSync(fd);
|
|
54
|
+
} },
|
|
55
|
+
rename: (from, to) => renameSync(from, to),
|
|
56
|
+
link: (from, to) => linkSync(from, to),
|
|
57
|
+
unlink: path => unlinkSync(path),
|
|
58
|
+
mkdir: path => mkdirSync(path, { mode: 0o700 }),
|
|
59
|
+
fsyncDir: fsyncDirReal,
|
|
60
|
+
read: path => { try {
|
|
61
|
+
return readFileSync(path, "utf8");
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (err.code === "ENOENT")
|
|
65
|
+
return null;
|
|
66
|
+
throw err;
|
|
67
|
+
} },
|
|
68
|
+
list: path => { try {
|
|
69
|
+
return readdirSync(path);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (err.code === "ENOENT")
|
|
73
|
+
return [];
|
|
74
|
+
throw err;
|
|
75
|
+
} },
|
|
76
|
+
step: () => { },
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* A fresh tmp name per write (Prism #4494 R2): a crash between a link and the tmp's unlink leaves that tmp as a second
|
|
80
|
+
* name of the published file, so a tmp name is never reused. Opened with O_EXCL, a retry can't truncate it.
|
|
81
|
+
*/
|
|
82
|
+
let tmpSeq = 0;
|
|
83
|
+
const tmpOf = (path) => `${path}.tmp-${process.pid}-${Date.now().toString(36)}-${(tmpSeq++).toString(36)}`;
|
|
84
|
+
/** Replace `path` atomically and durably: tmp written and fsynced, renamed over, the directory fsynced. */
|
|
85
|
+
function writeAtomic(io, path, data) {
|
|
86
|
+
const tmp = tmpOf(path);
|
|
87
|
+
io.writeSynced(tmp, data);
|
|
88
|
+
io.step(`write:${basename(tmp)}`);
|
|
89
|
+
io.rename(tmp, path);
|
|
90
|
+
io.step(`rename:${basename(path)}`);
|
|
91
|
+
io.fsyncDir(dirname(path));
|
|
92
|
+
io.step(`fsync-dir:${basename(dirname(path))}`);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Publish `path` only if it doesn't exist (Prism #4494 3): tmp written and fsynced, hard-linked into place (never
|
|
96
|
+
* replacing anything), tmp removed, the directory fsynced. An exact retry (the same bytes already there) succeeds; a
|
|
97
|
+
* conflicting one throws and the original stays.
|
|
98
|
+
*/
|
|
99
|
+
function writeNew(io, path, data) {
|
|
100
|
+
const tmp = tmpOf(path);
|
|
101
|
+
io.writeSynced(tmp, data);
|
|
102
|
+
io.step(`write:${basename(tmp)}`);
|
|
103
|
+
try {
|
|
104
|
+
io.link(tmp, path);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
try {
|
|
108
|
+
io.unlink(tmp);
|
|
109
|
+
}
|
|
110
|
+
catch { /* best effort */ }
|
|
111
|
+
if (err.code !== "EEXIST")
|
|
112
|
+
throw err;
|
|
113
|
+
if (io.read(path) !== data)
|
|
114
|
+
throw new Error(`${path} already exists with other content; the original is kept`);
|
|
115
|
+
// An exact retry: published already, but maybe not durably (a crash between the link and the directory fsync).
|
|
116
|
+
io.fsyncDir(dirname(path));
|
|
117
|
+
io.step(`fsync-dir:${basename(dirname(path))}`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
io.step(`link:${basename(path)}`);
|
|
121
|
+
io.unlink(tmp);
|
|
122
|
+
io.fsyncDir(dirname(path));
|
|
123
|
+
io.step(`fsync-dir:${basename(dirname(path))}`);
|
|
124
|
+
}
|
|
125
|
+
/** Rename and make it durable: the destination's directory fsynced (and the source's, when different). */
|
|
126
|
+
function renameDurable(io, from, to) {
|
|
127
|
+
io.rename(from, to);
|
|
128
|
+
io.step(`rename:${basename(to)}`);
|
|
129
|
+
io.fsyncDir(dirname(to));
|
|
130
|
+
io.step(`fsync-dir:${basename(dirname(to))}`);
|
|
131
|
+
if (dirname(from) !== dirname(to)) {
|
|
132
|
+
io.fsyncDir(dirname(from));
|
|
133
|
+
io.step(`fsync-dir:${basename(dirname(from))}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create the directory chain from `base` (which must exist: the AgEnD home) down to `path` durably (Prism #4494 4, R2):
|
|
138
|
+
* each component's parent is fsynced whether this call made the component or a crashed earlier call did (a retry
|
|
139
|
+
* finding it present can't tell, so it syncs again before going on). `exclusive`: the last component must be new (an
|
|
140
|
+
* attempt's directory is never reused).
|
|
141
|
+
*/
|
|
142
|
+
/** Create `path` below `base`, each new level made durable (its parent fsynced). `exclusive`: the last level must be new. */
|
|
143
|
+
export function mkdirDurable(io, base, path, exclusive = false) {
|
|
144
|
+
const root = base.replace(/\/+$/, "");
|
|
145
|
+
const rel = path.slice(root.length).split("/").filter(Boolean);
|
|
146
|
+
if (!path.startsWith(root + "/") || rel.length === 0)
|
|
147
|
+
throw new Error(`${path} is not below ${base}`);
|
|
148
|
+
let dir = root;
|
|
149
|
+
rel.forEach((part, i) => {
|
|
150
|
+
dir = join(dir, part);
|
|
151
|
+
const last = i === rel.length - 1;
|
|
152
|
+
try {
|
|
153
|
+
io.mkdir(dir);
|
|
154
|
+
io.step(`mkdir:${part}`);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
if (err.code !== "EEXIST")
|
|
158
|
+
throw err;
|
|
159
|
+
if (last && exclusive)
|
|
160
|
+
throw new Error(`${dir} already exists; an attempt's directory is never reused`);
|
|
161
|
+
}
|
|
162
|
+
io.fsyncDir(dirname(dir));
|
|
163
|
+
io.step(`fsync-dir:${basename(dirname(dir))}`);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
export const journalDir = (home) => join(home, ".update-journal");
|
|
167
|
+
const currentPath = (home) => join(journalDir(home), "current");
|
|
168
|
+
export const attemptDir = (home, id) => join(journalDir(home), "attempts", id);
|
|
169
|
+
const recordPath = (home, id) => join(attemptDir(home, id), "attempt.json");
|
|
170
|
+
const marksPath = (home) => join(journalDir(home), "marks.json");
|
|
171
|
+
const ID = /^\d{8}T\d{6}Z-[0-9a-f]{8}$/;
|
|
172
|
+
/** An attempt id as `newAttemptId` makes it (and as `current` must name it). */
|
|
173
|
+
export const isAttemptId = (v) => ID.test(v);
|
|
174
|
+
/** A time-sortable attempt id: `<UTC compact ISO>-<8 hex>`. */
|
|
175
|
+
export function newAttemptId(now, hex8) {
|
|
176
|
+
if (!/^[0-9a-f]{8}$/.test(hex8))
|
|
177
|
+
throw new Error("hex8 must be 8 lowercase hex digits");
|
|
178
|
+
return `${now.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}Z$/, "Z")}-${hex8}`;
|
|
179
|
+
}
|
|
180
|
+
const STAGES = new Set(Object.keys(NEXT));
|
|
181
|
+
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
182
|
+
const nonEmpty = (v) => typeof v === "string" && v.length > 0;
|
|
183
|
+
const isTime = (v) => nonEmpty(v) && Number.isFinite(Date.parse(v));
|
|
184
|
+
const isPid = (v) => Number.isSafeInteger(v) && v > 0;
|
|
185
|
+
const isArtifact = (v) => isObj(v) && nonEmpty(v.name) && nonEmpty(v.version) && (v.integrity === null || nonEmpty(v.integrity));
|
|
186
|
+
const isStart = (v) => isObj(v) && nonEmpty(v.processStart)
|
|
187
|
+
&& (v.startTicks === undefined || (typeof v.startTicks === "string" && /^\d+$/.test(v.startTicks)))
|
|
188
|
+
&& (v.bootId === undefined || nonEmpty(v.bootId));
|
|
189
|
+
/**
|
|
190
|
+
* Every required field, by shape (Prism #4494 2): a record that's valid JSON but malformed is invalid, so it reads
|
|
191
|
+
* unknown and is never cleared. Future opaque fields (ownership, tuples, generations) are 2.1b's.
|
|
192
|
+
*/
|
|
193
|
+
function parseRecord(text, id) {
|
|
194
|
+
let r;
|
|
195
|
+
try {
|
|
196
|
+
r = JSON.parse(text);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
if (!isObj(r) || r.schema !== 1 || r.id !== id || !(r.kind === "update" || r.kind === "go-back") || !isTime(r.createdAt))
|
|
202
|
+
return null;
|
|
203
|
+
if (!isObj(r.updater) || !isPid(r.updater.pid) || !isStart(r.updater.start) || !isArtifact(r.from) || !isArtifact(r.to))
|
|
204
|
+
return null;
|
|
205
|
+
const stage = r.stage;
|
|
206
|
+
if (!STAGES.has(stage) || (r.substep !== undefined && !nonEmpty(r.substep)))
|
|
207
|
+
return null;
|
|
208
|
+
if (r.goBackOf !== undefined && !(typeof r.goBackOf === "string" && ID.test(r.goBackOf)))
|
|
209
|
+
return null;
|
|
210
|
+
if (r.kind === "go-back" && r.goBackOf === undefined)
|
|
211
|
+
return null;
|
|
212
|
+
const h = r.history;
|
|
213
|
+
if (!Array.isArray(h) || h.length === 0 || h[0]?.stage !== "opened")
|
|
214
|
+
return null;
|
|
215
|
+
for (const e of h) {
|
|
216
|
+
if (!isObj(e) || !STAGES.has(e.stage) || !isTime(e.at) || (e.substep !== undefined && !nonEmpty(e.substep)) || (e.note !== undefined && typeof e.note !== "string"))
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
if (h[h.length - 1].stage !== stage)
|
|
220
|
+
return null;
|
|
221
|
+
const terminal = TERMINAL.has(stage);
|
|
222
|
+
if (terminal !== (r.outcome !== undefined))
|
|
223
|
+
return null;
|
|
224
|
+
if (terminal) {
|
|
225
|
+
const o = r.outcome;
|
|
226
|
+
if (!isObj(o) || o.kind !== stage || !isTime(o.at) || (o.reason !== undefined && typeof o.reason !== "string"))
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return r;
|
|
230
|
+
}
|
|
231
|
+
/** One attempt's own record, validated (null: absent, unreadable or invalid) — whatever `current` names. */
|
|
232
|
+
export function readAttemptRecord(home, id, io = defaultJournalIo) {
|
|
233
|
+
if (!ID.test(id))
|
|
234
|
+
return null;
|
|
235
|
+
try {
|
|
236
|
+
const text = io.read(recordPath(home, id));
|
|
237
|
+
return text === null ? null : parseRecord(text, id);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/** §2.5: the journal as every reader sees it. Only an absent `current` is "none". */
|
|
244
|
+
export function readCurrent(home, io = defaultJournalIo) {
|
|
245
|
+
let text;
|
|
246
|
+
try {
|
|
247
|
+
text = io.read(currentPath(home));
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
return { state: "unknown", reason: `current can't be read (${err.message})`, path: currentPath(home) };
|
|
251
|
+
}
|
|
252
|
+
if (text === null)
|
|
253
|
+
return { state: "none" };
|
|
254
|
+
const id = text.trim();
|
|
255
|
+
if (!ID.test(id))
|
|
256
|
+
return { state: "unknown", reason: "current names no attempt", path: currentPath(home) };
|
|
257
|
+
let body;
|
|
258
|
+
try {
|
|
259
|
+
body = io.read(recordPath(home, id));
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
return { state: "unknown", reason: `the attempt record can't be read (${err.message})`, path: recordPath(home, id) };
|
|
263
|
+
}
|
|
264
|
+
if (body === null)
|
|
265
|
+
return { state: "unknown", reason: "current names an attempt with no record", path: recordPath(home, id) };
|
|
266
|
+
const attempt = parseRecord(body, id);
|
|
267
|
+
if (!attempt)
|
|
268
|
+
return { state: "unknown", reason: "the attempt record isn't valid", path: recordPath(home, id) };
|
|
269
|
+
if (attempt.stage === "manual-recovery")
|
|
270
|
+
return { state: "manual", attempt };
|
|
271
|
+
if (TERMINAL.has(attempt.stage))
|
|
272
|
+
return { state: "closing", attempt };
|
|
273
|
+
return { state: "open", attempt };
|
|
274
|
+
}
|
|
275
|
+
/** §2.4 step 3, for a "closing" journal: clear `current` (rename it into the attempt). Only under the home lock. */
|
|
276
|
+
export function finishClosing(home, attempt, io = defaultJournalIo) {
|
|
277
|
+
if (!TERMINAL.has(attempt.stage) || attempt.stage === "manual-recovery")
|
|
278
|
+
throw new Error(`attempt ${attempt.id} is not closing`);
|
|
279
|
+
renameDurable(io, currentPath(home), join(attemptDir(home, attempt.id), "current.closed"));
|
|
280
|
+
io.step("current-cleared");
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* §5.7 (rev 16, Fable Go back design): the update transaction's protocol, stamped into every attempt at open by the code
|
|
284
|
+
* that drives it — the OLD install's updater — so a later Go back knows what the version it would return to speaks
|
|
285
|
+
* (handoff takeover, the fleet's hand-back). Bump it when a version can't take part in a transaction an older one could.
|
|
286
|
+
*/
|
|
287
|
+
export const UPDATE_TX_PROTOCOL = 1;
|
|
288
|
+
export function openAttempt(home, init, io = defaultJournalIo) {
|
|
289
|
+
if (!ID.test(init.id))
|
|
290
|
+
return { ok: false, reason: "not an attempt id" };
|
|
291
|
+
let read = readCurrent(home, io);
|
|
292
|
+
if (read.state === "closing") {
|
|
293
|
+
finishClosing(home, read.attempt, io);
|
|
294
|
+
read = readCurrent(home, io);
|
|
295
|
+
}
|
|
296
|
+
if (read.state !== "none")
|
|
297
|
+
return { ok: false, reason: read.state === "unknown" ? `the update journal is unknown: ${read.reason} (${read.path})` : `attempt ${read.attempt.id} is ${read.attempt.stage}` };
|
|
298
|
+
const at = io.now().toISOString();
|
|
299
|
+
const attempt = { ...(init.extra ?? {}), txProtocol: UPDATE_TX_PROTOCOL, schema: 1, id: init.id, kind: init.kind, createdAt: at, updater: init.updater, from: init.from, to: init.to,
|
|
300
|
+
...(init.goBackOf ? { goBackOf: init.goBackOf } : {}), stage: "opened", history: [{ stage: "opened", at }] };
|
|
301
|
+
// The chain .update-journal/attempts/<id> made durable first; the attempt's directory must be new (never rebound).
|
|
302
|
+
mkdirDurable(io, home, attemptDir(home, init.id), true);
|
|
303
|
+
writeNew(io, recordPath(home, init.id), JSON.stringify(attempt, null, 2) + "\n");
|
|
304
|
+
io.step("record-written");
|
|
305
|
+
writeAtomic(io, currentPath(home), init.id + "\n");
|
|
306
|
+
io.step("current-written");
|
|
307
|
+
return { ok: true, attempt };
|
|
308
|
+
}
|
|
309
|
+
function write(home, attempt, io, step) {
|
|
310
|
+
writeAtomic(io, recordPath(home, attempt.id), JSON.stringify(attempt, null, 2) + "\n");
|
|
311
|
+
io.step(step);
|
|
312
|
+
}
|
|
313
|
+
/** §2.3: move to `to` (refused unless the table allows it). Returns the new record; the caller keeps using it. */
|
|
314
|
+
export function advance(home, attempt, to, opts = {}, io = defaultJournalIo) {
|
|
315
|
+
if (TERMINAL.has(to))
|
|
316
|
+
throw new Error(`a terminal stage (${to}) is written by finish()`);
|
|
317
|
+
if (!canAdvance(attempt.stage, to))
|
|
318
|
+
throw new Error(`attempt ${attempt.id}: ${attempt.stage} → ${to} is not allowed`);
|
|
319
|
+
const at = io.now().toISOString();
|
|
320
|
+
const next = { ...attempt, stage: to, history: [...attempt.history, { stage: to, at, ...(opts.substep ? { substep: opts.substep } : {}), ...(opts.note ? { note: opts.note } : {}) }] };
|
|
321
|
+
if (opts.substep)
|
|
322
|
+
next.substep = opts.substep;
|
|
323
|
+
else
|
|
324
|
+
delete next.substep;
|
|
325
|
+
write(home, next, io, `stage-${to}`);
|
|
326
|
+
return next;
|
|
327
|
+
}
|
|
328
|
+
/** A substep inside the current stage (§2.3 abandoning, §5.5, §6.3): journaled after its effect is durable. */
|
|
329
|
+
export function substep(home, attempt, name, io = defaultJournalIo) {
|
|
330
|
+
if (TERMINAL.has(attempt.stage))
|
|
331
|
+
throw new Error(`attempt ${attempt.id} is ${attempt.stage}`);
|
|
332
|
+
const next = { ...attempt, substep: name, history: [...attempt.history, { stage: attempt.stage, substep: name, at: io.now().toISOString() }] };
|
|
333
|
+
write(home, next, io, `substep-${name}`);
|
|
334
|
+
return next;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* §2.4 "Terminal": a rollback's mark first, then the terminal record, then `current` cleared — except manual-recovery,
|
|
338
|
+
* which keeps `current` until a person resolves it.
|
|
339
|
+
*/
|
|
340
|
+
export function finish(home, attempt, outcome, io = defaultJournalIo) {
|
|
341
|
+
const to = outcome.kind;
|
|
342
|
+
const allowed = to === "manual-recovery" ? !TERMINAL.has(attempt.stage)
|
|
343
|
+
: (to === "abandoned" && attempt.stage === "abandoning") || (to === "rolled-back" && attempt.stage === "rolling-back")
|
|
344
|
+
|| (to === "committed" && attempt.stage === "committing");
|
|
345
|
+
if (!allowed)
|
|
346
|
+
throw new Error(`attempt ${attempt.id}: ${attempt.stage} → ${to} is not allowed`);
|
|
347
|
+
if (outcome.kind === "rolled-back")
|
|
348
|
+
appendMark(home, { version: attempt.to.version, integrity: attempt.to.integrity, attemptId: attempt.id }, io);
|
|
349
|
+
const at = io.now().toISOString();
|
|
350
|
+
const next = { ...attempt, stage: to, history: [...attempt.history, { stage: to, at, ...(outcome.reason ? { note: outcome.reason } : {}) }],
|
|
351
|
+
outcome: { kind: outcome.kind, ...(outcome.reason ? { reason: outcome.reason } : {}), at } };
|
|
352
|
+
delete next.substep;
|
|
353
|
+
write(home, next, io, `terminal-${to}`);
|
|
354
|
+
if (to !== "manual-recovery")
|
|
355
|
+
finishClosing(home, next, io);
|
|
356
|
+
return next;
|
|
357
|
+
}
|
|
358
|
+
/** `marks.json`; unreadable is never "no marks" (§2.5): the caller refuses every automatic or required update. */
|
|
359
|
+
export function readMarks(home, io = defaultJournalIo) {
|
|
360
|
+
let text;
|
|
361
|
+
try {
|
|
362
|
+
text = io.read(marksPath(home));
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
365
|
+
return { ok: false, reason: err.message };
|
|
366
|
+
}
|
|
367
|
+
if (text === null)
|
|
368
|
+
return { ok: true, marks: [] };
|
|
369
|
+
try {
|
|
370
|
+
const v = JSON.parse(text);
|
|
371
|
+
const valid = (m) => isObj(m) && nonEmpty(m.version) && (m.integrity === null || nonEmpty(m.integrity))
|
|
372
|
+
&& typeof m.attemptId === "string" && ID.test(m.attemptId) && isTime(m.at);
|
|
373
|
+
if (!Array.isArray(v) || !v.every(valid))
|
|
374
|
+
return { ok: false, reason: "marks.json isn't a list of valid marks" };
|
|
375
|
+
return { ok: true, marks: v };
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
return { ok: false, reason: "marks.json isn't JSON" };
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/** Append-only: the whole list rewritten atomically with the new mark (never pruned). Refuses on an unreadable list. */
|
|
382
|
+
export function appendMark(home, mark, io = defaultJournalIo) {
|
|
383
|
+
const read = readMarks(home, io);
|
|
384
|
+
if (!read.ok)
|
|
385
|
+
throw new Error(`marks.json can't be read, so no mark is written over it: ${read.reason}`);
|
|
386
|
+
const landed = read.marks.find(m => m.attemptId === mark.attemptId);
|
|
387
|
+
if (landed) {
|
|
388
|
+
// A retry after the mark's rename landed (Prism #4494 R3): it must be this mark, and durable before the caller
|
|
389
|
+
// publishes anything that depends on it (a terminal record), so the directory is synced again.
|
|
390
|
+
if (landed.version !== mark.version || landed.integrity !== mark.integrity)
|
|
391
|
+
throw new Error(`marks.json holds another mark for attempt ${mark.attemptId}`);
|
|
392
|
+
io.fsyncDir(journalDir(home));
|
|
393
|
+
io.step(`fsync-dir:${basename(journalDir(home))}`);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
mkdirDurable(io, home, journalDir(home));
|
|
397
|
+
writeAtomic(io, marksPath(home), JSON.stringify([...read.marks, { ...mark, at: mark.at ?? io.now().toISOString() }], null, 2) + "\n");
|
|
398
|
+
io.step("mark-written");
|
|
399
|
+
}
|
|
400
|
+
/** Whether a version rolled back here (automatic and required updates never retry it). Unknown marks: "unknown". */
|
|
401
|
+
export function isMarked(home, artifact, io = defaultJournalIo) {
|
|
402
|
+
const read = readMarks(home, io);
|
|
403
|
+
if (!read.ok)
|
|
404
|
+
return "unknown";
|
|
405
|
+
return read.marks.some(m => m.version === artifact.version && (m.integrity === null || artifact.integrity === null || m.integrity === artifact.integrity));
|
|
406
|
+
}
|
|
407
|
+
export const SEQ_WIDTH = 12;
|
|
408
|
+
const pad = (seq) => { if (!Number.isSafeInteger(seq) || seq < 0)
|
|
409
|
+
throw new Error("seq must be a non-negative integer"); return String(seq).padStart(SEQ_WIDTH, "0"); };
|
|
410
|
+
export const inboxName = (seq, source) => `${pad(seq)}-${source}.json`;
|
|
411
|
+
export const deferredName = (seq) => `${pad(seq)}.json`;
|
|
412
|
+
/** The outbox `source_key` a copy is admitted under: stable per attempt and seq, so a replay reuses its row (§2.6). */
|
|
413
|
+
export const handbackSourceKey = (attemptId, seq) => `update-handback:${attemptId}:${pad(seq)}`;
|
|
414
|
+
export function writeInboxItem(home, attemptId, seq, source, item, io = defaultJournalIo) {
|
|
415
|
+
const dir = join(attemptDir(home, attemptId), "inbox");
|
|
416
|
+
mkdirDurable(io, home, dir);
|
|
417
|
+
writeNew(io, join(dir, inboxName(seq, source)), JSON.stringify(item) + "\n"); // an accepted item is never replaced
|
|
418
|
+
io.step(`inbox-${seq}`);
|
|
419
|
+
}
|
|
420
|
+
export function writeDeferred(home, attemptId, seq, job, io = defaultJournalIo) {
|
|
421
|
+
const dir = join(attemptDir(home, attemptId), "deferred");
|
|
422
|
+
mkdirDurable(io, home, dir);
|
|
423
|
+
writeNew(io, join(dir, deferredName(seq)), JSON.stringify({ seq, ...job }) + "\n");
|
|
424
|
+
io.step(`deferred-${seq}`);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Everything to hand back, in the one sequence order (§2.6). An unreadable or invalid item throws: hand-back never
|
|
428
|
+
* skips an item it can't read.
|
|
429
|
+
*/
|
|
430
|
+
export function listHandback(home, attemptId, io = defaultJournalIo) {
|
|
431
|
+
const out = [];
|
|
432
|
+
const inbox = join(attemptDir(home, attemptId), "inbox"), deferred = join(attemptDir(home, attemptId), "deferred");
|
|
433
|
+
const inboxFiles = io.list(inbox), deferredFiles = io.list(deferred);
|
|
434
|
+
for (const f of inboxFiles) {
|
|
435
|
+
const m = /^(\d{12})-(outbox|adapter|web|hub)\.json$/.exec(f);
|
|
436
|
+
if (!m)
|
|
437
|
+
continue;
|
|
438
|
+
const text = io.read(join(inbox, f));
|
|
439
|
+
if (text === null)
|
|
440
|
+
throw new Error(`inbox item ${f} vanished`);
|
|
441
|
+
const item = JSON.parse(text);
|
|
442
|
+
if (!(item.kind === "reference" && typeof item.deliveryId === "string" && Number.isSafeInteger(item.createdSeq)) && !(item.kind === "copy" && "body" in item && typeof item.target === "string" && item.target !== ""))
|
|
443
|
+
throw new Error(`inbox item ${f} isn't valid`);
|
|
444
|
+
out.push({ seq: Number(m[1]), kind: "inbox", source: m[2], file: join(inbox, f), item, acked: inboxFiles.includes(`${f}.acked`) });
|
|
445
|
+
}
|
|
446
|
+
for (const f of deferredFiles) {
|
|
447
|
+
const m = /^(\d{12})\.json$/.exec(f);
|
|
448
|
+
if (!m)
|
|
449
|
+
continue;
|
|
450
|
+
const text = io.read(join(deferred, f));
|
|
451
|
+
if (text === null)
|
|
452
|
+
throw new Error(`deferred job ${f} vanished`);
|
|
453
|
+
const job = JSON.parse(text);
|
|
454
|
+
if (job.seq !== Number(m[1]) || typeof job.scheduleId !== "string" || typeof job.runId !== "string")
|
|
455
|
+
throw new Error(`deferred job ${f} isn't valid`);
|
|
456
|
+
out.push({ seq: job.seq, kind: "deferred", file: join(deferred, f), job: { scheduleId: job.scheduleId, runId: job.runId },
|
|
457
|
+
started: deferredFiles.includes(`${f}.started`), acked: deferredFiles.includes(`${f}.acked`) });
|
|
458
|
+
}
|
|
459
|
+
const seqs = out.map(e => e.seq);
|
|
460
|
+
if (new Set(seqs).size !== seqs.length)
|
|
461
|
+
throw new Error("two hand-back items share a sequence number");
|
|
462
|
+
return out.sort((a, b) => a.seq - b.seq);
|
|
463
|
+
}
|
|
464
|
+
/** `<file>.started` (a deferred job, before it runs) and `<file>.acked` (after its hand-back took effect). */
|
|
465
|
+
export function markHandback(entry, mark, io = defaultJournalIo) {
|
|
466
|
+
if (mark === "started" && entry.kind !== "deferred")
|
|
467
|
+
throw new Error("only a deferred job is marked started");
|
|
468
|
+
const path = `${entry.file}.${mark}`;
|
|
469
|
+
if (io.read(path) !== null)
|
|
470
|
+
return; // already marked: a mark is a fact, never rewritten
|
|
471
|
+
writeNew(io, path, JSON.stringify({ at: io.now().toISOString(), ...(entry.kind === "deferred" ? { runId: entry.job.runId } : {}) }) + "\n");
|
|
472
|
+
io.step(`${mark}-${entry.seq}`);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* What a resumed hand-back does with one entry (§2.6). A deferred job started but not acknowledged was interrupted: it
|
|
476
|
+
* is recorded, never re-run (at most once).
|
|
477
|
+
*/
|
|
478
|
+
export function handbackAction(entry) {
|
|
479
|
+
if (entry.acked)
|
|
480
|
+
return "skip";
|
|
481
|
+
if (entry.kind === "inbox")
|
|
482
|
+
return entry.item.kind === "reference" ? "claim" : "admit-then-claim";
|
|
483
|
+
return entry.started ? "record-interrupted" : "run";
|
|
484
|
+
}
|
|
485
|
+
/** The fleet's cancel request (§2.6): written only while the card is cancellable. */
|
|
486
|
+
export function writeCancel(home, attemptId, cancel, io = defaultJournalIo) {
|
|
487
|
+
const path = join(attemptDir(home, attemptId), "cancel");
|
|
488
|
+
if (io.read(path) !== null)
|
|
489
|
+
return; // one cancel stands; a second one adds nothing
|
|
490
|
+
writeNew(io, path, JSON.stringify({ ...cancel, at: io.now().toISOString() }) + "\n");
|
|
491
|
+
io.step("cancel-written");
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* The updater consumes a cancel by the stage it finds (§2.6), under the home lock, crash-safe (Prism #4494 1):
|
|
495
|
+
* honoured (opened, barrier, stopping with no snapshot): `abandoning` is journaled FIRST, then the marker becomes
|
|
496
|
+
* `cancel.consumed`. A retry finds either the marker still there with the attempt already abandoning (it only
|
|
497
|
+
* retires the marker), or no marker (nothing to do).
|
|
498
|
+
* too late: a history note is journaled first, then the marker becomes `cancel.ignored-<stage>`.
|
|
499
|
+
* Returns the outcome and the attempt as now recorded.
|
|
500
|
+
*/
|
|
501
|
+
export function consumeCancel(home, attempt, snapshotPublished, io = defaultJournalIo) {
|
|
502
|
+
const path = join(attemptDir(home, attempt.id), "cancel");
|
|
503
|
+
const text = io.read(path);
|
|
504
|
+
if (text === null)
|
|
505
|
+
return { result: "none", attempt };
|
|
506
|
+
let reason = "cancelled";
|
|
507
|
+
try {
|
|
508
|
+
const c = JSON.parse(text);
|
|
509
|
+
if (nonEmpty(c.reason))
|
|
510
|
+
reason = c.reason;
|
|
511
|
+
}
|
|
512
|
+
catch { /* the request stands; its words don't */ }
|
|
513
|
+
const honour = attempt.stage === "abandoning" || attempt.stage === "opened" || attempt.stage === "barrier" || (attempt.stage === "stopping" && !snapshotPublished);
|
|
514
|
+
let next = attempt;
|
|
515
|
+
if (honour) {
|
|
516
|
+
if (attempt.stage !== "abandoning")
|
|
517
|
+
next = advance(home, attempt, "abandoning", { note: `cancel: ${reason}` }, io);
|
|
518
|
+
renameDurable(io, path, `${path}.consumed`);
|
|
519
|
+
return { result: "honoured", attempt: next };
|
|
520
|
+
}
|
|
521
|
+
const note = `cancel too late at ${attempt.stage}: ${reason}`;
|
|
522
|
+
if (attempt.history[attempt.history.length - 1]?.note !== note) {
|
|
523
|
+
next = { ...attempt, history: [...attempt.history, { stage: attempt.stage, at: io.now().toISOString(), note }] };
|
|
524
|
+
write(home, next, io, "cancel-ignored-noted");
|
|
525
|
+
}
|
|
526
|
+
renameDurable(io, path, `${path}.ignored-${attempt.stage}`);
|
|
527
|
+
return { result: "too-late", attempt: next };
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* §7, a pure function: what a fleet start (or the recovery runner) does with the journal it read. `ownStart`: this start
|
|
531
|
+
* holds the attempt's planned handoff nonce (it is the attempt's own start).
|
|
532
|
+
*/
|
|
533
|
+
export function recoveryPlan(read, updater, ownStart = false) {
|
|
534
|
+
switch (read.state) {
|
|
535
|
+
case "none": return { kind: "start" };
|
|
536
|
+
case "unknown": return { kind: "refuse", reason: "unknown" };
|
|
537
|
+
case "manual": return { kind: "refuse", reason: "manual", attemptId: read.attempt.id, stage: read.attempt.stage };
|
|
538
|
+
case "closing": return { kind: "finish-closing", attemptId: read.attempt.id };
|
|
539
|
+
}
|
|
540
|
+
const a = read.attempt;
|
|
541
|
+
if (updater === "live")
|
|
542
|
+
return ownStart ? { kind: "start" } : { kind: "refuse", reason: "in-progress", attemptId: a.id, stage: a.stage };
|
|
543
|
+
if (updater === "unknown")
|
|
544
|
+
return { kind: "refuse", reason: "updater-unknown", attemptId: a.id, stage: a.stage };
|
|
545
|
+
const sub = a.substep ? { substep: a.substep } : {};
|
|
546
|
+
switch (a.stage) {
|
|
547
|
+
case "opened":
|
|
548
|
+
case "barrier":
|
|
549
|
+
case "stopping":
|
|
550
|
+
case "abandoning": return { kind: "resume-abandoning", attemptId: a.id, ...sub };
|
|
551
|
+
case "snapshotted":
|
|
552
|
+
case "installing":
|
|
553
|
+
case "trial":
|
|
554
|
+
case "proving":
|
|
555
|
+
case "rolling-back": return { kind: "resume-rolling-back", attemptId: a.id, ...sub };
|
|
556
|
+
case "committing": return { kind: "resume-committing", attemptId: a.id, ...sub };
|
|
557
|
+
default: return { kind: "refuse", reason: "unknown" };
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* §4.3 "the fence doesn't depend on fleet.lock alone", §7: every fleet start reads the journal FIRST. It goes on only
|
|
562
|
+
* when the plan is a normal start — no attempt, a closing one (a plain start doesn't run `finishClosing`: the updater,
|
|
563
|
+
* the recovery runner or the next update does, under the home lock — 2.1c), or this
|
|
564
|
+
* start holding the open attempt's planned nonce while its updater lives. Everything else refuses, naming the attempt;
|
|
565
|
+
* resuming an interrupted attempt is the recovery runner's (2.1c), never a plain start's.
|
|
566
|
+
*/
|
|
567
|
+
export function fleetStartGate(home, handoffNonce, liveness, io = defaultJournalIo) {
|
|
568
|
+
const read = readCurrent(home, io);
|
|
569
|
+
const own = read.state === "open" && !!handoffNonce && plannedGeneration(read.attempt, handoffNonce) !== null;
|
|
570
|
+
const plan = recoveryPlan(read, read.state === "open" ? ownerState(home, read.attempt, liveness, io) : "gone", own);
|
|
571
|
+
if (plan.kind === "start" || plan.kind === "finish-closing")
|
|
572
|
+
return { ok: true };
|
|
573
|
+
// §7 (rev 13; Fable #4533 F1): an interrupted commit is admitted — this start finishes it (`resumeCommitting`), never
|
|
574
|
+
// rolls it back. Its updater is gone; fleet.lock still admits one fleet at a time.
|
|
575
|
+
if (plan.kind === "resume-committing")
|
|
576
|
+
return { ok: true, resumeCommitting: plan.attemptId };
|
|
577
|
+
if (read.state === "unknown")
|
|
578
|
+
return { ok: false, reason: `This fleet start is refused: the update journal can't be read (${read.reason}: ${read.path}). Run \`agend update --resolve\`.` };
|
|
579
|
+
const a = read.attempt;
|
|
580
|
+
if (plan.kind === "refuse" && plan.reason === "in-progress")
|
|
581
|
+
return { ok: false, reason: `AgEnD is updating (attempt ${a.id}, ${a.stage}); this fleet start is refused until the update hands over or ends.` };
|
|
582
|
+
if (plan.kind === "refuse" && plan.reason === "manual")
|
|
583
|
+
return { ok: false, reason: `This fleet start is refused: update attempt ${a.id} needs manual recovery. Run \`agend update --resolve\`.` };
|
|
584
|
+
return { ok: false, reason: `This fleet start is refused: update attempt ${a.id} (${a.stage}) was interrupted and must be recovered first. Run \`agend update --resolve\`.` };
|
|
585
|
+
}
|
|
586
|
+
/** The publication primitives, for the crash tests only. */
|
|
587
|
+
export const journalPrimitivesForTests = { writeNew, writeAtomic, mkdirDurable };
|
|
588
|
+
const generationsOf = (a) => (Array.isArray(a.fleets) ? a.fleets : []);
|
|
589
|
+
/** §3.3: journal a generation with a fresh nonce BEFORE it is started (substep `start-planned`). */
|
|
590
|
+
export function planGeneration(home, attempt, gen, nonce, io = defaultJournalIo) {
|
|
591
|
+
if (!/^[0-9a-f]{32}$/.test(nonce))
|
|
592
|
+
throw new Error("a handoff nonce is 32 hex digits");
|
|
593
|
+
if (generationsOf(attempt).some(g => g.nonce === nonce))
|
|
594
|
+
throw new Error("a nonce is never reused");
|
|
595
|
+
const fleets = [...generationsOf(attempt), { gen, nonce, plannedAt: io.now().toISOString() }];
|
|
596
|
+
return substep(home, { ...attempt, fleets }, "start-planned", io);
|
|
597
|
+
}
|
|
598
|
+
/** The generation a nonce names, if it is planned and not yet consumed or voided. */
|
|
599
|
+
export function plannedGeneration(attempt, nonce) {
|
|
600
|
+
return generationsOf(attempt).find(g => g.nonce === nonce && !g.consumed && !g.dead) ?? null;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* §4.3 step 1: the single-use claim of a handoff. Only for the open attempt's planned, unconsumed nonce; created with
|
|
604
|
+
* O_EXCL and synced, so exactly one contender wins. Returns false when another holds it or the nonce isn't planned.
|
|
605
|
+
*/
|
|
606
|
+
export function claimHandoff(home, attemptId, nonce, claimant, liveness, io = defaultJournalIo) {
|
|
607
|
+
const read = readCurrent(home, io);
|
|
608
|
+
if (read.state !== "open" || read.attempt.id !== attemptId || !plannedGeneration(read.attempt, nonce))
|
|
609
|
+
return false;
|
|
610
|
+
// §2.7, §7: only while the attempt's owner (its updater, or the recovery runner acting for it) lives. A gone or
|
|
611
|
+
// unknown owner's planned nonce hands nothing over (a start holding it then refuses; pre-start starts the runner).
|
|
612
|
+
if (ownerState(home, read.attempt, liveness, io) !== "live")
|
|
613
|
+
return false;
|
|
614
|
+
const path = join(attemptDir(home, attemptId), `handoff-${nonce}.claim`);
|
|
615
|
+
try {
|
|
616
|
+
writeNew(io, path, JSON.stringify({ pid: claimant.pid, start: claimant.start }) + "\n");
|
|
617
|
+
}
|
|
618
|
+
catch {
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
// An exact retry by the same claimant is fine; another claimant's bytes differ, and writeNew refused them above.
|
|
622
|
+
return true;
|
|
623
|
+
}
|
|
624
|
+
/** §4.3 step 3: the updater acknowledges a takeover: the generation's pid recorded, its nonce consumed. */
|
|
625
|
+
export function ackGeneration(home, attempt, nonce, pid, opts = {}, io = defaultJournalIo) {
|
|
626
|
+
if (!isPid(pid))
|
|
627
|
+
throw new Error("a generation's pid is a positive integer");
|
|
628
|
+
const fleets = generationsOf(attempt).map(g => (g.nonce === nonce ? { ...g, pid, consumed: true, ...(opts.dead ? { dead: true } : {}) } : g));
|
|
629
|
+
if (!fleets.some(g => g.nonce === nonce))
|
|
630
|
+
throw new Error("no generation was planned with that nonce");
|
|
631
|
+
return substep(home, { ...attempt, fleets }, opts.dead ? "start-dead" : "start-acknowledged", io);
|
|
632
|
+
}
|
|
633
|
+
const startOf = (pid, start) => ({ pid, processStart: start.processStart, ...(start.startTicks !== undefined ? { startTicks: start.startTicks, bootId: start.bootId } : {}) });
|
|
634
|
+
/**
|
|
635
|
+
* §2.7: the attempt's updater, by install-lock's `holderState` on its `{ pid, start }`. `gone` only on proof (no such
|
|
636
|
+
* pid, or another start in this boot); `unknown` never authorizes anything. The attempt's owner — this, or the recovery
|
|
637
|
+
* runner — is `ownerState`.
|
|
638
|
+
*/
|
|
639
|
+
export function updaterState(attempt, deps) {
|
|
640
|
+
const state = holderState(startOf(attempt.updater.pid, attempt.updater.start), deps);
|
|
641
|
+
return state === "stale" ? "gone" : state;
|
|
642
|
+
}
|
|
643
|
+
/** §6.2: the recovery runner's identity, written after it holds the three locks (the bootstrap handshake's answer). */
|
|
644
|
+
export const RUNNER_FILE = "runner.json";
|
|
645
|
+
export const runnerPath = (home, id) => join(attemptDir(home, id), RUNNER_FILE);
|
|
646
|
+
export function writeRunnerRecord(home, attemptId, runner, io = defaultJournalIo) {
|
|
647
|
+
if (!isPid(runner.pid) || !isStart(runner.start))
|
|
648
|
+
throw new Error("a runner record needs a pid and a start");
|
|
649
|
+
writeAtomic(io, runnerPath(home, attemptId), JSON.stringify({ pid: runner.pid, start: runner.start }) + "\n");
|
|
650
|
+
}
|
|
651
|
+
/** The runner's record: absent (null), its identity, or "unreadable" (never taken as absent). */
|
|
652
|
+
export function readRunnerRecord(home, attemptId, io = defaultJournalIo) {
|
|
653
|
+
let text;
|
|
654
|
+
try {
|
|
655
|
+
text = io.read(runnerPath(home, attemptId));
|
|
656
|
+
}
|
|
657
|
+
catch {
|
|
658
|
+
return "unreadable";
|
|
659
|
+
}
|
|
660
|
+
if (text === null)
|
|
661
|
+
return null;
|
|
662
|
+
try {
|
|
663
|
+
const r = JSON.parse(text);
|
|
664
|
+
return isObj(r) && isPid(r.pid) && isStart(r.start) ? { pid: r.pid, start: r.start } : "unreadable";
|
|
665
|
+
}
|
|
666
|
+
catch {
|
|
667
|
+
return "unreadable";
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* §2.7, §6.2: the attempt's owner — its updater, or the recovery runner acting for a gone one. Unknown when either
|
|
672
|
+
* can't be told (or the runner's record can't be read) — whatever the other is; otherwise live when either is live;
|
|
673
|
+
* gone only when both are proven gone (or no runner was ever recorded).
|
|
674
|
+
*/
|
|
675
|
+
export function ownerState(home, attempt, deps, io = defaultJournalIo) {
|
|
676
|
+
const updater = updaterState(attempt, deps);
|
|
677
|
+
const record = readRunnerRecord(home, attempt.id, io);
|
|
678
|
+
const runner = record === null ? "gone" : record === "unreadable" ? "unknown"
|
|
679
|
+
: (s => (s === "stale" ? "gone" : s))(holderState(startOf(record.pid, record.start), deps));
|
|
680
|
+
// Unknown evidence on either side is never outweighed (design §6.2's "liveness unknown" row; Prism #4511): a live
|
|
681
|
+
// updater beside a runner that can't be told — or the reverse — refuses, as does a record that can't be read.
|
|
682
|
+
if (updater === "unknown" || runner === "unknown")
|
|
683
|
+
return "unknown";
|
|
684
|
+
if (updater === "live" || runner === "live")
|
|
685
|
+
return "live";
|
|
686
|
+
return "gone";
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* §4.3: the updater takes back a planned handoff (to replace or clear it) by taking its single-use claim itself — the
|
|
690
|
+
* same O_EXCL file a start's `claimHandoff` creates, so exactly one of them wins. True: revoked (no start can claim it
|
|
691
|
+
* now; an exact retry by the same updater is fine). False: a start already holds the claim — the updater must not
|
|
692
|
+
* rewrite fleet.lock; it acknowledges or voids that generation instead.
|
|
693
|
+
*/
|
|
694
|
+
export function revokeHandoff(home, attemptId, nonce, updater, liveness, io = defaultJournalIo) {
|
|
695
|
+
if (!/^[0-9a-f]{32}$/.test(nonce))
|
|
696
|
+
throw new Error("a handoff nonce is 32 hex digits");
|
|
697
|
+
const path = join(attemptDir(home, attemptId), `handoff-${nonce}.claim`);
|
|
698
|
+
try {
|
|
699
|
+
writeNew(io, path, JSON.stringify({ revokedBy: updater.pid, start: updater.start }) + "\n");
|
|
700
|
+
return "revoked";
|
|
701
|
+
}
|
|
702
|
+
catch { /* a start holds the claim (or it can't be written): judge its holder */ }
|
|
703
|
+
// §4.3 "a claim left by a claimant that died": a claimant proven gone can never rename over fleet.lock, so the
|
|
704
|
+
// updater may go on — voiding that nonce (voidGeneration) and planning a new one. An unknown claimant is never voided.
|
|
705
|
+
// Every failure from here on (an unreadable or malformed claim, a probe that throws) is "claimant-unknown": the
|
|
706
|
+
// updater rewrites nothing on it (Prism #4499 R2).
|
|
707
|
+
try {
|
|
708
|
+
const claim = JSON.parse(io.read(path) ?? "null");
|
|
709
|
+
if (!isObj(claim) || !isPid(claim.pid) || !isStart(claim.start))
|
|
710
|
+
return "claimant-unknown";
|
|
711
|
+
const state = holderState(startOf(claim.pid, claim.start), liveness);
|
|
712
|
+
return state === "stale" ? "claimant-gone" : state === "live" ? "claimed-live" : "claimant-unknown";
|
|
713
|
+
}
|
|
714
|
+
catch {
|
|
715
|
+
return "claimant-unknown";
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
/** A nonce whose claimant is proven gone with the update's fence still in place: void, never reused (§4.3). */
|
|
719
|
+
export function voidGeneration(home, attempt, nonce, io = defaultJournalIo) {
|
|
720
|
+
const fleets = generationsOf(attempt).map(g => (g.nonce === nonce ? { ...g, consumed: true, dead: true } : g));
|
|
721
|
+
return substep(home, { ...attempt, fleets }, "start-voided", io);
|
|
722
|
+
}
|
|
723
|
+
//# sourceMappingURL=update-journal.js.map
|