scope-agent-workbench 0.2.0 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/bridge/agent-email-relay.mjs +160 -160
  3. package/bridge/app-server-websocket-transport.mjs +219 -219
  4. package/bridge/archive/service.mjs +130 -130
  5. package/bridge/auth-profile-failover.mjs +58 -58
  6. package/bridge/auth-profile-manager.mjs +215 -215
  7. package/bridge/capacity-recovery.mjs +90 -90
  8. package/bridge/gpu-usage-history.mjs +322 -322
  9. package/bridge/local/history.mjs +20 -5
  10. package/bridge/plugins/aliyun-dlc/monitor.mjs +236 -236
  11. package/bridge/plugins/aliyun-dlc/probe.mjs +701 -701
  12. package/bridge/private-gateway.mjs +371 -371
  13. package/bridge/private-start.mjs +22 -22
  14. package/bridge/probes/app-server-handoff-probe.mjs +87 -87
  15. package/bridge/probes/app-server-writer-probe.mjs +69 -69
  16. package/bridge/probes/assistant-search-probe.mjs +321 -321
  17. package/bridge/probes/dialogue-probe.mjs +462 -462
  18. package/bridge/probes/history-probe.mjs +430 -345
  19. package/bridge/probes/new-session-preflight.mjs +14 -14
  20. package/bridge/probes/profile-cancel-probe.mjs +17 -17
  21. package/bridge/probes/profile-delete-probe.mjs +26 -26
  22. package/bridge/probes/profile-list-probe.mjs +114 -114
  23. package/bridge/probes/profile-write-probe.mjs +109 -109
  24. package/bridge/probes/raw-context-probe.mjs +51 -51
  25. package/bridge/probes/remote-probe.mjs +627 -626
  26. package/bridge/probes/submission-probe.mjs +2 -2
  27. package/bridge/probes/takeover-probe.mjs +326 -326
  28. package/bridge/probes/vscode-open-preflight.mjs +21 -21
  29. package/bridge/providers/claude-interactive.py +463 -341
  30. package/bridge/providers/cli-command.mjs +103 -103
  31. package/bridge/providers/conversations.mjs +231 -231
  32. package/bridge/providers/native-commands.py +38 -38
  33. package/bridge/providers/native-session-state.mjs +14 -14
  34. package/bridge/providers/native-session-state.py +96 -96
  35. package/bridge/providers/remote-job.py +130 -130
  36. package/bridge/remote-app-server-command.mjs +121 -121
  37. package/bridge/remote-directory-listing.mjs +148 -148
  38. package/bridge/rollout-summary.mjs +20 -2
  39. package/bridge/routes/dialogue.mjs +48 -3
  40. package/bridge/routes/models.mjs +312 -312
  41. package/bridge/server.mjs +3357 -3332
  42. package/bridge/session-attachments.mjs +150 -150
  43. package/bridge/session-catalog/agy-history.py +141 -2
  44. package/bridge/session-catalog/catalog.mjs +17 -0
  45. package/bridge/session-catalog/probe.py +1207 -331
  46. package/bridge/session-catalog/routes.mjs +6 -0
  47. package/bridge/start.mjs +205 -205
  48. package/bridge/state-persistence.mjs +9 -1
  49. package/bridge/tmux-session-control.mjs +29 -29
  50. package/bridge/vscode-opener.mjs +157 -157
  51. package/bridge/web-terminal.mjs +52 -52
  52. package/bridge/workbench/manager-context.mjs +51 -51
  53. package/bridge/workbench/service.mjs +301 -301
  54. package/dist/client/.vite/manifest.json +4 -4
  55. package/dist/client/assets/{index-Enu1x0PS.js → index-BMior55c.js} +2 -2
  56. package/dist/client/assets/{layout-segment-context-CmJzExWq.js → layout-segment-context-DjGudgXn.js} +1 -1
  57. package/dist/client/assets/page-CJqXlhDs.js +551 -0
  58. package/dist/client/assets/page-LYzRz6_S.css +1 -0
  59. package/dist/client/favicon.svg +6 -6
  60. package/dist/server/__vite_rsc_assets_manifest.js +8 -8
  61. package/dist/server/index.js +7 -7
  62. package/dist/server/ssr/__vite_rsc_assets_manifest.js +8 -8
  63. package/dist/server/ssr/assets/{page-CYYyCnKD.js → page-BB9Dri2u.js} +2416 -271
  64. package/dist/server/ssr/assets/page-LYzRz6_S.css +1 -0
  65. package/dist/server/ssr/index.js +1 -1
  66. package/dist/server/ssr/vinext-server.json +1 -1
  67. package/dist/server/vinext-server.json +1 -1
  68. package/dist/server/wrangler.json +1 -1
  69. package/lib/browser-snapshot-cache.js +53 -53
  70. package/lib/formula-preview.js +1 -1
  71. package/lib/incremental-snapshot.js +300 -300
  72. package/lib/markdown-math.js +151 -151
  73. package/lib/remote-links.js +95 -95
  74. package/lib/runtime-config.js +70 -70
  75. package/lib/session-filters.js +38 -38
  76. package/lib/ssh-config.js +26 -26
  77. package/lib/stable-order.js +39 -39
  78. package/lib/subagent-display-prefs.ts +130 -0
  79. package/package.json +1 -1
  80. package/scripts/agent-email-relay.mjs +104 -104
  81. package/scripts/email-notification-cli.mjs +28 -28
  82. package/scripts/enable-private-access.ps1 +109 -109
  83. package/scripts/fixtures/native-conversations.mjs +164 -6
  84. package/scripts/fixtures/workbench-conversations.mjs +475 -352
  85. package/scripts/preview-workbench.mjs +669 -669
  86. package/dist/client/assets/page-COBv6VWj.css +0 -1
  87. package/dist/client/assets/page-DVjU6VG_.js +0 -550
  88. package/dist/server/ssr/assets/page-COBv6VWj.css +0 -1
