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,219 +1,219 @@
1
- import { createHash, randomBytes } from "node:crypto";
2
- import { EventEmitter } from "node:events";
3
- import { PassThrough, Writable } from "node:stream";
4
-
5
- const WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
6
-
7
- function frame(opcode, payload = Buffer.alloc(0)) {
8
- const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
9
- const mask = randomBytes(4);
10
- let header;
11
- if (body.length < 126) {
12
- header = Buffer.alloc(2);
13
- header[1] = 0x80 | body.length;
14
- } else if (body.length <= 0xffff) {
15
- header = Buffer.alloc(4);
16
- header[1] = 0x80 | 126;
17
- header.writeUInt16BE(body.length, 2);
18
- } else {
19
- header = Buffer.alloc(10);
20
- header[1] = 0x80 | 127;
21
- header.writeBigUInt64BE(BigInt(body.length), 2);
22
- }
23
- header[0] = 0x80 | opcode;
24
- const masked = Buffer.alloc(body.length);
25
- for (let index = 0; index < body.length; index += 1) {
26
- masked[index] = body[index] ^ mask[index % 4];
27
- }
28
- return Buffer.concat([header, mask, masked]);
29
- }
30
-
31
- export class WebSocketJsonlChild extends EventEmitter {
32
- constructor(
33
- child,
34
- {
35
- path = "/",
36
- host = "localhost",
37
- pingIntervalMs = 25_000,
38
- setIntervalFn = setInterval,
39
- clearIntervalFn = clearInterval,
40
- } = {},
41
- ) {
42
- super();
43
- this.child = child;
44
- this.stdout = new PassThrough();
45
- this.stderr = child.stderr;
46
- this.killed = false;
47
- this.ready = false;
48
- this.closed = false;
49
- this.buffer = Buffer.alloc(0);
50
- this.fragments = [];
51
- this.pendingWrites = [];
52
- this.pingIntervalMs = Math.max(0, Number(pingIntervalMs) || 0);
53
- this.setIntervalFn = setIntervalFn;
54
- this.clearIntervalFn = clearIntervalFn;
55
- this.pingTimer = null;
56
- // Lets JsonlAppServerConnection distinguish this disposable SSH/WebSocket
57
- // bridge from an actual remote app-server process exit.
58
- this.scopeTransport = "ssh-websocket";
59
- this.key = randomBytes(16).toString("base64");
60
- this.stdin = new Writable({
61
- write: (chunk, _encoding, callback) => {
62
- try {
63
- const payload = Buffer.from(chunk);
64
- if (this.ready) this.child.stdin.write(frame(0x1, payload));
65
- else this.pendingWrites.push(payload);
66
- callback();
67
- } catch (error) {
68
- callback(error);
69
- }
70
- },
71
- final: (callback) => {
72
- try {
73
- this.#stopHeartbeat();
74
- if (!this.child.stdin.destroyed) {
75
- if (this.ready) this.child.stdin.write(frame(0x8));
76
- this.child.stdin.end();
77
- }
78
- callback();
79
- } catch (error) {
80
- callback(error);
81
- }
82
- },
83
- });
84
- child.stdout.on("data", (chunk) => this.#read(chunk));
85
- child.once("error", (error) => this.emit("error", error));
86
- child.once("exit", (code, signal) => {
87
- this.#stopHeartbeat();
88
- this.closed = true;
89
- this.stdout.end();
90
- this.emit("exit", code, signal);
91
- });
92
- child.stdin.on("error", (error) => this.stdin.destroy(error));
93
- const request = [
94
- `GET ${path} HTTP/1.1`,
95
- `Host: ${host}`,
96
- "Upgrade: websocket",
97
- "Connection: Upgrade",
98
- `Sec-WebSocket-Key: ${this.key}`,
99
- "Sec-WebSocket-Version: 13",
100
- "",
101
- "",
102
- ].join("\r\n");
103
- child.stdin.write(request);
104
- }
105
-
106
- kill() {
107
- // Compatibility with ChildProcess consumers. This intentionally closes the
108
- // proxy stream instead of signalling the durable remote app-server.
109
- this.killed = true;
110
- this.#stopHeartbeat();
111
- this.stdin.end();
112
- }
113
-
114
- #read(chunk) {
115
- this.buffer = Buffer.concat([this.buffer, Buffer.from(chunk)]);
116
- if (!this.ready) {
117
- const marker = this.buffer.indexOf("\r\n\r\n");
118
- if (marker < 0) return;
119
- const response = this.buffer.subarray(0, marker + 4).toString("utf8");
120
- this.buffer = this.buffer.subarray(marker + 4);
121
- const status = response.split("\r\n", 1)[0] || "";
122
- const accept = response.match(/\r\nsec-websocket-accept:\s*([^\r\n]+)/i)?.[1]?.trim();
123
- const expected = createHash("sha1")
124
- .update(`${this.key}${WEBSOCKET_GUID}`)
125
- .digest("base64");
126
- if (!/^HTTP\/1\.[01] 101\b/.test(status) || accept !== expected) {
127
- this.emit(
128
- "error",
129
- new Error(`app-server WebSocket 握手失败:${status || "无响应"}`),
130
- );
131
- return;
132
- }
133
- this.ready = true;
134
- this.#startHeartbeat();
135
- for (const payload of this.pendingWrites.splice(0)) {
136
- this.child.stdin.write(frame(0x1, payload));
137
- }
138
- }
139
- this.#drainFrames();
140
- }
141
-
142
- #drainFrames() {
143
- while (this.buffer.length >= 2) {
144
- const first = this.buffer[0];
145
- const second = this.buffer[1];
146
- const fin = Boolean(first & 0x80);
147
- const opcode = first & 0x0f;
148
- const masked = Boolean(second & 0x80);
149
- let length = second & 0x7f;
150
- let offset = 2;
151
- if (length === 126) {
152
- if (this.buffer.length < 4) return;
153
- length = this.buffer.readUInt16BE(2);
154
- offset = 4;
155
- } else if (length === 127) {
156
- if (this.buffer.length < 10) return;
157
- const wide = this.buffer.readBigUInt64BE(2);
158
- if (wide > BigInt(Number.MAX_SAFE_INTEGER)) {
159
- this.emit("error", new Error("app-server WebSocket 帧过大"));
160
- return;
161
- }
162
- length = Number(wide);
163
- offset = 10;
164
- }
165
- const maskOffset = offset;
166
- if (masked) offset += 4;
167
- if (this.buffer.length < offset + length) return;
168
- const mask = masked
169
- ? Buffer.from(this.buffer.subarray(maskOffset, maskOffset + 4))
170
- : null;
171
- let payload = Buffer.from(this.buffer.subarray(offset, offset + length));
172
- this.buffer = this.buffer.subarray(offset + length);
173
- if (mask) {
174
- for (let index = 0; index < payload.length; index += 1) {
175
- payload[index] ^= mask[index % 4];
176
- }
177
- }
178
- if (opcode === 0x8) {
179
- this.#stopHeartbeat();
180
- if (!this.child.stdin.destroyed) this.child.stdin.end(frame(0x8));
181
- continue;
182
- }
183
- if (opcode === 0x9) {
184
- if (!this.child.stdin.destroyed) this.child.stdin.write(frame(0xa, payload));
185
- continue;
186
- }
187
- if (opcode === 0xa) continue;
188
- if (opcode === 0x1) this.fragments = [payload];
189
- else if (opcode === 0x0) this.fragments.push(payload);
190
- else continue;
191
- if (fin) {
192
- this.stdout.write(Buffer.concat(this.fragments));
193
- this.stdout.write("\n");
194
- this.fragments = [];
195
- }
196
- }
197
- }
198
-
199
- #startHeartbeat() {
200
- if (this.pingTimer || !this.ready || this.closed || !this.pingIntervalMs) {
201
- return;
202
- }
203
- this.pingTimer = this.setIntervalFn(() => {
204
- if (!this.ready || this.closed || this.child.stdin.destroyed) return;
205
- try {
206
- this.child.stdin.write(frame(0x9));
207
- } catch {
208
- // The child exit/error handlers surface the real disconnect.
209
- }
210
- }, this.pingIntervalMs);
211
- this.pingTimer?.unref?.();
212
- }
213
-
214
- #stopHeartbeat() {
215
- if (!this.pingTimer) return;
216
- this.clearIntervalFn(this.pingTimer);
217
- this.pingTimer = null;
218
- }
219
- }
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { EventEmitter } from "node:events";
3
+ import { PassThrough, Writable } from "node:stream";
4
+
5
+ const WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
6
+
7
+ function frame(opcode, payload = Buffer.alloc(0)) {
8
+ const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
9
+ const mask = randomBytes(4);
10
+ let header;
11
+ if (body.length < 126) {
12
+ header = Buffer.alloc(2);
13
+ header[1] = 0x80 | body.length;
14
+ } else if (body.length <= 0xffff) {
15
+ header = Buffer.alloc(4);
16
+ header[1] = 0x80 | 126;
17
+ header.writeUInt16BE(body.length, 2);
18
+ } else {
19
+ header = Buffer.alloc(10);
20
+ header[1] = 0x80 | 127;
21
+ header.writeBigUInt64BE(BigInt(body.length), 2);
22
+ }
23
+ header[0] = 0x80 | opcode;
24
+ const masked = Buffer.alloc(body.length);
25
+ for (let index = 0; index < body.length; index += 1) {
26
+ masked[index] = body[index] ^ mask[index % 4];
27
+ }
28
+ return Buffer.concat([header, mask, masked]);
29
+ }
30
+
31
+ export class WebSocketJsonlChild extends EventEmitter {
32
+ constructor(
33
+ child,
34
+ {
35
+ path = "/",
36
+ host = "localhost",
37
+ pingIntervalMs = 25_000,
38
+ setIntervalFn = setInterval,
39
+ clearIntervalFn = clearInterval,
40
+ } = {},
41
+ ) {
42
+ super();
43
+ this.child = child;
44
+ this.stdout = new PassThrough();
45
+ this.stderr = child.stderr;
46
+ this.killed = false;
47
+ this.ready = false;
48
+ this.closed = false;
49
+ this.buffer = Buffer.alloc(0);
50
+ this.fragments = [];
51
+ this.pendingWrites = [];
52
+ this.pingIntervalMs = Math.max(0, Number(pingIntervalMs) || 0);
53
+ this.setIntervalFn = setIntervalFn;
54
+ this.clearIntervalFn = clearIntervalFn;
55
+ this.pingTimer = null;
56
+ // Lets JsonlAppServerConnection distinguish this disposable SSH/WebSocket
57
+ // bridge from an actual remote app-server process exit.
58
+ this.scopeTransport = "ssh-websocket";
59
+ this.key = randomBytes(16).toString("base64");
60
+ this.stdin = new Writable({
61
+ write: (chunk, _encoding, callback) => {
62
+ try {
63
+ const payload = Buffer.from(chunk);
64
+ if (this.ready) this.child.stdin.write(frame(0x1, payload));
65
+ else this.pendingWrites.push(payload);
66
+ callback();
67
+ } catch (error) {
68
+ callback(error);
69
+ }
70
+ },
71
+ final: (callback) => {
72
+ try {
73
+ this.#stopHeartbeat();
74
+ if (!this.child.stdin.destroyed) {
75
+ if (this.ready) this.child.stdin.write(frame(0x8));
76
+ this.child.stdin.end();
77
+ }
78
+ callback();
79
+ } catch (error) {
80
+ callback(error);
81
+ }
82
+ },
83
+ });
84
+ child.stdout.on("data", (chunk) => this.#read(chunk));
85
+ child.once("error", (error) => this.emit("error", error));
86
+ child.once("exit", (code, signal) => {
87
+ this.#stopHeartbeat();
88
+ this.closed = true;
89
+ this.stdout.end();
90
+ this.emit("exit", code, signal);
91
+ });
92
+ child.stdin.on("error", (error) => this.stdin.destroy(error));
93
+ const request = [
94
+ `GET ${path} HTTP/1.1`,
95
+ `Host: ${host}`,
96
+ "Upgrade: websocket",
97
+ "Connection: Upgrade",
98
+ `Sec-WebSocket-Key: ${this.key}`,
99
+ "Sec-WebSocket-Version: 13",
100
+ "",
101
+ "",
102
+ ].join("\r\n");
103
+ child.stdin.write(request);
104
+ }
105
+
106
+ kill() {
107
+ // Compatibility with ChildProcess consumers. This intentionally closes the
108
+ // proxy stream instead of signalling the durable remote app-server.
109
+ this.killed = true;
110
+ this.#stopHeartbeat();
111
+ this.stdin.end();
112
+ }
113
+
114
+ #read(chunk) {
115
+ this.buffer = Buffer.concat([this.buffer, Buffer.from(chunk)]);
116
+ if (!this.ready) {
117
+ const marker = this.buffer.indexOf("\r\n\r\n");
118
+ if (marker < 0) return;
119
+ const response = this.buffer.subarray(0, marker + 4).toString("utf8");
120
+ this.buffer = this.buffer.subarray(marker + 4);
121
+ const status = response.split("\r\n", 1)[0] || "";
122
+ const accept = response.match(/\r\nsec-websocket-accept:\s*([^\r\n]+)/i)?.[1]?.trim();
123
+ const expected = createHash("sha1")
124
+ .update(`${this.key}${WEBSOCKET_GUID}`)
125
+ .digest("base64");
126
+ if (!/^HTTP\/1\.[01] 101\b/.test(status) || accept !== expected) {
127
+ this.emit(
128
+ "error",
129
+ new Error(`app-server WebSocket 握手失败:${status || "无响应"}`),
130
+ );
131
+ return;
132
+ }
133
+ this.ready = true;
134
+ this.#startHeartbeat();
135
+ for (const payload of this.pendingWrites.splice(0)) {
136
+ this.child.stdin.write(frame(0x1, payload));
137
+ }
138
+ }
139
+ this.#drainFrames();
140
+ }
141
+
142
+ #drainFrames() {
143
+ while (this.buffer.length >= 2) {
144
+ const first = this.buffer[0];
145
+ const second = this.buffer[1];
146
+ const fin = Boolean(first & 0x80);
147
+ const opcode = first & 0x0f;
148
+ const masked = Boolean(second & 0x80);
149
+ let length = second & 0x7f;
150
+ let offset = 2;
151
+ if (length === 126) {
152
+ if (this.buffer.length < 4) return;
153
+ length = this.buffer.readUInt16BE(2);
154
+ offset = 4;
155
+ } else if (length === 127) {
156
+ if (this.buffer.length < 10) return;
157
+ const wide = this.buffer.readBigUInt64BE(2);
158
+ if (wide > BigInt(Number.MAX_SAFE_INTEGER)) {
159
+ this.emit("error", new Error("app-server WebSocket 帧过大"));
160
+ return;
161
+ }
162
+ length = Number(wide);
163
+ offset = 10;
164
+ }
165
+ const maskOffset = offset;
166
+ if (masked) offset += 4;
167
+ if (this.buffer.length < offset + length) return;
168
+ const mask = masked
169
+ ? Buffer.from(this.buffer.subarray(maskOffset, maskOffset + 4))
170
+ : null;
171
+ let payload = Buffer.from(this.buffer.subarray(offset, offset + length));
172
+ this.buffer = this.buffer.subarray(offset + length);
173
+ if (mask) {
174
+ for (let index = 0; index < payload.length; index += 1) {
175
+ payload[index] ^= mask[index % 4];
176
+ }
177
+ }
178
+ if (opcode === 0x8) {
179
+ this.#stopHeartbeat();
180
+ if (!this.child.stdin.destroyed) this.child.stdin.end(frame(0x8));
181
+ continue;
182
+ }
183
+ if (opcode === 0x9) {
184
+ if (!this.child.stdin.destroyed) this.child.stdin.write(frame(0xa, payload));
185
+ continue;
186
+ }
187
+ if (opcode === 0xa) continue;
188
+ if (opcode === 0x1) this.fragments = [payload];
189
+ else if (opcode === 0x0) this.fragments.push(payload);
190
+ else continue;
191
+ if (fin) {
192
+ this.stdout.write(Buffer.concat(this.fragments));
193
+ this.stdout.write("\n");
194
+ this.fragments = [];
195
+ }
196
+ }
197
+ }
198
+
199
+ #startHeartbeat() {
200
+ if (this.pingTimer || !this.ready || this.closed || !this.pingIntervalMs) {
201
+ return;
202
+ }
203
+ this.pingTimer = this.setIntervalFn(() => {
204
+ if (!this.ready || this.closed || this.child.stdin.destroyed) return;
205
+ try {
206
+ this.child.stdin.write(frame(0x9));
207
+ } catch {
208
+ // The child exit/error handlers surface the real disconnect.
209
+ }
210
+ }, this.pingIntervalMs);
211
+ this.pingTimer?.unref?.();
212
+ }
213
+
214
+ #stopHeartbeat() {
215
+ if (!this.pingTimer) return;
216
+ this.clearIntervalFn(this.pingTimer);
217
+ this.pingTimer = null;
218
+ }
219
+ }