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,130 +1,130 @@
1
- /** Durable intents make lost SSH replies retryable without pretending local-only deletion succeeded. */
2
- export function sessionArchiveService({
3
- manager,
4
- getState,
5
- persist,
6
- findAgent,
7
- getHost,
8
- executable,
9
- connectionKey,
10
- notify,
11
- restored,
12
- protectedSession = () => false,
13
- }) {
14
- const busy = new Set();
15
- const keyOf = (host, id) => `${host}:${id}`;
16
- function list() {
17
- return Object.values(getState().sessions).flatMap((value) =>
18
- value.archive && value.archive.phase !== "restored"
19
- ? [value.archive]
20
- : [],
21
- );
22
- }
23
- async function write(key, record) {
24
- const sessions = getState().sessions;
25
- const previous = sessions[key];
26
- sessions[key] = { ...previous, archive: record };
27
- try {
28
- await persist();
29
- } catch (error) {
30
- sessions[key] = previous;
31
- throw error;
32
- }
33
- notify();
34
- }
35
- async function change(host, sessionId, action, receipt = null) {
36
- if (!host || !sessionId || !["archive", "restore"].includes(action))
37
- throw new Error("归档参数无效");
38
- if (protectedSession(host, sessionId))
39
- throw new Error("这是总调度的主会话,请从左侧归档普通项目会话或任务");
40
- const key = keyOf(host, sessionId);
41
- if (busy.has(key)) throw new Error("此会话的归档操作尚未完成");
42
- if (!getHost(host)?.reachable)
43
- throw new Error("主机当前离线,恢复连接后可归档或恢复");
44
- busy.add(key);
45
- let record;
46
- try {
47
- const previous = getState().sessions[key]?.archive;
48
- if (action === "restore" && !previous) throw new Error("找不到归档记录");
49
- if (action === "restore" && previous.phase === "restored")
50
- return previous;
51
- const agent = findAgent(host, sessionId);
52
- const managed = manager
53
- .sessionRecords()
54
- .find((s) => s.host === host && s.sessionId === sessionId);
55
- if (action === "archive") {
56
- if (!agent && !managed && !receipt && !previous)
57
- throw new Error("找不到对应会话");
58
- if (
59
- agent?.status === "working" ||
60
- (!managed && (agent?.pid > 0 || agent?.pane))
61
- )
62
- throw new Error("会话仍由运行中的 Agent 使用,请结束后再归档");
63
- if (agent?.subagents?.some((child) => child.status === "working"))
64
- throw new Error("子会话仍在执行,请结束后再归档");
65
- }
66
- record = {
67
- ...previous,
68
- host,
69
- sessionId,
70
- title:
71
- previous?.title ||
72
- agent?.title ||
73
- agent?.rollout?.firstUser ||
74
- sessionId,
75
- session: managed || previous?.session || null,
76
- cwd: previous?.cwd || agent?.cwd || managed?.cwd || receipt?.cwd || "",
77
- executable:
78
- managed?.executable ||
79
- receipt?.executable ||
80
- previous?.executable ||
81
- executable(host),
82
- connectionKey:
83
- managed?.connectionKey ||
84
- receipt?.connectionKey ||
85
- previous?.connectionKey ||
86
- (await connectionKey(host, sessionId)),
87
- phase: action === "archive" ? "archiving" : "restoring",
88
- error: null,
89
- updatedAt: new Date().toISOString(),
90
- };
91
- await write(key, record);
92
- if (action === "archive") {
93
- await manager.archiveSession(
94
- host,
95
- sessionId,
96
- record.executable,
97
- record.connectionKey,
98
- );
99
- record = {
100
- ...record,
101
- phase: "archived",
102
- archivedAt: new Date().toISOString(),
103
- };
104
- } else {
105
- const thread = await manager.unarchiveSession(
106
- host,
107
- sessionId,
108
- record.executable,
109
- record.connectionKey,
110
- );
111
- if (record.session)
112
- await manager.resumeSession({
113
- ...record.session,
114
- path: thread.path || null,
115
- });
116
- await restored(host, sessionId, thread);
117
- record = { ...record, phase: "restored" };
118
- }
119
- await write(key, record);
120
- return record;
121
- } catch (error) {
122
- if (record)
123
- await write(key, { ...record, error: error.message }).catch(() => {});
124
- throw error;
125
- } finally {
126
- busy.delete(key);
127
- }
128
- }
129
- return { list, change };
130
- }
1
+ /** Durable intents make lost SSH replies retryable without pretending local-only deletion succeeded. */
2
+ export function sessionArchiveService({
3
+ manager,
4
+ getState,
5
+ persist,
6
+ findAgent,
7
+ getHost,
8
+ executable,
9
+ connectionKey,
10
+ notify,
11
+ restored,
12
+ protectedSession = () => false,
13
+ }) {
14
+ const busy = new Set();
15
+ const keyOf = (host, id) => `${host}:${id}`;
16
+ function list() {
17
+ return Object.values(getState().sessions).flatMap((value) =>
18
+ value.archive && value.archive.phase !== "restored"
19
+ ? [value.archive]
20
+ : [],
21
+ );
22
+ }
23
+ async function write(key, record) {
24
+ const sessions = getState().sessions;
25
+ const previous = sessions[key];
26
+ sessions[key] = { ...previous, archive: record };
27
+ try {
28
+ await persist();
29
+ } catch (error) {
30
+ sessions[key] = previous;
31
+ throw error;
32
+ }
33
+ notify();
34
+ }
35
+ async function change(host, sessionId, action, receipt = null) {
36
+ if (!host || !sessionId || !["archive", "restore"].includes(action))
37
+ throw new Error("归档参数无效");
38
+ if (protectedSession(host, sessionId))
39
+ throw new Error("这是总调度的主会话,请从左侧归档普通项目会话或任务");
40
+ const key = keyOf(host, sessionId);
41
+ if (busy.has(key)) throw new Error("此会话的归档操作尚未完成");
42
+ if (!getHost(host)?.reachable)
43
+ throw new Error("主机当前离线,恢复连接后可归档或恢复");
44
+ busy.add(key);
45
+ let record;
46
+ try {
47
+ const previous = getState().sessions[key]?.archive;
48
+ if (action === "restore" && !previous) throw new Error("找不到归档记录");
49
+ if (action === "restore" && previous.phase === "restored")
50
+ return previous;
51
+ const agent = findAgent(host, sessionId);
52
+ const managed = manager
53
+ .sessionRecords()
54
+ .find((s) => s.host === host && s.sessionId === sessionId);
55
+ if (action === "archive") {
56
+ if (!agent && !managed && !receipt && !previous)
57
+ throw new Error("找不到对应会话");
58
+ if (
59
+ agent?.status === "working" ||
60
+ (!managed && (agent?.pid > 0 || agent?.pane))
61
+ )
62
+ throw new Error("会话仍由运行中的 Agent 使用,请结束后再归档");
63
+ if (agent?.subagents?.some((child) => child.status === "working"))
64
+ throw new Error("子会话仍在执行,请结束后再归档");
65
+ }
66
+ record = {
67
+ ...previous,
68
+ host,
69
+ sessionId,
70
+ title:
71
+ previous?.title ||
72
+ agent?.title ||
73
+ agent?.rollout?.firstUser ||
74
+ sessionId,
75
+ session: managed || previous?.session || null,
76
+ cwd: previous?.cwd || agent?.cwd || managed?.cwd || receipt?.cwd || "",
77
+ executable:
78
+ managed?.executable ||
79
+ receipt?.executable ||
80
+ previous?.executable ||
81
+ executable(host),
82
+ connectionKey:
83
+ managed?.connectionKey ||
84
+ receipt?.connectionKey ||
85
+ previous?.connectionKey ||
86
+ (await connectionKey(host, sessionId)),
87
+ phase: action === "archive" ? "archiving" : "restoring",
88
+ error: null,
89
+ updatedAt: new Date().toISOString(),
90
+ };
91
+ await write(key, record);
92
+ if (action === "archive") {
93
+ await manager.archiveSession(
94
+ host,
95
+ sessionId,
96
+ record.executable,
97
+ record.connectionKey,
98
+ );
99
+ record = {
100
+ ...record,
101
+ phase: "archived",
102
+ archivedAt: new Date().toISOString(),
103
+ };
104
+ } else {
105
+ const thread = await manager.unarchiveSession(
106
+ host,
107
+ sessionId,
108
+ record.executable,
109
+ record.connectionKey,
110
+ );
111
+ if (record.session)
112
+ await manager.resumeSession({
113
+ ...record.session,
114
+ path: thread.path || null,
115
+ });
116
+ await restored(host, sessionId, thread);
117
+ record = { ...record, phase: "restored" };
118
+ }
119
+ await write(key, record);
120
+ return record;
121
+ } catch (error) {
122
+ if (record)
123
+ await write(key, { ...record, error: error.message }).catch(() => {});
124
+ throw error;
125
+ } finally {
126
+ busy.delete(key);
127
+ }
128
+ }
129
+ return { list, change };
130
+ }
@@ -1,58 +1,58 @@
1
- const DEFAULT_PROFILE_COOLDOWN_MS = 30 * 60_000;
2
-
3
- export function orderedReadyProfileCandidates(
4
- profiles,
5
- activeSlug,
6
- {
7
- failedUntil = new Map(),
8
- now = Date.now(),
9
- } = {},
10
- ) {
11
- const ready = (Array.isArray(profiles) ? profiles : []).filter(
12
- (profile) => profile?.ready && typeof profile.slug === "string" && profile.slug,
13
- );
14
- if (ready.length < 2) return [];
15
- const activeIndex = ready.findIndex((profile) => profile.slug === activeSlug);
16
- const rotationBase = activeIndex >= 0 ? activeIndex : -1;
17
- const candidateCount = activeIndex >= 0 ? ready.length - 1 : ready.length;
18
- const ordered = [];
19
- for (let offset = 1; offset <= candidateCount; offset += 1) {
20
- const index = (rotationBase + offset) % ready.length;
21
- const profile = ready[index];
22
- if (profile.slug === activeSlug) continue;
23
- if (Number(failedUntil.get(profile.slug) || 0) > now) continue;
24
- ordered.push(profile);
25
- }
26
- return ordered;
27
- }
28
-
29
- export function markProfileUnavailable(
30
- failedUntil,
31
- slug,
32
- {
33
- now = Date.now(),
34
- cooldownMs = DEFAULT_PROFILE_COOLDOWN_MS,
35
- } = {},
36
- ) {
37
- if (!(failedUntil instanceof Map) || !slug) return null;
38
- const until = now + Math.max(1_000, Number(cooldownMs) || DEFAULT_PROFILE_COOLDOWN_MS);
39
- failedUntil.set(slug, until);
40
- return until;
41
- }
42
-
43
- export function publicProfileFailoverJob(job) {
44
- if (!job) return null;
45
- return {
46
- host: job.host,
47
- status: job.status,
48
- failedProfile: job.failedProfile || null,
49
- targetProfile: job.targetProfile || null,
50
- interruptedSessions: Array.from(job.interruptedSessions || []),
51
- waitingForSessions: Array.from(job.waitingForSessions || []),
52
- attemptedProfiles: Array.from(job.attemptedProfiles || []),
53
- nextAttemptAt: job.nextAttemptAt || null,
54
- startedAt: job.startedAt,
55
- completedAt: job.completedAt || null,
56
- error: job.error || null,
57
- };
58
- }
1
+ const DEFAULT_PROFILE_COOLDOWN_MS = 30 * 60_000;
2
+
3
+ export function orderedReadyProfileCandidates(
4
+ profiles,
5
+ activeSlug,
6
+ {
7
+ failedUntil = new Map(),
8
+ now = Date.now(),
9
+ } = {},
10
+ ) {
11
+ const ready = (Array.isArray(profiles) ? profiles : []).filter(
12
+ (profile) => profile?.ready && typeof profile.slug === "string" && profile.slug,
13
+ );
14
+ if (ready.length < 2) return [];
15
+ const activeIndex = ready.findIndex((profile) => profile.slug === activeSlug);
16
+ const rotationBase = activeIndex >= 0 ? activeIndex : -1;
17
+ const candidateCount = activeIndex >= 0 ? ready.length - 1 : ready.length;
18
+ const ordered = [];
19
+ for (let offset = 1; offset <= candidateCount; offset += 1) {
20
+ const index = (rotationBase + offset) % ready.length;
21
+ const profile = ready[index];
22
+ if (profile.slug === activeSlug) continue;
23
+ if (Number(failedUntil.get(profile.slug) || 0) > now) continue;
24
+ ordered.push(profile);
25
+ }
26
+ return ordered;
27
+ }
28
+
29
+ export function markProfileUnavailable(
30
+ failedUntil,
31
+ slug,
32
+ {
33
+ now = Date.now(),
34
+ cooldownMs = DEFAULT_PROFILE_COOLDOWN_MS,
35
+ } = {},
36
+ ) {
37
+ if (!(failedUntil instanceof Map) || !slug) return null;
38
+ const until = now + Math.max(1_000, Number(cooldownMs) || DEFAULT_PROFILE_COOLDOWN_MS);
39
+ failedUntil.set(slug, until);
40
+ return until;
41
+ }
42
+
43
+ export function publicProfileFailoverJob(job) {
44
+ if (!job) return null;
45
+ return {
46
+ host: job.host,
47
+ status: job.status,
48
+ failedProfile: job.failedProfile || null,
49
+ targetProfile: job.targetProfile || null,
50
+ interruptedSessions: Array.from(job.interruptedSessions || []),
51
+ waitingForSessions: Array.from(job.waitingForSessions || []),
52
+ attemptedProfiles: Array.from(job.attemptedProfiles || []),
53
+ nextAttemptAt: job.nextAttemptAt || null,
54
+ startedAt: job.startedAt,
55
+ completedAt: job.completedAt || null,
56
+ error: job.error || null,
57
+ };
58
+ }