wezard 2.9.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/CLAUDE.md +43 -21
  2. package/README.md +37 -50
  3. package/cli/wezard.sh +59 -20
  4. package/config.example.jsonc +5 -8
  5. package/dist/cli/audit.js +11 -13
  6. package/dist/cli/audit.js.map +1 -1
  7. package/dist/cli/codex-hook.js +20 -17
  8. package/dist/cli/codex-hook.js.map +1 -1
  9. package/dist/cli/ext.js +271 -0
  10. package/dist/cli/ext.js.map +1 -0
  11. package/dist/cli/init.js +44 -13
  12. package/dist/cli/init.js.map +1 -1
  13. package/dist/cli/skills.js +113 -0
  14. package/dist/cli/skills.js.map +1 -0
  15. package/dist/cli/sync.js +3 -2
  16. package/dist/cli/sync.js.map +1 -1
  17. package/dist/cli/wx.js +7 -6
  18. package/dist/cli/wx.js.map +1 -1
  19. package/dist/daemon/aibot-media.js +28 -20
  20. package/dist/daemon/aibot-media.js.map +1 -1
  21. package/dist/daemon/apprentice.js +75 -0
  22. package/dist/daemon/apprentice.js.map +1 -0
  23. package/dist/daemon/approval.js +75 -33
  24. package/dist/daemon/approval.js.map +1 -1
  25. package/dist/daemon/channel-context.js +7 -0
  26. package/dist/daemon/channel-context.js.map +1 -1
  27. package/dist/daemon/channel-onboarding.js +61 -0
  28. package/dist/daemon/channel-onboarding.js.map +1 -0
  29. package/dist/daemon/channel-posts.js +93 -0
  30. package/dist/daemon/channel-posts.js.map +1 -0
  31. package/dist/daemon/channel-rebind.js +100 -0
  32. package/dist/daemon/channel-rebind.js.map +1 -0
  33. package/dist/daemon/channel-store.js.map +1 -1
  34. package/dist/daemon/channel.js +273 -409
  35. package/dist/daemon/channel.js.map +1 -1
  36. package/dist/daemon/chat-name.js +24 -161
  37. package/dist/daemon/chat-name.js.map +1 -1
  38. package/dist/daemon/claim.js +1 -45
  39. package/dist/daemon/claim.js.map +1 -1
  40. package/dist/daemon/classes.js +416 -0
  41. package/dist/daemon/classes.js.map +1 -0
  42. package/dist/daemon/config-api.js +6 -30
  43. package/dist/daemon/config-api.js.map +1 -1
  44. package/dist/daemon/control-socket.js +93 -0
  45. package/dist/daemon/control-socket.js.map +1 -0
  46. package/dist/daemon/danger-scrub.js +315 -0
  47. package/dist/daemon/danger-scrub.js.map +1 -0
  48. package/dist/daemon/danger.js +146 -16
  49. package/dist/daemon/danger.js.map +1 -1
  50. package/dist/daemon/detail.js +50 -22
  51. package/dist/daemon/detail.js.map +1 -1
  52. package/dist/daemon/exec-surface.js +108 -0
  53. package/dist/daemon/exec-surface.js.map +1 -0
  54. package/dist/daemon/external.js +595 -0
  55. package/dist/daemon/external.js.map +1 -0
  56. package/dist/daemon/handoff.js +51 -50
  57. package/dist/daemon/handoff.js.map +1 -1
  58. package/dist/daemon/http.js +119 -31
  59. package/dist/daemon/http.js.map +1 -1
  60. package/dist/daemon/idle-reap.js +30 -0
  61. package/dist/daemon/idle-reap.js.map +1 -0
  62. package/dist/daemon/inbound.js +436 -207
  63. package/dist/daemon/inbound.js.map +1 -1
  64. package/dist/daemon/index.js +3353 -2760
  65. package/dist/daemon/index.js.map +1 -1
  66. package/dist/daemon/last-response.js +51 -25
  67. package/dist/daemon/last-response.js.map +1 -1
  68. package/dist/daemon/legacy-panes.js +67 -0
  69. package/dist/daemon/legacy-panes.js.map +1 -0
  70. package/dist/daemon/mcp-http.js.map +1 -1
  71. package/dist/daemon/me-room.js +137 -0
  72. package/dist/daemon/me-room.js.map +1 -0
  73. package/dist/daemon/media.js +14 -0
  74. package/dist/daemon/media.js.map +1 -1
  75. package/dist/daemon/memory-steward.js +1 -1
  76. package/dist/daemon/memory-steward.js.map +1 -1
  77. package/dist/daemon/message-format.js +15 -2
  78. package/dist/daemon/message-format.js.map +1 -1
  79. package/dist/daemon/mirror-bridge.js +583 -488
  80. package/dist/daemon/mirror-bridge.js.map +1 -1
  81. package/dist/daemon/mirror-store.js +24 -0
  82. package/dist/daemon/mirror-store.js.map +1 -1
  83. package/dist/daemon/notices.js +5 -6
  84. package/dist/daemon/notices.js.map +1 -1
  85. package/dist/daemon/onboarding.js +459 -0
  86. package/dist/daemon/onboarding.js.map +1 -0
  87. package/dist/daemon/outbound.js +21 -11
  88. package/dist/daemon/outbound.js.map +1 -1
  89. package/dist/daemon/peers.js +39 -231
  90. package/dist/daemon/peers.js.map +1 -1
  91. package/dist/daemon/plan-http.js +2 -3
  92. package/dist/daemon/plan-http.js.map +1 -1
  93. package/dist/daemon/plans.js.map +1 -1
  94. package/dist/daemon/reach.js +1 -5
  95. package/dist/daemon/reach.js.map +1 -1
  96. package/dist/daemon/room-auto-adhoc.js +18 -0
  97. package/dist/daemon/room-auto-adhoc.js.map +1 -0
  98. package/dist/daemon/room-bind.js +297 -0
  99. package/dist/daemon/room-bind.js.map +1 -0
  100. package/dist/daemon/room-facts.js +35 -0
  101. package/dist/daemon/room-facts.js.map +1 -0
  102. package/dist/daemon/room-hub.js +569 -0
  103. package/dist/daemon/room-hub.js.map +1 -0
  104. package/dist/daemon/room-overdue.js +160 -0
  105. package/dist/daemon/room-overdue.js.map +1 -0
  106. package/dist/daemon/room-prune.js +74 -0
  107. package/dist/daemon/room-prune.js.map +1 -0
  108. package/dist/daemon/room-spawn.js +20 -0
  109. package/dist/daemon/room-spawn.js.map +1 -0
  110. package/dist/daemon/room-watchdog.js +175 -0
  111. package/dist/daemon/room-watchdog.js.map +1 -0
  112. package/dist/daemon/rooms.js +204 -0
  113. package/dist/daemon/rooms.js.map +1 -0
  114. package/dist/daemon/route.js +7 -18
  115. package/dist/daemon/route.js.map +1 -1
  116. package/dist/daemon/session-scan.js +1 -1
  117. package/dist/daemon/session-scan.js.map +1 -1
  118. package/dist/daemon/short-id-log.js +43 -0
  119. package/dist/daemon/short-id-log.js.map +1 -0
  120. package/dist/daemon/spawn-tmux.js +60 -45
  121. package/dist/daemon/spawn-tmux.js.map +1 -1
  122. package/dist/daemon/steward-guard.js +3 -3
  123. package/dist/daemon/steward-guard.js.map +1 -1
  124. package/dist/daemon/steward-model.js +17 -3
  125. package/dist/daemon/steward-model.js.map +1 -1
  126. package/dist/daemon/steward-repair.js +171 -0
  127. package/dist/daemon/steward-repair.js.map +1 -0
  128. package/dist/daemon/steward.js +171 -0
  129. package/dist/daemon/steward.js.map +1 -0
  130. package/dist/daemon/tasks.js +4 -14
  131. package/dist/daemon/tasks.js.map +1 -1
  132. package/dist/daemon/tool-face.js +31 -0
  133. package/dist/daemon/tool-face.js.map +1 -0
  134. package/dist/daemon/turn-opening.js +30 -0
  135. package/dist/daemon/turn-opening.js.map +1 -0
  136. package/dist/daemon/wake-tail.js +55 -0
  137. package/dist/daemon/wake-tail.js.map +1 -0
  138. package/dist/daemon/weixin-cmd.js +10 -14
  139. package/dist/daemon/weixin-cmd.js.map +1 -1
  140. package/dist/daemon/wezard-session.js +6 -2
  141. package/dist/daemon/wezard-session.js.map +1 -1
  142. package/dist/daemon/wizard-memory.js +4 -10
  143. package/dist/daemon/wizard-memory.js.map +1 -1
  144. package/dist/daemon/wizard-names.js +0 -22
  145. package/dist/daemon/wizard-names.js.map +1 -1
  146. package/dist/daemon/wizard.js +683 -159
  147. package/dist/daemon/wizard.js.map +1 -1
  148. package/dist/daemon/ws.js +1 -1
  149. package/dist/daemon/ws.js.map +1 -1
  150. package/dist/mcp/output.js +30 -7
  151. package/dist/mcp/output.js.map +1 -1
  152. package/dist/mcp/relay.js +152 -0
  153. package/dist/mcp/relay.js.map +1 -0
  154. package/dist/mcp/tools.js +318 -265
  155. package/dist/mcp/tools.js.map +1 -1
  156. package/dist/shared/allow-rules.js +1 -7
  157. package/dist/shared/allow-rules.js.map +1 -1
  158. package/dist/shared/charter-rearm.js +179 -0
  159. package/dist/shared/charter-rearm.js.map +1 -0
  160. package/dist/shared/chat-http.js +412 -480
  161. package/dist/shared/chat-http.js.map +1 -1
  162. package/dist/shared/chat-record.js +55 -0
  163. package/dist/shared/chat-record.js.map +1 -0
  164. package/dist/shared/chat-render.js +7 -4
  165. package/dist/shared/chat-render.js.map +1 -1
  166. package/dist/shared/chat-view.js +2 -41
  167. package/dist/shared/chat-view.js.map +1 -1
  168. package/dist/shared/cli-backends.js +13 -5
  169. package/dist/shared/cli-backends.js.map +1 -1
  170. package/dist/shared/cli-local-status.js +28 -0
  171. package/dist/shared/cli-local-status.js.map +1 -0
  172. package/dist/shared/cli-socket.js +14 -0
  173. package/dist/shared/cli-socket.js.map +1 -0
  174. package/dist/shared/codex-hooks.js +5 -2
  175. package/dist/shared/codex-hooks.js.map +1 -1
  176. package/dist/shared/config.js +90 -66
  177. package/dist/shared/config.js.map +1 -1
  178. package/dist/shared/daemon-addr.js +23 -0
  179. package/dist/shared/daemon-addr.js.map +1 -0
  180. package/dist/shared/daemon-client.js +41 -0
  181. package/dist/shared/daemon-client.js.map +1 -0
  182. package/dist/shared/daemon-token.js +2 -2
  183. package/dist/shared/daemon-token.js.map +1 -1
  184. package/dist/shared/detail-render.js +98 -21
  185. package/dist/shared/detail-render.js.map +1 -1
  186. package/dist/shared/detail-store.js.map +1 -1
  187. package/dist/shared/external.js +402 -0
  188. package/dist/shared/external.js.map +1 -0
  189. package/dist/shared/group-members.js +35 -0
  190. package/dist/shared/group-members.js.map +1 -0
  191. package/dist/shared/inject-view.js +143 -0
  192. package/dist/shared/inject-view.js.map +1 -0
  193. package/dist/shared/instance-id.js +21 -0
  194. package/dist/shared/instance-id.js.map +1 -0
  195. package/dist/shared/legacy-routes.js +199 -0
  196. package/dist/shared/legacy-routes.js.map +1 -0
  197. package/dist/shared/mem-guard.js +32 -0
  198. package/dist/shared/mem-guard.js.map +1 -0
  199. package/dist/shared/message-footer.js +11 -3
  200. package/dist/shared/message-footer.js.map +1 -1
  201. package/dist/shared/model-tiers.js +39 -1
  202. package/dist/shared/model-tiers.js.map +1 -1
  203. package/dist/shared/ports.js +56 -0
  204. package/dist/shared/ports.js.map +1 -0
  205. package/dist/shared/reminder.js +30 -38
  206. package/dist/shared/reminder.js.map +1 -1
  207. package/dist/shared/role-render.js +210 -210
  208. package/dist/shared/role-render.js.map +1 -1
  209. package/dist/shared/role-view.js +65 -300
  210. package/dist/shared/role-view.js.map +1 -1
  211. package/dist/shared/room-label.js +13 -0
  212. package/dist/shared/room-label.js.map +1 -0
  213. package/dist/shared/room-migrate.js +404 -0
  214. package/dist/shared/room-migrate.js.map +1 -0
  215. package/dist/shared/room-overdue.js +153 -0
  216. package/dist/shared/room-overdue.js.map +1 -0
  217. package/dist/shared/room-search.js +102 -0
  218. package/dist/shared/room-search.js.map +1 -0
  219. package/dist/shared/room-view.js +275 -0
  220. package/dist/shared/room-view.js.map +1 -0
  221. package/dist/shared/room.js +827 -0
  222. package/dist/shared/room.js.map +1 -0
  223. package/dist/shared/session-hooks.js +20 -8
  224. package/dist/shared/session-hooks.js.map +1 -1
  225. package/dist/shared/session-label.js +82 -84
  226. package/dist/shared/session-label.js.map +1 -1
  227. package/dist/shared/session-mcp.js +36 -40
  228. package/dist/shared/session-mcp.js.map +1 -1
  229. package/dist/shared/session-skills.js +8 -0
  230. package/dist/shared/session-skills.js.map +1 -1
  231. package/dist/shared/skill-sync.js +229 -0
  232. package/dist/shared/skill-sync.js.map +1 -0
  233. package/dist/shared/smarts.js +24 -0
  234. package/dist/shared/smarts.js.map +1 -0
  235. package/dist/shared/stream-page.js +22 -0
  236. package/dist/shared/stream-page.js.map +1 -0
  237. package/dist/shared/task-file.js +0 -5
  238. package/dist/shared/task-file.js.map +1 -1
  239. package/dist/shared/task-template.js +1 -1
  240. package/dist/shared/task-template.js.map +1 -1
  241. package/dist/shared/tool-hints.js +20 -11
  242. package/dist/shared/tool-hints.js.map +1 -1
  243. package/dist/shared/workspace-trust.js +8 -0
  244. package/dist/shared/workspace-trust.js.map +1 -1
  245. package/dist/shared/world.js +101 -166
  246. package/dist/shared/world.js.map +1 -1
  247. package/dist/svr/facts-store.js +26 -0
  248. package/dist/svr/facts-store.js.map +1 -0
  249. package/dist/svr/index.js +114 -16
  250. package/dist/svr/index.js.map +1 -1
  251. package/hooks/pre-tool-use.sh +14 -10
  252. package/hooks/stop.sh +28 -0
  253. package/launchd/com.wezard.svr.plist.template +2 -0
  254. package/package.json +9 -2
  255. package/scripts/install.sh +23 -0
  256. package/skills/LICENSE.wecom-unified.txt +21 -0
  257. package/skills/wecom-unified/SKILL.md +151 -0
  258. package/skills/wecom-unified/assets/templates/broadside/DESIGN.preset.md +172 -0
  259. package/skills/wecom-unified/assets/templates/broadside/shell/content.jsx +31 -0
  260. package/skills/wecom-unified/assets/templates/broadside/slides/01_cover.slide +48 -0
  261. package/skills/wecom-unified/assets/templates/broadside/slides/02_section.slide +58 -0
  262. package/skills/wecom-unified/assets/templates/broadside/slides/03_cards.slide +53 -0
  263. package/skills/wecom-unified/assets/templates/broadside/slides/04_image.slide +64 -0
  264. package/skills/wecom-unified/assets/templates/cartesian/DESIGN.preset.md +139 -0
  265. package/skills/wecom-unified/assets/templates/cartesian/shell/content.jsx +28 -0
  266. package/skills/wecom-unified/assets/templates/cartesian/slides/01_cover.slide +44 -0
  267. package/skills/wecom-unified/assets/templates/cartesian/slides/02_compare.slide +79 -0
  268. package/skills/wecom-unified/assets/templates/cartesian/slides/03_table.slide +79 -0
  269. package/skills/wecom-unified/assets/templates/cobalt-grid/DESIGN.preset.md +118 -0
  270. package/skills/wecom-unified/assets/templates/cobalt-grid/shell/content.jsx +24 -0
  271. package/skills/wecom-unified/assets/templates/cobalt-grid/slides/01_cover.slide +61 -0
  272. package/skills/wecom-unified/assets/templates/cobalt-grid/slides/02_structure.slide +85 -0
  273. package/skills/wecom-unified/assets/templates/cobalt-grid/slides/03_data.slide +60 -0
  274. package/skills/wecom-unified/assets/templates/editorial-forest/DESIGN.preset.md +135 -0
  275. package/skills/wecom-unified/assets/templates/editorial-forest/shell/content.jsx +19 -0
  276. package/skills/wecom-unified/assets/templates/editorial-forest/slides/01_cover.slide +29 -0
  277. package/skills/wecom-unified/assets/templates/editorial-forest/slides/02_cards.slide +60 -0
  278. package/skills/wecom-unified/assets/templates/editorial-forest/slides/03_data.slide +49 -0
  279. package/skills/wecom-unified/assets/templates/editorial-forest/slides/04_image.slide +46 -0
  280. package/skills/wecom-unified/assets/templates/emerald-editorial/DESIGN.preset.md +119 -0
  281. package/skills/wecom-unified/assets/templates/emerald-editorial/shell/content.jsx +18 -0
  282. package/skills/wecom-unified/assets/templates/emerald-editorial/slides/01_cover.slide +36 -0
  283. package/skills/wecom-unified/assets/templates/emerald-editorial/slides/02_section.slide +39 -0
  284. package/skills/wecom-unified/assets/templates/emerald-editorial/slides/03_data.slide +79 -0
  285. package/skills/wecom-unified/assets/templates/emerald-editorial/slides/04_steps.slide +53 -0
  286. package/skills/wecom-unified/assets/templates/grove/DESIGN.preset.md +159 -0
  287. package/skills/wecom-unified/assets/templates/grove/shell/content.jsx +18 -0
  288. package/skills/wecom-unified/assets/templates/grove/shell/content_light.jsx +18 -0
  289. package/skills/wecom-unified/assets/templates/grove/slides/01_cover.slide +26 -0
  290. package/skills/wecom-unified/assets/templates/grove/slides/02_compare.slide +92 -0
  291. package/skills/wecom-unified/assets/templates/grove/slides/03_table.slide +68 -0
  292. package/skills/wecom-unified/assets/templates/index.json +280 -0
  293. package/skills/wecom-unified/assets/templates/long-table/DESIGN.preset.md +135 -0
  294. package/skills/wecom-unified/assets/templates/long-table/shell/content.jsx +36 -0
  295. package/skills/wecom-unified/assets/templates/long-table/slides/01_cover.slide +71 -0
  296. package/skills/wecom-unified/assets/templates/long-table/slides/02_cards.slide +72 -0
  297. package/skills/wecom-unified/assets/templates/long-table/slides/03_timeline.slide +81 -0
  298. package/skills/wecom-unified/assets/templates/long-table/slides/04_image.slide +60 -0
  299. package/skills/wecom-unified/assets/templates/sakura-chroma/DESIGN.preset.md +121 -0
  300. package/skills/wecom-unified/assets/templates/sakura-chroma/shell/content.jsx +13 -0
  301. package/skills/wecom-unified/assets/templates/sakura-chroma/slides/01_cover.slide +54 -0
  302. package/skills/wecom-unified/assets/templates/sakura-chroma/slides/02_products.slide +134 -0
  303. package/skills/wecom-unified/assets/templates/sakura-chroma/slides/03_section.slide +30 -0
  304. package/skills/wecom-unified/assets/templates/sakura-chroma/slides/04_schedule.slide +65 -0
  305. package/skills/wecom-unified/assets/templates/signal/DESIGN.preset.md +121 -0
  306. package/skills/wecom-unified/assets/templates/signal/shell/content.jsx +18 -0
  307. package/skills/wecom-unified/assets/templates/signal/shell/content_dark.jsx +23 -0
  308. package/skills/wecom-unified/assets/templates/signal/slides/01_cover.slide +48 -0
  309. package/skills/wecom-unified/assets/templates/signal/slides/02_cards.slide +67 -0
  310. package/skills/wecom-unified/assets/templates/signal/slides/03_data.slide +68 -0
  311. package/skills/wecom-unified/references/wecomcli-calendar-agenda.md +227 -0
  312. package/skills/wecom-unified/references/wecomcli-calendar-cancel.md +108 -0
  313. package/skills/wecom-unified/references/wecomcli-calendar-create.md +238 -0
  314. package/skills/wecom-unified/references/wecomcli-calendar-freebusy.md +207 -0
  315. package/skills/wecom-unified/references/wecomcli-calendar-meeting-room.md +170 -0
  316. package/skills/wecom-unified/references/wecomcli-calendar-search.md +209 -0
  317. package/skills/wecom-unified/references/wecomcli-calendar-update.md +272 -0
  318. package/skills/wecom-unified/references/wecomcli-calendar.md +296 -0
  319. package/skills/wecom-unified/references/wecomcli-contact.md +48 -0
  320. package/skills/wecom-unified/references/wecomcli-disk.md +380 -0
  321. package/skills/wecom-unified/references/wecomcli-doc-contents-append.md +20 -0
  322. package/skills/wecom-unified/references/wecomcli-doc-contents-overwrite.md +27 -0
  323. package/skills/wecom-unified/references/wecomcli-doc-create.md +162 -0
  324. package/skills/wecom-unified/references/wecomcli-doc-manage-doc-members-update.md +24 -0
  325. package/skills/wecom-unified/references/wecomcli-doc-manage-doc-names-update.md +20 -0
  326. package/skills/wecom-unified/references/wecomcli-doc-manage-doc-rules-update.md +22 -0
  327. package/skills/wecom-unified/references/wecomcli-doc-manage.md +127 -0
  328. package/skills/wecom-unified/references/wecomcli-doc.md +135 -0
  329. package/skills/wecom-unified/references/wecomcli-email-forward-mail.md +131 -0
  330. package/skills/wecom-unified/references/wecomcli-email-get-mail.md +187 -0
  331. package/skills/wecom-unified/references/wecomcli-email-reply-mail.md +138 -0
  332. package/skills/wecom-unified/references/wecomcli-email-search-mail.md +114 -0
  333. package/skills/wecom-unified/references/wecomcli-email-security.md +52 -0
  334. package/skills/wecom-unified/references/wecomcli-email-send-mail.md +186 -0
  335. package/skills/wecom-unified/references/wecomcli-email-send-schedule.md +83 -0
  336. package/skills/wecom-unified/references/wecomcli-email.md +206 -0
  337. package/skills/wecom-unified/references/wecomcli-media.md +89 -0
  338. package/skills/wecom-unified/references/wecomcli-meeting-cancel.md +113 -0
  339. package/skills/wecom-unified/references/wecomcli-meeting-create.md +167 -0
  340. package/skills/wecom-unified/references/wecomcli-meeting-list.md +228 -0
  341. package/skills/wecom-unified/references/wecomcli-meeting-original-get.md +101 -0
  342. package/skills/wecom-unified/references/wecomcli-meeting-search.md +176 -0
  343. package/skills/wecom-unified/references/wecomcli-meeting-update.md +217 -0
  344. package/skills/wecom-unified/references/wecomcli-meeting.md +366 -0
  345. package/skills/wecom-unified/references/wecomcli-message.md +190 -0
  346. package/skills/wecom-unified/references/wecomcli-pptx-component-animation.md +62 -0
  347. package/skills/wecom-unified/references/wecomcli-pptx-component-box.md +102 -0
  348. package/skills/wecom-unified/references/wecomcli-pptx-component-chart.md +261 -0
  349. package/skills/wecom-unified/references/wecomcli-pptx-component-codeblock.md +70 -0
  350. package/skills/wecom-unified/references/wecomcli-pptx-component-diagram.md +54 -0
  351. package/skills/wecom-unified/references/wecomcli-pptx-component-faicon.md +71 -0
  352. package/skills/wecom-unified/references/wecomcli-pptx-component-hyperlink.md +55 -0
  353. package/skills/wecom-unified/references/wecomcli-pptx-component-image.md +107 -0
  354. package/skills/wecom-unified/references/wecomcli-pptx-component-math.md +65 -0
  355. package/skills/wecom-unified/references/wecomcli-pptx-component-qrcode.md +22 -0
  356. package/skills/wecom-unified/references/wecomcli-pptx-component-slide.md +74 -0
  357. package/skills/wecom-unified/references/wecomcli-pptx-component-svg.md +95 -0
  358. package/skills/wecom-unified/references/wecomcli-pptx-component-table.md +72 -0
  359. package/skills/wecom-unified/references/wecomcli-pptx-component-text.md +96 -0
  360. package/skills/wecom-unified/references/wecomcli-pptx-content-contract.md +73 -0
  361. package/skills/wecom-unified/references/wecomcli-pptx-create-from-material.md +67 -0
  362. package/skills/wecom-unified/references/wecomcli-pptx-create-from-scratch.md +178 -0
  363. package/skills/wecom-unified/references/wecomcli-pptx-create-from-template.md +123 -0
  364. package/skills/wecom-unified/references/wecomcli-pptx-design-principle.md +65 -0
  365. package/skills/wecom-unified/references/wecomcli-pptx-government-contract.md +40 -0
  366. package/skills/wecom-unified/references/wecomcli-pptx-human-alignment.md +140 -0
  367. package/skills/wecom-unified/references/wecomcli-pptx-pptx-api.md +161 -0
  368. package/skills/wecom-unified/references/wecomcli-pptx-pptx-edit.md +37 -0
  369. package/skills/wecom-unified/references/wecomcli-pptx-story-principle.md +184 -0
  370. package/skills/wecom-unified/references/wecomcli-pptx-templates-README.md +165 -0
  371. package/skills/wecom-unified/references/wecomcli-pptx-templates-anti-ai-slop.md +52 -0
  372. package/skills/wecom-unified/references/wecomcli-pptx.md +158 -0
  373. package/skills/wecom-unified/references/wecomcli-sheet-conditional-formatting.md +203 -0
  374. package/skills/wecom-unified/references/wecomcli-sheet-filter.md +179 -0
  375. package/skills/wecom-unified/references/wecomcli-sheet-float-image.md +235 -0
  376. package/skills/wecom-unified/references/wecomcli-sheet-formulas.md +71 -0
  377. package/skills/wecom-unified/references/wecomcli-sheet-history.md +118 -0
  378. package/skills/wecom-unified/references/wecomcli-sheet-protection.md +170 -0
  379. package/skills/wecom-unified/references/wecomcli-sheet-range-operations.md +306 -0
  380. package/skills/wecom-unified/references/wecomcli-sheet-read-data.md +151 -0
  381. package/skills/wecom-unified/references/wecomcli-sheet-search-replace.md +121 -0
  382. package/skills/wecom-unified/references/wecomcli-sheet-structure-operations.md +394 -0
  383. package/skills/wecom-unified/references/wecomcli-sheet-style.md +246 -0
  384. package/skills/wecom-unified/references/wecomcli-sheet-table-style.md +199 -0
  385. package/skills/wecom-unified/references/wecomcli-sheet-validation.md +217 -0
  386. package/skills/wecom-unified/references/wecomcli-sheet-visual-standards.md +166 -0
  387. package/skills/wecom-unified/references/wecomcli-sheet-workbook.md +264 -0
  388. package/skills/wecom-unified/references/wecomcli-sheet-write-cells.md +320 -0
  389. package/skills/wecom-unified/references/wecomcli-sheet-xlsx-process.md +324 -0
  390. package/skills/wecom-unified/references/wecomcli-sheet.md +96 -0
  391. package/skills/wecom-unified/references/wecomcli-smartpage-data-driven-pages.md +50 -0
  392. package/skills/wecom-unified/references/wecomcli-smartpage-edit.md +526 -0
  393. package/skills/wecom-unified/references/wecomcli-smartpage-formula-arraylist.md +369 -0
  394. package/skills/wecom-unified/references/wecomcli-smartpage-formula-datetime.md +283 -0
  395. package/skills/wecom-unified/references/wecomcli-smartpage-formula-logic.md +247 -0
  396. package/skills/wecom-unified/references/wecomcli-smartpage-formula-math.md +362 -0
  397. package/skills/wecom-unified/references/wecomcli-smartpage-formula-operators.md +246 -0
  398. package/skills/wecom-unified/references/wecomcli-smartpage-formula-pageblock.md +76 -0
  399. package/skills/wecom-unified/references/wecomcli-smartpage-formula-reference.md +192 -0
  400. package/skills/wecom-unified/references/wecomcli-smartpage-formula-templates.md +410 -0
  401. package/skills/wecom-unified/references/wecomcli-smartpage-formula-text.md +377 -0
  402. package/skills/wecom-unified/references/wecomcli-smartpage-formula-user.md +22 -0
  403. package/skills/wecom-unified/references/wecomcli-smartpage-mdx-syntax.md +739 -0
  404. package/skills/wecom-unified/references/wecomcli-smartpage.md +179 -0
  405. package/skills/wecom-unified/references/wecomcli-smartsheet-chart-types.md +95 -0
  406. package/skills/wecom-unified/references/wecomcli-smartsheet-common.md +160 -0
  407. package/skills/wecom-unified/references/wecomcli-smartsheet-edit.md +609 -0
  408. package/skills/wecom-unified/references/wecomcli-smartsheet-field-types.md +438 -0
  409. package/skills/wecom-unified/references/wecomcli-smartsheet-formula.md +845 -0
  410. package/skills/wecom-unified/references/wecomcli-smartsheet-read.md +411 -0
  411. package/skills/wecom-unified/references/wecomcli-smartsheet-record-values.md +218 -0
  412. package/skills/wecom-unified/references/wecomcli-smartsheet-template-ai_efficiency.md +709 -0
  413. package/skills/wecom-unified/references/wecomcli-smartsheet-template-connect_to_app.md +380 -0
  414. package/skills/wecom-unified/references/wecomcli-smartsheet-template-financial_accounting.md +369 -0
  415. package/skills/wecom-unified/references/wecomcli-smartsheet-template-hr_and_administration.md +475 -0
  416. package/skills/wecom-unified/references/wecomcli-smartsheet-template-ledger_records.md +156 -0
  417. package/skills/wecom-unified/references/wecomcli-smartsheet-template-manufacturing.md +395 -0
  418. package/skills/wecom-unified/references/wecomcli-smartsheet-template-marketing.md +186 -0
  419. package/skills/wecom-unified/references/wecomcli-smartsheet-template-office_essentials.md +299 -0
  420. package/skills/wecom-unified/references/wecomcli-smartsheet-template-personal_efficiency.md +70 -0
  421. package/skills/wecom-unified/references/wecomcli-smartsheet-template-procurement_logistics.md +325 -0
  422. package/skills/wecom-unified/references/wecomcli-smartsheet-template-project_management.md +564 -0
  423. package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_customer.md +222 -0
  424. package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_ops.md +105 -0
  425. package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_project.md +109 -0
  426. package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_research.md +92 -0
  427. package/skills/wecom-unified/references/wecomcli-smartsheet-template-sales_and_operations.md +446 -0
  428. package/skills/wecom-unified/references/wecomcli-smartsheet-template-store_management.md +431 -0
  429. package/skills/wecom-unified/references/wecomcli-smartsheet-template-team_tasks.md +274 -0
  430. package/skills/wecom-unified/references/wecomcli-smartsheet-template-wechat_customer.md +384 -0
  431. package/skills/wecom-unified/references/wecomcli-smartsheet-template-work_report.md +100 -0
  432. package/skills/wecom-unified/references/wecomcli-smartsheet-templates.md +53 -0
  433. package/skills/wecom-unified/references/wecomcli-smartsheet-view-types.md +373 -0
  434. package/skills/wecom-unified/references/wecomcli-smartsheet-webhook-examples.md +176 -0
  435. package/skills/wecom-unified/references/wecomcli-smartsheet-webhook.md +186 -0
  436. package/skills/wecom-unified/references/wecomcli-smartsheet.md +147 -0
  437. package/skills/wecom-unified/references/wecomcli-todo-create.md +137 -0
  438. package/skills/wecom-unified/references/wecomcli-todo-delete.md +63 -0
  439. package/skills/wecom-unified/references/wecomcli-todo-finish.md +72 -0
  440. package/skills/wecom-unified/references/wecomcli-todo-get.md +69 -0
  441. package/skills/wecom-unified/references/wecomcli-todo-list.md +136 -0
  442. package/skills/wecom-unified/references/wecomcli-todo-update.md +112 -0
  443. package/skills/wecom-unified/references/wecomcli-todo.md +68 -0
  444. package/skills/wecom-unified/scripts/build_docx.py +1274 -0
  445. package/skills/wecom-unified/scripts/build_page.py +2449 -0
  446. package/skills/wecom-unified/scripts/collect.py +868 -0
  447. package/skills/wecom-unified/scripts/doc_image_extractor.py +498 -0
  448. package/skills/wecom-unified/scripts/pptx2image.py +268 -0
  449. package/skills/wecom-unified/scripts/recalc.py +403 -0
  450. package/systemd/wezard-svr.service.template +2 -0
  451. package/systemd/wezard.service.template +6 -0
  452. package/web/chat.css +70 -273
  453. package/web/chat.js +2269 -2190
  454. package/dist/daemon/bot-mux.js +0 -161
  455. package/dist/daemon/bot-mux.js.map +0 -1
  456. package/dist/daemon/chat-log.js +0 -130
  457. package/dist/daemon/chat-log.js.map +0 -1
  458. package/dist/daemon/dispatch.js +0 -6
  459. package/dist/daemon/dispatch.js.map +0 -1
  460. package/dist/daemon/idle-nudge.js +0 -90
  461. package/dist/daemon/idle-nudge.js.map +0 -1
  462. package/dist/daemon/message-events.js +0 -1155
  463. package/dist/daemon/message-events.js.map +0 -1
  464. package/dist/daemon/pending-items.js +0 -160
  465. package/dist/daemon/pending-items.js.map +0 -1
  466. package/dist/daemon/router.js +0 -742
  467. package/dist/daemon/router.js.map +0 -1
  468. package/dist/daemon/tips.js +0 -25
  469. package/dist/daemon/tips.js.map +0 -1
  470. package/dist/daemon/wedoc.js +0 -210
  471. package/dist/daemon/wedoc.js.map +0 -1
  472. package/dist/shared/role-search.js +0 -100
  473. package/dist/shared/role-search.js.map +0 -1
  474. package/dist/shared/startup-notice.js +0 -21
  475. package/dist/shared/startup-notice.js.map +0 -1
  476. package/dist/shared/turn-state.js +0 -27
  477. package/dist/shared/turn-state.js.map +0 -1
