@firstpick/pi-package-webui 0.8.0 → 0.8.2

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 (63) hide show
  1. package/README.md +34 -5
  2. package/bin/pi-webui.mjs +606 -102
  3. package/lib/component-update-state.mjs +126 -0
  4. package/lib/npm-command.mjs +81 -0
  5. package/lib/queue-mutation.mjs +6 -0
  6. package/lib/trust-boundaries.mjs +1 -0
  7. package/lib/workspace-files-live-watcher.mjs +138 -0
  8. package/package.json +8 -3
  9. package/public/app.js +4231 -376
  10. package/public/index.html +265 -52
  11. package/public/mobile-shell-state.mjs +166 -0
  12. package/public/service-worker.js +60 -13
  13. package/public/styles.css +1790 -383
  14. package/public/subagent-gate-visibility.mjs +16 -0
  15. package/public/subagent-launch-slot-state.mjs +16 -0
  16. package/public/transcript-renderer.mjs +433 -0
  17. package/tests/boot-failure-diagnostics.test.mjs +63 -5
  18. package/tests/browser/control-deck-component-updates.spec.mjs +180 -0
  19. package/tests/browser/interaction-continuity.spec.mjs +897 -0
  20. package/tests/browser/mobile-foundation.spec.mjs +363 -0
  21. package/tests/browser/optimistic-prompt.spec.mjs +130 -0
  22. package/tests/browser/side-panel-section-reorder.spec.mjs +101 -0
  23. package/tests/browser/stats-overlay.spec.mjs +265 -0
  24. package/tests/chat-scroll-intent-static.test.mjs +6 -1
  25. package/tests/codex-fast-mode-static.test.mjs +8 -5
  26. package/tests/compact-sections-static.test.mjs +20 -2
  27. package/tests/compaction-mutation-contract.test.mjs +18 -4
  28. package/tests/compaction-static.test.mjs +1 -0
  29. package/tests/completion-signal-contract.test.mjs +13 -2
  30. package/tests/component-update-api-static.test.mjs +67 -0
  31. package/tests/component-update-state.test.mjs +80 -0
  32. package/tests/control-deck-component-updates-static.test.mjs +251 -0
  33. package/tests/fast-mode-client-static.test.mjs +7 -4
  34. package/tests/fixtures/fake-pi.mjs +305 -2
  35. package/tests/footer-provider-usage-visual-static.test.mjs +71 -0
  36. package/tests/git-panel-gitignore-static.test.mjs +104 -0
  37. package/tests/http-endpoints-harness.test.mjs +228 -2
  38. package/tests/interaction-state-stability-static.test.mjs +271 -0
  39. package/tests/mobile-continuity-tablet-static.test.mjs +55 -0
  40. package/tests/mobile-foundation-static.test.mjs +71 -0
  41. package/tests/mobile-phone-experience-static.test.mjs +65 -0
  42. package/tests/mobile-shell-state.test.mjs +69 -0
  43. package/tests/mobile-static.test.mjs +246 -39
  44. package/tests/mobile-transcript-cache-characterization.test.mjs +34 -0
  45. package/tests/native-parity-harness.test.mjs +2 -0
  46. package/tests/npm-command.test.mjs +64 -1
  47. package/tests/open-issue-wizard-static.test.mjs +2 -1
  48. package/tests/queue-edit-reorder-static.test.mjs +9 -1
  49. package/tests/queue-mutation-contract.test.mjs +22 -0
  50. package/tests/service-worker-lifecycle.test.mjs +120 -0
  51. package/tests/side-panel-section-reorder-static.test.mjs +68 -0
  52. package/tests/sse-backpressure-harness.test.mjs +137 -0
  53. package/tests/stats-dashboard-static.test.mjs +266 -0
  54. package/tests/streaming-ui-coupling.test.mjs +7 -1
  55. package/tests/subagent-gate-visibility.test.mjs +18 -2
  56. package/tests/subagent-launch-slot-state.test.mjs +32 -0
  57. package/tests/subagent-launch-slots-static.test.mjs +8 -2
  58. package/tests/subagents-helper.test.mjs +90 -0
  59. package/tests/terminal-tab-workspace-static.test.mjs +1 -1
  60. package/tests/update-commands.test.mjs +4 -0
  61. package/tests/workspace-files-live-updates-static.test.mjs +76 -0
  62. package/tests/workspace-files-live-watcher.test.mjs +95 -0
  63. package/webui-rpc-helper.mjs +175 -3