@@ -1,301 +1,301 @@
1
- import { taskArchiveActions } from "./task-archive.mjs";
2
- import { randomUUID } from "node:crypto";
3
- import {
4
- PROVIDERS,
5
- validateWorkbenchConfig,
6
- } from "../../lib/workbench-config.js";
7
- import { HELD_STATES, placement, validateTask } from "./scheduler.mjs";
8
- import { managerPrompt } from "./manager-context.mjs";
9
- import { formatUserPromptPreview } from "../session-attachments.mjs";
10
-
11
- const timestamp = () => new Date().toISOString();
12
- export class WorkbenchService {
13
- constructor({ store, snapshot, adapters, taskQueueEnabled = true, resolveAttachments = null }) {
14
- this.taskQueueEnabled = taskQueueEnabled;
15
- this.store = store;
16
- this.snapshot = snapshot;
17
- this.adapters = adapters;
18
- this.resolveAttachments = resolveAttachments;
19
- this.archiveTask = taskArchiveActions({ store, adapters });
20
- this.launching = new Set();
21
- this.ticking = false;
22
- this.error = null;
23
- }
24
- state() {
25
- const state = this.store.read();
26
- const snapshot = this.snapshot();
27
- return {
28
- ...state,
29
- providers: PROVIDERS,
30
- features: { taskQueue: this.taskQueueEnabled },
31
- error: this.error,
32
- tasks: state.tasks.map((task) => ({
33
- ...task,
34
- queueReason:
35
- task.status === "queued"
36
- ? (!this.taskQueueEnabled && task.kind !== "manager" ? "实验任务队列未启用" : placement(task, state, snapshot).reason || "准备执行")
37
- : null,
38
- })),
39
- };
40
- }
41
- async configure(config, revision) {
42
- const valid = validateWorkbenchConfig(config);
43
- await this.store.update((state) => {
44
- if (revision !== (state.configRevision || 0))
45
- throw new Error("配置已变化,请重新载入后保存");
46
- const changed =
47
- JSON.stringify(valid.manager) !== JSON.stringify(state.config.manager);
48
- if (
49
- changed &&
50
- state.tasks.some(
51
- (t) =>
52
- t.kind === "manager" &&
53
- (HELD_STATES.has(t.status) || t.status === "queued"),
54
- )
55
- )
56
- throw new Error("总调度仍有未结束的消息,请等待结果后更改设置");
57
- if (
58
- valid.manager.host !== state.config.manager.host ||
59
- valid.manager.cwd !== state.config.manager.cwd
60
- )
61
- state.managerSession = null;
62
- state.config = valid;
63
- state.configRevision = (state.configRevision || 0) + 1;
64
- });
65
- }
66
- async enqueue(body, kind = "task") {
67
- if (kind !== "manager" && !this.taskQueueEnabled) throw new Error("实验任务队列未启用,请先配置 deployment.json");
68
- if (
69
- typeof body.requestId !== "string" ||
70
- !/^[a-zA-Z0-9_-]{8,100}$/.test(body.requestId)
71
- )
72
- throw new Error("缺少有效的请求标识");
73
- const state = this.store.read();
74
- const existing = state.tasks.find((t) => t.requestId === body.requestId);
75
- const rawAttachments =
76
- Array.isArray(body.attachments) && body.attachments.length
77
- ? body.attachments
78
- : [];
79
- const targetHost =
80
- kind === "manager" ? state.config.manager.host : body.host;
81
- const attachments = rawAttachments.length
82
- ? this.resolveAttachments
83
- ? this.resolveAttachments(rawAttachments, targetHost, {
84
- scope: kind === "manager" ? "manager" : "task",
85
- })
86
- : rawAttachments
87
- : [];
88
- const input =
89
- kind === "manager"
90
- ? {
91
- provider: "codex",
92
- host: state.config.manager.host,
93
- cwd: state.config.manager.cwd,
94
- prompt: body.prompt ?? "",
95
- ...(attachments.length ? { attachments } : {}),
96
- }
97
- : {
98
- ...body,
99
- ...(attachments.length ? { attachments } : {}),
100
- };
101
- const taskInput = validateTask(input);
102
- const signature = JSON.stringify({ ...taskInput, kind });
103
- if (existing) {
104
- if (existing.signature !== signature)
105
- throw new Error("同一请求标识不能用于不同任务");
106
- return existing;
107
- }
108
- if (!state.config.providers[taskInput.provider].enabled)
109
- throw new Error("请先在设置中启用此 Agent");
110
- if (!this.snapshot().hosts.some((h) => h.alias === taskInput.host))
111
- throw new Error("所选主机尚未被 SCOPE 发现");
112
- const task = {
113
- ...taskInput,
114
- id: randomUUID(),
115
- requestId: body.requestId,
116
- signature,
117
- kind,
118
- status: "queued",
119
- createdAt: timestamp(),
120
- updatedAt: timestamp(),
121
- remote: null,
122
- gpuIndices: [],
123
- };
124
- return this.store.update((current) => {
125
- const duplicate = current.tasks.find(
126
- (t) => t.requestId === body.requestId,
127
- );
128
- if (duplicate) {
129
- if (duplicate.signature !== signature) throw new Error("请求标识冲突");
130
- return duplicate;
131
- }
132
- if (kind !== "manager" && current.tasks.filter((t) => t.kind !== "manager" && !t.archivedAt).length >= 500)
133
- throw new Error("未归档任务已达 500 条,请在左侧归档已结束的任务后继续");
134
- if (!current.config.providers[task.provider].enabled)
135
- throw new Error("此 Agent 的配置已变化,请重新载入后派发");
136
- if (
137
- kind === "manager" &&
138
- (current.config.manager.host !== task.host ||
139
- current.config.manager.cwd !== task.cwd)
140
- )
141
- throw new Error("总调度配置已变化,请重新载入后发送");
142
- current.tasks.push(task);
143
- if (kind === "manager")
144
- current.messages.push({
145
- id: randomUUID(),
146
- role: "user",
147
- text: formatUserPromptPreview(task.prompt, task.attachments),
148
- taskId: task.id,
149
- createdAt: task.createdAt,
150
- });
151
- return task;
152
- });
153
- }
154
- async action(id, action) {
155
- if (["archive", "restore"].includes(action))
156
- return this.archiveTask(id, action);
157
- await this.store.update((state) => {
158
- const task = state.tasks.find((t) => t.id === id);
159
- if (!task) throw new Error("任务不存在");
160
- if (action === "cancel" && task.status === "queued")
161
- task.status = "cancelled";
162
- else if (action === "release" && task.status === "unknown")
163
- task.status = "released";
164
- else throw new Error("当前状态不支持此操作");
165
- task.updatedAt = timestamp();
166
- task.note =
167
- action === "release"
168
- ? "用户核实远端后释放工作台占用;未向远端发送终止信号"
169
- : "排队任务已取消";
170
- });
171
- }
172
- async checkpoint(id, remote) {
173
- await this.store.update((state) => {
174
- const task = state.tasks.find((t) => t.id === id);
175
- task.remote = remote;
176
- if (task.kind === "manager") state.managerSession = remote;
177
- });
178
- }
179
- async launch(task, config) {
180
- this.launching.add(task.id);
181
- try {
182
- const adapter = this.adapters[task.provider];
183
- const remote = await adapter.launch(task, config, (value) =>
184
- this.checkpoint(task.id, value),
185
- );
186
- await this.store.update((state) => {
187
- const record = state.tasks.find((t) => t.id === task.id);
188
- record.remote = remote;
189
- record.status = "running";
190
- record.updatedAt = timestamp();
191
- if (record.kind === "manager") state.managerSession = remote;
192
- });
193
- } catch (error) {
194
- // The transport may have accepted the request before the connection failed.
195
- // Keep the slot and receipt for reconciliation; never silently relaunch.
196
- await this.store.update((state) => {
197
- const record = state.tasks.find((t) => t.id === task.id);
198
- record.status = error.beforeLaunch === true ? "failed" : "unknown";
199
- record.error = error.message;
200
- record.updatedAt = timestamp();
201
- if (record.kind === "manager" && record.status === "failed")
202
- state.messages.push({
203
- id: randomUUID(),
204
- role: "assistant",
205
- text: error.message,
206
- taskId: task.id,
207
- createdAt: timestamp(),
208
- });
209
- });
210
- } finally {
211
- this.launching.delete(task.id);
212
- }
213
- }
214
- async poll(task) {
215
- if (this.launching.has(task.id)) return;
216
- let result;
217
- try {
218
- result = await this.adapters[task.provider].poll(task);
219
- } catch (error) {
220
- result = { status: "unknown", error: error.message };
221
- }
222
- const previous = JSON.stringify({
223
- status: task.status,
224
- result: task.result,
225
- });
226
- if (previous === JSON.stringify({ status: result.status, result })) return;
227
- await this.store.update((state) => {
228
- const record = state.tasks.find((t) => t.id === task.id);
229
- if (!HELD_STATES.has(record.status)) return;
230
- record.status = result.status;
231
- record.result = result;
232
- record.error = result.error || null;
233
- record.updatedAt = timestamp();
234
- if (
235
- record.kind === "manager" &&
236
- ["completed", "failed"].includes(result.status)
237
- ) {
238
- state.messages.push({
239
- id: randomUUID(),
240
- role: "assistant",
241
- text: result.text || result.error || "本次没有返回文本。",
242
- taskId: task.id,
243
- createdAt: timestamp(),
244
- });
245
- }
246
- });
247
- }
248
- async tick() {
249
- if (this.ticking) return;
250
- this.ticking = true;
251
- try {
252
- const active = this.store
253
- .read()
254
- .tasks.filter((t) => HELD_STATES.has(t.status));
255
- // A failed host must not prevent reconciliation on the other hosts.
256
- await Promise.all(active.map((t) => this.poll(t)));
257
- for (const candidate of this.store
258
- .read()
259
- .tasks.filter((t) => t.status === "queued" && (this.taskQueueEnabled || t.kind === "manager"))) {
260
- let launch;
261
- await this.store.update((state) => {
262
- const task = state.tasks.find((t) => t.id === candidate.id);
263
- if (task.status !== "queued") return;
264
- const selected = placement(task, state, this.snapshot());
265
- if (selected.reason) return;
266
- task.status = "starting";
267
- task.gpuIndices = selected.gpuIndices;
268
- task.updatedAt = timestamp();
269
- if (task.kind === "manager") task.remote = state.managerSession;
270
- if (task.provider !== "codex")
271
- task.remote = { kind: "remote-cli", id: task.id };
272
- const effective = structuredClone(task);
273
- if (task.kind === "manager")
274
- effective.prompt = managerPrompt(
275
- task.prompt,
276
- state,
277
- this.snapshot(),
278
- this.taskQueueEnabled,
279
- );
280
- launch = { task: effective, config: structuredClone(state.config) };
281
- });
282
- if (launch)
283
- void this.launch(launch.task, launch.config).catch((error) => {
284
- this.error = error.message;
285
- });
286
- }
287
- this.error = null;
288
- } catch (error) {
289
- this.error = error.message;
290
- } finally {
291
- this.ticking = false;
292
- }
293
- }
294
- start() {
295
- this.timer = setInterval(() => void this.tick(), 3000);
296
- this.timer.unref();
297
- }
298
- stop() {
299
- clearInterval(this.timer);
300
- }
301
- }
1
+ import { taskArchiveActions } from "./task-archive.mjs";
2
+ import { randomUUID } from "node:crypto";
3
+ import {
4
+ PROVIDERS,
5
+ validateWorkbenchConfig,
6
+ } from "../../lib/workbench-config.js";
7
+ import { HELD_STATES, placement, validateTask } from "./scheduler.mjs";
8
+ import { managerPrompt } from "./manager-context.mjs";
9
+ import { formatUserPromptPreview } from "../session-attachments.mjs";
10
+
11
+ const timestamp = () => new Date().toISOString();
12
+ export class WorkbenchService {
13
+ constructor({ store, snapshot, adapters, taskQueueEnabled = true, resolveAttachments = null }) {
14
+ this.taskQueueEnabled = taskQueueEnabled;
15
+ this.store = store;
16
+ this.snapshot = snapshot;
17
+ this.adapters = adapters;
18
+ this.resolveAttachments = resolveAttachments;
19
+ this.archiveTask = taskArchiveActions({ store, adapters });
20
+ this.launching = new Set();
21
+ this.ticking = false;
22
+ this.error = null;
23
+ }
24
+ state() {
25
+ const state = this.store.read();
26
+ const snapshot = this.snapshot();
27
+ return {
28
+ ...state,
29
+ providers: PROVIDERS,
30
+ features: { taskQueue: this.taskQueueEnabled },
31
+ error: this.error,
32
+ tasks: state.tasks.map((task) => ({
33
+ ...task,
34
+ queueReason:
35
+ task.status === "queued"
36
+ ? (!this.taskQueueEnabled && task.kind !== "manager" ? "实验任务队列未启用" : placement(task, state, snapshot).reason || "准备执行")
37
+ : null,
38
+ })),
39
+ };
40
+ }
41
+ async configure(config, revision) {
42
+ const valid = validateWorkbenchConfig(config);
43
+ await this.store.update((state) => {
44
+ if (revision !== (state.configRevision || 0))
45
+ throw new Error("配置已变化,请重新载入后保存");
46
+ const changed =
47
+ JSON.stringify(valid.manager) !== JSON.stringify(state.config.manager);
48
+ if (
49
+ changed &&
50
+ state.tasks.some(
51
+ (t) =>
52
+ t.kind === "manager" &&
53
+ (HELD_STATES.has(t.status) || t.status === "queued"),
54
+ )
55
+ )
56
+ throw new Error("总调度仍有未结束的消息,请等待结果后更改设置");
57
+ if (
58
+ valid.manager.host !== state.config.manager.host ||
59
+ valid.manager.cwd !== state.config.manager.cwd
60
+ )
61
+ state.managerSession = null;
62
+ state.config = valid;
63
+ state.configRevision = (state.configRevision || 0) + 1;
64
+ });
65
+ }
66
+ async enqueue(body, kind = "task") {
67
+ if (kind !== "manager" && !this.taskQueueEnabled) throw new Error("实验任务队列未启用,请先配置 deployment.json");
68
+ if (
69
+ typeof body.requestId !== "string" ||
70
+ !/^[a-zA-Z0-9_-]{8,100}$/.test(body.requestId)
71
+ )
72
+ throw new Error("缺少有效的请求标识");
73
+ const state = this.store.read();
74
+ const existing = state.tasks.find((t) => t.requestId === body.requestId);
75
+ const rawAttachments =
76
+ Array.isArray(body.attachments) && body.attachments.length
77
+ ? body.attachments
78
+ : [];
79
+ const targetHost =
80
+ kind === "manager" ? state.config.manager.host : body.host;
81
+ const attachments = rawAttachments.length
82
+ ? this.resolveAttachments
83
+ ? this.resolveAttachments(rawAttachments, targetHost, {
84
+ scope: kind === "manager" ? "manager" : "task",
85
+ })
86
+ : rawAttachments
87
+ : [];
88
+ const input =
89
+ kind === "manager"
90
+ ? {
91
+ provider: "codex",
92
+ host: state.config.manager.host,
93
+ cwd: state.config.manager.cwd,
94
+ prompt: body.prompt ?? "",
95
+ ...(attachments.length ? { attachments } : {}),
96
+ }
97
+ : {
98
+ ...body,
99
+ ...(attachments.length ? { attachments } : {}),
100
+ };
101
+ const taskInput = validateTask(input);
102
+ const signature = JSON.stringify({ ...taskInput, kind });
103
+ if (existing) {
104
+ if (existing.signature !== signature)
105
+ throw new Error("同一请求标识不能用于不同任务");
106
+ return existing;
107
+ }
108
+ if (!state.config.providers[taskInput.provider].enabled)
109
+ throw new Error("请先在设置中启用此 Agent");
110
+ if (!this.snapshot().hosts.some((h) => h.alias === taskInput.host))
111
+ throw new Error("所选主机尚未被 SCOPE 发现");
112
+ const task = {
113
+ ...taskInput,
114
+ id: randomUUID(),
115
+ requestId: body.requestId,
116
+ signature,
117
+ kind,
118
+ status: "queued",
119
+ createdAt: timestamp(),
120
+ updatedAt: timestamp(),
121
+ remote: null,
122
+ gpuIndices: [],
123
+ };
124
+ return this.store.update((current) => {
125
+ const duplicate = current.tasks.find(
126
+ (t) => t.requestId === body.requestId,
127
+ );
128
+ if (duplicate) {
129
+ if (duplicate.signature !== signature) throw new Error("请求标识冲突");
130
+ return duplicate;
131
+ }
132
+ if (kind !== "manager" && current.tasks.filter((t) => t.kind !== "manager" && !t.archivedAt).length >= 500)
133
+ throw new Error("未归档任务已达 500 条,请在左侧归档已结束的任务后继续");
134
+ if (!current.config.providers[task.provider].enabled)
135
+ throw new Error("此 Agent 的配置已变化,请重新载入后派发");
136
+ if (
137
+ kind === "manager" &&
138
+ (current.config.manager.host !== task.host ||
139
+ current.config.manager.cwd !== task.cwd)
140
+ )
141
+ throw new Error("总调度配置已变化,请重新载入后发送");
142
+ current.tasks.push(task);
143
+ if (kind === "manager")
144
+ current.messages.push({
145
+ id: randomUUID(),
146
+ role: "user",
147
+ text: formatUserPromptPreview(task.prompt, task.attachments),
148
+ taskId: task.id,
149
+ createdAt: task.createdAt,
150
+ });
151
+ return task;
152
+ });
153
+ }
154
+ async action(id, action) {
155
+ if (["archive", "restore"].includes(action))
156
+ return this.archiveTask(id, action);
157
+ await this.store.update((state) => {
158
+ const task = state.tasks.find((t) => t.id === id);
159
+ if (!task) throw new Error("任务不存在");
160
+ if (action === "cancel" && task.status === "queued")
161
+ task.status = "cancelled";
162
+ else if (action === "release" && task.status === "unknown")
163
+ task.status = "released";
164
+ else throw new Error("当前状态不支持此操作");
165
+ task.updatedAt = timestamp();
166
+ task.note =
167
+ action === "release"
168
+ ? "用户核实远端后释放工作台占用;未向远端发送终止信号"
169
+ : "排队任务已取消";
170
+ });
171
+ }
172
+ async checkpoint(id, remote) {
173
+ await this.store.update((state) => {
174
+ const task = state.tasks.find((t) => t.id === id);
175
+ task.remote = remote;
176
+ if (task.kind === "manager") state.managerSession = remote;
177
+ });
178
+ }
179
+ async launch(task, config) {
180
+ this.launching.add(task.id);
181
+ try {
182
+ const adapter = this.adapters[task.provider];
183
+ const remote = await adapter.launch(task, config, (value) =>
184
+ this.checkpoint(task.id, value),
185
+ );
186
+ await this.store.update((state) => {
187
+ const record = state.tasks.find((t) => t.id === task.id);
188
+ record.remote = remote;
189
+ record.status = "running";
190
+ record.updatedAt = timestamp();
191
+ if (record.kind === "manager") state.managerSession = remote;
192
+ });
193
+ } catch (error) {
194
+ // The transport may have accepted the request before the connection failed.
195
+ // Keep the slot and receipt for reconciliation; never silently relaunch.
196
+ await this.store.update((state) => {
197
+ const record = state.tasks.find((t) => t.id === task.id);
198
+ record.status = error.beforeLaunch === true ? "failed" : "unknown";
199
+ record.error = error.message;
200
+ record.updatedAt = timestamp();
201
+ if (record.kind === "manager" && record.status === "failed")
202
+ state.messages.push({
203
+ id: randomUUID(),
204
+ role: "assistant",
205
+ text: error.message,
206
+ taskId: task.id,
207
+ createdAt: timestamp(),
208
+ });
209
+ });
210
+ } finally {
211
+ this.launching.delete(task.id);
212
+ }
213
+ }
214
+ async poll(task) {
215
+ if (this.launching.has(task.id)) return;
216
+ let result;
217
+ try {
218
+ result = await this.adapters[task.provider].poll(task);
219
+ } catch (error) {
220
+ result = { status: "unknown", error: error.message };
221
+ }
222
+ const previous = JSON.stringify({
223
+ status: task.status,
224
+ result: task.result,
225
+ });
226
+ if (previous === JSON.stringify({ status: result.status, result })) return;
227
+ await this.store.update((state) => {
228
+ const record = state.tasks.find((t) => t.id === task.id);
229
+ if (!HELD_STATES.has(record.status)) return;
230
+ record.status = result.status;
231
+ record.result = result;
232
+ record.error = result.error || null;
233
+ record.updatedAt = timestamp();
234
+ if (
235
+ record.kind === "manager" &&
236
+ ["completed", "failed"].includes(result.status)
237
+ ) {
238
+ state.messages.push({
239
+ id: randomUUID(),
240
+ role: "assistant",
241
+ text: result.text || result.error || "本次没有返回文本。",
242
+ taskId: task.id,
243
+ createdAt: timestamp(),
244
+ });
245
+ }
246
+ });
247
+ }
248
+ async tick() {
249
+ if (this.ticking) return;
250
+ this.ticking = true;
251
+ try {
252
+ const active = this.store
253
+ .read()
254
+ .tasks.filter((t) => HELD_STATES.has(t.status));
255
+ // A failed host must not prevent reconciliation on the other hosts.
256
+ await Promise.all(active.map((t) => this.poll(t)));
257
+ for (const candidate of this.store
258
+ .read()
259
+ .tasks.filter((t) => t.status === "queued" && (this.taskQueueEnabled || t.kind === "manager"))) {
260
+ let launch;
261
+ await this.store.update((state) => {
262
+ const task = state.tasks.find((t) => t.id === candidate.id);
263
+ if (task.status !== "queued") return;
264
+ const selected = placement(task, state, this.snapshot());
265
+ if (selected.reason) return;
266
+ task.status = "starting";
267
+ task.gpuIndices = selected.gpuIndices;
268
+ task.updatedAt = timestamp();
269
+ if (task.kind === "manager") task.remote = state.managerSession;
270
+ if (task.provider !== "codex")
271
+ task.remote = { kind: "remote-cli", id: task.id };
272
+ const effective = structuredClone(task);
273
+ if (task.kind === "manager")
274
+ effective.prompt = managerPrompt(
275
+ task.prompt,
276
+ state,
277
+ this.snapshot(),
278
+ this.taskQueueEnabled,
279
+ );
280
+ launch = { task: effective, config: structuredClone(state.config) };
281
+ });
282
+ if (launch)
283
+ void this.launch(launch.task, launch.config).catch((error) => {
284
+ this.error = error.message;
285
+ });
286
+ }
287
+ this.error = null;
288
+ } catch (error) {
289
+ this.error = error.message;
290
+ } finally {
291
+ this.ticking = false;
292
+ }
293
+ }
294
+ start() {
295
+ this.timer = setInterval(() => void this.tick(), 3000);
296
+ this.timer.unref();
297
+ }
298
+ stop() {
299
+ clearInterval(this.timer);
300
+ }
301
+ }
@@ -11,7 +11,7 @@
11
11
  "name": "rolldown-runtime"
