@firstpick/pi-package-webui 0.8.6 → 0.8.8

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 (90) hide show
  1. package/README.md +18 -606
  2. package/bin/pi-webui-launcher.mjs +22 -0
  3. package/bin/pi-webui-update-supervisor.mjs +86 -0
  4. package/bin/pi-webui.mjs +562 -524
  5. package/index.ts +8 -5
  6. package/lib/component-update-state.mjs +21 -0
  7. package/lib/git-workflow-preferences.mjs +17 -2
  8. package/lib/optional-feature-catalog.mjs +1 -0
  9. package/lib/sampling-parameter-capabilities.mjs +160 -0
  10. package/lib/session-summary-preferences.mjs +16 -1
  11. package/lib/subagent-launch-slots.mjs +14 -2
  12. package/lib/trust-boundaries.mjs +3 -0
  13. package/lib/update/executor.mjs +99 -0
  14. package/lib/update/journal.mjs +175 -0
  15. package/lib/update/owners.mjs +70 -0
  16. package/lib/update/plan.mjs +134 -0
  17. package/lib/update/resolver.mjs +168 -0
  18. package/lib/update/supervisor.mjs +238 -0
  19. package/lib/update/verify.mjs +52 -0
  20. package/lib/update-commands.mjs +25 -13
  21. package/lib/webui-workspaces.mjs +17 -1
  22. package/package.json +4 -4
  23. package/public/app.js +1543 -109
  24. package/public/index.html +146 -48
  25. package/public/middle-button-drag-scroll.mjs +154 -0
  26. package/public/sampling-parameter-controls.mjs +361 -0
  27. package/public/service-worker.js +3 -1
  28. package/public/styles.css +512 -1
  29. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  30. package/tests/browser/control-deck-component-updates.spec.mjs +20 -22
  31. package/tests/browser/middle-button-drag-scroll.spec.mjs +145 -0
  32. package/tests/browser/persistent-ui-layout.spec.mjs +68 -23
  33. package/tests/browser/sampling-tooltip.spec.mjs +228 -0
  34. package/tests/browser/update-reconnect.spec.mjs +92 -0
  35. package/tests/codex-fast-mode-static.test.mjs +2 -2
  36. package/tests/common-options-submenus-interaction-static.test.mjs +172 -0
  37. package/tests/common-options-submenus-markup-static.test.mjs +152 -0
  38. package/tests/component-update-api-static.test.mjs +22 -61
  39. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  40. package/tests/control-deck-component-updates-static.test.mjs +13 -237
  41. package/tests/durable-rpc-supervisor-harness.test.mjs +3 -1
  42. package/tests/fast-mode-client-static.test.mjs +1 -1
  43. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  44. package/tests/feature-system-prompt-optional-feature-static.test.mjs +49 -0
  45. package/tests/fixtures/fake-pi.mjs +68 -1
  46. package/tests/fixtures/update/tree-timeout-descendant.mjs +6 -0
  47. package/tests/fixtures/update/tree-timeout-parent.mjs +11 -0
  48. package/tests/git-footer-context-menu-static.test.mjs +58 -0
  49. package/tests/http-endpoints-harness.test.mjs +68 -18
  50. package/tests/middle-button-drag-scroll-static.test.mjs +24 -0
  51. package/tests/middle-button-drag-scroll.test.mjs +170 -0
  52. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  53. package/tests/mobile-foundation-static.test.mjs +4 -4
  54. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  55. package/tests/mobile-static.test.mjs +217 -24
  56. package/tests/open-issue-wizard-static.test.mjs +1 -1
  57. package/tests/optional-feature-migration-frontend.test.mjs +13 -5
  58. package/tests/persistent-ui-layout-static.test.mjs +13 -2
  59. package/tests/prompt-routing-tab-status.test.mjs +8 -0
  60. package/tests/questionnaire-dialog.test.mjs +3 -3
  61. package/tests/remote-auth-settings-harness.test.mjs +34 -0
  62. package/tests/rpc-supervisor-host.test.mjs +11 -2
  63. package/tests/safety-guard-auto-review-harness.test.mjs +117 -0
  64. package/tests/safety-guard-auto-review-static.test.mjs +34 -0
  65. package/tests/sampling-native-controls-user-flow.test.mjs +752 -0
  66. package/tests/sampling-parameter-capabilities.test.mjs +167 -0
  67. package/tests/sampling-parameter-controls.test.mjs +241 -0
  68. package/tests/session-sampling-helper.test.mjs +228 -0
  69. package/tests/session-sampling-http.test.mjs +168 -0
  70. package/tests/session-sampling-ui-static.test.mjs +370 -0
  71. package/tests/session-summary-core.test.mjs +24 -11
  72. package/tests/side-panel-section-height-removal-static.test.mjs +34 -0
  73. package/tests/side-panel-section-reorder-static.test.mjs +3 -3
  74. package/tests/staged-content-hash-contract.test.mjs +52 -11
  75. package/tests/subagent-launch-slots.test.mjs +18 -1
  76. package/tests/theme-customizer-static.test.mjs +1 -1
  77. package/tests/ui-layout-settings.test.mjs +18 -1
  78. package/tests/update-api-harness.test.mjs +111 -0
  79. package/tests/update-commands.test.mjs +15 -45
  80. package/tests/update-executor-process-tree-harness.test.mjs +22 -0
  81. package/tests/update-journal-harness.test.mjs +59 -0
  82. package/tests/update-lock-multiprocess-harness.test.mjs +46 -0
  83. package/tests/update-owners.test.mjs +27 -0
  84. package/tests/update-plan.test.mjs +58 -0
  85. package/tests/update-resolver.test.mjs +56 -0
  86. package/tests/update-supervisor-harness.test.mjs +57 -0
  87. package/tests/update-tab-restore-harness.test.mjs +24 -0
  88. package/tests/update-verify.test.mjs +31 -0
  89. package/tests/workspace-files-live-updates-static.test.mjs +13 -4
  90. package/webui-rpc-helper.mjs +119 -0