@@ -1,22 +1,26 @@
1
- import { attachmentLine, inboxName, saveToInbox } from "./media.js";
2
- import { PRIMARY_BOT } from "../shared/config.js";
3
- import { messageId } from "./message-events.js";
4
- import { tailTurnsWithTools, peerMentionPart, renderHumanEnvelope, renderStewardHint } from "./peers.js";
5
- import { noticeSuffixFor } from "./notices.js";
6
- import { renderTail } from "../shared/reminder.js";
1
+ import { attachmentLine, inboxName, saveToInbox, sniffExt } from "./media.js";
2
+ import { resolveCliBackend } from "../shared/cli-backends.js";
3
+ import { lastModel, tailTurnsWithTools } from "./peers.js";
7
4
  import { expandHome, sanitizeId } from "../shared/paths.js";
8
5
  import { parseWxCommand, wxCommandHandler } from "./weixin-cmd.js";
9
- import { tryConsumeClaim, persistClaim, ackClaim, shouldAutoClaim, ackAutoClaim, shouldBotAutoClaim, persistBotClaim, ackBotClaim } from "./claim.js";
6
+ import { tryConsumeClaim, persistClaim, ackClaim, shouldAutoClaim, ackAutoClaim } from "./claim.js";
10
7
  import { getLastResponse } from "./last-response.js";
