wezard 2.9.0 → 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.md +34 -15
- package/README.md +36 -49
- package/cli/wezard.sh +3 -0
- package/config.example.jsonc +2 -8
- package/dist/cli/init.js +35 -0
- 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.map +1 -1
- package/dist/daemon/apprentice.js +75 -0
- package/dist/daemon/apprentice.js.map +1 -0
- package/dist/daemon/approval.js +26 -7
- 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-posts.js +53 -0
- package/dist/daemon/channel-posts.js.map +1 -0
- package/dist/daemon/channel.js +124 -12
- 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/classes.js +418 -0
- package/dist/daemon/classes.js.map +1 -0
- package/dist/daemon/config-api.js +1 -1
- package/dist/daemon/detail.js +14 -8
- package/dist/daemon/detail.js.map +1 -1
- package/dist/daemon/handoff.js +51 -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 +360 -142
- package/dist/daemon/inbound.js.map +1 -1
- package/dist/daemon/index.js +2172 -2676
- 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 +511 -467
- 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/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 +48 -36
- 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 +6 -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 +247 -242
- 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 +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 +13 -5
- package/dist/shared/cli-backends.js.map +1 -1
- package/dist/shared/config.js +48 -24
- package/dist/shared/config.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/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/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/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 +20 -8
- package/dist/shared/session-hooks.js.map +1 -1
- package/dist/shared/session-label.js +80 -60
- package/dist/shared/session-label.js.map +1 -1
- package/dist/shared/session-mcp.js +21 -3
- 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 +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 +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 +62 -6
- package/dist/svr/index.js.map +1 -1
- package/hooks/stop.sh +26 -0
- package/package.json +7 -2
- 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 -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,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { envelopeFor, parseEnvelope, renderTail } from "../shared/reminder.js";
|
|
2
|
+
import { turnOpening } from "./turn-opening.js";
|
|
3
|
+
import { charterInContext, charterPreamble, charterToRearm } from "../shared/charter-rearm.js";
|
|
3
4
|
import { codexSessions, codexSessionForPane, recordCodexPaneSession } from "../shared/codex.js";
|
|
4
5
|
import { codexHookLaunchArgs, codexHookCommand, inspectCodexHooks, trustCodexHookSet } from "../shared/codex-hooks.js";
|
|
5
6
|
import { fileURLToPath } from "node:url";
|
|
@@ -28,31 +29,34 @@ import { augmentedPath } from "../shared/exec-path.js";
|
|
|
28
29
|
import { sleep, truncateWithCount, mapLimit, clipLine } from "../shared/std.js";
|
|
29
30
|
import { withImageClipboard, pasteVerifiedImage } from "./image-input.js";
|
|
30
31
|
import { createKeyedScheduler } from "../shared/keyed-scheduler.js";
|
|
31
|
-
import { withPaneInput } from "./pane-input.js";
|
|
32
|
+
import { PaneInputError, withPaneInput } from "./pane-input.js";
|
|
32
33
|
import { activeBackends, resolveCliBackend, backendForPath, projectDirFor, projectDirsFor, } from "../shared/cli-backends.js";
|
|
33
34
|
import { isModalPane, isCodexHookReviewPane, isAskqSubmitPage, parseModalOptions, pickModalAnswer, pickAutoAllowAnswer, parseConfirmContext, modalFingerprint, modalCallFingerprint, looksLikePicker } from "../shared/modal-pane.js";
|
|
35
|
+
import { loadJsonMap } from "../shared/json-map-store.js";
|
|
36
|
+
import { paneIdentityMatches, paneReclaimMatches } from "./mirror-store.js";
|
|
34
37
|
import { hasMirrorAskq, mootMirrorAskq, runMirrorAskqFlow, hasMirrorPlan, mootMirrorPlan, runMirrorPlanFlow, hasMirrorPicker, mootMirrorPicker, runMirrorPickerFlow } from "./approval.js";
|
|
35
38
|
import { replAskqInput } from "../shared/repl-script.js";
|
|
36
39
|
import { isAutoWindowActive } from "./session-cache.js";
|
|
37
40
|
import { noticeSuffixFor } from "./notices.js";
|
|
38
41
|
import { dispatchPickerPolicy, pickerPolicy, pressNoticeOf } from "./picker-policy.js";
|
|
42
|
+
import { idleSkipReason, lastActiveOf, paneBornAt } from "./idle-reap.js";
|
|
39
43
|
import { markManagedPane, renameWindow, runTmux, sparePoolFencedSids, spawnTmuxClaude } from "./spawn-tmux.js";
|
|
40
44
|
import { prepareSessionHooks, sessionHookArgs } from "../shared/session-hooks.js";
|
|
41
45
|
import { prepareSessionSkills, sessionSkillArgs } from "../shared/session-skills.js";
|
|
42
46
|
import { selectEffort, selectModel } from "./model-select.js";
|
|
43
47
|
import { parseEffort } from "../shared/effort.js";
|
|
44
|
-
import { hasRegistry, liveSessionPids, markTranscript, probeOf, readRegistry, registrySnapshot, sessionOfPid, sessionOnPane, submittedSince, submittedEventSince, watchRegistry } from "./wezard-session.js";
|
|
48
|
+
import { hasRegistry, liveSessionPids, markTranscript, probeOf, readRegistry, registrySnapshot, sessionBySid, sessionOfPid, sessionOnPane, submittedSince, submittedEventSince, watchRegistry } from "./wezard-session.js";
|
|
45
49
|
import { waitForIdle } from "./wait-idle.js";
|
|
46
|
-
import { wizardStore } from "./wizard.js";
|
|
50
|
+
import { manifestationOf, wizardStore } from "./wizard.js";
|
|
47
51
|
import { startSubagentWatch } from "./subagent-tail.js";
|
|
48
52
|
import { getDetail, knowsToolUse, recordTool, recordToolResult, recordMark, recordTurnStart, recordTurnQuery, recordTurnInject, recordTurnItem, recordTurnUsage, recordTurnClose, recordCloseOpenTurns, lastChannelOf, openTurnsOf, buildDetailUrl, buildChatUrl, roleUniq, markTurnTextFinal } from "./detail.js";
|
|
49
53
|
import { errText } from "./last-response.js";
|
|
50
|
-
import { labelFor, tagOfKey, baseOfKey, stripSigil, displayName, windowLabel, withTagHeader, withLinkedTagHeader, chatHead, headed, tagBadge, parseTagHeader, MAX_BODY_LINKS, isInternalKey, sameBot } from "../shared/session-label.js";
|
|
54
|
+
import { labelFor, tagOfKey, baseOfKey, stripSigil, displayName, createdAck, windowLabel, withTagHeader, withLinkedTagHeader, chatHead, headed, tagBadge, parseTagHeader, MAX_BODY_LINKS, isInternalKey, sameBot } from "../shared/session-label.js";
|
|
51
55
|
import { splitMarkdown } from "../shared/md-chunk.js";
|
|
52
56
|
import { readHookMode } from "../shared/hook-mode.js";
|
|
53
57
|
import { isWxFrame } from "../shared/wx-text.js";
|
|
54
58
|
import { chatNameOf, listChatNames, peerAddress } from "./chat-name.js";
|
|
55
|
-
import { stripAnsi, paneIsBusy, codexTurnBusy, summarizeTail, lastAssistantText, lastReply, replyToPeer as replyToPeerIn, unwrapPasted, lastContextTokens, lastModel, lastUserTurn, talkRounds, openToolUses, turnClosed, renderDialog
|
|
59
|
+
import { stripAnsi, paneIsBusy, lastRecordMs, codexTurnBusy, summarizeTail, lastAssistantText, lastReply, replyToPeer as replyToPeerIn, unwrapPasted, lastContextTokens, lastModel, lastUserTurn, talkRounds, openToolUses, turnClosed, renderDialog } from "./peers.js";
|
|
56
60
|
// PATH augmentation: launchd / systemd start the daemon
|
|
57
61
|
// with a stripped PATH that often lacks nvm / homebrew, breaking spawn(claudeBin).
|
|
58
62
|
// Backend resolution is per-transcript, not global: `backendForPath` recovers
|
|
@@ -326,7 +330,7 @@ const renderTaskNotification = (block) => {
|
|
|
326
330
|
const cleanUserText = (wrapped) => {
|
|
327
331
|
// 多行注入落盘时被 CLI 包了一层 `<pasted_content>` (见 peers.unwrapPasted) —— 先剥,
|
|
328
332
|
// 否则回显去重对不上, 我们自己注入的那一行会被认成「人在 CLI 里敲的」, 整轮回复
|
|
329
|
-
// 因此被
|
|
333
|
+
// 因此被 出处门 挡在群外 (公开的 chat_ask / 定时任务的多行提示全中)。
|
|
330
334
|
const raw = unwrapPasted(wrapped);
|
|
331
335
|
const nameMatch = raw.match(SLASH_TAG_RE);
|
|
332
336
|
const slashCmd = nameMatch?.[1]?.trim() ?? "";
|
|
@@ -784,11 +788,12 @@ const renderLine = (raw, deps) => {
|
|
|
784
788
|
};
|
|
785
789
|
// Block-wise packing (shared/md-chunk): never cuts mid-line, and never cuts a
|
|
786
790
|
// fenced block or table in a way that breaks rendering — see splitMarkdown.
|
|
787
|
-
// Room reserved in every chunk for the signed
|
|
791
|
+
// Room reserved in every chunk for the signed `🧙♂️ name` / `2/5` header line and
|
|
788
792
|
// the chat-detail links linkTags hangs on it and on up to MAX_BODY_LINKS body
|
|
789
793
|
// mentions — each `(url)` runs ~200-250 bytes. 头里最多两条: 自己的, 以及公开 peer 轮
|
|
790
|
-
// 的 `→
|
|
791
|
-
|
|
794
|
+
// 的 `→ 🧙♂️ 对方`。v3 起头从 `.name` 换成 `🧙♂️ name` (每条约 +13 字节, ZWJ 序列 12
|
|
795
|
+
// 字节 + 空格), 预算加 64 字帖余量; md-chunk 按行块切, 不会把序列切成两半。
|
|
796
|
+
const TAG_HEADER_BUDGET = 256 * (2 + MAX_BODY_LINKS) + 64;
|
|
792
797
|
export const startMirrorTail = (deps) => {
|
|
793
798
|
const { log } = deps;
|
|
794
799
|
// Codex records model/effort separately from per-response usage. Keep that
|
|
@@ -934,8 +939,8 @@ export const startMirrorTail = (deps) => {
|
|
|
934
939
|
};
|
|
935
940
|
};
|
|
936
941
|
const parsePaneList = (out) => new Map(out.split("\n").flatMap((line) => {
|
|
937
|
-
const [id,
|
|
938
|
-
return id?.startsWith("%") ? [[id,
|
|
942
|
+
const [id, cwd = "", window = "", pid = ""] = line.trim().split("\t");
|
|
943
|
+
return id?.startsWith("%") ? [[id, { cwd, window, pid }]] : [];
|
|
939
944
|
}));
|
|
940
945
|
// Stable JSON: sort object keys recursively. Used to fingerprint a tool_use's
|
|
941
946
|
// `input` so the hook-side and the jsonl-side compute the same signature even
|
|
@@ -1422,10 +1427,26 @@ const paneLiveness = async (paneId) => {
|
|
|
1422
1427
|
const r = await runTmux(["display-message", "-p", "-t", paneId, "#{pane_id}"]);
|
|
1423
1428
|
if (r.timedOut || r.code === null)
|
|
1424
1429
|
return "unknown";
|
|
1425
|
-
if (r.code === 0)
|
|
1426
|
-
|
|
1430
|
+
if (r.code === 0) {
|
|
1431
|
+
const out = r.stdout.trim();
|
|
1432
|
+
if (out === paneId)
|
|
1433
|
+
return "alive";
|
|
1434
|
+
// tmux 3.6a 实测 (2026-11-19): 解析不到的目标仍退 0, 只把格式串展开成空, 而旧版报
|
|
1435
|
+
// "can't find pane" 退 1。活着的 pane 上 #{pane_id} 永远有值 —— 空回答 = 没这个
|
|
1436
|
+
// pane, 回了别的 id 才是「问不出定论」。判成 unknown 会让死 pane 永远不重生。
|
|
1437
|
+
return out ? "unknown" : "gone";
|
|
1438
|
+
}
|
|
1427
1439
|
return "gone"; // "can't find pane: %N" / "no server running" —— 两条都等于它没了
|
|
1428
1440
|
};
|
|
1441
|
+
/** 现查一块 pane 的窗口名 + shell pid (restore 的懒路径; boot 走 list-panes 快照)。
|
|
1442
|
+
* 空输出 = 问不出来 (死 pane / 解析不到) → undefined, 调用方按「对不上」处理。 */
|
|
1443
|
+
const paneIdentityOf = async (paneId) => {
|
|
1444
|
+
const r = await runTmux(["display-message", "-p", "-t", paneId, "#{window_name}\t#{pane_pid}"]);
|
|
1445
|
+
if (!r.ok)
|
|
1446
|
+
return undefined;
|
|
1447
|
+
const [window = "", pid = ""] = r.stdout.trim().split("\t");
|
|
1448
|
+
return window && pid ? { window, pid } : undefined;
|
|
1449
|
+
};
|
|
1429
1450
|
/** 沿 ps 快照从某个 pid 往下找「会话注册表登记过、进程还活着」的那个 pid。注册表没有
|
|
1430
1451
|
* `tmux` 字段的后端 (codebuddy) 只能这样把 pane 和进程对上: pane_pid 是 shell, CLI 是
|
|
1431
1452
|
* 它的子孙。认不出返回 undefined。 */
|
|
@@ -1497,6 +1518,15 @@ const paneHasLiveSession = async (paneId, homeDir, panePid, ps) => {
|
|
|
1497
1518
|
};
|
|
1498
1519
|
/** 注入前问 pane 一句话: 还在吗 / 里面还有 AI 会话吗。
|
|
1499
1520
|
* `unknown` 必须由调用方按「不知道」处理 —— 不许当 pane 死了去重生。 */
|
|
1521
|
+
/** A resume respawn whose transcript is gone can only die at the CLI's
|
|
1522
|
+
* "No conversation found" — after opening a pane, which, as the shared
|
|
1523
|
+
* session's lone window, takes the whole `wezard` session down with it. The
|
|
1524
|
+
* binding is kept on purpose (f113e25: only a human /new replaces a session),
|
|
1525
|
+
* so every retry would replay that; answer it here instead, non-retryable.
|
|
1526
|
+
* Codex rollouts are prepared by its own app-server, not resumed by path. */
|
|
1527
|
+
const resumeTranscriptMissing = (jsonlPath, cli) => cli !== "codex" && jsonlPath && !existsSync(jsonlPath)
|
|
1528
|
+
? `会话转录已不存在 (${basename(jsonlPath)}), 无法 resume; 发 /new 开新会话`
|
|
1529
|
+
: undefined;
|
|
1500
1530
|
const probePane = async (paneId, jsonlPath) => {
|
|
1501
1531
|
const live = await paneLiveness(paneId);
|
|
1502
1532
|
if (live !== "alive")
|
|
@@ -2291,6 +2321,10 @@ const INJECT_JOB_TIMEOUT_MS = 90_000;
|
|
|
2291
2321
|
/** 没有绑定的 pane 静默多久才算孤儿。刚 spawn、还没 attach 的 pane (并发 fan-out 时
|
|
2292
2322
|
* 别人的 sweep 会撞见它) 在这段时间里一直有输出, 远大于一次 spawn → attach 的耗时。 */
|
|
2293
2323
|
const ORPHAN_GRACE_MS = 10 * 60_000;
|
|
2324
|
+
/** pane 上限回收里「最近有人说过话」的口径: transcript 一天内动过的 target 只 detach
|
|
2325
|
+
* 不 kill —— pane 和 CLI 留着 (绑定也没动), 下一条消息 / 下次 reload 按 %N 或窗口名+pid
|
|
2326
|
+
* 直接认回; 为省内存把活会话整个换代码, 代价是 --resume fork 一代新 jsonl。 */
|
|
2327
|
+
const RECENT_TALK_MS = 24 * 3600_000;
|
|
2294
2328
|
/** ps 的 `etime` ([[dd-]hh:]mm:ss) → 秒; 认不出 = NaN。 */
|
|
2295
2329
|
const etimeSec = (s) => {
|
|
2296
2330
|
const m = /^(?:(\d+)-)?(?:(\d+):)?(\d+):(\d+)$/.exec(s);
|
|
@@ -2349,6 +2383,24 @@ export const startMirror = (deps) => {
|
|
|
2349
2383
|
// replace too (one WeCom chat can only show one mirror at a time).
|
|
2350
2384
|
const bySessionId = new Map();
|
|
2351
2385
|
const byTarget = new Map();
|
|
2386
|
+
// 本进程亲眼见到的最后一次活动 (注入落进 pane / tail 读到任何条目, 含轮结束) —— 空闲回收
|
|
2387
|
+
// 的时钟。不单靠 transcript mtime: 长工具调用期间它一直安静, 而注入在落盘之前就发生了。
|
|
2388
|
+
// 只在内存里: reload 后空着, 回落到 mtime (那时真在跑的 pane 还有截屏判忙兜着)。
|
|
2389
|
+
const seenAt = new Map();
|
|
2390
|
+
const touch = (target) => { seenAt.set(target, Date.now()); };
|
|
2391
|
+
/** transcript 里最后一条真记录的时刻; 没有 (刚起) 才回落 mtime; 0 = 认不出。mtime 不可信:
|
|
2392
|
+
* 闲置会话的 jsonl 会被外部碰新, 见 `lastRecordMs`。 */
|
|
2393
|
+
const transcriptActiveAt = (target) => {
|
|
2394
|
+
const jsonl = jsonlOf(target);
|
|
2395
|
+
if (!jsonl)
|
|
2396
|
+
return 0;
|
|
2397
|
+
return lastRecordMs(jsonl) || (() => { try {
|
|
2398
|
+
return statSync(jsonl).mtimeMs;
|
|
2399
|
+
}
|
|
2400
|
+
catch {
|
|
2401
|
+
return 0;
|
|
2402
|
+
} })();
|
|
2403
|
+
};
|
|
2352
2404
|
// Ring buffer of recently-injected user texts to suppress WeCom→CLI echo.
|
|
2353
2405
|
const INJECT_TTL_MS = 60_000;
|
|
2354
2406
|
const recentInjects = [];
|
|
@@ -2465,88 +2517,10 @@ export const startMirror = (deps) => {
|
|
|
2465
2517
|
turnRegistry.delete(k);
|
|
2466
2518
|
};
|
|
2467
2519
|
const TOOL_DETAIL_PREFIX = "TOOL_DETAIL|";
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
const
|
|
2472
|
-
const event = id ? deps.events?.get(id) : undefined;
|
|
2473
|
-
return !event || eventOwnerGate(event);
|
|
2474
|
-
};
|
|
2475
|
-
const briefMode = (a) => cfg.wrc.mirror.brief
|
|
2476
|
-
|| !!(a.activeEventId && (deps.events?.get(a.activeEventId)?.payload.peer?.transferred || deps.events?.get(a.activeEventId)?.payload.peer?.from.receipt));
|
|
2477
|
-
const bubbleOwned = (a, b) => {
|
|
2478
|
-
const event = b.owner ? deps.events?.get(b.owner) : undefined;
|
|
2479
|
-
return !event || event.target === a.target && eventOwnerGate(event);
|
|
2480
|
-
};
|
|
2481
|
-
const replyBubbles = new Map();
|
|
2482
|
-
const rememberReplyBubble = (id, bubble) => {
|
|
2483
|
-
if (replyBubbles.has(id))
|
|
2484
|
-
return;
|
|
2485
|
-
replyBubbles.set(id, bubble);
|
|
2486
|
-
setTimeout(() => { if (replyBubbles.get(id) === bubble)
|
|
2487
|
-
replyBubbles.delete(id); }, Math.max(0, (bubble.expires ?? Date.now()) - Date.now()) + 60_000).unref?.();
|
|
2488
|
-
};
|
|
2489
|
-
const claimReplyBubble = (event) => {
|
|
2490
|
-
if (!deps.events || !eventOwnerGate(event) || !event.channel)
|
|
2491
|
-
return undefined;
|
|
2492
|
-
const origin = deps.events.replyOrigin(event);
|
|
2493
|
-
const human = origin?.payload.human;
|
|
2494
|
-
if (!origin || !human)
|
|
2495
|
-
return undefined;
|
|
2496
|
-
const source = byTarget.get(origin.target);
|
|
2497
|
-
const out = source?.outbound;
|
|
2498
|
-
if (source && out?.streamId === human.streamId) {
|
|
2499
|
-
if (out.kind === "deferred")
|
|
2500
|
-
clearTimeout(out.timer);
|
|
2501
|
-
source.outbound = undefined;
|
|
2502
|
-
}
|
|
2503
|
-
let bubble = replyBubbles.get(origin.id);
|
|
2504
|
-
if (!bubble) {
|
|
2505
|
-
const expires = origin.at + HARD_TIMEOUT_MS;
|
|
2506
|
-
if (expires <= Date.now() || deps.events.hasReplyDelivery(human.streamId))
|
|
2507
|
-
return undefined;
|
|
2508
|
-
bubble = { frame: human.frame, streamId: human.streamId, expires, done: false, owner: event.id };
|
|
2509
|
-
rememberReplyBubble(origin.id, bubble);
|
|
2510
|
-
}
|
|
2511
|
-
if (bubble.done || Date.now() >= (bubble.expires ?? 0))
|
|
2512
|
-
return undefined;
|
|
2513
|
-
if (bubble.source) {
|
|
2514
|
-
const stream = bubble.source;
|
|
2515
|
-
stream.closed = true;
|
|
2516
|
-
clearTimeout(stream.flushTimer);
|
|
2517
|
-
clearTimeout(stream.idleTimer);
|
|
2518
|
-
clearTimeout(stream.hardTimer);
|
|
2519
|
-
bubble.pending = stream.pending;
|
|
2520
|
-
const source = byTarget.get(stream.target);
|
|
2521
|
-
if (source?.liveStream === stream)
|
|
2522
|
-
source.liveStream = undefined;
|
|
2523
|
-
bubble.source = undefined;
|
|
2524
|
-
}
|
|
2525
|
-
if (bubble.owner !== event.id) {
|
|
2526
|
-
// The same object carries the last in-flight write into the receiver's FIFO.
|
|
2527
|
-
// Old final/cleanup/timer paths lose authority before this object is reused.
|
|
2528
|
-
byTarget.forEach((a) => {
|
|
2529
|
-
if (a.briefBubble === bubble) {
|
|
2530
|
-
clearCot(a);
|
|
2531
|
-
a.briefBubble = undefined;
|
|
2532
|
-
}
|
|
2533
|
-
});
|
|
2534
|
-
clearTimeout(bubble.hardTimer);
|
|
2535
|
-
bubble.owner = event.id;
|
|
2536
|
-
}
|
|
2537
|
-
return bubble;
|
|
2538
|
-
};
|
|
2539
|
-
const transferReply = (event) => {
|
|
2540
|
-
const bubble = claimReplyBubble(event);
|
|
2541
|
-
if (!bubble)
|
|
2542
|
-
return;
|
|
2543
|
-
const origin = deps.events?.replyOrigin(event);
|
|
2544
|
-
bubble.pending = (bubble.pending ?? Promise.resolve()).catch(() => undefined).then(async () => {
|
|
2545
|
-
if (bubble.done || bubble.owner !== event.id || !eventOwnerGate(event))
|
|
2546
|
-
return;
|
|
2547
|
-
await client.replyStream(bubble.frame, bubble.streamId, withLinkedTagHeader(event.target, "…", chatTurnUrl(event.target, event.turn || origin?.turn), undefined, undefined, event.channel), false);
|
|
2548
|
-
}).catch((e) => { log.debug({ event: event.id, err: errText(e) }, "transfer reply refresh failed"); });
|
|
2549
|
-
};
|
|
2520
|
+
// ── 事件表已退役 (room 模型, wiring C): 这些判定只剩恒真桩, 保留调用点形状不动。 ──
|
|
2521
|
+
const eventOwned = (_id) => true;
|
|
2522
|
+
const briefMode = (_a) => cfg.wrc.mirror.brief;
|
|
2523
|
+
const bubbleOwned = (_a, _b) => true;
|
|
2550
2524
|
const armBriefBubble = (a, b, turnId, channel) => {
|
|
2551
2525
|
clearTimeout(b.hardTimer);
|
|
2552
2526
|
const owner = b.owner;
|
|
@@ -2555,7 +2529,8 @@ export const startMirror = (deps) => {
|
|
|
2555
2529
|
if (b.owner !== owner || !bubbleOwned(a, b))
|
|
2556
2530
|
return;
|
|
2557
2531
|
const live = a.briefBubble === b && !a.briefConcluded;
|
|
2558
|
-
|
|
2532
|
+
const rest = live ? STILL_WORKING : "";
|
|
2533
|
+
void finishBubble(a, b, briefLine(a, turnId, rest), true);
|
|
2559
2534
|
}, Math.max(0, (b.expires ?? Date.now()) - Date.now()));
|
|
2560
2535
|
};
|
|
2561
2536
|
const newTurnId = () => `t${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -2575,6 +2550,7 @@ export const startMirror = (deps) => {
|
|
|
2575
2550
|
};
|
|
2576
2551
|
const flushStream = async (s) => {
|
|
2577
2552
|
s.flushTimer = undefined;
|
|
2553
|
+
// P7-S2 严格群: 流式帧不出站; lastSent 推进避免反复重试。
|
|
2578
2554
|
if (s.closed || s.dead || s.acc === s.lastSent || !eventOwned(s.eventId))
|
|
2579
2555
|
return;
|
|
2580
2556
|
const content = s.acc;
|
|
@@ -2583,7 +2559,7 @@ export const startMirror = (deps) => {
|
|
|
2583
2559
|
await (s.pending = (s.pending ?? Promise.resolve()).catch(() => undefined).then(async () => {
|
|
2584
2560
|
if (s.closed || s.dead || !eventOwned(s.eventId))
|
|
2585
2561
|
return;
|
|
2586
|
-
await client.replyStream(s.frame, s.streamId, withLinkedTagHeader(s.target, content || "…", chatTurnUrl(s.target, s.turnId)
|
|
2562
|
+
await client.replyStream(s.frame, s.streamId, withLinkedTagHeader(s.target, content || "…", chatTurnUrl(s.target, s.turnId)), false);
|
|
2587
2563
|
}));
|
|
2588
2564
|
log.debug({ turnId: s.turnId, len: content.length }, "stream flush ok");
|
|
2589
2565
|
}
|
|
@@ -2669,11 +2645,6 @@ export const startMirror = (deps) => {
|
|
|
2669
2645
|
capped: false, closed: false, dead: false, cardSent: false,
|
|
2670
2646
|
tools: [], sawTool: false,
|
|
2671
2647
|
};
|
|
2672
|
-
const event = eventId ? deps.events?.get(eventId) : undefined;
|
|
2673
|
-
if (event?.payload.human)
|
|
2674
|
-
rememberReplyBubble(event.id, {
|
|
2675
|
-
frame, streamId, done: false, owner: event.id, source: s, expires: event.at + HARD_TIMEOUT_MS,
|
|
2676
|
-
});
|
|
2677
2648
|
// 微信帧没有 stream 窗口: 到点收口只会多发一条「仍在处理中」, 白占它那几格出站额度。
|
|
2678
2649
|
if (!isWxFrame(frame))
|
|
2679
2650
|
s.hardTimer = setTimeout(() => void finalizeStream(a, s, true), HARD_TIMEOUT_MS);
|
|
@@ -2688,7 +2659,7 @@ export const startMirror = (deps) => {
|
|
|
2688
2659
|
? buildChatUrl(cfg.daemon.detailPublicBase, cfg.daemon.host, cfg.daemon.port, turnId, roleUniq(target), target)
|
|
2689
2660
|
: undefined;
|
|
2690
2661
|
// `[mirror]` / `[wezard]` 系统提示不是答给谁的话, 不标方向。
|
|
2691
|
-
const withLinkedTag = (a, content, seq, turnId) => withLinkedTagHeader(a.target, content, chatTurnUrl(a.target, turnId ?? a.briefTurnId), seq, /^\[(mirror|wezard)\]/.test(content.trim()) ? undefined : a.replyTo
|
|
2662
|
+
const withLinkedTag = (a, content, seq, turnId) => withLinkedTagHeader(a.target, content, chatTurnUrl(a.target, turnId ?? a.briefTurnId), seq, /^\[(mirror|wezard)\]/.test(content.trim()) ? undefined : a.replyTo);
|
|
2692
2663
|
// 空正文一票否决 (近源拦截): 剥掉可能存在的路由头 (`.name:` / `[.name](url):`)
|
|
2693
2664
|
// 后没有可见内容就不发。中央 chat-gate (last-response 的 SDK 包装) 是最后一道
|
|
2694
2665
|
// 防线; 这里拦在源头 —— 空内容不进 standalonePending FIFO、不占防抖 buf、
|
|
@@ -2703,6 +2674,7 @@ export const startMirror = (deps) => {
|
|
|
2703
2674
|
return;
|
|
2704
2675
|
if (isPrivate(a) && !/^\[(mirror|wezard)\]/.test(content.trim()))
|
|
2705
2676
|
return;
|
|
2677
|
+
// P7-S2 严格群: 系统提示照放, 模型正文一律走 chat_reply / chat_say。
|
|
2706
2678
|
const chatId = replyChatId(a);
|
|
2707
2679
|
const turnId = a.briefTurnId ?? a.liveStream?.turnId; // 推送是排队异步的, 到发出时 turn 早已收口
|
|
2708
2680
|
const pieces = splitMarkdown(content, Math.max(200, cfg.wrc.mirror.chunkBytes - TAG_HEADER_BUDGET));
|
|
@@ -2902,6 +2874,7 @@ export const startMirror = (deps) => {
|
|
|
2902
2874
|
try {
|
|
2903
2875
|
// 有正文才写旧 streamId (收入 stream); 空缓冲一个字都不写 —— 否则
|
|
2904
2876
|
// loading 气泡被 " " 覆盖, 结束处理自己凭空制造一条空消息。
|
|
2877
|
+
// P7-S2 严格群: 终句不写流 (占位保持, 交付走 chat_reply)。
|
|
2905
2878
|
if (bubbleMd && eventOwned(out.eventId))
|
|
2906
2879
|
await client.replyStream(out.frame, out.streamId, withLinkedTag(a, bubbleMd), true);
|
|
2907
2880
|
}
|
|
@@ -3032,12 +3005,11 @@ export const startMirror = (deps) => {
|
|
|
3032
3005
|
a.cotText = undefined;
|
|
3033
3006
|
a.cotTool = undefined;
|
|
3034
3007
|
};
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
return !e?.payload.peer?.from.receipt || (!e.quiet && !(text && receiptQuiet(e, text)) && eventProgressGate(e));
|
|
3038
|
-
};
|
|
3008
|
+
/** 回执轮的 CoT 静默判定已随事件表退役 (room 模型): CoT 进度一律允许推进。 */
|
|
3009
|
+
const receiptProgress = (_a, _text) => true;
|
|
3039
3010
|
const flushCot = async (a) => {
|
|
3040
3011
|
a.cotTimer = undefined;
|
|
3012
|
+
// P7-S2 严格群: CoT 进度行不出站, 占位保持「…」。
|
|
3041
3013
|
// 展示选取: assistant text (含 thinking) 优先; 没有新 text 时才落最新 tool_use。
|
|
3042
3014
|
const text = a.cotText ?? a.cotTool;
|
|
3043
3015
|
a.cotText = undefined;
|
|
@@ -3090,93 +3062,8 @@ export const startMirror = (deps) => {
|
|
|
3090
3062
|
// 是凭据 (不可枚举), 只是页面从"一个 turn"扩成"这个 chat 的全部会话"。
|
|
3091
3063
|
// wizard 名字作为 ww_uniq 传下去, 让同一个 wizard 的所有 turn 详情都复用一个 WeCom 窗口。
|
|
3092
3064
|
// 头怎么写归 chatHead (默认 wizard 在 home 群: 企微只留名字链接, 微信不写头); 头与正文都空时留 `…`, 不发空气泡。
|
|
3093
|
-
const briefLine = (a, turnId, rest
|
|
3094
|
-
//
|
|
3095
|
-
// 人在 CLI 里手敲的一轮, 镜像只发生在两处: 他眼前的终端, 和 chat 详情页 (turn
|
|
3096
|
-
// store 全量记录 + SSE 实时刷新)。聊天里不再下发它的气泡 —— 那份内容他本来就
|
|
3097
|
-
// 在看。群里保留的是需要在群里发生的事: WeCom 发起的轮次、审批/提问卡、
|
|
3098
|
-
// `[mirror]` 系统提示 —— 它们都不走这道门。
|
|
3099
|
-
// 只在 brief 下生效: 抑制的前提是详情页兜得住内容, 而 turn store 只有 brief 在写。
|
|
3100
|
-
// 私聊轮 (wizard 之间, 非 public) 同理: 它的回复属于那场私聊, 只进双方的 rolepage。
|
|
3101
|
-
const turnSilent = (a) => !eventOwned(a.activeEventId) || isPrivate(a) || (cfg.wrc.mirror.brief && cfg.wrc.mirror.chatOriginOnly && a.turnFromChat === false);
|
|
3102
|
-
const formatFinal = (target, turn, channel, body) => {
|
|
3103
|
-
const pieces = splitMarkdown(body, Math.max(200, cfg.wrc.mirror.chunkBytes - TAG_HEADER_BUDGET));
|
|
3104
|
-
return pieces.map((text, n) => withLinkedTagHeader(target, text, chatTurnUrl(target, turn), pieces.length > 1 ? `${n + 1}/${pieces.length}` : undefined, undefined, channel));
|
|
3105
|
-
};
|
|
3106
|
-
const finalProgress = new Map();
|
|
3107
|
-
const settleFinalProgress = async (id) => {
|
|
3108
|
-
await finalProgress.get(id)?.catch(() => undefined);
|
|
3109
|
-
finalProgress.delete(id);
|
|
3110
|
-
};
|
|
3111
|
-
const queueFinal = (target, turn, channel, body, eventId, bubble, reportKind = parseClosing(body).kind === "need" ? "need" : "done") => {
|
|
3112
|
-
// 投递出口剥掉行首收口标记与 ARTIFACT 行 (peers.stripForChat): 判定读原文, 群里只看结论。
|
|
3113
|
-
const text = stripForChat(body);
|
|
3114
|
-
if (!deps.events || !channel || !text.trim())
|
|
3115
|
-
return undefined;
|
|
3116
|
-
const revision = finalId(eventId || turn, channel, text);
|
|
3117
|
-
const id = finalId(eventId || turn, channel, revision);
|
|
3118
|
-
const chunks = formatFinal(target, turn, channel, text);
|
|
3119
|
-
if (bubble?.pending)
|
|
3120
|
-
finalProgress.set(id, bubble.pending);
|
|
3121
|
-
const claimed = deps.events.delivery({ id, eventId, target, turn, channel, body: text, revision, chunks, reportKind,
|
|
3122
|
-
...(eventId && deps.events.get(eventId) ? { coverage: receiptCoverage(deps.events.get(eventId), channel, parseClosing(body).kind === "need", body) } : {}),
|
|
3123
|
-
...(bubble && !bubble.done ? { stream: { frame: bubble.frame, id: bubble.streamId, expires: bubble.expires ?? Date.now() } } : {}) });
|
|
3124
|
-
if (claimed !== id || deps.events.deliveryStatus(id)?.every((s) => s === "delivered"))
|
|
3125
|
-
finalProgress.delete(id);
|
|
3126
|
-
if (bubble) {
|
|
3127
|
-
bubble.done = true;
|
|
3128
|
-
clearTimeout(bubble.hardTimer);
|
|
3129
|
-
}
|
|
3130
|
-
return claimed;
|
|
3131
|
-
};
|
|
3132
|
-
const recoverEventFinal = (event, bubble) => {
|
|
3133
|
-
const current = deps.events?.get(event.id) ?? event;
|
|
3134
|
-
runEventFinalRecovery(current, eventOwnerGate, (current) => {
|
|
3135
|
-
const result = current.result;
|
|
3136
|
-
// 事件泵的 evidence 探针 (observe → io.recovered) 与 brief 软收口赛跑: 两者同为
|
|
3137
|
-
// ~1s 周期, 探针常先跑到, 而它调这里不带气泡 —— queueFinal 拿不到 stream, 终句
|
|
3138
|
-
// 全部走 standalone, 气泡定格在最后一行 CoT 进度。没传气泡时按 target/turn 找回
|
|
3139
|
-
// 活着的那只 (turn 已换人/气泡已收则不挂, 维持 standalone)。
|
|
3140
|
-
bubble ??= claimReplyBubble(current);
|
|
3141
|
-
bubble ??= (() => {
|
|
3142
|
-
const a = byTarget.get(current.target);
|
|
3143
|
-
return a && (!current.turn || a.briefTurnId === current.turn) && a.briefBubble && !a.briefBubble.done ? a.briefBubble : undefined;
|
|
3144
|
-
})();
|
|
3145
|
-
const turn = current.turn || current.id;
|
|
3146
|
-
const record = getDetail(turn);
|
|
3147
|
-
if (!record)
|
|
3148
|
-
recordTurnStart({ id: turn, eventId: current.id, target: current.target,
|
|
3149
|
-
userQuery: current.payload.text, createdAt: current.originalAt ?? current.at, channel: current.channel,
|
|
3150
|
-
speaker: current.payload.human ? current.speaker : undefined, from: current.payload.peer?.from });
|
|
3151
|
-
// tail 已按软收口记过这句话 (final:false —— 它不带终句语义, doneAt 不认): 就地升级,
|
|
3152
|
-
// 不追加同文第二条, 否则 rolepage 上草稿与终稿各画一颗气泡。没有同文的才补 —— 但也
|
|
3153
|
-
// 只补「这轮还没有任何终句」的: 已有终句而 body 不同, 是续答链把子事件的终句写进了
|
|
3154
|
-
// 同一段话只落一次 (子轮 / 父轮不各画一颗气泡)。
|
|
3155
|
-
if (!(record?.kind === "turn" && markTurnTextFinal(turn, result.body)) &&
|
|
3156
|
-
(record ? record.kind === "turn" && !record.items.some((x) => x.t === "text" && x.final) : true))
|
|
3157
|
-
recordTurnItem(turn, { t: "text", final: true, body: result.body, ts: result.at });
|
|
3158
|
-
recordTurnClose(turn);
|
|
3159
|
-
if (!current.turn)
|
|
3160
|
-
deps.events?.bind(current.id, turn);
|
|
3161
|
-
// 终句按事件自己的路由上下文放行 (§9.4/§9.5): 收口与否由路由表判 (eventFinalGate)。
|
|
3162
|
-
publishEventFinal(current, (candidate) => eventOwnerGate(candidate), (candidate) => eventFinalGate(candidate), (target, finalTurn, channel, published) => queueFinal(target, finalTurn, channel, result.body, published.id, bubble));
|
|
3163
|
-
});
|
|
3164
|
-
};
|
|
3165
|
-
const deliverTransferredFinal = (event, body, status = "error") => {
|
|
3166
|
-
if (!eventOwnerGate(event) || !event.channel)
|
|
3167
|
-
return;
|
|
3168
|
-
const turn = event.turn || event.id;
|
|
3169
|
-
if (!getDetail(turn))
|
|
3170
|
-
recordTurnStart({ id: turn, eventId: event.id, target: event.target,
|
|
3171
|
-
userQuery: event.payload.text, createdAt: event.at, channel: event.channel, from: event.payload.peer?.from });
|
|
3172
|
-
queueFinal(event.target, turn, event.channel, body, event.id, claimReplyBubble(event), status);
|
|
3173
|
-
};
|
|
3174
|
-
// 收口一条 loading 气泡: finish=true 写入最终内容, 只生效一次。发送失败退回 standalone。
|
|
3175
|
-
// raw=true skips withTagHeader (used when content already contains the linked tag header).
|
|
3176
|
-
// WeCom 客户端收到 finish=true 后仍有打字机动画要播放, 如果紧接着就下发
|
|
3177
|
-
// standalone (sendMessage), 用户会看到 standalone 抢在气泡动画结束之前出现。
|
|
3178
|
-
// 把 finishBubble 的 replyStream promise 链入 standalonePending, 让后续
|
|
3179
|
-
// standalone 自然排在 finish 之后; 额外加一小段延迟留给客户端渲染。
|
|
3065
|
+
const briefLine = (a, turnId, rest) => headed(chatHead(a.target, chatTurnUrl(a.target, turnId)), rest) || "…";
|
|
3066
|
+
// WeCom 客户端收到 finish=true 后仍有打字机动画要播放, standalone 排队前留一小段渲染时间。
|
|
3180
3067
|
const BUBBLE_FINISH_SETTLE_MS = 600;
|
|
3181
3068
|
const finishBubble = async (a, b, content, raw = false) => {
|
|
3182
3069
|
if (!b || b.done || !bubbleOwned(a, b))
|
|
@@ -3238,28 +3125,11 @@ export const startMirror = (deps) => {
|
|
|
3238
3125
|
/** 公开派活的那个同伴 —— 回复的头要标给它 (见 AttachState.replyTo)。 */
|
|
3239
3126
|
const publicPeer = (from) => from?.kind === "peer" && from.public ? from.from : undefined;
|
|
3240
3127
|
/** reload 后 tail 从 EOF 接上: 正在跑的这一轮的开头那句已在身后, 它的印章随旧进程没了。
|
|
3241
|
-
*
|
|
3242
|
-
/** 回执 / 定时任务信封携带当前 event; 普通 peer 只从注入事件的 durable serves 归属任务。 */
|
|
3243
|
-
const rowOf = (env) => (env.receipt || env.kind === "task" ? env.event : undefined)
|
|
3244
|
-
?? (env.eventId ? deps.events?.get(env.eventId)?.serves : undefined);
|
|
3128
|
+
* 那句话自己带着出处 —— 信封 (定时任务 / 老转录), 或 room 唤醒头 + 触发行 (见 turn-opening.ts); 都读不出 = undefined。 */
|
|
3245
3129
|
const openingOf = (a) => {
|
|
3246
3130
|
const t = a.jsonlPath ? lastUserTurn(a.jsonlPath, a.openingOffset) : undefined;
|
|
3247
|
-
|
|
3248
|
-
a.
|
|
3249
|
-
if (!env)
|
|
3250
|
-
return undefined;
|
|
3251
|
-
const home = baseOfKey(a.target);
|
|
3252
|
-
// transfer 过来的那一笔信封上写着群 (不是 private), 但它不是公开派活: 回复不标给发话方。
|
|
3253
|
-
const handed = !!(env.eventId && deps.events?.get(env.eventId)?.payload.peer?.from?.transferred);
|
|
3254
|
-
const from = env.kind === "peer" ? { kind: "peer", from: wizardStore()?.byName(stripSigil(env.from))?.target, ...(handed ? { transferred: true } : env.private ? {} : { public: true }), ...(env.receipt ? { receipt: true } : {}), ...(env.status ? { status: env.status } : {}), ...((turn) => (turn ? { turn } : {}))(rowOf(env)), ...(env.asker ? { asker: env.asker } : {}) }
|
|
3255
|
-
: env.kind === "task" ? { kind: "task", taskId: env.from.replace(/^定时 /, "") }
|
|
3256
|
-
: undefined;
|
|
3257
|
-
return {
|
|
3258
|
-
channel: env.private ? "" : env.chatKey || home,
|
|
3259
|
-
speaker: env.kind === "human" ? `user:${env.from}` : undefined,
|
|
3260
|
-
from,
|
|
3261
|
-
query: t.text,
|
|
3262
|
-
};
|
|
3131
|
+
a.activeEventId = t?.env?.eventId;
|
|
3132
|
+
return turnOpening(t, baseOfKey(a.target), (name) => wizardStore()?.byName(stripSigil(name))?.target);
|
|
3263
3133
|
};
|
|
3264
3134
|
/** 频道印章: 有新印章就换频道; 没有则 `reset` (CLI 手敲 / 人从聊天发起) 回到
|
|
3265
3135
|
* home, 其余续写 (收口后的补写) 沿用上一轮。`from` = 本轮的出处, 答给谁跟着频道走。
|
|
@@ -3370,7 +3240,7 @@ export const startMirror = (deps) => {
|
|
|
3370
3240
|
a.pendingBriefQuery = undefined;
|
|
3371
3241
|
a.pendingChannel = { channel: s.channel ?? baseOfKey(a.target), speaker: s.speaker, at: Date.now() };
|
|
3372
3242
|
consumeChannel(a, true, undefined);
|
|
3373
|
-
recordTurnStart({ id: q.turnId, target: a.target, sessionId: a.sessionId, cli: cliOf(a), initialModel: a.model || undefined, initialEffort: a.effort || undefined, cwd: a.runningCwd || undefined, userQuery: s.query.trim() || undefined, createdAt: (s.
|
|
3243
|
+
recordTurnStart({ id: q.turnId, target: a.target, sessionId: a.sessionId, cli: cliOf(a), initialModel: a.model || undefined, initialEffort: a.effort || undefined, cwd: a.runningCwd || undefined, userQuery: s.query.trim() || undefined, createdAt: at, ...channelFields(a), ...(s.rawQuery?.trim() ? { rawQuery: s.rawQuery } : {}) });
|
|
3374
3244
|
openBriefTurn(a, q);
|
|
3375
3245
|
};
|
|
3376
3246
|
/** 一句插话记进它插进的那一轮: 出处、频道、发话人都取它自己的印章 (没写频道 = 在 home 里开口)。 */
|
|
@@ -3387,12 +3257,7 @@ export const startMirror = (deps) => {
|
|
|
3387
3257
|
};
|
|
3388
3258
|
/** 一行注入露面了: 把它的印章落成下一轮的出处 / 频道。返回认领到的印章。`ts` = 那一行落盘的时刻。 */
|
|
3389
3259
|
const bindLine = (a, said, ts, eventId) => {
|
|
3390
|
-
const
|
|
3391
|
-
const s = takeSeal(a, said, undefined, eventId) ?? (recovered?.target === a.target ? {
|
|
3392
|
-
eventId, keys: [], at: recovered.at, query: recovered.payload.text, channel: recovered.channel,
|
|
3393
|
-
speaker: recovered.payload.human ? recovered.speaker : undefined, from: recovered.payload.peer?.from,
|
|
3394
|
-
fresh: recovered.priority === "normal" || idleVerdict(a.target) === true,
|
|
3395
|
-
} : undefined);
|
|
3260
|
+
const s = takeSeal(a, said, undefined, eventId);
|
|
3396
3261
|
if (!s)
|
|
3397
3262
|
return undefined;
|
|
3398
3263
|
if (s.turn) {
|
|
@@ -3425,13 +3290,8 @@ export const startMirror = (deps) => {
|
|
|
3425
3290
|
const startBriefTurn = async (a, frame, streamId, isSlash = false, userQuery = "", channel, speaker, eventId) => {
|
|
3426
3291
|
const turnId = newTurnId();
|
|
3427
3292
|
// hardTimer 兜底: turn 若无终句 / turn_end 收口 (卡死/漏收), 到点仍收气泡。
|
|
3428
|
-
const bubble = { frame, streamId, done: false, owner: eventId, expires:
|
|
3429
|
-
if (eventId)
|
|
3430
|
-
deps.events?.bind(eventId, turnId);
|
|
3293
|
+
const bubble = { frame, streamId, done: false, owner: eventId, expires: Date.now() + HARD_TIMEOUT_MS };
|
|
3431
3294
|
const q = { turnId, bubble, isSlash };
|
|
3432
|
-
// 微信帧不挂: 没有 stream 窗口要赶, 气泡等终句来了再一次发出 (见 openStream 同一条)。
|
|
3433
|
-
if (eventId)
|
|
3434
|
-
rememberReplyBubble(eventId, bubble);
|
|
3435
3295
|
armBriefBubble(a, bubble, turnId, channel);
|
|
3436
3296
|
const seal = { eventId, keys: sealKeys(userQuery), at: Date.now(), query: userQuery, channel, speaker, fresh: true, turn: q };
|
|
3437
3297
|
// 对方闲着 → 这一句就是下一轮, 当场接上。正忙 (在跑别人的回执 / 派活 / 上一句) 就先排着:
|
|
@@ -3440,7 +3300,7 @@ export const startMirror = (deps) => {
|
|
|
3440
3300
|
const queued = !isSlash && idleVerdict(a.target) === false;
|
|
3441
3301
|
pushSeal(a, seal);
|
|
3442
3302
|
if (queued)
|
|
3443
|
-
recordTurnStart({ id: turnId, target: a.target, sessionId: a.sessionId, cli: cliOf(a), initialModel: a.model || undefined, initialEffort: a.effort || undefined, cwd: a.runningCwd || undefined, userQuery: userQuery.trim() || undefined, eventId,
|
|
3303
|
+
recordTurnStart({ id: turnId, target: a.target, sessionId: a.sessionId, cli: cliOf(a), initialModel: a.model || undefined, initialEffort: a.effort || undefined, cwd: a.runningCwd || undefined, userQuery: userQuery.trim() || undefined, eventId, channel: channel ?? baseOfKey(a.target), speaker });
|
|
3444
3304
|
else
|
|
3445
3305
|
activateDispatch(a, seal);
|
|
3446
3306
|
// Durable normal inputs arrive only after the preceding full turn; expired bubbles use the final outbox standalone path.
|
|
@@ -3449,7 +3309,7 @@ export const startMirror = (deps) => {
|
|
|
3449
3309
|
// 也不必猜后端: codebuddy 那种几十秒后才落盘的轮, 入口从第一秒就在。
|
|
3450
3310
|
// 尾随 `…` 表示"正文还没到", 正文到位时整条内容被 `链接 正文` 覆盖。
|
|
3451
3311
|
try {
|
|
3452
|
-
await (bubble.pending = client.replyStream(frame, streamId, briefLine(a, turnId, "…"
|
|
3312
|
+
await (bubble.pending = client.replyStream(frame, streamId, briefLine(a, turnId, "…"), false));
|
|
3453
3313
|
}
|
|
3454
3314
|
catch (e) {
|
|
3455
3315
|
log.warn({ sessionId: a.sessionId, turnId, err: e.message }, "brief: turn ack failed");
|
|
@@ -3478,10 +3338,7 @@ export const startMirror = (deps) => {
|
|
|
3478
3338
|
a.replyTo = publicPeer(r.from);
|
|
3479
3339
|
a.turnFromChat = a.turnFromChat ?? true;
|
|
3480
3340
|
a.briefTurnId = r.id;
|
|
3481
|
-
|
|
3482
|
-
a.briefBubble = event ? claimReplyBubble(event) : undefined;
|
|
3483
|
-
if (a.briefBubble)
|
|
3484
|
-
armBriefBubble(a, a.briefBubble, r.id, a.channel);
|
|
3341
|
+
a.briefBubble = undefined; // replyBubbles 已随事件表退役; 占位覆盖走 daemon 的 bubble-frames 表
|
|
3485
3342
|
a.briefIsSlash = false;
|
|
3486
3343
|
a.briefHadTool = r.items.some((it) => it.t === "tool_use");
|
|
3487
3344
|
a.briefConcluded = false;
|
|
@@ -3513,12 +3370,7 @@ export const startMirror = (deps) => {
|
|
|
3513
3370
|
const from = fresh ?? a.convFrom;
|
|
3514
3371
|
recordTurnStart({ id: turnId, target: a.target, sessionId: a.sessionId, cli: cliOf(a), initialModel: a.model || undefined, initialEffort: a.effort || undefined, cwd: a.runningCwd || undefined, userQuery: query || opened || undefined, from, ...channelFields(a), ...(query && at ? { createdAt: at } : {}) });
|
|
3515
3372
|
a.briefTurnId = turnId;
|
|
3516
|
-
|
|
3517
|
-
deps.events?.bind(a.activeEventId, turnId);
|
|
3518
|
-
const event = a.activeEventId ? deps.events?.get(a.activeEventId) : undefined;
|
|
3519
|
-
a.briefBubble = event ? claimReplyBubble(event) : undefined;
|
|
3520
|
-
if (a.briefBubble)
|
|
3521
|
-
armBriefBubble(a, a.briefBubble, turnId, a.channel);
|
|
3373
|
+
a.briefBubble = undefined;
|
|
3522
3374
|
a.briefIsSlash = false;
|
|
3523
3375
|
a.briefHadTool = false;
|
|
3524
3376
|
a.briefConcluded = false;
|
|
@@ -3527,7 +3379,7 @@ export const startMirror = (deps) => {
|
|
|
3527
3379
|
// 详情链接不在这里单独发 — 本轮的每条 standalone 都由 withLinkedTag 自带
|
|
3528
3380
|
// (chatTurnUrl 读的正是 a.briefTurnId)。静默轮没有 standalone 可搭车, 那就
|
|
3529
3381
|
// 一条都不发: 群里只该出现有正文的消息, 纯入口提示是噪音。
|
|
3530
|
-
log.info({ sessionId: a.sessionId, turnId, fromCli
|
|
3382
|
+
log.info({ sessionId: a.sessionId, turnId, fromCli }, "brief: turn started (CLI-side, no bubble)");
|
|
3531
3383
|
};
|
|
3532
3384
|
// 本轮出现过工具调用 / tool_result / 非 final 文本 —— 只记状态: 详情链接从 ack 起
|
|
3533
3385
|
// 就挂在气泡里, 无需再推一次。气泡仍然不关, 等正文到来后以 `链接 正文` 覆盖收口。
|
|
@@ -3554,6 +3406,9 @@ export const startMirror = (deps) => {
|
|
|
3554
3406
|
&& Date.now() - (a.lastConcludedAt ?? 0) < DUP_CONCLUSION_WINDOW_MS
|
|
3555
3407
|
&& (!a.briefBubble || a.briefBubble.done)
|
|
3556
3408
|
&& textSimilarity(a.lastConcludedBody, body) >= DUP_CONCLUSION_RATIO;
|
|
3409
|
+
/** 终句落地 (契约 §5 F-1: 终句零语义)。只做三件事: 防重复终稿、记 turn store、
|
|
3410
|
+
* 推进收口标记。不出站、不关账、不写任何投递账 —— 群里的交付只有 room 的镜像
|
|
3411
|
+
* (chat_reply / chat_say 触发), 终句本身谁也送不到。 */
|
|
3557
3412
|
const concludeBriefTurn = (a, body) => {
|
|
3558
3413
|
const turnId = a.briefTurnId;
|
|
3559
3414
|
if (!turnId || a.briefConcluded)
|
|
@@ -3561,46 +3416,10 @@ export const startMirror = (deps) => {
|
|
|
3561
3416
|
if (!body.trim())
|
|
3562
3417
|
return;
|
|
3563
3418
|
if (!a.activeEventId && isDuplicateConclusion(a, body)) {
|
|
3564
|
-
a.briefConcluded = true; // 本轮已"定稿"
|
|
3419
|
+
a.briefConcluded = true; // 本轮已"定稿"
|
|
3565
3420
|
log.info({ sessionId: a.sessionId, turnId, epoch: a.queryEpoch ?? 0 }, "brief: duplicate conclusion suppressed");
|
|
3566
3421
|
return;
|
|
3567
3422
|
}
|
|
3568
|
-
const event = a.activeEventId ? deps.events?.get(a.activeEventId) : undefined;
|
|
3569
|
-
if (event)
|
|
3570
|
-
deps.events.result(event.id, body, finalId(event.id, event.channel, body), turnId);
|
|
3571
|
-
const gated = !!event && !eventFinalGate(event);
|
|
3572
|
-
if (!turnSilent(a) && !gated) {
|
|
3573
|
-
if (event)
|
|
3574
|
-
recoverEventFinal(deps.events.get(event.id), a.briefBubble);
|
|
3575
|
-
else
|
|
3576
|
-
queueFinal(a.target, turnId, a.channel ?? baseOfKey(a.target), body, undefined, a.briefBubble);
|
|
3577
|
-
}
|
|
3578
|
-
else if (event && gated && !turnSilent(a) && eventProgressGate(deps.events.get(event.id))) {
|
|
3579
|
-
// A live parent may report progress; settled/canceled rows never use this outlet.
|
|
3580
|
-
const text = stripForChat(body);
|
|
3581
|
-
const channel = event.channel;
|
|
3582
|
-
const id = finalId(event.id, channel, `progress:${text}`);
|
|
3583
|
-
const b = a.briefBubble;
|
|
3584
|
-
if (b?.pending)
|
|
3585
|
-
finalProgress.set(id, b.pending);
|
|
3586
|
-
if (text && channel)
|
|
3587
|
-
deps.events.delivery({ id, eventId: event.id, target: event.target, turn: turnId,
|
|
3588
|
-
channel, body: text, revision: id, purpose: "progress", chunks: formatFinal(event.target, turnId, channel, text),
|
|
3589
|
-
...(b && !b.done ? { stream: { frame: b.frame, id: b.streamId, expires: b.expires ?? Date.now() } } : {}) });
|
|
3590
|
-
if (b) {
|
|
3591
|
-
b.done = true;
|
|
3592
|
-
clearTimeout(b.hardTimer);
|
|
3593
|
-
}
|
|
3594
|
-
}
|
|
3595
|
-
const current = event ? deps.events.get(event.id) : undefined;
|
|
3596
|
-
if (current && (current.quiet || gated && !eventProgressGate(current))) {
|
|
3597
|
-
const b = a.briefBubble;
|
|
3598
|
-
if (b) {
|
|
3599
|
-
b.done = true;
|
|
3600
|
-
clearTimeout(b.hardTimer);
|
|
3601
|
-
}
|
|
3602
|
-
}
|
|
3603
|
-
// The durable result/outbox must exist before this in-memory dedup bit advances.
|
|
3604
3423
|
a.briefConcluded = true;
|
|
3605
3424
|
a.lastConcludedBody = body;
|
|
3606
3425
|
a.lastConcludedEpoch = a.queryEpoch ?? 0;
|
|
@@ -3618,6 +3437,15 @@ export const startMirror = (deps) => {
|
|
|
3618
3437
|
if (!a.briefTurnId)
|
|
3619
3438
|
return;
|
|
3620
3439
|
concludeBriefTurn(a, a.briefLastText ?? "");
|
|
3440
|
+
// recoverEventFinal 的补写搬到这里 (wiring C): 终句没记进 turn store 的场合
|
|
3441
|
+
// (软收口竞态把 final 标记漏了 / 落盘顺序) 就地补上 —— rolepage 的正文只有这一份,
|
|
3442
|
+
// 不依赖任何投递账。
|
|
3443
|
+
{
|
|
3444
|
+
const rec = getDetail(a.briefTurnId);
|
|
3445
|
+
if (rec?.kind === "turn" && (a.briefLastText ?? "").trim()
|
|
3446
|
+
&& !(markTurnTextFinal(a.briefTurnId, a.briefLastText) || rec.items.some((x) => x.t === "text" && x.final)))
|
|
3447
|
+
recordTurnItem(a.briefTurnId, { t: "text", final: true, body: a.briefLastText, ts: Date.now() });
|
|
3448
|
+
}
|
|
3621
3449
|
recordTurnClose(a.briefTurnId);
|
|
3622
3450
|
log.info({ sessionId: a.sessionId, turnId: a.briefTurnId }, "brief: turn closed");
|
|
3623
3451
|
a.briefTurnId = undefined;
|
|
@@ -3639,7 +3467,6 @@ export const startMirror = (deps) => {
|
|
|
3639
3467
|
closeSubagentTurns(a); // 父 turn 收口 = 它派出的 subagent 都已结束
|
|
3640
3468
|
clearCot(a);
|
|
3641
3469
|
// 它闲下来了: 收件箱里等它闲的回执 / 派活此刻就该贴, 不等下一拍定时泵。
|
|
3642
|
-
void deps.events?.pump();
|
|
3643
3470
|
};
|
|
3644
3471
|
// ── Subagent turns ─────────────────────────────────────────────────
|
|
3645
3472
|
// Task/Agent 工具派出的子 agent 在自己的转录文件里跑 (主 jsonl 只有派发与最终
|
|
@@ -3874,8 +3701,8 @@ export const startMirror = (deps) => {
|
|
|
3874
3701
|
return;
|
|
3875
3702
|
}
|
|
3876
3703
|
if (item.kind === "turn_end") {
|
|
3877
|
-
if (
|
|
3878
|
-
deps.
|
|
3704
|
+
if (!item.soft)
|
|
3705
|
+
deps.onTurnEnd?.(a.target);
|
|
3879
3706
|
closeBriefTurn(a);
|
|
3880
3707
|
return;
|
|
3881
3708
|
}
|
|
@@ -3893,9 +3720,6 @@ export const startMirror = (deps) => {
|
|
|
3893
3720
|
if (a.briefIsSlash && !a.briefHadTool && a.briefBubble && !a.briefBubble.done) {
|
|
3894
3721
|
void finishBriefBubble(a, item.body);
|
|
3895
3722
|
}
|
|
3896
|
-
else if (turnSilent(a)) {
|
|
3897
|
-
// CLI 里手敲的 /clear、/model 之类, 回执给敲的人看就够了 —— 只进详情页。
|
|
3898
|
-
}
|
|
3899
3723
|
else {
|
|
3900
3724
|
sendStandalone(a, item.body); // 链接前缀同上, 走 withLinkedTag
|
|
3901
3725
|
}
|
|
@@ -4024,6 +3848,7 @@ export const startMirror = (deps) => {
|
|
|
4024
3848
|
void finalizeStream(a, a.liveStream);
|
|
4025
3849
|
};
|
|
4026
3850
|
const onItem = (a, item) => {
|
|
3851
|
+
touch(a.target);
|
|
4027
3852
|
// 新 spawn 的 pane 在首次 inject 落地前吞掉所有初始输出 (greeting/system)。
|
|
4028
3853
|
if (a.muteUntilInject)
|
|
4029
3854
|
return;
|
|
@@ -4093,18 +3918,13 @@ export const startMirror = (deps) => {
|
|
|
4093
3918
|
// user 行只作边界信号 (上面已清账/推进轮次), 不渲染。brief 下无条件丢:
|
|
4094
3919
|
// 有活跃 turn 时 handleBriefItem 本就丢它, 没有 turn 时 (user_text 不是
|
|
4095
3920
|
// BRIEF_TURN_OPENERS) 它会一路穿到底部的 standalone fallback —— includeUser=true
|
|
4096
|
-
// 的配置下, 人在 CLI 敲的那一行就这么原样回显进了群, 正好破了
|
|
3921
|
+
// 的配置下, 人在 CLI 敲的那一行就这么原样回显进了群, 正好破了 出处门。
|
|
4097
3922
|
if (item.kind === "user_text" && (item.quiet || briefMode(a)))
|
|
4098
3923
|
return;
|
|
4099
3924
|
// thinking 唯一的出口是 brief 气泡的 CoT 进度行。必须在这里就吃掉 —— 漏到下面任何
|
|
4100
3925
|
// 一条通道 (deferred buf → renderBuf / standalone / stream append) 都会把它写进正文,
|
|
4101
3926
|
// 那就变回已下线的 thinkStyle 了。
|
|
4102
3927
|
if (item.kind === "thinking") {
|
|
4103
|
-
const event = a.activeEventId ? deps.events?.get(a.activeEventId) : undefined;
|
|
4104
|
-
// A receiver can begin with thinking, before any text/tool opener. Bind its
|
|
4105
|
-
// turn and inherited bubble now; pending input alone never authorizes output.
|
|
4106
|
-
if (!a.briefTurnId && event?.payload.peer?.transferred && eventOwnerGate(event))
|
|
4107
|
-
ensureBriefTurn(a);
|
|
4108
3928
|
if (briefMode(a) && a.briefTurnId)
|
|
4109
3929
|
updateBriefProgress(a, item.body);
|
|
4110
3930
|
return;
|
|
@@ -4259,19 +4079,7 @@ export const startMirror = (deps) => {
|
|
|
4259
4079
|
}
|
|
4260
4080
|
}
|
|
4261
4081
|
}
|
|
4262
|
-
|
|
4263
|
-
const e = deps.events.get(a.activeEventId);
|
|
4264
|
-
if (e) {
|
|
4265
|
-
// Soft final text waits for transcript/idle evidence; it must not escape through the legacy stream.
|
|
4266
|
-
if (item.final !== true)
|
|
4267
|
-
return;
|
|
4268
|
-
const turn = a.liveStream?.turnId ?? e.id;
|
|
4269
|
-
deps.events.result(e.id, item.body, finalId(e.id, e.channel, item.body), turn);
|
|
4270
|
-
if (eventFinalGate(e))
|
|
4271
|
-
recoverEventFinal(deps.events.get(e.id));
|
|
4272
|
-
return;
|
|
4273
|
-
}
|
|
4274
|
-
}
|
|
4082
|
+
// 非 brief 终句的投递已随事件表退役 (F-1 终句零语义): 文本只进 turn store。
|
|
4275
4083
|
if (!briefMode(a) && (isPrivate(a) || !eventOwned(a.activeEventId)))
|
|
4276
4084
|
return;
|
|
4277
4085
|
// /goal mode overrides everything below: the session-scoped Stop hook
|
|
@@ -4398,6 +4206,25 @@ export const startMirror = (deps) => {
|
|
|
4398
4206
|
enqueueStandalone(a, item.body);
|
|
4399
4207
|
};
|
|
4400
4208
|
const resolveTarget = (override) => sanitizeId(override?.trim() || cfg.wrc.mirror.pushChat.trim() || cfg.defaultChat.trim());
|
|
4209
|
+
// 身份提供者。newSession / 重生 / clone / attach 全都从这里取「这个 target 是谁」, 于是
|
|
4210
|
+
// 无论是群里手打的 /new、pane 死了的自愈重生, 还是编排生出来的分身, 新进程一
|
|
4211
|
+
// 睁眼就知道自己是谁 —— 而不是只有走 wizard 路由那一条路才有身份。
|
|
4212
|
+
// 由 index.ts 在启动时装上 (注册表活在那边); 没装 = 退回无身份行为, 全链路无回归。
|
|
4213
|
+
// 声明在 attach 之前: 重启后按 pinned sessionId 直接 attach 的路径在 startMirror 的
|
|
4214
|
+
// 同步段里就会走到它 (const 有 TDZ, 放到后面整段初始化会直接抛)。
|
|
4215
|
+
let charterOf;
|
|
4216
|
+
const setCharterProvider = (fn) => { charterOf = fn; };
|
|
4217
|
+
// `cwd` = 这个 pane 正要启动的目录。attach 在 spawn 之后才发生, 所以此刻 getCwd
|
|
4218
|
+
// 给的还是上一个 pane 的目录 —— 换目录重开时照它渲染, 新 wizard 会以为自己还在
|
|
4219
|
+
// 旧工作区里。
|
|
4220
|
+
const charterFor = (target, ctx) => {
|
|
4221
|
+
try {
|
|
4222
|
+
return charterOf?.(target, ctx);
|
|
4223
|
+
}
|
|
4224
|
+
catch {
|
|
4225
|
+
return undefined;
|
|
4226
|
+
}
|
|
4227
|
+
};
|
|
4401
4228
|
// Detach an attachment: finalize any live stream, stop the tail, drop from indexes.
|
|
4402
4229
|
const detach = (a, reason) => {
|
|
4403
4230
|
if (a.migrationWatcher) {
|
|
@@ -4437,6 +4264,35 @@ export const startMirror = (deps) => {
|
|
|
4437
4264
|
const detailUrlFor = (id, principal) => cfg.daemon.detailLinksInMirror && id
|
|
4438
4265
|
? buildDetailUrl(cfg.daemon.detailPublicBase, cfg.daemon.host, cfg.daemon.port, id, principal ? stripPrincipalPrefix(principal) : undefined)
|
|
4439
4266
|
: "";
|
|
4267
|
+
// 绑定补存窗口名 + pid (2026-11-19): restore 凭窗口名/shell pid 核对 pane id 有没有被
|
|
4268
|
+
// tmux 重新发号指到别人身上, %N 失效时再凭它们 (+注册表 sid / CLI pid) 把原 pane 认回来。
|
|
4269
|
+
// respawn / 重挂路径不经 attach, 各自的 store.set 会整条覆盖记录 —— 不补就丢认回凭据。
|
|
4270
|
+
// fire-and-forget: 结果回来时绑定已换人就丢弃; 三样都齐且 pane 没换就不重查 (boot 批量
|
|
4271
|
+
// 恢复靠 restore 预写快照, 不逐个 ps)。
|
|
4272
|
+
const refreshPaneIdentity = (target, pane, jsonlPath) => {
|
|
4273
|
+
if (!pane)
|
|
4274
|
+
return;
|
|
4275
|
+
void paneIdentityOf(pane).then(async (id) => {
|
|
4276
|
+
if (!id)
|
|
4277
|
+
return;
|
|
4278
|
+
const cur = deps.store.get(target);
|
|
4279
|
+
if (!cur || (cur.tmuxPane ?? "") !== pane)
|
|
4280
|
+
return;
|
|
4281
|
+
if (cur.tmuxWindow === id.window && cur.tmuxPid === id.pid && cur.cliPid)
|
|
4282
|
+
return;
|
|
4283
|
+
let cliPid;
|
|
4284
|
+
try {
|
|
4285
|
+
const backend = backendForPath(jsonlPath);
|
|
4286
|
+
const { kids } = await psSnap();
|
|
4287
|
+
cliPid = registeredPidUnder(Number(id.pid), liveSessionPids(backend.homeDir), kids);
|
|
4288
|
+
}
|
|
4289
|
+
catch { /* ps 失败 = 认不出 CLI pid, 不写 */ }
|
|
4290
|
+
const nowRec = deps.store.get(target);
|
|
4291
|
+
if (!nowRec || (nowRec.tmuxPane ?? "") !== pane)
|
|
4292
|
+
return;
|
|
4293
|
+
deps.store.set(target, { ...nowRec, tmuxWindow: id.window, tmuxPid: id.pid, ...(cliPid ? { cliPid } : {}) });
|
|
4294
|
+
}).catch(() => undefined);
|
|
4295
|
+
};
|
|
4440
4296
|
const attach = ({ sessionId, jsonlPath, target: targetOverride, tmuxPane, tmuxSession, cwd, model, effort, pendingCwd }) => {
|
|
4441
4297
|
const target = resolveTarget(targetOverride);
|
|
4442
4298
|
if (!target)
|
|
@@ -4521,18 +4377,45 @@ export const startMirror = (deps) => {
|
|
|
4521
4377
|
startSubagentsFor(a);
|
|
4522
4378
|
bySessionId.set(sessionId, a);
|
|
4523
4379
|
byTarget.set(target, a);
|
|
4380
|
+
const cliName = backendForPath(jsonlPath).name;
|
|
4524
4381
|
const prevRec = deps.store.get(target);
|
|
4382
|
+
// 宪章只在内存里 (charterPending), reload 之后就没了 —— 而所有建绑定的路径
|
|
4383
|
+
// (newSession / restoreFromStore / pinned / clone / 外部认领) 都汇聚在这里, 所以
|
|
4384
|
+
// 在这里统一按「落盘标记 + 转录里有没有 user 行」补一次。codex 的宪章在
|
|
4385
|
+
// developer_instructions 里, 判据对它恒 false。
|
|
4386
|
+
// 同一个会话在内存里还挂着就沿用它的 pending (重挂路径); 记录换过会话时那份落盘标记
|
|
4387
|
+
// 是上一个会话的账, 不认。
|
|
4388
|
+
const owedCharter = Boolean(prevBySid?.charterPending?.trim()) ||
|
|
4389
|
+
(prevRec?.sessionId === sessionId && Boolean(prevRec.charterOwed));
|
|
4390
|
+
a.charterPending = charterToRearm({
|
|
4391
|
+
cli: cliName,
|
|
4392
|
+
owed: owedCharter,
|
|
4393
|
+
jsonlPath,
|
|
4394
|
+
render: () => charterFor(target, { cwd: a.runningCwd, cli: cliName }),
|
|
4395
|
+
});
|
|
4396
|
+
// 同一块 pane 上重绑 (re-attach / 换 sid) 沿用已存的身份; 新 pane 为空 (死 pane 保留
|
|
4397
|
+
// 绑定 / spawn-mode) 也沿用 —— 那是认回原 pane 的凭据, 别在重挂时丢掉; 真换了 pane
|
|
4398
|
+
// 才清空, 由 refreshPaneIdentity 填新值, 绝不把上一块 pane 的窗口名/pid 记到新 pane 头上。
|
|
4399
|
+
const samePane = (prevRec?.tmuxPane ?? "") === (a.tmuxPane ?? "");
|
|
4400
|
+
const carryIdentity = samePane || !(a.tmuxPane ?? "").trim();
|
|
4525
4401
|
deps.store.set(target, {
|
|
4526
4402
|
sessionId,
|
|
4527
4403
|
jsonlPath,
|
|
4528
4404
|
tmuxSession: a.tmuxSession || undefined,
|
|
4529
4405
|
tmuxPane: a.tmuxPane || undefined,
|
|
4406
|
+
...(carryIdentity && prevRec?.tmuxWindow ? { tmuxWindow: prevRec.tmuxWindow } : {}),
|
|
4407
|
+
...(carryIdentity && prevRec?.tmuxPid ? { tmuxPid: prevRec.tmuxPid } : {}),
|
|
4408
|
+
...(carryIdentity && prevRec?.cliPid ? { cliPid: prevRec.cliPid } : {}),
|
|
4530
4409
|
cwd: a.runningCwd || undefined,
|
|
4531
4410
|
model: a.model || undefined,
|
|
4532
4411
|
effort: a.effort || undefined,
|
|
4533
4412
|
pendingCwd: a.pendingCwd || undefined,
|
|
4534
4413
|
cwdConfirmed: prevRec?.cwdConfirmed,
|
|
4414
|
+
charterOwed: a.charterPending ? true : undefined,
|
|
4535
4415
|
});
|
|
4416
|
+
// 绑定补存窗口名 + pid (2026-11-19): attach 是同步的, 异步补查一次 (见 refreshPaneIdentity)。
|
|
4417
|
+
if (a.tmuxPane)
|
|
4418
|
+
refreshPaneIdentity(target, a.tmuxPane, jsonlPath);
|
|
4536
4419
|
// 这个 pane 现在归 wezard 管 (spawn / reload 恢复 / switch 认下的人自己开的终端):
|
|
4537
4420
|
// 打上归属标记, 它的 hook 才走 IM 审批。spawn 出来的进程本身带 WEZARD_MANAGED,
|
|
4538
4421
|
// 这一下是给「升级前就在跑的 pane」和「switch 绑进来的外部会话」补的。
|
|
@@ -4587,6 +4470,73 @@ export const startMirror = (deps) => {
|
|
|
4587
4470
|
s.add(a.sessionId);
|
|
4588
4471
|
return s;
|
|
4589
4472
|
};
|
|
4473
|
+
// %N 失效 (server 重启重编号 / 陈年记录) 后, 把原来那块 pane 认回来 —— 认得回就不
|
|
4474
|
+
// respawn, 会话不用靠 --resume fork 换代。判据按强度排: ① 注册表里本绑定 sid 的活进程
|
|
4475
|
+
// 登记在哪个 pane (sid 是唯一键, 最强); ②③ 窗口名 + shell pid 等值 / CLI pid 在候选
|
|
4476
|
+
// pane 的进程树里 (paneReclaimMatches 钉死: 窗口名单独永远不认)。全部认不出返回 ""。
|
|
4477
|
+
const paneByIdentity = async (rec, jsonlPath) => {
|
|
4478
|
+
const backend = backendForPath(jsonlPath);
|
|
4479
|
+
if (backend.name !== "codex") {
|
|
4480
|
+
const row = sessionBySid(backend.homeDir, rec.sessionId);
|
|
4481
|
+
if (row?.pane && (await probePane(row.pane, jsonlPath)).state === "session")
|
|
4482
|
+
return row.pane;
|
|
4483
|
+
}
|
|
4484
|
+
const win = (rec.tmuxWindow ?? "").trim();
|
|
4485
|
+
const pid = (rec.tmuxPid ?? "").trim();
|
|
4486
|
+
if (!win && !pid && !rec.cliPid)
|
|
4487
|
+
return "";
|
|
4488
|
+
const snap = await runTmux(["list-panes", "-a", "-F", "#{pane_id}\t#{window_name}\t#{pane_pid}"]);
|
|
4489
|
+
if (!snap.ok)
|
|
4490
|
+
return "";
|
|
4491
|
+
const ps = await psSnap();
|
|
4492
|
+
const treeHas = (root, want) => {
|
|
4493
|
+
const seen = new Set();
|
|
4494
|
+
const stack = [root];
|
|
4495
|
+
while (stack.length) {
|
|
4496
|
+
const p = stack.pop() ?? 0;
|
|
4497
|
+
if (p === want)
|
|
4498
|
+
return true;
|
|
4499
|
+
if (seen.has(p))
|
|
4500
|
+
continue;
|
|
4501
|
+
seen.add(p);
|
|
4502
|
+
for (const k of ps.kids.get(p) ?? [])
|
|
4503
|
+
stack.push(k);
|
|
4504
|
+
}
|
|
4505
|
+
return false;
|
|
4506
|
+
};
|
|
4507
|
+
for (const line of snap.stdout.split("\n")) {
|
|
4508
|
+
if (!line.trim())
|
|
4509
|
+
continue;
|
|
4510
|
+
const [pane = "", window = "", panePid = ""] = line.trim().split("\t");
|
|
4511
|
+
if (!pane.startsWith("%"))
|
|
4512
|
+
continue;
|
|
4513
|
+
if (paneReclaimMatches(rec, { window, pid: panePid }, treeHas)
|
|
4514
|
+
&& (await probePane(pane, jsonlPath)).state === "session")
|
|
4515
|
+
return pane;
|
|
4516
|
+
}
|
|
4517
|
+
return "";
|
|
4518
|
+
};
|
|
4519
|
+
// 会话丢失的人可见提示 (去重): 同一 (target, sid) 只发一次 —— restore 每次都会重进丢失
|
|
4520
|
+
// 分支, 不去重就是每条消息一条告警。boot 批量恢复不发 (没人看着, WS 也未必就绪), 只在
|
|
4521
|
+
// 懒恢复 (下一条消息进来) 时发, 正好落在 --resume 报错旁边, 告诉人怎么办。
|
|
4522
|
+
const lostNoticeFile = (cfg.wrc.mirror.attachmentsFile || "").trim()
|
|
4523
|
+
? join(dirname(expandHome(cfg.wrc.mirror.attachmentsFile)), "mirror-lost-notices.json") : "";
|
|
4524
|
+
const lostNotices = lostNoticeFile ? loadJsonMap(lostNoticeFile) : undefined;
|
|
4525
|
+
if (lostNotices) {
|
|
4526
|
+
const cutoff = Date.now() - 30 * 24 * 3600_000;
|
|
4527
|
+
for (const [k, at] of Object.entries(lostNotices.all()))
|
|
4528
|
+
if (!at || at < cutoff)
|
|
4529
|
+
lostNotices.drop(k);
|
|
4530
|
+
}
|
|
4531
|
+
const notifySessionLost = (a) => {
|
|
4532
|
+
if (!lostNotices)
|
|
4533
|
+
return;
|
|
4534
|
+
const key = `${a.target}|${a.sessionId}`;
|
|
4535
|
+
if (lostNotices.get(key))
|
|
4536
|
+
return;
|
|
4537
|
+
lostNotices.set(key, Date.now());
|
|
4538
|
+
sendStandalone(a, "[mirror] ⚠ 这场会话的记录已丢失 (pane 与 transcript 都不在了)。绑定原样保留: 下一条消息的 --resume 会报错, 需要发 /new 重开会话。");
|
|
4539
|
+
};
|
|
4590
4540
|
// `panes` = boot 快照; 给了就不再为每个 principal 单独问 tmux。lazy 调用方
|
|
4591
4541
|
// 不传, 维持原来的逐个探活。
|
|
4592
4542
|
const restoreFromStore = async (principal, panes, permitted) => {
|
|
@@ -4608,16 +4558,50 @@ export const startMirror = (deps) => {
|
|
|
4608
4558
|
// jsonl means "no input yet", NOT "rotated away" — healing it onto some
|
|
4609
4559
|
// unrelated newest-in-cwd file is exactly the cross-wire we must avoid.
|
|
4610
4560
|
const storedPane = (rec.tmuxPane ?? "").trim();
|
|
4611
|
-
|
|
4561
|
+
// 身份核对 (2026-11-19): pane id 只是 server 生命周期内的编号 —— server 重启后 %N 会
|
|
4562
|
+
// 重新发号, 存下来的 %N 可能落到别人的 pane 上。存过窗口名/pid 就必须对上, 对不上当它
|
|
4563
|
+
// 没了 (绝不按名字猜), 免得 restore 把这一群接去别人的 pane。
|
|
4564
|
+
const storedMeta = storedPane && panes ? panes.get(storedPane) : undefined;
|
|
4565
|
+
const aliveById = storedPane && (panes ? panes.has(storedPane) : await tmuxPaneAlive(storedPane));
|
|
4566
|
+
const identityOk = aliveById ? paneIdentityMatches(rec, storedMeta ?? (await paneIdentityOf(storedPane))) : false;
|
|
4567
|
+
if (aliveById && !identityOk)
|
|
4568
|
+
log.warn({ principal, pane: storedPane, boundWindow: rec.tmuxWindow, boundPid: rec.tmuxPid }, "mirror restore: pane id 指向的已不是原来那块 pane (窗口名/pid 对不上), 按死 pane 处理");
|
|
4569
|
+
let livePane = aliveById && identityOk ? storedPane : "";
|
|
4570
|
+
if (!livePane) {
|
|
4571
|
+
// %N 认不到: 先按注册表 sid / 窗口名+pid 把原 pane 认回来 (免 respawn 换代),
|
|
4572
|
+
// 认不回再走原来的 codex 兜底。
|
|
4573
|
+
const reAdopted = await paneByIdentity(rec, jsonlAbs);
|
|
4574
|
+
if (permitted && !permitted())
|
|
4575
|
+
return undefined;
|
|
4576
|
+
if (reAdopted) {
|
|
4577
|
+
log.info({ principal, sessionId: rec.sessionId, pane: reAdopted, window: rec.tmuxWindow, boundPid: rec.tmuxPid }, "mirror restore: pane id 失效, 按注册表/窗口名+pid 认回原 pane (免 respawn 换代)");
|
|
4578
|
+
rec.tmuxPane = reAdopted;
|
|
4579
|
+
deps.store.set(principal, rec);
|
|
4580
|
+
livePane = reAdopted;
|
|
4581
|
+
}
|
|
4582
|
+
}
|
|
4583
|
+
if (!livePane)
|
|
4584
|
+
livePane = await codexPaneForTranscript(jsonlAbs);
|
|
4612
4585
|
if (permitted && !permitted())
|
|
4613
4586
|
return undefined;
|
|
4587
|
+
// boot 快照里有窗口名/pid 而记录里还没有 (升级前的老记录): 先预写, attach 的沿用规则
|
|
4588
|
+
// 就能把它们带进新记录, refreshPaneIdentity 也不会为每个绑定各跑一次 ps。
|
|
4589
|
+
if (livePane && panes) {
|
|
4590
|
+
const meta = panes.get(livePane);
|
|
4591
|
+
if (meta && (!rec.tmuxWindow || !rec.tmuxPid)) {
|
|
4592
|
+
rec.tmuxWindow = meta.window;
|
|
4593
|
+
rec.tmuxPid = meta.pid;
|
|
4594
|
+
deps.store.set(principal, rec);
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
let lostBinding = false;
|
|
4614
4598
|
if (!existsSync(jsonlAbs)) {
|
|
4615
4599
|
// First: the SAME-sid transcript may have merely relocated to a sibling
|
|
4616
4600
|
// project dir (Claude Code EnterWorktree/ExitWorktree moved it while the
|
|
4617
4601
|
// daemon was down). Re-home onto it WITHOUT changing the sessionId — the
|
|
4618
|
-
// tail then follows it natively.
|
|
4619
|
-
//
|
|
4620
|
-
//
|
|
4602
|
+
// tail then follows it natively. 仍然必须放在任何"按目录认领最新 jsonl"之前 ——
|
|
4603
|
+
// 那种认领会抓到原 cwd 目录里最新的会话 (通常是**另一个** chat) 并串线。restore
|
|
4604
|
+
// 现在不再 heal, 但先认 worktree 里的同 sid 依然是对的。
|
|
4621
4605
|
const owner = backendForPath(expandHome(rec.jsonlPath));
|
|
4622
4606
|
const relocated = findJsonlBySid(rec.sessionId, owner);
|
|
4623
4607
|
if (relocated) {
|
|
@@ -4635,23 +4619,13 @@ export const startMirror = (deps) => {
|
|
|
4635
4619
|
log.info({ principal, sessionId: rec.sessionId, pane: livePane }, "mirror restore: live pane, transcript not written yet — keeping spawn-mode binding");
|
|
4636
4620
|
}
|
|
4637
4621
|
else {
|
|
4638
|
-
// Pane dead AND transcript gone
|
|
4639
|
-
//
|
|
4640
|
-
//
|
|
4641
|
-
//
|
|
4642
|
-
//
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
if (!healed) {
|
|
4646
|
-
log.warn({ principal, jsonlPath: rec.jsonlPath }, "mirror restore: jsonl missing and no unclaimed sibling, dropping entry");
|
|
4647
|
-
deps.store.drop(principal);
|
|
4648
|
-
return undefined;
|
|
4649
|
-
}
|
|
4650
|
-
log.warn({ principal, from: rec.sessionId, to: healed.sessionId }, "mirror restore: recorded jsonl gone, healed to latest unclaimed in project dir");
|
|
4651
|
-
rec.sessionId = healed.sessionId;
|
|
4652
|
-
rec.jsonlPath = healed.jsonlPath;
|
|
4653
|
-
jsonlAbs = healed.jsonlPath;
|
|
4654
|
-
deps.store.set(principal, rec);
|
|
4622
|
+
// Pane dead AND transcript gone: 旧行为是"heal"到项目目录里最新、没人绑的 jsonl 上
|
|
4623
|
+
// (常常是别人的 sid, 2026-11-19 现场: 一秒内 5 条 heal 把镜像接到别人头上), 后来
|
|
4624
|
+
// 改成的「悄悄丢绑定」也只是把静默串线换成静默新开。现在 fail-visible: 绑定原样
|
|
4625
|
+
// 保留 (sessionId 一个字不动), 下一条消息走 --resume 由 CLI 报错 (人可见), 聊天里
|
|
4626
|
+
// 再补一条去重过的 [mirror] 提示 —— 换不换会话只由人 /new 说了算。
|
|
4627
|
+
log.warn({ principal, sessionId: rec.sessionId, jsonlPath: rec.jsonlPath }, "mirror restore: pane gone and transcript missing — keeping binding, resume will fail visibly (no sid heal)");
|
|
4628
|
+
lostBinding = true;
|
|
4655
4629
|
}
|
|
4656
4630
|
}
|
|
4657
4631
|
// Pane-cwd worktree re-home: the stored jsonl can EXIST yet be stale because
|
|
@@ -4664,7 +4638,7 @@ export const startMirror = (deps) => {
|
|
|
4664
4638
|
// boot; the 3s drift follower maintains it thereafter.
|
|
4665
4639
|
if (livePane) {
|
|
4666
4640
|
const paneCwd = panes
|
|
4667
|
-
? (panes.get(livePane) ?? "")
|
|
4641
|
+
? (panes.get(livePane)?.cwd ?? "")
|
|
4668
4642
|
: (await runTmux(["display-message", "-p", "-t", livePane, "#{pane_current_path}"])).stdout.trim();
|
|
4669
4643
|
if (permitted && !permitted())
|
|
4670
4644
|
return undefined;
|
|
@@ -4706,6 +4680,9 @@ export const startMirror = (deps) => {
|
|
|
4706
4680
|
}
|
|
4707
4681
|
const restored = byTarget.get(principal);
|
|
4708
4682
|
log.info({ principal, sessionId: rec.sessionId, livePane: livePane || "(spawn-mode)" }, "mirror restored from store");
|
|
4683
|
+
// 只在懒恢复 (下一条消息进来, panes 未传) 时发丢失提示: boot 批量恢复没人看着。
|
|
4684
|
+
if (lostBinding && restored && !panes)
|
|
4685
|
+
notifySessionLost(restored);
|
|
4709
4686
|
return restored;
|
|
4710
4687
|
};
|
|
4711
4688
|
// We re-attach lazily on demand too (see restoreFromStore in dispatch /
|
|
@@ -4722,7 +4699,7 @@ export const startMirror = (deps) => {
|
|
|
4722
4699
|
// reload 探测早放弃了 (「reload issued but /status not responding」的真身)。
|
|
4723
4700
|
// 一张快照 + 封顶并发; await 立刻让出, startHttp 先绑端口。
|
|
4724
4701
|
restored = (async () => {
|
|
4725
|
-
const snap = await runTmux(["list-panes", "-a", "-F", "#{pane_id}\t#{pane_current_path}"]);
|
|
4702
|
+
const snap = await runTmux(["list-panes", "-a", "-F", "#{pane_id}\t#{pane_current_path}\t#{window_name}\t#{pane_pid}"]);
|
|
4726
4703
|
const panes = snap.ok ? parsePaneList(snap.stdout) : undefined;
|
|
4727
4704
|
await mapLimit(persistedKeys, RESTORE_CONC, (principal) => restoreFromStore(principal, panes));
|
|
4728
4705
|
log.info({ restored: persistedKeys.length, panes: panes?.size ?? -1 }, "mirror: boot restore done");
|
|
@@ -4776,10 +4753,9 @@ export const startMirror = (deps) => {
|
|
|
4776
4753
|
// input. Detect the rotation by watching the project dir for a new .jsonl
|
|
4777
4754
|
// that didn't exist at /clear time and contains a non-empty user line, then
|
|
4778
4755
|
// re-target this attachment onto it.
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
};
|
|
4756
|
+
// CLI 自己的 `/new` (codebuddy 有, 注入进 pane 时并非 daemon 的 /new) 与 /clear 同效:
|
|
4757
|
+
// 当场换 sid、新转录首条是 <command-name>/new —— 不当 /clear 认, 绑定就钉在旧转录上。
|
|
4758
|
+
const isClearCommand = (text) => /^\/(?:clear|new)(?:\s|$)/.test(text.trim());
|
|
4783
4759
|
/** mtime(ms), 0 when unreadable — "newest transcript wins" 的排序键。 */
|
|
4784
4760
|
const mtimeOf = (path) => {
|
|
4785
4761
|
try {
|
|
@@ -4823,7 +4799,7 @@ export const startMirror = (deps) => {
|
|
|
4823
4799
|
// new jsonl. Match that signature to (a) confirm the file is a /clear-rotated
|
|
4824
4800
|
// child, (b) avoid mis-migrating onto an unrelated jsonl that some other
|
|
4825
4801
|
// claude process happened to create on the same cwd in our window.
|
|
4826
|
-
const SLASH_CLEAR_USER_RE = /<command-name>\s*\/clear\s*<\/command-name>/;
|
|
4802
|
+
const SLASH_CLEAR_USER_RE = /<command-name>\s*\/(?:clear|new)\s*<\/command-name>/;
|
|
4827
4803
|
const jsonlIsPostClearChild = (path) => {
|
|
4828
4804
|
try {
|
|
4829
4805
|
const fd = openSync(path, "r");
|
|
@@ -4943,15 +4919,24 @@ export const startMirror = (deps) => {
|
|
|
4943
4919
|
});
|
|
4944
4920
|
// 会话轮换 = 新 <sid>/subagents/ 目录; 旧 run 的 turn 一并收口。
|
|
4945
4921
|
startSubagentsFor(a);
|
|
4922
|
+
// pane 没换 (轮换只换会话): 窗口名/pid/cliPid 照旧带着, restore 的核对才不会失去凭据。
|
|
4923
|
+
const prevAtt = deps.store.get(a.target);
|
|
4924
|
+
const rotKeep = prevAtt?.tmuxPane === (a.tmuxPane || undefined);
|
|
4946
4925
|
deps.store.set(a.target, {
|
|
4947
4926
|
sessionId: newSessionId,
|
|
4948
4927
|
jsonlPath: newJsonlPath,
|
|
4949
4928
|
tmuxSession: a.tmuxSession || undefined,
|
|
4950
4929
|
tmuxPane: a.tmuxPane || undefined,
|
|
4930
|
+
...(rotKeep && prevAtt?.tmuxWindow ? { tmuxWindow: prevAtt.tmuxWindow } : {}),
|
|
4931
|
+
...(rotKeep && prevAtt?.tmuxPid ? { tmuxPid: prevAtt.tmuxPid } : {}),
|
|
4932
|
+
...(rotKeep && prevAtt?.cliPid ? { cliPid: prevAtt.cliPid } : {}),
|
|
4951
4933
|
cwd: a.runningCwd || undefined,
|
|
4952
4934
|
model: a.model || undefined,
|
|
4953
4935
|
effort: a.effort || undefined,
|
|
4954
4936
|
pendingCwd: a.pendingCwd || undefined,
|
|
4937
|
+
// /clear 刚挂上的那份 (contextCut → armCharter) 跟到新会话的记录上; fork/drift
|
|
4938
|
+
// 上下文是延续的, pending 为空, 也就不欠。
|
|
4939
|
+
charterOwed: a.charterPending ? true : undefined,
|
|
4955
4940
|
});
|
|
4956
4941
|
log.info({ target: a.target, oldSessionId, newSessionId, oldJsonlPath, newJsonlPath, startOffset }, "mirror migrated session");
|
|
4957
4942
|
};
|
|
@@ -5303,12 +5288,6 @@ export const startMirror = (deps) => {
|
|
|
5303
5288
|
// /new path: kill the old pane (so we don't leak orphan tmux windows) and
|
|
5304
5289
|
// spawn a fresh claude in pendingCwd ?? runningCwd ?? default. Returns the
|
|
5305
5290
|
// new sessionId/cwd so callers can render the user-facing reply.
|
|
5306
|
-
// 身份提供者。newSession / 重生 / clone 全都从这里取「这个 target 是谁」, 于是
|
|
5307
|
-
// 无论是群里手打的 /new、pane 死了的自愈重生, 还是编排生出来的分身, 新进程一
|
|
5308
|
-
// 睁眼就知道自己是谁 —— 而不是只有走 wizard 路由那一条路才有身份。
|
|
5309
|
-
// 由 index.ts 在启动时装上 (注册表活在那边); 没装 = 退回无身份行为, 全链路无回归。
|
|
5310
|
-
let charterOf;
|
|
5311
|
-
const setCharterProvider = (fn) => { charterOf = fn; };
|
|
5312
5291
|
// 新 pane 落地后的钩子 —— pane 上限在这里数 (由 index.ts 装上; 没装 = 不数)。
|
|
5313
5292
|
let afterSpawn = () => { };
|
|
5314
5293
|
const onSpawn = (fn) => { afterSpawn = fn; };
|
|
@@ -5323,26 +5302,31 @@ export const startMirror = (deps) => {
|
|
|
5323
5302
|
log.warn({ target, cut, err: e.message }, "onContextCut hook threw");
|
|
5324
5303
|
}
|
|
5325
5304
|
};
|
|
5326
|
-
// `cwd` = 这个 pane 正要启动的目录。attach 在 spawn 之后才发生, 所以此刻 getCwd
|
|
5327
|
-
// 给的还是上一个 pane 的目录 —— 换目录重开时照它渲染, 新 wizard 会以为自己还在
|
|
5328
|
-
// 旧工作区里。
|
|
5329
|
-
const charterFor = (target, ctx) => {
|
|
5330
|
-
try {
|
|
5331
|
-
return charterOf?.(target, ctx);
|
|
5332
|
-
}
|
|
5333
|
-
catch {
|
|
5334
|
-
return undefined;
|
|
5335
|
-
}
|
|
5336
|
-
};
|
|
5337
|
-
/** 宪章 → 首条注入顶在最前的 reminder 块。认/剥/折叠全靠它是合法 reminder 块
|
|
5338
|
-
* (kind "charter", shared/reminder.ts): cleanUserText 剥它 → 回显去重与印章
|
|
5339
|
-
* 认到的仍是纯正文; peers.stripMeta 剥它 → talkTurns / read_chat 的问话干净;
|
|
5340
|
-
* rolepage 把它折叠成 `<charter>` 标签。正文里出现闭合标签字面量会截断这些
|
|
5341
|
-
* 剥离 (懒惰匹配到第一个闭合就停), 顺手转义掉。 */
|
|
5342
|
-
const charterPreamble = (charter) => `<system-reminder wezard="charter">\n${charter.trim().replace(/<\/(system-reminder|pasted_content)/g, "<\\/$1")}\n</system-reminder>\n`;
|
|
5343
5305
|
/** 这一条注入该带的前置宪章: 挂了 charterPending 且不是斜杠命令才有 —— preamble
|
|
5344
5306
|
* 会把命令顶得不再是命令, 宪章留到下一条非命令消息。 */
|
|
5345
5307
|
const charterPrefixOf = (a, text) => a.charterPending?.trim() && !text.trimStart().startsWith("/") ? charterPreamble(a.charterPending) : "";
|
|
5308
|
+
/** 宪章 pending 的内存态写同步到绑定记录: reload 之后内存没了, 磁盘上的
|
|
5309
|
+
* `charterOwed` 是 attach 重新武装它的唯一凭据。记录已被别的会话接管时不写 ——
|
|
5310
|
+
* 那是别人的账。 */
|
|
5311
|
+
const persistCharterOwed = (a, owed) => {
|
|
5312
|
+
const rec = deps.store.get(a.target);
|
|
5313
|
+
if (!rec || rec.sessionId !== a.sessionId)
|
|
5314
|
+
return;
|
|
5315
|
+
if (Boolean(rec.charterOwed) === owed)
|
|
5316
|
+
return;
|
|
5317
|
+
deps.store.set(a.target, { ...rec, charterOwed: owed || undefined });
|
|
5318
|
+
};
|
|
5319
|
+
/** --resume 重生后宪章该不该重挂: 已欠着就照挂; 否则上下文里已有 (最近切断之后) 就不挂。 */
|
|
5320
|
+
const charterOwedOnResume = (a, charter) => a.charterPending?.trim() || deps.store.get(a.target)?.charterOwed || charterInContext({ cli: backendForPath(a.jsonlPath).name, jsonlPath: a.jsonlPath }) !== true
|
|
5321
|
+
? charter
|
|
5322
|
+
: undefined;
|
|
5323
|
+
/** 挂/清这个 pane 的宪章 (内存 + 落盘): 除 attach 自己那次 (它紧接着整份重写记录,
|
|
5324
|
+
* 一并带上 charterOwed) 之外, 所有 `charterPending = …` 都走它 —— 否则 reload
|
|
5325
|
+
* 恢复出来的绑定分不清「欠着」与「已送达」。 */
|
|
5326
|
+
const setCharterPending = (a, charter) => {
|
|
5327
|
+
a.charterPending = charter?.trim() || undefined;
|
|
5328
|
+
persistCharterOwed(a, Boolean(a.charterPending));
|
|
5329
|
+
};
|
|
5346
5330
|
/** 把宪章挂到 target 的首条注入上 (见 AttachState.charterPending)。给了 `charter`
|
|
5347
5331
|
* 就用它, 没给现渲染。codex 免: developer_instructions 已带, 不必重复。 */
|
|
5348
5332
|
const armCharter = (target, charter) => {
|
|
@@ -5351,7 +5335,7 @@ export const startMirror = (deps) => {
|
|
|
5351
5335
|
return false;
|
|
5352
5336
|
const cli = backendForPath(a.jsonlPath).name;
|
|
5353
5337
|
const text = (charter ?? charterFor(target, { cwd: a.runningCwd, cli }) ?? "").trim();
|
|
5354
|
-
a
|
|
5338
|
+
setCharterPending(a, cli === "codex" ? undefined : text);
|
|
5355
5339
|
return true;
|
|
5356
5340
|
};
|
|
5357
5341
|
/** 死 pane 重生: 管家重新取 router 档位, 普通 wizard 沿用绑定模型。 */
|
|
@@ -5378,6 +5362,10 @@ export const startMirror = (deps) => {
|
|
|
5378
5362
|
(prev?.pendingCwd?.trim()) ||
|
|
5379
5363
|
(prev?.runningCwd?.trim()) ||
|
|
5380
5364
|
(rec?.cwd?.trim()) ||
|
|
5365
|
+
// 身份有工作区 (引导建的管家、它在别的群的化身) 而这个 target 还没起过会话: 落在身份的
|
|
5366
|
+
// 工作区, 不落聊天兜底 / 全局默认。排在 running 之后: 已在跑的会话 (含 set_workspace
|
|
5367
|
+
// 换过目录的) 重开仍跟自己的 cwd 走。
|
|
5368
|
+
(deps.identityWorkspace?.(target)?.trim() ? expandHome(deps.identityWorkspace(target).trim()) : "") ||
|
|
5381
5369
|
chat.running ||
|
|
5382
5370
|
expandedDefaultCwd;
|
|
5383
5371
|
// Fresh panes always use the configured backend, regardless of old bindings
|
|
@@ -5409,7 +5397,6 @@ export const startMirror = (deps) => {
|
|
|
5409
5397
|
handoffId: opts?.handoffId,
|
|
5410
5398
|
windowName: windowLabel(target, windowName),
|
|
5411
5399
|
cwdOverride: eff,
|
|
5412
|
-
chatKey: target,
|
|
5413
5400
|
cli: effCli,
|
|
5414
5401
|
model: effModel,
|
|
5415
5402
|
effort: effEffort,
|
|
@@ -5451,7 +5438,7 @@ export const startMirror = (deps) => {
|
|
|
5451
5438
|
spawned.justSpawned = true;
|
|
5452
5439
|
spawned.muteUntilInject = true;
|
|
5453
5440
|
// 全新的会话 = 一份它还没读过的宪章; codex 的已在 developer_instructions。
|
|
5454
|
-
spawned
|
|
5441
|
+
setCharterPending(spawned, effCli === "codex" ? undefined : charter);
|
|
5455
5442
|
// 只有换过 pane 才是断点 —— 首次建会话时 prev 为空, 那不是"不连续", 是开局。
|
|
5456
5443
|
if (prev)
|
|
5457
5444
|
markCut(target, spawned.sessionId, "new");
|
|
@@ -5472,6 +5459,7 @@ export const startMirror = (deps) => {
|
|
|
5472
5459
|
model: baseA.model || undefined,
|
|
5473
5460
|
effort: baseA.effort || undefined,
|
|
5474
5461
|
cwdConfirmed: deps.store.get(base)?.cwdConfirmed,
|
|
5462
|
+
charterOwed: deps.store.get(base)?.charterOwed,
|
|
5475
5463
|
pendingCwd: undefined,
|
|
5476
5464
|
});
|
|
5477
5465
|
}
|
|
@@ -5482,7 +5470,7 @@ export const startMirror = (deps) => {
|
|
|
5482
5470
|
}
|
|
5483
5471
|
}
|
|
5484
5472
|
if (!opts?.silent)
|
|
5485
|
-
pushProjectInfo(target,
|
|
5473
|
+
pushProjectInfo(target, createdAck(target));
|
|
5486
5474
|
afterSpawn();
|
|
5487
5475
|
return { ok: true, sessionId: r.sessionId, cwd: r.cwd, model: r.model, modelWarning: r.modelWarning, effort: r.effort };
|
|
5488
5476
|
};
|
|
@@ -5565,7 +5553,6 @@ export const startMirror = (deps) => {
|
|
|
5565
5553
|
forkSession: true,
|
|
5566
5554
|
windowName: windowLabel(args.target, args.windowName),
|
|
5567
5555
|
cwdOverride: parent.runningCwd,
|
|
5568
|
-
chatKey: args.target,
|
|
5569
5556
|
cli: parentCli,
|
|
5570
5557
|
model,
|
|
5571
5558
|
effort,
|
|
@@ -5686,6 +5673,13 @@ export const startMirror = (deps) => {
|
|
|
5686
5673
|
return { runningCwd: rec.cwd?.trim() || expandedDefaultCwd, pendingCwd: pending, defaultCwd: expandedDefaultCwd };
|
|
5687
5674
|
return { runningCwd: chat.running || expandedDefaultCwd, pendingCwd: pending, defaultCwd: expandedDefaultCwd };
|
|
5688
5675
|
};
|
|
5676
|
+
/** getCwd 的事实部分 (不掺默认目录): 附着的看 pane, 其次记录, 再其次聊天级 base 的 running。 */
|
|
5677
|
+
const knownCwd = (target) => {
|
|
5678
|
+
const chat = chatCwdFallback(target);
|
|
5679
|
+
const a = byTarget.get(target);
|
|
5680
|
+
const running = a ? (a.runningCwd ?? "").trim() : (deps.store.get(target)?.cwd ?? "").trim() || chat.running;
|
|
5681
|
+
return { runningCwd: running, pendingCwd: chat.pending, defaultCwd: expandedDefaultCwd };
|
|
5682
|
+
};
|
|
5689
5683
|
// Write `pendingCwd` to the BASE principal so the switch applies chat-wide —
|
|
5690
5684
|
// the next /new or self-handoff in any tagged/untagged session picks it up. `set_workspace`
|
|
5691
5685
|
// from a tagged session still writes to the shared slot, not the tagged
|
|
@@ -5710,6 +5704,7 @@ export const startMirror = (deps) => {
|
|
|
5710
5704
|
tmuxPane: baseA.tmuxPane || undefined,
|
|
5711
5705
|
cwd: baseA.runningCwd || undefined,
|
|
5712
5706
|
cwdConfirmed: deps.store.get(base)?.cwdConfirmed,
|
|
5707
|
+
charterOwed: deps.store.get(base)?.charterOwed,
|
|
5713
5708
|
pendingCwd: baseA.pendingCwd || undefined,
|
|
5714
5709
|
});
|
|
5715
5710
|
log.info({ target, base, runningCwd: callerRunning, pendingCwd: expanded }, "setPendingCwd (chat-scoped, live base)");
|
|
@@ -5734,6 +5729,7 @@ export const startMirror = (deps) => {
|
|
|
5734
5729
|
tmuxPane: callerA.tmuxPane || undefined,
|
|
5735
5730
|
cwd: callerA.runningCwd || undefined,
|
|
5736
5731
|
cwdConfirmed: deps.store.get(target)?.cwdConfirmed,
|
|
5732
|
+
charterOwed: deps.store.get(target)?.charterOwed,
|
|
5737
5733
|
pendingCwd: callerA.pendingCwd || undefined,
|
|
5738
5734
|
});
|
|
5739
5735
|
log.info({ target, runningCwd: callerA.runningCwd, pendingCwd: callerA.pendingCwd }, "setPendingCwd (fallback: no base, wrote to caller)");
|
|
@@ -5747,32 +5743,6 @@ export const startMirror = (deps) => {
|
|
|
5747
5743
|
}
|
|
5748
5744
|
return { ok: false, reason: "no mirror binding for target — send a message in the WeCom chat first", runningCwd: "", pendingCwd: "" };
|
|
5749
5745
|
};
|
|
5750
|
-
// 「人说了就用这个目录」。一个新聊天的第一个 wizard 落在默认兜底目录里 —— 那不是
|
|
5751
|
-
// 选择, 只是没人说过。所以默认按「还要换」办 (charter 让它开工前先问一句), 直到人
|
|
5752
|
-
// 明说不用换。**只有这一个写入点**: 换去别的目录本身就是选择, 不必记一笔, 那时
|
|
5753
|
-
// runningCwd 已经不等于默认目录, cwdUnconfirmed 自然为假。
|
|
5754
|
-
// 寻址与 pendingCwd 同规 —— 写在 base 上 (聊天级), 没有 base 记录 (只有 tagged
|
|
5755
|
-
// 会话的聊天) 就退回调用方自己的那条。
|
|
5756
|
-
const confirmCwd = (target) => {
|
|
5757
|
-
const base = baseOfKey(target);
|
|
5758
|
-
const key = deps.store.get(base) ? base : deps.store.get(target) ? target : "";
|
|
5759
|
-
const rec = key ? deps.store.get(key) : undefined;
|
|
5760
|
-
if (!rec)
|
|
5761
|
-
return { ok: false, reason: "no mirror binding for target — send a message in the WeCom chat first", cwd: "" };
|
|
5762
|
-
deps.store.set(key, { ...rec, cwdConfirmed: true });
|
|
5763
|
-
const cwd = getCwd(target).runningCwd;
|
|
5764
|
-
log.info({ target, key, cwd }, "cwd confirmed by user");
|
|
5765
|
-
return { ok: true, cwd };
|
|
5766
|
-
};
|
|
5767
|
-
/** 该不该问人「要在哪个项目下干活」: 还蹲在默认兜底目录里, 而且人没说过就用它。 */
|
|
5768
|
-
const cwdUnconfirmed = (target, cwd) => {
|
|
5769
|
-
const base = baseOfKey(target);
|
|
5770
|
-
if (deps.store.get(base)?.cwdConfirmed || deps.store.get(target)?.cwdConfirmed)
|
|
5771
|
-
return false;
|
|
5772
|
-
// `cwd` 是调用方已经知道的「即将生效的目录」(spawn 前的宪章渲染)。没给就问现状。
|
|
5773
|
-
const eff = cwd?.trim() ? expandHome(cwd.trim()) : getCwd(target).runningCwd;
|
|
5774
|
-
return eff === expandedDefaultCwd;
|
|
5775
|
-
};
|
|
5776
5746
|
// ── Peer graph (sibling sessions of one chat) ────────────────────────
|
|
5777
5747
|
// 关一个会话的 pane。`drop` = /kill: 连绑定一起删, 下一条消息另起白板; 否则只是睡着 (同 pane cap 的 reap), 绑定留着、`--resume` 带全上下文复活。
|
|
5778
5748
|
const downPane = async (target, drop) => {
|
|
@@ -5841,14 +5811,16 @@ export const startMirror = (deps) => {
|
|
|
5841
5811
|
if (/^(user|chat|group|external_user):/.test(raw)) {
|
|
5842
5812
|
return all.includes(raw) ? hit(raw) : { ok: false, reason: `no running session '${raw}'` };
|
|
5843
5813
|
}
|
|
5844
|
-
|
|
5814
|
+
// 名字属于身份 (§2): 优先落「身份在调用方本聊天的化身」(A 群里的 chat_ask 点名只找
|
|
5815
|
+
// A 群的化身, 不串 B 群的); 身份在本聊天没有化身时回落锚点化身 (旧世界的跨群寻址)。
|
|
5816
|
+
const named = ((t) => (t && sameBot(self, t) ? t : undefined))(manifestationOf(wizardStore(), raw, baseOfKey(self)));
|
|
5845
5817
|
if (named && all.includes(named))
|
|
5846
5818
|
return hit(named);
|
|
5847
5819
|
if (named)
|
|
5848
|
-
return { ok: false, reason: `wizard '
|
|
5820
|
+
return { ok: false, reason: `wizard '${raw}' exists but its session is not running — respawn it (spawn_wizard) or pick another` };
|
|
5849
5821
|
return {
|
|
5850
5822
|
ok: false,
|
|
5851
|
-
reason: `no wizard named '
|
|
5823
|
+
reason: `no wizard named '${raw}' — wizard_roster lists every name`,
|
|
5852
5824
|
candidates: all.map((k) => peerAddress(cfg, k)),
|
|
5853
5825
|
};
|
|
5854
5826
|
};
|
|
@@ -5870,6 +5842,34 @@ export const startMirror = (deps) => {
|
|
|
5870
5842
|
};
|
|
5871
5843
|
const paneOf = (target) => byTarget.get(target)?.tmuxPane || deps.store.get(target)?.tmuxPane || "";
|
|
5872
5844
|
const jsonlOf = (target) => expandHome(byTarget.get(target)?.jsonlPath || deps.store.get(target)?.jsonlPath || "");
|
|
5845
|
+
// pane 回收 (上限 / 空闲) 共用: 一次 list-panes 同时回答「活着吗」和「有人盯着吗」——
|
|
5846
|
+
// 跑了几个月的机器上 allTargets 是几百个 key, 见 target 就问 tmux 会打穿 fd (同
|
|
5847
|
+
// worldPeers 的 WORLD_PROBE 取舍)。`watchedBy` 的键集合就是活着的 pane。
|
|
5848
|
+
const paneSnapshot = async () => {
|
|
5849
|
+
const snap = await runTmux(["list-panes", "-a", "-F", "#{pane_id}\t#{window_active}:#{session_attached}\t#{session_name}\t#{pane_pid}"]);
|
|
5850
|
+
if (snap.code !== 0)
|
|
5851
|
+
return undefined;
|
|
5852
|
+
const rows = snap.stdout.split("\n").filter(Boolean).map((l) => l.split("\t"));
|
|
5853
|
+
const watchedBy = new Map(rows.map(([id = "", w = ""]) => {
|
|
5854
|
+
const [wActive, sAttached] = w.split(":");
|
|
5855
|
+
return [id, wActive === "1" && sAttached !== "0"];
|
|
5856
|
+
}));
|
|
5857
|
+
return { rows, watchedBy };
|
|
5858
|
+
};
|
|
5859
|
+
// 收一个 pane; 返回没收成的原因, 收掉了返回 undefined。
|
|
5860
|
+
const putDownPane = async (pane, watchedBy) => {
|
|
5861
|
+
// 人正盯着这个 window —— 收掉他的视野比省下那点内存更讨嫌。
|
|
5862
|
+
if (watchedBy.get(pane))
|
|
5863
|
+
return "watched";
|
|
5864
|
+
// 截屏判忙 (TUI spinner 脚注): 长工具调用 / 停在审批里都还是这一轮, 不收。
|
|
5865
|
+
if (paneIsBusy(await capturePaneTail(pane, 12)))
|
|
5866
|
+
return "busy";
|
|
5867
|
+
// 与 killPane 同款前戏: Esc 给生成中的 CLI 一个收束落盘的机会。
|
|
5868
|
+
await runTmux(["send-keys", "-t", pane, "Escape"]);
|
|
5869
|
+
await sleep(250);
|
|
5870
|
+
const r = await runTmux(["kill-pane", "-t", pane]);
|
|
5871
|
+
return r.code === 0 ? undefined : `kill-pane failed: ${r.stdout.slice(-120) || r.code}`;
|
|
5872
|
+
};
|
|
5873
5873
|
const inputSessionInfo = (target) => {
|
|
5874
5874
|
const pane = paneOf(target);
|
|
5875
5875
|
const transcript = jsonlOf(target);
|
|
@@ -5912,19 +5912,22 @@ export const startMirror = (deps) => {
|
|
|
5912
5912
|
return false;
|
|
5913
5913
|
if (live.status !== "idle")
|
|
5914
5914
|
return undefined;
|
|
5915
|
-
return !hanging(target, live.sessionId);
|
|
5915
|
+
return !hanging(target, live.sessionId, live.startedAt);
|
|
5916
5916
|
};
|
|
5917
5917
|
/** 闲着却悬着工具调用 = 停在审批卡 / 本地弹窗上。resume / fork 会换 sid: 悬着的
|
|
5918
5918
|
* 调用记在注册表报的当前那份 transcript 里。 */
|
|
5919
|
-
const hanging = (target, sid) => {
|
|
5919
|
+
const hanging = (target, sid, startedAt = 0) => {
|
|
5920
5920
|
const bound = jsonlOf(target);
|
|
5921
5921
|
const jsonl = bound ? join(dirname(bound), `${sid}.jsonl`) : "";
|
|
5922
|
-
|
|
5922
|
+
// 只数这个 CLI 进程启动之后发出的调用: 重生 / resume 的 pane 读到的是上一个进程被杀时
|
|
5923
|
+
// 留在 transcript 里的悬空调用, 它没有任何审批在等 —— 误判成「停在审批卡」会让
|
|
5924
|
+
// requireIdle 的唤醒永远贴不进去 (BobZane 循环的第二半)。
|
|
5925
|
+
return !!jsonl && existsSync(jsonl) && openToolUses(jsonl, startedAt).length > 0;
|
|
5923
5926
|
};
|
|
5924
5927
|
const parkedNow = (target) => {
|
|
5925
5928
|
const pane = paneOf(target);
|
|
5926
5929
|
const live = pane ? activeBackends().map((b) => sessionOnPane(b.homeDir, pane)).find(Boolean) : undefined;
|
|
5927
|
-
return live?.status === "idle" && hanging(target, live.sessionId);
|
|
5930
|
+
return live?.status === "idle" && hanging(target, live.sessionId, live.startedAt);
|
|
5928
5931
|
};
|
|
5929
5932
|
const idleNow = async (target) => {
|
|
5930
5933
|
// An interrupt footer vetoes stale idle records; never strip its dim text.
|
|
@@ -5947,6 +5950,10 @@ export const startMirror = (deps) => {
|
|
|
5947
5950
|
return !(await paneRunsShell(pane));
|
|
5948
5951
|
return !!cap.trim() && box.known;
|
|
5949
5952
|
};
|
|
5953
|
+
const paneAliveFor = async (target) => {
|
|
5954
|
+
const pane = paneOf(target);
|
|
5955
|
+
return !!pane && (await tmuxPaneAlive(pane));
|
|
5956
|
+
};
|
|
5950
5957
|
// 等到它闲下来, 事件驱动: 注册表目录一有写入就重判, 翻成 idle 的那一刻即返回。
|
|
5951
5958
|
// 兜底轮询只防 watch 漏事件 (以及悬着的审批被点掉后 status 没再动的边角)。
|
|
5952
5959
|
const IDLE_SAFETY_POLL_MS = 1000;
|
|
@@ -6121,7 +6128,7 @@ export const startMirror = (deps) => {
|
|
|
6121
6128
|
const jsonl = jsonlOf(target);
|
|
6122
6129
|
const busy = await isBusy(target);
|
|
6123
6130
|
if (!jsonl || !existsSync(jsonl))
|
|
6124
|
-
return { ok: false, reason: "它还没有 transcript (没接过第一句话) ——
|
|
6131
|
+
return { ok: false, reason: "它还没有 transcript (没接过第一句话) —— 在它的 room 里 chat_ask 一句就有了", busy };
|
|
6125
6132
|
// `n` 数的是来回: 每个来回给问话和它最新的一句 (跑完的是终句, 还在跑的是途中
|
|
6126
6133
|
// 最近说的那句) —— 途中的其余叙述不给, 那是过程不是结论。
|
|
6127
6134
|
const rounds = talkRounds(jsonl, n).slice(-n);
|
|
@@ -6641,7 +6648,9 @@ export const startMirror = (deps) => {
|
|
|
6641
6648
|
?.catch((e) => {
|
|
6642
6649
|
if (maintenanceValid(a, pane, sid, gen, maintenance.signal))
|
|
6643
6650
|
a.pickerSentinelFp = undefined;
|
|
6644
|
-
|
|
6651
|
+
// 真实输入抢占维护任务是预期行为 (pane-input canceled), 不是故障。
|
|
6652
|
+
const preempted = e instanceof PaneInputError && e.code === "canceled";
|
|
6653
|
+
(preempted ? log.debug : log.warn).call(log, { target: a.target, err: e.message }, "picker sentinel tick failed");
|
|
6645
6654
|
});
|
|
6646
6655
|
}
|
|
6647
6656
|
};
|
|
@@ -6812,6 +6821,17 @@ export const startMirror = (deps) => {
|
|
|
6812
6821
|
return { ok: false, reason: `pane 里跑的是会话 ${live}, 绑定的是 ${a.sessionId} — 原生切过会话, 拒绝凭错的现场清空` };
|
|
6813
6822
|
return { ok: true };
|
|
6814
6823
|
};
|
|
6824
|
+
const processIdentity = async (target) => {
|
|
6825
|
+
const a = byTarget.get(target);
|
|
6826
|
+
if (!a?.tmuxPane)
|
|
6827
|
+
return undefined;
|
|
6828
|
+
const panePid = await panePidOf(a.tmuxPane);
|
|
6829
|
+
if (!panePid)
|
|
6830
|
+
return undefined;
|
|
6831
|
+
const backend = backendForPath(a.jsonlPath);
|
|
6832
|
+
const pid = backend.name === "claude" || backend.name === "claude-internal" ? sessionOnPane(backend.homeDir, a.tmuxPane)?.pid : undefined;
|
|
6833
|
+
return `${a.tmuxPane}:${panePid}:${pid ?? ""}`;
|
|
6834
|
+
};
|
|
6815
6835
|
const clearContext = async (target, attempt, submitted, guard = () => true) => {
|
|
6816
6836
|
if (!guard())
|
|
6817
6837
|
return { ok: false, reason: "handoff continuation authority withdrawn; no input" };
|
|
@@ -7085,6 +7105,7 @@ export const startMirror = (deps) => {
|
|
|
7085
7105
|
};
|
|
7086
7106
|
return {
|
|
7087
7107
|
attach,
|
|
7108
|
+
processIdentity,
|
|
7088
7109
|
clearContext,
|
|
7089
7110
|
nativeClearSupport,
|
|
7090
7111
|
verifyClearContext,
|
|
@@ -7097,6 +7118,7 @@ export const startMirror = (deps) => {
|
|
|
7097
7118
|
peekTurns,
|
|
7098
7119
|
isBusy,
|
|
7099
7120
|
idleNow,
|
|
7121
|
+
paneAliveFor,
|
|
7100
7122
|
parkedNow,
|
|
7101
7123
|
idleVerdict,
|
|
7102
7124
|
untilIdle,
|
|
@@ -7348,13 +7370,19 @@ export const startMirror = (deps) => {
|
|
|
7348
7370
|
if (probe.state !== "session") {
|
|
7349
7371
|
if (opts?.noRespawn)
|
|
7350
7372
|
return { ok: false, retryable: false, reason: "original CLI is unavailable; handoff never respawns" };
|
|
7373
|
+
const respawnCli = backendForPath(a.jsonlPath).name;
|
|
7374
|
+
// Checked before the warn: callers like the room pump retry every 30s,
|
|
7375
|
+
// and a "respawning" line per round for a pane that will never be born
|
|
7376
|
+
// reads as churn that isn't happening.
|
|
7377
|
+
const missing = resumeTranscriptMissing(a.jsonlPath, respawnCli);
|
|
7378
|
+
if (missing)
|
|
7379
|
+
return { ok: false, retryable: false, reason: `respawn skipped: ${missing}` };
|
|
7351
7380
|
log.warn({ target, sessionId: sid, oldPane: a.tmuxPane, why: probe.state }, "injectText: pane not alive, respawning");
|
|
7352
7381
|
// Same resume-fork hazard as dispatch: snapshot before spawn, re-bind
|
|
7353
7382
|
// onto the forked jsonl once it appears (EOF offset — fork is seeded).
|
|
7354
7383
|
const resumeBaseline = listJsonls(dirname(a.jsonlPath));
|
|
7355
|
-
const respawnCli = backendForPath(a.jsonlPath).name;
|
|
7356
7384
|
const charter = charterFor(target, { cwd: a.runningCwd, cli: respawnCli });
|
|
7357
|
-
const r = await spawnTmuxClaude({ cfg, log: log.child({ sub: "respawn-init", sessionId: sid }), resumeSessionId: sid, windowName: displayName(target) || target, cwdOverride: a.runningCwd,
|
|
7385
|
+
const r = await spawnTmuxClaude({ cfg, log: log.child({ sub: "respawn-init", sessionId: sid }), resumeSessionId: sid, windowName: displayName(target) || target, cwdOverride: a.runningCwd, cli: respawnCli, ...respawnSpec(a), systemPrompt: charter });
|
|
7358
7386
|
if (!r.ok || !r.tmuxPane)
|
|
7359
7387
|
return { ok: false, retryable: r.retryable !== false, reason: `respawn failed: ${r.reason ?? "unknown"}` };
|
|
7360
7388
|
if (!permitted() || a.tmuxPane !== probedPane) {
|
|
@@ -7375,10 +7403,13 @@ export const startMirror = (deps) => {
|
|
|
7375
7403
|
if (r.model !== undefined)
|
|
7376
7404
|
a.model = r.model;
|
|
7377
7405
|
deps.store.set(target, { sessionId: sid, jsonlPath: a.jsonlPath, tmuxSession: a.tmuxSession, tmuxPane: a.tmuxPane, cwd: a.runningCwd || undefined, model: a.model || undefined, effort: a.effort || undefined, pendingCwd: a.pendingCwd || undefined });
|
|
7406
|
+
refreshPaneIdentity(target, a.tmuxPane, a.jsonlPath);
|
|
7378
7407
|
startMigrationWatcher(a, resumeBaseline, forkOf(a.jsonlPath));
|
|
7379
7408
|
// 重生出的 pane 里是同一份会话, 但宪章要重挂: --resume 读的是 CLI 自己的
|
|
7380
7409
|
// 系统提示, 我们的宪章只跟着消息走。下面的注入 (本函数尾部) 会带上它。
|
|
7381
|
-
|
|
7410
|
+
// 同一个会话 --resume 回来, 上下文里已有宪章 (最近一次切断之后) 就不再挂;
|
|
7411
|
+
// 欠着 / 读不到转录 / 被压缩压掉了才挂。
|
|
7412
|
+
setCharterPending(a, respawnCli === "codex" ? undefined : charterOwedOnResume(a, charter));
|
|
7382
7413
|
fresh = true;
|
|
7383
7414
|
}
|
|
7384
7415
|
if (!permitted())
|
|
@@ -7386,7 +7417,7 @@ export const startMirror = (deps) => {
|
|
|
7386
7417
|
// Busy/queued retries must not consume notices or stamp a future turn.
|
|
7387
7418
|
// Render only after the pane lane grants delivery, then stamp exactly at
|
|
7388
7419
|
// the first permitted input.
|
|
7389
|
-
const envelope = text
|
|
7420
|
+
const envelope = envelopeFor(text, opts?.envelope, opts?.eventId);
|
|
7390
7421
|
// 首条注入带上宪章 preamble (newSession/重生/清空后挂上的那份)。印章与回显
|
|
7391
7422
|
// 去重都记纯正文 —— cleanUserText 两侧都会剥掉 preamble, 认出的仍是同一句。
|
|
7392
7423
|
const pre = charterPrefixOf(a, text);
|
|
@@ -7394,8 +7425,9 @@ export const startMirror = (deps) => {
|
|
|
7394
7425
|
const beforeInput = () => {
|
|
7395
7426
|
a.pendingFromCli = false;
|
|
7396
7427
|
a.turnFromChat = true;
|
|
7428
|
+
touch(target);
|
|
7397
7429
|
rememberInject(full);
|
|
7398
|
-
pushSeal(a, { eventId: parseEnvelope(full)?.eventId, keys: sealKeys(full), at: Date.now(), query: text, from: opts?.from, channel: opts?.channel, fresh: idleVerdict(target) === true });
|
|
7430
|
+
pushSeal(a, { eventId: parseEnvelope(full)?.eventId, keys: sealKeys(full), at: Date.now(), query: text, from: opts?.from, speaker: opts?.speaker, channel: opts?.channel, fresh: idleVerdict(target) === true });
|
|
7399
7431
|
a.muteUntilInject = false;
|
|
7400
7432
|
a.justSpawned = false;
|
|
7401
7433
|
};
|
|
@@ -7411,14 +7443,14 @@ export const startMirror = (deps) => {
|
|
|
7411
7443
|
physicalGuard: opts?.handoff ? async (phase) => { const ok = permission() && await verifyClearInput(target, opts.handoff, phase, permission) && permission(); if (!ok)
|
|
7412
7444
|
pinRejected = true; return ok; } : undefined,
|
|
7413
7445
|
requireIdle: opts?.requireIdle ? () => idleNow(target) : undefined,
|
|
7414
|
-
prepareText: () => (full = pre + text + renderTail(envelope, noticeSuffixFor(target, text))),
|
|
7446
|
+
prepareText: () => (full = pre + text + renderTail(envelope, noticeSuffixFor(target, text, opts?.tail?.via, opts?.tail?.lead))),
|
|
7415
7447
|
beforeInput,
|
|
7416
7448
|
});
|
|
7417
7449
|
if (pinRejected)
|
|
7418
7450
|
return { ...r, ok: false, retryable: false, reason: "handoff process/session or continuation authority changed at physical input; carry withheld" };
|
|
7419
7451
|
// 带进去的宪章随这一条落定; 失败可重试 (r.ok=false) 的不清 —— 重投的下一条接着带。
|
|
7420
7452
|
if (r.ok)
|
|
7421
|
-
a
|
|
7453
|
+
setCharterPending(a, undefined);
|
|
7422
7454
|
if (r.ok && a.tmuxPane && permitted()) {
|
|
7423
7455
|
if (preClearBaseline) {
|
|
7424
7456
|
a.clearRebind = { baseline: preClearBaseline };
|
|
@@ -7432,15 +7464,11 @@ export const startMirror = (deps) => {
|
|
|
7432
7464
|
interruptPane: async (target, opts) => {
|
|
7433
7465
|
if (opts?.guard && !opts.guard())
|
|
7434
7466
|
return { ok: false, reason: "interrupt authority changed" };
|
|
7435
|
-
if (opts?.teardown)
|
|
7436
|
-
deps.events?.cancel((e) => e.target === target);
|
|
7437
7467
|
const a = byTarget.get(target);
|
|
7438
7468
|
if (!a)
|
|
7439
7469
|
return { ok: false, reason: "no mirror attached for target" };
|
|
7440
7470
|
const interruptedEvent = a.activeEventId;
|
|
7441
7471
|
const interruptedPane = a.tmuxPane;
|
|
7442
|
-
if (opts?.teardown && interruptedEvent)
|
|
7443
|
-
deps.events?.cancel((e) => e.id === interruptedEvent);
|
|
7444
7472
|
// `/stop` (teardown: true) must work when tmux itself is the problem, so
|
|
7445
7473
|
// the order is: local state first, pane second. The old implementation
|
|
7446
7474
|
// probed the pane FIRST and returned early on failure — meaning a wedged
|
|
@@ -7490,10 +7518,7 @@ export const startMirror = (deps) => {
|
|
|
7490
7518
|
return { ok: true, torndown, escOk, escReason: escReason || undefined };
|
|
7491
7519
|
},
|
|
7492
7520
|
killPane: async (target) => {
|
|
7493
|
-
deps.events?.cancel((e) => e.target === target);
|
|
7494
7521
|
const r = await downPane(target, true);
|
|
7495
|
-
if (r.ok)
|
|
7496
|
-
deps.events?.stopped(target, "pane kill acknowledged; queued input revoked");
|
|
7497
7522
|
return r;
|
|
7498
7523
|
},
|
|
7499
7524
|
sleepPane: (target) => downPane(target, false),
|
|
@@ -7506,6 +7531,51 @@ export const startMirror = (deps) => {
|
|
|
7506
7531
|
return 0;
|
|
7507
7532
|
}
|
|
7508
7533
|
},
|
|
7534
|
+
reapIdle: async (idleMs, skip) => {
|
|
7535
|
+
const now = Date.now();
|
|
7536
|
+
const reaped = [];
|
|
7537
|
+
const skipped = {};
|
|
7538
|
+
if (idleMs <= 0)
|
|
7539
|
+
return { reaped, skipped };
|
|
7540
|
+
const snap = await paneSnapshot();
|
|
7541
|
+
if (!snap)
|
|
7542
|
+
return { reaped, skipped };
|
|
7543
|
+
// pane 里 shell 的年龄 = 这个 pane 被本进程 (或更早) spawn / respawn 出来的时刻。resume
|
|
7544
|
+
// 出来的 pane 不会写新的 transcript 记录, 只信 transcript 会让刚重生的 pane 下一轮就被收。
|
|
7545
|
+
const ps = await psSnap();
|
|
7546
|
+
const bornAtOf = new Map(snap.rows.map(([id = "", , , pid = ""]) => [id, paneBornAt(now, ps.etimes.get(Number(pid)))]));
|
|
7547
|
+
for (const target of allTargets()) {
|
|
7548
|
+
const pane = paneOf(target);
|
|
7549
|
+
// 没活 pane 的绑定 (已经睡着的 / spawn-mode) 不是候选。
|
|
7550
|
+
if (!pane || !snap.watchedBy.has(pane))
|
|
7551
|
+
continue;
|
|
7552
|
+
const a = byTarget.get(target);
|
|
7553
|
+
const sessionId = a?.sessionId || deps.store.get(target)?.sessionId || "";
|
|
7554
|
+
const lastActiveAt = lastActiveOf({ seenAt: seenAt.get(target), transcriptAt: transcriptActiveAt(target), paneBornAt: bornAtOf.get(pane) });
|
|
7555
|
+
const why = idleSkipReason({
|
|
7556
|
+
lastActiveAt,
|
|
7557
|
+
watched: !!snap.watchedBy.get(pane),
|
|
7558
|
+
inFlight: spawningPanes.has(pane) || (!!sessionId && queues.has(sessionId)),
|
|
7559
|
+
veto: skip?.(target, sessionId),
|
|
7560
|
+
}, now, idleMs);
|
|
7561
|
+
if (why) {
|
|
7562
|
+
if (why !== "recent")
|
|
7563
|
+
skipped[target] = why;
|
|
7564
|
+
continue;
|
|
7565
|
+
}
|
|
7566
|
+
const down = await putDownPane(pane, snap.watchedBy);
|
|
7567
|
+
if (down) {
|
|
7568
|
+
skipped[target] = down;
|
|
7569
|
+
continue;
|
|
7570
|
+
}
|
|
7571
|
+
if (a)
|
|
7572
|
+
detach(a, "idle reap");
|
|
7573
|
+
// 不碰 store —— 绑定 / 身份留着, 下一条 inbound 走 dead-pane `--resume` 复活。
|
|
7574
|
+
reaped.push(target);
|
|
7575
|
+
log.info({ target, sessionId, pane, idleMin: Math.round((now - lastActiveAt) / 60_000), thresholdMin: Math.round(idleMs / 60_000) }, "mirror idle reap — pane killed, binding kept");
|
|
7576
|
+
}
|
|
7577
|
+
return { reaped, skipped };
|
|
7578
|
+
},
|
|
7509
7579
|
reapUnborn: async (names) => {
|
|
7510
7580
|
const want = new Set(names.flatMap((n) => [n, `.${n}`]));
|
|
7511
7581
|
if (!want.size)
|
|
@@ -7538,31 +7608,13 @@ export const startMirror = (deps) => {
|
|
|
7538
7608
|
const now = Date.now();
|
|
7539
7609
|
const reaped = [];
|
|
7540
7610
|
const skipped = {};
|
|
7541
|
-
// 一次 list-panes 同时回答「活着吗」和「有人盯着吗」—— 跑了几个月的机器上
|
|
7542
|
-
// allTargets 是几百个 key, 见 target 就问 tmux 会打穿 fd (同 worldPeers 的
|
|
7543
|
-
// WORLD_PROBE 取舍)。
|
|
7544
7611
|
const orphans = [];
|
|
7545
|
-
|
|
7546
|
-
|
|
7612
|
+
// 一次 list-panes 同时回答「活着吗」和「有人盯着吗」(见 paneSnapshot)。
|
|
7613
|
+
const snap = await paneSnapshot();
|
|
7614
|
+
if (!snap)
|
|
7547
7615
|
return { reaped, orphans, skipped };
|
|
7548
|
-
const rows = snap
|
|
7549
|
-
const
|
|
7550
|
-
const [wActive, sAttached] = w.split(":");
|
|
7551
|
-
return [id, wActive === "1" && sAttached !== "0"];
|
|
7552
|
-
}));
|
|
7553
|
-
// 收一个 pane; 返回没收成的原因, 收掉了返回 undefined。
|
|
7554
|
-
const putDown = async (pane) => {
|
|
7555
|
-
// 人正盯着这个 window —— 收掉他的视野比省下那点内存更讨嫌。
|
|
7556
|
-
if (watchedBy.get(pane))
|
|
7557
|
-
return "watched";
|
|
7558
|
-
if (paneIsBusy(await capturePaneTail(pane, 12)))
|
|
7559
|
-
return "busy";
|
|
7560
|
-
// 与 killPane 同款前戏: Esc 给生成中的 CLI 一个收束落盘的机会。
|
|
7561
|
-
await runTmux(["send-keys", "-t", pane, "Escape"]);
|
|
7562
|
-
await sleep(250);
|
|
7563
|
-
const r = await runTmux(["kill-pane", "-t", pane]);
|
|
7564
|
-
return r.code === 0 ? undefined : `kill-pane failed: ${r.stdout.slice(-120) || r.code}`;
|
|
7565
|
-
};
|
|
7616
|
+
const { rows, watchedBy } = snap;
|
|
7617
|
+
const putDown = (pane) => putDownPane(pane, watchedBy);
|
|
7566
7618
|
const targets = allTargets();
|
|
7567
7619
|
// 孤儿: 住在 daemon 自己的 tmux session 里、却没有任何绑定指着它的 pane —— 绑定
|
|
7568
7620
|
// 丢了 pane id (restore 认不出 → 下一条消息另起新 pane, 旧 pane 不杀) 之后留下的。
|
|
@@ -7574,6 +7626,9 @@ export const startMirror = (deps) => {
|
|
|
7574
7626
|
// 全盲。普通 pane (人自己开的 shell / ssh / 编辑器, 会话已退回 shell 的) 树里
|
|
7575
7627
|
// 没有注册表 pid, 一律跳过 —— 认不出就不动。
|
|
7576
7628
|
const regPids = new Set(activeBackends().flatMap((b) => [...liveSessionPids(b.homeDir)]));
|
|
7629
|
+
// store 里还指着它的绑定 (detach-only 回收 / 死 pane 保留的绑定): 这些 pane 不是孤儿,
|
|
7630
|
+
// 孤儿清扫不许收 —— 否则「只 detach 不 kill」的保护马上被自己拆掉。
|
|
7631
|
+
const storeBoundPanes = new Set(Object.values(deps.store.all()).map((r) => (r.tmuxPane ?? "").trim()).filter(Boolean));
|
|
7577
7632
|
const ps = await psSnap();
|
|
7578
7633
|
// 沿进程树找注册表 pid; 找到返回那个 pid (它的 etimes 供宽限判), 找不到返回 0。
|
|
7579
7634
|
const hostedBy = (pid) => {
|
|
@@ -7593,7 +7648,7 @@ export const startMirror = (deps) => {
|
|
|
7593
7648
|
};
|
|
7594
7649
|
for (const [pane = "", , session, pid] of rows) {
|
|
7595
7650
|
// 绑定现查而非用开头的快照: 前面几轮 putDown 的 await 期间别人可能刚 attach 上。
|
|
7596
|
-
if (session !== cfg.wrc.tmuxPrefix || spawningPanes.has(pane) || allTargets().some((t) => paneOf(t) === pane))
|
|
7651
|
+
if (session !== cfg.wrc.tmuxPrefix || spawningPanes.has(pane) || storeBoundPanes.has(pane) || allTargets().some((t) => paneOf(t) === pane))
|
|
7597
7652
|
continue;
|
|
7598
7653
|
const cliPid = hostedBy(Number(pid) || 0);
|
|
7599
7654
|
if (!cliPid)
|
|
@@ -7615,14 +7670,7 @@ export const startMirror = (deps) => {
|
|
|
7615
7670
|
if (over <= 0)
|
|
7616
7671
|
return { reaped, orphans, skipped };
|
|
7617
7672
|
// 超了才 stat: 最久没动的先收。还没写过 transcript 的是刚起的 pane, 按"此刻"算。
|
|
7618
|
-
const mtimeOf = (target) =>
|
|
7619
|
-
try {
|
|
7620
|
-
return statSync(jsonlOf(target)).mtimeMs;
|
|
7621
|
-
}
|
|
7622
|
-
catch {
|
|
7623
|
-
return now;
|
|
7624
|
-
}
|
|
7625
|
-
};
|
|
7673
|
+
const mtimeOf = (target) => transcriptActiveAt(target) || now;
|
|
7626
7674
|
const oldestFirst = live.map((target) => ({ target, mtime: mtimeOf(target) })).sort((x, y) => x.mtime - y.mtime);
|
|
7627
7675
|
for (const { target, mtime } of oldestFirst) {
|
|
7628
7676
|
if (over <= 0)
|
|
@@ -7634,6 +7682,15 @@ export const startMirror = (deps) => {
|
|
|
7634
7682
|
skipped[target] = veto;
|
|
7635
7683
|
continue;
|
|
7636
7684
|
}
|
|
7685
|
+
// 最近有人说过话: 只 detach 不 kill (pane/CLI/绑定全留着, 下次按 %N 或窗口名+pid
|
|
7686
|
+
// 认回), 不占回收名额 —— 宁可暂时超上限, 不把活会话换代码。
|
|
7687
|
+
if (now - mtime < RECENT_TALK_MS) {
|
|
7688
|
+
if (a)
|
|
7689
|
+
detach(a, "pane cap (recent)");
|
|
7690
|
+
skipped[target] = `recent (<${Math.round(RECENT_TALK_MS / 3.6e6)}h): detached only, pane kept`;
|
|
7691
|
+
log.info({ target, sessionId, idleHours: Math.round((now - mtime) / 3.6e6), max }, "mirror pane cap — recent target detached only (pane kept)");
|
|
7692
|
+
continue;
|
|
7693
|
+
}
|
|
7637
7694
|
const pane = paneOf(target);
|
|
7638
7695
|
const why = await putDown(pane);
|
|
7639
7696
|
if (why) {
|
|
@@ -7743,9 +7800,8 @@ export const startMirror = (deps) => {
|
|
|
7743
7800
|
return { status: "answered", title: v.title, index: pick.index, label: pick.label };
|
|
7744
7801
|
},
|
|
7745
7802
|
getCwd,
|
|
7803
|
+
knownCwd,
|
|
7746
7804
|
setPendingCwd,
|
|
7747
|
-
cwdUnconfirmed,
|
|
7748
|
-
confirmCwd,
|
|
7749
7805
|
newSession,
|
|
7750
7806
|
cloneSession,
|
|
7751
7807
|
sessionInfo,
|
|
@@ -7785,14 +7841,6 @@ export const startMirror = (deps) => {
|
|
|
7785
7841
|
const a = byTarget.get(target);
|
|
7786
7842
|
return a?.channel ?? baseOfKey(target);
|
|
7787
7843
|
},
|
|
7788
|
-
formatFinal,
|
|
7789
|
-
recoverEventFinal,
|
|
7790
|
-
deliverTransferredFinal,
|
|
7791
|
-
transferReply,
|
|
7792
|
-
setEventFinalGate: (gate) => { eventFinalGate = gate; },
|
|
7793
|
-
setEventProgressGate: (gate) => { eventProgressGate = gate; },
|
|
7794
|
-
setEventOwnerGate: (gate) => { eventOwnerGate = gate; },
|
|
7795
|
-
settleFinalProgress,
|
|
7796
7844
|
dispatch: async ({ principal, text, images, frame, streamId, channel, speaker, eventId, guard, onSubmitted }) => {
|
|
7797
7845
|
// Route by inbound principal — the WeCom chat the user just messaged us
|
|
7798
7846
|
// from is the same string we registered as `target` on attach. After a
|
|
@@ -7840,7 +7888,7 @@ export const startMirror = (deps) => {
|
|
|
7840
7888
|
// syncTmuxToSystemClipboard 冲掉, 见 injectViaTmux 分流注释) —— 图片只能以
|
|
7841
7889
|
// @<path> 文本进会话。既然如此, 问话 / 印章 / 回显去重 / 静默分叉跟随都按这个
|
|
7842
7890
|
// 最终落盘形态记 (与 inject 拿到的同一个字符串); 否则落盘的 `@<path>` 行认不出
|
|
7843
|
-
// 是自己注入的: 被当成 CLI 手敲另开幽灵轮、触发
|
|
7891
|
+
// 是自己注入的: 被当成 CLI 手敲另开幽灵轮、触发 出处门 吞回复, 而 IM 侧
|
|
7844
7892
|
// 预建的 turn 永远等不到问话改写, rolepage 的入消息丢了图 (rolepage 一律按 CLI
|
|
7845
7893
|
// 最终展示的那条消息渲染)。slash / /clear 判定仍用原始 text —— 命令不带图。
|
|
7846
7894
|
const refsFirst = backendForPath(a.jsonlPath).name === "codebuddy" && (images?.length ?? 0) > 0;
|
|
@@ -7985,7 +8033,10 @@ export const startMirror = (deps) => {
|
|
|
7985
8033
|
// mid-turn reincarnation — only /new and /clear-with-pending swap cwd).
|
|
7986
8034
|
const respawnCli = backendForPath(a.jsonlPath).name;
|
|
7987
8035
|
const charter = charterFor(a.target, { cwd: a.runningCwd, cli: respawnCli });
|
|
7988
|
-
const
|
|
8036
|
+
const missing = resumeTranscriptMissing(a.jsonlPath, respawnCli);
|
|
8037
|
+
const r = missing
|
|
8038
|
+
? { ok: false, retryable: false, reason: missing, tmuxPane: undefined, tmuxSession: undefined, cwd: undefined, model: undefined }
|
|
8039
|
+
: await spawnTmuxClaude({ cfg, log: log.child({ sub: "respawn", sessionId: sid }), resumeSessionId: sid, windowName: displayName(a.target) || a.target, cwdOverride: a.runningCwd, cli: respawnCli, ...respawnSpec(a), systemPrompt: charter });
|
|
7989
8040
|
if (byTarget.get(a.target) !== a || a.sessionId !== sid || (a.injectGen ?? 0) !== myGen || (guard && !guard())) {
|
|
7990
8041
|
// A stop or replacement during startup revokes this birth before binding.
|
|
7991
8042
|
if (r.tmuxPane)
|
|
@@ -8011,10 +8062,11 @@ export const startMirror = (deps) => {
|
|
|
8011
8062
|
effort: a.effort || undefined,
|
|
8012
8063
|
pendingCwd: a.pendingCwd || undefined,
|
|
8013
8064
|
});
|
|
8065
|
+
refreshPaneIdentity(a.target, a.tmuxPane, a.jsonlPath);
|
|
8014
8066
|
log.info({ target: a.target, sessionId: sid, newPane: a.tmuxPane, newSession: a.tmuxSession }, "mirror: tmux respawned");
|
|
8015
8067
|
// 重挂宪章 (同 injectText 的 respawn-init): --resume 只带回对话内容,
|
|
8016
8068
|
// 我们的宪章跟着消息走。本条注入 (下面) 会带上它。
|
|
8017
|
-
a
|
|
8069
|
+
setCharterPending(a, respawnCli === "codex" ? undefined : charterOwedOnResume(a, charter));
|
|
8018
8070
|
// Re-bind onto the resume fork once it appears (EOF offset: the fork
|
|
8019
8071
|
// already holds the full prior transcript — replaying from 0 would
|
|
8020
8072
|
// re-dump it). If --resume happens to keep the same jsonl, no new
|
|
@@ -8058,6 +8110,7 @@ export const startMirror = (deps) => {
|
|
|
8058
8110
|
}
|
|
8059
8111
|
if (!brief)
|
|
8060
8112
|
pushSeal(a, { eventId: a.activeEventId, keys: sealKeys(effText), at: Date.now(), query: effText, channel: channel ?? baseOfKey(principal), speaker, fresh: true });
|
|
8113
|
+
touch(a.target);
|
|
8061
8114
|
rememberInject(effText);
|
|
8062
8115
|
// 首条注入带上宪章 preamble (印章/去重/轮次问话都记纯正文 —— cleanUserText
|
|
8063
8116
|
// 在两侧剥掉 preamble, 认出的仍是同一句, 回执链的认领不受影响)。
|
|
@@ -8080,21 +8133,11 @@ export const startMirror = (deps) => {
|
|
|
8080
8133
|
guard: (phase, identity) => byTarget.get(a.target) === a && a.tmuxPane === injectPane && (a.injectGen ?? 0) === myGen && (!guard || guard(phase, identity)),
|
|
8081
8134
|
});
|
|
8082
8135
|
// 注入失败可以迟于转录消费;只认这一笔在原绑定转录里的标记,不用别轮产出猜 ACK。
|
|
8083
|
-
const submissionConfirmed = () => {
|
|
8084
|
-
const event = eventId ? deps.events?.get(eventId) : undefined;
|
|
8085
|
-
return !!event && !event.canceled
|
|
8086
|
-
&& (event.exposure === "consumed" || event.execution === "complete"
|
|
8087
|
-
|| !!event.transcript && submittedEventSince([{ path: event.transcript, offset: 0 }], event.id, event.at));
|
|
8088
|
-
};
|
|
8089
|
-
if (!r.ok && r.uncertain && submissionConfirmed()) {
|
|
8090
|
-
log.info({ target: a.target, eventId, reason: r.reason }, "mirror inject: late failure superseded by event submission evidence");
|
|
8091
|
-
r = { ok: true };
|
|
8092
|
-
}
|
|
8093
8136
|
// 宪章已随这一条进了 pane; 失败可重试的 (消息事件层会重投) 不清 —— 重投接着带。
|
|
8094
8137
|
// /clear 例外: 它自己不带 preamble, 而 tail 认出会话轮换 → contextCut → armCharter
|
|
8095
8138
|
// 可能先于这里的返回发生, 清了就会把刚挂上的下一份宪章抹掉。
|
|
8096
8139
|
if (r.ok && !armMigration)
|
|
8097
|
-
a
|
|
8140
|
+
setCharterPending(a, undefined);
|
|
8098
8141
|
onSubmitted?.(r);
|
|
8099
8142
|
if (!r.ok) {
|
|
8100
8143
|
// retryable = 一个字都没进输入框, 消息事件层会稍后重投 —— 不是失败, 别报 ✗
|
|
@@ -8110,8 +8153,7 @@ export const startMirror = (deps) => {
|
|
|
8110
8153
|
const note = r.uncertain
|
|
8111
8154
|
? "[mirror] ⚠ 暂时无法确认目标会话是否收到消息,已停止继续输入;为避免重复执行,不会自动重发"
|
|
8112
8155
|
: `[mirror] ✗ ${r.reason ?? "failed"}`;
|
|
8113
|
-
|
|
8114
|
-
const stillWanted = () => !r.uncertain || !submissionConfirmed();
|
|
8156
|
+
const stillWanted = () => true;
|
|
8115
8157
|
if (s) {
|
|
8116
8158
|
s.acc = s.acc ? `${s.acc}\n\n${note}` : note;
|
|
8117
8159
|
await finalizeStream(a, s, false, stillWanted);
|
|
@@ -8173,6 +8215,8 @@ export const startMirror = (deps) => {
|
|
|
8173
8215
|
// and surface a standalone "cleared" so the user gets explicit
|
|
8174
8216
|
// feedback (the skip-stream path otherwise leaves WeCom silent).
|
|
8175
8217
|
if (armMigration) {
|
|
8218
|
+
// room 口径: 出站门已废, 确认就是一条普通 standalone (裸 "cleared"),
|
|
8219
|
+
// 不再加 [wezard] 前缀 —— 系统行前缀的写法只留 daemon 系统行那一处。
|
|
8176
8220
|
sendStandalone(a, "cleared");
|
|
8177
8221
|
a.clearRebind = { baseline: preClearBaseline };
|
|
8178
8222
|
startMigrationWatcher(a, preClearBaseline, jsonlIsPostClearChild, 0, true);
|