@firstpick/pi-package-webui 0.11.1 → 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 +151 -12
- package/README.md +34 -6
- package/TECHNICAL.md +75 -8
- package/bin/pi-webui.mjs +5390 -11423
- package/index.ts +10 -3
- 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 +4 -4
- 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 -3886
- 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/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-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-source.test.mjs +4 -3
- 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-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 +21 -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-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
|
@@ -1,566 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const WEBUI_SETTINGS_LOCK_TIMEOUT_MS = 2_000;
|
|
37
|
-
const WEBUI_SETTINGS_LOCK_RETRY_MS = 25;
|
|
38
|
-
const WEBUI_SETTINGS_LOCK_INVALID_RECORD_GRACE_MS = 1_000;
|
|
39
|
-
export const WEBUI_SIDE_PANEL_WIDTH_MIN_PX = 320;
|
|
40
|
-
export const WEBUI_SIDE_PANEL_WIDTH_MAX_PX = 4096;
|
|
41
|
-
const webuiSettingsUpdateQueues = new Map();
|
|
42
|
-
|
|
43
|
-
function cleanBoundedString(value, maxLength = 512) {
|
|
44
|
-
return typeof value === "string" ? value.trim().slice(0, maxLength) : "";
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function choice(value, choices, fallback) {
|
|
48
|
-
const clean = cleanBoundedString(value, 64);
|
|
49
|
-
return choices.includes(clean) ? clean : fallback;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function defaultGitWorkflowPreferences() {
|
|
53
|
-
return {
|
|
54
|
-
setupVersion: 0,
|
|
55
|
-
generation: {
|
|
56
|
-
provider: "",
|
|
57
|
-
modelId: "",
|
|
58
|
-
thinkingLevel: "low",
|
|
59
|
-
unavailablePolicy: "ask",
|
|
60
|
-
fallback: {
|
|
61
|
-
provider: "",
|
|
62
|
-
modelId: "",
|
|
63
|
-
thinkingLevel: "low",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
commit: {
|
|
67
|
-
language: "en",
|
|
68
|
-
defaultVariant: "short",
|
|
69
|
-
scope: "auto",
|
|
70
|
-
},
|
|
71
|
-
stagingPolicy: "review",
|
|
72
|
-
reviewProcessEnabled: true,
|
|
73
|
-
deliveryMode: "ask",
|
|
74
|
-
verificationPolicy: "ask",
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function normalizeGitWorkflowPreferences(value) {
|
|
79
|
-
const defaults = defaultGitWorkflowPreferences();
|
|
80
|
-
const provider = cleanBoundedString(value?.generation?.provider, 160);
|
|
81
|
-
const modelId = cleanBoundedString(value?.generation?.modelId, 512);
|
|
82
|
-
const fallbackProvider = cleanBoundedString(value?.generation?.fallback?.provider, 160);
|
|
83
|
-
const fallbackModelId = cleanBoundedString(value?.generation?.fallback?.modelId, 512);
|
|
84
|
-
return {
|
|
85
|
-
setupVersion: provider && modelId ? GIT_WORKFLOW_SETUP_VERSION : 0,
|
|
86
|
-
generation: {
|
|
87
|
-
provider,
|
|
88
|
-
modelId,
|
|
89
|
-
thinkingLevel: choice(value?.generation?.thinkingLevel, GIT_WORKFLOW_THINKING_LEVELS, defaults.generation.thinkingLevel),
|
|
90
|
-
unavailablePolicy: choice(value?.generation?.unavailablePolicy, GIT_WORKFLOW_UNAVAILABLE_POLICIES, defaults.generation.unavailablePolicy),
|
|
91
|
-
fallback: {
|
|
92
|
-
provider: fallbackProvider,
|
|
93
|
-
modelId: fallbackModelId,
|
|
94
|
-
thinkingLevel: choice(value?.generation?.fallback?.thinkingLevel, GIT_WORKFLOW_THINKING_LEVELS, defaults.generation.fallback.thinkingLevel),
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
commit: {
|
|
98
|
-
language: choice(value?.commit?.language, GIT_WORKFLOW_LANGUAGES, defaults.commit.language),
|
|
99
|
-
defaultVariant: choice(value?.commit?.defaultVariant, GIT_WORKFLOW_DEFAULT_VARIANTS, defaults.commit.defaultVariant),
|
|
100
|
-
scope: choice(value?.commit?.scope, GIT_WORKFLOW_SCOPE_POLICIES, defaults.commit.scope),
|
|
101
|
-
},
|
|
102
|
-
stagingPolicy: choice(value?.stagingPolicy, GIT_WORKFLOW_STAGING_POLICIES, defaults.stagingPolicy),
|
|
103
|
-
reviewProcessEnabled: typeof value?.reviewProcessEnabled === "boolean" ? value.reviewProcessEnabled : defaults.reviewProcessEnabled,
|
|
104
|
-
deliveryMode: choice(value?.deliveryMode, GIT_WORKFLOW_DELIVERY_MODES, defaults.deliveryMode),
|
|
105
|
-
verificationPolicy: choice(value?.verificationPolicy, GIT_WORKFLOW_VERIFICATION_POLICIES, defaults.verificationPolicy),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function mergeGitWorkflowPreferences(current, patch) {
|
|
110
|
-
const base = normalizeGitWorkflowPreferences(current);
|
|
111
|
-
return normalizeGitWorkflowPreferences({
|
|
112
|
-
...base,
|
|
113
|
-
...(patch || {}),
|
|
114
|
-
generation: {
|
|
115
|
-
...base.generation,
|
|
116
|
-
...(patch?.generation || {}),
|
|
117
|
-
fallback: { ...base.generation.fallback, ...(patch?.generation?.fallback || {}) },
|
|
118
|
-
},
|
|
119
|
-
commit: { ...base.commit, ...(patch?.commit || {}) },
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function isGitWorkflowSetupComplete(preferences) {
|
|
124
|
-
const normalized = normalizeGitWorkflowPreferences(preferences);
|
|
125
|
-
return normalized.setupVersion === GIT_WORKFLOW_SETUP_VERSION && !!normalized.generation.provider && !!normalized.generation.modelId;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function gitWorkflowPreferencesSummary(preferences) {
|
|
129
|
-
const value = normalizeGitWorkflowPreferences(preferences);
|
|
130
|
-
const model = isGitWorkflowSetupComplete(value) ? `${value.generation.provider}/${value.generation.modelId}` : "not configured";
|
|
131
|
-
const fallback = value.generation.fallback.provider && value.generation.fallback.modelId
|
|
132
|
-
? `${value.generation.fallback.provider}/${value.generation.fallback.modelId} · ${value.generation.fallback.thinkingLevel}`
|
|
133
|
-
: "disabled";
|
|
134
|
-
return [
|
|
135
|
-
`Model: ${model}`,
|
|
136
|
-
`Thinking: ${value.generation.thinkingLevel}`,
|
|
137
|
-
`Fallback: ${fallback}`,
|
|
138
|
-
`Commit: ${value.commit.language} · ${value.commit.defaultVariant} · scope ${value.commit.scope}`,
|
|
139
|
-
`Staging: ${value.stagingPolicy}`,
|
|
140
|
-
`Review process: ${value.reviewProcessEnabled ? "enabled" : "disabled"}`,
|
|
141
|
-
`Delivery: ${value.deliveryMode}`,
|
|
142
|
-
`Verification: ${value.verificationPolicy}`,
|
|
143
|
-
].join("\n");
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function webuiSettingsFile(env = process.env) {
|
|
147
|
-
if (env[WEBUI_SETTINGS_FILE_ENV]) return path.resolve(String(env[WEBUI_SETTINGS_FILE_ENV]).replace(/^~(?=$|[\\/])/, homedir()));
|
|
148
|
-
return path.join(homedir(), ".pi", "webui", "settings.json");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function legacyWebuiSettingsFile(env = process.env) {
|
|
152
|
-
const configRoot = env.XDG_CONFIG_HOME || path.join(homedir(), ".config");
|
|
153
|
-
return path.join(configRoot, "pi-webui", "settings.json");
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export { normalizeResourceDefaults } from "./resource-selection.mjs";
|
|
157
|
-
|
|
158
|
-
export function normalizeInterfacePreferences(value) {
|
|
159
|
-
const rawSidePanelWidth = value?.sidePanelWidth;
|
|
160
|
-
const sidePanelWidth = rawSidePanelWidth === null || rawSidePanelWidth === undefined ? Number.NaN : Number(rawSidePanelWidth);
|
|
161
|
-
return {
|
|
162
|
-
sidePanelWidth: Number.isFinite(sidePanelWidth)
|
|
163
|
-
? Math.max(WEBUI_SIDE_PANEL_WIDTH_MIN_PX, Math.min(WEBUI_SIDE_PANEL_WIDTH_MAX_PX, Math.round(sidePanelWidth)))
|
|
164
|
-
: null,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function settingsObject(value) {
|
|
169
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function normalizedSettingsVersion(value) {
|
|
173
|
-
const stored = Number.isInteger(value?.version) ? value.version : 0;
|
|
174
|
-
return Math.max(WEBUI_SETTINGS_VERSION, stored, value?.subagentLaunchSlots !== undefined ? 5 : 0);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function normalizeWebuiSettings(value) {
|
|
178
|
-
const source = settingsObject(value);
|
|
179
|
-
const storedVersion = Number.isInteger(source.version) ? source.version : 0;
|
|
180
|
-
const resourceDefaultsSource = storedVersion >= 8
|
|
181
|
-
? source.resourceDefaults
|
|
182
|
-
: { ...settingsObject(source.resourceDefaults), modelProfiles: [] };
|
|
183
|
-
const interfacePreferences = normalizeInterfacePreferences(source.interfacePreferences);
|
|
184
|
-
const legacyLayoutSource = source.uiLayout === undefined
|
|
185
|
-
&& interfacePreferences.sidePanelWidth !== null
|
|
186
|
-
&& (!Number.isInteger(source.version) || source.version < WEBUI_SETTINGS_VERSION)
|
|
187
|
-
? { version: 1 }
|
|
188
|
-
: source.uiLayout;
|
|
189
|
-
return {
|
|
190
|
-
...source,
|
|
191
|
-
version: normalizedSettingsVersion(source),
|
|
192
|
-
remoteAuthEnabled: source.remoteAuthEnabled === true,
|
|
193
|
-
appendSystemPromptPath: normalizeAppendSystemPromptPath(source.appendSystemPromptPath),
|
|
194
|
-
appendSystemPromptRootPath: normalizeAppendSystemPromptRootPath(source.appendSystemPromptRootPath),
|
|
195
|
-
outputModeDefault: normalizeOutputMode(source.outputModeDefault, OUTPUT_MODE_NORMAL),
|
|
196
|
-
gitWorkflow: normalizeGitWorkflowPreferences(source.gitWorkflow),
|
|
197
|
-
resourceDefaults: normalizeResourceDefaults(resourceDefaultsSource),
|
|
198
|
-
interfacePreferences,
|
|
199
|
-
uiLayout: normalizeUiLayout(legacyLayoutSource, { legacySidePanelWidth: interfacePreferences.sidePanelWidth }),
|
|
200
|
-
subagentLaunchSlots: normalizeSubagentLaunchSlots(source.subagentLaunchSlots),
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function settingsReadError(storageFile, error) {
|
|
205
|
-
const wrapped = new Error(`Cannot read Pi Web UI settings at ${storageFile}: ${error instanceof Error ? error.message : String(error)}`);
|
|
206
|
-
wrapped.code = "WEBUI_SETTINGS_READ_FAILED";
|
|
207
|
-
wrapped.cause = error;
|
|
208
|
-
return wrapped;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
async function readRawWebuiSettings(storageFile, { missing = {} } = {}) {
|
|
212
|
-
let text;
|
|
213
|
-
try {
|
|
214
|
-
text = await readFile(storageFile, "utf8");
|
|
215
|
-
} catch (error) {
|
|
216
|
-
if (error?.code === "ENOENT") return missing;
|
|
217
|
-
throw settingsReadError(storageFile, error);
|
|
218
|
-
}
|
|
219
|
-
try {
|
|
220
|
-
const parsed = JSON.parse(text);
|
|
221
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new TypeError("settings must contain a JSON object");
|
|
222
|
-
return parsed;
|
|
223
|
-
} catch (error) {
|
|
224
|
-
throw settingsReadError(storageFile, error);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function isDefaultSettingsTarget(storageFile, env = process.env) {
|
|
229
|
-
return !env[WEBUI_SETTINGS_FILE_ENV] && path.resolve(storageFile) === path.resolve(webuiSettingsFile(env));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async function ensurePrivateSettingsDirectory(storageFile) {
|
|
233
|
-
await mkdir(path.dirname(storageFile), { recursive: true, mode: 0o700 });
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function lockDirectoryFor(storageFile) {
|
|
237
|
-
return `${storageFile}.lock`;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function lockOwnerIsDead(pid) {
|
|
241
|
-
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
242
|
-
try {
|
|
243
|
-
process.kill(pid, 0);
|
|
244
|
-
return false;
|
|
245
|
-
} catch (error) {
|
|
246
|
-
return error?.code === "ESRCH";
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function settingsLockRecordNameMetadata(name) {
|
|
251
|
-
const match = name.match(/^(\d+)-(\d+)-[^/]+\.json$/);
|
|
252
|
-
if (!match) return {};
|
|
253
|
-
const ownerPid = Number(match[1]);
|
|
254
|
-
const createdAt = Number(match[2]);
|
|
255
|
-
return {
|
|
256
|
-
ownerPid: Number.isSafeInteger(ownerPid) && ownerPid > 0 ? ownerPid : undefined,
|
|
257
|
-
createdAt: Number.isSafeInteger(createdAt) && createdAt > 0 ? createdAt : undefined,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
async function readSettingsLockRecords(lockDirectory) {
|
|
262
|
-
const names = (await readdir(lockDirectory)).filter((name) => name.endsWith(".json")).sort();
|
|
263
|
-
const records = await Promise.all(names.map(async (name) => {
|
|
264
|
-
const recordFile = path.join(lockDirectory, name);
|
|
265
|
-
const nameMetadata = settingsLockRecordNameMetadata(name);
|
|
266
|
-
try {
|
|
267
|
-
const [value, fileStat] = await Promise.all([
|
|
268
|
-
readFile(recordFile, "utf8").then((text) => JSON.parse(text)),
|
|
269
|
-
stat(recordFile),
|
|
270
|
-
]);
|
|
271
|
-
const valid = Number.isSafeInteger(value?.pid)
|
|
272
|
-
&& value.pid > 0
|
|
273
|
-
&& typeof value?.token === "string"
|
|
274
|
-
&& value.token.length > 0
|
|
275
|
-
&& ["pending", "active"].includes(value?.state);
|
|
276
|
-
const createdAt = Number.isSafeInteger(value?.createdAt) && value.createdAt > 0
|
|
277
|
-
? value.createdAt
|
|
278
|
-
: nameMetadata.createdAt;
|
|
279
|
-
return {
|
|
280
|
-
...value,
|
|
281
|
-
ownerPid: nameMetadata.ownerPid,
|
|
282
|
-
createdAt,
|
|
283
|
-
name,
|
|
284
|
-
recordFile,
|
|
285
|
-
mtimeMs: fileStat.mtimeMs,
|
|
286
|
-
valid,
|
|
287
|
-
};
|
|
288
|
-
} catch (error) {
|
|
289
|
-
if (error?.code === "ENOENT") return undefined;
|
|
290
|
-
const fileStat = await stat(recordFile).catch(() => undefined);
|
|
291
|
-
return { ...nameMetadata, name, recordFile, mtimeMs: fileStat?.mtimeMs, valid: false };
|
|
292
|
-
}
|
|
293
|
-
}));
|
|
294
|
-
return records.filter(Boolean);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
async function renameWithWindowsRetry(source, target) {
|
|
298
|
-
let lastError;
|
|
299
|
-
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
300
|
-
try {
|
|
301
|
-
await rename(source, target);
|
|
302
|
-
return;
|
|
303
|
-
} catch (error) {
|
|
304
|
-
lastError = error;
|
|
305
|
-
if (process.platform !== "win32" || !["EACCES", "EBUSY", "EPERM"].includes(error?.code)) throw error;
|
|
306
|
-
await delay(25 * (attempt + 1));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
throw lastError;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async function writeSettingsLockRecord(recordFile, value) {
|
|
313
|
-
const temporaryFile = `${recordFile}.${process.pid}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
314
|
-
let handle;
|
|
315
|
-
try {
|
|
316
|
-
handle = await open(temporaryFile, "wx", 0o600);
|
|
317
|
-
await handle.writeFile(`${JSON.stringify(value)}\n`, "utf8");
|
|
318
|
-
await handle.sync();
|
|
319
|
-
await handle.close();
|
|
320
|
-
handle = undefined;
|
|
321
|
-
await renameWithWindowsRetry(temporaryFile, recordFile);
|
|
322
|
-
} catch (error) {
|
|
323
|
-
await handle?.close().catch(() => {});
|
|
324
|
-
await rm(temporaryFile, { force: true }).catch(() => {});
|
|
325
|
-
throw error;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
async function releaseSettingsLock(lockDirectory, recordFile) {
|
|
330
|
-
await rm(recordFile, { force: true });
|
|
331
|
-
await rmdir(lockDirectory).catch((error) => {
|
|
332
|
-
if (error?.code !== "ENOENT" && error?.code !== "ENOTEMPTY" && error?.code !== "EEXIST") throw error;
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
export async function withWebuiSettingsLock(storageFile, operation, {
|
|
337
|
-
timeoutMs = WEBUI_SETTINGS_LOCK_TIMEOUT_MS,
|
|
338
|
-
retryMs = WEBUI_SETTINGS_LOCK_RETRY_MS,
|
|
339
|
-
} = {}) {
|
|
340
|
-
await ensurePrivateSettingsDirectory(storageFile);
|
|
341
|
-
const lockDirectory = lockDirectoryFor(storageFile);
|
|
342
|
-
await mkdir(lockDirectory, { mode: 0o700 }).catch((error) => {
|
|
343
|
-
if (error?.code !== "EEXIST") throw error;
|
|
344
|
-
});
|
|
345
|
-
const createdAt = Date.now();
|
|
346
|
-
const token = `${process.pid}-${createdAt}-${Math.random().toString(16).slice(2)}`;
|
|
347
|
-
const recordFile = path.join(lockDirectory, `${token}.json`);
|
|
348
|
-
const ownRecord = { pid: process.pid, token, state: "pending", createdAt };
|
|
349
|
-
let handle;
|
|
350
|
-
try {
|
|
351
|
-
handle = await open(recordFile, "wx", 0o600);
|
|
352
|
-
await handle.writeFile(`${JSON.stringify(ownRecord)}\n`, "utf8");
|
|
353
|
-
await handle.sync();
|
|
354
|
-
await handle.close();
|
|
355
|
-
handle = undefined;
|
|
356
|
-
} catch (error) {
|
|
357
|
-
await handle?.close().catch(() => {});
|
|
358
|
-
await rm(recordFile, { force: true }).catch(() => {});
|
|
359
|
-
throw error;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
const deadline = Date.now() + Math.max(0, timeoutMs);
|
|
363
|
-
let acquired = false;
|
|
364
|
-
try {
|
|
365
|
-
while (!acquired) {
|
|
366
|
-
let records = await readSettingsLockRecords(lockDirectory);
|
|
367
|
-
let removedStaleRecord = false;
|
|
368
|
-
for (const record of records) {
|
|
369
|
-
const ownerPid = record.valid ? record.pid : record.ownerPid;
|
|
370
|
-
const ownerIsDead = lockOwnerIsDead(ownerPid);
|
|
371
|
-
const recordAgeMs = Math.max(
|
|
372
|
-
Number.isFinite(record.mtimeMs) ? Date.now() - record.mtimeMs : 0,
|
|
373
|
-
Number.isSafeInteger(record.createdAt) ? Date.now() - record.createdAt : 0,
|
|
374
|
-
);
|
|
375
|
-
const invalidRecordIsStale = !record.valid
|
|
376
|
-
&& (ownerIsDead || recordAgeMs >= WEBUI_SETTINGS_LOCK_INVALID_RECORD_GRACE_MS);
|
|
377
|
-
if ((record.valid && ownerIsDead) || invalidRecordIsStale) {
|
|
378
|
-
await rm(record.recordFile, { force: true });
|
|
379
|
-
removedStaleRecord = true;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
if (removedStaleRecord) continue;
|
|
383
|
-
|
|
384
|
-
const active = records.filter((record) => record.valid && record.state === "active");
|
|
385
|
-
if (active.length === 1 && active[0].token === token) {
|
|
386
|
-
acquired = true;
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
if (active.length === 0 && records[0]?.token === token && records[0]?.valid) {
|
|
390
|
-
ownRecord.state = "active";
|
|
391
|
-
await writeSettingsLockRecord(recordFile, ownRecord);
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
if (Date.now() >= deadline) {
|
|
395
|
-
const timeoutError = new Error("Timed out waiting for the Pi Web UI settings lock");
|
|
396
|
-
timeoutError.code = "WEBUI_SETTINGS_LOCK_TIMEOUT";
|
|
397
|
-
throw timeoutError;
|
|
398
|
-
}
|
|
399
|
-
await delay(Math.max(1, Math.min(retryMs, deadline - Date.now())));
|
|
400
|
-
}
|
|
401
|
-
return await operation();
|
|
402
|
-
} finally {
|
|
403
|
-
await releaseSettingsLock(lockDirectory, recordFile);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
async function syncDirectoryBestEffort(directory) {
|
|
408
|
-
let handle;
|
|
409
|
-
try {
|
|
410
|
-
handle = await open(directory, "r");
|
|
411
|
-
await handle.sync();
|
|
412
|
-
} catch {
|
|
413
|
-
// Directory fsync is unsupported on some platforms/filesystems.
|
|
414
|
-
} finally {
|
|
415
|
-
await handle?.close().catch(() => {});
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
async function writePrivateAtomicSettings(storageFile, value) {
|
|
420
|
-
await ensurePrivateSettingsDirectory(storageFile);
|
|
421
|
-
const temporaryFile = path.join(
|
|
422
|
-
path.dirname(storageFile),
|
|
423
|
-
`.${path.basename(storageFile)}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`,
|
|
424
|
-
);
|
|
425
|
-
let handle;
|
|
426
|
-
try {
|
|
427
|
-
handle = await open(temporaryFile, "wx", 0o600);
|
|
428
|
-
await handle.writeFile(`${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
429
|
-
await handle.sync();
|
|
430
|
-
await handle.close();
|
|
431
|
-
handle = undefined;
|
|
432
|
-
await renameWithWindowsRetry(temporaryFile, storageFile);
|
|
433
|
-
await syncDirectoryBestEffort(path.dirname(storageFile));
|
|
434
|
-
} catch (error) {
|
|
435
|
-
await handle?.close().catch(() => {});
|
|
436
|
-
await rm(temporaryFile, { force: true }).catch(() => {});
|
|
437
|
-
throw error;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
export async function migrateLegacyWebuiSettings(targetFile, legacyFile) {
|
|
442
|
-
if (path.resolve(targetFile) === path.resolve(legacyFile)) return false;
|
|
443
|
-
try {
|
|
444
|
-
await readFile(targetFile, "utf8");
|
|
445
|
-
return false;
|
|
446
|
-
} catch (error) {
|
|
447
|
-
if (error?.code !== "ENOENT") throw settingsReadError(targetFile, error);
|
|
448
|
-
}
|
|
449
|
-
let legacy;
|
|
450
|
-
try {
|
|
451
|
-
legacy = await readRawWebuiSettings(legacyFile, { missing: null });
|
|
452
|
-
} catch {
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
if (!legacy) return false;
|
|
456
|
-
return withWebuiSettingsLock(targetFile, async () => {
|
|
457
|
-
try {
|
|
458
|
-
await readFile(targetFile, "utf8");
|
|
459
|
-
return false;
|
|
460
|
-
} catch (error) {
|
|
461
|
-
if (error?.code !== "ENOENT") throw settingsReadError(targetFile, error);
|
|
462
|
-
}
|
|
463
|
-
const { settings, persistLaunchSlots, persistedUiLayout } = mergeWebuiSettings(legacy, {});
|
|
464
|
-
const persisted = { ...settings, uiLayout: persistedUiLayout };
|
|
465
|
-
if (!persistLaunchSlots) delete persisted.subagentLaunchSlots;
|
|
466
|
-
await writePrivateAtomicSettings(targetFile, persisted);
|
|
467
|
-
return true;
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
async function ensureDefaultSettingsMigration(storageFile, env = process.env) {
|
|
472
|
-
if (!isDefaultSettingsTarget(storageFile, env)) return false;
|
|
473
|
-
return migrateLegacyWebuiSettings(storageFile, legacyWebuiSettingsFile(env));
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
export async function readWebuiSettings(storageFile = webuiSettingsFile(), { reportInvalidOutputMode = false } = {}) {
|
|
477
|
-
await ensureDefaultSettingsMigration(storageFile);
|
|
478
|
-
const raw = await readRawWebuiSettings(storageFile);
|
|
479
|
-
const normalized = normalizeWebuiSettings(raw);
|
|
480
|
-
if (reportInvalidOutputMode && raw.outputModeDefault !== undefined && normalized.outputModeDefault !== raw.outputModeDefault) {
|
|
481
|
-
console.warn(`Invalid persisted Web UI output mode ${JSON.stringify(raw.outputModeDefault)}; using ${OUTPUT_MODE_NORMAL}.`);
|
|
482
|
-
}
|
|
483
|
-
return normalized;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
function mergeWebuiSettings(rawCurrent, patch) {
|
|
487
|
-
const raw = settingsObject(rawCurrent);
|
|
488
|
-
const current = normalizeWebuiSettings(raw);
|
|
489
|
-
const patchValue = settingsObject(patch);
|
|
490
|
-
const hasLaunchSlotPatch = Object.hasOwn(patchValue, "subagentLaunchSlots");
|
|
491
|
-
const persistLaunchSlots = raw.subagentLaunchSlots !== undefined || hasLaunchSlotPatch;
|
|
492
|
-
const source = {
|
|
493
|
-
...raw,
|
|
494
|
-
...patchValue,
|
|
495
|
-
gitWorkflow: patchValue.gitWorkflow
|
|
496
|
-
? mergeGitWorkflowPreferences(current.gitWorkflow, patchValue.gitWorkflow)
|
|
497
|
-
: current.gitWorkflow,
|
|
498
|
-
resourceDefaults: patchValue.resourceDefaults
|
|
499
|
-
? {
|
|
500
|
-
...current.resourceDefaults,
|
|
501
|
-
...patchValue.resourceDefaults,
|
|
502
|
-
tools: { ...current.resourceDefaults.tools, ...(patchValue.resourceDefaults.tools || {}) },
|
|
503
|
-
skills: { ...current.resourceDefaults.skills, ...(patchValue.resourceDefaults.skills || {}) },
|
|
504
|
-
}
|
|
505
|
-
: current.resourceDefaults,
|
|
506
|
-
interfacePreferences: patchValue.interfacePreferences
|
|
507
|
-
? { ...current.interfacePreferences, ...patchValue.interfacePreferences }
|
|
508
|
-
: current.interfacePreferences,
|
|
509
|
-
uiLayout: Object.hasOwn(patchValue, "uiLayout")
|
|
510
|
-
? normalizeUiLayout(patchValue.uiLayout)
|
|
511
|
-
: current.uiLayout,
|
|
512
|
-
};
|
|
513
|
-
if (persistLaunchSlots) {
|
|
514
|
-
source.subagentLaunchSlots = hasLaunchSlotPatch
|
|
515
|
-
? normalizeSubagentLaunchSlots(patchValue.subagentLaunchSlots)
|
|
516
|
-
: normalizeSubagentLaunchSlots(raw.subagentLaunchSlots);
|
|
517
|
-
source.version = Math.max(5, Number.isInteger(raw.version) ? raw.version : 0);
|
|
518
|
-
} else {
|
|
519
|
-
delete source.subagentLaunchSlots;
|
|
520
|
-
source.version = Math.max(WEBUI_SETTINGS_VERSION, Number.isInteger(raw.version) ? raw.version : 0);
|
|
521
|
-
}
|
|
522
|
-
const settings = normalizeWebuiSettings(source);
|
|
523
|
-
const rawLayoutVersion = Number.isInteger(raw.uiLayout?.version) ? raw.uiLayout.version : 0;
|
|
524
|
-
const persistedUiLayout = !Object.hasOwn(patchValue, "uiLayout") && rawLayoutVersion > settings.uiLayout.version
|
|
525
|
-
? raw.uiLayout
|
|
526
|
-
: settings.uiLayout;
|
|
527
|
-
return { settings, persistLaunchSlots, persistedUiLayout };
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
async function writeMergedWebuiSettings(rawCurrent, patch, storageFile) {
|
|
531
|
-
const { settings, persistLaunchSlots, persistedUiLayout } = mergeWebuiSettings(rawCurrent, patch);
|
|
532
|
-
const persisted = { ...settings, uiLayout: persistedUiLayout };
|
|
533
|
-
if (!persistLaunchSlots) delete persisted.subagentLaunchSlots;
|
|
534
|
-
await writePrivateAtomicSettings(storageFile, persisted);
|
|
535
|
-
return settings;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Applies a settings patch against the latest on-disk snapshot and writes it
|
|
540
|
-
* atomically. Returning undefined from the updater avoids an unnecessary write.
|
|
541
|
-
*/
|
|
542
|
-
export function updateWebuiSettings(updater, storageFile = webuiSettingsFile()) {
|
|
543
|
-
const queueKey = path.resolve(storageFile);
|
|
544
|
-
const previous = webuiSettingsUpdateQueues.get(queueKey) || Promise.resolve();
|
|
545
|
-
const currentUpdate = previous.catch(() => {}).then(async () => {
|
|
546
|
-
await ensureDefaultSettingsMigration(storageFile);
|
|
547
|
-
return withWebuiSettingsLock(storageFile, async () => {
|
|
548
|
-
const rawCurrent = await readRawWebuiSettings(storageFile);
|
|
549
|
-
const current = normalizeWebuiSettings(rawCurrent);
|
|
550
|
-
const patch = await updater(current);
|
|
551
|
-
if (patch === undefined) return current;
|
|
552
|
-
return writeMergedWebuiSettings(rawCurrent, patch, storageFile);
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
webuiSettingsUpdateQueues.set(queueKey, currentUpdate);
|
|
556
|
-
return currentUpdate.finally(() => {
|
|
557
|
-
if (webuiSettingsUpdateQueues.get(queueKey) === currentUpdate) webuiSettingsUpdateQueues.delete(queueKey);
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
export async function writeWebuiSettings(patch, storageFile = webuiSettingsFile()) {
|
|
562
|
-
return updateWebuiSettings(() => patch, storageFile);
|
|
563
|
-
}
|
|
1
|
+
import { readWebuiSettings, webuiSettingsFile, writeWebuiSettings } from "./server/settings-store.mjs";
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
GIT_WORKFLOW_SETUP_VERSION,
|
|
5
|
+
GIT_WORKFLOW_THINKING_LEVELS,
|
|
6
|
+
GIT_WORKFLOW_LANGUAGES,
|
|
7
|
+
GIT_WORKFLOW_DEFAULT_VARIANTS,
|
|
8
|
+
GIT_WORKFLOW_SCOPE_POLICIES,
|
|
9
|
+
GIT_WORKFLOW_STAGING_POLICIES,
|
|
10
|
+
GIT_WORKFLOW_DELIVERY_MODES,
|
|
11
|
+
GIT_WORKFLOW_VERIFICATION_POLICIES,
|
|
12
|
+
GIT_WORKFLOW_UNAVAILABLE_POLICIES,
|
|
13
|
+
supportedGitWorkflowThinkingLevels,
|
|
14
|
+
defaultGitWorkflowPreferences,
|
|
15
|
+
normalizeGitWorkflowPreferences,
|
|
16
|
+
mergeGitWorkflowPreferences,
|
|
17
|
+
isGitWorkflowSetupComplete,
|
|
18
|
+
gitWorkflowPreferencesSummary,
|
|
19
|
+
} from "./git-workflow-preference-values.mjs";
|
|
20
|
+
export {
|
|
21
|
+
WEBUI_SIDE_PANEL_WIDTH_MIN_PX,
|
|
22
|
+
WEBUI_SIDE_PANEL_WIDTH_MAX_PX,
|
|
23
|
+
webuiSettingsFile,
|
|
24
|
+
legacyWebuiSettingsFile,
|
|
25
|
+
normalizeResourceDefaults,
|
|
26
|
+
normalizeInterfacePreferences,
|
|
27
|
+
normalizeWebuiSettings,
|
|
28
|
+
withWebuiSettingsLock,
|
|
29
|
+
migrateLegacyWebuiSettings,
|
|
30
|
+
validatedShellRolloutCohort,
|
|
31
|
+
initializeWebuiShellRollout,
|
|
32
|
+
readWebuiSettings,
|
|
33
|
+
updateWebuiSettings,
|
|
34
|
+
writeWebuiSettings,
|
|
35
|
+
} from "./server/settings-store.mjs";
|
|
564
36
|
|
|
565
37
|
export async function readGitWorkflowPreferences(storageFile = webuiSettingsFile()) {
|
|
566
38
|
return (await readWebuiSettings(storageFile)).gitWorkflow;
|