@firstpick/pi-package-webui 0.8.7 → 0.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +5 -0
  2. package/bin/pi-webui-rpc-supervisor.mjs +4 -1
  3. package/bin/pi-webui.mjs +9 -1
  4. package/lib/rpc-supervisor-protocol.mjs +6 -1
  5. package/package.json +1 -1
  6. package/public/app.js +679 -128
  7. package/public/index.html +49 -13
  8. package/public/service-worker.js +1 -1
  9. package/public/styles.css +836 -16
  10. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  11. package/tests/browser/interaction-continuity.spec.mjs +58 -0
  12. package/tests/browser/mobile-foundation.spec.mjs +363 -5
  13. package/tests/browser/optimistic-prompt.spec.mjs +24 -10
  14. package/tests/browser/persistent-ui-layout.spec.mjs +2 -0
  15. package/tests/browser/side-panel-section-reorder.spec.mjs +16 -1
  16. package/tests/codex-fast-mode-static.test.mjs +2 -2
  17. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  18. package/tests/fast-mode-client-static.test.mjs +1 -1
  19. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  20. package/tests/file-tree-search-layout-static.test.mjs +261 -0
  21. package/tests/fixtures/fake-pi.mjs +6 -2
  22. package/tests/http-endpoints-harness.test.mjs +6 -2
  23. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  24. package/tests/mobile-compact-layout.test.mjs +60 -0
  25. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  26. package/tests/mobile-foundation-static.test.mjs +12 -12
  27. package/tests/mobile-phone-experience-static.test.mjs +2 -2
  28. package/tests/mobile-static.test.mjs +226 -21
  29. package/tests/open-issue-wizard-static.test.mjs +1 -1
  30. package/tests/optional-feature-migration-frontend.test.mjs +4 -0
  31. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  32. package/tests/prompt-routing-tab-status.test.mjs +8 -0
  33. package/tests/questionnaire-dialog.test.mjs +3 -3
  34. package/tests/rpc-supervisor-host.test.mjs +18 -1
  35. package/tests/rpc-supervisor-protocol.test.mjs +5 -0
  36. package/tests/session-sampling-ui-static.test.mjs +3 -3
  37. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  38. package/tests/side-panel-section-reorder-static.test.mjs +23 -10
  39. package/tests/streaming-ui-coupling.test.mjs +8 -0
  40. package/tests/terminal-tab-workspace-static.test.mjs +15 -1
  41. package/tests/theme-customizer-static.test.mjs +1 -1
