@firstpick/pi-package-webui 0.7.5 → 0.7.7

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 (40) hide show
  1. package/README.md +37 -4
  2. package/bin/pi-webui-rpc-supervisor.mjs +518 -0
  3. package/bin/pi-webui.mjs +1003 -82
  4. package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
  5. package/lib/rpc-supervisor-client.mjs +301 -0
  6. package/lib/rpc-supervisor-protocol.mjs +236 -0
  7. package/lib/rpc-supervisor-state.mjs +165 -0
  8. package/lib/trust-boundaries.mjs +1 -0
  9. package/package.json +2 -2
  10. package/public/app.js +1243 -87
  11. package/public/index.html +334 -24
  12. package/public/service-worker.js +6 -1
  13. package/public/styles.css +642 -41
  14. package/public/subagent-gate-visibility.mjs +36 -0
  15. package/public/workflow-status-stack.mjs +69 -0
  16. package/tests/app-runner-process-tree-harness.test.mjs +37 -3
  17. package/tests/boot-failure-diagnostics.test.mjs +180 -0
  18. package/tests/compact-sections-static.test.mjs +111 -0
  19. package/tests/durable-rpc-supervisor-harness.test.mjs +252 -0
  20. package/tests/fast-mode-client-static.test.mjs +2 -2
  21. package/tests/fixtures/compacting-pi.mjs +0 -0
  22. package/tests/fixtures/fake-pi.mjs +81 -2
  23. package/tests/git-panel-file-preview-static.test.mjs +221 -0
  24. package/tests/http-endpoints-harness.test.mjs +458 -33
  25. package/tests/mobile-static.test.mjs +77 -9
  26. package/tests/native-parity-harness.test.mjs +2 -1
  27. package/tests/native-parity.test.mjs +11 -0
  28. package/tests/numpad-decimal-input-static.test.mjs +128 -0
  29. package/tests/prompt-routing-input-clear-static.test.mjs +34 -0
  30. package/tests/prompt-routing-tab-status.test.mjs +103 -0
  31. package/tests/rpc-supervisor-host.test.mjs +275 -0
  32. package/tests/rpc-supervisor-protocol.test.mjs +67 -0
  33. package/tests/rpc-supervisor-state.test.mjs +62 -0
  34. package/tests/run-all.mjs +4 -1
  35. package/tests/streaming-ui-coupling.test.mjs +15 -0
  36. package/tests/subagent-gate-visibility.test.mjs +66 -0
  37. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  38. package/tests/subagents-helper.test.mjs +145 -8
  39. package/tests/workflow-status-stack.test.mjs +87 -0
  40. package/webui-rpc-helper.mjs +164 -4
