@firstpick/pi-package-webui 0.7.7 → 0.7.9

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 (50) hide show
  1. package/README.md +23 -0
  2. package/bin/pi-webui-rpc-supervisor.mjs +115 -21
  3. package/bin/pi-webui.mjs +447 -88
  4. package/lib/queue-mutation.mjs +109 -0
  5. package/lib/rpc-supervisor-client.mjs +18 -2
  6. package/lib/rpc-supervisor-protocol.mjs +11 -2
  7. package/lib/scoped-models.mjs +19 -0
  8. package/lib/webui-workspaces.mjs +265 -0
  9. package/package.json +4 -4
  10. package/public/app.js +2227 -195
  11. package/public/index.html +143 -2
  12. package/public/issue-bot-client.mjs +344 -0
  13. package/public/issue-wizard-state.mjs +443 -0
  14. package/public/service-worker.js +3 -1
  15. package/public/styles.css +787 -56
  16. package/public/voice-conversation.mjs +1 -1
  17. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  18. package/tests/compaction-mutation-contract.test.mjs +166 -0
  19. package/tests/compaction-resume-harness.test.mjs +113 -2
  20. package/tests/compaction-static.test.mjs +5 -0
  21. package/tests/completion-signal-contract.test.mjs +156 -0
  22. package/tests/cwd-footer-reliability-static.test.mjs +112 -0
  23. package/tests/durable-rpc-supervisor-harness.test.mjs +25 -2
  24. package/tests/fast-mode-client-static.test.mjs +1 -1
  25. package/tests/file-selection-overlay-static.test.mjs +21 -0
  26. package/tests/file-viewer-search-static.test.mjs +65 -0
  27. package/tests/fixtures/compacting-pi.mjs +0 -0
  28. package/tests/fixtures/fake-pi.mjs +186 -49
  29. package/tests/footer-context-contrast-static.test.mjs +10 -0
  30. package/tests/git-panel-file-preview-static.test.mjs +20 -5
  31. package/tests/git-panel-render-stability-static.test.mjs +11 -1
  32. package/tests/http-endpoints-harness.test.mjs +160 -1
  33. package/tests/issue-bot-client.test.mjs +135 -0
  34. package/tests/issue-wizard-state.test.mjs +126 -0
  35. package/tests/mobile-static.test.mjs +61 -42
  36. package/tests/native-parity.test.mjs +3 -3
  37. package/tests/open-issue-wizard-static.test.mjs +75 -0
  38. package/tests/prompt-routing-tab-status.test.mjs +5 -0
  39. package/tests/queue-edit-reorder-static.test.mjs +101 -0
  40. package/tests/queue-mutation-contract.test.mjs +143 -0
  41. package/tests/rpc-supervisor-host.test.mjs +135 -2
  42. package/tests/rpc-supervisor-protocol.test.mjs +26 -0
  43. package/tests/scoped-models.test.mjs +42 -0
  44. package/tests/streaming-ui-coupling.test.mjs +3 -2
  45. package/tests/subagents-helper.test.mjs +216 -3
  46. package/tests/terminal-tab-workspace-static.test.mjs +101 -0
  47. package/tests/webui-workspaces-harness.test.mjs +223 -0
  48. package/tests/webui-workspaces.test.mjs +106 -0
  49. package/tests/workspace-save-load-static.test.mjs +69 -0
  50. package/webui-rpc-helper.mjs +300 -41
