@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
package/dist/fleet-manager.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requestDeliveryView, requestContextDisplayView } from "./request-context-view.js";
|
|
2
|
+
import { captureRequestHubOutput } from "./request-hub-output.js";
|
|
3
|
+
import { assertRequestContextOperation, requireRequestContextPolicy, RequestContextPolicyError } from "./request-context-policy.js";
|
|
4
|
+
import { permitWebContinuation } from "./web-continuation.js";
|
|
5
|
+
import { nativeContactCardText, nativeContactOutcome, nativeContactPrincipal, nativeDecisionFailure } from "./request-contact-native.js";
|
|
6
|
+
import { RequestContextReferenceMap } from "./request-context-fence.js";
|
|
7
|
+
import { ContactChangeSchema, prepareContactChange, resolvePendingTicket, shortContactTicketId } from "./contact-change-proposals.js";
|
|
2
8
|
import { contactStateView, ownContactRequestsView } from "./contact-state-view.js";
|
|
3
9
|
import { detectMonitoringPlatform } from './host-monitoring-defaults.js';
|
|
4
10
|
import { SharedDefaultAdoption } from "./shared-default-adoption.js";
|
|
@@ -73,7 +79,7 @@ import { handleWebIconRequest, useAppIconStore } from "./web-icons.js";
|
|
|
73
79
|
import { AppIconStore } from "./web-app-icon.js";
|
|
74
80
|
import { trackWebServer } from "./web-server-drain.js";
|
|
75
81
|
import { renderPublicLinkProgress, ThrottledMessageEditor } from "./public-link-progress.js";
|
|
76
|
-
import { PublicWebLink, publicLinkNamedHostname, publicLinkSettings } from "./public-web-link.js";
|
|
82
|
+
import { PublicWebLink, publicLinkNamedHostname, publicLinkPreviewHostname, publicLinkSettings } from "./public-web-link.js";
|
|
77
83
|
import { PublicLinkAutoOpen } from "./public-link-auto-open.js";
|
|
78
84
|
import { clearPublicLinkOwner, readPublicLinkOwner, writePublicLinkOwner } from "./public-link-owner.js";
|
|
79
85
|
import { PUBLIC_PREVIEW_FRAME_SRC, PUBLIC_PREVIEW_TUNNEL_DIR, PublicPreview, publicPreviewWanted } from "./public-preview.js";
|
|
@@ -81,7 +87,7 @@ import { CloudflaredProvider } from "./tunnel/cloudflared.js";
|
|
|
81
87
|
import { ensureCloudflared } from "./tunnel/cloudflared-install.js";
|
|
82
88
|
import { installExitMarker, unattendedInstallCommand, loginShell } from "./unattended-install.js";
|
|
83
89
|
import { InstallStream } from "./install-stream.js";
|
|
84
|
-
import { namedTestLane, runNamedLinkTest } from "./tunnel/named-link-test.js";
|
|
90
|
+
import { namedTestLane, runNamedLinkTest, runPreviewRouteTest } from "./tunnel/named-link-test.js";
|
|
85
91
|
import { daemonTopicMode, isWebOnlyFleetConfig } from "./web-only-fleet.js";
|
|
86
92
|
import { OFFICE_SHARE_TUNNEL_DIR, OfficeShareService } from "./office-share-service.js";
|
|
87
93
|
import { OfficeTalk } from "./office-talk.js";
|
|
@@ -274,7 +280,7 @@ import { WebChatHistory, WEB_CHAT_TEXT_MAX, isWebMessageId, newWebMessageId, web
|
|
|
274
280
|
import { WEB_ECHO_COPIES_MAX, WEB_MIRROR_TIMEOUT_MS, webReactionEmoji, webReactionProblem } from "./web-reactions.js";
|
|
275
281
|
import { WebChatDiskStore, isSafeInstanceDirName } from "./web-chat-store.js";
|
|
276
282
|
import { WebChatArchive } from "./web-chat-archive.js";
|
|
277
|
-
import { SeenUsers, resolveMentions } from "./web-mentions.js";
|
|
283
|
+
import { SEEN_USERS_FILE, SeenUsers, resolveMentions } from "./web-mentions.js";
|
|
278
284
|
import { OPERATOR, WebPrefsStore } from "./web-prefs.js";
|
|
279
285
|
import { agendVersion } from "./agent-whats-new.js";
|
|
280
286
|
import { OwnerCssStore } from "./web-owner-css-store.js";
|
|
@@ -322,11 +328,16 @@ import { WebSettingsTools } from "./web-settings-tools.js";
|
|
|
322
328
|
import { GUEST_COMMAND_RUNS, GUEST_PREF_WRITES, GUEST_SEARCHES, bindGuestRequest, guestRouteDecision } from "./web-guest-access.js";
|
|
323
329
|
import { GUEST_ROOM_TICK_MS, GuestRoomMembership, guestGroupRooms } from "./web-guest-rooms.js";
|
|
324
330
|
import { Delegations, TrafficLog, trafficItem } from "./fleet-traffic.js";
|
|
331
|
+
import { QuiescenceBarrier, stripHumanReceipt, UPDATE_HANDBACK_COPY_KIND, UPDATE_HANDBACK_SOURCE, handbackDue, turnSource } from "./update-quiescence.js";
|
|
332
|
+
import { readCurrent as readUpdateJournal } from "./update-journal.js";
|
|
325
333
|
import { installedChannel, updateNoticeKey } from "./update-check.js";
|
|
334
|
+
import { idleClaimOutcome, idleUpdateMessageId, UpdateOfferCard, updateAnswerLabel, updateOfferReply } from "./update-card.js";
|
|
335
|
+
import { preflightAllows } from "./update-readiness.js";
|
|
336
|
+
import { inUpdatePause, resolveUpdates } from "./update-settings.js";
|
|
326
337
|
import { resolveInstalledAgend, npmForRunningInstall } from "./update-dispatch.js";
|
|
327
338
|
import { HUB_UPDATE_NOTICE_FILE, HUB_UPDATE_REMIND_MS, hubNoticeDue, hubNoticeKey, readHubNoticeState, writeHubNoticeState } from "./hub-update-notice.js";
|
|
328
339
|
import { resolveUpdateLaunch, openUpdateLog, updateLogPath, watchUpdateLaunch } from "./update-launch.js";
|
|
329
|
-
import { isWebUpdateTarget, readLogTail, RUNNING_AGEND_VERSION, updateOffer, webProgressOf, webUpdateTarget } from "./web-update.js";
|
|
340
|
+
import { failureCause, isWebUpdateTarget, readLogTail, RUNNING_AGEND_VERSION, updateOffer, webProgressOf, webUpdateTarget } from "./web-update.js";
|
|
330
341
|
import { admitProfileLogin, LoginController, LOGIN_TOKEN_RESEND_PREFIX, POST_LOGIN_RECOVERY_DEADLINE_MS } from "./login-controller.js";
|
|
331
342
|
import { WebBackendLogins, dashboardSignInSupported } from "./web-backend-login.js";
|
|
332
343
|
import { CLAUDE_NPM_PACKAGE, claudeInstallKind, displayHostPath } from "./claude-install-kind.js";
|
|
@@ -661,13 +672,19 @@ const CLEAR_CONFIRM_CALLBACK_PREFIX = "clear-confirm:";
|
|
|
661
672
|
const KIRO_MIGRATE_CALLBACK_PREFIX = "kiro-migrate:";
|
|
662
673
|
/** M-3140: Update now on a Hub-recommended-version notice in General ("hub-update:" + 32 hex + ":update" = 50 bytes). */
|
|
663
674
|
const HUB_UPDATE_CALLBACK_PREFIX = "hub-update:";
|
|
675
|
+
/** M-3770 1.5: the update card in General's chat ("update-card:" + 32 hex + ":" + its answer). */
|
|
676
|
+
const UPDATE_CARD_CALLBACK_PREFIX = "update-card:";
|
|
677
|
+
/** M-3770 1.5: where the chat card's message is (one per fleet), so later states edit it in place across a restart. */
|
|
678
|
+
const UPDATE_CHAT_CARD_FILE = "update-chat-card.json";
|
|
679
|
+
/** The chat card's buttons live a week (Not now's own length); a newer card replaces them sooner. */
|
|
680
|
+
const UPDATE_CHAT_CARD_MS = 7 * 24 * 60 * 60_000;
|
|
664
681
|
const HUB_SHARING_CALLBACK_PREFIX = "hub-share:";
|
|
665
682
|
/** M-3680: a held contact request's card in General ("contact-ticket:" + 32 hex + ":approve" = 55 bytes, under Telegram's 64). */
|
|
666
683
|
const CONTACT_TICKET_PREFIX = "contact-ticket:";
|
|
667
684
|
/** How many requests' cards are remembered (one card per request; a decided one is forgotten at once). */
|
|
668
685
|
const HELD_CARDS_KEPT = 512;
|
|
669
686
|
/** A held request's card, retired after it was decided elsewhere (the dashboard, Needs you, another card) or closed. */
|
|
670
|
-
const heldCardOutcome = (state) => t(state === "approved" ? "contactHeld.approvedElsewhere"
|
|
687
|
+
const heldCardOutcome = (state, root = false) => t(state === "approved" ? root ? "contactCard.continued_elsewhere" : "contactHeld.approvedElsewhere"
|
|
671
688
|
: state === "declined" ? "contactHeld.declinedElsewhere" : state === "expired" ? "contactHeld.expired" : "contactHeld.closed");
|
|
672
689
|
const HUB_FLEET_UPDATE_CALLBACK_PREFIX = "hub-fleet-update:";
|
|
673
690
|
const KIRO_RECONCILE_CALLBACK_PREFIX = "kiro-reconcile:";
|
|
@@ -829,6 +846,101 @@ export class FleetManager {
|
|
|
829
846
|
static sighupHandlerInstalled = false;
|
|
830
847
|
/** Test seam: inject a spy to verify saveFleetConfig calls fsync. Default: fsyncSync. */
|
|
831
848
|
fsyncForTest = undefined;
|
|
849
|
+
/** S-244: the quiescence barrier. Unset, every pane write and admission proceeds as today. */
|
|
850
|
+
quiescence = null;
|
|
851
|
+
attachQuiescence(gate) { this.quiescence = gate; }
|
|
852
|
+
updateHandbackTimer = null;
|
|
853
|
+
/**
|
|
854
|
+
* M-3770 §2.3/§2.6 (rev 15): this fleet was restarted by an abandon as the attempt's `old` generation (its handoff
|
|
855
|
+
* nonce): it takes the held inbox and deferred jobs back. The first walk runs during the start, before the web chat,
|
|
856
|
+
* the adapters and the agents open any ingress, so a held copy keeps its place ahead of anything newer (Fable #4536
|
|
857
|
+
* design 3b): it waits, bounded, for the abandon driver to journal `restart-old`. Later walks every 10 s pick up
|
|
858
|
+
* stragglers until `hand-back` is journaled or the attempt closes.
|
|
859
|
+
*/
|
|
860
|
+
async startUpdateHandback(nonce = process.env.AGEND_UPDATE_HANDOFF ?? "", waitMs = 15_000, sleep = (ms) => new Promise(r => setTimeout(r, ms))) {
|
|
861
|
+
if (!/^[0-9a-f]{32}$/.test(nonce))
|
|
862
|
+
return;
|
|
863
|
+
const own = { nonce, pid: process.pid };
|
|
864
|
+
const mine = (a) => a.stage === "abandoning"
|
|
865
|
+
&& a.fleets?.some(g => g.gen === "old" && g.nonce === nonce) === true;
|
|
866
|
+
const until = performance.now() + waitMs;
|
|
867
|
+
for (;;) {
|
|
868
|
+
const read = readUpdateJournal(this.dataDir);
|
|
869
|
+
if (read.state !== "open" || !mine(read.attempt))
|
|
870
|
+
return;
|
|
871
|
+
if (handbackDue(read.attempt, own)) {
|
|
872
|
+
this.walkUpdateHandback(read.attempt, own);
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
if (performance.now() >= until || this.shuttingDown) {
|
|
876
|
+
this.logger.warn({ attemptId: read.attempt.id }, "Update hand-back: restart-old isn't journaled yet; the held work is taken back by the next walk");
|
|
877
|
+
break;
|
|
878
|
+
}
|
|
879
|
+
await sleep(250);
|
|
880
|
+
}
|
|
881
|
+
const again = () => {
|
|
882
|
+
this.updateHandbackTimer = null;
|
|
883
|
+
if (this.shuttingDown)
|
|
884
|
+
return;
|
|
885
|
+
const read = readUpdateJournal(this.dataDir);
|
|
886
|
+
if (read.state !== "open" || !mine(read.attempt))
|
|
887
|
+
return;
|
|
888
|
+
if (handbackDue(read.attempt, own))
|
|
889
|
+
this.walkUpdateHandback(read.attempt, own);
|
|
890
|
+
this.updateHandbackTimer = setTimeout(again, 10_000);
|
|
891
|
+
this.updateHandbackTimer.unref?.();
|
|
892
|
+
};
|
|
893
|
+
this.updateHandbackTimer = setTimeout(again, 10_000);
|
|
894
|
+
this.updateHandbackTimer.unref?.();
|
|
895
|
+
}
|
|
896
|
+
walkUpdateHandback(attempt, own) {
|
|
897
|
+
try {
|
|
898
|
+
const r = new QuiescenceBarrier(this.dataDir).runHandback(attempt, this.updateHandbackPorts(), own);
|
|
899
|
+
if (r.walked)
|
|
900
|
+
this.logger.info({ attemptId: attempt.id, acked: r.acked }, "Update hand-back walked");
|
|
901
|
+
}
|
|
902
|
+
catch (err) {
|
|
903
|
+
this.logger.warn({ err, attemptId: attempt.id }, "Update hand-back walk failed; the next walk retries");
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
/** §2.6 ports, rev 15 (Fable #4536 design): the pump owns a handed-back row again; copies go in as their own kind. */
|
|
907
|
+
updateHandbackPorts() {
|
|
908
|
+
const outbox = this.deliveryOutbox;
|
|
909
|
+
if (!outbox)
|
|
910
|
+
throw new Error("the delivery outbox isn't open");
|
|
911
|
+
return {
|
|
912
|
+
log: (fields, message) => this.logger.warn(fields, `Update hand-back: ${message}`),
|
|
913
|
+
lookup: id => { const row = outbox.get(id); return row ? { state: row.state, target: row.targetInstance } : null; },
|
|
914
|
+
// Queued and retry_wait rows (inside a backoff too) are the restarted pump's again: it delivers them per target in
|
|
915
|
+
// order. Nothing is claimed here, so the pump's lane bookkeeping stays whole.
|
|
916
|
+
claim: id => {
|
|
917
|
+
const row = outbox.get(id);
|
|
918
|
+
if (!row)
|
|
919
|
+
return "missing";
|
|
920
|
+
if (row.state !== "queued" && row.state !== "retry_wait")
|
|
921
|
+
return "settled";
|
|
922
|
+
this.scheduleDeliveryOutboxPump();
|
|
923
|
+
return "claimed";
|
|
924
|
+
},
|
|
925
|
+
admitCopy: (sourceKey, body, target) => {
|
|
926
|
+
if (!this.fleetConfig?.instances[target])
|
|
927
|
+
return null;
|
|
928
|
+
const payload = { ...body };
|
|
929
|
+
const meta = payload.meta && typeof payload.meta === "object" ? payload.meta : undefined;
|
|
930
|
+
if (meta) {
|
|
931
|
+
const stripped = stripHumanReceipt(meta);
|
|
932
|
+
payload.meta = stripped.meta;
|
|
933
|
+
if (stripped.receiptId)
|
|
934
|
+
outbox.markHumanReceiptUncertain(stripped.receiptId, target);
|
|
935
|
+
}
|
|
936
|
+
const admitted = outbox.admit({ operationId: sourceKey, sourceKey, sourceInstance: UPDATE_HANDBACK_SOURCE, sourceDaemonBootId: this.managerBootId,
|
|
937
|
+
targetInstance: target, kind: UPDATE_HANDBACK_COPY_KIND, payload });
|
|
938
|
+
return { deliveryId: admitted.delivery.deliveryId };
|
|
939
|
+
},
|
|
940
|
+
runDeferred: job => { this.scheduler?.runDeferredOccurrence(job.scheduleId, job.runId, name => !!this.fleetConfig?.instances[name]); },
|
|
941
|
+
recordInterrupted: job => { this.scheduler?.recordInterruptedOccurrence(job.scheduleId, job.runId); },
|
|
942
|
+
};
|
|
943
|
+
}
|
|
832
944
|
children = new Map();
|
|
833
945
|
lifecycle;
|
|
834
946
|
stormWindow;
|
|
@@ -1055,6 +1167,82 @@ export class FleetManager {
|
|
|
1055
1167
|
fleetConfig = null;
|
|
1056
1168
|
fleetWindowsRuntime = null;
|
|
1057
1169
|
nativeMcpStore = null;
|
|
1170
|
+
requestContextIpcCalls = new WeakMap();
|
|
1171
|
+
requestContextFleetCalls = new RequestContextReferenceMap(row => row.call.admission.coverage === "covered" ? row.call.admission.lease.snapshot.context.ref.rootContextId : null, row => `fleet-call:${row.call.id}`);
|
|
1172
|
+
setRequestContextDrainRegistration(registration) {
|
|
1173
|
+
if (this.instanceIpcClients.size)
|
|
1174
|
+
throw Error("Request context drain must bind before IPC starts");
|
|
1175
|
+
const calls = this.requestContextFleetCalls;
|
|
1176
|
+
if (!calls)
|
|
1177
|
+
throw Error("Request context drain registry unavailable");
|
|
1178
|
+
calls.installRegistration(registration);
|
|
1179
|
+
}
|
|
1180
|
+
get requestContextFleetDrainRevision() { return this.requestContextFleetCalls?.revision ?? "unavailable"; }
|
|
1181
|
+
requestContextFleetDrainView(rootId) { return this.requestContextFleetCalls?.view(rootId) ?? { registration: null, revision: "unavailable", references: [], unknown: true }; }
|
|
1182
|
+
finishRequestContextIpcCall(message) { const call = this.requestContextCallOf(message), calls = this.requestContextFleetCalls; if (call && calls)
|
|
1183
|
+
for (const [id, row] of calls)
|
|
1184
|
+
if (row.call === call)
|
|
1185
|
+
calls.delete(id); }
|
|
1186
|
+
purgeRequestContextIpcCalls(name, ipc) {
|
|
1187
|
+
const calls = this.requestContextFleetCalls;
|
|
1188
|
+
if (!calls)
|
|
1189
|
+
return;
|
|
1190
|
+
for (const [id, row] of calls)
|
|
1191
|
+
if (row.instance === name && row.ipc === ipc)
|
|
1192
|
+
calls.delete(id);
|
|
1193
|
+
}
|
|
1194
|
+
observeRequestContextResponses(name, ipc) {
|
|
1195
|
+
const calls = this.requestContextFleetCalls;
|
|
1196
|
+
if (!calls?.registrationGate)
|
|
1197
|
+
return;
|
|
1198
|
+
const send = ipc.send.bind(ipc);
|
|
1199
|
+
ipc.send = (message) => {
|
|
1200
|
+
try {
|
|
1201
|
+
return send(message);
|
|
1202
|
+
}
|
|
1203
|
+
finally {
|
|
1204
|
+
if (message && typeof message === "object") {
|
|
1205
|
+
const row = message, key = String(row.fleetRequestId ?? row.requestId ?? "");
|
|
1206
|
+
if (String(row.type ?? "").endsWith("_response") && key)
|
|
1207
|
+
for (const [id, call] of calls)
|
|
1208
|
+
if (call.instance === name && call.ipc === ipc && call.responseKey === key)
|
|
1209
|
+
calls.delete(id);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
/** Captured at IPC arrival, not a later lookup of this instance's current turn. */
|
|
1215
|
+
requestContextCallOf(message) { return this.requestContextIpcCalls?.get(message) ?? null; }
|
|
1216
|
+
captureRequestContextIpcCall(name, message, ipc) {
|
|
1217
|
+
const daemon = this.daemons.get(name);
|
|
1218
|
+
if (!daemon?.requestContextCallsRequired?.())
|
|
1219
|
+
return message.requestContextCallId === undefined;
|
|
1220
|
+
if (this.instanceIpcClients.get(name) !== ipc || message.sourceDaemonBootId !== daemon.bootId || typeof message.requestContextCallId !== "string")
|
|
1221
|
+
return false;
|
|
1222
|
+
const captured = daemon.requestContextCall(message.requestContextCallId);
|
|
1223
|
+
if (!captured)
|
|
1224
|
+
return false;
|
|
1225
|
+
const tool = message.type === "fleet_outbound" ? String(message.tool ?? "") : toolForIpcType(message.type);
|
|
1226
|
+
const originalBoot = daemon.bootId;
|
|
1227
|
+
const scoped = Object.freeze({ id: captured.id, admission: captured.admission,
|
|
1228
|
+
current: () => captured.current() && this.instanceIpcClients.get(name) === ipc && this.getDaemonBootId(name) === originalBoot
|
|
1229
|
+
&& !!tool && this.checkToolPermission("ipc-outbound", name, tool === "hub_room_status" ? "hub_room_list" : tool).allowed });
|
|
1230
|
+
const calls = this.requestContextFleetCalls;
|
|
1231
|
+
if (calls?.registrationGate) {
|
|
1232
|
+
const responseKey = String(message.fleetRequestId ?? message.requestId ?? "");
|
|
1233
|
+
const key = JSON.stringify([name, originalBoot, responseKey]);
|
|
1234
|
+
if (!responseKey || calls.has(key))
|
|
1235
|
+
return false;
|
|
1236
|
+
try {
|
|
1237
|
+
calls.set(key, { call: scoped, instance: name, bootId: originalBoot, ipc, responseKey });
|
|
1238
|
+
}
|
|
1239
|
+
catch {
|
|
1240
|
+
return false;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
this.requestContextIpcCalls.set(message, scoped);
|
|
1244
|
+
return true;
|
|
1245
|
+
}
|
|
1058
1246
|
paneManager = null;
|
|
1059
1247
|
localPaneRelay = null;
|
|
1060
1248
|
openingLocalPane = null;
|
|
@@ -1190,7 +1378,7 @@ export class FleetManager {
|
|
|
1190
1378
|
this.scheduleOwnerNoticeFlush(30_000); // a notice kept before a restart is delivered once the fleet is up
|
|
1191
1379
|
return this.runtimeHub ??= new RuntimeCoordinator(this.dataDir, {
|
|
1192
1380
|
handleMcp: (machineId, runId, body) => this.runtimeWindowsExecutor().mcp(machineId, runId, body),
|
|
1193
|
-
handlePaneMcp: async (machineId, body, current) => (await this.nativePanes()).handle(machineId, body, current),
|
|
1381
|
+
handlePaneMcp: async (machineId, body, current, stamp) => stamp ? (await this.nativePanes()).handle(machineId, body, current, stamp) : (await this.nativePanes()).handle(machineId, body, current),
|
|
1194
1382
|
warn: (fields, message) => this.logger.warn(fields, message),
|
|
1195
1383
|
// Issue, use, revocation (and a refused use) of an install-command token: ids and an opaque actor handle only, never the token.
|
|
1196
1384
|
audit: entry => {
|
|
@@ -1254,8 +1442,8 @@ export class FleetManager {
|
|
|
1254
1442
|
nativeInstanceRuntime() {
|
|
1255
1443
|
return this.fleetWindowsRuntime ??= new FleetWindowsRuntime({
|
|
1256
1444
|
owner: this, fleet: () => this.fleetConfig, save: () => this.saveFleetConfig(), stopping: () => this.shuttingDown, history: this.webChatHistory,
|
|
1257
|
-
openMcp: (instance, requestId, sandbox, stillCurrent) => this.healthServerListening
|
|
1258
|
-
? this.nativeMcpSessions().grant({ instance, requestId, sandbox, stillCurrent, endpoint: `http://127.0.0.1:${this.fleetConfig?.health_port ?? 19280}/agent` }) : null,
|
|
1445
|
+
openMcp: (instance, requestId, sandbox, stillCurrent, requestContext) => this.healthServerListening
|
|
1446
|
+
? this.nativeMcpSessions().grant({ instance, requestId, sandbox, stillCurrent, ...(requestContext ? { requestContext } : {}), endpoint: `http://127.0.0.1:${this.fleetConfig?.health_port ?? 19280}/agent` }) : null,
|
|
1259
1447
|
warn: (message, error) => this.logger.warn({ err: error }, message),
|
|
1260
1448
|
removed: name => this.nativeInstanceRemoved(name),
|
|
1261
1449
|
paneCurrent: name => this.daemons.get(name)?.nativePaneCurrent?.() === true,
|
|
@@ -1551,7 +1739,7 @@ export class FleetManager {
|
|
|
1551
1739
|
diagnostic: text => this.logger.warn({ stderr: text }, "Local Windows pane relay wrote to stderr"),
|
|
1552
1740
|
version: provider => inventory.clis.find(row => row.id === provider && row.runnable)?.version ?? null,
|
|
1553
1741
|
launch: () => launchLocalPaneRelay(this.dataDir, admit),
|
|
1554
|
-
mcp: async (body, current) => (await this.nativePanes()).handle("local", body, current),
|
|
1742
|
+
mcp: async (body, current, stamp) => stamp ? (await this.nativePanes()).handle("local", body, current, stamp) : (await this.nativePanes()).handle("local", body, current),
|
|
1555
1743
|
});
|
|
1556
1744
|
try {
|
|
1557
1745
|
admit();
|
|
@@ -1646,9 +1834,10 @@ export class FleetManager {
|
|
|
1646
1834
|
delegate_task: "delegate", request_information: "ask", report_result: "report", delivery_status: "delivery-status" };
|
|
1647
1835
|
const { nativeAgentAdmissionContext } = await import("./native-agent-admission.js");
|
|
1648
1836
|
const { dispatchAgentOperation } = await import("./agent-endpoint.js");
|
|
1649
|
-
return daemon.handlePaneToolCall(input, { current, allowed: tool => allowed(name, tool),
|
|
1837
|
+
return daemon.handlePaneToolCall(input, { current, allowed: tool => allowed(name, tool), ...(input.requestContext ? { requestContext: input.requestContext } : {}),
|
|
1650
1838
|
dispatch: (tool, args) => ops[tool] ? dispatchAgentOperation(nativeAgentAdmissionContext(this, {
|
|
1651
|
-
instance: name, current: () => current() && allowed(name, tool), taskAllowed: () => current() && allowed(name, "task"),
|
|
1839
|
+
instance: name, operation: { tool, args }, current: () => current() && allowed(name, tool), taskAllowed: () => current() && allowed(name, "task"),
|
|
1840
|
+
...(input.requestContext?.coverage === "covered" ? { requestContext: input.requestContext.lease } : input.requestContext ? { notCoveredReason: input.requestContext.reason } : {}),
|
|
1652
1841
|
}), name, ops[tool], args, input.operationId, () => current() && allowed(name, tool)) : undefined });
|
|
1653
1842
|
},
|
|
1654
1843
|
});
|
|
@@ -1982,14 +2171,251 @@ export class FleetManager {
|
|
|
1982
2171
|
await this.launchInstalledUpdate(`hub-recommended /update by ${adapterId}:${by}`, () => this.fleetAdminGate(by, adapterId) === "ok" && !this.shuttingDown && this.hubRecommendationFor(pin) !== null, advice.version);
|
|
1983
2172
|
return true;
|
|
1984
2173
|
}
|
|
2174
|
+
// ── M-3770 1.5 (design #4480 §3.1): the update card in General's chat ──────────────────────────────────────────
|
|
2175
|
+
updateChatCardBusy = false;
|
|
2176
|
+
/** #4485 review 2: a sync asked for while one ran; the running one runs again. */
|
|
2177
|
+
updateChatCardAgain = false;
|
|
2178
|
+
/** #4485 review 2: each posted card's delivery address and the version it shows, by nonce (independent of the pending map). */
|
|
2179
|
+
updateChatCardSent = new Map();
|
|
2180
|
+
/** #4485 r2: the version each card's buttons answer for, bound when its delivery starts (before the platform answers). */
|
|
2181
|
+
updateChatCardVersion = new Map();
|
|
2182
|
+
/** #4485 review 2: an answer that came while its card was still being posted (the post records it when it returns). */
|
|
2183
|
+
updateChatCardAnswered = new Map();
|
|
2184
|
+
updateChatCardTimer = null;
|
|
2185
|
+
readUpdateChatCard() {
|
|
2186
|
+
try {
|
|
2187
|
+
const r = JSON.parse(readFileSync(join(this.dataDir, UPDATE_CHAT_CARD_FILE), "utf8"));
|
|
2188
|
+
return r && typeof r.messageId === "string" ? r : null;
|
|
2189
|
+
}
|
|
2190
|
+
catch {
|
|
2191
|
+
return null;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
writeUpdateChatCard(r) {
|
|
2195
|
+
try {
|
|
2196
|
+
if (r)
|
|
2197
|
+
writeFileSync(join(this.dataDir, UPDATE_CHAT_CARD_FILE), JSON.stringify(r));
|
|
2198
|
+
else
|
|
2199
|
+
rmSync(join(this.dataDir, UPDATE_CHAT_CARD_FILE), { force: true });
|
|
2200
|
+
}
|
|
2201
|
+
catch (err) {
|
|
2202
|
+
this.logger.warn({ err }, "Update chat card state could not be saved");
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
/** The card's words for a state (the offer: two sentences, the second only where true — §3.1, Phase 1). */
|
|
2206
|
+
updateChatCardText(view, current) {
|
|
2207
|
+
if (view && view.state === "offered") {
|
|
2208
|
+
// M-3770 1.2's cached pre-flight, when this build has it (#4483): the second sentence only where it is true.
|
|
2209
|
+
const pre = this.updatePreflight;
|
|
2210
|
+
const p3 = pre?.checks.find(c => c.id === "P3");
|
|
2211
|
+
// The leader's copy pass (S-237): a title and one line, as on the web.
|
|
2212
|
+
const line = !p3 ? t("update.chatcard.continues") : p3.ok ? t("update.chatcard.back", current ?? "?") : t("update.chatcard.noWayBack");
|
|
2213
|
+
return `${t("update.chatcard.offer", view.version)}\n${line}`;
|
|
2214
|
+
}
|
|
2215
|
+
// The card's own short lines, as on the web (the leader's copy pass); anything else in /update's words.
|
|
2216
|
+
const at = (ms) => { if (!ms)
|
|
2217
|
+
return ""; const d = new Date(ms), p2 = (n) => String(n).padStart(2, "0"); return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())} ${p2(d.getHours())}:${p2(d.getMinutes())}`; };
|
|
2218
|
+
if (view?.state === "waiting-idle")
|
|
2219
|
+
return t("update.chatcard.state_waiting", view.version);
|
|
2220
|
+
if (view?.state === "scheduled")
|
|
2221
|
+
return t("update.chatcard.state_scheduled", view.version, at(view.scheduledAt));
|
|
2222
|
+
if (view?.state === "not-now")
|
|
2223
|
+
return t("update.chatcard.state_not_now", view.version, at(view.notNowUntil));
|
|
2224
|
+
if (view?.state === "updating")
|
|
2225
|
+
return t("update.chatcard.state_updating", view.version);
|
|
2226
|
+
if (view?.state === "done")
|
|
2227
|
+
return t("update.chatcard.state_done", view.version);
|
|
2228
|
+
if (view?.state === "failed")
|
|
2229
|
+
return t("update.chatcard.state_failed", view.version, current ?? "?");
|
|
2230
|
+
const reply = updateOfferReply(view, current, !!resolveUpdates(this.fleetConfig?.updates).pin);
|
|
2231
|
+
return t(reply.key, ...reply.args);
|
|
2232
|
+
}
|
|
2233
|
+
/** General's chat place for the card, or null (no General, no chat: a web-only fleet's banner says it). */
|
|
2234
|
+
updateChatCardPlace() {
|
|
2235
|
+
if (this.webOnlyPromptPlace())
|
|
2236
|
+
return null;
|
|
2237
|
+
const general = this.findGeneralInstance();
|
|
2238
|
+
const adapterId = general ? this.getInstanceAdapterId(general) : undefined;
|
|
2239
|
+
const adapter = general ? this.getAdapterForInstance(general) : undefined;
|
|
2240
|
+
const chatId = general ? this.getGroupIdForInstance(general) : undefined;
|
|
2241
|
+
const topic = general ? String(this.fleetConfig?.instances[general]?.topic_id ?? "") : "";
|
|
2242
|
+
if (!general || !adapterId || !adapter || !chatId)
|
|
2243
|
+
return null;
|
|
2244
|
+
return { general, adapter, adapterId, chatId, ...(topic ? { threadId: topic } : {}) };
|
|
2245
|
+
}
|
|
2246
|
+
/**
|
|
2247
|
+
* M-3770 1.5: keep General's one update card in step with the fleet's card (S-234's UpdateOfferCard). An offer that
|
|
2248
|
+
* newly qualifies (a new version, or back after Not now) is posted with its buttons; every later state edits that same
|
|
2249
|
+
* message (its buttons retired: the adapters cannot swap them). Never throws; one at a time.
|
|
2250
|
+
*/
|
|
2251
|
+
async syncUpdateChatCard() {
|
|
2252
|
+
// A call while one runs is not dropped: the running one syncs again when it is done (#4485 review 2).
|
|
2253
|
+
if (this.shuttingDown)
|
|
2254
|
+
return;
|
|
2255
|
+
if (this.updateChatCardBusy) {
|
|
2256
|
+
this.updateChatCardAgain = true;
|
|
2257
|
+
return;
|
|
2258
|
+
}
|
|
2259
|
+
this.updateChatCardBusy = true;
|
|
2260
|
+
try {
|
|
2261
|
+
const view = this.updateOfferView();
|
|
2262
|
+
let current = null;
|
|
2263
|
+
try {
|
|
2264
|
+
current = this.runningAgendVersion();
|
|
2265
|
+
}
|
|
2266
|
+
catch { /* unknown */ }
|
|
2267
|
+
const posted = this.readUpdateChatCard();
|
|
2268
|
+
const state = view?.state ?? "none";
|
|
2269
|
+
// #4485 review 1: an offered card whose buttons are gone (a restart empties the nonce map; they also expire) is not
|
|
2270
|
+
// a usable card: it is marked expired and one with live buttons is posted.
|
|
2271
|
+
const live = !!posted?.nonce && this.pendingNonceButtons.get(posted.nonce)?.prefix === UPDATE_CARD_CALLBACK_PREFIX;
|
|
2272
|
+
if (view && state === "offered" && view.installable && (!posted || posted.version !== view.version || posted.state !== "offered" || !live)) {
|
|
2273
|
+
const place = this.updateChatCardPlace();
|
|
2274
|
+
if (!place)
|
|
2275
|
+
return;
|
|
2276
|
+
if (posted) {
|
|
2277
|
+
const old = posted.state === "offered" && posted.version === view.version && !live ? t("update.chatcard.expired")
|
|
2278
|
+
: posted.version === view.version ? t("update.chatcard.cancelled", posted.version) : t("update.chatcard.replaced", view.version);
|
|
2279
|
+
await this.editUpdateChatCard(posted, old);
|
|
2280
|
+
}
|
|
2281
|
+
const version = view.version;
|
|
2282
|
+
const nonce = await this.postNonceButtonPromptOrThrow({
|
|
2283
|
+
prefix: UPDATE_CARD_CALLBACK_PREFIX, alertType: "tip", instanceName: place.general, adapter: place.adapter, adapterId: place.adapterId,
|
|
2284
|
+
chatId: place.chatId, ...(place.threadId ? { threadId: place.threadId } : {}),
|
|
2285
|
+
message: this.updateChatCardText(view, current),
|
|
2286
|
+
choices: [{ action: "when-idle", label: t("update.chatcard.when_idle") }, { action: "tonight", label: t("update.chatcard.tonight") }, { action: "not-now", label: t("update.chatcard.not_now") }],
|
|
2287
|
+
expiredText: t("update.chatcard.expired"),
|
|
2288
|
+
timeoutMs: UPDATE_CHAT_CARD_MS,
|
|
2289
|
+
// #4485 review 2: the provider's own delivery address, kept per nonce as it is sent — a click may consume the
|
|
2290
|
+
// pending entry before this post returns, so the entry is never the place to read it from.
|
|
2291
|
+
deliver: async (choices) => {
|
|
2292
|
+
// #4485 r2: the buttons' version is bound before anything is sent — a click can come before the platform answers.
|
|
2293
|
+
const nonceOf = (choices[0]?.id ?? "").slice(UPDATE_CARD_CALLBACK_PREFIX.length, UPDATE_CARD_CALLBACK_PREFIX.length + 32);
|
|
2294
|
+
this.updateChatCardVersion.set(nonceOf, version);
|
|
2295
|
+
const shown = this.renderPlaces(place.adapterId, this.updateChatCardText(view, current), place.threadId ? { threadId: place.threadId } : undefined);
|
|
2296
|
+
const sent = await place.adapter.notifyAlert(place.chatId, { type: "tip", instanceName: place.general, message: shown.text, choices }, shown.opts);
|
|
2297
|
+
const id = choices[0]?.id ?? "";
|
|
2298
|
+
this.updateChatCardSent.set(id.slice(UPDATE_CARD_CALLBACK_PREFIX.length, UPDATE_CARD_CALLBACK_PREFIX.length + 32), { version, chatId: sent.chatId, ...(sent.threadId !== undefined ? { threadId: sent.threadId } : {}), messageId: String(sent.messageId ?? "") });
|
|
2299
|
+
return sent;
|
|
2300
|
+
},
|
|
2301
|
+
});
|
|
2302
|
+
const sent = this.updateChatCardSent.get(nonce);
|
|
2303
|
+
const answered = this.updateChatCardAnswered.get(nonce);
|
|
2304
|
+
this.updateChatCardAnswered.delete(nonce);
|
|
2305
|
+
this.writeUpdateChatCard({ version, state: answered ?? "offered", nonce: answered ? null : nonce, messageId: sent?.messageId ?? "",
|
|
2306
|
+
chatId: sent?.chatId ?? place.chatId, ...((sent?.threadId ?? place.threadId) ? { threadId: sent?.threadId ?? place.threadId } : {}),
|
|
2307
|
+
adapterId: place.adapterId, at: Date.now() });
|
|
2308
|
+
// The card may have moved on while this was being posted (a newer version, an answer on the web): sync again.
|
|
2309
|
+
const after = this.updateOfferView();
|
|
2310
|
+
if (!answered && (after?.version !== version || (after?.state ?? "none") !== "offered"))
|
|
2311
|
+
this.updateChatCardAgain = true;
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
if (posted && posted.state !== state) {
|
|
2315
|
+
const text = state === "none" && posted.state !== "done" ? t("update.chatcard.cancelled", posted.version) : this.updateChatCardText(view, current);
|
|
2316
|
+
await this.editUpdateChatCard(posted, text);
|
|
2317
|
+
this.writeUpdateChatCard(state === "none" ? null : { ...posted, state, nonce: null });
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
catch (err) {
|
|
2321
|
+
this.logger.warn({ err: err.message }, "Update chat card not posted");
|
|
2322
|
+
}
|
|
2323
|
+
finally {
|
|
2324
|
+
this.updateChatCardBusy = false;
|
|
2325
|
+
if (this.updateChatCardAgain && !this.shuttingDown) {
|
|
2326
|
+
this.updateChatCardAgain = false;
|
|
2327
|
+
void this.syncUpdateChatCard();
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
/** Edit the posted card: retire its buttons if they are still live (with `text`), else edit its text without buttons. */
|
|
2332
|
+
async editUpdateChatCard(posted, text) {
|
|
2333
|
+
const entry = posted.nonce ? this.pendingNonceButtons.get(posted.nonce) : undefined;
|
|
2334
|
+
if (entry && entry.prefix === UPDATE_CARD_CALLBACK_PREFIX) {
|
|
2335
|
+
this.pendingNonceButtons.delete(posted.nonce);
|
|
2336
|
+
await this.retireNonceButtons(entry, entry.messageId ?? posted.messageId, text);
|
|
2337
|
+
return;
|
|
2338
|
+
}
|
|
2339
|
+
const place = this.updateChatCardPlace();
|
|
2340
|
+
const adapter = this.adapters.get(posted.adapterId) ?? this.worlds.get(posted.adapterId)?.adapter ?? (place && place.adapterId === posted.adapterId ? place.adapter : undefined);
|
|
2341
|
+
if (!adapter || !posted.messageId)
|
|
2342
|
+
return;
|
|
2343
|
+
// Dead buttons (after a restart, or expired) go with the edit where the adapter can drop them.
|
|
2344
|
+
if (adapter.editMessageRemoveButtons)
|
|
2345
|
+
await adapter.editMessageRemoveButtons(posted.chatId, posted.messageId, text, posted.threadId).catch(() => { });
|
|
2346
|
+
else
|
|
2347
|
+
await adapter.editMessage(posted.chatId, posted.messageId, text, posted.threadId).catch(() => { });
|
|
2348
|
+
}
|
|
2349
|
+
/**
|
|
2350
|
+
* M-3770 1.5: a press on the chat card — a fleet admin's only (anyone else is told privately, the buttons stay: the
|
|
2351
|
+
* same gate as the Hub's Update now). The answer is the web's (the one card); the message is edited to its new state.
|
|
2352
|
+
*/
|
|
2353
|
+
async handleUpdateCardCallback(data, adapterId, adapter) {
|
|
2354
|
+
const claimed = this.consumeNonceCallback(UPDATE_CARD_CALLBACK_PREFIX, /^update-card:([0-9a-f]{32}):(when-idle|tonight|not-now)$/, data, adapterId, adapter, undefined, userId => this.fleetAdminGate(userId, adapterId) === "ok");
|
|
2355
|
+
if (claimed === null)
|
|
2356
|
+
return false;
|
|
2357
|
+
if (claimed === "consumed")
|
|
2358
|
+
return true;
|
|
2359
|
+
const { entry, action } = claimed;
|
|
2360
|
+
const nonce = data.callbackData.slice(UPDATE_CARD_CALLBACK_PREFIX.length, UPDATE_CARD_CALLBACK_PREFIX.length + 32);
|
|
2361
|
+
const sent = this.updateChatCardSent.get(nonce);
|
|
2362
|
+
const messageId = entry.messageId ?? sent?.messageId ?? data.messageId;
|
|
2363
|
+
// #4485 review 2: a press answers the offer its message showed — never a newer one that came since. The version is
|
|
2364
|
+
// bound when the card's delivery starts; a press with no binding at all answers nothing (fail closed).
|
|
2365
|
+
const before = this.updateOfferView();
|
|
2366
|
+
const shownVersion = this.updateChatCardVersion.get(nonce);
|
|
2367
|
+
if (!shownVersion || !before || before.version !== shownVersion) {
|
|
2368
|
+
await this.retireNonceButtons(entry, messageId, shownVersion && before && before.version !== shownVersion ? t("update.chatcard.replaced", before.version) : t("update.chatcard.expired"));
|
|
2369
|
+
return true;
|
|
2370
|
+
}
|
|
2371
|
+
const tonight = (() => { const d = new Date(); d.setHours(22, 0, 0, 0); if (d.getTime() - Date.now() < 30 * 60_000)
|
|
2372
|
+
d.setDate(d.getDate() + 1); return d.getTime(); })();
|
|
2373
|
+
const body = action === "tonight" ? { action: "pick-time", at: tonight } : { action: action };
|
|
2374
|
+
const by = updateAnswerLabel(data.username ?? "");
|
|
2375
|
+
let text;
|
|
2376
|
+
try {
|
|
2377
|
+
const r = await this.ensureUpdateCard().answer(`chat-${nonce}`, by, body);
|
|
2378
|
+
const view = this.updateOfferView();
|
|
2379
|
+
let current = null;
|
|
2380
|
+
try {
|
|
2381
|
+
current = this.runningAgendVersion();
|
|
2382
|
+
}
|
|
2383
|
+
catch { /* unknown */ }
|
|
2384
|
+
const why = r.ok ? "" : ("key" in r.body && r.body.key !== "preflight" ? r.body.key : "error" in r.body ? r.body.error : r.body.key);
|
|
2385
|
+
text = r.ok ? t("update.chatcard.by", this.updateChatCardText(view, current), by) : t("update.chatcard.refused", why || String(r.status));
|
|
2386
|
+
const posted = this.readUpdateChatCard();
|
|
2387
|
+
const nextState = view?.state ?? "none";
|
|
2388
|
+
if (posted && posted.nonce === nonce) {
|
|
2389
|
+
// The press carries the message's own id where the post's record has none yet.
|
|
2390
|
+
this.writeUpdateChatCard({ ...posted, state: nextState, nonce: null, messageId: posted.messageId || sent?.messageId || String(messageId ?? "") });
|
|
2391
|
+
}
|
|
2392
|
+
else if (r.ok) {
|
|
2393
|
+
// The card is still being posted (its record is written when the post returns): it records this answer then.
|
|
2394
|
+
this.updateChatCardAnswered.set(nonce, nextState);
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
catch (err) {
|
|
2398
|
+
text = t("update.chatcard.refused", err.message);
|
|
2399
|
+
}
|
|
2400
|
+
await this.retireNonceButtons(entry, messageId, text);
|
|
2401
|
+
return true;
|
|
2402
|
+
}
|
|
1985
2403
|
hubUpdates = null;
|
|
1986
2404
|
hubUpdateOwned = null;
|
|
1987
2405
|
hubUpdateBootProgress = null;
|
|
2406
|
+
/** This process's local idle launch. Its own claim must not look like some other update holding the machine. */
|
|
2407
|
+
localIdleOwned = null;
|
|
2408
|
+
localIdleBootProgress = null;
|
|
1988
2409
|
pendingHubFleetUpdates = new Map();
|
|
1989
2410
|
hubFleetUpdates() { return this.hubUpdates; }
|
|
1990
|
-
|
|
2411
|
+
/** `ownClaim` is this caller's launch, so that launch does not look busy to itself. The Hub queue passes its claim; the local card passes its own. */
|
|
2412
|
+
hubUpdateIdle(ownClaim = this.hubUpdateOwned?.claim ?? null) {
|
|
2413
|
+
const updates = resolveUpdates(this.fleetConfig?.updates);
|
|
2414
|
+
// Pause and pin hold the row. Update now forces idle on the Hub queue itself; allowed() must not cancel it.
|
|
2415
|
+
if (updates.pin || inUpdatePause(updates.pause, new Date()))
|
|
2416
|
+
return false;
|
|
1991
2417
|
if (!this.startupComplete || this.shuttingDown || this.reconcileInFlight || this.topicCleanupInFlight
|
|
1992
|
-
|| this.deliveryPumpRunning || (this.webUpdateOwned && this.webUpdateOwned !==
|
|
2418
|
+
|| this.deliveryPumpRunning || (this.webUpdateOwned && this.webUpdateOwned !== ownClaim))
|
|
1993
2419
|
return false;
|
|
1994
2420
|
for (const name of Object.keys(this.fleetConfig?.instances ?? {})) {
|
|
1995
2421
|
if (this.restartsInFlight.has(name) || this.stopsInFlight.has(name) || this.handOffsInFlight.has(name)
|
|
@@ -2025,22 +2451,48 @@ export class FleetManager {
|
|
|
2025
2451
|
return false;
|
|
2026
2452
|
}
|
|
2027
2453
|
}
|
|
2028
|
-
async launchHubUpdate(row, control) {
|
|
2029
|
-
|
|
2454
|
+
async launchHubUpdate(row, control, pressed = false) {
|
|
2455
|
+
return this.launchClaimedUpdate({
|
|
2456
|
+
id: row.id, version: row.version, origin: `Hub-requested update ${row.id}`, messageId: `hub-fleet-update:${row.id}`, control, hub: true,
|
|
2457
|
+
// M-3770 (#4480 §4.1): the owner's own Update now is a press; the idle wait starting the request is unattended.
|
|
2458
|
+
kind: pressed ? "press" : "unattended",
|
|
2459
|
+
onExit: () => {
|
|
2460
|
+
const outcome = this.hubUpdateOutcome(row);
|
|
2461
|
+
if (outcome)
|
|
2462
|
+
this.hubUpdates?.complete(row.id, outcome.state, outcome.currentVersion, "interrupted");
|
|
2463
|
+
},
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
/**
|
|
2467
|
+
* One idle installer, Hub or local. Claims the machine and writes a marker before any await, then settles the row
|
|
2468
|
+
* when the child is gone and the marker is no longer in progress.
|
|
2469
|
+
*/
|
|
2470
|
+
async launchClaimedUpdate(input) {
|
|
2471
|
+
if (this.shuttingDown || this.webUpdateOwned || isUpdateInProgress(this.dataDir) || !input.control.current())
|
|
2030
2472
|
return false;
|
|
2031
|
-
const claim = { startedAt: Date.now() }
|
|
2032
|
-
|
|
2473
|
+
const claim = { startedAt: Date.now() };
|
|
2474
|
+
const hubOwned = input.hub ? { id: input.id, claim } : null;
|
|
2475
|
+
if (hubOwned)
|
|
2476
|
+
this.hubUpdateOwned = hubOwned;
|
|
2477
|
+
else
|
|
2478
|
+
this.localIdleOwned = claim;
|
|
2033
2479
|
this.webUpdateOwned = claim;
|
|
2034
|
-
const
|
|
2035
|
-
|
|
2036
|
-
this.
|
|
2037
|
-
|
|
2038
|
-
|
|
2480
|
+
const owns = () => input.hub ? this.hubUpdateOwned === hubOwned : this.localIdleOwned === claim;
|
|
2481
|
+
const release = () => {
|
|
2482
|
+
if (hubOwned && this.hubUpdateOwned === hubOwned)
|
|
2483
|
+
this.hubUpdateOwned = null;
|
|
2484
|
+
if (!input.hub && this.localIdleOwned === claim)
|
|
2485
|
+
this.localIdleOwned = null;
|
|
2486
|
+
if (this.webUpdateOwned === claim)
|
|
2487
|
+
this.webUpdateOwned = null;
|
|
2488
|
+
};
|
|
2489
|
+
if (!persistUpdateProgress(this.dataDir, { ...webUpdateTarget(claim.startedAt), messageId: input.messageId }, claim.startedAt)
|
|
2490
|
+
|| !setUpdateProgressStage(this.dataDir, "preparing", { version: input.version })) {
|
|
2039
2491
|
release();
|
|
2040
2492
|
return false;
|
|
2041
2493
|
}
|
|
2042
2494
|
try {
|
|
2043
|
-
const child = await this.launchInstalledUpdate(
|
|
2495
|
+
const child = await this.launchInstalledUpdate(input.origin, () => !this.shuttingDown && owns() && input.control.current() && input.control.claim(), input.version, input.kind);
|
|
2044
2496
|
if (!child) {
|
|
2045
2497
|
release();
|
|
2046
2498
|
return false;
|
|
@@ -2051,19 +2503,17 @@ export class FleetManager {
|
|
|
2051
2503
|
return;
|
|
2052
2504
|
endedOnce = true;
|
|
2053
2505
|
const settle = () => {
|
|
2054
|
-
if (this.shuttingDown ||
|
|
2506
|
+
if (this.shuttingDown || !owns())
|
|
2055
2507
|
return;
|
|
2056
2508
|
// systemd-run may exit before its independent updater. Keep the claim while its bounded marker is active.
|
|
2057
2509
|
const marker = readUpdateProgress(this.dataDir)?.progress;
|
|
2058
|
-
if (marker?.target.messageId ===
|
|
2510
|
+
if (marker?.target.messageId === input.messageId && isUpdateInProgress(this.dataDir)) {
|
|
2059
2511
|
const timer = setTimeout(settle, 5000);
|
|
2060
2512
|
timer.unref();
|
|
2061
2513
|
return;
|
|
2062
2514
|
}
|
|
2063
2515
|
release();
|
|
2064
|
-
|
|
2065
|
-
if (outcome)
|
|
2066
|
-
this.hubUpdates?.complete(row.id, outcome.state, outcome.currentVersion, "interrupted");
|
|
2516
|
+
input.onExit();
|
|
2067
2517
|
};
|
|
2068
2518
|
settle();
|
|
2069
2519
|
};
|
|
@@ -2076,6 +2526,22 @@ export class FleetManager {
|
|
|
2076
2526
|
return false;
|
|
2077
2527
|
}
|
|
2078
2528
|
}
|
|
2529
|
+
claimedIdleOutcome(id, version) {
|
|
2530
|
+
let current = null;
|
|
2531
|
+
try {
|
|
2532
|
+
current = this.runningAgendVersion();
|
|
2533
|
+
}
|
|
2534
|
+
catch {
|
|
2535
|
+
current = null;
|
|
2536
|
+
}
|
|
2537
|
+
const messageId = idleUpdateMessageId(id);
|
|
2538
|
+
const matches = (marker) => !!marker
|
|
2539
|
+
&& marker.progress.target.messageId === messageId
|
|
2540
|
+
&& (marker.progress.version === undefined || marker.progress.version === version);
|
|
2541
|
+
const saved = readUpdateProgress(this.dataDir);
|
|
2542
|
+
const marker = matches(saved) ? saved : matches(this.localIdleBootProgress) ? this.localIdleBootProgress : null;
|
|
2543
|
+
return { state: idleClaimOutcome(version, current, marker) };
|
|
2544
|
+
}
|
|
2079
2545
|
hubUpdateOutcome(row) {
|
|
2080
2546
|
if (!this.startupComplete || this.hubUpdateOwned?.id === row.id)
|
|
2081
2547
|
return null;
|
|
@@ -2803,6 +3269,7 @@ export class FleetManager {
|
|
|
2803
3269
|
&& (interaction.kind === "permission" || interaction.kind === "dangerous_command") };
|
|
2804
3270
|
},
|
|
2805
3271
|
deliver: input => this.deliverHubQuestion(input),
|
|
3272
|
+
updateHeld: () => this.quiescence?.armed() === true,
|
|
2806
3273
|
agentToken: agent => this.hubAgentToken(agent),
|
|
2807
3274
|
// attachments-v1: a question's files go into the agent's inbox; an answer's come from its own paths.
|
|
2808
3275
|
files: { stateDir: this.dataDir,
|
|
@@ -2837,8 +3304,9 @@ export class FleetManager {
|
|
|
2837
3304
|
}, caller.agent, receiptId),
|
|
2838
3305
|
attachExposures: api => this.attachHubMemberExposures(api),
|
|
2839
3306
|
attachAttention: (read, retry, close) => this.attachHubExecutionAttention(read, retry, close),
|
|
2840
|
-
updates: { idle: () => this.hubUpdateIdle(), busy: () => !!this.webUpdateOwned || isUpdateInProgress(this.dataDir),
|
|
2841
|
-
canInstall: () => this.hubUpdateCanInstall(), launch: (row, control) => this.launchHubUpdate(row, control),
|
|
3307
|
+
updates: { idle: () => this.hubUpdateIdle(), busy: () => !!this.webUpdateOwned || isUpdateInProgress(this.dataDir) || !!this.updateCard?.blocksAdmission(),
|
|
3308
|
+
canInstall: () => this.hubUpdateCanInstall(), launch: (row, control, pressed) => this.launchHubUpdate(row, control, pressed),
|
|
3309
|
+
onQueue: row => { this.ensureUpdateCard().observeHub(row); },
|
|
2842
3310
|
active: id => this.hubUpdateOwned?.id === id, outcome: row => this.hubUpdateOutcome(row), notify: n => this.recordHubUpdateNotice(n) },
|
|
2843
3311
|
attachUpdates: updates => { this.hubUpdates = updates; },
|
|
2844
3312
|
attachRecommendations: read => { this.hubRecommendationRead = read; },
|
|
@@ -3977,8 +4445,13 @@ export class FleetManager {
|
|
|
3977
4445
|
updateCheckTimer = null;
|
|
3978
4446
|
/** M-2738: the last update check's answer, for the web (null until the first check settles). */
|
|
3979
4447
|
updateCheckState = null;
|
|
4448
|
+
/** S-234: the one durable update offer. Opened on the first check or answer. */
|
|
4449
|
+
updateCard;
|
|
3980
4450
|
/** M-2738: a web "check now" in flight, and when the last one ran (one a minute at most). */
|
|
3981
4451
|
updateCheckNow = { running: null, lastAt: 0 };
|
|
4452
|
+
/** M-3770 (#4480 §4): the last pre-flight — a diagnostic for the page; every launch proves its local checks again. */
|
|
4453
|
+
updatePreflight = null;
|
|
4454
|
+
updatePreflightRunning = null;
|
|
3982
4455
|
/** M-2738: a web start's Idempotency-Key → its answer (a retried request never starts a second update). */
|
|
3983
4456
|
webUpdateStarts = new Map();
|
|
3984
4457
|
/**
|
|
@@ -4110,7 +4583,7 @@ export class FleetManager {
|
|
|
4110
4583
|
}
|
|
4111
4584
|
/** #1770: an instance's web-files byte cap (a field, so a test can make it small). */
|
|
4112
4585
|
webReplyMaxBytes = REPLY_FILES_MAX_BYTES;
|
|
4113
|
-
/** #1682: the people seen on inbound messages (id → name), for the web chat's mention pills; bounded
|
|
4586
|
+
/** #1682: the people seen on inbound messages (id → name), for the web chat's mention pills; bounded; on disk since M-3827. */
|
|
4114
4587
|
seenUsers = new SeenUsers();
|
|
4115
4588
|
webPrefsStore;
|
|
4116
4589
|
/** #1665: the web preferences kept on the host (<home>/web-prefs.json), read on first use. */
|
|
@@ -6341,6 +6814,8 @@ export class FleetManager {
|
|
|
6341
6814
|
delivered: ticket => !!ticket.deliveryId && this.deliveryOutbox.get(ticket.deliveryId)?.state === "delivered",
|
|
6342
6815
|
deliveryState: ticket => ticket.deliveryId ? this.deliveryOutbox.get(ticket.deliveryId)?.state : undefined,
|
|
6343
6816
|
admit: (request, ticketId) => {
|
|
6817
|
+
if (this.daemons.get(request.target)?.requestContextCallsRequired?.() || this.fleetWindowsRuntime?.requestContextCallsRequired?.(request.target))
|
|
6818
|
+
throw Object.assign(Error(t("contact.legacyUpgrade")), { code: "request-context-legacy-decision-upgrade-required" });
|
|
6344
6819
|
const payload = { ...request.payload, contactTicket: { id: ticketId, state: "delivered" } };
|
|
6345
6820
|
const admitted = this.deliveryOutbox.admit({ operationId: request.operationId,
|
|
6346
6821
|
sourceKey: `contact:${ticketId}`, sourceInstance: request.source,
|
|
@@ -6420,6 +6895,111 @@ export class FleetManager {
|
|
|
6420
6895
|
...(service.needsApplication(name) ? { originRestriction: { active: true,
|
|
6421
6896
|
reason: !service.origin(name) || service.origin(name)?.kind === "unknown" ? "unknown-origin" : "earlier-non-admin", resetSupported: false } } : {}) };
|
|
6422
6897
|
}
|
|
6898
|
+
/** Identity-only read. This does not install/enable the same-card host. */
|
|
6899
|
+
requestContextPolicy;
|
|
6900
|
+
requestContextRelay;
|
|
6901
|
+
/** L installs this explicitly; H defines no production switch. */
|
|
6902
|
+
makeRequestContextPolicy() {
|
|
6903
|
+
return { assert: input => {
|
|
6904
|
+
try {
|
|
6905
|
+
return assertRequestContextOperation(input);
|
|
6906
|
+
}
|
|
6907
|
+
catch (error) {
|
|
6908
|
+
if (error instanceof RequestContextPolicyError) {
|
|
6909
|
+
const call = input.admission, view = call?.coverage === "covered" && call.lease.snapshot.owner.instance === input.instance ? requestContextDisplayView(call.lease.snapshot.context) : null;
|
|
6910
|
+
this.emitSseEvent("message", { instance: input.instance, sender: "AgEnD", role: "status", wrap: true, text: error.message, ts: new Date().toISOString(), ...(view ? { requestProvenance: { ...view, refused: true } } : {}) });
|
|
6911
|
+
}
|
|
6912
|
+
throw error;
|
|
6913
|
+
}
|
|
6914
|
+
} };
|
|
6915
|
+
}
|
|
6916
|
+
requestContactPrincipal(req, url) {
|
|
6917
|
+
const resolve = () => {
|
|
6918
|
+
const verdict = evaluateWebRequest(req, url, this.webToken, this.webSessions, { touch: false });
|
|
6919
|
+
if (verdict.kind === "reject" && (verdict.reason === "csrf" || verdict.reason === "cross-site"))
|
|
6920
|
+
throw Error(verdict.reason);
|
|
6921
|
+
if (verdict.kind !== "allow" || verdict.via !== "session" || verdict.session.tier !== "admin")
|
|
6922
|
+
return null;
|
|
6923
|
+
const identity = this.webSessionIdentity(verdict.session);
|
|
6924
|
+
if (!identity)
|
|
6925
|
+
return null;
|
|
6926
|
+
const authority = this.webAuthority({ session: verdict.session, gateway: !!gatewayRequestContext(req), peer: gatewayRequestContext(req) ? gatewayRequestContext(req).named ? "named_link" : "quick_link" : classifyWebPeer(req) }).authority;
|
|
6927
|
+
const action = this.contactActor(req, url), person = { platform: identity.platform, adapterId: identity.adapter_id, userId: identity.user_id, label: identity.user_id };
|
|
6928
|
+
const verified = !!action && sameContactPerson(action, person);
|
|
6929
|
+
const binding = JSON.stringify([identity.session_handle, authority.authority_epoch, authority.kind === "web-verified" ? authority.session?.authorized_at : null]);
|
|
6930
|
+
return { person, binding, verified };
|
|
6931
|
+
};
|
|
6932
|
+
const first = resolve();
|
|
6933
|
+
if (!first)
|
|
6934
|
+
return null;
|
|
6935
|
+
return { ...first, current: () => { try {
|
|
6936
|
+
const now = resolve();
|
|
6937
|
+
return !!now && now.binding === first.binding && sameContactPerson(now.person, first.person) && now.verified === first.verified;
|
|
6938
|
+
}
|
|
6939
|
+
catch {
|
|
6940
|
+
return false;
|
|
6941
|
+
} } };
|
|
6942
|
+
}
|
|
6943
|
+
/**
|
|
6944
|
+
* S-229: the same-card service the native cards use. Null — today's M-3680 card and General proposals, unchanged —
|
|
6945
|
+
* until L installs it at the cutover; synthetic rigs install it directly. Installing it grants no actor: every
|
|
6946
|
+
* decision still comes from a platform callback's person through cards.decide.
|
|
6947
|
+
*/
|
|
6948
|
+
requestContactCardsPort = null;
|
|
6949
|
+
installRequestContactCards(cards) { this.requestContactCardsPort = cards; }
|
|
6950
|
+
/** Dormant assembly for L and synthetic rigs; merely defining this method installs no service or route authority. */
|
|
6951
|
+
makeRequestContactCards() {
|
|
6952
|
+
this.ensureDeliveryOutbox();
|
|
6953
|
+
const outbox = this.deliveryOutbox, legacy = this.contactService();
|
|
6954
|
+
const names = () => [...new Set([...Object.keys(this.fleetConfig?.instances ?? {}), ...(this.classicChannels?.getAll() ?? []).map(room => room.instanceName)])].sort();
|
|
6955
|
+
const manage = (name, person) => this.contactAdminOf(name, person);
|
|
6956
|
+
const cards = outbox.requestContactCards({
|
|
6957
|
+
current: (_context, binding) => this.contactGeneration(binding.source.instance) === binding.source.incarnation && this.contactGeneration(binding.target.instance) === binding.target.incarnation && !this.hubContactRestricted(binding.source.instance),
|
|
6958
|
+
generation: name => { try {
|
|
6959
|
+
return this.contactGeneration(name);
|
|
6960
|
+
}
|
|
6961
|
+
catch {
|
|
6962
|
+
return null;
|
|
6963
|
+
} },
|
|
6964
|
+
canManage: manage, canDecide: (name, person) => { if (!manage(name, person))
|
|
6965
|
+
return false; const policy = legacy.host.store.policySnapshot(name, this.contactGeneration(name)); return person.platform === "host" && person.userId === "operator" || (policy.approvers ?? legacy.host.defaultApprovers(name)).some(row => sameContactPerson(row, person)); },
|
|
6966
|
+
adminOf: (name, person) => this.contactAdminOf(name, person),
|
|
6967
|
+
person: actor => {
|
|
6968
|
+
if (actor.kind !== "person" || actor.platform === "hub")
|
|
6969
|
+
return null;
|
|
6970
|
+
if (actor.platform === "host")
|
|
6971
|
+
return { platform: "host", adapterId: "host", userId: "operator", label: "Operator" };
|
|
6972
|
+
const channel = (this.fleetConfig?.channels ?? (this.fleetConfig?.channel ? [this.fleetConfig.channel] : [])).find(row => row.type === actor.platform);
|
|
6973
|
+
const adapter = [...this.adapters.values(), ...[...this.worlds.values()].map(world => world.adapter)].find(row => row.type === actor.platform);
|
|
6974
|
+
const adapterId = adapter?.id ?? channel?.id ?? channel?.type;
|
|
6975
|
+
if (!adapterId)
|
|
6976
|
+
return null;
|
|
6977
|
+
return { platform: actor.platform, adapterId, userId: actor.userId, label: actor.displayName ?? actor.userId };
|
|
6978
|
+
},
|
|
6979
|
+
managedTargets: person => names().filter(name => manage(name, person)),
|
|
6980
|
+
roleRevision: () => settingsFingerprint([settingsRevision(this.configPath), this.settingsRuntimeRevision, this.fleetConfig, names().map(name => [name, this.contactGeneration(name), legacy.host.defaultApprovers(name), legacy.host.store.policySnapshot(name).revision])]),
|
|
6981
|
+
label: name => this.fleetConfig?.instances[name]?.display_name ?? this.classicChannels?.getAll().find(room => room.instanceName === name)?.displayName ?? name,
|
|
6982
|
+
deliveryState: ticket => ticket.deliveryId ? outbox.get(ticket.deliveryId)?.state : undefined,
|
|
6983
|
+
legacyCurrent: request => !this.hubContactRestricted(request.source) && this.contactGeneration(request.source) === request.sourceGeneration && this.contactGeneration(request.target) === request.targetGeneration,
|
|
6984
|
+
admitLegacy: (request, id) => legacy.host.admit(request, id), changed: ticket => {
|
|
6985
|
+
this.sweepContactAuthorizationOutcomes();
|
|
6986
|
+
this.emitSseEvent("contact-auth", { instance: ticket.target, ticketId: ticket.id, revision: ticket.revision });
|
|
6987
|
+
// S-229: a decision anywhere (the web, a card) closes every native card of that request.
|
|
6988
|
+
try {
|
|
6989
|
+
this.syncHeldTicketCard(ticket);
|
|
6990
|
+
}
|
|
6991
|
+
catch (err) {
|
|
6992
|
+
this.logger?.warn?.({ err: err?.message, ticket: ticket.id }, "Held contact request card failed");
|
|
6993
|
+
}
|
|
6994
|
+
this.needsYou?.poke();
|
|
6995
|
+
},
|
|
6996
|
+
});
|
|
6997
|
+
return cards;
|
|
6998
|
+
}
|
|
6999
|
+
makeRequestContactApi() {
|
|
7000
|
+
const cards = this.makeRequestContactCards();
|
|
7001
|
+
return { principal: (req, url) => this.requestContactPrincipal(req, url), needs: actor => cards.needs(actor), permitContinuation: (req, res) => permitWebContinuation(req, res, { webToken: this.webToken, webSessions: this.webSessions }), canRead: (card, actor) => cards.canRead(card, actor), read: (id, actor) => cards.read(id, actor), list: (filter, actor) => cards.list(filter, actor), decide: (id, input, actor) => cards.decide(id, input, actor) };
|
|
7002
|
+
}
|
|
6423
7003
|
contactActor(req, url) {
|
|
6424
7004
|
const verdict = evaluateWebRequest(req, url, this.webToken, this.webSessions, { touch: false });
|
|
6425
7005
|
if (verdict.kind !== "allow" || verdict.via !== "session" || verdict.session.tier !== "admin")
|
|
@@ -6525,9 +7105,13 @@ export class FleetManager {
|
|
|
6525
7105
|
throw Error("general-only");
|
|
6526
7106
|
if (this.hubContactRestricted(requester))
|
|
6527
7107
|
throw Error("hub-contact-restricted");
|
|
6528
|
-
|
|
7108
|
+
// S-229: a same-card proposal (contact-ticket: with a General) counts against the same limits.
|
|
7109
|
+
const pending = [...this.pendingNonceButtons.values()].filter(e => e.prefix === "contact-change:" || e.prefix === CONTACT_TICKET_PREFIX && !!e.generalName);
|
|
6529
7110
|
if (pending.length >= 64 || pending.filter(e => e.generalName === requester).length >= 8)
|
|
6530
7111
|
throw Error("contact-proposal-limit");
|
|
7112
|
+
const port = this.requestContactCardsPort;
|
|
7113
|
+
if (port && raw?.kind === "ticket-decision")
|
|
7114
|
+
return this.proposeSameContactCard(port, requester, raw, callerCurrent);
|
|
6531
7115
|
const service = this.contactService();
|
|
6532
7116
|
const plan = prepareContactChange(raw, { service, label: n => this.fleetConfig?.instances[n]?.display_name || this.contactRoom(n)?.displayName || n, timeZone: () => this.usageZone(), mode: n => { const room = this.contactRoom(n); return room ? room.restrictedMode ? "restricted" : "legacy" : undefined; },
|
|
6533
7117
|
generation: n => this.contactGeneration(n), modeAdmin: (n, p) => this.contactAdminOf(n, p),
|
|
@@ -6628,7 +7212,7 @@ export class FleetManager {
|
|
|
6628
7212
|
clearTimeout(entry.timer);
|
|
6629
7213
|
// #4438 review: a card still being posted has no message yet; postHeldTicketCard retires it once it has one.
|
|
6630
7214
|
if (entry.messageId)
|
|
6631
|
-
void this.
|
|
7215
|
+
void this.removeDecidedContactCard(entry, entry.messageId, heldCardOutcome(ticket.state, !!ticket.requestContext));
|
|
6632
7216
|
}
|
|
6633
7217
|
return;
|
|
6634
7218
|
}
|
|
@@ -6645,24 +7229,138 @@ export class FleetManager {
|
|
|
6645
7229
|
}
|
|
6646
7230
|
void this.postHeldTicketCard(ticket).catch((err) => this.logger?.warn?.({ err: err?.message, ticket: ticket.id }, "Could not post a held contact request to General"));
|
|
6647
7231
|
}
|
|
6648
|
-
|
|
6649
|
-
|
|
7232
|
+
/** The one General on the target's Discord/Telegram connection that may carry its contact cards. */
|
|
7233
|
+
contactCardRoute(target) {
|
|
7234
|
+
const adapter = this.contactAdapter(target);
|
|
6650
7235
|
if (!adapter || (adapter.type !== "discord" && adapter.type !== "telegram"))
|
|
6651
|
-
return;
|
|
7236
|
+
return "use-web";
|
|
6652
7237
|
const routes = Object.keys(this.fleetConfig?.instances ?? {}).flatMap(n => {
|
|
6653
7238
|
const route = this.settingsGeneralRoute(n, adapter.type, new Set());
|
|
6654
7239
|
return route && route.adapterId === adapter.id && route.adapter === adapter ? [{ name: n, ...route }] : [];
|
|
6655
7240
|
});
|
|
6656
7241
|
if (routes.length !== 1) {
|
|
6657
|
-
this.logger.info({
|
|
6658
|
-
return;
|
|
7242
|
+
this.logger.info({ target, routes: routes.length }, "No single General for a held contact request's card");
|
|
7243
|
+
return "route-unavailable";
|
|
7244
|
+
}
|
|
7245
|
+
return { adapter, route: routes[0] };
|
|
7246
|
+
}
|
|
7247
|
+
/**
|
|
7248
|
+
* S-229: post slice I's same card. prepareForNativePost checks this exact General route as the posting owner before
|
|
7249
|
+
* and after reading (authority none, canDecide false); the entry keeps the card's CAS snapshot, so a click decides
|
|
7250
|
+
* exactly the image people saw, through cards.decide.
|
|
7251
|
+
*/
|
|
7252
|
+
postSameContactCard(port, id, found, opts = {}) {
|
|
7253
|
+
const { adapter, route } = found;
|
|
7254
|
+
const owner = (ticket) => ticket.id === id && route.current() && this.contactAdapter(ticket.target) === adapter
|
|
7255
|
+
&& this.adapters.get(adapter.id) === adapter && (!opts.proposalCurrent || opts.proposalCurrent());
|
|
7256
|
+
const card = port.prepareForNativePost(id, owner);
|
|
7257
|
+
if (card.ticket.state !== "pending" || card.continuedFrom)
|
|
7258
|
+
throw Error("contact-proposal-ticket-unavailable");
|
|
7259
|
+
const view = nativeContactCardText(card, opts.proposal ? { proposal: opts.proposal } : {});
|
|
7260
|
+
const left = Date.parse(card.ticket.expiresAt) - Date.now();
|
|
7261
|
+
return this.postNonceButtonPromptOrThrow({ prefix: CONTACT_TICKET_PREFIX, alertType: "clear_confirm", instanceName: route.name,
|
|
7262
|
+
adapter: route.adapter, adapterId: route.adapterId, chatId: route.chatId, threadId: route.topic,
|
|
7263
|
+
message: view.message, choices: view.choices,
|
|
7264
|
+
expiredText: t(opts.proposal ? "contactProposal.expired" : "contactHeld.expired"),
|
|
7265
|
+
timeoutMs: opts.proposal ? 5 * 60_000 : Math.max(60_000, Math.min(left, 24 * 3_600_000)),
|
|
7266
|
+
extra: { contactTicketId: id, contactSnapshot: card.snapshot, contactActions: view.choices.map(c => c.action), ...(opts.generalName ? { generalName: opts.generalName } : {}),
|
|
7267
|
+
...(opts.proposalCurrent ? { contactProposalCurrent: opts.proposalCurrent } : {}) } });
|
|
7268
|
+
}
|
|
7269
|
+
/**
|
|
7270
|
+
* S-229: General proposes a decision on the same card — its one suggested choice plus Not now. General never decides:
|
|
7271
|
+
* the platform callback's person does, through cards.decide. Always allow needs people, expiry and a confirmation, so
|
|
7272
|
+
* a grant proposal is sent to the web.
|
|
7273
|
+
*/
|
|
7274
|
+
async proposeSameContactCard(port, requester, raw, callerCurrent) {
|
|
7275
|
+
const input = ContactChangeSchema.parse(raw);
|
|
7276
|
+
if (input.kind !== "ticket-decision")
|
|
7277
|
+
throw Error("contact-proposal-use-web");
|
|
7278
|
+
if (input.grant)
|
|
7279
|
+
throw Error("contact-proposal-use-web");
|
|
7280
|
+
const ticket = resolvePendingTicket(this.contactService().host.store, input.ticket_id);
|
|
7281
|
+
if (input.revision !== undefined && input.revision !== ticket.revision)
|
|
7282
|
+
throw Error("conflict");
|
|
7283
|
+
const found = this.contactCardRoute(ticket.target);
|
|
7284
|
+
if (found === "use-web")
|
|
7285
|
+
throw Error("contact-proposal-use-web");
|
|
7286
|
+
if (found === "route-unavailable")
|
|
7287
|
+
throw Error("contact-proposal-route-unavailable");
|
|
7288
|
+
const requesterPin = this.lifecyclePin(requester), deadline = performance.now() + 5 * 60_000;
|
|
7289
|
+
let retired = false;
|
|
7290
|
+
const current = () => !retired && !this.shuttingDown && performance.now() < deadline && callerCurrent() && requesterPin()
|
|
7291
|
+
&& this.fleetConfig?.instances[requester]?.general_topic === true && !this.hubContactRestricted(requester)
|
|
7292
|
+
&& found.route.current() && this.contactAdapter(ticket.target) === found.adapter && this.adapters.get(found.adapter.id) === found.adapter;
|
|
7293
|
+
if (!current())
|
|
7294
|
+
throw Error("conflict");
|
|
7295
|
+
const armedBefore = new Set(this.pendingNonceButtons.values());
|
|
7296
|
+
const posted = this.postSameContactCard(port, ticket.id, found, { proposal: input.decision, generalName: requester, proposalCurrent: current });
|
|
7297
|
+
// The entry is armed synchronously; keep it, because a decision while the post is in flight removes it from the map
|
|
7298
|
+
// before it has a message (Prism #4501 P2) — the posted message must still close with the committed outcome.
|
|
7299
|
+
const entry = [...this.pendingNonceButtons.values()].find(e => !armedBefore.has(e) && e.contactTicketId === ticket.id && e.generalName === requester);
|
|
7300
|
+
let closed = false;
|
|
7301
|
+
const retire = (nonce) => {
|
|
7302
|
+
if (!entry || closed)
|
|
7303
|
+
return;
|
|
7304
|
+
const armed = this.pendingNonceButtons.get(nonce) === entry, fresh = this.contactService().host.store.get(ticket.id);
|
|
7305
|
+
if (armed && fresh?.state === "pending" && !retired && current())
|
|
7306
|
+
return;
|
|
7307
|
+
if (armed) {
|
|
7308
|
+
this.pendingNonceButtons.delete(nonce);
|
|
7309
|
+
if (entry.timer)
|
|
7310
|
+
clearTimeout(entry.timer);
|
|
7311
|
+
}
|
|
7312
|
+
if (!entry.messageId)
|
|
7313
|
+
return; // never an edit without a message
|
|
7314
|
+
closed = true;
|
|
7315
|
+
if (fresh && fresh.state !== "pending")
|
|
7316
|
+
void this.removeDecidedContactCard(entry, entry.messageId, heldCardOutcome(fresh.state, !!fresh.requestContext));
|
|
7317
|
+
else
|
|
7318
|
+
void this.retireNonceButtons(entry, entry.messageId, t("contactProposal.expired"));
|
|
7319
|
+
};
|
|
7320
|
+
void posted.then(retire, () => { });
|
|
7321
|
+
try {
|
|
7322
|
+
const nonce = await withinBudget(posted, performance.now() + 5000);
|
|
7323
|
+
if (!current() || this.contactService().host.store.get(ticket.id)?.state !== "pending") {
|
|
7324
|
+
retire(nonce);
|
|
7325
|
+
throw Error("conflict");
|
|
7326
|
+
}
|
|
7327
|
+
return { status: "awaiting_platform_admin_confirmation" };
|
|
6659
7328
|
}
|
|
7329
|
+
catch (error) {
|
|
7330
|
+
retired = true;
|
|
7331
|
+
throw error;
|
|
7332
|
+
}
|
|
7333
|
+
}
|
|
7334
|
+
/**
|
|
7335
|
+
* M-3820 (the user, 11-26: General filled with cards edited to "approved elsewhere"): a contact card whose request was
|
|
7336
|
+
* decided or expired somewhere else — the web, another card, a General proposal — is deleted; the card a person pressed
|
|
7337
|
+
* keeps its outcome, and the decision stays in the agent's Permissions history. One try: a delete the platform refuses
|
|
7338
|
+
* (no permission, a Telegram message over 48 h old, a gateway not ready) falls back to the edit it had before.
|
|
7339
|
+
*/
|
|
7340
|
+
async removeDecidedContactCard(entry, messageId, text) {
|
|
7341
|
+
if (!entry.retire && entry.adapter.deleteMessage) {
|
|
7342
|
+
try {
|
|
7343
|
+
await entry.adapter.deleteMessage(entry.chatId, messageId, entry.threadId);
|
|
7344
|
+
this.webPromptGone(entry, text);
|
|
7345
|
+
return;
|
|
7346
|
+
}
|
|
7347
|
+
catch (err) {
|
|
7348
|
+
this.logger.info({ err: err?.message, instanceName: entry.instanceName }, "Could not delete a contact card decided elsewhere; editing it instead");
|
|
7349
|
+
}
|
|
7350
|
+
}
|
|
7351
|
+
await this.retireNonceButtons(entry, messageId, text);
|
|
7352
|
+
}
|
|
7353
|
+
async postHeldTicketCard(ticket) {
|
|
7354
|
+
const found = this.contactCardRoute(ticket.target);
|
|
7355
|
+
if (typeof found === "string")
|
|
7356
|
+
return;
|
|
7357
|
+
const { route } = found, port = this.requestContactCardsPort;
|
|
6660
7358
|
// A ClassicBot room by its own name (its display name, else its channel's), as Fleet lists it.
|
|
6661
|
-
const
|
|
7359
|
+
const label = (n) => this.fleetConfig?.instances[n]?.display_name || this.contactRoom(n)?.displayName || this.contactRoom(n)?.name || n;
|
|
6662
7360
|
const shortId = /^R[a-f0-9]{8}-/.test(ticket.id) ? ticket.id.slice(0, 9) : ticket.id;
|
|
6663
7361
|
const left = Date.parse(ticket.expiresAt) - Date.now();
|
|
6664
7362
|
const text = ticket.message.length > 300 ? `${ticket.message.slice(0, 299)}…` : ticket.message;
|
|
6665
|
-
const posting = this.postNonceButtonPromptOrThrow({ prefix: CONTACT_TICKET_PREFIX, alertType: "clear_confirm", instanceName: route.name,
|
|
7363
|
+
const posting = port ? this.postSameContactCard(port, ticket.id, found) : this.postNonceButtonPromptOrThrow({ prefix: CONTACT_TICKET_PREFIX, alertType: "clear_confirm", instanceName: route.name,
|
|
6666
7364
|
adapter: route.adapter, adapterId: route.adapterId, chatId: route.chatId, threadId: route.topic,
|
|
6667
7365
|
message: [t("contactHeld.title", label(ticket.source), label(ticket.target)), `> ${text.replace(/\n+/g, " ")}`,
|
|
6668
7366
|
t("contactHeld.meta", shortId, ticket.verb, left < 2 * 3_600_000 ? t("contactHeld.minutes", Math.max(1, Math.round(left / 60_000))) : t("contactHeld.hours", Math.round(left / 3_600_000))),
|
|
@@ -6671,7 +7369,7 @@ export class FleetManager {
|
|
|
6671
7369
|
expiredText: t("contactHeld.expired"), timeoutMs: Math.max(60_000, Math.min(left, 24 * 3_600_000)),
|
|
6672
7370
|
extra: { contactTicketId: ticket.id } });
|
|
6673
7371
|
// The entry is armed before the platform answers (postNonceButtonPromptOrThrow sets it synchronously).
|
|
6674
|
-
const entry = [...this.pendingNonceButtons.values()].find(e => e.prefix === CONTACT_TICKET_PREFIX && e.contactTicketId === ticket.id);
|
|
7372
|
+
const entry = [...this.pendingNonceButtons.values()].find(e => e.prefix === CONTACT_TICKET_PREFIX && e.contactTicketId === ticket.id && !e.generalName);
|
|
6675
7373
|
const nonce = await posting;
|
|
6676
7374
|
// #4438 review: decided elsewhere, or expired, while the card was being posted — it had no message to retire then; it
|
|
6677
7375
|
// has one now. A card still armed for a request still waiting stays.
|
|
@@ -6685,7 +7383,10 @@ export class FleetManager {
|
|
|
6685
7383
|
if (entry.timer)
|
|
6686
7384
|
clearTimeout(entry.timer);
|
|
6687
7385
|
}
|
|
6688
|
-
|
|
7386
|
+
if (!fresh || fresh.state === "pending")
|
|
7387
|
+
await this.retireNonceButtons(entry, entry.messageId, t("contactHeld.expired"));
|
|
7388
|
+
else
|
|
7389
|
+
await this.removeDecidedContactCard(entry, entry.messageId, heldCardOutcome(fresh.state, !!fresh.requestContext));
|
|
6689
7390
|
}
|
|
6690
7391
|
async handleContactTicketCallback(data, adapterId, adapter) {
|
|
6691
7392
|
if (!data.callbackData.startsWith(CONTACT_TICKET_PREFIX))
|
|
@@ -6693,8 +7394,28 @@ export class FleetManager {
|
|
|
6693
7394
|
const person = data.userId && adapter && this.adapters.get(adapterId) === adapter && adapter.id === adapterId
|
|
6694
7395
|
&& (adapter.type === "discord" || adapter.type === "telegram") && data.userId !== adapter.getBotUserId?.()
|
|
6695
7396
|
? { platform: adapter.type, adapterId, userId: data.userId, label: data.username || data.userId } : null;
|
|
6696
|
-
const service = this.contactService();
|
|
6697
|
-
|
|
7397
|
+
const service = this.contactService(), port = this.requestContactCardsPort;
|
|
7398
|
+
// S-229: the clicker on the bot that posted the card; the nonce binds adapter, chat, thread and message.
|
|
7399
|
+
const nonce = /^contact-ticket:([0-9a-f]{32}):/.exec(data.callbackData)?.[1] ?? "";
|
|
7400
|
+
const principal = port ? nativeContactPrincipal({ adapter, adapterId, userId: data.userId, username: data.username, nonce,
|
|
7401
|
+
live: () => !!adapter && this.adapters.get(adapterId) === adapter && !this.shuttingDown }) : null;
|
|
7402
|
+
const sameCard = (entry) => !!port && !!entry.contactSnapshot;
|
|
7403
|
+
const mayDecide = (entry, action) => {
|
|
7404
|
+
if (sameCard(entry)) {
|
|
7405
|
+
// Only a choice this card offered: Not now exists only on a General proposal, and a proposal offers one decision.
|
|
7406
|
+
if (!principal || !entry.contactTicketId || !entry.contactActions?.includes(action))
|
|
7407
|
+
return false;
|
|
7408
|
+
// A reader who may decide it acts; a manager who reads a request already closed hears its outcome.
|
|
7409
|
+
try {
|
|
7410
|
+
const card = port.read(entry.contactTicketId, principal);
|
|
7411
|
+
return card.actions.canDecide || card.ticket.state !== "pending" && this.contactAdminOf(card.ticket.target, principal.person);
|
|
7412
|
+
}
|
|
7413
|
+
catch {
|
|
7414
|
+
return false;
|
|
7415
|
+
}
|
|
7416
|
+
}
|
|
7417
|
+
if (action === "cancel")
|
|
7418
|
+
return false;
|
|
6698
7419
|
const ticket = person && entry.contactTicketId ? service.host.store.get(entry.contactTicketId) : undefined;
|
|
6699
7420
|
try {
|
|
6700
7421
|
return !!ticket && !!person && service.view(ticket, person).canDecide;
|
|
@@ -6703,12 +7424,17 @@ export class FleetManager {
|
|
|
6703
7424
|
return false;
|
|
6704
7425
|
}
|
|
6705
7426
|
};
|
|
6706
|
-
const
|
|
7427
|
+
const action0 = /:(approve|decline|cancel)$/.exec(data.callbackData)?.[1] ?? "";
|
|
7428
|
+
const claimed = this.consumeNonceCallback(CONTACT_TICKET_PREFIX, /^contact-ticket:([0-9a-f]{32}):(approve|decline|cancel)$/, data, adapterId, adapter, undefined, (_user, entry) => !!entry.messageId && !this.webPromptClicks.has(data) && mayDecide(entry, action0));
|
|
6707
7429
|
if (claimed === null)
|
|
6708
7430
|
return false;
|
|
6709
7431
|
if (claimed === "consumed")
|
|
6710
7432
|
return true;
|
|
6711
7433
|
const { entry, action } = claimed;
|
|
7434
|
+
if (sameCard(entry)) {
|
|
7435
|
+
await this.decideSameContactCard(port, principal, entry, action, data);
|
|
7436
|
+
return true;
|
|
7437
|
+
}
|
|
6712
7438
|
const ticket = entry.contactTicketId ? service.host.store.get(entry.contactTicketId) : undefined;
|
|
6713
7439
|
let text = t("contactHeld.closed");
|
|
6714
7440
|
if (ticket?.state === "pending" && person) {
|
|
@@ -6723,6 +7449,55 @@ export class FleetManager {
|
|
|
6723
7449
|
await this.retireNonceButtons(entry, entry.messageId ?? data.messageId, text);
|
|
6724
7450
|
return true;
|
|
6725
7451
|
}
|
|
7452
|
+
/**
|
|
7453
|
+
* S-229: one click on the same card. The decision is the clicker's, on the posted snapshot, through cards.decide —
|
|
7454
|
+
* the web's writer — so a duplicate, another card or the web racing it yields one committed outcome. A lost race
|
|
7455
|
+
* re-reads and shows that outcome; a changed request closes this card and posts one fresh card.
|
|
7456
|
+
*/
|
|
7457
|
+
async decideSameContactCard(port, principal, entry, action, data) {
|
|
7458
|
+
const id = entry.contactTicketId, proposal = !!entry.generalName;
|
|
7459
|
+
const read = () => { try {
|
|
7460
|
+
return port.read(id, principal);
|
|
7461
|
+
}
|
|
7462
|
+
catch {
|
|
7463
|
+
return null;
|
|
7464
|
+
} };
|
|
7465
|
+
let text, repost = false;
|
|
7466
|
+
if (action === "cancel")
|
|
7467
|
+
text = t(entry.contactProposalCurrent?.() ? "contactCard.not_now_done" : "contactProposal.expired");
|
|
7468
|
+
else if (proposal && entry.contactProposalCurrent?.() !== true)
|
|
7469
|
+
text = t("contactProposal.expired");
|
|
7470
|
+
else {
|
|
7471
|
+
try {
|
|
7472
|
+
const card = port.decide(id, { snapshot: entry.contactSnapshot, decision: action === "approve" ? "approve-once" : "decline" }, principal);
|
|
7473
|
+
text = nativeContactOutcome(card, { decided: true, by: principal.person });
|
|
7474
|
+
}
|
|
7475
|
+
catch (error) {
|
|
7476
|
+
const failure = nativeDecisionFailure(error), card = read();
|
|
7477
|
+
if (failure === "changed" && card?.ticket.state === "pending") {
|
|
7478
|
+
text = t(proposal ? "contactProposal.expired" : "contactCard.changed");
|
|
7479
|
+
repost = !proposal;
|
|
7480
|
+
}
|
|
7481
|
+
else if (failure === "failed" && card?.ticket.state === "pending")
|
|
7482
|
+
text = t("contactHeld.failed");
|
|
7483
|
+
else
|
|
7484
|
+
text = nativeContactOutcome(card, { decided: false });
|
|
7485
|
+
this.logger.info({ ticket: id, code: error?.message }, "A native contact card's decision did not apply");
|
|
7486
|
+
}
|
|
7487
|
+
}
|
|
7488
|
+
await this.retireNonceButtons(entry, entry.messageId ?? data.messageId, text);
|
|
7489
|
+
const fresh = this.contactService().host.store.get(id);
|
|
7490
|
+
if (!fresh)
|
|
7491
|
+
return;
|
|
7492
|
+
if (repost)
|
|
7493
|
+
this.heldTicketCards?.delete(id);
|
|
7494
|
+
try {
|
|
7495
|
+
this.syncHeldTicketCard(fresh);
|
|
7496
|
+
}
|
|
7497
|
+
catch (err) {
|
|
7498
|
+
this.logger?.warn?.({ err: err?.message, ticket: id }, "Held contact request card failed");
|
|
7499
|
+
}
|
|
7500
|
+
}
|
|
6726
7501
|
contactAuthorization(id, actor) {
|
|
6727
7502
|
const service = this.contactService(), ticket = service.host.store.get(id);
|
|
6728
7503
|
if (!ticket)
|
|
@@ -6852,6 +7627,8 @@ export class FleetManager {
|
|
|
6852
7627
|
}
|
|
6853
7628
|
/** Synchronous SQLite admission; the caller may acknowledge only after this returns. */
|
|
6854
7629
|
admitDurableDelivery(input) {
|
|
7630
|
+
if (this.requestContextPolicy || this.requestContextRelay)
|
|
7631
|
+
throw Error("Scoped contact admission is required; no legacy fallback");
|
|
6855
7632
|
const bindingHold = this.generalLocationDeliveryHold(input.targetInstance);
|
|
6856
7633
|
if (bindingHold)
|
|
6857
7634
|
throw Error(bindingHold);
|
|
@@ -6883,6 +7660,8 @@ export class FleetManager {
|
|
|
6883
7660
|
service.host.store.inheritOrigin(input.targetInstance, { ...inheritedOrigin, chain: [...inheritedOrigin.chain, input.targetInstance] });
|
|
6884
7661
|
const sourceKey = `mcp:${input.sourceInstance}:${input.operationId}:${input.targetInstance}:${input.targetSession ?? ""}:${input.kind}`;
|
|
6885
7662
|
const admitted = outbox.admit({ ...input, sourceDaemonBootId, sourceKey });
|
|
7663
|
+
if (admitted.inserted)
|
|
7664
|
+
this.quiescence?.noteAdmission(admitted.delivery.deliveryId, admitted.delivery.createdSeq);
|
|
6886
7665
|
if (admitted.inserted)
|
|
6887
7666
|
this.publishTraffic(admitted.delivery);
|
|
6888
7667
|
if (admitted.inserted)
|
|
@@ -6904,12 +7683,18 @@ export class FleetManager {
|
|
|
6904
7683
|
kind: admitted.delivery.kind,
|
|
6905
7684
|
};
|
|
6906
7685
|
}
|
|
7686
|
+
requestDeliveryView(deliveryId) { return this.requestContextPolicy && this.requestContextRelay && this.deliveryOutbox ? requestDeliveryView(this.deliveryOutbox, deliveryId) : null; }
|
|
6907
7687
|
queryDurableDeliveryStatus(callerInstance, selector) {
|
|
6908
7688
|
this.ensureDeliveryOutbox();
|
|
6909
7689
|
const page = this.deliveryOutbox.queryStatusForInstance(callerInstance, selector);
|
|
6910
7690
|
// #1939 §10: a human receipt's authority as it reads now (switch, epoch, loopback_only).
|
|
6911
7691
|
const state = page.items.some(item => item.authority) ? this.webAuthorityState() : null;
|
|
6912
7692
|
const human = (item) => {
|
|
7693
|
+
if (selector.messageId) {
|
|
7694
|
+
const projection = this.requestDeliveryView(item.delivery_id);
|
|
7695
|
+
if (projection)
|
|
7696
|
+
item = { ...item, request_provenance: projection.view };
|
|
7697
|
+
}
|
|
6913
7698
|
if (!item.authority || !state)
|
|
6914
7699
|
return item;
|
|
6915
7700
|
const authority = this.receiptAuthorityNow(item.authority, state);
|
|
@@ -7406,6 +8191,19 @@ export class FleetManager {
|
|
|
7406
8191
|
}
|
|
7407
8192
|
sent = true;
|
|
7408
8193
|
}
|
|
8194
|
+
else if (claimed.kind === UPDATE_HANDBACK_COPY_KIND) {
|
|
8195
|
+
// M-3770 §2.6 (rev 15, Fable #4536 design 3a): a turn the update barrier held, delivered as journaled. A person's
|
|
8196
|
+
// turn stays a person's — no from_instance is stamped — and only the fence's delivery id and attempt are added.
|
|
8197
|
+
if (payload.type === "raw_paste") {
|
|
8198
|
+
if (typeof payload.content !== "string")
|
|
8199
|
+
throw new Error("Durable hand-back copy has an invalid payload");
|
|
8200
|
+
sent = await this.deliverToInstance(target, { ...payload, delivery_id: claimed.deliveryId, delivery_attempt: String(claimed.attemptNo) }, { waitForIdle: false, noInlineWake: this.deliveryWorkerMode(target) !== "off" });
|
|
8201
|
+
}
|
|
8202
|
+
else {
|
|
8203
|
+
payload.meta = { ...rawMeta, delivery_id: claimed.deliveryId, delivery_attempt: String(claimed.attemptNo) };
|
|
8204
|
+
sent = await this.deliverToInstance(target, payload, { waitForIdle: true, noInlineWake: this.deliveryWorkerMode(target) !== "off" });
|
|
8205
|
+
}
|
|
8206
|
+
}
|
|
7409
8207
|
else if (claimed.kind === "raw_paste") {
|
|
7410
8208
|
if (payload.type !== "raw_paste" || typeof payload.content !== "string") {
|
|
7411
8209
|
throw new Error("Durable raw_paste row has an invalid payload");
|
|
@@ -8215,12 +9013,23 @@ export class FleetManager {
|
|
|
8215
9013
|
await data.respond(gate === "disabled" ? t("update.disabled", this.adminListKey(adapterId)) : t("not_authorized"));
|
|
8216
9014
|
return;
|
|
8217
9015
|
}
|
|
9016
|
+
// Bare slash /update is the card. `/update now` (options.now) keeps today's immediate path.
|
|
9017
|
+
if (data.options?.now !== true) {
|
|
9018
|
+
await data.respond(this.describeUpdateOffer());
|
|
9019
|
+
return;
|
|
9020
|
+
}
|
|
9021
|
+
const refused = this.refuseImmediateUpdate();
|
|
9022
|
+
if (refused) {
|
|
9023
|
+
await data.respond(refused);
|
|
9024
|
+
return;
|
|
9025
|
+
}
|
|
8218
9026
|
const messageId = await data.respond(t("update.progress.preparing", 0));
|
|
8219
9027
|
const adapter = this.adapters.get(adapterId) ?? this.adapter;
|
|
8220
9028
|
if (messageId && adapter) {
|
|
8221
9029
|
const chatId = String(this.getChannelConfig(adapterId)?.group_id ?? data.channelId);
|
|
8222
9030
|
this.beginUpdateProgress(adapter, chatId, data.channelId, messageId);
|
|
8223
9031
|
}
|
|
9032
|
+
this.beginUpdateRun();
|
|
8224
9033
|
// Plain `agend update`: the CLI picks the channel from the version it is about to replace (a beta install
|
|
8225
9034
|
// stays on beta). Deciding here, from the package.json next to THIS code, read a source checkout's 1.22.0 as
|
|
8226
9035
|
// "not a beta" and sent a beta install to @latest. #1450 C5: the INSTALLED agend, verified, by absolute path.
|
|
@@ -8231,8 +9040,14 @@ export class FleetManager {
|
|
|
8231
9040
|
* independently with its log — or a failure in the progress marker. `stillAllowed` is asked again once the awaits
|
|
8232
9041
|
* are done (the asker may have lost the right, or the fleet begun stopping, meanwhile).
|
|
8233
9042
|
*/
|
|
8234
|
-
async launchInstalledUpdate(origin, stillAllowed, pin) {
|
|
9043
|
+
async launchInstalledUpdate(origin, stillAllowed, pin, kind = "press") {
|
|
8235
9044
|
const { spawn } = await import("./child-process.js");
|
|
9045
|
+
// M-3770 (#4480 §4): the machine's pre-flight, proven again now — before the installed agend is resolved or run.
|
|
9046
|
+
const refused = await this.updatePreflightGate(kind);
|
|
9047
|
+
if (refused) {
|
|
9048
|
+
this.failUpdateProgress(refused);
|
|
9049
|
+
return null;
|
|
9050
|
+
}
|
|
8236
9051
|
const installed = await resolveInstalledAgend();
|
|
8237
9052
|
if (!installed.ok) {
|
|
8238
9053
|
this.failUpdateProgress(`${t("update.failure.shell")} ${t("update.failure.installed", installed.reason)}`);
|
|
@@ -9189,6 +10004,18 @@ export class FleetManager {
|
|
|
9189
10004
|
this.logger.warn({ instanceName, deliveryEpoch }, "Delivery held during tmux server recovery");
|
|
9190
10005
|
await this.stormWindow.waitForDeliveryAllowed(instanceName);
|
|
9191
10006
|
}
|
|
10007
|
+
/**
|
|
10008
|
+
* Last synchronous commit of a pane write (S-244). True: the barrier journaled an adapter or web turn, so it is
|
|
10009
|
+
* not sent. There is no await between this and `ipc.send`. Unarmed, or not an agent turn: false, and the send proceeds.
|
|
10010
|
+
* A Hub or room payload is not a copy: `refuseHubPane` refuses it before this, and the producer leaves the row queued.
|
|
10011
|
+
*/
|
|
10012
|
+
holdPaneSend(instanceName, payload) {
|
|
10013
|
+
return this.quiescence?.commitTurn(payload, instanceName) === true;
|
|
10014
|
+
}
|
|
10015
|
+
/** The fence is up and this payload belongs to a durable Hub or room row. Do not send it and do not copy it. */
|
|
10016
|
+
refuseHubPane(payload) {
|
|
10017
|
+
return this.quiescence?.armed() === true && turnSource(payload) === "hub";
|
|
10018
|
+
}
|
|
9192
10019
|
/**
|
|
9193
10020
|
* Hand a payload to an instance's IPC, waiting out a *transient* disconnect.
|
|
9194
10021
|
*
|
|
@@ -9217,7 +10044,12 @@ export class FleetManager {
|
|
|
9217
10044
|
if (ipc?.connected) {
|
|
9218
10045
|
if (beforeInput)
|
|
9219
10046
|
return this.handOffAfterBeforeInput(instanceName, payload, deliveryEpoch, stillCurrent, beforeInput);
|
|
9220
|
-
|
|
10047
|
+
const wire = this.bindHumanReceiptPayload(instanceName, payload);
|
|
10048
|
+
if (this.refuseHubPane(wire))
|
|
10049
|
+
return false;
|
|
10050
|
+
if (this.holdPaneSend(instanceName, wire))
|
|
10051
|
+
return true;
|
|
10052
|
+
if (ipc.send(wire))
|
|
9221
10053
|
return true;
|
|
9222
10054
|
}
|
|
9223
10055
|
}
|
|
@@ -9249,15 +10081,31 @@ export class FleetManager {
|
|
|
9249
10081
|
* goes in one attempt. After the intent is spent nothing here retries: false is the caller's uncertain outcome.
|
|
9250
10082
|
*/
|
|
9251
10083
|
async handOffAfterBeforeInput(instanceName, payload, deliveryEpoch, stillCurrent, beforeInput) {
|
|
10084
|
+
// The flag is read before beforeInput and before prepareClassicForPerson. A Hub or room row stays
|
|
10085
|
+
// queued at its producer: no begin lease, no input intent, and no plaintext copy of the question.
|
|
10086
|
+
if (this.refuseHubPane(payload))
|
|
10087
|
+
return false;
|
|
10088
|
+
if (this.quiescence?.armed()) {
|
|
10089
|
+
const early = this.bindHumanReceiptPayload(instanceName, payload);
|
|
10090
|
+
if (this.holdPaneSend(instanceName, early))
|
|
10091
|
+
return true;
|
|
10092
|
+
}
|
|
9252
10093
|
if (!(await beforeInput()))
|
|
9253
10094
|
return false;
|
|
10095
|
+
if (this.refuseHubPane(payload))
|
|
10096
|
+
return false;
|
|
9254
10097
|
const privateToken = await this.prepareClassicForPerson(instanceName, payload, deliveryEpoch, stillCurrent);
|
|
9255
10098
|
if (privateToken === false || this.shuttingDown || !this.deliveryCurrent(instanceName, deliveryEpoch, stillCurrent))
|
|
9256
10099
|
return false;
|
|
9257
10100
|
const ipc = this.instanceIpcClients.get(instanceName);
|
|
9258
10101
|
if (!ipc?.connected || (privateToken && this.classicPrivacy().read(instanceName)?.token !== privateToken))
|
|
9259
10102
|
return false;
|
|
9260
|
-
const
|
|
10103
|
+
const wire = this.bindHumanReceiptPayload(instanceName, payload);
|
|
10104
|
+
if (this.refuseHubPane(wire))
|
|
10105
|
+
return false;
|
|
10106
|
+
if (this.holdPaneSend(instanceName, wire))
|
|
10107
|
+
return true;
|
|
10108
|
+
const sent = ipc.send(wire);
|
|
9261
10109
|
if (sent && privateToken) {
|
|
9262
10110
|
try {
|
|
9263
10111
|
if (this.classicPrivacy().resume(instanceName, privateToken)) {
|
|
@@ -9285,8 +10133,15 @@ export class FleetManager {
|
|
|
9285
10133
|
const ipc = this.instanceIpcClients.get(instanceName);
|
|
9286
10134
|
if (ipc?.connected && beforeInput)
|
|
9287
10135
|
return this.handOffAfterBeforeInput(instanceName, payload, deliveryEpoch, stillCurrent, beforeInput);
|
|
9288
|
-
if (ipc?.connected
|
|
9289
|
-
|
|
10136
|
+
if (ipc?.connected) {
|
|
10137
|
+
const wire = this.bindHumanReceiptPayload(instanceName, payload);
|
|
10138
|
+
if (this.refuseHubPane(wire))
|
|
10139
|
+
return false;
|
|
10140
|
+
if (this.holdPaneSend(instanceName, wire))
|
|
10141
|
+
return true;
|
|
10142
|
+
if (ipc.send(wire))
|
|
10143
|
+
return true;
|
|
10144
|
+
}
|
|
9290
10145
|
// #2484: while the instance waits for (or runs) its own start retry, the grace runs from now — so the message is
|
|
9291
10146
|
// delivered once a retry brings it up, and fails only after the retries stop (they gave up, or a person stopped
|
|
9292
10147
|
// or paused it) and a last grace passes without it.
|
|
@@ -9640,7 +10495,11 @@ export class FleetManager {
|
|
|
9640
10495
|
const contactStore = this.deliveryOutbox.contactAuthorizations;
|
|
9641
10496
|
if (this.contactRoom(instanceName)?.restrictedMode === true && !contactStore)
|
|
9642
10497
|
throw Error("Contact origin storage unavailable");
|
|
9643
|
-
|
|
10498
|
+
// M-3830 (user 11-26, Fable): a person's message becomes contact origin only in a restricted ClassicBot room. Who may
|
|
10499
|
+
// talk to a fleet agent in its own topic is the admin's channel access (#754); recording it only once some earlier
|
|
10500
|
+
// inheritance had created a row made a cleared agent re-arm on its next topic message (a project lead, 11-26). What an
|
|
10501
|
+
// agent inherits from peers, rooms, new instances and board notes still carries its origin.
|
|
10502
|
+
if (contactStore && this.contactRoom(instanceName)?.restrictedMode === true) {
|
|
9644
10503
|
const authority = origin.authority;
|
|
9645
10504
|
const identity = origin.platform === "web" && isWebSessionIdentity(origin.web_identity) ? origin.web_identity : undefined;
|
|
9646
10505
|
const actor = origin.platform === "web" ? identity ?? (authority?.kind === "web-verified" ? authority.actor : null)
|
|
@@ -9750,7 +10609,14 @@ export class FleetManager {
|
|
|
9750
10609
|
const id = admitted.meta?.human_receipt_id;
|
|
9751
10610
|
let sent = false;
|
|
9752
10611
|
try {
|
|
9753
|
-
|
|
10612
|
+
const wire = this.bindHumanReceiptPayload(instanceName, admitted);
|
|
10613
|
+
if (this.refuseHubPane(wire))
|
|
10614
|
+
return false;
|
|
10615
|
+
if (this.holdPaneSend(instanceName, wire)) {
|
|
10616
|
+
sent = true;
|
|
10617
|
+
return true;
|
|
10618
|
+
}
|
|
10619
|
+
sent = ipc.send(wire);
|
|
9754
10620
|
return sent;
|
|
9755
10621
|
}
|
|
9756
10622
|
finally {
|
|
@@ -11897,6 +12763,28 @@ export class FleetManager {
|
|
|
11897
12763
|
this.namedLinkTestRunning = false;
|
|
11898
12764
|
}
|
|
11899
12765
|
}
|
|
12766
|
+
previewRouteTestRunning = false;
|
|
12767
|
+
/**
|
|
12768
|
+
* M-3814: Settings → Access → the fixed preview address's Check — the saved `web.public_link.preview_hostname`,
|
|
12769
|
+
* through the open fixed link's tunnel, to this preview listener (its boot id is the proof). One at a time; starts
|
|
12770
|
+
* nothing. An admin session only, over the public link too (M-3278; settings-api.ts).
|
|
12771
|
+
*/
|
|
12772
|
+
async testPreviewRoute(input = {}) {
|
|
12773
|
+
if (this.previewRouteTestRunning)
|
|
12774
|
+
return { busy: true };
|
|
12775
|
+
this.previewRouteTestRunning = true;
|
|
12776
|
+
try {
|
|
12777
|
+
const listener = this.previewListening ? this.previewListener : null;
|
|
12778
|
+
const hostname = publicLinkPreviewHostname(this.fleetConfig?.web);
|
|
12779
|
+
const result = await runPreviewRouteTest({ hostname, linkOpen: !!hostname && this.publicWebLink?.fixedPreviewHost?.() === hostname,
|
|
12780
|
+
bootId: listener?.bootId ?? null, port: listener?.settings.port ?? null, ...(input.hostname !== undefined ? { shown: input.hostname } : {}) });
|
|
12781
|
+
this.logger.info({ steps: result.steps.map(s => `${s.step}:${s.code}`) }, "Fixed preview address check");
|
|
12782
|
+
return result;
|
|
12783
|
+
}
|
|
12784
|
+
finally {
|
|
12785
|
+
this.previewRouteTestRunning = false;
|
|
12786
|
+
}
|
|
12787
|
+
}
|
|
11900
12788
|
getTunnelLane() {
|
|
11901
12789
|
return this.tunnelPurposeLane ??= new TunnelPurposeLane(new ManagedTunnel({ dataDir: this.dataDir,
|
|
11902
12790
|
log: () => this.logger.warn("Managed tunnel cleanup requires attention") }));
|
|
@@ -13505,6 +14393,7 @@ export class FleetManager {
|
|
|
13505
14393
|
const bootUpdateMarker = updateMarkerIdentity(this.dataDir);
|
|
13506
14394
|
const savedUpdateProgress = readUpdateProgress(this.dataDir);
|
|
13507
14395
|
this.hubUpdateBootProgress = savedUpdateProgress;
|
|
14396
|
+
this.localIdleBootProgress = savedUpdateProgress;
|
|
13508
14397
|
const pendingUpdateProgress = savedUpdateProgress
|
|
13509
14398
|
&& savedUpdateProgress.progress.stage !== "failed"
|
|
13510
14399
|
&& savedUpdateProgress.progress.stage !== "complete"
|
|
@@ -13517,6 +14406,8 @@ export class FleetManager {
|
|
|
13517
14406
|
setUpdateProgressStage(this.dataDir, "starting", { version: pendingUpdateProgress.progress.version });
|
|
13518
14407
|
}
|
|
13519
14408
|
this.initializeWebAuthTokens();
|
|
14409
|
+
// M-3827: the people seen before this start keep their names in the web chat's mentions (before any adapter connects).
|
|
14410
|
+
this.seenUsers?.persistTo({ path: join(this.dataDir, SEEN_USERS_FILE), onWarn: message => this.logger.warn(message) });
|
|
13520
14411
|
// Must run before the first General/CLI spawn: pressure can hold startup.
|
|
13521
14412
|
// Logs remain available even before the adapters and health listener exist.
|
|
13522
14413
|
this.memoryPressure.start();
|
|
@@ -13827,6 +14718,8 @@ export class FleetManager {
|
|
|
13827
14718
|
// rows can never crowd an instance's own out (#3421 review). Nothing unbounded goes into process.env.
|
|
13828
14719
|
this.snapshotActiveDecisions();
|
|
13829
14720
|
}
|
|
14721
|
+
// M-3770 §2.6: a fleet an abandon restarted takes the held work back before any ingress opens (rev 15).
|
|
14722
|
+
await this.startUpdateHandback();
|
|
13830
14723
|
// Phase 1: Start general instances first and wait for them
|
|
13831
14724
|
// M-2457: a held fleet starts no agent (the hold's Needs-you line says why and what to do).
|
|
13832
14725
|
const allEntries = this.tmuxHold ? [] : Object.entries(fleet.instances).filter(([, config]) => !isNativeExecInstance(config));
|
|
@@ -14092,6 +14985,9 @@ export class FleetManager {
|
|
|
14092
14985
|
this.checkForUpdates();
|
|
14093
14986
|
this.updateCheckTimer = setInterval(() => this.checkForUpdates(), 24 * 60 * 60 * 1000);
|
|
14094
14987
|
}, 60 * 60 * 1000);
|
|
14988
|
+
// M-3770 1.5: General's update card follows the fleet's card (a Not now that ran out, a wait that started or ended).
|
|
14989
|
+
this.updateChatCardTimer = setInterval(() => { void this.syncUpdateChatCard(); }, 60_000);
|
|
14990
|
+
this.updateChatCardTimer.unref?.();
|
|
14095
14991
|
const onRestart = () => this.onGracefulRestartSignal(() => process.once("SIGUSR2", onRestart));
|
|
14096
14992
|
process.once("SIGUSR2", onRestart);
|
|
14097
14993
|
// SIGUSR1: full process reload (graceful stop → exit). Nothing in this AgEnD sends it any more (#2356); an older
|
|
@@ -15081,6 +15977,7 @@ export class FleetManager {
|
|
|
15081
15977
|
if (this.instanceIpcClients.get(name) === existing) {
|
|
15082
15978
|
this.instanceIpcClients.delete(name);
|
|
15083
15979
|
}
|
|
15980
|
+
this.purgeRequestContextIpcCalls(name, existing);
|
|
15084
15981
|
}
|
|
15085
15982
|
}
|
|
15086
15983
|
const daemon = this.daemons.get(name);
|
|
@@ -15094,7 +15991,17 @@ export class FleetManager {
|
|
|
15094
15991
|
try {
|
|
15095
15992
|
await ipc.connect();
|
|
15096
15993
|
this.instanceIpcClients.set(name, ipc);
|
|
15994
|
+
this.observeRequestContextResponses(name, ipc);
|
|
15097
15995
|
ipc.on("message", safeHandler(async (msg) => {
|
|
15996
|
+
if ((msg.type === "fleet_outbound" || toolForIpcType(msg.type) !== null) && !this.captureRequestContextIpcCall(name, msg, ipc)) {
|
|
15997
|
+
if (this.instanceIpcClients.get(name) !== ipc)
|
|
15998
|
+
return;
|
|
15999
|
+
if (msg.type === "fleet_outbound")
|
|
16000
|
+
ipc.send({ type: "fleet_outbound_response", fleetRequestId: msg.fleetRequestId, error: "Originating request context is unavailable" });
|
|
16001
|
+
else
|
|
16002
|
+
this.refuseTypedIpc(name, msg, "Originating request context is unavailable");
|
|
16003
|
+
return;
|
|
16004
|
+
}
|
|
15098
16005
|
if (msg.type === "mcp_ready") {
|
|
15099
16006
|
// Register external sessions (sessionName differs from instance name)
|
|
15100
16007
|
const sessionName = msg.sessionName;
|
|
@@ -15119,7 +16026,12 @@ export class FleetManager {
|
|
|
15119
16026
|
this.sessionRegistry.set(sender, name);
|
|
15120
16027
|
this.logger.info({ sessionName: sender, instanceName: name }, "Registered external session");
|
|
15121
16028
|
}
|
|
15122
|
-
|
|
16029
|
+
try {
|
|
16030
|
+
await this.handleOutboundFromInstance(name, msg);
|
|
16031
|
+
}
|
|
16032
|
+
finally {
|
|
16033
|
+
this.finishRequestContextIpcCall(msg);
|
|
16034
|
+
}
|
|
15123
16035
|
}
|
|
15124
16036
|
else if (toolForIpcType(msg.type) !== null) {
|
|
15125
16037
|
// Sink 2 of 3. Each of these types IS a tool and reaches its own
|
|
@@ -15240,6 +16152,7 @@ export class FleetManager {
|
|
|
15240
16152
|
if (this.instanceIpcClients.get(name) !== ipc)
|
|
15241
16153
|
return;
|
|
15242
16154
|
this.instanceIpcClients.delete(name);
|
|
16155
|
+
this.purgeRequestContextIpcCalls(name, ipc);
|
|
15243
16156
|
if (this.ipcStoppingInstances.has(name))
|
|
15244
16157
|
return;
|
|
15245
16158
|
this.ipcReconnect(name).catch(() => { });
|
|
@@ -16636,6 +17549,7 @@ export class FleetManager {
|
|
|
16636
17549
|
return { allowed: true, message: "" };
|
|
16637
17550
|
}
|
|
16638
17551
|
async handleOutboundFromInstance(instanceName, msg) {
|
|
17552
|
+
const originatingCall = this.requestContextCallOf(msg);
|
|
16639
17553
|
this.touchActivity(instanceName);
|
|
16640
17554
|
this.setTopicIcon(instanceName, "green");
|
|
16641
17555
|
const tool = msg.tool;
|
|
@@ -16676,13 +17590,30 @@ export class FleetManager {
|
|
|
16676
17590
|
respond(null, permitted.message);
|
|
16677
17591
|
return;
|
|
16678
17592
|
}
|
|
17593
|
+
try {
|
|
17594
|
+
if (this.requestContextPolicy)
|
|
17595
|
+
requireRequestContextPolicy(this, instanceName, tool === "hub_room_status" ? "hub_room_list" : tool, args, originatingCall?.admission);
|
|
17596
|
+
}
|
|
17597
|
+
catch (error) {
|
|
17598
|
+
respond(null, error.message);
|
|
17599
|
+
return;
|
|
17600
|
+
}
|
|
16679
17601
|
// Fleet tools resolve their own targets. A missing chat world must not prevent local
|
|
16680
17602
|
// delivery, inspection or receipt lookup; only channel tools need reply routing below.
|
|
16681
17603
|
const handler = outboundHandlers.get(tool);
|
|
16682
17604
|
if (handler && !usesChannelAddress(tool)) {
|
|
16683
17605
|
this.eventLog?.logActivity("tool_call", senderSessionName ?? instanceName, this.summarizeToolCall(tool, args));
|
|
16684
|
-
|
|
17606
|
+
let context = this;
|
|
17607
|
+
if (originatingCall || this.requestContextPolicy) {
|
|
17608
|
+
const entryBoot = sourceDaemonBootId ?? this.getDaemonBootId(instanceName);
|
|
17609
|
+
context = (await import("./native-agent-admission.js")).nativeAgentAdmissionContext(this, {
|
|
17610
|
+
instance: instanceName, operation: { tool, args }, current: () => originatingCall ? originatingCall.current() : !!entryBoot && this.getDaemonBootId(instanceName) === entryBoot, taskAllowed: () => this.checkToolPermission("ipc-outbound", instanceName, "task").allowed,
|
|
17611
|
+
...(originatingCall?.admission.coverage === "covered" ? { requestContext: originatingCall.admission.lease } : { notCoveredReason: originatingCall?.admission.reason ?? "unbound-input" }),
|
|
17612
|
+
});
|
|
17613
|
+
}
|
|
17614
|
+
await handler(context, args, respond, {
|
|
16685
17615
|
instanceName, requestId, fleetRequestId, senderSessionName, operationId, sourceDaemonBootId,
|
|
17616
|
+
...(originatingCall ? { callerCurrent: () => originatingCall.current(), requestContextAdmission: originatingCall.admission } : {}),
|
|
16686
17617
|
});
|
|
16687
17618
|
return;
|
|
16688
17619
|
}
|
|
@@ -16695,7 +17626,8 @@ export class FleetManager {
|
|
|
16695
17626
|
return;
|
|
16696
17627
|
}
|
|
16697
17628
|
const claimed = this.hubReact({ correlationId: args.message_id, caller: instanceName, emoji: typeof args.emoji === "string" ? args.emoji : "",
|
|
16698
|
-
|
|
17629
|
+
...(this.requestContextPolicy ? { requestScope: captureRequestHubOutput(originatingCall?.admission) } : {}),
|
|
17630
|
+
callerCurrent: () => this.getDaemonBootId(instanceName) === bootSent && (!originatingCall || originatingCall.current()) });
|
|
16699
17631
|
if (!claimed) {
|
|
16700
17632
|
respond(null, "That message_id is not a Hub room question you were asked.");
|
|
16701
17633
|
return;
|
|
@@ -16740,15 +17672,17 @@ export class FleetManager {
|
|
|
16740
17672
|
return;
|
|
16741
17673
|
}
|
|
16742
17674
|
let replyBookkeeping = Promise.resolve();
|
|
16743
|
-
const restrictedExtras = restrictedRoute ? {
|
|
16744
|
-
prepareFiles: (paths) => this.prepareContactFiles(instanceName, paths),
|
|
17675
|
+
const restrictedExtras = restrictedRoute || originatingCall ? {
|
|
17676
|
+
...(restrictedRoute ? { prepareFiles: (paths) => this.prepareContactFiles(instanceName, paths),
|
|
17677
|
+
downloadAttachment: (id) => this.downloadRoomAttachment(instanceName, id) } : {}),
|
|
16745
17678
|
replyFinished: () => replyBookkeeping,
|
|
16746
|
-
downloadAttachment: (id) => this.downloadRoomAttachment(instanceName, id),
|
|
16747
17679
|
beforeSend: () => {
|
|
17680
|
+
if (originatingCall && !originatingCall.current())
|
|
17681
|
+
throw Error("Originating request context is no longer current");
|
|
16748
17682
|
const current = this.restrictedClassicRouting(instanceName);
|
|
16749
|
-
if (!current || current.adapterId !== restrictedRoute.adapterId || current.chatId !== restrictedRoute.chatId
|
|
17683
|
+
if (restrictedRoute && (!current || current.adapterId !== restrictedRoute.adapterId || current.chatId !== restrictedRoute.chatId
|
|
16750
17684
|
|| current.threadId !== restrictedRoute.threadId || this.contactGeneration(instanceName) !== restrictedIncarnation
|
|
16751
|
-
|| this.getDaemonBootId(instanceName) !== restrictedBoot)
|
|
17685
|
+
|| this.getDaemonBootId(instanceName) !== restrictedBoot))
|
|
16752
17686
|
throw Error("Restricted room route changed before delivery");
|
|
16753
17687
|
},
|
|
16754
17688
|
} : {};
|
|
@@ -17466,7 +18400,20 @@ export class FleetManager {
|
|
|
17466
18400
|
ipc.send({ type: responseType, fleetRequestId, error: message });
|
|
17467
18401
|
}
|
|
17468
18402
|
dispatchTypedIpc(name, msg) {
|
|
18403
|
+
const captured = this.requestContextCallOf(msg);
|
|
18404
|
+
if (captured && !captured.current()) {
|
|
18405
|
+
this.refuseTypedIpc(name, msg, "Originating request context is no longer current");
|
|
18406
|
+
return;
|
|
18407
|
+
}
|
|
17469
18408
|
const type = String(msg.type);
|
|
18409
|
+
try {
|
|
18410
|
+
if (this.requestContextPolicy)
|
|
18411
|
+
requireRequestContextPolicy(this, name, toolForIpcType(type) ?? type, (msg.payload ?? {}), captured?.admission);
|
|
18412
|
+
}
|
|
18413
|
+
catch (error) {
|
|
18414
|
+
this.refuseTypedIpc(name, msg, error.message);
|
|
18415
|
+
return;
|
|
18416
|
+
}
|
|
17470
18417
|
if (type.startsWith("fleet_schedule_")) {
|
|
17471
18418
|
this.handleScheduleCrud(name, msg);
|
|
17472
18419
|
return;
|
|
@@ -17518,6 +18465,8 @@ export class FleetManager {
|
|
|
17518
18465
|
const tool = String(msg.type).replace(/^fleet_/, "");
|
|
17519
18466
|
try {
|
|
17520
18467
|
const args = (msg.payload ?? {});
|
|
18468
|
+
if (this.requestContextPolicy)
|
|
18469
|
+
requireRequestContextPolicy(this, instanceName, tool, args, this.requestContextCallOf(msg)?.admission);
|
|
17521
18470
|
const result = tool === "get_web_appearance" || tool === "preview_web_appearance"
|
|
17522
18471
|
? this.appearanceTools.handle(instanceName, tool, args)
|
|
17523
18472
|
: tool === "office_view" || tool === "office_set" ? this.officeActs.handle(instanceName, tool, args)
|
|
@@ -17563,6 +18512,7 @@ export class FleetManager {
|
|
|
17563
18512
|
try {
|
|
17564
18513
|
const op = String(msg.type).replace("fleet_schedule_", "");
|
|
17565
18514
|
const result = this.performScheduleOp(instanceName, op, payload, {
|
|
18515
|
+
requestContextAdmission: this.requestContextCallOf(msg)?.admission,
|
|
17566
18516
|
// The daemon sends its last chat id, which is unset until the instance
|
|
17567
18517
|
// has had a chat message — and cross-instance traffic never sets it. So
|
|
17568
18518
|
// a worker that only takes delegated tasks, the very instance #895 lets
|
|
@@ -17729,7 +18679,7 @@ export class FleetManager {
|
|
|
17729
18679
|
ipc.send({ type: "fleet_description_response", fleetRequestId, result: { description } });
|
|
17730
18680
|
}
|
|
17731
18681
|
// ── Agent CLI HTTP handlers ─────────────────────────────────────────
|
|
17732
|
-
async handleScheduleCrudHttp(instance, op, args) {
|
|
18682
|
+
async handleScheduleCrudHttp(instance, op, args, requestContextAdmission) {
|
|
17733
18683
|
if (!this.scheduler)
|
|
17734
18684
|
return { error: "Scheduler not available" };
|
|
17735
18685
|
if (op !== "create" && op !== "list" && op !== "update" && op !== "delete") {
|
|
@@ -17737,7 +18687,7 @@ export class FleetManager {
|
|
|
17737
18687
|
}
|
|
17738
18688
|
// No bound chat on this path, as before: a schedule made through the agent
|
|
17739
18689
|
// endpoint has nowhere of its own to reply.
|
|
17740
|
-
return this.performScheduleOp(instance, op, args, { chatId: "", threadId: null });
|
|
18690
|
+
return this.performScheduleOp(instance, op, args, { chatId: "", threadId: null, requestContextAdmission });
|
|
17741
18691
|
}
|
|
17742
18692
|
/**
|
|
17743
18693
|
* The only place an agent's request creates, changes or removes a schedule
|
|
@@ -17752,6 +18702,8 @@ export class FleetManager {
|
|
|
17752
18702
|
* of the schedule response on IPC.
|
|
17753
18703
|
*/
|
|
17754
18704
|
performScheduleOp(caller, op, args, reply) {
|
|
18705
|
+
if (this.requestContextPolicy)
|
|
18706
|
+
requireRequestContextPolicy(this, caller, op === "list" ? "list_schedules" : `${op}_schedule`, args, reply.requestContextAdmission);
|
|
17755
18707
|
const scheduler = this.scheduler;
|
|
17756
18708
|
// Shape first, so the value the permission decision reads is the value the
|
|
17757
18709
|
// scheduler gets. `target` used to be filtered through typeof for the
|
|
@@ -17953,10 +18905,12 @@ export class FleetManager {
|
|
|
17953
18905
|
default: return { error: `Unknown decision op: ${op}` };
|
|
17954
18906
|
}
|
|
17955
18907
|
}
|
|
17956
|
-
async handleTaskCrudHttp(instance, args) {
|
|
18908
|
+
async handleTaskCrudHttp(instance, args, _snapshot, requestContextAdmission) {
|
|
17957
18909
|
if (!this.scheduler)
|
|
17958
18910
|
return { error: "Scheduler not available" };
|
|
17959
18911
|
const db = this.scheduler.db;
|
|
18912
|
+
if (this.requestContextPolicy)
|
|
18913
|
+
requireRequestContextPolicy(this, instance, "task", args, requestContextAdmission);
|
|
17960
18914
|
const action = args.action;
|
|
17961
18915
|
const asStr = (v) => typeof v === "string" ? v : undefined;
|
|
17962
18916
|
const asStrArr = (v) => Array.isArray(v) && v.every(x => typeof x === "string") ? v : undefined;
|
|
@@ -18069,7 +19023,9 @@ export class FleetManager {
|
|
|
18069
19023
|
return this.setPersonaEmoji(instance, args);
|
|
18070
19024
|
}
|
|
18071
19025
|
/** #1629: `agend-agent theme …` — the same service as the tools; `instance` is the token's. */
|
|
18072
|
-
async handleWebThemeHttp(instance, tool, args) {
|
|
19026
|
+
async handleWebThemeHttp(instance, tool, args, requestContextAdmission) {
|
|
19027
|
+
if (this.requestContextPolicy)
|
|
19028
|
+
requireRequestContextPolicy(this, instance, tool, args, requestContextAdmission);
|
|
18073
19029
|
if (isCanvasWorkerTool(tool))
|
|
18074
19030
|
return { error: "canvas_worker_experimental", message: CANVAS_WORKER_EXPERIMENTAL_MESSAGE }; // #2799: removed
|
|
18075
19031
|
if (tool === "get_web_appearance" || tool === "preview_web_appearance")
|
|
@@ -18126,6 +19082,14 @@ export class FleetManager {
|
|
|
18126
19082
|
return;
|
|
18127
19083
|
}
|
|
18128
19084
|
const db = this.scheduler.db;
|
|
19085
|
+
try {
|
|
19086
|
+
if (this.requestContextPolicy)
|
|
19087
|
+
requireRequestContextPolicy(this, instanceName, "task", payload, this.requestContextCallOf(msg)?.admission);
|
|
19088
|
+
}
|
|
19089
|
+
catch (error) {
|
|
19090
|
+
ipc.send({ type: "fleet_task_response", fleetRequestId, error: error.message });
|
|
19091
|
+
return;
|
|
19092
|
+
}
|
|
18129
19093
|
const action = payload.action;
|
|
18130
19094
|
// #1336 P2: use the shared normalizer — trims whitespace AND drops empties,
|
|
18131
19095
|
// so " \t " / [" ","\t"] are treated identically to undefined.
|
|
@@ -18592,7 +19556,9 @@ export class FleetManager {
|
|
|
18592
19556
|
* document. Unknown keys and comments remain untouched; redundant
|
|
18593
19557
|
* non-identity instance leaves are canonicalized to inheritance afterward.
|
|
18594
19558
|
*/
|
|
18595
|
-
saveFleetConfig(explicitPatches = []) {
|
|
19559
|
+
saveFleetConfig(explicitPatches = [], requestContextAdmission) {
|
|
19560
|
+
if (this.requestContextPolicy && requestContextAdmission)
|
|
19561
|
+
requireRequestContextPolicy(this, requestContextAdmission.coverage === "covered" ? requestContextAdmission.lease.snapshot.owner.instance : "", "update_instance_config", {}, requestContextAdmission);
|
|
18596
19562
|
if (!this.companyMembershipWrite && explicitPatches.some(p => p.path[0] === "hub_member"
|
|
18597
19563
|
&& (p.path[1] === "enabled" ? p.value !== true || p.remove : p.path.length === 1)))
|
|
18598
19564
|
this.invalidateHubCompanyJoin();
|
|
@@ -20991,7 +21957,8 @@ export class FleetManager {
|
|
|
20991
21957
|
entry.web = {
|
|
20992
21958
|
text: web.text,
|
|
20993
21959
|
...(links ? { links } : {}),
|
|
20994
|
-
|
|
21960
|
+
...(opts.view ? { view: opts.view } : {}),
|
|
21961
|
+
actions: [...opts.choices.map(c => ({ id: c.action, label: c.label, ...(c.hint ? { hint: c.hint } : {}), ...(c.role ? { role: c.role } : {}), ...(c.confirmation ? { confirmation: c.confirmation } : {}) })), ...(opts.webInput ? [{ id: opts.webInput.action, label: opts.webInput.label, input: true }] : [])],
|
|
20995
21962
|
expiresAt: Date.now() + (opts.timeoutMs ?? NONCE_BUTTON_TIMEOUT_MS),
|
|
20996
21963
|
};
|
|
20997
21964
|
this.emitSseEvent("prompt", { instance: entry.instanceName, nonce, ...entry.web });
|
|
@@ -21178,6 +22145,8 @@ export class FleetManager {
|
|
|
21178
22145
|
return true;
|
|
21179
22146
|
if (await this.handleHubUpdateCallback(data, adapterId, adapter))
|
|
21180
22147
|
return true;
|
|
22148
|
+
if (await this.handleUpdateCardCallback(data, adapterId, adapter))
|
|
22149
|
+
return true; // M-3770 1.5
|
|
21181
22150
|
if (await this.handleKiroReconcileCallback(data, adapterId, adapter))
|
|
21182
22151
|
return true;
|
|
21183
22152
|
if (await this.handleOfficePackCallback(data, adapterId, adapter))
|
|
@@ -21587,6 +22556,7 @@ export class FleetManager {
|
|
|
21587
22556
|
createdAt: e.createdAt ?? Date.now(), adapterId: e.adapterId, chatId: e.chatId,
|
|
21588
22557
|
...(e.threadId !== undefined ? { threadId: e.threadId } : {}), ...(e.messageId ? { messageId: e.messageId } : {}),
|
|
21589
22558
|
...(e.assistFor ? { assistFor: e.assistFor } : {}),
|
|
22559
|
+
...(e.web.view ? { view: e.web.view } : {}),
|
|
21590
22560
|
});
|
|
21591
22561
|
}
|
|
21592
22562
|
return out;
|
|
@@ -23751,10 +24721,10 @@ export class FleetManager {
|
|
|
23751
24721
|
...card, title: redactSecrets(card.title), question: redactSecrets(card.question),
|
|
23752
24722
|
options: card.options.map(o => ({ ...o, title: redactSecrets(o.title), description: o.description === null ? null : redactSecrets(o.description) })),
|
|
23753
24723
|
} : card;
|
|
23754
|
-
const prompt = remoteCardPrompt(instanceName, shown);
|
|
24724
|
+
const prompt = remoteCardPrompt(instanceName, shown, this.shownInstanceName(instanceName));
|
|
23755
24725
|
const nonce = await this.postNonceButtonPrompt({
|
|
23756
24726
|
prefix: REMOTE_CARD_CALLBACK_PREFIX, alertType: "interactive_prompt", instanceName, ...place,
|
|
23757
|
-
message: prompt.message, choices: prompt.choices, webInput: prompt.webInput,
|
|
24727
|
+
message: prompt.message, choices: prompt.choices, webInput: prompt.webInput, ...(prompt.view ? { view: prompt.view } : {}),
|
|
23758
24728
|
expiredText: t("card.expired", instanceName), timeoutMs: REMOTE_CARD_TIMEOUT_MS,
|
|
23759
24729
|
extra: { remoteCard: { identity: card.identity, kind: card.kind, options: shown.kind === "question" ? shown.options.map(o => ({ n: o.n, title: o.title })) : [],
|
|
23760
24730
|
requiresAdmin, ownerAdapterId: this.getInstanceAdapterId(instanceName), humanOnly: card.kind === "question" && card.humanOnly === true } },
|
|
@@ -27057,6 +28027,8 @@ export class FleetManager {
|
|
|
27057
28027
|
posts: m.posts, // #2281: kept beside the row, never broadcast (not a row field)
|
|
27058
28028
|
reserved: m.reserved, // #1774: an agent reply's place, taken when it was sent
|
|
27059
28029
|
contactTicket: m.contactTicket,
|
|
28030
|
+
requestProvenance: m.requestProvenance,
|
|
28031
|
+
wrap: m.wrap,
|
|
27060
28032
|
});
|
|
27061
28033
|
// A sending page's own id for its pending bubble rides on the live copy only: never recorded, never replayed.
|
|
27062
28034
|
const clientId = typeof data.clientId === "string" ? data.clientId : "";
|
|
@@ -30912,6 +31884,10 @@ export class FleetManager {
|
|
|
30912
31884
|
// because we asked it to. Set synchronously — doStopAll runs to its first
|
|
30913
31885
|
// await in the same tick as the signal handler, so no event can slip in.
|
|
30914
31886
|
this.shuttingDown = true;
|
|
31887
|
+
try {
|
|
31888
|
+
this.updateCard?.close();
|
|
31889
|
+
}
|
|
31890
|
+
catch { /* stopping */ }
|
|
30915
31891
|
this.hostMonitor?.stop();
|
|
30916
31892
|
this.stopQuotaObserver?.();
|
|
30917
31893
|
this.stopQuotaObserver = null;
|
|
@@ -31058,6 +32034,10 @@ export class FleetManager {
|
|
|
31058
32034
|
clearInterval(this.updateCheckTimer);
|
|
31059
32035
|
this.updateCheckTimer = null;
|
|
31060
32036
|
}
|
|
32037
|
+
if (this.updateChatCardTimer) {
|
|
32038
|
+
clearInterval(this.updateChatCardTimer);
|
|
32039
|
+
this.updateChatCardTimer = null;
|
|
32040
|
+
}
|
|
31061
32041
|
if (this.eventLogPruneTimer) {
|
|
31062
32042
|
clearInterval(this.eventLogPruneTimer);
|
|
31063
32043
|
this.eventLogPruneTimer = null;
|
|
@@ -31169,6 +32149,7 @@ export class FleetManager {
|
|
|
31169
32149
|
// noticeable latency.
|
|
31170
32150
|
await Promise.all([...this.instanceIpcClients.values()].map(ipc => Promise.resolve(ipc.close()).catch(() => { })));
|
|
31171
32151
|
this.instanceIpcClients.clear();
|
|
32152
|
+
this.requestContextFleetCalls?.clear();
|
|
31172
32153
|
this.ipcStoppingInstances.clear();
|
|
31173
32154
|
for (const [, w] of this.worlds) {
|
|
31174
32155
|
await w.stop().catch(() => { });
|
|
@@ -31197,6 +32178,7 @@ export class FleetManager {
|
|
|
31197
32178
|
// write that failed and is still owed — is paid now, so a restart neither shortens the idle window
|
|
31198
32179
|
// nor revives a session that was revoked while the disk was refusing writes.
|
|
31199
32180
|
this.webSessions?.flush();
|
|
32181
|
+
this.seenUsers?.flush(); // M-3827: the names seen since the last write
|
|
31200
32182
|
this.eventLog?.close();
|
|
31201
32183
|
this.replyButtonsCtl?.stop();
|
|
31202
32184
|
this.replyButtonsStore?.close();
|
|
@@ -33175,6 +34157,7 @@ export class FleetManager {
|
|
|
33175
34157
|
await ipc.close();
|
|
33176
34158
|
}
|
|
33177
34159
|
this.instanceIpcClients.clear();
|
|
34160
|
+
this.requestContextFleetCalls?.clear();
|
|
33178
34161
|
await this.stopInstancesInBatches(instanceNames, name => this.stopInstance(name));
|
|
33179
34162
|
// Kill remaining orphan windows to prevent stale state on restart
|
|
33180
34163
|
try {
|
|
@@ -33361,10 +34344,200 @@ export class FleetManager {
|
|
|
33361
34344
|
}
|
|
33362
34345
|
return { target, fromChannel };
|
|
33363
34346
|
}
|
|
33364
|
-
/** M-
|
|
34347
|
+
/** M-3770: the pre-flight probes (runUpdatePreflight; tests stub that module, so no real npm or systemctl runs). */
|
|
34348
|
+
async probeUpdatePreflight(opts) {
|
|
34349
|
+
const { defaultReadinessDeps, runUpdatePreflight } = await import("./update-readiness.js");
|
|
34350
|
+
return runUpdatePreflight(opts, { ...defaultReadinessDeps(), home: this.dataDir });
|
|
34351
|
+
}
|
|
34352
|
+
/**
|
|
34353
|
+
* M-3770: refresh the cached pre-flight for the offered version. One at a time; never throws. A run is bound to the
|
|
34354
|
+
* version it judged: if the offer moved meanwhile its result is not published (Prism #4483 3) and the run starts again
|
|
34355
|
+
* for the new one. What it finds is merged by check (mergePreflight): a launch's fresher local rows are kept.
|
|
34356
|
+
*/
|
|
34357
|
+
refreshUpdatePreflight() {
|
|
34358
|
+
if (this.updatePreflightRunning)
|
|
34359
|
+
return this.updatePreflightRunning;
|
|
34360
|
+
const running = (async () => {
|
|
34361
|
+
const { mergePreflight } = await import("./update-readiness.js");
|
|
34362
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
34363
|
+
const target = this.updateCheckState?.offer?.version ?? null;
|
|
34364
|
+
let fresh;
|
|
34365
|
+
try {
|
|
34366
|
+
fresh = await this.probeUpdatePreflight({ target });
|
|
34367
|
+
}
|
|
34368
|
+
catch (err) {
|
|
34369
|
+
this.logger.warn({ err }, "Update pre-flight could not run");
|
|
34370
|
+
return;
|
|
34371
|
+
}
|
|
34372
|
+
const now = this.updateCheckState?.offer?.version ?? null;
|
|
34373
|
+
if (now !== target)
|
|
34374
|
+
continue; // the offer changed: judge the new one
|
|
34375
|
+
this.updatePreflight = mergePreflight(this.updatePreflight, fresh, now);
|
|
34376
|
+
return;
|
|
34377
|
+
}
|
|
34378
|
+
})().finally(() => { if (this.updatePreflightRunning === running)
|
|
34379
|
+
this.updatePreflightRunning = null; });
|
|
34380
|
+
this.updatePreflightRunning = running;
|
|
34381
|
+
return running;
|
|
34382
|
+
}
|
|
34383
|
+
/**
|
|
34384
|
+
* M-3770 (#4480 §4.2): identity is proven at the moment of change. The local checks run again now, whatever the cached
|
|
34385
|
+
* result says, and decide; the network ones (P7, P10) are `agend update`'s own. The cache takes the fresh rows and
|
|
34386
|
+
* keeps a cached P7/P10 only while it still applies, with its own age (mergePreflight).
|
|
34387
|
+
* Returns the refusal in words, or null to go ahead.
|
|
34388
|
+
*/
|
|
34389
|
+
async updatePreflightGate(origin) {
|
|
34390
|
+
const { mergePreflight, preflightRefusal } = await import("./update-readiness.js");
|
|
34391
|
+
let fresh;
|
|
34392
|
+
try {
|
|
34393
|
+
fresh = await this.probeUpdatePreflight({ localOnly: true });
|
|
34394
|
+
}
|
|
34395
|
+
catch (err) {
|
|
34396
|
+
this.logger.warn({ err }, "Update pre-flight could not run at launch");
|
|
34397
|
+
return t("update.preflight.refused", t("update.preflight.code.unreadable"));
|
|
34398
|
+
}
|
|
34399
|
+
this.updatePreflight = mergePreflight(this.updatePreflight, fresh, this.updateCheckState?.offer?.version ?? null);
|
|
34400
|
+
return preflightRefusal(fresh, origin, (key, ...args) => t(key, ...args));
|
|
34401
|
+
}
|
|
34402
|
+
ensureUpdateCard() {
|
|
34403
|
+
if (this.updateCard)
|
|
34404
|
+
return this.updateCard;
|
|
34405
|
+
this.updateCard = new UpdateOfferCard({
|
|
34406
|
+
dataDir: this.dataDir,
|
|
34407
|
+
now: () => Date.now(),
|
|
34408
|
+
settings: () => this.fleetConfig?.updates,
|
|
34409
|
+
busyNames: () => this.updateBusyNames(),
|
|
34410
|
+
// The local claim only. The Hub queue keeps the default, so this launch still looks busy to it.
|
|
34411
|
+
agentsIdle: () => this.hubUpdateIdle(this.localIdleOwned),
|
|
34412
|
+
externalBusy: () => !!this.webUpdateOwned || isUpdateInProgress(this.dataDir) || !!this.hubUpdates?.idlePending(),
|
|
34413
|
+
launchNow: (by, stillAllowed) => this.startWebUpdate(by, () => !this.shuttingDown && stillAllowed()),
|
|
34414
|
+
launchHubNow: async (id, stillAllowed) => {
|
|
34415
|
+
const owner = this.hubUpdates;
|
|
34416
|
+
if (!owner)
|
|
34417
|
+
return { ok: false, status: 409, error: "request_not_found" };
|
|
34418
|
+
const current = () => !this.shuttingDown && this.hubUpdates === owner && stillAllowed();
|
|
34419
|
+
return await owner.updateNow(id, current) ? { ok: true } : { ok: false, status: 409, error: "update_not_started" };
|
|
34420
|
+
},
|
|
34421
|
+
cancelHub: id => { this.hubUpdates?.cancelWaiting(id); },
|
|
34422
|
+
// M-3770 (#4480 §4.1): the card refuses (412) what the machine's last pre-flight doesn't allow — a press needs
|
|
34423
|
+
// pressHere, a picked time (a schedule) needs self. No result yet: nothing is refused here; the launch decides.
|
|
34424
|
+
preflight: action => {
|
|
34425
|
+
const p = this.updatePreflight;
|
|
34426
|
+
if (!p || (action !== "when-idle" && action !== "now" && action !== "pick-time"))
|
|
34427
|
+
return null;
|
|
34428
|
+
return preflightAllows(p, action === "pick-time" ? "unattended" : "press") ? null : { preflight: p };
|
|
34429
|
+
},
|
|
34430
|
+
launchIdle: (version, control, id) => this.launchClaimedUpdate({
|
|
34431
|
+
id, version, origin: `idle update ${version}`, messageId: idleUpdateMessageId(id), control, hub: false,
|
|
34432
|
+
// M-3770 (#4480 §4.1): "Update when idle" is an admin's press that waits for idle; a picked time is a schedule,
|
|
34433
|
+
// which an admin-only machine never takes.
|
|
34434
|
+
kind: this.updateCard?.view()?.lastAnswer?.action === "when-idle" ? "press" : "unattended",
|
|
34435
|
+
onExit: () => { this.updateCard?.settleLocal(id, this.claimedIdleOutcome(id, version).state); },
|
|
34436
|
+
}),
|
|
34437
|
+
currentVersion: () => { try {
|
|
34438
|
+
return this.runningAgendVersion();
|
|
34439
|
+
}
|
|
34440
|
+
catch {
|
|
34441
|
+
return null;
|
|
34442
|
+
} },
|
|
34443
|
+
bootMarker: () => this.localIdleBootProgress,
|
|
34444
|
+
});
|
|
34445
|
+
return this.updateCard;
|
|
34446
|
+
}
|
|
34447
|
+
/** Display names of agents still working. Pause is not an agent. */
|
|
34448
|
+
updateBusyNames() {
|
|
34449
|
+
const out = [];
|
|
34450
|
+
for (const name of Object.keys(this.fleetConfig?.instances ?? {})) {
|
|
34451
|
+
try {
|
|
34452
|
+
if (this.restartsInFlight.has(name) || this.stopsInFlight.has(name) || this.handOffsInFlight.has(name)
|
|
34453
|
+
|| this.ipcConnectInFlight.has(name) || this.ipcReconnectInFlight.has(name) || this.hasPendingIdleGatedDelivery(name)
|
|
34454
|
+
|| this.webChannelEchoTails.has(name)) {
|
|
34455
|
+
out.push(this.shownInstanceName(name));
|
|
34456
|
+
continue;
|
|
34457
|
+
}
|
|
34458
|
+
const process = this.getInstanceStatus(name);
|
|
34459
|
+
if (process === "stopped" || process === "crashed")
|
|
34460
|
+
continue;
|
|
34461
|
+
if (process === "paused" && ["stopped", "crashed"].includes(this.daemons.get(name)?.getProcessStatus?.() ?? "unknown"))
|
|
34462
|
+
continue;
|
|
34463
|
+
if (process !== "running" || this.getInstanceExecutionState(name) !== "idle" || this.getInstanceInteraction(name)?.phase === "waiting") {
|
|
34464
|
+
out.push(this.shownInstanceName(name));
|
|
34465
|
+
}
|
|
34466
|
+
}
|
|
34467
|
+
catch { /* one agent that cannot be read is not named */ }
|
|
34468
|
+
}
|
|
34469
|
+
return out;
|
|
34470
|
+
}
|
|
34471
|
+
refreshUpdateCard() {
|
|
34472
|
+
try {
|
|
34473
|
+
const card = this.ensureUpdateCard();
|
|
34474
|
+
const marker = readUpdateProgress(this.dataDir);
|
|
34475
|
+
if (marker) {
|
|
34476
|
+
const progress = marker.progress;
|
|
34477
|
+
card.noteMarker({
|
|
34478
|
+
startedAt: marker.startedAt,
|
|
34479
|
+
stage: progress.stage,
|
|
34480
|
+
operation: progress.operation,
|
|
34481
|
+
...(progress.version ? { version: progress.version } : {}),
|
|
34482
|
+
...(progress.stage === "failed" ? { cause: failureCause(progress.error) } : {}),
|
|
34483
|
+
});
|
|
34484
|
+
}
|
|
34485
|
+
card.tick();
|
|
34486
|
+
void this.syncUpdateChatCard(); // M-3770 1.5: an answer from the web edits the chat card too
|
|
34487
|
+
return card.view();
|
|
34488
|
+
}
|
|
34489
|
+
catch (err) {
|
|
34490
|
+
this.logger.warn({ err }, "Update card could not be read");
|
|
34491
|
+
return null;
|
|
34492
|
+
}
|
|
34493
|
+
}
|
|
34494
|
+
/** The card, for a test or a chat reply. Null when nothing is offered, including a pin. */
|
|
34495
|
+
updateOfferView() {
|
|
34496
|
+
try {
|
|
34497
|
+
return this.ensureUpdateCard().view();
|
|
34498
|
+
}
|
|
34499
|
+
catch {
|
|
34500
|
+
return null;
|
|
34501
|
+
}
|
|
34502
|
+
}
|
|
34503
|
+
describeUpdateOffer() {
|
|
34504
|
+
let current = null;
|
|
34505
|
+
try {
|
|
34506
|
+
current = this.runningAgendVersion();
|
|
34507
|
+
}
|
|
34508
|
+
catch { /* unknown */ }
|
|
34509
|
+
const pinned = !!resolveUpdates(this.fleetConfig?.updates).pin;
|
|
34510
|
+
const reply = updateOfferReply(this.updateOfferView(), current, pinned);
|
|
34511
|
+
return t(reply.key, ...reply.args);
|
|
34512
|
+
}
|
|
34513
|
+
refuseImmediateUpdate() {
|
|
34514
|
+
return resolveUpdates(this.fleetConfig?.updates).pin ? t("update.offer.pinned") : null;
|
|
34515
|
+
}
|
|
34516
|
+
beginUpdateRun() {
|
|
34517
|
+
try {
|
|
34518
|
+
this.ensureUpdateCard().beginRun(this.updateCheckState?.offer?.version ?? "");
|
|
34519
|
+
}
|
|
34520
|
+
catch (err) {
|
|
34521
|
+
this.logger.warn({ err }, "Update card could not record the run");
|
|
34522
|
+
}
|
|
34523
|
+
}
|
|
34524
|
+
/** M-2738: record a look's answer for the web — the same offer the card keeps. */
|
|
33365
34525
|
recordUpdateCheck(currentVersion, found) {
|
|
33366
34526
|
const offer = found ? updateOffer(currentVersion, found.target, found.fromChannel, !!found.target && this.semverGt(found.target, currentVersion)) : null;
|
|
33367
34527
|
this.updateCheckState = { offer, checkedAt: Date.now(), failed: found === null };
|
|
34528
|
+
try {
|
|
34529
|
+
const card = this.ensureUpdateCard();
|
|
34530
|
+
if (offer) {
|
|
34531
|
+
const channel = offer.channel === "latest" ? "stable" : offer.channel;
|
|
34532
|
+
card.noteOffer({ version: offer.version, channel, installable: offer.installable });
|
|
34533
|
+
}
|
|
34534
|
+
else if (found)
|
|
34535
|
+
card.clearQuietOffer();
|
|
34536
|
+
}
|
|
34537
|
+
catch (err) {
|
|
34538
|
+
this.logger.warn({ err }, "Update offer could not be recorded");
|
|
34539
|
+
}
|
|
34540
|
+
void this.syncUpdateChatCard(); // M-3770 1.5
|
|
33368
34541
|
}
|
|
33369
34542
|
async checkForUpdates() {
|
|
33370
34543
|
let currentVersion;
|
|
@@ -33377,19 +34550,19 @@ export class FleetManager {
|
|
|
33377
34550
|
try {
|
|
33378
34551
|
const { target, fromChannel } = await this.lookUpUpdateTarget(currentVersion);
|
|
33379
34552
|
this.recordUpdateCheck(currentVersion, { target, fromChannel });
|
|
34553
|
+
void this.refreshUpdatePreflight(); // M-3770: the page's "Updates on this machine" line
|
|
33380
34554
|
// Only notify when target is genuinely newer (semver), so a beta user on
|
|
33381
34555
|
// 2.0.8-beta.16 is never told that stable 2.0.7 is "available".
|
|
33382
34556
|
if (target && this.semverGt(target, currentVersion)) {
|
|
33383
34557
|
// #2910 D2 (#2925 review): a web-only fleet first — even with a General instance it has no chat for /update.
|
|
33384
34558
|
const generalId = this.webOnlyPromptPlace() ? null : this.findGeneralInstance();
|
|
33385
34559
|
if (generalId) {
|
|
33386
|
-
//
|
|
33387
|
-
//
|
|
33388
|
-
//
|
|
33389
|
-
|
|
33390
|
-
const key = fromChannel ? "update.available_current" : updateNoticeKey(currentVersion, target);
|
|
34560
|
+
// M-3770 1.5: an offer this install can take is General's update card (syncUpdateChatCard, from
|
|
34561
|
+
// recordUpdateCheck above) — posted once, edited in place — never the daily "Run: /update" post any more.
|
|
34562
|
+
// What stays is the line about a stable an alpha install can't take here (no card: nothing to press).
|
|
34563
|
+
const key = fromChannel ? null : updateNoticeKey(currentVersion, target);
|
|
33391
34564
|
// #2775: null = a beta install and a stable target; beta users are never told to switch.
|
|
33392
|
-
if (key)
|
|
34565
|
+
if (key && key !== "update.available_current")
|
|
33393
34566
|
this.notifyInstanceTopic(generalId, t(key, `v${target}`, `v${currentVersion}`));
|
|
33394
34567
|
}
|
|
33395
34568
|
else if (this.webOnlyPromptPlace() && (fromChannel || updateNoticeKey(currentVersion, target))) {
|
|
@@ -33416,13 +34589,15 @@ export class FleetManager {
|
|
|
33416
34589
|
}
|
|
33417
34590
|
catch { /* unknown: the page compares nothing */ }
|
|
33418
34591
|
const s = this.updateCheckState;
|
|
33419
|
-
return { current, offer: s?.offer ?? null, hubRecommendation: this.hubRecommendedUpdate(), checkedAt: s?.checkedAt ?? null, checkFailed: s?.failed ?? false };
|
|
34592
|
+
return { current, offer: s?.offer ?? null, hubRecommendation: this.hubRecommendedUpdate(), checkedAt: s?.checkedAt ?? null, checkFailed: s?.failed ?? false, preflight: this.updatePreflight };
|
|
33420
34593
|
},
|
|
33421
34594
|
checkUpdateNow: () => this.checkUpdateNow(),
|
|
33422
34595
|
updateProgress: () => webProgressOf(readUpdateProgress(this.dataDir)),
|
|
33423
34596
|
startWebUpdate: (key, person, stillAllowed, pin) => this.startWebUpdateOnce(key, person, stillAllowed, pin),
|
|
33424
34597
|
startHubRequestedUpdate: (key, person, stillAllowed, id) => this.startHubRequestedUpdateOnce(key, person, stillAllowed, id),
|
|
33425
34598
|
updateLog: () => ({ text: readLogTail(updateLogPath(this.dataDir)), error: readUpdateProgress(this.dataDir)?.progress.error ?? null }),
|
|
34599
|
+
card: () => this.refreshUpdateCard(),
|
|
34600
|
+
answerUpdate: (key, by, body, stillAllowed) => this.ensureUpdateCard().answer(key, by, body, stillAllowed),
|
|
33426
34601
|
};
|
|
33427
34602
|
}
|
|
33428
34603
|
/** "Check for updates": look now, no chat notice. One a minute; a second ask while one runs waits for it. */
|
|
@@ -33449,6 +34624,7 @@ export class FleetManager {
|
|
|
33449
34624
|
catch {
|
|
33450
34625
|
this.recordUpdateCheck(currentVersion, null);
|
|
33451
34626
|
}
|
|
34627
|
+
await this.refreshUpdatePreflight(); // M-3770: answered with the page's next view
|
|
33452
34628
|
})();
|
|
33453
34629
|
try {
|
|
33454
34630
|
await c.running;
|
|
@@ -33464,6 +34640,8 @@ export class FleetManager {
|
|
|
33464
34640
|
* targets no chat message (WEB_UPDATE_ADAPTER); the page reads the stages the updater writes into it.
|
|
33465
34641
|
*/
|
|
33466
34642
|
async startWebUpdate(person, stillAllowed, pin, hubRequestId) {
|
|
34643
|
+
if (resolveUpdates(this.fleetConfig?.updates).pin)
|
|
34644
|
+
return { ok: false, status: 409, error: "pinned" };
|
|
33467
34645
|
if (this.shuttingDown)
|
|
33468
34646
|
return { ok: false, status: 409, error: "stopping" };
|
|
33469
34647
|
// Synchronous from here to the claim: a second start cannot slip in between on the event loop.
|
|
@@ -33502,6 +34680,12 @@ export class FleetManager {
|
|
|
33502
34680
|
this.logger.error("Web update refused: its progress marker could not be written");
|
|
33503
34681
|
return { ok: false, status: 503, error: "progress_not_recorded" };
|
|
33504
34682
|
}
|
|
34683
|
+
try {
|
|
34684
|
+
this.ensureUpdateCard().beginRun(offer.version);
|
|
34685
|
+
}
|
|
34686
|
+
catch (err) {
|
|
34687
|
+
this.logger.warn({ err }, "Update card could not record the run");
|
|
34688
|
+
}
|
|
33505
34689
|
const origin = `web update by ${person}`;
|
|
33506
34690
|
// Prism #3505 P2-3: the asking session must still be current and an admin's when the updater is launched.
|
|
33507
34691
|
void this.launchInstalledUpdate(origin, () => !this.shuttingDown && stillAllowed() && (!pin || this.hubRecommendationFor(pin) !== null)
|
|
@@ -34350,7 +35534,12 @@ export class FleetManager {
|
|
|
34350
35534
|
}
|
|
34351
35535
|
const listener = createPreviewListener({ settings, healthPort: boundPort, config: this.fleetConfig,
|
|
34352
35536
|
// #1723: with a web.preview_origin, the open public link's dashboard frames this listener's preview too.
|
|
34353
|
-
extraOrigins: () => {
|
|
35537
|
+
extraOrigins: () => {
|
|
35538
|
+
const o = settings.origin || this.publicWebLink?.fixedPreviewHost?.() ? this.publicWebLink?.openDashboardOrigin() : null;
|
|
35539
|
+
return o ? [o] : [];
|
|
35540
|
+
},
|
|
35541
|
+
// M-3814: the fixed link's preview address (a second route on its named tunnel to this port), only while it is open.
|
|
35542
|
+
extraHosts: () => { const h = this.publicWebLink?.fixedPreviewHost?.(); return h ? [h] : []; },
|
|
34354
35543
|
// #2911 (7): CDN libraries in previews, as fleet.yaml says now (a change applies to the next preview started).
|
|
34355
35544
|
cdn: () => this.fleetConfig?.web?.preview_cdn === true });
|
|
34356
35545
|
this.previewListener = listener;
|
|
@@ -34434,6 +35623,18 @@ export class FleetManager {
|
|
|
34434
35623
|
return off("needHttps", "Previews need an https web.preview_origin when the dashboard is reached over https.");
|
|
34435
35624
|
return { dashboardOrigin, previewOrigin: configured, reason: null, code: null, boot: listener.bootId, frameSrc: `${configured}/frame` };
|
|
34436
35625
|
}
|
|
35626
|
+
// M-3814: a fixed link with a fixed preview address frames this listener through its own named tunnel — never a
|
|
35627
|
+
// quick tunnel (no 429 from Cloudflare's limit on new temporary links).
|
|
35628
|
+
const fixedHost = this.publicWebLink?.fixedPreviewHost?.(exposureId) ?? null;
|
|
35629
|
+
if (fixedHost) {
|
|
35630
|
+
const listener = this.previewListening ? this.previewListener : null;
|
|
35631
|
+
if (!listener) {
|
|
35632
|
+
const why = this.previewNotListening();
|
|
35633
|
+
return off(why.code, why.reason, why.detail ? { detail: why.detail } : {});
|
|
35634
|
+
}
|
|
35635
|
+
const origin = `https://${fixedHost}`;
|
|
35636
|
+
return { dashboardOrigin, previewOrigin: origin, reason: null, code: null, boot: listener.bootId, frameSrc: `${origin}/frame` };
|
|
35637
|
+
}
|
|
34437
35638
|
const status = this.publicWebLink?.previewStatus(exposureId) ?? null;
|
|
34438
35639
|
if (!status)
|
|
34439
35640
|
return off("publicLink", "Previews are not offered on this public link.");
|