@firstpick/pi-package-webui 0.9.1 → 0.9.3
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/README.md +31 -9
- package/bin/pi-webui-launcher.mjs +23 -12
- package/bin/pi-webui.mjs +729 -93
- package/index.ts +266 -1
- package/lib/agent-run-adapters.mjs +500 -0
- package/lib/agent-run-protocol.mjs +262 -0
- package/lib/agent-run-registry.mjs +339 -0
- package/lib/git-workflow-preferences.mjs +18 -28
- package/lib/intercom-conversations.mjs +491 -0
- package/lib/intercom-transcript-filter.mjs +99 -0
- package/lib/resource-selection.mjs +140 -0
- package/lib/trust-boundaries.mjs +2 -0
- package/lib/ui-layout-settings.mjs +172 -28
- package/lib/update/package-layout.mjs +50 -0
- package/lib/update/plan.mjs +11 -0
- package/package.json +2 -2
- package/public/app.js +2276 -419
- package/public/index.html +142 -72
- package/public/service-worker.js +2 -1
- package/public/stream-output-controller.mjs +15 -0
- package/public/styles.css +764 -92
- package/public/syntax-highlight.mjs +622 -0
- package/tests/agent-run-adapters.test.mjs +217 -0
- package/tests/agent-run-launcher.test.mjs +41 -0
- package/tests/agent-run-protocol.test.mjs +82 -0
- package/tests/agent-run-registry.test.mjs +102 -0
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-deck-side-panels.spec.mjs +354 -0
- package/tests/browser/controls-layout.spec.mjs +122 -0
- package/tests/browser/file-tree-git-ignored.spec.mjs +113 -0
- package/tests/browser/interaction-continuity.spec.mjs +161 -0
- package/tests/browser/intercom-conversation-viewer.spec.mjs +355 -0
- package/tests/browser/mobile-foundation.spec.mjs +26 -0
- package/tests/browser/model-search-focus.spec.mjs +96 -0
- package/tests/browser/optimistic-prompt.spec.mjs +22 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +285 -66
- package/tests/browser/resource-profiles.spec.mjs +200 -0
- package/tests/browser/subagent-observability.spec.mjs +116 -0
- package/tests/codex-fast-mode-static.test.mjs +7 -6
- package/tests/common-options-submenus-interaction-static.test.mjs +2 -0
- package/tests/common-options-submenus-markup-static.test.mjs +1 -0
- package/tests/component-update-api-static.test.mjs +2 -1
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/composer-skill-tag-layout.test.mjs +32 -2
- package/tests/control-deck-component-updates-static.test.mjs +6 -0
- package/tests/control-deck-side-panels-static.test.mjs +68 -0
- package/tests/controls-layout-static.test.mjs +22 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +5 -5
- package/tests/file-tree-git-ignored-static.test.mjs +152 -0
- package/tests/file-tree-search-layout-static.test.mjs +2 -1
- package/tests/file-viewer-image-static.test.mjs +69 -0
- package/tests/fixtures/fake-pi.mjs +147 -12
- package/tests/foreground-transcript-catch-up-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +5 -5
- package/tests/git-panel-live-updates-static.test.mjs +3 -3
- package/tests/git-workflow-preferences.test.mjs +55 -6
- package/tests/http-endpoints-harness.test.mjs +295 -14
- package/tests/intercom-conversation-viewer-static.test.mjs +105 -0
- package/tests/intercom-conversations-http.test.mjs +252 -0
- package/tests/intercom-conversations.test.mjs +374 -0
- package/tests/intercom-main-transcript-suppression-static.test.mjs +52 -0
- package/tests/intercom-tag-layout-static.test.mjs +46 -0
- package/tests/intercom-transcript-filter.test.mjs +98 -0
- package/tests/main-output-loading-static.test.mjs +59 -0
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +6 -6
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +76 -42
- package/tests/native-parity.test.mjs +8 -7
- package/tests/open-issue-wizard-static.test.mjs +2 -2
- package/tests/optional-feature-migration-frontend.test.mjs +5 -5
- package/tests/optional-feature-resource-setup-static.test.mjs +29 -0
- package/tests/persistent-ui-layout-static.test.mjs +13 -13
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/resource-defaults-helper.test.mjs +60 -6
- package/tests/resource-selection.test.mjs +114 -0
- package/tests/resource-tui-extension.test.mjs +23 -0
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-context-menu-static.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +26 -16
- package/tests/side-panel-section-height-removal-static.test.mjs +4 -4
- package/tests/side-panel-section-reorder-static.test.mjs +16 -70
- package/tests/stream-output-controller.test.mjs +8 -0
- package/tests/stream-output-isolation-static.test.mjs +2 -2
- package/tests/streaming-ui-coupling.test.mjs +5 -0
- package/tests/subagent-gate-visibility.test.mjs +2 -1
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +32 -0
- package/tests/subagent-reliability-integration.test.mjs +183 -0
- package/tests/subagent-workflow-section-static.test.mjs +67 -0
- package/tests/subagents-helper.test.mjs +548 -5
- package/tests/syntax-highlight.test.mjs +235 -0
- package/tests/syntax-highlighting-static.test.mjs +84 -0
- package/tests/terminal-tabs-resize-static.test.mjs +35 -0
- package/tests/theme-customizer-static.test.mjs +5 -5
- package/tests/thinking-format-parser.test.mjs +64 -0
- package/tests/ui-layout-settings.test.mjs +104 -32
- package/tests/update-api-harness.test.mjs +24 -10
- package/tests/update-package-layout.test.mjs +38 -0
- package/tests/update-plan.test.mjs +11 -1
- package/tests/webui-settings-locking.test.mjs +33 -3
- package/webui-rpc-helper.mjs +700 -89
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const MAX_RESOURCE_NAME_LENGTH = 256;
|
|
2
|
+
const MAX_PROVIDER_LENGTH = 160;
|
|
3
|
+
const MAX_MODEL_ID_LENGTH = 512;
|
|
4
|
+
const MAX_MODEL_PROFILES = 512;
|
|
5
|
+
|
|
6
|
+
export function cleanResourceString(value, maxLength) {
|
|
7
|
+
return typeof value === "string" ? value.trim().slice(0, maxLength) : "";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function normalizeResourceNameList(value) {
|
|
11
|
+
if (!Array.isArray(value)) return null;
|
|
12
|
+
const names = [];
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
for (const item of value) {
|
|
15
|
+
const name = cleanResourceString(item, MAX_RESOURCE_NAME_LENGTH);
|
|
16
|
+
if (!name || seen.has(name)) continue;
|
|
17
|
+
seen.add(name);
|
|
18
|
+
names.push(name);
|
|
19
|
+
}
|
|
20
|
+
return names;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function resourceObject(value) {
|
|
24
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizeResourceSelection(value, key) {
|
|
28
|
+
const source = resourceObject(value);
|
|
29
|
+
return { ...source, [key]: normalizeResourceNameList(source[key]) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function normalizeModelProfiles(value) {
|
|
33
|
+
if (!Array.isArray(value)) return [];
|
|
34
|
+
const profiles = [];
|
|
35
|
+
const indexes = new Map();
|
|
36
|
+
for (const candidate of value.slice(0, MAX_MODEL_PROFILES)) {
|
|
37
|
+
const source = resourceObject(candidate);
|
|
38
|
+
const provider = cleanResourceString(source.provider, MAX_PROVIDER_LENGTH);
|
|
39
|
+
const modelId = cleanResourceString(source.modelId, MAX_MODEL_ID_LENGTH);
|
|
40
|
+
if (!provider || !modelId) continue;
|
|
41
|
+
const profile = {
|
|
42
|
+
...source,
|
|
43
|
+
provider,
|
|
44
|
+
modelId,
|
|
45
|
+
tools: normalizeResourceSelection(source.tools, "enabledTools"),
|
|
46
|
+
skills: normalizeResourceSelection(source.skills, "enabledSkills"),
|
|
47
|
+
};
|
|
48
|
+
if (profile.tools.enabledTools === null && profile.skills.enabledSkills === null) {
|
|
49
|
+
const existingIndex = indexes.get(`${provider}\0${modelId}`);
|
|
50
|
+
if (existingIndex !== undefined) {
|
|
51
|
+
profiles.splice(existingIndex, 1);
|
|
52
|
+
indexes.clear();
|
|
53
|
+
profiles.forEach((entry, index) => indexes.set(`${entry.provider}\0${entry.modelId}`, index));
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const key = `${provider}\0${modelId}`;
|
|
58
|
+
const existingIndex = indexes.get(key);
|
|
59
|
+
if (existingIndex === undefined) {
|
|
60
|
+
indexes.set(key, profiles.length);
|
|
61
|
+
profiles.push(profile);
|
|
62
|
+
} else {
|
|
63
|
+
profiles[existingIndex] = profile;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return profiles;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function normalizeResourceDefaults(value) {
|
|
70
|
+
const source = resourceObject(value);
|
|
71
|
+
return {
|
|
72
|
+
...source,
|
|
73
|
+
tools: normalizeResourceSelection(source.tools, "enabledTools"),
|
|
74
|
+
skills: normalizeResourceSelection(source.skills, "enabledSkills"),
|
|
75
|
+
modelProfiles: normalizeModelProfiles(source.modelProfiles),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function exactModelProfile(resourceDefaults, provider, modelId) {
|
|
80
|
+
if (!provider || !modelId) return null;
|
|
81
|
+
return normalizeModelProfiles(resourceDefaults?.modelProfiles)
|
|
82
|
+
.find((profile) => profile.provider === provider && profile.modelId === modelId) || null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function resolveResourceSelection(resourceDefaults, resourceType, provider, modelId, runtimeDefault = null) {
|
|
86
|
+
const selectionKey = resourceType === "tools" ? "enabledTools" : "enabledSkills";
|
|
87
|
+
const profile = exactModelProfile(resourceDefaults, provider, modelId);
|
|
88
|
+
const modelSelection = normalizeResourceNameList(profile?.[resourceType]?.[selectionKey]);
|
|
89
|
+
if (modelSelection !== null) return { names: modelSelection, source: "model" };
|
|
90
|
+
const globalSelection = normalizeResourceNameList(resourceDefaults?.[resourceType]?.[selectionKey]);
|
|
91
|
+
if (globalSelection !== null) return { names: globalSelection, source: "global" };
|
|
92
|
+
return { names: normalizeResourceNameList(runtimeDefault), source: "runtime" };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function branchResourceDirective(entryData, resourceType) {
|
|
96
|
+
const data = entryData && typeof entryData === "object" ? entryData : {};
|
|
97
|
+
if (data.version === 2 && data.mode === "inherit") return { pinned: false, names: null, legacyDisabledNames: null };
|
|
98
|
+
const selectionKey = resourceType === "tools" ? "enabledTools" : "enabledSkills";
|
|
99
|
+
const names = normalizeResourceNameList(data[selectionKey]);
|
|
100
|
+
if (names !== null) return { pinned: true, names, legacyDisabledNames: null };
|
|
101
|
+
if (resourceType === "skills") {
|
|
102
|
+
const disabled = normalizeResourceNameList(data.disabledSkills);
|
|
103
|
+
if (disabled !== null) return { pinned: true, names: null, legacyDisabledNames: disabled };
|
|
104
|
+
}
|
|
105
|
+
return { pinned: false, names: null, legacyDisabledNames: null };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function setExactModelProfile(resourceDefaults, providerValue, modelIdValue, resourceType, enabledNames) {
|
|
109
|
+
const provider = cleanResourceString(providerValue, MAX_PROVIDER_LENGTH);
|
|
110
|
+
const modelId = cleanResourceString(modelIdValue, MAX_MODEL_ID_LENGTH);
|
|
111
|
+
if (!provider || !modelId) throw new Error("Model resource profile requires an exact provider and model ID");
|
|
112
|
+
const selectionKey = resourceType === "tools" ? "enabledTools" : "enabledSkills";
|
|
113
|
+
const nextSelection = normalizeResourceNameList(enabledNames);
|
|
114
|
+
const normalized = normalizeResourceDefaults(resourceDefaults);
|
|
115
|
+
const profiles = normalized.modelProfiles.map((profile) => ({
|
|
116
|
+
...profile,
|
|
117
|
+
tools: { ...profile.tools },
|
|
118
|
+
skills: { ...profile.skills },
|
|
119
|
+
}));
|
|
120
|
+
const index = profiles.findIndex((profile) => profile.provider === provider && profile.modelId === modelId);
|
|
121
|
+
const profile = index >= 0 ? profiles[index] : {
|
|
122
|
+
provider,
|
|
123
|
+
modelId,
|
|
124
|
+
tools: { enabledTools: null },
|
|
125
|
+
skills: { enabledSkills: null },
|
|
126
|
+
};
|
|
127
|
+
profile[resourceType][selectionKey] = nextSelection;
|
|
128
|
+
if (profile.tools.enabledTools === null && profile.skills.enabledSkills === null) {
|
|
129
|
+
if (index >= 0) profiles.splice(index, 1);
|
|
130
|
+
} else if (index >= 0) profiles[index] = profile;
|
|
131
|
+
else profiles.push(profile);
|
|
132
|
+
return normalizeModelProfiles(profiles);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function preserveUnavailableResourceNames(previousNames, visibleNames, selectedVisibleNames) {
|
|
136
|
+
const visible = new Set(normalizeResourceNameList(visibleNames) || []);
|
|
137
|
+
const selected = normalizeResourceNameList(selectedVisibleNames) || [];
|
|
138
|
+
const unavailable = (normalizeResourceNameList(previousNames) || []).filter((name) => !visible.has(name));
|
|
139
|
+
return normalizeResourceNameList([...selected, ...unavailable]) || [];
|
|
140
|
+
}
|
package/lib/trust-boundaries.mjs
CHANGED
|
@@ -17,6 +17,8 @@ export const LOCALHOST_ONLY_POST_ROUTES = new Map([
|
|
|
17
17
|
["/api/remote-auth/settings", "Remote PIN authentication settings are only allowed from localhost"],
|
|
18
18
|
["/api/workflow-policy", "Workflow policy setup is only allowed from localhost"],
|
|
19
19
|
["/api/subagents/config", "Saving subagent launch-slot configuration is only allowed from localhost"],
|
|
20
|
+
["/api/subagents/cancel", "Cancelling subagent runs is only allowed from localhost"],
|
|
21
|
+
["/api/subagents/dismiss", "Dismissing retained subagent runs is only allowed from localhost"],
|
|
20
22
|
["/api/recovery/plan", "Opening recovery plans is only allowed from localhost"],
|
|
21
23
|
["/api/restart", "Restart is only allowed from localhost"],
|
|
22
24
|
["/api/update", "Updating Pi from the Web UI is only allowed from localhost"],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
|
|
3
|
-
export const UI_LAYOUT_VERSION =
|
|
3
|
+
export const UI_LAYOUT_VERSION = 2;
|
|
4
4
|
export const UI_LAYOUT_REQUEST_MAX_BYTES = 32 * 1024;
|
|
5
5
|
export const UI_LAYOUT_LIMITS = Object.freeze({
|
|
6
6
|
idLength: 256,
|
|
@@ -9,12 +9,20 @@ export const UI_LAYOUT_LIMITS = Object.freeze({
|
|
|
9
9
|
groups: 32,
|
|
10
10
|
gridColumns: 24,
|
|
11
11
|
gridSlots: 4096,
|
|
12
|
+
panelWidthMin: 320,
|
|
13
|
+
panelWidthMax: 4096,
|
|
14
|
+
panelWidthDefault: 384,
|
|
12
15
|
fileViewerWidthMin: 384,
|
|
13
16
|
fileViewerWidthMax: 4096,
|
|
17
|
+
terminalTabsSidebarWidthMin: 208,
|
|
18
|
+
terminalTabsSidebarWidthMax: 4096,
|
|
14
19
|
});
|
|
15
20
|
|
|
21
|
+
const LEGACY_UI_LAYOUT_VERSION = 1;
|
|
16
22
|
const UNSAFE_OBJECT_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
17
23
|
const TERMINAL_TAB_LAYOUTS = new Set(["top", "left"]);
|
|
24
|
+
const CONTROL_DECK_PLACEMENTS = new Set(["right", "left", "both"]);
|
|
25
|
+
const SIDES = ["left", "right"];
|
|
18
26
|
|
|
19
27
|
function objectValue(value) {
|
|
20
28
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
@@ -57,21 +65,85 @@ function nullable(value, validate) {
|
|
|
57
65
|
return value === null ? null : validate(value);
|
|
58
66
|
}
|
|
59
67
|
|
|
68
|
+
function validatePlacement(value) {
|
|
69
|
+
if (!CONTROL_DECK_PLACEMENTS.has(value)) invalid("layout.sidePanel.placement must be right, left, both, or null");
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function validateSectionLayout(value) {
|
|
74
|
+
const source = objectValue(value);
|
|
75
|
+
if (!source) invalid("layout.sidePanel.sectionLayout must be an object or null");
|
|
76
|
+
assertOnlyKeys(source, new Set(["order", "leftSectionIds"]), "layout.sidePanel.sectionLayout");
|
|
77
|
+
if (!own(source, "order") || !own(source, "leftSectionIds")) {
|
|
78
|
+
invalid("layout.sidePanel.sectionLayout must include order and leftSectionIds together");
|
|
79
|
+
}
|
|
80
|
+
const order = nullable(source.order, (entry) => boundedUniqueStringList(entry, "layout.sidePanel.sectionLayout.order"));
|
|
81
|
+
const leftSectionIds = nullable(source.leftSectionIds, (entry) => boundedUniqueStringList(entry, "layout.sidePanel.sectionLayout.leftSectionIds"));
|
|
82
|
+
if ((order === null) !== (leftSectionIds === null)) {
|
|
83
|
+
invalid("layout.sidePanel.sectionLayout order and leftSectionIds must both be arrays or both be null");
|
|
84
|
+
}
|
|
85
|
+
if (order !== null) {
|
|
86
|
+
const orderIds = new Set(order);
|
|
87
|
+
if (leftSectionIds.some((id) => !orderIds.has(id))) {
|
|
88
|
+
invalid("layout.sidePanel.sectionLayout.leftSectionIds entries must occur in order");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { order, leftSectionIds };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function validateBooleanSides(value, label, { partial = false } = {}) {
|
|
95
|
+
const source = objectValue(value);
|
|
96
|
+
if (!source) invalid(`${label} must be an object or null`);
|
|
97
|
+
assertOnlyKeys(source, new Set(SIDES), label);
|
|
98
|
+
if (partial && Object.keys(source).length === 0) invalid(`${label} must name at least one side`);
|
|
99
|
+
const result = {};
|
|
100
|
+
for (const side of SIDES) {
|
|
101
|
+
if (!partial || own(source, side)) {
|
|
102
|
+
const state = source[side] ?? null;
|
|
103
|
+
if (state !== null && typeof state !== "boolean") invalid(`${label}.${side} must be a boolean or null`);
|
|
104
|
+
result[side] = state;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function validatePanelWidth(value, label) {
|
|
111
|
+
if (!Number.isFinite(value) || value < UI_LAYOUT_LIMITS.panelWidthMin || value > UI_LAYOUT_LIMITS.panelWidthMax) {
|
|
112
|
+
invalid(`${label} must be between ${UI_LAYOUT_LIMITS.panelWidthMin} and ${UI_LAYOUT_LIMITS.panelWidthMax} pixels or null`);
|
|
113
|
+
}
|
|
114
|
+
return Math.round(value);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function validatePanelWidths(value, { partial = false } = {}) {
|
|
118
|
+
const source = objectValue(value);
|
|
119
|
+
if (!source) invalid("layout.sidePanel.panelWidths must be an object or null");
|
|
120
|
+
assertOnlyKeys(source, new Set(SIDES), "layout.sidePanel.panelWidths");
|
|
121
|
+
if (partial && Object.keys(source).length === 0) invalid("layout.sidePanel.panelWidths must name at least one side");
|
|
122
|
+
const result = {};
|
|
123
|
+
for (const side of SIDES) {
|
|
124
|
+
if (!partial || own(source, side)) {
|
|
125
|
+
result[side] = nullable(source[side] ?? null, (entry) => validatePanelWidth(entry, `layout.sidePanel.panelWidths.${side}`));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
60
131
|
function validateSidePanel(value, { partial = false } = {}) {
|
|
61
132
|
const source = objectValue(value);
|
|
62
133
|
if (!source) invalid("layout.sidePanel must be an object or null");
|
|
63
|
-
const fields = new Set(["
|
|
134
|
+
const fields = new Set(["placement", "sectionLayout", "collapsedSectionIds", "hiddenSectionIds", "collapsedPanels", "panelWidths"]);
|
|
64
135
|
assertOnlyKeys(source, fields, "layout.sidePanel");
|
|
65
136
|
if (partial && Object.keys(source).length === 0) invalid("layout.sidePanel must name at least one field");
|
|
66
137
|
const result = {};
|
|
67
|
-
|
|
138
|
+
if (!partial || own(source, "placement")) result.placement = nullable(source.placement ?? null, validatePlacement);
|
|
139
|
+
if (!partial || own(source, "sectionLayout")) result.sectionLayout = nullable(source.sectionLayout ?? null, validateSectionLayout);
|
|
140
|
+
for (const field of ["collapsedSectionIds", "hiddenSectionIds"]) {
|
|
68
141
|
if (!partial || own(source, field)) result[field] = nullable(source[field] ?? null, (entry) => boundedUniqueStringList(entry, `layout.sidePanel.${field}`));
|
|
69
142
|
}
|
|
70
|
-
if (!partial || own(source, "
|
|
71
|
-
|
|
72
|
-
if (collapsed !== null && typeof collapsed !== "boolean") invalid("layout.sidePanel.collapsed must be a boolean or null");
|
|
73
|
-
result.collapsed = collapsed;
|
|
143
|
+
if (!partial || own(source, "collapsedPanels")) {
|
|
144
|
+
result.collapsedPanels = nullable(source.collapsedPanels ?? null, (entry) => validateBooleanSides(entry, "layout.sidePanel.collapsedPanels", { partial }));
|
|
74
145
|
}
|
|
146
|
+
if (!partial || own(source, "panelWidths")) result.panelWidths = nullable(source.panelWidths ?? null, (entry) => validatePanelWidths(entry, { partial }));
|
|
75
147
|
return result;
|
|
76
148
|
}
|
|
77
149
|
|
|
@@ -146,7 +218,7 @@ function validateCustomGroups(value) {
|
|
|
146
218
|
function validateTerminalTabs(value, { partial = false } = {}) {
|
|
147
219
|
const source = objectValue(value);
|
|
148
220
|
if (!source) invalid("layout.terminalTabs must be an object or null");
|
|
149
|
-
assertOnlyKeys(source, new Set(["layout", "customGroups"]), "layout.terminalTabs");
|
|
221
|
+
assertOnlyKeys(source, new Set(["layout", "customGroups", "sidebarWidth"]), "layout.terminalTabs");
|
|
150
222
|
if (partial && Object.keys(source).length === 0) invalid("layout.terminalTabs must name at least one field");
|
|
151
223
|
const result = {};
|
|
152
224
|
if (!partial || own(source, "layout")) {
|
|
@@ -155,23 +227,40 @@ function validateTerminalTabs(value, { partial = false } = {}) {
|
|
|
155
227
|
result.layout = layout;
|
|
156
228
|
}
|
|
157
229
|
if (!partial || own(source, "customGroups")) result.customGroups = nullable(source.customGroups ?? null, validateCustomGroups);
|
|
230
|
+
if (!partial || own(source, "sidebarWidth")) {
|
|
231
|
+
result.sidebarWidth = nullable(source.sidebarWidth ?? null, (width) => validateBoundedWidth(
|
|
232
|
+
width,
|
|
233
|
+
"layout.terminalTabs.sidebarWidth",
|
|
234
|
+
UI_LAYOUT_LIMITS.terminalTabsSidebarWidthMin,
|
|
235
|
+
UI_LAYOUT_LIMITS.terminalTabsSidebarWidthMax,
|
|
236
|
+
));
|
|
237
|
+
}
|
|
158
238
|
return result;
|
|
159
239
|
}
|
|
160
240
|
|
|
161
|
-
function
|
|
162
|
-
if (!Number.isFinite(value) || value <
|
|
163
|
-
invalid(`layout.fileViewerWidth must be between ${UI_LAYOUT_LIMITS.fileViewerWidthMin} and ${UI_LAYOUT_LIMITS.fileViewerWidthMax} pixels or null`);
|
|
164
|
-
}
|
|
241
|
+
function validateBoundedWidth(value, label, min, max) {
|
|
242
|
+
if (!Number.isFinite(value) || value < min || value > max) invalid(`${label} must be between ${min} and ${max} pixels or null`);
|
|
165
243
|
return Math.round(value);
|
|
166
244
|
}
|
|
167
245
|
|
|
246
|
+
function validateFileViewerWidth(value) {
|
|
247
|
+
return validateBoundedWidth(value, "layout.fileViewerWidth", UI_LAYOUT_LIMITS.fileViewerWidthMin, UI_LAYOUT_LIMITS.fileViewerWidthMax);
|
|
248
|
+
}
|
|
249
|
+
|
|
168
250
|
export function defaultUiLayout() {
|
|
169
251
|
return {
|
|
170
252
|
version: UI_LAYOUT_VERSION,
|
|
171
|
-
sidePanel: {
|
|
253
|
+
sidePanel: {
|
|
254
|
+
placement: null,
|
|
255
|
+
sectionLayout: { order: null, leftSectionIds: null },
|
|
256
|
+
collapsedSectionIds: null,
|
|
257
|
+
hiddenSectionIds: null,
|
|
258
|
+
collapsedPanels: { left: null, right: null },
|
|
259
|
+
panelWidths: { left: null, right: null },
|
|
260
|
+
},
|
|
172
261
|
composerActions: { order: null, grid: null },
|
|
173
262
|
footerScopedModelOrder: null,
|
|
174
|
-
terminalTabs: { layout: null, customGroups: null },
|
|
263
|
+
terminalTabs: { layout: null, customGroups: null, sidebarWidth: null },
|
|
175
264
|
fileViewerWidth: null,
|
|
176
265
|
};
|
|
177
266
|
}
|
|
@@ -184,21 +273,12 @@ function softField(validate, fallback = null) {
|
|
|
184
273
|
}
|
|
185
274
|
}
|
|
186
275
|
|
|
187
|
-
|
|
188
|
-
const source = objectValue(value);
|
|
189
|
-
const defaults = defaultUiLayout();
|
|
190
|
-
if (!source || source.version !== UI_LAYOUT_VERSION) return defaults;
|
|
191
|
-
const sidePanel = objectValue(source.sidePanel);
|
|
276
|
+
function normalizeSharedLayoutFields(source, sidePanel) {
|
|
192
277
|
const composerActions = objectValue(source.composerActions);
|
|
193
278
|
const terminalTabs = objectValue(source.terminalTabs);
|
|
194
279
|
return {
|
|
195
280
|
version: UI_LAYOUT_VERSION,
|
|
196
|
-
sidePanel
|
|
197
|
-
sectionOrder: softField(() => nullable(sidePanel?.sectionOrder ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.sectionOrder"))),
|
|
198
|
-
collapsedSectionIds: softField(() => nullable(sidePanel?.collapsedSectionIds ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.collapsedSectionIds"))),
|
|
199
|
-
hiddenSectionIds: softField(() => nullable(sidePanel?.hiddenSectionIds ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.hiddenSectionIds"))),
|
|
200
|
-
collapsed: typeof sidePanel?.collapsed === "boolean" ? sidePanel.collapsed : null,
|
|
201
|
-
},
|
|
281
|
+
sidePanel,
|
|
202
282
|
composerActions: {
|
|
203
283
|
order: softField(() => nullable(composerActions?.order ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.composerActions.order"))),
|
|
204
284
|
grid: softField(() => nullable(composerActions?.grid ?? null, validateGrid)),
|
|
@@ -207,11 +287,68 @@ export function normalizeUiLayout(value) {
|
|
|
207
287
|
terminalTabs: {
|
|
208
288
|
layout: TERMINAL_TAB_LAYOUTS.has(terminalTabs?.layout) ? terminalTabs.layout : null,
|
|
209
289
|
customGroups: softField(() => nullable(terminalTabs?.customGroups ?? null, validateCustomGroups)),
|
|
290
|
+
sidebarWidth: softField(() => nullable(terminalTabs?.sidebarWidth ?? null, (width) => validateBoundedWidth(
|
|
291
|
+
width,
|
|
292
|
+
"uiLayout.terminalTabs.sidebarWidth",
|
|
293
|
+
UI_LAYOUT_LIMITS.terminalTabsSidebarWidthMin,
|
|
294
|
+
UI_LAYOUT_LIMITS.terminalTabsSidebarWidthMax,
|
|
295
|
+
))),
|
|
210
296
|
},
|
|
211
297
|
fileViewerWidth: softField(() => nullable(source.fileViewerWidth ?? null, validateFileViewerWidth)),
|
|
212
298
|
};
|
|
213
299
|
}
|
|
214
300
|
|
|
301
|
+
function normalizeSideValues(source, validate, fallback) {
|
|
302
|
+
const record = objectValue(source);
|
|
303
|
+
return Object.fromEntries(SIDES.map((side) => [side, softField(() => nullable(record?.[side] ?? null, (value) => validate(value, side)), fallback)]));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function normalizeVersionTwo(source) {
|
|
307
|
+
const sidePanel = objectValue(source.sidePanel);
|
|
308
|
+
return normalizeSharedLayoutFields(source, {
|
|
309
|
+
placement: CONTROL_DECK_PLACEMENTS.has(sidePanel?.placement) ? sidePanel.placement : null,
|
|
310
|
+
sectionLayout: softField(
|
|
311
|
+
() => sidePanel?.sectionLayout == null ? defaultUiLayout().sidePanel.sectionLayout : validateSectionLayout(sidePanel.sectionLayout),
|
|
312
|
+
defaultUiLayout().sidePanel.sectionLayout,
|
|
313
|
+
),
|
|
314
|
+
collapsedSectionIds: softField(() => nullable(sidePanel?.collapsedSectionIds ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.collapsedSectionIds"))),
|
|
315
|
+
hiddenSectionIds: softField(() => nullable(sidePanel?.hiddenSectionIds ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.hiddenSectionIds"))),
|
|
316
|
+
collapsedPanels: normalizeSideValues(sidePanel?.collapsedPanels, (value, side) => {
|
|
317
|
+
if (typeof value !== "boolean") invalid(`uiLayout.sidePanel.collapsedPanels.${side} must be a boolean or null`);
|
|
318
|
+
return value;
|
|
319
|
+
}, null),
|
|
320
|
+
panelWidths: normalizeSideValues(sidePanel?.panelWidths, (value, side) => validatePanelWidth(value, `uiLayout.sidePanel.panelWidths.${side}`), null),
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function migrateVersionOne(source, legacySidePanelWidth) {
|
|
325
|
+
const sidePanel = objectValue(source.sidePanel);
|
|
326
|
+
const order = softField(() => nullable(sidePanel?.sectionOrder ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.sectionOrder")));
|
|
327
|
+
const rightWidth = softField(
|
|
328
|
+
() => validatePanelWidth(legacySidePanelWidth, "interfacePreferences.sidePanelWidth"),
|
|
329
|
+
UI_LAYOUT_LIMITS.panelWidthDefault,
|
|
330
|
+
);
|
|
331
|
+
return normalizeSharedLayoutFields(source, {
|
|
332
|
+
placement: "right",
|
|
333
|
+
sectionLayout: order === null ? { order: null, leftSectionIds: null } : { order, leftSectionIds: [] },
|
|
334
|
+
collapsedSectionIds: softField(() => nullable(sidePanel?.collapsedSectionIds ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.collapsedSectionIds"))),
|
|
335
|
+
hiddenSectionIds: softField(() => nullable(sidePanel?.hiddenSectionIds ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.hiddenSectionIds"))),
|
|
336
|
+
collapsedPanels: {
|
|
337
|
+
left: false,
|
|
338
|
+
right: typeof sidePanel?.collapsed === "boolean" ? sidePanel.collapsed : false,
|
|
339
|
+
},
|
|
340
|
+
panelWidths: { left: UI_LAYOUT_LIMITS.panelWidthDefault, right: rightWidth },
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export function normalizeUiLayout(value, { legacySidePanelWidth = null } = {}) {
|
|
345
|
+
const source = objectValue(value);
|
|
346
|
+
if (!source) return defaultUiLayout();
|
|
347
|
+
if (source.version === UI_LAYOUT_VERSION) return normalizeVersionTwo(source);
|
|
348
|
+
if (source.version === LEGACY_UI_LAYOUT_VERSION) return migrateVersionOne(source, legacySidePanelWidth);
|
|
349
|
+
return defaultUiLayout();
|
|
350
|
+
}
|
|
351
|
+
|
|
215
352
|
export function validateUiLayoutPatch(value) {
|
|
216
353
|
const source = objectValue(value);
|
|
217
354
|
if (!source) invalid("layout must be an object");
|
|
@@ -234,9 +371,16 @@ export function mergeUiLayout(current, patch) {
|
|
|
234
371
|
const value = validateUiLayoutPatch(patch);
|
|
235
372
|
const merged = { ...base };
|
|
236
373
|
if (own(value, "sidePanel")) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
374
|
+
if (value.sidePanel === null) {
|
|
375
|
+
merged.sidePanel = defaultUiLayout().sidePanel;
|
|
376
|
+
} else {
|
|
377
|
+
merged.sidePanel = { ...base.sidePanel, ...value.sidePanel };
|
|
378
|
+
for (const field of ["collapsedPanels", "panelWidths"]) {
|
|
379
|
+
if (own(value.sidePanel, field) && value.sidePanel[field] !== null) {
|
|
380
|
+
merged.sidePanel[field] = { ...base.sidePanel[field], ...value.sidePanel[field] };
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
240
384
|
}
|
|
241
385
|
if (own(value, "composerActions")) merged.composerActions = value.composerActions === null ? defaultUiLayout().composerActions : value.composerActions;
|
|
242
386
|
if (own(value, "footerScopedModelOrder")) merged.footerScopedModelOrder = value.footerScopedModelOrder;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
function pathApi(platform) {
|
|
4
|
+
return platform === "win32" ? path.win32 : path.posix;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function exactPathInside(api, root, candidate) {
|
|
8
|
+
const relative = api.relative(api.resolve(root), api.resolve(candidate));
|
|
9
|
+
return relative === "" || (!relative.startsWith(`..${api.sep}`) && relative !== ".." && !api.isAbsolute(relative));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function sameExactPath(api, left, right) {
|
|
13
|
+
return exactPathInside(api, left, right) && exactPathInside(api, right, left);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Return the installation root that owns the nearest node_modules containing a package. */
|
|
17
|
+
export function packageOwnerRoot(packageRoot, { platform = process.platform } = {}) {
|
|
18
|
+
const api = pathApi(platform);
|
|
19
|
+
const resolved = api.resolve(String(packageRoot || ""));
|
|
20
|
+
if (!packageRoot) return "";
|
|
21
|
+
let cursor = resolved;
|
|
22
|
+
while (true) {
|
|
23
|
+
if (api.basename(cursor).toLowerCase() === "node_modules") return api.dirname(cursor);
|
|
24
|
+
const parent = api.dirname(cursor);
|
|
25
|
+
if (parent === cursor) return resolved;
|
|
26
|
+
cursor = parent;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Prove that a resolver-selected bundled package belongs to the Web UI package
|
|
32
|
+
* installation. Supports both package-local nesting and npm's normal hoisted
|
|
33
|
+
* sibling layout while refusing explicit, PATH, unrelated, and opaque roots.
|
|
34
|
+
*/
|
|
35
|
+
export function bundledPackageOwnership({ hostPackageRoot = "", packageRoot = "", source = "" } = {}, { platform = process.platform } = {}) {
|
|
36
|
+
if (source !== "bundled" || !hostPackageRoot || !packageRoot) return null;
|
|
37
|
+
const api = pathApi(platform);
|
|
38
|
+
const hostRoot = api.resolve(hostPackageRoot);
|
|
39
|
+
const bundledRoot = api.resolve(packageRoot);
|
|
40
|
+
const nested = exactPathInside(api, api.join(hostRoot, "node_modules"), bundledRoot);
|
|
41
|
+
const hostOwnerRoot = packageOwnerRoot(hostRoot, { platform });
|
|
42
|
+
const bundledOwnerRoot = packageOwnerRoot(bundledRoot, { platform });
|
|
43
|
+
const hoisted = Boolean(hostOwnerRoot && bundledOwnerRoot && sameExactPath(api, hostOwnerRoot, bundledOwnerRoot));
|
|
44
|
+
if (!nested && !hoisted) return null;
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
ownerRoot: bundledOwnerRoot,
|
|
47
|
+
packageRoot: bundledRoot,
|
|
48
|
+
layout: nested ? "nested" : "hoisted",
|
|
49
|
+
});
|
|
50
|
+
}
|
package/lib/update/plan.mjs
CHANGED
|
@@ -114,6 +114,17 @@ export async function createUpdatePlan({
|
|
|
114
114
|
return Object.freeze({ ...unsigned, digest });
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
export function assertActionableUpdatePlan(plan) {
|
|
118
|
+
if (Array.isArray(plan?.targets) && plan.targets.length > 0) return true;
|
|
119
|
+
const refusals = Array.isArray(plan?.refusals) ? plan.refusals.map((item) => clean(item?.id)).filter(Boolean) : [];
|
|
120
|
+
const error = new Error(refusals.length
|
|
121
|
+
? `Update plan has no accepted targets; automatic update was refused for: ${refusals.join(", ")}.`
|
|
122
|
+
: "Update plan has no accepted targets.");
|
|
123
|
+
error.code = "UPDATE_PLAN_NO_TARGETS";
|
|
124
|
+
error.statusCode = 409;
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
|
|
117
128
|
export function assertUpdatePlanDigest(plan, suppliedDigest) {
|
|
118
129
|
const expected = digestUpdatePlan(plan);
|
|
119
130
|
if (!/^[a-f0-9]{64}$/.test(clean(suppliedDigest)) || suppliedDigest !== plan?.digest || suppliedDigest !== expected) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
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",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"pi-webui": "./bin/pi-webui-launcher.mjs"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"check": "node --check public/app.js && node --check lib/app-runner-terminal.mjs && node --check public/middle-button-drag-scroll.mjs && node --check public/stream-output-controller.mjs && node --check public/theme-contract.mjs && 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-launcher.mjs && node --check bin/pi-webui-update-supervisor.mjs && node --check lib/update/supervisor.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",
|
|
33
|
+
"check": "node --check public/app.js && node --check lib/app-runner-terminal.mjs && node --check public/middle-button-drag-scroll.mjs && node --check public/stream-output-controller.mjs && node --check public/theme-contract.mjs && node --check public/transcript-renderer.mjs && node --check public/syntax-highlight.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-launcher.mjs && node --check bin/pi-webui-update-supervisor.mjs && node --check lib/update/supervisor.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",
|
|
34
34
|
"test": "node tests/run-all.mjs",
|
|
35
35
|
"test:browser": "playwright test"
|
|
36
36
|
},
|