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
package/CHANGELOG.md CHANGED
@@ -2,6 +2,47 @@
2
2
 
3
3
  All notable changes to **SCOPE** (`scope-agent-workbench`) are documented in this file.
4
4
 
5
+ ## [0.2.3] — 2026-11-25
6
+
7
+ ### Added
8
+
9
+ - **Collapsible Long User Messages**: Long user-sent prompts (rendered height `> 216px`) across **Codex**, **Claude Code**, **Antigravity**, and **Manager Chat** now auto-collapse to a clean 5–6 line preview (`156px`) with a smooth bottom gradient fade and one-click **Expand · N lines / chars** / **Collapse** pill button, leaving short messages completely untouched.
10
+ - **Unified One-Click Message Copy**: Added a shared copy button beneath user and assistant messages across **Claude Code**, **Antigravity**, **Codex**, and **Manager Chat**, with 1.8s **Copied** auto-reset and a `document.execCommand("copy")` fallback for non-HTTPS LAN access.
11
+
12
+ ## [0.2.2] — 2026-11-25
13
+
14
+ ### Added
15
+
16
+ - **Parent ↔ Subsession Bidirectional Interaction Timeline (Claude Code & Codex)**:
17
+ - Surfaces dispatched task instructions (`promptPreview`), subagent handback reports (`SubagentHandback` / `<agent-message>`), cross-session `SendMessage` / `send_message` / `send_input` / `wait_agent` exchanges, and `<task-notification>` / `<subagent_notification>` cards chronologically inside the conversation feed with clean Markdown rendering, deduplication, encrypted payload handling, and one-click **Inspect workflow** drawer links.
18
+ - Displays follow-up parent prompts (`Follow-up prompt from parent`) inside the subagent workflow drawer and resolves native disk subagents cleanly for SCOPE-launched `cli:` Claude Code sessions.
19
+ - **Session Subagents Directory & Inline Per-Task Cards**:
20
+ - Upgrades the right slide-over drawer into a dual-mode **Session Subagents Directory Overview** (with search and per-task grouping) ↔ **Step-by-Step Workflow Detail** (`All subagents` back button, dropdown switcher, prev/next arrows, step category filters, and Expand/Collapse all).
21
+ - Renders inline **`Spawned N subagents`** cards directly inside each task turn showing exact subagent names, types, models, statuses, and dispatched prompt previews.
22
+ - **External Terminal Lock Detection & Read-Only Mode (Claude Code & Antigravity)**:
23
+ - Detects active non-SCOPE, non-tmux terminal sessions via `~/.claude/sessions/*.json` + `/proc` + `tmux` (Claude Code) and `~/.gemini/antigravity-cli/presence/*.lock` `fcntl.flock` + `/proc/<pid>/fd` (Antigravity).
24
+ - Marks externally locked sessions with a sidebar **`TTY`** badge (disabling archive), an amber header lock pill (`Terminal locked · pts/N`), a read-only banner with **Check unlock**, disabled composer input, and 4-second live tail auto-refresh while locked.
25
+ - **Subagent Display Toggles (Sliding Switch UI)**:
26
+ - Adds four instant-apply `localStorage`-persisted display switches (`Inline spawn cards`, `Parent ↔ subagent feed`, `Auto-expand handbacks`, `Header shortcut badge`) with custom theme-aware sliding toggle switches in both **Settings → General → Subagent Display** and the drawer header **`Display`** tray.
27
+
28
+ ### Fixed
29
+
30
+ - **Subagent Workflow Drawer Scrolling**: Fixed a flexbox shrinking bug in `.subagent-drawer-body` that squished long 60–160+ step timelines into overlapping slivers instead of scrolling smoothly.
31
+ - **Large Claude History Streaming**: Raised the tail streaming budget in `probe.py` to 24 MB while skipping oversized `api-request*` / `data-flow-records` payloads so long sessions retain complete subagent discovery and interaction history.
32
+
33
+ ## [0.2.1] — 2026-11-24
34
+
35
+ ### Added
36
+
37
+ - **Subagent Workflow Drawer for Claude Code & Codex**: Click any subagent row or the header **`Subagents · N`** button in a Claude Code or Codex session to open a right slide-over inspector drawer displaying the full step-by-step workflow timeline — task prompt, thinking/reasoning duration, shell commands & tool calls with concise summaries and expandable input/output, `SubagentHandback` Markdown reports, rich-media Markdown replies (KaTeX, GFM tables, inline images/videos, `file://` links), sibling subagent switcher tabs, and live auto-refresh while running.
38
+ - **Claude Code Subagent Parsing & Live Buffering**:
39
+ - Streams `agent-*.jsonl` + companion `agent-*.meta.json` on demand via `GET /api/session-catalog/subagent-workflow` (skips large API request blobs, strips base64 images, caps oversized tool outputs, matches `tool_use_id`, supports `agent-*` and `toolUseId` lookup, strict path containment, and `version` cache short-circuiting).
40
+ - Preserves live `parent_tool_use_id` thinking, tool calls/results, and streaming text deltas in `claude-interactive.py` so active subagents update in real time before disk flush.
41
+ - **Codex Subagent Discovery & Authorized Inspection**:
42
+ - Automatically discovers and attaches child subagent rollouts (`source.subagent.thread_spawn`) onto live CLI, App Server, cached historical, and catalog-selected Codex parent sessions without cluttering the root session list.
43
+ - Extends `POST /api/dialogue` with ownership-verified `subagentId` reading and earlier-step pagination across both remote SSH and local hosts.
44
+ - **Interactive Preview Fixtures**: Updated `scope preview` with synthetic Claude Code and Codex subagent workflows so the slide-over drawer can be explored offline with zero SSH.
45
+
5
46
  ## [0.2.0] — 2026-11-24