@@ -0,0 +1,166 @@
1
+ // Pure, browser-independent state helpers for the opt-in Mobile Experience v2
2
+ // shell. Rendering remains in app.js until functional mobile destinations land.
3
+
4
+ export const MOBILE_SHELL_V2_DEFAULT = false;
5
+ export const TABLET_SHELL_V2_DEFAULT = false;
6
+ export const MOBILE_SHELL_STORAGE_KEY = "pi-webui-mobile-shell-v2";
7
+ export const TABLET_SHELL_STORAGE_KEY = "pi-webui-tablet-shell-v2";
8
+ export const MOBILE_ROUTES = new Set(["chat", "sessions", "activity", "project"]);
9
+ export const MOBILE_SURFACES = new Set(["none", "more", "actionSheet", "file", "dialog"]);
10
+ export const MOBILE_TARGET_VERSION = 1;
11
+
12
+ const OPAQUE_ID = /^[A-Za-z0-9_-]{8,128}$/;
13
+ const FEATURE_MODES = new Set(["legacy", "preview", "v2"]);
14
+
15
+ function safeString(value) {
16
+ return typeof value === "string" ? value : "";
17
+ }
18
+
19
+ function opaqueId(value) {
20
+ const normalized = safeString(value);
21
+ return OPAQUE_ID.test(normalized) ? normalized : null;
22
+ }
23
+
24
+ export function classifyMobileViewport({ width = 0, height = 0, coarsePointer = false, hover = true } = {}) {
25
+ const safeWidth = Number.isFinite(width) ? width : 0;
26
+ const safeHeight = Number.isFinite(height) ? height : 0;
27
+ const compactLandscapePhone = coarsePointer === true && hover === false && safeHeight <= 500 && safeWidth <= 950;
28
+ if (safeWidth <= 720 || compactLandscapePhone) {
29
+ return { viewportMode: "phone", posture: compactLandscapePhone ? "compactLandscapePhone" : "regular" };
30
+ }
31
+ if (safeWidth <= 1050) return { viewportMode: "tablet", posture: "regular" };
32
+ return { viewportMode: "desktop", posture: "regular" };
33
+ }
34
+
35
+ export function resolveMobileShellFeatureMode({ urlValue, storedValue, defaultEnabled = MOBILE_SHELL_V2_DEFAULT } = {}) {
36
+ if (urlValue === "legacy") return "legacy";
37
+ if (urlValue === "v2") return "v2";
38
+ if (storedValue === "legacy") return "legacy";
39
+ if (storedValue === "preview") return "preview";
40
+ return defaultEnabled === true ? "v2" : "legacy";
41
+ }
42
+
43
+ export function resolveTabletShellFeatureMode({ urlValue, storedValue, defaultEnabled = TABLET_SHELL_V2_DEFAULT } = {}) {
44
+ return resolveMobileShellFeatureMode({ urlValue, storedValue, defaultEnabled });
45
+ }
46
+
47
+ export function isMobileShellV2Enabled(featureMode, viewportMode, tabletFeatureMode = "legacy") {
48
+ if (viewportMode === "phone") return featureMode === "preview" || featureMode === "v2";
49
+ if (viewportMode === "tablet") return tabletFeatureMode === "preview" || tabletFeatureMode === "v2";
50
+ return false;
51
+ }
52
+
53
+ export function createMobileShellState({ viewport = {}, featureMode = "legacy", tabletFeatureMode = "legacy", route = "chat" } = {}) {
54
+ const { viewportMode, posture } = classifyMobileViewport(viewport);
55
+ return {
56
+ viewportMode,
57
+ posture,
58
+ featureMode: FEATURE_MODES.has(featureMode) ? featureMode : "legacy",
59
+ tabletFeatureMode: FEATURE_MODES.has(tabletFeatureMode) ? tabletFeatureMode : "legacy",
60
+ route: MOBILE_ROUTES.has(route) ? route : "chat",
61
+ surface: "none",
62
+ surfacePage: "root",
63
+ routeHistory: [],
64
+ };
65
+ }
66
+
67
+ function normalizedState(state) {
68
+ const next = state && typeof state === "object" ? state : {};
69
+ return {
70
+ viewportMode: ["phone", "tablet", "desktop"].includes(next.viewportMode) ? next.viewportMode : "desktop",
71
+ posture: ["regular", "compactLandscapePhone"].includes(next.posture) ? next.posture : "regular",
72
+ featureMode: FEATURE_MODES.has(next.featureMode) ? next.featureMode : "legacy",
73
+ tabletFeatureMode: FEATURE_MODES.has(next.tabletFeatureMode) ? next.tabletFeatureMode : "legacy",
74
+ route: MOBILE_ROUTES.has(next.route) ? next.route : "chat",
75
+ surface: MOBILE_SURFACES.has(next.surface) ? next.surface : "none",
76
+ surfacePage: safeString(next.surfacePage) || "root",
77
+ routeHistory: Array.isArray(next.routeHistory) ? next.routeHistory.filter((route) => MOBILE_ROUTES.has(route)).slice(-16) : [],
78
+ };
79
+ }
80
+
81
+ function closeSurface(state) {
82
+ return { ...state, surface: "none", surfacePage: "root" };
83
+ }
84
+
85
+ export function reduceMobileShellState(state, event = {}) {
86
+ const current = normalizedState(state);
87
+ switch (event.type) {
88
+ case "viewport": {
89
+ const viewport = classifyMobileViewport(event.viewport);
90
+ const next = { ...current, ...viewport };
91
+ if (!isMobileShellV2Enabled(next.featureMode, next.viewportMode, next.tabletFeatureMode)) return closeSurface(next);
92
+ return next;
93
+ }
94
+ case "feature": {
95
+ const next = { ...current, featureMode: FEATURE_MODES.has(event.featureMode) ? event.featureMode : "legacy" };
96
+ return isMobileShellV2Enabled(next.featureMode, next.viewportMode, next.tabletFeatureMode) ? next : closeSurface(next);
97
+ }
98
+ case "tablet-feature": {
99
+ const next = { ...current, tabletFeatureMode: FEATURE_MODES.has(event.featureMode) ? event.featureMode : "legacy" };
100
+ return isMobileShellV2Enabled(next.featureMode, next.viewportMode, next.tabletFeatureMode) ? next : closeSurface(next);
101
+ }
102
+ case "route": {
103
+ const route = MOBILE_ROUTES.has(event.route) ? event.route : current.route;
104
+ const routeHistory = event.replace === true || route === current.route
105
+ ? current.routeHistory
106
+ : [...current.routeHistory, current.route].slice(-16);
107
+ return { ...closeSurface(current), route, routeHistory };
108
+ }
109
+ case "surface": {
110
+ if (!MOBILE_SURFACES.has(event.surface) || event.surface === "none") return closeSurface(current);
111
+ return { ...current, surface: event.surface, surfacePage: event.page || "root" };
112
+ }
113
+ case "surface-page": {
114
+ if (current.surface === "none" || !safeString(event.page)) return current;
115
+ return { ...current, surfacePage: event.page };
116
+ }
117
+ case "back": {
118
+ if (current.surface === "dialog") return closeSurface(current);
119
+ if (current.surface !== "none" && current.surfacePage !== "root") return { ...current, surfacePage: "root" };
120
+ if (current.surface !== "none") return closeSurface(current);
121
+ const previousRoute = current.routeHistory.at(-1);
122
+ if (!previousRoute) return current;
123
+ return { ...current, route: previousRoute, routeHistory: current.routeHistory.slice(0, -1) };
124
+ }
125
+ default:
126
+ return current;
127
+ }
128
+ }
129
+
130
+ export function normalizeMobileNavigationTarget(value) {
131
+ const target = value && typeof value === "object" && !Array.isArray(value) ? value : {};
132
+ if (target.v !== MOBILE_TARGET_VERSION || !MOBILE_ROUTES.has(target.route)) return null;
133
+ const tabId = opaqueId(target.tabId);
134
+ const runId = opaqueId(target.runId);
135
+ const blockerId = opaqueId(target.blockerId);
136
+ if (!tabId && !runId && !blockerId) return null;
137
+ return {
138
+ v: MOBILE_TARGET_VERSION,
139
+ route: target.route,
140
+ ...(tabId ? { tabId } : {}),
141
+ ...(runId ? { runId } : {}),
142
+ ...(blockerId ? { blockerId } : {}),
143
+ };
144
+ }
145
+
146
+ export function mobileNavigationTargetFromSearch(search = "") {
147
+ const params = new URLSearchParams(search);
148
+ const target = {
149
+ v: MOBILE_TARGET_VERSION,
150
+ route: params.get("mobileRoute"),
151
+ tabId: params.get("tab"),
152
+ runId: params.get("run"),
153
+ blockerId: params.get("blocker"),
154
+ };
155
+ return normalizeMobileNavigationTarget(target);
156
+ }
157
+
158
+ export function mobileNavigationTargetSearch(target) {
159
+ const normalized = normalizeMobileNavigationTarget(target);
160
+ if (!normalized) return "";
161
+ const params = new URLSearchParams({ mobileRoute: normalized.route });
162
+ if (normalized.tabId) params.set("tab", normalized.tabId);
163
+ if (normalized.runId) params.set("run", normalized.runId);
164
+ if (normalized.blockerId) params.set("blocker", normalized.blockerId);
165
+ return params.toString();
166
+ }
@@ -1,4 +1,4 @@
1
- const CACHE_NAME = "pi-webui-pwa-v50";
1
+ const CACHE_NAME = "pi-webui-pwa-v62";
2
2
  const APP_SHELL = [
3
3
  "/",
4
4
  "/index.html",
@@ -6,10 +6,12 @@ const APP_SHELL = [
6
6
  "/app.js",
7
7
  "/issue-wizard-state.mjs",
8
8
  "/issue-bot-client.mjs",
9
+ "/mobile-shell-state.mjs",
9
10
  "/aur-review-payload.mjs",
10
11
  "/guided-git-command-state.mjs",
11
12
  "/guided-git-review-state.mjs",
12
13
  "/fast-output-live.mjs",
14
+ "/transcript-renderer.mjs",
13
15
  "/subagent-launch-slot-state.mjs",
14
16
  "/subagent-gate-visibility.mjs",
15
17
  "/workflow-status-stack.mjs",
@@ -35,13 +37,43 @@ self.addEventListener("activate", (event) => {
35
37
  );
36
38
  });
37
39
 
40
+ const OPAQUE_TARGET_ID = /^[A-Za-z0-9_-]{8,128}$/;
41
+ const MOBILE_NAVIGATION_MESSAGE_TYPE = "pi-webui:navigate:v1";
42
+
43
+ function notificationTarget(data) {
44
+ const target = data?.target;
45
+ if (!target || target.v !== 1 || !["chat", "sessions", "activity", "project"].includes(target.route)) return null;
46
+ const normalized = { v: 1, route: target.route };
47
+ for (const key of ["tabId", "runId", "blockerId"]) {
48
+ if (typeof target[key] === "string" && OPAQUE_TARGET_ID.test(target[key])) normalized[key] = target[key];
49
+ }
50
+ return Object.keys(normalized).length > 2 ? normalized : null;
51
+ }
52
+
53
+ function notificationTargetUrl(data) {
54
+ const target = notificationTarget(data);
55
+ if (!target) return `${self.location.origin}/`;
56
+ const url = new URL("/", self.location.origin);
57
+ url.searchParams.set("mobileRoute", target.route);
58
+ if (target.tabId) url.searchParams.set("tab", target.tabId);
59
+ if (target.runId) url.searchParams.set("run", target.runId);
60
+ if (target.blockerId) url.searchParams.set("blocker", target.blockerId);
61
+ return url.href;
62
+ }
63
+
38
64
  self.addEventListener("notificationclick", (event) => {
39
65
  event.notification.close();
40
- const targetUrl = event.notification.data?.url || `${self.location.origin}/`;
66
+ const target = notificationTarget(event.notification.data);
67
+ const targetUrl = notificationTargetUrl(event.notification.data);
41
68
  event.waitUntil(
42
69
  self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((clients) => {
43
70
  const webuiClient = clients.find((client) => client.url.startsWith(self.location.origin));
44
- if (webuiClient) return webuiClient.focus();
71
+ if (webuiClient) {
72
+ return webuiClient.focus().then((client) => {
73
+ if (target) client.postMessage({ type: MOBILE_NAVIGATION_MESSAGE_TYPE, target });
74
+ return client;
75
+ });
76
+ }
45
77
  return self.clients.openWindow?.(targetUrl);
46
78
  }),
47
79
  );
@@ -49,14 +81,29 @@ self.addEventListener("notificationclick", (event) => {
49
81
 
50
82
  // Network-first keeps the app shell fresh after deploys regardless of
51
83
  // CACHE_NAME or ?v= cache-buster drift; the cache only serves offline clients.
52
- function fetchThenCache(request) {
53
- return fetch(request).then((response) => {
54
- if (response.ok) {
55
- const copy = response.clone();
56
- caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
57
- }
58
- return response;
59
- });
84
+ // A bounded request prevents a stalled browser network service from blocking
85
+ // startup forever. Cache writes extend the event lifetime without delaying a
86
+ // usable network response, so a stalled CacheStorage service cannot block boot.
87
+ const APP_SHELL_NETWORK_TIMEOUT_MS = 8_000;
88
+
89
+ function fetchWithTimeout(request) {
90
+ const controller = new AbortController();
91
+ const timeout = setTimeout(() => controller.abort(), APP_SHELL_NETWORK_TIMEOUT_MS);
92
+ return fetch(request, { signal: controller.signal }).finally(() => clearTimeout(timeout));
93
+ }
94
+
95
+ function fetchThenCache(event) {
96
+ const { request } = event;
97
+ const networkResponse = fetchWithTimeout(request);
98
+ event.waitUntil(
99
+ networkResponse
100
+ .then((response) => {
101
+ if (!response.ok) return undefined;
102
+ return caches.open(CACHE_NAME).then((cache) => cache.put(request, response.clone()));
103
+ })
104
+ .catch(() => undefined),
105
+ );
106
+ return networkResponse;
60
107
  }
61
108
 
62
109
  // ignoreSearch lets precached bare paths satisfy ?v= cache-busted requests offline.
@@ -75,10 +122,10 @@ self.addEventListener("fetch", (event) => {
75
122
  if (url.origin !== self.location.origin || url.pathname.startsWith("/api/")) return;
76
123
 
77
124
  if (request.mode === "navigate") {
78
- event.respondWith(fetchThenCache(request).catch(() => cachedAppShell(request, "/index.html")));
125
+ event.respondWith(fetchThenCache(event).catch(() => cachedAppShell(request, "/index.html")));
79
126
  return;
80
127
  }
81
128
 
82
129
  if (!APP_SHELL.includes(url.pathname)) return;
83
- event.respondWith(fetchThenCache(request).catch(() => cachedAppShell(request)));
130
+ event.respondWith(fetchThenCache(event).catch(() => cachedAppShell(request)));
84
131
  });