@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.
- package/package.json +5 -5
- package/public/dev-gallery.html +19 -0
- package/src/__tests__/bench/baselines/format-timestamp.json +44 -0
- package/src/__typeprobe__.d.ts +4 -0
- package/src/components/harness/extension-panel/panels/terminal/__tests__/terminal-instance.test.tsx +93 -4
- package/src/components/harness/extension-panel/panels/terminal/sse-transport.ts +28 -5
- package/src/components/harness/extension-panel/panels/terminal/terminal-instance.tsx +53 -10
- package/src/components/harness/extension-panel/panels/terminal/transport.ts +10 -3
- package/src/components/harness/extension-panel/panels/terminal/ws-transport.ts +13 -2
- package/src/components/settings/harness/connectors-card.tsx +5 -0
- package/src/dev/gallery-entry.tsx +38 -0
- package/src/dev/gallery.tsx +610 -0
- package/src/lib/changelog/sdk-versions.ts +3 -3
- package/src/paraglide/README.md +1 -1
- package/src/paraglide/messages/_index.d.ts +9 -0
- package/src/paraglide/messages/_index.js +9 -0
- package/src/paraglide/messages/capabilities_webhook.d.ts +16 -0
- package/src/paraglide/messages/capabilities_webhook.js +29 -0
- package/src/paraglide/messages/capabilities_workflow.d.ts +16 -0
- package/src/paraglide/messages/capabilities_workflow.js +29 -0
- package/src/paraglide/messages/harness_panel_terminal_exitedrecycled1.d.ts +17 -0
- package/src/paraglide/messages/harness_panel_terminal_exitedrecycled1.js +30 -0
- package/src/paraglide/messages/harness_panel_terminal_restarted.d.ts +16 -0
- package/src/paraglide/messages/harness_panel_terminal_restarted.js +29 -0
- package/src/paraglide/messages/settings_harness_connectors_needsauth1.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_connectors_needsauth1.js +30 -0
- package/src/paraglide/messages/settings_harness_ralphenabled1.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_ralphenabled1.js +30 -0
- package/src/paraglide/messages/settings_harness_ralphenabled_description1.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_ralphenabled_description1.js +30 -0
- package/src/paraglide/messages/settings_harness_ralphmaxrounds2.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_ralphmaxrounds2.js +30 -0
- package/src/paraglide/messages/settings_harness_ralphmaxrounds_description2.d.ts +17 -0
- package/src/paraglide/messages/settings_harness_ralphmaxrounds_description2.js +30 -0
- package/src/routeTree.gen.ts +21 -0
- package/src/routes/api/harness/terminal/$.ts +32 -13
- package/src/routes/api/harness/terminal/__tests__/route.test.ts +41 -0
- package/src/routes/api/harness/webhook/$token.ts +23 -0
- package/src/routes/api/sync/__tests__/bootstrap.test.ts +32 -1
- package/src/routes/api/sync/bootstrap.ts +11 -0
- package/src/server/ai-gateway/durability/__tests__/sse-resume-frames.test.ts +123 -0
- package/src/server/harness/__tests__/agent-terminal-sandbox.test.ts +23 -4
- package/src/server/harness/__tests__/agent-terminal.server.test.ts +118 -2
- package/src/server/harness/__tests__/credentials.server.test.ts +25 -2
- package/src/server/harness/__tests__/host-schedule-worker.test.ts +43 -0
- package/src/server/harness/__tests__/runtime-without-providers.test.ts +11 -0
- package/src/server/harness/__tests__/sticky-route.test.ts +86 -0
- package/src/server/harness/__tests__/terminal-foreground.server.test.ts +80 -0
- package/src/server/harness/__tests__/terminal-manager.server.test.ts +75 -1
- package/src/server/harness/__tests__/tool-entitlements.test.ts +6 -2
- package/src/server/harness/agent-terminal.server.ts +25 -4
- package/src/server/harness/agents/__tests__/agent-control.test.ts +1 -0
- package/src/server/harness/agents/run-view.server.ts +55 -2
- package/src/server/harness/capabilities/__tests__/__snapshots__/matrix.test.ts.snap +92 -0
- package/src/server/harness/capabilities/__tests__/execution-plane-denials.test.ts +3 -1
- package/src/server/harness/capabilities/__tests__/p3-matrix.test.ts +3 -3
- package/src/server/harness/capabilities/__tests__/p5-matrix.test.ts +293 -0
- package/src/server/harness/capabilities/__tests__/validate.test.ts +8 -2
- package/src/server/harness/capabilities/execution-plane-denials.ts +9 -3
- package/src/server/harness/capabilities/manifests/agent-terminal.ts +3 -2
- package/src/server/harness/capabilities/manifests/webhook.ts +45 -0
- package/src/server/harness/capabilities/manifests/workflow.ts +40 -0
- package/src/server/harness/capabilities/registry.ts +4 -0
- package/src/server/harness/connectors/__tests__/connector-accounts.test.ts +22 -1
- package/src/server/harness/connectors/connector-accounts.server.ts +7 -0
- package/src/server/harness/credentials.server.ts +3 -1
- package/src/server/harness/define.server.ts +11 -0
- package/src/server/harness/mcp/mcp-config.server.ts +3 -1
- package/src/server/harness/outbox/outbox-dispatcher.server.ts +9 -0
- package/src/server/harness/outbox/outbox-store.server.ts +7 -0
- package/src/server/harness/persistence/__tests__/log-store.server.test.ts +4 -1
- package/src/server/harness/plugins/__tests__/tool-risk-audit.test.ts +5 -1
- package/src/server/harness/plugins/builtin/agent-terminal.plugin.ts +12 -2
- package/src/server/harness/providers/contracts.ts +16 -0
- package/src/server/harness/schedule/schedule-dispatcher.server.ts +3 -0
- package/src/server/harness/search/__tests__/indexer.test.ts +4 -1
- package/src/server/harness/search/__tests__/lifecycle.test.ts +4 -1
- package/src/server/harness/search/__tests__/search.test.ts +4 -1
- package/src/server/harness/sticky-route.server.ts +72 -0
- package/src/server/harness/terminal-foreground.server.ts +90 -0
- package/src/server/harness/terminal-manager.server.ts +78 -3
- package/src/server/harness/tool-entitlements.server.ts +5 -0
- package/src/server/harness/webhook/__tests__/body.test.ts +73 -0
- package/src/server/harness/webhook/__tests__/payload.test.ts +215 -0
- package/src/server/harness/webhook/__tests__/signature.test.ts +170 -0
- package/src/server/harness/webhook/__tests__/webhook-dispatcher.test.ts +212 -0
- package/src/server/harness/webhook/__tests__/webhook.plugin.test.ts +195 -0
- package/src/server/harness/webhook/__tests__/webhook.service.test.ts +354 -0
- package/src/server/harness/webhook/body.server.ts +56 -0
- package/src/server/harness/webhook/payload.server.ts +169 -0
- package/src/server/harness/webhook/signature.server.ts +118 -0
- package/src/server/harness/webhook/types.ts +57 -0
- package/src/server/harness/webhook/webhook-dispatcher.server.ts +495 -0
- package/src/server/harness/webhook/webhook-store.server.ts +115 -0
- package/src/server/harness/webhook/webhook.plugin.ts +273 -0
- package/src/server/harness/webhook/webhook.service.server.ts +577 -0
- package/src/server/harness/worker/__tests__/worker-http.test.ts +8 -1
- package/src/server/harness/worker/worker-health.server.ts +4 -1
- package/src/server/harness/worker/worker-runtime.server.ts +43 -1
- package/src/server/harness/workflow/__tests__/engine.test.ts +195 -0
- package/src/server/harness/workflow/__tests__/settings.test.ts +125 -0
- package/src/server/harness/workflow/__tests__/validate.test.ts +151 -0
- package/src/server/harness/workflow/engine.server.ts +155 -0
- package/src/server/harness/workflow/settings.ts +84 -0
- package/src/server/harness/workflow/store.server.ts +147 -0
- package/src/server/harness/workflow/types.ts +80 -0
- package/src/server/harness/workflow/validate.ts +130 -0
- package/src/server/harness/workflow/workflow.plugin.ts +261 -0
- package/src/server/serverFns/harness/__tests__/fork-thread.test.ts +14 -1
- package/src/server/serverFns/harness/fork-thread.ts +17 -0
|
@@ -5,6 +5,8 @@ const {
|
|
|
5
5
|
materializeMock,
|
|
6
6
|
scheduleTickMock,
|
|
7
7
|
createScheduleDispatcherMock,
|
|
8
|
+
webhookTickMock,
|
|
9
|
+
createWebhookDispatcherMock,
|
|
8
10
|
createWorkerMock,
|
|
9
11
|
fakeHost,
|
|
10
12
|
fakeWorker,
|
|
@@ -21,6 +23,10 @@ const {
|
|
|
21
23
|
createScheduleDispatcherMock: vi.fn((_options: { plane?: string; submit: ScheduleSubmit }) => ({
|
|
22
24
|
tick: scheduleTickMock,
|
|
23
25
|
})),
|
|
26
|
+
webhookTickMock: vi.fn(),
|
|
27
|
+
createWebhookDispatcherMock: vi.fn((_options: { plane?: string; submit: ScheduleSubmit }) => ({
|
|
28
|
+
tick: webhookTickMock,
|
|
29
|
+
})),
|
|
24
30
|
createWorkerMock: vi.fn(() => fakeWorker),
|
|
25
31
|
fakeHost,
|
|
26
32
|
fakeWorker,
|
|
@@ -33,6 +39,9 @@ vi.mock('@/server/harness/schedule/schedule-materializer.server', () => ({
|
|
|
33
39
|
vi.mock('@/server/harness/schedule/schedule-dispatcher.server', () => ({
|
|
34
40
|
createScheduleDispatcher: createScheduleDispatcherMock,
|
|
35
41
|
}))
|
|
42
|
+
vi.mock('@/server/harness/webhook/webhook-dispatcher.server', () => ({
|
|
43
|
+
createWebhookDispatcher: createWebhookDispatcherMock,
|
|
44
|
+
}))
|
|
36
45
|
vi.mock('@/server/harness/define.server', () => ({
|
|
37
46
|
buildAllblueHarnessForRuntime: vi.fn().mockResolvedValue({ name: 'allblue/test' }),
|
|
38
47
|
}))
|
|
@@ -79,7 +88,17 @@ describe('host schedule ticker', () => {
|
|
|
79
88
|
retried: 0,
|
|
80
89
|
leaseLost: 0,
|
|
81
90
|
})
|
|
91
|
+
webhookTickMock.mockReset()
|
|
92
|
+
webhookTickMock.mockResolvedValue({
|
|
93
|
+
claimed: 0,
|
|
94
|
+
delivered: 0,
|
|
95
|
+
skipped: 0,
|
|
96
|
+
failed: 0,
|
|
97
|
+
retried: 0,
|
|
98
|
+
leaseLost: 0,
|
|
99
|
+
})
|
|
82
100
|
createScheduleDispatcherMock.mockClear()
|
|
101
|
+
createWebhookDispatcherMock.mockClear()
|
|
83
102
|
createWorkerMock.mockClear()
|
|
84
103
|
fakeHost.recover.mockClear()
|
|
85
104
|
fakeHost.close.mockClear()
|
|
@@ -115,6 +134,9 @@ describe('host schedule ticker', () => {
|
|
|
115
134
|
|
|
116
135
|
expect(createScheduleDispatcherMock).toHaveBeenCalledTimes(1)
|
|
117
136
|
expect(scheduleTickMock).toHaveBeenCalledTimes(1)
|
|
137
|
+
// P5 任务 3:webhook dispatcher 与 schedule 同源启动,但各自独立排队。
|
|
138
|
+
expect(createWebhookDispatcherMock).toHaveBeenCalledTimes(1)
|
|
139
|
+
expect(webhookTickMock).toHaveBeenCalledTimes(1)
|
|
118
140
|
expect(vi.getTimerCount()).toBe(1)
|
|
119
141
|
|
|
120
142
|
const dispatcherOptions = createScheduleDispatcherMock.mock.calls[0]![0]
|
|
@@ -160,6 +182,27 @@ describe('host schedule ticker', () => {
|
|
|
160
182
|
expect(scheduleTickMock).toHaveBeenCalledTimes(2)
|
|
161
183
|
})
|
|
162
184
|
|
|
185
|
+
it('webhook tick 与 schedule tick 独立排队:schedule 首轮挂起不阻塞 webhook 领取', async () => {
|
|
186
|
+
let releaseFirst!: () => void
|
|
187
|
+
scheduleTickMock.mockImplementationOnce(() => new Promise<void>((resolve) => {
|
|
188
|
+
releaseFirst = resolve
|
|
189
|
+
}))
|
|
190
|
+
const { getHarnessHost, closeHarnessHost } = await import('../host.server')
|
|
191
|
+
await getHarnessHost()
|
|
192
|
+
await flushMicrotasks()
|
|
193
|
+
expect(scheduleTickMock).toHaveBeenCalledTimes(1)
|
|
194
|
+
|
|
195
|
+
// schedule 首轮仍未完成,webhook 已独立跑过至少一轮(不被串行队列挡住)。
|
|
196
|
+
expect(webhookTickMock.mock.calls.length).toBeGreaterThanOrEqual(1)
|
|
197
|
+
|
|
198
|
+
releaseFirst()
|
|
199
|
+
await flushMicrotasks()
|
|
200
|
+
await vi.advanceTimersByTimeAsync(1_000)
|
|
201
|
+
expect(webhookTickMock.mock.calls.length).toBeGreaterThanOrEqual(2)
|
|
202
|
+
|
|
203
|
+
await closeHarnessHost()
|
|
204
|
+
})
|
|
205
|
+
|
|
163
206
|
it('getHarnessHost 启动官方 worker 时同时执行首次统一 schedule tick', async () => {
|
|
164
207
|
const { getHarnessHost } = await import('../host.server')
|
|
165
208
|
await getHarnessHost()
|
|
@@ -65,6 +65,17 @@ const BASELINE_TOOL_NAMES: ReadonlyArray<string> = [
|
|
|
65
65
|
'wait_agent',
|
|
66
66
|
'webfetch',
|
|
67
67
|
'websearch',
|
|
68
|
+
// P5 任务 3:webhook 五工具(随 scheduler Provider 挂载;该环境 scheduler 在场)。
|
|
69
|
+
'webhook_create',
|
|
70
|
+
'webhook_delete',
|
|
71
|
+
'webhook_edit',
|
|
72
|
+
'webhook_list',
|
|
73
|
+
'webhook_view',
|
|
74
|
+
// P5 任务 1:workflow 四工具(编排面随 agents 挂载守卫,四端一致)。
|
|
75
|
+
'workflow_cancel',
|
|
76
|
+
'workflow_list',
|
|
77
|
+
'workflow_start',
|
|
78
|
+
'workflow_view',
|
|
68
79
|
'write_file',
|
|
69
80
|
]
|
|
70
81
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
//
|
|
5
|
+
// sticky 路由契约单测(P5 任务 8,母规格 §5.2.1 / §6.5)。
|
|
6
|
+
//
|
|
7
|
+
// 这里只测**应用侧能保证的部分**,因为 sticky 本身是 ingress 语义、应用不可测:
|
|
8
|
+
// 1. 粘性键只由 threadId 派生(同一线程恒等、不同线程不同、不含实例信息)——
|
|
9
|
+
// 否则 ingress 的一致性哈希会因同一线程算出不同键而立刻失效;
|
|
10
|
+
// 2. 实例标识形状稳定且**无随机段**(同进程多次读取恒等、重启后 pid 变化即变脸),
|
|
11
|
+
// 客户端「同一实例」的比对语义依赖它;
|
|
12
|
+
// 3. 响应头两键齐备,且实例标识不掺进粘性键(诊断头与哈希输入是两件事)。
|
|
13
|
+
|
|
14
|
+
// @vitest-environment node
|
|
15
|
+
|
|
16
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
17
|
+
|
|
18
|
+
/** 可控 hostname:验证实例标识跟随 hostname,而粘性键不跟随任何实例信息。 */
|
|
19
|
+
const host = vi.hoisted(() => ({ name: 'test-host' }))
|
|
20
|
+
|
|
21
|
+
vi.mock('node:os', async (importOriginal) => {
|
|
22
|
+
const actual = await importOriginal<typeof import('node:os')>()
|
|
23
|
+
return { ...actual, hostname: () => host.name }
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
__resetInstanceIdForTests,
|
|
28
|
+
getInstanceId,
|
|
29
|
+
INSTANCE_HEADER,
|
|
30
|
+
stickyHeadersForThread,
|
|
31
|
+
stickyKeyForThread,
|
|
32
|
+
STICKY_KEY_HEADER,
|
|
33
|
+
} from '../sticky-route.server'
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
host.name = 'test-host'
|
|
37
|
+
__resetInstanceIdForTests()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('sticky 路由:可哈希粘性键(只由 threadId 派生)', () => {
|
|
41
|
+
it('同一 threadId 恒等;不同 threadId 不同;键里不含实例信息', () => {
|
|
42
|
+
const a = stickyKeyForThread('t1')
|
|
43
|
+
expect(stickyKeyForThread('t1')).toBe(a)
|
|
44
|
+
expect(stickyKeyForThread('t2')).not.toBe(a)
|
|
45
|
+
// 键形状 `thread:<id>`:与 ingress 的 $arg_threadId 哈希输入一一对应
|
|
46
|
+
expect(a).toBe('thread:t1')
|
|
47
|
+
// 换实例不改键——否则多实例下同一线程会被哈希到不同机器
|
|
48
|
+
host.name = 'other-host'
|
|
49
|
+
__resetInstanceIdForTests()
|
|
50
|
+
expect(stickyKeyForThread('t1')).toBe(a)
|
|
51
|
+
expect(stickyKeyForThread('t1')).not.toContain(getInstanceId())
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
describe('sticky 路由:实例标识(<hostname>:<pid>,无随机段)', () => {
|
|
56
|
+
it('形状为 <hostname>:<pid> 且同进程内多次读取恒等', () => {
|
|
57
|
+
const id = getInstanceId()
|
|
58
|
+
expect(id).toBe(`${host.name}:${process.pid}`)
|
|
59
|
+
expect(id).toMatch(/^.+:\d+$/)
|
|
60
|
+
// 无随机段:连续读取必须同一个值(客户端靠「值变没变」判断是否换了实例)
|
|
61
|
+
expect(getInstanceId()).toBe(id)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('hostname 变 → 实例标识变(重置缓存后重算);缓存期内不重算', () => {
|
|
65
|
+
const first = getInstanceId()
|
|
66
|
+
host.name = 'other-host'
|
|
67
|
+
// 缓存期内不重算:同一进程不能「中途变脸」
|
|
68
|
+
expect(getInstanceId()).toBe(first)
|
|
69
|
+
__resetInstanceIdForTests()
|
|
70
|
+
expect(getInstanceId()).toBe(`other-host:${process.pid}`)
|
|
71
|
+
expect(getInstanceId()).not.toBe(first)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('sticky 路由:响应头', () => {
|
|
76
|
+
it('两键齐备:实例头 = 实例标识,粘性键头 = thread:<id>', () => {
|
|
77
|
+
const headers = stickyHeadersForThread('t1')
|
|
78
|
+
expect(headers).toEqual({
|
|
79
|
+
[INSTANCE_HEADER]: getInstanceId(),
|
|
80
|
+
[STICKY_KEY_HEADER]: 'thread:t1',
|
|
81
|
+
})
|
|
82
|
+
// 头名是部署方/运维的比对契约,改动即为破坏性变更
|
|
83
|
+
expect(INSTANCE_HEADER).toBe('x-allblue-instance')
|
|
84
|
+
expect(STICKY_KEY_HEADER).toBe('x-allblue-sticky-key')
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
//
|
|
5
|
+
// 终端前台进程组探测(P5 任务 4 / §6.5 O2/O3):ps 输出解析与 fail-closed 取向。
|
|
6
|
+
|
|
7
|
+
import { describe, expect, it } from 'vitest'
|
|
8
|
+
import { isAwaitingInput, probeForeground, type PsRunner } from '../terminal-foreground.server'
|
|
9
|
+
|
|
10
|
+
/** 按调用顺序回放 ps 输出(null = ps 失败/超时)。 */
|
|
11
|
+
function scripted(outputs: Array<string | null>): PsRunner {
|
|
12
|
+
let index = 0
|
|
13
|
+
return async () => outputs[index++] ?? null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('probeForeground', () => {
|
|
17
|
+
it('tpgid 与 pty 进程组相同 → shell 在前台', async () => {
|
|
18
|
+
const probe = await probeForeground(4242, scripted(['4242 4242\n']))
|
|
19
|
+
expect(probe).toEqual({ kind: 'shell', pgid: 4242 })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('tpgid 不同 → 前台命令,并带 leader 状态', async () => {
|
|
23
|
+
const probe = await probeForeground(4242, scripted(['9100 4242\n', 'S+\n']))
|
|
24
|
+
expect(probe).toEqual({ kind: 'command', pgid: 9100, state: 'S+' })
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('leader 已退出(stat 拿不到)→ 仍是 command,但无状态(不做等待输入判断)', async () => {
|
|
28
|
+
const probe = await probeForeground(4242, scripted(['9100 4242\n', null]))
|
|
29
|
+
expect(probe).toEqual({ kind: 'command', pgid: 9100 })
|
|
30
|
+
expect(isAwaitingInput(probe)).toBe(false)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('无控制终端(tpgid=-1)→ unknown', async () => {
|
|
34
|
+
expect(await probeForeground(4242, scripted(['-1 4242\n']))).toEqual({ kind: 'unknown' })
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('tpgid<=1(init/非法组)→ unknown', async () => {
|
|
38
|
+
expect(await probeForeground(4242, scripted(['1 4242\n']))).toEqual({ kind: 'unknown' })
|
|
39
|
+
expect(await probeForeground(4242, scripted(['0 4242\n']))).toEqual({ kind: 'unknown' })
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('ps 不可用 / 输出非法 / pid 非法 → unknown(fail-closed,绝不猜 pgid)', async () => {
|
|
43
|
+
expect(await probeForeground(4242, scripted([null]))).toEqual({ kind: 'unknown' })
|
|
44
|
+
expect(await probeForeground(4242, scripted(['\n']))).toEqual({ kind: 'unknown' })
|
|
45
|
+
expect(await probeForeground(4242, scripted(['garbage']))).toEqual({ kind: 'unknown' })
|
|
46
|
+
expect(await probeForeground(0, scripted(['1 1']))).toEqual({ kind: 'unknown' })
|
|
47
|
+
expect(await probeForeground(-5, scripted(['1 1']))).toEqual({ kind: 'unknown' })
|
|
48
|
+
expect(await probeForeground(1.5, scripted(['1 1']))).toEqual({ kind: 'unknown' })
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('先查 tpgid/pgid,再按需查 leader 状态(两次 ps 的参数正确)', async () => {
|
|
52
|
+
const calls: string[][] = []
|
|
53
|
+
const run: PsRunner = async (args) => {
|
|
54
|
+
calls.push([...args])
|
|
55
|
+
return calls.length === 1 ? '9100 4242\n' : 'S\n'
|
|
56
|
+
}
|
|
57
|
+
await probeForeground(4242, run)
|
|
58
|
+
expect(calls).toEqual([
|
|
59
|
+
['-o', 'tpgid=,pgid=', '-p', '4242'],
|
|
60
|
+
['-o', 'stat=', '-p', '9100'],
|
|
61
|
+
])
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('isAwaitingInput', () => {
|
|
66
|
+
it('前台命令处于可中断睡眠/空闲 → true(启发式)', () => {
|
|
67
|
+
expect(isAwaitingInput({ kind: 'command', pgid: 1, state: 'S+' })).toBe(true)
|
|
68
|
+
expect(isAwaitingInput({ kind: 'command', pgid: 1, state: 'S' })).toBe(true)
|
|
69
|
+
expect(isAwaitingInput({ kind: 'command', pgid: 1, state: 'I+' })).toBe(true)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('运行中 / 被停止 / shell 在前台 / 未知 → false', () => {
|
|
73
|
+
expect(isAwaitingInput({ kind: 'command', pgid: 1, state: 'R+' })).toBe(false)
|
|
74
|
+
expect(isAwaitingInput({ kind: 'command', pgid: 1, state: 'T' })).toBe(false)
|
|
75
|
+
expect(isAwaitingInput({ kind: 'command', pgid: 1 })).toBe(false)
|
|
76
|
+
expect(isAwaitingInput({ kind: 'shell', pgid: 1 })).toBe(false)
|
|
77
|
+
expect(isAwaitingInput({ kind: 'unknown' })).toBe(false)
|
|
78
|
+
expect(isAwaitingInput(undefined)).toBe(false)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
type SpawnHelperProbe,
|
|
32
32
|
type TerminalFrame,
|
|
33
33
|
} from '../terminal-manager.server'
|
|
34
|
+
import type { ForegroundProber } from '../terminal-foreground.server'
|
|
34
35
|
|
|
35
36
|
/** fake IPty:记录 write/resize/kill 调用,暴露 onData/onExit 监听器供测试触发。 */
|
|
36
37
|
function makeFakePty() {
|
|
@@ -86,7 +87,13 @@ function makeFakePty() {
|
|
|
86
87
|
type FakeRegistry = ReturnType<typeof makeFakePty>
|
|
87
88
|
|
|
88
89
|
/** 注入 fake spawn 的 manager 工厂:每次 create 产出一个新 fake pty 并登记。 */
|
|
89
|
-
function makeManager(opts: {
|
|
90
|
+
function makeManager(opts: {
|
|
91
|
+
now?: () => number
|
|
92
|
+
pollIntervalMs?: number
|
|
93
|
+
idleKillMs?: number
|
|
94
|
+
ringMaxBytes?: number
|
|
95
|
+
probeForeground?: ForegroundProber
|
|
96
|
+
} = {}) {
|
|
90
97
|
const spawned: FakeRegistry[] = []
|
|
91
98
|
// spawnPty 签名:(file, args, options) => Promise<IPty>(真实现动态 import node-pty 后
|
|
92
99
|
// 调其 spawn)。fake 保持同语义——调用即登记新 fake 并 resolve 其 pty。
|
|
@@ -100,6 +107,8 @@ function makeManager(opts: { now?: () => number; pollIntervalMs?: number; idleKi
|
|
|
100
107
|
const manager = createTerminalManager({
|
|
101
108
|
...opts,
|
|
102
109
|
spawnPty: fakeSpawn,
|
|
110
|
+
// 默认探测替身(P5 任务 4):不碰真实进程表;需要前台组的用例显式注入。
|
|
111
|
+
probeForeground: opts.probeForeground ?? (async () => ({ kind: 'unknown' as const })),
|
|
103
112
|
})
|
|
104
113
|
return { manager, spawned }
|
|
105
114
|
}
|
|
@@ -522,6 +531,71 @@ describe('terminal-manager(真 PTY 后端,设计 §4.2)', () => {
|
|
|
522
531
|
expect(() => manager.agentSignal(r.terminalId, 'SIGINT')).toThrow(TerminalControlError)
|
|
523
532
|
})
|
|
524
533
|
|
|
534
|
+
it('agentSignalForeground:只对前台进程组发 kill(-pgid);前台是 shell / 探测不可用则拒(P5 任务 4 / O3)', async () => {
|
|
535
|
+
// ① 前台有命令 → kill(-pgid)
|
|
536
|
+
const command = makeManager({
|
|
537
|
+
probeForeground: async () => ({ kind: 'command', pgid: 4321, state: 'S+' }),
|
|
538
|
+
})
|
|
539
|
+
const r = await command.manager.createForAgent({ threadId: 't1', userId: 'u1' }, ROOT)
|
|
540
|
+
const killSpy = vi.spyOn(process, 'kill').mockImplementation(() => true)
|
|
541
|
+
try {
|
|
542
|
+
expect(await command.manager.agentSignalForeground(r.terminalId, 'SIGTERM')).toEqual({
|
|
543
|
+
delivered: true,
|
|
544
|
+
method: 'foreground-group',
|
|
545
|
+
pgid: 4321,
|
|
546
|
+
})
|
|
547
|
+
// 负 pgid = 整个前台进程组;绝不发给 shell 自身(正 pid)
|
|
548
|
+
expect(killSpy).toHaveBeenCalledWith(-4321, 'SIGTERM')
|
|
549
|
+
} finally {
|
|
550
|
+
killSpy.mockRestore()
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// ② 前台是 shell 自身 → 拒(等价关终端)
|
|
554
|
+
const shellFg = makeManager({ probeForeground: async () => ({ kind: 'shell', pgid: 4242 }) })
|
|
555
|
+
const s = await shellFg.manager.createForAgent({ threadId: 't1', userId: 'u1' }, ROOT)
|
|
556
|
+
await expect(shellFg.manager.agentSignalForeground(s.terminalId, 'SIGTERM')).rejects.toMatchObject({
|
|
557
|
+
code: 'invalid_signal',
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
// ③ 探测不可用 → fail-closed 拒(不回退成控制字符,也不猜 pgid)
|
|
561
|
+
const unknown = makeManager()
|
|
562
|
+
const u = await unknown.manager.createForAgent({ threadId: 't1', userId: 'u1' }, ROOT)
|
|
563
|
+
const killSpy2 = vi.spyOn(process, 'kill').mockImplementation(() => true)
|
|
564
|
+
try {
|
|
565
|
+
await expect(unknown.manager.agentSignalForeground(u.terminalId, 'SIGKILL')).rejects.toMatchObject({
|
|
566
|
+
code: 'invalid_signal',
|
|
567
|
+
})
|
|
568
|
+
expect(killSpy2).not.toHaveBeenCalled()
|
|
569
|
+
} finally {
|
|
570
|
+
killSpy2.mockRestore()
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// ④ 守卫同 agentWrite:接管后 → user-control(control 不符不得发信号)
|
|
574
|
+
command.manager.write(r.terminalId, 1, 'x', true)
|
|
575
|
+
await expect(command.manager.agentSignalForeground(r.terminalId, 'SIGTERM')).rejects.toMatchObject({
|
|
576
|
+
code: 'terminal/control-unavailable',
|
|
577
|
+
})
|
|
578
|
+
})
|
|
579
|
+
|
|
580
|
+
it('foregroundOf:只读探测,终端不存在/已退出/无 pid → undefined(不抛)', async () => {
|
|
581
|
+
const { manager, spawned } = makeManager({
|
|
582
|
+
probeForeground: async () => ({ kind: 'command', pgid: 777, state: 'R' }),
|
|
583
|
+
})
|
|
584
|
+
const r = await manager.createForAgent({ threadId: 't1', userId: 'u1' }, ROOT)
|
|
585
|
+
expect(await manager.foregroundOf(r.terminalId)).toEqual({ kind: 'command', pgid: 777, state: 'R' })
|
|
586
|
+
expect(await manager.foregroundOf('nope')).toBeUndefined()
|
|
587
|
+
spawned[0].listeners.exit.forEach((fn) => fn({ exitCode: 0 }))
|
|
588
|
+
expect(await manager.foregroundOf(r.terminalId)).toBeUndefined()
|
|
589
|
+
// 探测器抛错也不外溢(旁路信息不参与控制流)
|
|
590
|
+
const throwing = makeManager({
|
|
591
|
+
probeForeground: async () => {
|
|
592
|
+
throw new Error('ps 炸了')
|
|
593
|
+
},
|
|
594
|
+
})
|
|
595
|
+
const t = await throwing.manager.createForAgent({ threadId: 't1', userId: 'u1' }, ROOT)
|
|
596
|
+
expect(await throwing.manager.foregroundOf(t.terminalId)).toBeUndefined()
|
|
597
|
+
})
|
|
598
|
+
|
|
525
599
|
it('agentClose:control=agent → 真杀返回 closed(exit 帧经 onExit 广播);关闭中再调 already-closing;exit 后幂等 closed', async () => {
|
|
526
600
|
const { manager, spawned } = makeManager()
|
|
527
601
|
const r = await manager.createForAgent({ threadId: 't1', userId: 'u1' }, ROOT)
|
|
@@ -228,7 +228,7 @@ describe('requireFeatureForTool 三态门控(hostedAi 通路证明,Ruling P6
|
|
|
228
228
|
})
|
|
229
229
|
|
|
230
230
|
describe('enforceToolFeature(工具名级入口)', () => {
|
|
231
|
-
it('仅 team
|
|
231
|
+
it('仅 team 四工具、agents 七工具与 workflow 四工具映射 customAgents,七域不发明 key', () => {
|
|
232
232
|
const expected = {
|
|
233
233
|
team_task_create: 'customAgents',
|
|
234
234
|
team_task_list: 'customAgents',
|
|
@@ -241,13 +241,17 @@ describe('enforceToolFeature(工具名级入口)', () => {
|
|
|
241
241
|
send_message: 'customAgents',
|
|
242
242
|
wait_agent: 'customAgents',
|
|
243
243
|
interrupt_agent: 'customAgents',
|
|
244
|
+
workflow_start: 'customAgents',
|
|
245
|
+
workflow_list: 'customAgents',
|
|
246
|
+
workflow_view: 'customAgents',
|
|
247
|
+
workflow_cancel: 'customAgents',
|
|
244
248
|
}
|
|
245
249
|
expect(HARNESS_TOOL_FEATURE_MAP).toEqual(expected)
|
|
246
250
|
const manifestTools = CAPABILITY_REGISTRY
|
|
247
251
|
.filter((manifest) => manifest.entitlement === 'customAgents')
|
|
248
252
|
.flatMap((manifest) => manifest.tools.map((tool) => tool.name))
|
|
249
253
|
expect(Object.keys(HARNESS_TOOL_FEATURE_MAP).sort()).toEqual(manifestTools.sort())
|
|
250
|
-
expect(Object.keys(HARNESS_TOOL_FEATURE_MAP)).toHaveLength(
|
|
254
|
+
expect(Object.keys(HARNESS_TOOL_FEATURE_MAP)).toHaveLength(15)
|
|
251
255
|
expect(new Set(Object.keys(HARNESS_TOOL_FEATURE_MAP))).toEqual(new Set(Object.keys(expected)))
|
|
252
256
|
})
|
|
253
257
|
|
|
@@ -50,6 +50,7 @@ import type {
|
|
|
50
50
|
import type { CreateForAgentOptions } from './terminal-manager.server'
|
|
51
51
|
import type { WorkspaceRootResolution } from './workspace-binder.server'
|
|
52
52
|
import { ProviderError } from './providers/contracts'
|
|
53
|
+
import { isAwaitingInput } from './terminal-foreground.server'
|
|
53
54
|
import { buildAgentTerminalLaunch, resolveLocalSandbox } from './sandbox/local-sandbox.server'
|
|
54
55
|
import {
|
|
55
56
|
readThreadExecutionPolicy,
|
|
@@ -154,6 +155,8 @@ export interface AgentTerminalCallOpts {
|
|
|
154
155
|
| 'createForAgent'
|
|
155
156
|
| 'agentWrite'
|
|
156
157
|
| 'agentSignal'
|
|
158
|
+
| 'agentSignalForeground'
|
|
159
|
+
| 'foregroundOf'
|
|
157
160
|
| 'agentClose'
|
|
158
161
|
| 'readScreen'
|
|
159
162
|
| 'listForAgent'
|
|
@@ -185,6 +188,12 @@ export interface AgentTerminalSendResult {
|
|
|
185
188
|
waitReason: AgentTerminalWaitReason
|
|
186
189
|
sessionStatus: AgentTerminalSessionStatus
|
|
187
190
|
truncated: boolean
|
|
191
|
+
/**
|
|
192
|
+
* stdin readiness 启发式(P5 任务 4 / §6.5 O2):前台命令处于可中断睡眠(大概率阻塞在
|
|
193
|
+
* 读 stdin——交互提示/REPL/分页器)。仅在为 true 时出现,避免给模型塞恒 false 的噪声。
|
|
194
|
+
* 不是保证(`sleep 10` 同样睡眠),工具描述按「可能」表述。
|
|
195
|
+
*/
|
|
196
|
+
awaitingInput?: boolean
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
/** terminal_list 列表项(§6.2:exitCode 不下发的 agent 通道恒 running,省略可选键)。 */
|
|
@@ -605,7 +614,12 @@ export async function sendToAgentTerminal(
|
|
|
605
614
|
} catch {
|
|
606
615
|
// 回收竞态 / 读取悬挂超时(兜底):viewport 保持空(进程已不在,输出无从读取)
|
|
607
616
|
}
|
|
608
|
-
|
|
617
|
+
// stdin readiness(P5 任务 4):仍 running 时探一次前台组——命令多半在等输入(交互提示
|
|
618
|
+
// 回显后静默、REPL、less/man 分页)时给模型一个明确信号,免得它以为命令跑完了。
|
|
619
|
+
const awaitingInput = state === 'running'
|
|
620
|
+
? isAwaitingInput(await manager.foregroundOf(sessionId))
|
|
621
|
+
: false
|
|
622
|
+
return { viewport, waitReason, sessionStatus: state, truncated, ...(awaitingInput ? { awaitingInput } : {}) }
|
|
609
623
|
}
|
|
610
624
|
|
|
611
625
|
// ── terminal_read / terminal_signal / terminal_close / terminal_list(§6.2)──────
|
|
@@ -630,21 +644,28 @@ export async function readAgentTerminal(
|
|
|
630
644
|
}
|
|
631
645
|
}
|
|
632
646
|
|
|
647
|
+
/** 终止型信号(P5 任务 4 / §6.5 O3):仅定向到前台进程组,绝不发给 shell/后台作业。 */
|
|
648
|
+
const FOREGROUND_ONLY_SIGNALS: ReadonlySet<TerminalAgentSignal> = new Set(['SIGTERM', 'SIGKILL', 'SIGHUP'])
|
|
649
|
+
|
|
633
650
|
/**
|
|
634
|
-
* 发送信号(§6.2 terminal_signal
|
|
635
|
-
*
|
|
651
|
+
* 发送信号(§6.2 terminal_signal):
|
|
652
|
+
* - SIGINT/SIGTSTP → 控制字符(`\x03`/`\x1a`,等价于用户在终端按键);
|
|
653
|
+
* - SIGTERM/SIGKILL/SIGHUP → **前台进程组定向**(`kill(-pgid)`):只命当前前台命令,
|
|
654
|
+
* 不波及 shell 与后台作业;前台就是 shell 或无法探测时 fail-closed 拒绝并引导
|
|
655
|
+
* terminal_close(P5 任务 4 收口 O3 偏离:v1 曾对这三个信号一律拒)。
|
|
636
656
|
*/
|
|
637
657
|
export async function signalAgentTerminal(
|
|
638
658
|
ctx: AgentTerminalCtx,
|
|
639
659
|
sessionId: string,
|
|
640
660
|
signal: TerminalAgentSignal,
|
|
641
661
|
opts: AgentTerminalCallOpts = {},
|
|
642
|
-
): Promise<{ delivered: true; method: 'control-char' }> {
|
|
662
|
+
): Promise<{ delivered: true; method: 'control-char' | 'foreground-group'; pgid?: number }> {
|
|
643
663
|
const manager = await resolveManager(opts)
|
|
644
664
|
// 发送前档位门控(安全边界):信号同样能改变沙箱内进程状态。
|
|
645
665
|
ensureSendAllowedWithinPolicy(manager, ctx.threadId, sessionId, await readThreadExecutionPolicy(ctx.threadId))
|
|
646
666
|
ensureThreadTerminal(manager, ctx.threadId, sessionId)
|
|
647
667
|
try {
|
|
668
|
+
if (FOREGROUND_ONLY_SIGNALS.has(signal)) return await manager.agentSignalForeground(sessionId, signal)
|
|
648
669
|
return manager.agentSignal(sessionId, signal)
|
|
649
670
|
} catch (err) {
|
|
650
671
|
if (isManagerError(err) && err.code === 'invalid_signal') {
|
|
@@ -703,6 +703,7 @@ describe('agentControlLogReduce', () => {
|
|
|
703
703
|
agents: {
|
|
704
704
|
'agent-1': { ...started, type: 'allblue.agent.finished', status: 'completed', finishedAt: 200, tokens: 12 },
|
|
705
705
|
},
|
|
706
|
+
workflows: {},
|
|
706
707
|
config: { modelSearchEnabled: { value: true } },
|
|
707
708
|
settings: { reasoning: 'high' },
|
|
708
709
|
})
|
|
@@ -43,14 +43,21 @@ export interface AgentControlLogEntry {
|
|
|
43
43
|
|
|
44
44
|
export interface AgentControlLogState {
|
|
45
45
|
agents: Record<string, AgentControlLogEntry>
|
|
46
|
+
/**
|
|
47
|
+
* workflow run 折叠态(P5 任务 1):allblue.workflow.* 记录折叠产物。与 agents
|
|
48
|
+
* 共用同一 reducer(官方 durability.logState 只有一个槽位),按 runId 索引。
|
|
49
|
+
*/
|
|
50
|
+
workflows: Record<string, import('../workflow/types').WorkflowRunSnapshot>
|
|
46
51
|
settings?: ThreadSettings
|
|
47
52
|
config: Record<string, { value: unknown }>
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export const agentControlLogReduce: ReduceOptions<AgentControlLogState> = {
|
|
51
56
|
includeHarnessRecords: ['harness.settings', 'harness.config'],
|
|
52
|
-
version
|
|
53
|
-
|
|
57
|
+
// v3(P5 任务 1):state 增加 workflows 折叠桶,形状变更须 bump version——旧快照
|
|
58
|
+
// 被忽略并全量重放一次(每线程一次性成本),保证 workflows 从空桶正确起算。
|
|
59
|
+
version: '3',
|
|
60
|
+
initial: { agents: {}, workflows: {}, config: {} },
|
|
54
61
|
record: ({ state, record }) => {
|
|
55
62
|
if (record.type === 'harness.settings') {
|
|
56
63
|
if (!record.settings || typeof record.settings !== 'object' || Array.isArray(record.settings)) return state
|
|
@@ -73,6 +80,52 @@ export const agentControlLogReduce: ReduceOptions<AgentControlLogState> = {
|
|
|
73
80
|
if (!previous) return state
|
|
74
81
|
return { ...state, agents: { ...state.agents, [patch.runId]: { ...previous, ...patch } } }
|
|
75
82
|
}
|
|
83
|
+
const workflows = state.workflows ?? {}
|
|
84
|
+
if (record.type === 'allblue.workflow.started') {
|
|
85
|
+
const entry = record as unknown as import('../workflow/types').WorkflowRunSnapshot
|
|
86
|
+
if (workflows[entry.runId]) return state
|
|
87
|
+
return { ...state, workflows: { ...workflows, [entry.runId]: entry } }
|
|
88
|
+
}
|
|
89
|
+
if (record.type === 'allblue.workflow.stage') {
|
|
90
|
+
const patch = record as unknown as {
|
|
91
|
+
runId: string
|
|
92
|
+
stage: import('../workflow/types').WorkflowStageState
|
|
93
|
+
}
|
|
94
|
+
const previous = workflows[patch.runId]
|
|
95
|
+
if (!previous) return state
|
|
96
|
+
const stages = previous.stages.map((stage) =>
|
|
97
|
+
stage.id === patch.stage.id ? { ...stage, ...patch.stage } : stage,
|
|
98
|
+
)
|
|
99
|
+
return {
|
|
100
|
+
...state,
|
|
101
|
+
workflows: {
|
|
102
|
+
...workflows,
|
|
103
|
+
[patch.runId]: { ...previous, stages, updatedAt: patch.stage.finishedAt ?? Date.now() },
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (record.type === 'allblue.workflow.finished') {
|
|
108
|
+
const patch = record as unknown as {
|
|
109
|
+
runId: string
|
|
110
|
+
status: import('../workflow/types').WorkflowRunStatus
|
|
111
|
+
round?: number
|
|
112
|
+
finishedAt: number
|
|
113
|
+
}
|
|
114
|
+
const previous = workflows[patch.runId]
|
|
115
|
+
if (!previous) return state
|
|
116
|
+
return {
|
|
117
|
+
...state,
|
|
118
|
+
workflows: {
|
|
119
|
+
...workflows,
|
|
120
|
+
[patch.runId]: {
|
|
121
|
+
...previous,
|
|
122
|
+
status: patch.status,
|
|
123
|
+
...(patch.round === undefined ? {} : { round: patch.round }),
|
|
124
|
+
updatedAt: patch.finishedAt,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
}
|
|
76
129
|
return state
|
|
77
130
|
},
|
|
78
131
|
}
|