6
47
 
7
48
  Initial public open-source release of **SCOPE — One monitor for all agent sessions.**
@@ -1,160 +1,160 @@
1
- import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
2
- import { mkdir, readFile, writeFile } from "node:fs/promises";
3
- import http from "node:http";
4
- import path from "node:path";
5
-
6
- const MAX_REQUEST_BYTES = 32 * 1024;
7
- const VALID_STATUSES = new Set(["completed", "failed", "needs_attention"]);
8
-
9
- function clean(value, limit = 4_000) {
10
- return String(value ?? "")
11
- .replace(/\u0000/g, "")
12
- .trim()
13
- .slice(0, limit);
14
- }
15
-
16
- function digest(value) {
17
- return createHash("sha256").update(String(value ?? "")).digest();
18
- }
19
-
20
- function equalSecret(actual, expected) {
21
- return timingSafeEqual(digest(actual), digest(expected));
22
- }
23
-
24
- function bearerToken(request) {
25
- const authorization = clean(request.headers.authorization, 2_000);
26
- const match = authorization.match(/^Bearer\s+(.+)$/i);
27
- return match?.[1] || "";
28
- }
29
-
30
- async function readJsonBody(request) {
31
- const chunks = [];
32
- let total = 0;
33
- for await (const chunk of request) {
34
- total += chunk.length;
35
- if (total > MAX_REQUEST_BYTES) throw new Error("request-too-large");
36
- chunks.push(chunk);
37
- }
38
- const body = Buffer.concat(chunks).toString("utf8");
39
- return JSON.parse(body || "{}");
40
- }
41
-
42
- function sendJson(response, statusCode, payload) {
43
- response.writeHead(statusCode, {
44
- "Cache-Control": "no-store",
45
- "Content-Type": "application/json; charset=utf-8",
46
- "X-Content-Type-Options": "nosniff",
47
- });
48
- response.end(`${JSON.stringify(payload)}\n`);
49
- }
50
-
51
- export function normalizeAgentEmailEvent(payload) {
52
- const status = clean(payload?.status, 40).toLowerCase();
53
- const title = clean(payload?.title, 240);
54
- const summary = clean(payload?.summary, 8_000);
55
- if (!VALID_STATUSES.has(status)) {
56
- throw new Error("status must be completed, failed, or needs_attention");
57
- }
58
- if (!title || !summary) throw new Error("title and summary are required");
59
-
60
- const host = clean(payload?.host, 300) || "unknown-host";
61
- const agent = clean(payload?.agent, 80) || "agent";
62
- const session = clean(payload?.session, 300);
63
- const cwd = clean(payload?.cwd, 1_000);
64
- const suppliedDetails = Array.isArray(payload?.details)
65
- ? payload.details.slice(0, 12).map((item) => clean(item, 2_000)).filter(Boolean)
66
- : [];
67
- const details = [
68
- `Status: ${status}`,
69
- `Agent: ${agent}`,
70
- `Host: ${host}`,
71
- session ? `Session: ${session}` : "",
72
- cwd ? `Directory: ${cwd}` : "",
73
- ...suppliedDetails,
74
- ].filter(Boolean);
75
- const keyMaterial = JSON.stringify({ status, title, summary, host, agent, session, cwd });
76
-
77
- return {
78
- key: `agent-completion:${createHash("sha256").update(keyMaterial).digest("hex")}`,
79
- severity: status,
80
- title: `[${host}] ${title}`,
81
- summary,
82
- details,
83
- timestamp: clean(payload?.timestamp, 100) || new Date().toISOString(),
84
- };
85
- }
86
-
87
- export function createAgentEmailRelayServer({ token, notifier }) {
88
- if (typeof token !== "string" || token.length < 32) {
89
- throw new Error("Agent email relay token must contain at least 32 characters");
90
- }
91
- if (!notifier || typeof notifier.notify !== "function") {
92
- throw new Error("Agent email relay requires an email notifier");
93
- }
94
-
95
- return http.createServer(async (request, response) => {
96
- const requestUrl = new URL(request.url || "/", "http://scope-agent-email.local");
97
- if (request.method === "GET" && requestUrl.pathname === "/health") {
98
- sendJson(response, 200, {
99
- service: "scope-agent-email-relay",
100
- email: notifier.publicState(),
101
- });
102
- return;
103
- }
104
-
105
- if (request.method !== "POST" || requestUrl.pathname !== "/v1/notify") {
106
- sendJson(response, 404, { error: "not-found" });
107
- return;
108
- }
109
- if (!equalSecret(bearerToken(request), token)) {
110
- sendJson(response, 401, { error: "unauthorized" });
111
- return;
112
- }
113
-
114
- try {
115
- const event = normalizeAgentEmailEvent(await readJsonBody(request));
116
- const result = await notifier.notify(event);
117
- if (result.sent || result.reason === "duplicate") {
118
- sendJson(response, 200, {
119
- accepted: true,
120
- sent: Boolean(result.sent),
121
- duplicate: result.reason === "duplicate",
122
- });
123
- return;
124
- }
125
- sendJson(response, 503, {
126
- accepted: false,
127
- error: clean(result.reason || "email-send-failed", 600),
128
- });
129
- } catch (error) {
130
- const invalid = ["SyntaxError", "TypeError"].includes(error?.name) ||
131
- /required|status|request-too-large/.test(error?.message || "");
132
- sendJson(response, invalid ? 400 : 500, {
133
- error: clean(error?.message || "relay-failed", 600),
134
- });
135
- }
136
- });
137
- }
138
-
139
- export async function loadOrCreateAgentEmailRelayState(filename, defaults = {}) {
140
- try {
141
- const parsed = JSON.parse(await readFile(filename, "utf8"));
142
- if (typeof parsed.token === "string" && parsed.token.length >= 32) {
143
- return { ...defaults, ...parsed };
144
- }
145
- } catch (error) {
146
- if (error?.code !== "ENOENT") throw error;
147
- }
148
-
149
- const state = {
150
- token: randomBytes(32).toString("base64url"),
151
- createdAt: new Date().toISOString(),
152
- ...defaults,
153
- };
154
- await mkdir(path.dirname(filename), { recursive: true });
155
- await writeFile(filename, `${JSON.stringify(state, null, 2)}\n`, {
156
- encoding: "utf8",
157
- mode: 0o600,
158
- });
159
- return state;
160
- }
1
+ import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import http from "node:http";
4
+ import path from "node:path";
5
+
6
+ const MAX_REQUEST_BYTES = 32 * 1024;
7
+ const VALID_STATUSES = new Set(["completed", "failed", "needs_attention"]);
8
+
9
+ function clean(value, limit = 4_000) {
10
+ return String(value ?? "")
11
+ .replace(/\u0000/g, "")
12
+ .trim()
13
+ .slice(0, limit);
14
+ }
15
+
16
+ function digest(value) {
17
+ return createHash("sha256").update(String(value ?? "")).digest();
18
+ }
19
+
20
+ function equalSecret(actual, expected) {
21
+ return timingSafeEqual(digest(actual), digest(expected));
22
+ }
23
+
24
+ function bearerToken(request) {
25
+ const authorization = clean(request.headers.authorization, 2_000);
26
+ const match = authorization.match(/^Bearer\s+(.+)$/i);
27
+ return match?.[1] || "";
28
+ }
29
+
30
+ async function readJsonBody(request) {
31
+ const chunks = [];
32
+ let total = 0;
33
+ for await (const chunk of request) {
34
+ total += chunk.length;
35
+ if (total > MAX_REQUEST_BYTES) throw new Error("request-too-large");
36
+ chunks.push(chunk);
37
+ }
38
+ const body = Buffer.concat(chunks).toString("utf8");
39
+ return JSON.parse(body || "{}");
40
+ }
41
+
42
+ function sendJson(response, statusCode, payload) {
43
+ response.writeHead(statusCode, {
44
+ "Cache-Control": "no-store",
45
+ "Content-Type": "application/json; charset=utf-8",
46
+ "X-Content-Type-Options": "nosniff",
47
+ });
48
+ response.end(`${JSON.stringify(payload)}\n`);
49
+ }
50
+
51
+ export function normalizeAgentEmailEvent(payload) {
52
+ const status = clean(payload?.status, 40).toLowerCase();
53
+ const title = clean(payload?.title, 240);
54
+ const summary = clean(payload?.summary, 8_000);
55
+ if (!VALID_STATUSES.has(status)) {
56
+ throw new Error("status must be completed, failed, or needs_attention");
57
+ }
58
+ if (!title || !summary) throw new Error("title and summary are required");
59
+
60
+ const host = clean(payload?.host, 300) || "unknown-host";
61
+ const agent = clean(payload?.agent, 80) || "agent";
62
+ const session = clean(payload?.session, 300);
63
+ const cwd = clean(payload?.cwd, 1_000);
64
+ const suppliedDetails = Array.isArray(payload?.details)
65
+ ? payload.details.slice(0, 12).map((item) => clean(item, 2_000)).filter(Boolean)
66
+ : [];
67
+ const details = [
68
+ `Status: ${status}`,
69
+ `Agent: ${agent}`,
70
+ `Host: ${host}`,
71
+ session ? `Session: ${session}` : "",
72
+ cwd ? `Directory: ${cwd}` : "",
73
+ ...suppliedDetails,
74
+ ].filter(Boolean);
75
+ const keyMaterial = JSON.stringify({ status, title, summary, host, agent, session, cwd });
76
+
77
+ return {
78
+ key: `agent-completion:${createHash("sha256").update(keyMaterial).digest("hex")}`,
79
+ severity: status,
80
+ title: `[${host}] ${title}`,
81
+ summary,
82
+ details,
83
+ timestamp: clean(payload?.timestamp, 100) || new Date().toISOString(),
84
+ };
85
+ }
86
+
87
+ export function createAgentEmailRelayServer({ token, notifier }) {
88
+ if (typeof token !== "string" || token.length < 32) {
89
+ throw new Error("Agent email relay token must contain at least 32 characters");
90
+ }
91
+ if (!notifier || typeof notifier.notify !== "function") {
92
+ throw new Error("Agent email relay requires an email notifier");
93
+ }
94
+
95
+ return http.createServer(async (request, response) => {
96
+ const requestUrl = new URL(request.url || "/", "http://scope-agent-email.local");
97
+ if (request.method === "GET" && requestUrl.pathname === "/health") {
98
+ sendJson(response, 200, {
99
+ service: "scope-agent-email-relay",
100
+ email: notifier.publicState(),
101
+ });
102
+ return;
103
+ }
104
+
105
+ if (request.method !== "POST" || requestUrl.pathname !== "/v1/notify") {
106
+ sendJson(response, 404, { error: "not-found" });
107
+ return;
108
+ }
109
+ if (!equalSecret(bearerToken(request), token)) {
110
+ sendJson(response, 401, { error: "unauthorized" });
111
+ return;
112
+ }
113
+
114
+ try {
115
+ const event = normalizeAgentEmailEvent(await readJsonBody(request));
116
+ const result = await notifier.notify(event);
117
+ if (result.sent || result.reason === "duplicate") {
118
+ sendJson(response, 200, {
119
+ accepted: true,
120
+ sent: Boolean(result.sent),
121
+ duplicate: result.reason === "duplicate",
122
+ });
123
+ return;
124
+ }
125
+ sendJson(response, 503, {
126
+ accepted: false,
127
+ error: clean(result.reason || "email-send-failed", 600),
128
+ });
129
+ } catch (error) {
130
+ const invalid = ["SyntaxError", "TypeError"].includes(error?.name) ||
131
+ /required|status|request-too-large/.test(error?.message || "");
132
+ sendJson(response, invalid ? 400 : 500, {
133
+ error: clean(error?.message || "relay-failed", 600),
134
+ });
135
+ }
136
+ });
137
+ }
138
+
139
+ export async function loadOrCreateAgentEmailRelayState(filename, defaults = {}) {
140
+ try {
141
+ const parsed = JSON.parse(await readFile(filename, "utf8"));
142
+ if (typeof parsed.token === "string" && parsed.token.length >= 32) {
143
+ return { ...defaults, ...parsed };
144
+ }
145
+ } catch (error) {
146
+ if (error?.code !== "ENOENT") throw error;
147
+ }
148
+
149
+ const state = {
150
+ token: randomBytes(32).toString("base64url"),
151
+ createdAt: new Date().toISOString(),
152
+ ...defaults,
153
+ };
154
+ await mkdir(path.dirname(filename), { recursive: true });
155
+ await writeFile(filename, `${JSON.stringify(state, null, 2)}\n`, {
156
+ encoding: "utf8",
157
+ mode: 0o600,
158
+ });
159
+ return state;
160
+ }