@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/web-app",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -195,7 +195,8 @@
|
|
|
195
195
|
"@vercel/speed-insights": "^2.0.0",
|
|
196
196
|
"@vscode/ripgrep": "1.18.0",
|
|
197
197
|
"@xterm/addon-fit": "^0.11.0",
|
|
198
|
-
"@xterm/addon-
|
|
198
|
+
"@xterm/addon-serialize": "0.14.0",
|
|
199
|
+
"@xterm/headless": "6.0.0",
|
|
199
200
|
"@xterm/xterm": "^6.0.0",
|
|
200
201
|
"@zumer/snapdom": "^2.12.9",
|
|
201
202
|
"ai": "^7.0.172",
|
|
@@ -232,7 +233,7 @@
|
|
|
232
233
|
"nanoid": "^5.1.11",
|
|
233
234
|
"next-themes": "^0.4.6",
|
|
234
235
|
"nitro": "3.0.260903-beta",
|
|
235
|
-
"node-pty": "
|
|
236
|
+
"node-pty": "1.2.0-beta.15",
|
|
236
237
|
"nodemailer": "^10.0.3",
|
|
237
238
|
"ogl": "^1.0.11",
|
|
238
239
|
"partial-json": "^0.1.7",
|
|
@@ -220,6 +220,49 @@ describe("panelVersion 递增触发快照变化", () => {
|
|
|
220
220
|
})
|
|
221
221
|
})
|
|
222
222
|
|
|
223
|
+
describe("clearTabInstanceId(T14 reopen 接缝,I-1)", () => {
|
|
224
|
+
it("清除 tab.instanceId(换新 state 引用 + panelVersion +1 + write-through 落盘)", () => {
|
|
225
|
+
const reg = createDockRegistry()
|
|
226
|
+
reg.registerKind(makeKind({ kind: "terminal", multiple: true, maxInstances: 8 }))
|
|
227
|
+
reg.switchThread("ci1")
|
|
228
|
+
reg.openKind("terminal", { instanceId: "term_dead", title: "agent 终端" })
|
|
229
|
+
const tab = Object.values(reg.getState().tabs).find((t) => t.kind === "terminal")!
|
|
230
|
+
expect(tab.instanceId).toBe("term_dead")
|
|
231
|
+
const s0 = reg.getState()
|
|
232
|
+
const v0 = s0.panelVersion
|
|
233
|
+
|
|
234
|
+
reg.clearTabInstanceId(tab.id)
|
|
235
|
+
|
|
236
|
+
const after = reg.getState().tabs[tab.id]
|
|
237
|
+
expect(after).toBeDefined()
|
|
238
|
+
// 不变量:reopen 后 tab 不携带 instanceId(回归「用户 tab 无 instanceId」)
|
|
239
|
+
expect("instanceId" in after).toBe(false)
|
|
240
|
+
expect(after.instanceId).toBeUndefined()
|
|
241
|
+
// 其余元数据保留
|
|
242
|
+
expect(after.kind).toBe("terminal")
|
|
243
|
+
expect(after.title).toBe("agent 终端")
|
|
244
|
+
// 换新 state 引用触发订阅重渲染(useSyncExternalStore 快照语义)
|
|
245
|
+
expect(reg.getState()).not.toBe(s0)
|
|
246
|
+
expect(reg.getState().panelVersion).toBe(v0 + 1)
|
|
247
|
+
// write-through:持久化载荷不再含 instanceId
|
|
248
|
+
const raw = window.localStorage.getItem(dockStorageKey("ci1")!)
|
|
249
|
+
expect(raw).not.toBeNull()
|
|
250
|
+
expect(JSON.parse(raw!).tabs[tab.id].instanceId).toBeUndefined()
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it("无 instanceId 的 tab / 不存在的 tab → no-op(换引用 + 抛错防护)", () => {
|
|
254
|
+
const reg = createDockRegistry()
|
|
255
|
+
reg.registerKind(makeKind({ kind: "terminal", multiple: true }))
|
|
256
|
+
reg.switchThread("ci2")
|
|
257
|
+
reg.openKind("terminal")
|
|
258
|
+
const tab = Object.values(reg.getState().tabs).find((t) => t.kind === "terminal")!
|
|
259
|
+
const before = reg.getState()
|
|
260
|
+
reg.clearTabInstanceId(tab.id)
|
|
261
|
+
expect(reg.getState()).toBe(before) // 同值 no-op 不换引用
|
|
262
|
+
expect(() => reg.clearTabInstanceId("ghost")).not.toThrow()
|
|
263
|
+
})
|
|
264
|
+
})
|
|
265
|
+
|
|
223
266
|
describe("closeTab 五规则副作用描述", () => {
|
|
224
267
|
it("关最后一个非 guide docked tab → collapsePanel/exitFullscreen 描述", () => {
|
|
225
268
|
const reg = createDockRegistry()
|
|
@@ -128,6 +128,26 @@ describe('useHarnessChatAdapter(T2.8 适配层)', () => {
|
|
|
128
128
|
expect(idle.result.current.connectionStatus).toBe('connected')
|
|
129
129
|
})
|
|
130
130
|
|
|
131
|
+
it('空闲期重连静默(2026-11-21 对齐 DSH):reconnecting 仅在 running 才报 connecting', () => {
|
|
132
|
+
// 空闲会话(含空 entry 桥接交接的 open→reconnecting→open 闪断)重连是后台
|
|
133
|
+
// 自愈,指示灯必须保持隐藏(connected → workbench-page 映射 hidden)。
|
|
134
|
+
const idle = renderHook(() =>
|
|
135
|
+
useHarnessChatAdapter(
|
|
136
|
+
makeFakeSession({ status: 'idle', connection: 'reconnecting' }),
|
|
137
|
+
),
|
|
138
|
+
)
|
|
139
|
+
expect(idle.result.current.connectionStatus).toBe('connected')
|
|
140
|
+
|
|
141
|
+
// requires_action(审批等待)掉线同样静默:审批卡已落客户端 store,
|
|
142
|
+
// approve 结果经重连后的流补投。
|
|
143
|
+
const acting = renderHook(() =>
|
|
144
|
+
useHarnessChatAdapter(
|
|
145
|
+
makeFakeSession({ status: 'requires_action', connection: 'reconnecting' }),
|
|
146
|
+
),
|
|
147
|
+
)
|
|
148
|
+
expect(acting.result.current.connectionStatus).toBe('connected')
|
|
149
|
+
})
|
|
150
|
+
|
|
131
151
|
it('interrupts:approvals/interrupts/questions 保 kind 分类(F5-2 三档选举原料)', () => {
|
|
132
152
|
const session = makeFakeSession({
|
|
133
153
|
approvals: [{ id: 'ap1', tool: 'bash', args: {}, approve: vi.fn(), reject: vi.fn() }],
|
package/src/components/harness/conversation-panel/messages/harness-chain/use-agent-terminals.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
// T13 旁路插件事件 → roster query invalidate(设计 §6.6/§7.2):包一层 harness
|
|
19
|
+
// client.events()(仿 use-file-changes.ts 同款 wrap),遇 AgentTerminalOpened /
|
|
20
|
+
// AgentTerminalClosed 插件事件(CUSTOM name='harness.plugin.event' 信封,value =
|
|
21
|
+
// { plugin, name, value })时 invalidate ['harnessTerminalRoster'] 前缀——roster
|
|
22
|
+
// query(10s 轮询)立即重取,DockSurface 的 reconcile effect 即刻开/关 agent tab,
|
|
23
|
+
// 不必等下一个轮询周期。
|
|
24
|
+
//
|
|
25
|
+
// 事件名镜像(服务端 agent-terminal.plugin.ts 的 createPluginEvent 名,客户端不
|
|
26
|
+
// 跨界 import server 模块——eslint TL-01 + bundle 纪律;wire 名对账由服务端
|
|
27
|
+
// agent-terminal.plugin.test.ts 的「typed 通道名」断言锁定,本处改名须连带):
|
|
28
|
+
// - allblue/agent-terminal:opened,载荷 { terminalId, title }
|
|
29
|
+
// - allblue/agent-terminal:closed,载荷 { terminalId }(仅真杀 outcome='closed'
|
|
30
|
+
// 才发;接管除名 left-for-user 不发——tab 不关)
|
|
31
|
+
//
|
|
32
|
+
// 直接 invalidate 而非旁路 store:消费方只关心「事件发生了」(触发重取),不消费
|
|
33
|
+
// 载荷内容(开/关指令由 roster 重建,事件只做加速)——store→hook→invalidate 的
|
|
34
|
+
// 间接层无增益,故经 query-client-seam 单例直呼(与 harness-workbench-page 同源
|
|
35
|
+
// client,router.tsx 装配)。挂载点:use-harness-session 的包装链(compaction →
|
|
36
|
+
// model-retry → file-changes → 本层)。
|
|
37
|
+
|
|
38
|
+
import type { SessionEvent } from '@tanstack/ai-harness'
|
|
39
|
+
import type { SessionViewSource } from '@tanstack/ai-harness/view'
|
|
40
|
+
import { getQueryClient } from '@/lib/query-client-seam'
|
|
41
|
+
import { HARNESS_TERMINAL_ROSTER_QUERY_KEY } from '@/lib/queries/harness-terminal'
|
|
42
|
+
|
|
43
|
+
/** wire 事件名镜像:AgentTerminalOpened(服务端 createPluginEvent 名)。 */
|
|
44
|
+
const AGENT_TERMINAL_OPENED = 'allblue/agent-terminal:opened'
|
|
45
|
+
/** wire 事件名镜像:AgentTerminalClosed(服务端 createPluginEvent 名)。 */
|
|
46
|
+
const AGENT_TERMINAL_CLOSED = 'allblue/agent-terminal:closed'
|
|
47
|
+
|
|
48
|
+
/** 旁路事件 sightings(判别联合,readAgentTerminalEvent 的产出)。 */
|
|
49
|
+
export type AgentTerminalEventSight =
|
|
50
|
+
| { kind: 'opened'; terminalId: string; title: string }
|
|
51
|
+
| { kind: 'closed'; terminalId: string }
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 从 CUSTOM 事件抽 AgentTerminalOpened/Closed sighting(fail-closed:信封/载荷
|
|
55
|
+
* 结构不符或非终端事件 → null)。插件事件 wire 信封:CUSTOM name=
|
|
56
|
+
* 'harness.plugin.event',value = { plugin, name, value }(toolcall-diff 同口径;
|
|
57
|
+
* name 全局唯一带 'allblue/agent-terminal:' 前缀,plugin 字段不再重复校验)。
|
|
58
|
+
*/
|
|
59
|
+
export function readAgentTerminalEvent(event: SessionEvent['event']): AgentTerminalEventSight | null {
|
|
60
|
+
if (event.type !== 'CUSTOM') return null
|
|
61
|
+
if (event.name !== 'harness.plugin.event') return null
|
|
62
|
+
const value = (event as { value?: unknown }).value
|
|
63
|
+
if (!value || typeof value !== 'object') return null
|
|
64
|
+
const record = value as { name?: unknown; value?: unknown }
|
|
65
|
+
const inner = record.value
|
|
66
|
+
if (!inner || typeof inner !== 'object') return null
|
|
67
|
+
if (record.name === AGENT_TERMINAL_OPENED) {
|
|
68
|
+
const payload = inner as { terminalId?: unknown; title?: unknown }
|
|
69
|
+
if (typeof payload.terminalId !== 'string' || payload.terminalId.length === 0) return null
|
|
70
|
+
// title 服务端已兜底 'shell',此处仍防缺省(跨版本 wire 容错)
|
|
71
|
+
return {
|
|
72
|
+
kind: 'opened',
|
|
73
|
+
terminalId: payload.terminalId,
|
|
74
|
+
title: typeof payload.title === 'string' && payload.title.length > 0 ? payload.title : 'shell',
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (record.name === AGENT_TERMINAL_CLOSED) {
|
|
78
|
+
const payload = inner as { terminalId?: unknown }
|
|
79
|
+
if (typeof payload.terminalId !== 'string' || payload.terminalId.length === 0) return null
|
|
80
|
+
return { kind: 'closed', terminalId: payload.terminalId }
|
|
81
|
+
}
|
|
82
|
+
return null
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 包一层 session source(HarnessClient 满足 SessionViewSource):events() 流内遇
|
|
87
|
+
* AgentTerminalOpened/Closed 时 invalidate roster query 前缀(原事件照旧 yield 给
|
|
88
|
+
* view,互不影响)。source 为 null(空态)时原样返回。泛型保持入参类型,使
|
|
89
|
+
* createSessionView(wrapped) 的类型与原 client 一致。
|
|
90
|
+
*/
|
|
91
|
+
export function wrapClientWithAgentTerminals<TSource extends SessionViewSource>(
|
|
92
|
+
source: TSource | null,
|
|
93
|
+
): TSource | null {
|
|
94
|
+
if (!source) return null
|
|
95
|
+
const wrapped = {
|
|
96
|
+
...source,
|
|
97
|
+
events: (eventOptions?: { from?: string; signal?: AbortSignal }) =>
|
|
98
|
+
injectAgentTerminalEvents(source, eventOptions ?? {}),
|
|
99
|
+
} as unknown as TSource
|
|
100
|
+
return wrapped
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 异步生成器:透传原事件给 view,旁路遇终端插件事件即 invalidate roster query。 */
|
|
104
|
+
async function* injectAgentTerminalEvents(
|
|
105
|
+
source: SessionViewSource,
|
|
106
|
+
eventOptions: { from?: string; signal?: AbortSignal },
|
|
107
|
+
): AsyncGenerator<SessionEvent> {
|
|
108
|
+
for await (const entry of source.events(eventOptions ?? {})) {
|
|
109
|
+
yield entry
|
|
110
|
+
const sight = readAgentTerminalEvent(entry.event)
|
|
111
|
+
if (!sight) continue
|
|
112
|
+
// 前缀失效(threadId 段位不参与)——现网单工作台单活动会话,命中当前 roster
|
|
113
|
+
// query;切线程后的旧 query 无观察者,标记 stale 无代价。
|
|
114
|
+
getQueryClient().invalidateQueries({ queryKey: [HARNESS_TERMINAL_ROSTER_QUERY_KEY] })
|
|
115
|
+
}
|
|
116
|
+
}
|
package/src/components/harness/conversation-panel/messages/harness-chain/use-harness-chat-adapter.ts
CHANGED
|
@@ -191,10 +191,22 @@ function mapStatus(status: 'idle' | 'running' | 'requires_action'): LegacyChatSt
|
|
|
191
191
|
return 'ready'
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
/**
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
/**
|
|
195
|
+
* harness connection → 旧 ConnectionStatus。
|
|
196
|
+
*
|
|
197
|
+
* 空闲期重连静默(2026-11-21 用户裁决,对齐 DSH):官方 client.events 对流结束
|
|
198
|
+
* 无限退避重连(1s→30s 封顶),空闲会话的重连是后台自愈、不丢任何可见状态,
|
|
199
|
+
* 指示灯只在「运行中掉线」(丢流式输出,用户正在等的那段回复可能中断)时亮。
|
|
200
|
+
* 发送路径的失败经 error 字段另行反馈(workbench-page 的 error 分支),不依赖
|
|
201
|
+
* 连接灯;requires_action(审批等待)掉线不亮——审批卡是客户端已落 store 的
|
|
202
|
+
* 状态,approve 结果经重连后的流补投,无需报警。
|
|
203
|
+
*/
|
|
204
|
+
function mapConnection(
|
|
205
|
+
connection: 'open' | 'reconnecting' | 'closed',
|
|
206
|
+
status: 'idle' | 'running' | 'requires_action',
|
|
207
|
+
): LegacyConnectionStatus {
|
|
208
|
+
if (connection === 'reconnecting' && status === 'running') return 'connecting'
|
|
209
|
+
// open(正常)/ closed(未启动或已释放)/ 空闲期 reconnecting:指示灯隐藏,不报警
|
|
198
210
|
return 'connected'
|
|
199
211
|
}
|
|
200
212
|
|
|
@@ -473,7 +485,7 @@ export function useHarnessChatAdapter(session: HarnessSession): HarnessChatLike
|
|
|
473
485
|
isLoading: status === 'running',
|
|
474
486
|
error,
|
|
475
487
|
status: mapStatus(status),
|
|
476
|
-
connectionStatus: mapConnection(connection),
|
|
488
|
+
connectionStatus: mapConnection(connection, status),
|
|
477
489
|
runId: null,
|
|
478
490
|
contextTokens,
|
|
479
491
|
sessionUsage,
|
package/src/components/harness/conversation-panel/messages/harness-chain/use-harness-session.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { clearCompactionNotices, useCompactionNotices, wrapClientWithCompactionN
|
|
|
31
31
|
import { collectTerminalEntries } from './terminal-entries'
|
|
32
32
|
import { clearModelRetryNotices, useModelRetryNotices, wrapClientWithModelRetryNotices } from './use-model-retry-notices'
|
|
33
33
|
import { clearWorkspaceFileChanges, wrapClientWithFileChanges } from './use-file-changes'
|
|
34
|
+
import { wrapClientWithAgentTerminals } from './use-agent-terminals'
|
|
34
35
|
|
|
35
36
|
/** 会话实例(client + view 成对生命周期管理;view 持有 SSE 连接,dispose 断流)。 */
|
|
36
37
|
interface HarnessSessionInstance {
|
|
@@ -99,7 +100,9 @@ export function useHarnessSession({ threadId }: UseHarnessSessionOptions) {
|
|
|
99
100
|
const modelRetryWrapped = wrapClientWithModelRetryNotices(compactionWrapped)
|
|
100
101
|
// P2-B 工作区文件联动:再包一层,遇 FileChanged 插件事件抽轻量切片进旁路 store
|
|
101
102
|
// (原事件照旧透传,view 不受影响)。
|
|
102
|
-
|
|
103
|
+
// T13 agent 终端联动:最外层再包一层,遇 AgentTerminalOpened/Closed 插件事件
|
|
104
|
+
// invalidate roster query(DockSurface reconcile 即刻开/关 agent tab)。
|
|
105
|
+
const client = wrapClientWithAgentTerminals(wrapClientWithFileChanges(modelRetryWrapped))
|
|
103
106
|
// rawClient 非空(threadId 就位),wrapped 亦非空——兜底断言以满足 createSessionView。
|
|
104
107
|
if (!client) {
|
|
105
108
|
setSession(null)
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { describe, expect, it } from 'vitest'
|
|
13
13
|
import { m } from '@/paraglide/messages.js'
|
|
14
14
|
import type { AgentPart, MediaPart, ToolCallPart, ViewPart } from '@tanstack/ai-harness/view'
|
|
15
|
-
import { collectToolRuns, taskStepsOf } from '../tool-run'
|
|
15
|
+
import { collectToolRuns, HARNESS_TOOL_KIND, taskStepsOf } from '../tool-run'
|
|
16
16
|
|
|
17
17
|
let seq = 0
|
|
18
18
|
function toolCall(
|
|
@@ -200,3 +200,28 @@ describe('taskStepsOf(Task 步骤投影)', () => {
|
|
|
200
200
|
expect(steps[1]).toEqual({ title: m.harness_tool_bash({ target: 'tsc' }), running: true })
|
|
201
201
|
})
|
|
202
202
|
})
|
|
203
|
+
|
|
204
|
+
describe('HARNESS_TOOL_KIND(agent 终端工具映射,2026-11-20 T15)', () => {
|
|
205
|
+
it('agent 终端六工具 + 用户终端只读两工具 → terminal(复用 bash 形态)', () => {
|
|
206
|
+
const terminalTools = [
|
|
207
|
+
'terminal_open',
|
|
208
|
+
'terminal_send',
|
|
209
|
+
'terminal_read',
|
|
210
|
+
'terminal_signal',
|
|
211
|
+
'terminal_close',
|
|
212
|
+
'terminal_list',
|
|
213
|
+
'user_terminal_read',
|
|
214
|
+
'user_terminal_list',
|
|
215
|
+
]
|
|
216
|
+
for (const name of terminalTools) {
|
|
217
|
+
expect(HARNESS_TOOL_KIND[name]).toBe('terminal')
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
it('terminal_send 步骤行与 bash 同标题链(terminal kind → bash 标题,目标缺省省略号)', () => {
|
|
222
|
+
const [step] = taskStepsOf([
|
|
223
|
+
toolCall('terminal_send', { sessionId: 's1', text: 'watch files' }, 'done'),
|
|
224
|
+
])
|
|
225
|
+
expect(step).toEqual({ title: m.harness_tool_bash({ target: '…' }) })
|
|
226
|
+
})
|
|
227
|
+
})
|
|
@@ -53,6 +53,17 @@ export const HARNESS_TOOL_KIND: Record<string, AgentToolKind> = {
|
|
|
53
53
|
webfetch: 'web',
|
|
54
54
|
websearch: 'web',
|
|
55
55
|
bash: 'terminal',
|
|
56
|
+
// agent 终端六工具 + 用户终端只读两工具(agent-terminal 插件,2026-11-20 T15):
|
|
57
|
+
// 复用 bash 的 terminal 形态(ToolCardCore 按 summary.kind 出终端展开体,
|
|
58
|
+
// 无 name 硬编码);terminal_send 卡与 bash 同形态(命令文本在结果条目里)。
|
|
59
|
+
terminal_open: 'terminal',
|
|
60
|
+
terminal_send: 'terminal',
|
|
61
|
+
terminal_read: 'terminal',
|
|
62
|
+
terminal_signal: 'terminal',
|
|
63
|
+
terminal_close: 'terminal',
|
|
64
|
+
terminal_list: 'terminal',
|
|
65
|
+
user_terminal_read: 'terminal',
|
|
66
|
+
user_terminal_list: 'terminal',
|
|
56
67
|
todo_write: 'todo',
|
|
57
68
|
question: 'ask',
|
|
58
69
|
plan_submit: 'plan',
|
|
@@ -391,6 +391,51 @@ describe("TabStrip 拖拽/caret/flash(P1c)", () => {
|
|
|
391
391
|
})
|
|
392
392
|
})
|
|
393
393
|
|
|
394
|
+
describe("TabStrip renderTabTitle 钩子(T14 agent 徽章)", () => {
|
|
395
|
+
it("kind 未实现 renderTabTitle → 标题槽纯文本(与现状一致)", () => {
|
|
396
|
+
dockRegistry.registerKind({
|
|
397
|
+
kind: "k-plain-title",
|
|
398
|
+
title: "t",
|
|
399
|
+
icon: null,
|
|
400
|
+
render: () => null,
|
|
401
|
+
})
|
|
402
|
+
try {
|
|
403
|
+
renderStrip({ tabs: [makeTab("k-plain-title", "纯标题")], activeTabId: "k-plain-title" })
|
|
404
|
+
const chip = screen.getByRole("tab", { name: "纯标题" })
|
|
405
|
+
const title = chip.querySelector('[data-slot="dock-chip-title"]')
|
|
406
|
+
expect(title).toBeTruthy()
|
|
407
|
+
expect(title!.textContent).toBe("纯标题")
|
|
408
|
+
} finally {
|
|
409
|
+
dockRegistry.unregisterKind("k-plain-title")
|
|
410
|
+
}
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
it("kind.renderTabTitle 提供时 → 标题槽渲染钩子返回的节点", () => {
|
|
414
|
+
dockRegistry.registerKind({
|
|
415
|
+
kind: "k-title-probe",
|
|
416
|
+
title: "t",
|
|
417
|
+
icon: null,
|
|
418
|
+
render: () => null,
|
|
419
|
+
renderTabTitle: (tab) => (
|
|
420
|
+
<span data-testid="probe-title-node">
|
|
421
|
+
<span data-testid="probe-title-text">{tab.title}</span>
|
|
422
|
+
<span data-testid="probe-title-badge">徽</span>
|
|
423
|
+
</span>
|
|
424
|
+
),
|
|
425
|
+
})
|
|
426
|
+
try {
|
|
427
|
+
renderStrip({ tabs: [makeTab("k-title-probe", "探针")], activeTabId: "k-title-probe" })
|
|
428
|
+
const chip = screen.getByRole("tab", { name: /探针/ })
|
|
429
|
+
const slot = chip.querySelector('[data-slot="dock-chip-title"]')
|
|
430
|
+
expect(slot).toBeTruthy()
|
|
431
|
+
expect(slot!.querySelector('[data-testid="probe-title-node"]')).toBeTruthy()
|
|
432
|
+
expect(slot!.querySelector('[data-testid="probe-title-text"]')!.textContent).toBe("探针")
|
|
433
|
+
} finally {
|
|
434
|
+
dockRegistry.unregisterKind("k-title-probe")
|
|
435
|
+
}
|
|
436
|
+
})
|
|
437
|
+
})
|
|
438
|
+
|
|
394
439
|
describe("TabStrip 双击重命名(P6a-1,设计 §3.1)", () => {
|
|
395
440
|
// renameable probe kind:strip 直调 dockRegistry.renameTab,故 spy registry 方法。
|
|
396
441
|
const RENAME_KIND = "terminal"
|
|
@@ -93,6 +93,19 @@ export interface DockPanelKind {
|
|
|
93
93
|
renameable?: boolean
|
|
94
94
|
/** 关闭守卫:guide 在唯一 docked tab 时不可关(控件全隐)。 */
|
|
95
95
|
canCloseTab?: (ctx: { soleDockedTab: boolean }) => boolean
|
|
96
|
+
/**
|
|
97
|
+
* tab 关闭钩子:关闭生效(从 state 移除)前调用一次。terminal 用它杀 PTY 进程 + 清
|
|
98
|
+
* binding(DSH 对标,服务端 idle 回收兜底)。只在 closeTab 挂一处——closeOthers/
|
|
99
|
+
* closeRight 内部循环调 this.closeTab,自动覆盖。
|
|
100
|
+
*/
|
|
101
|
+
onTabClose?: (tab: DockTab) => void
|
|
102
|
+
/**
|
|
103
|
+
* tab 标题自定义渲染钩子(T14,onTabClose 同款可选钩子模式):缺省 = tab.title 纯
|
|
104
|
+
* 文本(零消费者行为不变)。terminal kind 用它返回自订阅标题节点(TerminalTabTitle,
|
|
105
|
+
* 经 useSyncExternalStore 订阅闭包 store),state 帧控制权变化时 Agent 徽章自行出现/
|
|
106
|
+
* 消失——tab-strip 只把返回的 ReactNode 渲进标题槽,无终端特有逻辑、无额外订阅。
|
|
107
|
+
*/
|
|
108
|
+
renderTabTitle?: (tab: DockTab) => ReactNode
|
|
96
109
|
/** 渲染该 kind 的 tab 内容。 */
|
|
97
110
|
render: (tab: DockTab) => ReactNode
|
|
98
111
|
/** page.refresh 命令钩子(files/browser 绑定)。 */
|
|
@@ -382,6 +395,9 @@ export function createDockRegistry() {
|
|
|
382
395
|
if (r.rejected) {
|
|
383
396
|
return { collapsePanel: false, exitFullscreen: false, rejected: true }
|
|
384
397
|
}
|
|
398
|
+
// onTabClose 钩子:state 移除前通知(唯一调用点;closeOthers/closeRight 循环走本
|
|
399
|
+
// 方法自动覆盖)。放在 rejected 检查之后,被拒关不触发清理副作用。
|
|
400
|
+
kinds.get(tab.kind)?.onTabClose?.(tab)
|
|
385
401
|
state = r.state
|
|
386
402
|
persist()
|
|
387
403
|
emit()
|
|
@@ -468,6 +484,24 @@ export function createDockRegistry() {
|
|
|
468
484
|
renameTab(tabId: string, title: string) {
|
|
469
485
|
commit(layoutRenameTab(state, tabId, title))
|
|
470
486
|
},
|
|
487
|
+
/**
|
|
488
|
+
* 清除 tab 的 instanceId(T14-I1 reopen 专口):agent tab 重开后必须回归「用户 tab
|
|
489
|
+
* 无 instanceId」不变量——instanceId 全仓仅 openKind 一个写入点、本方法是唯一清除点。
|
|
490
|
+
* 残留死 agent id 会让 T13 reconcile(close 规则命中「带 instanceId 且不在 roster」)
|
|
491
|
+
* 强制关掉用户刚重开的新终端,且 onTabClose 的 kill 打在死 id 上、新 PTY 成孤儿。
|
|
492
|
+
* tab 不存在 / 本就无 instanceId → no-op(返回原引用,不换快照)。
|
|
493
|
+
*/
|
|
494
|
+
clearTabInstanceId(tabId: string) {
|
|
495
|
+
const tab = state.tabs[tabId]
|
|
496
|
+
if (!tab || tab.instanceId == null) return
|
|
497
|
+
const nextTab = { ...tab }
|
|
498
|
+
delete nextTab.instanceId
|
|
499
|
+
commit({
|
|
500
|
+
...state,
|
|
501
|
+
tabs: { ...state.tabs, [tabId]: nextTab },
|
|
502
|
+
panelVersion: state.panelVersion + 1,
|
|
503
|
+
})
|
|
504
|
+
},
|
|
471
505
|
|
|
472
506
|
// -------------------------------------------------------------------------
|
|
473
507
|
// 派生查询(容器 / 壳层用)
|
|
@@ -51,6 +51,10 @@ import { m } from "@/paraglide/messages.js"
|
|
|
51
51
|
import { createTodoKind } from "@/components/harness/extension-panel/panels/todo/kind"
|
|
52
52
|
import { createPluginKind } from "@/components/harness/extension-panel/panels/plugin/kind"
|
|
53
53
|
import { createTerminalKind } from "@/components/harness/extension-panel/panels/terminal/kind"
|
|
54
|
+
import {
|
|
55
|
+
reconcileAgentTerminalTabs,
|
|
56
|
+
useAgentTerminalRoster,
|
|
57
|
+
} from "@/components/harness/extension-panel/panels/terminal/use-agent-terminal-roster"
|
|
54
58
|
import { createMediaKind } from "@/components/harness/extension-panel/panels/media/kind"
|
|
55
59
|
import { createChangesKind } from "@/components/harness/extension-panel/panels/changes/kind"
|
|
56
60
|
import { createFilesKind } from "@/components/harness/extension-panel/panels/files/kind"
|
|
@@ -206,6 +210,35 @@ export function DockSurface({
|
|
|
206
210
|
}
|
|
207
211
|
}, [])
|
|
208
212
|
|
|
213
|
+
// -------------------------------------------------------------------------
|
|
214
|
+
// agent 终端 roster 消费 → dock tab 动态开合(T13,设计 §7.2):roster query
|
|
215
|
+
// (10s 轮询 + AgentTerminalOpened/Closed 旁路事件 invalidate,事件包装挂
|
|
216
|
+
// use-harness-session)→ reconcileAgentTerminalTabs 纯函数出开/关指令 → registry
|
|
217
|
+
// 执行。开:openKind('terminal', { instanceId, title })(openTab 需完整 DockTab
|
|
218
|
+
// 含自增 id,不是正确入口);关:closeTab(terminal kind onTabClose 钩子自动
|
|
219
|
+
// 杀 PTY + 清 binding)。control 翻转不关 tab(reconcile 只看 origin+state+存在性);
|
|
220
|
+
// 用户终端(origin='user')不参与。query 失败/空态静默(data undefined → 早退)。
|
|
221
|
+
// 挂载点=DockSurface:threadId 真源(mediaThreadId,与 terminal kind 注册同源)
|
|
222
|
+
// 与 dockRegistry 单例都在此。指令计算执行时点读 getState(),幂等(重复 reconcile
|
|
223
|
+
// 命中已开 tab → 零指令)。effect 声明在 kind 注册 effect 之后:同 commit 内
|
|
224
|
+
// effect 按声明序执行,保证 reconcile 首跑时 terminal kind 已注册(openKind 查表)。
|
|
225
|
+
// -------------------------------------------------------------------------
|
|
226
|
+
const rosterQuery = useAgentTerminalRoster(mediaThreadId ?? null)
|
|
227
|
+
const rosterTerminals = rosterQuery.data?.terminals
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (!rosterTerminals) return
|
|
230
|
+
const plan = reconcileAgentTerminalTabs(
|
|
231
|
+
rosterTerminals,
|
|
232
|
+
Object.values(dockRegistry.getState().tabs),
|
|
233
|
+
)
|
|
234
|
+
for (const cmd of plan.open) {
|
|
235
|
+
dockRegistry.openKind("terminal", { instanceId: cmd.instanceId, title: cmd.title })
|
|
236
|
+
}
|
|
237
|
+
for (const tabId of plan.close) {
|
|
238
|
+
dockRegistry.closeTab(tabId)
|
|
239
|
+
}
|
|
240
|
+
}, [rosterTerminals])
|
|
241
|
+
|
|
209
242
|
const chromePaneId = topRightPaneId(state)
|
|
210
243
|
|
|
211
244
|
// 分栏 blocked 判定(P1c-4 room 实测):measurePaneFits 两档——budget(已达两格上限)
|
|
@@ -40,6 +40,7 @@ import { formatForDisplay } from "@tanstack/hotkeys"
|
|
|
40
40
|
import { dockRegistry, type DockPanelKind } from "./dock-registry"
|
|
41
41
|
import { appHotkeys, formatAppHotkeyForBadge, type AppHotkeyId } from "@/lib/hotkeys/registry"
|
|
42
42
|
import {
|
|
43
|
+
readTerminalShellPref,
|
|
43
44
|
writeTerminalShellPref,
|
|
44
45
|
} from "@/components/harness/extension-panel/panels/terminal/shell-pref"
|
|
45
46
|
import { Kbd } from "@/components/ui/kbd"
|
|
@@ -178,8 +179,10 @@ function TerminalShellMenu({
|
|
|
178
179
|
aria-label={m.harness_panel_shellLabel()}
|
|
179
180
|
// 卡主体是可点容器(开默认 shell),chevron 点击须截停冒泡,防误开卡
|
|
180
181
|
onClick={(e) => e.stopPropagation()}
|
|
181
|
-
className="flex
|
|
182
|
+
className="flex h-6 shrink-0 items-center gap-1 rounded-sm px-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
|
|
182
183
|
>
|
|
184
|
+
{/* 显示当前选中(默认 zsh)/上次选中的 shell 名——用户可见默认类型 */}
|
|
185
|
+
<span className="text-xs">{readTerminalShellPref()}</span>
|
|
183
186
|
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
|
184
187
|
<path
|
|
185
188
|
d="M3 4.5L6 7.5L9 4.5"
|
|
@@ -99,6 +99,7 @@ export interface TabStripProps {
|
|
|
99
99
|
function TabChip({
|
|
100
100
|
tab,
|
|
101
101
|
icon,
|
|
102
|
+
titleNode,
|
|
102
103
|
active,
|
|
103
104
|
quiet,
|
|
104
105
|
editable,
|
|
@@ -114,6 +115,12 @@ function TabChip({
|
|
|
114
115
|
tab: DockTab
|
|
115
116
|
/** kind 图标(由 TabStrip 经 dockRegistry.getKind(tab.kind)?.icon 解析后传入)。 */
|
|
116
117
|
icon: ReactNode
|
|
118
|
+
/**
|
|
119
|
+
* 标题槽内容(T14):kind 实现 renderTabTitle 时为钩子返回的 ReactNode(terminal 的
|
|
120
|
+
* Agent 徽章即经此进入),否则回退 tab.title 纯文本。仅影响展示——拖拽起手/重命名/
|
|
121
|
+
* 关闭 aria-label 等逻辑仍读 tab.title。
|
|
122
|
+
*/
|
|
123
|
+
titleNode: ReactNode
|
|
117
124
|
active: boolean
|
|
118
125
|
quiet: boolean
|
|
119
126
|
/** 该 kind 是否可重命名(renameable)——true 时双击 chip 进 inline 编辑。 */
|
|
@@ -275,7 +282,7 @@ function TabChip({
|
|
|
275
282
|
className={cn("min-w-0 truncate", !quiet && "pr-5")}
|
|
276
283
|
data-slot="dock-chip-title"
|
|
277
284
|
>
|
|
278
|
-
{
|
|
285
|
+
{titleNode}
|
|
279
286
|
</span>
|
|
280
287
|
{!quiet ? closeBtn : null}
|
|
281
288
|
</Button>
|
|
@@ -437,6 +444,7 @@ export function TabStrip({
|
|
|
437
444
|
<TabChip
|
|
438
445
|
tab={tab}
|
|
439
446
|
icon={dockRegistry.getKind(tab.kind)?.icon}
|
|
447
|
+
titleNode={dockRegistry.getKind(tab.kind)?.renderTabTitle?.(tab) ?? tab.title}
|
|
440
448
|
active={tab.id === activeTabId}
|
|
441
449
|
quiet={quiet}
|
|
442
450
|
editable={dockRegistry.getKind(tab.kind)?.renameable === true}
|