@firstpick/pi-package-webui 0.8.2 → 0.8.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 +9 -3
- package/bin/pi-webui.mjs +97 -12
- package/lib/git-workflow-preferences.mjs +246 -19
- package/lib/thinking-stream-recovery.mjs +156 -0
- package/lib/ui-layout-settings.mjs +254 -0
- package/package.json +5 -3
- package/public/app.js +1618 -41
- package/public/index.html +35 -14
- package/public/service-worker.js +1 -1
- package/public/styles.css +324 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/composer-action-grid-reorder.spec.mjs +303 -0
- package/tests/browser/feature-decision-output-popup.spec.mjs +156 -0
- package/tests/browser/interaction-continuity.spec.mjs +29 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +744 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +63 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/feature-decision-output-popup-static.test.mjs +172 -0
- package/tests/fixtures/fake-pi.mjs +51 -1
- package/tests/git-workflow-preferences.test.mjs +4 -2
- package/tests/http-endpoints-harness.test.mjs +88 -1
- package/tests/interaction-state-stability-static.test.mjs +3 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- 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 +32 -15
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +267 -0
- package/tests/questionnaire-dialog.test.mjs +511 -0
- package/tests/queue-edit-reorder-static.test.mjs +1 -0
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +1 -0
- package/tests/side-panel-section-reorder-static.test.mjs +3 -3
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/thinking-stream-recovery.test.mjs +88 -0
- package/tests/ui-layout-settings.test.mjs +92 -0
- package/tests/webui-settings-locking.test.mjs +159 -0
package/public/app.js
CHANGED
|
@@ -91,6 +91,8 @@ const elements = {
|
|
|
91
91
|
composerRow: $(".composer-row"),
|
|
92
92
|
composerActionsButton: $("#composerActionsButton"),
|
|
93
93
|
composerActionsPanel: $("#composerActionsPanel"),
|
|
94
|
+
composerActionGridGuide: $("#composerActionGridGuide"),
|
|
95
|
+
composerActionOrderStatus: $("#composerActionOrderStatus"),
|
|
94
96
|
promptInput: $("#promptInput"),
|
|
95
97
|
mobileFailedSendRecovery: $("#mobileFailedSendRecovery"),
|
|
96
98
|
mobileFailedSendRetryButton: $("#mobileFailedSendRetryButton"),
|
|
@@ -106,6 +108,9 @@ const elements = {
|
|
|
106
108
|
busyPromptBehaviorMenu: $("#busyPromptBehaviorMenu"),
|
|
107
109
|
sessionSkillTags: $("#sessionSkillTags"),
|
|
108
110
|
featureCategoryTag: $("#featureCategoryTag"),
|
|
111
|
+
featureDecisionDialog: $("#featureDecisionDialog"),
|
|
112
|
+
featureDecisionDialogOutput: $("#featureDecisionDialogOutput"),
|
|
113
|
+
featureDecisionDialogCloseButton: $("#featureDecisionDialogCloseButton"),
|
|
109
114
|
conversationModeChip: $("#conversationModeChip"),
|
|
110
115
|
workflowModeChip: $("#workflowModeChip"),
|
|
111
116
|
skillEditorDialog: $("#skillEditorDialog"),
|
|
@@ -302,6 +307,7 @@ const elements = {
|
|
|
302
307
|
issueWizardBotHint: $("#issueWizardBotHint"),
|
|
303
308
|
stateDetails: $("#stateDetails"),
|
|
304
309
|
subagentsStatus: $("#subagentsStatus"),
|
|
310
|
+
subagentsAutoClearButton: $("#subagentsAutoClearButton"),
|
|
305
311
|
subagentsClearFinishedButton: $("#subagentsClearFinishedButton"),
|
|
306
312
|
subagentsBox: $("#subagentsBox"),
|
|
307
313
|
subagentCountBadge: $("#subagentCountBadge"),
|
|
@@ -493,6 +499,12 @@ let sidePanelContextMenuState = null;
|
|
|
493
499
|
let sidePanelSectionPointerDrag = null;
|
|
494
500
|
let sidePanelSectionLastDragOverKey = "";
|
|
495
501
|
let sidePanelSectionSuppressClickUntil = 0;
|
|
502
|
+
let composerActionPointerDrag = null;
|
|
503
|
+
let composerActionLastDragOverKey = "";
|
|
504
|
+
let composerActionSuppressClickUntil = 0;
|
|
505
|
+
let composerActionSlotLayout = new Map();
|
|
506
|
+
let composerActionLayoutColumns = 0;
|
|
507
|
+
let composerActionLayoutRestoreFrame = null;
|
|
496
508
|
let fileTreeDragState = null;
|
|
497
509
|
let fileViewerResizeState = null;
|
|
498
510
|
let sidePanelResizeState = null;
|
|
@@ -560,6 +572,7 @@ const supervisorGapWarnings = new Set();
|
|
|
560
572
|
const supervisorContinuityRefreshes = new Map();
|
|
561
573
|
const supervisorEnvelopeWarnings = new Set();
|
|
562
574
|
let activeDialog = null;
|
|
575
|
+
let activeDialogCancel = null;
|
|
563
576
|
let activeConfirmationResolve = null;
|
|
564
577
|
let activeWorkspaceReplacementResolve = null;
|
|
565
578
|
let workspaceLoadPickerFocusReturn = null;
|
|
@@ -667,6 +680,7 @@ let latestSubagents = null;
|
|
|
667
680
|
let subagentsError = null;
|
|
668
681
|
let subagentsLoading = false;
|
|
669
682
|
let subagentsClearingFinished = false;
|
|
683
|
+
let subagentAutoClearEnabled = false;
|
|
670
684
|
let refreshSubagentsTimer = null;
|
|
671
685
|
const dismissedSubagentGateKeys = new Set();
|
|
672
686
|
let subagentOverlaySelection = null;
|
|
@@ -809,6 +823,9 @@ const SIDE_PANEL_SECTION_STORAGE_KEY = "pi-webui-side-panel-sections-collapsed";
|
|
|
809
823
|
const SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY = "pi-webui-side-panel-sections-hidden";
|
|
810
824
|
const SIDE_PANEL_SECTION_ORDER_STORAGE_KEY = "pi-webui-side-panel-section-order-v1";
|
|
811
825
|
const SIDE_PANEL_SECTION_POINTER_DRAG_THRESHOLD_PX = 6;
|
|
826
|
+
const COMPOSER_ACTION_ORDER_STORAGE_KEY = "pi-webui-composer-action-order-v1";
|
|
827
|
+
const COMPOSER_ACTION_LAYOUT_STORAGE_KEY = "pi-webui-composer-action-layout-v2";
|
|
828
|
+
const COMPOSER_ACTION_POINTER_DRAG_THRESHOLD_PX = 6;
|
|
812
829
|
const TAB_STORAGE_KEY = "pi-webui-active-tab";
|
|
813
830
|
const PATH_FAST_PICKS_STORAGE_KEY = "pi-webui-path-fast-picks";
|
|
814
831
|
const AGENT_DONE_NOTIFICATIONS_STORAGE_KEY = "pi-webui-agent-done-notifications";
|
|
@@ -824,6 +841,7 @@ const BUSY_PROMPT_BEHAVIOR_STORAGE_KEY = "pi-webui-busy-prompt-behavior";
|
|
|
824
841
|
const SKILL_USAGE_STORAGE_KEY = "pi-webui-skill-usage-v1";
|
|
825
842
|
const TERMINAL_TABS_LAYOUT_STORAGE_KEY = "pi-webui-terminal-tabs-layout";
|
|
826
843
|
const SUBAGENT_OPEN_MODE_STORAGE_KEY = "pi-webui-subagent-open-mode";
|
|
844
|
+
const SUBAGENT_AUTO_CLEAR_STORAGE_KEY = "pi-webui-subagent-auto-clear";
|
|
827
845
|
const TERMINAL_CUSTOM_GROUPS_STORAGE_KEY = "pi-webui-terminal-custom-groups-v1";
|
|
828
846
|
const TERMINAL_TAB_DRAG_MIME = "application/x-pi-terminal-tab-id";
|
|
829
847
|
const FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY = "pi-webui-footer-scoped-model-order-v1";
|
|
@@ -921,7 +939,10 @@ const WORKFLOW_INSPECTOR_PAYLOAD_PREFIX = "WORKFLOW_RPC_PAYLOAD ";
|
|
|
921
939
|
const WORKFLOW_INSPECTOR_PAYLOAD_TYPE = "firstpick.pi-extension-workflows.inspector";
|
|
922
940
|
const WORKFLOW_INSPECTOR_PAYLOAD_VERSION = 1;
|
|
923
941
|
const WORKFLOW_MODE_STATUS_KEY = "workflow-mode";
|
|
942
|
+
const FEATURE_DECISION_OUTPUT_STATUS_KEY = "feature-decision-output";
|
|
924
943
|
const FEATURE_CATEGORY_STATUS_KEY = "feature-category";
|
|
944
|
+
const FEATURE_DECISION_PAYLOAD_MAX_CHARS = 4096;
|
|
945
|
+
const FEATURE_DECISION_REASON_MAX_CHARS = 500;
|
|
925
946
|
const WORKFLOW_MODE_RPC_WIDGET_KEY = "workflow-mode:rpc";
|
|
926
947
|
const WORKFLOW_MODE_RPC_PAYLOAD_PREFIX = "WORKFLOW_MODE_RPC_PAYLOAD ";
|
|
927
948
|
const WORKFLOW_MODE_RPC_PAYLOAD_TYPE = "firstpick.pi-extension-workflows.mode";
|
|
@@ -2134,6 +2155,8 @@ function receiveMobileNavigationTarget(value) {
|
|
|
2134
2155
|
syncMobileShellRoot();
|
|
2135
2156
|
const statusEntries = new Map();
|
|
2136
2157
|
const featureCategoryByTab = new Map();
|
|
2158
|
+
const featureDecisionOutputByTab = new Map();
|
|
2159
|
+
let featureDecisionDialogTabId = null;
|
|
2137
2160
|
const widgets = new Map();
|
|
2138
2161
|
const widgetsByTab = new Map();
|
|
2139
2162
|
const todoProgressWidgetExpandedByTab = new Map();
|
|
@@ -2177,6 +2200,7 @@ const optionalFeatureAvailability = {
|
|
|
2177
2200
|
todoProgressWidget: false,
|
|
2178
2201
|
tuiToolsCommand: false,
|
|
2179
2202
|
remoteWebui: false,
|
|
2203
|
+
questionnaire: false,
|
|
2180
2204
|
naturalConversation: false,
|
|
2181
2205
|
codexFastMode: false,
|
|
2182
2206
|
themeBundle: false,
|
|
@@ -2276,6 +2300,14 @@ const OPTIONAL_FEATURES = [
|
|
|
2276
2300
|
capabilityLabel: "/remote",
|
|
2277
2301
|
description: "Trusted-LAN QR helper for opening the Web UI from mobile browsers.",
|
|
2278
2302
|
},
|
|
2303
|
+
{
|
|
2304
|
+
id: "questionnaire",
|
|
2305
|
+
label: "Native questionnaires",
|
|
2306
|
+
packageName: "@firstpick/pi-package-questionnaire",
|
|
2307
|
+
capabilityLabel: "questionnaire tool in /tools",
|
|
2308
|
+
description: "Native TUI and WebUI single- or multi-select question series with Other answers and resumable clarification.",
|
|
2309
|
+
manageWith: "tools",
|
|
2310
|
+
},
|
|
2279
2311
|
{
|
|
2280
2312
|
id: "naturalConversation",
|
|
2281
2313
|
label: "Natural Conversation",
|
|
@@ -2724,7 +2756,7 @@ const OPTIONAL_FEATURE_SECTIONS = [
|
|
|
2724
2756
|
id: "widgets-native-parity",
|
|
2725
2757
|
label: "UI widgets & native parity",
|
|
2726
2758
|
description: "Status widgets, dashboards, themes, and browser access to terminal-native controls.",
|
|
2727
|
-
featureIds: ["tuiSkillsCommand", "todoProgressWidget", "tuiToolsCommand", "gitFooterStatus", "statsCommand", "themeBundle"],
|
|
2759
|
+
featureIds: ["tuiSkillsCommand", "todoProgressWidget", "tuiToolsCommand", "questionnaire", "gitFooterStatus", "statsCommand", "themeBundle"],
|
|
2728
2760
|
},
|
|
2729
2761
|
{
|
|
2730
2762
|
id: "conversation",
|
|
@@ -3415,6 +3447,7 @@ function persistSidePanelSectionOrder() {
|
|
|
3415
3447
|
} catch {
|
|
3416
3448
|
// Ignore storage failures; ordering should still work for this page load.
|
|
3417
3449
|
}
|
|
3450
|
+
markDurableUiLayoutDirty("sidePanel", "sectionOrder");
|
|
3418
3451
|
}
|
|
3419
3452
|
|
|
3420
3453
|
function restoreSidePanelSectionOrder() {
|
|
@@ -3545,6 +3578,7 @@ function persistSidePanelSectionState() {
|
|
|
3545
3578
|
} catch {
|
|
3546
3579
|
// Ignore storage failures; section toggles should still work for this page load.
|
|
3547
3580
|
}
|
|
3581
|
+
markDurableUiLayoutDirty("sidePanel", "collapsedSectionIds");
|
|
3548
3582
|
}
|
|
3549
3583
|
|
|
3550
3584
|
function readStoredSidePanelSectionHiddenIds() {
|
|
@@ -3567,6 +3601,7 @@ function persistSidePanelSectionVisibility() {
|
|
|
3567
3601
|
} catch {
|
|
3568
3602
|
// Ignore storage failures; visibility toggles should still work for this page load.
|
|
3569
3603
|
}
|
|
3604
|
+
markDurableUiLayoutDirty("sidePanel", "hiddenSectionIds");
|
|
3570
3605
|
}
|
|
3571
3606
|
|
|
3572
3607
|
function setSidePanelSectionVisible(record, visible, { persist = true } = {}) {
|
|
@@ -3695,6 +3730,481 @@ function bindSidePanelSectionToggles() {
|
|
|
3695
3730
|
}
|
|
3696
3731
|
}
|
|
3697
3732
|
|
|
3733
|
+
function composerActionRecords() {
|
|
3734
|
+
return Array.from(elements.composerRow?.querySelectorAll("[data-composer-action-id]") || [])
|
|
3735
|
+
.map((root, domIndex) => {
|
|
3736
|
+
const id = root.dataset.composerActionId || "";
|
|
3737
|
+
const focusTarget = root.matches("button") ? root : root.querySelector("button");
|
|
3738
|
+
const rawStoredOrder = root.style.getPropertyValue("--composer-action-order");
|
|
3739
|
+
const storedOrder = Number(rawStoredOrder);
|
|
3740
|
+
const order = rawStoredOrder !== "" && Number.isFinite(storedOrder) ? storedOrder : domIndex;
|
|
3741
|
+
const span = Number(root.dataset.composerActionSpan) === 2 ? 2 : 1;
|
|
3742
|
+
return { id, root, focusTarget, domIndex, order, span };
|
|
3743
|
+
})
|
|
3744
|
+
.filter((record) => record.id && record.focusTarget);
|
|
3745
|
+
}
|
|
3746
|
+
|
|
3747
|
+
function orderedComposerActionRecords({ visibleOnly = false } = {}) {
|
|
3748
|
+
return composerActionRecords()
|
|
3749
|
+
.filter(({ root }) => !visibleOnly || (!root.hidden && root.getClientRects().length > 0))
|
|
3750
|
+
.sort((a, b) => a.order - b.order || a.domIndex - b.domIndex);
|
|
3751
|
+
}
|
|
3752
|
+
|
|
3753
|
+
function readStoredComposerActionOrder() {
|
|
3754
|
+
try {
|
|
3755
|
+
const parsed = JSON.parse(localStorage.getItem(COMPOSER_ACTION_ORDER_STORAGE_KEY) || "[]");
|
|
3756
|
+
return Array.isArray(parsed) ? [...new Set(parsed.filter((id) => typeof id === "string" && id.trim()))] : [];
|
|
3757
|
+
} catch {
|
|
3758
|
+
return [];
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
|
|
3762
|
+
function applyComposerActionOrder(orderIds) {
|
|
3763
|
+
const records = composerActionRecords();
|
|
3764
|
+
const knownIds = new Set(records.map(({ id }) => id));
|
|
3765
|
+
const completeOrder = [
|
|
3766
|
+
...new Set(orderIds.filter((id) => knownIds.has(id))),
|
|
3767
|
+
...records.map(({ id }) => id).filter((id) => !orderIds.includes(id)),
|
|
3768
|
+
];
|
|
3769
|
+
const rank = new Map(completeOrder.map((id, index) => [id, index]));
|
|
3770
|
+
for (const record of records) record.root.style.setProperty("--composer-action-order", String(rank.get(record.id)));
|
|
3771
|
+
return completeOrder;
|
|
3772
|
+
}
|
|
3773
|
+
|
|
3774
|
+
function restoreComposerActionOrder() {
|
|
3775
|
+
if (composerActionPointerDrag?.active) return;
|
|
3776
|
+
applyComposerActionOrder(readStoredComposerActionOrder());
|
|
3777
|
+
}
|
|
3778
|
+
|
|
3779
|
+
function persistComposerActionOrder() {
|
|
3780
|
+
try {
|
|
3781
|
+
localStorage.setItem(COMPOSER_ACTION_ORDER_STORAGE_KEY, JSON.stringify(orderedComposerActionRecords().map(({ id }) => id)));
|
|
3782
|
+
} catch {
|
|
3783
|
+
// Ignore storage failures; ordering should still work for this page load.
|
|
3784
|
+
}
|
|
3785
|
+
markDurableUiLayoutDirty("composerActions");
|
|
3786
|
+
}
|
|
3787
|
+
|
|
3788
|
+
function composerActionGridColumnCount() {
|
|
3789
|
+
const row = elements.composerRow;
|
|
3790
|
+
const style = getComputedStyle(row);
|
|
3791
|
+
const rawMinWidth = style.getPropertyValue("--composer-action-cell-min-width").trim();
|
|
3792
|
+
const numericMinWidth = Number.parseFloat(rawMinWidth);
|
|
3793
|
+
const rootFontSize = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
3794
|
+
const rowFontSize = Number.parseFloat(style.fontSize) || rootFontSize;
|
|
3795
|
+
const minWidth = rawMinWidth.endsWith("rem")
|
|
3796
|
+
? numericMinWidth * rootFontSize
|
|
3797
|
+
: rawMinWidth.endsWith("em")
|
|
3798
|
+
? numericMinWidth * rowFontSize
|
|
3799
|
+
: numericMinWidth;
|
|
3800
|
+
const gap = Number.parseFloat(style.columnGap || style.gap) || 0;
|
|
3801
|
+
const availableWidth = row.clientWidth || row.getBoundingClientRect().width;
|
|
3802
|
+
if (!Number.isFinite(minWidth) || minWidth <= 0 || !Number.isFinite(availableWidth) || availableWidth <= 0) return 1;
|
|
3803
|
+
return Math.max(1, Math.floor((availableWidth + gap) / (minWidth + gap)));
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
function readStoredComposerActionLayout() {
|
|
3807
|
+
try {
|
|
3808
|
+
const parsed = JSON.parse(localStorage.getItem(COMPOSER_ACTION_LAYOUT_STORAGE_KEY) || "null");
|
|
3809
|
+
if (!parsed || parsed.version !== 2 || !Number.isInteger(parsed.columns) || parsed.columns < 1 || !parsed.positions || typeof parsed.positions !== "object") return null;
|
|
3810
|
+
const positions = new Map();
|
|
3811
|
+
for (const [id, slot] of Object.entries(parsed.positions)) {
|
|
3812
|
+
if (typeof id === "string" && id && Number.isInteger(slot) && slot >= 0) positions.set(id, slot);
|
|
3813
|
+
}
|
|
3814
|
+
return { columns: parsed.columns, positions };
|
|
3815
|
+
} catch {
|
|
3816
|
+
return null;
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
function composerActionSlotCanFit(record, slot, layout = composerActionSlotLayout, columns = composerActionLayoutColumns) {
|
|
3821
|
+
if (!record || !Number.isInteger(slot) || slot < 0 || columns < 1) return false;
|
|
3822
|
+
const column = slot % columns;
|
|
3823
|
+
if (column + record.span > columns) return false;
|
|
3824
|
+
const row = Math.floor(slot / columns);
|
|
3825
|
+
for (const [otherId, otherSlot] of layout) {
|
|
3826
|
+
if (otherId === record.id) continue;
|
|
3827
|
+
const other = composerActionRecords().find(({ id, root }) => id === otherId && !root.hidden && root.getClientRects().length > 0);
|
|
3828
|
+
if (!other || Math.floor(otherSlot / columns) !== row) continue;
|
|
3829
|
+
const otherColumn = otherSlot % columns;
|
|
3830
|
+
if (column < otherColumn + other.span && otherColumn < column + record.span) return false;
|
|
3831
|
+
}
|
|
3832
|
+
return true;
|
|
3833
|
+
}
|
|
3834
|
+
|
|
3835
|
+
function applyComposerActionSlotLayout() {
|
|
3836
|
+
for (const record of composerActionRecords()) {
|
|
3837
|
+
const slot = composerActionSlotLayout.get(record.id);
|
|
3838
|
+
if (!Number.isInteger(slot) || composerActionLayoutColumns < 1 || record.root.hidden) {
|
|
3839
|
+
record.root.style.removeProperty("--composer-action-grid-column");
|
|
3840
|
+
record.root.style.removeProperty("--composer-action-grid-row");
|
|
3841
|
+
continue;
|
|
3842
|
+
}
|
|
3843
|
+
record.root.style.setProperty("--composer-action-grid-column", String((slot % composerActionLayoutColumns) + 1));
|
|
3844
|
+
record.root.style.setProperty("--composer-action-grid-row", String(Math.floor(slot / composerActionLayoutColumns) + 1));
|
|
3845
|
+
}
|
|
3846
|
+
}
|
|
3847
|
+
|
|
3848
|
+
function persistComposerActionSlotLayout() {
|
|
3849
|
+
if (composerActionLayoutColumns < 1 || !composerActionSlotLayout.size) return;
|
|
3850
|
+
try {
|
|
3851
|
+
localStorage.setItem(COMPOSER_ACTION_LAYOUT_STORAGE_KEY, JSON.stringify({
|
|
3852
|
+
version: 2,
|
|
3853
|
+
columns: composerActionLayoutColumns,
|
|
3854
|
+
positions: Object.fromEntries(composerActionSlotLayout),
|
|
3855
|
+
}));
|
|
3856
|
+
} catch {
|
|
3857
|
+
// Ignore storage failures; sparse placement should still work for this page load.
|
|
3858
|
+
}
|
|
3859
|
+
markDurableUiLayoutDirty("composerActions");
|
|
3860
|
+
}
|
|
3861
|
+
|
|
3862
|
+
function remapComposerActionSlot(record, slot, sourceColumns, targetColumns) {
|
|
3863
|
+
const sourceRow = Math.floor(slot / sourceColumns);
|
|
3864
|
+
const sourceColumn = slot % sourceColumns;
|
|
3865
|
+
const sourceMaxColumn = Math.max(0, sourceColumns - record.span);
|
|
3866
|
+
const targetMaxColumn = Math.max(0, targetColumns - record.span);
|
|
3867
|
+
const relativeColumn = sourceMaxColumn > 0 ? Math.min(sourceColumn, sourceMaxColumn) / sourceMaxColumn : 0;
|
|
3868
|
+
return sourceRow * targetColumns + Math.round(relativeColumn * targetMaxColumn);
|
|
3869
|
+
}
|
|
3870
|
+
|
|
3871
|
+
function nearestAvailableComposerActionSlot(record, preferredSlot, layout, columns) {
|
|
3872
|
+
if (record.span > columns) return null;
|
|
3873
|
+
const preferredRow = Math.floor(preferredSlot / columns);
|
|
3874
|
+
const preferredColumn = preferredSlot % columns;
|
|
3875
|
+
const maxColumn = columns - record.span;
|
|
3876
|
+
const columnsByDistance = Array.from({ length: maxColumn + 1 }, (_, column) => column)
|
|
3877
|
+
.sort((a, b) => Math.abs(a - preferredColumn) - Math.abs(b - preferredColumn) || a - b);
|
|
3878
|
+
const maxRow = preferredRow + composerActionRecords().length;
|
|
3879
|
+
for (let row = preferredRow; row <= maxRow; row += 1) {
|
|
3880
|
+
for (const column of columnsByDistance) {
|
|
3881
|
+
const candidate = row * columns + column;
|
|
3882
|
+
if (composerActionSlotCanFit(record, candidate, layout, columns)) return candidate;
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
return null;
|
|
3886
|
+
}
|
|
3887
|
+
|
|
3888
|
+
function restoreComposerActionSlotLayout() {
|
|
3889
|
+
if (isMobileView()) return;
|
|
3890
|
+
const stored = readStoredComposerActionLayout();
|
|
3891
|
+
const columns = composerActionGridColumnCount();
|
|
3892
|
+
composerActionSlotLayout = new Map();
|
|
3893
|
+
composerActionLayoutColumns = columns;
|
|
3894
|
+
if (!stored) {
|
|
3895
|
+
applyComposerActionSlotLayout();
|
|
3896
|
+
return;
|
|
3897
|
+
}
|
|
3898
|
+
const records = new Map(composerActionRecords().map((record) => [record.id, record]));
|
|
3899
|
+
for (const [id, storedSlot] of [...stored.positions].sort((a, b) => a[1] - b[1])) {
|
|
3900
|
+
const record = records.get(id);
|
|
3901
|
+
if (!record || record.root.hidden || !record.root.getClientRects().length) continue;
|
|
3902
|
+
const preferredSlot = stored.columns === columns
|
|
3903
|
+
? storedSlot
|
|
3904
|
+
: remapComposerActionSlot(record, storedSlot, stored.columns, columns);
|
|
3905
|
+
const slot = nearestAvailableComposerActionSlot(record, preferredSlot, composerActionSlotLayout, columns);
|
|
3906
|
+
if (slot !== null) composerActionSlotLayout.set(id, slot);
|
|
3907
|
+
}
|
|
3908
|
+
applyComposerActionSlotLayout();
|
|
3909
|
+
}
|
|
3910
|
+
|
|
3911
|
+
function scheduleComposerActionSlotLayoutRestore() {
|
|
3912
|
+
if (composerActionPointerDrag?.active || composerActionLayoutRestoreFrame !== null) return;
|
|
3913
|
+
const restore = () => {
|
|
3914
|
+
composerActionLayoutRestoreFrame = null;
|
|
3915
|
+
if (!composerActionPointerDrag?.active) restoreComposerActionSlotLayout();
|
|
3916
|
+
};
|
|
3917
|
+
composerActionLayoutRestoreFrame = typeof requestAnimationFrame === "function"
|
|
3918
|
+
? requestAnimationFrame(restore)
|
|
3919
|
+
: setTimeout(restore, 0);
|
|
3920
|
+
}
|
|
3921
|
+
|
|
3922
|
+
function captureComposerActionSlotLayout() {
|
|
3923
|
+
const cells = Array.from(elements.composerActionGridGuide?.children || []);
|
|
3924
|
+
if (!cells.length) return;
|
|
3925
|
+
composerActionLayoutColumns = composerActionGridColumnCount();
|
|
3926
|
+
const nextLayout = new Map();
|
|
3927
|
+
for (const record of orderedComposerActionRecords({ visibleOnly: true })) {
|
|
3928
|
+
const actionRect = record.root.getBoundingClientRect();
|
|
3929
|
+
const slot = cells.findIndex((cell) => {
|
|
3930
|
+
const rect = cell.getBoundingClientRect();
|
|
3931
|
+
const centerX = rect.left + rect.width / 2;
|
|
3932
|
+
const centerY = rect.top + rect.height / 2;
|
|
3933
|
+
return centerX >= actionRect.left - 1 && centerX <= actionRect.right + 1 && centerY >= actionRect.top - 1 && centerY <= actionRect.bottom + 1;
|
|
3934
|
+
});
|
|
3935
|
+
if (slot >= 0) nextLayout.set(record.id, slot);
|
|
3936
|
+
}
|
|
3937
|
+
composerActionSlotLayout = nextLayout;
|
|
3938
|
+
applyComposerActionSlotLayout();
|
|
3939
|
+
}
|
|
3940
|
+
|
|
3941
|
+
function repackComposerActionSlotLayout() {
|
|
3942
|
+
if (composerActionLayoutColumns < 1) return;
|
|
3943
|
+
const nextLayout = new Map();
|
|
3944
|
+
let slot = 0;
|
|
3945
|
+
for (const record of orderedComposerActionRecords({ visibleOnly: true })) {
|
|
3946
|
+
const column = slot % composerActionLayoutColumns;
|
|
3947
|
+
if (column + record.span > composerActionLayoutColumns) slot += composerActionLayoutColumns - column;
|
|
3948
|
+
nextLayout.set(record.id, slot);
|
|
3949
|
+
slot += record.span;
|
|
3950
|
+
}
|
|
3951
|
+
composerActionSlotLayout = nextLayout;
|
|
3952
|
+
applyComposerActionSlotLayout();
|
|
3953
|
+
persistComposerActionSlotLayout();
|
|
3954
|
+
}
|
|
3955
|
+
|
|
3956
|
+
function syncComposerActionOrderFromSlots() {
|
|
3957
|
+
const visibleIds = orderedComposerActionRecords({ visibleOnly: true })
|
|
3958
|
+
.filter(({ id }) => composerActionSlotLayout.has(id))
|
|
3959
|
+
.sort((a, b) => composerActionSlotLayout.get(a.id) - composerActionSlotLayout.get(b.id))
|
|
3960
|
+
.map(({ id }) => id);
|
|
3961
|
+
const completeOrder = [
|
|
3962
|
+
...visibleIds,
|
|
3963
|
+
...orderedComposerActionRecords().map(({ id }) => id).filter((id) => !visibleIds.includes(id)),
|
|
3964
|
+
];
|
|
3965
|
+
applyComposerActionOrder(completeOrder);
|
|
3966
|
+
persistComposerActionOrder();
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3969
|
+
function moveComposerActionToGridCell(actionId, cell) {
|
|
3970
|
+
const record = composerActionRecords().find(({ id }) => id === actionId);
|
|
3971
|
+
const slot = Number(cell?.dataset.composerActionGridCell);
|
|
3972
|
+
if (!record || !Number.isInteger(slot)) return false;
|
|
3973
|
+
const nextLayout = new Map(composerActionSlotLayout);
|
|
3974
|
+
nextLayout.delete(actionId);
|
|
3975
|
+
if (!composerActionSlotCanFit(record, slot, nextLayout)) return false;
|
|
3976
|
+
nextLayout.set(actionId, slot);
|
|
3977
|
+
composerActionSlotLayout = nextLayout;
|
|
3978
|
+
applyComposerActionSlotLayout();
|
|
3979
|
+
syncComposerActionOrderFromSlots();
|
|
3980
|
+
clearComposerActionDragMarkers();
|
|
3981
|
+
cell.classList.add("composer-action-grid-cell-target");
|
|
3982
|
+
composerActionLastDragOverKey = `cell:${slot}`;
|
|
3983
|
+
persistComposerActionSlotLayout();
|
|
3984
|
+
return true;
|
|
3985
|
+
}
|
|
3986
|
+
|
|
3987
|
+
function clearComposerActionDragMarkers() {
|
|
3988
|
+
for (const { root } of composerActionRecords()) {
|
|
3989
|
+
root.classList.remove("composer-action-drag-before", "composer-action-drag-after");
|
|
3990
|
+
}
|
|
3991
|
+
for (const cell of elements.composerActionGridGuide?.children || []) {
|
|
3992
|
+
cell.classList.remove("composer-action-grid-cell-target");
|
|
3993
|
+
}
|
|
3994
|
+
}
|
|
3995
|
+
|
|
3996
|
+
function showComposerActionGridGuide() {
|
|
3997
|
+
const row = elements.composerRow;
|
|
3998
|
+
const guide = elements.composerActionGridGuide;
|
|
3999
|
+
if (!row || !guide) return;
|
|
4000
|
+
const columnCount = composerActionGridColumnCount();
|
|
4001
|
+
const rowTops = orderedComposerActionRecords({ visibleOnly: true })
|
|
4002
|
+
.map(({ root }) => root.getBoundingClientRect().top)
|
|
4003
|
+
.sort((a, b) => a - b)
|
|
4004
|
+
.reduce((groups, top) => {
|
|
4005
|
+
if (!groups.length || top - groups.at(-1) > 4) groups.push(top);
|
|
4006
|
+
return groups;
|
|
4007
|
+
}, []);
|
|
4008
|
+
const rowCount = Math.max(1, rowTops.length);
|
|
4009
|
+
const fragment = document.createDocumentFragment();
|
|
4010
|
+
for (let index = 0; index < columnCount * rowCount; index += 1) {
|
|
4011
|
+
const cell = document.createElement("span");
|
|
4012
|
+
cell.className = "composer-action-grid-cell";
|
|
4013
|
+
cell.dataset.composerActionGridCell = String(index);
|
|
4014
|
+
fragment.append(cell);
|
|
4015
|
+
}
|
|
4016
|
+
guide.style.setProperty("--composer-action-grid-rows", String(rowCount));
|
|
4017
|
+
guide.replaceChildren(fragment);
|
|
4018
|
+
guide.hidden = false;
|
|
4019
|
+
document.body.classList.add("composer-action-drag-active");
|
|
4020
|
+
}
|
|
4021
|
+
|
|
4022
|
+
function hideComposerActionGridGuide() {
|
|
4023
|
+
document.body.classList.remove("composer-action-drag-active");
|
|
4024
|
+
if (elements.composerActionGridGuide) elements.composerActionGridGuide.hidden = true;
|
|
4025
|
+
}
|
|
4026
|
+
|
|
4027
|
+
function composerActionGridCellFromPoint(clientX, clientY) {
|
|
4028
|
+
for (const cell of elements.composerActionGridGuide?.children || []) {
|
|
4029
|
+
const rect = cell.getBoundingClientRect();
|
|
4030
|
+
if (clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom) return cell;
|
|
4031
|
+
}
|
|
4032
|
+
return null;
|
|
4033
|
+
}
|
|
4034
|
+
|
|
4035
|
+
function moveComposerActionRelative(fromId, targetId, insertBefore) {
|
|
4036
|
+
if (!fromId || !targetId || fromId === targetId) return false;
|
|
4037
|
+
const order = orderedComposerActionRecords().map(({ id }) => id).filter((id) => id !== fromId);
|
|
4038
|
+
const targetIndex = order.indexOf(targetId);
|
|
4039
|
+
if (targetIndex < 0) return false;
|
|
4040
|
+
order.splice(targetIndex + (insertBefore ? 0 : 1), 0, fromId);
|
|
4041
|
+
applyComposerActionOrder(order);
|
|
4042
|
+
if (composerActionSlotLayout.size) repackComposerActionSlotLayout();
|
|
4043
|
+
clearComposerActionDragMarkers();
|
|
4044
|
+
const targetRecord = composerActionRecords().find(({ id }) => id === targetId);
|
|
4045
|
+
targetRecord?.root.classList.add(insertBefore ? "composer-action-drag-before" : "composer-action-drag-after");
|
|
4046
|
+
composerActionLastDragOverKey = `${targetId}:${insertBefore ? "before" : "after"}`;
|
|
4047
|
+
persistComposerActionOrder();
|
|
4048
|
+
return true;
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
function composerActionLabel(record) {
|
|
4052
|
+
return record?.focusTarget?.getAttribute("aria-label")
|
|
4053
|
+
|| record?.focusTarget?.textContent?.trim()
|
|
4054
|
+
|| record?.focusTarget?.getAttribute("title")
|
|
4055
|
+
|| record?.id
|
|
4056
|
+
|| "Action";
|
|
4057
|
+
}
|
|
4058
|
+
|
|
4059
|
+
function announceComposerActionPosition(actionId) {
|
|
4060
|
+
if (!elements.composerActionOrderStatus) return;
|
|
4061
|
+
const records = orderedComposerActionRecords({ visibleOnly: true });
|
|
4062
|
+
const index = records.findIndex(({ id }) => id === actionId);
|
|
4063
|
+
const record = records[index];
|
|
4064
|
+
if (!record || index < 0) return;
|
|
4065
|
+
elements.composerActionOrderStatus.textContent = `${composerActionLabel(record)} moved to position ${index + 1} of ${records.length}.`;
|
|
4066
|
+
}
|
|
4067
|
+
|
|
4068
|
+
function moveComposerActionByOffset(actionId, offset) {
|
|
4069
|
+
const records = orderedComposerActionRecords({ visibleOnly: true });
|
|
4070
|
+
const fromIndex = records.findIndex(({ id }) => id === actionId);
|
|
4071
|
+
const toIndex = fromIndex + offset;
|
|
4072
|
+
if (fromIndex < 0 || toIndex < 0 || toIndex >= records.length) return false;
|
|
4073
|
+
const moved = moveComposerActionRelative(actionId, records[toIndex].id, offset < 0);
|
|
4074
|
+
clearComposerActionDragMarkers();
|
|
4075
|
+
if (moved) {
|
|
4076
|
+
announceComposerActionPosition(actionId);
|
|
4077
|
+
queueMicrotask(() => composerActionRecords().find(({ id }) => id === actionId)?.focusTarget.focus({ preventScroll: true }));
|
|
4078
|
+
}
|
|
4079
|
+
return moved;
|
|
4080
|
+
}
|
|
4081
|
+
|
|
4082
|
+
function composerActionRootFromPoint(clientX, clientY) {
|
|
4083
|
+
return document.elementFromPoint(clientX, clientY)?.closest?.("[data-composer-action-id]") || null;
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
function beginComposerActionPointerDrag(event, actionId) {
|
|
4087
|
+
if (event.button !== 0 || isMobileView() || !actionId || composerActionPointerDrag) return;
|
|
4088
|
+
if (event.target?.closest?.(".composer-publish-menu-panel, input, select, textarea, a")) return;
|
|
4089
|
+
composerActionPointerDrag = { actionId, pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, active: false };
|
|
4090
|
+
window.addEventListener("pointermove", updateComposerActionPointerDrag, { capture: true });
|
|
4091
|
+
window.addEventListener("pointerup", endComposerActionPointerDrag, { capture: true });
|
|
4092
|
+
window.addEventListener("pointercancel", endComposerActionPointerDrag, { capture: true });
|
|
4093
|
+
}
|
|
4094
|
+
|
|
4095
|
+
function updateComposerActionPointerDrag(event) {
|
|
4096
|
+
const drag = composerActionPointerDrag;
|
|
4097
|
+
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
4098
|
+
const distance = Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY);
|
|
4099
|
+
if (!drag.active && distance < COMPOSER_ACTION_POINTER_DRAG_THRESHOLD_PX) return;
|
|
4100
|
+
event.preventDefault();
|
|
4101
|
+
if (!drag.active) {
|
|
4102
|
+
drag.active = true;
|
|
4103
|
+
composerActionLastDragOverKey = "";
|
|
4104
|
+
clearTimeout(pointerActivationTimeout);
|
|
4105
|
+
pointerActivationTimeout = null;
|
|
4106
|
+
activePointerActivation = null;
|
|
4107
|
+
composerActionRecords().find(({ id }) => id === drag.actionId)?.root.classList.add("composer-action-dragging");
|
|
4108
|
+
showComposerActionGridGuide();
|
|
4109
|
+
captureComposerActionSlotLayout();
|
|
4110
|
+
}
|
|
4111
|
+
const targetRoot = composerActionRootFromPoint(event.clientX, event.clientY);
|
|
4112
|
+
const targetRecord = targetRoot
|
|
4113
|
+
? composerActionRecords().find(({ root }) => root === targetRoot)
|
|
4114
|
+
: null;
|
|
4115
|
+
if (targetRecord?.id === drag.actionId) {
|
|
4116
|
+
drag.pendingRelative = null;
|
|
4117
|
+
if (!composerActionLastDragOverKey.startsWith("cell:")) {
|
|
4118
|
+
clearComposerActionDragMarkers();
|
|
4119
|
+
composerActionLastDragOverKey = "";
|
|
4120
|
+
}
|
|
4121
|
+
return;
|
|
4122
|
+
}
|
|
4123
|
+
if (targetRecord && !targetRecord.root.hidden) {
|
|
4124
|
+
const rect = targetRoot.getBoundingClientRect();
|
|
4125
|
+
const insertBefore = event.clientX < rect.left + rect.width / 2;
|
|
4126
|
+
const markerKey = `${targetRecord.id}:${insertBefore ? "before" : "after"}`;
|
|
4127
|
+
if (markerKey === composerActionLastDragOverKey) return;
|
|
4128
|
+
clearComposerActionDragMarkers();
|
|
4129
|
+
targetRecord.root.classList.add(insertBefore ? "composer-action-drag-before" : "composer-action-drag-after");
|
|
4130
|
+
composerActionLastDragOverKey = markerKey;
|
|
4131
|
+
drag.pendingRelative = { targetId: targetRecord.id, insertBefore };
|
|
4132
|
+
return;
|
|
4133
|
+
}
|
|
4134
|
+
const gridCell = composerActionGridCellFromPoint(event.clientX, event.clientY);
|
|
4135
|
+
if (!gridCell) return;
|
|
4136
|
+
const markerKey = `cell:${gridCell.dataset.composerActionGridCell}`;
|
|
4137
|
+
if (markerKey === composerActionLastDragOverKey) return;
|
|
4138
|
+
drag.pendingRelative = null;
|
|
4139
|
+
moveComposerActionToGridCell(drag.actionId, gridCell);
|
|
4140
|
+
}
|
|
4141
|
+
|
|
4142
|
+
function endComposerActionPointerDrag(event) {
|
|
4143
|
+
const drag = composerActionPointerDrag;
|
|
4144
|
+
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
4145
|
+
window.removeEventListener("pointermove", updateComposerActionPointerDrag, { capture: true });
|
|
4146
|
+
window.removeEventListener("pointerup", endComposerActionPointerDrag, { capture: true });
|
|
4147
|
+
window.removeEventListener("pointercancel", endComposerActionPointerDrag, { capture: true });
|
|
4148
|
+
const sourceRecord = composerActionRecords().find(({ id }) => id === drag.actionId);
|
|
4149
|
+
if (drag.active && event.type === "pointerup" && drag.pendingRelative) {
|
|
4150
|
+
moveComposerActionRelative(drag.actionId, drag.pendingRelative.targetId, drag.pendingRelative.insertBefore);
|
|
4151
|
+
}
|
|
4152
|
+
composerActionPointerDrag = null;
|
|
4153
|
+
composerActionLastDragOverKey = "";
|
|
4154
|
+
clearComposerActionDragMarkers();
|
|
4155
|
+
sourceRecord?.root.classList.remove("composer-action-dragging");
|
|
4156
|
+
hideComposerActionGridGuide();
|
|
4157
|
+
if (drag.active) {
|
|
4158
|
+
composerActionSuppressClickUntil = Date.now() + 250;
|
|
4159
|
+
event.preventDefault();
|
|
4160
|
+
persistComposerActionOrder();
|
|
4161
|
+
persistComposerActionSlotLayout();
|
|
4162
|
+
announceComposerActionPosition(drag.actionId);
|
|
4163
|
+
queueMicrotask(() => sourceRecord?.focusTarget.focus({ preventScroll: true }));
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
|
|
4167
|
+
function syncComposerActionGridAvailability() {
|
|
4168
|
+
document.body.classList.toggle("composer-action-grid-enabled", !isMobileView());
|
|
4169
|
+
}
|
|
4170
|
+
|
|
4171
|
+
function initializeComposerActionOrdering() {
|
|
4172
|
+
syncComposerActionGridAvailability();
|
|
4173
|
+
restoreComposerActionOrder();
|
|
4174
|
+
restoreComposerActionSlotLayout();
|
|
4175
|
+
const layoutObserver = new MutationObserver((mutations) => {
|
|
4176
|
+
if (mutations.some((mutation) => mutation.type === "childList" || mutation.target.matches?.("[data-composer-action-id]"))) {
|
|
4177
|
+
scheduleComposerActionSlotLayoutRestore();
|
|
4178
|
+
}
|
|
4179
|
+
});
|
|
4180
|
+
layoutObserver.observe(elements.composerRow, { childList: true, subtree: true, attributes: true, attributeFilter: ["hidden"] });
|
|
4181
|
+
if (typeof ResizeObserver === "function") {
|
|
4182
|
+
let observedRowWidth = elements.composerRow.getBoundingClientRect().width;
|
|
4183
|
+
const rowResizeObserver = new ResizeObserver(([entry]) => {
|
|
4184
|
+
const nextWidth = entry?.contentRect?.width ?? elements.composerRow.getBoundingClientRect().width;
|
|
4185
|
+
if (Math.abs(nextWidth - observedRowWidth) < 0.5) return;
|
|
4186
|
+
observedRowWidth = nextWidth;
|
|
4187
|
+
scheduleComposerActionSlotLayoutRestore();
|
|
4188
|
+
});
|
|
4189
|
+
rowResizeObserver.observe(elements.composerRow);
|
|
4190
|
+
}
|
|
4191
|
+
window.addEventListener("resize", scheduleComposerActionSlotLayoutRestore);
|
|
4192
|
+
for (const record of composerActionRecords()) {
|
|
4193
|
+
record.focusTarget.setAttribute("aria-keyshortcuts", "Alt+ArrowLeft Alt+ArrowRight Alt+ArrowUp Alt+ArrowDown");
|
|
4194
|
+
record.focusTarget.addEventListener("keydown", (event) => {
|
|
4195
|
+
if (isMobileView() || !event.altKey || !["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)) return;
|
|
4196
|
+
event.preventDefault();
|
|
4197
|
+
moveComposerActionByOffset(record.id, ["ArrowLeft", "ArrowUp"].includes(event.key) ? -1 : 1);
|
|
4198
|
+
});
|
|
4199
|
+
record.root.addEventListener("pointerdown", (event) => beginComposerActionPointerDrag(event, record.id));
|
|
4200
|
+
record.root.addEventListener("click", (event) => {
|
|
4201
|
+
if (Date.now() >= composerActionSuppressClickUntil) return;
|
|
4202
|
+
event.preventDefault();
|
|
4203
|
+
event.stopImmediatePropagation();
|
|
4204
|
+
}, { capture: true });
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
|
|
3698
4208
|
function bindSidePanelContextMenu() {
|
|
3699
4209
|
elements.sidePanel?.addEventListener("contextmenu", showSidePanelContextMenu);
|
|
3700
4210
|
elements.sidePanel?.addEventListener("keydown", (event) => {
|
|
@@ -3813,6 +4323,7 @@ function persistTerminalTabsLayout(layout) {
|
|
|
3813
4323
|
} catch {
|
|
3814
4324
|
// Ignore storage failures; the layout control should still work for this page load.
|
|
3815
4325
|
}
|
|
4326
|
+
markDurableUiLayoutDirty("terminalTabs", "layout");
|
|
3816
4327
|
}
|
|
3817
4328
|
|
|
3818
4329
|
function readStoredToolOutputExpanded() {
|
|
@@ -3906,6 +4417,36 @@ function restoreSubagentOpenModeSetting() {
|
|
|
3906
4417
|
setSubagentOpenMode(readStoredSubagentOpenMode(), { persist: false });
|
|
3907
4418
|
}
|
|
3908
4419
|
|
|
4420
|
+
function readStoredSubagentAutoClearEnabled() {
|
|
4421
|
+
try {
|
|
4422
|
+
return localStorage.getItem(SUBAGENT_AUTO_CLEAR_STORAGE_KEY) === "1";
|
|
4423
|
+
} catch {
|
|
4424
|
+
return false;
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
|
|
4428
|
+
function persistSubagentAutoClearEnabled(enabled) {
|
|
4429
|
+
try {
|
|
4430
|
+
localStorage.setItem(SUBAGENT_AUTO_CLEAR_STORAGE_KEY, enabled ? "1" : "0");
|
|
4431
|
+
} catch {
|
|
4432
|
+
// Ignore storage failures; the preference still applies for this page load.
|
|
4433
|
+
}
|
|
4434
|
+
}
|
|
4435
|
+
|
|
4436
|
+
function setSubagentAutoClearEnabled(enabled, { persist = true, announce = false } = {}) {
|
|
4437
|
+
subagentAutoClearEnabled = Boolean(enabled);
|
|
4438
|
+
if (persist) persistSubagentAutoClearEnabled(subagentAutoClearEnabled);
|
|
4439
|
+
renderSubagents();
|
|
4440
|
+
if (announce) addEvent(`subagent auto-clear ${subagentAutoClearEnabled ? "enabled" : "disabled"}`, "info");
|
|
4441
|
+
if (subagentAutoClearEnabled && !subagentsLoading && !subagentsClearingFinished && finishedSubagentRunSelections().length) {
|
|
4442
|
+
void clearFinishedSubagentRuns({ automatic: true });
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
|
|
4446
|
+
function restoreSubagentAutoClearSetting() {
|
|
4447
|
+
setSubagentAutoClearEnabled(readStoredSubagentAutoClearEnabled(), { persist: false });
|
|
4448
|
+
}
|
|
4449
|
+
|
|
3909
4450
|
function normalizeTerminalCustomGroupTitle(value, fallback = "Custom group") {
|
|
3910
4451
|
const title = String(value || "").replace(/\s+/g, " ").trim();
|
|
3911
4452
|
return (title || fallback).slice(0, 40);
|
|
@@ -3967,6 +4508,7 @@ function persistTerminalCustomGroups() {
|
|
|
3967
4508
|
} catch {
|
|
3968
4509
|
// Ignore storage failures; custom tab groups still work for this page load.
|
|
3969
4510
|
}
|
|
4511
|
+
markDurableUiLayoutDirty("terminalTabs", "customGroups");
|
|
3970
4512
|
}
|
|
3971
4513
|
|
|
3972
4514
|
function workspaceGroupsForSave() {
|
|
@@ -4846,22 +5388,134 @@ function normalizeFeatureCategory(value) {
|
|
|
4846
5388
|
return value === "lightweight-feature" || value === "complex-feature" ? value : "";
|
|
4847
5389
|
}
|
|
4848
5390
|
|
|
5391
|
+
function normalizeFeatureDecisionKind(value) {
|
|
5392
|
+
return value === "feature_lightweight" || value === "feature_complex" ? value : "";
|
|
5393
|
+
}
|
|
5394
|
+
|
|
5395
|
+
function normalizeFeatureDecisionReason(value) {
|
|
5396
|
+
if (typeof value !== "string") return "";
|
|
5397
|
+
return value
|
|
5398
|
+
.replace(/[\u0000-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, " ")
|
|
5399
|
+
.replace(/\s+/g, " ")
|
|
5400
|
+
.trim()
|
|
5401
|
+
.slice(0, FEATURE_DECISION_REASON_MAX_CHARS)
|
|
5402
|
+
.trimEnd();
|
|
5403
|
+
}
|
|
5404
|
+
|
|
5405
|
+
// Accepts the structured {kind,reason} classifier payload and the legacy exact label.
|
|
5406
|
+
// Every other payload fails closed so the popup stays unavailable.
|
|
5407
|
+
function parseFeatureDecisionPayload(value) {
|
|
5408
|
+
if (typeof value !== "string" || !value || value.length > FEATURE_DECISION_PAYLOAD_MAX_CHARS) return null;
|
|
5409
|
+
const legacyKind = normalizeFeatureDecisionKind(value);
|
|
5410
|
+
if (legacyKind) return { kind: legacyKind, reason: "" };
|
|
5411
|
+
if (!value.startsWith("{")) return null;
|
|
5412
|
+
let parsed;
|
|
5413
|
+
try {
|
|
5414
|
+
parsed = JSON.parse(value);
|
|
5415
|
+
} catch {
|
|
5416
|
+
return null;
|
|
5417
|
+
}
|
|
5418
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return null;
|
|
5419
|
+
const keys = Object.keys(parsed);
|
|
5420
|
+
if (keys.length !== 2 || !keys.includes("kind") || !keys.includes("reason")) return null;
|
|
5421
|
+
if (typeof parsed.reason !== "string") return null;
|
|
5422
|
+
const kind = normalizeFeatureDecisionKind(parsed.kind);
|
|
5423
|
+
const reason = normalizeFeatureDecisionReason(parsed.reason);
|
|
5424
|
+
return kind && reason ? { kind, reason } : null;
|
|
5425
|
+
}
|
|
5426
|
+
|
|
5427
|
+
function featureDecisionKindLabel(kind) {
|
|
5428
|
+
return kind === "feature_complex" ? "Complex feature" : "Lightweight feature";
|
|
5429
|
+
}
|
|
5430
|
+
|
|
5431
|
+
function formatFeatureDecisionText(decision) {
|
|
5432
|
+
if (!decision) return "";
|
|
5433
|
+
const reason = decision.reason || `The classifier reported ${decision.kind} without a reason.`;
|
|
5434
|
+
return `Decision: ${featureDecisionKindLabel(decision.kind)} (${decision.kind})\nReason: ${reason}`;
|
|
5435
|
+
}
|
|
5436
|
+
|
|
5437
|
+
function featureDecisionForTab(tabId) {
|
|
5438
|
+
const category = normalizeFeatureCategory(featureCategoryByTab.get(tabId));
|
|
5439
|
+
const decision = featureDecisionOutputByTab.get(tabId) || null;
|
|
5440
|
+
if (!decision || !normalizeFeatureDecisionKind(decision.kind)) return null;
|
|
5441
|
+
if (category === "lightweight-feature" && decision.kind === "feature_lightweight") return decision;
|
|
5442
|
+
if (category === "complex-feature" && decision.kind === "feature_complex") return decision;
|
|
5443
|
+
return null;
|
|
5444
|
+
}
|
|
5445
|
+
|
|
5446
|
+
function featureDecisionOutputForTab(tabId) {
|
|
5447
|
+
return formatFeatureDecisionText(featureDecisionForTab(tabId));
|
|
5448
|
+
}
|
|
5449
|
+
|
|
5450
|
+
function closeFeatureDecisionDialog({ restoreFocus = true } = {}) {
|
|
5451
|
+
const dialog = elements.featureDecisionDialog;
|
|
5452
|
+
if (!dialog?.open) {
|
|
5453
|
+
featureDecisionDialogTabId = null;
|
|
5454
|
+
if (elements.featureDecisionDialogOutput) elements.featureDecisionDialogOutput.textContent = "";
|
|
5455
|
+
return;
|
|
5456
|
+
}
|
|
5457
|
+
if (!restoreFocus) modalSurfaceState.delete(dialog);
|
|
5458
|
+
dialog.close();
|
|
5459
|
+
}
|
|
5460
|
+
|
|
5461
|
+
function syncFeatureDecisionDialog() {
|
|
5462
|
+
const dialog = elements.featureDecisionDialog;
|
|
5463
|
+
if (!dialog?.open) return;
|
|
5464
|
+
const output = featureDecisionOutputForTab(featureDecisionDialogTabId);
|
|
5465
|
+
if (featureDecisionDialogTabId !== activeTabId || !output || elements.featureDecisionDialogOutput?.textContent !== output) {
|
|
5466
|
+
closeFeatureDecisionDialog({ restoreFocus: false });
|
|
5467
|
+
}
|
|
5468
|
+
}
|
|
5469
|
+
|
|
5470
|
+
function openFeatureDecisionDialog() {
|
|
5471
|
+
const tabId = activeTabId;
|
|
5472
|
+
const output = featureDecisionOutputForTab(tabId);
|
|
5473
|
+
const dialog = elements.featureDecisionDialog;
|
|
5474
|
+
if (!tabId || !output || !dialog || !elements.featureDecisionDialogOutput) return;
|
|
5475
|
+
featureDecisionDialogTabId = tabId;
|
|
5476
|
+
elements.featureDecisionDialogOutput.textContent = output;
|
|
5477
|
+
if (!dialog.open) dialog.showModal();
|
|
5478
|
+
queueMicrotask(() => elements.featureDecisionDialogCloseButton?.focus({ preventScroll: true }));
|
|
5479
|
+
}
|
|
5480
|
+
|
|
5481
|
+
function clearFeatureDecisionStateForTab(tabId, { render = false } = {}) {
|
|
5482
|
+
if (!tabId) return;
|
|
5483
|
+
featureCategoryByTab.delete(tabId);
|
|
5484
|
+
featureDecisionOutputByTab.delete(tabId);
|
|
5485
|
+
if (featureDecisionDialogTabId === tabId) closeFeatureDecisionDialog({ restoreFocus: false });
|
|
5486
|
+
if (render && tabId === activeTabId) renderFeatureCategoryTag(tabId);
|
|
5487
|
+
}
|
|
5488
|
+
|
|
4849
5489
|
function renderFeatureCategoryTag(tabId = activeTabId) {
|
|
4850
5490
|
const tag = elements.featureCategoryTag;
|
|
4851
5491
|
if (!tag) return;
|
|
4852
5492
|
const category = normalizeFeatureCategory(featureCategoryByTab.get(tabId));
|
|
5493
|
+
const output = featureDecisionOutputForTab(tabId);
|
|
4853
5494
|
tag.hidden = !category;
|
|
5495
|
+
tag.disabled = !output;
|
|
4854
5496
|
tag.textContent = category;
|
|
5497
|
+
tag.setAttribute("aria-label", output ? `Show classifier decision and reason for ${category}` : category || "Feature category");
|
|
4855
5498
|
tag.classList.toggle("lightweight-feature", category === "lightweight-feature");
|
|
4856
5499
|
tag.classList.toggle("complex-feature", category === "complex-feature");
|
|
5500
|
+
syncFeatureDecisionDialog();
|
|
5501
|
+
}
|
|
5502
|
+
|
|
5503
|
+
function handleFeatureDecisionOutputStatus(statusText, tabId = activeTabId) {
|
|
5504
|
+
if (!tabId) return;
|
|
5505
|
+
const decision = parseFeatureDecisionPayload(statusText);
|
|
5506
|
+
if (decision) featureDecisionOutputByTab.set(tabId, decision);
|
|
5507
|
+
else featureDecisionOutputByTab.delete(tabId);
|
|
5508
|
+
if (tabId === activeTabId) renderFeatureCategoryTag(tabId);
|
|
5509
|
+
else if (featureDecisionDialogTabId === tabId) syncFeatureDecisionDialog();
|
|
4857
5510
|
}
|
|
4858
5511
|
|
|
4859
5512
|
function handleFeatureCategoryStatus(statusText, tabId = activeTabId) {
|
|
4860
5513
|
if (!tabId) return;
|
|
4861
5514
|
const category = normalizeFeatureCategory(statusText);
|
|
4862
5515
|
if (category) featureCategoryByTab.set(tabId, category);
|
|
4863
|
-
else
|
|
5516
|
+
else clearFeatureDecisionStateForTab(tabId);
|
|
4864
5517
|
if (tabId === activeTabId) renderFeatureCategoryTag(tabId);
|
|
5518
|
+
else if (featureDecisionDialogTabId === tabId) syncFeatureDecisionDialog();
|
|
4865
5519
|
}
|
|
4866
5520
|
|
|
4867
5521
|
function trackSkillUsage(tabId, skillName, kind = "used", source = "", details = {}) {
|
|
@@ -5247,6 +5901,7 @@ function updateComposerModeButtons() {
|
|
|
5247
5901
|
}
|
|
5248
5902
|
renderBusyPromptBehaviorTag();
|
|
5249
5903
|
document.body.classList.toggle("pi-run-active", runActive || abortAvailable);
|
|
5904
|
+
scheduleComposerActionSlotLayoutRestore();
|
|
5250
5905
|
}
|
|
5251
5906
|
|
|
5252
5907
|
function scheduleComposerModeButtonsUpdate() {
|
|
@@ -5572,6 +6227,7 @@ function setSidePanelCollapsed(collapsed, { persist = true, focusPanel = false }
|
|
|
5572
6227
|
} catch {
|
|
5573
6228
|
// Ignore storage failures; the toggle should still work for this page load.
|
|
5574
6229
|
}
|
|
6230
|
+
markDurableUiLayoutDirty("sidePanel", "collapsed");
|
|
5575
6231
|
}
|
|
5576
6232
|
|
|
5577
6233
|
function restoreSidePanelState() {
|
|
@@ -5581,7 +6237,7 @@ function restoreSidePanelState() {
|
|
|
5581
6237
|
return;
|
|
5582
6238
|
}
|
|
5583
6239
|
const stored = readStoredSidePanelCollapsed();
|
|
5584
|
-
setSidePanelCollapsed(stored ?? false, { persist:
|
|
6240
|
+
setSidePanelCollapsed(stored ?? false, { persist: false });
|
|
5585
6241
|
}
|
|
5586
6242
|
|
|
5587
6243
|
function readStoredWorkspaceDashboardCollapsed() {
|
|
@@ -5649,6 +6305,7 @@ function bindMobileViewChanges() {
|
|
|
5649
6305
|
if (!mobileViewMedia) return;
|
|
5650
6306
|
const syncForViewport = (event) => {
|
|
5651
6307
|
applyMobileShellViewport();
|
|
6308
|
+
syncComposerActionGridAvailability();
|
|
5652
6309
|
if (isMobileShellV2Active()) return;
|
|
5653
6310
|
setComposerActionsOpen(false);
|
|
5654
6311
|
setMobileFooterExpanded(false);
|
|
@@ -9060,7 +9717,10 @@ function activeTabContext(tabId = activeTabId) {
|
|
|
9060
9717
|
|
|
9061
9718
|
function setActiveTabId(tabId, { remember = false } = {}) {
|
|
9062
9719
|
const nextTabId = tabId || null;
|
|
9063
|
-
if (nextTabId !== activeTabId)
|
|
9720
|
+
if (nextTabId !== activeTabId) {
|
|
9721
|
+
activeTabGeneration += 1;
|
|
9722
|
+
closeFeatureDecisionDialog({ restoreFocus: false });
|
|
9723
|
+
}
|
|
9064
9724
|
activeTabId = nextTabId;
|
|
9065
9725
|
bindGitWorkflowToActiveTab();
|
|
9066
9726
|
renderFeatureCategoryTag(nextTabId);
|
|
@@ -10101,6 +10761,594 @@ async function moveFileTreeEntry(entry = fileContextMenuState?.entry) {
|
|
|
10101
10761
|
await moveFileTreeEntryToDestination(entry, destinationPath, { confirmMove: true });
|
|
10102
10762
|
}
|
|
10103
10763
|
|
|
10764
|
+
// --- Durable UI layout settings -------------------------------------------
|
|
10765
|
+
// Browser storage stays the immediate, offline-capable cache while the durable
|
|
10766
|
+
// per-user layout lives in the WebUI settings file behind
|
|
10767
|
+
// GET/PUT /api/interface-preferences. Local writes always apply first; server
|
|
10768
|
+
// reconciliation is non-blocking, coalesced, and revision guarded.
|
|
10769
|
+
const UI_LAYOUT_SCHEMA_VERSION = 1;
|
|
10770
|
+
const UI_LAYOUT_ENDPOINT = "/api/interface-preferences";
|
|
10771
|
+
const UI_LAYOUT_SAVE_DEBOUNCE_MS = 250;
|
|
10772
|
+
const UI_LAYOUT_MAX_CONFLICT_RETRIES = 1;
|
|
10773
|
+
const UI_LAYOUT_FIELDS = ["sidePanel", "composerActions", "footerScopedModelOrder", "terminalTabs", "fileViewerWidth"];
|
|
10774
|
+
const UI_LAYOUT_SIDE_PANEL_FIELDS = ["sectionOrder", "collapsedSectionIds", "hiddenSectionIds", "collapsed"];
|
|
10775
|
+
const UI_LAYOUT_COMPOSER_FIELDS = ["order", "grid"];
|
|
10776
|
+
const UI_LAYOUT_TERMINAL_FIELDS = ["layout", "customGroups"];
|
|
10777
|
+
const UI_LAYOUT_PENDING_STORAGE_PREFIX = "pi-webui-ui-layout-pending-v3:";
|
|
10778
|
+
const UI_LAYOUT_PENDING_WRITER_ID = globalThis.crypto?.randomUUID?.() || `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
10779
|
+
let durableLayoutPendingMutationSerial = 0;
|
|
10780
|
+
const UI_LAYOUT_ID_MAX_LENGTH = 256;
|
|
10781
|
+
const UI_LAYOUT_TITLE_MAX_LENGTH = 160;
|
|
10782
|
+
const UI_LAYOUT_LIST_MAX_ITEMS = 128;
|
|
10783
|
+
const UI_LAYOUT_GROUP_MAX_COUNT = 32;
|
|
10784
|
+
const UI_LAYOUT_GRID_MAX_COLUMNS = 24;
|
|
10785
|
+
const UI_LAYOUT_GRID_MAX_SLOTS = 4096;
|
|
10786
|
+
const UI_LAYOUT_FILE_VIEWER_WIDTH_MAX_PX = 4096;
|
|
10787
|
+
const UI_LAYOUT_UNSAFE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
10788
|
+
const UI_LAYOUT_CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/;
|
|
10789
|
+
|
|
10790
|
+
let durableLayoutRevision = null;
|
|
10791
|
+
const durableLayoutGenerations = new Map();
|
|
10792
|
+
const durableLayoutDirtyFields = new Map();
|
|
10793
|
+
let durableLayoutSaveTimer = null;
|
|
10794
|
+
let durableLayoutSaveInFlight = false;
|
|
10795
|
+
let durableLayoutConflictAttempts = 0;
|
|
10796
|
+
let durableLayoutWarned = false;
|
|
10797
|
+
let durableLayoutReadEpoch = 0;
|
|
10798
|
+
let durableLayoutAppliedReadEpoch = 0;
|
|
10799
|
+
let durableLayoutWriteFenceReadEpoch = 0;
|
|
10800
|
+
|
|
10801
|
+
function readDurableLayoutCache(key) {
|
|
10802
|
+
try {
|
|
10803
|
+
return localStorage.getItem(key);
|
|
10804
|
+
} catch {
|
|
10805
|
+
return null;
|
|
10806
|
+
}
|
|
10807
|
+
}
|
|
10808
|
+
|
|
10809
|
+
function writeDurableLayoutCache(key, value) {
|
|
10810
|
+
try {
|
|
10811
|
+
localStorage.setItem(key, value);
|
|
10812
|
+
} catch {
|
|
10813
|
+
// Browser storage is only the local cache for the durable layout settings.
|
|
10814
|
+
}
|
|
10815
|
+
}
|
|
10816
|
+
|
|
10817
|
+
function durableLayoutIdList(value) {
|
|
10818
|
+
if (!Array.isArray(value)) return null;
|
|
10819
|
+
const ids = [];
|
|
10820
|
+
const seen = new Set();
|
|
10821
|
+
for (const item of value) {
|
|
10822
|
+
if (typeof item !== "string") continue;
|
|
10823
|
+
const id = item.trim();
|
|
10824
|
+
if (!id || id.length > UI_LAYOUT_ID_MAX_LENGTH || UI_LAYOUT_CONTROL_CHARACTERS.test(id) || seen.has(id)) continue;
|
|
10825
|
+
seen.add(id);
|
|
10826
|
+
ids.push(id);
|
|
10827
|
+
if (ids.length >= UI_LAYOUT_LIST_MAX_ITEMS) break;
|
|
10828
|
+
}
|
|
10829
|
+
return ids;
|
|
10830
|
+
}
|
|
10831
|
+
|
|
10832
|
+
function durableLayoutStoredIdList(key) {
|
|
10833
|
+
const raw = readDurableLayoutCache(key);
|
|
10834
|
+
if (raw === null) return null;
|
|
10835
|
+
try {
|
|
10836
|
+
return durableLayoutIdList(JSON.parse(raw));
|
|
10837
|
+
} catch {
|
|
10838
|
+
return null;
|
|
10839
|
+
}
|
|
10840
|
+
}
|
|
10841
|
+
|
|
10842
|
+
function collectDurableSidePanelLayout() {
|
|
10843
|
+
const collapsed = readStoredSidePanelCollapsed();
|
|
10844
|
+
return {
|
|
10845
|
+
sectionOrder: durableLayoutStoredIdList(SIDE_PANEL_SECTION_ORDER_STORAGE_KEY),
|
|
10846
|
+
collapsedSectionIds: durableLayoutStoredIdList(SIDE_PANEL_SECTION_STORAGE_KEY),
|
|
10847
|
+
hiddenSectionIds: durableLayoutStoredIdList(SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY),
|
|
10848
|
+
collapsed: typeof collapsed === "boolean" ? collapsed : null,
|
|
10849
|
+
};
|
|
10850
|
+
}
|
|
10851
|
+
|
|
10852
|
+
function collectDurableComposerActionsLayout() {
|
|
10853
|
+
const stored = readStoredComposerActionLayout();
|
|
10854
|
+
let grid = null;
|
|
10855
|
+
if (stored && Number.isInteger(stored.columns) && stored.columns >= 1 && stored.columns <= UI_LAYOUT_GRID_MAX_COLUMNS) {
|
|
10856
|
+
const positions = {};
|
|
10857
|
+
const usedSlots = new Set();
|
|
10858
|
+
let count = 0;
|
|
10859
|
+
for (const [rawId, slot] of stored.positions) {
|
|
10860
|
+
const id = typeof rawId === "string" ? rawId.trim() : "";
|
|
10861
|
+
if (!id || id.length > UI_LAYOUT_ID_MAX_LENGTH || UI_LAYOUT_CONTROL_CHARACTERS.test(id) || UI_LAYOUT_UNSAFE_KEYS.has(id)) continue;
|
|
10862
|
+
if (!Number.isInteger(slot) || slot < 0 || slot >= UI_LAYOUT_GRID_MAX_SLOTS || usedSlots.has(slot)) continue;
|
|
10863
|
+
usedSlots.add(slot);
|
|
10864
|
+
positions[id] = slot;
|
|
10865
|
+
count += 1;
|
|
10866
|
+
if (count >= UI_LAYOUT_LIST_MAX_ITEMS) break;
|
|
10867
|
+
}
|
|
10868
|
+
grid = { version: 2, columns: stored.columns, positions };
|
|
10869
|
+
}
|
|
10870
|
+
// Composer order and sparse grid always travel together as one logical update.
|
|
10871
|
+
return { order: durableLayoutStoredIdList(COMPOSER_ACTION_ORDER_STORAGE_KEY), grid };
|
|
10872
|
+
}
|
|
10873
|
+
|
|
10874
|
+
function collectDurableTerminalTabsLayout() {
|
|
10875
|
+
const rawLayout = readDurableLayoutCache(TERMINAL_TABS_LAYOUT_STORAGE_KEY);
|
|
10876
|
+
const rawGroups = readDurableLayoutCache(TERMINAL_CUSTOM_GROUPS_STORAGE_KEY);
|
|
10877
|
+
let customGroups = null;
|
|
10878
|
+
if (rawGroups !== null) {
|
|
10879
|
+
let parsed = null;
|
|
10880
|
+
try {
|
|
10881
|
+
parsed = JSON.parse(rawGroups);
|
|
10882
|
+
} catch {
|
|
10883
|
+
parsed = null;
|
|
10884
|
+
}
|
|
10885
|
+
const records = Array.isArray(parsed?.groups) ? parsed.groups : Array.isArray(parsed) ? parsed : [];
|
|
10886
|
+
const groups = [];
|
|
10887
|
+
const groupIds = new Set();
|
|
10888
|
+
const claimedTabIds = new Set();
|
|
10889
|
+
for (const record of records) {
|
|
10890
|
+
const id = String(record?.id || "").trim();
|
|
10891
|
+
if (!id || id.length > UI_LAYOUT_ID_MAX_LENGTH || UI_LAYOUT_CONTROL_CHARACTERS.test(id) || groupIds.has(id)) continue;
|
|
10892
|
+
const title = normalizeTerminalCustomGroupTitle(record?.title).slice(0, UI_LAYOUT_TITLE_MAX_LENGTH).trim();
|
|
10893
|
+
const tabIds = (durableLayoutIdList(normalizeTerminalCustomGroupTabIds(record?.tabIds)) || []).filter((tabId) => {
|
|
10894
|
+
if (claimedTabIds.has(tabId)) return false;
|
|
10895
|
+
claimedTabIds.add(tabId);
|
|
10896
|
+
return true;
|
|
10897
|
+
});
|
|
10898
|
+
if (!title || tabIds.length < 2) continue;
|
|
10899
|
+
groupIds.add(id);
|
|
10900
|
+
groups.push({ id, title, tabIds });
|
|
10901
|
+
if (groups.length >= UI_LAYOUT_GROUP_MAX_COUNT) break;
|
|
10902
|
+
}
|
|
10903
|
+
customGroups = { version: 1, groups };
|
|
10904
|
+
}
|
|
10905
|
+
return { layout: TERMINAL_TABS_LAYOUTS.has(rawLayout) ? rawLayout : null, customGroups };
|
|
10906
|
+
}
|
|
10907
|
+
|
|
10908
|
+
function collectDurableFileViewerWidth() {
|
|
10909
|
+
const width = readStoredFileViewerWidth();
|
|
10910
|
+
if (!Number.isFinite(width)) return null;
|
|
10911
|
+
const rounded = Math.round(width);
|
|
10912
|
+
return rounded >= FILE_VIEWER_WIDTH_MIN_PX && rounded <= UI_LAYOUT_FILE_VIEWER_WIDTH_MAX_PX ? rounded : null;
|
|
10913
|
+
}
|
|
10914
|
+
|
|
10915
|
+
function collectDurableUiLayoutField(field) {
|
|
10916
|
+
switch (field) {
|
|
10917
|
+
case "sidePanel":
|
|
10918
|
+
return collectDurableSidePanelLayout();
|
|
10919
|
+
case "composerActions":
|
|
10920
|
+
return collectDurableComposerActionsLayout();
|
|
10921
|
+
case "footerScopedModelOrder":
|
|
10922
|
+
return durableLayoutStoredIdList(FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY);
|
|
10923
|
+
case "terminalTabs":
|
|
10924
|
+
return collectDurableTerminalTabsLayout();
|
|
10925
|
+
case "fileViewerWidth":
|
|
10926
|
+
return collectDurableFileViewerWidth();
|
|
10927
|
+
default:
|
|
10928
|
+
return null;
|
|
10929
|
+
}
|
|
10930
|
+
}
|
|
10931
|
+
|
|
10932
|
+
function durableUiLayoutSubFields(field) {
|
|
10933
|
+
if (field === "sidePanel") return UI_LAYOUT_SIDE_PANEL_FIELDS;
|
|
10934
|
+
if (field === "composerActions") return UI_LAYOUT_COMPOSER_FIELDS;
|
|
10935
|
+
if (field === "terminalTabs") return UI_LAYOUT_TERMINAL_FIELDS;
|
|
10936
|
+
return null;
|
|
10937
|
+
}
|
|
10938
|
+
|
|
10939
|
+
function durableUiLayoutValuePresent(value) {
|
|
10940
|
+
return value !== null && value !== undefined;
|
|
10941
|
+
}
|
|
10942
|
+
|
|
10943
|
+
function durableUiLayoutMutationValue(field, subfield = null) {
|
|
10944
|
+
const value = collectDurableUiLayoutField(field);
|
|
10945
|
+
return subfield ? value?.[subfield] ?? null : value;
|
|
10946
|
+
}
|
|
10947
|
+
|
|
10948
|
+
function durableUiLayoutEntryPatch(field, entry) {
|
|
10949
|
+
if (!entry?.subfields?.size) return entry?.value ?? null;
|
|
10950
|
+
return Object.fromEntries([...entry.subfields].map((subfield) => [subfield, entry.value?.[subfield] ?? null]));
|
|
10951
|
+
}
|
|
10952
|
+
|
|
10953
|
+
function durableUiLayoutPendingMutationRecords() {
|
|
10954
|
+
const records = [];
|
|
10955
|
+
try {
|
|
10956
|
+
for (let index = 0; index < localStorage.length; index += 1) {
|
|
10957
|
+
const key = localStorage.key(index);
|
|
10958
|
+
if (!key?.startsWith(UI_LAYOUT_PENDING_STORAGE_PREFIX)) continue;
|
|
10959
|
+
let value;
|
|
10960
|
+
try {
|
|
10961
|
+
value = JSON.parse(localStorage.getItem(key) || "null");
|
|
10962
|
+
} catch {
|
|
10963
|
+
continue;
|
|
10964
|
+
}
|
|
10965
|
+
if (!value || value.version !== 3 || !UI_LAYOUT_FIELDS.includes(value.field)) continue;
|
|
10966
|
+
const allowedSubfields = durableUiLayoutSubFields(value.field);
|
|
10967
|
+
const subfield = typeof value.subfield === "string" ? value.subfield : null;
|
|
10968
|
+
if (subfield && !allowedSubfields?.includes(subfield)) continue;
|
|
10969
|
+
if (allowedSubfields && value.field !== "composerActions" && !subfield) continue;
|
|
10970
|
+
records.push({
|
|
10971
|
+
key,
|
|
10972
|
+
field: value.field,
|
|
10973
|
+
subfield,
|
|
10974
|
+
value: value.value,
|
|
10975
|
+
updatedAt: Number(value.updatedAt) || 0,
|
|
10976
|
+
});
|
|
10977
|
+
}
|
|
10978
|
+
} catch {
|
|
10979
|
+
return [];
|
|
10980
|
+
}
|
|
10981
|
+
return records;
|
|
10982
|
+
}
|
|
10983
|
+
|
|
10984
|
+
function writeDurableUiLayoutPendingMutation(field, subfield, value) {
|
|
10985
|
+
try {
|
|
10986
|
+
durableLayoutPendingMutationSerial += 1;
|
|
10987
|
+
const key = `${UI_LAYOUT_PENDING_STORAGE_PREFIX}${UI_LAYOUT_PENDING_WRITER_ID}:${Date.now().toString(36)}:${durableLayoutPendingMutationSerial.toString(36)}`;
|
|
10988
|
+
localStorage.setItem(key, JSON.stringify({
|
|
10989
|
+
version: 3,
|
|
10990
|
+
field,
|
|
10991
|
+
subfield,
|
|
10992
|
+
value,
|
|
10993
|
+
updatedAt: Date.now(),
|
|
10994
|
+
}));
|
|
10995
|
+
return key;
|
|
10996
|
+
} catch {
|
|
10997
|
+
return null;
|
|
10998
|
+
}
|
|
10999
|
+
}
|
|
11000
|
+
|
|
11001
|
+
function removeDurableUiLayoutPendingMutation(key) {
|
|
11002
|
+
if (!key) return;
|
|
11003
|
+
try {
|
|
11004
|
+
localStorage.removeItem(key);
|
|
11005
|
+
} catch {
|
|
11006
|
+
// A later startup can retry an immutable mutation record that remains.
|
|
11007
|
+
}
|
|
11008
|
+
}
|
|
11009
|
+
|
|
11010
|
+
function clearAcknowledgedDurableUiLayoutPendingMutations(snapshot) {
|
|
11011
|
+
for (const entry of snapshot.values()) {
|
|
11012
|
+
if (entry.subfieldMutationIds?.size) {
|
|
11013
|
+
for (const mutationId of entry.subfieldMutationIds.values()) removeDurableUiLayoutPendingMutation(mutationId);
|
|
11014
|
+
} else {
|
|
11015
|
+
removeDurableUiLayoutPendingMutation(entry.mutationId);
|
|
11016
|
+
}
|
|
11017
|
+
}
|
|
11018
|
+
}
|
|
11019
|
+
|
|
11020
|
+
function restoreDurableUiLayoutPendingJournal() {
|
|
11021
|
+
const records = durableUiLayoutPendingMutationRecords();
|
|
11022
|
+
const candidates = new Map();
|
|
11023
|
+
for (const record of records) {
|
|
11024
|
+
const path = record.subfield ? `${record.field}.${record.subfield}` : record.field;
|
|
11025
|
+
const previous = candidates.get(path);
|
|
11026
|
+
if (!previous || record.updatedAt > previous.updatedAt || (record.updatedAt === previous.updatedAt && record.key > previous.key)) {
|
|
11027
|
+
candidates.set(path, record);
|
|
11028
|
+
}
|
|
11029
|
+
}
|
|
11030
|
+
// Mutation records are immutable. Once a newer record exists for the same
|
|
11031
|
+
// path, older records are safely superseded and can never be rewritten.
|
|
11032
|
+
for (const record of records) {
|
|
11033
|
+
const path = record.subfield ? `${record.field}.${record.subfield}` : record.field;
|
|
11034
|
+
if (candidates.get(path)?.key !== record.key) removeDurableUiLayoutPendingMutation(record.key);
|
|
11035
|
+
}
|
|
11036
|
+
|
|
11037
|
+
for (const field of UI_LAYOUT_FIELDS) {
|
|
11038
|
+
const allowedSubfields = durableUiLayoutSubFields(field);
|
|
11039
|
+
const fieldCandidates = allowedSubfields && field !== "composerActions"
|
|
11040
|
+
? allowedSubfields.map((subfield) => candidates.get(`${field}.${subfield}`)).filter(Boolean)
|
|
11041
|
+
: [candidates.get(field)].filter(Boolean);
|
|
11042
|
+
if (!fieldCandidates.length) continue;
|
|
11043
|
+
const patch = allowedSubfields && field !== "composerActions"
|
|
11044
|
+
? Object.fromEntries(fieldCandidates.map((candidate) => [candidate.subfield, candidate.value]))
|
|
11045
|
+
: fieldCandidates[0].value;
|
|
11046
|
+
applyDurableUiLayoutField(field, patch);
|
|
11047
|
+
const generation = durableUiLayoutGeneration(field) + 1;
|
|
11048
|
+
const subfields = allowedSubfields && field !== "composerActions"
|
|
11049
|
+
? new Set(fieldCandidates.map((candidate) => candidate.subfield))
|
|
11050
|
+
: null;
|
|
11051
|
+
const subfieldGenerations = subfields
|
|
11052
|
+
? new Map([...subfields].map((subfield) => [subfield, generation]))
|
|
11053
|
+
: null;
|
|
11054
|
+
const subfieldMutationIds = subfields
|
|
11055
|
+
? new Map(fieldCandidates.map((candidate) => [candidate.subfield, candidate.key]))
|
|
11056
|
+
: null;
|
|
11057
|
+
durableLayoutGenerations.set(field, generation);
|
|
11058
|
+
durableLayoutDirtyFields.set(field, {
|
|
11059
|
+
generation,
|
|
11060
|
+
value: collectDurableUiLayoutField(field),
|
|
11061
|
+
subfields,
|
|
11062
|
+
subfieldGenerations,
|
|
11063
|
+
subfieldMutationIds,
|
|
11064
|
+
mutationId: subfields ? null : fieldCandidates[0].key,
|
|
11065
|
+
});
|
|
11066
|
+
}
|
|
11067
|
+
if (durableLayoutDirtyFields.size) scheduleDurableUiLayoutSave();
|
|
11068
|
+
}
|
|
11069
|
+
|
|
11070
|
+
function applyDurableSidePanelLayout(value) {
|
|
11071
|
+
if (!value) return;
|
|
11072
|
+
if (Array.isArray(value.sectionOrder)) {
|
|
11073
|
+
writeDurableLayoutCache(SIDE_PANEL_SECTION_ORDER_STORAGE_KEY, JSON.stringify(value.sectionOrder));
|
|
11074
|
+
restoreSidePanelSectionOrder();
|
|
11075
|
+
}
|
|
11076
|
+
if (Array.isArray(value.hiddenSectionIds)) {
|
|
11077
|
+
writeDurableLayoutCache(SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY, JSON.stringify(value.hiddenSectionIds));
|
|
11078
|
+
restoreSidePanelSectionVisibility();
|
|
11079
|
+
}
|
|
11080
|
+
if (Array.isArray(value.collapsedSectionIds)) {
|
|
11081
|
+
writeDurableLayoutCache(SIDE_PANEL_SECTION_STORAGE_KEY, JSON.stringify(value.collapsedSectionIds));
|
|
11082
|
+
restoreSidePanelSectionState();
|
|
11083
|
+
}
|
|
11084
|
+
if (typeof value.collapsed === "boolean") {
|
|
11085
|
+
writeDurableLayoutCache(SIDE_PANEL_STORAGE_KEY, value.collapsed ? "1" : "0");
|
|
11086
|
+
restoreSidePanelState();
|
|
11087
|
+
}
|
|
11088
|
+
}
|
|
11089
|
+
|
|
11090
|
+
function applyDurableComposerActionsLayout(value) {
|
|
11091
|
+
if (!value) return;
|
|
11092
|
+
if (Array.isArray(value.order)) {
|
|
11093
|
+
writeDurableLayoutCache(COMPOSER_ACTION_ORDER_STORAGE_KEY, JSON.stringify(value.order));
|
|
11094
|
+
restoreComposerActionOrder();
|
|
11095
|
+
}
|
|
11096
|
+
if (value.grid && value.grid.version === 2) {
|
|
11097
|
+
// Keep the saved geometry as the canonical layout. Restore projects its
|
|
11098
|
+
// horizontal positions into the current responsive grid without rewriting
|
|
11099
|
+
// the source slots, so resizing back restores the exact original cells.
|
|
11100
|
+
writeDurableLayoutCache(COMPOSER_ACTION_LAYOUT_STORAGE_KEY, JSON.stringify(value.grid));
|
|
11101
|
+
restoreComposerActionSlotLayout();
|
|
11102
|
+
}
|
|
11103
|
+
}
|
|
11104
|
+
|
|
11105
|
+
function applyDurableFooterScopedModelOrder(value) {
|
|
11106
|
+
if (!Array.isArray(value)) return;
|
|
11107
|
+
writeDurableLayoutCache(FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY, JSON.stringify(value));
|
|
11108
|
+
footerScopedModels = orderedFooterScopedModels();
|
|
11109
|
+
renderFooter();
|
|
11110
|
+
}
|
|
11111
|
+
|
|
11112
|
+
function applyDurableTerminalTabsLayout(value) {
|
|
11113
|
+
if (!value) return;
|
|
11114
|
+
if (TERMINAL_TABS_LAYOUTS.has(value.layout)) {
|
|
11115
|
+
writeDurableLayoutCache(TERMINAL_TABS_LAYOUT_STORAGE_KEY, value.layout);
|
|
11116
|
+
setTerminalTabsLayout(value.layout, { persist: false });
|
|
11117
|
+
}
|
|
11118
|
+
if (value.customGroups && value.customGroups.version === 1) {
|
|
11119
|
+
writeDurableLayoutCache(TERMINAL_CUSTOM_GROUPS_STORAGE_KEY, JSON.stringify(value.customGroups));
|
|
11120
|
+
restoreTerminalCustomGroups();
|
|
11121
|
+
syncTerminalCustomGroupsWithTabs(tabs, { persist: false });
|
|
11122
|
+
renderTabs();
|
|
11123
|
+
}
|
|
11124
|
+
}
|
|
11125
|
+
|
|
11126
|
+
function applyDurableFileViewerWidth(value) {
|
|
11127
|
+
if (!Number.isFinite(value)) return;
|
|
11128
|
+
const width = Math.round(value);
|
|
11129
|
+
if (width < FILE_VIEWER_WIDTH_MIN_PX) return;
|
|
11130
|
+
writeDurableLayoutCache(FILE_VIEWER_WIDTH_STORAGE_KEY, String(width));
|
|
11131
|
+
restoreFileViewerWidthPreference();
|
|
11132
|
+
if (activeFileViewer && !isSidePanelOverlayView()) applyFileViewerWidth(width);
|
|
11133
|
+
}
|
|
11134
|
+
|
|
11135
|
+
function applyDurableUiLayoutField(field, value) {
|
|
11136
|
+
if (field === "sidePanel") applyDurableSidePanelLayout(value);
|
|
11137
|
+
else if (field === "composerActions") applyDurableComposerActionsLayout(value);
|
|
11138
|
+
else if (field === "footerScopedModelOrder") applyDurableFooterScopedModelOrder(value);
|
|
11139
|
+
else if (field === "terminalTabs") applyDurableTerminalTabsLayout(value);
|
|
11140
|
+
else if (field === "fileViewerWidth") applyDurableFileViewerWidth(value);
|
|
11141
|
+
}
|
|
11142
|
+
|
|
11143
|
+
function durableUiLayoutInteractionActive(field = null) {
|
|
11144
|
+
const activeByField = {
|
|
11145
|
+
sidePanel: Boolean(sidePanelSectionPointerDrag?.active),
|
|
11146
|
+
composerActions: Boolean(composerActionPointerDrag?.active),
|
|
11147
|
+
footerScopedModelOrder: Boolean(footerScopedModelPointerDrag?.active),
|
|
11148
|
+
terminalTabs: Boolean(terminalTabDragId),
|
|
11149
|
+
fileViewerWidth: Boolean(fileViewerResizeState),
|
|
11150
|
+
};
|
|
11151
|
+
return field ? activeByField[field] === true : Object.values(activeByField).some(Boolean);
|
|
11152
|
+
}
|
|
11153
|
+
|
|
11154
|
+
function durableUiLayoutGeneration(field) {
|
|
11155
|
+
return durableLayoutGenerations.get(field) || 0;
|
|
11156
|
+
}
|
|
11157
|
+
|
|
11158
|
+
function warnDurableUiLayoutOnce(message) {
|
|
11159
|
+
if (durableLayoutWarned) return;
|
|
11160
|
+
durableLayoutWarned = true;
|
|
11161
|
+
addEvent(message, "warn");
|
|
11162
|
+
}
|
|
11163
|
+
|
|
11164
|
+
function scheduleDurableUiLayoutSave(delay = UI_LAYOUT_SAVE_DEBOUNCE_MS) {
|
|
11165
|
+
// One coalescing writer: repeated drag-over commits only reset this timer.
|
|
11166
|
+
if (durableLayoutSaveTimer !== null) clearTimeout(durableLayoutSaveTimer);
|
|
11167
|
+
durableLayoutSaveTimer = setTimeout(() => {
|
|
11168
|
+
durableLayoutSaveTimer = null;
|
|
11169
|
+
flushDurableUiLayoutSave();
|
|
11170
|
+
}, delay);
|
|
11171
|
+
}
|
|
11172
|
+
|
|
11173
|
+
function markDurableUiLayoutDirty(field, subfield = null) {
|
|
11174
|
+
if (!UI_LAYOUT_FIELDS.includes(field)) return;
|
|
11175
|
+
const allowedSubfields = durableUiLayoutSubFields(field);
|
|
11176
|
+
if (subfield && !allowedSubfields?.includes(subfield)) return;
|
|
11177
|
+
const generation = durableUiLayoutGeneration(field) + 1;
|
|
11178
|
+
const previous = durableLayoutDirtyFields.get(field);
|
|
11179
|
+
const value = collectDurableUiLayoutField(field);
|
|
11180
|
+
let subfields = null;
|
|
11181
|
+
let subfieldGenerations = null;
|
|
11182
|
+
let subfieldMutationIds = null;
|
|
11183
|
+
let mutationId = null;
|
|
11184
|
+
if (allowedSubfields && field !== "composerActions") {
|
|
11185
|
+
subfields = new Set(previous?.subfields || []);
|
|
11186
|
+
subfieldGenerations = new Map(previous?.subfieldGenerations || []);
|
|
11187
|
+
subfieldMutationIds = new Map(previous?.subfieldMutationIds || []);
|
|
11188
|
+
const changedSubfields = subfield ? [subfield] : allowedSubfields;
|
|
11189
|
+
for (const key of changedSubfields) {
|
|
11190
|
+
const nextMutationId = writeDurableUiLayoutPendingMutation(field, key, value?.[key] ?? null);
|
|
11191
|
+
if (nextMutationId) {
|
|
11192
|
+
removeDurableUiLayoutPendingMutation(subfieldMutationIds.get(key));
|
|
11193
|
+
subfieldMutationIds.set(key, nextMutationId);
|
|
11194
|
+
}
|
|
11195
|
+
subfields.add(key);
|
|
11196
|
+
subfieldGenerations.set(key, generation);
|
|
11197
|
+
}
|
|
11198
|
+
} else {
|
|
11199
|
+
mutationId = writeDurableUiLayoutPendingMutation(field, null, value);
|
|
11200
|
+
if (mutationId) removeDurableUiLayoutPendingMutation(previous?.mutationId);
|
|
11201
|
+
else mutationId = previous?.mutationId || null;
|
|
11202
|
+
}
|
|
11203
|
+
durableLayoutGenerations.set(field, generation);
|
|
11204
|
+
durableLayoutDirtyFields.set(field, {
|
|
11205
|
+
generation,
|
|
11206
|
+
value,
|
|
11207
|
+
subfields,
|
|
11208
|
+
subfieldGenerations,
|
|
11209
|
+
subfieldMutationIds,
|
|
11210
|
+
mutationId,
|
|
11211
|
+
});
|
|
11212
|
+
durableLayoutConflictAttempts = 0;
|
|
11213
|
+
scheduleDurableUiLayoutSave();
|
|
11214
|
+
}
|
|
11215
|
+
|
|
11216
|
+
function applyDurableUiLayoutSnapshot(data, { generations = null, readEpoch = 0 } = {}) {
|
|
11217
|
+
if (!data || typeof data !== "object") return false;
|
|
11218
|
+
if (readEpoch && readEpoch <= durableLayoutWriteFenceReadEpoch) return false;
|
|
11219
|
+
if (readEpoch && readEpoch < durableLayoutAppliedReadEpoch) return false;
|
|
11220
|
+
if (readEpoch) durableLayoutAppliedReadEpoch = readEpoch;
|
|
11221
|
+
if (typeof data.layoutRevision === "string" && data.layoutRevision) durableLayoutRevision = data.layoutRevision;
|
|
11222
|
+
const layout = data.layout && typeof data.layout === "object" ? data.layout : null;
|
|
11223
|
+
if (!layout || layout.version !== UI_LAYOUT_SCHEMA_VERSION) return Boolean(durableLayoutRevision);
|
|
11224
|
+
for (const field of UI_LAYOUT_FIELDS) {
|
|
11225
|
+
const requestedGeneration = generations ? generations.get(field) ?? 0 : durableUiLayoutGeneration(field);
|
|
11226
|
+
const generationChanged = durableUiLayoutGeneration(field) !== requestedGeneration;
|
|
11227
|
+
const dirtyEntry = durableLayoutDirtyFields.get(field);
|
|
11228
|
+
const serverValue = layout[field] ?? null;
|
|
11229
|
+
const localValue = collectDurableUiLayoutField(field);
|
|
11230
|
+
const subfields = durableUiLayoutSubFields(field);
|
|
11231
|
+
const dirtySubfields = dirtyEntry?.subfields;
|
|
11232
|
+
|
|
11233
|
+
if (subfields && field !== "composerActions") {
|
|
11234
|
+
const applicable = {};
|
|
11235
|
+
let hasApplicable = false;
|
|
11236
|
+
for (const subfield of subfields) {
|
|
11237
|
+
const isDirty = dirtySubfields?.has(subfield) === true;
|
|
11238
|
+
const remote = serverValue?.[subfield] ?? null;
|
|
11239
|
+
const local = localValue?.[subfield] ?? null;
|
|
11240
|
+
if (!isDirty && !generationChanged && !durableUiLayoutInteractionActive(field) && durableUiLayoutValuePresent(remote)) {
|
|
11241
|
+
applicable[subfield] = remote;
|
|
11242
|
+
hasApplicable = true;
|
|
11243
|
+
}
|
|
11244
|
+
if (!isDirty && !durableUiLayoutValuePresent(remote) && durableUiLayoutValuePresent(local)) {
|
|
11245
|
+
markDurableUiLayoutDirty(field, subfield);
|
|
11246
|
+
}
|
|
11247
|
+
}
|
|
11248
|
+
if (hasApplicable) applyDurableUiLayoutField(field, applicable);
|
|
11249
|
+
continue;
|
|
11250
|
+
}
|
|
11251
|
+
|
|
11252
|
+
if (!dirtyEntry && !generationChanged && !durableUiLayoutInteractionActive(field) && durableUiLayoutValuePresent(serverValue)) {
|
|
11253
|
+
applyDurableUiLayoutField(field, serverValue);
|
|
11254
|
+
}
|
|
11255
|
+
if (!dirtyEntry && !durableUiLayoutValuePresent(serverValue) && durableUiLayoutValuePresent(localValue)) {
|
|
11256
|
+
markDurableUiLayoutDirty(field);
|
|
11257
|
+
}
|
|
11258
|
+
}
|
|
11259
|
+
return true;
|
|
11260
|
+
}
|
|
11261
|
+
|
|
11262
|
+
async function refreshDurableUiLayoutFromServer() {
|
|
11263
|
+
const generations = new Map(UI_LAYOUT_FIELDS.map((field) => [field, durableUiLayoutGeneration(field)]));
|
|
11264
|
+
const readEpoch = ++durableLayoutReadEpoch;
|
|
11265
|
+
try {
|
|
11266
|
+
const response = await api(UI_LAYOUT_ENDPOINT, { scoped: false });
|
|
11267
|
+
return applyDurableUiLayoutSnapshot(response.data, { generations, readEpoch });
|
|
11268
|
+
} catch {
|
|
11269
|
+
// Keep the local cache authoritative until the settings file is reachable.
|
|
11270
|
+
return false;
|
|
11271
|
+
}
|
|
11272
|
+
}
|
|
11273
|
+
|
|
11274
|
+
async function flushDurableUiLayoutSave() {
|
|
11275
|
+
if (durableLayoutSaveInFlight || !durableLayoutDirtyFields.size) return;
|
|
11276
|
+
if ([...durableLayoutDirtyFields.keys()].some((field) => durableUiLayoutInteractionActive(field))) {
|
|
11277
|
+
scheduleDurableUiLayoutSave();
|
|
11278
|
+
return;
|
|
11279
|
+
}
|
|
11280
|
+
if (typeof navigator !== "undefined" && navigator.onLine === false) return;
|
|
11281
|
+
durableLayoutSaveInFlight = true;
|
|
11282
|
+
let snapshot = new Map();
|
|
11283
|
+
let retryImmediately = false;
|
|
11284
|
+
try {
|
|
11285
|
+
if (!durableLayoutRevision) await refreshDurableUiLayoutFromServer();
|
|
11286
|
+
if (!durableLayoutRevision || !durableLayoutDirtyFields.size) return;
|
|
11287
|
+
snapshot = new Map([...durableLayoutDirtyFields].map(([field, entry]) => [field, {
|
|
11288
|
+
...entry,
|
|
11289
|
+
subfields: entry.subfields ? new Set(entry.subfields) : null,
|
|
11290
|
+
subfieldGenerations: entry.subfieldGenerations ? new Map(entry.subfieldGenerations) : null,
|
|
11291
|
+
subfieldMutationIds: entry.subfieldMutationIds ? new Map(entry.subfieldMutationIds) : null,
|
|
11292
|
+
}]));
|
|
11293
|
+
const patch = { version: UI_LAYOUT_SCHEMA_VERSION };
|
|
11294
|
+
for (const [field, entry] of snapshot) patch[field] = durableUiLayoutEntryPatch(field, entry);
|
|
11295
|
+
const response = await api(UI_LAYOUT_ENDPOINT, {
|
|
11296
|
+
method: "PUT",
|
|
11297
|
+
scoped: false,
|
|
11298
|
+
body: { layout: patch, expectedLayoutRevision: durableLayoutRevision },
|
|
11299
|
+
});
|
|
11300
|
+
// A successful write is newer than every GET that began before this
|
|
11301
|
+
// acknowledgement, even if one of those reads completes afterward.
|
|
11302
|
+
durableLayoutWriteFenceReadEpoch = Math.max(durableLayoutWriteFenceReadEpoch, durableLayoutReadEpoch);
|
|
11303
|
+
if (typeof response.data?.layoutRevision === "string" && response.data.layoutRevision) durableLayoutRevision = response.data.layoutRevision;
|
|
11304
|
+
for (const [field, entry] of snapshot) {
|
|
11305
|
+
const current = durableLayoutDirtyFields.get(field);
|
|
11306
|
+
if (!current) continue;
|
|
11307
|
+
if (entry.subfields?.size) {
|
|
11308
|
+
for (const subfield of entry.subfields) {
|
|
11309
|
+
if (current.subfieldGenerations?.get(subfield) !== entry.subfieldGenerations?.get(subfield)) continue;
|
|
11310
|
+
if (current.subfieldMutationIds?.get(subfield) !== entry.subfieldMutationIds?.get(subfield)) continue;
|
|
11311
|
+
current.subfields.delete(subfield);
|
|
11312
|
+
current.subfieldGenerations.delete(subfield);
|
|
11313
|
+
current.subfieldMutationIds.delete(subfield);
|
|
11314
|
+
}
|
|
11315
|
+
if (!current.subfields.size) durableLayoutDirtyFields.delete(field);
|
|
11316
|
+
else current.value = collectDurableUiLayoutField(field);
|
|
11317
|
+
} else if (current.generation === entry.generation && current.mutationId === entry.mutationId) {
|
|
11318
|
+
durableLayoutDirtyFields.delete(field);
|
|
11319
|
+
}
|
|
11320
|
+
}
|
|
11321
|
+
clearAcknowledgedDurableUiLayoutPendingMutations(snapshot);
|
|
11322
|
+
durableLayoutConflictAttempts = 0;
|
|
11323
|
+
durableLayoutWarned = false;
|
|
11324
|
+
} catch (error) {
|
|
11325
|
+
const status = Number(error?.statusCode) || 0;
|
|
11326
|
+
if (status === 409) {
|
|
11327
|
+
durableLayoutConflictAttempts += 1;
|
|
11328
|
+
await refreshDurableUiLayoutFromServer();
|
|
11329
|
+
if (durableLayoutConflictAttempts <= UI_LAYOUT_MAX_CONFLICT_RETRIES) retryImmediately = durableLayoutDirtyFields.size > 0;
|
|
11330
|
+
else warnDurableUiLayoutOnce("Durable layout changes stayed in this browser because the saved layout kept changing elsewhere.");
|
|
11331
|
+
} else if (status >= 400 && status < 500 && status !== 401 && status !== 408 && status !== 429) {
|
|
11332
|
+
// Keep the pending journal for recovery, but do not retry a rejected
|
|
11333
|
+
// payload until another user/lifecycle event supplies a new opportunity.
|
|
11334
|
+
warnDurableUiLayoutOnce(`Could not save the durable UI layout: ${error?.message || String(error)}`);
|
|
11335
|
+
}
|
|
11336
|
+
// Offline and server failures keep the newest dirty state for the next
|
|
11337
|
+
// mutation, online event, or foreground reconciliation.
|
|
11338
|
+
} finally {
|
|
11339
|
+
durableLayoutSaveInFlight = false;
|
|
11340
|
+
}
|
|
11341
|
+
const hasNewerMutation = [...durableLayoutDirtyFields].some(([field, entry]) => snapshot.get(field)?.generation !== entry.generation);
|
|
11342
|
+
if (retryImmediately || hasNewerMutation) scheduleDurableUiLayoutSave(retryImmediately ? 0 : UI_LAYOUT_SAVE_DEBOUNCE_MS);
|
|
11343
|
+
}
|
|
11344
|
+
|
|
11345
|
+
function reconcileDurableUiLayout() {
|
|
11346
|
+
if (durableUiLayoutInteractionActive()) return;
|
|
11347
|
+
refreshDurableUiLayoutFromServer().then((ready) => {
|
|
11348
|
+
if (ready && durableLayoutDirtyFields.size) scheduleDurableUiLayoutSave(0);
|
|
11349
|
+
});
|
|
11350
|
+
}
|
|
11351
|
+
|
|
10104
11352
|
function readStoredSidePanelWidth() {
|
|
10105
11353
|
try {
|
|
10106
11354
|
const width = Number.parseFloat(localStorage.getItem(SIDE_PANEL_WIDTH_STORAGE_KEY) || "");
|
|
@@ -10184,8 +11432,13 @@ async function restoreSidePanelWidthPreference() {
|
|
|
10184
11432
|
else updateSidePanelResizeHandle(localWidth || SIDE_PANEL_WIDTH_DEFAULT_PX);
|
|
10185
11433
|
|
|
10186
11434
|
const restoreRevision = sidePanelWidthPreferenceRevision;
|
|
11435
|
+
const layoutGenerations = new Map(UI_LAYOUT_FIELDS.map((field) => [field, durableUiLayoutGeneration(field)]));
|
|
11436
|
+
const readEpoch = ++durableLayoutReadEpoch;
|
|
10187
11437
|
try {
|
|
11438
|
+
// One non-blocking unscoped read hydrates both the width preference and the
|
|
11439
|
+
// durable layout after the synchronous local-cache startup pass.
|
|
10188
11440
|
const response = await api("/api/interface-preferences", { scoped: false });
|
|
11441
|
+
applyDurableUiLayoutSnapshot(response.data, { generations: layoutGenerations, readEpoch });
|
|
10189
11442
|
if (restoreRevision !== sidePanelWidthPreferenceRevision) return;
|
|
10190
11443
|
const userWidth = Number(response.data?.preferences?.sidePanelWidth);
|
|
10191
11444
|
if (Number.isFinite(userWidth) && userWidth >= SIDE_PANEL_WIDTH_MIN_PX) {
|
|
@@ -10253,7 +11506,10 @@ function syncSidePanelWidthForViewport() {
|
|
|
10253
11506
|
updateSidePanelResizeHandle();
|
|
10254
11507
|
return;
|
|
10255
11508
|
}
|
|
10256
|
-
|
|
11509
|
+
// Keep viewport/layout reconciliation anchored to the durable preference.
|
|
11510
|
+
// Reading the rendered width here can capture an in-progress CSS transition
|
|
11511
|
+
// during hard-reset startup and permanently freeze the panel below its saved width.
|
|
11512
|
+
applySidePanelWidth(readStoredSidePanelWidth() || currentSidePanelWidth());
|
|
10257
11513
|
}
|
|
10258
11514
|
|
|
10259
11515
|
function readStoredFileViewerWidth() {
|
|
@@ -10271,6 +11527,7 @@ function persistFileViewerWidth(width) {
|
|
|
10271
11527
|
} catch {
|
|
10272
11528
|
// Ignore storage failures; resizing should still work for this page load.
|
|
10273
11529
|
}
|
|
11530
|
+
markDurableUiLayoutDirty("fileViewerWidth");
|
|
10274
11531
|
}
|
|
10275
11532
|
|
|
10276
11533
|
function fileViewerMaxWidth() {
|
|
@@ -11176,7 +12433,7 @@ function syncTabMetadata(nextTabs = []) {
|
|
|
11176
12433
|
suppressPendingAgentDoneNotificationsForTab(tabId, { markSeen: false });
|
|
11177
12434
|
actionFeedbackByTab.delete(tabId);
|
|
11178
12435
|
skillUsageByTab.delete(tabId);
|
|
11179
|
-
|
|
12436
|
+
clearFeatureDecisionStateForTab(tabId);
|
|
11180
12437
|
tabMessagesCache.delete(tabId);
|
|
11181
12438
|
widgetsByTab.delete(tabId);
|
|
11182
12439
|
appRunnerDataByTab.delete(tabId);
|
|
@@ -11502,6 +12759,7 @@ function cancelPendingDialogs() {
|
|
|
11502
12759
|
}).catch((error) => console.warn("failed to cancel stale extension dialog", error));
|
|
11503
12760
|
}
|
|
11504
12761
|
activeDialog = null;
|
|
12762
|
+
activeDialogCancel = null;
|
|
11505
12763
|
if (elements.dialog.open) elements.dialog.close();
|
|
11506
12764
|
}
|
|
11507
12765
|
|
|
@@ -13122,7 +14380,7 @@ async function closeTerminalTabs(tabIds, { label = "selected terminal tabs", all
|
|
|
13122
14380
|
tabDrafts.delete(id);
|
|
13123
14381
|
clearAttachments(id);
|
|
13124
14382
|
clearGitWorkflowForTab(id);
|
|
13125
|
-
|
|
14383
|
+
clearFeatureDecisionStateForTab(id);
|
|
13126
14384
|
commandCatalogsByTab.delete(id);
|
|
13127
14385
|
appRunnerDataByTab.delete(id);
|
|
13128
14386
|
tabMessagesCache.delete(id);
|
|
@@ -13175,6 +14433,10 @@ async function closeAllTerminalTabs() {
|
|
|
13175
14433
|
|
|
13176
14434
|
async function initializeTabs() {
|
|
13177
14435
|
const loadedTabs = await refreshTabs({ selectStored: true });
|
|
14436
|
+
// Durable groups can arrive before the initial tab catalog. Rehydrate them
|
|
14437
|
+
// after tabs load so valid memberships are not filtered against an empty set.
|
|
14438
|
+
restoreTerminalCustomGroups();
|
|
14439
|
+
syncTerminalCustomGroupsWithTabs(tabs, { persist: false });
|
|
13178
14440
|
restoreMobileContinuityState();
|
|
13179
14441
|
resetActiveTabUi();
|
|
13180
14442
|
renderTabs();
|
|
@@ -18282,6 +19544,7 @@ function writeFooterScopedModelOrder(order) {
|
|
|
18282
19544
|
try {
|
|
18283
19545
|
localStorage.setItem(FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY, JSON.stringify([...new Set(order.filter(Boolean))]));
|
|
18284
19546
|
} catch {}
|
|
19547
|
+
markDurableUiLayoutDirty("footerScopedModelOrder");
|
|
18285
19548
|
}
|
|
18286
19549
|
|
|
18287
19550
|
function orderedFooterScopedModels() {
|
|
@@ -19754,7 +21017,7 @@ function finishedSubagentRunSelections(data = latestSubagents) {
|
|
|
19754
21017
|
));
|
|
19755
21018
|
}
|
|
19756
21019
|
|
|
19757
|
-
async function clearFinishedSubagentRuns() {
|
|
21020
|
+
async function clearFinishedSubagentRuns({ automatic = false } = {}) {
|
|
19758
21021
|
if (subagentsClearingFinished || subagentsLoading) return;
|
|
19759
21022
|
const selections = finishedSubagentRunSelections();
|
|
19760
21023
|
if (!selections.length) return;
|
|
@@ -19782,8 +21045,8 @@ async function clearFinishedSubagentRuns() {
|
|
|
19782
21045
|
renderSubagents();
|
|
19783
21046
|
scheduleRefreshSubagents();
|
|
19784
21047
|
}
|
|
19785
|
-
if (dismissed) addEvent(
|
|
19786
|
-
if (failures.length) addEvent(`could not clear ${failures.length} finished subagent ${failures.length === 1 ? "run" : "runs"}`, "warn");
|
|
21048
|
+
if (dismissed) addEvent(`${automatic ? "auto-cleared" : "cleared"} ${dismissed} finished subagent ${dismissed === 1 ? "run" : "runs"}`, "info");
|
|
21049
|
+
if (failures.length) addEvent(`could not ${automatic ? "auto-clear" : "clear"} ${failures.length} finished subagent ${failures.length === 1 ? "run" : "runs"}`, "warn");
|
|
19787
21050
|
}
|
|
19788
21051
|
|
|
19789
21052
|
function subagentOverlayTranscriptMessages(data = subagentOverlayData) {
|
|
@@ -20796,6 +22059,13 @@ function renderSubagents() {
|
|
|
20796
22059
|
elements.subagentCountBadge.textContent = String(totalAgents);
|
|
20797
22060
|
elements.subagentCountBadge.hidden = totalAgents === 0;
|
|
20798
22061
|
}
|
|
22062
|
+
if (elements.subagentsAutoClearButton) {
|
|
22063
|
+
elements.subagentsAutoClearButton.setAttribute("aria-pressed", subagentAutoClearEnabled ? "true" : "false");
|
|
22064
|
+
elements.subagentsAutoClearButton.classList.toggle("selected", subagentAutoClearEnabled);
|
|
22065
|
+
elements.subagentsAutoClearButton.title = subagentAutoClearEnabled
|
|
22066
|
+
? "Auto-Clear is on: finished subagent runs are removed automatically"
|
|
22067
|
+
: "Auto-Clear is off: keep finished subagent runs until they are cleared manually";
|
|
22068
|
+
}
|
|
20799
22069
|
if (elements.subagentsClearFinishedButton) {
|
|
20800
22070
|
elements.subagentsClearFinishedButton.disabled = subagentsLoading || subagentsClearingFinished || finishedRuns.length === 0;
|
|
20801
22071
|
elements.subagentsClearFinishedButton.textContent = subagentsClearingFinished ? "Clearing…" : "Clear finished";
|
|
@@ -20826,6 +22096,7 @@ function renderSubagents() {
|
|
|
20826
22096
|
|
|
20827
22097
|
async function refreshSubagents() {
|
|
20828
22098
|
if (subagentsLoading) return;
|
|
22099
|
+
let refreshed = false;
|
|
20829
22100
|
let subagentViewsChanged = false;
|
|
20830
22101
|
let materializedTerminalViews = false;
|
|
20831
22102
|
subagentsLoading = true;
|
|
@@ -20837,6 +22108,7 @@ async function refreshSubagents() {
|
|
|
20837
22108
|
subagentViewsChanged = syncSubagentTerminalViewsFromOverview();
|
|
20838
22109
|
materializedTerminalViews = materializeRetainedSubagentTerminalViews();
|
|
20839
22110
|
subagentsError = null;
|
|
22111
|
+
refreshed = true;
|
|
20840
22112
|
} catch (error) {
|
|
20841
22113
|
subagentsError = error;
|
|
20842
22114
|
} finally {
|
|
@@ -20849,6 +22121,9 @@ async function refreshSubagents() {
|
|
|
20849
22121
|
}
|
|
20850
22122
|
if (subagentViewsChanged || materializedTerminalViews) renderTabs();
|
|
20851
22123
|
}
|
|
22124
|
+
if (refreshed && subagentAutoClearEnabled && finishedSubagentRunSelections().length) {
|
|
22125
|
+
await clearFinishedSubagentRuns({ automatic: true });
|
|
22126
|
+
}
|
|
20852
22127
|
}
|
|
20853
22128
|
|
|
20854
22129
|
function scheduleRefreshSubagents(delay) {
|
|
@@ -21461,6 +22736,166 @@ function releaseDialogLineClass(plainLine, section) {
|
|
|
21461
22736
|
return "";
|
|
21462
22737
|
}
|
|
21463
22738
|
|
|
22739
|
+
// Enter inside a native input dialog must never fall through to the browser's
|
|
22740
|
+
// implicit `method="dialog"` submission. "ignore" leaves IME composition alone,
|
|
22741
|
+
// "suppress" only blocks the implicit close, and "submit" sends one response.
|
|
22742
|
+
function dialogInputEnterIntent(event) {
|
|
22743
|
+
if (!event || event.key !== "Enter") return "ignore";
|
|
22744
|
+
if (event.isComposing || event.keyCode === 229) return "ignore";
|
|
22745
|
+
if (event.repeat) return "suppress";
|
|
22746
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return "suppress";
|
|
22747
|
+
return "submit";
|
|
22748
|
+
}
|
|
22749
|
+
|
|
22750
|
+
const QUESTIONNAIRE_TITLE_PATTERN = /^Question\s+([1-9]\d*)\s+of\s+([1-9]\d*):\s+\S.*$/;
|
|
22751
|
+
const QUESTIONNAIRE_ROW_PATTERN = /^(\d{2})\.\s(.*)$/;
|
|
22752
|
+
const QUESTIONNAIRE_STATE_PATTERN = /^(\[ \]|\[x\]|\[selected\])\s(.*)$/;
|
|
22753
|
+
const QUESTIONNAIRE_MAX_QUESTIONS = 20;
|
|
22754
|
+
const QUESTIONNAIRE_MAX_OPTIONS = 50;
|
|
22755
|
+
|
|
22756
|
+
function isQuestionnaireChangeOtherAction(value) {
|
|
22757
|
+
const prefix = "Change Other… (currently ";
|
|
22758
|
+
if (!value.startsWith(prefix) || !value.endsWith(")")) return false;
|
|
22759
|
+
const encoded = value.slice(prefix.length, -1);
|
|
22760
|
+
try {
|
|
22761
|
+
const other = JSON.parse(encoded);
|
|
22762
|
+
return typeof other === "string" && JSON.stringify(other) === encoded;
|
|
22763
|
+
} catch {
|
|
22764
|
+
return false;
|
|
22765
|
+
}
|
|
22766
|
+
}
|
|
22767
|
+
|
|
22768
|
+
// Bounded, presentation-only grammar for the native questionnaire runtime's
|
|
22769
|
+
// action strings. Anything outside this list stays a generic option.
|
|
22770
|
+
function questionnaireContinueCount(text) {
|
|
22771
|
+
const match = String(text || "").match(/^Continue with (0|[1-9]\d*) selection\(s\)$/);
|
|
22772
|
+
if (!match) return null;
|
|
22773
|
+
const count = Number(match[1]);
|
|
22774
|
+
return Number.isSafeInteger(count) && count <= QUESTIONNAIRE_MAX_OPTIONS + 1 ? count : null;
|
|
22775
|
+
}
|
|
22776
|
+
|
|
22777
|
+
function questionnaireActionKind(text) {
|
|
22778
|
+
const value = String(text || "");
|
|
22779
|
+
if (value === "Cancel questionnaire") return "cancel";
|
|
22780
|
+
if (value === "Ask Pi to clarify…") return "clarify";
|
|
22781
|
+
if (value === "Remove Other answer") return "remove-other";
|
|
22782
|
+
if (value === "Other… (enter a custom answer)" || value === "Add Other…") return "other";
|
|
22783
|
+
if (isQuestionnaireChangeOtherAction(value)) return "other";
|
|
22784
|
+
if (questionnaireContinueCount(value) !== null) return "continue";
|
|
22785
|
+
return null;
|
|
22786
|
+
}
|
|
22787
|
+
|
|
22788
|
+
// Parses one native option string for presentation only; the caller always
|
|
22789
|
+
// transports the untouched original string back to the extension.
|
|
22790
|
+
function parseQuestionnaireOption(text) {
|
|
22791
|
+
const value = String(text || "");
|
|
22792
|
+
const action = questionnaireActionKind(value);
|
|
22793
|
+
if (action) return { kind: "action", action, value };
|
|
22794
|
+
|
|
22795
|
+
const row = value.match(QUESTIONNAIRE_ROW_PATTERN);
|
|
22796
|
+
if (!row) return null;
|
|
22797
|
+
const number = row[1];
|
|
22798
|
+
const state = row[2].match(QUESTIONNAIRE_STATE_PATTERN);
|
|
22799
|
+
const marker = state ? (state[1] === "[ ]" ? "unselected" : "selected") : "none";
|
|
22800
|
+
const body = state ? state[2] : row[2];
|
|
22801
|
+
if (!body.trim()) return null;
|
|
22802
|
+
|
|
22803
|
+
const separator = body.indexOf(" — ");
|
|
22804
|
+
const label = separator === -1 ? body : body.slice(0, separator);
|
|
22805
|
+
const description = separator === -1 ? "" : body.slice(separator + 3);
|
|
22806
|
+
if (!label.trim()) return null;
|
|
22807
|
+
return { kind: "option", marker, number, label, description, value };
|
|
22808
|
+
}
|
|
22809
|
+
|
|
22810
|
+
function questionnaireActionSequenceMatches(mode, actionRows) {
|
|
22811
|
+
const values = actionRows.map((row) => row.value);
|
|
22812
|
+
if (mode === "single") {
|
|
22813
|
+
const expected = values[0] === "Other… (enter a custom answer)"
|
|
22814
|
+
? ["Other… (enter a custom answer)", "Ask Pi to clarify…", "Cancel questionnaire"]
|
|
22815
|
+
: ["Ask Pi to clarify…", "Cancel questionnaire"];
|
|
22816
|
+
return values.length === expected.length && values.every((value, index) => value === expected[index]);
|
|
22817
|
+
}
|
|
22818
|
+
|
|
22819
|
+
let index = 0;
|
|
22820
|
+
if (values[index] === "Add Other…") {
|
|
22821
|
+
index += 1;
|
|
22822
|
+
} else if (isQuestionnaireChangeOtherAction(values[index] || "")) {
|
|
22823
|
+
index += 1;
|
|
22824
|
+
if (values[index] !== "Remove Other answer") return false;
|
|
22825
|
+
index += 1;
|
|
22826
|
+
}
|
|
22827
|
+
if (values[index] !== "Ask Pi to clarify…") return false;
|
|
22828
|
+
index += 1;
|
|
22829
|
+
if (questionnaireContinueCount(values[index]) === null) return false;
|
|
22830
|
+
index += 1;
|
|
22831
|
+
return values[index] === "Cancel questionnaire" && index === values.length - 1;
|
|
22832
|
+
}
|
|
22833
|
+
|
|
22834
|
+
// Detection requires the complete runtime title, contiguous numbered rows, one
|
|
22835
|
+
// consistent state-marker mode, and the exact ordered action tail. This keeps
|
|
22836
|
+
// lookalike extension selects on the generic renderer.
|
|
22837
|
+
function questionnaireSelectParts(prompt, options) {
|
|
22838
|
+
if (!Array.isArray(options) || options.length < 3 || options.length > QUESTIONNAIRE_MAX_OPTIONS + 5) return null;
|
|
22839
|
+
const title = stripAnsi(prompt?.title || "").trim();
|
|
22840
|
+
const titleMatch = title.match(QUESTIONNAIRE_TITLE_PATTERN);
|
|
22841
|
+
if (!titleMatch) return null;
|
|
22842
|
+
const current = Number(titleMatch[1]);
|
|
22843
|
+
const total = Number(titleMatch[2]);
|
|
22844
|
+
if (current > total || total > QUESTIONNAIRE_MAX_QUESTIONS) return null;
|
|
22845
|
+
|
|
22846
|
+
const rows = [];
|
|
22847
|
+
for (const option of options) {
|
|
22848
|
+
const parsed = parseQuestionnaireOption(String(option));
|
|
22849
|
+
if (!parsed) return null;
|
|
22850
|
+
rows.push(parsed);
|
|
22851
|
+
}
|
|
22852
|
+
|
|
22853
|
+
const firstAction = rows.findIndex((row) => row.kind === "action");
|
|
22854
|
+
if (firstAction < 1 || firstAction > QUESTIONNAIRE_MAX_OPTIONS) return null;
|
|
22855
|
+
const optionRows = rows.slice(0, firstAction);
|
|
22856
|
+
const actionRows = rows.slice(firstAction);
|
|
22857
|
+
if (actionRows.some((row) => row.kind !== "action")) return null;
|
|
22858
|
+
if (!optionRows.every((row, index) => row.kind === "option" && row.number === String(index + 1).padStart(2, "0"))) return null;
|
|
22859
|
+
|
|
22860
|
+
const single = optionRows.every((row) => row.marker === "none");
|
|
22861
|
+
const multi = optionRows.every((row) => row.marker !== "none");
|
|
22862
|
+
if (!single && !multi) return null;
|
|
22863
|
+
const mode = multi ? "multi" : "single";
|
|
22864
|
+
if (!questionnaireActionSequenceMatches(mode, actionRows)) return null;
|
|
22865
|
+
return { rows, mode };
|
|
22866
|
+
}
|
|
22867
|
+
|
|
22868
|
+
function renderQuestionnaireOptionButton(row, mode) {
|
|
22869
|
+
const classNames = ["questionnaire-option", `questionnaire-option-${mode}`];
|
|
22870
|
+
if (row.marker === "selected") classNames.push("is-selected");
|
|
22871
|
+
const button = make("button", classNames.join(" "));
|
|
22872
|
+
button.type = "button";
|
|
22873
|
+
// The visible text is split into semantic parts, so the accessible name keeps
|
|
22874
|
+
// the exact native string that click transport sends back.
|
|
22875
|
+
button.setAttribute("aria-label", row.value);
|
|
22876
|
+
if (row.marker !== "none") button.setAttribute("aria-pressed", String(row.marker === "selected"));
|
|
22877
|
+
|
|
22878
|
+
button.append(make("span", "questionnaire-option-number", row.number));
|
|
22879
|
+
if (row.marker !== "none") {
|
|
22880
|
+
const state = make("span", "questionnaire-option-state", row.marker === "selected" ? "✓" : "");
|
|
22881
|
+
state.setAttribute("aria-hidden", "true");
|
|
22882
|
+
button.append(state);
|
|
22883
|
+
}
|
|
22884
|
+
const text = make("span", "questionnaire-option-text");
|
|
22885
|
+
text.append(make("span", "questionnaire-option-label", row.label));
|
|
22886
|
+
if (row.description) text.append(make("span", "questionnaire-option-description", row.description));
|
|
22887
|
+
button.append(text);
|
|
22888
|
+
return button;
|
|
22889
|
+
}
|
|
22890
|
+
|
|
22891
|
+
function renderQuestionnaireActionButton(row) {
|
|
22892
|
+
const classNames = ["questionnaire-action", `questionnaire-action-${row.action}`];
|
|
22893
|
+
if (row.action === "continue") classNames.push("primary");
|
|
22894
|
+
const button = make("button", classNames.join(" "), row.value);
|
|
22895
|
+
button.type = "button";
|
|
22896
|
+
return button;
|
|
22897
|
+
}
|
|
22898
|
+
|
|
21464
22899
|
function renderReleaseDialogMessage(parent, text) {
|
|
21465
22900
|
parent.replaceChildren();
|
|
21466
22901
|
let section = "";
|
|
@@ -23319,6 +24754,7 @@ function renderAppRunnerControls() {
|
|
|
23319
24754
|
item.append(label, command);
|
|
23320
24755
|
panel.append(item);
|
|
23321
24756
|
}
|
|
24757
|
+
scheduleComposerActionSlotLayoutRestore();
|
|
23322
24758
|
}
|
|
23323
24759
|
|
|
23324
24760
|
function renderAppRunnerInfoDialog() {
|
|
@@ -29839,10 +31275,10 @@ function resetChatOutput() {
|
|
|
29839
31275
|
transcriptRenderer.replaceChildren(elements.chat, ...preservedNodes);
|
|
29840
31276
|
}
|
|
29841
31277
|
|
|
29842
|
-
function appendChatMessageBubble(bubble) {
|
|
31278
|
+
function appendChatMessageBubble(bubble, { liveTail = false } = {}) {
|
|
29843
31279
|
const liveBubbles = standaloneLiveTranscriptBubbles();
|
|
29844
31280
|
const tailAnchor = [...elements.chat.children]
|
|
29845
|
-
.find((child) => child !== bubble && (child === runIndicatorBubble || liveBubbles.has(child)));
|
|
31281
|
+
.find((child) => child !== bubble && (child === runIndicatorBubble || (!liveTail && liveBubbles.has(child))));
|
|
29846
31282
|
if (tailAnchor) elements.chat.insertBefore(bubble, tailAnchor);
|
|
29847
31283
|
else elements.chat.append(bubble);
|
|
29848
31284
|
}
|
|
@@ -31082,7 +32518,7 @@ function appendMessage(message, options = {}) {
|
|
|
31082
32518
|
return reused;
|
|
31083
32519
|
}
|
|
31084
32520
|
const created = createMessageBubble(message, { ...options, segmentId });
|
|
31085
|
-
appendChatMessageBubble(created.bubble);
|
|
32521
|
+
appendChatMessageBubble(created.bubble, { liveTail: streaming || message?.live === true });
|
|
31086
32522
|
return created;
|
|
31087
32523
|
}
|
|
31088
32524
|
|
|
@@ -32421,6 +33857,7 @@ function resetOptionalFeatureAvailability() {
|
|
|
32421
33857
|
for (const key of Object.keys(optionalFeatureAvailability)) optionalFeatureAvailability[key] = false;
|
|
32422
33858
|
optionalFeatureAvailability.themeBundle = availableThemes.length > 0;
|
|
32423
33859
|
renderOptionalFeatureControls();
|
|
33860
|
+
if (activeTabId) queueMicrotask(() => refreshQuestionnaireFeatureAvailability());
|
|
32424
33861
|
}
|
|
32425
33862
|
|
|
32426
33863
|
function optionalFeaturePackageStatus(featureId) {
|
|
@@ -32510,6 +33947,24 @@ async function copyOptionalFeatureInstallCommand(featureId) {
|
|
|
32510
33947
|
}
|
|
32511
33948
|
}
|
|
32512
33949
|
|
|
33950
|
+
async function refreshQuestionnaireFeatureAvailability(tabContext = activeTabContext()) {
|
|
33951
|
+
if (!tabContext.tabId) return false;
|
|
33952
|
+
try {
|
|
33953
|
+
const response = await api("/api/tools?scope=session", { tabId: tabContext.tabId });
|
|
33954
|
+
if (!isCurrentTabContext(tabContext)) return false;
|
|
33955
|
+
optionalFeatureAvailability.questionnaire = Array.isArray(response.data?.tools)
|
|
33956
|
+
&& response.data.tools.some((tool) => tool?.name === "questionnaire");
|
|
33957
|
+
renderOptionalFeatureControls();
|
|
33958
|
+
return true;
|
|
33959
|
+
} catch {
|
|
33960
|
+
if (isCurrentTabContext(tabContext)) {
|
|
33961
|
+
optionalFeatureAvailability.questionnaire = false;
|
|
33962
|
+
renderOptionalFeatureControls();
|
|
33963
|
+
}
|
|
33964
|
+
return false;
|
|
33965
|
+
}
|
|
33966
|
+
}
|
|
33967
|
+
|
|
32513
33968
|
async function refreshOptionalFeaturePackageStatuses({ announce = false } = {}) {
|
|
32514
33969
|
try {
|
|
32515
33970
|
const response = await api("/api/optional-features", { scoped: false });
|
|
@@ -32518,6 +33973,7 @@ async function refreshOptionalFeaturePackageStatuses({ announce = false } = {})
|
|
|
32518
33973
|
for (const status of response.data?.features || []) {
|
|
32519
33974
|
if (status?.featureId) optionalFeaturePackageStatuses.set(status.featureId, status);
|
|
32520
33975
|
}
|
|
33976
|
+
await refreshQuestionnaireFeatureAvailability();
|
|
32521
33977
|
renderOptionalFeatureControls();
|
|
32522
33978
|
return true;
|
|
32523
33979
|
} catch (error) {
|
|
@@ -32635,8 +34091,10 @@ function updateOptionalFeatureAvailability() {
|
|
|
32635
34091
|
}
|
|
32636
34092
|
|
|
32637
34093
|
function optionalFeatureStatus(featureId) {
|
|
34094
|
+
const feature = OPTIONAL_FEATURE_BY_ID.get(featureId);
|
|
32638
34095
|
const detected = isOptionalFeatureDetected(featureId);
|
|
32639
|
-
const
|
|
34096
|
+
const managedWithTools = feature?.manageWith === "tools";
|
|
34097
|
+
const disabled = managedWithTools ? false : isOptionalFeatureDisabled(featureId);
|
|
32640
34098
|
const packageStatus = optionalFeaturePackageStatus(featureId);
|
|
32641
34099
|
const installMessage = optionalFeatureInstallMessages.get(featureId);
|
|
32642
34100
|
const installState = optionalFeatureInstallState(featureId);
|
|
@@ -32663,6 +34121,7 @@ function optionalFeatureStatus(featureId) {
|
|
|
32663
34121
|
}
|
|
32664
34122
|
const doneDetail = installState?.phase === "done" ? optionalFeatureInstallDetail(installState, installMessage) : "";
|
|
32665
34123
|
if (packageStatus?.updateAvailable) return { label: "Update available", className: "updating", detail: packageStatus.updateReason || `Installed package is older than the Web UI expects${versionSuffix}` };
|
|
34124
|
+
if (detected && managedWithTools) return { label: "Loaded", className: "enabled", detail: doneDetail || `Detected in the active Pi tab; manage access in Tools${versionSuffix}`, command: installState?.command || "" };
|
|
32666
34125
|
if (detected && !disabled) return { label: "Enabled", className: "enabled", detail: doneDetail || `Detected and enabled in Web UI${versionSuffix}`, command: installState?.command || "" };
|
|
32667
34126
|
if (detected && disabled) return { label: "Disabled", className: "disabled", detail: `Detected, but disabled in Web UI${versionSuffix}` };
|
|
32668
34127
|
if (packageStatus?.installed) return { label: "Installed", className: "installed", detail: doneDetail || `Package is installed but not loaded in the active Pi tab${versionSuffix}`, command: installState?.command || "" };
|
|
@@ -32809,6 +34268,9 @@ function renderOptionalFeatureRow(feature) {
|
|
|
32809
34268
|
action.textContent = "Update…";
|
|
32810
34269
|
action.classList.add("update");
|
|
32811
34270
|
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: true }));
|
|
34271
|
+
} else if (detected && feature.manageWith === "tools") {
|
|
34272
|
+
action.textContent = "Tools…";
|
|
34273
|
+
action.addEventListener("click", () => openNativeToolsSelector());
|
|
32812
34274
|
} else if (detected) {
|
|
32813
34275
|
action.textContent = enabled ? "Disable" : "Enable";
|
|
32814
34276
|
action.addEventListener("click", async () => {
|
|
@@ -35112,7 +36574,7 @@ function renderCompactToolShell(event, { complete = false } = {}) {
|
|
|
35112
36574
|
transcriptRenderer.ownMessage(bubble, { key: `live:compact-tool:${id}`, role: "toolExecution" });
|
|
35113
36575
|
transcriptRenderer.ownSurface(body, { messageKey: `live:compact-tool:${id}`, kind: "tool-execution", segment: "0" });
|
|
35114
36576
|
transcriptRenderer.ownSurface(status, { messageKey: `live:compact-tool:${id}`, kind: "tool-execution", segment: "status" });
|
|
35115
|
-
appendChatMessageBubble(bubble);
|
|
36577
|
+
appendChatMessageBubble(bubble, { liveTail: true });
|
|
35116
36578
|
shell = { bubble, role, status };
|
|
35117
36579
|
compactToolShells.set(id, shell);
|
|
35118
36580
|
}
|
|
@@ -35529,26 +36991,38 @@ function restoreCompactLiveOutputAfterChatRebuild() {
|
|
|
35529
36991
|
compactThinkingBubble = null;
|
|
35530
36992
|
compactThinkingNode = null;
|
|
35531
36993
|
if (streamMessageActive) flushCompactLiveOutput();
|
|
35532
|
-
for (const shell of compactToolShells.values()) appendChatMessageBubble(shell.bubble);
|
|
36994
|
+
for (const shell of compactToolShells.values()) appendChatMessageBubble(shell.bubble, { liveTail: true });
|
|
35533
36995
|
renderRunIndicator({ scroll: false });
|
|
35534
36996
|
}
|
|
35535
36997
|
|
|
35536
36998
|
/**
|
|
35537
|
-
*
|
|
35538
|
-
*
|
|
35539
|
-
*
|
|
36999
|
+
* Reconcile live stream surfaces after an authoritative transcript render.
|
|
37000
|
+
* Transcript resets intentionally keep mounted live-tail bubbles, so reuse
|
|
37001
|
+
* those nodes and only rebuild a surface when it was actually detached.
|
|
35540
37002
|
*/
|
|
35541
37003
|
function restoreStreamRenderAfterChatRebuild() {
|
|
35542
37004
|
const thinkingText = streamThinking?._rawThinkingText || streamThinking?.textContent || "";
|
|
35543
37005
|
const thinkingComplete = streamThinkingBubble?.classList.contains("complete") === true;
|
|
35544
37006
|
const toolCallWasVisible = !!(streamToolCallBubble?.parentElement === elements.chat || streamToolCallRawArguments || streamToolCallName);
|
|
35545
|
-
|
|
35546
|
-
|
|
35547
|
-
|
|
35548
|
-
|
|
35549
|
-
|
|
35550
|
-
|
|
35551
|
-
|
|
37007
|
+
const streamOutputMounted = !!(streamBubble?.parentElement === elements.chat && streamText?.isConnected && streamBubble.contains(streamText));
|
|
37008
|
+
const thinkingOutputMounted = !!(streamThinkingBubble?.parentElement === elements.chat && streamThinking?.isConnected && streamThinkingBubble.contains(streamThinking));
|
|
37009
|
+
const toolCallOutputMounted = !!(streamToolCallBubble?.parentElement === elements.chat && streamToolCallText?.isConnected && streamToolCallBubble.contains(streamToolCallText));
|
|
37010
|
+
if (!streamOutputMounted) {
|
|
37011
|
+
removeLiveTranscriptBubble(streamBubble, "assistant-rebuild");
|
|
37012
|
+
streamBubble = null;
|
|
37013
|
+
streamText = null;
|
|
37014
|
+
streamBubbleVisibleSince = 0;
|
|
37015
|
+
}
|
|
37016
|
+
if (!thinkingOutputMounted) {
|
|
37017
|
+
removeLiveTranscriptBubble(streamThinkingBubble, "thinking-rebuild");
|
|
37018
|
+
streamThinkingBubble = null;
|
|
37019
|
+
streamThinking = null;
|
|
37020
|
+
}
|
|
37021
|
+
if (!toolCallOutputMounted) {
|
|
37022
|
+
removeLiveTranscriptBubble(streamToolCallBubble, "tool-call-rebuild");
|
|
37023
|
+
streamToolCallBubble = null;
|
|
37024
|
+
streamToolCallText = null;
|
|
37025
|
+
}
|
|
35552
37026
|
if (thinkingText && setStreamingThinkingText(thinkingText) && thinkingComplete) {
|
|
35553
37027
|
streamThinkingBubble?.classList.add("complete");
|
|
35554
37028
|
}
|
|
@@ -37691,6 +39165,7 @@ function removeQueuedDialogRequests(ids = []) {
|
|
|
37691
39165
|
if (activeDialog && idSet.has(String(activeDialog.id || ""))) {
|
|
37692
39166
|
if (elements.dialog.open) elements.dialog.close();
|
|
37693
39167
|
activeDialog = null;
|
|
39168
|
+
activeDialogCancel = null;
|
|
37694
39169
|
showNextDialog();
|
|
37695
39170
|
return true;
|
|
37696
39171
|
}
|
|
@@ -37709,6 +39184,10 @@ function handleExtensionUiRequest(request) {
|
|
|
37709
39184
|
}
|
|
37710
39185
|
case "setStatus": {
|
|
37711
39186
|
const statusKey = request.statusKey || "extension";
|
|
39187
|
+
if (statusKey === FEATURE_DECISION_OUTPUT_STATUS_KEY) {
|
|
39188
|
+
handleFeatureDecisionOutputStatus(request.statusText, request.tabId || activeTabId);
|
|
39189
|
+
return;
|
|
39190
|
+
}
|
|
37712
39191
|
if (statusKey === FEATURE_CATEGORY_STATUS_KEY) {
|
|
37713
39192
|
handleFeatureCategoryStatus(request.statusText, request.tabId || activeTabId);
|
|
37714
39193
|
return;
|
|
@@ -37831,6 +39310,7 @@ async function sendDialogResponse(payload) {
|
|
|
37831
39310
|
if (responseId && activeDialog && String(activeDialog.id || "") !== responseId) return;
|
|
37832
39311
|
if (elements.dialog.open) elements.dialog.close();
|
|
37833
39312
|
activeDialog = null;
|
|
39313
|
+
activeDialogCancel = null;
|
|
37834
39314
|
if (runIndicatorIsActive()) {
|
|
37835
39315
|
setRunIndicatorActivity("Continuing after your response…");
|
|
37836
39316
|
// Extension commands can continue background work after Pi has already
|
|
@@ -37842,6 +39322,23 @@ async function sendDialogResponse(payload) {
|
|
|
37842
39322
|
}
|
|
37843
39323
|
}
|
|
37844
39324
|
|
|
39325
|
+
function cancelActiveExtensionDialog(event) {
|
|
39326
|
+
if (!activeDialog || typeof activeDialogCancel !== "function") return false;
|
|
39327
|
+
event?.preventDefault?.();
|
|
39328
|
+
return activeDialogCancel();
|
|
39329
|
+
}
|
|
39330
|
+
|
|
39331
|
+
function createDialogResponder(sendResponse) {
|
|
39332
|
+
let responseSent = false;
|
|
39333
|
+
return (response, onAccept) => {
|
|
39334
|
+
if (responseSent) return false;
|
|
39335
|
+
responseSent = true;
|
|
39336
|
+
onAccept?.();
|
|
39337
|
+
sendResponse(response);
|
|
39338
|
+
return true;
|
|
39339
|
+
};
|
|
39340
|
+
}
|
|
39341
|
+
|
|
37845
39342
|
function addDialogButton(label, handler, className) {
|
|
37846
39343
|
const button = make("button", className, label);
|
|
37847
39344
|
button.type = "button";
|
|
@@ -37877,7 +39374,7 @@ function appendWorkflowScriptTokens(parent, line) {
|
|
|
37877
39374
|
if (start < line.length) parent.append(document.createTextNode(line.slice(start)));
|
|
37878
39375
|
}
|
|
37879
39376
|
|
|
37880
|
-
function renderWorkflowScriptPreview(request) {
|
|
39377
|
+
function renderWorkflowScriptPreview(request, respondToDialog) {
|
|
37881
39378
|
const source = request.prefill ?? "";
|
|
37882
39379
|
const sourceLines = source.split("\n");
|
|
37883
39380
|
const searchableLines = sourceLines.map((line) => line.toLocaleLowerCase());
|
|
@@ -38019,14 +39516,15 @@ function renderWorkflowScriptPreview(request) {
|
|
|
38019
39516
|
|
|
38020
39517
|
preview.append(metadata, toolbar, codeViewer);
|
|
38021
39518
|
elements.dialogBody.append(preview);
|
|
38022
|
-
addDialogButton("Cancel workflow", () =>
|
|
38023
|
-
addDialogButton("Back to approval", () =>
|
|
39519
|
+
addDialogButton("Cancel workflow", () => respondToDialog({ cancelled: true }));
|
|
39520
|
+
addDialogButton("Back to approval", () => respondToDialog({ value: request.prefill }), "primary");
|
|
38024
39521
|
setTimeout(() => codeViewer.focus(), 0);
|
|
38025
39522
|
}
|
|
38026
39523
|
|
|
38027
39524
|
function showNextDialog() {
|
|
38028
39525
|
if (activeDialog || dialogQueue.length === 0) return;
|
|
38029
39526
|
activeDialog = dialogQueue.shift();
|
|
39527
|
+
activeDialogCancel = null;
|
|
38030
39528
|
const request = activeDialog;
|
|
38031
39529
|
|
|
38032
39530
|
const prompt = normalizeDialogPrompt(request);
|
|
@@ -38036,9 +39534,11 @@ function showNextDialog() {
|
|
|
38036
39534
|
const isGuardrailDialog = isGuardrailDialogPrompt(displayPrompt);
|
|
38037
39535
|
const isReleaseDialog = !!releasePrompt;
|
|
38038
39536
|
const isWorkflowScriptPreview = isWorkflowScriptPreviewRequest(request, prompt);
|
|
39537
|
+
const questionnaire = request.method === "select" && !isReleaseDialog ? questionnaireSelectParts(prompt, request.options) : null;
|
|
38039
39538
|
elements.dialog.classList.toggle("guardrail-dialog", isGuardrailDialog);
|
|
38040
39539
|
elements.dialog.classList.toggle("release-dialog", isReleaseDialog);
|
|
38041
39540
|
elements.dialog.classList.toggle("workflow-script-dialog", isWorkflowScriptPreview);
|
|
39541
|
+
elements.dialog.classList.toggle("questionnaire-dialog", !!questionnaire);
|
|
38042
39542
|
elements.dialogTitle.textContent = displayPrompt.title;
|
|
38043
39543
|
if (isReleaseDialog) renderReleaseDialogMessage(elements.dialogMessage, displayPrompt.message);
|
|
38044
39544
|
else renderAnsiText(elements.dialogMessage, displayPrompt.message);
|
|
@@ -38046,9 +39546,33 @@ function showNextDialog() {
|
|
|
38046
39546
|
elements.dialogBody.replaceChildren();
|
|
38047
39547
|
elements.dialogActions.replaceChildren();
|
|
38048
39548
|
|
|
38049
|
-
const
|
|
38050
|
-
|
|
38051
|
-
|
|
39549
|
+
const respondToDialog = createDialogResponder((response) => {
|
|
39550
|
+
sendDialogResponse({ type: "extension_ui_response", id: request.id, tabId: request.tabId, ...response });
|
|
39551
|
+
});
|
|
39552
|
+
const cancel = () => respondToDialog({ cancelled: true });
|
|
39553
|
+
activeDialogCancel = cancel;
|
|
39554
|
+
|
|
39555
|
+
if (questionnaire) {
|
|
39556
|
+
const options = make("div", "dialog-options questionnaire-options");
|
|
39557
|
+
const respondToQuestionnaire = (response) => respondToDialog(response, () => {
|
|
39558
|
+
options.querySelectorAll("button").forEach((button) => { button.disabled = true; });
|
|
39559
|
+
elements.dialogActions.querySelectorAll("button").forEach((button) => { button.disabled = true; });
|
|
39560
|
+
});
|
|
39561
|
+
activeDialogCancel = () => respondToQuestionnaire({ cancelled: true });
|
|
39562
|
+
(request.options || []).forEach((option, index) => {
|
|
39563
|
+
const optionLabel = String(option);
|
|
39564
|
+
const row = questionnaire.rows[index];
|
|
39565
|
+
const button = row.kind === "action"
|
|
39566
|
+
? renderQuestionnaireActionButton(row)
|
|
39567
|
+
: renderQuestionnaireOptionButton(row, questionnaire.mode);
|
|
39568
|
+
// Presentation is derived, but the response always carries the exact
|
|
39569
|
+
// native option string the questionnaire runtime produced.
|
|
39570
|
+
button.addEventListener("click", () => respondToQuestionnaire({ value: optionLabel }));
|
|
39571
|
+
options.append(button);
|
|
39572
|
+
});
|
|
39573
|
+
elements.dialogBody.append(options);
|
|
39574
|
+
addDialogButton("Cancel", () => respondToQuestionnaire({ cancelled: true }), "questionnaire-dialog-cancel");
|
|
39575
|
+
} else if (request.method === "select") {
|
|
38052
39576
|
const options = make("div", "dialog-options");
|
|
38053
39577
|
for (const option of request.options || []) {
|
|
38054
39578
|
const optionLabel = String(option);
|
|
@@ -38061,37 +39585,55 @@ function showNextDialog() {
|
|
|
38061
39585
|
if (isReleaseDialog && /^\[x\]/.test(optionLabel)) button.classList.add("release-target-option", "release-target-selected");
|
|
38062
39586
|
if (isReleaseDialog && /^\[ \]/.test(optionLabel)) button.classList.add("release-target-option");
|
|
38063
39587
|
if (isReleaseDialog && /^(?:No|Cancel)$/i.test(optionLabel)) button.classList.add("release-cancel-action");
|
|
38064
|
-
button.addEventListener("click", () =>
|
|
39588
|
+
button.addEventListener("click", () => respondToDialog({ value: optionLabel }));
|
|
38065
39589
|
options.append(button);
|
|
38066
39590
|
}
|
|
38067
39591
|
elements.dialogBody.append(options);
|
|
38068
39592
|
addDialogButton("Cancel", cancel);
|
|
38069
39593
|
} else if (request.method === "confirm") {
|
|
38070
39594
|
addDialogButton("Cancel", cancel);
|
|
38071
|
-
addDialogButton("No", () =>
|
|
38072
|
-
addDialogButton("Yes", () =>
|
|
39595
|
+
addDialogButton("No", () => respondToDialog({ confirmed: false }));
|
|
39596
|
+
addDialogButton("Yes", () => respondToDialog({ confirmed: true }), "primary");
|
|
38073
39597
|
} else if (request.method === "input") {
|
|
38074
39598
|
const input = make("input", "dialog-input");
|
|
38075
39599
|
input.value = request.prefill || "";
|
|
38076
39600
|
input.placeholder = request.placeholder || "";
|
|
38077
39601
|
elements.dialogBody.append(input);
|
|
38078
|
-
|
|
38079
|
-
|
|
39602
|
+
// The dialog form uses method="dialog", so an unhandled Enter would close it
|
|
39603
|
+
// implicitly without ever sending a response and leave the extension blocked.
|
|
39604
|
+
// Keyboard, click, and cancel paths therefore share one guarded one-shot closure.
|
|
39605
|
+
const respondToInput = (response) => respondToDialog(response, () => {
|
|
39606
|
+
input.disabled = true;
|
|
39607
|
+
elements.dialogActions.querySelectorAll("button").forEach((button) => { button.disabled = true; });
|
|
39608
|
+
});
|
|
39609
|
+
const submitInput = () => respondToInput({ value: input.value });
|
|
39610
|
+
activeDialogCancel = () => respondToInput({ cancelled: true });
|
|
39611
|
+
input.addEventListener("keydown", (event) => {
|
|
39612
|
+
const intent = dialogInputEnterIntent(event);
|
|
39613
|
+
if (intent === "ignore") return;
|
|
39614
|
+
event.preventDefault();
|
|
39615
|
+
event.stopPropagation();
|
|
39616
|
+
if (intent === "submit") submitInput();
|
|
39617
|
+
});
|
|
39618
|
+
addDialogButton("Cancel", () => respondToInput({ cancelled: true }));
|
|
39619
|
+
addDialogButton("Submit", submitInput, "primary");
|
|
38080
39620
|
setTimeout(() => input.focus(), 0);
|
|
38081
39621
|
} else if (isWorkflowScriptPreview) {
|
|
38082
|
-
renderWorkflowScriptPreview(request);
|
|
39622
|
+
renderWorkflowScriptPreview(request, respondToDialog);
|
|
38083
39623
|
} else if (request.method === "editor") {
|
|
38084
39624
|
const textarea = make("textarea", "dialog-editor");
|
|
38085
39625
|
textarea.value = request.prefill || "";
|
|
38086
39626
|
elements.dialogBody.append(textarea);
|
|
38087
39627
|
addDialogButton("Cancel", cancel);
|
|
38088
|
-
addDialogButton("Submit", () =>
|
|
39628
|
+
addDialogButton("Submit", () => respondToDialog({ value: textarea.value }), "primary");
|
|
38089
39629
|
setTimeout(() => textarea.focus(), 0);
|
|
38090
39630
|
}
|
|
38091
39631
|
|
|
38092
39632
|
elements.dialog.showModal();
|
|
38093
39633
|
}
|
|
38094
39634
|
|
|
39635
|
+
elements.dialog.addEventListener("cancel", cancelActiveExtensionDialog);
|
|
39636
|
+
|
|
38095
39637
|
function supervisorEventEnvelope(event, fallbackTabId = activeTabId) {
|
|
38096
39638
|
if (!event || typeof event !== "object") return null;
|
|
38097
39639
|
const fields = ["supervisorScopeId", "supervisorEpoch", "supervisorSeq"];
|
|
@@ -38225,8 +39767,7 @@ function handleEvent(event) {
|
|
|
38225
39767
|
switch (event.type) {
|
|
38226
39768
|
case "webui_connected": {
|
|
38227
39769
|
const connectedTabId = event.tabId || activeTabId;
|
|
38228
|
-
|
|
38229
|
-
if (connectedTabId === activeTabId) renderFeatureCategoryTag(connectedTabId);
|
|
39770
|
+
clearFeatureDecisionStateForTab(connectedTabId, { render: true });
|
|
38230
39771
|
acceptOutputModeAcknowledgement(event);
|
|
38231
39772
|
setWebuiVersion(event.version);
|
|
38232
39773
|
setPiVersion(event.piVersion);
|
|
@@ -38679,6 +40220,11 @@ elements.skillEditorDialog?.addEventListener("keydown", (event) => {
|
|
|
38679
40220
|
if (!elements.skillEditorSaveButton?.disabled) saveSkillEditor();
|
|
38680
40221
|
});
|
|
38681
40222
|
elements.skillEditorDialog?.querySelector("form")?.addEventListener("submit", (event) => event.preventDefault());
|
|
40223
|
+
elements.featureCategoryTag?.addEventListener("click", openFeatureDecisionDialog);
|
|
40224
|
+
elements.featureDecisionDialog?.addEventListener("close", () => {
|
|
40225
|
+
featureDecisionDialogTabId = null;
|
|
40226
|
+
if (elements.featureDecisionDialogOutput) elements.featureDecisionDialogOutput.textContent = "";
|
|
40227
|
+
});
|
|
38682
40228
|
elements.sendFeedbackButton.addEventListener("click", () => submitQueuedActionFeedback());
|
|
38683
40229
|
elements.composer.addEventListener("submit", (event) => {
|
|
38684
40230
|
event.preventDefault();
|
|
@@ -39505,6 +41051,9 @@ if (elements.subagentOpenModeSelect) {
|
|
|
39505
41051
|
setSubagentOpenMode(elements.subagentOpenModeSelect.value, { announce: true });
|
|
39506
41052
|
});
|
|
39507
41053
|
}
|
|
41054
|
+
elements.subagentsAutoClearButton?.addEventListener("click", () => {
|
|
41055
|
+
setSubagentAutoClearEnabled(!subagentAutoClearEnabled, { announce: true });
|
|
41056
|
+
});
|
|
39508
41057
|
elements.subagentsClearFinishedButton?.addEventListener("click", () => {
|
|
39509
41058
|
void clearFinishedSubagentRuns();
|
|
39510
41059
|
});
|
|
@@ -39873,10 +41422,35 @@ window.addEventListener("storage", (event) => {
|
|
|
39873
41422
|
if (event.key === OPTIONAL_FEATURES_STORAGE_KEY) reconcileDisabledOptionalFeaturesFromStorage();
|
|
39874
41423
|
if (event.key === SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY) restoreSidePanelSectionVisibility();
|
|
39875
41424
|
if (event.key === SIDE_PANEL_SECTION_ORDER_STORAGE_KEY) restoreSidePanelSectionOrder();
|
|
41425
|
+
if (event.key === COMPOSER_ACTION_ORDER_STORAGE_KEY) restoreComposerActionOrder();
|
|
41426
|
+
if (event.key === COMPOSER_ACTION_LAYOUT_STORAGE_KEY) restoreComposerActionSlotLayout();
|
|
39876
41427
|
if (event.key === SIDE_PANEL_WIDTH_STORAGE_KEY) {
|
|
39877
41428
|
const width = readStoredSidePanelWidth();
|
|
39878
41429
|
if (width && !isSidePanelOverlayView()) applySidePanelWidth(width);
|
|
39879
41430
|
}
|
|
41431
|
+
// Another same-origin tab already saved these durable fields, so receiving
|
|
41432
|
+
// tabs only adopt the shared local cache without repeating the server write.
|
|
41433
|
+
if (event.key === SIDE_PANEL_SECTION_STORAGE_KEY) restoreSidePanelSectionState();
|
|
41434
|
+
if (event.key === SIDE_PANEL_STORAGE_KEY) restoreSidePanelState();
|
|
41435
|
+
if (event.key === TERMINAL_TABS_LAYOUT_STORAGE_KEY) restoreTerminalTabsLayoutSetting();
|
|
41436
|
+
if (event.key === TERMINAL_CUSTOM_GROUPS_STORAGE_KEY) {
|
|
41437
|
+
restoreTerminalCustomGroups();
|
|
41438
|
+
syncTerminalCustomGroupsWithTabs(tabs, { persist: false });
|
|
41439
|
+
renderTabs();
|
|
41440
|
+
}
|
|
41441
|
+
if (event.key === FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY) {
|
|
41442
|
+
footerScopedModels = orderedFooterScopedModels();
|
|
41443
|
+
renderFooter();
|
|
41444
|
+
}
|
|
41445
|
+
if (event.key === FILE_VIEWER_WIDTH_STORAGE_KEY) restoreFileViewerWidthPreference();
|
|
41446
|
+
});
|
|
41447
|
+
// Durable layout reconciliation runs on its own foreground/online lifecycle
|
|
41448
|
+
// listeners so retained dirty state retries without changing the existing
|
|
41449
|
+
// transcript/session reconciliation contracts.
|
|
41450
|
+
window.addEventListener("online", () => reconcileDurableUiLayout());
|
|
41451
|
+
window.addEventListener("pageshow", () => reconcileDurableUiLayout());
|
|
41452
|
+
document.addEventListener("visibilitychange", () => {
|
|
41453
|
+
if (document.visibilityState === "visible") reconcileDurableUiLayout();
|
|
39880
41454
|
});
|
|
39881
41455
|
window.addEventListener("resize", syncResizablePanelWidthsForViewport, { passive: true });
|
|
39882
41456
|
window.addEventListener("keydown", (event) => {
|
|
@@ -40265,6 +41839,7 @@ elements.promptInput.addEventListener("blur", () => {
|
|
|
40265
41839
|
installModalPrimitives();
|
|
40266
41840
|
initializeIssueWizard();
|
|
40267
41841
|
resizePromptInput();
|
|
41842
|
+
restoreDurableUiLayoutPendingJournal();
|
|
40268
41843
|
restoreSidePanelWidthPreference();
|
|
40269
41844
|
restoreFileViewerWidthPreference();
|
|
40270
41845
|
focusPromptInput({ defer: true });
|
|
@@ -40290,11 +41865,13 @@ restoreAgentDoneNotificationsSetting();
|
|
|
40290
41865
|
restoreThinkingVisibilitySetting();
|
|
40291
41866
|
restoreTerminalTabsLayoutSetting();
|
|
40292
41867
|
restoreSubagentOpenModeSetting();
|
|
41868
|
+
restoreSubagentAutoClearSetting();
|
|
40293
41869
|
restoreTerminalCustomGroups();
|
|
40294
41870
|
restoreToolOutputExpansionSetting();
|
|
40295
41871
|
restoreWorkspaceDashboardState();
|
|
40296
41872
|
restoreInterfaceDensity();
|
|
40297
41873
|
initializeTerminalHeaderTooltips();
|
|
41874
|
+
initializeComposerActionOrdering();
|
|
40298
41875
|
restoreSidePanelSectionOrder();
|
|
40299
41876
|
restoreSidePanelSectionVisibility();
|
|
40300
41877
|
restoreSidePanelSectionState();
|