@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
@@ -0,0 +1,328 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { existsSync, readFileSync, readdirSync, statfsSync, statSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { auditMirrorPath, auditWalDir, captainQueuePath, captainSessionsWalDir, captainSocketPath, captainStatePath, runRegistryWalDir, runsRootDir, } from '../../../../packages/core/src/paths.js';
6
+ import { loadRunRegistryConfig } from '../../../../packages/core/src/run-registry/config.js';
7
+ import { loadAuditPipeConfig } from '../../../../packages/core/src/audit-pipe/config.js';
8
+ import { createCaptainSessionStore } from '../../../../packages/core/src/captain/index.js';
9
+ import { createConcurrencyQueueIndex } from '../../../../packages/core/src/captain/concurrency-queue-index.js';
10
+ import { loadConcurrencyConfig } from '../../../../packages/core/src/captain/concurrency-config.js';
11
+ import { RUN_REGISTRY_ERROR_CODES } from '../../../../packages/core/src/run-registry/contracts.js';
12
+ import { CAPTAIN_ERROR_CODES } from '../../../../packages/core/src/captain/contracts.js';
13
+ import { readNdjsonSegments } from '../../../../packages/core/src/util/ndjson-rotation.js';
14
+ const WS_STALE_THRESHOLD_MS = 60_000;
15
+ const DISK_WARN_THRESHOLD_BYTES = 1024 * 1024 * 1024;
16
+ const CROSS_BOT_HB_STALE_MS = 30_000;
17
+ const AUDIT_MIRROR_STALE_MS = Number(process.env['WB_AUDIT_MIRROR_STALE_MS'] ?? 240_000);
18
+ const AUDIT_WAL_WARN_THRESHOLD = Number(process.env['WB_AUDIT_WAL_WARN_THRESHOLD'] ?? 100);
19
+ const RUN_REGISTRY_WAL_WARN_THRESHOLD = Number(process.env['WB_RUN_REGISTRY_WAL_WARN_THRESHOLD'] ?? 100);
20
+ const CAPTAIN_SESSIONS_WAL_WARN_THRESHOLD = Number(process.env['WB_CAPTAIN_SESSIONS_WAL_WARN_THRESHOLD'] ?? 100);
21
+ function formatAgo(at) {
22
+ return `${Math.floor((Date.now() - at) / 1000)}s 前`;
23
+ }
24
+ function checkWsClient(cp) {
25
+ const snap = cp.wsClientStatus();
26
+ if (snap.state) {
27
+ // 有连接状态时以它为准: 没人发消息时 "最近事件" 自然会很久, 不代表连接有问题.
28
+ const lastEvent = snap.lastEventAt === null ? '尚未收到事件' : `最近事件 ${formatAgo(snap.lastEventAt)}`;
29
+ const reconnect = snap.lastReconnectAt ? ` · 最近重连 ${formatAgo(snap.lastReconnectAt)}` : '';
30
+ const forced = snap.forcedReconnects ? ` · 保活重建 ${snap.forcedReconnects} 次` : '';
31
+ const detail = `${snap.state} · ${lastEvent}${reconnect}${forced}`;
32
+ if (snap.state === 'connected')
33
+ return { status: 'ok', label: 'WSClient', detail: `连接正常 (${detail})` };
34
+ return { status: snap.state === 'failed' ? 'error' : 'warn', label: 'WSClient', detail };
35
+ }
36
+ if (snap.lastEventAt === null) {
37
+ return { status: 'warn', label: 'WSClient', detail: '尚未收到任何事件 (服务启动后无消息)' };
38
+ }
39
+ const age = Date.now() - snap.lastEventAt;
40
+ const ageS = Math.floor(age / 1000);
41
+ if (age < WS_STALE_THRESHOLD_MS) {
42
+ return { status: 'ok', label: 'WSClient', detail: `连接正常, 最近事件 ${ageS}s 前` };
43
+ }
44
+ return { status: 'warn', label: 'WSClient', detail: `最近事件 ${ageS}s 前 (> ${Math.floor(WS_STALE_THRESHOLD_MS / 1000)}s)` };
45
+ }
46
+ function checkSqlite(store) {
47
+ if (store.isReadOnly) {
48
+ return { status: 'error', label: 'SQLite', detail: '数据库为只读模式 (migration 失败)' };
49
+ }
50
+ const result = store.quickCheck();
51
+ if (result.ok) {
52
+ return { status: 'ok', label: 'SQLite', detail: '可写 · quick_check ok' };
53
+ }
54
+ return { status: 'error', label: 'SQLite', detail: `quick_check 异常: ${result.error ?? 'unknown'}` };
55
+ }
56
+ function checkDisk(cp) {
57
+ const runsDir = runsRootDir(cp.dataDir);
58
+ if (!existsSync(runsDir)) {
59
+ return { status: 'warn', label: '磁盘', detail: `runs/ 目录不存在 (${runsDir})` };
60
+ }
61
+ try {
62
+ const stats = statfsSync(runsDir);
63
+ const available = Number(stats.bavail) * Number(stats.bsize);
64
+ const availableGb = (available / (1024 * 1024 * 1024)).toFixed(1);
65
+ if (available < DISK_WARN_THRESHOLD_BYTES) {
66
+ return { status: 'warn', label: '磁盘', detail: `runs/ 可用 ${availableGb}GB (低空间, <1GB)` };
67
+ }
68
+ return { status: 'ok', label: '磁盘', detail: `runs/ 可用 ${availableGb}GB` };
69
+ }
70
+ catch (err) {
71
+ return { status: 'warn', label: '磁盘', detail: `statfs 失败: ${err instanceof Error ? err.message : String(err)}` };
72
+ }
73
+ }
74
+ function emoji(status) {
75
+ return status === 'ok' ? '✅' : status === 'warn' ? '⚠️' : '❌';
76
+ }
77
+ function checkCrossBotHeartbeats(bots, nowFn) {
78
+ const now = (nowFn ?? Date.now)();
79
+ if (bots.length === 0) {
80
+ return { status: 'ok', label: 'Worker 心跳', detail: '无其它 bot (仅 Captain 自己)' };
81
+ }
82
+ const stales = bots.filter((bot) => !bot.online || (bot.lastHeartbeatAt !== null && (now - bot.lastHeartbeatAt) >= CROSS_BOT_HB_STALE_MS));
83
+ if (stales.length === 0) {
84
+ return { status: 'ok', label: 'Worker 心跳', detail: `全部 ${bots.length} 个 bot 心跳新鲜 (< 30s)` };
85
+ }
86
+ const staleNames = stales.map((bot) => {
87
+ if (bot.lastHeartbeatAt === null)
88
+ return `${bot.botId} (无 heartbeat)`;
89
+ const age = Math.floor((now - bot.lastHeartbeatAt) / 1000);
90
+ const ageDisplay = age < 60 ? `${age}s` : age < 3600 ? `${Math.floor(age / 60)}min` : `${Math.floor(age / 3600)}h`;
91
+ return `${bot.botId} (${ageDisplay} 前)`;
92
+ }).join(', ');
93
+ const status = stales.length === bots.length ? 'error' : 'warn';
94
+ return { status, label: 'Worker 心跳', detail: `${stales.length}/${bots.length} bot stale: ${staleNames}` };
95
+ }
96
+ function fmtAge(ageMs) {
97
+ const seconds = Math.floor(ageMs / 1000);
98
+ if (seconds < 60)
99
+ return `${seconds}s`;
100
+ if (seconds < 3600)
101
+ return `${Math.floor(seconds / 60)}min`;
102
+ return `${Math.floor(seconds / 3600)}h`;
103
+ }
104
+ export function checkAuditPipe(dataDir, nowFn, _plistPath) {
105
+ const plistPath = _plistPath ?? join(homedir(), 'Library', 'LaunchAgents', 'com.weaverbird.audit-pipe.plist');
106
+ const staleMs = Number(process.env['WB_AUDIT_MIRROR_STALE_MS'] ?? AUDIT_MIRROR_STALE_MS);
107
+ const walWarnThreshold = Number(process.env['WB_AUDIT_WAL_WARN_THRESHOLD'] ?? AUDIT_WAL_WARN_THRESHOLD);
108
+ try {
109
+ if (!existsSync(plistPath)) {
110
+ return {
111
+ status: 'warn',
112
+ label: 'Audit Pipe',
113
+ detail: '未安装 (可选 · 安装见 docs/guides/audit-pipe-setup.md)',
114
+ };
115
+ }
116
+ const mirrorPath = auditMirrorPath(dataDir);
117
+ const walDir = auditWalDir(dataDir);
118
+ let walCount = 0;
119
+ try {
120
+ walCount = existsSync(walDir)
121
+ ? readdirSync(walDir).filter((file) => file.endsWith('.jsonl')).length
122
+ : 0;
123
+ }
124
+ catch {
125
+ walCount = 0;
126
+ }
127
+ const mirrorLines = readNdjsonSegments(mirrorPath).length;
128
+ if (mirrorLines === 0) {
129
+ const wal = walCount > 0 ? ` · WAL 积压 ${walCount} 条` : '';
130
+ return {
131
+ status: 'warn',
132
+ label: 'Audit Pipe',
133
+ detail: `已安装 · 尚无审计记录 (audit-pipe 是否已运行?)${wal}`,
134
+ };
135
+ }
136
+ const now = (nowFn ?? Date.now)();
137
+ const activeMirrorExists = existsSync(mirrorPath);
138
+ const ageMs = activeMirrorExists ? now - statSync(mirrorPath).mtimeMs : 0;
139
+ if (activeMirrorExists && ageMs >= staleMs) {
140
+ const wal = walCount > 0 ? ` · WAL 积压 ${walCount} 条` : '';
141
+ return {
142
+ status: 'warn',
143
+ label: 'Audit Pipe',
144
+ detail: `已安装 · mirror ${fmtAge(ageMs)} 前 (> ${Math.floor(staleMs / 1000)}s) · 可能未运行${wal}`,
145
+ };
146
+ }
147
+ if (walCount >= walWarnThreshold) {
148
+ return {
149
+ status: 'warn',
150
+ label: 'Audit Pipe',
151
+ detail: `ok (最近 ${fmtAge(ageMs)}) · WAL 积压 ${walCount} 条 (≥ ${walWarnThreshold})`,
152
+ };
153
+ }
154
+ return {
155
+ status: 'ok',
156
+ label: 'Audit Pipe',
157
+ detail: `ok (最近 ${fmtAge(ageMs)} · ${walCount} pending)`,
158
+ };
159
+ }
160
+ catch (err) {
161
+ return {
162
+ status: 'warn',
163
+ label: 'Audit Pipe',
164
+ detail: `检查异常: ${err instanceof Error ? err.message : String(err)}`,
165
+ };
166
+ }
167
+ }
168
+ export function checkRunRegistry(dataDir) {
169
+ const walDir = runRegistryWalDir(dataDir);
170
+ let walCount = 0;
171
+ try {
172
+ walCount = existsSync(walDir)
173
+ ? readdirSync(walDir).filter((file) => file.endsWith('.jsonl')).length
174
+ : 0;
175
+ }
176
+ catch {
177
+ walCount = 0;
178
+ }
179
+ try {
180
+ loadRunRegistryConfig({ env: { WB_DATA_DIR: dataDir } });
181
+ }
182
+ catch (err) {
183
+ if (err instanceof Error && 'code' in err && err.code === RUN_REGISTRY_ERROR_CODES.E_CFG_MISSING) {
184
+ return { status: 'warn', label: 'Run Registry', detail: 'warn (not-configured)' };
185
+ }
186
+ return { status: 'warn', label: 'Run Registry', detail: `warn (config-error: ${err instanceof Error ? err.message : String(err)})` };
187
+ }
188
+ if (walCount >= RUN_REGISTRY_WAL_WARN_THRESHOLD) {
189
+ return { status: 'warn', label: 'Run Registry', detail: `warn (wal_backlog: ${walCount})` };
190
+ }
191
+ return { status: 'ok', label: 'Run Registry', detail: `ok (${walCount} pending)` };
192
+ }
193
+ export function checkCaptainSessions(dataDir) {
194
+ const walDir = captainSessionsWalDir(dataDir);
195
+ const mirrorPath = captainStatePath(dataDir);
196
+ let walCount = 0;
197
+ try {
198
+ walCount = existsSync(walDir)
199
+ ? readdirSync(walDir).filter((file) => file.endsWith('.jsonl')).length
200
+ : 0;
201
+ }
202
+ catch {
203
+ walCount = 0;
204
+ }
205
+ try {
206
+ const store = createCaptainSessionStore({ env: { WB_DATA_DIR: dataDir }, _client: { bitable: { appTableField: { list: async () => ({ code: 0, msg: 'ok', data: { items: [] } }) }, appTableRecord: { search: async () => ({ code: 0, msg: 'ok', data: { items: [] } }), batchCreate: async () => ({ code: 0, msg: 'ok', data: { records: [] } }), batchUpdate: async () => ({ code: 0, msg: 'ok', data: { records: [] } }) } } } });
207
+ void store;
208
+ }
209
+ catch (err) {
210
+ if (err instanceof Error && 'code' in err && err.code === CAPTAIN_ERROR_CODES.E_CONFIG_INCOMPLETE) {
211
+ return { status: 'warn', label: 'Captain Sessions', detail: 'captain not configured' };
212
+ }
213
+ return { status: 'warn', label: 'Captain Sessions', detail: `captain config error: ${err instanceof Error ? err.message : String(err)}` };
214
+ }
215
+ if (walCount > CAPTAIN_SESSIONS_WAL_WARN_THRESHOLD) {
216
+ return { status: 'warn', label: 'Captain Sessions', detail: `WAL backlog: ${walCount}` };
217
+ }
218
+ const mirrorLines = readNdjsonSegments(mirrorPath).length;
219
+ if (mirrorLines > 0) {
220
+ return { status: 'ok', label: 'Captain Sessions', detail: `${mirrorLines} sessions in mirror` };
221
+ }
222
+ return { status: 'ok', label: 'Captain Sessions', detail: `ok (${walCount} pending)` };
223
+ }
224
+ function readQueueEntries(dataDir) {
225
+ const path = captainQueuePath(dataDir);
226
+ const entries = [];
227
+ let parseErrors = 0;
228
+ for (const line of readNdjsonSegments(path)) {
229
+ if (!line.trim())
230
+ continue;
231
+ try {
232
+ entries.push(JSON.parse(line));
233
+ }
234
+ catch {
235
+ parseErrors += 1;
236
+ }
237
+ }
238
+ return { entries, parseErrors };
239
+ }
240
+ function formatCaptainQueueDetail(running, maxRunning, queued, maxQueued, parseErrors = 0) {
241
+ const counts = `running ${running}/${maxRunning} · queued ${queued}/${maxQueued}`;
242
+ if (parseErrors > 0)
243
+ return `queue parse error (${parseErrors} bad lines) · ${counts}`;
244
+ if (running === 0 && queued === 0)
245
+ return `idle · ${counts}`;
246
+ return counts;
247
+ }
248
+ export function checkCaptainQueue(dataDir) {
249
+ const { entries, parseErrors } = readQueueEntries(dataDir);
250
+ const config = loadConcurrencyConfig(dataDir);
251
+ const index = createConcurrencyQueueIndex();
252
+ index.replay(entries);
253
+ const running = index.countRunning();
254
+ const queued = index.countQueued();
255
+ const detail = formatCaptainQueueDetail(running, config.max_concurrent_runs, queued, config.queue_max_depth, parseErrors);
256
+ if (parseErrors > 0) {
257
+ return { status: 'warn', label: 'Captain Queue', detail };
258
+ }
259
+ if (queued >= config.queue_max_depth && config.queue_max_depth >= 0) {
260
+ return { status: 'warn', label: 'Captain Queue', detail };
261
+ }
262
+ return { status: 'ok', label: 'Captain Queue', detail };
263
+ }
264
+ export async function checkReverseChannel(dataDir) {
265
+ const socketPath = captainSocketPath(dataDir);
266
+ if (!existsSync(socketPath)) {
267
+ return { status: 'warn', label: 'Reverse Channel', detail: 'socket missing' };
268
+ }
269
+ const mode = (statSync(socketPath).mode & 0o777).toString(8);
270
+ if (mode !== '600') {
271
+ return { status: 'warn', label: 'Reverse Channel', detail: `socket mode ${mode} != 600` };
272
+ }
273
+ const { IpcClient } = await import('../../../../packages/core/src/reverse-channel/ipc-client.js');
274
+ const client = new IpcClient(socketPath);
275
+ const healthRunId = `health-check-${randomUUID().slice(0, 8)}`;
276
+ const connection = await client.openSession({ runId: healthRunId, pid: process.pid });
277
+ try {
278
+ const pong = await connection.send({ kind: 'ping' }, { timeoutMs: 5_000 });
279
+ if (pong.kind !== 'pong') {
280
+ return { status: 'warn', label: 'Reverse Channel', detail: 'ping failed' };
281
+ }
282
+ return { status: 'ok', label: 'Reverse Channel', detail: 'socket + ping + hello ack ready' };
283
+ }
284
+ catch (err) {
285
+ return { status: 'warn', label: 'Reverse Channel', detail: `ipc_unreachable:${err instanceof Error ? err.message : String(err)}` };
286
+ }
287
+ finally {
288
+ await connection.close();
289
+ }
290
+ }
291
+ function overall(results) {
292
+ if (results.some((r) => r.status === 'error'))
293
+ return 'error';
294
+ if (results.some((r) => r.status === 'warn'))
295
+ return 'warn';
296
+ return 'ok';
297
+ }
298
+ export async function renderHealth(arg1, arg2) {
299
+ const opts = 'cp' in arg1 ? arg1 : { cp: arg1, store: arg2 };
300
+ const results = [
301
+ checkWsClient(opts.cp),
302
+ checkSqlite(opts.store),
303
+ checkDisk(opts.cp),
304
+ ];
305
+ if (opts.bots !== undefined) {
306
+ results.push(checkCrossBotHeartbeats(opts.bots, opts.nowFn));
307
+ }
308
+ results.push(checkAuditPipe(opts.cp.dataDir, opts.nowFn));
309
+ results.push(checkRunRegistry(opts.cp.dataDir));
310
+ results.push(checkCaptainSessions(opts.cp.dataDir));
311
+ results.push(checkCaptainQueue(opts.cp.dataDir));
312
+ results.push(await checkReverseChannel(opts.cp.dataDir));
313
+ const status = overall(results);
314
+ const lines = [];
315
+ const suffix = opts.bots !== undefined ? ' (Captain mode)' : ' (single-bot mode)';
316
+ lines.push(`🩺 Health Check${suffix}`);
317
+ lines.push('─────────────────────────────────────');
318
+ for (const r of results) {
319
+ lines.push(`${emoji(r.status)} ${r.label}: ${r.detail}`);
320
+ }
321
+ lines.push('─────────────────────────────────────');
322
+ const overallText = status === 'ok' ? '✅ 健康' : status === 'warn' ? '⚠️ 部分异常' : '❌ 异常';
323
+ lines.push(`整体: ${overallText}`);
324
+ if (opts.bots === undefined) {
325
+ lines.push('(single-bot 模式: 跨 bot 心跳检查跳过)');
326
+ }
327
+ return lines.join('\n');
328
+ }
@@ -0,0 +1,100 @@
1
+ import { createRunRegistryWriter, RunQuerySchema } from '../../../../packages/core/src/run-registry/index.js';
2
+ function formatHistoryLine(run) {
3
+ const docs = run.produced_doc_urls.slice(0, 3);
4
+ const docSuffix = docs.length > 0 ? `\n docs: ${docs.join(', ')}` : '';
5
+ return `- ${run.run_id} | ${run.created_at} | ${run.cwd} | ${run.status} | ${run.agent}${docSuffix}`;
6
+ }
7
+ function parseHistoryArgs(args) {
8
+ const query = {};
9
+ for (let index = 0; index < args.length; index += 1) {
10
+ const arg = args[index] ?? '';
11
+ const next = args[index + 1];
12
+ if (arg === '--keyword' && next) {
13
+ query['keyword'] = next;
14
+ index += 1;
15
+ continue;
16
+ }
17
+ if (arg === '--operator' && next) {
18
+ query['operator'] = next;
19
+ index += 1;
20
+ continue;
21
+ }
22
+ if (arg === '--project' && next) {
23
+ query['project'] = next;
24
+ index += 1;
25
+ continue;
26
+ }
27
+ if (arg === '--agent' && next) {
28
+ query['agent'] = next;
29
+ index += 1;
30
+ continue;
31
+ }
32
+ if (arg === '--entry-form' && next) {
33
+ query['entry_form'] = next;
34
+ index += 1;
35
+ continue;
36
+ }
37
+ if (arg === '--status' && next) {
38
+ query['status'] = next;
39
+ index += 1;
40
+ continue;
41
+ }
42
+ if (arg === '--after' && next) {
43
+ query['after'] = next;
44
+ index += 1;
45
+ continue;
46
+ }
47
+ if (arg === '--before' && next) {
48
+ query['before'] = next;
49
+ index += 1;
50
+ continue;
51
+ }
52
+ if (arg === '--limit' && next) {
53
+ query['limit'] = Number.parseInt(next, 10);
54
+ index += 1;
55
+ continue;
56
+ }
57
+ if (arg === '--cursor' && next) {
58
+ query['cursor'] = next;
59
+ index += 1;
60
+ }
61
+ }
62
+ return RunQuerySchema.parse(query);
63
+ }
64
+ export function buildBitableFilter(query) {
65
+ const parts = [];
66
+ if (query['operator'])
67
+ parts.push(`CurrentValue.[operator]="${query['operator']}"`);
68
+ if (query['project'])
69
+ parts.push(`CurrentValue.[project]="${query['project']}"`);
70
+ if (query['agent'])
71
+ parts.push(`CurrentValue.[agent]="${query['agent']}"`);
72
+ if (query['entry_form'])
73
+ parts.push(`CurrentValue.[entry_form]="${query['entry_form']}"`);
74
+ if (query['status'])
75
+ parts.push(`CurrentValue.[status]="${query['status']}"`);
76
+ if (query['after'])
77
+ parts.push(`CurrentValue.[created_at]>=${Date.parse(query['after'])}`);
78
+ if (query['before'])
79
+ parts.push(`CurrentValue.[created_at]<=${Date.parse(query['before'])}`);
80
+ if (query['keyword']) {
81
+ parts.push(`OR(CurrentValue.[cwd]~"${query['keyword']}",CurrentValue.[cmd]~"${query['keyword']}",CurrentValue.[project]~"${query['keyword']}")`);
82
+ }
83
+ return parts.length > 0 ? `AND(${parts.join(',')})` : 'ALL()';
84
+ }
85
+ export async function handleHistory(args, _ctx) {
86
+ const query = parseHistoryArgs(args);
87
+ const writer = createRunRegistryWriter();
88
+ const result = await writer.queryRuns(query);
89
+ const lines = ['📚 Run History'];
90
+ if (result.runs.length === 0) {
91
+ lines.push('(no runs)');
92
+ }
93
+ else {
94
+ lines.push(...result.runs.map(formatHistoryLine));
95
+ }
96
+ if (result.next_cursor) {
97
+ lines.push(`next_cursor=${result.next_cursor}`);
98
+ }
99
+ return lines.join('\n');
100
+ }
@@ -0,0 +1,91 @@
1
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
2
+ import { basename, dirname, join } from 'node:path';
3
+ const DEFAULT_TAIL = 50;
4
+ const MAX_TAIL = 500;
5
+ /**
6
+ * Resolve the current log file. pino-roll appends a rotation number suffix
7
+ * (e.g. "wb-bot.log.1") so the configured logFilePath may not exist directly.
8
+ * Fall back to the most-recently-modified file matching "<basename>.*" in
9
+ * the same directory.
10
+ */
11
+ function resolveCurrentLogFile(basePath) {
12
+ if (existsSync(basePath))
13
+ return basePath;
14
+ const dir = dirname(basePath);
15
+ const base = basename(basePath);
16
+ if (!existsSync(dir))
17
+ return null;
18
+ let entries;
19
+ try {
20
+ entries = readdirSync(dir);
21
+ }
22
+ catch {
23
+ return null;
24
+ }
25
+ const candidates = [];
26
+ for (const entry of entries) {
27
+ if (!entry.startsWith(base))
28
+ continue;
29
+ const candidatePath = join(dir, entry);
30
+ try {
31
+ candidates.push({ path: candidatePath, mtime: statSync(candidatePath).mtimeMs });
32
+ }
33
+ catch {
34
+ // skip
35
+ }
36
+ }
37
+ if (candidates.length === 0)
38
+ return null;
39
+ candidates.sort((a, b) => b.mtime - a.mtime);
40
+ return candidates[0]?.path ?? null;
41
+ }
42
+ function parseTail(args) {
43
+ for (const arg of args) {
44
+ if (!arg)
45
+ continue;
46
+ if (arg.startsWith('bot=')) {
47
+ return { tail: DEFAULT_TAIL, rejected: 'single-bot 模式下 /logs 不接 bot=<id> 参数 (启用 multi-bot 后才生效); 直接使用 /logs [tail=N] 即可' };
48
+ }
49
+ if (/^tail=\d+$/.test(arg)) {
50
+ const v = parseInt(arg.slice('tail='.length), 10);
51
+ return { tail: Math.min(MAX_TAIL, Math.max(1, v)), rejected: null };
52
+ }
53
+ if (/^\d+$/.test(arg)) {
54
+ const v = parseInt(arg, 10);
55
+ return { tail: Math.min(MAX_TAIL, Math.max(1, v)), rejected: null };
56
+ }
57
+ return { tail: DEFAULT_TAIL, rejected: `single-bot 模式下 /logs 不接 <botId> 参数 (启用 multi-bot 后才生效); 直接使用 /logs [tail=N] 即可` };
58
+ }
59
+ return { tail: DEFAULT_TAIL, rejected: null };
60
+ }
61
+ function readTail(filePath, tail) {
62
+ if (!existsSync(filePath))
63
+ return [];
64
+ try {
65
+ const content = readFileSync(filePath, 'utf8');
66
+ const lines = content.split('\n');
67
+ while (lines.length > 0 && lines[lines.length - 1] === '')
68
+ lines.pop();
69
+ return lines.slice(-tail);
70
+ }
71
+ catch {
72
+ return [];
73
+ }
74
+ }
75
+ export function renderLogs(args, cp) {
76
+ const { tail, rejected } = parseTail(args);
77
+ if (rejected)
78
+ return `❌ ${rejected}`;
79
+ const actualFile = resolveCurrentLogFile(cp.logFilePath);
80
+ const lines = actualFile ? readTail(actualFile, tail) : [];
81
+ const header = [
82
+ `📋 logs/${cp.botId}/wb-bot.log (tail ${tail}, single-bot mode)`,
83
+ '─────────────────────────────────────',
84
+ ];
85
+ const body = lines.length === 0 ? ['(no log lines; file is empty or not yet created)'] : lines;
86
+ const footer = [
87
+ '─────────────────────────────────────',
88
+ `(file: ${actualFile ?? cp.logFilePath})`,
89
+ ];
90
+ return [...header, ...body, ...footer].join('\n');
91
+ }
@@ -0,0 +1,43 @@
1
+ export function parseCommand(input) {
2
+ const tokens = [];
3
+ let current = '';
4
+ let quote = null;
5
+ for (let index = 0; index < input.length; index += 1) {
6
+ const char = input[index] ?? '';
7
+ if (quote === 'single') {
8
+ if (char === "'")
9
+ quote = null;
10
+ else
11
+ current += char;
12
+ continue;
13
+ }
14
+ if (quote === 'double') {
15
+ if (char === '"')
16
+ quote = null;
17
+ else
18
+ current += char;
19
+ continue;
20
+ }
21
+ if (char === "'") {
22
+ quote = 'single';
23
+ continue;
24
+ }
25
+ if (char === '"') {
26
+ quote = 'double';
27
+ continue;
28
+ }
29
+ if (/\s/.test(char)) {
30
+ if (current) {
31
+ tokens.push(current);
32
+ current = '';
33
+ }
34
+ continue;
35
+ }
36
+ current += char;
37
+ }
38
+ if (quote)
39
+ throw new Error('unterminated quote');
40
+ if (current)
41
+ tokens.push(current);
42
+ return tokens;
43
+ }
@@ -0,0 +1,24 @@
1
+ function metricValue(value) {
2
+ return Number.isFinite(value) ? String(value) : '0';
3
+ }
4
+ export function renderQueueMetrics(snapshot) {
5
+ const running = snapshot.gauges.captain_queue_running_total;
6
+ const queued = snapshot.gauges.captain_queue_depth;
7
+ const decisionsTotal = snapshot.counters.captain_queue_decisions_total;
8
+ const promotedTotal = snapshot.counters.captain_queue_promotions_total;
9
+ const preemptedTotal = snapshot.counters.captain_queue_preempted_runs_total;
10
+ const cancelledTotal = snapshot.counters.captain_queue_cancelled_runs_total;
11
+ const waitP50 = snapshot.histograms.captain_queue_wait_duration_seconds?.p50;
12
+ const waitP95 = snapshot.histograms.captain_queue_wait_duration_seconds?.p95;
13
+ return [
14
+ 'Queue Metrics (session)',
15
+ `- running: ${metricValue(running)}`,
16
+ `- queued: ${metricValue(queued)}`,
17
+ `- decisions_total: ${metricValue(decisionsTotal)}`,
18
+ `- promoted_total: ${metricValue(promotedTotal)}`,
19
+ `- preempted_total: ${metricValue(preemptedTotal)}`,
20
+ `- cancelled_total: ${metricValue(cancelledTotal)}`,
21
+ `- wait_p50_s: ${metricValue(waitP50)}`,
22
+ `- wait_p95_s: ${metricValue(waitP95)}`,
23
+ ].join('\n');
24
+ }
@@ -0,0 +1,48 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { createRunRegistryWriter, RUN_REGISTRY_ERROR_CODES, RunRegistryError } from '../../../../packages/core/src/run-registry/index.js';
3
+ const INHERIT_FIELDS = ['project', 'cwd', 'scope', 'agent', 'home_group_id', 'entry_form'];
4
+ function makeNewRunId() {
5
+ return randomUUID();
6
+ }
7
+ export function buildInheritedRun(fromRun, newRunId = makeNewRunId()) {
8
+ return {
9
+ fromRunId: fromRun.run_id,
10
+ newRunId,
11
+ inherited: {
12
+ project: fromRun.project,
13
+ cwd: fromRun.cwd,
14
+ scope: fromRun.scope,
15
+ agent: fromRun.agent,
16
+ home_group_id: fromRun.home_group_id,
17
+ entry_form: fromRun.entry_form,
18
+ },
19
+ excluded: {
20
+ risk_level: 'unknown',
21
+ cost_tokens: null,
22
+ cost_minutes: null,
23
+ produced_doc_urls: [],
24
+ commit_shas: [],
25
+ },
26
+ };
27
+ }
28
+ export async function handleResume(args, ctx) {
29
+ if (args[0] !== 'resume' || args[1] !== '--inherit' || !args[2]) {
30
+ return 'Usage: /wb resume --inherit <run_id>';
31
+ }
32
+ const runId = args[2];
33
+ const writer = createRunRegistryWriter();
34
+ const fromRun = await writer.findByRunId(runId);
35
+ if (!fromRun) {
36
+ throw new RunRegistryError(RUN_REGISTRY_ERROR_CODES.E_INHERIT_NOT_FOUND, `run ${runId} not found in registry`);
37
+ }
38
+ const inherited = buildInheritedRun(fromRun);
39
+ ctx.store.setCurrentAgent(ctx.botId, ctx.userOpenId, ctx.threadId, inherited.inherited.agent ?? 'claude-code');
40
+ ctx.store.setCurrentCwd(ctx.botId, ctx.userOpenId, ctx.threadId, inherited.inherited.cwd);
41
+ return [
42
+ `♻️ Inherited run ${runId}`,
43
+ `new_run_id=${inherited.newRunId}`,
44
+ `agent=${inherited.inherited.agent}`,
45
+ `cwd=${inherited.inherited.cwd}`,
46
+ `scope=${inherited.inherited.scope}`,
47
+ ].join('\n');
48
+ }