@@ -0,0 +1,117 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawn } from "node:child_process";
3
+ import { chmod, mkdtemp, readFile, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import path, { dirname, join } from "node:path";
6
+ import { setTimeout as delay } from "node:timers/promises";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
10
+ const serverScript = join(root, "bin", "pi-webui.mjs");
11
+ const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
12
+ const port = 30000 + Math.floor(Math.random() * 20000);
13
+ const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-safety-guard-auto-review-"));
14
+ const safetyGuardSettingsFile = path.join(cwd, "safety-guard.json");
15
+
16
+ async function request(pathname, { method = "GET", body, timeoutMs = 5_000 } = {}) {
17
+ const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
18
+ method,
19
+ headers: body === undefined ? undefined : { "Content-Type": "application/json" },
20
+ body: body === undefined ? undefined : JSON.stringify(body),
21
+ signal: AbortSignal.timeout(timeoutMs),
22
+ });
23
+ return { status: response.status, body: await response.json().catch(() => undefined) };
24
+ }
25
+
26
+ async function removeWithRetry(target) {
27
+ let lastError;
28
+ for (let attempt = 0; attempt < 20; attempt += 1) {
29
+ try {
30
+ await rm(target, { recursive: true, force: true });
31
+ return;
32
+ } catch (error) {
33
+ lastError = error;
34
+ if (!["EBUSY", "EPERM", "ENOTEMPTY"].includes(error?.code)) throw error;
35
+ await delay(100 + attempt * 50);
36
+ }
37
+ }
38
+ throw lastError;
39
+ }
40
+
41
+ await chmod(fakePi, 0o755);
42
+ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
43
+ stdio: ["ignore", "pipe", "pipe"],
44
+ env: { ...process.env, PI_SAFETY_GUARD_CONFIG_FILE: safetyGuardSettingsFile, PI_WEBUI_RPC_SUPERVISOR: "0" },
45
+ });
46
+ let serverOutput = "";
47
+ child.stdout.on("data", (chunk) => { serverOutput += String(chunk); });
48
+ child.stderr.on("data", (chunk) => { serverOutput += String(chunk); });
49
+
50
+ try {
51
+ let health;
52
+ for (let attempt = 0; attempt < 100; attempt += 1) {
53
+ if (child.exitCode !== null) break;
54
+ try {
55
+ health = await request("/api/health", { timeoutMs: 1_000 });
56
+ if (health.status === 200) break;
57
+ } catch {
58
+ // Server not listening yet.
59
+ }
60
+ await delay(200);
61
+ }
62
+ assert.equal(health?.status, 200, `server should become healthy, output:\n${serverOutput}`);
63
+
64
+ const initial = await request("/api/safety-guard/config");
65
+ assert.equal(initial.status, 200);
66
+ assert.deepEqual(initial.body?.data?.config?.autoReview, {
67
+ enabled: false,
68
+ model: { provider: "", modelId: "", thinkingLevel: "off" },
69
+ });
70
+ assert.equal(initial.body?.data?.models?.[0]?.provider, "fake");
71
+ assert.equal(initial.body?.data?.models?.[0]?.id, "fake-model");
72
+ assert.deepEqual(initial.body?.data?.modelThinkingLevels, { "fake/fake-model": ["off"] });
73
+
74
+ const unavailable = await request("/api/safety-guard/config", {
75
+ method: "POST",
76
+ body: { config: { autoReview: { enabled: true, model: { provider: "fake", modelId: "missing-model", thinkingLevel: "off" } } } },
77
+ });
78
+ assert.equal(unavailable.status, 400);
79
+ assert.match(unavailable.body?.error || "", /not currently available/);
80
+
81
+ const unsupported = await request("/api/safety-guard/config", {
82
+ method: "POST",
83
+ body: { config: { autoReview: { enabled: true, model: { provider: "fake", modelId: "fake-model", thinkingLevel: "low" } } } },
84
+ });
85
+ assert.equal(unsupported.status, 400);
86
+ assert.match(unsupported.body?.error || "", /does not support thinking level low/);
87
+
88
+ const enabled = await request("/api/safety-guard/config", {
89
+ method: "POST",
90
+ body: { config: { autoReview: { enabled: true, model: { provider: "fake", modelId: "fake-model", thinkingLevel: "off" } } } },
91
+ });
92
+ assert.equal(enabled.status, 200);
93
+ assert.equal(enabled.body?.data?.config?.autoReview?.enabled, true);
94
+
95
+ const disabledWithRetainedSelection = await request("/api/safety-guard/config", {
96
+ method: "POST",
97
+ body: { config: { autoReview: { enabled: false, model: { provider: "fake", modelId: "missing-model", thinkingLevel: "low" } } } },
98
+ });
99
+ assert.equal(disabledWithRetainedSelection.status, 200, "disabled auto-review should tolerate retained selections without runtime validation");
100
+ assert.deepEqual(disabledWithRetainedSelection.body?.data?.config?.autoReview, {
101
+ enabled: false,
102
+ model: { provider: "fake", modelId: "missing-model", thinkingLevel: "low" },
103
+ });
104
+
105
+ const persisted = JSON.parse(await readFile(safetyGuardSettingsFile, "utf8"));
106
+ assert.deepEqual(persisted.autoReview, disabledWithRetainedSelection.body.data.config.autoReview);
107
+ console.log("safety-guard-auto-review-harness.test.mjs passed");
108
+ } finally {
109
+ const exited = new Promise((resolve) => child.once("exit", resolve));
110
+ child.kill("SIGTERM");
111
+ await Promise.race([exited, delay(2_000)]);
112
+ if (child.exitCode === null) {
113
+ child.kill("SIGKILL");
114
+ await Promise.race([exited, delay(2_000)]);
115
+ }
116
+ await removeWithRetry(cwd);
117
+ }
@@ -0,0 +1,34 @@
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 [app, server] = await Promise.all([
8
+ readFile(join(root, "public", "app.js"), "utf8"),
9
+ readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
10
+ ]);
11
+
12
+ const dialog = app.match(/async function openNativeSafetyGuardSetupDialog\(\) \{[\s\S]*?\n\}\n\nfunction gitWorkflowSetupModelKey/)?.[0] || "";
13
+ assert.ok(dialog, "Safety Guard Setup dialog should remain extractable");
14
+ assert.match(dialog, /nativeSettingToggle\("Automatic model review"[\s\S]*config\.autoReview\?\.enabled === true/, "dialog should apply the canonical disabled-by-default auto-review toggle");
15
+ assert.match(dialog, /nativeSettingSelect\("Review model"[\s\S]*nativeSettingSelect\("Review thinking"/, "dialog should expose model and thinking selectors");
16
+ assert.match(dialog, /data\.modelThinkingLevels\?\.\[selectedModelKey\]/, "thinking options should come from the server's per-model support map");
17
+ assert.match(dialog, /controls\.autoReviewModel\.select\.disabled = !models\.length[\s\S]*controls\.autoReviewThinking\.select\.disabled = !selectedAvailable/, "model and thinking selectors should remain configurable before auto-review is enabled");
18
+ assert.match(dialog, /model and thinking can still be preselected before enabling auto-review/, "disabled auto-review state should explain that model setup remains available");
19
+ assert.match(dialog, /Unavailable: no authenticated Pi models are available[\s\S]*Unavailable: select one of the authenticated models from this active tab/, "dialog should explain model-unavailable states");
20
+ assert.match(dialog, /const collectConfig = \(\) =>[\s\S]*autoReview: \{[\s\S]*enabled: controls\.autoReview\.input\.checked[\s\S]*provider:[\s\S]*modelId:[\s\S]*thinkingLevel:/, "collection should persist the canonical nested autoReview shape");
21
+ assert.match(dialog, /const applyConfig = \(value\) =>[\s\S]*controls\.autoReview\.input\.checked = value\?\.autoReview\?\.enabled === true[\s\S]*syncAutoReviewControls/, "application and reset should restore auto-review controls and availability state");
22
+ assert.match(dialog, /addNativeCommandAction\("Reset defaults"[\s\S]*applyConfig\(defaults\)/, "reset should apply canonical defaults");
23
+ assert.match(dialog, /submitted\.autoReview\.enabled && !models\.some[\s\S]*submitted\.autoReview\.enabled && !supportedLevels\.includes[\s\S]*body: \{ config: submitted \}/, "save should reject unavailable browser selections before posting the nested config");
24
+
25
+ const api = server.match(/function safetyGuardModelKey\(model\)[\s\S]*?\n\}\n\nfunction requireSubagentLaunchSlotScope/)?.[0] || "";
26
+ assert.ok(api, "Safety Guard config API helpers should remain extractable");
27
+ assert.match(api, /availableGitWorkflowModels\(tab\)/, "GET payload should discover authenticated models through the active tab convention");
28
+ assert.match(api, /modelThinkingLevels: Object\.fromEntries[\s\S]*supportedGitWorkflowThinkingLevels\(model\)/, "GET payload should reuse the existing supported-thinking convention");
29
+ assert.match(api, /mergeSafetyGuardConfig\(settingsModule\.readSafetyGuardConfig\(\), submitted\)/, "POST validation should inspect the merged canonical config");
30
+ assert.match(api, /if \(next\.autoReview\.enabled\)[\s\S]*Selected auto-review model is not currently available[\s\S]*does not support thinking level/, "POST should validate availability and thinking support only when auto-review is enabled");
31
+ assert.match(server, /url\.pathname === "\/api\/safety-guard\/config" && req\.method === "GET"[\s\S]*const tab = getRequestedTab\(req, url\)[\s\S]*safetyGuardConfigData\(tab\)/, "GET route should pass the requested active tab into model discovery");
32
+ assert.match(server, /url\.pathname === "\/api\/safety-guard\/config" && req\.method === "POST"[\s\S]*saveSafetyGuardConfigData\(tab, body\)/, "POST route should validate against the requested active tab");
33
+
34
+ console.log("safety-guard-auto-review-static.test.mjs passed");