@@ -0,0 +1,36 @@
1
+ export const SUBAGENT_GATE_RETENTION_MS = 30_000;
2
+
3
+ export function subagentGateKey(tabId, gateId) {
4
+ const normalizedTabId = String(tabId || "").trim();
5
+ const normalizedGateId = String(gateId || "").trim();
6
+ return normalizedTabId && normalizedGateId ? `${normalizedTabId}:${normalizedGateId}` : "";
7
+ }
8
+
9
+ export function subagentGateIsTerminal(gate) {
10
+ return gate?.status !== "running";
11
+ }
12
+
13
+ export function visibleSubagentGates(tab, dismissedGateKeys, now = Date.now(), retentionMs = SUBAGENT_GATE_RETENTION_MS) {
14
+ const gates = Array.isArray(tab?.gates) ? tab.gates : [];
15
+ return gates.filter((gate) => {
16
+ if (!subagentGateIsTerminal(gate)) return true;
17
+ const key = subagentGateKey(tab?.tabId, gate?.id);
18
+ if (key && dismissedGateKeys?.has?.(key)) return false;
19
+ const endedAt = Number(gate?.endedAt ?? gate?.updatedAt);
20
+ return !Number.isFinite(endedAt) || Math.max(0, now - endedAt) < retentionMs;
21
+ });
22
+ }
23
+
24
+ export function pruneDismissedSubagentGateKeys(tabs, dismissedGateKeys) {
25
+ if (!dismissedGateKeys?.size) return;
26
+ const liveKeys = new Set();
27
+ for (const tab of Array.isArray(tabs) ? tabs : []) {
28
+ for (const gate of Array.isArray(tab?.gates) ? tab.gates : []) {
29
+ const key = subagentGateKey(tab?.tabId, gate?.id);
30
+ if (key) liveKeys.add(key);
31
+ }
32
+ }
33
+ for (const key of dismissedGateKeys) {
34
+ if (!liveKeys.has(key)) dismissedGateKeys.delete(key);
35
+ }
36
+ }
@@ -0,0 +1,69 @@
1
+ const WORKFLOW_STATUS_TOOL_NAME = "workflow_status";
2
+
3
+ export function isCompletedWorkflowStatusExecution(message) {
4
+ if (message?.role !== "toolExecution") return false;
5
+ const name = String(message.toolName || message.name || "");
6
+ return name === WORKFLOW_STATUS_TOOL_NAME && !message.live && !message.isPartial && message.result !== undefined && message.result !== null;
7
+ }
8
+
9
+ function workflowStatusStackKey(items) {
10
+ const first = items[0] || {};
11
+ const toolCallId = String(first.message?.toolCallId ?? "").trim();
12
+ const id = toolCallId || (first.messageIndex !== undefined ? `m:${first.messageIndex}` : first.order !== undefined ? `o:${first.order}` : "first");
13
+ return `workflow-status-stack:${id}`;
14
+ }
15
+
16
+ export function groupConsecutiveWorkflowStatusItems(items) {
17
+ const grouped = [];
18
+ let pending = [];
19
+
20
+ const flush = () => {
21
+ if (pending.length === 1) {
22
+ grouped.push(pending[0]);
23
+ } else if (pending.length > 1) {
24
+ const first = pending[0];
25
+ const latest = pending.at(-1);
26
+ const updates = pending.map((item) => item.message);
27
+ grouped.push({
28
+ ...first,
29
+ message: {
30
+ role: "workflowStatusStack",
31
+ title: `workflow_status · ${updates.length} updates`,
32
+ timestamp: latest.message?.timestamp || first.message?.timestamp,
33
+ content: latest.message?.result?.content,
34
+ workflowStatusUpdates: updates,
35
+ isError: updates.some((update) => update?.isError || update?.result?.isError),
36
+ },
37
+ transcriptKey: workflowStatusStackKey(pending),
38
+ });
39
+ }
40
+ pending = [];
41
+ };
42
+
43
+ for (const item of items || []) {
44
+ if (isCompletedWorkflowStatusExecution(item?.message)) pending.push(item);
45
+ else {
46
+ flush();
47
+ grouped.push(item);
48
+ }
49
+ }
50
+ flush();
51
+ return grouped;
52
+ }
53
+
54
+ export function workflowStatusSnapshot(text) {
55
+ const fields = {};
56
+ const lines = String(text || "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
57
+ for (const line of lines) {
58
+ const match = /^(Workflow|Run|Status|Tasks):\s*(.+)$/i.exec(line);
59
+ if (match) fields[match[1].toLowerCase()] = match[2].trim();
60
+ }
61
+ const fallback = lines[0] || "No workflow status details were returned.";
62
+ return {
63
+ workflow: fields.workflow || "",
64
+ run: fields.run || "",
65
+ status: fields.status || "",
66
+ tasks: fields.tasks || "",
67
+ fallback: fallback.length > 180 ? `${fallback.slice(0, 179)}…` : fallback,
68
+ };
69
+ }
@@ -6,6 +6,8 @@ import path from "node:path";
6
6
  import { setTimeout as delay } from "node:timers/promises";
7
7
  import { dirname, join } from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
+ import { connectRpcSupervisor } from "../lib/rpc-supervisor-client.mjs";
10
+ import { readSupervisorState, supervisorPaths } from "../lib/rpc-supervisor-state.mjs";
9
11
 
10
12
  const root = join(dirname(fileURLToPath(import.meta.url)), "..");
11
13
  const serverScript = join(root, "bin", "pi-webui.mjs");
@@ -53,6 +55,8 @@ function killFixtureProcess(pid) {
53
55
  }
54
56
 
55
57
  const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-app-runner-tree-"));
58
+ const agentDir = path.join(cwd, "agent");
59
+ const supervisorStatePaths = await supervisorPaths({ agentDir, port });
56
60
  const settingsFile = path.join(cwd, "webui-settings.json");
57
61
  await chmod(fakePi, 0o755);
58
62
  await writeFile(path.join(cwd, "tree-child.mjs"), "setInterval(() => {}, 1000);\n");
@@ -72,27 +76,37 @@ const server = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "1
72
76
  stdio: ["ignore", "pipe", "pipe"],
73
77
  env: {
74
78
  ...process.env,
79
+ PI_CODING_AGENT_DIR: agentDir,
75
80
  PI_WEBUI_SETTINGS_FILE: settingsFile,
76
81
  PI_WEBUI_APP_RUNNER_PTY: "off",
77
82
  },
78
83
  windowsHide: true,
79
84
  });
