@allbluecn/web-app 0.28.11 → 0.28.12

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 (110) hide show
  1. package/package.json +5 -5
  2. package/public/dev-gallery.html +19 -0
  3. package/src/__tests__/bench/baselines/format-timestamp.json +44 -0
  4. package/src/__typeprobe__.d.ts +4 -0
  5. package/src/components/harness/extension-panel/panels/terminal/__tests__/terminal-instance.test.tsx +93 -4
  6. package/src/components/harness/extension-panel/panels/terminal/sse-transport.ts +28 -5
  7. package/src/components/harness/extension-panel/panels/terminal/terminal-instance.tsx +53 -10
  8. package/src/components/harness/extension-panel/panels/terminal/transport.ts +10 -3
  9. package/src/components/harness/extension-panel/panels/terminal/ws-transport.ts +13 -2
  10. package/src/components/settings/harness/connectors-card.tsx +5 -0
  11. package/src/dev/gallery-entry.tsx +38 -0
  12. package/src/dev/gallery.tsx +610 -0
  13. package/src/lib/changelog/sdk-versions.ts +3 -3
  14. package/src/paraglide/README.md +1 -1
  15. package/src/paraglide/messages/_index.d.ts +9 -0
  16. package/src/paraglide/messages/_index.js +9 -0
  17. package/src/paraglide/messages/capabilities_webhook.d.ts +16 -0
  18. package/src/paraglide/messages/capabilities_webhook.js +29 -0
  19. package/src/paraglide/messages/capabilities_workflow.d.ts +16 -0
  20. package/src/paraglide/messages/capabilities_workflow.js +29 -0
  21. package/src/paraglide/messages/harness_panel_terminal_exitedrecycled1.d.ts +17 -0
  22. package/src/paraglide/messages/harness_panel_terminal_exitedrecycled1.js +30 -0
  23. package/src/paraglide/messages/harness_panel_terminal_restarted.d.ts +16 -0
  24. package/src/paraglide/messages/harness_panel_terminal_restarted.js +29 -0
  25. package/src/paraglide/messages/settings_harness_connectors_needsauth1.d.ts +17 -0
  26. package/src/paraglide/messages/settings_harness_connectors_needsauth1.js +30 -0
  27. package/src/paraglide/messages/settings_harness_ralphenabled1.d.ts +17 -0
  28. package/src/paraglide/messages/settings_harness_ralphenabled1.js +30 -0
  29. package/src/paraglide/messages/settings_harness_ralphenabled_description1.d.ts +17 -0
  30. package/src/paraglide/messages/settings_harness_ralphenabled_description1.js +30 -0
  31. package/src/paraglide/messages/settings_harness_ralphmaxrounds2.d.ts +17 -0
  32. package/src/paraglide/messages/settings_harness_ralphmaxrounds2.js +30 -0
  33. package/src/paraglide/messages/settings_harness_ralphmaxrounds_description2.d.ts +17 -0
  34. package/src/paraglide/messages/settings_harness_ralphmaxrounds_description2.js +30 -0
  35. package/src/routeTree.gen.ts +21 -0
  36. package/src/routes/api/harness/terminal/$.ts +32 -13
  37. package/src/routes/api/harness/terminal/__tests__/route.test.ts +41 -0
  38. package/src/routes/api/harness/webhook/$token.ts +23 -0
  39. package/src/routes/api/sync/__tests__/bootstrap.test.ts +32 -1
  40. package/src/routes/api/sync/bootstrap.ts +11 -0
  41. package/src/server/ai-gateway/durability/__tests__/sse-resume-frames.test.ts +123 -0
  42. package/src/server/harness/__tests__/agent-terminal-sandbox.test.ts +23 -4
  43. package/src/server/harness/__tests__/agent-terminal.server.test.ts +118 -2
  44. package/src/server/harness/__tests__/credentials.server.test.ts +25 -2
  45. package/src/server/harness/__tests__/host-schedule-worker.test.ts +43 -0
  46. package/src/server/harness/__tests__/runtime-without-providers.test.ts +11 -0
  47. package/src/server/harness/__tests__/sticky-route.test.ts +86 -0
  48. package/src/server/harness/__tests__/terminal-foreground.server.test.ts +80 -0
  49. package/src/server/harness/__tests__/terminal-manager.server.test.ts +75 -1
  50. package/src/server/harness/__tests__/tool-entitlements.test.ts +6 -2
  51. package/src/server/harness/agent-terminal.server.ts +25 -4
  52. package/src/server/harness/agents/__tests__/agent-control.test.ts +1 -0
  53. package/src/server/harness/agents/run-view.server.ts +55 -2
  54. package/src/server/harness/capabilities/__tests__/__snapshots__/matrix.test.ts.snap +92 -0
  55. package/src/server/harness/capabilities/__tests__/execution-plane-denials.test.ts +3 -1
  56. package/src/server/harness/capabilities/__tests__/p3-matrix.test.ts +3 -3
  57. package/src/server/harness/capabilities/__tests__/p5-matrix.test.ts +293 -0
  58. package/src/server/harness/capabilities/__tests__/validate.test.ts +8 -2
  59. package/src/server/harness/capabilities/execution-plane-denials.ts +9 -3
  60. package/src/server/harness/capabilities/manifests/agent-terminal.ts +3 -2
  61. package/src/server/harness/capabilities/manifests/webhook.ts +45 -0
  62. package/src/server/harness/capabilities/manifests/workflow.ts +40 -0
  63. package/src/server/harness/capabilities/registry.ts +4 -0
  64. package/src/server/harness/connectors/__tests__/connector-accounts.test.ts +22 -1
  65. package/src/server/harness/connectors/connector-accounts.server.ts +7 -0
  66. package/src/server/harness/credentials.server.ts +3 -1
  67. package/src/server/harness/define.server.ts +11 -0
  68. package/src/server/harness/mcp/mcp-config.server.ts +3 -1
  69. package/src/server/harness/outbox/outbox-dispatcher.server.ts +9 -0
  70. package/src/server/harness/outbox/outbox-store.server.ts +7 -0
  71. package/src/server/harness/persistence/__tests__/log-store.server.test.ts +4 -1
  72. package/src/server/harness/plugins/__tests__/tool-risk-audit.test.ts +5 -1
  73. package/src/server/harness/plugins/builtin/agent-terminal.plugin.ts +12 -2
  74. package/src/server/harness/providers/contracts.ts +16 -0
  75. package/src/server/harness/schedule/schedule-dispatcher.server.ts +3 -0
  76. package/src/server/harness/search/__tests__/indexer.test.ts +4 -1
  77. package/src/server/harness/search/__tests__/lifecycle.test.ts +4 -1
  78. package/src/server/harness/search/__tests__/search.test.ts +4 -1
  79. package/src/server/harness/sticky-route.server.ts +72 -0
  80. package/src/server/harness/terminal-foreground.server.ts +90 -0
  81. package/src/server/harness/terminal-manager.server.ts +78 -3
  82. package/src/server/harness/tool-entitlements.server.ts +5 -0
  83. package/src/server/harness/webhook/__tests__/body.test.ts +73 -0
  84. package/src/server/harness/webhook/__tests__/payload.test.ts +215 -0
  85. package/src/server/harness/webhook/__tests__/signature.test.ts +170 -0
  86. package/src/server/harness/webhook/__tests__/webhook-dispatcher.test.ts +212 -0
  87. package/src/server/harness/webhook/__tests__/webhook.plugin.test.ts +195 -0
  88. package/src/server/harness/webhook/__tests__/webhook.service.test.ts +354 -0
  89. package/src/server/harness/webhook/body.server.ts +56 -0
  90. package/src/server/harness/webhook/payload.server.ts +169 -0
  91. package/src/server/harness/webhook/signature.server.ts +118 -0
  92. package/src/server/harness/webhook/types.ts +57 -0
  93. package/src/server/harness/webhook/webhook-dispatcher.server.ts +495 -0
  94. package/src/server/harness/webhook/webhook-store.server.ts +115 -0
  95. package/src/server/harness/webhook/webhook.plugin.ts +273 -0
  96. package/src/server/harness/webhook/webhook.service.server.ts +577 -0
  97. package/src/server/harness/worker/__tests__/worker-http.test.ts +8 -1
  98. package/src/server/harness/worker/worker-health.server.ts +4 -1
  99. package/src/server/harness/worker/worker-runtime.server.ts +43 -1
  100. package/src/server/harness/workflow/__tests__/engine.test.ts +195 -0
  101. package/src/server/harness/workflow/__tests__/settings.test.ts +125 -0
  102. package/src/server/harness/workflow/__tests__/validate.test.ts +151 -0
  103. package/src/server/harness/workflow/engine.server.ts +155 -0
  104. package/src/server/harness/workflow/settings.ts +84 -0
  105. package/src/server/harness/workflow/store.server.ts +147 -0
  106. package/src/server/harness/workflow/types.ts +80 -0
  107. package/src/server/harness/workflow/validate.ts +130 -0
  108. package/src/server/harness/workflow/workflow.plugin.ts +261 -0
  109. package/src/server/serverFns/harness/__tests__/fork-thread.test.ts +14 -1
  110. package/src/server/serverFns/harness/fork-thread.ts +17 -0