12
12
  },
13
13
  "app/page.tsx": {
14
- "file": "assets/page-DVjU6VG_.js",
14
+ "file": "assets/page-CJqXlhDs.js",
15
15
  "name": "page",
16
16
  "src": "app/page.tsx",
17
17
  "isDynamicEntry": true,
@@ -25,7 +25,7 @@
25
25
  "node_modules/@xterm/addon-fit/lib/addon-fit.mjs"
26
26
  ],
27
27
  "css": [
28
- "assets/page-COBv6VWj.css"
28
+ "assets/page-LYzRz6_S.css"
29
29
  ],
30
30
  "assets": [
31
31
  "assets/KaTeX_AMS-Regular-BQhdFMY1.woff2",
@@ -338,7 +338,7 @@
338
338
  "src": "node_modules/katex/dist/fonts/KaTeX_Typewriter-Regular.woff2"
339
339
  },
340
340
  "node_modules/vinext/dist/shims/layout-segment-context.js": {
341
- "file": "assets/layout-segment-context-CmJzExWq.js",
341
+ "file": "assets/layout-segment-context-DjGudgXn.js",
342
342
  "name": "layout-segment-context",
343
343
  "src": "node_modules/vinext/dist/shims/layout-segment-context.js",
344
344
  "isDynamicEntry": true,
@@ -349,7 +349,7 @@
349
349
  ]
350
350
  },
351
351
  "virtual:vinext-app-browser-entry": {
352
- "file": "assets/index-Enu1x0PS.js",
352
+ "file": "assets/index-BMior55c.js",
353
353
  "name": "index",
354
354
  "src": "virtual:vinext-app-browser-entry",
355
355
  "isEntry": true,