@allbluecn/web-app 0.28.0 → 0.28.1
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.
- package/package.json +4 -3
- package/src/components/harness/__tests__/dock-registry.test.ts +43 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/__tests__/use-harness-chat-adapter.test.ts +20 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/use-agent-terminals.ts +116 -0
- package/src/components/harness/conversation-panel/messages/harness-chain/use-harness-chat-adapter.ts +17 -5
- package/src/components/harness/conversation-panel/messages/harness-chain/use-harness-session.ts +4 -1
- package/src/components/harness/conversation-panel/messages/tools/__tests__/tool-run.test.ts +26 -1
- package/src/components/harness/conversation-panel/messages/tools/tool-run.ts +11 -0
- package/src/components/harness/extension-panel/dock/__tests__/tab-strip.test.tsx +45 -0
- package/src/components/harness/extension-panel/dock/dock-registry.ts +34 -0
- package/src/components/harness/extension-panel/dock/dock-surface.tsx +33 -0
- package/src/components/harness/extension-panel/dock/guide-page.tsx +4 -1
- package/src/components/harness/extension-panel/dock/tab-strip.tsx +9 -1
- package/src/components/harness/extension-panel/panels/terminal/__tests__/kind.test.tsx +219 -2
- package/src/components/harness/extension-panel/panels/terminal/__tests__/terminal-instance.test.tsx +322 -19
- package/src/components/harness/extension-panel/panels/terminal/__tests__/use-agent-terminal-roster.test.tsx +393 -0
- package/src/components/harness/extension-panel/panels/terminal/__tests__/ws-transport.test.ts +25 -0
- package/src/components/harness/extension-panel/panels/terminal/kind.tsx +55 -1
- package/src/components/harness/extension-panel/panels/terminal/shell-pref.ts +7 -4
- package/src/components/harness/extension-panel/panels/terminal/sse-transport.ts +26 -6
- package/src/components/harness/extension-panel/panels/terminal/tab-control-state.tsx +114 -0
- package/src/components/harness/extension-panel/panels/terminal/terminal-instance.tsx +190 -96
- package/src/components/harness/extension-panel/panels/terminal/terminal-theme.ts +113 -0
- package/src/components/harness/extension-panel/panels/terminal/transport.ts +28 -6
- package/src/components/harness/extension-panel/panels/terminal/use-agent-terminal-roster.ts +107 -0
- package/src/components/harness/extension-panel/panels/terminal/ws-transport.ts +7 -5
- package/src/components/harness/extension-panel/panels/terminal/xterm-terminal.tsx +5 -67
- package/src/lib/changelog/sdk-versions.ts +2 -2
- package/src/lib/queries/harness-terminal.ts +77 -0
- package/src/paraglide/messages/_index.js +48 -0
- package/src/paraglide/messages/en.js +15 -0
- package/src/paraglide/messages/zh.js +15 -0
- package/src/routes/api/harness/$.ts +19 -2
- package/src/routes/api/harness/terminal/$.ts +37 -6
- package/src/routes/api/harness/terminal/__tests__/route.test.ts +120 -0
- package/src/server/harness/__tests__/agent-terminal.server.test.ts +448 -0
- package/src/server/harness/__tests__/builtin-tools-invariant.test.ts +22 -12
- package/src/server/harness/__tests__/first-contact-fakes.test.ts +103 -3
- package/src/server/harness/__tests__/terminal-manager.server.test.ts +761 -2
- package/src/server/harness/agent-terminal.server.ts +631 -0
- package/src/server/harness/first-contact-fakes.ts +115 -4
- package/src/server/harness/host.server.ts +28 -1
- package/src/server/harness/persistence/__tests__/session-index-store.server.test.ts +83 -0
- package/src/server/harness/persistence/prisma-persistence.server.ts +12 -3
- package/src/server/harness/persistence/session-index-store.server.ts +26 -0
- package/src/server/harness/plugins/__tests__/assemble-disable.test.ts +25 -17
- package/src/server/harness/plugins/__tests__/tool-risk-audit.test.ts +16 -6
- package/src/server/harness/plugins/assemble-app.ts +12 -0
- package/src/server/harness/plugins/base-patch.ts +9 -2
- package/src/server/harness/plugins/builtin/__tests__/agent-terminal.plugin.test.ts +702 -0
- package/src/server/harness/plugins/builtin/agent-terminal.plugin.ts +518 -0
- package/src/server/harness/terminal-frame-builder.server.ts +5 -3
- package/src/server/harness/terminal-manager.server.ts +772 -35
- package/src/server/harness/terminal-ws-handler.server.ts +8 -2
- package/src/server/harness/tool-risk.ts +20 -4
- package/src/components/harness/extension-panel/panels/terminal/__tests__/xterm-webgl.test.ts +0 -68
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
// describe/snapshot/transcript/events 对「无线条 entry」线程的 404 容错:官方 handler
|
|
8
8
|
// 对未落库线程返回 404,而 ai-harness 0.3.0 客户端对 describe/transcript/events 无
|
|
9
9
|
// 404 容错(client.js `Harness * failed`)→ view fail → 重连退避耗尽 → Disconnected。
|
|
10
|
-
// 这里把 404
|
|
10
|
+
// 这里把 404 转成形状对齐官方的空响应;events 例外——空流会让客户端进入无限重连
|
|
11
|
+
// 循环(「重连中…」结构性永挂 + 首答延迟),故提供桥接保活流(bridgingEventsSseResponse,
|
|
12
|
+
// 轮询实现经参数注入保持零依赖)。形状回归哨兵见 __tests__/first-contact-fakes.test.ts。
|
|
11
13
|
|
|
12
14
|
/** 空 SessionDescription(对齐官方 session.describe() 形状,view reduce.js
|
|
13
15
|
* applyDescription 消费 commands/config/tools/settings/models 五字段)。 */
|
|
@@ -70,7 +72,9 @@ export function emptyTranscriptResponse(): Response {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
/** 空 events SSE(立即 end 的空流 = 无事件;客户端 read 循环读到 stream end →
|
|
73
|
-
* 空闲 +
|
|
75
|
+
* 空闲 + 定时重连,不崩)。仅作无轮询注入时的回落——立即结束的流会让客户端进入
|
|
76
|
+
* 「reconnecting → 退避重连」循环(attempt 不重置则指数涨到 30s 封顶),见
|
|
77
|
+
* bridgingEventsSseResponse。 */
|
|
74
78
|
export function emptyEventsSseResponse(): Response {
|
|
75
79
|
return new Response(': harness events(无线条 entry 容错,空流)\n\n', {
|
|
76
80
|
status: 200,
|
|
@@ -78,15 +82,115 @@ export function emptyEventsSseResponse(): Response {
|
|
|
78
82
|
})
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
/**
|
|
86
|
+
* events 404 桥接流的节奏:ping 对齐官方服务端心跳(sse.ts HEARTBEAT_MS = 20s,
|
|
87
|
+
* 客户端 idleTimeoutMs = 60s = 3×心跳,桥接流恒有字节、永不 idle 断开);轮询间隔
|
|
88
|
+
* 决定「首条消息 → 事件流交接」的衔接延迟上限(≈ 一次轮询 + 客户端重连 ~1s)。
|
|
89
|
+
*/
|
|
90
|
+
const BRIDGE_PING_MS = 20_000
|
|
91
|
+
const BRIDGE_POLL_MS = 2_000
|
|
92
|
+
|
|
93
|
+
/** events 404 桥接流的注入面($.ts 用 host.sessions.get 实现 existence 轮询)。 */
|
|
94
|
+
export interface BridgingEventsOptions {
|
|
95
|
+
/**
|
|
96
|
+
* 轮询「线程 entry 是否已建立」。true = 交出连接:桥接流主动 close,客户端
|
|
97
|
+
* 读循环正常结束 → reconnecting(attempt 已被 ping 归零,退避保持 1s 档)→
|
|
98
|
+
* ~1s 内重连命中真实事件流。查询异常按 false 处理(继续桥接,不让瞬态故障
|
|
99
|
+
* 拆掉保活)。
|
|
100
|
+
*/
|
|
101
|
+
pollSessionExists: () => Promise<boolean>
|
|
102
|
+
/** 客户端断开信号(标准 Request.signal):终止计时器并 close,防计时器泄漏。 */
|
|
103
|
+
signal?: AbortSignal | null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 无线条 entry 的 events 404 桥接流(2026-11-21,「重连中…」结构性永挂根治)。
|
|
108
|
+
*
|
|
109
|
+
* 旧容错(emptyEventsSseResponse)返回立即结束的空流:客户端读循环正常结束 →
|
|
110
|
+
* reconnecting → 退避重连 → 又是空流 → 无限循环。空会话(新建未发首条消息)在
|
|
111
|
+
* UI 上恒显「重连中…」,且 attempt 不重置使退避指数涨到 30s——首条消息的回复
|
|
112
|
+
* 事件要等下一次重连才送达,用户体感「模型迟迟不回答」。
|
|
113
|
+
*
|
|
114
|
+
* 桥接流改为:立即发首帧注释(连接 open、attempt 归零)→ 每 20s `: ping` 保活
|
|
115
|
+
* (对齐官方心跳)→ 每 2s 轮询 entry 出现(首回合事件落库,与官方 events 路由
|
|
116
|
+
* 404 判定同源:host.sessions.get)→ close 交还连接,客户端重连拿真实事件流。
|
|
117
|
+
* 空会话因此恒 'open'(指示灯静默),回复事件在 entry 落库后 ~3s 内开始流式。
|
|
118
|
+
* 纯净同构模块纪律不变:轮询实现经参数注入,本文件零依赖。
|
|
119
|
+
*/
|
|
120
|
+
export function bridgingEventsSseResponse(options: BridgingEventsOptions): Response {
|
|
121
|
+
const encoder = new TextEncoder()
|
|
122
|
+
let pingTimer: ReturnType<typeof setInterval> | undefined
|
|
123
|
+
let pollTimer: ReturnType<typeof setInterval> | undefined
|
|
124
|
+
let closed = false
|
|
125
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
126
|
+
start(controller) {
|
|
127
|
+
const close = () => {
|
|
128
|
+
if (closed) return
|
|
129
|
+
closed = true
|
|
130
|
+
clearInterval(pingTimer)
|
|
131
|
+
clearInterval(pollTimer)
|
|
132
|
+
try {
|
|
133
|
+
controller.close()
|
|
134
|
+
} catch {
|
|
135
|
+
// 已 close/errored(cancel 或重复 close),幂等忽略
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// 首帧注释立即发出:客户端 fetch ok 即记 'open',此帧把读循环喂活并触发
|
|
139
|
+
// onRead(attempt 归零——后续重连退避保持 1s 档,交接延迟最小化)。
|
|
140
|
+
controller.enqueue(
|
|
141
|
+
encoder.encode(': harness bridge(无线条 entry,保活等首个回合)\n\n'),
|
|
142
|
+
)
|
|
143
|
+
pingTimer = setInterval(() => {
|
|
144
|
+
try {
|
|
145
|
+
controller.enqueue(encoder.encode(': ping\n\n'))
|
|
146
|
+
} catch {
|
|
147
|
+
close()
|
|
148
|
+
}
|
|
149
|
+
}, BRIDGE_PING_MS)
|
|
150
|
+
const poll = async () => {
|
|
151
|
+
let exists = false
|
|
152
|
+
try {
|
|
153
|
+
exists = await options.pollSessionExists()
|
|
154
|
+
} catch {
|
|
155
|
+
exists = false
|
|
156
|
+
}
|
|
157
|
+
if (exists) close()
|
|
158
|
+
}
|
|
159
|
+
pollTimer = setInterval(() => void poll(), BRIDGE_POLL_MS)
|
|
160
|
+
void poll()
|
|
161
|
+
if (options.signal?.aborted) close()
|
|
162
|
+
else options.signal?.addEventListener('abort', close, { once: true })
|
|
163
|
+
},
|
|
164
|
+
cancel() {
|
|
165
|
+
// HTTP 层取消消费(客户端断开的另一路径):计时器必须停,否则进程泄漏。
|
|
166
|
+
closed = true
|
|
167
|
+
clearInterval(pingTimer)
|
|
168
|
+
clearInterval(pollTimer)
|
|
169
|
+
},
|
|
170
|
+
})
|
|
171
|
+
return new Response(stream, {
|
|
172
|
+
status: 200,
|
|
173
|
+
headers: { 'content-type': 'text/event-stream' },
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** events 404 桥接注入面(缺省回落旧的立即结束空流)。 */
|
|
178
|
+
export interface FirstContactBridge {
|
|
179
|
+
/** entry 存在性轮询($.ts 实现:host.sessions.get 同源判定)。 */
|
|
180
|
+
pollSessionExists?: () => Promise<boolean>
|
|
181
|
+
}
|
|
182
|
+
|
|
81
183
|
/**
|
|
82
184
|
* describe/snapshot/transcript/events 首连 404 容错:GET 这四个路由对「无线条 entry」
|
|
83
185
|
* 的线程,官方 handler 返回 404(openToRead → not found),客户端无 404 容错 → 抛错
|
|
84
186
|
* 或断连。仅拦这四个 GET 的 404 转成对应空响应;其余路由与非 404 状态原样透传
|
|
85
|
-
* (403 access-denied、400 缺 threadId 等不被掩盖)。
|
|
187
|
+
* (403 access-denied、400 缺 threadId 等不被掩盖)。events 404 在提供 bridge 轮询时
|
|
188
|
+
* 转桥接保活流(bridgingEventsSseResponse),否则回落立即结束的空流(emptyEventsSseResponse)。
|
|
86
189
|
*/
|
|
87
190
|
export async function withFirstContact404Tolerance(
|
|
88
191
|
request: Request,
|
|
89
192
|
handlerPromise: Promise<Response>,
|
|
193
|
+
bridge?: FirstContactBridge,
|
|
90
194
|
): Promise<Response> {
|
|
91
195
|
const url = new URL(request.url)
|
|
92
196
|
const isToleratedGet =
|
|
@@ -108,6 +212,13 @@ export async function withFirstContact404Tolerance(
|
|
|
108
212
|
|
|
109
213
|
if (url.pathname.endsWith('/snapshot')) return emptySessionSnapshotResponse(url.searchParams.get('threadId'))
|
|
110
214
|
if (url.pathname.endsWith('/transcript')) return emptyTranscriptResponse()
|
|
111
|
-
if (url.pathname.endsWith('/events'))
|
|
215
|
+
if (url.pathname.endsWith('/events')) {
|
|
216
|
+
return bridge?.pollSessionExists
|
|
217
|
+
? bridgingEventsSseResponse({
|
|
218
|
+
pollSessionExists: bridge.pollSessionExists,
|
|
219
|
+
signal: request.signal,
|
|
220
|
+
})
|
|
221
|
+
: emptyEventsSseResponse()
|
|
222
|
+
}
|
|
112
223
|
return emptySessionDescriptionResponse()
|
|
113
224
|
}
|
|
@@ -71,7 +71,34 @@ export function buildHarnessHost(
|
|
|
71
71
|
harness: AnyHarness,
|
|
72
72
|
options: BuildHostOptions = {},
|
|
73
73
|
): HarnessHost<HarnessHostUser> {
|
|
74
|
-
const persistence =
|
|
74
|
+
const persistence =
|
|
75
|
+
options.persistence ??
|
|
76
|
+
createPrismaPersistence(undefined, {
|
|
77
|
+
// thread 删除清理(任务 4 / 规格 §4.3 修订裁决):sessions store 软删除
|
|
78
|
+
// (tombstone)后回收该 thread 名下全部终端进程——服务端兜底路径,覆盖官方
|
|
79
|
+
// host 删除路径与应用 serverFn 删线程联动(conversations.ts 的
|
|
80
|
+
// host.sessions.delete),两者共用本装配产生的同一 store 实例,无论终端
|
|
81
|
+
// tab 是否还开着。层次约束:persistence store 不 import TerminalManager,
|
|
82
|
+
// 回调由本装配层注入;惰性 import(动态 import)保持 host ↔ terminal-manager
|
|
83
|
+
// 解耦惯例。best-effort:失败只告警,不阻断会话删除(store 内已 try-catch,
|
|
84
|
+
// 此处再兜异步 import / killByThread 的 rejection)。
|
|
85
|
+
onThreadDeleted: (threadId) => {
|
|
86
|
+
try {
|
|
87
|
+
void import('@/server/harness/terminal-manager.server')
|
|
88
|
+
.then(({ getTerminalManager }) =>
|
|
89
|
+
getTerminalManager().killByThread(threadId),
|
|
90
|
+
)
|
|
91
|
+
.catch((err: unknown) => {
|
|
92
|
+
console.warn(
|
|
93
|
+
'[harness] thread 删除清理终端失败(best-effort):',
|
|
94
|
+
err,
|
|
95
|
+
)
|
|
96
|
+
})
|
|
97
|
+
} catch (err: unknown) {
|
|
98
|
+
console.warn('[harness] thread 删除清理终端失败(best-effort):', err)
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
})
|
|
75
102
|
// ownership 租约:桌面单宿主缩短 15s(更快接管,§11-6);云端多实例用官方
|
|
76
103
|
// 默认 30s(Phase 4——误判与接管的平衡,进程内 worker 轮询 + 租约续期均按
|
|
77
104
|
// 官方默认节奏)。
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
//
|
|
5
|
+
// SessionIndexStore 软删除钩子(onThreadDeleted)回归(任务 4,规格 §4.3 修订裁决):
|
|
6
|
+
// thread 软删除(tombstone,deletedAt 置位)后以 threadId 调用清理回调一次——host
|
|
7
|
+
// 装配层注入 killByThread,回收该 thread 名下全部终端进程(服务端兜底路径,无论
|
|
8
|
+
// tab 是否还开着)。persistence store 不 import TerminalManager:回调由上层注入,
|
|
9
|
+
// 本测试只验证 store 的回调机制。
|
|
10
|
+
//
|
|
11
|
+
// 回调入参换算:store delete 的输入是复合 key(SessionIndexKey:tenantId? + threadId),
|
|
12
|
+
// 回调取 threadId 段(终端按 threadId 绑定,tenant 维度对终端管理器无意义)。
|
|
13
|
+
|
|
14
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
15
|
+
import type { PrismaClient } from '@allbluecn/database'
|
|
16
|
+
|
|
17
|
+
import { createPrismaSessionIndexStore } from '../session-index-store.server'
|
|
18
|
+
|
|
19
|
+
/** delete 路径只需 harnessSession.updateMany(其余 store 方法不在本测试面)。 */
|
|
20
|
+
function makeFakeClient(updateMany: ReturnType<typeof vi.fn>): PrismaClient {
|
|
21
|
+
return {
|
|
22
|
+
harnessSession: { updateMany },
|
|
23
|
+
} as unknown as PrismaClient
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('createPrismaSessionIndexStore 软删除钩子(onThreadDeleted)', () => {
|
|
27
|
+
it('传回调:软删除写入后以 key.threadId 调用回调恰一次', async () => {
|
|
28
|
+
const updateMany = vi.fn().mockResolvedValue({ count: 1 })
|
|
29
|
+
const onThreadDeleted = vi.fn()
|
|
30
|
+
const store = createPrismaSessionIndexStore(makeFakeClient(updateMany), {
|
|
31
|
+
onThreadDeleted,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
await store.delete({ tenantId: 'tenant-a', threadId: 'thr_1' })
|
|
35
|
+
|
|
36
|
+
expect(updateMany).toHaveBeenCalledTimes(1)
|
|
37
|
+
expect(updateMany).toHaveBeenCalledWith(
|
|
38
|
+
expect.objectContaining({
|
|
39
|
+
where: { tenantId: 'tenant-a', threadId: 'thr_1' },
|
|
40
|
+
data: expect.objectContaining({ deletedAt: expect.any(Date) }),
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
43
|
+
expect(onThreadDeleted).toHaveBeenCalledTimes(1)
|
|
44
|
+
expect(onThreadDeleted).toHaveBeenCalledWith('thr_1')
|
|
45
|
+
// 回调在 tombstone 落库之后触发(先删后清)
|
|
46
|
+
expect(updateMany.mock.invocationCallOrder[0]).toBeLessThan(
|
|
47
|
+
onThreadDeleted.mock.invocationCallOrder[0]!,
|
|
48
|
+
)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('未传回调:行为不变(tombstone 照常写入,无回调调用)', async () => {
|
|
52
|
+
const updateMany = vi.fn().mockResolvedValue({ count: 1 })
|
|
53
|
+
const store = createPrismaSessionIndexStore(makeFakeClient(updateMany))
|
|
54
|
+
|
|
55
|
+
await expect(
|
|
56
|
+
store.delete({ threadId: 'thr_2' }),
|
|
57
|
+
).resolves.toBeUndefined()
|
|
58
|
+
|
|
59
|
+
expect(updateMany).toHaveBeenCalledTimes(1)
|
|
60
|
+
expect(updateMany).toHaveBeenCalledWith(
|
|
61
|
+
expect.objectContaining({
|
|
62
|
+
where: { tenantId: '', threadId: 'thr_2' },
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('回调抛错不阻断删除(best-effort:delete 正常 resolve)', async () => {
|
|
68
|
+
const updateMany = vi.fn().mockResolvedValue({ count: 1 })
|
|
69
|
+
const onThreadDeleted = vi.fn(() => {
|
|
70
|
+
throw new Error('terminal manager boom')
|
|
71
|
+
})
|
|
72
|
+
const store = createPrismaSessionIndexStore(makeFakeClient(updateMany), {
|
|
73
|
+
onThreadDeleted,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
await expect(
|
|
77
|
+
store.delete({ threadId: 'thr_3' }),
|
|
78
|
+
).resolves.toBeUndefined()
|
|
79
|
+
|
|
80
|
+
expect(updateMany).toHaveBeenCalledTimes(1)
|
|
81
|
+
expect(onThreadDeleted).toHaveBeenCalledTimes(1)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
@@ -25,7 +25,10 @@ import type { PrismaClient } from '@allbluecn/database'
|
|
|
25
25
|
|
|
26
26
|
import { prisma } from '@allbluecn/database'
|
|
27
27
|
import { createPrismaLogStore } from '@/server/harness/persistence/log-store.server'
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
createPrismaSessionIndexStore,
|
|
30
|
+
type SessionIndexStoreOptions,
|
|
31
|
+
} from '@/server/harness/persistence/session-index-store.server'
|
|
29
32
|
import { createPrismaMetadataStore } from '@/server/harness/persistence/metadata-store.server'
|
|
30
33
|
import { createPrismaArtifactStore } from '@/server/harness/persistence/artifact-store.server'
|
|
31
34
|
import { createPrismaBlobStore } from '@/server/harness/persistence/blob-store.server'
|
|
@@ -39,15 +42,21 @@ import { createPrismaBlobStore } from '@/server/harness/persistence/blob-store.s
|
|
|
39
42
|
*
|
|
40
43
|
* @param client Prisma client;省略时用 @allbluecn/database 单例(生产:PG / 桌面
|
|
41
44
|
* PGlite 全局句柄)。集成测试注入一次性 PGlite client 做隔离验证。
|
|
45
|
+
* @param opts sessions store 装配参数(透传 createPrismaSessionIndexStore;当前仅
|
|
46
|
+
* onThreadDeleted——thread 软删除清理钩子,由 host 装配层注入 killByThread,
|
|
47
|
+
* 规格 §4.3 修订裁决:persistence store 不 import TerminalManager)。
|
|
42
48
|
*
|
|
43
49
|
* 五 store 共享同一 prisma client。桌面 PGlite 下为单连接内嵌 PG——store 实现已
|
|
44
50
|
* 遵守「$transaction 回调内只发 tx」铁律(避免单连接死锁 P2028)。
|
|
45
51
|
*/
|
|
46
|
-
export function createPrismaPersistence(
|
|
52
|
+
export function createPrismaPersistence(
|
|
53
|
+
client: PrismaClient = prisma,
|
|
54
|
+
opts: SessionIndexStoreOptions = {},
|
|
55
|
+
): HarnessPersistence {
|
|
47
56
|
return defineAIPersistence({
|
|
48
57
|
stores: {
|
|
49
58
|
log: createPrismaLogStore(client),
|
|
50
|
-
sessions: createPrismaSessionIndexStore(client),
|
|
59
|
+
sessions: createPrismaSessionIndexStore(client, opts),
|
|
51
60
|
metadata: createPrismaMetadataStore(client),
|
|
52
61
|
artifacts: createPrismaArtifactStore(client),
|
|
53
62
|
blobs: createPrismaBlobStore(client),
|
|
@@ -89,8 +89,21 @@ function parseCursor(cursor: string): Cursor {
|
|
|
89
89
|
return { updatedAt, threadId: cursor.slice(split + 1) };
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/** SessionIndexStore 可选装配参数(host 装配层注入,store 不 import 具体管理器)。 */
|
|
93
|
+
export interface SessionIndexStoreOptions {
|
|
94
|
+
/**
|
|
95
|
+
* thread 软删除(tombstone,deletedAt 置位)成功后的清理钩子,以 key.threadId
|
|
96
|
+
* 调用(任务 4 / 规格 §4.3 修订裁决:thread 删除时回收其名下全部终端进程的
|
|
97
|
+
* 服务端兜底路径,无论终端 tab 是否还开着)。best-effort:实现内 try-catch 包裹,
|
|
98
|
+
* 回调异常不阻断删除;终端按 threadId 绑定,故回调只取 threadId 段(tenant 维度
|
|
99
|
+
* 对终端管理器无意义)。
|
|
100
|
+
*/
|
|
101
|
+
onThreadDeleted?: (threadId: string) => void;
|
|
102
|
+
}
|
|
103
|
+
|
|
92
104
|
export function createPrismaSessionIndexStore(
|
|
93
105
|
client: PrismaClient,
|
|
106
|
+
opts: SessionIndexStoreOptions = {},
|
|
94
107
|
): SessionIndexStore {
|
|
95
108
|
const keyOf = (k: SessionIndexKey): Prisma.HarnessSessionWhereUniqueInput => ({
|
|
96
109
|
tenantId_threadId: { tenantId: k.tenantId ?? "", threadId: k.threadId },
|
|
@@ -284,6 +297,19 @@ export function createPrismaSessionIndexStore(
|
|
|
284
297
|
where: { tenantId: key.tenantId ?? "", threadId: key.threadId },
|
|
285
298
|
data: { deletedAt: new Date() },
|
|
286
299
|
});
|
|
300
|
+
// thread 删除清理钩子(§4.3 修订裁决):tombstone 落库成功后触发,
|
|
301
|
+
// best-effort——回调异常只告警不阻断删除(终端进程回收失败由关 tab
|
|
302
|
+
// 主动杀(T3)与 idle 回收兜底,不应让会话删除失败)。
|
|
303
|
+
if (opts.onThreadDeleted) {
|
|
304
|
+
try {
|
|
305
|
+
opts.onThreadDeleted(key.threadId);
|
|
306
|
+
} catch (err: unknown) {
|
|
307
|
+
console.warn(
|
|
308
|
+
"[harness] onThreadDeleted 清理钩子异常(不阻断删除):",
|
|
309
|
+
err,
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
287
313
|
},
|
|
288
314
|
};
|
|
289
315
|
}
|
|
@@ -26,7 +26,7 @@ import type { PatchLine } from "@allbluecn/dsh-compat";
|
|
|
26
26
|
import { assembleAppPlugins } from "../assemble-app";
|
|
27
27
|
import { writeUserHarnessPatch } from "../../profile";
|
|
28
28
|
|
|
29
|
-
/** 内置域 patch id(canonical;plan 域任务 14 增挂 →
|
|
29
|
+
/** 内置域 patch id(canonical;plan 域任务 14 增挂、agent-terminal 任务 10/11 增挂 → 九域 34 工具)。 */
|
|
30
30
|
const ALL_DOMAIN_IDS = [
|
|
31
31
|
"allblue/knowledge",
|
|
32
32
|
"allblue/project",
|
|
@@ -36,9 +36,10 @@ const ALL_DOMAIN_IDS = [
|
|
|
36
36
|
"allblue/design",
|
|
37
37
|
"allblue/task",
|
|
38
38
|
"allblue/plan",
|
|
39
|
+
"allblue/agent-terminal",
|
|
39
40
|
];
|
|
40
41
|
|
|
41
|
-
/** 禁用 story 后仍应激活的域(
|
|
42
|
+
/** 禁用 story 后仍应激活的域(34→30,禁用域 4 工具移除——F4-1 起 story 含写面 2+2)。 */
|
|
42
43
|
const SIX_DOMAINS_EXCEPT_STORY = ALL_DOMAIN_IDS.filter((d) => d !== "allblue/story");
|
|
43
44
|
|
|
44
45
|
let dir: string;
|
|
@@ -75,21 +76,26 @@ async function collectContributedToolNames(): Promise<string[]> {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
describe("F2-6 用户 patch 禁用内置插件:app 组装层端到端(assembleAppPlugins)", () => {
|
|
78
|
-
it("用例 B(回归基线):无用户 patch →
|
|
79
|
+
it("用例 B(回归基线):无用户 patch → 九域全激活、34 工具(排序后集合不变式)", async () => {
|
|
79
80
|
// 不写 cordis.patch.yml → loadUserHarnessPatch 返回 [] → base 层全启用
|
|
80
81
|
const { plugins, report } = await assembleAppPlugins();
|
|
81
82
|
|
|
82
83
|
const activatedIds = report.activated.map((a) => a.id);
|
|
83
84
|
for (const id of ALL_DOMAIN_IDS) {
|
|
84
|
-
expect(activatedIds,
|
|
85
|
+
expect(activatedIds, `九域 ${id} 应激活`).toContain(id);
|
|
85
86
|
}
|
|
86
87
|
expect(report.disabled).toEqual([]);
|
|
87
|
-
expect(plugins).toHaveLength(
|
|
88
|
+
expect(plugins).toHaveLength(9);
|
|
88
89
|
|
|
89
90
|
const toolNames = await collectContributedToolNames();
|
|
90
|
-
expect(toolNames).toHaveLength(
|
|
91
|
+
expect(toolNames).toHaveLength(34);
|
|
91
92
|
// plan 域 1 工具在产出面(任务 14,P8-1 计划审批 harness 侧)
|
|
92
93
|
expect(toolNames).toContain("plan_submit");
|
|
94
|
+
// agent-terminal 域 8 工具在产出面(任务 10 §6.2 六工具 + 任务 11 §6.3 两 user 工具)
|
|
95
|
+
expect(toolNames).toContain("terminal_open");
|
|
96
|
+
expect(toolNames).toContain("terminal_list");
|
|
97
|
+
expect(toolNames).toContain("user_terminal_read");
|
|
98
|
+
expect(toolNames).toContain("user_terminal_list");
|
|
93
99
|
// knowledge 域 3 工具在产出面(F4-5 起含 document_action 收编面)
|
|
94
100
|
expect(toolNames).toContain("document_action");
|
|
95
101
|
// project 域 3 工具在产出面(F4-8 起含 project_delete 删面)
|
|
@@ -114,7 +120,7 @@ describe("F2-6 用户 patch 禁用内置插件:app 组装层端到端(assemb
|
|
|
114
120
|
expect(new Set(toolNames).size).toBe(toolNames.length);
|
|
115
121
|
});
|
|
116
122
|
|
|
117
|
-
it("用例 A(禁用实证):patch disabled:true 禁用 allblue/story → report.disabled 含该域、story 工具消失、其余域照常、
|
|
123
|
+
it("用例 A(禁用实证):patch disabled:true 禁用 allblue/story → report.disabled 含该域、story 工具消失、其余域照常、34→30", async () => {
|
|
118
124
|
const userPatch: PatchLine[] = [{ id: "allblue/story", disabled: true }];
|
|
119
125
|
await writeUserHarnessPatch(userPatch);
|
|
120
126
|
|
|
@@ -130,16 +136,18 @@ describe("F2-6 用户 patch 禁用内置插件:app 组装层端到端(assemb
|
|
|
130
136
|
for (const id of SIX_DOMAINS_EXCEPT_STORY) {
|
|
131
137
|
expect(activatedIds, `其余域 ${id} 应照常激活`).toContain(id);
|
|
132
138
|
}
|
|
133
|
-
expect(plugins).toHaveLength(
|
|
139
|
+
expect(plugins).toHaveLength(8);
|
|
134
140
|
|
|
135
|
-
// ④ 产出面:story 工具消失、其余域
|
|
141
|
+
// ④ 产出面:story 工具消失、其余域 30 工具仍在(排序后集合 = 34 减 story 四工具)
|
|
136
142
|
const toolNames = await collectContributedToolNames();
|
|
137
143
|
expect(toolNames).not.toContain("story_search");
|
|
138
144
|
expect(toolNames).not.toContain("story_get");
|
|
139
145
|
expect(toolNames).not.toContain("story_create");
|
|
140
146
|
expect(toolNames).not.toContain("story_update");
|
|
141
|
-
expect(toolNames).toHaveLength(
|
|
147
|
+
expect(toolNames).toHaveLength(30);
|
|
142
148
|
expect(toolNames).toContain("plan_submit");
|
|
149
|
+
expect(toolNames).toContain("terminal_open");
|
|
150
|
+
expect(toolNames).toContain("user_terminal_list");
|
|
143
151
|
for (const name of [
|
|
144
152
|
"knowledge_search",
|
|
145
153
|
"reindex_knowledge_base",
|
|
@@ -168,7 +176,7 @@ describe("F2-6 用户 patch 禁用内置插件:app 组装层端到端(assemb
|
|
|
168
176
|
expect(new Set(toolNames).size).toBe(toolNames.length);
|
|
169
177
|
});
|
|
170
178
|
|
|
171
|
-
it("用例 C(启停可逆):先 disabled:true 再 disabled:false → allblue/story 回到激活、
|
|
179
|
+
it("用例 C(启停可逆):先 disabled:true 再 disabled:false → allblue/story 回到激活、34 工具复原", async () => {
|
|
172
180
|
// 第一步:禁用
|
|
173
181
|
await writeUserHarnessPatch([{ id: "allblue/story", disabled: true }]);
|
|
174
182
|
const { report } = await assembleAppPlugins();
|
|
@@ -181,17 +189,17 @@ describe("F2-6 用户 patch 禁用内置插件:app 组装层端到端(assemb
|
|
|
181
189
|
const activatedIds = reenabled.activated.map((a) => a.id);
|
|
182
190
|
expect(activatedIds, "重新启用后 allblue/story 应回到激活").toContain("allblue/story");
|
|
183
191
|
expect(reenabled.disabled.map((d) => d.id)).not.toContain("allblue/story");
|
|
184
|
-
expect(plugins).toHaveLength(
|
|
192
|
+
expect(plugins).toHaveLength(9);
|
|
185
193
|
|
|
186
194
|
const toolNames = await collectContributedToolNames();
|
|
187
|
-
expect(toolNames).toHaveLength(
|
|
195
|
+
expect(toolNames).toHaveLength(34);
|
|
188
196
|
expect(toolNames).toContain("story_search");
|
|
189
197
|
expect(toolNames).toContain("story_get");
|
|
190
198
|
expect(toolNames).toContain("story_create");
|
|
191
199
|
expect(toolNames).toContain("story_update");
|
|
192
200
|
});
|
|
193
201
|
|
|
194
|
-
it("用例 D(G2 disabledTools 过滤):config.disabledTools=['story_get'] → story 域仍激活、产出面
|
|
202
|
+
it("用例 D(G2 disabledTools 过滤):config.disabledTools=['story_get'] → story 域仍激活、产出面 34→33、story_get 消失而其余三工具仍在", async () => {
|
|
195
203
|
// 用户 patch 覆写 config(非 disabled 整域,仅禁用单个工具)。
|
|
196
204
|
// applyPatches 语义:同 id 行的后层 config 整体替换前层(不深合并),用户层覆写
|
|
197
205
|
// base 层的 config → story 工厂收到 { disabledTools: ['story_get'] }。
|
|
@@ -209,15 +217,15 @@ describe("F2-6 用户 patch 禁用内置插件:app 组装层端到端(assemb
|
|
|
209
217
|
const activatedIds = report.activated.map((a) => a.id);
|
|
210
218
|
expect(activatedIds, "story 域应仍激活(仅禁用单工具)").toContain("allblue/story");
|
|
211
219
|
expect(report.disabled.map((d) => d.id)).not.toContain("allblue/story");
|
|
212
|
-
expect(plugins).toHaveLength(
|
|
220
|
+
expect(plugins).toHaveLength(9);
|
|
213
221
|
|
|
214
|
-
// 产出面:story_get 消失、story 其余三工具仍在、总工具数
|
|
222
|
+
// 产出面:story_get 消失、story 其余三工具仍在、总工具数 34→33。
|
|
215
223
|
const toolNames = await collectContributedToolNames();
|
|
216
224
|
expect(toolNames, "story_get 应被 disabledTools 滤除").not.toContain("story_get");
|
|
217
225
|
expect(toolNames).toContain("story_search");
|
|
218
226
|
expect(toolNames).toContain("story_create");
|
|
219
227
|
expect(toolNames).toContain("story_update");
|
|
220
|
-
expect(toolNames).toHaveLength(
|
|
228
|
+
expect(toolNames).toHaveLength(33);
|
|
221
229
|
// 无重名(去重池 + 产出面双保险)。
|
|
222
230
|
expect(new Set(toolNames).size).toBe(toolNames.length);
|
|
223
231
|
});
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
// Copyright (C) 2026 AllBlue Contributors
|
|
4
4
|
//
|
|
5
5
|
// harness 工具风险分类审计(F4-6 §1.3 needsApproval 全量 + §1.4 风险分类落档,
|
|
6
|
-
// Ruling P7;任务 14 plan_submit +1
|
|
6
|
+
// Ruling P7;任务 14 plan_submit +1、任务 10 agent-terminal 六工具 +6、任务 11
|
|
7
|
+
// user_terminal_list/read 两工具 +2 = 36)。机制设计:
|
|
7
8
|
// - 分类真源 = server/harness/tool-risk.ts 的 HARNESS_TOOL_RISK(覆盖 harness
|
|
8
|
-
// 全部自有工具:七域 25 + plugin_manager + image_gen + plan_submit
|
|
9
|
+
// 全部自有工具:七域 25 + plugin_manager + image_gen + plan_submit
|
|
10
|
+
// + agent-terminal 八工具(六 + user_terminal 两)= 36);
|
|
9
11
|
// - 双向精确覆盖断言:新增工具漏登记分类 → 红;分类表残留已删工具 → 红;
|
|
10
12
|
// - 全部分级工具不声明 needsApproval:审批统一由 permissions rules 承接
|
|
11
13
|
// (2026-11-14 烟测语义,plan_submit 的 'approval' 分类也走 ask 规则);
|
|
@@ -24,10 +26,17 @@ import { taskTools } from '../builtin/task.plugin'
|
|
|
24
26
|
import { planTools } from '../builtin/plan.plugin'
|
|
25
27
|
import { pluginManagerTools } from '../plugin-manager.plugin'
|
|
26
28
|
import { mediaTools } from '../builtin/media.plugin'
|
|
29
|
+
import { agentTerminalToolNames } from '../builtin/agent-terminal.plugin'
|
|
27
30
|
import { HARNESS_TOOL_RISK } from '../../tool-risk'
|
|
28
31
|
|
|
29
|
-
/**
|
|
30
|
-
|
|
32
|
+
/**
|
|
33
|
+
* harness 全部自有工具(七域 + plan 域 canonical 导出 + 系统插件 + media
|
|
34
|
+
* + agent-terminal 八工具)。agent-terminal 工具体在 setup(ctx) 内构建(emit
|
|
35
|
+
* 接线需要 setup ctx 闭包),无模块级 canonical tools 数组——以名字常量
|
|
36
|
+
* 登记({name} 形状满足本文件的 name/needsApproval 断言面;任务 11 起常量
|
|
37
|
+
* 含 user_terminal_read/list 两名)。
|
|
38
|
+
*/
|
|
39
|
+
const allTools: ReadonlyArray<{ name: string; needsApproval?: unknown }> = [
|
|
31
40
|
...knowledgeTools,
|
|
32
41
|
...projectTools,
|
|
33
42
|
...storyTools,
|
|
@@ -38,13 +47,14 @@ const allTools = [
|
|
|
38
47
|
...planTools,
|
|
39
48
|
...pluginManagerTools,
|
|
40
49
|
...mediaTools,
|
|
50
|
+
...agentTerminalToolNames.map((name) => ({ name })),
|
|
41
51
|
]
|
|
42
52
|
|
|
43
53
|
describe('harness 工具风险分类审计(F4-6 §1.3/§1.4,Ruling P7)', () => {
|
|
44
|
-
it('分类表双向精确覆盖:
|
|
54
|
+
it('分类表双向精确覆盖:36 个工具全部登记,无残留键(任务 11 user_terminal_* 已入表)', () => {
|
|
45
55
|
const toolNames = allTools.map((t) => t.name).sort()
|
|
46
56
|
const classified = Object.keys(HARNESS_TOOL_RISK).sort()
|
|
47
|
-
expect(toolNames).toHaveLength(
|
|
57
|
+
expect(toolNames).toHaveLength(36)
|
|
48
58
|
// 双向:新工具未登记分类 → 红;分类表残留已删工具 → 红
|
|
49
59
|
expect(classified).toEqual(toolNames)
|
|
50
60
|
})
|
|
@@ -44,6 +44,10 @@ import {
|
|
|
44
44
|
import { createTaskPlugin, taskTools } from '@/server/harness/plugins/builtin/task.plugin'
|
|
45
45
|
import { createPlanPlugin, planTools } from '@/server/harness/plugins/builtin/plan.plugin'
|
|
46
46
|
import { createMediaPlugin, mediaTools } from '@/server/harness/plugins/builtin/media.plugin'
|
|
47
|
+
import {
|
|
48
|
+
agentTerminalToolNames,
|
|
49
|
+
createAgentTerminalPlugin,
|
|
50
|
+
} from '@/server/harness/plugins/builtin/agent-terminal.plugin'
|
|
47
51
|
import { builtinBasePatch } from '@/server/harness/plugins/base-patch'
|
|
48
52
|
import { createLazyL1ServicesFactory } from '@/server/harness/cordis-l1.server'
|
|
49
53
|
import {
|
|
@@ -145,6 +149,14 @@ const builtinFactories: Record<string, BuiltinFactory> = {
|
|
|
145
149
|
toolNames: mediaTools.map((t) => t.name),
|
|
146
150
|
toolNamesFor: (config) => filterDisabled(mediaTools.map((t) => t.name), config),
|
|
147
151
|
},
|
|
152
|
+
// agent-terminal 六工具:工具体在 setup(ctx) 内构建(T11 emit 接线),无模块级
|
|
153
|
+
// canonical tools 数组——toolNames/toolNamesFor 以名字常量消费(任务 10)
|
|
154
|
+
'@allblue/agent-terminal': {
|
|
155
|
+
kind: 'builtin',
|
|
156
|
+
create: (config) => createAgentTerminalPlugin(config as never),
|
|
157
|
+
toolNames: agentTerminalToolNames,
|
|
158
|
+
toolNamesFor: (config) => filterDisabled(agentTerminalToolNames, config),
|
|
159
|
+
},
|
|
148
160
|
}
|
|
149
161
|
|
|
150
162
|
/**
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// AllBlue - 理想之海
|
|
3
3
|
// Copyright (C) 2026 AllBlue Contributors
|
|
4
4
|
//
|
|
5
|
-
// 内置 base patch 层(F2-2b,设计 §4.2.1「两类插件一条管线」;七域 + plan
|
|
5
|
+
// 内置 base patch 层(F2-2b,设计 §4.2.1「两类插件一条管线」;七域 + plan(任务 14)
|
|
6
|
+
// + agent-terminal(任务 10,§6.2 六工具))。
|
|
6
7
|
//
|
|
7
8
|
// 编译期常量:声明内置插件的解析名 + 默认 config,作为 assembleProfile 的 base 层
|
|
8
9
|
// (最底优先层,先于用户 patch / DSH 插件追加层)。用户 patch 可定向覆写某行
|
|
@@ -11,10 +12,15 @@
|
|
|
11
12
|
//
|
|
12
13
|
// `name` 用 `@allblue/*` 标识——define.server 的 resolver 按此键映射到静态 config
|
|
13
14
|
// 工厂(`createXxxPlugin`)。`config: {}` = 默认全启用(工厂内 disabledTools 缺省)。
|
|
15
|
+
//
|
|
16
|
+
// ⚠ 每个内置插件**必须**同时有 builtinFactories 表条目(assemble-app.ts)与本文件
|
|
17
|
+
// patch 行——装配只遍历 patch 行(dsh-compat assemble.ts),只加工厂条目插件不会被
|
|
18
|
+
// 激活(media 域曾是有工厂无 patch 行的不可达先例;agent-terminal 的装配断言见
|
|
19
|
+
// agent-terminal.plugin.test.ts,复审问题 #2)。
|
|
14
20
|
|
|
15
21
|
import type { PatchLine } from '@allbluecn/dsh-compat'
|
|
16
22
|
|
|
17
|
-
/**
|
|
23
|
+
/** 内置九域 base patch 层(编译期常量,base 优先层;plan 任务 14 / agent-terminal 任务 10 增挂)。 */
|
|
18
24
|
export const builtinBasePatch: PatchLine[] = [
|
|
19
25
|
{ id: 'allblue/knowledge', name: '@allblue/knowledge', config: {} },
|
|
20
26
|
{ id: 'allblue/project', name: '@allblue/project', config: {} },
|
|
@@ -24,6 +30,7 @@ export const builtinBasePatch: PatchLine[] = [
|
|
|
24
30
|
{ id: 'allblue/design', name: '@allblue/design', config: {} },
|
|
25
31
|
{ id: 'allblue/task', name: '@allblue/task', config: {} },
|
|
26
32
|
{ id: 'allblue/plan', name: '@allblue/plan', config: {} },
|
|
33
|
+
{ id: 'allblue/agent-terminal', name: '@allblue/agent-terminal', config: {} },
|
|
27
34
|
]
|
|
28
35
|
|
|
29
36
|
/**
|