@@ -0,0 +1,106 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
3
+ import { homedir, tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import {
6
+ WEBUI_WORKSPACE_LIMIT,
7
+ WEBUI_WORKSPACE_TAB_LIMIT,
8
+ deleteWebuiWorkspace,
9
+ getWebuiWorkspace,
10
+ listWebuiWorkspaces,
11
+ normalizeWebuiWorkspaces,
12
+ readWebuiWorkspaces,
13
+ saveWebuiWorkspace,
14
+ webuiWorkspacesFile,
15
+ } from "../lib/webui-workspaces.mjs";
16
+
17
+ function tab(id, cwd, index = 1) {
18
+ return {
19
+ id,
20
+ index,
21
+ title: `Tab ${index}`,
22
+ titleSource: "explicit",
23
+ conversationStarted: index % 2 === 0,
24
+ cwd,
25
+ sessionFile: path.join(cwd, `${id}.jsonl`),
26
+ };
27
+ }
28
+
29
+ const root = await mkdtemp(path.join(tmpdir(), "pi-webui-workspaces-"));
30
+ const storageFile = path.join(root, "nested", "workspaces.json");
31
+ const concurrentFile = path.join(root, "concurrent.json");
32
+
33
+ try {
34
+ assert.equal(webuiWorkspacesFile({ PI_WEBUI_WORKSPACES_FILE: "~/workspace-file.json" }), path.resolve(homedir(), "workspace-file.json"));
35
+ assert.equal(webuiWorkspacesFile({ XDG_CONFIG_HOME: path.join(root, "xdg") }), path.join(root, "xdg", "pi-webui", "workspaces.json"));
36
+
37
+ const oversizedTabs = Array.from({ length: WEBUI_WORKSPACE_TAB_LIMIT + 3 }, (_, index) => tab(`tab-${index}`, root, index + 1));
38
+ const normalized = normalizeWebuiWorkspaces({
39
+ version: 1,
40
+ workspaces: [{
41
+ id: "ws-normalized",
42
+ name: ` ${"n".repeat(200)} `,
43
+ savedAt: new Date().toISOString(),
44
+ activeTabId: "tab-0",
45
+ tabs: oversizedTabs,
46
+ groups: [{ title: " Group ", tabIds: ["tab-0", "tab-0", "unknown"] }],
47
+ }],
48
+ });
49
+ assert.equal(normalized.version, 1);
50
+ assert.equal(normalized.workspaces[0].name.length, 160, "workspace names must be bounded");
51
+ assert.equal(normalized.workspaces[0].tabs.length, WEBUI_WORKSPACE_TAB_LIMIT, "workspace tabs must be bounded");
52
+ assert.deepEqual(normalized.workspaces[0].groups, [{ title: "Group", tabIds: ["tab-0"] }], "groups must only retain unique saved tab ids");
53
+
54
+ await mkdir(path.dirname(storageFile), { recursive: true });
55
+ await writeFile(storageFile, "{ malformed", "utf8");
56
+ const warnings = [];
57
+ assert.deepEqual(await readWebuiWorkspaces(storageFile, { onWarning: (message) => warnings.push(message) }), { version: 1, workspaces: [] });
58
+ assert.equal(warnings.length, 1, "malformed persisted files must fail soft with one warning");
59
+ assert.match(warnings[0], /treating it as empty/i);
60
+
61
+ for (let index = 0; index <= WEBUI_WORKSPACE_LIMIT; index += 1) {
62
+ await saveWebuiWorkspace({ name: `workspace-${index}`, tabs: [tab(`saved-${index}`, root)] }, storageFile);
63
+ }
64
+ const afterEviction = await listWebuiWorkspaces(storageFile);
65
+ assert.equal(afterEviction.length, WEBUI_WORKSPACE_LIMIT, "oldest workspace must be evicted at the configured bound");
66
+ assert.equal(afterEviction.some((workspace) => workspace.name === "workspace-0"), false);
67
+ assert.ok(afterEviction.some((workspace) => workspace.name === `workspace-${WEBUI_WORKSPACE_LIMIT}`));
68
+
69
+ const overwriteTarget = afterEviction.find((workspace) => workspace.name === "workspace-1");
70
+ await assert.rejects(
71
+ saveWebuiWorkspace({ name: "workspace-1", tabs: [tab("replacement", root)] }, storageFile),
72
+ (error) => error?.code === "WORKSPACE_NAME_CONFLICT",
73
+ "duplicate names must require explicit overwrite",
74
+ );
75
+ const overwritten = await saveWebuiWorkspace({
76
+ name: "workspace-1",
77
+ overwrite: true,
78
+ activeTabId: "replacement",
79
+ groups: [{ title: "Replacement", tabIds: ["replacement"] }],
80
+ tabs: [tab("replacement", root)],
81
+ }, storageFile);
82
+ assert.equal(overwritten.workspace.id, overwriteTarget.id, "overwrite must preserve the saved workspace identity");
83
+ const stored = await getWebuiWorkspace(overwritten.workspace.id, storageFile);
84
+ assert.equal(stored.activeTabId, "replacement");
85
+ assert.deepEqual(stored.groups, [{ title: "Replacement", tabIds: ["replacement"] }]);
86
+
87
+ const deleted = await deleteWebuiWorkspace(overwritten.workspace.id, storageFile);
88
+ assert.equal(deleted.deletedId, overwritten.workspace.id);
89
+ assert.equal(await getWebuiWorkspace(overwritten.workspace.id, storageFile), null);
90
+ if (process.platform !== "win32") assert.equal((await stat(storageFile)).mode & 0o777, 0o600, "atomic writes must be owner-only");
91
+ assert.equal((await readWebuiWorkspaces(storageFile)).version, 1, "atomic writes must leave valid JSON behind");
92
+
93
+ await Promise.all(Array.from({ length: 8 }, (_, index) => saveWebuiWorkspace({
94
+ name: `concurrent-${index}`,
95
+ tabs: [tab(`concurrent-tab-${index}`, root)],
96
+ }, concurrentFile)));
97
+ const concurrent = await listWebuiWorkspaces(concurrentFile);
98
+ assert.equal(concurrent.length, 8, "serialized writes must retain every concurrent save");
99
+ assert.deepEqual(new Set(concurrent.map((workspace) => workspace.name)), new Set(Array.from({ length: 8 }, (_, index) => `concurrent-${index}`)));
100
+ const concurrentDocument = JSON.parse(await readFile(concurrentFile, "utf8"));
101
+ assert.equal(concurrentDocument.version, 1, "serialized atomic writes must not leave partial JSON");
102
+
103
+ console.log("webui-workspaces.test.mjs passed");
104
+ } finally {
105
+ await rm(root, { recursive: true, force: true });
106
+ }
@@ -0,0 +1,69 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
7
+ const read = (relativePath) => readFile(path.join(root, relativePath), "utf8");
8
+ const [html, app, css] = await Promise.all([
9
+ read("public/index.html"),
10
+ read("public/app.js"),
11
+ read("public/styles.css"),
12
+ ]);
13
+
14
+ const actionStart = html.indexOf('<div class="terminal-sidebar-actions"');
15
+ const actionEnd = html.indexOf("</div>", actionStart);
16
+ const saveButton = html.indexOf('id="workspaceSaveButton"', actionStart);
17
+ assert.ok(actionStart >= 0 && saveButton > actionStart && saveButton < actionEnd, "Save workspace must be a header action");
18
+ assert.match(html, /workspaceSaveButton[\s\S]*?aria-label="Save workspace"/, "Save workspace must be labelled");
19
+ assert.match(app, /applyStyledTooltip\(elements\.workspaceSaveButton,[\s\S]*?floating: false/, "Save workspace must keep only its dedicated styled tooltip instead of also binding the shared floating tooltip");
20
+
21
+ assert.match(app, /function saveWebuiWorkspace[\s\S]*?api\("\/api\/workspaces", \{ method: "POST", body, scoped: false \}\)/, "Save must use an unscoped workspace API call");
22
+ assert.match(app, /function refreshSavedWorkspaces[\s\S]*?api\("\/api\/workspaces", \{ scoped: false \}\)/, "Workspace list must use an unscoped API call");
23
+ assert.match(app, /function deleteWebuiWorkspace[\s\S]*?method: "DELETE", scoped: false/, "Delete must use an unscoped API call");
24
+ assert.match(app, /function saveWebuiWorkspace[\s\S]*?appConfirm\(\{[\s\S]*?confirmLabel: "Overwrite"/, "Duplicate saves must use the existing confirmation modal");
25
+
26
+ const loadStart = app.indexOf("async function loadWebuiWorkspace");
27
+ const loadEnd = app.indexOf("async function deleteWebuiWorkspace", loadStart);
28
+ const loadFlow = app.slice(loadStart, loadEnd);
29
+ assert.ok(loadStart >= 0 && loadEnd > loadStart, "Load flow must be defined before delete flow");
30
+ assert.match(loadFlow, /\/api\/workspaces\/\$\{encodeURIComponent\(workspaceId\)\}\/load/, "Load must call the workspace load endpoint");
31
+ assert.match(loadFlow, /scoped: false/, "Load must be unscoped");
32
+ assert.ok(loadFlow.indexOf("await refreshTabs();") < loadFlow.indexOf("installLoadedWorkspaceGroups"), "Tabs must refresh before restored groups are installed");
33
+ assert.match(loadFlow, /await hydrateLoadedWorkspaceActiveTab\(data\.activeTabId\)/, "Load must hydrate the restored active tab even when refreshTabs selected it already");
34
+ assert.match(loadFlow, /settleUndoToast\(/, "Load must show a bounded restore summary");
35
+ assert.match(loadFlow, /addEvent\(/, "Load must record restore warnings/events");
36
+
37
+ assert.match(app, /function hydrateLoadedWorkspaceActiveTab[\s\S]*?connectEvents\(tabContext\);[\s\S]*?await refreshAll\(tabContext\)/, "A restored tab already selected by refreshTabs must still connect events and hydrate session state");
38
+ assert.match(app, /function installLoadedWorkspaceGroups[\s\S]*?terminalCustomGroups = new Map\(\);[\s\S]*?nextTerminalCustomGroupId\(\)[\s\S]*?persistTerminalCustomGroups\(\)/, "Restored groups must replace stale groups, use local ids, and persist");
39
+ assert.match(app, /const TERMINAL_CUSTOM_GROUPS_STORAGE_KEY = "pi-webui-terminal-custom-groups-v1"/, "The existing custom-group storage key must remain unchanged");
40
+ assert.match(app, /const savedWorkspacePanel = !tabs\.length \? renderSavedWorkspacePicker\(\) : null/, "The saved-workspace picker must be dashboard-only at zero tabs");
41
+ assert.match(app, /label: "Workspace: Save"/, "The command palette must offer workspace save when tabs exist");
42
+ assert.match(app, /label: "Workspace: Load…"/, "The command palette must offer workspace load when no tabs exist");
43
+ assert.match(app, /function closeAllTerminalTabs[\s\S]*?allowEmpty: true/, "Close all must permit the planned zero-tab workspace-load state");
44
+ assert.match(app, /function closeTerminalTabs[\s\S]*?if \(!tabs\.length\) setWorkspaceDashboardCollapsed\(false, \{ persist: false \}\)/, "Closing all tabs must reveal the workspace picker dashboard");
45
+ assert.match(app, /function initializeTabs[\s\S]*?if \(!saved\.length\) await createFirstTerminalTabFromChosenDirectory\(\)/, "Fresh installs without saved workspaces must retain the first-terminal cwd prompt");
46
+
47
+ const emptyStart = app.slice(app.indexOf("function renderEmptyStartState"), app.indexOf("function userPromptTargets"));
48
+ assert.match(emptyStart, /title: "Load workspace"[\s\S]*?description: "Restore a saved tab constellation"[\s\S]*?openWorkspaceLoadPicker/, "The empty-start card must offer a labelled saved-workspace picker action");
49
+ assert.match(html, /id="workspaceLoadDialog"[\s\S]*?aria-labelledby="workspaceLoadDialogTitle"/, "The saved-workspace picker must use a labelled dialog");
50
+ assert.match(html, /id="workspaceReplaceDialog"[\s\S]*?workspaceReplaceCurrentTabsList[\s\S]*?workspaceReplaceSaveName[\s\S]*?Load without saving[\s\S]*?Save &amp; load/, "The replacement dialog must expose current tabs, a save name, and explicit discard/save choices");
51
+ assert.match(app, /function renderWorkspaceLoadDialog[\s\S]*?Loading saved workspaces…[\s\S]*?workspace-load-dialog-retry[\s\S]*?No saved workspaces yet[\s\S]*?loadWebuiWorkspace[\s\S]*?workspace-load-dialog-item-delete danger[\s\S]*?deleteWebuiWorkspace[\s\S]*?workspaceLoadDialogCloseButton\?\.focus/, "The dialog picker must render loading, retry/error, empty, load, and destructive delete states while preserving focus after deletion");
52
+ assert.match(app, /const result = await loadWebuiWorkspace[\s\S]*?result === "cancelled"[\s\S]*?openWorkspaceLoadPicker[\s\S]*?result === "error"[\s\S]*?focusReturn\.focus/, "Cancelled and failed picker loads must restore a usable keyboard destination");
53
+ assert.match(app, /function workspaceReplacementTabRow[\s\S]*?tabIndicator\(tab\)[\s\S]*?tab\.id === activeTabId[\s\S]*?normalizeDisplayPath\(tab\.cwd/, "The replacement dialog must identify each current tab's activity, active state, and cwd");
54
+ assert.match(app, /function workspaceSaveCurrentDecision[\s\S]*?replaceOpenTabs: true[\s\S]*?groups: workspaceGroupsForSave\(\)[\s\S]*?activeTabId/, "Save-and-load must send only UI-owned group and active-tab metadata");
55
+ assert.match(app, /workspaceReplaceDiscardButton[\s\S]*?replaceOpenTabs: true, discardCurrent: true/, "Discard-and-load must require its own explicit dialog action");
56
+ assert.match(loadFlow, /const decision = await chooseWorkspaceReplacement[\s\S]*?Object\.keys\(decision\)\.length[\s\S]*?body: decision/, "Open-tab loading must send the WS1 decision body while zero-tab loading keeps an empty body");
57
+ assert.match(loadFlow, /workspace with that name already exists[\s\S]*?confirmLabel: "Overwrite & load"[\s\S]*?overwrite: true/, "Duplicate save-and-load names must confirm overwrite before retrying");
58
+ assert.match(loadFlow, /data\.closedIds[\s\S]*?retireClosedWorkspaceTabContexts\(closedIds\)[\s\S]*?data\.savedCurrent\?\.workspaces/, "The client must reconcile closed tabs and optional saved-current workspace metadata");
59
+ assert.match(app, /function retireClosedWorkspaceTabContexts[\s\S]*?tabDrafts\.delete[\s\S]*?clearAttachments[\s\S]*?fileViewersByTab\.delete[\s\S]*?removeSubagentTerminalViewsForParent/, "Workspace replacement must retire per-tab client state along with closed tabs");
60
+
61
+ assert.match(css, /body\.terminal-tabs-left \.terminal-sidebar-actions \{[\s\S]*?grid-template-columns: repeat\(4, minmax\(0, 1fr\)\)/, "The left tab layout must provide four action slots");
62
+ assert.match(css, /\.workspace-saved-workspaces/, "Saved-workspace picker styles must be scoped");
63
+ assert.match(css, /\.workspace-load-dialog,[\s\S]*?\.workspace-replace-dialog/, "Workspace loading and replacement dialogs must have scoped styles");
64
+ assert.match(css, /\.workspace-replace-current-tabs-list[\s\S]*?max-height:[\s\S]*?overflow: auto/, "The replacement tab disclosure must remain bounded and scrollable");
65
+ assert.match(css, /\.workspace-load-dialog-item-actions button \{ flex: 1 1 7rem; min-height: 44px; \}/, "Picker load and delete actions must remain touch-friendly on narrow layouts");
66
+ assert.match(css, /\.workspace-replace-dialog menu button \{ flex: 1 1 9rem; min-height: 44px; \}/, "Replacement decisions must remain touch-friendly on narrow layouts");
67
+ assert.match(css, /@media \(max-width: 720px\)[\s\S]*?\.workspace-saved-workspace-actions button \{ flex: 1 1 7rem; min-height: 44px; \}/, "Saved-workspace actions must stay touch-friendly on narrow layouts");
68
+
69
+ console.log("workspace-save-load-static.test.mjs passed");