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,352 +1,475 @@
1
- /** Representative chat data, deliberately isolated from real hosts and agents. */
2
- export function createConversationFixture(snapshot, notify) {
3
- const isEn = process.env.SCOPE_PREVIEW_LOCALE === "en";
4
- const chats = new Map();
5
- const timers = new Map();
6
- function add(id, host, cwd, title, messages) {
7
- const events = messages.map(([kind, text], index) => ({
8
- id: `${id}-${index}`,
9
- kind,
10
- text,
11
- title: kind === "tool" ? (isEn ? "Inspect project layout" : "检查项目结构") : "",
12
- category: kind === "tool" ? "operations" : "dialogue",
13
- timestamp: new Date(
14
- Date.now() - (messages.length - index) * 60000,
15
- ).toISOString(),
16
- }));
17
- const rollout = {
18
- id,
19
- cwd,
20
- path: `/preview/${id}.jsonl`,
21
- model: "gpt-5-codex",
22
- reasoningEffort: "high",
23
- firstUser: title,
24
- lastUser: events.findLast((e) => e.kind === "user")?.text || "",
25
- lastAssistant: events.findLast((e) => e.kind === "assistant")?.text || "",
26
- userMessages: [],
27
- assistantMessages: [],
28
- turnState: "idle",
29
- lastEventAt: events.at(-1).timestamp,
30
- mtimeMs: Date.now(),
31
- account: null,
32
- tokenUsage: null,
33
- };
34
- const agent = {
35
- id: `app-server:${host}:${id}`,
36
- host,
37
- hostname: host,
38
- cwd,
39
- title,
40
- status: "idle",
41
- pid: 0,
42
- tty: "",
43
- executable: "codex",
44
- elapsedSeconds: 300,
45
- pane: null,
46
- rollout,
47
- subagents: [],
48
- mapping: { rollout: "exact", tmux: "none" },
49
- appServerManaged: true,
50
- suggestedSummary: {
51
- theme: title,
52
- category: "engineering",
53
- objective: "",
54
- progress: "",
55
- result: "",
56
- nextStep: "",
57
- source: "rollout",
58
- updatedAt: null,
59
- },
60
- lastActivityAt: Date.now(),
61
- };
62
- const session = {
63
- host,
64
- sessionId: id,
65
- cwd,
66
- path: rollout.path,
67
- status: "idle",
68
- model: rollout.model,
69
- effort: "high",
70
- connectionKey: "active",
71
- yolo: false,
72
- };
73
- snapshot.hosts.find((h) => h.alias === host).agents.push(agent);
74
- snapshot.appServer.sessions.push(session);
75
- chats.set(`${host}:${id}`, { events, agent, session });
76
- }
77
- if (isEn) {
78
- add("vision-plan", "lab-gpu", "/workspace/vision", "Vision model experiment roadmap", [
79
- ["user", "Help me organize the experiment roadmap for this project, starting with dataset splits and evaluation metrics."],
80
- [
81
- "intermediate",
82
- "Inspecting repository layout and existing configs before breaking down executable milestones.",
83
- ],
84
- [
85
- "tool",
86
- "Read README, dataset manifest, and evaluation entrypoints.\n\nSynthetic tool log from isolated preview mode.",
87
- ],
88
- ["tool", "Verified alignment between training and evaluation configs."],
89
- [
90
- "assistant",
91
- "Let's lock down three foundations first:\n\n1. **Freeze dataset splits**: share one manifest across train, val, and test.\n2. **Establish a compact baseline**: run a small model end-to-end to confirm reproducibility.\n3. **Unify evaluation metrics**: log accuracy, latency, and peak VRAM for apples-to-apples comparisons.\n\nI recommend finalizing the dataset config before reserving multi-GPU nodes.",
92
- ],
93
- ["user", "Sounds good—start with the dataset config and keep every milestone logged in this session."],
94
- [
95
- "assistant",
96
- "Got it. This session will serve as the persistent experiment log.\n\nI'll verify the dataset paths and split manifests first, and surface any confirmation prompts inline. Expand \"Used tools\" anytime to inspect commands and raw outputs.\n\n*Isolated UI preview — no remote agents or credentials connected.*",
97
- ],
98
- ]);
99
- add("vision-eval", "lab-gpu", "/workspace/vision", "Benchmark scripts & metric logs", [
100
- ["user", "Aggregate evaluation metrics across runs so they are easy to compare."],
101
- [
102
- "assistant",
103
- "We can index runs by model, dataset revision, metric score, and wall-clock time. This session tracks all evaluation runs.\n\nSynthetic conversation from isolated preview mode.",
104
- ],
105
- ]);
106
- add("scope-ui", "build-node", "/workspace/scope", "Project-native conversation workspace", [
107
- ["user", "Organize sessions by project on the left so I can resume any run in one click."],
108
- [
109
- "assistant",
110
- "Each session preserves its full message feed with a sticky composer below. Filters, GPU telemetry, and diagnostics stay tucked away until needed.\n\nSynthetic conversation from isolated preview mode.",
111
- ],
112
- ]);
113
- add("math-preview", "lab-gpu", "/workspace/research", "LaTeX & equation rendering check", [
114
- ["user", "Verify math preview while preserving custom paper macros."],
115
- ["assistant", [
116
- "Inline math: `\\pi`, `H=8`, `e(a)=\\widehat{J}(a)-J^\\beta(a)`.",
117
- "",
118
- "```latex",
119
- "% Eq. (5)",
120
- "\\widehat{J}(a)-J^\\pi(a)=e(a)+(1-\\gamma)\\gamma^H E_{s,a}\\Delta V(s_H).",
121
- "```",
122
- "",
123
- "Undefined paper macros stay intact:",
124
- "```tex",
125
- "\\hJ(\\va)-J^\\pi(\\va)=e(\\va).",
126
- "```",
127
- "",
128
- "Code identifiers remain code: `session_id`.",
129
- ].join("\n")],
130
- ]);
131
- } else {
132
- add("vision-plan", "lab-gpu", "/workspace/vision", "整理视觉模型的实验计划", [
133
- ["user", "帮我整理一下这个项目的实验计划,先把数据和评估方法确定下来。"],
134
- [
135
- "intermediate",
136
- "我先看一下项目结构和已有配置,再把下一步拆成可以直接执行的任务。",
137
- ],
138
- [
139
- "tool",
140
- "读取 README、数据配置和评估入口。\n\n这是隔离预览中的示例执行记录。",
141
- ],
142
- ["tool", "检查训练与评估配置的对应关系。"],
143
- [
144
- "assistant",
145
- "可以先完成三件事:\n\n1. **固定数据划分**:让训练、验证和测试使用同一份清单。\n2. **建立基线**:先跑一个较小模型,确认整个流程能够复现。\n3. **统一评估入口**:记录准确率、耗时和显存,方便比较后续实验。\n\n建议先处理数据配置,完成后再申请训练资源。",
146
- ],
147
- ["user", "好,先从数据配置开始。每一步的结果都留在这个会话里。"],
148
- [
149
- "assistant",
150
- "好,这个会话就作为实验工作的持续记录。\n\n我会先核对数据目录和划分清单,把需要你确认的内容直接放在对话中。具体命令和输出可以展开“执行过程”查看。\n\n*当前是界面演示,尚未连接真实的远端 Agent。*",
151
- ],
152
- ]);
153
- add("vision-eval", "lab-gpu", "/workspace/vision", "评估脚本与结果记录", [
154
- ["user", "把各轮评估结果放在一起,便于比较。"],
155
- [
156
- "assistant",
157
- "可以按模型、数据版本、指标和运行时间来记录。这个会话专门处理评估。\n\n这是隔离预览中的示例对话。",
158
- ],
159
- ]);
160
- add("scope-ui", "build-node", "/workspace/scope", "让项目会话真正成为聊天", [
161
- ["user", "左侧按项目组织,点开会话后就能直接继续聊。"],
162
- [
163
- "assistant",
164
- "会话会保留完整消息流,输入框固定在底部。筛选、资源和运行详情放在需要时才打开的工具中。\n\n这是隔离预览中的示例对话。",
165
- ],
166
- ]);
167
- add("math-preview", "lab-gpu", "/workspace/research", "公式显示验证", [
168
- ["user", "查看公式预览,保留论文未定义的宏名称。"],
169
- ["assistant", [
170
- "行内公式:`\\pi`,`H=8`,`e(a)=\\widehat{J}(a)-J^\\beta(a)`。",
171
- "",
172
- "```latex",
173
- "% Eq. (5)",
174
- "\\widehat{J}(a)-J^\\pi(a)=e(a)+(1-\\gamma)\\gamma^H E_{s,a}\\Delta V(s_H).",
175
- "```",
176
- "",
177
- "未定义的论文宏保持原名:",
178
- "```tex",
179
- "\\hJ(\\va)-J^\\pi(\\va)=e(\\va).",
180
- "```",
181
- "",
182
- "程序代码仍然是源码:`session_id`。",
183
- ].join("\n")],
184
- ]);
185
- }
186
- snapshot.appServer.connections = snapshot.hosts.map((h) => ({
187
- host: h.alias,
188
- status: "connected",
189
- connectionKey: "active",
190
- sessionIds: h.agents.map((a) => a.rollout.id),
191
- }));
192
- const evaluation = chats.get("lab-gpu:vision-eval");
193
- evaluation.events.unshift(
194
- ...Array.from({ length: 36 }, (_, index) => ({
195
- id: `earlier-${index}`,
196
- kind: index % 2 ? "assistant" : "user",
197
- text:
198
- index % 2
199
- ? `第 ${Math.ceil(index / 2)} 轮的示例评估记录已整理。这里保留数据版本、指标和复现步骤,便于之后核对。`
200
- : `整理第 ${index / 2 + 1} 轮评估结果。`,
201
- title: "",
202
- category: "dialogue",
203
- timestamp: new Date(Date.now() - (40 - index) * 60000).toISOString(),
204
- })),
205
- );
206
- snapshot.summary.codex = chats.size;
207
- const event = (chat, kind, text) => {
208
- const timestamp = new Date().toISOString();
209
- chat.events.push({
210
- id: crypto.randomUUID(),
211
- kind,
212
- text,
213
- title: "",
214
- category: "dialogue",
215
- timestamp,
216
- });
217
- chat.agent.rollout.lastEventAt = timestamp;
218
- if (kind === "assistant") chat.agent.rollout.lastAssistant = text;
219
- if (kind === "user") chat.agent.rollout.lastUser = text;
220
- };
221
- return async (request, response, url, json, readBody) => {
222
- if (url.pathname === "/api/session/create") {
223
- const body = await readBody(request);
224
- const id = crypto.randomUUID();
225
- add(id, body.host, body.cwd, body.prompt, [
226
- ["user", body.prompt],
227
- ["assistant", "预览会话已创建,没有调用远端 Agent。"],
228
- ]);
229
- const chat = chats.get(`${body.host}:${id}`);
230
- Object.assign(chat.session, {
231
- model: body.model || "gpt-5-codex",
232
- effort: body.effort || "high",
233
- yolo: body.yolo,
234
- });
235
- snapshot.appServer.connections
236
- .find((c) => c.host === body.host)
237
- .sessionIds.push(id);
238
- notify();
239
- json(response, 200, { transport: "app-server", session: chat.session });
240
- return true;
241
- }
242
- if (url.pathname === "/api/session/model") {
243
- const body = await readBody(request);
244
- const chat = chats.get(`${body.host}:${body.sessionId}`);
245
- if (!chat) {
246
- json(response, 404, { error: "找不到预览会话" });
247
- return true;
248
- }
249
- Object.assign(chat.session, {
250
- model: body.model,
251
- effort: body.effort,
252
- yolo: body.yolo,
253
- });
254
- Object.assign(chat.agent.rollout, {
255
- model: body.model,
256
- reasoningEffort: body.effort,
257
- });
258
- notify();
259
- json(response, 200, {
260
- transport: "app-server",
261
- model: body.model,
262
- yolo: body.yolo,
263
- });
264
- return true;
265
- }
266
- if (url.pathname === "/api/dialogue") {
267
- const input =
268
- request.method === "POST"
269
- ? await readBody(request)
270
- : Object.fromEntries(url.searchParams);
271
- const chat = chats.get(`${input.host}:${input.sessionId}`);
272
- if (!chat) {
273
- json(response, 404, { error: "找不到预览会话" });
274
- return true;
275
- }
276
- const end =
277
- input.before == null ? chat.events.length : Number(input.before);
278
- const start = Math.max(0, end - (Number(input.limit) || 30));
279
- const events = chat.events.slice(start, end);
280
- json(response, 200, {
281
- host: chat.agent.host,
282
- sessionId: chat.agent.rollout.id,
283
- path: chat.agent.rollout.path,
284
- events,
285
- loadedAt: new Date().toISOString(),
286
- totalLines: chat.events.length,
287
- totalBytes: 0,
288
- scannedBytes: 0,
289
- counts: Object.fromEntries(
290
- ["user", "assistant", "intermediate", "tool", "system"].map(
291
- (kind) => [kind, events.filter((e) => e.kind === kind).length],
292
- ),
293
- ),
294
- toolEventCount: 2,
295
- omittedToolEvents: 0,
296
- hiddenReasoningCount: 0,
297
- pageSize: 30,
298
- hasMore: start > 0,
299
- nextBefore: start > 0 ? start : null,
300
- });
301
- return true;
302
- }
303
- if (
304
- !["/api/session/instruct", "/api/session/interrupt"].includes(
305
- url.pathname,
306
- )
307
- )
308
- return false;
309
- const body = await readBody(request);
310
- const key = `${body.host}:${body.sessionId}`;
311
- const chat = chats.get(key);
312
- if (!chat) {
313
- json(response, 404, { error: "找不到预览会话" });
314
- return true;
315
- }
316
- if (url.pathname.endsWith("/interrupt")) {
317
- clearTimeout(timers.get(key));
318
- timers.delete(key);
319
- event(chat, "system", "已停止生成。");
320
- chat.agent.status = chat.session.status = "idle";
321
- notify();
322
- json(response, 200, { interrupted: true, sessionId: body.sessionId });
323
- return true;
324
- }
325
- if (timers.has(key)) {
326
- json(response, 409, { error: "当前回复尚未结束" });
327
- return true;
328
- }
329
- event(chat, "user", body.prompt);
330
- chat.agent.status = chat.session.status = "working";
331
- notify();
332
- json(response, 200, {
333
- transport: "app-server",
334
- acknowledged: true,
335
- deliveryId: body.deliveryId,
336
- });
337
- timers.set(
338
- key,
339
- setTimeout(() => {
340
- event(
341
- chat,
342
- "assistant",
343
- `收到。这条消息已接在当前会话里,切换到其他项目后也能继续回来查看。\n\n这是隔离预览的模拟回复,没有调用远端模型。`,
344
- );
345
- chat.agent.status = chat.session.status = "idle";
346
- timers.delete(key);
347
- notify();
348
- }, 6000),
349
- );
350
- return true;
351
- };
352
- }
1
+ /** Representative chat data, deliberately isolated from real hosts and agents. */
2
+ export function createConversationFixture(snapshot, notify) {
3
+ const isEn = process.env.SCOPE_PREVIEW_LOCALE === "en";
4
+ const chats = new Map();
5
+ const timers = new Map();
6
+ function add(id, host, cwd, title, messages) {
7
+ const events = messages.map(([kind, text], index) => ({
8
+ id: `${id}-${index}`,
9
+ kind,
10
+ text,
11
+ title: kind === "tool" ? (isEn ? "Inspect project layout" : "检查项目结构") : "",
12
+ category: kind === "tool" ? "operations" : "dialogue",
13
+ timestamp: new Date(
14
+ Date.now() - (messages.length - index) * 60000,
15
+ ).toISOString(),
16
+ }));
17
+ const rollout = {
18
+ id,
19
+ cwd,
20
+ path: `/preview/${id}.jsonl`,
21
+ model: "gpt-5-codex",
22
+ reasoningEffort: "high",
23
+ firstUser: title,
24
+ lastUser: events.findLast((e) => e.kind === "user")?.text || "",
25
+ lastAssistant: events.findLast((e) => e.kind === "assistant")?.text || "",
26
+ userMessages: [],
27
+ assistantMessages: [],
28
+ turnState: "idle",
29
+ lastEventAt: events.at(-1).timestamp,
30
+ mtimeMs: Date.now(),
31
+ account: null,
32
+ tokenUsage: null,
33
+ };
34
+ const agent = {
35
+ id: `app-server:${host}:${id}`,
36
+ host,
37
+ hostname: host,
38
+ cwd,
39
+ title,
40
+ status: "idle",
41
+ pid: 0,
42
+ tty: "",
43
+ executable: "codex",
44
+ elapsedSeconds: 300,
45
+ pane: null,
46
+ rollout,
47
+ subagents: [],
48
+ mapping: { rollout: "exact", tmux: "none" },
49
+ appServerManaged: true,
50
+ suggestedSummary: {
51
+ theme: title,
52
+ category: "engineering",
53
+ objective: "",
54
+ progress: "",
55
+ result: "",
56
+ nextStep: "",
57
+ source: "rollout",
58
+ updatedAt: null,
59
+ },
60
+ lastActivityAt: Date.now(),
61
+ };
62
+ const session = {
63
+ host,
64
+ sessionId: id,
65
+ cwd,
66
+ path: rollout.path,
67
+ status: "idle",
68
+ model: rollout.model,
69
+ effort: "high",
70
+ connectionKey: "active",
71
+ yolo: false,
72
+ };
73
+ snapshot.hosts.find((h) => h.alias === host).agents.push(agent);
74
+ snapshot.appServer.sessions.push(session);
75
+ chats.set(`${host}:${id}`, { events, agent, session });
76
+ }
77
+ if (isEn) {
78
+ add("vision-plan", "lab-gpu", "/workspace/vision", "Vision model experiment roadmap", [
79
+ ["user", "Help me organize the experiment roadmap for this project, starting with dataset splits and evaluation metrics."],
80
+ [
81
+ "intermediate",
82
+ "Inspecting repository layout and existing configs before breaking down executable milestones.",
83
+ ],
84
+ [
85
+ "tool",
86
+ "Read README, dataset manifest, and evaluation entrypoints.\n\nSynthetic tool log from isolated preview mode.",
87
+ ],
88
+ ["tool", "Verified alignment between training and evaluation configs."],
89
+ [
90
+ "assistant",
91
+ "Let's lock down three foundations first:\n\n1. **Freeze dataset splits**: share one manifest across train, val, and test.\n2. **Establish a compact baseline**: run a small model end-to-end to confirm reproducibility.\n3. **Unify evaluation metrics**: log accuracy, latency, and peak VRAM for apples-to-apples comparisons.\n\nI recommend finalizing the dataset config before reserving multi-GPU nodes.",
92
+ ],
93
+ ["user", "Sounds good—start with the dataset config and keep every milestone logged in this session."],
94
+ [
95
+ "assistant",
96
+ "Got it. This session will serve as the persistent experiment log.\n\nI'll verify the dataset paths and split manifests first, and surface any confirmation prompts inline. Expand \"Used tools\" anytime to inspect commands and raw outputs.\n\n*Isolated UI preview — no remote agents or credentials connected.*",
97
+ ],
98
+ ]);
99
+ add("vision-eval", "lab-gpu", "/workspace/vision", "Benchmark scripts & metric logs", [
100
+ ["user", "Aggregate evaluation metrics across runs so they are easy to compare."],
101
+ [
102
+ "assistant",
103
+ "We can index runs by model, dataset revision, metric score, and wall-clock time. This session tracks all evaluation runs.\n\nSynthetic conversation from isolated preview mode.",
104
+ ],
105
+ ]);
106
+ add("scope-ui", "build-node", "/workspace/scope", "Project-native conversation workspace", [
107
+ ["user", "Organize sessions by project on the left so I can resume any run in one click."],
108
+ [
109
+ "assistant",
110
+ "Each session preserves its full message feed with a sticky composer below. Filters, GPU telemetry, and diagnostics stay tucked away until needed.\n\nSynthetic conversation from isolated preview mode.",
111
+ ],
112
+ ]);
113
+ add("math-preview", "lab-gpu", "/workspace/research", "LaTeX & equation rendering check", [
114
+ ["user", "Verify math preview while preserving custom paper macros."],
115
+ ["assistant", [
116
+ "Inline math: `\\pi`, `H=8`, `e(a)=\\widehat{J}(a)-J^\\beta(a)`.",
117
+ "",
118
+ "```latex",
119
+ "% Eq. (5)",
120
+ "\\widehat{J}(a)-J^\\pi(a)=e(a)+(1-\\gamma)\\gamma^H E_{s,a}\\Delta V(s_H).",
121
+ "```",
122
+ "",
123
+ "Undefined paper macros stay intact:",
124
+ "```tex",
125
+ "\\hJ(\\va)-J^\\pi(\\va)=e(\\va).",
126
+ "```",
127
+ "",
128
+ "Code identifiers remain code: `session_id`.",
129
+ ].join("\n")],
130
+ ]);
131
+ } else {
132
+ add("vision-plan", "lab-gpu", "/workspace/vision", "整理视觉模型的实验计划", [
133
+ ["user", "帮我整理一下这个项目的实验计划,先把数据和评估方法确定下来。"],
134
+ [
135
+ "intermediate",
136
+ "我先看一下项目结构和已有配置,再把下一步拆成可以直接执行的任务。",
137
+ ],
138
+ [
139
+ "tool",
140
+ "读取 README、数据配置和评估入口。\n\n这是隔离预览中的示例执行记录。",
141
+ ],
142
+ ["tool", "检查训练与评估配置的对应关系。"],
143
+ [
144
+ "assistant",
145
+ "可以先完成三件事:\n\n1. **固定数据划分**:让训练、验证和测试使用同一份清单。\n2. **建立基线**:先跑一个较小模型,确认整个流程能够复现。\n3. **统一评估入口**:记录准确率、耗时和显存,方便比较后续实验。\n\n建议先处理数据配置,完成后再申请训练资源。",
146
+ ],
147
+ ["user", "好,先从数据配置开始。每一步的结果都留在这个会话里。"],
148
+ [
149
+ "assistant",
150
+ "好,这个会话就作为实验工作的持续记录。\n\n我会先核对数据目录和划分清单,把需要你确认的内容直接放在对话中。具体命令和输出可以展开“执行过程”查看。\n\n*当前是界面演示,尚未连接真实的远端 Agent。*",
151
+ ],
152
+ ]);
153
+ add("vision-eval", "lab-gpu", "/workspace/vision", "评估脚本与结果记录", [
154
+ ["user", "把各轮评估结果放在一起,便于比较。"],
155
+ [
156
+ "assistant",
157
+ "可以按模型、数据版本、指标和运行时间来记录。这个会话专门处理评估。\n\n这是隔离预览中的示例对话。",
158
+ ],
159
+ ]);
160
+ add("scope-ui", "build-node", "/workspace/scope", "让项目会话真正成为聊天", [
161
+ ["user", "左侧按项目组织,点开会话后就能直接继续聊。"],
162
+ [
163
+ "assistant",
164
+ "会话会保留完整消息流,输入框固定在底部。筛选、资源和运行详情放在需要时才打开的工具中。\n\n这是隔离预览中的示例对话。",
165
+ ],
166
+ ]);
167
+ add("math-preview", "lab-gpu", "/workspace/research", "公式显示验证", [
168
+ ["user", "查看公式预览,保留论文未定义的宏名称。"],
169
+ ["assistant", [
170
+ "行内公式:`\\pi`,`H=8`,`e(a)=\\widehat{J}(a)-J^\\beta(a)`。",
171
+ "",
172
+ "```latex",
173
+ "% Eq. (5)",
174
+ "\\widehat{J}(a)-J^\\pi(a)=e(a)+(1-\\gamma)\\gamma^H E_{s,a}\\Delta V(s_H).",
175
+ "```",
176
+ "",
177
+ "未定义的论文宏保持原名:",
178
+ "```tex",
179
+ "\\hJ(\\va)-J^\\pi(\\va)=e(\\va).",
180
+ "```",
181
+ "",
182
+ "程序代码仍然是源码:`session_id`。",
183
+ ].join("\n")],
184
+ ]);
185
+ }
186
+ snapshot.appServer.connections = snapshot.hosts.map((h) => ({
187
+ host: h.alias,
188
+ status: "connected",
189
+ connectionKey: "active",
190
+ sessionIds: h.agents.map((a) => a.rollout.id),
191
+ }));
192
+ const evaluation = chats.get("lab-gpu:vision-eval");
193
+ evaluation.events.unshift(
194
+ ...Array.from({ length: 36 }, (_, index) => ({
195
+ id: `earlier-${index}`,
196
+ kind: index % 2 ? "assistant" : "user",
197
+ text:
198
+ index % 2
199
+ ? `第 ${Math.ceil(index / 2)} 轮的示例评估记录已整理。这里保留数据版本、指标和复现步骤,便于之后核对。`
200
+ : `整理第 ${index / 2 + 1} 轮评估结果。`,
201
+ title: "",
202
+ category: "dialogue",
203
+ timestamp: new Date(Date.now() - (40 - index) * 60000).toISOString(),
204
+ })),
205
+ );
206
+ const subagentDialogues = new Map();
207
+ const visionPlan = chats.get("lab-gpu:vision-plan");
208
+ if (visionPlan) {
209
+ const subId = "sub-kepler-audit";
210
+ visionPlan.agent.subagents = [
211
+ {
212
+ id: subId,
213
+ cwd: "/workspace/vision",
214
+ path: `/preview/${subId}.jsonl`,
215
+ model: "gpt-5-codex",
216
+ reasoningEffort: "medium",
217
+ firstUser: isEn
218
+ ? "Audit dataset split manifests and check for train/val leakage."
219
+ : "核查数据集划分清单并排查训练/验证集泄漏。",
220
+ lastUser: isEn
221
+ ? "Audit dataset split manifests and check for train/val leakage."
222
+ : "核查数据集划分清单并排查训练/验证集泄漏。",
223
+ lastAssistant: isEn
224
+ ? "Verified zero sample overlap across 12,480 train and 1,560 val items."
225
+ : "已确认 12,480 条训练样本与 1,560 条验证样本零重叠。",
226
+ lastAction: isEn ? "python3 scripts/verify_splits.py" : "python3 scripts/verify_splits.py",
227
+ userMessages: [],
228
+ assistantMessages: [],
229
+ turnState: "idle",
230
+ lastEventAt: new Date(Date.now() - 45000).toISOString(),
231
+ mtimeMs: Date.now() - 45000,
232
+ account: null,
233
+ tokenUsage: null,
234
+ isSubagent: true,
235
+ parentThreadId: "vision-plan",
236
+ agentNickname: "Kepler",
237
+ agentRole: "explorer",
238
+ agentPath: "/root/kepler",
239
+ },
240
+ ];
241
+ subagentDialogues.set(`lab-gpu:vision-plan:${subId}`, {
242
+ subagent: visionPlan.agent.subagents[0],
243
+ events: [
244
+ {
245
+ id: "sub-kepler-1",
246
+ kind: "user",
247
+ text: isEn
248
+ ? "Audit dataset split manifests under `/workspace/vision/manifests` and verify there is no train/val overlap."
249
+ : "核查 `/workspace/vision/manifests` 下的数据集划分清单,确认训练/验证集不存在样本重叠。",
250
+ title: "",
251
+ category: "dialogue",
252
+ timestamp: new Date(Date.now() - 120000).toISOString(),
253
+ },
254
+ {
255
+ id: "sub-kepler-2",
256
+ kind: "reasoning",
257
+ text: isEn
258
+ ? "Inspecting manifest checksums and comparing sample IDs across train, val, and test splits."
259
+ : "检查各划分清单的校验和,并比对 train / val / test 样本 ID 集合交集。",
260
+ title: isEn ? "Reasoning" : "思考摘要",
261
+ category: "operations",
262
+ timestamp: new Date(Date.now() - 95000).toISOString(),
263
+ },
264
+ {
265
+ id: "sub-kepler-3",
266
+ kind: "command",
267
+ toolName: "exec_command",
268
+ title: "exec_command",
269
+ command: "python3 scripts/verify_splits.py --manifest manifests/v2.json",
270
+ text: "python3 scripts/verify_splits.py --manifest manifests/v2.json",
271
+ output: "train=12480 val=1560 test=1560\noverlap(train, val)=0\noverlap(train, test)=0\nStatus: OK",
272
+ status: "completed",
273
+ category: "operations",
274
+ timestamp: new Date(Date.now() - 70000).toISOString(),
275
+ },
276
+ {
277
+ id: "sub-kepler-4",
278
+ kind: "assistant",
279
+ text: isEn
280
+ ? "Verified `manifests/v2.json` via [verify_splits.py](file:///workspace/vision/scripts/verify_splits.py#L1-L40): **0 overlap** across `train` (12,480), `val` (1,560), and `test` (1,560)."
281
+ : "已通过 [verify_splits.py](file:///workspace/vision/scripts/verify_splits.py#L1-L40) 完成核验:`train` (12,480)、`val` (1,560) 与 `test` (1,560) 之间 **0 重叠**。",
282
+ title: "",
283
+ category: "dialogue",
284
+ timestamp: new Date(Date.now() - 45000).toISOString(),
285
+ },
286
+ ],
287
+ });
288
+ }
289
+ snapshot.summary.codex = chats.size;
290
+ const event = (chat, kind, text) => {
291
+ const timestamp = new Date().toISOString();
292
+ chat.events.push({
293
+ id: crypto.randomUUID(),
294
+ kind,
295
+ text,
296
+ title: "",
297
+ category: "dialogue",
298
+ timestamp,
299
+ });
300
+ chat.agent.rollout.lastEventAt = timestamp;
301
+ if (kind === "assistant") chat.agent.rollout.lastAssistant = text;
302
+ if (kind === "user") chat.agent.rollout.lastUser = text;
303
+ };
304
+ return async (request, response, url, json, readBody) => {
305
+ if (url.pathname === "/api/session/create") {
306
+ const body = await readBody(request);
307
+ const id = crypto.randomUUID();
308
+ add(id, body.host, body.cwd, body.prompt, [
309
+ ["user", body.prompt],
310
+ ["assistant", "预览会话已创建,没有调用远端 Agent。"],
311
+ ]);
312
+ const chat = chats.get(`${body.host}:${id}`);
313
+ Object.assign(chat.session, {
314
+ model: body.model || "gpt-5-codex",
315
+ effort: body.effort || "high",
316
+ yolo: body.yolo,
317
+ });
318
+ snapshot.appServer.connections
319
+ .find((c) => c.host === body.host)
320
+ .sessionIds.push(id);
321
+ notify();
322
+ json(response, 200, { transport: "app-server", session: chat.session });
323
+ return true;
324
+ }
325
+ if (url.pathname === "/api/session/model") {
326
+ const body = await readBody(request);
327
+ const chat = chats.get(`${body.host}:${body.sessionId}`);
328
+ if (!chat) {
329
+ json(response, 404, { error: "找不到预览会话" });
330
+ return true;
331
+ }
332
+ Object.assign(chat.session, {
333
+ model: body.model,
334
+ effort: body.effort,
335
+ yolo: body.yolo,
336
+ });
337
+ Object.assign(chat.agent.rollout, {
338
+ model: body.model,
339
+ reasoningEffort: body.effort,
340
+ });
341
+ notify();
342
+ json(response, 200, {
343
+ transport: "app-server",
344
+ model: body.model,
345
+ yolo: body.yolo,
346
+ });
347
+ return true;
348
+ }
349
+ if (url.pathname === "/api/dialogue") {
350
+ const input =
351
+ request.method === "POST"
352
+ ? await readBody(request)
353
+ : Object.fromEntries(url.searchParams);
354
+ if (input.subagentId) {
355
+ const subRecord = subagentDialogues.get(
356
+ `${input.host}:${input.sessionId}:${input.subagentId}`,
357
+ );
358
+ if (!subRecord) {
359
+ json(response, 404, { error: "找不到预览子代理会话" });
360
+ return true;
361
+ }
362
+ const end =
363
+ input.before == null ? subRecord.events.length : Number(input.before);
364
+ const start = Math.max(0, end - (Number(input.limit) || 40));
365
+ const events = subRecord.events.slice(start, end);
366
+ json(response, 200, {
367
+ host: input.host,
368
+ sessionId: input.sessionId,
369
+ subagentId: subRecord.subagent.id,
370
+ subagent: {
371
+ id: subRecord.subagent.id,
372
+ agentNickname: subRecord.subagent.agentNickname,
373
+ agentPath: subRecord.subagent.agentPath,
374
+ agentRole: subRecord.subagent.agentRole,
375
+ model: subRecord.subagent.model,
376
+ turnState: subRecord.subagent.turnState,
377
+ },
378
+ path: subRecord.subagent.path,
379
+ events,
380
+ loadedAt: new Date().toISOString(),
381
+ totalLines: subRecord.events.length,
382
+ totalBytes: 0,
383
+ scannedBytes: 0,
384
+ counts: {},
385
+ toolEventCount: 1,
386
+ omittedToolEvents: 0,
387
+ hiddenReasoningCount: 0,
388
+ pageSize: 40,
389
+ hasMore: start > 0,
390
+ nextBefore: start > 0 ? start : null,
391
+ });
392
+ return true;
393
+ }
394
+ const chat = chats.get(`${input.host}:${input.sessionId}`);
395
+ if (!chat) {
396
+ json(response, 404, { error: "找不到预览会话" });
397
+ return true;
398
+ }
399
+ const end =
400
+ input.before == null ? chat.events.length : Number(input.before);
401
+ const start = Math.max(0, end - (Number(input.limit) || 30));
402
+ const events = chat.events.slice(start, end);
403
+ json(response, 200, {
404
+ host: chat.agent.host,
405
+ sessionId: chat.agent.rollout.id,
406
+ path: chat.agent.rollout.path,
407
+ events,
408
+ loadedAt: new Date().toISOString(),
409
+ totalLines: chat.events.length,
410
+ totalBytes: 0,
411
+ scannedBytes: 0,
412
+ counts: Object.fromEntries(
413
+ ["user", "assistant", "intermediate", "tool", "system"].map(
414
+ (kind) => [kind, events.filter((e) => e.kind === kind).length],
415
+ ),
416
+ ),
417
+ toolEventCount: 2,
418
+ omittedToolEvents: 0,
419
+ hiddenReasoningCount: 0,
420
+ pageSize: 30,
421
+ hasMore: start > 0,
422
+ nextBefore: start > 0 ? start : null,
423
+ });
424
+ return true;
425
+ }
426
+ if (
427
+ !["/api/session/instruct", "/api/session/interrupt"].includes(
428
+ url.pathname,
429
+ )
430
+ )
431
+ return false;
432
+ const body = await readBody(request);
433
+ const key = `${body.host}:${body.sessionId}`;
434
+ const chat = chats.get(key);
435
+ if (!chat) {
436
+ json(response, 404, { error: "找不到预览会话" });
437
+ return true;
438
+ }
439
+ if (url.pathname.endsWith("/interrupt")) {
440
+ clearTimeout(timers.get(key));
441
+ timers.delete(key);
442
+ event(chat, "system", "已停止生成。");
443
+ chat.agent.status = chat.session.status = "idle";
444
+ notify();
445
+ json(response, 200, { interrupted: true, sessionId: body.sessionId });
446
+ return true;
447
+ }
448
+ if (timers.has(key)) {
449
+ json(response, 409, { error: "当前回复尚未结束" });
450
+ return true;
451
+ }
452
+ event(chat, "user", body.prompt);
453
+ chat.agent.status = chat.session.status = "working";
454
+ notify();
455
+ json(response, 200, {
456
+ transport: "app-server",
457
+ acknowledged: true,
458
+ deliveryId: body.deliveryId,
459
+ });
460
+ timers.set(
461
+ key,
462
+ setTimeout(() => {
463
+ event(
464
+ chat,
465
+ "assistant",
466
+ `收到。这条消息已接在当前会话里,切换到其他项目后也能继续回来查看。\n\n这是隔离预览的模拟回复,没有调用远端模型。`,
467
+ );
468
+ chat.agent.status = chat.session.status = "idle";
469
+ timers.delete(key);
470
+ notify();
471
+ }, 6000),
472
+ );
473
+ return true;
474
+ };
475
+ }