package/public/app.js CHANGED
@@ -32,6 +32,9 @@ const elements = {
32
32
  webuiDevBadge: $("#webuiDevBadge"),
33
33
  tabBar: $("#tabBar"),
34
34
  terminalTabsToggleButton: $("#terminalTabsToggleButton"),
35
+ terminalTabsShell: $(".terminal-tabs-shell"),
36
+ terminalTabsDrawerContent: $("#terminalTabsDrawerContent"),
37
+ terminalTabsBackdrop: $("#terminalTabsBackdrop"),
35
38
  workspaceSaveButton: $("#workspaceSaveButton"),
36
39
  newTabMenu: $("#newTabMenu"),
37
40
  newTabButton: $("#newTabButton"),
@@ -90,6 +93,7 @@ const elements = {
90
93
  subagentCancelSubmitButton: $("#subagentCancelSubmitButton"),
91
94
  stickyUserPromptButton: $("#stickyUserPromptButton"),
92
95
  chat: $("#chat"),
96
+ runIndicatorHost: $("#runIndicatorHost"),
93
97
  chatSearchBar: $("#chatSearchBar"),
94
98
  chatSearchInput: $("#chatSearchInput"),
95
99
  chatSearchCount: $("#chatSearchCount"),
@@ -101,6 +105,8 @@ const elements = {
101
105
  sendFeedbackButton: $("#sendFeedbackButton"),
102
106
  jumpToLatestButton: $("#jumpToLatestButton"),
103
107
  composer: $("#composer"),
108
+ composerInputRow: $(".composer-input-row"),
109
+ composerContextTags: $(".composer-context-tags"),
104
110
  composerRow: $(".composer-row"),
105
111
  composerActionsButton: $("#composerActionsButton"),
106
112
  composerActionsPanel: $("#composerActionsPanel"),
@@ -329,6 +335,8 @@ const elements = {
329
335
  sidePanelContextMenu: $("#sidePanelContextMenu"),
330
336
  gitFooterContextMenu: $("#gitFooterContextMenu"),
331
337
  sidePanelResizeHandle: $("#sidePanelResizeHandle"),
338
+ sidePanelEditButton: $("#sidePanelEditButton"),
339
+ sidePanelEditHint: $("#sidePanelEditHint"),
332
340
  toggleSidePanelButton: $("#toggleSidePanelButton"),
333
341
  sidePanelExpandButton: $("#sidePanelExpandButton"),
334
342
  sidePanelBackdrop: $("#sidePanelBackdrop"),
@@ -430,6 +438,17 @@ const elements = {
430
438
  confirmationUndo: $("#confirmationUndo"),
431
439
  confirmationCancelButton: $("#confirmationCancelButton"),
432
440
  confirmationConfirmButton: $("#confirmationConfirmButton"),
441
+ gitPullErrorDialog: $("#gitPullErrorDialog"),
442
+ gitPullErrorDialogTitle: $("#gitPullErrorDialogTitle"),
443
+ gitPullErrorDialogDescription: $("#gitPullErrorDialogDescription"),
444
+ gitPullErrorOutput: $("#gitPullErrorOutput"),
445
+ gitPullErrorStatus: $("#gitPullErrorStatus"),
446
+ gitPullErrorRecovery: $("#gitPullErrorRecovery"),
447
+ gitPullErrorMergeButton: $("#gitPullErrorMergeButton"),
448
+ gitPullErrorRebaseButton: $("#gitPullErrorRebaseButton"),
449
+ gitPullErrorReviewButton: $("#gitPullErrorReviewButton"),
450
+ gitPullErrorCopyButton: $("#gitPullErrorCopyButton"),
451
+ gitPullErrorCloseButton: $("#gitPullErrorCloseButton"),
433
452
  workspaceLoadDialog: $("#workspaceLoadDialog"),
434
453
  workspaceLoadDialogCloseButton: $("#workspaceLoadDialogCloseButton"),
435
454
  workspaceLoadDialogStatus: $("#workspaceLoadDialogStatus"),
@@ -559,6 +578,7 @@ let fileViewerSearchHighlightElement = null;
559
578
  let fileContextMenuState = null;
560
579
  let sidePanelContextMenuState = null;
561
580
  let gitFooterContextMenuState = null;
581
+ let sidePanelSectionEditMode = false;
562
582
  let sidePanelSectionPointerDrag = null;
563
583
  let sidePanelSectionLastDragOverKey = "";
564
584
  let sidePanelSectionSuppressClickUntil = 0;
@@ -707,9 +727,9 @@ let runIndicatorRenderFrame = null;
707
727
  let runIndicatorRenderScroll = false;
708
728
  let runIndicatorGraceCheckTimer = null;
709
729
  let runIndicatorLastStateCheckAt = 0;
710
- // Lifecycle ownership is deliberately separate from the transcript-owned
711
- // activity label: the transcript ticker only repaints its own elapsed-time
712
- // node, while this watchdog owns the low-frequency canonical state recheck.
730
+ // Lifecycle ownership is deliberately separate from the status-host-owned
731
+ // activity label: the status ticker only repaints its own elapsed-time node,
732
+ // while this watchdog owns the low-frequency canonical state recheck.
713
733
  let lifecycleStateWatchdogTimer = null;
714
734
  let lifecycleComposerSignature = null;
715
735
  // Bounded dedupe of semantic tool-boundary records (skill tags, event log),
@@ -785,9 +805,13 @@ let pathFastPicks = [];
785
805
  let pathFastPicksReady = false;
786
806
  let pathFastPicksLoadPromise = null;
787
807
  let mobileTabsExpanded = false;
808
+ let mobileTabsFocusReturn = null;
809
+ let composerActionsFocusReturn = null;
810
+ const mobileComposerOriginalPositions = new Map();
788
811
  let openTerminalTabGroupKey = null;
789
812
  let terminalCustomGroups = new Map();
790
813
  let terminalCustomGroupSerial = 1;
814
+ let terminalTabGroupMenuSerial = 0;
791
815
  let savedWorkspaces = [];
792
816
  let savedWorkspacesLoaded = false;
793
817
  let savedWorkspacesLoading = false;
@@ -2296,6 +2320,9 @@ function applyMobileShellViewport() {
2296
2320
  const wasActive = isMobileShellV2Active();
2297
2321
  applyMobileShellEvent({ type: "viewport", viewport: mobileShellViewport() });
2298
2322
  if (wasActive !== isMobileShellV2Active() && isMobileShellV2Active()) {
2323
+ mobileFooterExpanded = false;
2324
+ elements.statusBar.removeAttribute("aria-label");
2325
+ deactivateDrawerModal(elements.statusBar, { restoreFocus: false });
2299
2326
  document.body.classList.remove("composer-actions-open", "footer-details-expanded", "mobile-tabs-expanded", "mobile-keyboard-open");
2300
2327
  }
2301
2328
  }
@@ -3060,6 +3087,7 @@ let optionalFeatureMigrationReadyDismissTimer = null;
3060
3087
  let optionalFeatureMigrationPendingReadyDismissKey = "";
3061
3088
  let optionalFeatureMigrationDismissedReadyKey = "";
3062
3089
  let optionalFeatureMigrationDismissedCompletionKey = "";
3090
+ let optionalFeatureMigrationDismissedNoticeKey = "";
3063
3091
  let optionalFeatureMigrationDialogState = null;
3064
3092
  let optionalFeatureMigrationLastPhase = "";
3065
3093
  let optionalFeatureMigrationCompletionFocusKey = "";
@@ -3071,6 +3099,8 @@ const gitFooterPayloadStateByTab = new Map();
3071
3099
  const gitFooterPayloadSettlementTimersByTab = new Map();
3072
3100
  const gitFooterPayloadRequestSerialByTab = new Map();
3073
3101
  const gitFooterSyncInFlightByTab = new Set();
3102
+ let gitPullErrorText = "";
3103
+ let gitPullErrorContext = { code: "", tabId: null, syncValue: "", busy: false, requestId: 0 };
3074
3104
  const gitFooterPiCalibrationInFlightByTab = new Set();
3075
3105
  let gitFooterVisibilityApplyInFlight = false;
3076
3106
  let gitFooterVisibilityDirty = false;
@@ -3712,7 +3742,55 @@ function clearSidePanelSectionDragMarkers() {
3712
3742
  }
3713
3743
  }
3714
3744
 
3745
+ function isSidePanelSectionReorderingEnabled() {
3746
+ return !isMobileView() || sidePanelSectionEditMode;
3747
+ }
3748
+
3749
+ function updateSidePanelSectionEditAffordance(record) {
3750
+ const collapsed = record.section.classList.contains("collapsed");
3751
+ const label = record.button.querySelector(".side-panel-section-label")?.textContent?.trim() || "side panel";
3752
+ const action = `${collapsed ? "Expand" : "Collapse"} ${label} section`;
3753
+ const reorderingEnabled = isSidePanelSectionReorderingEnabled();
3754
+ record.button.setAttribute("aria-label", action);
3755
+ record.button.setAttribute("title", reorderingEnabled
3756
+ ? `${action} · drag to reorder · Alt+↑/↓ moves`
3757
+ : action);
3758
+ if (reorderingEnabled) record.button.setAttribute("aria-keyshortcuts", "Alt+ArrowUp Alt+ArrowDown");
3759
+ else record.button.removeAttribute("aria-keyshortcuts");
3760
+ }
3761
+
3762
+ function cancelSidePanelSectionPointerDrag() {
3763
+ const drag = sidePanelSectionPointerDrag;
3764
+ if (!drag) return;
3765
+ window.removeEventListener("pointermove", updateSidePanelSectionPointerDrag, { capture: true });
3766
+ window.removeEventListener("pointerup", endSidePanelSectionPointerDrag, { capture: true });
3767
+ window.removeEventListener("pointercancel", endSidePanelSectionPointerDrag, { capture: true });
3768
+ sidePanelSectionRecords().find(({ id }) => id === drag.sectionId)?.section.classList.remove("dragging");
3769
+ sidePanelSectionPointerDrag = null;
3770
+ sidePanelSectionLastDragOverKey = "";
3771
+ clearSidePanelSectionDragMarkers();
3772
+ }
3773
+
3774
+ function setSidePanelSectionEditMode(enabled) {
3775
+ if (!enabled) cancelSidePanelSectionPointerDrag();
3776
+ const next = isMobileView() && !!enabled;
3777
+ const reorderingEnabled = !isMobileView() || next;
3778
+ if (sidePanelSectionEditMode === next && elements.sidePanel?.classList.contains("section-edit-mode") === reorderingEnabled) return;
3779
+ sidePanelSectionEditMode = next;
3780
+ elements.sidePanel?.classList.toggle("section-edit-mode", reorderingEnabled);
3781
+ if (elements.sidePanelEditButton) {
3782
+ elements.sidePanelEditButton.setAttribute("aria-pressed", next ? "true" : "false");
3783
+ elements.sidePanelEditButton.setAttribute("aria-label", next ? "Finish editing Control Deck section order" : "Edit Control Deck section order");
3784
+ elements.sidePanelEditButton.setAttribute("title", next ? "Finish editing Control Deck section order" : "Edit Control Deck section order");
3785
+ const label = elements.sidePanelEditButton.querySelector(".side-panel-edit-button-label");
3786
+ if (label) label.textContent = next ? "Done" : "Edit";
3787
+ }
3788
+ if (elements.sidePanelEditHint) elements.sidePanelEditHint.hidden = !next;
3789
+ for (const record of sidePanelSectionRecords()) updateSidePanelSectionEditAffordance(record);
3790
+ }
3791
+
3715
3792
  function moveSidePanelSectionRelative(fromId, targetRecord, insertBefore) {
3793
+ if (!isSidePanelSectionReorderingEnabled()) return false;
3716
3794
  const sourceRecord = sidePanelSectionRecords().find(({ id }) => id === fromId);
3717
3795
  if (!sourceRecord || !targetRecord || sourceRecord.section === targetRecord.section) return false;
3718
3796
  const parent = sourceRecord.section.parentElement;
@@ -3727,6 +3805,7 @@ function moveSidePanelSectionRelative(fromId, targetRecord, insertBefore) {
3727
3805
  }
3728
3806
 
3729
3807
  function moveSidePanelSectionByOffset(sectionId, offset) {
3808
+ if (!isSidePanelSectionReorderingEnabled()) return false;
3730
3809
  const records = visibleSidePanelSectionRecords();
3731
3810
  const fromIndex = records.findIndex(({ id }) => id === sectionId);
3732
3811
  const toIndex = fromIndex + offset;
@@ -3743,7 +3822,7 @@ function sidePanelSectionToggleFromPoint(clientX, clientY) {
3743
3822
  }
3744
3823
 
3745
3824
  function beginSidePanelSectionPointerDrag(event, sectionId) {
3746
- if (event.button !== 0 || !sectionId || sidePanelSectionPointerDrag) return;
3825
+ if (!isSidePanelSectionReorderingEnabled() || event.button !== 0 || !sectionId || sidePanelSectionPointerDrag) return;
3747
3826
  sidePanelSectionPointerDrag = { sectionId, pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, active: false };
3748
3827
  window.addEventListener("pointermove", updateSidePanelSectionPointerDrag, { capture: true });
3749
3828
  window.addEventListener("pointerup", endSidePanelSectionPointerDrag, { capture: true });
@@ -3864,12 +3943,10 @@ function restoreSidePanelSectionVisibility() {
3864
3943
  }
3865
3944
 
3866
3945
  function setSidePanelSectionCollapsed(record, collapsed, { persist = true } = {}) {
3867
- const label = record.button.querySelector(".side-panel-section-label")?.textContent?.trim() || "side panel";
3868
3946
  record.section.classList.toggle("collapsed", collapsed);
3869
3947
  record.content.hidden = collapsed;
3870
3948
  record.button.setAttribute("aria-expanded", collapsed ? "false" : "true");
3871
- record.button.setAttribute("aria-label", `${collapsed ? "Expand" : "Collapse"} ${label} section`);
3872
- record.button.setAttribute("title", `${collapsed ? "Expand" : "Collapse"} ${label} section · drag to reorder · Alt+↑/↓ moves`);
3949
+ updateSidePanelSectionEditAffordance(record);
3873
3950
  if (!collapsed && record.id === "git" && !record.section.hidden) {
3874
3951
  queueMicrotask(() => {
3875
3952
  renderGitPanel();
@@ -3966,7 +4043,7 @@ function bindSidePanelSectionToggles() {
3966
4043
  }
3967
4044
  });
3968
4045
  record.button.addEventListener("keydown", (event) => {
3969
- if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown")) return;
4046
+ if (!isSidePanelSectionReorderingEnabled() || !event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown")) return;
3970
4047
  event.preventDefault();
3971
4048
  moveSidePanelSectionByOffset(record.id, event.key === "ArrowUp" ? -1 : 1);
3972
4049
  });
@@ -6100,18 +6177,70 @@ async function refreshNativeSettings(tabContext = activeTabContext()) {
6100
6177
  applyNativeSettingsForBrowser(response.data?.settings || {});
6101
6178
  }
6102
6179
 
6103
- function setComposerActionsOpen(open) {
6180
+ function mobileComposerSecondaryNodes() {
6181
+ return [
6182
+ elements.workflowModeControls,
6183
+ elements.composerContextTags,
6184
+ elements.busyPromptBehaviorMenu,
6185
+ elements.followUpQueueTrigger,
6186
+ elements.btwButton,
6187
+ elements.conversationVoiceMenu,
6188
+ elements.conversationModeEndButton,
6189
+ ].filter(Boolean);
6190
+ }
6191
+
6192
+ function rememberMobileComposerOriginalPositions() {
6193
+ for (const node of mobileComposerSecondaryNodes()) {
6194
+ if (!mobileComposerOriginalPositions.has(node)) {
6195
+ mobileComposerOriginalPositions.set(node, { parent: node.parentNode, nextSibling: node.nextSibling });
6196
+ }
6197
+ }
6198
+ }
6199
+
6200
+ function restoreMobileComposerOriginalPositions() {
6201
+ for (const [node, { parent, nextSibling }] of mobileComposerOriginalPositions) {
6202
+ if (!parent) continue;
6203
+ if (nextSibling?.parentNode === parent) parent.insertBefore(node, nextSibling);
6204
+ else parent.append(node);
6205
+ }
6206
+ }
6207
+
6208
+ function syncMobileComposerDisclosureLayout() {
6209
+ rememberMobileComposerOriginalPositions();
6210
+ const useMobileDisclosure = isMobileView() && !isMobileShellV2Active();
6211
+ document.body.classList.toggle("mobile-composer-disclosure", useMobileDisclosure);
6212
+ if (!useMobileDisclosure) {
6213
+ restoreMobileComposerOriginalPositions();
6214
+ return;
6215
+ }
6216
+ for (const node of mobileComposerSecondaryNodes()) elements.composerActionsPanel.append(node);
6217
+ }
6218
+
6219
+ function setComposerActionsOpen(open, { restoreFocus = false } = {}) {
6104
6220
  if (isMobileShellV2Active()) return;
6221
+ syncMobileComposerDisclosureLayout();
6105
6222
  const shouldOpen = open && isMobileView();
6106
- if (shouldOpen && followUpQueueOpen) setFollowUpQueueOpen(false);
6223
+ if (shouldOpen) {
6224
+ composerActionsFocusReturn = document.activeElement instanceof HTMLElement ? document.activeElement : elements.composerActionsButton;
6225
+ if (followUpQueueOpen) setFollowUpQueueOpen(false);
6226
+ setMobileTabsExpanded(false);
6227
+ setMobileFooterExpanded(false);
6228
+ }
6107
6229
  document.body.classList.toggle("composer-actions-open", shouldOpen);
6108
6230
  elements.composerActionsButton.setAttribute("aria-expanded", shouldOpen ? "true" : "false");
6231
+ elements.composerActionsButton.textContent = shouldOpen ? "−" : "More";
6232
+ elements.composerActionsButton.setAttribute("aria-label", shouldOpen ? "Minimize more composer actions" : "Show more composer actions");
6233
+ elements.composerActionsButton.title = shouldOpen ? "Minimize more composer actions" : "Show more composer actions";
6234
+ elements.composerActionsPanel.setAttribute("aria-hidden", shouldOpen || !isMobileView() ? "false" : "true");
6109
6235
  if (!shouldOpen) {
6110
6236
  setPublishMenuOpen(false);
6111
6237
  setNativeCommandMenuOpen(false);
6112
6238
  setAppRunnerMenuOpen(false);
6113
6239
  setOptionsMenuOpen(false);
6114
6240
  setBusyPromptBehaviorMenuOpen(false);
6241
+ const focusReturn = restoreFocus ? composerActionsFocusReturn : null;
6242
+ composerActionsFocusReturn = null;
6243
+ if (focusReturn?.isConnected) requestAnimationFrame(() => focusReturn.focus({ preventScroll: true }));
6115
6244
  }
6116
6245
  scheduleMobileDropdownScrollBoundsUpdate();
6117
6246
  if (!shouldOpen) scheduleDeferredUiFlushAfterDropdownClose();
@@ -6261,30 +6390,71 @@ function updateFooterModelPickerPosition() {
6261
6390
  document.documentElement.style.setProperty("--footer-model-picker-right", "auto");
6262
6391
  }
6263
6392
 
6264
- function setMobileFooterExpanded(expanded) {
6393
+ function setMobileFooterExpanded(expanded, { restoreFocus = false } = {}) {
6265
6394
  if (isMobileShellV2Active()) return;
6266
6395
  mobileFooterExpanded = expanded && isMobileView();
6267
- if (mobileFooterExpanded && isFooterPickerOpen()) {
6268
- footerModelPickerOpen = false;
6269
- footerThinkingPickerOpen = false;
6270
- footerBranchPickerOpen = false;
6271
- document.body.classList.remove("footer-model-picker-open");
6272
- elements.statusBar.querySelectorAll(".footer-model-picker").forEach((node) => node.remove());
6396
+ if (mobileFooterExpanded) {
6397
+ setComposerActionsOpen(false);
6398
+ setMobileTabsExpanded(false);
6399
+ if (isFooterPickerOpen()) {
6400
+ footerModelPickerOpen = false;
6401
+ footerThinkingPickerOpen = false;
6402
+ footerBranchPickerOpen = false;
6403
+ document.body.classList.remove("footer-model-picker-open");
6404
+ elements.statusBar.querySelectorAll(".footer-model-picker").forEach((node) => node.remove());
6405
+ }
6273
6406
  }
6274
6407
  document.body.classList.toggle("footer-details-expanded", mobileFooterExpanded);
6275
6408
  const button = elements.statusBar.querySelector(".footer-details-toggle");
6276
6409
  if (button) {
6277
- button.textContent = mobileFooterExpanded ? "Less" : "Details";
6410
+ button.textContent = mobileFooterExpanded ? "−" : "Details";
6411
+ button.setAttribute("aria-label", mobileFooterExpanded ? "Minimize Git footer details" : "Show Git footer details");
6412
+ button.setAttribute("title", mobileFooterExpanded ? "Minimize Git footer details" : "Show Git footer details");
6278
6413
  button.setAttribute("aria-expanded", mobileFooterExpanded ? "true" : "false");
6279
6414
  }
6415
+ if (mobileFooterExpanded && button) {
6416
+ elements.statusBar.setAttribute("aria-label", "Git footer details");
6417
+ activateDrawerModal(elements.statusBar, button, {
6418
+ close: () => setMobileFooterExpanded(false, { restoreFocus: true }),
6419
+ });
6420
+ } else {
6421
+ elements.statusBar.removeAttribute("aria-label");
6422
+ deactivateDrawerModal(elements.statusBar, { restoreFocus });
6423
+ }
6280
6424
  updateFooterModelPickerPosition();
6281
6425
  }
6282
6426
 
6283
- function setMobileTabsExpanded(expanded) {
6427
+ function setMobileTabsExpanded(expanded, { restoreFocus = false } = {}) {
6284
6428
  if (isMobileShellV2Active()) return;
6285
- mobileTabsExpanded = expanded && isMobileView();
6429
+ const shouldExpand = expanded && isMobileView();
6430
+ if (shouldExpand) {
6431
+ mobileTabsFocusReturn = elements.terminalTabsToggleButton;
6432
+ setComposerActionsOpen(false);
6433
+ setMobileFooterExpanded(false);
6434
+ }
6435
+ mobileTabsExpanded = shouldExpand;
6286
6436
  document.body.classList.toggle("mobile-tabs-expanded", mobileTabsExpanded);
6287
6437
  elements.terminalTabsToggleButton.setAttribute("aria-expanded", mobileTabsExpanded ? "true" : "false");
6438
+ if (mobileTabsExpanded) {
6439
+ activateDrawerModal(elements.terminalTabsShell, elements.terminalTabsToggleButton, {
6440
+ close: () => {
6441
+ setNewTabMenuOpen(false);
6442
+ setMobileTabsExpanded(false, { restoreFocus: true });
6443
+ },
6444
+ });
6445
+ } else {
6446
+ deactivateDrawerModal(elements.terminalTabsShell, { restoreFocus: false });
6447
+ }
6448
+ if (elements.terminalTabsBackdrop) elements.terminalTabsBackdrop.hidden = !mobileTabsExpanded;
6449
+ if (elements.terminalTabsDrawerContent) {
6450
+ if (isMobileView()) elements.terminalTabsDrawerContent.setAttribute("aria-hidden", mobileTabsExpanded ? "false" : "true");
6451
+ else elements.terminalTabsDrawerContent.removeAttribute("aria-hidden");
6452
+ }
6453
+ if (!mobileTabsExpanded) {
6454
+ const focusReturn = restoreFocus ? mobileTabsFocusReturn : null;
6455
+ mobileTabsFocusReturn = null;
6456
+ if (focusReturn?.isConnected) requestAnimationFrame(() => focusReturn.focus({ preventScroll: true }));
6457
+ }
6288
6458
  }
6289
6459
 
6290
6460
  function modalFocusableElements(surface) {
@@ -6449,8 +6619,17 @@ function chooseGitWorktreeBase(branch) {
6449
6619
  function handleDrawerModalKeydown(event) {
6450
6620
  if (!activeDrawerModal || event.defaultPrevented) return;
6451
6621
  if (event.key === "Escape") {
6622
+ if (activeDrawerModal.surface === elements.terminalTabsShell && openTerminalTabGroupKey) {
6623
+ event.preventDefault();
6624
+ event.stopPropagation();
6625
+ const openGroup = [...elements.tabBar.querySelectorAll(".terminal-tab-group")]
6626
+ .find((group) => group.dataset.groupKey === openTerminalTabGroupKey);
6627
+ clearOpenTerminalTabGroup(openTerminalTabGroupKey, { force: true });
6628
+ openGroup?.querySelector(".terminal-tab-group-button")?.focus({ preventScroll: true });
6629
+ return;
6630
+ }
6452
6631
  event.preventDefault();
6453
- setSidePanelCollapsed(true, { persist: false });
6632
+ activeDrawerModal.close?.();
6454
6633
  return;
6455
6634
  }
6456
6635
  if (event.key !== "Tab") return;
@@ -6462,7 +6641,10 @@ function handleDrawerModalKeydown(event) {
6462
6641
  }
6463
6642
  const first = focusable[0];
6464
6643
  const last = focusable[focusable.length - 1];
6465
- if (event.shiftKey && document.activeElement === first) {
6644
+ if (!activeDrawerModal.surface.contains(document.activeElement)) {
6645
+ event.preventDefault();
6646
+ (event.shiftKey ? last : first).focus({ preventScroll: true });
6647
+ } else if (event.shiftKey && document.activeElement === first) {
6466
6648
  event.preventDefault();
6467
6649
  last.focus({ preventScroll: true });
6468
6650
  } else if (!event.shiftKey && document.activeElement === last) {
@@ -6471,34 +6653,55 @@ function handleDrawerModalKeydown(event) {
6471
6653
  }
6472
6654
  }
6473
6655
 
6474
- function activateDrawerModal(surface, trigger) {
6475
- if (activeDrawerModal?.surface === surface) return;
6476
- activeDrawerModal = { surface, trigger };
6656
+ function activateDrawerModal(surface, trigger, { close } = {}) {
6657
+ if (activeDrawerModal?.surface === surface) {
6658
+ activeDrawerModal.trigger = trigger;
6659
+ activeDrawerModal.close = close;
6660
+ return;
6661
+ }
6662
+ activeDrawerModal = {
6663
+ surface,
6664
+ trigger,
6665
+ close,
6666
+ previousRole: surface.getAttribute("role"),
6667
+ previousTabindex: surface.getAttribute("tabindex"),
6668
+ };
6669
+ surface.setAttribute("role", "dialog");
6477
6670
  surface.setAttribute("aria-modal", "true");
6478
6671
  surface.setAttribute("tabindex", "-1");
6479
6672
  document.addEventListener("keydown", handleDrawerModalKeydown, true);
6480
6673
  }
6481
6674
 
6482
- function deactivateDrawerModal(surface) {
6675
+ function deactivateDrawerModal(surface, { restoreFocus = true } = {}) {
6483
6676
  if (activeDrawerModal?.surface !== surface) {
6484
6677
  surface?.removeAttribute("aria-modal");
6485
6678
  return;
6486
6679
  }
6487
- const trigger = activeDrawerModal.trigger;
6680
+ const { trigger, previousRole, previousTabindex } = activeDrawerModal;
6488
6681
  activeDrawerModal = null;
6489
6682
  surface.removeAttribute("aria-modal");
6683
+ if (previousRole === null) surface.removeAttribute("role");
6684
+ else surface.setAttribute("role", previousRole);
6685
+ if (previousTabindex === null) surface.removeAttribute("tabindex");
6686
+ else surface.setAttribute("tabindex", previousTabindex);
6490
6687
  document.removeEventListener("keydown", handleDrawerModalKeydown, true);
6491
- if (trigger?.isConnected) queueMicrotask(() => trigger.focus({ preventScroll: true }));
6688
+ if (restoreFocus && trigger?.isConnected) queueMicrotask(() => trigger.focus({ preventScroll: true }));
6492
6689
  }
6493
6690
 
6494
6691
  function syncMobileSidePanelState(collapsed) {
6495
6692
  const showBackdrop = !collapsed && isSidePanelOverlayView();
6496
6693
  elements.sidePanelBackdrop.hidden = !showBackdrop;
6497
- if (showBackdrop) activateDrawerModal(elements.sidePanel, elements.sidePanelExpandButton);
6498
- else deactivateDrawerModal(elements.sidePanel);
6694
+ if (showBackdrop) {
6695
+ activateDrawerModal(elements.sidePanel, elements.sidePanelExpandButton, {
6696
+ close: () => setSidePanelCollapsed(true, { persist: false }),
6697
+ });
6698
+ } else {
6699
+ deactivateDrawerModal(elements.sidePanel);
6700
+ }
6499
6701
  }
6500
6702
 
6501
6703
  function setSidePanelCollapsed(collapsed, { persist = true, focusPanel = false } = {}) {
6704
+ if (collapsed) setSidePanelSectionEditMode(false);
6502
6705
  document.body.classList.toggle("side-panel-collapsed", collapsed);
6503
6706
  elements.toggleSidePanelButton.setAttribute("aria-expanded", collapsed ? "false" : "true");
6504
6707
  elements.toggleSidePanelButton.setAttribute("title", collapsed ? "Expand side panel" : "Collapse side panel");
@@ -6598,6 +6801,8 @@ function bindMobileViewChanges() {
6598
6801
  const syncForViewport = (event) => {
6599
6802
  applyMobileShellViewport();
6600
6803
  syncComposerActionGridAvailability();
6804
+ syncMobileComposerDisclosureLayout();
6805
+ setSidePanelSectionEditMode(false);
6601
6806
  if (isMobileShellV2Active()) return;
6602
6807
  setComposerActionsOpen(false);
6603
6808
  setMobileFooterExpanded(false);
@@ -10819,9 +11024,11 @@ function fileTreeExpander(expanded = false) {
10819
11024
  function appendFileSearchEntry(parent, entry) {
10820
11025
  const path = normalizeFileTreePath(entry.path);
10821
11026
  const isDirectory = entry.type === "directory" || entry.directory === true;
11027
+ const expanded = isDirectory && fileTreeState.expanded.has(path);
11028
+ const loading = isDirectory && fileTreeState.loading.has(path);
10822
11029
  const gitStatus = fileTreeGitStatusForEntry(entry);
10823
11030
  const gitStatusClasses = fileTreeGitStatusClasses(gitStatus);
10824
- const item = make("li", `file-tree-node file-tree-search-node ${entry.type || "file"}${gitStatusClasses ? ` ${gitStatusClasses}` : ""}${fileTreeState.selectedPath === path ? " selected" : ""}`);
11031
+ const item = make("li", `file-tree-node file-tree-search-node ${entry.type || "file"}${gitStatusClasses ? ` ${gitStatusClasses}` : ""}${expanded ? " expanded" : ""}${fileTreeState.selectedPath === path ? " selected" : ""}`);
10825
11032
  item.setAttribute("role", "none");
10826
11033
  const button = make("button", "file-tree-item file-tree-search-item");
10827
11034
  button.type = "button";
@@ -10831,18 +11038,19 @@ function appendFileSearchEntry(parent, entry) {
10831
11038
  button.setAttribute("role", "treeitem");
10832
11039
  button.setAttribute("aria-selected", fileTreeState.selectedPath === path ? "true" : "false");
10833
11040
  if (isDirectory) {
10834
- button.setAttribute("aria-expanded", "false");
10835
- button.setAttribute("aria-label", `Expand ${entry.name || fileDisplayName(path)}`);
11041
+ button.setAttribute("aria-expanded", expanded ? "true" : "false");
11042
+ button.setAttribute("aria-label", `${expanded ? "Collapse" : "Expand"} ${entry.name || fileDisplayName(path)}`);
10836
11043
  }
10837
11044
  button.title = [path || ".", fileTreeGitStatusTitle(gitStatus), entry.error || ""].filter(Boolean).join("\n");
11045
+ const contextPath = fileParentPath(path) || ".";
10838
11046
  const label = make("span", "file-tree-search-label");
10839
11047
  label.append(
10840
11048
  make("span", "file-tree-name", entry.name || fileDisplayName(path)),
10841
- make("span", "file-tree-search-path", path || "."),
11049
+ make("span", "file-tree-search-path", contextPath),
10842
11050
  );
10843
11051
  button.append(
10844
- isDirectory ? fileTreeExpander(false) : make("span", "file-tree-expander-spacer"),
10845
- make("span", "file-tree-icon", fileEntryIcon(entry)),
11052
+ isDirectory ? fileTreeExpander(expanded) : make("span", "file-tree-expander-spacer"),
11053
+ make("span", "file-tree-icon", loading ? "…" : fileEntryIcon(entry)),
10846
11054
  label,
10847
11055
  );
10848
11056
  const gitBadge = fileTreeGitStatusBadge(gitStatus);
@@ -10853,20 +11061,28 @@ function appendFileSearchEntry(parent, entry) {
10853
11061
  button.addEventListener("click", () => {
10854
11062
  fileTreeState.selectedPath = path;
10855
11063
  if (entry.type === "file") openFileInViewer(path);
10856
- else revealFileTreeEntry(entry).catch((error) => addEvent(error.message || String(error), "error"));
11064
+ else toggleFileTreeDirectory(path).catch((error) => addEvent(error.message || String(error), "error"));
10857
11065
  });
10858
11066
  button.addEventListener("contextmenu", (event) => showFileContextMenu(event, entry));
10859
11067
  bindFileTreeDragAndDrop(button, item, entry);
10860
11068
  item.append(button, fileTreeOverflowButton(entry));
11069
+ if (isDirectory && expanded) {
11070
+ const children = fileTreeState.entriesByPath.get(path) || [];
11071
+ const childList = make("ul", "file-tree-list");
11072
+ childList.setAttribute("role", "group");
11073
+ if (loading) childList.append(make("li", "file-tree-loading muted", "Loading…"));
11074
+ else if (!children.length) childList.append(make("li", "file-tree-empty muted", "Empty"));
11075
+ else for (const child of children) appendFileTreeEntry(childList, child, 1);
11076
+ item.append(childList);
11077
+ }
10861
11078
  parent.append(item);
10862
11079
  }
10863
11080
 
10864
- async function revealFileTreeEntry(entry = {}) {
11081
+ async function revealFileTreeEntry(entry = {}, { expandTarget = true } = {}) {
10865
11082
  const targetPath = normalizeFileTreePath(entry.path || "");
10866
11083
  if (!targetPath && targetPath !== FILE_TREE_ROOT_PATH) return;
10867
11084
  const isDirectory = entry.type === "directory" || entry.directory === true;
10868
- const parentPath = isDirectory ? targetPath : fileParentPath(targetPath);
10869
- clearFileTreeSearch();
11085
+ const parentPath = fileParentPath(targetPath);
10870
11086
  fileTreeState.selectedPath = targetPath;
10871
11087
  await loadFileTreeDirectory(FILE_TREE_ROOT_PATH);
10872
11088
  let currentPath = "";
@@ -10876,7 +11092,7 @@ async function revealFileTreeEntry(entry = {}) {
10876
11092
  renderFileTree();
10877
11093
  await loadFileTreeDirectory(currentPath);
10878
11094
  }
10879
- if (isDirectory) {
11095
+ if (isDirectory && expandTarget) {
10880
11096
  fileTreeState.expanded.add(targetPath);
10881
11097
  await loadFileTreeDirectory(targetPath);
10882
11098
  }
@@ -10974,21 +11190,49 @@ async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false
10974
11190
  }
10975
11191
  }
10976
11192
 
11193
+ function focusVisibleFileTreeSelection(path = fileTreeState.selectedPath) {
11194
+ const normalized = normalizeFileTreePath(path);
11195
+ if (!normalized) return false;
11196
+ const selected = visibleFileTreeItems().find((item) => normalizeFileTreePath(item.dataset.path) === normalized);
11197
+ if (!selected) return false;
11198
+ selected.focus({ preventScroll: true });
11199
+ selected.scrollIntoView?.({ block: "nearest" });
11200
+ return true;
11201
+ }
11202
+
10977
11203
  function clearFileTreeSearch({ focus = false } = {}) {
10978
11204
  clearTimeout(fileTreeSearchTimer);
10979
11205
  fileTreeSearchTimer = null;
10980
11206
  fileTreeSearchRequestSerial += 1;
11207
+ const serial = fileTreeSearchRequestSerial;
11208
+ const selectedPath = normalizeFileTreePath(fileTreeState.selectedPath || "");
11209
+ const selectedEntry = fileTreeState.searchEntries.find((entry) => normalizeFileTreePath(entry.path) === selectedPath) || fileEntryByPath(selectedPath);
11210
+ const selectedDirectoryExpanded = fileTreeState.expanded.has(selectedPath);
10981
11211
  if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
10982
- fileTreeState.searchQuery = "";
10983
- fileTreeState.searchEntries = [];
10984
- fileTreeState.searchLoading = false;
10985
- fileTreeState.searchTruncated = false;
10986
- fileTreeState.searchTotal = 0;
10987
11212
  updateFileTreeSearchControls();
10988
- const rootEntries = fileTreeState.entriesByPath.get(FILE_TREE_ROOT_PATH) || [];
10989
- setFileTreeStatus(rootEntries.length ? fileTreeEntriesStatus(rootEntries) : "");
10990
- renderFileTree();
10991
- if (focus) elements.fileTreeSearchInput?.focus();
11213
+
11214
+ const commitClear = () => {
11215
+ if (serial !== fileTreeSearchRequestSerial || fileTreeSearchQueryText()) return;
11216
+ fileTreeState.searchQuery = "";
11217
+ fileTreeState.searchEntries = [];
11218
+ fileTreeState.searchLoading = false;
11219
+ fileTreeState.searchTruncated = false;
11220
+ fileTreeState.searchTotal = 0;
11221
+ const rootEntries = fileTreeState.entriesByPath.get(FILE_TREE_ROOT_PATH) || [];
11222
+ setFileTreeStatus(rootEntries.length ? fileTreeEntriesStatus(rootEntries) : "");
11223
+ renderFileTree();
11224
+ if (selectedPath && focusVisibleFileTreeSelection(selectedPath)) return;
11225
+ if (focus) elements.fileTreeSearchInput?.focus();
11226
+ };
11227
+
11228
+ if (!selectedPath || !selectedEntry) {
11229
+ commitClear();
11230
+ return;
11231
+ }
11232
+ revealFileTreeEntry(selectedEntry, { expandTarget: selectedDirectoryExpanded }).then(commitClear).catch((error) => {
11233
+ addEvent(error.message || String(error), "error");
11234
+ commitClear();
11235
+ });
10992
11236
  }
10993
11237
 
10994
11238
  async function runFileTreeSearch({ background = false } = {}) {
@@ -14666,11 +14910,11 @@ function terminalTabGroupTooltip(group, groupTitle = terminalDisplayGroupTitle(g
14666
14910
  ];
14667
14911
  const active = terminalTabGroupActiveTooltip(groupTabs);
14668
14912
  if (active) lines.push(`Active: ${active}`);
14669
- lines.push("Click to switch · Drop tabs here to add");
14913
+ lines.push(isMobileView() ? "Tap to open group terminals" : "Click to switch · Drop tabs here to add");
14670
14914
  return lines.join("\n");
14671
14915
  }
14672
14916
 
14673
- function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false, workflowModeActive = false, workflowCount = 0, subagent = false }) {
14917
+ function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false, workflowModeActive = false, workflowCount = 0, subagent = false, dropdown = false }) {
14674
14918
  const titleRow = make("span", "terminal-tab-title-row");
14675
14919
  const indicatorDot = make("span", "terminal-tab-activity-indicator");
14676
14920
  indicatorDot.setAttribute("aria-hidden", "true");
@@ -14680,6 +14924,11 @@ function appendTerminalTabContent(button, { title, indicator, meta, count = null
14680
14924
  if (conversationModeActive) titleRow.append(make("span", "terminal-tab-conversation-indicator", "voice"));
14681
14925
  if (workflowModeActive || workflowCount) titleRow.append(make("span", "terminal-tab-workflow-indicator", workflowCount ? `wf ${workflowCount}` : "wf"));
14682
14926
  if (count !== null) titleRow.append(make("span", "terminal-tab-group-count", String(count)));
14927
+ if (dropdown) {
14928
+ const disclosure = make("span", "terminal-tab-group-dropdown-indicator", "⌄");
14929
+ disclosure.setAttribute("aria-hidden", "true");
14930
+ titleRow.append(disclosure);
14931
+ }
14683
14932
  button.append(titleRow, make("span", "terminal-tab-meta", meta));
14684
14933
  }
14685
14934
 
@@ -14787,10 +15036,19 @@ function renderTerminalTabGroup(group, groupCount = 1) {
14787
15036
  wrapper.dataset.groupKey = group.key;
14788
15037
  if (group.customGroupId) wrapper.dataset.customGroupId = group.customGroupId;
14789
15038
  bindTerminalTabDragAndDrop(wrapper, { sourceTabId: activeGroupTab?.id || "", target: { type: "group", group } });
14790
- wrapper.addEventListener("pointerenter", () => setOpenTerminalTabGroup(group.key));
14791
- wrapper.addEventListener("pointerleave", () => clearOpenTerminalTabGroup(group.key));
14792
- wrapper.addEventListener("focusin", () => setOpenTerminalTabGroup(group.key));
15039
+ wrapper.addEventListener("pointerenter", (event) => {
15040
+ if (event.pointerType === "touch") return;
15041
+ setOpenTerminalTabGroup(group.key);
15042
+ });
15043
+ wrapper.addEventListener("pointerleave", (event) => {
15044
+ if (event.pointerType === "touch") return;
15045
+ clearOpenTerminalTabGroup(group.key);
15046
+ });
15047
+ wrapper.addEventListener("focusin", () => {
15048
+ if (!isMobileView()) setOpenTerminalTabGroup(group.key);
15049
+ });
14793
15050
  wrapper.addEventListener("focusout", () => {
15051
+ if (isMobileView()) return;
14794
15052
  setTimeout(() => {
14795
15053
  if (!wrapper.contains(document.activeElement)) clearOpenTerminalTabGroup(group.key);
14796
15054
  }, 0);
@@ -14802,10 +15060,16 @@ function renderTerminalTabGroup(group, groupCount = 1) {
14802
15060
  button.setAttribute("aria-selected", isActive ? "true" : "false");
14803
15061
  button.setAttribute("aria-haspopup", "true");
14804
15062
  button.setAttribute("aria-expanded", group.key === openTerminalTabGroupKey ? "true" : "false");
14805
- button.setAttribute("aria-label", `${groupTitle} ${group.custom ? "custom" : "cwd"} group: ${groupTabs.length} tabs, ${indicator.label}${appRunnerSummary ? `, ${appRunnerSummary}` : ""}${workflowModeActive ? ", workflow mode active" : ""}${workflowCount ? `, ${workflowCount} workflow runs active` : ""}. Active ${activeTitle}`);
15063
+ button.setAttribute("aria-label", `${groupTitle} ${group.custom ? "custom" : "cwd"} group: ${groupTabs.length} tabs, ${indicator.label}${appRunnerSummary ? `, ${appRunnerSummary}` : ""}${workflowModeActive ? ", workflow mode active" : ""}${workflowCount ? `, ${workflowCount} workflow runs active` : ""}. Active ${activeTitle}. ${isMobileView() ? "Toggle group terminal list" : "Switch to the active group terminal"}`);
14806
15064
  applyStyledTooltip(button, terminalTabGroupTooltip(group, groupTitle), { ariaLabel: false, description: true, placement: "right", variant: "workspace", targetKey: `terminal-group:${group.key}:switch` });
14807
- appendTerminalTabContent(button, { title: activeTitle, indicator, meta: `${groupTitle} · ${indicator.meta}${groupAppRunnerMeta ? ` · ${groupAppRunnerMeta}` : ""}${workflowModeActive ? " · workflow mode" : ""}${workflowCount ? ` · ${workflowCount} workflows` : ""}`, appRunnerRun, count: groupTabs.length, workflowModeActive, workflowCount });
14808
- button.addEventListener("click", () => switchTab(activeGroupTab.id));
15065
+ appendTerminalTabContent(button, { title: activeTitle, indicator, meta: `${groupTitle} · ${indicator.meta}${groupAppRunnerMeta ? ` · ${groupAppRunnerMeta}` : ""}${workflowModeActive ? " · workflow mode" : ""}${workflowCount ? ` · ${workflowCount} workflows` : ""}`, appRunnerRun, count: groupTabs.length, workflowModeActive, workflowCount, dropdown: true });
15066
+ button.addEventListener("click", () => {
15067
+ if (isMobileView()) {
15068
+ toggleOpenTerminalTabGroup(group.key);
15069
+ return;
15070
+ }
15071
+ switchTab(activeGroupTab.id);
15072
+ });
14809
15073
  wrapper.append(button);
14810
15074
 
14811
15075
  if (groupCount > 1 || group.custom) {
@@ -14822,8 +15086,10 @@ function renderTerminalTabGroup(group, groupCount = 1) {
14822
15086
  }
14823
15087
 
14824
15088
  const menu = make("div", "terminal-tab-group-menu");
15089
+ menu.id = `terminalTabGroupMenu${++terminalTabGroupMenuSerial}`;
14825
15090
  menu.setAttribute("role", "group");
14826
15091
  menu.setAttribute("aria-label", `${groupTitle} tabs`);
15092
+ button.setAttribute("aria-controls", menu.id);
14827
15093
  for (const tab of groupTabs) menu.append(renderTerminalTabGroupItem(tab, group));
14828
15094
 
14829
15095
  const add = make("button", "terminal-tab-group-add", "+ Tab");
@@ -14854,6 +15120,12 @@ function setOpenTerminalTabGroup(groupKey) {
14854
15120
  updateTerminalTabGroupOpenState();
14855
15121
  }
14856
15122
 
15123
+ function toggleOpenTerminalTabGroup(groupKey) {
15124
+ if (!groupKey) return;
15125
+ if (openTerminalTabGroupKey === groupKey) clearOpenTerminalTabGroup(groupKey);
15126
+ else setOpenTerminalTabGroup(groupKey);
15127
+ }
15128
+
14857
15129
  function clearOpenTerminalTabGroup(groupKey, { force = false } = {}) {
14858
15130
  if (!openTerminalTabGroupKey || (!force && openTerminalTabGroupKey !== groupKey)) return;
14859
15131
  openTerminalTabGroupKey = null;
@@ -15029,6 +15301,8 @@ async function refreshTabs({ selectStored = false } = {}) {
15029
15301
  async function switchTab(tabId) {
15030
15302
  if (!tabId || !tabs.some((tab) => tab.id === tabId)) return;
15031
15303
  if (tabId === activeTabId) {
15304
+ clearOpenTerminalTabGroup(null, { force: true });
15305
+ setMobileTabsExpanded(false);
15032
15306
  if (activeSubagentTerminalId) deactivateSubagentTerminalView({ focusParent: true });
15033
15307
  return;
15034
15308
  }
@@ -16278,10 +16552,13 @@ function hideFooterTooltip(target) {
16278
16552
  function bindStyledTooltipEvents(node) {
16279
16553
  if (!node || node._styledTooltipBound) return;
16280
16554
  node._styledTooltipBound = true;
16281
- node.addEventListener("mouseenter", () => scheduleFooterTooltip(node));
16282
- node.addEventListener("mouseleave", () => hideFooterTooltip(node));
16555
+ node.addEventListener("pointerenter", (event) => {
16556
+ if (event.pointerType === "touch") return;
16557
+ scheduleFooterTooltip(node);
16558
+ });
16559
+ node.addEventListener("pointerleave", () => hideFooterTooltip(node));
16283
16560
  node.addEventListener("focus", () => {
16284
- if (node.getAttribute("data-tooltip-variant") === "workspace" && !node.matches(":focus-visible")) return;
16561
+ if (!node.matches(":focus-visible")) return;
16285
16562
  showFooterTooltip(node);
16286
16563
  });
16287
16564
  node.addEventListener("blur", () => hideFooterTooltip(node));
@@ -16320,12 +16597,17 @@ function applyFooterTooltip(node, tooltip, options = {}) {
16320
16597
  return applyStyledTooltip(node, tooltip, options);
16321
16598
  }
16322
16599
 
16600
+ function runFooterControlAction(action, event) {
16601
+ if (mobileFooterExpanded) setMobileFooterExpanded(false, { restoreFocus: false });
16602
+ return action(event);
16603
+ }
16604
+
16323
16605
  function footerMetric(icon, label, value, tone = "", options = {}) {
16324
16606
  const isAction = typeof options.onClick === "function";
16325
16607
  const node = make(isAction ? "button" : "span", ["footer-metric", tone, isAction ? "footer-metric-action" : ""].filter(Boolean).join(" "));
16326
16608
  if (isAction) {
16327
16609
  node.type = "button";
16328
- node.addEventListener("click", options.onClick);
16610
+ node.addEventListener("click", (event) => runFooterControlAction(options.onClick, event));
16329
16611
  if (options.ariaPressed !== undefined) node.setAttribute("aria-pressed", options.ariaPressed ? "true" : "false");
16330
16612
  if (options.ariaBusy) node.setAttribute("aria-busy", "true");
16331
16613
  }
@@ -16431,7 +16713,7 @@ function footerMeta(label, value, className = "", options = {}) {
16431
16713
  const node = make(isAction ? "button" : "span", ["footer-meta", className, isAction ? "footer-meta-action" : ""].filter(Boolean).join(" "));
16432
16714
  if (isAction) {
16433
16715
  node.type = "button";
16434
- node.addEventListener("click", options.onClick);
16716
+ node.addEventListener("click", (event) => runFooterControlAction(options.onClick, event));
16435
16717
  if (options.ariaPressed !== undefined) node.setAttribute("aria-pressed", options.ariaPressed ? "true" : "false");
16436
16718
  if (options.ariaBusy) node.setAttribute("aria-busy", "true");
16437
16719
  if (options.disabled) {
@@ -17242,7 +17524,8 @@ function gitFooterSyncCounts(value) {
17242
17524
  function gitFooterSyncAction(chip) {
17243
17525
  if (chip?.key !== "sync") return "";
17244
17526
  const { ahead, behind } = gitFooterSyncCounts(chip.value);
17245
- if (behind > 0 && ahead === 0) return "pull";
17527
+ if (behind > 0 && ahead > 0) return "pull-push";
17528
+ if (behind > 0) return "pull";
17246
17529
  if (ahead > 0) return "push";
17247
17530
  return "";
17248
17531
  }
@@ -17253,8 +17536,172 @@ function gitFooterCurrentBranch() {
17253
17536
  return value && value !== "no repo" ? cleanFooterPayloadText(gitChip.value, "") : "";
17254
17537
  }
17255
17538
 
17256
- async function pullGitFooterSync(tabId = activeTabId) {
17257
- if (!tabId || gitFooterSyncInFlightByTab.has(tabId)) return;
17539
+ function gitFailureDisplayText(response, fallback = "Git operation failed") {
17540
+ const errorText = String(response?.error || "").trim();
17541
+ const hintText = String(response?.hint || "").trim();
17542
+ const result = response?.data && typeof response.data === "object" ? { ...response.data } : null;
17543
+ if (result && errorText) {
17544
+ if (String(result.stderr || "").trim() === errorText) result.stderr = "";
17545
+ if (String(result.stdout || "").trim() === errorText) result.stdout = "";
17546
+ }
17547
+ const parts = [errorText || fallback, hintText, formatGitCommandResult(result)].map((part) => String(part || "").trim()).filter(Boolean);
17548
+ const seen = new Set();
17549
+ return parts.filter((part) => {
17550
+ const key = part.replace(/\r\n/g, "\n");
17551
+ if (seen.has(key)) return false;
17552
+ seen.add(key);
17553
+ return true;
17554
+ }).join("\n\n");
17555
+ }
17556
+
17557
+ function setGitPullErrorBusy(busy) {
17558
+ gitPullErrorContext = { ...gitPullErrorContext, busy: !!busy };
17559
+ for (const button of [elements.gitPullErrorMergeButton, elements.gitPullErrorRebaseButton, elements.gitPullErrorReviewButton, elements.gitPullErrorCloseButton]) {
17560
+ if (button) button.disabled = !!busy;
17561
+ }
17562
+ if (elements.gitPullErrorDialog) elements.gitPullErrorDialog.setAttribute("aria-busy", busy ? "true" : "false");
17563
+ }
17564
+
17565
+ function closeGitPullErrorDialog() {
17566
+ if (gitPullErrorContext.busy) return;
17567
+ if (elements.gitPullErrorDialog?.open) elements.gitPullErrorDialog.close();
17568
+ }
17569
+
17570
+ function openGitPullErrorDialog(message, { code = "", tabId = null, syncValue = "" } = {}) {
17571
+ const text = String(message || "git pull from origin failed").trim();
17572
+ const diverged = code === "DIVERGED";
17573
+ gitPullErrorText = text;
17574
+ gitPullErrorContext = {
17575
+ code,
17576
+ tabId: typeof tabId === "string" && tabId ? tabId : null,
17577
+ syncValue: String(syncValue || ""),
17578
+ busy: false,
17579
+ requestId: gitPullErrorContext.requestId + 1,
17580
+ };
17581
+ if (!elements.gitPullErrorDialog?.showModal || !elements.gitPullErrorOutput) {
17582
+ window.alert(`${diverged ? "Branches diverged" : "Git pull failed"}\n\n${text}`);
17583
+ return;
17584
+ }
17585
+ if (elements.gitPullErrorDialogTitle) elements.gitPullErrorDialogTitle.textContent = diverged ? "Branches diverged" : "Git pull failed";
17586
+ if (elements.gitPullErrorDialogDescription) {
17587
+ elements.gitPullErrorDialogDescription.textContent = diverged
17588
+ ? "Local and remote contain unique commits. This does not mean conflicts exist; conflicts are known only after a merge or rebase is attempted."
17589
+ : "The repository was not changed by the failed pull. Review or copy the complete error output below.";
17590
+ }
17591
+ elements.gitPullErrorOutput.textContent = text;
17592
+ if (elements.gitPullErrorRecovery) elements.gitPullErrorRecovery.hidden = !diverged;
17593
+ elements.gitPullErrorCloseButton?.classList.toggle("primary", !diverged);
17594
+ if (elements.gitPullErrorStatus) {
17595
+ elements.gitPullErrorStatus.textContent = diverged
17596
+ ? "Review the incoming changes, merge them, or rebase your local commits. No integration runs without confirmation."
17597
+ : "Select the output or use Copy error output.";
17598
+ elements.gitPullErrorStatus.classList.remove("error", "success");
17599
+ }
17600
+ setGitPullErrorBusy(false);
17601
+ if (!elements.gitPullErrorDialog.open) elements.gitPullErrorDialog.showModal();
17602
+ queueMicrotask(() => (diverged ? elements.gitPullErrorReviewButton : elements.gitPullErrorCopyButton)?.focus({ preventScroll: true }));
17603
+ }
17604
+
17605
+ async function copyGitPullErrorOutput() {
17606
+ if (!gitPullErrorText) return;
17607
+ if (elements.gitPullErrorCopyButton) elements.gitPullErrorCopyButton.disabled = true;
17608
+ try {
17609
+ await copyText(gitPullErrorText);
17610
+ if (elements.gitPullErrorStatus) {
17611
+ elements.gitPullErrorStatus.textContent = "Error output copied to the clipboard.";
17612
+ elements.gitPullErrorStatus.classList.add("success");
17613
+ elements.gitPullErrorStatus.classList.remove("error");
17614
+ }
17615
+ addEvent("copied Git pull error output", "info");
17616
+ } catch (error) {
17617
+ const message = `Copy failed: ${error.message || String(error)}`;
17618
+ if (elements.gitPullErrorStatus) {
17619
+ elements.gitPullErrorStatus.textContent = message;
17620
+ elements.gitPullErrorStatus.classList.add("error");
17621
+ elements.gitPullErrorStatus.classList.remove("success");
17622
+ }
17623
+ addEvent(`Git pull error output copy failed: ${error.message || String(error)}`, "error");
17624
+ } finally {
17625
+ if (elements.gitPullErrorCopyButton) elements.gitPullErrorCopyButton.disabled = false;
17626
+ }
17627
+ }
17628
+
17629
+ function reviewGitPullDivergence() {
17630
+ if (gitPullErrorContext.code !== "DIVERGED" || !gitPullErrorContext.tabId || gitPullErrorContext.busy) return;
17631
+ const tabId = gitPullErrorContext.tabId;
17632
+ closeGitPullErrorDialog();
17633
+ openGitChangesDialog(tabId);
17634
+ }
17635
+
17636
+ async function integrateGitPullDivergence(mode) {
17637
+ if (!["merge", "rebase"].includes(mode) || gitPullErrorContext.code !== "DIVERGED" || !gitPullErrorContext.tabId || gitPullErrorContext.busy) return false;
17638
+ const { tabId, syncValue, requestId } = gitPullErrorContext;
17639
+ const targetTab = tabs.find((tab) => tab.id === tabId);
17640
+ const activeBranch = tabId === activeTabId ? gitFooterCurrentBranch() : "";
17641
+ const target = activeBranch || targetTab?.title || targetTab?.cwd || "the selected branch";
17642
+ const merge = mode === "merge";
17643
+ const confirmed = await appConfirmText([
17644
+ `${merge ? "Merge upstream changes into" : "Rebase local commits onto the upstream of"} ${target}?`,
17645
+ "",
17646
+ merge
17647
+ ? "This preserves both histories and may create a merge commit. Conflicts are possible but are not currently known."
17648
+ : "This replays local commits on top of upstream and rewrites their commit IDs. Conflicts are possible but are not currently known.",
17649
+ ].join("\n"), {
17650
+ affected: `Git history for ${target}`,
17651
+ confirmLabel: merge ? "Merge changes" : "Rebase commits",
17652
+ danger: !merge,
17653
+ });
17654
+ if (!confirmed || gitPullErrorContext.requestId !== requestId) return false;
17655
+
17656
+ const tabContext = activeTabContext(tabId);
17657
+ let pushSyncValue = "";
17658
+ setGitPullErrorBusy(true);
17659
+ gitFooterSyncInFlightByTab.add(tabId);
17660
+ if (isCurrentTabContext(tabContext)) renderFooter();
17661
+ if (elements.gitPullErrorStatus) elements.gitPullErrorStatus.textContent = merge ? "Merging upstream changes…" : "Rebasing local commits…";
17662
+ try {
17663
+ const response = await api("/api/git-changes/integrate", { method: "POST", body: { mode, confirmed: true }, tabId });
17664
+ if (gitPullErrorContext.requestId !== requestId) return false;
17665
+ if (!response.ok) {
17666
+ const message = gitFailureDisplayText(response, `git ${mode} failed`);
17667
+ addEvent(message, "error");
17668
+ setGitPullErrorBusy(false);
17669
+ if (response.code === "CONFLICTS") {
17670
+ closeGitPullErrorDialog();
17671
+ openGitChangesDialog(tabId);
17672
+ return false;
17673
+ }
17674
+ openGitPullErrorDialog(message, { code: response.code || "", tabId, syncValue });
17675
+ return false;
17676
+ }
17677
+ setGitPullErrorBusy(false);
17678
+ closeGitPullErrorDialog();
17679
+ addEvent(`${merge ? "Merged" : "Rebased"} upstream changes.`, "success");
17680
+ requestGitFooterWebuiPayload(tabContext, { force: true });
17681
+ const freshAheadValue = response.data?.changes?.summary?.ahead;
17682
+ const freshAhead = Number(freshAheadValue);
17683
+ if (freshAheadValue !== undefined) {
17684
+ if (Number.isFinite(freshAhead) && freshAhead > 0) pushSyncValue = `⇡${freshAhead}`;
17685
+ } else if (gitFooterSyncCounts(syncValue).ahead > 0) {
17686
+ pushSyncValue = syncValue;
17687
+ }
17688
+ } catch (error) {
17689
+ if (gitPullErrorContext.requestId !== requestId) return false;
17690
+ const message = error.message || String(error);
17691
+ addEvent(message, "error");
17692
+ setGitPullErrorBusy(false);
17693
+ openGitPullErrorDialog(message, { tabId, syncValue });
17694
+ return false;
17695
+ } finally {
17696
+ gitFooterSyncInFlightByTab.delete(tabId);
17697
+ if (isCurrentTabContext(tabContext)) renderFooter();
17698
+ }
17699
+ if (pushSyncValue) await pushGitFooterSync(tabId, pushSyncValue);
17700
+ return true;
17701
+ }
17702
+
17703
+ async function pullGitFooterSync(tabId = activeTabId, { syncValue = "" } = {}) {
17704
+ if (!tabId || gitFooterSyncInFlightByTab.has(tabId)) return false;
17258
17705
  const tabContext = activeTabContext(tabId);
17259
17706
  hideFooterTooltip();
17260
17707
  gitFooterSyncInFlightByTab.add(tabId);
@@ -17262,23 +17709,36 @@ async function pullGitFooterSync(tabId = activeTabId) {
17262
17709
  try {
17263
17710
  const response = await api("/api/git-changes/pull", { method: "POST", body: { remote: "origin" }, tabId });
17264
17711
  if (!response.ok) {
17265
- const detail = [response.error, response.hint, formatGitCommandResult(response.data)].filter(Boolean).join("\n\n").trim();
17266
- throw new Error(detail || "git pull from origin failed");
17712
+ const message = gitFailureDisplayText(response, "git pull from origin failed");
17713
+ addEvent(message, "error");
17714
+ openGitPullErrorDialog(message, { code: response.code || "", tabId, syncValue });
17715
+ return false;
17267
17716
  }
17268
17717
  addEvent("Pulled Git changes from origin.", "success");
17269
17718
  requestGitFooterWebuiPayload(tabContext, { force: true });
17719
+ return true;
17270
17720
  } catch (error) {
17271
- addEvent(error.message || String(error), "error");
17721
+ const message = error.message || String(error);
17722
+ addEvent(message, "error");
17723
+ openGitPullErrorDialog(message, { code: error?.code || "", tabId, syncValue });
17724
+ return false;
17272
17725
  } finally {
17273
17726
  gitFooterSyncInFlightByTab.delete(tabId);
17274
17727
  if (isCurrentTabContext(tabContext)) renderFooter();
17275
17728
  }
17276
17729
  }
17277
17730
 
17731
+ async function pullThenPushGitFooterSync(tabId = activeTabId, syncValue = "") {
17732
+ const pulled = await pullGitFooterSync(tabId, { syncValue });
17733
+ if (!pulled) return;
17734
+ await pushGitFooterSync(tabId, syncValue);
17735
+ }
17736
+
17278
17737
  async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
17279
17738
  if (!tabId || gitFooterSyncInFlightByTab.has(tabId)) return;
17280
17739
  const outgoing = gitFooterSyncCounts(syncValue).ahead;
17281
17740
  if (outgoing <= 0) return;
17741
+ let recoverWithPullFirst = false;
17282
17742
  const tabContext = activeTabContext(tabId);
17283
17743
  const tab = tabs.find((item) => item.id === tabId);
17284
17744
  const target = tab?.title || tab?.cwd || "this tab";
@@ -17306,34 +17766,25 @@ async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
17306
17766
  throw new Error([response.error, response.hint].filter(Boolean).join("\n"));
17307
17767
  }
17308
17768
  if (response.code === "NON_FAST_FORWARD") {
17309
- const forcePush = await appConfirmText([
17310
- response.error,
17311
- "",
17312
- response.hint || "",
17313
- "",
17314
- "Recommended: open the Git Changes dialog, fetch, and review the incoming diff first.",
17315
- `DANGER: force-push ${branch || "the current branch"} with --force-with-lease instead? This rewrites the remote branch (but still refuses if the remote moved past what you fetched).`,
17316
- ].join("\n"));
17317
- if (forcePush) {
17318
- const forceResponse = await api("/api/git-workflow/push", { method: "POST", body: { forceWithLease: true, confirmed: true }, tabId });
17319
- if (!forceResponse.ok) throw new Error([forceResponse.error, forceResponse.hint].filter(Boolean).join("\n"));
17320
- addEvent("Force-pushed with --force-with-lease.", "success");
17321
- requestGitFooterWebuiPayload(tabContext, { force: true });
17322
- return;
17323
- }
17324
- throw new Error([response.error, response.hint].filter(Boolean).join("\n"));
17769
+ recoverWithPullFirst = true;
17770
+ } else {
17771
+ const detail = [response.error, response.hint, formatGitCommandResult(response.data)].filter(Boolean).join("\n\n").trim();
17772
+ throw new Error(detail || "git push failed");
17325
17773
  }
17326
- const detail = [response.error, response.hint, formatGitCommandResult(response.data)].filter(Boolean).join("\n\n").trim();
17327
- throw new Error(detail || "git push failed");
17774
+ } else {
17775
+ addEvent(`Pushed ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"}.`, "success");
17776
+ requestGitFooterWebuiPayload(tabContext, { force: true });
17328
17777
  }
17329
- addEvent(`Pushed ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"}.`, "success");
17330
- requestGitFooterWebuiPayload(tabContext, { force: true });
17331
17778
  } catch (error) {
17332
17779
  addEvent(error.message || String(error), "error");
17333
17780
  } finally {
17334
17781
  gitFooterSyncInFlightByTab.delete(tabId);
17335
17782
  if (isCurrentTabContext(tabContext)) renderFooter();
17336
17783
  }
17784
+ if (recoverWithPullFirst) {
17785
+ addEvent("Push found incoming commits. Starting pull-first recovery.", "info");
17786
+ await pullThenPushGitFooterSync(tabId, syncValue);
17787
+ }
17337
17788
  }
17338
17789
 
17339
17790
  function renderGitFooterPayloadMeta(chip, tab, payload) {
@@ -17359,6 +17810,9 @@ function renderGitFooterPayloadMeta(chip, tab, payload) {
17359
17810
  if (syncAction === "pull") {
17360
17811
  options.onClick = () => pullGitFooterSync(tabId);
17361
17812
  action = inFlight ? "Pulling from origin." : "Click to pull from origin with fast-forward only.";
17813
+ } else if (syncAction === "pull-push") {
17814
+ options.onClick = () => pullThenPushGitFooterSync(tabId, chip.value);
17815
+ action = inFlight ? "Pulling from origin before pushing local commits." : "Click to pull from origin with fast-forward only, then push if the pull succeeds.";
17362
17816
  } else if (syncAction === "push") {
17363
17817
  options.onClick = () => pushGitFooterSync(tabId, chip.value);
17364
17818
  action = inFlight ? "Pushing local commits to the configured remote." : "Click to push local commits to the configured remote.";
@@ -17552,10 +18006,12 @@ function renderGitFooterPayload(payload) {
17552
18006
  const row2 = make("div", "footer-line footer-line-meta");
17553
18007
  const row2Children = [...metaNodes];
17554
18008
  if (gitFooterPayloadVisible(payload, "webui-details-button")) {
17555
- const footerToggle = make("button", "footer-details-toggle", mobileFooterExpanded ? "Less" : "Details");
18009
+ const footerToggle = make("button", "footer-details-toggle", mobileFooterExpanded ? "−" : "Details");
17556
18010
  footerToggle.type = "button";
18011
+ footerToggle.setAttribute("aria-label", mobileFooterExpanded ? "Minimize Git footer details" : "Show Git footer details");
18012
+ footerToggle.setAttribute("title", mobileFooterExpanded ? "Minimize Git footer details" : "Show Git footer details");
17557
18013
  footerToggle.setAttribute("aria-expanded", mobileFooterExpanded ? "true" : "false");
17558
- footerToggle.addEventListener("click", () => setMobileFooterExpanded(!mobileFooterExpanded));
18014
+ footerToggle.addEventListener("click", () => setMobileFooterExpanded(!mobileFooterExpanded, { restoreFocus: true }));
17559
18015
  row2Children.push(footerToggle);
17560
18016
  }
17561
18017
  row2.append(...row2Children);
@@ -19974,7 +20430,8 @@ async function confirmFooterGitWorktreeAction(branch, { path = "", create = fals
19974
20430
  ...(trackedRemoteRef ? [`Remote ref: ${trackedRemoteRef}`, `Creates local branch ${branchName} tracking ${trackedRemoteRef}.`] : []),
19975
20431
  targetPath ? `Worktree: ${targetPath}` : `Default location: ${footerBranchPickerState.defaultWorktreesRoot || "repo sibling .worktrees directory"}`,
19976
20432
  "",
19977
- "This opens a separate checkout in a separate Pi tab and does not switch this tab's branch.",
20433
+ "This creates a separate checkout without changing this tab's branch.",
20434
+ "After creation, you can choose whether to open it in a separate Pi tab and switch to it.",
19978
20435
  "Ignored dependencies such as node_modules or .venv are not copied; bootstrap them manually if needed.",
19979
20436
  "",
19980
20437
  "Continue?",
@@ -20056,7 +20513,7 @@ function footerBranchCreateTooltip(branchName = footerBranchCreateName(), state
20056
20513
  "",
20057
20514
  "What happens:",
20058
20515
  "• asks whether to base the new branch on origin/main (default) or this workspace's current HEAD",
20059
- "• opens a separate Pi tab rooted at that worktree",
20516
+ "• creates the worktree, then asks whether to open and switch to it in a separate Pi tab",
20060
20517
  "• does not switch this tab's branch, commit, push, or delete anything",
20061
20518
  "",
20062
20519
  "Tip: ignored dependencies such as node_modules or .venv are not copied.",
@@ -20074,7 +20531,7 @@ async function createFooterGitBranch(branch = footerBranchCreateName()) {
20074
20531
  await applyFooterGitBranch(branchName, { create: true, tabContext, skipConfirm: true });
20075
20532
  }
20076
20533
 
20077
- async function openWorktreeResponseTab(response, { branchName = "", action = "open" } = {}) {
20534
+ async function openWorktreeResponseTab(response, { branchName = "", action = "open", announce = true } = {}) {
20078
20535
  if (!response.ok) throw new Error(response.error || `Failed to ${action} branch worktree`);
20079
20536
  const payload = response.data || {};
20080
20537
  if (Array.isArray(payload.tabs)) {
@@ -20091,12 +20548,27 @@ async function openWorktreeResponseTab(response, { branchName = "", action = "op
20091
20548
  const branch = cleanStatusText(payload.worktree?.branch || payload.branch || branchName || targetTab?.gitWorkspace?.branch || "");
20092
20549
  const where = payload.worktree?.path || payload.path || targetTab?.cwd || "worktree";
20093
20550
  const prefix = payload.created ? "Created" : payload.openedExisting || payload.openedExistingTab ? "Opened existing" : "Opened";
20094
- addEvent(`${prefix} branch worktree${branch ? ` ${branch}` : ""} at ${normalizeDisplayPath(where)}.`, "success");
20551
+ if (announce) addEvent(`${prefix} branch worktree${branch ? ` ${branch}` : ""} at ${normalizeDisplayPath(where)}.`, "success");
20095
20552
  if (payload.session?.warning) addEvent(payload.session.warning, "warn");
20096
20553
  if (payload.dependencyHint) addEvent(payload.dependencyHint, "info");
20097
20554
  requestGitFooterWebuiPayload(activeTabContext(), { force: true });
20098
20555
  }
20099
20556
 
20557
+ async function confirmSwitchToCreatedFooterGitWorktree(payload = {}, branchName = "") {
20558
+ if (payload.created !== true) return false;
20559
+ const branch = cleanStatusText(payload.worktree?.branch || payload.branch || branchName);
20560
+ const worktreePath = cleanFooterPayloadText(payload.worktree?.path || payload.path, "", 4000);
20561
+ if (!worktreePath) return false;
20562
+ return appConfirm({
20563
+ title: "Switch to new worktree?",
20564
+ summary: `The${branch ? ` ${branch}` : ""} worktree was created. Open it in a separate Pi tab and switch to it now? The worktree remains available if you stay here.`,
20565
+ affected: normalizeDisplayPath(worktreePath),
20566
+ undoable: true,
20567
+ confirmLabel: "Switch to worktree",
20568
+ danger: false,
20569
+ });
20570
+ }
20571
+
20100
20572
  async function createFooterGitBranchWorktree(branch = footerBranchCreateName(), { tabContext = activeTabContext(), skipConfirm = false, chooseBase = true, remoteRef = "", switchingLabel = "", switchingKey = "" } = {}) {
20101
20573
  const branchName = cleanStatusText(branch);
20102
20574
  if (!branchName) {
@@ -20114,9 +20586,20 @@ async function createFooterGitBranchWorktree(branch = footerBranchCreateName(),
20114
20586
  // Remote-only creation submits the exact advertised remote ref instead of a
20115
20587
  // base ref; the server re-verifies it and creates a local tracking branch.
20116
20588
  const response = trackedRemoteRef
20117
- ? await api("/api/git-worktrees", { method: "POST", body: { branchName, remoteRef: trackedRemoteRef, sessionMode: "fork-current", openTab: true }, tabId })
20118
- : await api("/api/git-worktrees", { method: "POST", body: { branchName, baseRef, sessionMode: "fork-current", openTab: true }, tabId });
20119
- await openWorktreeResponseTab(response, { branchName, action: "create" });
20589
+ ? await api("/api/git-worktrees", { method: "POST", body: { branchName, remoteRef: trackedRemoteRef, sessionMode: "fork-current", openTab: false }, tabId })
20590
+ : await api("/api/git-worktrees", { method: "POST", body: { branchName, baseRef, sessionMode: "fork-current", openTab: false }, tabId });
20591
+ if (!response.ok) throw new Error(response.error || "Failed to create branch worktree");
20592
+ const payload = response.data || {};
20593
+ const worktreePath = cleanFooterPayloadText(payload.worktree?.path || payload.path, "", 4000);
20594
+ if (!worktreePath) throw new Error("Git worktree creation did not return a path");
20595
+ if (payload.created) {
20596
+ await openWorktreeResponseTab(response, { branchName, action: "create" });
20597
+ if (await confirmSwitchToCreatedFooterGitWorktree(payload, branchName)) {
20598
+ await openFooterGitWorktree(worktreePath, { branchName, tabContext, skipConfirm: true, announce: false });
20599
+ }
20600
+ } else {
20601
+ await openFooterGitWorktree(worktreePath, { branchName, tabContext, skipConfirm: true });
20602
+ }
20120
20603
  } catch (error) {
20121
20604
  if (isCurrentTabContext(tabContext)) {
20122
20605
  footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", switchingKey: "", error: error.message || String(error) };
@@ -20127,7 +20610,7 @@ async function createFooterGitBranchWorktree(branch = footerBranchCreateName(),
20127
20610
  }
20128
20611
  }
20129
20612
 
20130
- async function openFooterGitWorktree(path, { branchName = "", tabContext = activeTabContext(), skipConfirm = false, switchingKey = "" } = {}) {
20613
+ async function openFooterGitWorktree(path, { branchName = "", tabContext = activeTabContext(), skipConfirm = false, switchingKey = "", announce = true } = {}) {
20131
20614
  const worktreePath = cleanFooterPayloadText(path, "", 4000);
20132
20615
  if (!worktreePath) return;
20133
20616
  if (!skipConfirm && !(await confirmFooterGitWorktreeAction(branchName, { path: worktreePath, requireConfirm: false }))) return;
@@ -20136,7 +20619,7 @@ async function openFooterGitWorktree(path, { branchName = "", tabContext = activ
20136
20619
  footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: branchName || worktreePath, switchingKey, tabId };
20137
20620
  renderFooter();
20138
20621
  const response = await api("/api/git-worktrees/open", { method: "POST", body: { path: worktreePath, sessionMode: "fork-current", openTab: true }, tabId });
20139
- await openWorktreeResponseTab(response, { branchName, action: "open" });
20622
+ await openWorktreeResponseTab(response, { branchName, action: "open", announce });
20140
20623
  } catch (error) {
20141
20624
  if (isCurrentTabContext(tabContext)) {
20142
20625
  footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", switchingKey: "", error: error.message || String(error) };
@@ -22661,6 +23144,8 @@ function deactivateSubagentTerminalView({ render = true, focusParent = false } =
22661
23144
  async function activateSubagentTerminalView(viewId) {
22662
23145
  const view = subagentTerminalViews.get(viewId);
22663
23146
  if (!view) return;
23147
+ clearOpenTerminalTabGroup(null, { force: true });
23148
+ setMobileTabsExpanded(false);
22664
23149
  if (activeTabId !== view.parentTabId) await switchTab(view.parentTabId);
22665
23150
  closeSubagentOverlay();
22666
23151
  activeSubagentTerminalId = view.id;
@@ -22891,10 +23376,19 @@ function renderSubagentTerminalTabGroup(group) {
22891
23376
  const groupTitle = group.parentTitle || "workspace";
22892
23377
  const wrapper = make("div", `terminal-tab terminal-tab-group terminal-tab-subagent terminal-tab-subagent-group ${stateClass}${active ? " active" : ""}`);
22893
23378
  wrapper.dataset.groupKey = group.key;
22894
- wrapper.addEventListener("pointerenter", () => setOpenTerminalTabGroup(group.key));
22895
- wrapper.addEventListener("pointerleave", () => clearOpenTerminalTabGroup(group.key));
22896
- wrapper.addEventListener("focusin", () => setOpenTerminalTabGroup(group.key));
23379
+ wrapper.addEventListener("pointerenter", (event) => {
23380
+ if (event.pointerType === "touch") return;
23381
+ setOpenTerminalTabGroup(group.key);
23382
+ });
23383
+ wrapper.addEventListener("pointerleave", (event) => {
23384
+ if (event.pointerType === "touch") return;
23385
+ clearOpenTerminalTabGroup(group.key);
23386
+ });
23387
+ wrapper.addEventListener("focusin", () => {
23388
+ if (!isMobileView()) setOpenTerminalTabGroup(group.key);
23389
+ });
22897
23390
  wrapper.addEventListener("focusout", () => {
23391
+ if (isMobileView()) return;
22898
23392
  setTimeout(() => {
22899
23393
  if (!wrapper.contains(document.activeElement)) clearOpenTerminalTabGroup(group.key);
22900
23394
  }, 0);
@@ -22906,7 +23400,7 @@ function renderSubagentTerminalTabGroup(group) {
22906
23400
  button.setAttribute("aria-selected", active ? "true" : "false");
22907
23401
  button.setAttribute("aria-haspopup", "true");
22908
23402
  button.setAttribute("aria-expanded", group.key === openTerminalTabGroupKey ? "true" : "false");
22909
- button.setAttribute("aria-label", `${groupTitle} workspace subagents: ${groupViews.length} views, ${runningCount} running. Active ${subagentTerminalViewTitle(activeView)}`);
23403
+ button.setAttribute("aria-label", `${groupTitle} workspace subagents: ${groupViews.length} views, ${runningCount} running. Active ${subagentTerminalViewTitle(activeView)}. ${isMobileView() ? "Toggle subagent view list" : "Switch to the active subagent view"}`);
22910
23404
  applyStyledTooltip(button, `${groupTitle} · ${groupViews.length} subagent views\n${runningCount ? `${runningCount} running` : "All finished"}\nActive: ${subagentTerminalViewTitle(activeView)}`, { ariaLabel: false, description: true, placement: "right", variant: "workspace" });
22911
23405
  appendTerminalTabContent(button, {
22912
23406
  title: groupTitle,
@@ -22914,8 +23408,15 @@ function renderSubagentTerminalTabGroup(group) {
22914
23408
  meta: `${groupViews.length} subagents · ${runningCount ? `${runningCount} running` : "finished"}`,
22915
23409
  count: groupViews.length,
22916
23410
  subagent: true,
23411
+ dropdown: true,
23412
+ });
23413
+ button.addEventListener("click", () => {
23414
+ if (isMobileView()) {
23415
+ toggleOpenTerminalTabGroup(group.key);
23416
+ return;
23417
+ }
23418
+ activateSubagentTerminalView(activeView.id);
22917
23419
  });
22918
- button.addEventListener("click", () => activateSubagentTerminalView(activeView.id));
22919
23420
  wrapper.append(button);
22920
23421
 
22921
23422
  const close = make("button", "terminal-tab-close terminal-tab-group-close", "×");
@@ -22928,8 +23429,10 @@ function renderSubagentTerminalTabGroup(group) {
22928
23429
  wrapper.append(close);
22929
23430
 
22930
23431
  const menu = make("div", "terminal-tab-group-menu");
23432
+ menu.id = `terminalTabGroupMenu${++terminalTabGroupMenuSerial}`;
22931
23433
  menu.setAttribute("role", "group");
22932
23434
  menu.setAttribute("aria-label", `${groupTitle} subagent views`);
23435
+ button.setAttribute("aria-controls", menu.id);
22933
23436
  for (const view of groupViews) menu.append(renderSubagentTerminalTab(view, { groupItem: true }));
22934
23437
  wrapper.append(menu);
22935
23438
  return wrapper;
@@ -32852,14 +33355,14 @@ function resetChatOutput() {
32852
33355
  renderedTranscriptState = { epoch: "", entries: [] };
32853
33356
  const liveBubbles = standaloneLiveTranscriptBubbles();
32854
33357
  const preservedNodes = [...elements.chat.children]
32855
- .filter((child) => child === elements.stickyUserPromptButton || child === runIndicatorBubble || liveBubbles.has(child));
33358
+ .filter((child) => child === elements.stickyUserPromptButton || liveBubbles.has(child));
32856
33359
  transcriptRenderer.replaceChildren(elements.chat, ...preservedNodes);
32857
33360
  }
32858
33361
 
32859
33362
  function appendChatMessageBubble(bubble, { liveTail = false } = {}) {
32860
33363
  const liveBubbles = standaloneLiveTranscriptBubbles();
32861
33364
  const tailAnchor = [...elements.chat.children]
32862
- .find((child) => child !== bubble && (child === runIndicatorBubble || (!liveTail && liveBubbles.has(child))));
33365
+ .find((child) => child !== bubble && !liveTail && liveBubbles.has(child));
32863
33366
  if (tailAnchor) elements.chat.insertBefore(bubble, tailAnchor);
32864
33367
  else elements.chat.append(bubble);
32865
33368
  }
@@ -34103,7 +34606,9 @@ function appendOptimisticUserPrompt(message, attachmentCount = 0) {
34103
34606
  });
34104
34607
  if (transientMessages.length > 80) transientMessages.splice(0, transientMessages.length - 80);
34105
34608
  renderAllMessages();
34106
- if (autoFollowChat || isChatNearBottom()) scrollChatToBottom({ force: true });
34609
+ // Sending a prompt is an explicit request to follow the new turn, even when
34610
+ // the reader had previously paused auto-follow higher in the transcript.
34611
+ scrollChatToBottom({ force: true });
34107
34612
  return optimisticPromptId;
34108
34613
  }
34109
34614
 
@@ -34216,9 +34721,9 @@ function runIndicatorDetail() {
34216
34721
  return "Waiting for output or action…";
34217
34722
  }
34218
34723
 
34219
- // Transcript-owned ticker: it may only repaint the run-indicator bubble's own
34724
+ // Status-host-owned ticker: it may only repaint the run-indicator bubble's own
34220
34725
  // stable text nodes. Canonical state reconciliation belongs to the separate
34221
- // lifecycle watchdog below, so transcript rendering never issues network work.
34726
+ // lifecycle watchdog below, so status rendering never issues network work.
34222
34727
  function startRunIndicatorTicker() {
34223
34728
  startLifecycleStateWatchdog();
34224
34729
  if (runIndicatorTimer) return;
@@ -34258,8 +34763,8 @@ function stopLifecycleStateWatchdog() {
34258
34763
 
34259
34764
  function createRunIndicatorBubble() {
34260
34765
  runIndicatorBubble = make("article", "message runIndicator run-indicator-message streaming");
34261
- // Stable transcript-owned activity root: streaming activity updates rewrite
34262
- // only this bubble's own text nodes, never composer or chrome surfaces.
34766
+ // Stable status-host activity root: streaming activity updates rewrite only
34767
+ // this bubble's own text nodes, never transcript, composer, or chrome surfaces.
34263
34768
  runIndicatorBubble.dataset.streamOwned = "run-indicator";
34264
34769
  runIndicatorBubble.setAttribute("aria-live", "polite");
34265
34770
  runIndicatorBubble.setAttribute("aria-label", "Agent is running:");
@@ -34277,7 +34782,7 @@ function createRunIndicatorBubble() {
34277
34782
 
34278
34783
  function ensureRunIndicatorBubble() {
34279
34784
  if (!runIndicatorBubble || !runIndicatorText || !runIndicatorMeta) createRunIndicatorBubble();
34280
- if (elements.chat.lastElementChild !== runIndicatorBubble) elements.chat.append(runIndicatorBubble);
34785
+ if (runIndicatorBubble.parentElement !== elements.runIndicatorHost) elements.runIndicatorHost.replaceChildren(runIndicatorBubble);
34281
34786
  }
34282
34787
 
34283
34788
  function updateRunIndicatorBubble() {
@@ -34301,7 +34806,7 @@ function removeRunIndicatorBubble() {
34301
34806
 
34302
34807
  function renderRunIndicator({ scroll = false } = {}) {
34303
34808
  if (!runIndicatorIsActive()) {
34304
- if (runIndicatorRemovalDeferred && runIndicatorBubble?.parentElement === elements.chat) return;
34809
+ if (runIndicatorRemovalDeferred && runIndicatorBubble?.parentElement === elements.runIndicatorHost) return;
34305
34810
  removeRunIndicatorBubble();
34306
34811
  return;
34307
34812
  }
@@ -34327,7 +34832,7 @@ function scheduleRunIndicatorRender({ scroll = false } = {}) {
34327
34832
  function setRunIndicatorActivity(activity, { active = true, scroll = true } = {}) {
34328
34833
  const wasLocallyActive = runIndicatorLocallyActive;
34329
34834
  const previousActivity = runIndicatorActivity;
34330
- const hadRunIndicatorBubble = runIndicatorBubble?.parentElement === elements.chat;
34835
+ const hadRunIndicatorBubble = runIndicatorBubble?.parentElement === elements.runIndicatorHost;
34331
34836
  if (active) {
34332
34837
  runIndicatorLocallyActive = true;
34333
34838
  runIndicatorRemovalDeferred = false;
@@ -34337,7 +34842,7 @@ function setRunIndicatorActivity(activity, { active = true, scroll = true } = {}
34337
34842
  const needsRender = scroll || !hadRunIndicatorBubble || wasLocallyActive !== runIndicatorLocallyActive || previousActivity !== runIndicatorActivity;
34338
34843
  if (needsRender) scheduleRunIndicatorRender({ scroll });
34339
34844
  else if (runIndicatorIsActive()) startRunIndicatorTicker();
34340
- // Activity wording is transcript-owned. Composer/Stop chrome is reconciled
34845
+ // Activity wording is status-host-owned. Composer/Stop chrome is reconciled
34341
34846
  // only when the lifecycle enum itself changes, so wording updates can never
34342
34847
  // reparent Steer/Follow-up controls or rewrite the run-active body class.
34343
34848
  syncLifecycleComposerState();
@@ -34368,7 +34873,7 @@ function clearRunIndicatorActivity({ render = true, deferRemoval = false } = {})
34368
34873
  runIndicatorLocallyActive = false;
34369
34874
  runIndicatorStartedAt = null;
34370
34875
  runIndicatorActivity = "Waiting for output or action…";
34371
- runIndicatorRemovalDeferred = deferRemoval && runIndicatorBubble?.parentElement === elements.chat;
34876
+ runIndicatorRemovalDeferred = deferRemoval && runIndicatorBubble?.parentElement === elements.runIndicatorHost;
34372
34877
  if (runIndicatorRemovalDeferred) stopRunIndicatorTicker();
34373
34878
  else if (render) renderRunIndicator();
34374
34879
  stopLifecycleStateWatchdog();
@@ -34903,7 +35408,7 @@ function restoreChatTextSelection(snapshot) {
34903
35408
  function removeChatBubblesAfterPrefix(keptKeys) {
34904
35409
  const liveBubbles = standaloneLiveTranscriptBubbles();
34905
35410
  for (const child of [...elements.chat.children]) {
34906
- if (child === elements.stickyUserPromptButton || child === runIndicatorBubble || liveBubbles.has(child)) continue;
35411
+ if (child === elements.stickyUserPromptButton || liveBubbles.has(child)) continue;
34907
35412
  const key = child.dataset?.itemKey || child.dataset?.transcriptMessageKey;
34908
35413
  if (key && keptKeys.has(key)) continue;
34909
35414
  child.remove();
@@ -34943,7 +35448,7 @@ function renderAllMessages({ preserveScroll = false, forceRebuild = false } = {}
34943
35448
  const affectedSurfaces = prefixLength === 0 && adoptedKeys.size === 0
34944
35449
  ? [elements.chat]
34945
35450
  : [...elements.chat.children].filter((child) => {
34946
- if (child === elements.stickyUserPromptButton || child === runIndicatorBubble || liveBubbles.has(child)) return false;
35451
+ if (child === elements.stickyUserPromptButton || liveBubbles.has(child)) return false;
34947
35452
  const key = child.dataset?.itemKey || child.dataset?.transcriptMessageKey;
34948
35453
  return !prefixKeys.has(key) && !adoptedKeys.has(key);
34949
35454
  });
@@ -36031,6 +36536,11 @@ function optionalFeatureMigrationCompletionKey(snapshot = optionalFeatureMigrati
36031
36536
  return completedAt ? `${snapshot.revision || "pending"}:${completedAt}` : "";
36032
36537
  }
36033
36538
 
36539
+ function optionalFeatureMigrationNoticeDismissKey(snapshot = optionalFeatureMigrationSnapshot) {
36540
+ if (snapshot.phase !== "degraded") return "";
36541
+ return JSON.stringify([snapshot.revision || "pending", snapshot.diagnostic?.message || ""]);
36542
+ }
36543
+
36034
36544
  function storedDismissedOptionalFeatureMigrationKey() {
36035
36545
  try {
36036
36546
  return localStorage.getItem(OPTIONAL_FEATURE_MIGRATION_DISMISS_STORAGE_KEY) || "";
@@ -36060,6 +36570,14 @@ function dismissOptionalFeatureMigrationCompletion() {
36060
36570
  renderOptionalFeatureMigrationSurface();
36061
36571
  }
36062
36572
 
36573
+ function dismissOptionalFeatureMigrationNotice() {
36574
+ const key = optionalFeatureMigrationNoticeDismissKey();
36575
+ if (!key) return;
36576
+ optionalFeatureMigrationDismissedNoticeKey = key;
36577
+ clearOptionalFeatureReadyDismissTimer();
36578
+ renderOptionalFeatureMigrationSurface();
36579
+ }
36580
+
36063
36581
  function scheduleOptionalFeatureReadyDismiss(key) {
36064
36582
  if (!key) {
36065
36583
  clearOptionalFeatureReadyDismissTimer();
@@ -36135,6 +36653,7 @@ function renderOptionalFeatureMigrationSurface() {
36135
36653
  const conflicts = (snapshot.features || []).filter((feature) => feature.state === "conflict");
36136
36654
  const progress = snapshot.progress;
36137
36655
  const readyDismissKey = optionalFeatureReadyDismissKey(snapshot);
36656
+ const noticeDismissKey = optionalFeatureMigrationNoticeDismissKey(snapshot);
36138
36657
  const readyCanAutoDismiss = Boolean(readyDismissKey && !optionalFeatureRestartNotice);
36139
36658
  if (optionalFeatureMigrationCompletionIsDismissed(snapshot)) {
36140
36659
  clearOptionalFeatureReadyDismissTimer();
@@ -36150,6 +36669,12 @@ function renderOptionalFeatureMigrationSurface() {
36150
36669
  ensureOptionalFeatureMigrationRenderTimer();
36151
36670
  return;
36152
36671
  }
36672
+ if (noticeDismissKey && optionalFeatureMigrationDismissedNoticeKey === noticeDismissKey) {
36673
+ surface.replaceChildren();
36674
+ surface.hidden = true;
36675
+ ensureOptionalFeatureMigrationRenderTimer();
36676
+ return;
36677
+ }
36153
36678
  const card = make("div", `optional-feature-migration-card phase-${snapshot.phase}`);
36154
36679
  const copy = make("div", "optional-feature-migration-copy");
36155
36680
  const title = make("strong", "optional-feature-migration-title");
@@ -36198,6 +36723,12 @@ function renderOptionalFeatureMigrationSurface() {
36198
36723
  copy.append(title, detail);
36199
36724
  card.append(copy);
36200
36725
  if (actions.childElementCount) card.append(actions);
36726
+ if (noticeDismissKey) {
36727
+ const dismissButton = optionalFeatureMigrationAction("×", dismissOptionalFeatureMigrationNotice, "optional-feature-migration-dismiss");
36728
+ dismissButton.setAttribute("aria-label", "Close optional feature startup notice");
36729
+ dismissButton.title = "Close";
36730
+ card.append(dismissButton);
36731
+ }
36201
36732
 
36202
36733
  if (conflicts.length) {
36203
36734
  const alert = make("div", "optional-feature-migration-alert sr-only", "Optional feature conflict detected; duplicate top-level resources were safely excluded.");
@@ -40610,7 +41141,7 @@ function renderNetworkStatus() {
40610
41141
  if (elements.showRemoteQrButton) {
40611
41142
  elements.showRemoteQrButton.hidden = !open;
40612
41143
  elements.showRemoteQrButton.disabled = rebinding || !open;
40613
- elements.showRemoteQrButton.textContent = "Show QR code";
41144
+ elements.showRemoteQrButton.textContent = "Open QR-Code";
40614
41145
  }
40615
41146
  }
40616
41147
 
@@ -42343,10 +42874,13 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
42343
42874
  response = await api("/api/prompt", { method: "POST", body, tabId: targetTabId });
42344
42875
  }
42345
42876
  applyResponseTab(response);
42877
+ // A successful RPC response ends prompt-routing ownership even when an
42878
+ // extension command handled the input without starting an agent turn.
42879
+ // Canonical streaming state keeps real agent runs active after this handoff.
42880
+ if (startsRun) promptRoutingTabs.delete(targetTabId);
42346
42881
  if (response?.command === "native_slash_command" && /^\/new(?:\s|$)/.test(message)) forgetLastUserPrompt(targetTabId);
42347
42882
  const targetStillActive = isCurrentTabContext(tabContext);
42348
42883
  if (startsRun && response?.command === "native_slash_command") {
42349
- promptRoutingTabs.delete(targetTabId);
42350
42884
  discardOptimisticUserPrompt(optimisticPromptId);
42351
42885
  markTabIdleLocally(targetTabId);
42352
42886
  if (targetStillActive) clearRunIndicatorActivity();
@@ -43522,7 +44056,7 @@ elements.followUpQueueTrigger?.addEventListener("click", () => {
43522
44056
  });
43523
44057
  elements.followUpQueueCloseButton?.addEventListener("click", () => setFollowUpQueueOpen(false, { restoreFocus: true }));
43524
44058
  elements.composerActionsButton.addEventListener("click", () => {
43525
- setComposerActionsOpen(!document.body.classList.contains("composer-actions-open"));
44059
+ setComposerActionsOpen(!document.body.classList.contains("composer-actions-open"), { restoreFocus: true });
43526
44060
  });
43527
44061
  elements.busyPromptBehaviorTag?.addEventListener("click", (event) => {
43528
44062
  event.preventDefault();
@@ -43531,7 +44065,7 @@ elements.busyPromptBehaviorTag?.addEventListener("click", (event) => {
43531
44065
  setNativeCommandMenuOpen(false);
43532
44066
  setAppRunnerMenuOpen(false);
43533
44067
  setOptionsMenuOpen(false);
43534
- setComposerActionsOpen(false);
44068
+ if (!document.body.classList.contains("mobile-composer-disclosure")) setComposerActionsOpen(false);
43535
44069
  setBusyPromptBehaviorMenuOpen(nextOpen);
43536
44070
  });
43537
44071
  elements.busyPromptBehaviorTag?.addEventListener("keydown", (event) => {
@@ -43578,7 +44112,7 @@ elements.steerButton.addEventListener("click", () => sendPromptFromModeButton("s
43578
44112
  elements.followUpButton.addEventListener("click", () => sendPromptFromModeButton("follow-up", elements.followUpButton));
43579
44113
  elements.btwButton?.addEventListener("click", () => sendBtwPromptFromButton());
43580
44114
  elements.terminalTabsToggleButton.addEventListener("click", () => {
43581
- setMobileTabsExpanded(!document.body.classList.contains("mobile-tabs-expanded"));
44115
+ setMobileTabsExpanded(!document.body.classList.contains("mobile-tabs-expanded"), { restoreFocus: true });
43582
44116
  });
43583
44117
  elements.newTabButton.addEventListener("click", (event) => {
43584
44118
  event.stopPropagation();
@@ -43906,6 +44440,14 @@ elements.undoToastButton?.addEventListener("click", () => runOfferedUndo());
43906
44440
  elements.undoToastDismissButton?.addEventListener("click", dismissUndoToast);
43907
44441
  elements.confirmationCancelButton?.addEventListener("click", () => finishApplicationConfirmation(false));
43908
44442
  elements.confirmationConfirmButton?.addEventListener("click", () => finishApplicationConfirmation(true));
44443
+ elements.gitPullErrorMergeButton?.addEventListener("click", () => integrateGitPullDivergence("merge"));
44444
+ elements.gitPullErrorRebaseButton?.addEventListener("click", () => integrateGitPullDivergence("rebase"));
44445
+ elements.gitPullErrorReviewButton?.addEventListener("click", reviewGitPullDivergence);
44446
+ elements.gitPullErrorCopyButton?.addEventListener("click", () => copyGitPullErrorOutput());
44447
+ elements.gitPullErrorCloseButton?.addEventListener("click", closeGitPullErrorDialog);
44448
+ elements.gitPullErrorDialog?.addEventListener("cancel", (event) => {
44449
+ if (gitPullErrorContext.busy) event.preventDefault();
44450
+ });
43909
44451
  elements.confirmationDialog?.addEventListener("cancel", (event) => {
43910
44452
  event.preventDefault();
43911
44453
  finishApplicationConfirmation(false);
@@ -44129,6 +44671,9 @@ async function abortActiveRun({ source = "button" } = {}) {
44129
44671
  }
44130
44672
  if (hadActiveRun) setRunIndicatorActivity(`Abort requested${source === "escape" ? " from Esc" : source === "long-press" ? " from long-press" : ""}; checking whether Pi stopped…`);
44131
44673
  await api("/api/abort", { method: "POST", body: {}, tabId: tabContext.tabId });
44674
+ // Abort also terminates an in-flight local routing handoff. Without this,
44675
+ // canonical idle state cannot clear a stale extension-command indicator.
44676
+ promptRoutingTabs.delete(tabContext.tabId);
44132
44677
  if (!isCurrentTabContext(tabContext)) return;
44133
44678
  addAbortTranscriptNotice({ activeRun: hadActiveRun });
44134
44679
  scheduleAbortStateChecks(tabContext);
@@ -44495,6 +45040,10 @@ elements.webuiPackageNpmButton?.addEventListener("click", () => {
44495
45040
  });
44496
45041
  elements.webuiPackageCloseButton?.addEventListener("click", () => elements.webuiPackageDialog?.close());
44497
45042
  elements.piReleaseNotesCloseButton?.addEventListener("click", () => elements.piReleaseNotesDialog?.close());
45043
+ elements.sidePanelEditButton?.addEventListener("click", () => {
45044
+ if (!isMobileView()) return;
45045
+ setSidePanelSectionEditMode(!sidePanelSectionEditMode);
45046
+ });
44498
45047
  elements.toggleSidePanelButton.addEventListener("click", () => {
44499
45048
  setSidePanelCollapsed(true);
44500
45049
  });
@@ -44555,9 +45104,9 @@ document.addEventListener("pointerdown", (event) => {
44555
45104
  if (busyPromptBehaviorMenuOpen && !event.target?.closest?.(".composer-context-tags, .composer-busy-mode-menu")) {
44556
45105
  setBusyPromptBehaviorMenuOpen(false);
44557
45106
  }
44558
- if (document.body.classList.contains("mobile-tabs-expanded") && !elements.tabBar.contains(event.target) && !elements.terminalTabsToggleButton.contains(event.target)) {
45107
+ if (document.body.classList.contains("mobile-tabs-expanded") && !elements.terminalTabsDrawerContent?.contains(event.target) && !elements.terminalTabsToggleButton.contains(event.target)) {
44559
45108
  setNewTabMenuOpen(false);
44560
- setMobileTabsExpanded(false);
45109
+ setMobileTabsExpanded(false, { restoreFocus: true });
44561
45110
  }
44562
45111
  if (isFooterPickerOpen() && !elements.statusBar.contains(event.target)) {
44563
45112
  setFooterModelPickerOpen(false);
@@ -44864,12 +45413,12 @@ window.addEventListener("keydown", (event) => {
44864
45413
  return;
44865
45414
  }
44866
45415
  if (document.body.classList.contains("composer-actions-open")) {
44867
- setComposerActionsOpen(false);
45416
+ setComposerActionsOpen(false, { restoreFocus: true });
44868
45417
  return;
44869
45418
  }
44870
45419
  if (document.body.classList.contains("mobile-tabs-expanded")) {
44871
45420
  setNewTabMenuOpen(false);
44872
- setMobileTabsExpanded(false);
45421
+ setMobileTabsExpanded(false, { restoreFocus: true });
44873
45422
  return;
44874
45423
  }
44875
45424
  if (isFooterPickerOpen()) {
@@ -45255,6 +45804,7 @@ restoreFileViewerWidthPreference();
45255
45804
  focusPromptInput({ defer: true });
45256
45805
  restoreStoredSkillUsage();
45257
45806
  restoreBusyPromptBehaviorSetting();
45807
+ syncMobileComposerDisclosureLayout();
45258
45808
  updateComposerModeButtons();
45259
45809
  installSessionSkillTagResizeHandling();
45260
45810
  updateOptionalFeatureAvailability();
@@ -45286,6 +45836,7 @@ initializeComposerActionOrdering();
45286
45836
  restoreSidePanelSectionOrder();
45287
45837
  restoreSidePanelSectionVisibility();
45288
45838
  restoreSidePanelSectionState();
45839
+ setSidePanelSectionEditMode(false);
45289
45840
  bindSidePanelSectionToggles();
45290
45841
  restoreSidePanelState();
45291
45842
  initializeCodexUsage();