@@ -0,0 +1,261 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // AllBlue - 理想之海
3
+ // Copyright (C) 2026 AllBlue Contributors
4
+ //
5
+ // allblue/workflow 插件(P5 任务 1):多阶段 DAG 编排(workflow)与 Ralph 长跑。
6
+ //
7
+ // 权威分层:run 状态一律进官方 log(store.server.ts 的三类 allblue.workflow.*
8
+ // 记录,由 agentControlLogReduce 折叠),**不建 Prisma 第二份可写事实**。
9
+ //
10
+ // 工具面四个:
11
+ // workflow_start —— durableTool:校验 DAG → 写 started → 逐阶段派发子代理推进
12
+ // (每阶段 step.do 幂等,崩溃重放不重跑已完成阶段)
13
+ // workflow_list —— 读当前线程全部 run(log 投影)
14
+ // workflow_view —— 读单个 run(归属校验)
15
+ // workflow_cancel —— 将 running 的 run 置 cancelled(引擎在阶段间复查后停)
16
+ //
17
+ // 执行平面:workflow 阶段脚本走 PTC(进程内 QuickJS isolate),四端可用、不属
18
+ // 执行平面;阶段内调用的 workspace 类工具仍受既有账本约束,不由本插件绕过。
19
+
20
+ import { toolDefinition, type AnyTool } from '@tanstack/ai'
21
+ import {
22
+ createPluginEvent,
23
+ definePlugin,
24
+ durableTool,
25
+ type HarnessRunContext,
26
+ type PluginSetupContext,
27
+ } from '@tanstack/ai-harness'
28
+ import { z } from 'zod'
29
+
30
+ import { ProviderError } from '../providers/contracts'
31
+ import { withSession } from '../session-control.server'
32
+ import { enforceToolFeature } from '../tool-entitlements.server'
33
+ import { resolveToolIdentity } from '../tool-identity.server'
34
+ import { runWorkflow } from './engine.server'
35
+ import {
36
+ appendWorkflowFinished,
37
+ appendWorkflowStarted,
38
+ readWorkflowRuns,
39
+ requireWorkflowRun,
40
+ } from './store.server'
41
+ import {
42
+ assertRalphAllowed,
43
+ readRalphSettings,
44
+ RALPH_ENABLED_SETTING,
45
+ RALPH_MAX_ROUNDS_SETTING,
46
+ } from './settings'
47
+ import { RALPH_MAX_ROUNDS_CEILING, type WorkflowDefinition } from './types'
48
+ import { validateWorkflowDefinition } from './validate'
49
+
50
+ export const workflowToolNames = [
51
+ 'workflow_start',
52
+ 'workflow_list',
53
+ 'workflow_view',
54
+ 'workflow_cancel',
55
+ ] as const
56
+
57
+ export interface WorkflowChangedEvent {
58
+ action: 'started' | 'finished' | 'cancelled'
59
+ runId: string
60
+ status?: string
61
+ }
62
+
63
+ export const WorkflowChanged = createPluginEvent<WorkflowChangedEvent>('workflow.changed')
64
+
65
+ const stageStateSchema = z.object({
66
+ id: z.string(),
67
+ status: z.enum(['pending', 'running', 'done', 'failed', 'skipped']),
68
+ subagentRunId: z.string().optional(),
69
+ startedAt: z.number().optional(),
70
+ finishedAt: z.number().optional(),
71
+ error: z.string().optional(),
72
+ })
73
+
74
+ const runSnapshotSchema = z.object({
75
+ runId: z.string(),
76
+ threadId: z.string(),
77
+ name: z.string(),
78
+ status: z.enum(['running', 'done', 'failed', 'cancelled']),
79
+ round: z.number(),
80
+ stages: z.array(stageStateSchema),
81
+ createdAt: z.number(),
82
+ updatedAt: z.number(),
83
+ })
84
+
85
+ const stageInputSchema = z.object({
86
+ id: z.string().trim().min(1).max(64),
87
+ title: z.string().trim().min(1).max(200),
88
+ kind: z.enum(['agent', 'script']).optional(),
89
+ agent: z.string().trim().min(1).max(64).optional(),
90
+ prompt: z.string().trim().min(1).max(20_000),
91
+ script: z.string().max(20_000).optional(),
92
+ dependsOn: z.array(z.string().trim().min(1).max(64)).max(50).optional(),
93
+ }).strict()
94
+
95
+ const definitionInputSchema = z.object({
96
+ name: z.string().trim().min(1).max(200),
97
+ stages: z.array(stageInputSchema).min(1).max(50),
98
+ ralph: z.object({
99
+ maxRounds: z.number().int().min(1).max(RALPH_MAX_ROUNDS_CEILING),
100
+ }).strict().optional(),
101
+ }).strict()
102
+
103
+ function asDefinition(input: z.infer<typeof definitionInputSchema>): WorkflowDefinition {
104
+ return {
105
+ name: input.name,
106
+ stages: input.stages.map((stage) => ({
107
+ id: stage.id,
108
+ title: stage.title,
109
+ prompt: stage.prompt,
110
+ ...(stage.kind === undefined ? {} : { kind: stage.kind }),
111
+ ...(stage.agent === undefined ? {} : { agent: stage.agent }),
112
+ ...(stage.script === undefined ? {} : { script: stage.script }),
113
+ ...(stage.dependsOn === undefined ? {} : { dependsOn: stage.dependsOn }),
114
+ })),
115
+ ...(input.ralph === undefined ? {} : { ralph: { maxRounds: input.ralph.maxRounds } }),
116
+ }
117
+ }
118
+
119
+ function requireThread(run: HarnessRunContext['run']): string {
120
+ if (!run.threadId) throw new ProviderError('workflow_forbidden', '当前运行缺少线程上下文')
121
+ return run.threadId
122
+ }
123
+
124
+ function buildWorkflowTools(setupContext: PluginSetupContext): AnyTool[] {
125
+ const start = durableTool(
126
+ toolDefinition({
127
+ name: 'workflow_start',
128
+ description:
129
+ '启动多阶段 workflow(DAG):按 dependsOn 拓扑序逐阶段派发子代理推进,' +
130
+ '阶段状态写入会话日志;ralph 时整轮重复并受 maxRounds 硬约束',
131
+ inputSchema: definitionInputSchema,
132
+ outputSchema: z.object({ run: runSnapshotSchema }),
133
+ }),
134
+ async (input, ctx) => {
135
+ const runCtx = ctx.context as HarnessRunContext
136
+ const userId = resolveToolIdentity(runCtx)
137
+ await enforceToolFeature('workflow_start', userId)
138
+ const threadId = requireThread(runCtx.run)
139
+ const definition = validateWorkflowDefinition(asDefinition(input))
140
+ // Ralph 两重前置(P5 任务 2):能力开关关闭即拒(不静默降级为单轮);定义要的
141
+ // 轮数超过线程级上限也拒——消息带上当前上限,用户据此去设置页调整。
142
+ const ralph = readRalphSettings((key) => setupContext.config.get(key))
143
+ assertRalphAllowed(definition, ralph)
144
+
145
+ const { getHarnessHost, getRuntimeHarnessDefinition } = await import('../host.server')
146
+ const host = await getHarnessHost()
147
+ const harness = getRuntimeHarnessDefinition()
148
+ const user = { id: userId, tenantId: runCtx.run.user?.tenantId ?? runCtx.run.tenantId }
149
+ const opened = await host.open(harness, { threadId, user })
150
+ try {
151
+ const runId = `wf_${crypto.randomUUID()}`
152
+ const snapshot = await appendWorkflowStarted(
153
+ opened,
154
+ { id: userId, tenantId: runCtx.run.user?.tenantId },
155
+ { runId, threadId, userId, definition, round: 0 },
156
+ )
157
+ setupContext.emit(WorkflowChanged, { action: 'started', runId })
158
+
159
+ const status = await runWorkflow({
160
+ session: opened,
161
+ run: runCtx.run,
162
+ definition,
163
+ snapshot,
164
+ step: ctx.step,
165
+ // 纵深防御:即便上游校验漏了,引擎也不会越过线程级上限。
166
+ ralphRoundsCap: ralph.maxRounds,
167
+ })
168
+
169
+ const finalLog = await readWorkflowRuns(opened)
170
+ const finalRun = finalLog.find((entry) => entry.runId === runId) ?? snapshot
171
+ setupContext.emit(WorkflowChanged, { action: 'finished', runId, status })
172
+ return { run: { ...finalRun, status } }
173
+ } finally {
174
+ await opened[Symbol.asyncDispose]()
175
+ }
176
+ },
177
+ { replay: 'safe' },
178
+ )
179
+
180
+ const list = toolDefinition({
181
+ name: 'workflow_list',
182
+ description: '列出当前线程的 workflow 运行(log 投影,最多 50 条,最新在前)',
183
+ inputSchema: z.object({}).strict(),
184
+ outputSchema: z.object({ runs: z.array(runSnapshotSchema) }),
185
+ }).server<HarnessRunContext>(async (_input, ctx) => {
186
+ const userId = resolveToolIdentity(ctx.context)
187
+ await enforceToolFeature('workflow_list', userId)
188
+ const threadId = requireThread(ctx.context.run)
189
+ const runs = await withSession(ctx.context.run, async (session) =>
190
+ (await readWorkflowRuns(session)).filter((entry) => entry.threadId === threadId),
191
+ )
192
+ return {
193
+ runs: runs.sort((a, b) => b.createdAt - a.createdAt).slice(0, 50),
194
+ }
195
+ })
196
+
197
+ const view = toolDefinition({
198
+ name: 'workflow_view',
199
+ description: '读取单个 workflow 运行的阶段进度;不存在或不属于当前用户时报错',
200
+ inputSchema: z.object({ runId: z.string().trim().min(1).max(200) }).strict(),
201
+ outputSchema: z.object({ run: runSnapshotSchema }),
202
+ }).server<HarnessRunContext>(async (input, ctx) => {
203
+ const userId = resolveToolIdentity(ctx.context)
204
+ await enforceToolFeature('workflow_view', userId)
205
+ const threadId = requireThread(ctx.context.run)
206
+ const run = await withSession(ctx.context.run, (session) =>
207
+ requireWorkflowRun(session, input.runId, { userId, threadId }),
208
+ )
209
+ return { run }
210
+ })
211
+
212
+ const cancel = toolDefinition({
213
+ name: 'workflow_cancel',
214
+ description: '取消一个 running 的 workflow;引擎在下一阶段边界停止推进',
215
+ inputSchema: z.object({ runId: z.string().trim().min(1).max(200) }).strict(),
216
+ outputSchema: z.object({ run: runSnapshotSchema }),
217
+ }).server<HarnessRunContext>(async (input, ctx) => {
218
+ const userId = resolveToolIdentity(ctx.context)
219
+ await enforceToolFeature('workflow_cancel', userId)
220
+ const threadId = requireThread(ctx.context.run)
221
+ const run = await withSession(ctx.context.run, async (session) => {
222
+ const current = await requireWorkflowRun(session, input.runId, { userId, threadId })
223
+ if (current.status !== 'running') {
224
+ throw new ProviderError('workflow_not_running', `workflow 已结束:${current.status}`)
225
+ }
226
+ await appendWorkflowFinished(session, ctx.context.run.user, input.runId, 'cancelled')
227
+ return { ...current, status: 'cancelled' as const, updatedAt: Date.now() }
228
+ })
229
+ setupContext.emit(WorkflowChanged, { action: 'cancelled', runId: input.runId })
230
+ return { run }
231
+ })
232
+
233
+ return [start, list, view, cancel]
234
+ }
235
+
236
+ export const workflowPlugin = definePlugin({
237
+ name: 'allblue/workflow',
238
+ description: '多阶段 workflow(DAG 编排)与 Ralph 长跑',
239
+ lifetime: 'session',
240
+ setup: async (context) => ({
241
+ // 无论开关都返回这两个 config(官方 pluginSettings() 只枚举 setup 返回的
242
+ // config,缺项会让 writeHarnessSetting 抛「Setting is not mounted」而永远
243
+ // 打不开——与 code-mode 同一死锁点)。Ralph 默认关闭(母规格 §6.2 opt-in)。
244
+ config: {
245
+ [RALPH_ENABLED_SETTING.key]: {
246
+ type: 'boolean',
247
+ default: RALPH_ENABLED_SETTING.default,
248
+ description: '开启后 workflow_start 可用 ralph 模式(整轮重复执行同一 DAG,' +
249
+ '每轮 fresh agent、共享 workspace)',
250
+ },
251
+ [RALPH_MAX_ROUNDS_SETTING.key]: {
252
+ type: 'number',
253
+ default: RALPH_MAX_ROUNDS_SETTING.default,
254
+ min: RALPH_MAX_ROUNDS_SETTING.min,
255
+ max: RALPH_MAX_ROUNDS_SETTING.max,
256
+ description: 'Ralph 单次运行允许的最大轮数(线程级硬上限,定义超过即拒)',
257
+ },
258
+ },
259
+ tools: buildWorkflowTools(context),
260
+ }),
261
+ })
@@ -62,7 +62,8 @@ const mocks = vi.hoisted(() => {
62
62
  const getCurrentSession = vi.fn()
63
63
  const fork = vi.fn()
64
64
  const resolveExecutionContext = vi.fn()
65
- return { findFirst, create, getCurrentSession, fork, resolveExecutionContext }
65
+ const auditLog = vi.fn()
66
+ return { findFirst, create, getCurrentSession, fork, resolveExecutionContext, auditLog }
66
67
  })