80
85
  let serverOutput = "";
86
+ let piPid = 0;
87
+ let supervisorPid = 0;
81
88
  let runnerPid = 0;
82
89
  let treeChildPid = 0;
83
90
  server.stdout.on("data", (chunk) => { serverOutput += String(chunk); });
84
91
  server.stderr.on("data", (chunk) => { serverOutput += String(chunk); });
85
92
 
86
93
  try {
87
- await waitFor("server health", async () => {
94
+ const health = await waitFor("server health", async () => {
88
95
  if (server.exitCode !== null) return false;
89
96
  try {
90
- const health = await request("/api/health", { timeoutMs: 1_000 });
91
- return health.status === 200 && health.body?.ok === true ? health : false;
97
+ const response = await request("/api/health", { timeoutMs: 1_000 });
98
+ return response.status === 200 && response.body?.ok === true ? response : false;
92
99
  } catch {
93
100
  return false;
94
101
  }
95
102
  }, { attempts: 100, intervalMs: 120 });
103
+ piPid = Number(health.body?.piPid) || 0;
104
+ assert.ok(piPid > 0, `startup fake Pi PID should be available, output:\n${serverOutput}`);
105
+ if (health.body?.rpcSupervisor?.enabled === true) {
106
+ const state = await waitFor("isolated supervisor state", () => readSupervisorState(supervisorStatePaths));
107
+ supervisorPid = Number(state.pid) || 0;
108
+ assert.ok(supervisorPid > 0, "isolated supervisor state should identify its process");
109
+ }
96
110
 
97
111
  const tabsResponse = await request("/api/tabs");
98
112
  const tabId = tabsResponse.body?.data?.tabs?.[0]?.id || tabsResponse.body?.tabs?.[0]?.id;
@@ -149,6 +163,11 @@ try {
149
163
  await request("/api/shutdown", { method: "POST" }).catch(() => undefined);
150
164
  for (let attempt = 0; attempt < 50 && server.exitCode === null; attempt += 1) await delay(100);
151
165
  assert.notEqual(server.exitCode, null, "server should exit after /api/shutdown");
166
+ await waitFor("fake Pi teardown", () => !isProcessRunning(piPid));
167
+ if (supervisorPid > 0) await waitFor("supervisor teardown", () => !isProcessRunning(supervisorPid));
168
+ await waitFor("isolated supervisor state cleanup", async () => (await readSupervisorState(supervisorStatePaths)) === null);
169
+ assert.equal(isProcessRunning(piPid), false, "server teardown must not leave its fake Pi running");
170
+ assert.equal(isProcessRunning(supervisorPid), false, "server teardown must not leave its supervisor running");
152
171
  console.log("app-runner-process-tree-harness.test.mjs passed");
153
172
  } finally {
154
173
  if (server.exitCode === null) {
@@ -156,7 +175,22 @@ try {
156
175
  for (let attempt = 0; attempt < 20 && server.exitCode === null; attempt += 1) await delay(100);
157
176
  if (server.exitCode === null) server.kill("SIGKILL");
158
177
  }
178
+ const remainingSupervisor = await readSupervisorState(supervisorStatePaths).catch(() => null);
179
+ if (remainingSupervisor) {
180
+ const cleanupClient = await connectRpcSupervisor({
181
+ agentDir,
182
+ port,
183
+ controllerId: "app-runner-process-tree-cleanup",
184
+ connectTimeoutMs: 1_000,
185
+ }).catch(() => null);
186
+ if (cleanupClient) {
187
+ try { await cleanupClient.shutdown(); } catch {}
188
+ cleanupClient.close();
189
+ }
190
+ }
159
191
  killFixtureProcess(runnerPid);
160
192
  killFixtureProcess(treeChildPid);
193
+ killFixtureProcess(piPid);
194
+ killFixtureProcess(supervisorPid);
161
195
  await rm(cwd, { recursive: true, force: true });
162
196
  }
@@ -0,0 +1,180 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
+ import vm from "node:vm";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
+ const [html, app, serviceWorker] = await Promise.all([
9
+ readFile(join(root, "public", "index.html"), "utf8"),
10
+ readFile(join(root, "public", "app.js"), "utf8"),
11
+ readFile(join(root, "public", "service-worker.js"), "utf8"),
12
+ ]);
13
+
14
+ const loaderMatch = html.match(/<script id="webuiBootLoader"[^>]*>([\s\S]*?)<\/script>/);
15
+ assert.ok(loaderMatch, "index.html should contain the inline WebUI boot loader");
16
+ const loaderSource = loaderMatch[1];
17
+
18
+ class FakeElement {
19
+ constructor(values = {}) {
20
+ Object.assign(this, values);
21
+ this.listeners = new Map();
22
+ this.hidden ??= true;
23
+ this.value ??= "";
24
+ this.textContent ??= "";
25
+ }
26
+
27
+ addEventListener(name, listener) {
28
+ this.listeners.set(name, listener);
29
+ }
30
+
31
+ focus() {}
32
+ select() { this.selected = true; }
33
+ }
34
+
35
+ class FakeResponse {
36
+ constructor(url, status, { type = "text/plain", text = "", json = null } = {}) {
37
+ this.url = url;
38
+ this.status = status;
39
+ this.ok = status >= 200 && status < 300;
40
+ this._text = text;
41
+ this._json = json;
42
+ this.headers = { get: (name) => name.toLowerCase() === "content-type" ? type : null };
43
+ this.body = { cancel: async () => {} };
44
+ }
45
+
46
+ clone() { return new FakeResponse(this.url, this.status, { type: this.headers.get("content-type"), text: this._text, json: this._json }); }
47
+ async text() { return this._text; }
48
+ async json() { return this._json; }
49
+ }
50
+
51
+ function makeEnvironment({ importApp, stylesheetLoaded = true, stylesheetStatus = 200, workflowModuleStatus = 404 } = {}) {
52
+ const elements = {
53
+ panel: new FakeElement({ hidden: true }),
54
+ reason: new FakeElement(),
55
+ report: new FakeElement({ value: "Collecting diagnostics…" }),
56
+ copy: new FakeElement(),
57
+ reload: new FakeElement(),
58
+ copyStatus: new FakeElement(),
59
+ };
60
+ const styleLink = new FakeElement({ href: "http://127.0.0.1:31415/styles.css?v=84", sheet: stylesheetLoaded ? {} : null });
61
+ const listeners = new Map();
62
+ const timers = new Map();
63
+ let timerId = 0;
64
+ let copied = "";
65
+ let reloaded = false;
66
+
67
+ const location = {
68
+ href: "http://127.0.0.1:31415/?pin=SUPERSECRET#private",
69
+ origin: "http://127.0.0.1:31415",
70
+ reload() { reloaded = true; },
71
+ };
72
+ const window = {
73
+ location,
74
+ __PI_WEBUI_BOOT_IMPORT__: importApp,
75
+ addEventListener(name, listener) { listeners.set(name, listener); },
76
+ removeEventListener(name) { listeners.delete(name); },
77
+ };
78
+ const document = {
79
+ currentScript: new FakeElement({ dataset: { appSrc: "/app.js?v=91" } }),
80
+ readyState: "complete",
81
+ querySelector(selector) {
82
+ return {
83
+ "#webuiBootFailurePanel": elements.panel,
84
+ "#webuiBootFailureReason": elements.reason,
85
+ "#webuiBootFailureReport": elements.report,
86
+ "#copyWebuiBootFailureReportButton": elements.copy,
87
+ "#reloadWebuiAfterBootFailureButton": elements.reload,
88
+ "#webuiBootFailureCopyStatus": elements.copyStatus,
89
+ 'link[rel="stylesheet"]': styleLink,
90
+ }[selector] || null;
91
+ },
92
+ execCommand() { return true; },
93
+ };
94
+
95
+ async function fetch(input) {
96
+ const url = String(input);
97
+ if (url.includes("/api/health")) return new FakeResponse(url, 200, { type: "application/json", json: { ok: true, webuiVersion: "0.7.6", remoteAuthPin: "1234" } });
98
+ if (url.includes("/app.js")) return new FakeResponse(url, 200, { type: "text/javascript", text: 'import "./workflow-status-stack.mjs";\nimport "./fast-output-live.mjs";' });
99
+ if (url.includes("workflow-status-stack.mjs")) return new FakeResponse(url, workflowModuleStatus, { type: workflowModuleStatus === 200 ? "text/javascript" : "application/json" });
100
+ if (url.includes("fast-output-live.mjs")) return new FakeResponse(url, 200, { type: "text/javascript" });
101
+ if (url.includes("styles.css")) return new FakeResponse(url, stylesheetStatus, { type: "text/css" });
102
+ return new FakeResponse(url, 404);
103
+ }
104
+
105
+ const context = {
106
+ window,
107
+ document,
108
+ navigator: {
109
+ userAgent: "Boot diagnostics test browser",
110
+ clipboard: { async writeText(value) { copied = value; } },
111
+ },
112
+ fetch,
113
+ URL,
114
+ Error,
115
+ Date,
116
+ Promise,
117
+ console,
118
+ setTimeout(callback) { const id = ++timerId; timers.set(id, callback); return id; },
119
+ clearTimeout(id) { timers.delete(id); },
120
+ };
121
+
122
+ return {
123
+ context,
124
+ elements,
125
+ listeners,
126
+ timers,
127
+ copied: () => copied,
128
+ reloaded: () => reloaded,
129
+ };
130
+ }
131
+
132
+ async function settleAsyncWork() {
133
+ for (let index = 0; index < 8; index += 1) await new Promise((resolve) => setImmediate(resolve));
134
+ }
135
+
136
+ const missingModule = makeEnvironment({
137
+ importApp: async () => { throw new Error("Failed to fetch dynamically imported module: http://127.0.0.1:31415/workflow-status-stack.mjs?pin=SUPERSECRET"); },
138
+ });
139
+ vm.runInNewContext(loaderSource, missingModule.context, { filename: "webui-boot-loader.js" });
140
+ await settleAsyncWork();
141
+ assert.equal(missingModule.elements.panel.hidden, false, "a rejected app import should expose the boot-failure panel");
142
+ assert.match(missingModule.elements.report.value, /Pi Web UI startup failure/);
143
+ assert.match(missingModule.elements.report.value, /Diagnosis[\s\S]*Summary: Missing startup module: \/workflow-status-stack\.mjs \(HTTP 404\)\./, "the diagnosis should name the actual missing transitive import before the full checks list");
144
+ assert.match(missingModule.elements.report.value, /Likely cause: The backend is healthy, but the running server's static asset allowlist is out of sync with app\.js\./);
145
+ assert.match(missingModule.elements.report.value, /Browser note: a transitive import failure may be reported as app\.js/);
146
+ assert.match(missingModule.elements.report.value, /Failing checks[\s\S]*HTTP 404 application\/json/, "the report should isolate failing probes");
147
+ assert.match(missingModule.elements.report.value, /Recheck the failing asset: curl -i http:\/\/127\.0\.0\.1:31415\/workflow-status-stack\.mjs/);
148
+ assert.match(missingModule.elements.report.value, /backend health: HTTP 200 application\/json \(ok=true, webuiVersion=0\.7\.6\)/);
149
+ assert.equal(missingModule.elements.reason.textContent, "Missing startup module: /workflow-status-stack.mjs (HTTP 404).", "the visible summary should expose the diagnosed file without requiring report inspection");
150
+ assert.match(missingModule.elements.report.value, /\/webui-status detailed/);
151
+ assert.doesNotMatch(missingModule.elements.report.value, /SUPERSECRET|remoteAuthPin|1234/, "diagnostics must omit URL secrets and unselected health fields");
152
+ await missingModule.elements.copy.listeners.get("click")();
153
+ assert.equal(missingModule.copied(), missingModule.elements.report.value, "Copy troubleshooting report should copy the complete generated report");
154
+ assert.equal(missingModule.elements.copyStatus.textContent, "Troubleshooting report copied.");
155
+ missingModule.elements.reload.listeners.get("click")();
156
+ assert.equal(missingModule.reloaded(), true, "Reload page should remain available without app.js");
157
+
158
+ const successfulBoot = makeEnvironment({ importApp: async () => ({}) });
159
+ vm.runInNewContext(loaderSource, successfulBoot.context, { filename: "webui-boot-loader.js" });
160
+ await settleAsyncWork();
161
+ assert.equal(successfulBoot.elements.panel.hidden, true, "a successful app import should keep the failure panel hidden");
162
+ assert.equal(successfulBoot.timers.size, 0, "successful startup should cancel the watchdog");
163
+ assert.equal(successfulBoot.listeners.has("error"), false, "successful startup should remove temporary global error capture");
164
+
165
+ const stylesheetFailure = makeEnvironment({ importApp: async () => ({}), stylesheetLoaded: false, stylesheetStatus: 404, workflowModuleStatus: 200 });
166
+ vm.runInNewContext(loaderSource, stylesheetFailure.context, { filename: "webui-boot-loader.js" });
167
+ await settleAsyncWork();
168
+ assert.equal(stylesheetFailure.elements.panel.hidden, false, "a missing critical stylesheet should expose the boot-failure panel");
169
+ assert.match(stylesheetFailure.elements.report.value, /Critical stylesheet returned HTTP 404/);
170
+
171
+ const startupModuleNames = [...new Set([...app.matchAll(/(?:\bfrom\s+|\bimport\s*(?:\(\s*)?)["']\.\/([^"'?]+)(?:\?[^"']*)?["']/g)].map((match) => match[1]))];
172
+ assert.ok(startupModuleNames.length >= 1, "the startup-module invariant should discover app.js imports");
173
+ for (const moduleName of startupModuleNames) {
174
+ assert.ok(serviceWorker.includes(`"/${moduleName}"`), `the PWA app shell should include every app.js startup module: ${moduleName}`);
175
+ }
176
+ assert.match(serviceWorker, /pi-webui-pwa-v\d+/, "the app-shell cache should retain a versioned identity");
177
+ assert.ok(html.indexOf('id="webuiBootLoader"') < html.indexOf("/app.js?v=91"), "the inline loader should own app module startup");
178
+ assert.doesNotMatch(html, /<script type="module" src="\/app\.js/, "the app module should not bypass the guarded loader");
179
+
180
+ console.log("boot-failure-diagnostics.test.mjs passed");
@@ -0,0 +1,111 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
7
+ const css = await readFile(join(root, "public", "styles.css"), "utf8");
8
+
9
+ function ruleBlock(selector, from = 0) {
10
+ const start = css.indexOf(`${selector} {`, from);
11
+ assert.notEqual(start, -1, `missing CSS rule: ${selector}`);
12
+ const end = css.indexOf("}", start);
13
+ assert.notEqual(end, -1, `unterminated CSS rule: ${selector}`);
14
+ return css.slice(start, end + 1);
15
+ }
16
+
17
+ function propertyValue(block, property) {
18
+ const match = block.match(new RegExp(`(?:^|\\n)\\s*${property.replace(/[.*+?^${}()|[\\]\\\\]/g, "\\$&")}:\\s*([^;]+);`));
19
+ assert.ok(match, `missing ${property} in CSS rule`);
20
+ return match[1].trim();
21
+ }
22
+
23
+ const compactStart = css.indexOf("/* Compact high-density surfaces:");
24
+ const responsiveStart = css.indexOf("@media (max-width: 1050px)");
25
+ assert.ok(compactStart >= 0 && responsiveStart > compactStart, "compact desktop overrides should stay before responsive rules so mobile adaptations win");
26
+
27
+ assert.match(
28
+ css,
29
+ /\/\* Compact high-density surfaces:[\s\S]*\.app-runner-widget \{[\s\S]*margin-block:\s*0\.18rem;[\s\S]*padding:\s*0\.52rem;[\s\S]*\.app-runner-live-widget \.release-npm-output-details\[open\] \.release-npm-terminal \{[\s\S]*height:\s*clamp\(8rem, 26dvh, 18rem\)/,
30
+ "App Runner should use compact widget chrome and a smaller live terminal",
31
+ );
32
+ assert.match(
33
+ css,
34
+ /\/\* Compact high-density surfaces:[\s\S]*\.subagent-launch-slots-summary \{[\s\S]*min-height:\s*2\.7rem;[\s\S]*\.subagents-box \{[\s\S]*padding:\s*0\.48rem;[\s\S]*\.subagent-tab-header \{[\s\S]*min-height:\s*36px;/,
35
+ "Subagents side-panel chrome should use the scoped compact density treatment",
36
+ );
37
+ assert.match(
38
+ css,
39
+ /\/\* Keep the Files tree visual language while giving Git its denser data-list rhythm\. \*\/[\s\S]*\.git-side-panel-folder-summary,[\s\S]*\.git-side-panel-file \{[\s\S]*min-height:\s*1\.55rem;[\s\S]*padding:\s*0\.08rem 0\.26rem;[\s\S]*border:\s*1px solid transparent;[\s\S]*border-radius:\s*0\.5rem;[\s\S]*\.git-side-panel-file:focus-visible \{[\s\S]*box-shadow:\s*inset 2px 0 0 var\(--ctp-blue\)/,
40
+ "Git changed-file rows should keep the Files tree visual language with denser spacing",
41
+ );
42
+ assert.match(
43
+ css,
44
+ /\/\* Compact high-density surfaces:[\s\S]*\.git-workflow-panel \{[\s\S]*gap:\s*0\.48rem;[\s\S]*max-height:\s*min\(28rem, 40dvh\);[\s\S]*padding:\s*0\.62rem;[\s\S]*\.git-workflow-output \{[\s\S]*min-height:\s*3\.5rem;/,
45
+ "Guided Git should use the scoped compact panel and output sizing",
46
+ );
47
+
48
+ const filesRow = ruleBlock(".file-tree-item");
49
+ const gitRows = ruleBlock(".git-side-panel-folder-summary,\n.git-side-panel-file", compactStart);
50
+ for (const property of ["color", "border-radius", "background"]) {
51
+ assert.equal(propertyValue(gitRows, property), propertyValue(filesRow, property), `Git and Files rows should share ${property}`);
52
+ }
53
+ assert.equal(propertyValue(gitRows, "min-height"), "1.55rem", "Git file rows should keep the compact data-list height");
54
+ assert.equal(propertyValue(gitRows, "padding"), "0.08rem 0.26rem", "Git file rows should keep their compact padding");
55
+ const gitTree = ruleBlock(".git-side-panel-tree", compactStart);
56
+ assert.equal(propertyValue(gitTree, "gap"), "0", "Git tree rows should not add inter-row gaps");
57
+ assert.equal(propertyValue(gitTree, "padding"), "0.14rem 0.18rem", "Git tree container padding should remain compact");
58
+ const denseGitRowsStart = css.indexOf("/* Keep the Files tree visual language", compactStart);
59
+ const genericDetailsStart = css.indexOf("\ndetails {\n margin: 0.5rem 0;");
60
+ assert.notEqual(genericDetailsStart, -1, "missing generic details card rule");
61
+ const genericDetails = ruleBlock("details", genericDetailsStart);
62
+ assert.equal(propertyValue(genericDetails, "padding"), "0.6rem", "generic details padding should remain explicit in the base stylesheet");
63
+ const gitFolderContainer = ruleBlock(".git-side-panel-folder", denseGitRowsStart);
64
+ assert.equal(propertyValue(gitFolderContainer, "margin"), "0", "Git directories should reset generic details margins");
65
+ assert.equal(propertyValue(gitFolderContainer, "padding"), "0", "Git directories should reset the generic details padding that creates inter-row gaps");
66
+ assert.equal(propertyValue(gitFolderContainer, "border"), "0", "Git directories should not inherit generic details borders");
67
+ assert.equal(propertyValue(gitFolderContainer, "border-radius"), "0", "Git directories should not retain generic details corner geometry");
68
+ assert.equal(propertyValue(gitFolderContainer, "background"), "transparent", "Git directories should not inherit generic details card backgrounds");
69
+ const gitFolderRow = ruleBlock(".git-side-panel-folder-summary", denseGitRowsStart);
70
+ assert.equal(propertyValue(gitFolderRow, "gap"), "0.18rem", "Git directory label spacing should remain compact");
71
+ assert.equal(propertyValue(gitFolderRow, "min-height"), "1.25rem", "Git directories should be denser than file rows");
72
+ assert.equal(propertyValue(gitFolderRow, "padding"), "0 0.2rem", "Git directories should remove vertical padding");
73
+ assert.equal(propertyValue(gitFolderRow, "line-height"), "1.1", "Git directory text should retain a compact readable line box");
74
+ const gitFolderChevron = ruleBlock(".git-side-panel-folder-chevron", denseGitRowsStart);
75
+ assert.equal(propertyValue(gitFolderChevron, "font-size"), "0.78rem", "Git directory chevrons should remain compact");
76
+ assert.equal(propertyValue(gitFolderChevron, "line-height"), "1", "Git directory chevrons should remain vertically centered");
77
+ const gitFolderBody = ruleBlock(".git-side-panel-folder-body", denseGitRowsStart);
78
+ assert.equal(propertyValue(gitFolderBody, "gap"), "0", "Nested Git entries should not add vertical gaps");
79
+ assert.equal(propertyValue(gitFolderBody, "margin"), "0 0 0 0.48rem", "Nested Git indentation should remain shallow");
80
+ assert.equal(propertyValue(gitFolderBody, "padding-left"), "0.24rem", "Nested guide padding should remain shallow");
81
+ assert.equal(propertyValue(filesRow, "border-color"), "transparent", "Files rows should start with a transparent border");
82
+ assert.equal(propertyValue(gitRows, "border"), "1px solid transparent", "Git rows should provide the same transparent one-pixel border geometry");
83
+ const filesHover = ruleBlock(".file-tree-item:hover,\n.file-tree-item:focus-visible");
84
+ const gitHover = ruleBlock(".git-side-panel-folder-summary:hover,\n.git-side-panel-folder-summary:focus-visible,\n.git-side-panel-file:hover,\n.git-side-panel-file:focus-visible", compactStart);
85
+ for (const property of ["border-color", "background", "box-shadow"]) {
86
+ assert.equal(propertyValue(gitHover, property), propertyValue(filesHover, property), `Git and Files rows should share hover/focus ${property}`);
87
+ }
88
+
89
+ const coarseStart = css.indexOf("@media (pointer: coarse)", compactStart);
90
+ const coarseEnd = css.indexOf("@media (prefers-reduced-motion: reduce)", coarseStart);
91
+ assert.ok(coarseStart > compactStart && coarseEnd > coarseStart, "coarse-pointer protections should follow compact desktop overrides");
92
+ const coarseBlock = css.slice(coarseStart, coarseEnd);
93
+ for (const selector of [
94
+ ".app-runner-output-controls .release-npm-action",
95
+ ".subagent-open-mode-field select",
96
+ ".subagent-launch-slots-summary",
97
+ ".subagent-tab-header",
98
+ ".git-side-panel-repository-toggle",
99
+ ".git-side-panel-tab",
100
+ ".git-side-panel-folder-summary",
101
+ ".git-side-panel-file",
102
+ "button.git-workflow-step",
103
+ ".git-workflow-message-input",
104
+ ]) {
105
+ assert.ok(coarseBlock.includes(selector), `${selector} should retain a coarse-pointer target floor`);
106
+ }
107
+ assert.match(coarseBlock, /min-height:\s*44px;/, "coarse-pointer compact controls should retain a 44px target floor");
108
+ const guidedGitTouchRule = css.indexOf("#gitWorkflowCancelButton { min-height: 44px; }");
109
+ assert.ok(guidedGitTouchRule > compactStart, "Guided Git action touch targets should override compact desktop sizing");
110
+
111
+ console.log("compact-sections-static.test.mjs passed");