@allbluecn/collab-server 0.0.0-stage → 0.1.6

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 (39) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +126 -2
  3. package/package.json +64 -3
  4. package/src/__tests__/clients.test.ts +93 -0
  5. package/src/__tests__/embed.test.ts +227 -0
  6. package/src/__tests__/env-setup.ts +33 -0
  7. package/src/__tests__/exporters-bug.test.ts +552 -0
  8. package/src/__tests__/exporters-case.test.ts +356 -0
  9. package/src/__tests__/exporters-design.test.ts +356 -0
  10. package/src/__tests__/exporters-knowledge.test.ts +366 -0
  11. package/src/__tests__/exporters-stats.test.ts +105 -0
  12. package/src/__tests__/exporters-story.test.ts +519 -0
  13. package/src/__tests__/internal-apply-channel.test.ts +233 -0
  14. package/src/__tests__/internal-apply-race.test.ts +165 -0
  15. package/src/__tests__/internal-apply.test.ts +418 -0
  16. package/src/__tests__/multiplex.test.ts +166 -0
  17. package/src/__tests__/persistence-retry.test.ts +262 -0
  18. package/src/__tests__/persistence.test.ts +302 -0
  19. package/src/__tests__/server.test.ts +145 -0
  20. package/src/__tests__/share-room-limit.test.ts +183 -0
  21. package/src/__tests__/shutdown.test.ts +130 -0
  22. package/src/__tests__/test-utils.ts +176 -0
  23. package/src/auth.ts +84 -0
  24. package/src/clients.ts +133 -0
  25. package/src/embed.ts +156 -0
  26. package/src/exporters/bug.ts +454 -0
  27. package/src/exporters/case.ts +317 -0
  28. package/src/exporters/design.ts +268 -0
  29. package/src/exporters/entity-shared.ts +75 -0
  30. package/src/exporters/knowledge.ts +259 -0
  31. package/src/exporters/story.ts +483 -0
  32. package/src/exporters.ts +173 -0
  33. package/src/index.ts +354 -0
  34. package/src/internal-apply-limit.ts +99 -0
  35. package/src/internal-apply.ts +888 -0
  36. package/src/metrics.ts +82 -0
  37. package/src/persistence.ts +409 -0
  38. package/src/rooms.ts +32 -0
  39. package/src/share-room-limit.ts +73 -0