11
8
  import { scanClaudeSessions } from "./session-scan.js";
12
9
  import { computeUsage, renderUsageReport } from "./usage.js";
13
10
  import { computeAuditReport } from "./audit.js";
14
11
  import { syncProjectConfig, renderSyncReport } from "./cfg-sync.js";
15
12
  import { captureQuota, renderQuotaReport } from "./quota.js";
16
- import { tagOfKey, baseOfKey, keyOf, withTagHeader, parseTagHeader, nameTokenRe, allNames, unlinkTags, uniqueTag, displayName, tagLink, withBot, sameBot } from "../shared/session-label.js";
17
- import { botTagOf } from "./bot-mux.js";
18
- import { chatNameOf, clearChatName, setChatName, stewardTierOf } from "./chat-name.js";
19
- import { evictStaleName, reclaimChatName, wizardStore } from "./wizard.js";
13
+ import { tagOfKey, baseOfKey, keyOf, withTagHeader, parseTagHeader, nameTokenRe, unlinkTags, uniqueTag, displayName, tagLink, stripSigil } from "../shared/session-label.js";
14
+ import { chatNameOf } from "./chat-name.js";
15
+ import { anchorOf, identityFieldsOf, identityOf, identityWorkspaceOf, manifestationOf, openInstance, settleName, wizardStore } from "./wizard.js";
16
+ import { stewardIdentityOf, stewardRoute as resolveSteward } from "./steward.js";
17
+ import { parseInstanceName } from "./classes.js";
18
+ import { noteNativeChannelFrame } from "./channel.js";
19
+ import { awaitChannelOfPost, channelOf, channelOfPost, postsOfChannel } from "./channel-posts.js";
20
+ import { settleChannelSteward } from "./onboarding.js";
21
+ import { applyOnboarding, bindSteward, classifyOnboardingInput, GUIDE_DESC, guideOf, guideTargetOf, judgeOnboarding, loadOnboardingStore, needsOnboarding, renderGuideOpening, renderGuideRetry, renderOnboardingDone } from "./onboarding.js";
22
+ import { isApprentice } from "./apprentice.js";
23
+ import { ensureMeWizard, meWorkspaceOf, ME_TAG } from "./me-room.js";
20
24
  import { truncate } from "../shared/std.js";
21
25
  import { hookModePath, readHookMode, writeHookMode } from "../shared/hook-mode.js";
22
26
  /** 判定"引用内容是否已在目标会话上下文里"时回看的轮数 —— 引用的通常是最近几轮
@@ -24,16 +28,14 @@ import { hookModePath, readHookMode, writeHookMode } from "../shared/hook-mode.j
24
28
  const QUOTE_TAIL_TURNS = 12;
25
29
  // Chat-binding key: stable id for "this conversation thread". Used as
26
30
  // session-map key, mirror target, defaultChat. NOT used for auth.
27
- // 副机器人收到的聊天挂 `~<bot>` (bot-mux 在转发时给 body 记了是谁收的): 同一个人私聊两个机器人、
28
- // 同一个群里两个机器人, 是两个聊天、两套 wizard。授权不走这里 (authPrincipals 不带后缀)。
29
- const chatPrincipal = (msg) => withBot(msg.chattype === "group" && msg.chatid ? `chat:${msg.chatid}` : `user:${msg.from.userid}`, botTagOf(msg));
30
- // 寻址靠 wizard 的**全局名字** `.name` —— 它可能住在任何一个聊天里。
31
+ const chatPrincipal = (msg) => msg.chattype === "group" && msg.chatid ? `chat:${msg.chatid}` : `user:${msg.from.userid}`;
32
+ // 寻址靠 wizard 的**全局名字** —— 人点名单写作 `.name` (`🧙 name` 同样认, 双态), 它可能住在任何一个聊天里。
31
33
  // Must be space-delimited or edge-of-string so paths / extensions like `a.ts`
32
34
  // survive. 一条消息只认**一个**路由名字, 且**只做前缀匹配**: 清洗之后 (链接标记
33
35
  // 还原成裸 `.name`、@ 已由 stripAt 剥掉、去掉开头的空白与不可见字符) 落在**消息
34
36
  // 开头**的那个 `.x` 才是目标 —— 认不认识都算 (不认识 = 叫一个新 wizard 出来)。
35
37
  // 正文里的 `.fix` / `.gitignore` 一律只是提及, 哪怕名册里真有这个名字。
36
- // 选中的那个 token 从正文里摘掉, 其余 `.foo` 原样留着 (见 peerMentions)。
38
+ // 选中的那个 token 从正文里摘掉, 其余 `.foo` 原样留着 (见 wake-tail.ts peerMentionsOf)。
37
39
  // Token 规则收在 session-label(nameTokenRe / allNames),路由与标注共用同一把尺子。
38
40
  const NAME_RE = nameTokenRe();
39
41
  const LEAD_NOISE_RE = /^[\s​-‍⁠]+/u;
@@ -45,16 +47,19 @@ const parseTag = (text) => {
45
47
  return { tag: m[2] ?? "", cleaned: lead.slice(m[0].length).replace(/[ \t]+/g, " ").trim() };
46
48
  };
47
49
  const tagOf = tagOfKey;
48
- /** 名字 → 投递目标。名册 (全局) > 在本聊天新开一个 slot。
50
+ /** 名字 → 投递目标。名册 (全局, 按身份解析到本聊天的化身) > 在本聊天新开一个 slot。
49
51
  * 新 wizard 的名字由 spawn 时 settleName 按 slot 落定。
50
52
  * 名册里那个名字归别的机器人 → 当作不认识 (落到「本聊天新开」; 名字全局唯一, settleName 会挂 `-N`)。
51
53
  * 引用气泡的 srcTag 也走这里, 同一把尺子。 */
