@zyaochen/weaverbird 0.0.0-stage → 0.1.0

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 (217) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +418 -0
  3. package/README.md +418 -2
  4. package/apps/wb-bot/README.md +118 -0
  5. package/dist/apps/wb-bot/src/agent-display.js +24 -0
  6. package/dist/apps/wb-bot/src/agent-registry.js +188 -0
  7. package/dist/apps/wb-bot/src/approval-gate/audit.js +37 -0
  8. package/dist/apps/wb-bot/src/approval-gate/cards.js +94 -0
  9. package/dist/apps/wb-bot/src/approval-gate/hook-env.js +15 -0
  10. package/dist/apps/wb-bot/src/approval-gate/hook-files.js +311 -0
  11. package/dist/apps/wb-bot/src/approval-gate/hook-main.js +147 -0
  12. package/dist/apps/wb-bot/src/approval-gate/notifier.js +29 -0
  13. package/dist/apps/wb-bot/src/approval-gate/store.js +157 -0
  14. package/dist/apps/wb-bot/src/binding/migration-runner.js +35 -0
  15. package/dist/apps/wb-bot/src/binding/migrations/001-add-run-id-agent-id.js +8 -0
  16. package/dist/apps/wb-bot/src/binding/migrations/002-add-bot-id.js +34 -0
  17. package/dist/apps/wb-bot/src/binding/migrations/003-inflight-card-agent-id-pk.js +31 -0
  18. package/dist/apps/wb-bot/src/binding/migrations/004-thread-alias-topic-key.js +31 -0
  19. package/dist/apps/wb-bot/src/binding/migrations/005-card-entity.js +21 -0
  20. package/dist/apps/wb-bot/src/binding/migrations/006-group-setting.js +17 -0
  21. package/dist/apps/wb-bot/src/binding/schema.js +58 -0
  22. package/dist/apps/wb-bot/src/binding/sleep-sync.js +5 -0
  23. package/dist/apps/wb-bot/src/binding/store.js +270 -0
  24. package/dist/apps/wb-bot/src/binding/task-index.js +127 -0
  25. package/dist/apps/wb-bot/src/boot/entry-path.js +9 -0
  26. package/dist/apps/wb-bot/src/boot/integrity.js +47 -0
  27. package/dist/apps/wb-bot/src/boot/logger.js +44 -0
  28. package/dist/apps/wb-bot/src/captain/bot-discovery.js +42 -0
  29. package/dist/apps/wb-bot/src/captain/captain-context.js +26 -0
  30. package/dist/apps/wb-bot/src/captain/captain-gate.js +9 -0
  31. package/dist/apps/wb-bot/src/captain/captain-status.js +101 -0
  32. package/dist/apps/wb-bot/src/captain/captain-stop-all.js +72 -0
  33. package/dist/apps/wb-bot/src/captain/list-bots.js +39 -0
  34. package/dist/apps/wb-bot/src/cli/doctor.js +105 -0
  35. package/dist/apps/wb-bot/src/cli/init.js +122 -0
  36. package/dist/apps/wb-bot/src/cli/parse-args.js +31 -0
  37. package/dist/apps/wb-bot/src/cli/preflight.js +9 -0
  38. package/dist/apps/wb-bot/src/cli/setup-checklist.js +10 -0
  39. package/dist/apps/wb-bot/src/commands/health.js +328 -0
  40. package/dist/apps/wb-bot/src/commands/history.js +100 -0
  41. package/dist/apps/wb-bot/src/commands/logs.js +91 -0
  42. package/dist/apps/wb-bot/src/commands/parser.js +43 -0
  43. package/dist/apps/wb-bot/src/commands/queue-metrics.js +24 -0
  44. package/dist/apps/wb-bot/src/commands/resume.js +48 -0
  45. package/dist/apps/wb-bot/src/commands/router.js +299 -0
  46. package/dist/apps/wb-bot/src/commands/status.js +77 -0
  47. package/dist/apps/wb-bot/src/commands/tasks.js +106 -0
  48. package/dist/apps/wb-bot/src/commands/wb-approval.js +86 -0
  49. package/dist/apps/wb-bot/src/commands/wb-audit.js +46 -0
  50. package/dist/apps/wb-bot/src/commands/wb-mute.js +84 -0
  51. package/dist/apps/wb-bot/src/commands/wb-sync.js +58 -0
  52. package/dist/apps/wb-bot/src/config/approval-code-owners.js +95 -0
  53. package/dist/apps/wb-bot/src/config/bot-env.js +80 -0
  54. package/dist/apps/wb-bot/src/config/config-paths.js +16 -0
  55. package/dist/apps/wb-bot/src/config/env.js +43 -0
  56. package/dist/apps/wb-bot/src/config/lark-credentials.js +14 -0
  57. package/dist/apps/wb-bot/src/e2e/preflight-env.js +147 -0
  58. package/dist/apps/wb-bot/src/e2e/preflight-main.js +12 -0
  59. package/dist/apps/wb-bot/src/feishu/admin-alert.js +94 -0
  60. package/dist/apps/wb-bot/src/feishu/artifacts.js +95 -0
  61. package/dist/apps/wb-bot/src/feishu/bot-identity.js +38 -0
  62. package/dist/apps/wb-bot/src/feishu/card-pipeline.js +121 -0
  63. package/dist/apps/wb-bot/src/feishu/card-renderer.js +360 -0
  64. package/dist/apps/wb-bot/src/feishu/card-transport.js +294 -0
  65. package/dist/apps/wb-bot/src/feishu/chat-mode-cache.js +47 -0
  66. package/dist/apps/wb-bot/src/feishu/completion-push.js +30 -0
  67. package/dist/apps/wb-bot/src/feishu/doc-comment.js +183 -0
  68. package/dist/apps/wb-bot/src/feishu/event-handler.js +2634 -0
  69. package/dist/apps/wb-bot/src/feishu/events-file-reader.js +162 -0
  70. package/dist/apps/wb-bot/src/feishu/inbound-context.js +53 -0
  71. package/dist/apps/wb-bot/src/feishu/keepalive.js +85 -0
  72. package/dist/apps/wb-bot/src/feishu/log-redact.js +20 -0
  73. package/dist/apps/wb-bot/src/feishu/markdown-style.js +95 -0
  74. package/dist/apps/wb-bot/src/feishu/media-cache.js +92 -0
  75. package/dist/apps/wb-bot/src/feishu/message-parser.js +126 -0
  76. package/dist/apps/wb-bot/src/feishu/pending-queue.js +133 -0
  77. package/dist/apps/wb-bot/src/feishu/reaction.js +44 -0
  78. package/dist/apps/wb-bot/src/feishu/reverse-at-im-handler.js +345 -0
  79. package/dist/apps/wb-bot/src/feishu/run-state.js +30 -0
  80. package/dist/apps/wb-bot/src/feishu/session-short-id.js +9 -0
  81. package/dist/apps/wb-bot/src/feishu/stream-state.js +72 -0
  82. package/dist/apps/wb-bot/src/feishu/topic-key.js +34 -0
  83. package/dist/apps/wb-bot/src/feishu/transport.js +768 -0
  84. package/dist/apps/wb-bot/src/feishu/wb-runner-spawner.js +84 -0
  85. package/dist/apps/wb-bot/src/heartbeat/bot-heartbeat.js +20 -0
  86. package/dist/apps/wb-bot/src/main.js +144 -0
  87. package/dist/apps/wb-bot/src/multi/discovery.js +53 -0
  88. package/dist/apps/wb-bot/src/multi/main.js +57 -0
  89. package/dist/apps/wb-bot/src/multi/parse-args.js +17 -0
  90. package/dist/apps/wb-bot/src/multi/supervisor.js +288 -0
  91. package/dist/apps/wb-bot/src/run-observability/orchestrator.js +61 -0
  92. package/dist/apps/wb-bot/src/security/bot-id-validator.js +18 -0
  93. package/dist/apps/wb-bot/src/security/cwd-guard.js +72 -0
  94. package/dist/apps/wb-bot/src/security/env-whitelist.js +94 -0
  95. package/dist/apps/wb-bot/src/server/wire-up.js +125 -0
  96. package/dist/apps/wb-cli/src/commands/approval.js +101 -0
  97. package/dist/apps/wb-cli/src/commands/attach.js +31 -0
  98. package/dist/apps/wb-cli/src/commands/audit.js +71 -0
  99. package/dist/apps/wb-cli/src/commands/captain.js +72 -0
  100. package/dist/apps/wb-cli/src/commands/debug.js +22 -0
  101. package/dist/apps/wb-cli/src/commands/history.js +75 -0
  102. package/dist/apps/wb-cli/src/commands/list.js +24 -0
  103. package/dist/apps/wb-cli/src/commands/logs.js +122 -0
  104. package/dist/apps/wb-cli/src/commands/resume.js +50 -0
  105. package/dist/apps/wb-cli/src/commands/runs.js +75 -0
  106. package/dist/apps/wb-cli/src/commands/status.js +35 -0
  107. package/dist/apps/wb-cli/src/commands/watch.js +73 -0
  108. package/dist/apps/wb-cli/src/main.js +312 -0
  109. package/dist/packages/core/src/agent/claude-code.js +354 -0
  110. package/dist/packages/core/src/agent/cli-subprocess.js +244 -0
  111. package/dist/packages/core/src/agent/codex.js +231 -0
  112. package/dist/packages/core/src/agent/index.js +5 -0
  113. package/dist/packages/core/src/agent/registry.js +47 -0
  114. package/dist/packages/core/src/agent/types.js +1 -0
  115. package/dist/packages/core/src/approval-gate/audit.js +16 -0
  116. package/dist/packages/core/src/approval-gate/contracts.js +26 -0
  117. package/dist/packages/core/src/approval-gate/matcher.js +112 -0
  118. package/dist/packages/core/src/audit-pipe/audit-pipe-main.js +38 -0
  119. package/dist/packages/core/src/audit-pipe/bitable-sink.js +156 -0
  120. package/dist/packages/core/src/audit-pipe/config.js +105 -0
  121. package/dist/packages/core/src/audit-pipe/contracts.js +33 -0
  122. package/dist/packages/core/src/audit-pipe/index.js +2 -0
  123. package/dist/packages/core/src/audit-pipe/mirror-sink.js +21 -0
  124. package/dist/packages/core/src/audit-pipe/normalizer.js +129 -0
  125. package/dist/packages/core/src/audit-pipe/orchestrator.js +252 -0
  126. package/dist/packages/core/src/audit-pipe/parser.js +24 -0
  127. package/dist/packages/core/src/audit-pipe/tailer.js +46 -0
  128. package/dist/packages/core/src/audit-pipe/wal.js +71 -0
  129. package/dist/packages/core/src/calendar-hook/config.js +45 -0
  130. package/dist/packages/core/src/calendar-hook/contracts.js +66 -0
  131. package/dist/packages/core/src/calendar-hook/index.js +5 -0
  132. package/dist/packages/core/src/calendar-hook/scheduler.js +169 -0
  133. package/dist/packages/core/src/calendar-hook/service.js +189 -0
  134. package/dist/packages/core/src/calendar-hook/transport.js +66 -0
  135. package/dist/packages/core/src/captain/captain-service.js +160 -0
  136. package/dist/packages/core/src/captain/command-catalog.js +41 -0
  137. package/dist/packages/core/src/captain/concurrency-config.js +10 -0
  138. package/dist/packages/core/src/captain/concurrency-queue-index.js +94 -0
  139. package/dist/packages/core/src/captain/concurrency-queue-store.js +43 -0
  140. package/dist/packages/core/src/captain/contracts.js +102 -0
  141. package/dist/packages/core/src/captain/cwd-inference.js +29 -0
  142. package/dist/packages/core/src/captain/enqueue-or-spawn.js +63 -0
  143. package/dist/packages/core/src/captain/index.js +27 -0
  144. package/dist/packages/core/src/captain/queue-metrics/aggregator.js +98 -0
  145. package/dist/packages/core/src/captain/queue-metrics/contracts.js +42 -0
  146. package/dist/packages/core/src/captain/queue-metrics/event-store.js +26 -0
  147. package/dist/packages/core/src/captain/session-store.js +429 -0
  148. package/dist/packages/core/src/captain/toml-loader.js +86 -0
  149. package/dist/packages/core/src/config/errors.js +15 -0
  150. package/dist/packages/core/src/config/registry.js +34 -0
  151. package/dist/packages/core/src/errors/codes.js +98 -0
  152. package/dist/packages/core/src/group-sync/autodoc.js +166 -0
  153. package/dist/packages/core/src/group-sync/config.js +45 -0
  154. package/dist/packages/core/src/group-sync/contracts.js +126 -0
  155. package/dist/packages/core/src/group-sync/dispatch.js +163 -0
  156. package/dist/packages/core/src/group-sync/index.js +9 -0
  157. package/dist/packages/core/src/group-sync/revdiff.js +138 -0
  158. package/dist/packages/core/src/group-sync/scheduler.js +93 -0
  159. package/dist/packages/core/src/group-sync/service.js +79 -0
  160. package/dist/packages/core/src/group-sync/transport.js +97 -0
  161. package/dist/packages/core/src/group-sync/xref.js +139 -0
  162. package/dist/packages/core/src/index.js +23 -0
  163. package/dist/packages/core/src/minutes/adapter.js +187 -0
  164. package/dist/packages/core/src/minutes/client.js +46 -0
  165. package/dist/packages/core/src/minutes/contracts.js +36 -0
  166. package/dist/packages/core/src/minutes/index.js +3 -0
  167. package/dist/packages/core/src/paths.js +158 -0
  168. package/dist/packages/core/src/periodic-tasks/config.js +45 -0
  169. package/dist/packages/core/src/periodic-tasks/contracts.js +75 -0
  170. package/dist/packages/core/src/periodic-tasks/index.js +4 -0
  171. package/dist/packages/core/src/periodic-tasks/orchestrator.js +249 -0
  172. package/dist/packages/core/src/periodic-tasks/state.js +29 -0
  173. package/dist/packages/core/src/reverse-channel/attach-handler.js +108 -0
  174. package/dist/packages/core/src/reverse-channel/audit-encoder.js +61 -0
  175. package/dist/packages/core/src/reverse-channel/contracts.js +136 -0
  176. package/dist/packages/core/src/reverse-channel/echo-tailer.js +36 -0
  177. package/dist/packages/core/src/reverse-channel/handoff.js +238 -0
  178. package/dist/packages/core/src/reverse-channel/index.js +5 -0
  179. package/dist/packages/core/src/reverse-channel/ipc-client.js +110 -0
  180. package/dist/packages/core/src/reverse-channel/ipc-control-handler.js +27 -0
  181. package/dist/packages/core/src/reverse-channel/ipc-server.js +127 -0
  182. package/dist/packages/core/src/reverse-channel/mute-registry.js +113 -0
  183. package/dist/packages/core/src/reverse-channel/pid-resolver.js +41 -0
  184. package/dist/packages/core/src/reverse-channel/reverse-at-handler.js +19 -0
  185. package/dist/packages/core/src/reverse-channel/sla-tracker.js +51 -0
  186. package/dist/packages/core/src/run-observability/alert-card-renderer.js +24 -0
  187. package/dist/packages/core/src/run-observability/alert-pusher.js +47 -0
  188. package/dist/packages/core/src/run-observability/card-refresher.js +31 -0
  189. package/dist/packages/core/src/run-observability/card-renderer-progress.js +33 -0
  190. package/dist/packages/core/src/run-observability/config-loader.js +23 -0
  191. package/dist/packages/core/src/run-observability/contracts.js +107 -0
  192. package/dist/packages/core/src/run-observability/exit-code-detector.js +16 -0
  193. package/dist/packages/core/src/run-observability/finalizer.js +114 -0
  194. package/dist/packages/core/src/run-observability/index.js +12 -0
  195. package/dist/packages/core/src/run-observability/obs-toggle-handler.js +29 -0
  196. package/dist/packages/core/src/run-observability/progress-collector.js +53 -0
  197. package/dist/packages/core/src/run-observability/progress-store.js +100 -0
  198. package/dist/packages/core/src/run-observability/silent-timeout-detector.js +12 -0
  199. package/dist/packages/core/src/run-registry/bitable-writer.js +308 -0
  200. package/dist/packages/core/src/run-registry/config.js +77 -0
  201. package/dist/packages/core/src/run-registry/contracts.js +114 -0
  202. package/dist/packages/core/src/run-registry/doc-sink-classifier.js +0 -0
  203. package/dist/packages/core/src/run-registry/doc-sink-transport.js +63 -0
  204. package/dist/packages/core/src/run-registry/doc-sink.js +200 -0
  205. package/dist/packages/core/src/run-registry/extractor.js +40 -0
  206. package/dist/packages/core/src/run-registry/index.js +11 -0
  207. package/dist/packages/core/src/run-registry/inherit.js +11 -0
  208. package/dist/packages/core/src/run-registry/orchestrator.js +86 -0
  209. package/dist/packages/core/src/run-registry/run-registry-main.js +38 -0
  210. package/dist/packages/core/src/run-registry/tailer.js +390 -0
  211. package/dist/packages/core/src/run-registry/wal.js +106 -0
  212. package/dist/packages/core/src/runner/event-replay.js +65 -0
  213. package/dist/packages/core/src/runner/wb-runner-main.js +27 -0
  214. package/dist/packages/core/src/runner/wb-runner.js +237 -0
  215. package/dist/packages/core/src/util/entry-module.js +21 -0
  216. package/dist/packages/core/src/util/ndjson-rotation.js +99 -0
  217. package/package.json +76 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ziyao Chen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,418 @@