@@ -0,0 +1,454 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // AllBlue - 理想之海
3
+ // Copyright (C) 2026 AllBlue Contributors
4
+ //
5
+ // This program is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU Affero General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU Affero General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU Affero General Public License
16
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ // Bug 回写导出器(Yjs 多人协作 §5.2 回写 / §7.1 entity:bug 行 / §10.2,任务 22,
19
+ // 与 exporters/story.ts 同构——复制适配,exporter 纪律逐条继承):
20
+ //
21
+ // Y 属主面 = description fragment + fields Y.Map + steps Y.Array:
22
+ // - description(Text 列 {html, markdown} JSON 串,与 Story.description 同构
23
+ // → parseStoryDescription/isEmptyEditorHtml 复用)。S12 裁决:UI 本期不接
24
+ // 协同编辑(只读渲染),但 room 结构自然预留——种子化/门卫转发/exporter
25
+ // 回写全链路照常(旁路写经 §5.3 门卫进 Y,Y 是权威)。
26
+ // - 6 字段:title/state/severity/assigneeId/labelIds/env(与 web 写端
27
+ // BUG_COLLAB_FIELDS 一致;storyId 不入 Y——关联需求走独立 serverFn,DB
28
+ // 单一事实源无互吞面)。
29
+ // - steps:reproduceSteps.steps 列表(order 不入 Y,落库按索引+1 归一;
30
+ // expectedResult/actualResult 不归 Y——exporter 从业务列保留原值,旁路
31
+ // steps patch 只拥有 steps 列表)。
32
+ // - 空 Y.Array steps = Y 无意见 → 不触碰业务列(业务 schema 步骤 min(1),
33
+ // 空集永不合法;collab-core/steps readStepsFromDoc 同口径)。防「DB 有
34
+ // steps 但 Y 从未写过」的 room 被 store 清空步骤。
35
+ //
36
+ // Bug 无 version 列(TestCase 独有)——「协同落库 version+1」仅 case 导出器
37
+ // 承担。活动:BugActivity 有 actorType 字段(schema 已核),协同活动用
38
+ // "collab" 值 + 归属作者 userId + changedFields 流水;机器身份 actor
39
+ // (`sdk:`/`agent:` 前缀,任务 23)保留 actorType=sdk|agent + userId null。
40
+ //
41
+ // 挂载模式 / 幽灵防御 / touch 快照(锚点 M②)/ FK 防御:逐条同 story.ts。
42
+
43
+ import type { CollabRoomName } from "@allbluecn/collab-core/rooms";
44
+ import { buildRoomName } from "@allbluecn/collab-core/rooms";
45
+ import { parseMachineActor } from "@allbluecn/collab-core/actors";
46
+ import { readStepsFromDoc, type CollabStep } from "@allbluecn/collab-core/steps";
47
+ import type * as Y from "yjs";
48
+ import {
49
+ computeAuthorAttribution,
50
+ registerExporter,
51
+ registerRoomGuard,
52
+ type CollabAuthorStat,
53
+ } from "../exporters";
54
+ import { ensureServerDom } from "./knowledge";
55
+ import {
56
+ isEmptyEditorHtml,
57
+ parseStoryDescription,
58
+ storyDocExtensions,
59
+ } from "./story";
60
+ import {
61
+ COLLAB_FIELDS_MAP_KEY,
62
+ normalizeRowSteps,
63
+ stepsEqual,
64
+ stepsWithOrder,
65
+ type StoryTx,
66
+ } from "./entity-shared";
67
+
68
+ /** 协同字段清单(web 写端 BUG_COLLAB_FIELDS 的镜像,两侧必须同步维护) */
69
+ // 枚举白名单(web shared/bug/constants.ts 镜像,apps 不互 import——变更需双侧同步)
70
+ const COLLAB_BUG_STATE_VALUES = new Set(["open", "in_progress", "fixed", "closed", "wontfix"]);
71
+ const COLLAB_BUG_SEVERITY_VALUES = new Set(["critical", "high", "medium", "low"]);
72
+
73
+ export const COLLAB_BUG_FIELDS = [
74
+ "title",
75
+ "state",
76
+ "severity",
77
+ "assigneeId",
78
+ "labelIds",
79
+ "env",
80
+ ] as const;
81
+
82
+ export type CollabBugField = (typeof COLLAB_BUG_FIELDS)[number];
83
+
84
+ /** 字段 patch(只含出现的 key;undefined key = Y 无意见不触碰) */
85
+ export type BugFieldsPatch = Partial<Record<CollabBugField, unknown>>;
86
+
87
+ /** 协同活动动作名(与 story 导出器 COLLAB_STORY_UPDATE_ACTION 同名口径) */
88
+ export const COLLAB_BUG_UPDATE_ACTION = "collab_update";
89
+
90
+ /** 机器/旁路写入的活动语义 hint:internal-apply live 路径入队、onStoreDocument
91
+ * 落库时出队写语义活动行。进程内存态——store 前 crash 与 Y 未落库状态同丢,
92
+ * 无孤儿行;单实例边界声明(§12)下无跨进程问题。 */
93
+ export interface BugActivityHint {
94
+ action: string;
95
+ actor: string;
96
+ field?: unknown;
97
+ oldValue?: unknown;
98
+ newValue?: unknown;
99
+ }
100
+ const pendingActivityHints = new Map<string, BugActivityHint[]>();
101
+
102
+ /**
103
+ * 单 room 待出队 hint 上界(防滞留兜底的兜底):正常口径下 hint 随落库出队
104
+ * (exportBug)、随文档卸载释放(forgetBugActivityHints,persistence 的
105
+ * beforeUnloadDocument 调用);幽灵检出 + 长期无 store 的极端窗口下由本上界
106
+ * 封顶——超限丢弃最旧并 warn 一次,语义活动缺段可接受(快照终态不受影响)。
107
+ */
108
+ export const MAX_PENDING_ACTIVITY_HINTS_PER_ROOM = 100;
109
+
110
+ export function notifyBugActivityHint(roomName: string, hint: BugActivityHint): void {
111
+ const arr = pendingActivityHints.get(roomName) ?? [];
112
+ if (arr.length >= MAX_PENDING_ACTIVITY_HINTS_PER_ROOM) {
113
+ console.warn(
114
+ `[collab-exporters] bug 活动 hint 滞留超上界(${arr.length}),丢弃最旧 room=${roomName}`,
115
+ );
116
+ arr.shift();
117
+ }
118
+ arr.push(hint);
119
+ pendingActivityHints.set(roomName, arr);
120
+ }
121
+ export function drainBugActivityHints(roomName: string): BugActivityHint[] {
122
+ const arr = pendingActivityHints.get(roomName);
123
+ pendingActivityHints.delete(roomName);
124
+ return arr ?? [];
125
+ }
126
+
127
+ /** 释放某 room 的待出队 hint(文档卸载 / 幽灵检出路径调用,防缓慢滞留) */
128
+ export function forgetBugActivityHints(roomName: string): void {
129
+ pendingActivityHints.delete(roomName);
130
+ }
131
+
132
+ /** description + 字段 + steps patch 的统一入参(undefined = 不触碰该面) */
133
+ export interface BugColumnWrite {
134
+ descriptionHtml?: string;
135
+ descriptionMarkdown?: string;
136
+ fields?: BugFieldsPatch;
137
+ /** Y 权威步骤目标态(readStepsFromDoc 产物;undefined = Y 无意见) */
138
+ steps?: CollabStep[];
139
+ /** 活动归属作者(null = 无归属不写活动) */
140
+ actor: string | null;
141
+ activityExtra?: Record<string, unknown>;
142
+ /** 语义活动 action(internal-apply 离线直落透传;缺省 collab_update) */
143
+ activityAction?: string;
144
+ /** 出队 hint 已单独成行时压制本 flush 的机器归属通用行(防重复流水) */
145
+ suppressMachineActivityRow?: boolean;
146
+ /** true(exporter)= 同事务显式 touch CollabDocument.updatedAt(锚点 M②) */
147
+ touchSnapshot: boolean;
148
+ }
149
+
150
+ /**
151
+ * 把「Y/patch 目标态」diff 进 Bug 业务列(单事务内调用):存在性复查 →
152
+ * FK 防御复核 → diff 建数据(无变化即止)→ bug.update → BugActivity
153
+ * (actorType="collab" + 归属作者 + changedFields)→ 可选快照 touch。
154
+ * 供 bug exporter(Y 全量态)与 internal-apply 离线直落(patch 增量)复用。
155
+ */
156
+ export async function writeBugColumns(
157
+ tx: StoryTx,
158
+ opts: { bugId: string; roomName: string } & BugColumnWrite,
159
+ ): Promise<void> {
160
+ const row = await tx.bug.findUnique({
161
+ where: { id: opts.bugId },
162
+ select: {
163
+ title: true,
164
+ state: true,
165
+ severity: true,
166
+ assigneeId: true,
167
+ env: true,
168
+ description: true,
169
+ reproduceSteps: true,
170
+ labels: { select: { labelId: true } },
171
+ },
172
+ });
173
+ // 幽灵兜底(首道防线是 store/load 守卫):实体已删则整体跳过
174
+ if (!row) return;
175
+
176
+ const data: Record<string, unknown> = {};
177
+ const changedFields: string[] = [];
178
+
179
+ // description({html, markdown} JSON 串;空产物 → null)。与 story 同构
180
+ // 复用解析与空产物判定,防空 room 反复 store 产出幻影 diff。
181
+ if (opts.descriptionHtml !== undefined) {
182
+ const html = opts.descriptionHtml;
183
+ const markdown = opts.descriptionMarkdown ?? html;
184
+ const current = parseStoryDescription(row.description);
185
+ const currentEmpty =
186
+ current.html.trim() === "" || isEmptyEditorHtml(current.html);
187
+ const newEmpty = isEmptyEditorHtml(html);
188
+ const changed = newEmpty ? !currentEmpty : current.html !== html;
189
+ if (changed) {
190
+ changedFields.push("description");
191
+ data.description = newEmpty ? null : JSON.stringify({ html, markdown });
192
+ }
193
+ }
194
+
195
+ const fields = opts.fields ?? {};
196
+ const has = (key: CollabBugField) => fields[key] !== undefined;
197
+
198
+ if (has("title")) {
199
+ const title = fields.title;
200
+ if (typeof title === "string" && title.trim() !== "") {
201
+ if (title !== row.title) {
202
+ changedFields.push("title");
203
+ data.title = title;
204
+ }
205
+ } else {
206
+ console.warn(`[collab-exporters] bug 字段 title 非法(${typeof title}),跳过 bugId=${opts.bugId}`);
207
+ }
208
+ }
209
+
210
+ // state/severity 白名单(web BUG_STATES/BUG_SEVERITIES 镜像,apps 不互 import)
211
+ if (has("state") && typeof fields.state === "string" && fields.state !== row.state) {
212
+ if (!COLLAB_BUG_STATE_VALUES.has(fields.state)) {
213
+ console.warn(`[collab-exporters] bug 字段 state 非法(${fields.state}),跳过 bugId=${opts.bugId}`);
214
+ } else {
215
+ changedFields.push("state");
216
+ data.state = fields.state;
217
+ }
218
+ }
219
+ if (has("severity") && typeof fields.severity === "string" && fields.severity !== row.severity) {
220
+ if (!COLLAB_BUG_SEVERITY_VALUES.has(fields.severity)) {
221
+ console.warn(`[collab-exporters] bug 字段 severity 非法(${fields.severity}),跳过 bugId=${opts.bugId}`);
222
+ } else {
223
+ changedFields.push("severity");
224
+ data.severity = fields.severity;
225
+ }
226
+ }
227
+
228
+ // env(可空文本:null = 清空)
229
+ if (has("env")) {
230
+ const env = fields.env;
231
+ if (env !== null && typeof env !== "string") {
232
+ console.warn(`[collab-exporters] bug 字段 env 非法(${typeof env}),跳过 bugId=${opts.bugId}`);
233
+ } else if (env !== row.env) {
234
+ changedFields.push("env");
235
+ data.env = env;
236
+ }
237
+ }
238
+
239
+ // assigneeId(FK 防御;关系形态 connect/disconnect,同 story)
240
+ if (has("assigneeId")) {
241
+ const assigneeId = fields.assigneeId as string | null;
242
+ if (assigneeId !== row.assigneeId) {
243
+ if (assigneeId !== null) {
244
+ const user = await tx.user.findUnique({ where: { id: assigneeId }, select: { id: true } });
245
+ if (!user) {
246
+ console.warn(`[collab-exporters] bug assigneeId 引用不存在(${assigneeId}),跳过 bugId=${opts.bugId}`);
247
+ } else {
248
+ changedFields.push("assigneeId");
249
+ data.assignee = { connect: { id: assigneeId } };
250
+ }
251
+ } else {
252
+ changedFields.push("assigneeId");
253
+ data.assignee = { disconnect: true };
254
+ }
255
+ }
256
+ }
257
+
258
+ // labelIds(BugLabel[] 关系表 diff 同步子行;FK 防御过滤已删标签,同 story)
259
+ if (has("labelIds")) {
260
+ const raw = fields.labelIds;
261
+ if (Array.isArray(raw)) {
262
+ const target = [...new Set(raw.filter((id): id is string => typeof id === "string"))];
263
+ const current = row.labels.map((l) => l.labelId);
264
+ const sameSet =
265
+ target.length === current.length && target.every((id) => current.includes(id));
266
+ if (!sameSet) {
267
+ const existing = await tx.label.findMany({
268
+ where: { id: { in: target } },
269
+ select: { id: true },
270
+ });
271
+ const valid = new Set(existing.map((l) => l.id));
272
+ const missing = target.filter((id) => !valid.has(id));
273
+ if (missing.length > 0) {
274
+ console.warn(
275
+ `[collab-exporters] bug labelIds 引用不存在的标签(${missing.join(",")}),已过滤 bugId=${opts.bugId}`,
276
+ );
277
+ }
278
+ const toCreate = target.filter((id) => valid.has(id) && !current.includes(id));
279
+ const toDelete = current.filter((id) => !target.includes(id));
280
+ if (toCreate.length > 0 || toDelete.length > 0) {
281
+ changedFields.push("labelIds");
282
+ data.labels = {
283
+ ...(toDelete.length > 0 && { deleteMany: { labelId: { in: toDelete } } }),
284
+ ...(toCreate.length > 0 && { create: toCreate.map((labelId) => ({ labelId })) }),
285
+ };
286
+ }
287
+ }
288
+ } else {
289
+ console.warn(`[collab-exporters] bug 字段 labelIds 非数组,跳过 bugId=${opts.bugId}`);
290
+ }
291
+ }
292
+
293
+ // steps(空 Y.Array = 无意见不触碰——readStepsFromDoc 已滤;diff 逐位比较,
294
+ // expectedResult/actualResult 从业务列保留:旁路 patch 只拥有 steps 列表)
295
+ if (opts.steps !== undefined) {
296
+ const rowSteps = normalizeRowSteps(row.reproduceSteps) ?? [];
297
+ if (!stepsEqual(rowSteps, opts.steps)) {
298
+ changedFields.push("steps");
299
+ const extras =
300
+ typeof row.reproduceSteps === "object" && row.reproduceSteps !== null
301
+ ? (row.reproduceSteps as Record<string, unknown>)
302
+ : {};
303
+ data.reproduceSteps = {
304
+ ...extras,
305
+ steps: stepsWithOrder(opts.steps),
306
+ };
307
+ }
308
+ }
309
+
310
+ // 无 diff 即止:不 bump updatedAt(避免无谓的重种子化判定输入)
311
+ if (changedFields.length === 0) return;
312
+
313
+ const updated = await tx.bug.update({
314
+ where: { id: opts.bugId },
315
+ data,
316
+ select: { updatedAt: true },
317
+ });
318
+
319
+ // §10.2 活动:BugActivity 有 actorType 字段(schema 已核)——协同活动直接
320
+ // 用 "collab" 值 + 归属作者 userId + changedFields 流水;actor null 不写。
321
+ // 机器身份 actor(任务 23,§5.3:`sdk:<source>` / `agent:<name>`,经门卫
322
+ // payload.actor → 系统 client → authorStats/直落透传到此)→ actorType 保留
323
+ // sdk|agent(非 collab)+ userId 置 null(机器写入无登录用户,schema 口径;
324
+ // 写用户 id 会撞 FK)+ agent 的 agentName 标识;metadata.source 记实际来源
325
+ // 类型(替代固定 "collab")。
326
+ if (opts.actor) {
327
+ const machine = parseMachineActor(opts.actor);
328
+ // 机器归属且 hint 行已单独成行(registerBugCollab 出队)时压制通用行防重复流水
329
+ if (!(machine && opts.suppressMachineActivityRow)) {
330
+ await tx.bugActivity.create({
331
+ data: {
332
+ bugId: opts.bugId,
333
+ userId: machine ? null : opts.actor,
334
+ actorType: machine ? machine.type : "collab",
335
+ ...(machine?.type === "agent" && machine.name && { agentName: machine.name }),
336
+ action: opts.activityAction ?? COLLAB_BUG_UPDATE_ACTION,
337
+ metadata: {
338
+ source: machine ? machine.type : "collab",
339
+ summary: "更新了 BUG",
340
+ changedFields,
341
+ ...(opts.activityExtra ?? {}),
342
+ },
343
+ },
344
+ });
345
+ }
346
+ }
347
+
348
+ // 锚点 M②:同事务显式 touch 快照 updatedAt = bug 回读值(语义同 story
349
+ // 导出器——快照行尚不存在时 updateMany 计 0 跳过,随后快照 upsert 天然 ≥)
350
+ if (opts.touchSnapshot) {
351
+ await tx.collabDocument.updateMany({
352
+ where: { roomName: opts.roomName },
353
+ data: { updatedAt: updated.updatedAt },
354
+ });
355
+ }
356
+ }
357
+
358
+ // ── 导出器主体 ────────────────────────────────────────────────────────
359
+
360
+ /** 从 Y.Doc 读取 6 字段 patch(只收 COLLAB_BUG_FIELDS 内出现的 key) */
361
+ export function readBugFieldsPatch(doc: Y.Doc): BugFieldsPatch {
362
+ const map = doc.getMap<unknown>(COLLAB_FIELDS_MAP_KEY);
363
+ const patch: BugFieldsPatch = {};
364
+ for (const key of COLLAB_BUG_FIELDS) {
365
+ const value = map.get(key);
366
+ if (value !== undefined) patch[key] = value;
367
+ }
368
+ return patch;
369
+ }
370
+
371
+ /** 幽灵 room 守卫:Bug 行仍存在 → true(归档不算删除,可解档继续协作) */
372
+ async function assertBugRoomAlive(
373
+ room: Extract<CollabRoomName, { kind: "entity-bug" }>,
374
+ ): Promise<boolean> {
375
+ const db = await import("@allbluecn/database");
376
+ const bug = await db.prisma.bug.findUnique({
377
+ where: { id: room.bugId },
378
+ select: { id: true },
379
+ });
380
+ return bug != null;
381
+ }
382
+
383
+ async function exportBug(input: {
384
+ room: CollabRoomName;
385
+ doc: Y.Doc;
386
+ authorStats: CollabAuthorStat[];
387
+ }): Promise<void> {
388
+ const room = input.room as Extract<CollabRoomName, { kind: "entity-bug" }>;
389
+ const db = await import("@allbluecn/database");
390
+ // 回写前复核实体存在(防已删实体被回写复活——锚点 J 第二道防线)
391
+ const alive = await db.prisma.bug.findUnique({
392
+ where: { id: room.bugId },
393
+ select: { id: true },
394
+ });
395
+ if (!alive) return;
396
+
397
+ await ensureServerDom();
398
+ // description:default fragment → {html, markdown}(与种子化同一扩展组合)
399
+ const { yDocToContent } = await import("@allbluecn/collab-core/tiptap-export");
400
+ const content = yDocToContent(input.doc, storyDocExtensions());
401
+ const fields = readBugFieldsPatch(input.doc);
402
+ // 空 Y.Array → null = Y 无意见,不触碰业务 steps 列
403
+ const steps = readStepsFromDoc(input.doc);
404
+
405
+ // per-author 占比(§10.2,共享助手单源)
406
+ const { primary, totalBytes, perAuthor } = computeAuthorAttribution(input.authorStats);
407
+
408
+ // 出队语义 hint:live forwarded 的机器写入(reopened_by_sdk 等)在落库时
409
+ // 单独成行;primary 为机器时压制通用行(语义已由 hint 行携带,字节统计
410
+ // 并入末条 hint 行 metadata)
411
+ const hints = drainBugActivityHints(buildRoomName({ kind: "entity-bug", bugId: room.bugId }));
412
+ const primaryMachine = primary != null && parseMachineActor(primary) != null;
413
+
414
+ await db.prisma.$transaction(async (tx) => {
415
+ await writeBugColumns(tx, {
416
+ bugId: room.bugId,
417
+ roomName: buildRoomName({ kind: "entity-bug", bugId: room.bugId }),
418
+ descriptionHtml: content.html,
419
+ descriptionMarkdown: content.markdown,
420
+ fields,
421
+ ...(steps && { steps }),
422
+ actor: primary,
423
+ activityExtra: { perAuthor, totalBytes },
424
+ touchSnapshot: true,
425
+ suppressMachineActivityRow: hints.length > 0 && primaryMachine,
426
+ });
427
+ for (const [i, hint] of hints.entries()) {
428
+ const hm = parseMachineActor(hint.actor);
429
+ await tx.bugActivity.create({
430
+ data: {
431
+ bugId: room.bugId,
432
+ userId: hm ? null : hint.actor,
433
+ actorType: hm ? hm.type : "collab",
434
+ ...(hm?.type === "agent" && hm.name && { agentName: hm.name }),
435
+ action: hint.action,
436
+ metadata: {
437
+ source: hm ? hm.type : "collab",
438
+ summary: "更新了 BUG",
439
+ ...(hint.field !== undefined && { field: hint.field }),
440
+ ...(hint.oldValue !== undefined && { oldValue: hint.oldValue }),
441
+ ...(hint.newValue !== undefined && { newValue: hint.newValue }),
442
+ ...(i === hints.length - 1 && primaryMachine && { perAuthor, totalBytes }),
443
+ },
444
+ },
445
+ });
446
+ }
447
+ });
448
+ }
449
+
450
+ /** 注册 Bug 导出器 + 幽灵 room 守卫(生产经 startCollabServerFromEnv 调用) */
451
+ export function registerBugCollab(): void {
452
+ registerExporter("entity-bug", exportBug);
453
+ registerRoomGuard("entity-bug", assertBugRoomAlive);
454
+ }