67
68
 
68
69
  vi.mock("@allbluecn/database", () => ({
@@ -82,6 +83,7 @@ vi.mock("@/server/harness/gate.server", () => ({
82
83
  vi.mock("@/server/harness/execution-context.server", () => ({
83
84
  resolveExecutionContext: mocks.resolveExecutionContext,
84
85
  }))
86
+ vi.mock("@/server/audit", () => ({ auditLog: mocks.auditLog }))
85
87
  vi.mock("@/server/harness/host.server", () => ({
86
88
  // 生产经 getHarnessRuntime 成对取 host + harness(再验收 P1-3),mock 同形状。
87
89
  getHarnessRuntime: async () => ({
@@ -176,6 +178,17 @@ describe("forkHarnessThreadFn", () => {
176
178
  title: "迁移计划 (fork)",
177
179
  engine: "cloud",
178
180
  })
181
+
182
+ // 审计(P5 任务 5 裁决 11):harness.sync.fork 记新线程 id + 来源,零 transcript 内容
183
+ expect(mocks.auditLog).toHaveBeenCalledWith(
184
+ expect.objectContaining({
185
+ action: "harness.sync.fork",
186
+ resourceType: "harness_thread",
187
+ resourceId: opts.newThreadId,
188
+ userId: "user-1",
189
+ metadata: { sourceThreadId: "t-1", atMessageId: null, partial: false },
190
+ }),
191
+ )
179
192
  })
180
193
 
181
194
  it("无标题源线程 fork → 标题落 (fork)", async () => {
@@ -17,6 +17,7 @@
17
17
  import { getPrisma } from "@allbluecn/database/get-prisma"
18
18
  import { createServerFn } from "@tanstack/react-start"
19
19
  import { authContextMiddleware } from "@/server/middlewares/auth-context"
20
+ import { auditLog } from "@/server/audit"
20
21
  import { SANDBOX_DEFAULT_POLICY_LEVEL } from "@/server/ai-gateway/sandbox/policy"
21
22
  import { z } from "zod"
22
23
 
@@ -98,6 +99,22 @@ export const forkHarnessThreadFn = createServerFn({ method: "POST" })
98
99
  const { resolveExecutionContext } = await import("@/server/harness/execution-context.server")
99
100
  await resolveExecutionContext({ threadId: conversation.id, user: { id: userId } })
100
101
 
102
+ // 审计(P5 任务 5 裁决 11):harness.sync.fork——跨设备/跨线程迁移的唯一合法
103
+ // 形态是 host.fork 生成新事实分支(不做事件级 merge)。metadata 只记来源与截断点,
104
+ // 不记 transcript 内容。
105
+ await auditLog({
106
+ workspaceId: source.workspaceId ?? '',
107
+ userId,
108
+ resourceType: 'harness_thread',
109
+ resourceId: newThreadId,
110
+ action: 'harness.sync.fork',
111
+ metadata: {
112
+ sourceThreadId: data.threadId,
113
+ atMessageId: data.atMessageId ?? null,
114
+ partial: Boolean(data.atMessageId),
115
+ },
116
+ })
117
+
101
118
  return {
102
119
  id: conversation.id,
103
120
  title: conversation.title,