wezard 2.8.8 → 3.0.1
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-plugin/plugin.json +0 -6
- package/CLAUDE.md +36 -16
- package/README.md +41 -54
- package/cli/wezard.sh +3 -0
- package/config.example.jsonc +6 -8
- package/dist/cli/codex-hook.js +20 -4
- package/dist/cli/codex-hook.js.map +1 -1
- package/dist/cli/init.js +45 -8
- 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 +32 -112
- package/dist/cli/sync.js.map +1 -1
- package/dist/daemon/apprentice.js +75 -0
- package/dist/daemon/apprentice.js.map +1 -0
- package/dist/daemon/approval.js +78 -20
- package/dist/daemon/approval.js.map +1 -1
- package/dist/daemon/channel-context.js +69 -0
- package/dist/daemon/channel-context.js.map +1 -0
- package/dist/daemon/channel-posts.js +53 -0
- package/dist/daemon/channel-posts.js.map +1 -0
- package/dist/daemon/channel-store.js +96 -0
- package/dist/daemon/channel-store.js.map +1 -0
- package/dist/daemon/channel.js +805 -0
- package/dist/daemon/channel.js.map +1 -0
- package/dist/daemon/chat-name.js +24 -161
- package/dist/daemon/chat-name.js.map +1 -1
- package/dist/daemon/classes.js +418 -0
- package/dist/daemon/classes.js.map +1 -0
- package/dist/daemon/config-api.js +11 -3
- package/dist/daemon/config-api.js.map +1 -1
- package/dist/daemon/danger.js +24 -205
- package/dist/daemon/danger.js.map +1 -1
- package/dist/daemon/detail.js +14 -8
- package/dist/daemon/detail.js.map +1 -1
- package/dist/daemon/handoff.js +266 -50
- package/dist/daemon/handoff.js.map +1 -1
- package/dist/daemon/http.js +25 -18
- 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 +366 -143
- package/dist/daemon/inbound.js.map +1 -1
- package/dist/daemon/index.js +2232 -2616
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/last-response.js +44 -9
- package/dist/daemon/last-response.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 +10 -2
- package/dist/daemon/message-format.js.map +1 -1
- package/dist/daemon/mirror-bridge.js +714 -485
- 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 +2 -2
- package/dist/daemon/notices.js.map +1 -1
- package/dist/daemon/onboarding.js +384 -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 +38 -230
- package/dist/daemon/peers.js.map +1 -1
- package/dist/daemon/pending.js +7 -5
- package/dist/daemon/pending.js.map +1 -1
- package/dist/daemon/picker-policy.js +27 -12
- package/dist/daemon/picker-policy.js.map +1 -1
- package/dist/daemon/plans.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-facts.js +35 -0
- package/dist/daemon/room-facts.js.map +1 -0
- package/dist/daemon/room-hub.js +430 -0
- package/dist/daemon/room-hub.js.map +1 -0
- package/dist/daemon/room-overdue.js +98 -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 +153 -0
- package/dist/daemon/room-watchdog.js.map +1 -0
- package/dist/daemon/rooms.js +107 -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/spawn-tmux.js +171 -55
- package/dist/daemon/spawn-tmux.js.map +1 -1
- package/dist/daemon/steward-guard.js +2 -2
- package/dist/daemon/steward.js +132 -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/turn-opening.js +25 -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 +7 -2
- package/dist/daemon/wezard-session.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 +589 -145
- package/dist/daemon/wizard.js.map +1 -1
- package/dist/mcp/output.js +6 -5
- package/dist/mcp/output.js.map +1 -1
- package/dist/mcp/tools.js +258 -236
- package/dist/mcp/tools.js.map +1 -1
- package/dist/shared/allow-rules.js +32 -8
- 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 +374 -459
- 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 +27 -5
- package/dist/shared/cli-backends.js.map +1 -1
- package/dist/shared/config.js +122 -38
- package/dist/shared/config.js.map +1 -1
- package/dist/shared/detail-render.js +104 -21
- package/dist/shared/detail-render.js.map +1 -1
- package/dist/shared/detail-store.js.map +1 -1
- package/dist/shared/group-members.js +35 -0
- package/dist/shared/group-members.js.map +1 -0
- package/dist/shared/inject-view.js +105 -0
- package/dist/shared/inject-view.js.map +1 -0
- package/dist/shared/json-map-store.js +23 -6
- package/dist/shared/json-map-store.js.map +1 -1
- 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 +4 -3
- package/dist/shared/message-footer.js.map +1 -1
- package/dist/shared/pricing.js +5 -0
- package/dist/shared/pricing.js.map +1 -1
- package/dist/shared/reminder.js +30 -38
- package/dist/shared/reminder.js.map +1 -1
- package/dist/shared/repl-script.js +114 -26
- package/dist/shared/repl-script.js.map +1 -1
- package/dist/shared/role-render.js +209 -210
- package/dist/shared/role-render.js.map +1 -1
- package/dist/shared/role-view.js +61 -299
- 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 +81 -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 +261 -0
- package/dist/shared/room-view.js.map +1 -0
- package/dist/shared/room.js +610 -0
- package/dist/shared/room.js.map +1 -0
- package/dist/shared/session-hooks.js +58 -0
- package/dist/shared/session-hooks.js.map +1 -0
- package/dist/shared/session-label.js +80 -60
- package/dist/shared/session-label.js.map +1 -1
- package/dist/shared/session-mcp.js +77 -0
- package/dist/shared/session-mcp.js.map +1 -0
- package/dist/shared/session-skills.js +63 -0
- package/dist/shared/session-skills.js.map +1 -0
- package/dist/shared/skill-sync.js +229 -0
- package/dist/shared/skill-sync.js.map +1 -0
- package/dist/shared/smarts.js +39 -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 +76 -17
- 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 +62 -6
- package/dist/svr/index.js.map +1 -1
- package/hooks/pre-tool-use.sh +18 -0
- package/hooks/stop.sh +26 -0
- package/package.json +7 -3
- package/scripts/install.sh +11 -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.service.template +6 -0
- package/web/chat.css +70 -273
- package/web/chat.js +2228 -2190
- 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 -69
- package/dist/daemon/idle-nudge.js.map +0 -1
- package/dist/daemon/message-events.js +0 -1083
- 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
- package/hooks/hooks.json +0 -16
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
// room 模型的纯核心 (契约: docs/room/contract.md, 已拍板)。
|
|
2
|
+
//
|
|
3
|
+
// 一条总原则: **完成信号、出处、发言权都是账本行上的显式字段**, 不从 transcript / 终句 /
|
|
4
|
+
// 信封里推断。room 是唯一的沟通对象 —— 企微群 / 单聊 / topic 帖是绑定了传输的 room,
|
|
5
|
+
// wizard 之间的两人对话是不绑定传输的 dm room。人和 wizard 走同一个 append 口子。
|
|
6
|
+
//
|
|
7
|
+
// 本文件无 IO: 账本行的类型、fold (行 → 状态)、append 前的判定 (ACL / status 写入权 /
|
|
8
|
+
// 覆盖检查 / 去重 / 唤醒 / 预算)、host 求值、镜像规则、uid 与 room id 的派生。落盘在
|
|
9
|
+
// daemon/rooms.ts, 接线在 daemon/room-hub.ts。
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { expandHome } from "./paths.js";
|
|
13
|
+
import { stripLegacyTail } from "./reminder.js";
|
|
14
|
+
export const whoKey = (w) => w.kind + ":" + w.id;
|
|
15
|
+
export const sameWho = (a, b) => !!a && !!b && a.kind === b.kind && a.id === b.id;
|
|
16
|
+
export const DAEMON = { kind: "daemon", id: "wezard" };
|
|
17
|
+
const UID_RE = /^w[0-9a-f]{12}$/;
|
|
18
|
+
export const isUid = (s) => !!s && UID_RE.test(s);
|
|
19
|
+
const sha1 = (s) => createHash("sha1").update(s).digest("hex");
|
|
20
|
+
/** 实例的稳定身份 id。已落盘的 uid 永远优先 (只读); 没有的按 target + bornAt 现算 ——
|
|
21
|
+
* 迁移脚本与 daemon boot 回填走同一个函数, 算出同一个值。bornAt 缺失 (或非有限数) 时
|
|
22
|
+
* 用确定的回退 \`target|-\`, 绝不把 undefined 拼进去。 */
|
|
23
|
+
export const uidOf = (rec) => {
|
|
24
|
+
if (isUid(rec.uid))
|
|
25
|
+
return rec.uid;
|
|
26
|
+
if (!rec.target)
|
|
27
|
+
throw new Error("uidOf: target required");
|
|
28
|
+
const born = typeof rec.bornAt === "number" && Number.isFinite(rec.bornAt) ? String(rec.bornAt) : "-";
|
|
29
|
+
const uid = "w" + sha1(rec.target + "|" + born).slice(0, 12);
|
|
30
|
+
if (!isUid(uid))
|
|
31
|
+
throw new Error("uidOf: bad uid " + uid);
|
|
32
|
+
return uid;
|
|
33
|
+
};
|
|
34
|
+
/** 新建实例时铸一个 uid (调用方给随机源, 保持本文件纯)。 */
|
|
35
|
+
export const mintUid = (randomHex) => {
|
|
36
|
+
const uid = "w" + randomHex.toLowerCase().replace(/[^0-9a-f]/g, "").slice(0, 12);
|
|
37
|
+
if (!isUid(uid))
|
|
38
|
+
throw new Error("mintUid: need ≥12 hex chars");
|
|
39
|
+
return uid;
|
|
40
|
+
};
|
|
41
|
+
// ── 账本目录 ────────────────────────────────────────────────────────────
|
|
42
|
+
/** room 账本目录 = <stateDir>/rooms, 唯一推导。daemon 读、迁移写、observe 重放都必须
|
|
43
|
+
* 从这里取 —— 2026-11-19 切换失败就是迁移自己拼了 <home>/rooms 而 daemon 读 <stateDir>/rooms,
|
|
44
|
+
* 新 daemon 起来账本为空 (内存 1 / 账本重放 17)。谁都不许再本地 join 一个 rooms 出来。 */
|
|
45
|
+
export const roomsDirOf = (stateDir) => join(expandHome(stateDir), "rooms");
|
|
46
|
+
/** 两个 wizard 的 dm room: uid 排序后 \`|\` 拼接, 同一对唯一。名字 / target 绝不进 id。 */
|
|
47
|
+
export const dmRoomId = (a, b) => {
|
|
48
|
+
if (!isUid(a) || !isUid(b))
|
|
49
|
+
throw new Error("dmRoomId: both sides must be uids (got " + a + ", " + b + ")");
|
|
50
|
+
if (a === b)
|
|
51
|
+
throw new Error("dmRoomId: a wizard has no dm with itself");
|
|
52
|
+
return "dm:" + [a, b].sort().join("|");
|
|
53
|
+
};
|
|
54
|
+
export const adhocRoomId = (randomHex) => {
|
|
55
|
+
const h = randomHex.toLowerCase().replace(/[^0-9a-f]/g, "").slice(0, 8);
|
|
56
|
+
if (h.length !== 8)
|
|
57
|
+
throw new Error("adhocRoomId: need ≥8 hex chars");
|
|
58
|
+
return "adhoc:" + h;
|
|
59
|
+
};
|
|
60
|
+
/** 绑定传输的 room = base principal 原样 (\`chat:…\` / \`user:…\`, 含 \`~bot\`); 无绑定的是 dm: / adhoc:。 */
|
|
61
|
+
export const isBoundRoom = (room) => !!room && !room.startsWith("dm:") && !room.startsWith("adhoc:");
|
|
62
|
+
export const dmPeers = (room) => {
|
|
63
|
+
if (!room.startsWith("dm:"))
|
|
64
|
+
return undefined;
|
|
65
|
+
const [a, b] = room.slice(3).split("|");
|
|
66
|
+
return isUid(a) && isUid(b) ? [a, b] : undefined;
|
|
67
|
+
};
|
|
68
|
+
/** room 的 8 位 hash —— 消息 id 的前缀, 使 id 全机唯一且能反查 room。 */
|
|
69
|
+
export const roomHash = (room) => sha1("room|" + room).slice(0, 8);
|
|
70
|
+
export const msgIdOf = (room, seq) => roomHash(room) + "." + seq;
|
|
71
|
+
export const parseMsgId = (id) => {
|
|
72
|
+
const m = /^([0-9a-f]{8})\.(\d+)$/.exec((id ?? "").trim());
|
|
73
|
+
return m ? { hash: m[1], seq: Number(m[2]) } : undefined;
|
|
74
|
+
};
|
|
75
|
+
/** 关 duty 的终态。need / progress / error 不关。 */
|
|
76
|
+
export const CLOSING = new Set(["done", "passed", "canceled"]);
|
|
77
|
+
/** 公告正文上限 (字)。 */
|
|
78
|
+
export const NOTICE_MAX = 500;
|
|
79
|
+
export const HOST_SLOT = "host";
|
|
80
|
+
export const dutyKey = (msg, slot) => msg + "@" + slot;
|
|
81
|
+
export const emptyRoom = (id) => ({
|
|
82
|
+
id, seq: 0, nextOrd: 1, members: new Map(), msgs: [], byId: new Map(), duties: new Map(), everMembers: new Map(), memberLog: [],
|
|
83
|
+
});
|
|
84
|
+
const slotOfWho = (w) => whoKey(w);
|
|
85
|
+
/** 一条 msg 行开出的 duty (fold 与 judge 共用)。 */
|
|
86
|
+
export const dutiesOpenedBy = (row) => {
|
|
87
|
+
const base = { msg: row.id, seq: row.seq, asker: row.author, at: row.at,
|
|
88
|
+
...(row.after?.length ? { after: row.after } : {}), ...(row.planId ? { planId: row.planId } : {}), ...(row.for ? { for: row.for } : {}) };
|
|
89
|
+
if (row.kind === "ask" || row.kind === "task")
|
|
90
|
+
// 点名的 wizard 与人 (人名下开的 ask / task 靠人的下一句话关账, 见 judge 的 humanCloses)。
|
|
91
|
+
return (row.to ?? []).filter((t) => t.kind === "wizard" || t.kind === "human").map((t) => ({ ...base, slot: slotOfWho(t), kind: row.kind }));
|
|
92
|
+
// wizard 的 need 回复: judge 把 re 里 duty 的人提问者补进 to —— 球传到人那边, 人名下开一条 need。
|
|
93
|
+
if (row.kind === "reply" && row.status === "need" && row.author.kind === "wizard")
|
|
94
|
+
return (row.to ?? []).filter((t) => t.kind === "human").map((t) => ({ ...base, slot: slotOfWho(t), kind: "need" }));
|
|
95
|
+
if (row.kind === "join-req")
|
|
96
|
+
return [{ ...base, slot: HOST_SLOT, kind: "join-req" }];
|
|
97
|
+
// 绑定 room 里的人话: 点名开给被点名者, 没点名开给 host。
|
|
98
|
+
if (row.author.kind === "human" && row.kind === "say" && isBoundRoom(row.room) && row.origin !== "migrate") {
|
|
99
|
+
const named = (row.to ?? []).filter((t) => t.kind === "wizard");
|
|
100
|
+
return named.length ? named.map((t) => ({ ...base, slot: slotOfWho(t), kind: "human" })) : [{ ...base, slot: HOST_SLOT, kind: "human" }];
|
|
101
|
+
}
|
|
102
|
+
return [];
|
|
103
|
+
};
|
|
104
|
+
/** 单步 fold —— 就地推进 (调用方持有状态; 纯度在「同一串行 = 同一状态」上)。 */
|
|
105
|
+
export const BATCH_KEEP = 64;
|
|
106
|
+
export const applyOp = (s, op) => {
|
|
107
|
+
switch (op.op) {
|
|
108
|
+
case "open":
|
|
109
|
+
s.kind = op.kind;
|
|
110
|
+
if (op.title)
|
|
111
|
+
s.title = op.title;
|
|
112
|
+
s.openedAt ??= op.at;
|
|
113
|
+
break;
|
|
114
|
+
case "name":
|
|
115
|
+
if (op.title)
|
|
116
|
+
s.title = op.title;
|
|
117
|
+
break;
|
|
118
|
+
case "notice":
|
|
119
|
+
if (op.text.trim())
|
|
120
|
+
s.notice = op.text;
|
|
121
|
+
else
|
|
122
|
+
delete s.notice;
|
|
123
|
+
break;
|
|
124
|
+
case "join": {
|
|
125
|
+
const k = whoKey(op.who);
|
|
126
|
+
const prev = s.members.get(k);
|
|
127
|
+
if (!prev)
|
|
128
|
+
s.memberLog.push({ at: op.at, op: "join", who: op.who, by: op.by, via: op.via });
|
|
129
|
+
s.members.set(k, prev ? { ...prev, via: op.via, by: op.by } : { who: op.who, ord: op.ord, via: op.via, since: op.at, by: op.by, seen: 0, watch: false, batches: [] });
|
|
130
|
+
s.everMembers.set(k, op.who);
|
|
131
|
+
s.nextOrd = Math.max(s.nextOrd, op.ord + 1);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case "leave":
|
|
135
|
+
if (s.members.has(whoKey(op.who)))
|
|
136
|
+
s.memberLog.push({ at: op.at, op: "leave", who: op.who, by: op.by, ...(op.why ? { why: op.why } : {}) });
|
|
137
|
+
s.members.delete(whoKey(op.who));
|
|
138
|
+
break;
|
|
139
|
+
case "seen": {
|
|
140
|
+
const m = s.members.get(whoKey(op.who));
|
|
141
|
+
if (m && op.seq > m.seen)
|
|
142
|
+
m.seen = op.seq;
|
|
143
|
+
if (m && op.batch && m.batches[m.batches.length - 1] !== op.at)
|
|
144
|
+
m.batches = [...m.batches, op.at].slice(-BATCH_KEEP);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case "watch": {
|
|
148
|
+
const m = s.members.get(whoKey(op.who));
|
|
149
|
+
if (m)
|
|
150
|
+
m.watch = op.on;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case "move": {
|
|
154
|
+
const from = s.duties.get(dutyKey(op.duty, slotOfWho(op.from))) ?? s.duties.get(dutyKey(op.duty, HOST_SLOT));
|
|
155
|
+
if (!from || from.closed)
|
|
156
|
+
break;
|
|
157
|
+
s.duties.delete(from.key);
|
|
158
|
+
const key = dutyKey(op.duty, slotOfWho(op.to));
|
|
159
|
+
s.duties.set(key, { ...from, key, slot: slotOfWho(op.to), movedAt: op.at });
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case "msg": {
|
|
163
|
+
s.seq = Math.max(s.seq, op.seq);
|
|
164
|
+
s.msgs.push(op);
|
|
165
|
+
s.byId.set(op.id, op);
|
|
166
|
+
s.everMembers.set(whoKey(op.author), op.author);
|
|
167
|
+
for (const d of dutiesOpenedBy(op)) {
|
|
168
|
+
const key = dutyKey(d.msg, d.slot);
|
|
169
|
+
if (!s.duties.has(key))
|
|
170
|
+
s.duties.set(key, { ...d, key });
|
|
171
|
+
}
|
|
172
|
+
for (const key of op.closes ?? []) {
|
|
173
|
+
const d = s.duties.get(key);
|
|
174
|
+
if (d && !d.closed)
|
|
175
|
+
d.closed = { by: op.id, status: op.status ?? "done", at: op.at };
|
|
176
|
+
}
|
|
177
|
+
// 非终态 status 记在 holder 名下的那条 duty 上 (need 反向唤醒提问者的依据)。
|
|
178
|
+
if (op.kind === "reply" && op.status && !CLOSING.has(op.status))
|
|
179
|
+
for (const re of op.re ?? [])
|
|
180
|
+
for (const d of s.duties.values())
|
|
181
|
+
if (d.msg === re && !d.closed && holderMatches(s, d, op.author))
|
|
182
|
+
d.last = { status: op.status, seq: op.seq };
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return s;
|
|
187
|
+
};
|
|
188
|
+
export const foldRoom = (id, ops) => ops.reduce(applyOp, emptyRoom(id));
|
|
189
|
+
// ── host ───────────────────────────────────────────────────────────────
|
|
190
|
+
/** host = 当前 wizard 成员里加入序最小的那个; 人不参与; 每次读时算, 不落盘。
|
|
191
|
+
* undefined = 没有 wizard 成员 (人兜底 / 绑定 room 下一句人话触发 onboarding)。 */
|
|
192
|
+
export const hostOf = (members) => {
|
|
193
|
+
let best;
|
|
194
|
+
for (const m of members)
|
|
195
|
+
if (m.who.kind === "wizard" && (!best || m.ord < best.ord))
|
|
196
|
+
best = m;
|
|
197
|
+
return best?.who;
|
|
198
|
+
};
|
|
199
|
+
export const roomHost = (s) => hostOf(s.members.values());
|
|
200
|
+
/** 起名 / 改名只有当前 host 能做 (人也不行 —— 人的意见走人话)。 */
|
|
201
|
+
export const canRename = (s, who) => sameWho(roomHost(s), who);
|
|
202
|
+
/** 改公告的权限同起名: 只有当前 host。人不受此限 (人的授权在 inbound 的 allowFrom 门)。 */
|
|
203
|
+
export const canNotice = (s, who) => who.kind === "human" || canRename(s, who);
|
|
204
|
+
/** 一次改公告的裁决: 权限 + 归一化 (空白折成单空格) + 长度。空串 = 清除, 与现有相同 = changed:false。 */
|
|
205
|
+
export const judgeNotice = (s, who, raw) => {
|
|
206
|
+
if (!canNotice(s, who))
|
|
207
|
+
return { ok: false, status: 403, reason: "只有本 room 的 host 能改公告" };
|
|
208
|
+
const notice = raw.replace(/\s+/g, " ").trim();
|
|
209
|
+
if (notice.length > NOTICE_MAX)
|
|
210
|
+
return { ok: false, status: 400, reason: "公告太长 (最多 " + NOTICE_MAX + " 字, 现在 " + notice.length + ")" };
|
|
211
|
+
return { ok: true, notice, changed: notice !== (s.notice ?? "") };
|
|
212
|
+
};
|
|
213
|
+
/** duty 此刻的处理人 (host 槽位读时求值)。 */
|
|
214
|
+
export const holderOf = (s, d) => {
|
|
215
|
+
if (d.slot === HOST_SLOT)
|
|
216
|
+
return roomHost(s);
|
|
217
|
+
const i = d.slot.indexOf(":");
|
|
218
|
+
return { kind: d.slot.slice(0, i), id: d.slot.slice(i + 1) };
|
|
219
|
+
};
|
|
220
|
+
const holderMatches = (s, d, who) => sameWho(holderOf(s, d), who);
|
|
221
|
+
export const openDuties = (s) => [...s.duties.values()].filter((d) => !d.closed);
|
|
222
|
+
/** who 在这个 room 手上未关的 duty。 */
|
|
223
|
+
export const dutiesHeldBy = (s, who) => openDuties(s).filter((d) => holderMatches(s, d, who));
|
|
224
|
+
/** 人 who 的下一句话关哪些 duty (key): 它在本 room 名下全部未关的; `re` (企微引用) 命中其中几条就只关那几条 ——
|
|
225
|
+
* 引用的不是它名下的账 (引了别的消息 / 引用没对上行) 不算「指定了哪一条」, 照全关, 免得一句答话挂着账不落。 */
|
|
226
|
+
export const humanCloses = (s, who, re) => {
|
|
227
|
+
const mine = dutiesHeldBy(s, who);
|
|
228
|
+
const quoted = mine.filter((x) => re.includes(x.msg));
|
|
229
|
+
return (quoted.length ? quoted : mine).map((x) => x.key);
|
|
230
|
+
};
|
|
231
|
+
const uniqWho = (ws) => ws.filter((w, i) => ws.findIndex((x) => sameWho(x, w)) === i);
|
|
232
|
+
/** 企微的引用只带文字、不带消息 id: 把引用正文对回本 room 里的一行 (别人 / daemon 说的、正文互相包含、取最近一条)。
|
|
233
|
+
* 只比字母数字 (镜像出去的气泡带名字头、markdown 会被企微改样), 太短 (< 4 字) 不认 —— 对不上就是没引用,
|
|
234
|
+
* 人话关账按「没指定哪一条」处理 (全关)。 */
|
|
235
|
+
export const quotedRowIds = (s, quoted, author) => {
|
|
236
|
+
const canon = (t) => t.replace(/[^\p{L}\p{N}]/gu, "");
|
|
237
|
+
const q = canon(quoted);
|
|
238
|
+
if (q.length < 4)
|
|
239
|
+
return [];
|
|
240
|
+
const hit = [...s.msgs].reverse().find((m) => !sameWho(m.author, author) && m.kind !== "trigger" && ((c) => c.length >= 4 && (c.includes(q) || q.includes(c)))(canon(m.text)));
|
|
241
|
+
return hit ? [hit.id] : [];
|
|
242
|
+
};
|
|
243
|
+
/** judge 替这一行补的收话人 (进行里的 `to`, 重放不再推断):
|
|
244
|
+
* wizard 的 need 回复 → re 里它所持 duty 的**人**提问者 (fold 据此在人名下开 need);
|
|
245
|
+
* 人的话关了谁的账 → 那些账的 wizard 提问者 (仍在 room 里的): 这句就是答给它们的, 与点名同义 —— 唤醒它们、
|
|
246
|
+
* 且不再当「没点名的人话」落给 host。 */
|
|
247
|
+
const judgeAddressees = (s, d, re, status, closes) => {
|
|
248
|
+
if (d.kind === "reply" && status === "need" && d.author.kind === "wizard")
|
|
249
|
+
return uniqWho(openDuties(s).filter((x) => re.includes(x.msg) && holderMatches(s, x, d.author)).map((x) => x.asker).filter((a) => a.kind === "human"));
|
|
250
|
+
if (d.kind === "say" && d.author.kind === "human")
|
|
251
|
+
return uniqWho(closes.flatMap((k) => { const a = s.duties.get(k)?.asker; return a?.kind === "wizard" && s.members.has(whoKey(a)) ? [a] : []; }));
|
|
252
|
+
return [];
|
|
253
|
+
};
|
|
254
|
+
/** holder 在最近一次被这条 duty 唤醒之后, 是否已用 chat_reply 交代过 —— 任何 status 都算
|
|
255
|
+
* (progress / need 不关账, 但已经「交代过这一轮」, 不该再被提醒、更不该给提问者写系统行)。
|
|
256
|
+
* 按唤醒算而不按「曾经回过」: need 之后提问者补了信息再唤醒它, 那一轮仍要重新交代。 */
|
|
257
|
+
export const dutyAnswered = (s, d, who) => {
|
|
258
|
+
const touches = (r) => r.id === d.msg || (r.re ?? []).includes(d.msg);
|
|
259
|
+
const wokeAt = s.msgs.reduce((at, r) => (touches(r) && r.wake.includes(who.id) ? Math.max(at, r.seq) : at), 0);
|
|
260
|
+
return s.msgs.some((r) => r.kind === "reply" && r.seq > wokeAt && sameWho(r.author, who) && (r.re ?? []).includes(d.msg));
|
|
261
|
+
};
|
|
262
|
+
/** 2026-11-20 起 idList 修好之前, 没给 after 的 chat_ask 落成了 after:["undefined"] —— 这个假 id
|
|
263
|
+
* 不指向任何消息, 视为「没有前置」(否则前置永不满足, 被点名者永不唤醒)。 */
|
|
264
|
+
export const FAKE_AFTER_ID = "undefined";
|
|
265
|
+
/** after 前置是否全部以 done 关闭 (跨 room 的前置由调用方给查询函数)。 */
|
|
266
|
+
export const afterSatisfied = (after, closedDone) => !after?.length || after.every((id) => id === FAKE_AFTER_ID || closedDone(id));
|
|
267
|
+
/** 这条 after 只由假 id 构成 (旧 bug 的受害行, 不是真在等谁)。 */
|
|
268
|
+
export const afterIsFake = (after) => !!after?.length && after.every((id) => id === FAKE_AFTER_ID);
|
|
269
|
+
/** 带 after 的 duty 是否欠一次补唤醒 —— 欠则返回该叫的 holder。
|
|
270
|
+
* judge 在前置未满足时把 wake 落成 [] 存进行里, 之后前置关了没人重算; 而 holder 的 seen 游标可能早已
|
|
271
|
+
* 越过那一行, pending() 现算也救不回来, 所以由 daemon 追加一条 trigger 行 (新 seq, 必在游标之后)。
|
|
272
|
+
* 欠 ⇔ 前置此刻满足 ∧ duty 仍开 ∧ holder 是 wizard 成员 ∧ 账本里没有任何一行 (原 ask / re 它的行)
|
|
273
|
+
* 唤醒过 holder ∧ 没有已写给 holder 的 trigger (幂等: 预算降级也不重写) ∧ holder 从没 re 过它
|
|
274
|
+
* (它已经从游标里读到并交代过, 不必再叫)。 */
|
|
275
|
+
export const afterWakeDue = (s, d, closedDone) => {
|
|
276
|
+
if (d.closed || !d.after?.length || !afterSatisfied(d.after, closedDone))
|
|
277
|
+
return undefined;
|
|
278
|
+
const holder = holderOf(s, d);
|
|
279
|
+
if (holder?.kind !== "wizard" || !s.members.has(whoKey(holder)))
|
|
280
|
+
return undefined;
|
|
281
|
+
const touches = (r) => r.id === d.msg || (r.re ?? []).includes(d.msg);
|
|
282
|
+
const handled = s.msgs.some((r) => touches(r) && (r.wake.includes(holder.id)
|
|
283
|
+
|| (r.kind === "trigger" && (r.to ?? []).some((t) => sameWho(t, holder)))
|
|
284
|
+
|| (r.id !== d.msg && sameWho(r.author, holder))));
|
|
285
|
+
return handled ? undefined : holder;
|
|
286
|
+
};
|
|
287
|
+
/** 补唤醒 trigger 行的正文: 原 ask 可能已在 holder 的游标之前 (渲染时不会再列), 所以带上原文。 */
|
|
288
|
+
export const afterTriggerText = (ask, askerName) => (afterIsFake(ask.after)
|
|
289
|
+
? "[wezard] 补投: " + ask.id + " 当时因 after 写坏 (假 id \"undefined\") 没有唤醒你, 它其实没有前置, 现在补上。"
|
|
290
|
+
: "[wezard] 前置 " + (ask.after ?? []).join(", ") + " 已完成, " + ask.id + " 现在轮到你了。")
|
|
291
|
+
+ "\n原话 (" + ask.kind + ", 来自 " + askerName + "): " + ask.text;
|
|
292
|
+
export const msgClosedDone = (s, msg) => {
|
|
293
|
+
const ds = [...s.duties.values()].filter((d) => d.msg === msg);
|
|
294
|
+
return ds.length > 0 && ds.every((d) => d.closed?.status === "done");
|
|
295
|
+
};
|
|
296
|
+
// ── 镜像规则 (§3a) ─────────────────────────────────────────────────────
|
|
297
|
+
/** 一行进企微 ⇔ room 绑定了传输 ∧ 是 msg ∧ origin ∉ {inbound, migrate} ∧ kind ≠ trigger。没有别的例外。 */
|
|
298
|
+
export const mirrors = (row) => row.op === "msg" && isBoundRoom(row.room) && row.origin !== "inbound" && row.origin !== "migrate" && row.kind !== "trigger";
|
|
299
|
+
/** 人话行的占位气泡由**第一条** re 它且带正文的 reply 覆盖; 之后的作为新消息。 */
|
|
300
|
+
export const coversBubble = (s, row) => {
|
|
301
|
+
if (row.kind !== "reply" || !row.text.trim())
|
|
302
|
+
return undefined;
|
|
303
|
+
for (const re of row.re ?? []) {
|
|
304
|
+
const target = s.byId.get(re);
|
|
305
|
+
if (!target?.bubble)
|
|
306
|
+
continue;
|
|
307
|
+
const earlier = s.msgs.some((m) => m !== row && m.kind === "reply" && m.text.trim() && m.seq < row.seq && (m.re ?? []).includes(re));
|
|
308
|
+
if (!earlier)
|
|
309
|
+
return re;
|
|
310
|
+
}
|
|
311
|
+
return undefined;
|
|
312
|
+
};
|
|
313
|
+
export const WAKE_BUDGET = 20;
|
|
314
|
+
export const WAKE_WINDOW_MS = 10 * 60_000;
|
|
315
|
+
export const DEDUP_WINDOW_MS = 10 * 60_000;
|
|
316
|
+
const fail = (status, reason) => ({ ok: false, status, reason });
|
|
317
|
+
/** 去重键: (author, kind, text, to, re, status) —— 10 分钟内同键视为同一次发言, 返回已有行。 */
|
|
318
|
+
const dedupKey = (author, kind, text, to, re, status) => [whoKey(author), kind, sha1(text).slice(0, 12), (to ?? []).map(whoKey).sort().join(","), (re ?? []).join(","), status ?? ""].join("|");
|
|
319
|
+
/** 请求体里的 id 列表: 缺省 = []。别写成 [x].map(String) —— undefined 会变成假 id "undefined"
|
|
320
|
+
* (2026-11-20: chat_ask 没给 after 时 after=["undefined"], 前置永不算满足, 被点名的人永不唤醒)。 */
|
|
321
|
+
export const idList = (x) => x == null ? [] : (Array.isArray(x) ? x : [x]).map((v) => String(v).trim()).filter(Boolean);
|
|
322
|
+
/** 10 分钟窗内这个 room 已经花掉的唤醒数 (从账本算, 重启不丢)。 */
|
|
323
|
+
export const wakesInWindow = (s, now, windowMs = WAKE_WINDOW_MS) => s.msgs.reduce((n, m) => (now - m.at < windowMs ? n + m.wake.length + (m.interrupt ? 1 : 0) : n), 0);
|
|
324
|
+
/** reply 的 status: 显式给的原样; 没给且调用方是 re 里某条 duty 的 holder → text ? done : passed;
|
|
325
|
+
* 没给且不是 holder → undefined (普通线程回复)。 */
|
|
326
|
+
const resolveStatus = (d, holdsAny) => d.statusGiven && d.status ? d.status : holdsAny ? (d.text.trim() ? "done" : "passed") : undefined;
|
|
327
|
+
/** 判定一条发言能不能落成行; 能 → 算好 seq / id / ord / speak / closes / wake。纯函数。 */
|
|
328
|
+
export const judge = (s, d, ctx) => {
|
|
329
|
+
const member = s.members.get(whoKey(d.author));
|
|
330
|
+
const isHuman = d.author.kind === "human";
|
|
331
|
+
const isDaemon = d.author.kind === "daemon";
|
|
332
|
+
// ① 发言权 (落盘时判, 被拒不成行)
|
|
333
|
+
let speak;
|
|
334
|
+
if (isDaemon)
|
|
335
|
+
speak = "daemon";
|
|
336
|
+
else if (isHuman)
|
|
337
|
+
speak = "human";
|
|
338
|
+
else if (member)
|
|
339
|
+
speak = "member";
|
|
340
|
+
else if (d.kind === "join-req")
|
|
341
|
+
speak = "join-req";
|
|
342
|
+
else
|
|
343
|
+
return fail(403, "非成员: 先 room_join 申请入群 (或请 host / 人邀请你)");
|
|
344
|
+
if (!isDaemon && (d.kind === "system" || d.kind === "trigger"))
|
|
345
|
+
return fail(403, d.kind + " 行只有 daemon 能写");
|
|
346
|
+
if (d.kind === "join-req" && member)
|
|
347
|
+
return fail(409, "你已经是成员");
|
|
348
|
+
if (!d.text.trim() && d.kind !== "reply" && !d.files?.length)
|
|
349
|
+
return fail(400, "text required");
|
|
350
|
+
// ② re 必须都在本 room
|
|
351
|
+
const re = [...new Set(d.re ?? [])];
|
|
352
|
+
const missing = re.filter((id) => !s.byId.has(id));
|
|
353
|
+
if (missing.length)
|
|
354
|
+
return fail(400, "re 不在这个 room: " + missing.join(", "));
|
|
355
|
+
if (d.kind === "reply" && !re.length)
|
|
356
|
+
return fail(400, "reply 必须带 re");
|
|
357
|
+
// ③ status 写入权: 只有 holder (人超集; error 只有 daemon)
|
|
358
|
+
let closes = [];
|
|
359
|
+
let status;
|
|
360
|
+
if (d.kind === "reply") {
|
|
361
|
+
if (d.statusGiven && d.status === "error" && !isDaemon)
|
|
362
|
+
return fail(403, "error 只有 daemon 能写");
|
|
363
|
+
// 提问方可以撤回自己开在人名下的账 (不再需要了): 只认显式的 canceled / passed, done 仍只有人 (或人话关账) 能写。
|
|
364
|
+
const retire = !!d.statusGiven && (d.status === "canceled" || d.status === "passed");
|
|
365
|
+
const retirable = (x) => retire && holderOf(s, x)?.kind === "human" && sameWho(x.asker, d.author);
|
|
366
|
+
const mine = (id) => openDuties(s).filter((x) => x.msg === id && (isHuman || isDaemon ? true : holderMatches(s, x, d.author) || retirable(x)));
|
|
367
|
+
const holds = re.map((id) => ({ id, duties: mine(id) }));
|
|
368
|
+
const holdsAny = holds.some((h) => h.duties.length);
|
|
369
|
+
status = resolveStatus(d, holdsAny);
|
|
370
|
+
if (status && !isHuman && !isDaemon) {
|
|
371
|
+
const notMine = holds.filter((h) => !h.duties.length).map((h) => h.id);
|
|
372
|
+
if (notMine.length)
|
|
373
|
+
return fail(403, "status 只有 duty 的处理人能写; 这几条不归你 (或已关): " + notMine.join(", "));
|
|
374
|
+
}
|
|
375
|
+
if (status && CLOSING.has(status)) {
|
|
376
|
+
// ④ 覆盖检查: 提问者在线程里有 holder 还没读到的补充 → 先读
|
|
377
|
+
const holderSeen = member?.seen ?? Number.MAX_SAFE_INTEGER;
|
|
378
|
+
for (const h of holds)
|
|
379
|
+
for (const duty of h.duties) {
|
|
380
|
+
// 提问者自己撤回: 没有「提问者的补充」要先读。
|
|
381
|
+
const newer = sameWho(duty.asker, d.author) ? [] : s.msgs.filter((m) => sameWho(m.author, duty.asker) && m.seq > holderSeen && (m.re ?? []).includes(duty.msg));
|
|
382
|
+
if (newer.length && !isHuman && !isDaemon)
|
|
383
|
+
return fail(409, "先读 seq " + newer[newer.length - 1].seq + ": 提问者对 " + duty.msg + " 有你还没读到的补充");
|
|
384
|
+
closes.push(duty.key);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
else if (d.statusGiven)
|
|
389
|
+
return fail(400, "status 只用于 reply");
|
|
390
|
+
// 人话关账: 人的下一句话关掉它名下 (本 room) 未关的 duty —— 带 re 且 re 命中其中几条就只关被引用的,
|
|
391
|
+
// 否则 (没引用 / 引用的不是它的账) 全关。被关账的提问 wizard 就是这句话的收话人 (judge 补进 to, 下面)。
|
|
392
|
+
if (isHuman && d.kind === "say")
|
|
393
|
+
closes = humanCloses(s, d.author, re);
|
|
394
|
+
// ⑤ to 只认成员 (人话的 .name 点名由调用方先拉进来)
|
|
395
|
+
const given = (d.to ?? []).filter((t, i, a) => a.findIndex((x) => sameWho(x, t)) === i);
|
|
396
|
+
if (!isDaemon) {
|
|
397
|
+
const outsiders = given.filter((t) => !s.members.has(whoKey(t)));
|
|
398
|
+
if (outsiders.length)
|
|
399
|
+
return fail(409, "这些不是本 room 成员: " + outsiders.map((t) => t.id).join(", ") + " — 先邀请, 或改去 dm room");
|
|
400
|
+
}
|
|
401
|
+
if ((d.kind === "ask" || d.kind === "task") && !given.some((t) => t.kind === "wizard" || t.kind === "human"))
|
|
402
|
+
return fail(400, d.kind + " 至少点名一个 wizard 或人成员");
|
|
403
|
+
// judge 自己补的收话人 (落进行里, 重放不再推断): need → 被反问的人 (开 need duty); 人话关账 → 提问的 wizard。
|
|
404
|
+
const addressees = judgeAddressees(s, d, re, status, closes);
|
|
405
|
+
const to = [...given, ...addressees.filter((a) => !given.some((t) => sameWho(t, a)))];
|
|
406
|
+
// ⑥ interrupt 限权: 直属 parent / host / 人
|
|
407
|
+
if (d.interrupt) {
|
|
408
|
+
if (d.kind !== "ask" && d.kind !== "task" && d.kind !== "say")
|
|
409
|
+
return fail(400, "interrupt 只用于 chat_ask / chat_say");
|
|
410
|
+
const targets = to.filter((t) => t.kind === "wizard");
|
|
411
|
+
if (!targets.length)
|
|
412
|
+
return fail(400, "interrupt 要点名被打断的 wizard");
|
|
413
|
+
const host = roomHost(s);
|
|
414
|
+
const allowed = (t) => isHuman || sameWho(host, d.author) || !!ctx.isParent?.(d.author, t);
|
|
415
|
+
const denied = targets.filter((t) => !allowed(t));
|
|
416
|
+
if (denied.length)
|
|
417
|
+
return fail(403, "interrupt 只有直属 parent / 本 room 的 host / 人能用: " + denied.map((t) => t.id).join(", "));
|
|
418
|
+
}
|
|
419
|
+
// ⑦ 去重 (幂等: 返回已有行)
|
|
420
|
+
const key = dedupKey(d.author, d.kind, d.text, to, re, status);
|
|
421
|
+
const dup = [...s.msgs].reverse().find((m) => ctx.now - m.at < DEDUP_WINDOW_MS && dedupKey(m.author, m.kind, m.text, m.to, m.re, m.status) === key);
|
|
422
|
+
if (dup && d.origin !== "inbound")
|
|
423
|
+
return { ok: true, row: dup, duplicate: true, degraded: [] };
|
|
424
|
+
// ⑧ 唤醒 + 回合预算
|
|
425
|
+
const seq = s.seq + 1;
|
|
426
|
+
const draftRow = {
|
|
427
|
+
op: "msg", at: ctx.now, room: s.id, id: msgIdOf(s.id, seq), seq, author: d.author, ord: member?.ord ?? 0, speak,
|
|
428
|
+
kind: d.kind, text: d.text, ...(to.length ? { to } : {}), ...(re.length ? { re } : {}), ...(status ? { status } : {}),
|
|
429
|
+
...(closes.length ? { closes } : {}), wake: [], ...(d.interrupt ? { interrupt: true } : {}),
|
|
430
|
+
...(d.for ? { for: d.for } : {}), ...(d.after?.length ? { after: d.after } : {}), ...(d.planId ? { planId: d.planId } : {}),
|
|
431
|
+
...(d.files?.length ? { files: d.files } : {}), origin: d.origin, ...(d.ext ? { ext: d.ext } : {}),
|
|
432
|
+
...(d.bubble ? { bubble: d.bubble } : {}), ...(d.sys ? { sys: d.sys } : {}),
|
|
433
|
+
};
|
|
434
|
+
const want = wakeTargets(s, draftRow, ctx);
|
|
435
|
+
const budget = ctx.budget ?? WAKE_BUDGET;
|
|
436
|
+
const used = wakesInWindow(s, ctx.now);
|
|
437
|
+
if (d.interrupt && used + want.length + 1 > budget)
|
|
438
|
+
return fail(409, "本 room 10 分钟内的唤醒预算 (" + budget + ") 已用完, interrupt 不放行");
|
|
439
|
+
const room = Math.max(0, budget - used);
|
|
440
|
+
const wake = want.slice(0, room);
|
|
441
|
+
const degraded = want.slice(room);
|
|
442
|
+
return { ok: true, row: { ...draftRow, wake }, degraded };
|
|
443
|
+
};
|
|
444
|
+
/** 这一行该唤醒谁 (wizard uid, 不含作者自己)。B-3: 点名 + host 兜底 + 订阅, 其余只推游标。
|
|
445
|
+
* 人话关了谁名下的账, 谁 (提问者) 就在 `to` 里 (judge 补的, 见 judgeAddressees) —— 走 named, 与 host 兜底天然去重。 */
|
|
446
|
+
export const wakeTargets = (s, row, ctx = {}) => {
|
|
447
|
+
const out = [];
|
|
448
|
+
const add = (w) => {
|
|
449
|
+
if (w?.kind === "wizard" && !sameWho(w, row.author) && !out.includes(w.id))
|
|
450
|
+
out.push(w.id);
|
|
451
|
+
};
|
|
452
|
+
const named = (row.to ?? []).filter((t) => t.kind === "wizard");
|
|
453
|
+
const closedDone = ctx.closedDone ?? ((m) => msgClosedDone(s, m));
|
|
454
|
+
switch (row.kind) {
|
|
455
|
+
case "ask":
|
|
456
|
+
case "task":
|
|
457
|
+
if (afterSatisfied(row.after, closedDone))
|
|
458
|
+
named.forEach(add);
|
|
459
|
+
break;
|
|
460
|
+
case "join-req":
|
|
461
|
+
add(roomHost(s));
|
|
462
|
+
break;
|
|
463
|
+
case "reply": {
|
|
464
|
+
if (row.status === "progress")
|
|
465
|
+
break;
|
|
466
|
+
for (const id of row.re ?? [])
|
|
467
|
+
add(s.byId.get(id)?.author);
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
case "trigger":
|
|
471
|
+
named.forEach(add);
|
|
472
|
+
break;
|
|
473
|
+
default:
|
|
474
|
+
named.forEach(add);
|
|
475
|
+
// 绑定 room 里没点名的人话 → host
|
|
476
|
+
if (row.author.kind === "human" && !named.length && isBoundRoom(row.room))
|
|
477
|
+
add(roomHost(s));
|
|
478
|
+
}
|
|
479
|
+
// 订阅 (B-3): 只在人话 / 带终态的 reply 时唤醒订阅者
|
|
480
|
+
const watchable = (row.author.kind === "human" && row.kind === "say") || (row.kind === "reply" && !!row.status && CLOSING.has(row.status));
|
|
481
|
+
if (watchable)
|
|
482
|
+
for (const m of s.members.values())
|
|
483
|
+
if (m.watch)
|
|
484
|
+
add(m.who);
|
|
485
|
+
return out;
|
|
486
|
+
};
|
|
487
|
+
// ── 离开 (§4): 手上的 duty 由 daemon 写 canceled, 唤醒提问者 ──────────
|
|
488
|
+
/** 成员离开要落的行: 每条它名下 (静态槽位) 未关的 duty 一行 canceled reply, 然后 leave。
|
|
489
|
+
* host 槽位的 duty 不取消 —— 它们随 host 求值自然落到下一位。 */
|
|
490
|
+
export const leaveOps = (s, who, by, now, why = "") => {
|
|
491
|
+
const mine = openDuties(s).filter((d) => d.slot !== HOST_SLOT && d.slot === whoKey(who));
|
|
492
|
+
const byMsg = new Map();
|
|
493
|
+
for (const d of mine)
|
|
494
|
+
byMsg.set(d.msg, [...(byMsg.get(d.msg) ?? []), d]);
|
|
495
|
+
let seq = s.seq;
|
|
496
|
+
const rows = [...byMsg.entries()].map(([msg, ds]) => {
|
|
497
|
+
seq += 1;
|
|
498
|
+
const asker = ds[0].asker;
|
|
499
|
+
return {
|
|
500
|
+
op: "msg", at: now, room: s.id, id: msgIdOf(s.id, seq), seq, author: DAEMON, ord: 0, speak: "daemon",
|
|
501
|
+
kind: "reply", text: "[wezard] " + who.id + " 已离开" + (why ? " (" + why + ")" : "") + ", 这条没有答案了", re: [msg],
|
|
502
|
+
status: "canceled", closes: ds.map((d) => d.key), wake: asker.kind === "wizard" && !sameWho(asker, who) ? [asker.id] : [],
|
|
503
|
+
origin: "daemon", sys: "left",
|
|
504
|
+
};
|
|
505
|
+
});
|
|
506
|
+
return [...rows, { op: "leave", at: now, room: s.id, who, by, ...(why ? { why } : {}) }];
|
|
507
|
+
};
|
|
508
|
+
const statusTag = (m) => (m.status ? " [" + m.status + "]" : "");
|
|
509
|
+
/** 行正文的读法: 人话行 (origin inbound) 曾把提醒尾巴一起写进 text, 老行不改写、读侧剥掉 (见 stripLegacyTail);
|
|
510
|
+
* 新行只存原话, 剥一遍是空操作。只有 inbound 行带过尾巴, 别的来源的 text 原样返回。 */
|
|
511
|
+
export const rowText = (m) => (m.origin === "inbound" ? stripLegacyTail(m.text) : m.text);
|
|
512
|
+
export const renderMsgLine = (m, n, max = 500) => {
|
|
513
|
+
const to = m.to?.length ? " → " + m.to.map(n.nameOf).join(", ") : "";
|
|
514
|
+
const re = m.re?.length ? " (re " + m.re.join(",") + ")" : "";
|
|
515
|
+
const body = rowText(m).replace(/\s+/g, " ").trim();
|
|
516
|
+
const files = m.files?.length ? " 📎" + m.files.map((f) => f.name).join(",") : "";
|
|
517
|
+
return "[" + m.id + "] " + n.nameOf(m.author) + to + re + statusTag(m) + ": " + (body.length > max ? body.slice(0, max) + "…(+" + (body.length - max) + ")" : body) + files;
|
|
518
|
+
};
|
|
519
|
+
/** who 的游标之后、别人说的行数 (不含自己) —— rolepage 的未读角标; 与 unreadFor 同一口径, 不装预算。 */
|
|
520
|
+
export const unreadCount = (s, who) => {
|
|
521
|
+
const seen = s.members.get(whoKey(who))?.seen ?? 0;
|
|
522
|
+
return s.msgs.reduce((n, m) => (m.seq > seen && !sameWho(m.author, who) ? n + 1 : n), 0);
|
|
523
|
+
};
|
|
524
|
+
export const UNREAD_BUDGET = 6000;
|
|
525
|
+
/** 游标之后、who 没看过的行 (不含自己说的), 触发行全文, 其余从新到旧装到预算为止。 */
|
|
526
|
+
export const unreadFor = (s, who, triggers = [], budget = UNREAD_BUDGET) => {
|
|
527
|
+
const seen = s.members.get(whoKey(who))?.seen ?? 0;
|
|
528
|
+
const eligible = s.msgs.filter((m) => m.seq > seen && !sameWho(m.author, who));
|
|
529
|
+
const picked = [];
|
|
530
|
+
let used = 0;
|
|
531
|
+
for (let i = eligible.length - 1; i >= 0; i--) {
|
|
532
|
+
const m = eligible[i];
|
|
533
|
+
const cost = triggers.includes(m.id) ? 0 : Math.min(rowText(m).length, 500);
|
|
534
|
+
if (picked.length && used + cost > budget && !triggers.includes(m.id))
|
|
535
|
+
continue;
|
|
536
|
+
picked.unshift(m);
|
|
537
|
+
used += cost;
|
|
538
|
+
}
|
|
539
|
+
return { rows: picked, more: eligible.length - picked.length, to: s.seq };
|
|
540
|
+
};
|
|
541
|
+
/** 入座时的初始 seen 游标 (null = 不写, 保持 0 = 全部可读); 输入不合法 → {error}。纯函数。
|
|
542
|
+
* seen 只往前推, 所以新成员 (从 0 起) 写这条 seen 就等于「只看游标之后」。 */
|
|
543
|
+
export const historyCursor = (s, history) => {
|
|
544
|
+
if (history === undefined || history === null || history === "" || history === "all")
|
|
545
|
+
return null;
|
|
546
|
+
if (history === "none")
|
|
547
|
+
return s.seq;
|
|
548
|
+
const asNum = typeof history === "number" ? history : typeof history === "string" && /^\d+$/.test(history.trim()) ? Number(history) : NaN;
|
|
549
|
+
if (Number.isFinite(asNum)) {
|
|
550
|
+
if (!Number.isInteger(asNum) || asNum < 1)
|
|
551
|
+
return { error: "history 的数字要是正整数 (得到 " + asNum + ")" };
|
|
552
|
+
return s.msgs.length <= asNum ? null : s.msgs[s.msgs.length - asNum].seq - 1;
|
|
553
|
+
}
|
|
554
|
+
if (typeof history === "string" && history.startsWith("from:")) {
|
|
555
|
+
const row = s.byId.get(history.slice(5).trim());
|
|
556
|
+
return row ? row.seq - 1 : { error: "history 的 from: 指向的消息不在本 room: " + history.slice(5) };
|
|
557
|
+
}
|
|
558
|
+
return { error: 'history 取值: "none" | 正整数 N | "from:<msgId>" | "all"' };
|
|
559
|
+
};
|
|
560
|
+
/** 入座那一批 op 后面跟的 seen (游标 ≤ 0 或 null 时没有)。 */
|
|
561
|
+
export const seatSeenOps = (s, who, at, history) => {
|
|
562
|
+
const c = historyCursor(s, history);
|
|
563
|
+
if (c !== null && typeof c === "object")
|
|
564
|
+
return c;
|
|
565
|
+
return c ? [{ op: "seen", at, room: s.id, who, seq: c }] : [];
|
|
566
|
+
};
|
|
567
|
+
/** dm:A|B 现状 → 怎么用: 不存在 → 建; 只有 A/B → 用 (缺人先补回); 混进第三人 → 不再落进它, 另找 / 另开 adhoc。 */
|
|
568
|
+
export const planDm = (s, a, b) => {
|
|
569
|
+
if (!s)
|
|
570
|
+
return { kind: "create" };
|
|
571
|
+
const ms = [...s.members.values()].map((m) => m.who);
|
|
572
|
+
if (ms.some((w) => !(w.kind === "wizard" && (w.id === a || w.id === b))))
|
|
573
|
+
return { kind: "pair-adhoc" };
|
|
574
|
+
const missing = [a, b].filter((u) => !s.members.has(whoKey({ kind: "wizard", id: u })));
|
|
575
|
+
return missing.length ? { kind: "rejoin", missing } : { kind: "use" };
|
|
576
|
+
};
|
|
577
|
+
/** 在 adhoc room 里找当前成员恰好等于 uids (wizard uid 集合, 顺序无关) 的那个; 多个取最近活动 (最后一条消息, 无则 open) 的。 */
|
|
578
|
+
export const findSetAdhoc = (states, uids) => {
|
|
579
|
+
const want = new Set(uids.map((u) => whoKey({ kind: "wizard", id: u })));
|
|
580
|
+
return states
|
|
581
|
+
.filter((s) => s.id.startsWith("adhoc:") && s.members.size === want.size && [...want].every((k) => s.members.has(k)))
|
|
582
|
+
.map((s) => ({ id: s.id, at: s.msgs.length ? s.msgs[s.msgs.length - 1].at : s.openedAt ?? 0 }))
|
|
583
|
+
.sort((x, y) => y.at - x.at)[0]?.id;
|
|
584
|
+
};
|
|
585
|
+
/** 两人的特例。 */
|
|
586
|
+
export const findPairAdhoc = (states, a, b) => findSetAdhoc(states, [a, b]);
|
|
587
|
+
/** parent 是不是 child 的直属 parent (judge ⑥ interrupt 限权的判据; hub 与自动 adhoc 落点共用)。 */
|
|
588
|
+
export const isDirectParent = (parentUidOf, parent, child) => parent.kind === "wizard" && child.kind === "wizard" && parentUidOf(child.id) === parent.id;
|
|
589
|
+
/** 「你要交代」的用法提示这次该不该附: 它最近 window 次成功唤醒批次 (跨 room 按 at 去重) 里写过任何 chat_reply 行 → 不附; 批次不足 window / 窗口内没写过 / window ≤ 0 → 附。
|
|
590
|
+
* states = 它所在的各 room; 只从尾往前扫到窗口起点为止。 */
|
|
591
|
+
export const replyHintDue = (states, uid, window) => {
|
|
592
|
+
if (window <= 0)
|
|
593
|
+
return true;
|
|
594
|
+
const me = whoKey({ kind: "wizard", id: uid });
|
|
595
|
+
const ats = [...new Set(states.flatMap((s) => s.members.get(me)?.batches ?? []))].sort((a, b) => b - a);
|
|
596
|
+
if (ats.length < window)
|
|
597
|
+
return true;
|
|
598
|
+
const cutoff = ats[window - 1];
|
|
599
|
+
return !states.some((s) => {
|
|
600
|
+
for (let i = s.msgs.length - 1; i >= 0; i--) {
|
|
601
|
+
const r = s.msgs[i];
|
|
602
|
+
if (r.at < cutoff)
|
|
603
|
+
return false;
|
|
604
|
+
if (r.kind === "reply" && r.author.kind === "wizard" && r.author.id === uid)
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
return false;
|
|
608
|
+
});
|
|
609
|
+
};
|
|
610
|
+
//# sourceMappingURL=room.js.map
|