wezard 2.9.0 → 3.0.2
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/CLAUDE.md +43 -21
- package/README.md +37 -50
- package/cli/wezard.sh +59 -20
- package/config.example.jsonc +5 -8
- package/dist/cli/audit.js +11 -13
- package/dist/cli/audit.js.map +1 -1
- package/dist/cli/codex-hook.js +20 -17
- package/dist/cli/codex-hook.js.map +1 -1
- package/dist/cli/ext.js +271 -0
- package/dist/cli/ext.js.map +1 -0
- package/dist/cli/init.js +44 -13
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/skills.js +113 -0
- package/dist/cli/skills.js.map +1 -0
- package/dist/cli/sync.js +3 -2
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/wx.js +7 -6
- package/dist/cli/wx.js.map +1 -1
- package/dist/daemon/aibot-media.js +28 -20
- package/dist/daemon/aibot-media.js.map +1 -1
- package/dist/daemon/apprentice.js +75 -0
- package/dist/daemon/apprentice.js.map +1 -0
- package/dist/daemon/approval.js +75 -33
- package/dist/daemon/approval.js.map +1 -1
- package/dist/daemon/channel-context.js +7 -0
- package/dist/daemon/channel-context.js.map +1 -1
- package/dist/daemon/channel-onboarding.js +61 -0
- package/dist/daemon/channel-onboarding.js.map +1 -0
- package/dist/daemon/channel-posts.js +93 -0
- package/dist/daemon/channel-posts.js.map +1 -0
- package/dist/daemon/channel-rebind.js +100 -0
- package/dist/daemon/channel-rebind.js.map +1 -0
- package/dist/daemon/channel-store.js.map +1 -1
- package/dist/daemon/channel.js +273 -409
- package/dist/daemon/channel.js.map +1 -1
- package/dist/daemon/chat-name.js +24 -161
- package/dist/daemon/chat-name.js.map +1 -1
- package/dist/daemon/claim.js +1 -45
- package/dist/daemon/claim.js.map +1 -1
- package/dist/daemon/classes.js +416 -0
- package/dist/daemon/classes.js.map +1 -0
- package/dist/daemon/config-api.js +6 -30
- package/dist/daemon/config-api.js.map +1 -1
- package/dist/daemon/control-socket.js +93 -0
- package/dist/daemon/control-socket.js.map +1 -0
- package/dist/daemon/danger-scrub.js +315 -0
- package/dist/daemon/danger-scrub.js.map +1 -0
- package/dist/daemon/danger.js +146 -16
- package/dist/daemon/danger.js.map +1 -1
- package/dist/daemon/detail.js +50 -22
- package/dist/daemon/detail.js.map +1 -1
- package/dist/daemon/exec-surface.js +108 -0
- package/dist/daemon/exec-surface.js.map +1 -0
- package/dist/daemon/external.js +595 -0
- package/dist/daemon/external.js.map +1 -0
- package/dist/daemon/handoff.js +51 -50
- package/dist/daemon/handoff.js.map +1 -1
- package/dist/daemon/http.js +119 -31
- package/dist/daemon/http.js.map +1 -1
- package/dist/daemon/idle-reap.js +30 -0
- package/dist/daemon/idle-reap.js.map +1 -0
- package/dist/daemon/inbound.js +436 -207
- package/dist/daemon/inbound.js.map +1 -1
- package/dist/daemon/index.js +3353 -2760
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/last-response.js +51 -25
- package/dist/daemon/last-response.js.map +1 -1
- package/dist/daemon/legacy-panes.js +67 -0
- package/dist/daemon/legacy-panes.js.map +1 -0
- package/dist/daemon/mcp-http.js.map +1 -1
- package/dist/daemon/me-room.js +137 -0
- package/dist/daemon/me-room.js.map +1 -0
- package/dist/daemon/media.js +14 -0
- package/dist/daemon/media.js.map +1 -1
- package/dist/daemon/memory-steward.js +1 -1
- package/dist/daemon/memory-steward.js.map +1 -1
- package/dist/daemon/message-format.js +15 -2
- package/dist/daemon/message-format.js.map +1 -1
- package/dist/daemon/mirror-bridge.js +583 -488
- package/dist/daemon/mirror-bridge.js.map +1 -1
- package/dist/daemon/mirror-store.js +24 -0
- package/dist/daemon/mirror-store.js.map +1 -1
- package/dist/daemon/notices.js +5 -6
- package/dist/daemon/notices.js.map +1 -1
- package/dist/daemon/onboarding.js +459 -0
- package/dist/daemon/onboarding.js.map +1 -0
- package/dist/daemon/outbound.js +21 -11
- package/dist/daemon/outbound.js.map +1 -1
- package/dist/daemon/peers.js +39 -231
- package/dist/daemon/peers.js.map +1 -1
- package/dist/daemon/plan-http.js +2 -3
- package/dist/daemon/plan-http.js.map +1 -1
- package/dist/daemon/plans.js.map +1 -1
- package/dist/daemon/reach.js +1 -5
- package/dist/daemon/reach.js.map +1 -1
- package/dist/daemon/room-auto-adhoc.js +18 -0
- package/dist/daemon/room-auto-adhoc.js.map +1 -0
- package/dist/daemon/room-bind.js +297 -0
- package/dist/daemon/room-bind.js.map +1 -0
- package/dist/daemon/room-facts.js +35 -0
- package/dist/daemon/room-facts.js.map +1 -0
- package/dist/daemon/room-hub.js +569 -0
- package/dist/daemon/room-hub.js.map +1 -0
- package/dist/daemon/room-overdue.js +160 -0
- package/dist/daemon/room-overdue.js.map +1 -0
- package/dist/daemon/room-prune.js +74 -0
- package/dist/daemon/room-prune.js.map +1 -0
- package/dist/daemon/room-spawn.js +20 -0
- package/dist/daemon/room-spawn.js.map +1 -0
- package/dist/daemon/room-watchdog.js +175 -0
- package/dist/daemon/room-watchdog.js.map +1 -0
- package/dist/daemon/rooms.js +204 -0
- package/dist/daemon/rooms.js.map +1 -0
- package/dist/daemon/route.js +7 -18
- package/dist/daemon/route.js.map +1 -1
- package/dist/daemon/session-scan.js +1 -1
- package/dist/daemon/session-scan.js.map +1 -1
- package/dist/daemon/short-id-log.js +43 -0
- package/dist/daemon/short-id-log.js.map +1 -0
- package/dist/daemon/spawn-tmux.js +60 -45
- package/dist/daemon/spawn-tmux.js.map +1 -1
- package/dist/daemon/steward-guard.js +3 -3
- package/dist/daemon/steward-guard.js.map +1 -1
- package/dist/daemon/steward-model.js +17 -3
- package/dist/daemon/steward-model.js.map +1 -1
- package/dist/daemon/steward-repair.js +171 -0
- package/dist/daemon/steward-repair.js.map +1 -0
- package/dist/daemon/steward.js +171 -0
- package/dist/daemon/steward.js.map +1 -0
- package/dist/daemon/tasks.js +4 -14
- package/dist/daemon/tasks.js.map +1 -1
- package/dist/daemon/tool-face.js +31 -0
- package/dist/daemon/tool-face.js.map +1 -0
- package/dist/daemon/turn-opening.js +30 -0
- package/dist/daemon/turn-opening.js.map +1 -0
- package/dist/daemon/wake-tail.js +55 -0
- package/dist/daemon/wake-tail.js.map +1 -0
- package/dist/daemon/weixin-cmd.js +10 -14
- package/dist/daemon/weixin-cmd.js.map +1 -1
- package/dist/daemon/wezard-session.js +6 -2
- package/dist/daemon/wezard-session.js.map +1 -1
- package/dist/daemon/wizard-memory.js +4 -10
- package/dist/daemon/wizard-memory.js.map +1 -1
- package/dist/daemon/wizard-names.js +0 -22
- package/dist/daemon/wizard-names.js.map +1 -1
- package/dist/daemon/wizard.js +683 -159
- package/dist/daemon/wizard.js.map +1 -1
- package/dist/daemon/ws.js +1 -1
- package/dist/daemon/ws.js.map +1 -1
- package/dist/mcp/output.js +30 -7
- package/dist/mcp/output.js.map +1 -1
- package/dist/mcp/relay.js +152 -0
- package/dist/mcp/relay.js.map +1 -0
- package/dist/mcp/tools.js +318 -265
- package/dist/mcp/tools.js.map +1 -1
- package/dist/shared/allow-rules.js +1 -7
- package/dist/shared/allow-rules.js.map +1 -1
- package/dist/shared/charter-rearm.js +179 -0
- package/dist/shared/charter-rearm.js.map +1 -0
- package/dist/shared/chat-http.js +412 -480
- package/dist/shared/chat-http.js.map +1 -1
- package/dist/shared/chat-record.js +55 -0
- package/dist/shared/chat-record.js.map +1 -0
- package/dist/shared/chat-render.js +7 -4
- package/dist/shared/chat-render.js.map +1 -1
- package/dist/shared/chat-view.js +2 -41
- package/dist/shared/chat-view.js.map +1 -1
- package/dist/shared/cli-backends.js +13 -5
- package/dist/shared/cli-backends.js.map +1 -1
- package/dist/shared/cli-local-status.js +28 -0
- package/dist/shared/cli-local-status.js.map +1 -0
- package/dist/shared/cli-socket.js +14 -0
- package/dist/shared/cli-socket.js.map +1 -0
- package/dist/shared/codex-hooks.js +5 -2
- package/dist/shared/codex-hooks.js.map +1 -1
- package/dist/shared/config.js +90 -66
- package/dist/shared/config.js.map +1 -1
- package/dist/shared/daemon-addr.js +23 -0
- package/dist/shared/daemon-addr.js.map +1 -0
- package/dist/shared/daemon-client.js +41 -0
- package/dist/shared/daemon-client.js.map +1 -0
- package/dist/shared/daemon-token.js +2 -2
- package/dist/shared/daemon-token.js.map +1 -1
- package/dist/shared/detail-render.js +98 -21
- package/dist/shared/detail-render.js.map +1 -1
- package/dist/shared/detail-store.js.map +1 -1
- package/dist/shared/external.js +402 -0
- package/dist/shared/external.js.map +1 -0
- package/dist/shared/group-members.js +35 -0
- package/dist/shared/group-members.js.map +1 -0
- package/dist/shared/inject-view.js +143 -0
- package/dist/shared/inject-view.js.map +1 -0
- package/dist/shared/instance-id.js +21 -0
- package/dist/shared/instance-id.js.map +1 -0
- package/dist/shared/legacy-routes.js +199 -0
- package/dist/shared/legacy-routes.js.map +1 -0
- package/dist/shared/mem-guard.js +32 -0
- package/dist/shared/mem-guard.js.map +1 -0
- package/dist/shared/message-footer.js +11 -3
- package/dist/shared/message-footer.js.map +1 -1
- package/dist/shared/model-tiers.js +39 -1
- package/dist/shared/model-tiers.js.map +1 -1
- package/dist/shared/ports.js +56 -0
- package/dist/shared/ports.js.map +1 -0
- package/dist/shared/reminder.js +30 -38
- package/dist/shared/reminder.js.map +1 -1
- package/dist/shared/role-render.js +210 -210
- package/dist/shared/role-render.js.map +1 -1
- package/dist/shared/role-view.js +65 -300
- package/dist/shared/role-view.js.map +1 -1
- package/dist/shared/room-label.js +13 -0
- package/dist/shared/room-label.js.map +1 -0
- package/dist/shared/room-migrate.js +404 -0
- package/dist/shared/room-migrate.js.map +1 -0
- package/dist/shared/room-overdue.js +153 -0
- package/dist/shared/room-overdue.js.map +1 -0
- package/dist/shared/room-search.js +102 -0
- package/dist/shared/room-search.js.map +1 -0
- package/dist/shared/room-view.js +275 -0
- package/dist/shared/room-view.js.map +1 -0
- package/dist/shared/room.js +827 -0
- package/dist/shared/room.js.map +1 -0
- package/dist/shared/session-hooks.js +20 -8
- package/dist/shared/session-hooks.js.map +1 -1
- package/dist/shared/session-label.js +82 -84
- package/dist/shared/session-label.js.map +1 -1
- package/dist/shared/session-mcp.js +36 -40
- package/dist/shared/session-mcp.js.map +1 -1
- package/dist/shared/session-skills.js +8 -0
- package/dist/shared/session-skills.js.map +1 -1
- package/dist/shared/skill-sync.js +229 -0
- package/dist/shared/skill-sync.js.map +1 -0
- package/dist/shared/smarts.js +24 -0
- package/dist/shared/smarts.js.map +1 -0
- package/dist/shared/stream-page.js +22 -0
- package/dist/shared/stream-page.js.map +1 -0
- package/dist/shared/task-file.js +0 -5
- package/dist/shared/task-file.js.map +1 -1
- package/dist/shared/task-template.js +1 -1
- package/dist/shared/task-template.js.map +1 -1
- package/dist/shared/tool-hints.js +20 -11
- package/dist/shared/tool-hints.js.map +1 -1
- package/dist/shared/workspace-trust.js +8 -0
- package/dist/shared/workspace-trust.js.map +1 -1
- package/dist/shared/world.js +101 -166
- package/dist/shared/world.js.map +1 -1
- package/dist/svr/facts-store.js +26 -0
- package/dist/svr/facts-store.js.map +1 -0
- package/dist/svr/index.js +114 -16
- package/dist/svr/index.js.map +1 -1
- package/hooks/pre-tool-use.sh +14 -10
- package/hooks/stop.sh +28 -0
- package/launchd/com.wezard.svr.plist.template +2 -0
- package/package.json +9 -2
- package/scripts/install.sh +23 -0
- package/skills/LICENSE.wecom-unified.txt +21 -0
- package/skills/wecom-unified/SKILL.md +151 -0
- package/skills/wecom-unified/assets/templates/broadside/DESIGN.preset.md +172 -0
- package/skills/wecom-unified/assets/templates/broadside/shell/content.jsx +31 -0
- package/skills/wecom-unified/assets/templates/broadside/slides/01_cover.slide +48 -0
- package/skills/wecom-unified/assets/templates/broadside/slides/02_section.slide +58 -0
- package/skills/wecom-unified/assets/templates/broadside/slides/03_cards.slide +53 -0
- package/skills/wecom-unified/assets/templates/broadside/slides/04_image.slide +64 -0
- package/skills/wecom-unified/assets/templates/cartesian/DESIGN.preset.md +139 -0
- package/skills/wecom-unified/assets/templates/cartesian/shell/content.jsx +28 -0
- package/skills/wecom-unified/assets/templates/cartesian/slides/01_cover.slide +44 -0
- package/skills/wecom-unified/assets/templates/cartesian/slides/02_compare.slide +79 -0
- package/skills/wecom-unified/assets/templates/cartesian/slides/03_table.slide +79 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/DESIGN.preset.md +118 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/shell/content.jsx +24 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/slides/01_cover.slide +61 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/slides/02_structure.slide +85 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/slides/03_data.slide +60 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/DESIGN.preset.md +135 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/shell/content.jsx +19 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/slides/01_cover.slide +29 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/slides/02_cards.slide +60 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/slides/03_data.slide +49 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/slides/04_image.slide +46 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/DESIGN.preset.md +119 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/shell/content.jsx +18 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/slides/01_cover.slide +36 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/slides/02_section.slide +39 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/slides/03_data.slide +79 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/slides/04_steps.slide +53 -0
- package/skills/wecom-unified/assets/templates/grove/DESIGN.preset.md +159 -0
- package/skills/wecom-unified/assets/templates/grove/shell/content.jsx +18 -0
- package/skills/wecom-unified/assets/templates/grove/shell/content_light.jsx +18 -0
- package/skills/wecom-unified/assets/templates/grove/slides/01_cover.slide +26 -0
- package/skills/wecom-unified/assets/templates/grove/slides/02_compare.slide +92 -0
- package/skills/wecom-unified/assets/templates/grove/slides/03_table.slide +68 -0
- package/skills/wecom-unified/assets/templates/index.json +280 -0
- package/skills/wecom-unified/assets/templates/long-table/DESIGN.preset.md +135 -0
- package/skills/wecom-unified/assets/templates/long-table/shell/content.jsx +36 -0
- package/skills/wecom-unified/assets/templates/long-table/slides/01_cover.slide +71 -0
- package/skills/wecom-unified/assets/templates/long-table/slides/02_cards.slide +72 -0
- package/skills/wecom-unified/assets/templates/long-table/slides/03_timeline.slide +81 -0
- package/skills/wecom-unified/assets/templates/long-table/slides/04_image.slide +60 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/DESIGN.preset.md +121 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/shell/content.jsx +13 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/slides/01_cover.slide +54 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/slides/02_products.slide +134 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/slides/03_section.slide +30 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/slides/04_schedule.slide +65 -0
- package/skills/wecom-unified/assets/templates/signal/DESIGN.preset.md +121 -0
- package/skills/wecom-unified/assets/templates/signal/shell/content.jsx +18 -0
- package/skills/wecom-unified/assets/templates/signal/shell/content_dark.jsx +23 -0
- package/skills/wecom-unified/assets/templates/signal/slides/01_cover.slide +48 -0
- package/skills/wecom-unified/assets/templates/signal/slides/02_cards.slide +67 -0
- package/skills/wecom-unified/assets/templates/signal/slides/03_data.slide +68 -0
- package/skills/wecom-unified/references/wecomcli-calendar-agenda.md +227 -0
- package/skills/wecom-unified/references/wecomcli-calendar-cancel.md +108 -0
- package/skills/wecom-unified/references/wecomcli-calendar-create.md +238 -0
- package/skills/wecom-unified/references/wecomcli-calendar-freebusy.md +207 -0
- package/skills/wecom-unified/references/wecomcli-calendar-meeting-room.md +170 -0
- package/skills/wecom-unified/references/wecomcli-calendar-search.md +209 -0
- package/skills/wecom-unified/references/wecomcli-calendar-update.md +272 -0
- package/skills/wecom-unified/references/wecomcli-calendar.md +296 -0
- package/skills/wecom-unified/references/wecomcli-contact.md +48 -0
- package/skills/wecom-unified/references/wecomcli-disk.md +380 -0
- package/skills/wecom-unified/references/wecomcli-doc-contents-append.md +20 -0
- package/skills/wecom-unified/references/wecomcli-doc-contents-overwrite.md +27 -0
- package/skills/wecom-unified/references/wecomcli-doc-create.md +162 -0
- package/skills/wecom-unified/references/wecomcli-doc-manage-doc-members-update.md +24 -0
- package/skills/wecom-unified/references/wecomcli-doc-manage-doc-names-update.md +20 -0
- package/skills/wecom-unified/references/wecomcli-doc-manage-doc-rules-update.md +22 -0
- package/skills/wecom-unified/references/wecomcli-doc-manage.md +127 -0
- package/skills/wecom-unified/references/wecomcli-doc.md +135 -0
- package/skills/wecom-unified/references/wecomcli-email-forward-mail.md +131 -0
- package/skills/wecom-unified/references/wecomcli-email-get-mail.md +187 -0
- package/skills/wecom-unified/references/wecomcli-email-reply-mail.md +138 -0
- package/skills/wecom-unified/references/wecomcli-email-search-mail.md +114 -0
- package/skills/wecom-unified/references/wecomcli-email-security.md +52 -0
- package/skills/wecom-unified/references/wecomcli-email-send-mail.md +186 -0
- package/skills/wecom-unified/references/wecomcli-email-send-schedule.md +83 -0
- package/skills/wecom-unified/references/wecomcli-email.md +206 -0
- package/skills/wecom-unified/references/wecomcli-media.md +89 -0
- package/skills/wecom-unified/references/wecomcli-meeting-cancel.md +113 -0
- package/skills/wecom-unified/references/wecomcli-meeting-create.md +167 -0
- package/skills/wecom-unified/references/wecomcli-meeting-list.md +228 -0
- package/skills/wecom-unified/references/wecomcli-meeting-original-get.md +101 -0
- package/skills/wecom-unified/references/wecomcli-meeting-search.md +176 -0
- package/skills/wecom-unified/references/wecomcli-meeting-update.md +217 -0
- package/skills/wecom-unified/references/wecomcli-meeting.md +366 -0
- package/skills/wecom-unified/references/wecomcli-message.md +190 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-animation.md +62 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-box.md +102 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-chart.md +261 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-codeblock.md +70 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-diagram.md +54 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-faicon.md +71 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-hyperlink.md +55 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-image.md +107 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-math.md +65 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-qrcode.md +22 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-slide.md +74 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-svg.md +95 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-table.md +72 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-text.md +96 -0
- package/skills/wecom-unified/references/wecomcli-pptx-content-contract.md +73 -0
- package/skills/wecom-unified/references/wecomcli-pptx-create-from-material.md +67 -0
- package/skills/wecom-unified/references/wecomcli-pptx-create-from-scratch.md +178 -0
- package/skills/wecom-unified/references/wecomcli-pptx-create-from-template.md +123 -0
- package/skills/wecom-unified/references/wecomcli-pptx-design-principle.md +65 -0
- package/skills/wecom-unified/references/wecomcli-pptx-government-contract.md +40 -0
- package/skills/wecom-unified/references/wecomcli-pptx-human-alignment.md +140 -0
- package/skills/wecom-unified/references/wecomcli-pptx-pptx-api.md +161 -0
- package/skills/wecom-unified/references/wecomcli-pptx-pptx-edit.md +37 -0
- package/skills/wecom-unified/references/wecomcli-pptx-story-principle.md +184 -0
- package/skills/wecom-unified/references/wecomcli-pptx-templates-README.md +165 -0
- package/skills/wecom-unified/references/wecomcli-pptx-templates-anti-ai-slop.md +52 -0
- package/skills/wecom-unified/references/wecomcli-pptx.md +158 -0
- package/skills/wecom-unified/references/wecomcli-sheet-conditional-formatting.md +203 -0
- package/skills/wecom-unified/references/wecomcli-sheet-filter.md +179 -0
- package/skills/wecom-unified/references/wecomcli-sheet-float-image.md +235 -0
- package/skills/wecom-unified/references/wecomcli-sheet-formulas.md +71 -0
- package/skills/wecom-unified/references/wecomcli-sheet-history.md +118 -0
- package/skills/wecom-unified/references/wecomcli-sheet-protection.md +170 -0
- package/skills/wecom-unified/references/wecomcli-sheet-range-operations.md +306 -0
- package/skills/wecom-unified/references/wecomcli-sheet-read-data.md +151 -0
- package/skills/wecom-unified/references/wecomcli-sheet-search-replace.md +121 -0
- package/skills/wecom-unified/references/wecomcli-sheet-structure-operations.md +394 -0
- package/skills/wecom-unified/references/wecomcli-sheet-style.md +246 -0
- package/skills/wecom-unified/references/wecomcli-sheet-table-style.md +199 -0
- package/skills/wecom-unified/references/wecomcli-sheet-validation.md +217 -0
- package/skills/wecom-unified/references/wecomcli-sheet-visual-standards.md +166 -0
- package/skills/wecom-unified/references/wecomcli-sheet-workbook.md +264 -0
- package/skills/wecom-unified/references/wecomcli-sheet-write-cells.md +320 -0
- package/skills/wecom-unified/references/wecomcli-sheet-xlsx-process.md +324 -0
- package/skills/wecom-unified/references/wecomcli-sheet.md +96 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-data-driven-pages.md +50 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-edit.md +526 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-arraylist.md +369 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-datetime.md +283 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-logic.md +247 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-math.md +362 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-operators.md +246 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-pageblock.md +76 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-reference.md +192 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-templates.md +410 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-text.md +377 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-user.md +22 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-mdx-syntax.md +739 -0
- package/skills/wecom-unified/references/wecomcli-smartpage.md +179 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-chart-types.md +95 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-common.md +160 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-edit.md +609 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-field-types.md +438 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-formula.md +845 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-read.md +411 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-record-values.md +218 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-ai_efficiency.md +709 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-connect_to_app.md +380 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-financial_accounting.md +369 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-hr_and_administration.md +475 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-ledger_records.md +156 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-manufacturing.md +395 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-marketing.md +186 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-office_essentials.md +299 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-personal_efficiency.md +70 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-procurement_logistics.md +325 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-project_management.md +564 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_customer.md +222 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_ops.md +105 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_project.md +109 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_research.md +92 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-sales_and_operations.md +446 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-store_management.md +431 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-team_tasks.md +274 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-wechat_customer.md +384 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-work_report.md +100 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-templates.md +53 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-view-types.md +373 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-webhook-examples.md +176 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-webhook.md +186 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet.md +147 -0
- package/skills/wecom-unified/references/wecomcli-todo-create.md +137 -0
- package/skills/wecom-unified/references/wecomcli-todo-delete.md +63 -0
- package/skills/wecom-unified/references/wecomcli-todo-finish.md +72 -0
- package/skills/wecom-unified/references/wecomcli-todo-get.md +69 -0
- package/skills/wecom-unified/references/wecomcli-todo-list.md +136 -0
- package/skills/wecom-unified/references/wecomcli-todo-update.md +112 -0
- package/skills/wecom-unified/references/wecomcli-todo.md +68 -0
- package/skills/wecom-unified/scripts/build_docx.py +1274 -0
- package/skills/wecom-unified/scripts/build_page.py +2449 -0
- package/skills/wecom-unified/scripts/collect.py +868 -0
- package/skills/wecom-unified/scripts/doc_image_extractor.py +498 -0
- package/skills/wecom-unified/scripts/pptx2image.py +268 -0
- package/skills/wecom-unified/scripts/recalc.py +403 -0
- package/systemd/wezard-svr.service.template +2 -0
- package/systemd/wezard.service.template +6 -0
- package/web/chat.css +70 -273
- package/web/chat.js +2269 -2190
- package/dist/daemon/bot-mux.js +0 -161
- package/dist/daemon/bot-mux.js.map +0 -1
- package/dist/daemon/chat-log.js +0 -130
- package/dist/daemon/chat-log.js.map +0 -1
- package/dist/daemon/dispatch.js +0 -6
- package/dist/daemon/dispatch.js.map +0 -1
- package/dist/daemon/idle-nudge.js +0 -90
- package/dist/daemon/idle-nudge.js.map +0 -1
- package/dist/daemon/message-events.js +0 -1155
- package/dist/daemon/message-events.js.map +0 -1
- package/dist/daemon/pending-items.js +0 -160
- package/dist/daemon/pending-items.js.map +0 -1
- package/dist/daemon/router.js +0 -742
- package/dist/daemon/router.js.map +0 -1
- package/dist/daemon/tips.js +0 -25
- package/dist/daemon/tips.js.map +0 -1
- package/dist/daemon/wedoc.js +0 -210
- package/dist/daemon/wedoc.js.map +0 -1
- package/dist/shared/role-search.js +0 -100
- package/dist/shared/role-search.js.map +0 -1
- package/dist/shared/startup-notice.js +0 -21
- package/dist/shared/startup-notice.js.map +0 -1
- package/dist/shared/turn-state.js +0 -27
- package/dist/shared/turn-state.js.map +0 -1
|
@@ -1,1155 +0,0 @@
|
|
|
1
|
-
import { NO_DEADLINE } from "../shared/turn-state.js";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { loadJsonMap } from "../shared/json-map-store.js";
|
|
4
|
-
const TOMB_AFTER_MS = 24 * 3600_000;
|
|
5
|
-
const TOMB_TTL_MS = 7 * 24 * 3600_000;
|
|
6
|
-
const isTomb = (x) => x.tomb === true;
|
|
7
|
-
const terminal = (x) => x === "complete" || x === "canceled";
|
|
8
|
-
/** complete 要等 finalized (路由判定补完) 才算了结; canceled 本身就是了结。 */
|
|
9
|
-
const settled = (e) => e.execution === "canceled" || (e.execution === "complete" && !!e.finalized);
|
|
10
|
-
const endedAt = (e) => typeof e.endedAt === "number" && Number.isFinite(e.endedAt) ? e.endedAt : undefined;
|
|
11
|
-
const authorityOf = (e) => ({ id: e.id, target: e.target, serves: e.serves,
|
|
12
|
-
feedbackRoute: e.feedbackRoute,
|
|
13
|
-
at: e.at, execution: e.execution, canceled: e.canceled || e.execution === "canceled", interjected: e.interjected,
|
|
14
|
-
handoffCut: e.handoffCut, handoffRestored: e.handoffRestored, receiptClaim: e.receiptClaim,
|
|
15
|
-
...(e.payload.human && e.exposure === "none" ? { unexposedHuman: true } : {}) });
|
|
16
|
-
const entomb = (e, at) => ({ id: e.id, fingerprint: e.fingerprint, execution: e.execution, endedAt: at, tomb: true, authority: authorityOf(e) });
|
|
17
|
-
/** 每次落盘前跑: 了结满一天的行裁成墓碑, 墓碑满七天删掉。 */
|
|
18
|
-
export const gcEvents = (now, retain = () => false) => (rows) => Object.fromEntries(Object.entries(rows).flatMap(([id, x]) => {
|
|
19
|
-
if (isTomb(x))
|
|
20
|
-
return now - x.endedAt >= TOMB_TTL_MS ? [] : [[id, x]];
|
|
21
|
-
const at = endedAt(x);
|
|
22
|
-
if (retain(x) || !settled(x) || !terminal(x.execution) || at === undefined || now - at < TOMB_AFTER_MS)
|
|
23
|
-
return [[id, x]];
|
|
24
|
-
return [[id, entomb({ ...x, execution: x.execution }, at)]];
|
|
25
|
-
}));
|
|
26
|
-
/** 重投造出来的「续办载体」(追问续答 / 闲置追问): 它们只承载一次追问, 了结后没有对账价值 ——
|
|
27
|
-
* 留着就是每次落盘都重写几十兆 (2026-11 事故: 12058 个已了结载体常驻 ~94MB)。 */
|
|
28
|
-
export const isRecoveryCarrier = (e) => (!!e.serves && e.id.startsWith(`route:${e.serves}:resume`)) || e.id.startsWith("idle-question:");
|
|
29
|
-
/** 同一件的事件探针连续失败这么多次就收手: 退避重试只是把同一句失败原因再写一遍。 */
|
|
30
|
-
export const PROBE_LIMIT = 30;
|
|
31
|
-
const HOLD_LOG_MS = 30_000;
|
|
32
|
-
const HOLD_RELOG_MS = 5 * 60_000;
|
|
33
|
-
const canonical = (x) => Array.isArray(x) ? x.map(canonical)
|
|
34
|
-
: x && typeof x === "object" ? Object.fromEntries(Object.entries(x).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => [k, canonical(v)])) : x;
|
|
35
|
-
const digest = (x) => createHash("sha256").update(JSON.stringify(canonical(x))).digest("hex");
|
|
36
|
-
export const messageId = (bot, chat, id) => `h${digest([bot, chat, id]).slice(0, 16)}`;
|
|
37
|
-
export const finalId = (event, channel, revision) => `f${digest([event, channel, revision])}`;
|
|
38
|
-
const clone = (x) => JSON.parse(JSON.stringify(x));
|
|
39
|
-
const backoff = (n) => Date.now() + Math.min(60_000, 1000 * 2 ** Math.min(n, 6));
|
|
40
|
-
/** 一条原因最多留这么多字。整库是整文件重写的, 无限拼接会把 message-events.json 撑到百兆。 */
|
|
41
|
-
export const REASON_MAX = 1000;
|
|
42
|
-
const REASON_ADD_MAX = 500;
|
|
43
|
-
const REASON_WHY_MAX = 500;
|
|
44
|
-
const clip = (s, max) => s.length <= max ? s : `${s.slice(0, Math.max(0, max - 1))}…`;
|
|
45
|
-
/** 超长时保留开头 300 + 末尾 (max − 340): 首条原因与最新一条都还在, 中间折叠成省略标记。 */
|
|
46
|
-
const fold = (s, max) => {
|
|
47
|
-
if (s.length <= max)
|
|
48
|
-
return s;
|
|
49
|
-
const head = Math.min(300, max);
|
|
50
|
-
let omitted = s.length - max;
|
|
51
|
-
for (;;) {
|
|
52
|
-
const marker = ` …[略 ${omitted} 字]… `;
|
|
53
|
-
const tail = Math.max(0, max - head - marker.length);
|
|
54
|
-
const next = s.length - head - tail;
|
|
55
|
-
if (next === omitted)
|
|
56
|
-
return s.slice(0, head) + marker + s.slice(s.length - tail);
|
|
57
|
-
omitted = next;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
/** 追加一条投递/探测失败原因: 同一条重复折叠成 (×N), 结果封顶 REASON_MAX。 */
|
|
61
|
-
export const appendReason = (prev, add, max = REASON_MAX) => {
|
|
62
|
-
const one = clip(add, REASON_ADD_MAX);
|
|
63
|
-
if (!prev)
|
|
64
|
-
return fold(one, max);
|
|
65
|
-
const n = /\(×([0-9]+)\)$/.exec(prev);
|
|
66
|
-
const repeats = n ? Number(n[1]) : undefined;
|
|
67
|
-
const base = repeats === undefined ? prev : prev.slice(0, prev.length - ` (×${repeats})`.length);
|
|
68
|
-
const merged = base === one ? `${one} (×${(repeats ?? 1) + 1})`
|
|
69
|
-
: base.endsWith(one) ? `${base} (×2)`
|
|
70
|
-
: `${prev}; ${one}`;
|
|
71
|
-
return fold(merged, max);
|
|
72
|
-
};
|
|
73
|
-
/** 异常 → 一行原因 (封顶 500 字): 模板句被重复拼进来时, 原文本身也可能很长。 */
|
|
74
|
-
export const why = (e) => clip(e instanceof Error ? e.message : typeof e === "object" ? JSON.stringify(e) : String(e), REASON_WHY_MAX);
|
|
75
|
-
// A negative transport ACK proves non-delivery; a timeout or disconnected socket does not.
|
|
76
|
-
export const rejectedAck = (e) => !!e && typeof e === "object"
|
|
77
|
-
&& typeof e.errcode === "number" && e.errcode !== 0
|
|
78
|
-
&& typeof e.errmsg === "string" && !!e.headers;
|
|
79
|
-
export const receiptFacts = (e) => e.payload.receipts ?? [];
|
|
80
|
-
/** Receipt QUIET is a whole-message control word, never a suffix of a real answer. */
|
|
81
|
-
export const receiptQuiet = (e, body) => !!e.payload.peer?.from.receipt && !e.payload.human && !e.interjected && body.trim() === "QUIET";
|
|
82
|
-
export const reportSource = (e) => ({ input: e.id,
|
|
83
|
-
...(e.turn ? { turn: e.turn } : {}),
|
|
84
|
-
...(receiptFacts(e).length ? { facts: receiptFacts(e).map((f) => JSON.stringify([f.event, f.version, f.receiver])) } : {}) });
|
|
85
|
-
export const taskInputCoverage = (rows, task, source, taskOf = (event) => event.serves) => {
|
|
86
|
-
const cutoff = source.turnClosedAt ?? source.result?.at ?? Date.now();
|
|
87
|
-
const relevant = rows.filter((e) => e.target === source.target && taskOf(e) === task && !e.canceled);
|
|
88
|
-
const inputs = [...new Set(relevant.filter((e) => e.id === source.id || e.exposure === "consumed"
|
|
89
|
-
&& (e.consumedAt ?? e.result?.at ?? e.turnClosedAt ?? Infinity) <= cutoff
|
|
90
|
-
&& !(e.execution === "complete" && !e.result))
|
|
91
|
-
.flatMap((e) => e.inputIds ?? [e.id]))].sort();
|
|
92
|
-
return { inputs, complete: coversTaskInputIds(relevant, inputs) };
|
|
93
|
-
};
|
|
94
|
-
export const coversTaskInputIds = (rows, inputs) => {
|
|
95
|
-
const covered = new Set(inputs);
|
|
96
|
-
return rows.filter((e) => !!e.payload.peer?.tell && !e.canceled).every((e) => covered.has(e.id));
|
|
97
|
-
};
|
|
98
|
-
export const correctionTaskEvent = (binding, serves) => binding ? binding.event ?? undefined : serves;
|
|
99
|
-
export const canSettleFinal = (event) => !event.id.startsWith("feedback:")
|
|
100
|
-
|| !!event.serves || !!event.feedbackRoute;
|
|
101
|
-
export const eventFinalPublication = (event, owns, allowed) => {
|
|
102
|
-
if (!event.result || event.quiet || event.canceled || event.interjected || !owns(event) || !allowed(event))
|
|
103
|
-
return undefined;
|
|
104
|
-
const channel = event.channel || event.feedbackRoute?.receiver;
|
|
105
|
-
return channel ? { channel, target: event.target, turn: event.turn || event.id } : undefined;
|
|
106
|
-
};
|
|
107
|
-
export const publishEventFinal = (event, owns, allowed, publish) => {
|
|
108
|
-
const destination = eventFinalPublication(event, owns, allowed);
|
|
109
|
-
if (!destination)
|
|
110
|
-
return false;
|
|
111
|
-
publish(destination.target, destination.turn, destination.channel, event);
|
|
112
|
-
return true;
|
|
113
|
-
};
|
|
114
|
-
export const eventDeliveryAllowed = (source, target, eventId, purpose, ownerAllowed, row) => {
|
|
115
|
-
if (!source)
|
|
116
|
-
return !eventId || purpose === "task";
|
|
117
|
-
const cancellation = purpose === "cancellation" && source.canceled && source.unexposedHuman;
|
|
118
|
-
if (source.feedbackRoute && (!row || row.owner !== source.target || row.receiver.kind !== "chat"))
|
|
119
|
-
return false;
|
|
120
|
-
return source.target === target && !source.interjected && ownerAllowed(source)
|
|
121
|
-
&& (cancellation || !source.canceled && row?.outcome?.status !== "canceled" && row?.status !== "held")
|
|
122
|
-
&& (purpose !== "progress" || !!row && ["open", "need", "error"].includes(row.status));
|
|
123
|
-
};
|
|
124
|
-
export const runEventFinalRecovery = (event, owns, recover) => {
|
|
125
|
-
if (event.handoffCut || !event.result || event.quiet || event.interjected || event.canceled || !owns(event))
|
|
126
|
-
return false;
|
|
127
|
-
recover(event);
|
|
128
|
-
return true;
|
|
129
|
-
};
|
|
130
|
-
export const peerEventPrerequisitesReady = (event, routeStatus, routePrerequisitesReady, inputPrerequisitesReady) => !(event.serves && routeStatus === "held" && !routePrerequisitesReady) && inputPrerequisitesReady;
|
|
131
|
-
export const resultCorrectionInputs = (source, section, index, reason, candidate, displayName, renderEnvelope) => {
|
|
132
|
-
const row = candidate;
|
|
133
|
-
const active = row && ["held", "open", "need", "error"].includes(row.status);
|
|
134
|
-
const owned = active && row.status !== "held" && row.owner === source.target;
|
|
135
|
-
const task = !!owned && row.receiver.kind === "wizard";
|
|
136
|
-
const fyiBody = () => row && row.owner !== source.target
|
|
137
|
-
? `执行者 ${displayName(source.target)} 的 RESULT 未被任务路由 ${row.event} 接受(${reason})。来源事件 ${source.id},当前 owner ${displayName(row.owner)}。这是私密知会,无需回复,也不要新建任务。`
|
|
138
|
-
: row && row.receiver.kind === "chat" && owned
|
|
139
|
-
? `本轮 RESULT 未结清人类任务 ${row.event}(${reason}),当前仍 pending。来源事件 ${source.id}。这是绑定原任务的私密纠正;补充读完后,完成时对原任务显式提交 RESULT;普通确认不会结清,也不会新建任务或公开此结果。`
|
|
140
|
-
: `RESULT 未进入有效任务:${reason}。这是私密纠正知会,无需回复,也不要新建任务。`;
|
|
141
|
-
const chatFeedbackRoute = owned && row?.receiver.kind === "chat"
|
|
142
|
-
? { event: row.event, receiver: row.receiver.channel } : undefined;
|
|
143
|
-
const make = (target, recipient, serves, asker, suffix = "", text, feedbackRoute) => ({
|
|
144
|
-
id: `feedback:${source.id}:${index}:${section}${suffix}`,
|
|
145
|
-
identity: JSON.stringify(["result-correction", source.id, index, section, target]), target, speaker: recipient, channel: "",
|
|
146
|
-
...(serves ? { serves, ...(asker ? { asker } : {}) } : {}), ...(feedbackRoute ? { feedbackRoute } : {}),
|
|
147
|
-
priority: "normal", deadline: NO_DEADLINE,
|
|
148
|
-
payload: { text: text ?? (serves
|
|
149
|
-
? `你的 RESULT 暂未交付:${reason}。请只对匹配收件人提交 \`@.name RESULT: <结论>\`;需要反问时使用 tell_peer({kind:"ask"})。`
|
|
150
|
-
: fyiBody()),
|
|
151
|
-
peer: { from: { kind: "peer", from: recipient, ...(serves ? { event: serves } : {}) },
|
|
152
|
-
envelope: renderEnvelope(displayName(recipient), !serves), kind: serves ? "task" : "fyi" } },
|
|
153
|
-
});
|
|
154
|
-
const executor = make(source.target, source.speaker, task ? row.event : undefined, task ? row.asker : undefined, "", undefined, chatFeedbackRoute);
|
|
155
|
-
return row && row.owner !== source.target
|
|
156
|
-
? [make(source.target, source.speaker, undefined, undefined, "", fyiBody()),
|
|
157
|
-
make(row.owner, source.target, undefined, undefined, `:owner:${row.owner}`, fyiBody())]
|
|
158
|
-
: [executor];
|
|
159
|
-
};
|
|
160
|
-
export const requiresExplicitResultAddress = (source, row, isResult) => isResult && row?.receiver.kind === "wizard";
|
|
161
|
-
export const settleUnaddressedResult = (source, row, isResult, reject) => {
|
|
162
|
-
if (!requiresExplicitResultAddress(source, row, isResult) || !row || row.receiver.kind !== "wizard")
|
|
163
|
-
return false;
|
|
164
|
-
const reason = row.owner !== source.target ? "任务已移交,旧执行者不能提交结果"
|
|
165
|
-
: row.status === "held" ? "任务前置尚未就绪"
|
|
166
|
-
: row.outcome?.status === "canceled" ? "任务已取消" : "回执必须显式写明收件人";
|
|
167
|
-
reject(source, row, reason);
|
|
168
|
-
return true;
|
|
169
|
-
};
|
|
170
|
-
export const servedChatResultPublicAllowed = (source, row, isResult, covers) => {
|
|
171
|
-
if (!isResult || row?.receiver.kind !== "chat")
|
|
172
|
-
return true;
|
|
173
|
-
const binding = source.resultRoutes?.served;
|
|
174
|
-
return !!binding?.event && !!binding.inputs && covers(row.event, source, binding.inputs);
|
|
175
|
-
};
|
|
176
|
-
export const servedChatResultFinalAllowed = (source, sourceRow, boundRow, isResult, covers) => {
|
|
177
|
-
const binding = source.resultRoutes?.served;
|
|
178
|
-
if (isResult && binding?.event && (!boundRow || !sourceRow || boundRow.event !== sourceRow.event))
|
|
179
|
-
return false;
|
|
180
|
-
return servedChatResultPublicAllowed(source, boundRow ?? sourceRow, isResult, covers);
|
|
181
|
-
};
|
|
182
|
-
export const rejectUncoveredServedChatResult = (source, row, isResult, inputs, covers, reject) => {
|
|
183
|
-
if (!isResult || row?.receiver.kind !== "chat" || covers(row.event, source, inputs))
|
|
184
|
-
return false;
|
|
185
|
-
reject(source, row);
|
|
186
|
-
return true;
|
|
187
|
-
};
|
|
188
|
-
export const settleServedChatResult = (source, row, isResult, inputs, covers, reject, settle) => {
|
|
189
|
-
if (!isResult || row?.receiver.kind !== "chat")
|
|
190
|
-
return false;
|
|
191
|
-
if (row.owner !== source.target || row.status === "held" || row.outcome?.status === "canceled") {
|
|
192
|
-
reject(source, row, row.owner !== source.target ? "任务已移交" : row.status === "held" ? "前置尚未就绪" : "任务已取消");
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
if (!covers(row.event, source, inputs)) {
|
|
196
|
-
reject(source, row, "同一任务还有本次结果未覆盖的补充;读完补充后重新提交结果");
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
settle(source, row);
|
|
200
|
-
return true;
|
|
201
|
-
};
|
|
202
|
-
export const settleAddressedResults = (source, sections, io) => {
|
|
203
|
-
sections.forEach((section, index) => {
|
|
204
|
-
const key = `${index}:${section.name}`;
|
|
205
|
-
const binding = io.binding(source, key);
|
|
206
|
-
const receiver = binding?.receiver ?? io.resolve(section.name);
|
|
207
|
-
if (!receiver) {
|
|
208
|
-
if (!binding)
|
|
209
|
-
io.bind(source, key, section.name, null, []);
|
|
210
|
-
io.reject(source, section, index, `收件人 ${section.name} 不存在`, undefined, key);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const selected = io.select(source, receiver, binding);
|
|
214
|
-
const row = selected && (!source.result || selected.at <= source.result.at) ? selected : undefined;
|
|
215
|
-
const inputs = binding?.inputs ?? (row ? io.consumed(row.event, source) : []);
|
|
216
|
-
if (!binding?.inputs)
|
|
217
|
-
io.bind(source, key, receiver, row?.event ?? null, inputs);
|
|
218
|
-
if (!row) {
|
|
219
|
-
io.reject(source, section, index, `${section.name} 不是这笔任务的收件人,或你当前没有欠它的未完成任务`, undefined, key);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
if (row.owner !== source.target) {
|
|
223
|
-
io.reject(source, section, index, `任务路由 ${row.event} 已移交,当前不能由你结算`, row, key);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (row.outcome?.status === "canceled" || row.status === "held"
|
|
227
|
-
|| !["open", "need", "error", "answered", "handed"].includes(row.status)) {
|
|
228
|
-
io.reject(source, section, index, row.status === "held" ? `任务路由 ${row.event} 的前置尚未就绪` : `任务路由 ${row.event} 已取消或不可结算`, row, key);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (!section.body || !io.covers(row.event, source, inputs)) {
|
|
232
|
-
io.reject(source, section, index, !section.body ? "RESULT 正文为空" : "同一任务还有本次结果未覆盖的补充;读完补充后重新提交结果", row, key);
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
io.settle(source, section, index, row);
|
|
236
|
-
});
|
|
237
|
-
};
|
|
238
|
-
export const receiptCoverage = (e, channel = e.channel, question = false, questionText) => {
|
|
239
|
-
const refs = (facts) => [...new Set(facts.map((f) => JSON.stringify([f.event, f.version, f.receiver])))].sort();
|
|
240
|
-
const receipts = receiptFacts(e);
|
|
241
|
-
// Publishing one question does not certify that all incoming NEEDs were handled.
|
|
242
|
-
// Claim the generated question version, leaving every input risk fact unclaimed.
|
|
243
|
-
const risks = receipts.some((f) => f.status !== "done");
|
|
244
|
-
const facts = question && receipts.length ? [JSON.stringify(["question", e.serves ?? "", refs(receipts), digest((questionText ?? e.result?.body ?? "").trim())])]
|
|
245
|
-
: [...refs(receipts.filter((f) => f.status === "done")),
|
|
246
|
-
...(risks ? [JSON.stringify(["summary", e.serves ?? "", refs(receipts)])] : [])];
|
|
247
|
-
return facts.length ? { context: JSON.stringify([e.target, e.serves ?? "", channel]), facts } : undefined;
|
|
248
|
-
};
|
|
249
|
-
const receiptFactOk = (f) => !!f && typeof f.event === "string" && !!f.event
|
|
250
|
-
&& (f.batch === undefined || typeof f.batch === "string" && !!f.batch)
|
|
251
|
-
&& typeof f.version === "string" && !!f.version && typeof f.body === "string" && typeof f.envelope === "string"
|
|
252
|
-
&& typeof f.speaker === "string" && ["done", "need", "error", "progress", "timeout", "silent", "dead", "canceled"].includes(f.status)
|
|
253
|
-
&& !!f.receiver && (f.receiver.kind === "wizard" ? typeof f.receiver.to === "string"
|
|
254
|
-
&& (f.receiver.event === undefined || typeof f.receiver.event === "string")
|
|
255
|
-
: f.receiver.kind === "chat" && typeof f.receiver.channel === "string" && typeof f.receiver.message === "string")
|
|
256
|
-
&& (f.source === undefined || !!f.source && typeof f.source.input === "string");
|
|
257
|
-
const coverageOk = (c) => !!c && typeof c.context === "string"
|
|
258
|
-
&& Array.isArray(c.facts) && c.facts.every((f) => typeof f === "string");
|
|
259
|
-
export const createMessageEvents = (file, io) => {
|
|
260
|
-
const db = loadJsonMap(file, (rows) => gcEvents(Date.now(), io.retain)(rows), {
|
|
261
|
-
strict: true, warnBytes: 32 * 1024 * 1024, onLarge: (bytes) => io.storeLarge?.(bytes, liveRows().length),
|
|
262
|
-
});
|
|
263
|
-
const outbox = loadJsonMap(`${file}.finals`, undefined, { strict: true });
|
|
264
|
-
Object.entries(db.all()).forEach(([id, e]) => {
|
|
265
|
-
if (e && isTomb(e)) {
|
|
266
|
-
if (e.id !== id || typeof e.fingerprint !== "string" || !terminal(e.execution) || !Number.isFinite(e.endedAt))
|
|
267
|
-
throw new Error(`invalid message event tombstone ${id}`);
|
|
268
|
-
const a = e.authority;
|
|
269
|
-
if (a !== undefined && (!a || a.id !== id || !a.target || typeof a.target !== "string" || !Number.isFinite(a.at)
|
|
270
|
-
|| a.execution !== e.execution || (e.execution === "canceled" && a.canceled !== true) || (a.serves !== undefined && typeof a.serves !== "string")
|
|
271
|
-
|| (a.feedbackRoute !== undefined && (!a.feedbackRoute || typeof a.feedbackRoute.event !== "string" || !a.feedbackRoute.event || typeof a.feedbackRoute.receiver !== "string"))
|
|
272
|
-
|| [a.canceled, a.interjected, a.handoffCut, a.handoffRestored].some((v) => v !== undefined && typeof v !== "boolean")
|
|
273
|
-
|| (a.unexposedHuman !== undefined && a.unexposedHuman !== true)))
|
|
274
|
-
throw new Error(`invalid event authority ${id}`);
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
if (!e || e.id !== id || typeof e.fingerprint !== "string" || !e.target || typeof e.speaker !== "string" || typeof e.channel !== "string" || (e.serves !== undefined && typeof e.serves !== "string") || (e.feedbackRoute !== undefined && (!e.feedbackRoute || typeof e.feedbackRoute.event !== "string" || !e.feedbackRoute.event || typeof e.feedbackRoute.receiver !== "string")) || !e.payload || typeof e.payload.text !== "string" || ([e.payload.human, e.payload.peer, e.payload.handoff].filter(Boolean).length !== 1) || !Number.isFinite(e.at) || !Number.isFinite(e.attempts) || !Number.isFinite(e.deadline) || !["queued", "dispatching", "awaiting-result", "complete", "canceled", "uncertain"].includes(e.execution))
|
|
278
|
-
throw new Error(`invalid message event ${id}`);
|
|
279
|
-
if (e.payload.receipts !== undefined && (!e.payload.peer?.from.receipt || !Array.isArray(e.payload.receipts)
|
|
280
|
-
|| !e.payload.receipts.every(receiptFactOk)))
|
|
281
|
-
throw new Error(`invalid receipt facts ${id}`);
|
|
282
|
-
if (e.payload.peer?.from.receipt && !e.finalized && (!Array.isArray(e.payload.receipts) || !e.payload.receipts.length
|
|
283
|
-
|| e.payload.receipts.some((f) => !receiptFactOk(f))))
|
|
284
|
-
throw new Error(`unsupported legacy receipt event ${id}; refusing to infer durable facts`);
|
|
285
|
-
if (!e.finalized && e.resultRoutes !== undefined && (!e.resultRoutes || typeof e.resultRoutes !== "object"
|
|
286
|
-
|| Object.keys(e.resultRoutes).some((key) => key.startsWith("legacy:"))
|
|
287
|
-
|| !Object.values(e.resultRoutes).every((b) => !!b && typeof b.receiver === "string" && !!b.receiver
|
|
288
|
-
&& (b.event === null || typeof b.event === "string" && !!b.event)
|
|
289
|
-
&& Array.isArray(b.inputs) && b.inputs.every((id) => typeof id === "string" && !!id))))
|
|
290
|
-
throw new Error(`invalid result bindings ${id}`);
|
|
291
|
-
if (e.inputIds !== undefined && (!Array.isArray(e.inputIds) || !e.inputIds.every((id) => typeof id === "string" && !!id)))
|
|
292
|
-
throw new Error(`invalid input coverage ${id}`);
|
|
293
|
-
if (e.payload.handoff && (typeof e.payload.handoff.pane !== "string" || !e.payload.handoff.pane || typeof e.payload.handoff.sessionId !== "string" || !e.payload.handoff.sessionId || !e.id.startsWith("handoff:")))
|
|
294
|
-
throw new Error(`invalid handoff event ${id}`);
|
|
295
|
-
const clear = e.payload.handoff?.clear;
|
|
296
|
-
if (e.payload.handoff && e.id.endsWith(":carry") && (!clear || clear.pane !== e.payload.handoff.pane || clear.nextSid !== e.payload.handoff.sessionId || !Number.isSafeInteger(clear.pid) || clear.pid <= 0 || !Number.isSafeInteger(clear.panePid) || !clear.panePid))
|
|
297
|
-
throw new Error(`invalid handoff clear evidence ${id}`);
|
|
298
|
-
});
|
|
299
|
-
Object.values(db.all()).forEach((e) => {
|
|
300
|
-
if (isTomb(e))
|
|
301
|
-
return;
|
|
302
|
-
if (!e.finalized && (e.serves || e.id.startsWith("route:") || e.id.startsWith("rcpt:")) && e.deadline !== NO_DEADLINE)
|
|
303
|
-
throw new Error(`unsupported expiring route event ${e.id}; refusing to migrate legacy event state`);
|
|
304
|
-
});
|
|
305
|
-
Object.entries(outbox.all()).forEach(([id, d]) => {
|
|
306
|
-
if (d?.coverage !== undefined && !coverageOk(d.coverage))
|
|
307
|
-
throw new Error(`invalid final coverage ${id}`);
|
|
308
|
-
if (!d || d.id !== id || !Array.isArray(d.parts) || d.parts.length !== d.chunks?.length || !d.chunks.every((c) => typeof c === "string") || !d.parts.every((p) => ["pending", "sending", "waiting-ack", "delivered", "uncertain", "failed"].includes(p.state)) || !d.channel)
|
|
309
|
-
throw new Error(`invalid final delivery ${id}`);
|
|
310
|
-
if (!d.purpose && d.eventId === `quiet:${d.target}:${d.turn}` && d.parts.some((part) => part.state !== "delivered"))
|
|
311
|
-
throw new Error(`active quiet delivery ${id} has no durable purpose`);
|
|
312
|
-
});
|
|
313
|
-
/** 调度只看活行; 墓碑只给 accept 判重 (与 `known`)。 */
|
|
314
|
-
const live = (id) => { const x = db.get(id); return x && !isTomb(x) ? x : undefined; };
|
|
315
|
-
const sourceOf = (id) => {
|
|
316
|
-
const row = db.get(id);
|
|
317
|
-
return row ? isTomb(row) ? row.authority : authorityOf(row) : undefined;
|
|
318
|
-
};
|
|
319
|
-
const liveRows = () => Object.values(db.all()).filter((x) => !isTomb(x));
|
|
320
|
-
let stopped = true;
|
|
321
|
-
let accepting = true;
|
|
322
|
-
let draining = false;
|
|
323
|
-
let pumping = false;
|
|
324
|
-
let timer;
|
|
325
|
-
const active = new Set();
|
|
326
|
-
const targets = new Set();
|
|
327
|
-
const delivering = new Set();
|
|
328
|
-
const probing = new Map();
|
|
329
|
-
let deliveryCursor = 0;
|
|
330
|
-
let probeCursor = 0;
|
|
331
|
-
let probeCount = 0;
|
|
332
|
-
const probeTargets = new Map();
|
|
333
|
-
/** 排队的回执 / 派活从哪一刻起被扣、此刻为什么、上次报到哪 (只在内存: 日志与 status 用)。 */
|
|
334
|
-
const holding = new Map();
|
|
335
|
-
const hold = (e, cause) => {
|
|
336
|
-
const now = Date.now();
|
|
337
|
-
// 扣留原因只进内存与日志, 但它是 status 的一行: 超长的 held 链一样要封顶。
|
|
338
|
-
const why = clip(cause, 300);
|
|
339
|
-
const h = { since: now, ...holding.get(e.id), why };
|
|
340
|
-
const due = now - h.since >= HOLD_LOG_MS && (!h.told || h.told.why !== why || now - h.told.at >= HOLD_RELOG_MS);
|
|
341
|
-
holding.set(e.id, due ? { ...h, told: { why, at: now } } : h);
|
|
342
|
-
if (due)
|
|
343
|
-
io.held?.(e, why, now - h.since);
|
|
344
|
-
};
|
|
345
|
-
/** 一次同步扫描 (pump 的一轮 / status 的一次) 内, 三个适配器按 target 只问一次: 它们读注册表、
|
|
346
|
-
* 读绑定, 每行现问就是 O(行数) 次 I/O, 而 pinOf / queue 又对每行扫全表 —— 那就是 O(R²)。
|
|
347
|
-
* 同一次同步调用里 pane / 会话本来不会变, 快照反而让一次扫描内各行口径一致。扫描外 (异步
|
|
348
|
-
* 回调、注入边界) 不在 scope 里, 照旧现问。 */
|
|
349
|
-
let pass;
|
|
350
|
-
const scan = (run) => {
|
|
351
|
-
if (pass)
|
|
352
|
-
return run();
|
|
353
|
-
pass = new Map();
|
|
354
|
-
try {
|
|
355
|
-
return run();
|
|
356
|
-
}
|
|
357
|
-
finally {
|
|
358
|
-
pass = undefined;
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
const ask = (kind, target) => {
|
|
362
|
-
const key = `${kind}\0${target}`;
|
|
363
|
-
if (pass?.has(key))
|
|
364
|
-
return pass.get(key);
|
|
365
|
-
const v = io[kind](target);
|
|
366
|
-
pass?.set(key, v);
|
|
367
|
-
return v;
|
|
368
|
-
};
|
|
369
|
-
const resourceAt = (target) => ask("resource", target);
|
|
370
|
-
// An exposed event belongs to the session that received it, not a replacement
|
|
371
|
-
// pane now bound to the same wizard. Keep its uncertain history for reconciliation.
|
|
372
|
-
const resourceOf = (e) => {
|
|
373
|
-
if (e.exposure === "none")
|
|
374
|
-
return resourceAt(e.target);
|
|
375
|
-
if (e.sessionId)
|
|
376
|
-
return e.sessionId === ask("sessionId", e.target) ? resourceAt(e.target) : `session:${e.sessionId}`;
|
|
377
|
-
if (e.transcript)
|
|
378
|
-
return e.transcript === ask("transcript", e.target) ? resourceAt(e.target) : `transcript:${e.transcript}`;
|
|
379
|
-
return resourceAt(e.target);
|
|
380
|
-
};
|
|
381
|
-
const bounded = (id, read) => {
|
|
382
|
-
const e = live(id);
|
|
383
|
-
const target = e ? resourceOf(e) : id;
|
|
384
|
-
if (probing.has(id) || probeTargets.has(target) || probeCount >= 16)
|
|
385
|
-
return Promise.reject(new Error("probe already running or probe capacity occupied"));
|
|
386
|
-
const token = Symbol(id);
|
|
387
|
-
probing.set(id, token);
|
|
388
|
-
probeTargets.set(target, token);
|
|
389
|
-
probeCount++;
|
|
390
|
-
const release = () => {
|
|
391
|
-
if (probing.get(id) === token)
|
|
392
|
-
probing.delete(id);
|
|
393
|
-
if (probeTargets.get(target) === token)
|
|
394
|
-
probeTargets.delete(target);
|
|
395
|
-
};
|
|
396
|
-
let timer;
|
|
397
|
-
const work = Promise.resolve().then(read);
|
|
398
|
-
void work.finally(release).catch(() => undefined);
|
|
399
|
-
return Promise.race([work, new Promise((_, reject) => {
|
|
400
|
-
timer = setTimeout(() => reject(new Error("pane probe exceeded 5s; no transport attempted")), 5000);
|
|
401
|
-
})]).finally(() => { clearTimeout(timer); probeCount--; release(); });
|
|
402
|
-
};
|
|
403
|
-
const patch = (id, p) => {
|
|
404
|
-
const prev = live(id);
|
|
405
|
-
const next = { ...prev, ...p };
|
|
406
|
-
return db.set(id, terminal(next.execution) && !terminal(prev.execution) ? { ...next, endedAt: Date.now() } : next);
|
|
407
|
-
};
|
|
408
|
-
const part = (id, n, p) => {
|
|
409
|
-
const d = outbox.get(id);
|
|
410
|
-
outbox.set(id, { ...d, parts: d.parts.map((x, i) => i === n ? { ...x, ...p } : x) });
|
|
411
|
-
};
|
|
412
|
-
const claimsOf = (coverage) => {
|
|
413
|
-
if (!coverage)
|
|
414
|
-
return [];
|
|
415
|
-
const rows = Object.values(outbox.all()).filter((d) => d.coverage?.context === coverage.context
|
|
416
|
-
&& d.coverage.facts.some((f) => coverage.facts.includes(f)));
|
|
417
|
-
const whole = rows.filter((d) => coverage.facts.every((f) => d.coverage.facts.includes(f)));
|
|
418
|
-
const best = whole.find((d) => d.parts.every((p) => p.state !== "failed")) ?? whole[0];
|
|
419
|
-
return best ? [best] : rows;
|
|
420
|
-
};
|
|
421
|
-
const HOLD_ADVICE = "; receipt retained; POST /message-events/release with id and reason after reconciliation";
|
|
422
|
-
const holdReceipt = (e, cause, reason) => {
|
|
423
|
-
// 扣留原因可能被反复重写: 先摘掉上一次的处置尾注, 只留原因本身再折叠, 免得尾注无限叠长。
|
|
424
|
-
const prev = e.reason?.endsWith(HOLD_ADVICE) ? e.reason.slice(0, -HOLD_ADVICE.length) : e.reason;
|
|
425
|
-
patch(e.id, { execution: e.exposure === "none" ? "queued" : "uncertain", deliveryHold: cause,
|
|
426
|
-
reason: `${appendReason(prev, reason)}${HOLD_ADVICE}`, retryAt: undefined });
|
|
427
|
-
};
|
|
428
|
-
const cancel = (select, reason = "canceled by owner") => {
|
|
429
|
-
const rows = liveRows().filter((e) => !["complete", "canceled"].includes(e.execution) && select(e));
|
|
430
|
-
rows.forEach((e) => {
|
|
431
|
-
if (receiptFacts(e).length) {
|
|
432
|
-
holdReceipt(e, "owner-stop", reason);
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
const next = patch(e.id, { canceled: true, reason, execution: e.exposure === "none" ? "canceled" : "uncertain" });
|
|
436
|
-
io.canceled(next); // Cancellation after exposure never asserts the pane stopped.
|
|
437
|
-
});
|
|
438
|
-
return rows.length;
|
|
439
|
-
};
|
|
440
|
-
const claimReceipt = (id) => {
|
|
441
|
-
const e = live(id);
|
|
442
|
-
if (!e || e.execution !== "queued" || e.exposure !== "none" || e.canceled || e.receiptClaim)
|
|
443
|
-
return { ok: false, reason: "receipt is not an unexposed unclaimed queued input" };
|
|
444
|
-
const facts = receiptFacts(e);
|
|
445
|
-
// wait_peer returns one route outcome, never all the siblings in a merged carrier.
|
|
446
|
-
// Keep mixed carriers intact for explicit release and transcript delivery.
|
|
447
|
-
if (!facts.length || facts.some((f) => f.event !== facts[0].event))
|
|
448
|
-
return { ok: false, reason: "merged receipt contains sibling outcomes; reconcile/release the carrier for transcript delivery" };
|
|
449
|
-
const event = facts[0].event;
|
|
450
|
-
const rows = liveRows().filter((x) => x.target === e.target && x.execution === "queued" && x.exposure === "none"
|
|
451
|
-
&& receiptFacts(x).length && receiptFacts(x).every((f) => f.event === event));
|
|
452
|
-
const at = Date.now();
|
|
453
|
-
db.merge(Object.fromEntries(rows.map((x) => [x.id, { ...x, execution: "complete", finalized: true,
|
|
454
|
-
receiptClaim: { at, via: "wait_peer", event,
|
|
455
|
-
facts: receiptFacts(x).map((f) => JSON.stringify([f.event, f.version, f.receiver])) }, deliveryHold: undefined,
|
|
456
|
-
reason: "receipt taken by wait_peer; CLI consumption not asserted", endedAt: at }])));
|
|
457
|
-
return { ok: true };
|
|
458
|
-
};
|
|
459
|
-
const accept = (input, retire) => {
|
|
460
|
-
if (!accepting)
|
|
461
|
-
throw new Error("message scheduler is stopped");
|
|
462
|
-
const clean = clone(input);
|
|
463
|
-
// `serves` 是路由元数据, 不参与身份: 同一个 id 重放 (含 reload 后重入箱) 带着同一份
|
|
464
|
-
// 内容就该是同一条消息, 哪怕 serves 的来历变了 —— 它不算内容的一部分。
|
|
465
|
-
const { serves: _routing, ...identified } = clean;
|
|
466
|
-
const fingerprint = digest(identified.identity ? [JSON.parse(identified.identity), identified.speaker, identified.channel] : identified);
|
|
467
|
-
const prior = db.get(input.id);
|
|
468
|
-
if (prior && prior.fingerprint !== fingerprint)
|
|
469
|
-
throw new Error(`event identity conflict: ${input.id}`);
|
|
470
|
-
const retired = retire ? live(retire) : undefined;
|
|
471
|
-
if (retire && (!retired || retired.id === input.id || retired.exposure !== "none"))
|
|
472
|
-
throw new Error("cannot retire an exposed or missing event");
|
|
473
|
-
const stored = prior ?? { ...clean, fingerprint, at: Date.now(), execution: "queued", exposure: "none", attempts: 0 };
|
|
474
|
-
// Replacement and retirement share one store write: recovery can never
|
|
475
|
-
// expose both the original inbox and its replacement to their recipients.
|
|
476
|
-
if (!prior || retired)
|
|
477
|
-
db.merge({ [stored.id]: stored,
|
|
478
|
-
...(retired ? { [retired.id]: { ...retired, execution: "canceled", endedAt: Date.now() } } : {}) });
|
|
479
|
-
// 墓碑 = 早已投过并了结: 重放 / 重入箱到此为止, 不复活、不再注入。
|
|
480
|
-
if (isTomb(stored))
|
|
481
|
-
return { ok: true, queued: false, eventId: stored.id };
|
|
482
|
-
const e = stored;
|
|
483
|
-
if (e.execution === "queued") {
|
|
484
|
-
try {
|
|
485
|
-
io.accepted(e);
|
|
486
|
-
}
|
|
487
|
-
catch (error) {
|
|
488
|
-
patch(e.id, { execution: "queued", retryAt: backoff(e.attempts), reason: `acceptance projection failed before exposure: ${why(error)}` });
|
|
489
|
-
io.error(error);
|
|
490
|
-
}
|
|
491
|
-
} // Idempotent adapters restore accounting/receipt intent after a torn cross-store write.
|
|
492
|
-
void pump();
|
|
493
|
-
return { ok: true, queued: e.execution === "queued", eventId: e.id };
|
|
494
|
-
};
|
|
495
|
-
const result = (id, body, revision, turn) => {
|
|
496
|
-
const e = live(id);
|
|
497
|
-
if (!e || e.canceled || e.execution === "canceled" || e.result?.revision === revision)
|
|
498
|
-
return;
|
|
499
|
-
const quiet = receiptQuiet(e, body);
|
|
500
|
-
const resultRoutes = { ...io.resultBindings?.({ ...e, ...(turn ? { turn } : {}) }, body), ...e.resultRoutes };
|
|
501
|
-
patch(id, { finalized: quiet, quiet: quiet ? true : undefined, result: { body, revision, at: Date.now() },
|
|
502
|
-
resultRoutes, execution: "complete", exposure: "consumed", consumedAt: e.consumedAt ?? Date.now(), ...(turn ? { turn } : {}) });
|
|
503
|
-
if (!quiet)
|
|
504
|
-
io.final?.(live(id), { text: body });
|
|
505
|
-
};
|
|
506
|
-
const delivery = (input) => {
|
|
507
|
-
const source = input.eventId ? live(input.eventId) : undefined;
|
|
508
|
-
const coverage = input.coverage ?? (input.purpose !== "progress" && source
|
|
509
|
-
? receiptCoverage(source, input.channel) ?? (!source.payload.peer?.from.receipt
|
|
510
|
-
? { context: JSON.stringify([source.target, source.serves ?? "", input.channel]), facts: [JSON.stringify([source.serves ?? "", source.id, input.reportKind ?? "done",
|
|
511
|
-
input.reportKind === "need" || input.reportKind === "error" ? digest(input.body.trim()) : undefined])] } : undefined)
|
|
512
|
-
: undefined);
|
|
513
|
-
const covering = claimsOf(coverage);
|
|
514
|
-
if (coverage && covering?.length) {
|
|
515
|
-
const claimed = new Set(covering.flatMap((d) => d.coverage.facts));
|
|
516
|
-
if (coverage.facts.every((f) => claimed.has(f))) {
|
|
517
|
-
// An explicit retry reuses the frozen delivery and only retries proven failures.
|
|
518
|
-
// Delivered and uncertain parts retain their original claims and transport identity.
|
|
519
|
-
const retries = covering.filter((d) => d.coverage.facts.some((f) => coverage.facts.includes(f)) && d.parts.some((p) => p.state === "failed"));
|
|
520
|
-
if (retries.length)
|
|
521
|
-
outbox.merge(Object.fromEntries(retries.map((d) => [d.id, { ...d,
|
|
522
|
-
parts: d.parts.map((p) => p.state === "failed" ? { ...p, state: "pending", retryAt: undefined } : p) }])));
|
|
523
|
-
void pump();
|
|
524
|
-
return covering[0].id;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
const old = outbox.get(input.id);
|
|
528
|
-
if (old) {
|
|
529
|
-
if (old.body !== input.body || old.channel !== input.channel || old.revision !== input.revision)
|
|
530
|
-
throw new Error(`final identity conflict: ${input.id}`);
|
|
531
|
-
return old.id;
|
|
532
|
-
}
|
|
533
|
-
const covered = { ...input, ...(coverage ? { coverage } : {}) };
|
|
534
|
-
const frozen = clone(io.format?.(covered) ?? covered);
|
|
535
|
-
outbox.set(input.id, { ...frozen, at: Date.now(), parts: frozen.chunks.map(() => ({ state: "pending", attempts: 0 })) });
|
|
536
|
-
void pump();
|
|
537
|
-
return input.id;
|
|
538
|
-
};
|
|
539
|
-
const send = async (id) => {
|
|
540
|
-
delivering.add(id);
|
|
541
|
-
try {
|
|
542
|
-
for (let n = 0; n < outbox.get(id).parts.length && !stopped; n++) {
|
|
543
|
-
const d = outbox.get(id);
|
|
544
|
-
const p = d.parts[n];
|
|
545
|
-
const source = d.eventId ? sourceOf(d.eventId) : undefined;
|
|
546
|
-
const cancellation = d.purpose === "cancellation" && source?.canceled && source.unexposedHuman;
|
|
547
|
-
if ((d.eventId && !source && d.purpose !== "task") || (source && source.target !== d.target)
|
|
548
|
-
|| ((source?.canceled || source?.interjected || source?.handoffCut && !source.handoffRestored) && !cancellation)) {
|
|
549
|
-
if (p.state === "pending")
|
|
550
|
-
part(id, n, { state: "failed", reason: "source event canceled or cut before delivery" });
|
|
551
|
-
break;
|
|
552
|
-
}
|
|
553
|
-
if (p.state === "delivered")
|
|
554
|
-
continue;
|
|
555
|
-
if (p.state !== "pending" || (p.retryAt ?? 0) > Date.now())
|
|
556
|
-
break;
|
|
557
|
-
part(id, n, { state: "sending", attempts: p.attempts + 1 });
|
|
558
|
-
try {
|
|
559
|
-
const ack = await io.send(d, n);
|
|
560
|
-
part(id, n, { state: ack.failed ? "failed" : ack.uncertain ? "uncertain" : ack.queued ? "waiting-ack" : "delivered", ack: ack.ack, reason: ack.failed ?? ack.uncertain });
|
|
561
|
-
if (ack.uncertain || ack.queued || ack.failed)
|
|
562
|
-
break;
|
|
563
|
-
}
|
|
564
|
-
catch (e) {
|
|
565
|
-
part(id, n, { state: rejectedAck(e) ? "pending" : "uncertain", reason: why(e), retryAt: backoff(p.attempts + 1) });
|
|
566
|
-
break;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
finally {
|
|
571
|
-
delivering.delete(id);
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
const observe = async (e) => {
|
|
575
|
-
const evidence = await bounded(e.id, () => io.evidence(e));
|
|
576
|
-
if (stopped)
|
|
577
|
-
return;
|
|
578
|
-
if (!evidence.consumed)
|
|
579
|
-
return;
|
|
580
|
-
const current = live(e.id);
|
|
581
|
-
if (["complete", "canceled"].includes(current.execution))
|
|
582
|
-
return;
|
|
583
|
-
if (current.exposure !== "consumed" || (evidence.closedAt && !current.turnClosedAt))
|
|
584
|
-
patch(e.id, {
|
|
585
|
-
exposure: "consumed", interjected: evidence.interjected,
|
|
586
|
-
consumedAt: current.consumedAt ?? Date.now(),
|
|
587
|
-
execution: current.canceled || (evidence.closedAt && !evidence.body) ? "uncertain" : "awaiting-result",
|
|
588
|
-
reason: current.canceled ? current.reason : evidence.closedAt && !evidence.body
|
|
589
|
-
? "input turn closed without a final assistant answer; delivery remains uncertain and will not be retried" : undefined,
|
|
590
|
-
...(evidence.closedAt ? { turnClosedAt: evidence.closedAt } : {}), turn: evidence.turn ?? current.turn,
|
|
591
|
-
});
|
|
592
|
-
if (!current.canceled)
|
|
593
|
-
io.committed(live(e.id));
|
|
594
|
-
if (evidence.body !== undefined && evidence.error) {
|
|
595
|
-
patch(e.id, { execution: "uncertain", turnClosedAt: evidence.closedAt ?? Date.now(),
|
|
596
|
-
failure: { body: evidence.body, at: Date.now() }, finalized: false });
|
|
597
|
-
io.final?.(live(e.id), { text: evidence.body, error: true });
|
|
598
|
-
patch(e.id, { finalized: true });
|
|
599
|
-
}
|
|
600
|
-
else if (evidence.body !== undefined && evidence.revision) {
|
|
601
|
-
result(e.id, evidence.body, evidence.revision, evidence.turn);
|
|
602
|
-
io.recovered(live(e.id));
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
/** 收件箱里的回执按接收 wizard 的待收批次合并; 不要求旧 receiver.event 关系存在。 */
|
|
606
|
-
const isRcpt = (e) => e.id.startsWith("rcpt:") && !!e.payload.peer?.from.receipt;
|
|
607
|
-
const isTask = (e) => e.id.startsWith("route:") && !!e.payload.peer?.tell
|
|
608
|
-
&& !e.payload.peer.transferred && !!e.serves;
|
|
609
|
-
/** 同一个 target 的待收回执并进当前批次 —— 扇出的结果是一轮, 不是一人一轮。被吸收的那些各自收口
|
|
610
|
-
* (`execution: complete`, 它们的 id 已终态, 重放不再注入); 结论由这一轮的终句统一交代。
|
|
611
|
-
* 每项保留独立事实、状态与信封, 合并正文与被吸收行的终态在同一次落盘中提交。 */
|
|
612
|
-
const absorb = (id) => {
|
|
613
|
-
const e = live(id);
|
|
614
|
-
if (!e || (!isRcpt(e) && !isTask(e)) || !io.valid(e))
|
|
615
|
-
return;
|
|
616
|
-
const mergeClass = isRcpt(e) ? isRcpt : isTask;
|
|
617
|
-
const batch = isRcpt(e) ? receiptFacts(e)[0]?.batch : undefined;
|
|
618
|
-
if (isRcpt(e) && (receiptFacts(e).some((f) => f.status !== "done") || !batch))
|
|
619
|
-
return;
|
|
620
|
-
const absorbed = liveRows()
|
|
621
|
-
.filter((x) => x.id !== e.id && mergeClass(x) && x.target === e.target
|
|
622
|
-
&& (isTask(e) ? (io.task?.(x) ?? x.serves) === (io.task?.(e) ?? e.serves) : true)
|
|
623
|
-
&& (!isRcpt(e) || receiptFacts(x).length > 0 && receiptFacts(x).every((f) => f.status === "done" && f.batch === batch))
|
|
624
|
-
&& x.channel === e.channel && x.execution === "queued" && x.exposure === "none" && !x.canceled && !x.deliveryHold
|
|
625
|
-
&& (!isTask(e) || JSON.stringify(x.payload.peer?.after ?? []) === JSON.stringify(e.payload.peer?.after ?? []))
|
|
626
|
-
&& x.deadline > Date.now() && io.valid(x))
|
|
627
|
-
.sort((a, b) => a.at - b.at || a.id.localeCompare(b.id));
|
|
628
|
-
if (!absorbed.length)
|
|
629
|
-
return;
|
|
630
|
-
const rows = [e, ...absorbed];
|
|
631
|
-
// Each item keeps its own status and envelope: a NEED must never inherit a sibling's done.
|
|
632
|
-
const receipts = rows.flatMap(receiptFacts);
|
|
633
|
-
const payload = isRcpt(e)
|
|
634
|
-
? { ...e.payload, receipts, text: receipts.map((f) => `${f.envelope}\n(回执 event=${f.event} version=${f.version} status=${f.status} receiver=${JSON.stringify(f.receiver)})\n${f.body}`).join("\n\n"),
|
|
635
|
-
peer: { ...e.payload.peer, envelope: `以下是同一件活的多份回执。逐项读取各自的状态、来源与正文。\n\n${e.payload.peer.envelope}` } }
|
|
636
|
-
: { ...e.payload, text: [...rows].sort((a, b) => a.at - b.at || a.id.localeCompare(b.id))
|
|
637
|
-
.map((x) => `${x.payload.peer?.envelope ?? ""}\n${x.payload.text}`).join("\n\n"),
|
|
638
|
-
peer: { ...e.payload.peer, envelope: `以下是同一项任务的补充要求,请合并处理并统一回复。\n\n${e.payload.peer.envelope}` } };
|
|
639
|
-
// One atomic store write: a crash cannot expose a merged input and an unretired sibling.
|
|
640
|
-
const inputIds = isTask(e) ? [...new Set(rows.flatMap((x) => x.inputIds ?? [x.id]))].sort() : e.inputIds;
|
|
641
|
-
db.merge({ [e.id]: { ...e, payload, ...(inputIds ? { inputIds } : {}) }, ...Object.fromEntries(absorbed.map((x) => [x.id,
|
|
642
|
-
{ ...x, execution: "complete", exposure: "consumed", finalized: true, endedAt: Date.now(), reason: `merged into ${e.id}` }])) });
|
|
643
|
-
};
|
|
644
|
-
const inject = async (id, resource) => {
|
|
645
|
-
const target = live(id).target;
|
|
646
|
-
active.add(resource);
|
|
647
|
-
targets.add(target);
|
|
648
|
-
try {
|
|
649
|
-
absorb(id);
|
|
650
|
-
const e = live(id);
|
|
651
|
-
if (stopped || e.execution !== "queued" || e.deliveryHold || !io.valid(e))
|
|
652
|
-
return;
|
|
653
|
-
io.accepted(e);
|
|
654
|
-
patch(id, { execution: "dispatching", attempts: e.attempts + 1, transcript: io.transcript(e.target) ?? e.transcript });
|
|
655
|
-
const boundary = (phase, identity) => {
|
|
656
|
-
const current = live(id);
|
|
657
|
-
if (stopped || current.canceled || current.deliveryHold || !io.valid(current))
|
|
658
|
-
return false;
|
|
659
|
-
// 已收下的输入不再允许迟到的边界回调触碰 pane 或降级消费见证。
|
|
660
|
-
if (current.execution === "complete" || ["submitted", "consumed"].includes(current.exposure))
|
|
661
|
-
return false;
|
|
662
|
-
if (current.exposure !== "none" && current.transcript && current.transcript !== io.transcript(e.target))
|
|
663
|
-
return false;
|
|
664
|
-
if (phase)
|
|
665
|
-
patch(id, { exposure: "possible", sessionId: identity?.sessionId ?? current.sessionId,
|
|
666
|
-
transcript: identity?.transcript ?? io.transcript(e.target) ?? current.transcript });
|
|
667
|
-
return true;
|
|
668
|
-
};
|
|
669
|
-
let r;
|
|
670
|
-
try {
|
|
671
|
-
r = await io.inject(live(id), boundary);
|
|
672
|
-
}
|
|
673
|
-
catch (error) {
|
|
674
|
-
r = { ok: false, uncertain: live(id).exposure !== "none", retryable: live(id).exposure === "none", reason: why(error) };
|
|
675
|
-
}
|
|
676
|
-
const latest = live(id);
|
|
677
|
-
if (latest.result || latest.execution === "complete") {
|
|
678
|
-
if (!latest.canceled)
|
|
679
|
-
io.committed(latest);
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
// 原生消费/收口证据比迟到的注入 ACK 强;既不降回 submitted,也不覆盖真实的收口原因。
|
|
683
|
-
if (latest.exposure === "consumed") {
|
|
684
|
-
if (!latest.canceled)
|
|
685
|
-
io.committed(latest);
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
if (latest.deliveryHold) {
|
|
689
|
-
if (r.ok || r.uncertain || latest.exposure !== "none")
|
|
690
|
-
patch(id, { execution: "uncertain",
|
|
691
|
-
exposure: r.ok ? "submitted" : latest.exposure, reason: appendReason(latest.reason, "late transport outcome requires reconciliation") });
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
if (r.ok && !r.uncertain) {
|
|
695
|
-
const committed = patch(id, { execution: latest.canceled ? "uncertain" : "awaiting-result", exposure: "submitted", transcript: latest.transcript ?? io.transcript(e.target) });
|
|
696
|
-
if (!latest.canceled)
|
|
697
|
-
io.committed(committed);
|
|
698
|
-
}
|
|
699
|
-
else if (!!latest.serves && latest.deadline === NO_DEADLINE && !receiptFacts(latest).length
|
|
700
|
-
&& !r.uncertain && latest.exposure === "none" && !latest.canceled) {
|
|
701
|
-
// A proven unexposed input is safe to retry after repair; an unlimited
|
|
702
|
-
// task must not become permanently orphaned after five transport failures.
|
|
703
|
-
patch(id, { execution: "queued", exposure: "none", retryAt: backoff(latest.attempts), reason: r.reason });
|
|
704
|
-
}
|
|
705
|
-
else if (latest.payload.planReminder && r.retryable && !r.uncertain
|
|
706
|
-
&& latest.exposure === "none" && !latest.canceled) {
|
|
707
|
-
// Reminder tokens are recorded at enqueue; keep this same event durable
|
|
708
|
-
// across proven-unexposed retries, with backoff capped by backoff().
|
|
709
|
-
patch(id, { execution: "queued", exposure: "none", retryAt: backoff(latest.attempts), reason: r.reason });
|
|
710
|
-
}
|
|
711
|
-
else if (r.gone && !r.uncertain && latest.exposure === "none" && !latest.canceled
|
|
712
|
-
&& (!latest.serves || receiptFacts(latest).length > 0 || latest.deadline !== NO_DEADLINE)) {
|
|
713
|
-
// 收方真没了 (绑定按 store 也恢复不了): 退避重投只会空转到期限, 收成 canceled 交给路由层上浮。
|
|
714
|
-
// Keep replay possible until the replacement inbox is durable.
|
|
715
|
-
const gone = patch(id, { execution: "queued", retryAt: backoff(latest.attempts), reason: r.reason || "target gone" });
|
|
716
|
-
io.gone?.(gone);
|
|
717
|
-
patch(id, { execution: "canceled" });
|
|
718
|
-
}
|
|
719
|
-
else if (!r.uncertain && latest.exposure === "none" && !latest.canceled && (!r.retryable
|
|
720
|
-
|| latest.attempts >= 5 && (!latest.serves || latest.deadline !== NO_DEADLINE))) {
|
|
721
|
-
const reason = `${r.reason || "submission failed"}${r.retryable ? "; retry limit reached" : ""}`;
|
|
722
|
-
if (receiptFacts(latest).length)
|
|
723
|
-
holdReceipt(latest, "transport-exhausted", reason);
|
|
724
|
-
else
|
|
725
|
-
cancel((e) => e.id === id, reason);
|
|
726
|
-
}
|
|
727
|
-
else if ((r.retryable || r.gone && !!latest.serves) && !r.uncertain && latest.exposure === "none" && !latest.canceled) {
|
|
728
|
-
patch(id, { execution: "queued", exposure: "none", retryAt: backoff(latest.attempts), reason: r.reason });
|
|
729
|
-
}
|
|
730
|
-
else
|
|
731
|
-
patch(id, { execution: "uncertain", reason: r.reason || "submission acknowledgement unknown" });
|
|
732
|
-
}
|
|
733
|
-
catch (e) {
|
|
734
|
-
try {
|
|
735
|
-
patch(id, { reason: why(e), retryAt: backoff(live(id).attempts) });
|
|
736
|
-
}
|
|
737
|
-
catch {
|
|
738
|
-
accepting = false;
|
|
739
|
-
stopped = true;
|
|
740
|
-
clearInterval(timer);
|
|
741
|
-
timer = undefined;
|
|
742
|
-
}
|
|
743
|
-
io.error(e);
|
|
744
|
-
}
|
|
745
|
-
finally {
|
|
746
|
-
active.delete(resource);
|
|
747
|
-
targets.delete(target);
|
|
748
|
-
void pump();
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
/** 人说的这一句不受 daemon 的顺序管辖 (§9.1): 只要同一只 pane 上没有正在贴的那一次
|
|
752
|
-
* (物理互斥), 就贴进去 —— 排在它前面的回执、正在跑的那一轮都不挡它, 顺序交给 backend CLI
|
|
753
|
-
* 自己的输入队列 (贴进运行中的一轮会被记成 queued 轮, 终句照样归到这条 event)。多笔 event
|
|
754
|
-
* 因此天然并行: 人话补一句还是新起一件, 由读它的 LLM 判。回执 (peer) 仍按老规矩排 ——
|
|
755
|
-
* 它要的是结果归属, 不是语义。 */
|
|
756
|
-
const direct = (e) => !!e.payload.human;
|
|
757
|
-
/** 同一资源上, 排在 `e` 前面且此刻真挡得住它的那一行; 没有 = 它可以贴了。
|
|
758
|
-
* `retryAt` 未到的行不算挡住 —— 它在退避, 不该把整条 pane 的后来者一起钉住: 队头一次
|
|
759
|
-
* 探测超时 (5s) 就能把一个 target 静音十几分钟, 人话排在后面时是纯损失。
|
|
760
|
-
* injectable 与 blocker 共用这一条 —— 判据分家过一次, 表现是「对外说没人挡着, 实际谁也进不去」。 */
|
|
761
|
-
// 先判执行态 (纯字段), 再问 resourceOf: 表里九成多是终态行, 不该替它们付 I/O。
|
|
762
|
-
const pinOf = (e) => scan(() => {
|
|
763
|
-
const rows = liveRows().sort((a, b) => a.at - b.at);
|
|
764
|
-
const resource = resourceAt(e.target);
|
|
765
|
-
return rows.find((x) => x.id !== e.id
|
|
766
|
-
&& (x.execution === "dispatching"
|
|
767
|
-
// A consumed, closed input cannot own the next turn. Keep its unknown
|
|
768
|
-
// result for reconciliation without replaying it or pinning later inputs.
|
|
769
|
-
|| (!direct(e) && io.blocksQueue?.(x) !== false && x.execution === "uncertain" && !x.releasedAt
|
|
770
|
-
&& !(x.exposure === "consumed" && x.turnClosedAt)))
|
|
771
|
-
&& resourceOf(x) === resource);
|
|
772
|
-
});
|
|
773
|
-
/** 全局 4 路并发只限回执 / 派活: 人话之间、人话与别的 pane 都互不相干, 只认同 pane 物理互斥。 */
|
|
774
|
-
const injectable = (e) => !stopped && e.execution === "queued" && !e.canceled && !e.deliveryHold && e.deadline > Date.now() && io.valid(e)
|
|
775
|
-
&& !targets.has(e.target) && !active.has(resourceAt(e.target)) && (direct(e) || active.size < 4)
|
|
776
|
-
&& pinOf(e) === undefined;
|
|
777
|
-
const blockerOf = (hit) => hit && { id: hit.id, execution: hit.execution,
|
|
778
|
-
reason: hit.reason ?? (hit.execution === "uncertain" ? "旧事件投递结果不确定,需对账" : `等待较早事件(${hit.execution})`) };
|
|
779
|
-
const blocker = (id) => {
|
|
780
|
-
const e = live(id);
|
|
781
|
-
return e?.execution === "queued" ? blockerOf(pinOf(e)) : undefined;
|
|
782
|
-
};
|
|
783
|
-
/** 一条还没贴出去的 event 此刻的排队全貌: 同 pane 上排在它前面的未了结行, 以及 injectable
|
|
784
|
-
* 的每一条否决项各自落在哪 —— 给人看「卡在谁后面、为什么、几时再试」, 不是一句「已排队」。
|
|
785
|
-
* `pin` 一并交回, 让 status 不必为 blocker 再扫一遍全表。 */
|
|
786
|
-
const queueOf = (e) => scan(() => {
|
|
787
|
-
const resource = resourceAt(e.target);
|
|
788
|
-
const ahead = liveRows()
|
|
789
|
-
.filter((x) => x.id !== e.id && x.at <= e.at && ["queued", "dispatching", "awaiting-result"].includes(x.execution) && !x.canceled
|
|
790
|
-
&& (x.execution !== "awaiting-result" || !x.releasedAt)
|
|
791
|
-
&& (x.execution === "dispatching" || io.blocksQueue?.(x) !== false)
|
|
792
|
-
&& resourceOf(x) === resource)
|
|
793
|
-
.sort((a, b) => a.at - b.at);
|
|
794
|
-
const pin = pinOf(e);
|
|
795
|
-
const holds = [
|
|
796
|
-
stopped ? "调度器未运行 (daemon 正在启停)" : "",
|
|
797
|
-
e.deliveryHold ? `回执持久待投 (${e.deliveryHold}); POST /message-events/release with id and reason` : "",
|
|
798
|
-
(e.retryAt ?? 0) > Date.now() ? `上次投递失败, ${new Date(e.retryAt).toTimeString().slice(0, 8)} 重试${e.reason ? `(${e.reason})` : ""}` : "",
|
|
799
|
-
targets.has(e.target) || active.has(resource) ? "同一 pane 正在贴另一条" : "",
|
|
800
|
-
!direct(e) && active.size >= 4 ? `全局同时投递已满 ${active.size} 路` : "",
|
|
801
|
-
pin ? `挡在前面: ${pin.id.slice(0, 10)}(${pin.execution}${pin.reason ? ` · ${pin.reason}` : ""})` : "",
|
|
802
|
-
].filter(Boolean);
|
|
803
|
-
return { execution: e.execution, ahead: ahead.map(clone), holds, pin };
|
|
804
|
-
});
|
|
805
|
-
const queue = (id) => {
|
|
806
|
-
const e = live(id);
|
|
807
|
-
if (!e)
|
|
808
|
-
return undefined;
|
|
809
|
-
const { pin: _pin, ...q } = queueOf(e);
|
|
810
|
-
return q;
|
|
811
|
-
};
|
|
812
|
-
const partsByEvent = () => Object.values(outbox.all()).reduce((m, d) => d.eventId ? m.set(d.eventId, [...(m.get(d.eventId) ?? []), ...d.parts]) : m, new Map());
|
|
813
|
-
const deliveryOf = (parts) => parts.some((p) => p.state === "failed") ? "failed"
|
|
814
|
-
: parts.some((p) => p.state === "uncertain") ? "uncertain" : parts.some((p) => p.state !== "delivered") ? "delivery-pending" : parts.length ? "delivered" : "none";
|
|
815
|
-
/** status 里的一行: 排着的行只扫一次队 (blocker 取 queueOf 交回的 pin)。 */
|
|
816
|
-
const view = (e, parts) => {
|
|
817
|
-
const q = e.execution === "queued" ? queueOf(e) : undefined;
|
|
818
|
-
const blockedBy = blockerOf(q?.pin);
|
|
819
|
-
const held = holding.get(e.id);
|
|
820
|
-
return { ...clone(e),
|
|
821
|
-
status: e.execution === "dispatching" ? "executing" : e.execution,
|
|
822
|
-
...(blockedBy ? { blockedBy } : {}),
|
|
823
|
-
// 回执 / 派活排着时把扣住它的每一条都摆出来 (含 ready=false 这种 queue() 看不见的)。
|
|
824
|
-
...(q && !direct(e) ? { holds: [...q.holds, ...(held ? [`${held.why} · 已扣 ${Math.round((Date.now() - held.since) / 1000)}s`] : [])] } : {}),
|
|
825
|
-
delivery: deliveryOf(parts),
|
|
826
|
-
};
|
|
827
|
-
};
|
|
828
|
-
const release = (id, reason) => {
|
|
829
|
-
const e = live(id);
|
|
830
|
-
const note = reason.trim().slice(0, 500);
|
|
831
|
-
if (!e)
|
|
832
|
-
return { ok: false, reason: "unknown event" };
|
|
833
|
-
if (!note)
|
|
834
|
-
return { ok: false, reason: "a reconciliation reason is required" };
|
|
835
|
-
if (e.deliveryHold && e.execution === "queued" && e.exposure === "none" && !e.canceled) {
|
|
836
|
-
const next = patch(id, { deliveryHold: undefined, attempts: 0, retryAt: undefined,
|
|
837
|
-
deadline: Math.max(e.deadline, Date.now() + 3600_000), reason: `receipt delivery explicitly resumed: ${note}` });
|
|
838
|
-
void pump();
|
|
839
|
-
return { ok: true, event: clone(next) };
|
|
840
|
-
}
|
|
841
|
-
if (e.deliveryHold)
|
|
842
|
-
return { ok: false, reason: "held receipt has possible exposure; reconcile transcript before any retry" };
|
|
843
|
-
if (!["awaiting-result", "uncertain"].includes(e.execution) || e.exposure === "none")
|
|
844
|
-
return { ok: false, reason: `event is not an exposed unresolved delivery (${e.execution}/${e.exposure})` };
|
|
845
|
-
if (e.releaseSource === "manual")
|
|
846
|
-
return { ok: false, event: clone(e), reason: "event already manually released" };
|
|
847
|
-
const next = patch(id, { execution: "uncertain", releasedAt: e.releasedAt ?? Date.now(), releaseSource: "manual", releaseReason: note,
|
|
848
|
-
reason: `manually released from queue; delivery remains uncertain: ${note}` });
|
|
849
|
-
void pump();
|
|
850
|
-
return { ok: true, event: clone(next) };
|
|
851
|
-
};
|
|
852
|
-
const releaseMissingPane = (target, sessionId, transcript, evidence) => {
|
|
853
|
-
const rows = liveRows().filter((e) => e.target === target && ["awaiting-result", "uncertain"].includes(e.execution)
|
|
854
|
-
&& e.exposure !== "none" && !e.releasedAt
|
|
855
|
-
&& (!e.sessionId || e.sessionId === sessionId) && (!e.transcript || e.transcript === transcript));
|
|
856
|
-
const at = Date.now();
|
|
857
|
-
rows.forEach((e) => patch(e.id, { execution: "uncertain", releasedAt: at, releaseSource: "pane-missing",
|
|
858
|
-
releaseReason: `pane/session disappeared (${evidence}); old execution remains uncertain and will not be replayed`,
|
|
859
|
-
supersededBy: `pane-missing:${evidence}`,
|
|
860
|
-
reason: appendReason(e.reason, "pane/session disappeared; queue slot released, old execution remains uncertain") }));
|
|
861
|
-
void pump();
|
|
862
|
-
return rows.map((e) => e.id);
|
|
863
|
-
};
|
|
864
|
-
async function pump() {
|
|
865
|
-
if (stopped || pumping)
|
|
866
|
-
return;
|
|
867
|
-
pumping = true;
|
|
868
|
-
try {
|
|
869
|
-
scan(() => {
|
|
870
|
-
// Scan the first unfinished part; later pending parts cannot jump an uncertain predecessor.
|
|
871
|
-
Object.values(outbox.all()).forEach((d) => d.parts.forEach((p, n) => {
|
|
872
|
-
if (!["waiting-ack", "uncertain"].includes(p.state))
|
|
873
|
-
return;
|
|
874
|
-
const evidence = io.deliveryEvidence?.(d, n);
|
|
875
|
-
if (evidence)
|
|
876
|
-
part(d.id, n, { state: evidence.state === "queued" ? "waiting-ack" : evidence.state, ack: evidence.ack, reason: evidence.reason });
|
|
877
|
-
}));
|
|
878
|
-
const finals = Object.values(outbox.all());
|
|
879
|
-
const rotated = [...finals.slice(deliveryCursor), ...finals.slice(0, deliveryCursor)];
|
|
880
|
-
rotated.filter((d) => {
|
|
881
|
-
const p = d.parts.find((x) => x.state !== "delivered");
|
|
882
|
-
return !delivering.has(d.id) && p?.state === "pending" && (p.retryAt ?? 0) <= Date.now();
|
|
883
|
-
}).slice(0, Math.max(0, 4 - delivering.size)).forEach((d) => {
|
|
884
|
-
deliveryCursor = (finals.findIndex((x) => x.id === d.id) + 1) % Math.max(1, finals.length);
|
|
885
|
-
void send(d.id).catch(io.error);
|
|
886
|
-
});
|
|
887
|
-
const rows = liveRows().sort((a, b) => a.at - b.at);
|
|
888
|
-
[...holding.keys()].filter((id) => live(id)?.execution !== "queued").forEach((id) => holding.delete(id));
|
|
889
|
-
const fair = [...rows.slice(probeCursor), ...rows.slice(0, probeCursor)];
|
|
890
|
-
fair.forEach((e) => {
|
|
891
|
-
if (stopped)
|
|
892
|
-
return;
|
|
893
|
-
if (e.execution === "queued" && io.blocksQueue?.(e) === false)
|
|
894
|
-
return;
|
|
895
|
-
// Expiration and permission withdrawal are ledger work; a busy or hung
|
|
896
|
-
// probe on this pane must not prevent queued messages from expiring.
|
|
897
|
-
if (e.execution === "queued" && e.deliveryHold)
|
|
898
|
-
return;
|
|
899
|
-
if (e.execution === "queued" && (e.deadline <= Date.now() || !io.valid(e))) {
|
|
900
|
-
const reason = e.deadline <= Date.now() ? "deadline expired before submission" : "permission withdrawn";
|
|
901
|
-
if (receiptFacts(e).length)
|
|
902
|
-
holdReceipt(e, "transport-exhausted", reason);
|
|
903
|
-
else
|
|
904
|
-
cancel((x) => x.id === e.id, reason);
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
907
|
-
if (["awaiting-result", "uncertain"].includes(e.execution) && e.deadline <= Date.now() && !e.releasedAt) {
|
|
908
|
-
patch(e.id, { execution: "uncertain", releasedAt: Date.now(),
|
|
909
|
-
releaseSource: "deadline",
|
|
910
|
-
releaseReason: "event deadline elapsed; uncertainty retained and automatic retry withheld",
|
|
911
|
-
reason: appendReason(e.reason, "event deadline elapsed; queue released with uncertain delivery") });
|
|
912
|
-
return;
|
|
913
|
-
}
|
|
914
|
-
// 人话的 ready 不碰 pane (只看交接闸), 不必占探测位: 否则同 pane 上一条 awaiting-result
|
|
915
|
-
// 每秒一次的 evidence 探测 (最长 5s) 几乎一直占着 probeTargets, 人话被反复跳过或误判失败退避。
|
|
916
|
-
if (e.execution === "queued" && direct(e)) {
|
|
917
|
-
if ((e.retryAt ?? 0) > Date.now() || !injectable(e))
|
|
918
|
-
return;
|
|
919
|
-
void io.ready(e).then((ready) => {
|
|
920
|
-
const current = live(e.id);
|
|
921
|
-
if (ready && injectable(current))
|
|
922
|
-
void inject(e.id, io.resource(current.target));
|
|
923
|
-
}).catch(io.error);
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
if (probing.has(e.id) || probeTargets.has(resourceOf(e)) || probeCount >= 16) {
|
|
927
|
-
if (e.execution === "queued")
|
|
928
|
-
hold(e, "探测位被占 (同 pane 上另一条正在探测)");
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
probeCursor = (rows.findIndex((x) => x.id === e.id) + 1) % Math.max(1, rows.length);
|
|
932
|
-
const failed = (error) => {
|
|
933
|
-
const current = live(e.id);
|
|
934
|
-
if (!stopped && current && !["complete", "canceled"].includes(current.execution)) {
|
|
935
|
-
const probeAttempts = (current.probeAttempts ?? 0) + 1;
|
|
936
|
-
// 探针连续失败到上限 = 这只 pane 已经问不出话: 再退避重试只是把同一条失败原因
|
|
937
|
-
// 再写一遍 (库里最长的 reason 就是这么长出来的), 该收成终态了。
|
|
938
|
-
if (probeAttempts >= PROBE_LIMIT) {
|
|
939
|
-
if (current.execution === "queued" && current.exposure === "none") {
|
|
940
|
-
if (receiptFacts(current).length)
|
|
941
|
-
holdReceipt(current, "transport-exhausted", `undeliverable: pane probe failed ${probeAttempts}×`);
|
|
942
|
-
else
|
|
943
|
-
cancel((x) => x.id === e.id, `undeliverable: pane probe failed ${probeAttempts} times; automatic retry stopped`);
|
|
944
|
-
}
|
|
945
|
-
else if (["awaiting-result", "uncertain"].includes(current.execution)) {
|
|
946
|
-
patch(e.id, { probeAttempts, retryAt: undefined, execution: "uncertain",
|
|
947
|
-
releasedAt: current.releasedAt ?? Date.now(), releaseSource: "probe-exhausted",
|
|
948
|
-
releaseReason: `pane probe failed ${probeAttempts} times; automatic retry stopped`,
|
|
949
|
-
reason: appendReason(current.reason, `undeliverable: pane probe failed ${probeAttempts}×; automatic retry stopped`) });
|
|
950
|
-
}
|
|
951
|
-
else {
|
|
952
|
-
patch(e.id, { probeAttempts, reason: appendReason(current.reason, why(error)) });
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
else {
|
|
956
|
-
patch(e.id, { probeAttempts, retryAt: backoff(probeAttempts), reason: appendReason(current.reason, why(error)) });
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
io.error(error);
|
|
960
|
-
};
|
|
961
|
-
if (["awaiting-result", "uncertain"].includes(e.execution)) {
|
|
962
|
-
if (e.failure && !e.finalized) {
|
|
963
|
-
io.final?.(e, { text: e.failure.body, error: true });
|
|
964
|
-
patch(e.id, { finalized: true });
|
|
965
|
-
}
|
|
966
|
-
if (e.execution === "uncertain" && (e.turnClosedAt || e.releasedAt))
|
|
967
|
-
return;
|
|
968
|
-
if ((e.retryAt ?? 0) > Date.now())
|
|
969
|
-
return;
|
|
970
|
-
const currentSession = ask("sessionId", e.target);
|
|
971
|
-
const currentTranscript = ask("transcript", e.target);
|
|
972
|
-
const replaced = e.exposure !== "none" && (e.sessionId
|
|
973
|
-
? e.sessionId !== currentSession : !!e.transcript && e.transcript !== currentTranscript);
|
|
974
|
-
if (replaced && !e.supersededBy)
|
|
975
|
-
patch(e.id, { supersededBy: currentSession ?? (currentTranscript ? `transcript:${currentTranscript}` : "replacement-session-unavailable"),
|
|
976
|
-
reason: appendReason(e.reason, "session replaced; old execution remains uncertain pending transcript reconciliation") });
|
|
977
|
-
void observe(e).then(() => {
|
|
978
|
-
// 探测成功就把失败计数清零: 只写一次, 不是每秒一次。
|
|
979
|
-
if (live(e.id)?.probeAttempts)
|
|
980
|
-
patch(e.id, { probeAttempts: 0 });
|
|
981
|
-
if (!stopped && e.deadline <= Date.now() && live(e.id).execution === "awaiting-result")
|
|
982
|
-
patch(e.id, { execution: "uncertain", reason: "deadline exceeded; result/physical completion not confirmed" });
|
|
983
|
-
}).catch(failed);
|
|
984
|
-
return;
|
|
985
|
-
}
|
|
986
|
-
if (e.execution === "complete") {
|
|
987
|
-
if (!e.finalized) {
|
|
988
|
-
if (!e.canceled)
|
|
989
|
-
io.committed(e);
|
|
990
|
-
if (e.result) {
|
|
991
|
-
// reload 落在 result 与 finalized 之间: 重放这一刻补上路由判定 (幂等 —— 同一条
|
|
992
|
-
// 定论重放只会在表上再写一次同样的 op)。
|
|
993
|
-
io.final?.(e, { text: e.result.body });
|
|
994
|
-
// 先落交接切断标记与路由归属, 再恢复外发; 否则旧 final 会抢在闸前公开。
|
|
995
|
-
io.recovered(live(e.id));
|
|
996
|
-
}
|
|
997
|
-
patch(e.id, { finalized: true });
|
|
998
|
-
}
|
|
999
|
-
return;
|
|
1000
|
-
}
|
|
1001
|
-
if (e.execution !== "queued")
|
|
1002
|
-
return;
|
|
1003
|
-
// 原因里不带重试时刻: 每次退避时刻都在变, 带上就成了「原因变了」, 日志每轮重报。
|
|
1004
|
-
if ((e.retryAt ?? 0) > Date.now()) {
|
|
1005
|
-
hold(e, `投递失败退避中${e.reason ? `(${e.reason})` : ""}`);
|
|
1006
|
-
return;
|
|
1007
|
-
}
|
|
1008
|
-
if (!injectable(e)) {
|
|
1009
|
-
hold(e, `injectable=false: ${queue(e.id)?.holds.join("; ") || "无效 / 过期"}`);
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
void bounded(e.id, () => io.ready(e)).then((ready) => {
|
|
1013
|
-
const current = live(e.id);
|
|
1014
|
-
if (current.probeAttempts)
|
|
1015
|
-
patch(e.id, { probeAttempts: 0 });
|
|
1016
|
-
if (ready && injectable(current))
|
|
1017
|
-
void inject(e.id, io.resource(current.target));
|
|
1018
|
-
else if (current.execution === "queued")
|
|
1019
|
-
hold(current, ready ? "injectable=false (ready 之后)" : "ready=false (前置未落定 / owner 未判闲)");
|
|
1020
|
-
}).catch(failed);
|
|
1021
|
-
});
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
|
-
catch (e) {
|
|
1025
|
-
io.error(e);
|
|
1026
|
-
}
|
|
1027
|
-
finally {
|
|
1028
|
-
pumping = false;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
const resume = () => {
|
|
1032
|
-
// Boot restoration may finish after shutdown has begun; never restart delivery then.
|
|
1033
|
-
if (draining)
|
|
1034
|
-
return;
|
|
1035
|
-
liveRows().filter((e) => e.execution === "dispatching").forEach((e) => patch(e.id, {
|
|
1036
|
-
execution: e.exposure === "none" ? "queued" : "uncertain", reason: "daemon restarted at input boundary; transcript evidence required",
|
|
1037
|
-
}));
|
|
1038
|
-
Object.values(outbox.all()).forEach((d) => d.parts.forEach((p, n) => {
|
|
1039
|
-
if (p.state === "sending")
|
|
1040
|
-
part(d.id, n, { state: "uncertain", reason: "daemon restarted before final ACK was persisted" });
|
|
1041
|
-
}));
|
|
1042
|
-
stopped = false;
|
|
1043
|
-
accepting = true;
|
|
1044
|
-
timer ??= setInterval(() => { void pump(); }, 1000);
|
|
1045
|
-
timer.unref();
|
|
1046
|
-
void pump();
|
|
1047
|
-
};
|
|
1048
|
-
return {
|
|
1049
|
-
accept, pump, resume, result, delivery, cancel, blocker, queue, release, releaseMissingPane, claimReceipt,
|
|
1050
|
-
taskInputs: (task) => liveRows().filter((e) => (io.task?.(e) ?? e.serves) === task).map(clone),
|
|
1051
|
-
consumedTaskInputs: (task, source) => taskInputCoverage(liveRows(), task, source, (event) => io.task?.(event) ?? event.serves).inputs,
|
|
1052
|
-
coversTaskInputs: (task, source, inputs) => {
|
|
1053
|
-
const relevant = liveRows().filter((e) => e.target === source.target && (io.task?.(e) ?? e.serves) === task && !e.canceled);
|
|
1054
|
-
return coversTaskInputIds(relevant, inputs);
|
|
1055
|
-
},
|
|
1056
|
-
running: () => !stopped,
|
|
1057
|
-
bind: (id, turn) => { if (live(id))
|
|
1058
|
-
patch(id, { turn }); },
|
|
1059
|
-
bindResultRoute: (id, section, receiver, event, inputs) => {
|
|
1060
|
-
const e = live(id);
|
|
1061
|
-
if (!e)
|
|
1062
|
-
return;
|
|
1063
|
-
const prior = e.resultRoutes?.[section];
|
|
1064
|
-
if (prior && (prior.receiver !== receiver || prior.event !== event))
|
|
1065
|
-
throw new Error(`RESULT section binding changed for ${id}/${section}`);
|
|
1066
|
-
if (prior?.inputs && inputs && JSON.stringify(prior.inputs) !== JSON.stringify(inputs))
|
|
1067
|
-
throw new Error(`RESULT coverage changed for ${id}/${section}`);
|
|
1068
|
-
patch(id, { resultRoutes: { ...e.resultRoutes, [section]: { ...prior, receiver, event, ...(inputs ? { inputs } : {}) } } });
|
|
1069
|
-
},
|
|
1070
|
-
finished: (id) => {
|
|
1071
|
-
const e = live(id);
|
|
1072
|
-
// Physical completion is not a task answer. Keep the missing outcome
|
|
1073
|
-
// visible while allowing the next input to use this pane.
|
|
1074
|
-
if (e && !e.canceled && !e.result)
|
|
1075
|
-
patch(id, { execution: "uncertain", exposure: "consumed",
|
|
1076
|
-
consumedAt: e.consumedAt ?? Date.now(),
|
|
1077
|
-
turnClosedAt: e.turnClosedAt ?? Date.now(),
|
|
1078
|
-
reason: "input turn ended without a final assistant answer; automatic retry withheld" });
|
|
1079
|
-
},
|
|
1080
|
-
released: (id) => { const e = live(id); if (e?.canceled)
|
|
1081
|
-
patch(id, { execution: "canceled", reason: appendReason(e.reason ?? "canceled", "pane idle confirmed") }); },
|
|
1082
|
-
stopped: (target, reason) => liveRows().filter((e) => e.target === target && e.canceled).forEach((e) => patch(e.id, { execution: "canceled", reason })),
|
|
1083
|
-
submission: async (id) => {
|
|
1084
|
-
for (;;) {
|
|
1085
|
-
const e = live(id);
|
|
1086
|
-
if (!e)
|
|
1087
|
-
return { ok: false, retryable: true, reason: "event missing" };
|
|
1088
|
-
if (["submitted", "consumed"].includes(e.exposure))
|
|
1089
|
-
return { ok: true };
|
|
1090
|
-
if (e.deliveryHold)
|
|
1091
|
-
return { ok: false, retryable: false, uncertain: e.exposure !== "none", reason: e.reason };
|
|
1092
|
-
if (e.execution === "uncertain" || stopped)
|
|
1093
|
-
return { ok: false, uncertain: true, reason: e.reason || "scheduler stopped" };
|
|
1094
|
-
if (e.execution === "canceled")
|
|
1095
|
-
return { ok: false, reason: e.reason };
|
|
1096
|
-
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
1097
|
-
}
|
|
1098
|
-
},
|
|
1099
|
-
// Keep ingress durable until WS/HTTP and their in-flight handlers have closed.
|
|
1100
|
-
drain: () => { draining = true; stopped = true; clearInterval(timer); timer = undefined; },
|
|
1101
|
-
stop: () => { accepting = false; stopped = true; clearInterval(timer); timer = undefined; },
|
|
1102
|
-
get: (id) => { const e = live(id); return e && clone(e); },
|
|
1103
|
-
suppressHandoffFinal: (id) => { if (live(id))
|
|
1104
|
-
patch(id, { handoffCut: true, handoffRestored: false }); },
|
|
1105
|
-
restoreHandoffFinal: (id) => { if (live(id))
|
|
1106
|
-
patch(id, { handoffCut: false, handoffRestored: true }); },
|
|
1107
|
-
/** 这个 id 用过没有 (含墓碑): 自己配 id 的调用方 (续问序号 / 交接续答) 据此避开撞号。 */
|
|
1108
|
-
known: (id) => db.get(id) !== undefined,
|
|
1109
|
-
ids: () => Object.keys(db.all()),
|
|
1110
|
-
/** 每条事件 (含墓碑期内的) 指着的 target / 发话方 —— 自动名查 target 是否仍被引用用。 */
|
|
1111
|
-
targets: () => Object.values(db.all()).flatMap((x) => isTomb(x) ? (x.authority ? [x.authority.target] : []) : [x.target, x.speaker]),
|
|
1112
|
-
/** 只问执行态 (含墓碑): 判「这份投过没有」的调用方不必在乎它是不是已被裁掉。 */
|
|
1113
|
-
executionOf: (id) => db.get(id)?.execution,
|
|
1114
|
-
exposureOf: (id) => {
|
|
1115
|
-
const e = live(id);
|
|
1116
|
-
// Absorbed siblings are complete/consumed before their carrier is injected.
|
|
1117
|
-
// Without their own result, that bookkeeping is not consumption evidence.
|
|
1118
|
-
return e?.execution === "complete" && !e.result ? undefined : e?.exposure;
|
|
1119
|
-
},
|
|
1120
|
-
authorityOf: (id) => {
|
|
1121
|
-
const authority = sourceOf(id);
|
|
1122
|
-
return authority && clone(authority);
|
|
1123
|
-
},
|
|
1124
|
-
// A transfer moves the route, not the human's original reply stream. Derive the
|
|
1125
|
-
// binding from durable inputs so chained transfers and reload use the same bubble.
|
|
1126
|
-
latestTransfer: (serves) => {
|
|
1127
|
-
const transfers = liveRows().filter((e) => e.serves === serves && e.payload.peer?.transferred && !e.canceled);
|
|
1128
|
-
const last = transfers.at(-1);
|
|
1129
|
-
return last && clone(last);
|
|
1130
|
-
},
|
|
1131
|
-
hasReplyDelivery: (streamId) => Object.values(outbox.all()).some((d) => d.stream?.id === streamId),
|
|
1132
|
-
replyOrigin: (event) => {
|
|
1133
|
-
const origin = event.payload.human ? live(event.id) : event.serves
|
|
1134
|
-
? liveRows().find((e) => e.serves === event.serves && !!e.payload.human && e.channel === event.channel)
|
|
1135
|
-
: undefined;
|
|
1136
|
-
return origin && clone(origin);
|
|
1137
|
-
},
|
|
1138
|
-
status: () => scan(() => {
|
|
1139
|
-
const parts = partsByEvent();
|
|
1140
|
-
return { events: liveRows().map((e) => view(e, parts.get(e.id) ?? [])), deliveries: Object.values(outbox.all()).map(clone) };
|
|
1141
|
-
}),
|
|
1142
|
-
/** 一条 event 的 status 视图 —— 轮询单条的调用方 (回归脚本) 不必为它把全表算一遍。 */
|
|
1143
|
-
event: (id) => { const e = live(id); return e && scan(() => view(e, partsByEvent().get(id) ?? [])); },
|
|
1144
|
-
deliveryStatus: (id) => outbox.get(id)?.parts.map((p) => p.state),
|
|
1145
|
-
deliveryClaims: (coverage) => claimsOf(coverage).map((d) => ({ id: d.id, states: d.parts.map((p) => p.state) })),
|
|
1146
|
-
// 泵可能正在同一 pane 上取证; 外部交接轮询复用在飞探针, 不能把 busy 当投递失败。
|
|
1147
|
-
reconcile: async (id) => {
|
|
1148
|
-
const e = live(id);
|
|
1149
|
-
if (e && !probing.has(id) && !probeTargets.has(resourceOf(e)) && probeCount < 16)
|
|
1150
|
-
await observe(e);
|
|
1151
|
-
return live(id);
|
|
1152
|
-
},
|
|
1153
|
-
};
|
|
1154
|
-
};
|
|
1155
|
-
//# sourceMappingURL=message-events.js.map
|