1
+ # Weaverbird
2
+
3
+ > English · [中文](README.md)
4
+
5
+ [![Node >= 22](https://img.shields.io/badge/Node-%E2%89%A5%2022-339933?logo=node.js&logoColor=white)](#quick-start)
6
+ [![npm >= 10](https://img.shields.io/badge/npm-%E2%89%A5%2010-CB3837?logo=npm&logoColor=white)](#quick-start)
7
+ [![Captain Ready](https://img.shields.io/badge/Captain-multi--bot-blue)](#commands--permissions-matrix)
8
+ [![Reverse-@ Governance](https://img.shields.io/badge/reverse--%40-governed-6f42c1)](#governance-flows)
9
+ [![W11 Card Cancel](https://img.shields.io/badge/W11-card%20%E5%8F%AB%E5%81%9C-brightgreen)](#commands--permissions-matrix)
10
+ [![Docs Only Safe Defaults](https://img.shields.io/badge/docs-safe%20defaults-black)](#config)
11
+
12
+ > **Weaverbird** is a single-host Feishu (Lark) AI agent console. You can drive local `claude` / `codex` from Feishu, use a single bot for everyday work, or run multi-bot + Captain mode for cross-bot control, reverse-@ governance, and card-based stop-loss actions.
13
+ >
14
+ > It is the author's own **personal tool**, not a general-purpose SDK or framework. This README only describes **current implemented behavior**. `passport role` is still a **NO-GO**, `takeover` is still **out of scope**, and real IM / real group / card-button end-to-end validation is still **pending manual verification**.
15
+
16
+ ---
17
+
18
+ <a id="table-of-contents"></a>
19
+ ## 📚 Table of Contents
20
+
21
+ - [⚡ 30-Second Overview](#30-second-overview)
22
+ - [🚀 Quick Start](#quick-start)
23
+ - [✅ First-run Verification](#first-run-verification)
24
+ - [🧭 Commands & Permissions Matrix](#commands--permissions-matrix)
25
+ - [⚙️ Config](#config)
26
+ - [🏗️ Architecture at a Glance](#architecture-at-a-glance)
27
+ - [🛑 Governance Flows](#governance-flows)
28
+ - [🧯 Troubleshooting](#troubleshooting)
29
+ - [❓ FAQ](#faq)
30
+ - [📖 Deep Dives](#deep-dives)
31
+ - [🔐 Security & Non-goals](#security--non-goals)
32
+
33
+ ---
34
+
35
+ <a id="30-second-overview"></a>
36
+ ## ⚡ 30-Second Overview
37
+
38
+ ### What this is
39
+
40
+ - Run local agent CLIs such as `claude` and `codex` from Feishu
41
+ - Support both **single-bot** and **multi-bot + Captain** as current main paths
42
+ - Ship **reverse-@ admin cancel** (`/cancel <shortId>`) and the card `叫停` (`Call Stop`) GUI entry
43
+ - Keep all stop-loss governance centered on **explicit shortId**, **fail-closed auth**, and **strong auditability**
44
+
45
+ ### What it can do today
46
+
47
+ - Run local agents from `@bot` and render results as streaming cards
48
+ - Use `/stop` / `/stop-all` for control-plane stop actions
49
+ - In Captain mode, use `/cancel <shortId>` or the card `叫停` button on the same admin-governance path
50
+ - In multi-bot mode, use `/list-bots`, `/status`, and `/health` for cross-bot visibility
51
+
52
+ ### What it does NOT already have
53
+
54
+ - `passport role`: **NO-GO** (see W10)
55
+ - `takeover`: **out of scope**
56
+ - Real IM / real group role / real card-button end-to-end validation: **pending manual verification**
57
+
58
+ ---
59
+
60
+ <a id="quick-start"></a>
61
+ ## 🚀 Quick Start
62
+
63
+ > **Recommended path**: if you already have a Feishu self-built app `LARK_APP_ID` / `LARK_APP_SECRET`, the 5 steps below are the shortest success path.
64
+ > **No Feishu credentials yet?** Use `wb-cli` for a local smoke test first; only go to [`apps/wb-bot/README.md`](apps/wb-bot/README.md) when you need to set up the Feishu app.
65
+
66
+ ### 5-step quick start
67
+
68
+ 1. **Install dependencies**
69
+
70
+ ```bash
71
+ npm install
72
+ ```
73
+
74
+ 2. **Copy the template**
75
+
76
+ ```bash
77
+ cp apps/wb-bot/.env.example apps/wb-bot/.env
78
+ ```
79
+
80
+ 3. **Fill only the minimum config**
81
+
82
+ ```dotenv
83
+ LARK_APP_ID=your_lark_app_id_here
84
+ LARK_APP_SECRET=your_lark_app_secret_here
85
+ LARK_ENCRYPT_KEY=
86
+ LARK_VERIFICATION_TOKEN=
87
+ ```
88
+
89
+ Alternatively, skip steps 2 and 3: `npm run wb-bot:dev -- init` generates the config interactively, `npm run wb-bot:dev -- doctor` checks it, and `--bot <id>` starts the bot with it. See [`apps/wb-bot/README.md`](apps/wb-bot/README.md#用-init--doctor-生成和检查配置).
90
+
91
+ 4. **Start the bot**
92
+
93
+ ```bash
94
+ npm run wb-bot:dev
95
+ ```
96
+
97
+ 5. **Verify in Feishu**
98
+
99
+ - DM or mention the bot with `@bot /help`
100
+ - Then send `/list-agents`
101
+ - If you get an agent capability card back, the path is working
102
+
103
+ ### Install from npm
104
+
105
+ You can also install the commands without cloning the repo:
106
+
107
+ ```bash
108
+ npm i -g @zyaochen/weaverbird
109
+ wb-bot init # interactively writes ~/.weaverbird/configs/.env.default
110
+ wb-bot doctor --bot default # checks config, Feishu credentials, agent commands and data dir
111
+ wb-bot --bot default # start the bot
112
+ ```
113
+
114
+ This installs three commands: `wb-bot` for a single bot, `wb-bot-multi` for several bots, and `wb-cli` for debugging agents locally.
115
+
116
+ Limitations:
117
+
118
+ - Requires Node 22 or later. `better-sqlite3` is a native module and needs its install script; on platforms without a prebuilt binary it must also compile locally. If npm blocks install scripts, reinstall with `npm i -g --allow-scripts=better-sqlite3 @zyaochen/weaverbird`. The native module is tied to the Node major version it was installed with; reinstall after switching Node majors.
119
+ - You create the Feishu app yourself. Scopes and event subscriptions are listed in [`apps/wb-bot/README.md`](apps/wb-bot/README.md); `init` and `doctor` print the same checklist.
120
+ - `claude` or `codex` must already be installed and logged in; wb-bot only drives them.
121
+ - It does not daemonize. Use launchd, systemd or pm2 if you want it to start at boot.
122
+ - This is a personal tool. Config keys and commands may change between versions.
123
+
124
+ ### 30-second local smoke without Feishu credentials
125
+
126
+ ```bash
127
+ npm run dev -- list-agents
128
+ npm run dev -- run "hello"
129
+ ```
130
+
131
+ This only verifies that local `claude` / `codex` commands can run. It does not validate Feishu integration.
132
+
133
+ ### Which guide should I open next?
134
+
135
+ - First single-bot setup: [`apps/wb-bot/README.md`](apps/wb-bot/README.md)
136
+ - Multi-bot / Captain: [`docs/guides/multi-bot-setup.md`](docs/guides/multi-bot-setup.md)
137
+ - Captain sessions / CLI binding: [`docs/guides/captain-setup.md`](docs/guides/captain-setup.md)
138
+ - Reverse channel / `wb-cli attach` / SLA: [`docs/guides/reverse-channel-setup.md`](docs/guides/reverse-channel-setup.md)
139
+ - Run history / `/wb resume --inherit`: [`docs/guides/run-registry-setup.md`](docs/guides/run-registry-setup.md)
140
+ - Audit-pipe supervision: [`docs/guides/audit-pipe-setup.md`](docs/guides/audit-pipe-setup.md)
141
+
142
+ ### When should you go directly to multi-bot?
143
+
144
+ Go straight to [`docs/guides/multi-bot-setup.md`](docs/guides/multi-bot-setup.md) if any of these are true:
145
+
146
+ - You want `@claude` and `@codex` in the same chat
147
+ - You need Captain `/list-bots`, `/status`, `/health`, or `/stop-all`
148
+ - You need the full reverse-@ admin cancel + card `叫停` governance surface
149
+
150
+ ---
151
+
152
+ <a id="first-run-verification"></a>
153
+ ## ✅ First-run Verification
154
+
155
+ For a first successful run, focus on these 4 signals:
156
+
157
+ | Success signal | What you should see |
158
+ |---|---|
159
+ | Dependency install succeeds | `npm install` completes without dependency errors |
160
+ | Startup succeeds | `npm run wb-bot:dev` stays up and does not report missing Lark config |
161
+ | Command surface is ready | `/help` and `/list-agents` respond in Feishu |
162
+ | Card path is ready | A normal request returns an updatable running card |
163
+
164
+ If you are already on the Captain path, also confirm:
165
+
166
+ - `/status` shows per-bot summary lines
167
+ - `/health` shows control-plane health details
168
+ - the running card shows a visible `#shortId`
169
+
170
+ ---
171
+
172
+ <a id="commands--permissions-matrix"></a>
173
+ ## 🧭 Commands & Permissions Matrix
174
+
175
+ > This section only documents **currently implemented** command surfaces. Hidden commands, future-state ideas, and research-only behavior are intentionally excluded.
176
+
177
+ | Entry | Surface | Explicit target | Current gate | Best use |
178
+ |---|---|---|---|---|
179
+ | `/stop` | Control-plane entry for the current bot / current thread | Current active session (or active runs in the current thread) | **Control-plane path**, not W8 admin governance | Stop your own current task |
180
+ | `/stop-all` | Single-bot or Captain control plane | Single-bot: current bot; Captain: all active runs across bots | **Control-plane path**, not `admin_cancel` | Emergency sweep / unified stop |
181
+ | `/cancel <shortId>` | Reverse-@ governance entry | **Visible shortId** | `operator -> admin(owner/group_admin/whitelist) -> deny`; role lookup failure is `fail-closed` | Governed stop-loss on someone else's run |
182
+ | Card `Stop` | Running card | Current card's session | **Operator/self-stop path** | Stop your own current task from the card |
183
+ | Card `叫停` | Running card | **shortId already shown on the card** | Exactly the same path as `/cancel <shortId>`; **visibility != authorization** | One-click stop-loss on someone else's run |
184
+
185
+ ### Operator vs Admin
186
+
187
+ | Role | `/stop` | `/stop-all` | `/cancel <shortId>` | Card `叫停` |
188
+ |---|---:|---:|---:|---:|
189
+ | operator | ✅ main path | ✅ control-plane path | ⛔ does not enter `admin_cancel`; falls back to operator stop path | ✅ but short-circuits back to operator stop path |
190
+ | admin (`owner / group_admin / whitelist`) | ➖ not part of the W8 governance entry | ➖ not part of the W8 governance entry | ✅ governed stop-loss | ✅ same path as `/cancel <shortId>` |
191
+ | ordinary member / non-member | ➖ depends on control-plane context | ➖ depends on control-plane context | ❌ deny | ❌ deny |
192
+
193
+ ### Three governance facts to remember
194
+
195
+ 1. **Visibility != authorization**: seeing the `叫停` button does not mean the request will be allowed.
196
+ 2. **shortId is the only explicit target**: no “stop the latest active task” guessing.
197
+ 3. **operator does not enter `admin_cancel` audit**: for operators, card `叫停` is only a GUI shortcut to the existing stop path.
198
+
199
+ ---
200
+
201
+ <a id="config"></a>
202
+ ## ⚙️ Config
203
+
204
+ > **Rules first**: this README only explains the key variables that matter for first success and governance safety. Advanced provider / wrapper / debug variables are documented in [`apps/wb-bot/.env.example`](apps/wb-bot/.env.example).
205
+ > All example values must remain **placeholders**. Do not put real secrets, real open_ids, or real allowlists in docs.
206
+
207
+ ### First-run config table
208
+
209
+ | Variable | Required | Safe default | If wrong, you'll see |
210
+ |---|---|---|---|
211
+ | `LARK_APP_ID` | yes | no default | the bot cannot start or connect to Lark |
212
+ | `LARK_APP_SECRET` | yes | no default | the bot cannot start or connect to Lark |
213
+ | `LARK_ENCRYPT_KEY` | only if enabled in Lark | empty | callback validation fails if Feishu-side encryption is enabled but this is missing |
214
+ | `LARK_VERIFICATION_TOKEN` | only if enabled in Lark | empty | same as above |
215
+ | `WB_DATA_DIR` | no | `~/.weaverbird` | runtime data lands in an unexpected location, or multiple environments mix together |
216
+ | `WB_DEFAULT_CWD` | no | empty | first message without explicit `/cwd` may be rejected as disallowed cwd |
217
+ | `WB_REVERSE_AT_ADMIN_OPEN_IDS` | no | **empty = empty set = no extra admin grant** | a wrong value may grant admin authority to the wrong people |
218
+ | `WB_CLAUDE_COMMAND` | only if you use a wrapper | `claude` | `claude` is unavailable, wrapper hangs, or model selection behaves unexpectedly |
219
+ | `WB_CODEX_COMMAND` | only if you use a wrapper | `codex` | `codex` is unavailable or wrapper args do not match |
220
+ | `WB_CLAUDE_CONSENT_LEVEL` | no | `auto` | no-TTY behavior differs from your interactive local CLI expectation |
221
+
222
+ ### Key security defaults
223
+
224
+ - `WB_REVERSE_AT_ADMIN_OPEN_IDS=` left empty means **no automatic privilege expansion**.
225
+ - Reverse-@ admin lookup is always **fail-closed**: role lookup failure means deny.
226
+ - All keys / tokens / app secrets in `.env.example` must remain placeholders.
227
+
228
+ ### Where to look for advanced options
229
+
230
+ These are still supported, but you should usually only touch them after the basic path is working:
231
+
232
+ - `ANTHROPIC_API_KEY`
233
+ - `OPENAI_API_KEY`
234
+ - `ANTHROPIC_BASE_URL`
235
+ - `OPENAI_BASE_URL`
236
+ - `LOG_LEVEL`
237
+ - `WB_CLAUDE_APPEND_SYSTEM_PROMPT`
238
+
239
+ Authoritative inline comments: [`apps/wb-bot/.env.example`](apps/wb-bot/.env.example)
240
+
241
+ ---
242
+
243
+ <a id="architecture-at-a-glance"></a>
244
+ ## 🏗️ Architecture at a Glance
245
+
246
+ ```mermaid
247
+ flowchart LR
248
+ U[Feishu user] --> B[wb-bot]
249
+ C[CLI user] --> L[wb-cli]
250
+ B --> K[Captain<br/>multi-bot only]
251
+ B --> R[wb-runner]
252
+ L --> P[packages/core]
253
+ K --> P
254
+ R --> P
255
+ P --> A[agent CLI<br/>claude / codex]
256
+ B --> D[SQLite<br/>binding / continuation / inflight]
257
+ R --> F[runs/<botId>/<runId><br/>status · events.ndjson · stop.signal]
258
+ ```
259
+
260
+ This diagram only represents the **current mainline implementation**:
261
+
262
+ - `wb-bot` and `wb-cli` are the two current entry points
263
+ - `Captain` only exists in multi-bot mode
264
+ - `wb-runner` is responsible for detached execution and `stop.signal`
265
+ - run state lives in SQLite and `runs/<botId>/<runId>/`
266
+
267
+ ---
268
+
269
+ <a id="governance-flows"></a>
270
+ ## 🛑 Governance Flows
271
+
272
+ ### Reverse-@ cancel sequence
273
+
274
+ ```mermaid
275
+ sequenceDiagram
276
+ participant User as Admin / Operator
277
+ participant Card as Session Card
278
+ participant EH as event-handler
279
+ participant RH as reverse-at-im-handler
280
+ participant Auth as auth resolver
281
+ participant Stop as stop path
282
+ participant Op as Operator notify
283
+
284
+ User->>Card: /cancel <shortId> or click 叫停
285
+ Card->>EH: shortId / admin_cancel(shortId)
286
+ alt same-session operator
287
+ EH->>Stop: reuse operator stop path
288
+ Stop-->>EH: stopped
289
+ EH-->>Card: Stopped
290
+ else governance path
291
+ EH->>RH: equivalent /cancel <shortId>
292
+ RH->>Auth: operator -> admin -> deny
293
+ alt admin allowed
294
+ RH->>Stop: executeReverseAtCancel
295
+ Stop-->>RH: cancelled / noop_already_ended
296
+ RH-->>Op: notify operator
297
+ RH-->>Card: Stopped / Already ended
298
+ else deny or fail-closed
299
+ RH-->>Card: Not authorized / fail-closed
300
+ end
301
+ end
302
+ ```
303
+
304
+ ### Authorization short-circuit
305
+
306
+ ```mermaid
307
+ flowchart TD
308
+ S[Request: /cancel <shortId> or card 叫停] --> T[Resolve visible shortId]
309
+ T --> O{Operator?}
310
+ O -- Yes --> OP[Operator stop path]
311
+ O -- No --> A{Admin source?}
312
+ A -- owner --> AC[Admin cancel path]
313
+ A -- group_admin --> AC
314
+ A -- whitelist --> AC
315
+ A -- lookup error --> FC[Deny<br/>fail-closed]
316
+ A -- no match --> DN[Deny<br/>not authorized]
317
+ AC --> AU[admin_cancel audit<br/>actor_role = owner / group_admin / whitelist]
318
+ ```
319
+
320
+ ### What is intentionally NOT on this governance path
321
+
322
+ - `passport role`: **NO-GO** (W10 research)
323
+ - `takeover`: **out of scope**
324
+ - implicit “stop the latest active run” targets: **out of scope**
325
+
326
+ ---
327
+
328
+ <a id="troubleshooting"></a>
329
+ ## 🧯 Troubleshooting
330
+
331
+ | Symptom / Error | Likely cause | What to do |
332
+ |---|---|---|
333
+ | `npm run wb-bot:dev` starts but Feishu never responds | the Feishu app is not using long connection mode, did not subscribe to `im.message.receive_v1` / `card.action.trigger`, or is missing required scopes | go back to [`apps/wb-bot/README.md`](apps/wb-bot/README.md) and verify the Feishu setup step by step |
334
+ | `claude: command not found` / `codex: command not found` | the local CLI is not installed, or the wrapper command name is wrong | first confirm `claude --version` / `codex --version`; if you use a wrapper, check `WB_CLAUDE_COMMAND` / `WB_CODEX_COMMAND` |
335
+ | you do not know where to start and suspect multiple components are failing together | the control plane now splits health into WSClient / SQLite / disk / audit-pipe / Run Registry / Captain Sessions / Captain Queue / Reverse Channel | run `/health` first, then branch into [`docs/guides/audit-pipe-setup.md`](docs/guides/audit-pipe-setup.md), [`docs/guides/run-registry-setup.md`](docs/guides/run-registry-setup.md), [`docs/guides/captain-setup.md`](docs/guides/captain-setup.md), or [`docs/guides/reverse-channel-setup.md`](docs/guides/reverse-channel-setup.md) based on the failing line |
336
+ | `/cancel <shortId>` or card `叫停` says the target cannot be found | the shortId is stale, the card is old, or the run already ended | re-check the `#shortId` shown on the running card; do not guess the latest active task |
337
+ | clicking `叫停` returns not authorized | you are neither the operator nor `owner / group_admin / whitelist`; or group-role lookup failed | confirm the current group role first; if lookup failed, the system denies by **fail-closed** |
338
+ | the running card does not show `叫停` | you are not on the matching governance surface, the session is not running, or the card has no shortId | first confirm this is a running session card, then confirm you are on a supported governance path |
339
+ | `strict` consent does not behave like your local CLI | `wb-bot` is a no-TTY backend process and will not show an interactive permission UI | use the no-TTY backend semantics described in this README, not the interactive local CLI mental model |
340
+ | multi-bot discovery returns 0 or `BOT_ID mismatch` | `.env.<botId>` filename and `BOT_ID=` inside do not match, or the file is in the wrong directory | see [`docs/guides/multi-bot-setup.md`](docs/guides/multi-bot-setup.md) for naming and directory rules |
341
+
342
+ ---
343
+
344
+ <a id="faq"></a>
345
+ ## ❓ FAQ
346
+
347
+ ### Should I start with single-bot or multi-bot?
348
+
349
+ - If you only want the shortest path to first success: **single-bot**
350
+ - If you need Captain, `/stop-all`, cross-bot visibility, reverse-@ admin cancel, or card `叫停`: **multi-bot**
351
+
352
+ ### What is the difference between `/stop` and `/cancel <shortId>`?
353
+
354
+ - `/stop`: the control-plane stop path for the current bot / current context
355
+ - `/cancel <shortId>`: the W8/W11 **admin-governed stop-loss path**, which requires an explicit shortId, fail-closed auth, and auditability
356
+
357
+ ### Why doesn't card `叫停` always work just because I can see it?
358
+
359
+ Because **visibility != authorization**. The button is only a GUI entry. Clicking it still goes through the same W8 auth chain: `operator -> admin -> deny`.
360
+
361
+ ### Why does this README explicitly say `passport role` is a NO-GO?
362
+
363
+ Because the W10 conclusion is already closed: it is not a drop-in replacement for the current W8/W11 chat-governance authority source.
364
+
365
+ ### Is `takeover` supported?
366
+
367
+ No. Current admin authority is limited to stop-loss, not becoming a second operator.
368
+
369
+ ### Has card `叫停` been validated end to end in real Feishu yet?
370
+
371
+ This README only promises **implemented code / test-surface behavior**. Real IM / real group-role / real card-button end-to-end validation is still treated as **pending manual verification**.
372
+
373
+ ---
374
+
375
+ <a id="deep-dives"></a>
376
+ ## 📖 Deep Dives
377
+
378
+ ### Open these first (new users / operators)
379
+
380
+ - Single-bot shortest path: [`apps/wb-bot/README.md`](apps/wb-bot/README.md)
381
+ - Multi-bot deployment: [`docs/guides/multi-bot-setup.md`](docs/guides/multi-bot-setup.md)
382
+ - Captain sessions / CLI binding: [`docs/guides/captain-setup.md`](docs/guides/captain-setup.md)
383
+ - Reverse channel / `wb-cli attach` / SLA: [`docs/guides/reverse-channel-setup.md`](docs/guides/reverse-channel-setup.md)
384
+ - Run registry / history / inherit-resume: [`docs/guides/run-registry-setup.md`](docs/guides/run-registry-setup.md)
385
+ - Audit-pipe launchctl supervision: [`docs/guides/audit-pipe-setup.md`](docs/guides/audit-pipe-setup.md)
386
+ - key file: `scripts/com.weaverbird.audit-pipe.plist.template`
387
+ - key outputs: `logs/_audit-pipe`, `audit-mirror.ndjson`
388
+ - common check: `launchctl list | grep weaverbird`
389
+ - Local hourly review mechanism: [`docs/guides/hourly-review-system.md`](docs/guides/hourly-review-system.md)
390
+
391
+ ### Then these (governance / architecture)
392
+
393
+ - Product boundary: [`docs/product-strategy.md`](docs/product-strategy.md)
394
+ - Current mainline abstraction: [`docs/topics/agent-adapter.md`](docs/topics/agent-adapter.md)
395
+
396
+ ---
397
+
398
+ <a id="security--non-goals"></a>
399
+ ## 🔐 Security & Non-goals
400
+
401
+ ### Security defaults
402
+
403
+ - All `.env` / `.env.example` values in docs must remain **placeholders**
404
+ - `WB_REVERSE_AT_ADMIN_OPEN_IDS=` left empty is the safe default; it does not auto-grant admin authority
405
+ - Reverse-@ group-role lookup is always **fail-closed** on lookup failure
406
+ - Do not put real tokens, real open_ids, or real allowlists into README / `.env.example` / `CHANGELOG.md`
407
+
408
+ ### Non-goals
409
+
410
+ - `passport role` as the authority source: **NO-GO**
411
+ - `takeover`: **out of scope**
412
+ - implicit “stop the latest active task” targets: **out of scope**
413
+ - turning Weaverbird into an external SDK / framework: **out of scope**
414
+ - claiming real IM / real group / real button E2E as completed: **out of scope**
415
+
416
+ ## License
417
+
418
+ MIT, see [LICENSE](LICENSE).