@firstpick/pi-package-webui 0.8.0 → 0.8.1

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 (51) hide show
  1. package/README.md +22 -5
  2. package/bin/pi-webui.mjs +434 -100
  3. package/lib/npm-command.mjs +81 -0
  4. package/lib/queue-mutation.mjs +6 -0
  5. package/lib/workspace-files-live-watcher.mjs +138 -0
  6. package/package.json +8 -3
  7. package/public/app.js +2816 -314
  8. package/public/index.html +112 -27
  9. package/public/mobile-shell-state.mjs +166 -0
  10. package/public/service-worker.js +60 -13
  11. package/public/styles.css +1049 -371
  12. package/public/subagent-gate-visibility.mjs +16 -0
  13. package/public/subagent-launch-slot-state.mjs +16 -0
  14. package/public/transcript-renderer.mjs +433 -0
  15. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  16. package/tests/browser/interaction-continuity.spec.mjs +739 -0
  17. package/tests/browser/mobile-foundation.spec.mjs +352 -0
  18. package/tests/browser/optimistic-prompt.spec.mjs +130 -0
  19. package/tests/chat-scroll-intent-static.test.mjs +6 -1
  20. package/tests/codex-fast-mode-static.test.mjs +8 -5
  21. package/tests/compact-sections-static.test.mjs +20 -2
  22. package/tests/compaction-mutation-contract.test.mjs +18 -4
  23. package/tests/compaction-static.test.mjs +1 -0
  24. package/tests/completion-signal-contract.test.mjs +13 -2
  25. package/tests/fast-mode-client-static.test.mjs +7 -4
  26. package/tests/fixtures/fake-pi.mjs +181 -2
  27. package/tests/git-panel-gitignore-static.test.mjs +104 -0
  28. package/tests/http-endpoints-harness.test.mjs +228 -2
  29. package/tests/interaction-state-stability-static.test.mjs +254 -0
  30. package/tests/mobile-continuity-tablet-static.test.mjs +55 -0
  31. package/tests/mobile-foundation-static.test.mjs +69 -0
  32. package/tests/mobile-phone-experience-static.test.mjs +65 -0
  33. package/tests/mobile-shell-state.test.mjs +69 -0
  34. package/tests/mobile-static.test.mjs +244 -38
  35. package/tests/mobile-transcript-cache-characterization.test.mjs +34 -0
  36. package/tests/npm-command.test.mjs +64 -1
  37. package/tests/open-issue-wizard-static.test.mjs +2 -1
  38. package/tests/queue-edit-reorder-static.test.mjs +9 -1
  39. package/tests/queue-mutation-contract.test.mjs +22 -0
  40. package/tests/service-worker-lifecycle.test.mjs +120 -0
  41. package/tests/sse-backpressure-harness.test.mjs +98 -0
  42. package/tests/streaming-ui-coupling.test.mjs +7 -1
  43. package/tests/subagent-gate-visibility.test.mjs +18 -2
  44. package/tests/subagent-launch-slot-state.test.mjs +32 -0
  45. package/tests/subagent-launch-slots-static.test.mjs +8 -2
  46. package/tests/subagents-helper.test.mjs +90 -0
  47. package/tests/terminal-tab-workspace-static.test.mjs +1 -1
  48. package/tests/update-commands.test.mjs +4 -0
  49. package/tests/workspace-files-live-updates-static.test.mjs +76 -0
  50. package/tests/workspace-files-live-watcher.test.mjs +95 -0
  51. package/webui-rpc-helper.mjs +175 -3
@@ -41,6 +41,83 @@ function existingPath(candidates, exists) {
41
41
  return "";
42
42
  }
43
43
 