52
- const resolveName = (base, name) => {
54
+ export const resolveName = (base, name) => {
53
55
  if (!name)
54
56
  return base;
55
57
  const rec = wizardStore()?.byName(name);
56
- if (rec && sameBot(base, rec.target))
57
- return rec.target;
58
+ // 名字属于身份 (§2): 投递落「身份在本聊天的化身」—— 有就用本群的, 没有回落锚点化身
59
+ // (共享锚点上下文), 不自动新建。按群隔离会话是管家专用 (resolve → stewardReception);
60
+ // worker 跨群点名沿用同一会话, 不每群新开 pane (人 2026-11-17, 测试 steward-reception 钉住)。
61
+ if (rec)
62
+ return manifestationOf(wizardStore(), name, base) ?? rec.target;
58
63
  const slot = name;
59
64
  // 这个 slot 已被一个改了名的 (冷) wizard 占着 → 挪到 `slot-N`, 别唤醒别人。
60
65
  const taken = new Set((wizardStore()?.all() ?? []).filter((w) => baseOfKey(w.target) === base).map((w) => tagOfKey(w.target)));
@@ -100,11 +105,22 @@ const parseUseCommand = (text) => {
100
105
  return "show";
101
106
  return arg === "cli" || arg === "wecom" ? arg : "invalid";
102
107
  };
108
+ // `/notice` 看 · `/notice clear` 清 · `/notice <文字>` 设 —— 本群 room 的公告 (账本 notice 行)。
109
+ // 保留原文 (含大小写): 公告是人写给 wizard 的话。
110
+ export const parseNoticeCommand = (text) => {
111
+ const m = /^\/notice(?:\s+([\s\S]*))?$/iu.exec(text.trim());
112
+ if (!m)
113
+ return undefined;
114
+ const arg = (m[1] ?? "").trim();
115
+ if (!arg)
116
+ return { op: "show" };
117
+ return /^(?:clear|清除|清空)$/iu.test(arg) ? { op: "clear" } : { op: "set", text: arg };
118
+ };
103
119
  // `/audit` or `/audit <name>`. A supplied name resolves only through the global wizard registry;
104
120
  // without one, the caller's own mirror binding is used.
105
121
  const parseAuditCommand = (text) => {
106
122
  const m = /^\/audit(?:\s+(.+))?$/u.exec(text.trim());
107
- return m ? { name: (m[1] ?? "").trim().replace(/^\./, "") } : undefined;
123
+ return m ? { name: stripSigil(m[1] ?? "") } : undefined;
108
124
  };
109
125
  const resolveAuditMirror = (mirrors, name, who, chatWho) => {
110
126
  if (name) {
@@ -143,20 +159,22 @@ const parseCfgSyncCommand = (text) => {
143
159
  const m = CFGSYNC_RE.exec(text.trim());
144
160
  return m ? { apply: Boolean(m[1]) } : undefined;
145
161
  };
146
- // `/name` 读, `/name x` 写, `/name -` 摘掉。名字是 chat 级的 —— 带不带 `.name`
147
- // 路由过来都命名同一个聊天, 所以这里不看路由目标。
148
- const NAME_RE_CMD = /^\/name(?:\s+(\S+))?$/i;
149
- const parseNameCommand = (text) => {
150
- const m = NAME_RE_CMD.exec(text.trim());
151
- return m ? { arg: m[1] ?? "" } : undefined;
152
- };
153
- // `/chats` — 跨聊天目录: 谁有名字、谁没有、各自跑着哪些会话。
154
- const isChatsCommand = (text) => /^\/chats?$/i.test(text.trim());
155
162
  const isUsageCommand = (text) => text.trim() === "/usage";
156
163
  const isStopCommand = (text) => /^(?:\/stop|stop)$/i.test(text.trim());
157
164
  const isKillCommand = (text) => text.trim() === "/kill";
158
165
  const isEnterCommand = (text) => text.trim() === "/n";
159
166
  const isRevealCommand = (text) => text.trim() === "/reveal";
167
+ const isModelCommand = (text) => /^\/model(?:\s|$)/i.test(text.trim());
168
+ /** `/model` 的回话: 有会话 = 转录里最近一轮真正用的模型 (绑定里的只是启动参数), 无会话 = 明说并给默认后端。 */
169
+ const renderModelReply = (text, who, info, defaultCli = "") => {
170
+ const name = displayName(who) || tagOf(who) || who;
171
+ const hasArg = text.trim().split(/\s+/).length > 1;
172
+ const tip = hasArg ? " · /model 不切换, 换模型请让 wizard 用 set_model 或改 config" : "";
173
+ if (!info)
174
+ return `[wezard] .${name} 当前无活会话${defaultCli ? `, 新会话用 ${defaultCli} 默认模型 (config 的 tiers 可按档固定)` : ""}${tip}`;
175
+ const model = (info.jsonlPath ? lastModel(info.jsonlPath) : "") || info.model || "CLI 默认 (本会话还没发过言)";
176
+ return `[wezard] .${name} 当前模型: ${model} · effort ${info.effort || "默认"} · cli ${info.cli}${tip}`;
177
+ };
160
178
  const isHelpCommand = (text) => /^\/(?:help|\?|h)$/i.test(text.trim());
161
179
  // Static command reference. Grouped: session control, usage/info. Anything
162
180
  // not matching a command is a
@@ -172,6 +190,7 @@ const renderHelp = () => [
172
190
  "`/sessions` 列出本机所有 live 会话 · `/sessions <emoji|id>` 把本聊天改接到某一个",
173
191
  "`/stop` 打断当前生成 (Esc)",
174
192
  "`/kill` 结束本会话并移除 tmux pane (下条消息自动让新的 wizard 就位)",
193
+ "`/model` 查看本会话当前模型 / effort (只读; 换模型让 wizard 用 set_model)",
175
194
  "`/n` 向 CLI 输入回车 (Enter)",
176
195
  "`/reveal` 把终端的 tmux 窗口切到本会话",
177
196
  "`/wx` 微信 ClawBot: 列出 / `bind` 扫码绑定 (每个微信号 = 一个群聊) / `unbind` (仅审批人)",
@@ -181,30 +200,31 @@ const renderHelp = () => [
181
200
  "位置参数可叠:`.docs /new opus 先读一遍 README` = 名字 + 模型 + 首句;新 pane 后端由配置决定。",
182
201
  "",
183
202
  "▎wizard",
184
- "每个 wizard 有一个**全局唯一**的名字,写作 `.name`;聊天的默认 wizard 名字就是聊天名。",
203
+ "每个 wizard 有一个**全局唯一**的名字;你点名写作 `.name`。类名是一个人的设定 (`X`), 实例地址是 `X-1`、`X-2`… (新群由引导落定)。",
185
204
  "消息里带 `.name`(如 `.docs 帮我改 README`)就是找那一个 —— 它可以住在任何一个聊天里,",
186
205
  "回复会回到你说话的这个群;不带 = 本聊天默认那个。开头写一个还不存在的 `.x` = 在这里叫出一个新的 x。",
187
- "它们的回复以 `emoji .name` 打头。`/clear .x`、`/pwd .x`、`/stop .x` 同理按名字走。",
206
+ "它们的回复以 `🧙 name` 打头。`/clear .x`、`/pwd .x`、`/stop .x` 同理按名字走 (`🧙 x` 写法同样认)。",
207
+ "`.me …` 是**你的个人分身**: 在任何聊天里说都只进你和它的私有对话 (带〔.me〕标注, 不进本群记录), 回复发回你说话的地方。它替你协调派活、直接找别的 wizard, 审批卡发你私聊。",
188
208
  "wizard 知道自己是谁、在哪个目录、还有谁在,也能给自己改名、写职责、记长期记忆、上下文满了自己交接重开。",
189
- "wizard 之间默认**私聊**,只有需要你知道的才发进群。",
209
+ "wizard 之间在 room 里说话: 两人私聊 / 三人以上的临时 room 只在 rolepage 看得到,说进本群的才进企微。",
190
210
  "",
191
211
  "▎分身(clone)",
192
212
  "对 AI 说「分个身去干 X」「开三个分身分头处理」即可。分身默认**继承它此刻的上下文** ——",
193
213
  "先把公共材料读进来、再分身,材料只读一遍却进了 N 份上下文;要白纸一张就说明白。",
194
- "分身有自己的 `.name`、自己的终端,也能再生分身。活干完对 AI 说「收掉它们」。",
214
+ "分身有自己的名字、自己的终端,也能再生分身。活干完对 AI 说「收掉它们」。",
195
215
  "",
196
- "▎跨聊天",
197
- "`/name <名字>` 给本聊天起名 · `/name` 查看 · `/name -` 取消",
198
- "`/chats` 列出所有已知聊天及其 wizard",
199
- "名字 1-32 位字母/数字/`_`/`-`,全机唯一;它同时就是这里默认 wizard 的名字 (撞名会自动加后缀)。",
216
+ "▎命名",
217
+ "名字由 wizard 自己起 (`wizard_identity`); 改别人用 `wizard_identity({to})` —— 直属 parent 或管家实例可改",
218
+ "类改名会同步它的全部实例 (`X-1..X-N`) 与指向它的管家绑定; 实例名 (形如 `X-3`) 不能当类名",
219
+ "名字 1-32 位字母/数字/`_`/`-`,全机唯一,跟着管家身份走 (同一管家进多个群共用一个名字)。",
200
220
  "对 AI 说「让 .fix 看一眼」「在 daily 里开个 .ingest 跑这个目录」即可。",
201
221
  "",
202
222
  "▎协作",
203
223
  "`/peers`(或 `/wizards`) 列出本聊天的 wizard:名字、职责、忙闲、谁是谁的分身",
204
224
  "同一聊天里的 wizard 互相看得见也驱动得动,直接说人话:",
205
- "「看下 `.fix` 的进展,推动它直到结束」— AI 会读它最近的对话、派活、收它的回执直到跑完。",
206
- "「让 `.fix` 和 `.review` 互相迭代到 review 说 LGTM」— AI 会把它们串成一条循环流水线。",
207
- "它们之间的往来默认只进各自的 rolepage;需要你知道的 (公开讨论、结论) 才发进群;工单的派活与回执不进群。",
225
+ "「看下 `.fix` 的进展,推动它直到结束」— AI 会看它卡在哪、追问它,等它交代做完为止。",
226
+ "「让 `.fix` 和 `.review` 互相迭代到 review 说 LGTM」— AI 会开一个跟进 room 让两边来回返修,直到通过。",
227
+ "派活、追问与交代走它们之间的 room,只在 rolepage 看得到;结论由你叫的那个 wizard 在群里交代。",
208
228
  "",
209
229
  "▎信息 (免授权)",
210
230
  "`/id` 查看会话/权限 id",
@@ -218,6 +238,9 @@ const renderHelp = () => [
218
238
  "▎审批",
219
239
  "`/use cli` 审批交给你本地 CLI 的权限框 (企微卡停用) · `/use wecom` 交回企微 · `/use` 看当前",
220
240
  "",
241
+ "▎群公告",
242
+ "`/notice <文字>` 设本群公告 (最多 500 字, 群里的 wizard 都会知道) · `/notice` 看当前 · `/notice clear` 清除",
243
+ "",
221
244
  "▎引用 (quote)",
222
245
  "引用消息 + 新文字:被引用内容作为上下文前缀附在你的话前。",
223
246
  "纯引用不加字:把被引用内容当正文重发 —— 微信会去重相同文本,",
@@ -304,20 +327,6 @@ const renderPeers = (peers, chatName) => {
304
327
  ].join("\n");
305
328
  };
306
329
  // /chats — 跨聊天目录: 每个聊天里住着哪些 wizard (`.name`, 全局可达)。
307
- const renderChats = (roster) => {
308
- if (roster.length === 0)
309
- return "[wezard] 还没有任何聊天在跑会话。";
310
- const rows = roster.flatMap((c) => {
311
- const sessions = c.targets.map((t) => tagLink(t, `.${displayName(t) || "?"}`)).join(" · ") || "(无)";
312
- const head = c.name ? `\`${c.name}\`` : `_(未命名)_ \`${c.base}\``;
313
- return [`**${head}**${c.self ? " ⬅️ 本聊天" : ""} · ${c.targets.length} 个会话`, ` ${sessions}`, ""];
314
- });
315
- return [
316
- `[wezard] 已知的聊天 · ${roster.length} 个`,
317
- "",
318
- ...rows,
319
- ].join("\n");
320
- };
321
330
  // Match a switch arg against a scanned session: animal emoji label, full
322
331
  // sessionId, or a ≥6 char sessionId prefix. Returns the session or undefined.
323
332
  const matchSession = (sessions, arg) => sessions.find((s) => s.label === arg) ??
@@ -351,13 +360,25 @@ const stripName = (text, name) => text
351
360
  // DMs can't @ a bot — any "@" the user types is content (e.g. "@src/foo.ts"),
352
361
  // so name detection is group-only. 配置里写死的名字 (`wrc.botNames`) 则任何
353
362
  // 场景都剥: 单聊里手打 "@wezard /usage" 同样不该漏进 prompt。
363
+ /** 下面各有 message.<type> 监听的 msgtype —— 与 SDK handleMessageCallback 的 switch 对齐。 */
364
+ const ROUTED_MSGTYPES = new Set(["text", "image", "mixed", "voice", "file", "video"]);
365
+ /** 不是人发的一句话, 不回「暂不支持」(stream 是流式刷新回调, event 正常走事件通道)。 */
366
+ const NO_REPLY_MSGTYPES = new Set(["stream", "event"]);
354
367
  const isGroup = (msg) => msg.chattype === "group" && !!msg.chatid;
368
+ /** 企微原生帧的来源标记: "channel" = 频道帖子里的 @ (base 是帖子自己的 opk 群, 见 channel-posts.ts)。 */
369
+ const sourceOf = (msg) => msg.compat_info?.source ?? "";
355
370
  const BUILTIN_BOT_NAMES = ["wezard"];
371
+ /** 这条消息里认定的机器人名 (剥离与 atBot 同一个判据): 配置里的名字优先, 群里第一个不像文件的 @token。 */
372
+ const botNameIn = (names, msg, text) => names.find((n) => mentionRe(n).test(text)) ?? (isGroup(msg) ? detectBotName(text) : undefined);
356
373
  const maybeStripMentions = (names, msg, text) => {
357
- const configured = names.find((n) => mentionRe(n).test(text));
358
- const name = configured ?? (isGroup(msg) ? detectBotName(text) : undefined);
374
+ const name = botNameIn(names, msg, text);
359
375
  return name ? stripName(text, name) : text.trim();
360
376
  };
377
+ /** 这一帧 = 「人 @ 了机器人」: 账本行据此记 mention:"bot" (等同点名 host —— 不再交给 room 的
378
+ * monitor 判决, 人 2026-11-24)。两条判据: ① 频道原生帧 (compat_info.source="channel"): 企微只为
379
+ * @ 的那一句发原生帧, 正文里反倒没有 @token (实录: 帖子里 @ 的帧 text 直接就是正文); ② 正文里
380
+ * 真有一个机器人名 (= 上面剥离时的同一判据)。 */
381
+ export const atBot = (names, msg, text) => sourceOf(msg) === "channel" || !!botNameIn(names, msg, text);
361
382
  // Render the user's "引用" (quoted message) into a markdown blockquote so the
362
383
  // claude prompt carries the upstream context. WeCom delivers `quote` as a
363
384
  // sibling field on the message body — currently we surface text/voice (already
@@ -389,6 +410,12 @@ const renderQuotePrefix = (body) => {
389
410
  const quoted = body.split("\n").map((l) => `> ${l}`).join("\n");
390
411
  return `> [引用]\n${quoted}\n\n`;
391
412
  };
413
+ // 频道 / 帖子里的「回复 (评论)」在企微回调里带的 quote 不是被回复的那一条, 而是**整篇帖子的
414
+ // 摘要**: 频道名 / 发帖人 / 发帖时间 / 帖子正文 / 回复 1..N (含 bot 自己的每次回复) —— 实测
415
+ // 2026-11-23 (daemon.log): 人的正文 17 字, quote 1803 字; 同一帖跟到第 21 条回复时 8753 字。
416
+ // 这份摘要本来就在 room 账本里, 贴回 prompt 只是把整个帖子再抄一遍, 且越跟越长。
417
+ const CHANNEL_POST_DIGEST = /^频道:[\s\S]*\n发帖人:/;
418
+ const isChannelPostDigest = (msg, body) => sourceOf(msg) === "channel" || CHANNEL_POST_DIGEST.test(body);
392
419
  // Normalize for self-reply quote dedup: WeCom mangles formatting on its quote
393
420
  // bubble in unpredictable ways — strips backticks, swaps `-` bullets for `·`,
394
421
  // re-wraps whitespace, sometimes loses inline markdown. Reduce both sides to
@@ -423,11 +450,11 @@ const canonContains = (haystack, needle) => {
423
450
  const isLastResponseQuote = (target, quoted) => canonContains(getLastResponse(target) ?? "", quoted);
424
451
  // ── 引用即路由 ─────────────────────────────────────────────────────────
425
452
  // 群里要跟 `.fix` 说话,手打名字太慢 —— 直接引用它的气泡即可。每条出站气泡都
426
- // 带 `emoji .name` 头 (withTagHeader),所以引用文本自带路由信息;用户自己发的
453
+ // 带 `🧙 name:` 头 (withTagHeader; 旧气泡是 `.name:`, 双态都认),所以引用文本自带路由信息;用户自己发的
427
454
  // 行首 `.fix 干活` 同样算数(限行首,否则正文里随手写的 .gitignore 会误判)。
428
455
  // `body` 是剥掉头/tag 后的净引用内容,用于跟目标 context 比对。
429
456
  // `tag` = 路由目标(引用继承的投递 tag)。
430
- // `srcTag` = 引用气泡真正出自哪个会话 —— 仅 bot 气泡可知(反解 `emoji .name` 头)。
457
+ // `srcTag` = 引用气泡真正出自哪个会话 —— 仅 bot 气泡可知(反解 `🧙 name:` / `.name:` 头)。
431
458
  // 去重要比对的是「内容在不在源会话」,而非路由目标: 带着引用新建 /
432
459
  // 改投到别的 tag 时,目标会话是空的,只有源会话里才有那段原文。
433
460
  // `srcTag===undefined` 表示源未知(用户自己打的引用),回退到按目标查。
@@ -441,7 +468,7 @@ const parseQuote = (q) => {
441
468
  const { tag, cleaned } = parseTag(raw);
442
469
  return { tag, body: cleaned };
443
470
  };
444
- const composeInbound = (msg, rawBody, inContext, stripAt, resolve) => {
471
+ export const composeInbound = (msg, rawBody, inContext, stripAt, resolve) => {
445
472
  const { tag: typed, cleaned } = parseTag(rawBody);
446
473
  const q = parseQuote(msg.quote);
447
474
  const tag = typed || q?.tag || "";
@@ -450,16 +477,20 @@ const composeInbound = (msg, rawBody, inContext, stripAt, resolve) => {
450
477
  // 的引用 / 改投)回退到路由目标。这修掉了「带引用新建/改投会话时原文被重复注入」。
451
478
  const dedupTag = q?.srcTag ?? tag;
452
479
  // 剥完头什么都不剩(折叠气泡这类纯 chrome 的引用)⇒ 没有可搬运的内容,只留路由。
453
- const consumed = !q || !q.body.trim() || inContext(resolve(chatPrincipal(msg), dedupTag), q.body);
480
+ // 频道帖子摘要是账本的重排, 不是人引用的话 —— 和"已在 context 里"同一个处置: 不贴回。
481
+ const speaker = String(msg.from?.userid ?? "");
482
+ const consumed = !q || !q.body.trim() || isChannelPostDigest(msg, q.body)
483
+ || inContext(resolve(chatPrincipal(msg), dedupTag, speaker), q.body);
484
+ // spoken = 人自己打的那部分 (不含引用/摘要): 账本人话行只存它, 进 prompt 的 text 才带引用。
454
485
  if (cleaned.trim()) {
455
- return { text: consumed ? cleaned : `${renderQuotePrefix(q.body)}${cleaned}`, tag, promoted: false };
486
+ return { text: consumed ? cleaned : `${renderQuotePrefix(q.body)}${cleaned}`, tag, promoted: false, spoken: cleaned };
456
487
  }
457
488
  if (q && !consumed) {
458
489
  // 提成正文时也剥一次 @mention,让 "@wezard /usage" → "/usage" 命中命令路径。
459
490
  const p = parseTag(stripAt(msg, q.body).trim());
460
- return { text: p.cleaned, tag: p.tag || tag, promoted: true };
491
+ return { text: p.cleaned, tag: p.tag || tag, promoted: true, spoken: "" };
461
492
  }
462
- return { text: cleaned, tag, promoted: false };
493
+ return { text: cleaned, tag, promoted: false, spoken: cleaned };
463
494
  };
464
495
  const isAllowed = (allow, principals) => {
465
496
  if (allow.length === 0)
@@ -475,22 +506,6 @@ const isAllowed = (allow, principals) => {
475
506
  // target can post back without being in `allowFrom`. A session bound to that
476
507
  // chat is the authorization signal.
477
508
  const isMirrorTarget = (bridge, who) => bridge.hasMirrorTarget(who);
478
- // Sniff extension from magic bytes; falls back to .bin. WeCom doesn't always
479
- // give us a filename for images, and we want claude's Read tool to recognize
480
- // the file (it dispatches on extension).
481
- const sniffExt = (buf) => {
482
- if (buf.length >= 8 && buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47)
483
- return ".png";
484
- if (buf.length >= 3 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff)
485
- return ".jpg";
486
- if (buf.length >= 6 && buf.subarray(0, 6).toString("ascii").startsWith("GIF8"))
487
- return ".gif";
488
- if (buf.length >= 12 && buf.subarray(0, 4).toString("ascii") === "RIFF" && buf.subarray(8, 12).toString("ascii") === "WEBP")
489
- return ".webp";
490
- if (buf.length >= 12 && buf.subarray(4, 12).toString("ascii") === "ftypheic")
491
- return ".heic";
492
- return ".bin";
493
- };
494
509
  /** 下载并解密到 inbox; 落盘名留着原文件名 (没有就按魔数补扩展名) —— agent 靠它认类型。 */
495
510
  const downloadToInbox = async (deps, url, aesKey, msgid, index, attempt = 0) => {
496
511
  try {
@@ -509,7 +524,7 @@ const downloadToInbox = async (deps, url, aesKey, msgid, index, attempt = 0) =>
509
524
  return attempt < 1 ? downloadToInbox(deps, url, aesKey, msgid, index, attempt + 1) : undefined;
510
525
  }
511
526
  };
512
- export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guardCharter) => {
527
+ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guardCharter, opts = {}) => {
513
528
  const inboxDir = expandHome(cfg.wrc.mirror.inboxDir);
514
529
  // 已知的机器人名只随配置变; 下面所有入站路径共用这一个剥离器。
515
530
  const botNames = [...BUILTIN_BOT_NAMES, ...cfg.wrc.botNames.filter(Boolean)];
@@ -524,8 +539,8 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
524
539
  // `.docs` → window `docs`, not the principal slug).
525
540
  // On success there is NO reply: newSession already pushed the single
526
541
  // "created + cwd" bubble. Only failures produce user-facing text.
527
- const spawnSession = async (who, silent, model) => {
528
- const r = await bridge.newSession(who, displayName(who) || tagOf(who) || who, { silent, model });
542
+ const spawnSession = async (who, silent, model, cwd) => {
543
+ const r = await bridge.newSession(who, displayName(who) || tagOf(who) || who, { silent, model, ...(cwd ? { cwd } : {}) });
529
544
  return r.ok ? {} : { err: `[wezard] /new failed: ${r.reason ?? "unknown"}` };
530
545
  };
531
546
  // 同一 wizard 的两条消息会并发落进 gate,双双判定「未附着」→ 双 spawn,后者
@@ -541,36 +556,28 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
541
556
  return next;
542
557
  };
543
558
  // 显式 /new:排队但仍强制重开(用户就是要换一个)。
544
- // 默认会话先把名字换回聊天名, 再 spawn —— charter 在 spawn 时按名字渲染。
545
- // 聊天名若被一个静默超过一天的 wizard 占着, 先顶掉它 —— 否则默认会话只能退避成 `-N`。
546
- const staleDeps = {
547
- lastActivity: (t) => bridge.lastActivity(t),
548
- retire: (t) => bridge.killPane(t),
549
- };
550
559
  // 新开的 slot 先按人写的名字落名: slot 只是内部 id, 被一个改过名的冷 wizard 占着
551
560
  // 时会挪成 `foo-N` —— 名字不该跟着它退避。已有名字的 wizard 不受影响 (claim 不改)。
561
+ // 聊天名已冻结为显示标签 (2026-11-16): 名字不再跟着聊天名走 —— 名册有就用名册的,
562
+ // 没有留给新群引导 / wizard_identity 去起。
552
563
  const claimAsked = (who, asked) => {
553
564
  if (asked)
554
565
  wizardStore()?.claim(who, asked);
555
566
  };
556
567
  const autoSpawnAndAttach = (who, asked, model) => serializeSpawn(who, async () => {
557
568
  claimAsked(who, asked);
558
- const chat = chatNameOf(cfg, who);
559
- if (chat && !tagOf(who)) {
560
- const gone = await evictStaleName(wizardStore(), chat, [who], staleDeps);
561
- if (gone)
562
- log.info({ target: gone.target, name: gone.name }, "stale name evicted by /new");
563
- }
564
- reclaimChatName(wizardStore(), chat, who);
565
- return spawnSession(who, false, model);
569
+ settleName(wizardStore(), chatNameOf(cfg, who), who);
570
+ // 管家化身 (/new 或裸消息首条) 落在身份的工作区 (引导落的身份级 workspace,
571
+ // 或锚点会话的 live cwd), 不落兜底目录。
572
+ return spawnSession(who, false, model, freshSteward.get(who) || identityWorkspaceOf(wizardStore(), who) || undefined);
566
573
  });
567
574
  // 隐式建会话(新 `.name` 的第一条消息):轮到自己时若前一条已经把会话建好,直接
568
575
  // 复用,不再 respawn —— 否则先到的消息会被注入进一个刚被杀掉的 pane。
569
- const ensureSession = (who, asked) => serializeSpawn(who, async () => {
576
+ const ensureSession = (who, asked, cwd) => serializeSpawn(who, async () => {
570
577
  if (bridge.hasMirrorTarget(who))
571
578
  return {};
572
579
  claimAsked(who, asked);
573
- return spawnSession(who, true);
580
+ return spawnSession(who, true, undefined, cwd);
574
581
  });
575
582
  // Prefix user-visible daemon replies with `<emoji> .name`, so a chat hosting
576
583
  // several wizards stays visually disambiguated. Emoji is derived from the
@@ -582,13 +589,22 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
582
589
  }
583
590
  catch { /* ignore */ }
584
591
  };
592
+ // daemon 自己的系统行 (会话边界确认 / 失败回执): 不署名头, 以 `[wezard]` 起头。
593
+ // 那个前缀不是装饰 —— 严格群的出站门 (mirror-bridge 的 sendStandalone) 只放行
594
+ // `[wezard]`/`[mirror]` 系统提示, 所以这条既是给人看的来源记号, 也是「这不是
595
+ // 模型发言」的判据。直发 replyStream, 与 /help /pwd 同一条不经门的口子。
596
+ const replySystem = async (frame, msg, text) => {
597
+ try {
598
+ await client.replyStream(frame, msg.msgid, text, true);
599
+ }
600
+ catch { /* ignore */ }
601
+ };
585
602
  // Common gating: claim bootstrap + allowFrom check. Returns true if the
586
603
  // caller should stop (claim consumed or message rejected).
587
604
  const gate = async (frame, msg, text, who, asked = "") => {
588
605
  const auths = authPrincipals(msg);
589
- // 多机器人: 收到这条的机器人自己的 allowFrom 与全局取并集。每条现算: 全局名单是热配置 (认领 / config_set 会改它)。
590
- const botId = botTagOf(msg);
591
- const allow = [...cfg.wrc.allowFrom, ...(cfg.bots.find((b) => b.id === botId)?.allowFrom ?? [])];
606
+ // 每条现算: 全局名单是热配置 (认领 / config_set 会改它)。
607
+ const allow = [...cfg.wrc.allowFrom];
592
608
  // Bootstrap / allowFrom operations are chat-scoped, not session-scoped;
593
609
  // use the chat principal, not the routed wizard — a first-time user typing
594
610
  // `.foo hello` still promotes them as `user:xxx` (not `user:xxx#foo`).
@@ -635,7 +651,7 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
635
651
  const audit = parseAuditCommand(text);
636
652
  if (audit) {
637
653
  // 别的机器人名下的会话不进候选: `/audit .x` 点到那边的名字 = 不认识。
638
- const mirror = resolveAuditMirror(bridge.status().mirrors.filter((x) => sameBot(who, x.target)), audit.name, who, chatPrincipal(msg));
654
+ const mirror = resolveAuditMirror(bridge.status().mirrors, audit.name, who, chatPrincipal(msg));
639
655
  let body;
640
656
  if (!mirror) {
641
657
  body = audit.name
@@ -656,9 +672,8 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
656
672
  await replyText(frame, msg, who, body);
657
673
  return { stop: true };
658
674
  }
659
- // 魔法短语认领只认主机器人 (`wezard init` 武装的就是它, 写全局 defaultChat / allowFrom);
660
- // 副机器人各走各的自动认领, 见下。
661
- if (!botId && tryConsumeClaim(text, basePrincipal)) {
675
+ // 魔法短语认领 (`wezard init` 武装的, 写全局 defaultChat / allowFrom)。
676
+ if (tryConsumeClaim(text, basePrincipal)) {
662
677
  log.info({ who: basePrincipal }, "claim consumed — bootstrapping defaultChat + allowFrom");
663
678
  try {
664
679
  persistClaim(cfg, sourcePath, basePrincipal);
@@ -674,7 +689,7 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
674
689
  // Falls through so the same message is also dispatched as a real prompt —
675
690
  // user types "hi" and gets both the promotion ack and the assistant reply.
676
691
  const isDm = !(msg.chattype === "group" && msg.chatid);
677
- if (!botId && shouldAutoClaim(cfg, isDm)) {
692
+ if (shouldAutoClaim(cfg, isDm)) {
678
693
  log.info({ who: basePrincipal }, "auto-claim — empty allowFrom, first DM sender promoted");
679
694
  try {
680
695
  persistClaim(cfg, sourcePath, basePrincipal);
@@ -685,27 +700,34 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
685
700
  await ackAutoClaim(client, basePrincipal, log);
686
701
  // fall through to dispatch
687
702
  }
688
- // 副机器人: 它自己的 allowFrom 空着时, 第一个单聊它的人认领它 (与主机器人互不相干)。同样落下去照常派发。
689
- if (shouldBotAutoClaim(cfg, botId, isDm)) {
690
- const owner = `user:${msg.from.userid}`;
691
- log.info({ who: owner, bot: botId }, "bot auto-claim — empty bots[].allowFrom, first DM sender promoted");
692
- try {
693
- persistBotClaim(cfg, sourcePath, botId, owner);
694
- }
695
- catch (e) {
696
- log.error({ err: e.message, bot: botId }, "bot auto-claim persist failed");
697
- }
698
- allow.push(owner);
699
- await ackBotClaim(client, basePrincipal, botId, log);
700
- }
701
703
  if (!isAllowed(allow, auths) && !isMirrorTarget(bridge, who)) {
702
- log.warn({ from: who, auths, bot: botId || PRIMARY_BOT }, "drop: not in allowFrom");
704
+ log.warn({ from: who, auths }, "drop: not in allowFrom");
703
705
  try {
704
- await client.replyStream(frame, msg.msgid, `未授权\n${renderIds(msg, allow)}\n请将上述任一权限id加入 config 的 wrc.allowFrom 数组${botId ? ` (或只给这个机器人: bots[id=${botId}].allowFrom)` : ""}`, true);
706
+ await client.replyStream(frame, msg.msgid, `未授权\n${renderIds(msg, allow)}\n请将上述任一权限id加入 config 的 wrc.allowFrom 数组`, true);
705
707
  }
706
708
  catch { /* ignore */ }
707
709
  return { stop: true };
708
710
  }
711
+ // Authorized `/notice [clear|<文字>]` — 本群 room 的公告; 人在绑定 room 里改的就是这个 room 的。
712
+ const notice = parseNoticeCommand(text);
713
+ if (notice) {
714
+ const base = baseOfKey(who);
715
+ if (notice.op === "show") {
716
+ const cur = opts.getNotice?.(base);
717
+ await replyText(frame, msg, who, cur ? `📌 群公告: ${cur}` : "📌 本群还没有公告 · `/notice <文字>` 设置");
718
+ return { stop: true };
719
+ }
720
+ const r = opts.setNotice
721
+ ? opts.setNotice(base, notice.op === "clear" ? "" : notice.text, { kind: "human", id: String(msg.from.userid) })
722
+ : { ok: false, reason: "room 接线还没就绪, 稍后再试" };
723
+ log.info({ who, op: notice.op, ok: r.ok }, "/notice");
724
+ // 成功时群里已有 daemon 的系统行 (📌 群公告…), 不再另回; 没变化 / 失败才答一句。
725
+ if (!r.ok)
726
+ await replyText(frame, msg, who, `[wezard] /notice 没生效: ${r.reason}`);
727
+ else if (!r.changed)
728
+ await replyText(frame, msg, who, notice.op === "clear" ? "📌 本群本来就没有公告" : "📌 公告没变");
729
+ return { stop: true };
730
+ }
709
731
  // Authorized `/use [cli|wecom]` — 审批 hook 的裁决权在企微卡片与本地 CLI 之间
710
732
  // 切换。写一个状态文件, 不改 hook 注册, 对已在跑的会话即刻生效。
711
733
  const use = parseUseCommand(text);
@@ -764,11 +786,24 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
764
786
  // picks which wizard (re)spawns; the name is also the tmux window name.
765
787
  const nu = parseNewCommand(text);
766
788
  if (nu) {
789
+ // 学徒 (§7) 是连续身份、唯一会话: /new 不换会话, 改为「整理记忆 + 原会话继续」。
790
+ if (isApprentice(wizardStore(), who)) {
791
+ const { err } = await ensureSession(who, asked, cfg.wrc.apprentice.workspace);
792
+ if (err) {
793
+ await replyText(frame, msg, who, err);
794
+ return { stop: true };
795
+ }
796
+ await send(frame, msg, who, "[系统] /new 已拦: 学徒是连续身份、唯一会话, 不换会话。请整理记忆 (值得跨会话留下的用 wizard_remember 记下) 后在原会话继续; 上下文紧张用 handoff 压简报, 会话与身份不变。");
797
+ return { stop: true };
798
+ }
767
799
  const { err } = await autoSpawnAndAttach(who, asked, nu.model);
768
800
  if (err) {
769
801
  await replyText(frame, msg, who, err);
770
802
  return { stop: true };
771
803
  }
804
+ // room 口径 (fix-task §8.3): /new 的会话边界确认只有一种形态, 由 mirror 的
805
+ // pushProjectInfo 发 (createdAck, 不带系统前缀); daemon 这里不再补发 —— 出站门
806
+ // 已废, 老的「严格群被静音要补一条」的前提不存在了。
772
807
  // 带正文的 `/new`: 这段就是新会话的第一句。走和「隐式建会话后 fall through」
773
808
  // 完全相同的 dispatch 路径 —— freshSpawn 的冷时序、peer 提示都在那里。
774
809
  if (nu.prompt)
@@ -797,10 +832,22 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
797
832
  // and drop the binding (no `--resume` resurrection). Routed by `.name` like
798
833
  // /stop, so `/kill #docs` only takes down that sibling.
799
834
  if (isKillCommand(text)) {
835
+ // 学徒 (§7) 不可退役: /kill 会去掉绑定且不复活, 对学徒是身份谋杀。
836
+ if (isApprentice(wizardStore(), who)) {
837
+ await replyText(frame, msg, who, "学徒是连续身份, 不可 /kill —— pane 死了会带着记忆同身份重生; 要停它这一轮用 /stop。");
838
+ return { stop: true };
839
+ }
800
840
  const r = await bridge.killPane(who);
801
841
  await replyText(frame, msg, who, r.ok ? "🗑️ 会话已结束,pane 已移除" : `[wezard] /kill failed: ${r.reason ?? "unknown"}`);
802
842
  return { stop: true };
803
843
  }
844
+ // `/model`: 原样注入 pane 会让 TUI 弹出交互式模型选择器, 把 pane 卡死 —— 所以绝不注入。
845
+ // 由 daemon 自己查「接待 wizard」(who = 这条消息会路由到的会话) 此刻真正在跑的模型回一行;
846
+ // 带参数不切换, 换模型走 MCP set_model / config (内部能力不变)。
847
+ if (isModelCommand(text)) {
848
+ await replyText(frame, msg, who, renderModelReply(text, who, bridge.sessionInfo(who), resolveCliBackend(cfg.wrc).name));
849
+ return { stop: true };
850
+ }
804
851
  // Authorized `/n` — send a bare Enter to the live pane. Confirms a prompt /
805
852
  // dismisses a "press enter to continue", or submits whatever's already in
806
853
  // the input box. Bails cleanly when no attachment.
@@ -834,42 +881,6 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
834
881
  await replyText(frame, msg, who, body);
835
882
  return { stop: true };
836
883
  }
837
- // /name [x|-] — 给本聊天起名,作为跨聊天操作使用的可读聊天名。
838
- // 名字写进 config.jsonc 而不是运行时 state; 改名即覆盖,一个聊天只留一个名字,
839
- // 一个名字只归一个聊天。
840
- const nc = parseNameCommand(text);
841
- if (nc) {
842
- const cur = chatNameOf(cfg, who);
843
- if (!nc.arg) {
844
- await replyText(frame, msg, who, cur
845
- ? `[wezard] 本聊天名为 \`${cur}\``
846
- : "[wezard] 本聊天还没起名。");
847
- return { stop: true };
848
- }
849
- // 聊天名进宪章 (home 群、管家那节的 config_set 路径): 过宪章守卫, 受影响的 wizard 被提醒 handoff。
850
- if (nc.arg === "-") {
851
- const { r: gone } = guardCharter(() => clearChatName(cfg, sourcePath, who), (g) => g ? { what: `人 \`/name -\` 取消了聊天名 \`${g}\``, byHuman: true } : undefined);
852
- await replyText(frame, msg, who, gone ? `[wezard] 已取消命名 \`${gone}\`` : "[wezard] 本聊天本来就没起名。");
853
- return { stop: true };
854
- }
855
- // 聊天名就是默认 wizard 的名字: 人起名即改名 (撞名照 pickName 挂 `-N`), tmux 窗口跟着换。
856
- const home = baseOfKey(who);
857
- const { r: [r, wiz] } = guardCharter(() => {
858
- const r = setChatName(cfg, sourcePath, who, nc.arg);
859
- return [r, r.ok ? wizardStore()?.rename(home, r.name) : undefined];
860
- }, ([r]) => r.ok && r.name !== cur ? { what: `人 \`/name ${r.name}\` 把聊天${cur ? ` \`${cur}\`` : ""}改名为 \`${r.name}\``, byHuman: true } : undefined);
861
- if (wiz)
862
- void bridge.retitlePane(home);
863
- await replyText(frame, msg, who, r.ok
864
- ? `[wezard] ✅ 本聊天更名为 \`${r.name}\`${cur && cur !== r.name ? `(原 \`${cur}\`)` : ""}${wiz && wiz !== r.name ? `; 默认 wizard 名 \`.${wiz}\` (\`.${r.name}\` 已被占)` : ""}`
865
- : `[wezard] /name failed: ${r.reason}`);
866
- return { stop: true };
867
- }
868
- // /chats — 跨聊天目录:谁有名字、各自跑着哪些会话。Read-only。
869
- if (isChatsCommand(text)) {
870
- await replyText(frame, msg, who, renderChats(bridge.chatRoster(who).filter((c) => sameBot(who, c.base))));
871
- return { stop: true };
872
- }
873
884
  // /peers — this chat's own wizard roster (default + siblings), with
874
885
  // live busy state. Read-only.
875
886
  if (isPeersCommand(text)) {
@@ -891,8 +902,7 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
891
902
  if (sc) {
892
903
  let sessions = [];
893
904
  try {
894
- // 已绑在别的机器人聊天上的会话不列、不许切过来 (没绑定的照旧可见)。
895
- sessions = (await scanClaudeSessions()).filter((s) => ((t) => !t || sameBot(who, t))(bridge.targetForSession(s.sessionId)));
905
+ sessions = await scanClaudeSessions();
896
906
  }
897
907
  catch (e) {
898
908
  log.error({ err: e.message }, "/sessions scan failed");
@@ -923,8 +933,14 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
923
933
  // sender is already in allowFrom, we treat that authorization as license
924
934
  // to auto-spawn: this inbound becomes both the binding signal and the
925
935
  // first prompt — attach, then fall through to dispatch.
926
- if (text.trimStart().startsWith("/") && !bridge.hasMirrorTarget(who)) {
927
- const { err } = await ensureSession(who, asked);
936
+ // v3 §3: 管家接待的新化身与 slash 命令同权 —— 裸消息也是该聊天的第一条消息,
937
+ // 直接在身份的工作区里起 pane, 不再回「还没有会话 — 发 /new」。其余 named slot
938
+ // 照旧 (点一个名字 ≠ 创建它, 创建走 spawn 的 409-clash 路径)。
939
+ // 学徒的首触同样在这里起 pane (工作区 = wrc.apprentice.workspace) —— 之后 pane 死亡由
940
+ // dispatch 的 --resume 自动同身份重生 (§7), 不再走这条。
941
+ const apprenticeHere = isApprentice(wizardStore(), who);
942
+ if (!bridge.hasMirrorTarget(who) && (text.trimStart().startsWith("/") || freshSteward.has(who) || apprenticeHere)) {
943
+ const { err } = await ensureSession(who, asked, freshSteward.get(who) || identityWorkspaceOf(wizardStore(), who) || (apprenticeHere ? cfg.wrc.apprentice.workspace : undefined));
928
944
  if (err) {
929
945
  await replyText(frame, msg, who, err);
930
946
  return { stop: true };
@@ -959,51 +975,238 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
959
975
  log.info({ target, jsonl, tailLen: tail.length, quotedLen: quoted.length, hit }, "quoteInContext: tail check");
960
976
  return hit;
961
977
  };
962
- // 路由用掉的那个 `.name` 已被 parseTag 摘走,正文里剩下的每个 `.x` 都可能是
963
- // 用户在指另一个 wizard。解析走 bridge 自己的 resolvePeerTag —— peer 工具用的
964
- // 同一套(全局名册),所以标注出来的地址一定是 peek_peer/send_peer 打得中的;
965
- // 解析不到的 `.foo` 与自指静默略过。
966
- const peerMentions = (who, text) => {
967
- const mb = bridge;
968
- const seen = new Set();
969
- return allNames(text).flatMap((name) => {
970
- const r = mb.resolvePeerTag(who, name);
971
- if (!r.ok || r.target === who || seen.has(r.target))
972
- return [];
973
- seen.add(r.target);
974
- const { runningCwd, defaultCwd } = mb.getCwd(r.target);
975
- return [{
976
- tag: name,
977
- target: r.target,
978
- chat: chatNameOf(cfg, r.target),
979
- foreign: r.foreign,
980
- job: wizardStore()?.get(r.target)?.description ?? "",
981
- cwd: runningCwd || defaultCwd,
982
- }];
983
- });
984
- };
985
978
  // 名字 → 它指向谁。哪个 `.x` 是路由不在这里定: parseTag 只认消息开头那一个。
986
- const resolve = (base, name) => resolveName(base, name);
979
+ // 裸消息 (name = "") 走管家接待 (§3): 绑定的管家身份在本群的化身; 解析要新开化身时先落记录
980
+ // (名字/身份/种类来自身份锚点), 会话由 gate 的 ensureSession 在身份的工作区里起。
981
+ const freshSteward = new Map(); // target → 新化身的工作区 (identity workspace)
982
+ /** 在 base 新开一条身份化身 —— 管家接待与「点类名」走同一条路 (人 2026-11-18):
983
+ * 身份有类 → 领一个序号 (allocOrdinal, 永不复用), 名字 `<类名>-<N>`, target 用实例名
984
+ * (uniqueTag 防撞), 记录带 identity=类 id / ordinal, 并继承类的字段;
985
+ * 没有类 → 旧行为 (锚点的名字 + 身份级字段)。返回落定的 target。 */
986
+ const openManifestation = (base, fresh, wantTarget) => {
987
+ const store = wizardStore();
988
+ if (!store)
989
+ return wantTarget;
990
+ const cls = fresh.classId ? store.classes?.get(fresh.classId) : undefined;
991
+ if (cls) {
992
+ // 领号 / 落名 / 继承类字段都在 wizard.openInstance 里 (同一把尺子给「点类名」复用)。
993
+ const target = openInstance(store, base, cls.id, fresh.kind ?? "steward");
994
+ if (target) {
995
+ freshSteward.set(target, cls.workspace);
996
+ log.info({ base, target, classId: cls.id }, "class: new instance registered");
997
+ return target;
998
+ }
999
+ }
1000
+ // 身份级字段 (职责 / 专长 / 记忆 / 角色) 从锚点带过来: 新化身是同一个身份在不同群的
1001
+ // 又一条记录, 不是一张白纸。
1002
+ const inherited = identityFieldsOf(anchorOf(store, fresh.identity));
1003
+ store.upsert(wantTarget, { ...inherited, identity: fresh.identity, name: fresh.name, ...(fresh.kind ? { kind: fresh.kind } : {}) });
1004
+ freshSteward.set(wantTarget, fresh.workspace ?? "");
1005
+ log.info({ base, target: wantTarget, identity: fresh.identity }, "steward reception: new manifestation registered");
1006
+ return wantTarget;
1007
+ };
1008
+ const stewardReception = (base) => {
1009
+ // §4.1: 源已绑进 room R → 接待 = R 的 host (stewardRoute 的第一道; resolve 里的
1010
+ // sourceRoute 已经先答过, 这里是无 sourceRoute 注入时的兜底, 比如测试 / 老接线)。
1011
+ const bound = (b) => {
1012
+ const t = opts.sourceRoute?.(b)?.target;
1013
+ return t ? { target: t } : undefined;
1014
+ };
1015
+ const r = resolveSteward(cfg, wizardStore(), base, (t) => ((c) => c.runningCwd || c.defaultCwd)(bridge.getCwd(t)), bound);
1016
+ if (r.fresh && !freshSteward.has(r.target))
1017
+ return openManifestation(base, r.fresh, r.target);
1018
+ return r.target;
1019
+ };
1020
+ // 点名: 已绑定的群里点本群管家 → 仍走接待 (落本群化身, 没有就新开), 不回落锚点 ——
1021
+ // 否则点名会与别的群共享那条会话, 而它明确是指「本群的管家」。这是「按群隔离会话」
1022
+ // 的唯一入口: 其余点名 (worker、别群的管家) 都走 resolveName, 跨群共享同一会话。
1023
+ const resolve = (base, name, speaker) => {
1024
+ // 保留别名 "me": 按发话人解析/惰性落他自己的分身 (me-room 的落账/回发在 wiring B 分流)。
1025
+ if (name === ME_TAG && speaker)
1026
+ return ensureMeWizard(wizardStore(), speaker, meWorkspaceOf(sourcePath));
1027
+ // §4.1: 源已绑 / 帖子源首触时, 裸消息的接待对象是承载 room 的 host, 不是源自己的类绑定化身
1028
+ // (后者会给首触开一个新实例 —— 正是 P3 要停掉的行为)。
1029
+ if (!name)
1030
+ return opts.sourceRoute?.(base)?.target ?? stewardReception(base);
1031
+ const store = wizardStore();
1032
+ const rec = store?.byName(name);
1033
+ if (store && rec) {
1034
+ const id = identityOf(rec);
1035
+ // 实例名 (`<类名>-<N>`) 是精确地址: 那一条就是那一条 (跨群也直接投它, 回复回本群)。
1036
+ if (rec.ordinal !== undefined && parseInstanceName(name))
1037
+ return rec.target;
1038
+ if (id === stewardIdentityOf(cfg, store, base))
1039
+ return stewardReception(base);
1040
+ // 类名: 本群有该类的实例就用它; 没有就在本群新建一个 (与管家接待同一路径)。
1041
+ const cls = store.classes?.get(id);
1042
+ if (cls) {
1043
+ const hit = store.all().find((w) => identityOf(w) === id && baseOfKey(w.target) === base);
1044
+ if (hit)
1045
+ return hit.target;
1046
+ const kind = anchorOf(store, id)?.kind;
1047
+ return openManifestation(base, {
1048
+ identity: id, name: cls.name, classId: cls.id, workspace: cls.workspace, ...(kind ? { kind } : {}),
1049
+ }, keyOf(base, cls.name));
1050
+ }
1051
+ }
1052
+ return resolveName(base, name);
1053
+ };
987
1054
  const route = (msg, raw) => {
988
1055
  const c = composeInbound(msg, raw, quoteInContext, stripAt, resolve);
989
- return { ...c, who: resolve(chatPrincipal(msg), c.tag) };
1056
+ return { ...c, who: resolve(chatPrincipal(msg), c.tag, String(msg.from?.userid ?? "")) };
1057
+ };
1058
+ // ── 新群引导 (onboarding.ts) ──────────────────────────────────────
1059
+ // 人 2026-11-17 改口径: 引导要一个**真实的引导会话** (对话式比系统行友好), 且「工作区
1060
+ // 设置以后就等同于绑定了管家, 就该退出引导」。daemon 是状态机主人 —— 判定/校验/落盘/
1061
+ // 强制全在这里 (模型跳不了步、落不了错盘); 引导化身 (base#guide, 不占 untagged —— 那是
1062
+ // 管家锚点的保留位) 只把 daemon 的指令转成人话回群, 没有工具面 (见 guideRefusal)。
1063
+ // 绑定即收: 目录 / 已有管家名一落定, 完成确认走 daemon 系统行, 引导化身当场 kill + drop
1064
+ // —— 不再留告别窗口与定时器 (reload 丢定时器 = 群里残留一个「等指令」的会话)。兜底:
1065
+ // 绑定已在 (人手改 config、上个进程死在半路) 而引导化身还挂着, 下一条群消息进门时收尸。
1066
+ const onboarding = opts.onboarding ?? loadOnboardingStore(cfg);
1067
+ /** 频道原生帧等 topic_at_bot 配对的上限 (实测事件先到 0.3–0.8s; 只有没配过的帖子会等)。 */
1068
+ const CHANNEL_PAIR_WAIT_MS = 2000;
1069
+ const reapGuide = async (base, why) => {
1070
+ const guide = guideOf(wizardStore(), base);
1071
+ if (!guide)
1072
+ return;
1073
+ const r = await bridge.killPane(guide);
1074
+ wizardStore()?.drop(guide);
1075
+ log.info({ base, guide, why, killed: r.ok, reason: r.reason }, "onboarding: guide reaped");
1076
+ };
1077
+ // 频道 (人 2026-11-17 拍板: 整个频道一个管家, 每个帖子复用): 原生帧的 base 是帖子群, 先等它与
1078
+ // 同句 topic_at_bot 配上对拿到频道键 (原生帧可能先到), 再把散落的帖子级绑定收口成频道一条。
1079
+ const settleChannelPost = async (base) => {
1080
+ const topicId = channelOfPost(cfg, base) || await awaitChannelOfPost(cfg, base, CHANNEL_PAIR_WAIT_MS);
1081
+ if (!topicId) {
1082
+ log.info({ base }, "channel post: 未配上频道 (没有同句 topic_at_bot), 按普通群判");
1083
+ return;
1084
+ }
1085
+ const { r } = guardCharter(() => settleChannelSteward(cfg, wizardStore(), sourcePath, base), (s) => (s ? { what: "频道 " + s.topicId + " 的管家收口为 " + s.name + " (清掉帖子级绑定 " + s.cleared.join(", ") + ")", byHuman: false } : undefined));
1086
+ if (r)
1087
+ log.info({ base, ...r }, "channel post: steward settled at channel level");
990
1088
  };
991
- const send = async (frame, msg, who, text, images = []) => {
992
- // 斜杠命令按行解析,尾巴上多挂一段会让它不再被识别成命令 —— 只标注普通消息。
993
- const slash = text.trimStart().startsWith("/");
994
- const hint = slash ? [] : [peerMentionPart(peerMentions(who, text), ((c) => c.runningCwd || c.defaultCwd)(bridge.getCwd(who)))];
995
- // 谁、在哪个群说的 —— transcript 里只有这一段记着它 (read_chat 从那里读回来)。
996
- // 私信也带真实 userid 与稳定 chat key, 不能从 wizard home/defaultChat 猜。
997
- const channel = chatPrincipal(msg);
998
- const chat = chatNameOf(cfg, channel);
999
- const envelope = slash ? "" : renderHumanEnvelope(msg.from.userid, chat || channel, channel);
1000
- const steward = slash || !stewardTierOf(cfg, who) ? "" : renderStewardHint();
1001
- // 同一条边界上再挂: 点名提示, 以及这个 wizard 不在场时群里发生的成员变动 (见 notices.ts,
1002
- // 近几次注入里给过的不再重复)。
1003
- const notice = noticeSuffixFor(who, text, { human: { channel } }, hint);
1089
+ // 频道级绑定落定: 同频道其余帖子的在途引导一并收掉 —— 它们从此复用这个管家。
1090
+ const reapChannelSiblings = async (base) => {
1091
+ const topicId = channelOf(cfg, base);
1092
+ if (!topicId)
1093
+ return;
1094
+ for (const b of postsOfChannel(cfg, topicId).filter((p) => p !== base)) {
1095
+ onboarding.finish(b);
1096
+ await reapGuide(b, "channel bound");
1097
+ }
1098
+ };
1099
+ const guideGate = async (frame, msg, raw) => {
1100
+ if (!isGroup(msg))
1101
+ return false;
1102
+ let base = chatPrincipal(msg);
1103
+ if (sourceOf(msg) === "channel") {
1104
+ await settleChannelPost(base);
1105
+ // §4.1: 这个源已绑进某个 room / 帖子 room 已有 host → 接待在 room 里, 不走频道引导
1106
+ // (绑定优先于「频道还没绑定管家」—— 一个帖子可以绑进别处, 不该被频道引导截走)。
1107
+ if (opts.sourceRoute?.(base))
1108
+ return false;
1109
+ // 频道: 绑定与引导的粒度都是频道 (人 2026-11-23: 一个频道一个管家、一条引导)。原生帧的
1110
+ // base 是**帖子**群 (chat:opk…), 配上频道就换回频道 room —— 引导化身住频道 room, 帖子
1111
+ // room 在绑定前没有 host, 人话落那儿没人接。
1112
+ const topicId = channelOfPost(cfg, base);
1113
+ if (topicId)
1114
+ base = "chat:" + topicId;
1115
+ }
1116
+ const store = wizardStore();
1117
+ if (!needsOnboarding(cfg, store, base)) {
1118
+ // 绑定已在 (含同频道别的帖子绑的): 在途引导状态 (出站豁免) 与引导化身一并收掉。
1119
+ onboarding.finish(base);
1120
+ if (guideOf(store, base))
1121
+ await reapGuide(base, "already bound");
1122
+ return false;
1123
+ }
1124
+ // 与 gate 同一把 allowFrom 尺子: 陌生人交给老路 (gate 回未授权), 引导不搭理。
1125
+ const allow = cfg.wrc.allowFrom;
1126
+ if (!isAllowed(allow, authPrincipals(msg)))
1127
+ return false;
1128
+ const text = raw.trim();
1129
+ // 引导期每条消息落一行: 「人说了但没反应」时要先分清是没进 daemon 还是判定没走通 —— 这条
1130
+ // 路径原本一个日志都没有, 空正文那条回复也只走 replySystem (不落日志)。
1131
+ log.info({ base, len: text.length, guide: guideOf(store, base) }, "onboarding: guideGate");
1132
+ if (!text) {
1133
+ await replySystem(frame, msg, "[wezard] 本群还在初始化引导中 — 请发文字: 管家的工作目录 (绝对路径), 或已有管家的名字。");
1134
+ return true;
1135
+ }
1136
+ // 点名 .x / 🧙 x 的消息不拦: 人在明确找某个 wizard (或叫一个新的), 与本群初始化无关。
1137
+ if (parseTag(text).tag)
1138
+ return false;
1139
+ // 免授权的发现面 (/id /help) 引导期照样给 —— 直接答, 不走 route (那会顺手注册管家化身)。
1140
+ if (isIdCommand(text)) {
1141
+ await replySystem(frame, msg, renderIds(msg, allow));
1142
+ return true;
1143
+ }
1144
+ if (isHelpCommand(text)) {
1145
+ await replySystem(frame, msg, renderHelp());
1146
+ return true;
1147
+ }
1148
+ const input = classifyOnboardingInput(text);
1149
+ if (input.kind === "command") {
1150
+ await replySystem(frame, msg, "[wezard] 本群还没完成初始化 — 先回复管家的工作目录 (绝对路径) 或已有管家的名字, 命令引导完成后可用。");
1151
+ return true;
1152
+ }
1153
+ const first = !onboarding.get(base);
1154
+ onboarding.begin(base);
1155
+ // ① 快路径 (2026-11-20 收窄): **整句**就是一个路径 / 一个名字才一步绑定。含路径但还有别的
1156
+ // 话、相对路径、认不出的 —— 全部下面交给引导化身, 不再从长句里抽第一个路径 (实录: 「在
1157
+ // ~/develop/Tencent 下建 dhtpm 并绑定」被绑成父目录, 人真正要的事全丢)。
1158
+ let retryReason = "";
1159
+ if (input.kind !== "sentence") {
1160
+ const verdict = judgeOnboarding(store, base, input, (t) => bridge.sessionInfo(t)?.cwd ?? "");
1161
+ if (verdict.kind !== "retry") {
1162
+ const bound = applyOnboarding(store, onboarding, base, verdict, (name) => guardCharter(() => bindSteward(cfg, sourcePath, base, name), () => ({ what: verdict.kind === "bind-new" ? "新群引导新建管家 " + name + " (工作区 " + verdict.workspace + ") 并绑到 " + base : "新群引导把 " + name + " 绑为 " + base + " 的管家", byHuman: true })), (t) => identityWorkspaceOf(store, t) || ((c) => c.runningCwd || c.defaultCwd)(bridge.getCwd(t)));
1163
+ log.info({ base, ...bound }, "onboarding: steward bound (fast path)");
1164
+ // 引导化身在 room 里 (上一句已经交给它了): 管家接进 room、duty 连原话一起转过去,
1165
+ // 完成确认由 room 的系统行发; 否则照旧回一条 daemon 系统行。
1166
+ if (!(opts.guideSettle?.(base, bound) ?? false))
1167
+ await replySystem(frame, msg, renderOnboardingDone(bound));
1168
+ await reapGuide(base, "bound");
1169
+ await reapChannelSiblings(base);
1170
+ return true;
1171
+ }
1172
+ retryReason = verdict.reason;
1173
+ }
1174
+ // ② 别的都是引导化身的事: 起/续引导会话, 把这轮的话术挂到它下一次注入上 (它就是引导的宪章),
1175
+ // 人这句由 inbound 端口落进本群 room (guide 作 founder) 并唤醒它 —— 绑定后 duty 连原话交给管家。
1176
+ // 引导化身自己的工作区 = 全局默认 (cfg.wrc.cwd) —— 要绑的 workspace 是管家的。
1177
+ const guide = guideTargetOf(store, base);
1178
+ if (!bridge.hasMirrorTarget(guide)) {
1179
+ store?.upsert(guide, { identity: guide, kind: "worker", description: GUIDE_DESC, workspace: expandHome(cfg.wrc.cwd) });
1180
+ log.info({ base, guide }, "onboarding: guide session spawned");
1181
+ }
1182
+ const { err } = await ensureSession(guide, "guide", expandHome(cfg.wrc.cwd));
1183
+ if (err) {
1184
+ await replySystem(frame, msg, "[wezard] 引导会话起不来: " + err + " — 稍后再发一句试试。");
1185
+ return true;
1186
+ }
1187
+ bridge.armCharter(guide, first ? renderGuideOpening() : renderGuideRetry(retryReason));
1188
+ const sent = opts.guideInbound
1189
+ ? await opts.guideInbound({ base, guide, text, from: msg.from.userid, streamId: msg.msgid, frame })
1190
+ : { ok: false, reason: "room 接线还没就绪" };
1191
+ if (sent.ok)
1192
+ return true;
1193
+ log.warn({ base, guide, reason: sent.reason }, "onboarding: 人这句没能进 room");
1194
+ await replySystem(frame, msg, "[wezard] 引导没接上 (" + (sent.reason ?? "未知原因") + ") — 稍后再发一句。");
1195
+ return true;
1196
+ };
1197
+ /** `text` 进 prompt (可带引用前缀); `spoken` = 人自己打的那部分, 账本人话行只存它;
1198
+ * `mentionBot` = 这句 @ 了机器人 (见 atBot) —— 账本行记 mention:"bot", 不再交给 monitor 判决。 */
1199
+ const send = async (frame, msg, who, text, images = [], spoken = "", mentionBot = false) => {
1200
+ // 账本行只存人的原话: 信封已删 (谁说的 = 行作者, 哪个群 = 行所在 room), 管家自查 / 点名提示 /
1201
+ // 名册增量这些提醒尾巴也不在这里拼 —— 它们在唤醒渲染那一刻才挂 (wake-tail.ts / room-hub)。
1202
+ // §4.1: 入口源已绑 / 帖子源首触 → 落承载 room (不是入口 base), 行上写死 src / post。
1203
+ const sr = opts.sourceRoute?.(chatPrincipal(msg));
1204
+ const channel = sr?.room ?? chatPrincipal(msg);
1205
+ // P7-S1 只记录不动行为: 人话 dispatch 前落一行 human (同步内存记账, 落盘在后台)。
1206
+ // room 模型: 人话行的去重键 = 企微 msgid (账本行 ext), 事件表已退役。
1004
1207
  try {
1005
1208
  // 回复回到发话的这个群 —— `who` 可能住在别的聊天 (名字全局可达)。
1006
- await bridge.dispatch({ eventId: slash ? undefined : messageId(botTagOf(msg), channel, msg.msgid), identity: JSON.stringify(msg), originalAt: msg.create_time ? (msg.create_time < 1e12 ? msg.create_time * 1000 : msg.create_time) : Date.now(), principal: who, text: text + renderTail(envelope, steward, notice), images, frame, streamId: msg.msgid, channel, speaker: `user:${msg.from.userid}` });
1209
+ await bridge.dispatch({ eventId: undefined, identity: JSON.stringify(msg), originalAt: msg.create_time ? (msg.create_time < 1e12 ? msg.create_time * 1000 : msg.create_time) : Date.now(), principal: who, text, rawText: spoken || text, images, frame, streamId: msg.msgid, channel, speaker: `user:${msg.from.userid}`, quoted: parseQuote(msg.quote)?.body, ...(mentionBot ? { mentionBot: true } : {}), ...(sr?.src && sr.room !== sr.src ? { src: sr.src } : {}), ...(sr?.post ? { post: sr.post } : {}) });
1007
1210
  }
1008
1211
  catch (e) {
1009
1212
  log.error({ err: e.message }, "bridge dispatch failed");
@@ -1013,11 +1216,32 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
1013
1216
  catch { /* ignore */ }
1014
1217
  }
1015
1218
  };
1219
+ // 入站最外层: SDK 对每条消息回调先 emit "message" 再按 msgtype 分发 —— 在这里落一行, 「人说了
1220
+ // 没反应」才分得清是帧没到 daemon (企微没推), 还是到了被后面的门吃掉 (guideGate 的日志在拿到
1221
+ // text 之后才落, 证明不了「没到」)。SDK 不认的 msgtype 只 logger.debug 一句就丢, daemon 是 info
1222
+ // 级永远看不见: 这里落 warn 带原帧, 并明确回一句 —— 人的话不能静默消失。
1223
+ client.on("message", (frame) => {
1224
+ const msg = frame.body;
1225
+ if (!msg)
1226
+ return;
1227
+ const source = msg.compat_info?.source;
1228
+ log.info({ msgid: msg.msgid, msgtype: msg.msgtype, chattype: msg.chattype, chat: chatPrincipal(msg), from: msg.from?.userid, hasQuote: !!msg.quote, ...(source ? { source } : {}) }, "rx frame");
1229
+ // 频道里 @ 机器人的原生帧 (chatid = 帖子群): 记一笔, 同一句的 topic_at_bot 桥接就不再重投 (channel.ts)。
1230
+ if (source === "channel")
1231
+ noteNativeChannelFrame(msg.from?.userid ?? "", chatPrincipal(msg));
1232
+ if (ROUTED_MSGTYPES.has(msg.msgtype) || NO_REPLY_MSGTYPES.has(msg.msgtype))
1233
+ return;
1234
+ log.warn({ body: msg }, "rx frame — unhandled msgtype, not routed to any wizard");
1235
+ void replySystem(frame, msg, "[wezard] 收到一条暂不支持的消息 (类型 " + msg.msgtype + "), 没有转给任何 wizard — 请改发文字。");
1236
+ });
1016
1237
  client.on("message.text", async (frame) => {
1017
1238
  const msg = frame.body;
1018
1239
  if (!msg)
1019
1240
  return;
1020
- const { text, tag, promoted, who } = route(msg, stripAt(msg, msg.text?.content ?? ""));
1241
+ const raw = msg.text?.content ?? "";
1242
+ if (await guideGate(frame, msg, stripAt(msg, raw)))
1243
+ return;
1244
+ const { text, tag, promoted, who, spoken } = route(msg, stripAt(msg, raw));
1021
1245
  const known = bridge.hasMirrorTarget(who);
1022
1246
  log.info({ msgid: msg.msgid, len: text.length, tag, hasQuote: !!msg.quote, promoted, chat: chatPrincipal(msg), who, known }, "rx text");
1023
1247
  // 落到一个没有任何会话的聊天时, 把原始回调也记一笔: 频道 / 群 / 单聊的 chatid
@@ -1027,13 +1251,15 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
1027
1251
  const { stop } = await gate(frame, msg, text, who, tag);
1028
1252
  if (stop)
1029
1253
  return;
1030
- await send(frame, msg, who, text);
1254
+ await send(frame, msg, who, text, [], spoken, atBot(botNames, msg, raw));
1031
1255
  });
1032
1256
  client.on("message.image", async (frame) => {
1033
1257
  const msg = frame.body;
1034
1258
  if (!msg)
1035
1259
  return;
1036
1260
  log.info({ msgid: msg.msgid, hasQuote: !!msg.quote }, "rx image");
1261
+ if (await guideGate(frame, msg, ""))
1262
+ return;
1037
1263
  // Images carry no text of their own — the quote (if any) is the only
1038
1264
  // routing signal; without it they land on the chat's default session.
1039
1265
  const { text, tag, who } = route(msg, "");
@@ -1052,7 +1278,7 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
1052
1278
  // each via macOS clipboard + Ctrl+V into the live TTY (matches Claude
1053
1279
  // Code's documented image paste flow → image content block, no Read tool
1054
1280
  // turn). Spawn-mode falls back to `@<path>` automatically.
1055
- await send(frame, msg, who, text, [path]);
1281
+ await send(frame, msg, who, text, [path], "", atBot(botNames, msg, ""));
1056
1282
  });
1057
1283
  client.on("message.mixed", async (frame) => {
1058
1284
  const msg = frame.body;
@@ -1065,6 +1291,8 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
1065
1291
  .filter((it) => it.msgtype === "text")
1066
1292
  .map((it) => it.text?.content ?? "")
1067
1293
  .join("\n");
1294
+ if (await guideGate(frame, msg, stripAt(msg, rawText)))
1295
+ return;
1068
1296
  const { tag, who } = route(msg, stripAt(msg, rawText));
1069
1297
  const { stop } = await gate(frame, msg, "", who, tag);
1070
1298
  if (stop)
@@ -1096,7 +1324,8 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
1096
1324
  // Re-compose on the per-item stripped text: drops the routing `.name` (it was
1097
1325
  // consumed above; leaving it in would leak into Claude) and attaches the
1098
1326
  // quote only when it isn't already in the target's context.
1099
- await send(frame, msg, who, composeInbound(msg, texts.join("\n"), quoteInContext, stripAt, resolve).text, images);
1327
+ const composed = composeInbound(msg, texts.join("\n"), quoteInContext, stripAt, resolve);
1328
+ await send(frame, msg, who, composed.text, images, composed.spoken, atBot(botNames, msg, rawText));
1100
1329
  });
1101
1330
  // 文件 / 视频 (企微只在单聊里推): 落进 inbox, 以一行 `[文件: 路径 (大小)]` 注入 —— 不走剪贴板,
1102
1331
  // agent 按需用 Read / Bash 去读。路由与 image 同理: 没有正文, 只有引用能带 `.name`。
@@ -1113,7 +1342,7 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
1113
1342
  const got = await downloadToInbox({ client, log, inboxDir }, url, aeskey, msg.msgid, 0);
1114
1343
  // 丢了也照样告诉 agent (同 mixed): 那条流留给 bridge 回这一轮。
1115
1344
  const line = got ? attachmentLine(kind, got.path, got.bytes) : `[对方发来一个${kind === "file" ? "文件" : "视频"}, 下载失败 —— 请让发送者重发]`;
1116
- await send(frame, msg, who, [text, line].filter(Boolean).join("\n"));
1345
+ await send(frame, msg, who, [text, line].filter(Boolean).join("\n"), [], "", atBot(botNames, msg, ""));
1117
1346
  };
1118
1347
  client.on("message.file", onAttachment("file", (m) => m.file));
1119
1348
  client.on("message.video", onAttachment("video", (m) => m.video));
@@ -1128,7 +1357,7 @@ export const installInboundRouter = (client, cfg, log, bridge, sourcePath, guard
1128
1357
  const { stop } = await gate(frame, msg, text, who, tag);
1129
1358
  if (stop)
1130
1359
  return;
1131
- await send(frame, msg, who, text ? `[语音转写] ${text}` : "[对方发来一段语音, 没有转写文本]");
1360
+ await send(frame, msg, who, text ? `[语音转写] ${text}` : "[对方发来一段语音, 没有转写文本]", [], "", atBot(botNames, msg, heard));
1132
1361
  });
1133
1362
  // template_card_event is handled in approval module; no listener here.
1134
1363
  };