@firstpick/pi-package-webui 0.11.0 → 0.11.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.
- package/DEVELOPMENT.md +181 -12
- package/README.md +41 -9
- package/TECHNICAL.md +91 -8
- package/bin/pi-webui.mjs +5432 -11428
- package/index.ts +10 -3
- package/lib/codex-cli-usage.mjs +232 -0
- package/lib/codex-usage-auth.mjs +39 -3
- package/lib/codex-usage-source.mjs +36 -0
- package/lib/component-update-state.mjs +2 -2
- package/lib/git-workflow-preference-values.mjs +122 -0
- package/lib/git-workflow-preferences.mjs +35 -563
- package/lib/package-updates.mjs +260 -0
- package/lib/rpc-supervisor-client.mjs +8 -4
- package/lib/server/app-runners.mjs +1667 -0
- package/lib/server/codex-fast-mode.mjs +161 -0
- package/lib/server/conversation-mode.mjs +218 -0
- package/lib/server/conversation-voice.mjs +318 -0
- package/lib/server/extension-ui-requests.mjs +114 -0
- package/lib/server/git-generation.mjs +459 -0
- package/lib/server/git-mutations.mjs +1827 -0
- package/lib/server/git-reads.mjs +608 -0
- package/lib/server/git-worktree-sessions.mjs +408 -0
- package/lib/server/helper-requests.mjs +82 -0
- package/lib/server/no-project-workspaces.mjs +103 -0
- package/lib/server/rpc-transports.mjs +394 -0
- package/lib/server/settings-store.mjs +544 -0
- package/lib/server/sse-delivery.mjs +138 -0
- package/lib/server/workspace-files.mjs +563 -0
- package/lib/update/supervisor.mjs +4 -0
- package/lib/webui-workspaces.mjs +2 -0
- package/package.json +5 -5
- package/public/activity-agents-controller.mjs +269 -0
- package/public/activity-events-controller.mjs +236 -0
- package/public/activity-intercom-controller.mjs +627 -0
- package/public/activity-queue-controller.mjs +534 -0
- package/public/activity-todo-view.mjs +89 -0
- package/public/activity-usage-controller.mjs +589 -0
- package/public/app.js +3761 -3878
- package/public/conversation-overview.css +84 -0
- package/public/conversation-overview.mjs +193 -0
- package/public/draft-conversations.mjs +135 -0
- package/public/focused-composer-controls.css +111 -0
- package/public/focused-composer-controls.mjs +143 -0
- package/public/focused-composer-disclosure.mjs +223 -0
- package/public/focused-shell-adapter.css +264 -0
- package/public/focused-shell-adapter.mjs +257 -0
- package/public/index.html +137 -80
- package/public/model-catalog-order.mjs +63 -0
- package/public/platform-event-stream.mjs +64 -0
- package/public/project-artifact-controller.mjs +218 -0
- package/public/project-file-viewer-controller.mjs +383 -0
- package/public/project-git-tools-controller.mjs +181 -0
- package/public/project-runners-controller.mjs +220 -0
- package/public/service-worker.js +52 -1
- package/public/session-attention-scheduler.mjs +182 -0
- package/public/session-composer-store.mjs +56 -0
- package/public/session-context.mjs +51 -0
- package/public/session-extension-requests.mjs +63 -0
- package/public/session-shelf-state.mjs +151 -0
- package/public/session-shelves.css +171 -0
- package/public/session-shelves.mjs +95 -0
- package/public/settings-navigation-controller.mjs +249 -0
- package/public/settings-navigation.css +61 -0
- package/public/settings-resource-controller.mjs +232 -0
- package/public/settings-workspace.css +19 -0
- package/public/settings-workspace.mjs +175 -0
- package/public/shell-actions.mjs +87 -0
- package/public/shell-attention-inbox.css +72 -0
- package/public/shell-attention-inbox.mjs +198 -0
- package/public/shell-context-actions.css +61 -0
- package/public/shell-context-actions.mjs +168 -0
- package/public/shell-inspector-resize.mjs +124 -0
- package/public/shell-navigation-resize.mjs +107 -0
- package/public/shell-navigation.mjs +127 -0
- package/public/shell-preferences.mjs +108 -0
- package/public/shell-surfaces.mjs +99 -0
- package/public/shell-tools-launcher.css +97 -0
- package/public/shell-tools-launcher.mjs +222 -0
- package/public/shell-view-host.mjs +115 -0
- package/public/shell-workspace.css +266 -0
- package/public/shell-workspace.mjs +402 -0
- package/public/sidebar-update-menu.css +190 -0
- package/public/sidebar-update-menu.mjs +512 -0
- package/public/styles.css +320 -169
- package/public/subagent-launch-slot-state.mjs +2 -2
- package/public/theme-contract.mjs +1 -1
- package/public/themed-selects.css +156 -0
- package/public/workspace-choices.mjs +104 -0
- package/tests/activity-agents-controller.test.mjs +652 -0
- package/tests/activity-events-controller.test.mjs +511 -0
- package/tests/app-runner-terminal-static.test.mjs +3 -3
- package/tests/append-system-http.test.mjs +7 -6
- package/tests/append-system-selector-static.test.mjs +6 -6
- package/tests/aur-review-widget-static.test.mjs +11 -3
- package/tests/boot-failure-diagnostics.test.mjs +8 -3
- package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
- package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
- package/tests/browser/activity-owner-integration.spec.mjs +201 -0
- package/tests/browser/activity-queue-controller.spec.mjs +405 -0
- package/tests/browser/activity-section-picker.spec.mjs +294 -0
- package/tests/browser/activity-todo-view.spec.mjs +60 -0
- package/tests/browser/activity-usage-controller.spec.mjs +416 -0
- package/tests/browser/compact-layout-integration.spec.mjs +58 -0
- package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
- package/tests/browser/composer-disclosure.spec.mjs +389 -0
- package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
- package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
- package/tests/browser/control-visibility.spec.mjs +5 -0
- package/tests/browser/controls-layout.spec.mjs +21 -2
- package/tests/browser/conversation-overview.spec.mjs +251 -0
- package/tests/browser/draft-conversations.spec.mjs +276 -0
- package/tests/browser/empty-startup-fixture.mjs +135 -0
- package/tests/browser/empty-startup.spec.mjs +282 -0
- package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
- package/tests/browser/focused-composer-more.spec.mjs +127 -0
- package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
- package/tests/browser/focused-navigation-fixture.mjs +32 -0
- package/tests/browser/focused-project-activity.spec.mjs +111 -0
- package/tests/browser/focused-shell-integration.spec.mjs +208 -0
- package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
- package/tests/browser/folder-picker-layout.spec.mjs +302 -0
- package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
- package/tests/browser/git-setup-cancel.spec.mjs +251 -0
- package/tests/browser/guided-git-fallback.spec.mjs +40 -21
- package/tests/browser/inspector-header.spec.mjs +221 -0
- package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
- package/tests/browser/inspector-resize.spec.mjs +227 -0
- package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
- package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
- package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
- package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
- package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
- package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
- package/tests/browser/interaction-continuity.spec.mjs +50 -26
- package/tests/browser/interaction-model-picker.spec.mjs +86 -0
- package/tests/browser/last-terminal-close.spec.mjs +280 -0
- package/tests/browser/mobile-foundation.spec.mjs +172 -20
- package/tests/browser/model-catalog-groups.spec.mjs +104 -0
- package/tests/browser/more-row-menus.spec.mjs +258 -0
- package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
- package/tests/browser/no-project-conversation.spec.mjs +113 -0
- package/tests/browser/optimistic-prompt.spec.mjs +3 -0
- package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
- package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
- package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
- package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
- package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
- package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
- package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
- package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
- package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
- package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
- package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
- package/tests/browser/project-artifact-controller.spec.mjs +324 -0
- package/tests/browser/project-artifact-integration.spec.mjs +103 -0
- package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
- package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
- package/tests/browser/session-fixture.mjs +118 -0
- package/tests/browser/session-ownership.spec.mjs +175 -0
- package/tests/browser/session-shelves-integration.spec.mjs +219 -0
- package/tests/browser/session-shelves.spec.mjs +340 -0
- package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
- package/tests/browser/session-summary.spec.mjs +17 -12
- package/tests/browser/settings-complete-home.spec.mjs +463 -0
- package/tests/browser/settings-entrypoint.spec.mjs +104 -0
- package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
- package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
- package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
- package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
- package/tests/browser/shell-ownership.spec.mjs +398 -0
- package/tests/browser/shell-rollout-fixture.mjs +259 -0
- package/tests/browser/shell-rollout.spec.mjs +357 -0
- package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
- package/tests/browser/shell-workspace.spec.mjs +433 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
- package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
- package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
- package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
- package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
- package/tests/browser/stream-output-isolation.spec.mjs +6 -3
- package/tests/browser/themed-selects.spec.mjs +297 -0
- package/tests/browser/thread-start-flow.spec.mjs +481 -0
- package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
- package/tests/browser/ui-polish-features.spec.mjs +85 -0
- package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
- package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
- package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
- package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
- package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
- package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
- package/tests/browser/windows-drive-parent.spec.mjs +4 -2
- package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
- package/tests/codex-cli-usage.test.mjs +189 -0
- package/tests/codex-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-auth.test.mjs +168 -9
- package/tests/codex-usage-http.test.mjs +124 -0
- package/tests/codex-usage-source.test.mjs +146 -0
- package/tests/component-update-api-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +9 -4
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +5 -5
- package/tests/conversation-overview-adapter.test.mjs +100 -0
- package/tests/document-artifact-static.test.mjs +2 -1
- package/tests/draft-conversations.test.mjs +205 -0
- package/tests/empty-startup-launcher.test.mjs +197 -0
- package/tests/events-tree-context-menu-static.test.mjs +22 -18
- package/tests/fake-pi-session-ownership.test.mjs +302 -0
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
- package/tests/file-viewer-image-static.test.mjs +15 -11
- package/tests/file-viewer-search-static.test.mjs +5 -5
- package/tests/fixtures/fake-codex-app-server.mjs +61 -0
- package/tests/fixtures/fake-pi.mjs +41 -9
- package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
- package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
- package/tests/git-footer-context-menu-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +41 -48
- package/tests/git-panel-live-updates-static.test.mjs +2 -1
- package/tests/git-workflow-dispatch.test.mjs +66 -0
- package/tests/git-workflow-preferences.test.mjs +9 -1
- package/tests/guided-git-activation-static.test.mjs +14 -11
- package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
- package/tests/guided-git-message-reliability-static.test.mjs +10 -6
- package/tests/guided-git-publication-backend-static.test.mjs +16 -11
- package/tests/http-endpoints-harness.test.mjs +29 -9
- package/tests/interaction-state-stability-static.test.mjs +4 -3
- package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
- package/tests/intercom-tag-layout-static.test.mjs +13 -12
- package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
- package/tests/main-output-loading-static.test.mjs +4 -4
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -2
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +10 -7
- package/tests/mobile-phone-experience-static.test.mjs +3 -2
- package/tests/mobile-static.test.mjs +173 -135
- package/tests/model-catalog-order.test.mjs +103 -0
- package/tests/native-parity.test.mjs +6 -4
- package/tests/native-session-choice-owner.test.mjs +102 -0
- package/tests/native-update-lifecycle.test.mjs +10 -5
- package/tests/no-project-http-harness.test.mjs +328 -0
- package/tests/no-project-navigation.test.mjs +54 -0
- package/tests/no-project-workspaces.test.mjs +77 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +4 -4
- package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
- package/tests/package-updates.test.mjs +630 -0
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/platform-event-stream.test.mjs +253 -0
- package/tests/project-file-viewer-controller.test.mjs +652 -0
- package/tests/project-git-tools-adapter.test.mjs +103 -0
- package/tests/project-git-tools-controller.test.mjs +577 -0
- package/tests/project-runners-controller.test.mjs +453 -0
- package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
- package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
- package/tests/questionnaire-dialog.test.mjs +6 -6
- package/tests/queue-edit-reorder-static.test.mjs +48 -51
- package/tests/rpc-supervisor-host.test.mjs +4 -1
- package/tests/safety-guard-auto-review-static.test.mjs +1 -1
- package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
- package/tests/server-app-runners.test.mjs +536 -0
- package/tests/server-codex-fast-mode.test.mjs +346 -0
- package/tests/server-conversation-mode.test.mjs +386 -0
- package/tests/server-conversation-voice.test.mjs +426 -0
- package/tests/server-extension-ui-requests.test.mjs +357 -0
- package/tests/server-git-generation.test.mjs +558 -0
- package/tests/server-git-mutations.test.mjs +729 -0
- package/tests/server-git-reads.test.mjs +381 -0
- package/tests/server-git-worktree-sessions.test.mjs +502 -0
- package/tests/server-helper-requests.test.mjs +364 -0
- package/tests/server-rpc-transports.test.mjs +553 -0
- package/tests/server-settings-store.test.mjs +132 -0
- package/tests/server-shell-rollout.test.mjs +478 -0
- package/tests/server-sse-delivery.test.mjs +410 -0
- package/tests/server-workspace-files.test.mjs +546 -0
- package/tests/session-attention-scheduler.test.mjs +514 -0
- package/tests/session-composer-store.test.mjs +153 -0
- package/tests/session-context.test.mjs +134 -0
- package/tests/session-extension-requests.test.mjs +193 -0
- package/tests/session-ownership-adapter.test.mjs +130 -0
- package/tests/session-sampling-ui-static.test.mjs +10 -4
- package/tests/session-send-lifetime.test.mjs +140 -0
- package/tests/session-shelf-state.test.mjs +348 -0
- package/tests/session-shelves-adapter.test.mjs +79 -0
- package/tests/session-summary-lifetime.test.mjs +54 -0
- package/tests/settings-resource-controller.test.mjs +548 -0
- package/tests/shell-action-adapter.test.mjs +169 -0
- package/tests/shell-actions.test.mjs +182 -0
- package/tests/shell-navigation.test.mjs +348 -0
- package/tests/shell-preferences.test.mjs +367 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-output-isolation-static.test.mjs +1 -1
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slot-state.test.mjs +2 -2
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagent-reliability-integration.test.mjs +13 -30
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +1 -1
- package/tests/tab-metadata-ordering.test.mjs +99 -0
- package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
- package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
- package/tests/terminal-tab-workspace-static.test.mjs +5 -4
- package/tests/terminal-tabs-resize-static.test.mjs +1 -1
- package/tests/theme-contract.test.mjs +10 -3
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thread-display-title.test.mjs +44 -0
- package/tests/update-api-harness.test.mjs +15 -14
- package/tests/update-tab-restore-harness.test.mjs +3 -0
- package/tests/webui-settings-locking.test.mjs +2 -2
- package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
- package/tests/workspace-choices.test.mjs +114 -0
- package/tests/workspace-save-load-static.test.mjs +7 -4
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { StringDecoder } from "node:string_decoder";
|
|
4
|
+
import { realpath, stat } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { resolveNpmCommandInvocation, resolvePiCommandInvocation } from "./npm-command.mjs";
|
|
7
|
+
|
|
8
|
+
const WEBUI = "@firstpick/pi-package-webui";
|
|
9
|
+
const PI = "@earendil-works/pi-coding-agent";
|
|
10
|
+
const TARGETS = new Set(["all", "webui", "pi"]);
|
|
11
|
+
const OUTPUT_LIMIT = 16_000;
|
|
12
|
+
const TRUNCATED_OUTPUT = "[output truncated]\n";
|
|
13
|
+
const COMMAND_TIMEOUT_MS = 10 * 60_000;
|
|
14
|
+
|
|
15
|
+
function httpError(statusCode, message) {
|
|
16
|
+
return Object.assign(new Error(message), { statusCode });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function boundedOutput(value, env) {
|
|
20
|
+
let text = String(value || "")
|
|
21
|
+
.replace(/\u001b(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "")
|
|
22
|
+
.replace(/\b((?:_?auth[_-]?token|api[_-]?key|password|secret|token)\s*[=:]\s*)[^\s,;]+/gi, "$1[redacted]")
|
|
23
|
+
.replace(/\b([a-z][a-z0-9+.-]*:\/\/)[^\s/@:]+:[^\s/@]+@/gi, "$1[redacted]@");
|
|
24
|
+
for (const [key, secret] of Object.entries(env)) {
|
|
25
|
+
if (!/(?:auth|token|password|secret|api[_-]?key)/i.test(key) || secret?.length < 6 || !secret) continue;
|
|
26
|
+
// Live output publishes complete lines before the rest of a multiline secret arrives.
|
|
27
|
+
const fragments = [...new Set([secret, ...secret.split(/\r\n|\r|\n/)])].filter(Boolean).sort((a, b) => b.length - a.length);
|
|
28
|
+
for (const fragment of fragments) text = text.replaceAll(fragment, "[redacted]");
|
|
29
|
+
}
|
|
30
|
+
return text.length > OUTPUT_LIMIT ? TRUNCATED_OUTPUT + text.slice(-(OUTPUT_LIMIT - TRUNCATED_OUTPUT.length)) : text;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function commandOutput(env) {
|
|
34
|
+
const decoder = new StringDecoder("utf8");
|
|
35
|
+
let pending = "";
|
|
36
|
+
let droppingLine = false;
|
|
37
|
+
let truncated = false;
|
|
38
|
+
let output = "";
|
|
39
|
+
const append = (text) => {
|
|
40
|
+
const combined = output + boundedOutput(text, env);
|
|
41
|
+
truncated ||= combined.length > OUTPUT_LIMIT || combined.includes(TRUNCATED_OUTPUT);
|
|
42
|
+
output = combined.slice(-(OUTPUT_LIMIT - (truncated ? TRUNCATED_OUTPUT.length : 0)));
|
|
43
|
+
};
|
|
44
|
+
const consume = (text, final = false) => {
|
|
45
|
+
const lines = (pending + text).split("\n");
|
|
46
|
+
pending = lines.pop();
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
if (droppingLine || line.length > OUTPUT_LIMIT) truncated = true;
|
|
49
|
+
else append(line + "\n");
|
|
50
|
+
droppingLine = false;
|
|
51
|
+
}
|
|
52
|
+
if (pending.length > OUTPUT_LIMIT) { truncated = true; droppingLine = true; pending = ""; }
|
|
53
|
+
if (final) {
|
|
54
|
+
if (!droppingLine) append(pending);
|
|
55
|
+
pending = "";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
// Withhold incomplete lines so secrets and ANSI sequences split across chunks stay private.
|
|
60
|
+
write(chunk) { consume(decoder.write(chunk)); },
|
|
61
|
+
end() { consume(decoder.end(), true); },
|
|
62
|
+
snapshot() { return (truncated ? TRUNCATED_OUTPUT : "") + output.slice(-(OUTPUT_LIMIT - (truncated ? TRUNCATED_OUTPUT.length : 0))); },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Run fixed package commands without a shell; stop their process tree on timeout. */
|
|
67
|
+
export function runPackageCommand(command, args, { cwd, env = process.env, timeoutMs = COMMAND_TIMEOUT_MS, onOutput } = {}) {
|
|
68
|
+
const invocation = command === "npm" ? resolveNpmCommandInvocation(args, { env }) :
|
|
69
|
+
resolvePiCommandInvocation(command, args, { env });
|
|
70
|
+
return new Promise((resolve) => {
|
|
71
|
+
const stdout = commandOutput(env);
|
|
72
|
+
const stderr = commandOutput(env);
|
|
73
|
+
const publish = () => {
|
|
74
|
+
// Observers must not interrupt command cleanup or change its result.
|
|
75
|
+
try { onOutput?.({ stdout: stdout.snapshot(), stderr: stderr.snapshot() }); } catch {}
|
|
76
|
+
};
|
|
77
|
+
let error = "";
|
|
78
|
+
let timedOut = false;
|
|
79
|
+
const child = spawn(invocation.command, invocation.args, { cwd, env, shell: false,
|
|
80
|
+
detached: process.platform !== "win32", windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
81
|
+
const stop = (signal) => {
|
|
82
|
+
try {
|
|
83
|
+
if (process.platform !== "win32" && child.pid) process.kill(-child.pid, signal);
|
|
84
|
+
else child.kill(signal);
|
|
85
|
+
} catch (failure) { if (failure.code !== "ESRCH") error = failure.message; }
|
|
86
|
+
};
|
|
87
|
+
const timer = setTimeout(() => {
|
|
88
|
+
timedOut = true;
|
|
89
|
+
if (process.platform === "win32" && child.pid) {
|
|
90
|
+
const killer = spawn("taskkill", ["/PID", String(child.pid), "/T", "/F"], { windowsHide: true, stdio: "ignore" });
|
|
91
|
+
killer.once("error", () => stop("SIGKILL"));
|
|
92
|
+
} else stop("SIGKILL");
|
|
93
|
+
}, timeoutMs);
|
|
94
|
+
child.stdout.on("data", (chunk) => { stdout.write(chunk); publish(); });
|
|
95
|
+
child.stderr.on("data", (chunk) => { stderr.write(chunk); publish(); });
|
|
96
|
+
child.once("error", (failure) => { error = failure.message; });
|
|
97
|
+
child.once("close", (exitCode, signal) => {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
stdout.end();
|
|
100
|
+
stderr.end();
|
|
101
|
+
publish();
|
|
102
|
+
resolve({ exitCode, signal: signal || null, timedOut, stdout: stdout.snapshot(), stderr: stderr.snapshot(),
|
|
103
|
+
error: boundedOutput(timedOut ? `Command timed out after ${timeoutMs} ms. Inspect its output before retrying.` : error, env) });
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function unchangedEvidence(item) {
|
|
109
|
+
const self = /^pi is already up to date \(v[^\s()]+\)$/;
|
|
110
|
+
const packages = "Packages are already up to date";
|
|
111
|
+
const extension = `npm:${WEBUI} is already up to date`;
|
|
112
|
+
const npm = /^up to date(?:, audited \d+ packages?)? in \d+(?:\.\d+)?(?:ms|s|m|h|d|w|y)$/;
|
|
113
|
+
const all = item.command.args.includes("--all");
|
|
114
|
+
const selfOnlyNote = "Extensions are skipped. Run pi update --extensions to update extensions.";
|
|
115
|
+
const npmInfo = (line) => /^\d+ packages? (?:is|are) looking for funding$/.test(line) ||
|
|
116
|
+
line === "run `npm fund` for details" || line === "found 0 vulnerabilities";
|
|
117
|
+
const allowed = item.id === "webui:npm-global" ? (line) => npm.test(line) || npmInfo(line) :
|
|
118
|
+
item.id === "webui:pi-user" ? (line) => line === extension :
|
|
119
|
+
(line) => self.test(line) || (all && line === packages) || (!all && line === selfOnlyNote);
|
|
120
|
+
const lines = (text) => String(text || "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
121
|
+
return {
|
|
122
|
+
safe(stdout, stderr) { return !String(stderr || "").trim() && lines(stdout).every(allowed); },
|
|
123
|
+
complete(stdout) {
|
|
124
|
+
const output = lines(stdout);
|
|
125
|
+
return output.length > 0 && output.every(allowed) &&
|
|
126
|
+
(item.id !== "webui:npm-global" || output.some((line) => npm.test(line))) &&
|
|
127
|
+
(item.id !== "pi" || (output.some((line) => self.test(line)) && (!all || output.includes(packages))));
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function installedWebui(nodeModulesRoot) {
|
|
133
|
+
if (!nodeModulesRoot) return null;
|
|
134
|
+
const root = path.join(nodeModulesRoot, ...WEBUI.split("/"));
|
|
135
|
+
try {
|
|
136
|
+
if (!(await stat(root)).isDirectory() || !(await stat(path.join(root, "package.json"))).isFile()) return null;
|
|
137
|
+
return await realpath(root);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code)) return null;
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function target(id, installedRoot, command, args) {
|
|
145
|
+
return { id, packageName: id === "pi" ? PI : WEBUI, beforeVersion: "",
|
|
146
|
+
installedRoot, effectRoot: installedRoot, command: { command, args } };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Installation-aware previews and in-memory jobs for one Web UI server. */
|
|
150
|
+
export function createPackageUpdates({ agentDir, cwd = process.cwd(), env = process.env,
|
|
151
|
+
runCommand = runPackageCommand, timeoutMs = COMMAND_TIMEOUT_MS } = {}) {
|
|
152
|
+
if (!path.isAbsolute(agentDir || "")) throw new TypeError("An absolute Pi agent directory is required.");
|
|
153
|
+
const jobs = new Map();
|
|
154
|
+
const latest = { all: null, webui: null, pi: null };
|
|
155
|
+
let running = false;
|
|
156
|
+
const snapshot = (job) => job ? structuredClone(job) : null;
|
|
157
|
+
|
|
158
|
+
async function plan(requested) {
|
|
159
|
+
if (!TARGETS.has(requested)) throw httpError(400, "Unsupported update target.");
|
|
160
|
+
if (running) throw httpError(409, "Another package update is running.");
|
|
161
|
+
const targets = [];
|
|
162
|
+
const refusals = [];
|
|
163
|
+
let userRoot = null;
|
|
164
|
+
let globalRoot = null;
|
|
165
|
+
if (requested !== "pi") {
|
|
166
|
+
try { userRoot = await installedWebui(path.join(agentDir, "npm", "node_modules")); }
|
|
167
|
+
catch (error) { refusals.push(`Pi-managed Web UI could not be inspected: ${boundedOutput(error.message, env)}`); }
|
|
168
|
+
try {
|
|
169
|
+
const result = await runCommand("npm", ["root", "-g"], { cwd, env, timeoutMs: Math.min(timeoutMs, 10_000) });
|
|
170
|
+
const npmRoot = String(result.stdout || "").trim();
|
|
171
|
+
if (result.exitCode !== 0 || result.error || result.timedOut || !path.isAbsolute(npmRoot) || /[\r\n]/.test(npmRoot)) {
|
|
172
|
+
refusals.push("The npm-global Web UI location could not be detected; no global update is planned.");
|
|
173
|
+
} else globalRoot = await installedWebui(npmRoot);
|
|
174
|
+
} catch (error) { refusals.push(`npm-global Web UI could not be inspected: ${boundedOutput(error.message, env)}`); }
|
|
175
|
+
}
|
|
176
|
+
if (requested === "pi" || requested === "all") {
|
|
177
|
+
const pi = target("pi", "PATH pi", "pi", ["update", ...(requested === "all" ? ["--all"] : [])]);
|
|
178
|
+
if (requested === "all" && userRoot) pi.coveredInstallations = [{ id: "webui:pi-user", installedRoot: userRoot }];
|
|
179
|
+
targets.push(pi);
|
|
180
|
+
}
|
|
181
|
+
if (requested === "webui" && userRoot) {
|
|
182
|
+
targets.push(target("webui:pi-user", userRoot, "pi", ["update", "--extension", `npm:${WEBUI}`]));
|
|
183
|
+
}
|
|
184
|
+
if (requested !== "pi") {
|
|
185
|
+
if (!userRoot) refusals.push("Pi-managed Web UI is not installed; no targeted installation command will run for it.");
|
|
186
|
+
if (globalRoot && globalRoot !== userRoot) {
|
|
187
|
+
targets.push(target("webui:npm-global", globalRoot, "npm", ["update", "-g", WEBUI]));
|
|
188
|
+
} else if (globalRoot) refusals.push("Pi-managed and npm-global Web UI share one installation; Pi updates it once.");
|
|
189
|
+
else refusals.push("No npm-global Web UI installation was found; no global update will run.");
|
|
190
|
+
}
|
|
191
|
+
if (!targets.length) throw httpError(409, refusals.join(" ") || "Web UI is not installed in either package location.");
|
|
192
|
+
const preview = { schemaVersion: 2, transactionId: randomUUID(), digest: randomBytes(32).toString("hex"),
|
|
193
|
+
requested, createdAt: new Date().toISOString(), targets, refusals, context: { cwd, agentDir },
|
|
194
|
+
warning: "Package commands use your existing configuration and may run package scripts. Restart Web UI manually after updating to load changes." };
|
|
195
|
+
// Bound retained previews without evicting launched jobs or their receipts.
|
|
196
|
+
const previews = [...jobs.values()].filter((job) => job.phase === "planned");
|
|
197
|
+
if (previews.length >= 100) jobs.delete(previews[0].transactionId);
|
|
198
|
+
jobs.set(preview.transactionId, { transactionId: preview.transactionId, plan: preview, phase: "planned",
|
|
199
|
+
receipts: [], verifiedTargets: [], outcome: "", error: "" });
|
|
200
|
+
return structuredClone(preview);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function execute(job) {
|
|
204
|
+
for (const item of job.plan.targets) {
|
|
205
|
+
const stepStartedAt = new Date().toISOString();
|
|
206
|
+
Object.assign(job.progress, { currentTargetId: item.id, stepStartedAt, stdout: "", stderr: "" });
|
|
207
|
+
const evidence = unchangedEvidence(item);
|
|
208
|
+
let safeEvidence = true;
|
|
209
|
+
let settled = false;
|
|
210
|
+
const onOutput = ({ stdout, stderr }) => {
|
|
211
|
+
if (settled) return;
|
|
212
|
+
const output = { stdout: boundedOutput(stdout, env), stderr: boundedOutput(stderr, env) };
|
|
213
|
+
safeEvidence &&= evidence.safe(output.stdout, output.stderr);
|
|
214
|
+
Object.assign(job.progress, output);
|
|
215
|
+
};
|
|
216
|
+
let result;
|
|
217
|
+
try { result = await runCommand(item.command.command, item.command.args, { cwd, env, timeoutMs, onOutput }); }
|
|
218
|
+
catch (error) { result = { exitCode: null, error: error.message }; }
|
|
219
|
+
onOutput({ stdout: result.stdout ?? job.progress.stdout, stderr: result.stderr ?? job.progress.stderr });
|
|
220
|
+
settled = true;
|
|
221
|
+
const success = result.exitCode === 0 && !result.signal && !result.error && !result.timedOut;
|
|
222
|
+
const unchanged = success && safeEvidence && evidence.complete(job.progress.stdout);
|
|
223
|
+
job.receipts.push({ id: item.id, startedAt: stepStartedAt, at: new Date().toISOString(), status: unchanged ? "unchanged" : success ? "success" : "failed",
|
|
224
|
+
exitCode: result.exitCode ?? null, signal: result.signal || null, timedOut: Boolean(result.timedOut),
|
|
225
|
+
stdout: job.progress.stdout, stderr: job.progress.stderr, error: boundedOutput(result.error, env) });
|
|
226
|
+
job.progress.completedSteps++;
|
|
227
|
+
job.progress.currentTargetId = null;
|
|
228
|
+
}
|
|
229
|
+
const successes = job.receipts.filter((receipt) => receipt.status !== "failed").length;
|
|
230
|
+
job.phase = job.receipts.every((receipt) => receipt.status === "unchanged") ? "unchanged" :
|
|
231
|
+
successes === job.receipts.length ? "success" : successes ? "partial" : "failed";
|
|
232
|
+
job.outcome = job.phase;
|
|
233
|
+
job.finishedAt = new Date().toISOString();
|
|
234
|
+
job.restartRequired = job.receipts.some((receipt) => receipt.status === "success");
|
|
235
|
+
job.message = job.phase === "unchanged" ? "Already up to date. All commands explicitly reported no changes." :
|
|
236
|
+
`Commands completed.${job.restartRequired ? " Restart Web UI manually to load updates." : ""} Command exit codes do not verify installed versions or health.`;
|
|
237
|
+
job.error = job.receipts.filter((receipt) => receipt.status === "failed")
|
|
238
|
+
.map((receipt) => `${receipt.id}: ${receipt.error || `command exited ${receipt.exitCode ?? receipt.signal ?? "without a status"}`}`).join("\n");
|
|
239
|
+
running = false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function apply(transactionId, digest) {
|
|
243
|
+
const job = jobs.get(transactionId);
|
|
244
|
+
if (!job) throw httpError(404, "Update preview was not found in this server. Request a new preview.");
|
|
245
|
+
if (job.plan.digest !== digest) throw httpError(409, "Update confirmation does not match the preview.");
|
|
246
|
+
if (job.phase !== "planned") throw httpError(409, "This update has already been started.");
|
|
247
|
+
if (running) throw httpError(409, "Another package update is running.");
|
|
248
|
+
running = true;
|
|
249
|
+
job.phase = "running";
|
|
250
|
+
job.progress = { totalSteps: job.plan.targets.length, completedSteps: 0, currentTargetId: null,
|
|
251
|
+
startedAt: new Date().toISOString(), stepStartedAt: null, stdout: "", stderr: "" };
|
|
252
|
+
latest[job.plan.requested] = transactionId;
|
|
253
|
+
void execute(job);
|
|
254
|
+
return { transactionId, phase: "running" };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return { plan, apply, getJob: (transactionId) => snapshot(jobs.get(transactionId)),
|
|
258
|
+
getJobs: () => Object.fromEntries(Object.entries(latest).map(([key, id]) => [key, snapshot(jobs.get(id))])),
|
|
259
|
+
get running() { return running; } };
|
|
260
|
+
}
|
|
@@ -38,6 +38,10 @@ function replacementConnectionError(error) {
|
|
|
38
38
|
return error?.code === "ECONNREFUSED" || error?.code === "ENOENT";
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
function disconnectedError(message) {
|
|
42
|
+
return Object.assign(new Error(message), { code: "RPC_SUPERVISOR_DISCONNECTED" });
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
function transientConnectionError(error) {
|
|
42
46
|
return error?.code === "EPIPE" || error?.code === "ECONNRESET";
|
|
43
47
|
}
|
|
@@ -93,7 +97,7 @@ export class RpcSupervisorClient {
|
|
|
93
97
|
const consume = frameReader((frame) => this.#receive(frame), (error) => this.#fail(error));
|
|
94
98
|
this.socket.on("data", consume);
|
|
95
99
|
this.socket.on("error", (error) => this.#fail(error));
|
|
96
|
-
this.socket.on("close", () => this.#fail(
|
|
100
|
+
this.socket.on("close", () => this.#fail(disconnectedError("RPC supervisor connection closed")));
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
#dispatchEvent(frame) {
|
|
@@ -148,7 +152,7 @@ export class RpcSupervisorClient {
|
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
#write(frame) {
|
|
151
|
-
if (!this.connected || this.socket.destroyed) throw
|
|
155
|
+
if (!this.connected || this.socket.destroyed) throw disconnectedError("RPC supervisor is not connected");
|
|
152
156
|
this.socket.write(encodeFrame(frame));
|
|
153
157
|
}
|
|
154
158
|
|
|
@@ -196,7 +200,7 @@ export class RpcSupervisorClient {
|
|
|
196
200
|
isCurrentVersion() { return protocolCurrent(this.state.version); }
|
|
197
201
|
|
|
198
202
|
request(type, payload = {}, { requestId = newRequestId() } = {}) {
|
|
199
|
-
if (!this.attached) return Promise.reject(
|
|
203
|
+
if (!this.attached) return Promise.reject(disconnectedError("RPC supervisor client is not attached"));
|
|
200
204
|
if (this.pending.has(requestId)) return this.pending.get(requestId).promise;
|
|
201
205
|
const result = deferred();
|
|
202
206
|
this.pending.set(requestId, result);
|
|
@@ -240,7 +244,7 @@ export class RpcSupervisorClient {
|
|
|
240
244
|
if (!this.connected) return;
|
|
241
245
|
this.socket.end();
|
|
242
246
|
this.socket.destroy();
|
|
243
|
-
this.#fail(
|
|
247
|
+
this.#fail(disconnectedError("RPC supervisor client closed"));
|
|
244
248
|
}
|
|
245
249
|
}
|
|
246
250
|
|