44
+ function windowsCommandExtensions(command, env, pathApi) {
45
+ if (pathApi.extname(command)) return [""];
46
+ const configured = String(env.PATHEXT || env.PathExt || ".COM;.EXE;.BAT;.CMD")
47
+ .split(";")
48
+ .map((extension) => extension.trim())
49
+ .filter(Boolean);
50
+ return ["", ...configured];
51
+ }
52
+
53
+ /** Resolve the directory that supplies a command, using the same PATH order as the process. */
54
+ export function resolveCommandDirectory(command, runtime = {}) {
55
+ const env = runtime.env ?? process.env;
56
+ const platform = runtime.platform ?? process.platform;
57
+ const exists = runtime.existsSync ?? existsSync;
58
+ const pathApi = pathApiForPlatform(platform);
59
+ const value = String(command || "").trim().replace(/^"|"$/g, "");
60
+ if (!value) return "";
61
+
62
+ const directBase = pathApi.isAbsolute(value)
63
+ ? value
64
+ : value.includes("/") || value.includes("\\")
65
+ ? pathApi.resolve(runtime.cwd ?? process.cwd(), value)
66
+ : "";
67
+ const extensions = platform === "win32" ? windowsCommandExtensions(value, env, pathApi) : [""];
68
+ const pathCandidates = directBase
69
+ ? extensions.map((extension) => `${directBase}${extension}`)
70
+ : pathEntries(env, pathApi).flatMap((entry) => extensions.map((extension) => pathApi.join(entry, `${value}${extension}`)));
71
+ const resolved = existingPath(pathCandidates, exists);
72
+ return resolved ? pathApi.dirname(resolved) : "";
73
+ }
74
+
75
+ /** Put the selected Pi/Node installation first without discarding other PATH entries. */
76
+ export function prependPathDirectory(directory, runtime = {}) {
77
+ const env = runtime.env ?? process.env;
78
+ const platform = runtime.platform ?? process.platform;
79
+ const pathApi = pathApiForPlatform(platform);
80
+ const value = String(directory || "").trim();
81
+ if (!value) return envPathValue(env);
82
+ const comparable = (entry) => platform === "win32" ? pathApi.normalize(entry).toLowerCase() : pathApi.normalize(entry);
83
+ const selected = comparable(value);
84
+ const remaining = pathEntries(env, pathApi).filter((entry) => comparable(entry) !== selected);
85
+ return [value, ...remaining].join(pathApi.delimiter);
86
+ }
87
+
88
+ /** Preserve the process's PATH key casing so Windows does not receive Path and PATH entries. */
89
+ export function prependedPathEnvironment(directory, runtime = {}) {
90
+ const env = runtime.env ?? process.env;
91
+ const pathKey = Object.keys(env).find((key) => key.toLowerCase() === "path") || "PATH";
92
+ return { [pathKey]: prependPathDirectory(directory, runtime) };
93
+ }
94
+
95
+ /** Normalize Windows npm-generated Pi shims to Node plus the installation's CLI script. */
96
+ export function resolvePiCommandInvocation(command, args = [], runtime = {}) {
97
+ const env = runtime.env ?? process.env;
98
+ const execPath = runtime.execPath ?? process.execPath;
99
+ const platform = runtime.platform ?? process.platform;
100
+ const exists = runtime.existsSync ?? existsSync;
101
+ const pathApi = pathApiForPlatform(platform);
102
+ const requestedArgs = Array.isArray(args) ? args.map(String) : [];
103
+ const value = String(command || "").trim();
104
+
105
+ if (isJavaScriptPath(value)) {
106
+ return { command: execPath, args: [value, ...requestedArgs], source: "node-script" };
107
+ }
108
+ if (platform !== "win32" || !/^pi(?:\.(?:cmd|ps1))?$/i.test(pathApi.basename(value))) {
109
+ return { command: value, args: requestedArgs, source: "command" };
110
+ }
111
+
112
+ const installDirectory = resolveCommandDirectory(value, { ...runtime, env, execPath, platform, existsSync: exists });
113
+ const cliPath = pathApi.join(installDirectory, "node_modules", "@earendil-works", "pi-coding-agent", "dist", "cli.js");
114
+ if (installDirectory && existingPath([cliPath], exists)) {
115
+ const bundledNode = existingPath([pathApi.join(installDirectory, "node.exe"), execPath], exists) || execPath;
116
+ return { command: bundledNode, args: [cliPath, ...requestedArgs], source: "windows-node-cli", installDirectory };
117
+ }
118
+ return { command: value, args: requestedArgs, source: "command", installDirectory };
119
+ }
120
+
44
121
  /**
45
122
  * Resolve npm without relying on Windows CreateProcess to discover npm.cmd.
46
123
  * The returned display command intentionally remains npm-oriented while the
@@ -79,7 +156,11 @@ export function resolveNpmCommandInvocation(args = [], runtime = {}) {
79
156
  }
80
157
 
81
158
  const npmExecPath = String(env.npm_execpath || "").trim();
159
+ const preferredDirectories = Array.isArray(runtime.preferredDirectories)
160
+ ? runtime.preferredDirectories.map(String).filter(Boolean)
161
+ : [];
82
162
  const candidates = [
163
+ ...preferredDirectories.map((directory) => npmCliPathForDirectory(directory, pathApi)),
83
164
  isJavaScriptPath(npmExecPath) ? npmExecPath : "",
84
165
  npmCliPathForDirectory(pathApi.dirname(execPath), pathApi),
85
166
  ...pathEntries(env, pathApi).map((entry) => npmCliPathForDirectory(entry, pathApi)),
@@ -98,6 +98,12 @@ export function mutatePiRuntimeFollowUpQueue(session, payload = {}) {
98
98
  // `to` is the final zero-based index after the item has been removed.
99
99
  nextTracked.splice(operation.to, 0, tracked);
100
100
  nextMessages.splice(operation.to, 0, message);
101
+ } else if (operation.type === "delete") {
102
+ if (!validIndex(operation.index, followUp.length) || followUp[operation.index] !== operation.expectedText) {
103
+ return mutationFailure("invalid-request", steering, followUp);
104
+ }
105
+ nextTracked.splice(operation.index, 1);
106
+ nextMessages.splice(operation.index, 1);
101
107
  } else {
102
108
  return mutationFailure("invalid-request", steering, followUp);
103
109
  }
@@ -0,0 +1,138 @@
1
+ import { watch as watchDirectory } from "node:fs";
2
+ import path from "node:path";
3
+
4
+ export const WORKSPACE_FILES_LIVE_WATCH_DEBOUNCE_MS = 250;
5
+ export const WORKSPACE_FILES_LIVE_WATCH_MAX_WAIT_MS = 2_000;
6
+
7
+ function cleanTabId(value) {
8
+ return String(value || "").trim();
9
+ }
10
+
11
+ function canonicalRoot(value) {
12
+ const root = String(value || "").trim();
13
+ return root ? path.resolve(root) : "";
14
+ }
15
+
16
+ export function createWorkspaceFilesLiveWatcher({
17
+ watch = watchDirectory,
18
+ debounceMs = WORKSPACE_FILES_LIVE_WATCH_DEBOUNCE_MS,
19
+ maxWaitMs = WORKSPACE_FILES_LIVE_WATCH_MAX_WAIT_MS,
20
+ onChange = () => {},
21
+ onError = () => {},
22
+ } = {}) {
23
+ const roots = new Map();
24
+ const tabRoots = new Map();
25
+ const delayMs = Math.max(0, Number(debounceMs) || 0);
26
+ const maximumWaitMs = Math.max(0, Number(maxWaitMs) || WORKSPACE_FILES_LIVE_WATCH_MAX_WAIT_MS);
27
+
28
+ function reportError(root, error) {
29
+ try {
30
+ onError({ root, error });
31
+ } catch {
32
+ // Watcher diagnostics must never crash the Web UI server.
33
+ }
34
+ }
35
+
36
+ function closeRoot(root, { clearTabs = true } = {}) {
37
+ const record = roots.get(root);
38
+ if (!record) return false;
39
+ roots.delete(root);
40
+ if (record.timer) clearTimeout(record.timer);
41
+ try {
42
+ record.watcher?.close();
43
+ } catch {
44
+ // The watcher may already be closed after an error.
45
+ }
46
+ if (clearTabs) {
47
+ for (const tabId of record.tabs) {
48
+ if (tabRoots.get(tabId) === root) tabRoots.delete(tabId);
49
+ }
50
+ }
51
+ return true;
52
+ }
53
+
54
+ function failRoot(root, error) {
55
+ if (!roots.has(root)) return;
56
+ closeRoot(root);
57
+ reportError(root, error);
58
+ }
59
+
60
+ function scheduleChange(root) {
61
+ const record = roots.get(root);
62
+ if (!record) return;
63
+ record.tabIds = new Set(record.tabs);
64
+ if (record.timer) clearTimeout(record.timer);
65
+ const now = Date.now();
66
+ if (!record.burstStartedAt) record.burstStartedAt = now;
67
+ const remainingMs = Math.max(0, maximumWaitMs - (now - record.burstStartedAt));
68
+ record.timer = setTimeout(() => {
69
+ const current = roots.get(root);
70
+ if (!current || current !== record) return;
71
+ current.timer = null;
72
+ current.burstStartedAt = 0;
73
+ const tabIds = [...current.tabIds];
74
+ current.tabIds.clear();
75
+ try {
76
+ onChange({ root, tabIds, changedAt: new Date().toISOString() });
77
+ } catch (error) {
78
+ reportError(root, error);
79
+ }
80
+ }, Math.min(delayMs, remainingMs));
81
+ record.timer.unref?.();
82
+ }
83
+
84
+ function ensureRoot(root) {
85
+ const existing = roots.get(root);
86
+ if (existing) return existing;
87
+ const record = { root, tabs: new Set(), tabIds: new Set(), watcher: null, timer: null, burstStartedAt: 0 };
88
+ roots.set(root, record);
89
+ try {
90
+ record.watcher = watch(root, { recursive: true, persistent: false }, () => scheduleChange(root));
91
+ record.watcher.on?.("error", (error) => failRoot(root, error));
92
+ return record;
93
+ } catch (error) {
94
+ roots.delete(root);
95
+ reportError(root, error);
96
+ return null;
97
+ }
98
+ }
99
+
100
+ function unsubscribe(tabIdValue) {
101
+ const tabId = cleanTabId(tabIdValue);
102
+ const root = tabRoots.get(tabId);
103
+ if (!root) return false;
104
+ tabRoots.delete(tabId);
105
+ const record = roots.get(root);
106
+ if (!record) return true;
107
+ record.tabs.delete(tabId);
108
+ if (!record.tabs.size) closeRoot(root, { clearTabs: false });
109
+ return true;
110
+ }
111
+
112
+ function subscribe(tabIdValue, rootValue) {
113
+ const tabId = cleanTabId(tabIdValue);
114
+ const root = canonicalRoot(rootValue);
115
+ if (!tabId || !root) return false;
116
+ const previousRoot = tabRoots.get(tabId);
117
+ if (previousRoot === root && roots.has(root)) return true;
118
+ if (previousRoot) unsubscribe(tabId);
119
+ const record = ensureRoot(root);
120
+ if (!record) return false;
121
+ record.tabs.add(tabId);
122
+ tabRoots.set(tabId, root);
123
+ return true;
124
+ }
125
+
126
+ function closeAll() {
127
+ for (const root of [...roots.keys()]) closeRoot(root);
128
+ tabRoots.clear();
129
+ }
130
+
131
+ return {
132
+ subscribe,
133
+ unsubscribe,
134
+ closeAll,
135
+ watchedRootCount: () => roots.size,
136
+ subscribedRootForTab: (tabId) => tabRoots.get(cleanTabId(tabId)) || "",
137
+ };
138
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firstpick/pi-package-webui",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Pi Web UI companion package with a local browser UI CLI plus /webui-start and /webui-status commands.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/Firstp1ck/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
@@ -52,8 +52,9 @@
52
52
  "pi-webui": "./bin/pi-webui.mjs"
53
53
  },
54
54
  "scripts": {
55
- "check": "node --check public/app.js && node --check public/issue-wizard-state.mjs && node --check public/issue-bot-client.mjs && node --check public/workflow-status-stack.mjs && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.mjs && node --check public/subagent-gate-visibility.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check bin/pi-webui-rpc-supervisor.mjs && node --check lib/rpc-supervisor-protocol.mjs && node --check lib/rpc-supervisor-state.mjs && node --check lib/rpc-supervisor-client.mjs && node --check webui-rpc-helper.mjs && node --check lib/subagent-launch-slots.mjs && node --check lib/git-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
56
- "test": "node tests/run-all.mjs"
55
+ "check": "node --check public/app.js && node --check public/transcript-renderer.mjs && node --check public/mobile-shell-state.mjs && node --check public/issue-wizard-state.mjs && node --check public/issue-bot-client.mjs && node --check public/workflow-status-stack.mjs && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.mjs && node --check public/subagent-gate-visibility.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check bin/pi-webui-rpc-supervisor.mjs && node --check lib/rpc-supervisor-protocol.mjs && node --check lib/rpc-supervisor-state.mjs && node --check lib/rpc-supervisor-client.mjs && node --check webui-rpc-helper.mjs && node --check lib/subagent-launch-slots.mjs && node --check lib/git-live-watcher.mjs && node --check lib/workspace-files-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
56
+ "test": "node tests/run-all.mjs",
57
+ "test:browser": "playwright test"
57
58
  },
58
59
  "dependencies": {
59
60
  "@earendil-works/pi-coding-agent": "^0.83.0",
@@ -101,5 +102,9 @@
101
102
  "undici": "8.5.0",
102
103
  "ws": "8.21.0"
103
104
  }
105
+ },
106
+ "devDependencies": {
107
+ "@axe-core/playwright": "4.12.1",
108
+ "@playwright/test": "1.62.1"
104
109
  }
105
110
  }