@firstpick/pi-package-webui 0.9.7 → 0.9.8

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 (55) hide show
  1. package/README.md +7 -3
  2. package/bin/pi-webui.mjs +114 -25
  3. package/index.ts +2 -1
  4. package/lib/optional-feature-catalog.mjs +1 -1
  5. package/package.json +1 -1
  6. package/public/app.js +629 -98
  7. package/public/guided-git-command-state.mjs +175 -1
  8. package/public/index.html +12 -9
  9. package/public/service-worker.js +1 -1
  10. package/public/styles.css +133 -31
  11. package/public/transcript-renderer.mjs +62 -0
  12. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  13. package/tests/browser/footer-model-advanced-layout.spec.mjs +512 -0
  14. package/tests/browser/guided-git-extension-command.spec.mjs +180 -0
  15. package/tests/browser/guided-git-fallback.spec.mjs +68 -3
  16. package/tests/browser/interaction-continuity.spec.mjs +33 -0
  17. package/tests/codex-fast-mode-static.test.mjs +2 -2
  18. package/tests/compaction-static.test.mjs +1 -1
  19. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  20. package/tests/control-visibility-static.test.mjs +3 -3
  21. package/tests/controls-layout-static.test.mjs +3 -3
  22. package/tests/events-tree-context-menu-static.test.mjs +3 -3
  23. package/tests/fast-mode-client-static.test.mjs +1 -1
  24. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  25. package/tests/file-viewer-image-static.test.mjs +3 -3
  26. package/tests/fixtures/fake-pi.mjs +34 -3
  27. package/tests/git-footer-context-menu-static.test.mjs +103 -1
  28. package/tests/guided-git-activation-http.test.mjs +194 -0
  29. package/tests/guided-git-activation-static.test.mjs +80 -0
  30. package/tests/guided-git-activation.test.mjs +244 -0
  31. package/tests/guided-git-fallback-runtime.test.mjs +1 -0
  32. package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
  33. package/tests/guided-git-message-reliability-static.test.mjs +2 -1
  34. package/tests/guided-git-optional-feature.test.mjs +31 -0
  35. package/tests/http-endpoints-harness.test.mjs +3 -0
  36. package/tests/interaction-state-stability-static.test.mjs +1 -1
  37. package/tests/intercom-conversation-viewer-static.test.mjs +3 -3
  38. package/tests/main-output-loading-static.test.mjs +11 -9
  39. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  40. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  41. package/tests/mobile-foundation-static.test.mjs +3 -3
  42. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  43. package/tests/mobile-static.test.mjs +85 -4
  44. package/tests/open-issue-wizard-static.test.mjs +1 -1
  45. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  46. package/tests/prompt-input-vertical-scroll-static.test.mjs +6 -6
  47. package/tests/prompt-routing-input-clear-static.test.mjs +1 -1
  48. package/tests/questionnaire-dialog.test.mjs +3 -3
  49. package/tests/session-sampling-ui-static.test.mjs +3 -3
  50. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  51. package/tests/subagent-observability-static.test.mjs +2 -2
  52. package/tests/syntax-highlighting-static.test.mjs +3 -3
  53. package/tests/tab-close-continuity-static.test.mjs +2 -0
  54. package/tests/theme-customizer-static.test.mjs +1 -1
  55. package/tests/thinking-block-grouping.test.mjs +79 -0
package/public/app.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { aurReviewSafePath as parsedAurReviewSafePath, parseAurReviewPayload as parseValidatedAurReviewPayload } from "./aur-review-payload.mjs";
2
- import { guidedGitReviewAvailableForTabCatalog, resolveCommandForTabCatalog, resolveRpcSlashCommandForTabCatalog } from "./guided-git-command-state.mjs";
2
+ import { GUIDED_GIT_START_STATUS_KEY, createGuidedGitActivationController, createGuidedGitLaunchPermitController, guidedGitLaunchBlockedReason, guidedGitLaunchModeForTabCatalog, guidedGitReviewAvailableForTabCatalog, guidedGitWorkflowCommandForTabCatalog, resolveCommandForTabCatalog, resolveRpcSlashCommandForTabCatalog } from "./guided-git-command-state.mjs";
3
3
  import { guidedGitReviewCanRequestStagedContent, guidedGitReviewHasApprovedBinding, guidedGitReviewProcessNavigationAllowed, guidedGitReviewProcessSelectionPatch, guidedGitReviewTransition, guidedGitReviewWidgetRemovalTransition } from "./guided-git-review-state.mjs";
4
4
  import { createFastOutputLiveState, createSustainedFlushScheduler, fastOutputLiveTextAndThinking, reduceFastOutputLiveEvent, seedFastOutputLiveState, shouldConsumeFastOutputLiveEvent } from "./fast-output-live.mjs";
5
5
  import { addLaunchSlot, cloneLaunchSlotRoles, launchSlotRolesEqual, removeLaunchSlot, subagentLaunchSlotSaveState, updateLaunchSlot } from "./subagent-launch-slot-state.mjs";
@@ -8,7 +8,7 @@ import { groupConsecutiveWorkflowStatusItems, isCompletedWorkflowStatusExecution
8
8
  import { buildIssuePayload, createIssueWizardCatalog, createIssueWizardState, getCompatibleTemplates, isIssueWizardStepValid, issueClipboardText, reduceIssueWizardState } from "./issue-wizard-state.mjs";
9
9
  import { createIssueBotClient, readIssueBotRuntimeConfig } from "./issue-bot-client.mjs";
10
10
  import { MOBILE_SHELL_STORAGE_KEY, TABLET_SHELL_STORAGE_KEY, createMobileShellState, isMobileShellV2Enabled, mobileNavigationTargetFromSearch, normalizeMobileNavigationTarget, reduceMobileShellState, resolveMobileShellFeatureMode, resolveTabletShellFeatureMode } from "./mobile-shell-state.mjs";
11
- import { createTranscriptRenderer } from "./transcript-renderer.mjs";
11
+ import { createTranscriptRenderer, groupConsecutiveThinkingItems, groupConsecutiveThinkingMessages } from "./transcript-renderer.mjs";
12
12
  import { createStreamDerivedOutputState } from "./stream-derived-output.mjs";
13
13
  import { advanceStreamingMarkdownTail } from "./stream-markdown-tail.mjs";
14
14
  import { createLatestWinsRenderScheduler } from "./stream-render-scheduler.mjs";
@@ -1086,6 +1086,7 @@ let gitChangesRequestSerial = 0;
1086
1086
  const gitChangesUntrackedContentRequests = new Set();
1087
1087
  let nativeCommandTabId = null;
1088
1088
  let nativeSettingsDirty = false;
1089
+ let guidedGitSetupDialogOwner = null;
1089
1090
  let sessionSummaryOverlayTabId = null;
1090
1091
  let sessionSummaryOverlayFocusReturn = null;
1091
1092
  let sessionSummaryOverlayFocusReturnKey = "";
@@ -1278,6 +1279,7 @@ let customBackgroundLoading = false;
1278
1279
  let footerScopedModels = [];
1279
1280
  let footerScopedModelPatterns = [];
1280
1281
  let footerScopedModelSource = "none";
1282
+ let footerScopedModelLayout = "flat";
1281
1283
  const contextUsageUnknownAfterCompactionByTab = new Map();
1282
1284
  let autoFollowChat = true;
1283
1285
  let chatFollowFrame = null;
@@ -1291,6 +1293,7 @@ let chatPausedScrollRestoreUntil = 0;
1291
1293
  let chatLastTouchClientY = null;
1292
1294
  let mobileFooterExpanded = false;
1293
1295
  let footerModelPickerOpen = false;
1296
+ let footerModelApplyInFlight = false;
1294
1297
  let footerThinkingPickerOpen = false;
1295
1298
  let footerAutoCompactionToggleInFlight = false;
1296
1299
  let footerBranchPickerOpen = false;
@@ -1369,6 +1372,8 @@ const SUBAGENT_AUTO_CLEAR_STORAGE_KEY = "pi-webui-subagent-auto-clear";
1369
1372
  const TERMINAL_CUSTOM_GROUPS_STORAGE_KEY = "pi-webui-terminal-custom-groups-v1";
1370
1373
  const TERMINAL_TAB_DRAG_MIME = "application/x-pi-terminal-tab-id";
1371
1374
  const FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY = "pi-webui-footer-scoped-model-order-v1";
1375
+ const FOOTER_SCOPED_MODEL_LAYOUT_STORAGE_KEY = "pi-webui-footer-scoped-model-layout-v1";
1376
+ footerScopedModelLayout = readStoredFooterScopedModelLayout();
1372
1377
  const FOOTER_SCOPED_MODEL_POINTER_DRAG_THRESHOLD_PX = 6;
1373
1378
  const TOOL_OUTPUT_EXPANDED_STORAGE_KEY = "pi-webui-tool-output-expanded";
1374
1379
  const THEME_STORAGE_KEY = "pi-webui-theme";
@@ -2819,9 +2824,9 @@ const OPTIONAL_FEATURES = [
2819
2824
  {
2820
2825
  id: "gitWorkflow",
2821
2826
  label: "Guided Git workflow",
2822
- packageName: "@firstpick/pi-prompts-git-pr",
2823
- capabilityLabel: "/git-staged-msg",
2824
- description: "Generate staged commit messages for the guided Git workflow.",
2827
+ packageName: "@firstpick/pi-extension-git-guided-workflow",
2828
+ capabilityLabel: "/git-guided-workflow",
2829
+ description: "Cross-surface launcher with bundled commit, branch, and pull-request prompt templates.",
2825
2830
  setup: "git-workflow",
2826
2831
  },
2827
2832
  {
@@ -3370,6 +3375,7 @@ const OPTIONAL_COMMAND_FEATURES = new Map([
3370
3375
  ["btw", "btwCommand"],
3371
3376
  ["btw-transfer", "btwCommand"],
3372
3377
  ["btw-status", "btwCommand"],
3378
+ ["git-guided-workflow", "gitWorkflow"],
3373
3379
  ["git-staged-msg", "gitWorkflow"],
3374
3380
  ["git-branch-name", "gitWorkflow"],
3375
3381
  ["pr", "gitWorkflow"],
@@ -3560,6 +3566,10 @@ function createGitWorkflowState() {
3560
3566
 
3561
3567
  const gitWorkflowsByTab = new Map();
3562
3568
  const gitWorkflowMessageLoadsByTab = new Map();
3569
+ const guidedGitLaunchPermits = createGuidedGitLaunchPermitController();
3570
+ const guidedGitActivationController = createGuidedGitActivationController({
3571
+ claimStart: (tabId, _payload, request, now) => guidedGitLaunchPermits.consume(tabId, request?.guidedGitLaunchId, now),
3572
+ });
3563
3573
  let gitWorkflow = createGitWorkflowState();
3564
3574
  let gitWorkflowPreferences = null;
3565
3575
 
@@ -3584,6 +3594,8 @@ function gitWorkflowActionTabId() {
3584
3594
 
3585
3595
  function resetGitWorkflowForTab(tabId = activeTabId) {
3586
3596
  if (!tabId) return;
3597
+ guidedGitLaunchPermits.clearTab(tabId);
3598
+ guidedGitActivationController.clearTab(tabId);
3587
3599
  gitWorkflowsByTab.set(tabId, createGitWorkflowState());
3588
3600
  if (tabId === activeTabId) {
3589
3601
  bindGitWorkflowToActiveTab();
@@ -3593,6 +3605,8 @@ function resetGitWorkflowForTab(tabId = activeTabId) {
3593
3605
 
3594
3606
  function clearGitWorkflowForTab(tabId) {
3595
3607
  if (!tabId) return;
3608
+ guidedGitLaunchPermits.clearTab(tabId);
3609
+ guidedGitActivationController.clearTab(tabId);
3596
3610
  gitWorkflowsByTab.delete(tabId);
3597
3611
  if (tabId === activeTabId) {
3598
3612
  bindGitWorkflowToActiveTab();
@@ -7449,10 +7463,13 @@ function isAbortAvailable() {
7449
7463
  function resizePromptInput() {
7450
7464
  const input = elements.promptInput;
7451
7465
  input.style.height = "auto";
7452
- const maxHeight = Number.parseFloat(getComputedStyle(input).maxHeight);
7453
- const nextHeight = Number.isFinite(maxHeight) ? Math.min(input.scrollHeight, maxHeight) : input.scrollHeight;
7454
- input.style.height = `${Math.ceil(nextHeight)}px`;
7455
- input.style.overflowY = "auto";
7466
+ const style = getComputedStyle(input);
7467
+ const maxHeight = Number.parseFloat(style.maxHeight);
7468
+ const borderBlock = Number.parseFloat(style.borderTopWidth) + Number.parseFloat(style.borderBottomWidth);
7469
+ const naturalHeight = input.scrollHeight + borderBlock;
7470
+ const isCapped = Number.isFinite(maxHeight) && naturalHeight > Math.ceil(maxHeight);
7471
+ input.style.height = `${Math.ceil(isCapped ? maxHeight : naturalHeight)}px`;
7472
+ input.style.overflowY = isCapped ? "auto" : "hidden";
7456
7473
  }
7457
7474
 
7458
7475
  function updateComposerModeButtons() {
@@ -17813,7 +17830,7 @@ async function closeTerminalTabs(tabIds, { label = "selected terminal tabs", all
17813
17830
  } else {
17814
17831
  renderTabs();
17815
17832
  }
17816
- addEvent(`closed ${closedIds.length || targetTabs.length} terminal ${closedIds.length === 1 ? "tab" : "tabs"}`, "warn");
17833
+ addEvent(`closed ${closedIds.length || targetTabs.length} terminal ${closedIds.length === 1 ? "tab" : "tabs"}`, "info");
17817
17834
  } catch (error) {
17818
17835
  addEvent(error.message, "error");
17819
17836
  } finally {
@@ -18091,11 +18108,26 @@ function setEventDisplayMode(value, { persist = true } = {}) {
18091
18108
  }
18092
18109
  }
18093
18110
 
18094
- function addEvent(message, level = "info", { toolCallId = "", toolEventPhase = "", details = [], notify = true, occurredAt = Date.now() } = {}) {
18111
+ function addEvent(message, level = "info", { toolCallId = "", toolEventPhase = "", details = [], notify = true, occurredAt = Date.now(), aggregateKey = "", aggregateIncrement = 1, aggregateSingular = "", aggregatePlural = "" } = {}) {
18112
+ const stableAggregateKey = String(aggregateKey || "").trim();
18113
+ const priorAggregate = stableAggregateKey
18114
+ ? [...(elements.eventLog?.children || [])].find((candidate) => candidate.dataset.eventAggregateKey === stableAggregateKey)
18115
+ : null;
18116
+ const aggregateCount = stableAggregateKey
18117
+ ? Math.max(0, Number.parseInt(priorAggregate?.dataset.eventAggregateCount || "0", 10) || 0) + Math.max(1, Math.trunc(Number(aggregateIncrement) || 1))
18118
+ : 0;
18119
+ const eventMessage = stableAggregateKey && aggregateSingular
18120
+ ? `${message} ${aggregateCount} ${aggregateCount === 1 ? aggregateSingular : aggregatePlural || aggregateSingular}`
18121
+ : String(message || "");
18122
+ priorAggregate?.remove();
18095
18123
  const line = make("button", `event ${level}`.trim());
18096
18124
  line.type = "button";
18097
18125
  line.dataset.eventLevel = String(level || "info").trim().toLowerCase() || "info";
18098
18126
  line.dataset.chatEventTimestamp = String(occurredAt);
18127
+ if (stableAggregateKey) {
18128
+ line.dataset.eventAggregateKey = stableAggregateKey;
18129
+ line.dataset.eventAggregateCount = String(aggregateCount);
18130
+ }
18099
18131
  const stableToolCallId = String(toolCallId || "").trim();
18100
18132
  const toolLifecycle = ["start", "finish"].includes(toolEventPhase);
18101
18133
  const treeEligible = stableToolCallId && toolLifecycle;
@@ -18104,7 +18136,7 @@ function addEvent(message, level = "info", { toolCallId = "", toolEventPhase = "
18104
18136
  if (toolLifecycle) line.dataset.eventToolPhase = toolEventPhase;
18105
18137
  line.setAttribute("aria-keyshortcuts", "ContextMenu Shift+F10");
18106
18138
  const time = make("span", "event-time", `[${new Date(occurredAt).toLocaleTimeString()}]`);
18107
- const summary = make("span", "event-summary", String(message || ""));
18139
+ const summary = make("span", "event-summary", eventMessage);
18108
18140
  const main = make("span", "event-main");
18109
18141
  main.append(time, summary);
18110
18142
  line.append(main);
@@ -18126,7 +18158,7 @@ function addEvent(message, level = "info", { toolCallId = "", toolEventPhase = "
18126
18158
  while (elements.eventLog.children.length > 120) elements.eventLog.lastElementChild?.remove();
18127
18159
  applyEventFilter();
18128
18160
  if (notify && (level === "error" || level === "warn")) {
18129
- showNoticeToast(message, level);
18161
+ showNoticeToast(eventMessage, level);
18130
18162
  noteUnreadEvent();
18131
18163
  }
18132
18164
  }
@@ -19775,6 +19807,14 @@ function closeGitFooterContextMenu({ returnFocus = true } = {}) {
19775
19807
  if (returnFocus && trigger?.isConnected) queueMicrotask(() => trigger.focus?.({ preventScroll: true }));
19776
19808
  }
19777
19809
 
19810
+ function syncGitFooterAdvancedMenuItem(key = gitFooterContextMenuState?.key) {
19811
+ const advancedButton = elements.gitFooterContextMenu?.querySelector('[data-git-footer-menu-action="toggle-advanced"]');
19812
+ if (!advancedButton) return;
19813
+ advancedButton.hidden = key !== "model";
19814
+ advancedButton.textContent = footerScopedModelLayout === "advanced" ? "Toggle Simple" : "Toggle advanced";
19815
+ advancedButton.setAttribute("aria-checked", footerScopedModelLayout === "advanced" ? "true" : "false");
19816
+ }
19817
+
19778
19818
  function showGitFooterContextMenu(event, chip, trigger) {
19779
19819
  const menu = elements.gitFooterContextMenu;
19780
19820
  const key = cleanStatusText(chip?.key);
@@ -19792,6 +19832,7 @@ function showGitFooterContextMenu(event, chip, trigger) {
19792
19832
  gitFooterContextMenuState = { key, label, trigger };
19793
19833
  const disableButton = menu.querySelector('[data-git-footer-menu-action="disable"]');
19794
19834
  if (disableButton) disableButton.textContent = `Disable ${label} box`;
19835
+ syncGitFooterAdvancedMenuItem(key);
19795
19836
  menu.hidden = false;
19796
19837
  const rect = menu.getBoundingClientRect();
19797
19838
  const left = Math.min(event.clientX, Math.max(8, window.innerWidth - rect.width - 8));
@@ -20625,13 +20666,18 @@ function footerBranchPickerRenderKey() {
20625
20666
  return footerBranchPickerOpen ? JSON.stringify(footerBranchPickerState) : "";
20626
20667
  }
20627
20668
 
20669
+ function footerModelPickerRenderKey() {
20670
+ if (!footerModelPickerOpen) return "";
20671
+ return `${footerScopedModelLayout}:${orderedFooterScopedModels().map(footerScopedModelKey).join(",")}`;
20672
+ }
20673
+
20628
20674
  function gitFooterPickerStateKey(payload) {
20629
20675
  const tabContext = activeTabContext();
20630
20676
  const refreshInFlight = tabContext.tabId ? gitFooterPayloadRefreshInFlightByTab.has(tabContext.tabId) : false;
20631
20677
  const syncInFlight = tabContext.tabId ? gitFooterSyncInFlightByTab.has(tabContext.tabId) : false;
20632
20678
  const piCalibrationInFlight = tabContext.tabId ? gitFooterPiCalibrationInFlightByTab.has(tabContext.tabId) : false;
20633
20679
  const refreshAvailable = hasLoadedRpcCommand("git-footer-refresh");
20634
- return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${footerBranchPickerRenderKey()}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${syncInFlight ? 1 : 0}|${piCalibrationInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}|${gitFooterPayloadVisibilityKey(payload)}`;
20680
+ return `${footerModelPickerOpen ? 1 : 0}|${footerModelPickerRenderKey()}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${footerBranchPickerRenderKey()}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${syncInFlight ? 1 : 0}|${piCalibrationInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}|${gitFooterPayloadVisibilityKey(payload)}`;
20635
20681
  }
20636
20682
 
20637
20683
  function updateGitFooterChipNodeValue(node, chip, valueSelector) {
@@ -22924,7 +22970,7 @@ function renderSavedWorkspacePicker() {
22924
22970
  return panel;
22925
22971
  }
22926
22972
 
22927
- function setFooterModelPickerOpen(open) {
22973
+ function setFooterModelPickerOpen(open, { restoreFocus = false } = {}) {
22928
22974
  const wasOpen = footerModelPickerOpen;
22929
22975
  footerModelPickerOpen = !!open;
22930
22976
  if (footerModelPickerOpen) {
@@ -22941,7 +22987,11 @@ function setFooterModelPickerOpen(open) {
22941
22987
  document.body.classList.toggle("footer-model-picker-open", isFooterPickerOpen());
22942
22988
  renderFooter();
22943
22989
  updateFooterModelPickerPosition();
22944
- if (wasOpen && !footerModelPickerOpen) scheduleDeferredUiFlushAfterDropdownClose();
22990
+ if (footerModelPickerOpen && footerScopedModelLayout === "advanced") focusFooterModelPickerInitialOption();
22991
+ if (wasOpen && !footerModelPickerOpen) {
22992
+ scheduleDeferredUiFlushAfterDropdownClose();
22993
+ if (restoreFocus) focusFooterModelTrigger();
22994
+ }
22945
22995
  }
22946
22996
 
22947
22997
  function setFooterThinkingPickerOpen(open) {
@@ -23794,6 +23844,55 @@ function footerScopedModelKey(model) {
23794
23844
  return model?.provider && model?.id ? `${model.provider}/${model.id}` : "";
23795
23845
  }
23796
23846
 
23847
+ function normalizeFooterScopedModelLayout(value) {
23848
+ return value === "advanced" ? "advanced" : "flat";
23849
+ }
23850
+
23851
+ function readStoredFooterScopedModelLayout() {
23852
+ try {
23853
+ return normalizeFooterScopedModelLayout(localStorage.getItem(FOOTER_SCOPED_MODEL_LAYOUT_STORAGE_KEY));
23854
+ } catch {
23855
+ return "flat";
23856
+ }
23857
+ }
23858
+
23859
+ function setFooterScopedModelLayout(value, { persist = true } = {}) {
23860
+ const next = normalizeFooterScopedModelLayout(value);
23861
+ if (persist) {
23862
+ try {
23863
+ localStorage.setItem(FOOTER_SCOPED_MODEL_LAYOUT_STORAGE_KEY, next);
23864
+ } catch {}
23865
+ }
23866
+ const changed = next !== footerScopedModelLayout;
23867
+ footerScopedModelLayout = next;
23868
+ syncGitFooterAdvancedMenuItem();
23869
+ if (!changed || !footerModelPickerOpen) return;
23870
+ renderFooter();
23871
+ updateFooterModelPickerPosition();
23872
+ focusFooterModelPickerInitialOption();
23873
+ }
23874
+
23875
+ function toggleFooterScopedModelLayout() {
23876
+ setFooterScopedModelLayout(footerScopedModelLayout === "advanced" ? "flat" : "advanced");
23877
+ }
23878
+
23879
+ function compareFooterScopedModelProviders(a, b) {
23880
+ const baseOrder = String(a).localeCompare(String(b), undefined, { sensitivity: "base" });
23881
+ return baseOrder || String(a).localeCompare(String(b));
23882
+ }
23883
+
23884
+ function footerScopedModelProviderGroups(models = orderedFooterScopedModels()) {
23885
+ const modelsByProvider = new Map();
23886
+ for (const model of models) {
23887
+ const provider = String(model?.provider || "");
23888
+ if (!modelsByProvider.has(provider)) modelsByProvider.set(provider, []);
23889
+ modelsByProvider.get(provider).push(model);
23890
+ }
23891
+ return [...modelsByProvider.entries()]
23892
+ .sort(([a], [b]) => compareFooterScopedModelProviders(a, b))
23893
+ .map(([provider, providerModels]) => ({ provider, models: providerModels }));
23894
+ }
23895
+
23797
23896
  function readFooterScopedModelOrder() {
23798
23897
  try {
23799
23898
  const parsed = JSON.parse(localStorage.getItem(FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY) || "[]");
@@ -23821,14 +23920,30 @@ function orderedFooterScopedModels() {
23821
23920
  });
23822
23921
  }
23823
23922
 
23923
+ function focusFooterScopedModelOrderButton(modelKey) {
23924
+ if (!modelKey) return;
23925
+ const movedButton = document.querySelector(`[data-footer-model-key="${CSS.escape(modelKey)}"]`);
23926
+ if (!movedButton) return;
23927
+ const advancedPicker = movedButton.closest(".footer-model-picker-advanced");
23928
+ if (advancedPicker) focusAdvancedFooterModelOption(advancedPicker, movedButton);
23929
+ else movedButton.focus();
23930
+ }
23931
+
23932
+ function rebuildOpenFooterModelPicker() {
23933
+ const picker = elements.statusBar.querySelector(".footer-model-picker");
23934
+ if (!footerModelPickerOpen || !picker) {
23935
+ renderFooter();
23936
+ return;
23937
+ }
23938
+ picker.replaceWith(renderFooterModelPicker());
23939
+ updateFooterModelPickerPosition();
23940
+ }
23941
+
23824
23942
  function commitFooterScopedModelOrder(order, { render = true, focusKey = "" } = {}) {
23825
23943
  writeFooterScopedModelOrder(order);
23826
23944
  footerScopedModels = orderedFooterScopedModels();
23827
- if (render) renderFooter();
23828
- if (focusKey) {
23829
- const movedButton = document.querySelector(`[data-footer-model-key="${CSS.escape(focusKey)}"]`);
23830
- if (movedButton) movedButton.focus();
23831
- }
23945
+ if (render) rebuildOpenFooterModelPicker();
23946
+ focusFooterScopedModelOrderButton(focusKey);
23832
23947
  }
23833
23948
 
23834
23949
  function reorderFooterScopedModel(fromKey, toKey, { focus = true } = {}) {
@@ -23854,6 +23969,50 @@ function moveFooterScopedModelByOffset(modelKey, offset) {
23854
23969
  return true;
23855
23970
  }
23856
23971
 
23972
+ function footerScopedModelOrderWithProviderOrder(provider, providerOrder) {
23973
+ const models = orderedFooterScopedModels();
23974
+ const providerKeys = models
23975
+ .filter((model) => String(model?.provider || "") === provider)
23976
+ .map(footerScopedModelKey);
23977
+ const allowedKeys = new Set(providerKeys);
23978
+ const nextProviderKeys = [...new Set(providerOrder.filter((key) => allowedKeys.has(key)))];
23979
+ for (const key of providerKeys) {
23980
+ if (!nextProviderKeys.includes(key)) nextProviderKeys.push(key);
23981
+ }
23982
+ let providerIndex = 0;
23983
+ return models.map((model) => String(model?.provider || "") === provider
23984
+ ? nextProviderKeys[providerIndex++]
23985
+ : footerScopedModelKey(model));
23986
+ }
23987
+
23988
+ function commitFooterScopedModelProviderOrder(provider, providerOrder, { render = true, focusKey = "" } = {}) {
23989
+ if (!provider || !providerOrder.length) return false;
23990
+ const currentOrder = orderedFooterScopedModels().map(footerScopedModelKey);
23991
+ const nextOrder = footerScopedModelOrderWithProviderOrder(provider, providerOrder);
23992
+ if (nextOrder.every((key, index) => key === currentOrder[index])) {
23993
+ focusFooterScopedModelOrderButton(focusKey);
23994
+ return false;
23995
+ }
23996
+ commitFooterScopedModelOrder(nextOrder, { render, focusKey });
23997
+ return true;
23998
+ }
23999
+
24000
+ function moveFooterScopedModelWithinProviderByOffset(modelKey, offset) {
24001
+ const models = orderedFooterScopedModels();
24002
+ const model = models.find((candidate) => footerScopedModelKey(candidate) === modelKey);
24003
+ const provider = String(model?.provider || "");
24004
+ if (!provider) return false;
24005
+ const providerOrder = models
24006
+ .filter((candidate) => String(candidate?.provider || "") === provider)
24007
+ .map(footerScopedModelKey);
24008
+ const fromIndex = providerOrder.indexOf(modelKey);
24009
+ const toIndex = fromIndex + offset;
24010
+ if (fromIndex < 0 || toIndex < 0 || toIndex >= providerOrder.length) return false;
24011
+ const [moved] = providerOrder.splice(fromIndex, 1);
24012
+ providerOrder.splice(toIndex, 0, moved);
24013
+ return commitFooterScopedModelProviderOrder(provider, providerOrder, { focusKey: modelKey });
24014
+ }
24015
+
23857
24016
  function footerScopedModelButtons() {
23858
24017
  return [...document.querySelectorAll(".footer-model-picker .footer-model-option[data-footer-model-key]")];
23859
24018
  }
@@ -23868,9 +24027,16 @@ function clearFooterScopedModelDragMarkers() {
23868
24027
  }
23869
24028
  }
23870
24029
 
23871
- function commitVisibleFooterScopedModelOrder({ render = false, focusKey = "" } = {}) {
23872
- const order = footerScopedModelButtons().map((button) => button.dataset.footerModelKey).filter(Boolean);
24030
+ function commitVisibleFooterScopedModelOrder({ render = false, focusKey = "", provider = "" } = {}) {
24031
+ const order = footerScopedModelButtons()
24032
+ .filter((button) => !provider || button.dataset.footerProvider === provider)
24033
+ .map((button) => button.dataset.footerModelKey)
24034
+ .filter(Boolean);
23873
24035
  if (!order.length) return;
24036
+ if (provider) {
24037
+ commitFooterScopedModelProviderOrder(provider, order, { render, focusKey });
24038
+ return;
24039
+ }
23874
24040
  commitFooterScopedModelOrder(order, { render, focusKey });
23875
24041
  }
23876
24042
 
@@ -23890,7 +24056,7 @@ function moveVisibleFooterScopedModel(fromKey, targetButton, clientY) {
23890
24056
 
23891
24057
  if (insertBefore) parent.insertBefore(sourceButton, targetButton);
23892
24058
  else parent.insertBefore(sourceButton, targetButton.nextSibling);
23893
- commitVisibleFooterScopedModelOrder({ render: false });
24059
+ commitVisibleFooterScopedModelOrder({ render: false, provider: parent.dataset.footerProvider || "" });
23894
24060
  return true;
23895
24061
  }
23896
24062
 
@@ -23935,6 +24101,7 @@ function endFooterScopedModelPointerDrag(event) {
23935
24101
  window.removeEventListener("pointercancel", endFooterScopedModelPointerDrag, { capture: true });
23936
24102
  const wasActive = drag.active;
23937
24103
  const sourceButton = document.querySelector(`[data-footer-model-key="${CSS.escape(drag.modelKey)}"]`);
24104
+ const provider = sourceButton?.dataset.footerProvider || "";
23938
24105
  footerScopedModelPointerDrag = null;
23939
24106
  footerScopedModelDragKey = "";
23940
24107
  footerScopedModelLastDragOverKey = "";
@@ -23943,15 +24110,18 @@ function endFooterScopedModelPointerDrag(event) {
23943
24110
  if (wasActive) {
23944
24111
  footerScopedModelSuppressClickUntil = Date.now() + 250;
23945
24112
  event.preventDefault();
23946
- commitVisibleFooterScopedModelOrder({ render: false, focusKey: drag.modelKey });
24113
+ commitVisibleFooterScopedModelOrder({ render: false, focusKey: drag.modelKey, provider });
23947
24114
  }
23948
24115
  }
23949
24116
 
23950
24117
  async function applyFooterModel(model) {
23951
- if (!model?.provider || !model?.id) return;
24118
+ if (!model?.provider || !model?.id || footerModelApplyInFlight) return;
23952
24119
  const tabContext = activeTabContext();
24120
+ footerModelApplyInFlight = true;
24121
+ footerModelPickerOpen = false;
24122
+ document.body.classList.toggle("footer-model-picker-open", isFooterPickerOpen());
24123
+ renderFooter();
23953
24124
  try {
23954
- footerModelPickerOpen = false;
23955
24125
  const response = await api("/api/model", { method: "POST", body: { provider: model.provider, modelId: model.id }, tabId: tabContext.tabId });
23956
24126
  if (!isCurrentTabContext(tabContext)) return;
23957
24127
  applyOptimisticModelSelection(response.data || model, tabContext);
@@ -23960,6 +24130,7 @@ async function applyFooterModel(model) {
23960
24130
  } catch (error) {
23961
24131
  if (isCurrentTabContext(tabContext)) addEvent(error.message, "error");
23962
24132
  } finally {
24133
+ footerModelApplyInFlight = false;
23963
24134
  if (isCurrentTabContext(tabContext)) {
23964
24135
  document.body.classList.toggle("footer-model-picker-open", isFooterPickerOpen());
23965
24136
  renderFooter();
@@ -23967,12 +24138,159 @@ async function applyFooterModel(model) {
23967
24138
  }
23968
24139
  }
23969
24140
 
24141
+ function focusFooterModelTrigger() {
24142
+ queueMicrotask(() => {
24143
+ const trigger = elements.statusBar.querySelector(".footer-model.footer-meta-action, .footer-tui-model");
24144
+ trigger?.focus({ preventScroll: true });
24145
+ });
24146
+ }
24147
+
24148
+ function footerModelPickerInitialKey() {
24149
+ const models = orderedFooterScopedModels();
24150
+ const currentKey = footerScopedModelKey(currentState?.model);
24151
+ return models.some((model) => footerScopedModelKey(model) === currentKey) ? currentKey : footerScopedModelKey(models[0]);
24152
+ }
24153
+
24154
+ function focusFooterModelPickerInitialOption({ retryAfterPointerRender = true } = {}) {
24155
+ const initialKey = footerModelPickerInitialKey();
24156
+ queueMicrotask(() => {
24157
+ if (!footerModelPickerOpen) return;
24158
+ const picker = elements.statusBar.querySelector(".footer-model-picker");
24159
+ if (!picker) {
24160
+ if (retryAfterPointerRender) setTimeout(() => focusFooterModelPickerInitialOption({ retryAfterPointerRender: false }), 0);
24161
+ return;
24162
+ }
24163
+ const escapedKey = initialKey ? CSS.escape(initialKey) : "";
24164
+ const target = (escapedKey && picker.querySelector(`[data-footer-model-key="${escapedKey}"]`))
24165
+ || picker.querySelector(".footer-model-option[data-footer-model-key]");
24166
+ if (!target) return;
24167
+ if (footerScopedModelLayout === "advanced") {
24168
+ for (const button of picker.querySelectorAll(".footer-model-option[data-footer-model-key]")) button.tabIndex = button === target ? 0 : -1;
24169
+ }
24170
+ target.focus({ preventScroll: true });
24171
+ target.scrollIntoView({ block: "nearest", inline: "nearest" });
24172
+ });
24173
+ }
24174
+
24175
+ function syncAdvancedFooterModelRovingTabStop(picker = elements.statusBar.querySelector(".footer-model-picker-advanced")) {
24176
+ if (!picker) return;
24177
+ const options = [...picker.querySelectorAll(".footer-model-option[data-footer-model-key]")];
24178
+ const focused = picker.contains(document.activeElement) ? document.activeElement.closest?.(".footer-model-option[data-footer-model-key]") : null;
24179
+ const target = focused || options.find((option) => option.tabIndex === 0) || options[0];
24180
+ for (const option of options) option.tabIndex = option === target ? 0 : -1;
24181
+ }
24182
+
24183
+ function focusAdvancedFooterModelOption(picker, button) {
24184
+ if (!picker || !button) return;
24185
+ for (const option of picker.querySelectorAll(".footer-model-option[data-footer-model-key]")) option.tabIndex = option === button ? 0 : -1;
24186
+ button.focus({ preventScroll: true });
24187
+ button.scrollIntoView({ block: "nearest", inline: "nearest" });
24188
+ }
24189
+
24190
+ function advancedFooterModelColumnButtons(picker, providerIndex) {
24191
+ const column = picker.querySelector(`[data-footer-provider-index="${providerIndex}"]`);
24192
+ return column ? [...column.querySelectorAll(".footer-model-option[data-footer-model-key]")] : [];
24193
+ }
24194
+
24195
+ function handleAdvancedFooterModelKeydown(event, model) {
24196
+ const picker = event.currentTarget.closest(".footer-model-picker-advanced");
24197
+ if (!picker) return;
24198
+ const providerIndex = Number(event.currentTarget.dataset.footerProviderIndex);
24199
+ const modelIndex = Number(event.currentTarget.dataset.footerModelIndex);
24200
+ const columns = [...picker.querySelectorAll(".footer-model-provider-column[data-footer-provider-index]")];
24201
+ let target = null;
24202
+
24203
+ if (event.key === "Enter" || event.key === " ") {
24204
+ event.preventDefault();
24205
+ if (!event.repeat) void applyFooterModel(model);
24206
+ return;
24207
+ }
24208
+ if (event.key === "Escape") {
24209
+ event.preventDefault();
24210
+ event.stopPropagation();
24211
+ setFooterModelPickerOpen(false, { restoreFocus: true });
24212
+ return;
24213
+ }
24214
+ if (event.altKey && (event.key === "ArrowUp" || event.key === "ArrowDown")) {
24215
+ event.preventDefault();
24216
+ moveFooterScopedModelWithinProviderByOffset(footerScopedModelKey(model), event.key === "ArrowUp" ? -1 : 1);
24217
+ return;
24218
+ }
24219
+ if (event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Home" || event.key === "End") {
24220
+ const buttons = advancedFooterModelColumnButtons(picker, providerIndex);
24221
+ const lastIndex = Math.max(0, buttons.length - 1);
24222
+ const targetIndex = event.key === "Home"
24223
+ ? 0
24224
+ : event.key === "End"
24225
+ ? lastIndex
24226
+ : Math.min(lastIndex, Math.max(0, modelIndex + (event.key === "ArrowUp" ? -1 : 1)));
24227
+ target = buttons[targetIndex] || event.currentTarget;
24228
+ } else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
24229
+ const lastProviderIndex = Math.max(0, columns.length - 1);
24230
+ const targetProviderIndex = Math.min(lastProviderIndex, Math.max(0, providerIndex + (event.key === "ArrowLeft" ? -1 : 1)));
24231
+ const buttons = advancedFooterModelColumnButtons(picker, targetProviderIndex);
24232
+ target = buttons[Math.min(Math.max(0, modelIndex), Math.max(0, buttons.length - 1))] || event.currentTarget;
24233
+ } else {
24234
+ return;
24235
+ }
24236
+
24237
+ event.preventDefault();
24238
+ focusAdvancedFooterModelOption(picker, target);
24239
+ }
24240
+
24241
+ function renderFooterModelOption(model, { advanced = false, providerIndex = -1, modelIndex = -1, initialKey = "" } = {}) {
24242
+ const current = currentState?.model;
24243
+ const selected = current?.provider === model.provider && current?.id === model.id;
24244
+ const modelKey = footerScopedModelKey(model);
24245
+ const dragging = footerScopedModelDragKey === modelKey;
24246
+ const dragOver = footerScopedModelDragKey && footerScopedModelLastDragOverKey === modelKey;
24247
+ const button = make("button", `footer-model-option${selected ? " active" : ""}${dragging ? " dragging" : ""}${dragOver ? " drag-over" : ""}`);
24248
+ button.type = "button";
24249
+ button.draggable = false;
24250
+ button.dataset.footerModelKey = modelKey;
24251
+ button.setAttribute("role", "option");
24252
+ button.setAttribute("aria-selected", selected ? "true" : "false");
24253
+ button.title = `${model.provider}/${model.id}${model.name ? ` · ${model.name}` : ""}`;
24254
+ button.append(
24255
+ make("span", "footer-model-option-main", advanced ? model.id : `${model.provider}/${model.id}`),
24256
+ make("span", "footer-model-option-name", model.name || ""),
24257
+ );
24258
+ button.addEventListener("click", (event) => {
24259
+ if (Date.now() < footerScopedModelSuppressClickUntil) {
24260
+ event.preventDefault();
24261
+ return;
24262
+ }
24263
+ void applyFooterModel(model);
24264
+ });
24265
+ if (advanced) {
24266
+ button.dataset.footerProvider = model.provider;
24267
+ button.dataset.footerProviderIndex = String(providerIndex);
24268
+ button.dataset.footerModelIndex = String(modelIndex);
24269
+ button.tabIndex = modelKey === initialKey ? 0 : -1;
24270
+ button.addEventListener("keydown", (event) => handleAdvancedFooterModelKeydown(event, model));
24271
+ } else {
24272
+ button.addEventListener("keydown", (event) => {
24273
+ if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown")) return;
24274
+ event.preventDefault();
24275
+ moveFooterScopedModelByOffset(modelKey, event.key === "ArrowUp" ? -1 : 1);
24276
+ });
24277
+ }
24278
+ button.addEventListener("pointerdown", (event) => beginFooterScopedModelPointerDrag(event, modelKey));
24279
+ return button;
24280
+ }
24281
+
23970
24282
  function renderFooterModelPicker() {
23971
- const picker = make("div", "footer-model-picker");
24283
+ const advanced = footerScopedModelLayout === "advanced";
24284
+ const picker = make("div", `footer-model-picker${advanced ? " footer-model-picker-advanced" : ""}`);
23972
24285
  picker.setAttribute("role", "listbox");
23973
- picker.setAttribute("aria-label", "Scoped models");
23974
- picker.append(make("div", "footer-model-picker-title", "Scoped models"));
23975
- picker.append(make("div", "footer-model-picker-source", "Drag models to reorder · Alt+↑/↓ moves focused model"));
24286
+ picker.setAttribute("aria-label", advanced ? "Scoped models by provider" : "Scoped models");
24287
+ picker.append(make("div", "footer-model-picker-title", advanced ? "Scoped models by provider" : "Scoped models"));
24288
+ const help = make("div", "footer-model-picker-source", advanced
24289
+ ? "Drag within provider · Alt+Up/Down reorders · Left/Right changes provider · Up/Down changes model · Home/End jumps within provider · Enter/Space selects · Escape closes"
24290
+ : "Drag models to reorder · Alt+Up/Down moves focused model");
24291
+ help.id = "footerModelPickerHelp";
24292
+ picker.setAttribute("aria-describedby", help.id);
24293
+ picker.append(help);
23976
24294
  if (footerScopedModels.length === 0) {
23977
24295
  const empty = make("div", "footer-model-picker-empty muted");
23978
24296
  empty.append(
@@ -23982,39 +24300,29 @@ function renderFooterModelPicker() {
23982
24300
  picker.append(empty);
23983
24301
  return picker;
23984
24302
  }
23985
- const current = currentState?.model;
23986
24303
  footerScopedModels = orderedFooterScopedModels();
23987
- for (const model of footerScopedModels) {
23988
- const selected = current?.provider === model.provider && current?.id === model.id;
23989
- const modelKey = footerScopedModelKey(model);
23990
- const dragging = footerScopedModelDragKey === modelKey;
23991
- const dragOver = footerScopedModelDragKey && footerScopedModelLastDragOverKey === modelKey;
23992
- const button = make("button", `footer-model-option${selected ? " active" : ""}${dragging ? " dragging" : ""}${dragOver ? " drag-over" : ""}`);
23993
- button.type = "button";
23994
- button.draggable = false;
23995
- button.dataset.footerModelKey = modelKey;
23996
- button.setAttribute("role", "option");
23997
- button.setAttribute("aria-selected", selected ? "true" : "false");
23998
- button.title = `${model.provider}/${model.id}${model.name ? ` · ${model.name}` : ""}`;
23999
- button.append(
24000
- make("span", "footer-model-option-main", `${model.provider}/${model.id}`),
24001
- make("span", "footer-model-option-name", model.name || ""),
24002
- );
24003
- button.addEventListener("click", (event) => {
24004
- if (Date.now() < footerScopedModelSuppressClickUntil) {
24005
- event.preventDefault();
24006
- return;
24007
- }
24008
- applyFooterModel(model);
24009
- });
24010
- button.addEventListener("keydown", (event) => {
24011
- if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown")) return;
24012
- event.preventDefault();
24013
- moveFooterScopedModelByOffset(modelKey, event.key === "ArrowUp" ? -1 : 1);
24014
- });
24015
- button.addEventListener("pointerdown", (event) => beginFooterScopedModelPointerDrag(event, modelKey));
24016
- picker.append(button);
24304
+ const initialKey = footerModelPickerInitialKey();
24305
+ if (!advanced) {
24306
+ for (const model of footerScopedModels) picker.append(renderFooterModelOption(model));
24307
+ return picker;
24308
+ }
24309
+
24310
+ const columns = make("div", "footer-model-provider-columns");
24311
+ for (const [providerIndex, group] of footerScopedModelProviderGroups(footerScopedModels).entries()) {
24312
+ const heading = make("div", "footer-model-provider-title", group.provider);
24313
+ heading.id = `footerModelProvider${providerIndex}`;
24314
+ const column = make("div", "footer-model-provider-column");
24315
+ column.dataset.footerProvider = group.provider;
24316
+ column.dataset.footerProviderIndex = String(providerIndex);
24317
+ column.setAttribute("role", "group");
24318
+ column.setAttribute("aria-labelledby", heading.id);
24319
+ column.append(heading);
24320
+ for (const [modelIndex, model] of group.models.entries()) {
24321
+ column.append(renderFooterModelOption(model, { advanced: true, providerIndex, modelIndex, initialKey }));
24322
+ }
24323
+ columns.append(column);
24017
24324
  }
24325
+ picker.append(columns);
24018
24326
  return picker;
24019
24327
  }
24020
24328
 
@@ -24497,6 +24805,7 @@ function renderFooter() {
24497
24805
  else renderMinimalFooter();
24498
24806
  if (!tooltipSnapshot && footerTooltipTarget && !footerTooltipTarget.isConnected) hideFooterTooltip();
24499
24807
  restoreScopedControlContinuity(elements.statusBar, continuityContextKey, focusSnapshot, (key) => [...elements.statusBar.querySelectorAll("input, textarea, select, button")].find((node) => footerControlKey(node) === key));
24808
+ syncAdvancedFooterModelRovingTabStop();
24500
24809
  restoreTooltipContinuity(elements.statusBar, tooltipSnapshot);
24501
24810
  }
24502
24811
 
@@ -25594,7 +25903,18 @@ async function clearFinishedSubagentRuns({ automatic = false } = {}) {
25594
25903
  renderSubagents();
25595
25904
  scheduleRefreshSubagents();
25596
25905
  }
25597
- if (dismissed) addEvent(`${automatic ? "auto-cleared" : "cleared"} ${dismissed} finished subagent ${dismissed === 1 ? "run" : "runs"}`, "info");
25906
+ if (dismissed) {
25907
+ if (automatic) {
25908
+ addEvent("auto-cleared", "info", {
25909
+ aggregateKey: "subagent-auto-clear",
25910
+ aggregateIncrement: dismissed,
25911
+ aggregateSingular: "finished subagent run",
25912
+ aggregatePlural: "finished subagent runs",
25913
+ });
25914
+ } else {
25915
+ addEvent(`cleared ${dismissed} finished subagent ${dismissed === 1 ? "run" : "runs"}`, "info");
25916
+ }
25917
+ }
25598
25918
  if (failures.length) addEvent(`could not ${automatic ? "auto-clear" : "clear"} ${failures.length} finished subagent ${failures.length === 1 ? "run" : "runs"}`, "warn");
25599
25919
  }
25600
25920
 
@@ -32937,10 +33257,10 @@ function renderGitWorkflow() {
32937
33257
  addGitWorkflowAction("Creating PR…", () => {}, "primary", true);
32938
33258
  } else if (gitWorkflow.step === "done") {
32939
33259
  addGitWorkflowAction("Close", () => setGitWorkflow({ active: false }), "primary", false);
32940
- addGitWorkflowAction("Start another", () => startGitWorkflow(), "", false);
33260
+ addGitWorkflowAction("Start another", () => launchGuidedGitWorkflow(gitWorkflowActionTabId()), "", false);
32941
33261
  } else if (["cancelled", "error"].includes(gitWorkflow.step)) {
32942
33262
  addGitWorkflowAction("Close", () => setGitWorkflow({ active: false }), "primary", false);
32943
- addGitWorkflowAction("Restart", () => startGitWorkflow(), "", false);
33263
+ addGitWorkflowAction("Restart", () => launchGuidedGitWorkflow(gitWorkflowActionTabId()), "", false);
32944
33264
  }
32945
33265
  restoreGitWorkflowInputFocus(inputFocus);
32946
33266
  }
@@ -33195,14 +33515,108 @@ function reconcileGuidedGitReviewWidgetRemoval(tabId) {
33195
33515
  return true;
33196
33516
  }
33197
33517
 
33198
- async function startGitWorkflow(tabId = activeTabId, { skipSetup = false } = {}) {
33199
- if (!tabId) return;
33200
- if (!isOptionalFeatureEnabled("gitWorkflow")) {
33201
- const tabContext = activeTabContext(tabId);
33202
- addEvent(commandUnavailableMessage("git-staged-msg"), "warn");
33203
- refreshCommands(tabContext).catch((error) => {
33204
- if (isCurrentTabContext(tabContext)) addEvent(error.message || String(error), "error");
33205
- });
33518
+ function guidedGitPromptCommandUnavailable(commandName) {
33519
+ return `Guided Git browser generation requires /${commandName} from @firstpick/pi-prompts-git-pr in the originating tab.`;
33520
+ }
33521
+
33522
+ function guidedGitPromptCompanionAvailable(tabId) {
33523
+ return !isOptionalFeatureDisabled("gitWorkflow") && hasLoadedRpcCommand("git-staged-msg", { tabId });
33524
+ }
33525
+
33526
+ function reportGuidedGitPromptCompanionUnavailable(tabId) {
33527
+ const tabContext = activeTabContext(tabId);
33528
+ const message = isOptionalFeatureDisabled("gitWorkflow")
33529
+ ? optionalFeatureUnavailableMessage("gitWorkflow")
33530
+ : guidedGitPromptCommandUnavailable("git-staged-msg");
33531
+ addEvent(message, "warn");
33532
+ refreshCommands(tabContext).catch((error) => {
33533
+ if (isCurrentTabContext(tabContext)) addEvent(error.message || String(error), "error");
33534
+ });
33535
+ }
33536
+
33537
+ function handleGuidedGitActivationRequest(request) {
33538
+ if (request?.method !== "setStatus" || request.statusKey !== GUIDED_GIT_START_STATUS_KEY) return false;
33539
+ const result = guidedGitActivationController.consume(request, async (tabId, activationIsCurrent) => {
33540
+ if (!guidedGitPromptCompanionAvailable(tabId)) {
33541
+ reportGuidedGitPromptCompanionUnavailable(tabId);
33542
+ return;
33543
+ }
33544
+ await startGitWorkflow(tabId, { activationIsCurrent });
33545
+ });
33546
+ result.promise?.catch((error) => addEvent(`Guided Git could not start: ${error?.message || String(error)}`, "error"));
33547
+ return true;
33548
+ }
33549
+
33550
+ function guidedGitLaunchStateForTab(tabId) {
33551
+ return tabId === activeTabId ? currentState : tabStateCache.get(tabId) || null;
33552
+ }
33553
+
33554
+ function guidedGitLaunchRefusalReason(tabId) {
33555
+ if (promptRoutingTabs.has(tabId)) return "pending";
33556
+ return guidedGitLaunchBlockedReason(guidedGitLaunchStateForTab(tabId), queueMessageCount(queuedSnapshotForTab(tabId)));
33557
+ }
33558
+
33559
+ function reportGuidedGitLaunchRefused(reason) {
33560
+ const detail = reason === "compacting"
33561
+ ? "Pi is compacting context"
33562
+ : reason === "streaming"
33563
+ ? "Pi is running"
33564
+ : reason === "pending"
33565
+ ? "the tab has pending messages"
33566
+ : "the tab state is not ready";
33567
+ addEvent(`Guided Git was not started because ${detail}. Wait until the originating tab is idle with no pending messages, then start it again.`, "warn");
33568
+ }
33569
+
33570
+ function guidedGitLaunchAdmitted(tabId) {
33571
+ const reason = guidedGitLaunchRefusalReason(tabId);
33572
+ if (!reason) return true;
33573
+ reportGuidedGitLaunchRefused(reason);
33574
+ return false;
33575
+ }
33576
+
33577
+ async function startLegacyGuidedGitWorkflowFallback(tabId) {
33578
+ if (!guidedGitLaunchAdmitted(tabId)) return;
33579
+ if (!guidedGitPromptCompanionAvailable(tabId)) {
33580
+ addEvent(isOptionalFeatureDisabled("gitWorkflow")
33581
+ ? optionalFeatureUnavailableMessage("gitWorkflow")
33582
+ : "Guided Git is unavailable: install @firstpick/pi-extension-git-guided-workflow. Browser generation also requires @firstpick/pi-prompts-git-pr.", "warn");
33583
+ return;
33584
+ }
33585
+ try {
33586
+ await api("/api/git-workflow/launch-admission", { method: "POST", body: {}, tabId });
33587
+ } catch (error) {
33588
+ reportGuidedGitLaunchRefused("pending");
33589
+ return;
33590
+ }
33591
+ addEvent("Using the temporary prompt-only Guided Git compatibility launcher. Install @firstpick/pi-extension-git-guided-workflow to route future starts through /git-guided-workflow.", "info");
33592
+ await guidedGitActivationController.run(tabId, (_tabId, activationIsCurrent) => startGitWorkflow(tabId, { activationIsCurrent }));
33593
+ }
33594
+
33595
+ async function launchGuidedGitWorkflow(tabId = activeTabId) {
33596
+ if (!tabId || !guidedGitLaunchAdmitted(tabId)) return;
33597
+ const launchMode = guidedGitLaunchModeForTabCatalog(commandCatalogForTab(tabId), { disabled: isOptionalFeatureDisabled("gitWorkflow") });
33598
+ if (launchMode === "fallback") {
33599
+ await startLegacyGuidedGitWorkflowFallback(tabId);
33600
+ return;
33601
+ }
33602
+ if (launchMode !== "extension") {
33603
+ addEvent(launchMode === "disabled"
33604
+ ? optionalFeatureUnavailableMessage("gitWorkflow")
33605
+ : "Guided Git is unavailable: install @firstpick/pi-extension-git-guided-workflow. Browser generation also requires @firstpick/pi-prompts-git-pr.", "warn");
33606
+ return;
33607
+ }
33608
+ const commandName = resolveAvailableCommandName("git-guided-workflow", { tabId, rpcOnly: true });
33609
+ try {
33610
+ await sendPrompt("prompt", `/${commandName}`, { targetTabId: tabId, throwOnError: true });
33611
+ } catch (error) {
33612
+ addEvent(`Guided Git activation request failed: ${error?.message || String(error)}`, "error");
33613
+ }
33614
+ }
33615
+
33616
+ async function startGitWorkflow(tabId = activeTabId, { skipSetup = false, activationIsCurrent = () => true } = {}) {
33617
+ if (!tabId || !activationIsCurrent()) return;
33618
+ if (!guidedGitPromptCompanionAvailable(tabId)) {
33619
+ reportGuidedGitPromptCompanionUnavailable(tabId);
33206
33620
  return;
33207
33621
  }
33208
33622
 
@@ -33210,6 +33624,7 @@ async function startGitWorkflow(tabId = activeTabId, { skipSetup = false } = {})
33210
33624
  try {
33211
33625
  const response = await api("/api/git-workflow/preferences", { tabId });
33212
33626
  setupData = response.data || {};
33627
+ if (!activationIsCurrent()) return;
33213
33628
  gitWorkflowPreferences = setupData.preferences || null;
33214
33629
  } catch (error) {
33215
33630
  addEvent(`guided Git setup could not be loaded: ${error.message || String(error)}`, "error");
@@ -33221,12 +33636,17 @@ async function startGitWorkflow(tabId = activeTabId, { skipSetup = false } = {})
33221
33636
  return;
33222
33637
  }
33223
33638
  addEvent("Complete Guided Git Setup before starting the workflow.", "info");
33224
- await openNativeGitWorkflowSetupDialog({ onSaved: () => startGitWorkflow(tabId, { skipSetup: true }) });
33639
+ await openNativeGitWorkflowSetupDialog({
33640
+ tabId,
33641
+ activationIsCurrent,
33642
+ onSaved: () => startGitWorkflow(tabId, { skipSetup: true, activationIsCurrent }),
33643
+ });
33225
33644
  return;
33226
33645
  }
33227
33646
 
33228
33647
  const workflow = gitWorkflowForTab(tabId);
33229
33648
  if (workflow.active && !["done", "cancelled", "error"].includes(workflow.step) && !(await appConfirmText("Restart the active git workflow?", { affected: "The active guided Git workflow", confirmLabel: "Restart workflow" }))) return;
33649
+ if (!activationIsCurrent()) return;
33230
33650
  const preferences = setupData.preferences;
33231
33651
  workflow.runId += 1;
33232
33652
  setGitWorkflow({
@@ -33672,6 +34092,10 @@ async function loadGitWorkflowDefaultCommitMessage({ runId, tabId = activeTabId
33672
34092
 
33673
34093
  async function runGitMessagePrompt(tabId = gitWorkflowActionTabId()) {
33674
34094
  const tabContext = activeTabContext(tabId);
34095
+ if (!hasLoadedRpcCommand("git-staged-msg", { tabId })) {
34096
+ failGitWorkflow(new Error(guidedGitPromptCommandUnavailable("git-staged-msg")), "generate", { tabId });
34097
+ return;
34098
+ }
33675
34099
  const targetTab = tabs.find((tab) => tab.id === tabId);
33676
34100
  const targetBusy = tabId === activeTabId ? !!currentState?.isStreaming : activityForTab(targetTab).isWorking;
33677
34101
  if (targetBusy) {
@@ -33762,7 +34186,7 @@ async function loadGitWorkflowMessage({ requireFresh = false, generationId, runI
33762
34186
  if (existing?.key === loadKey) return existing.promise;
33763
34187
 
33764
34188
  const promise = (async () => {
33765
- const deadline = Date.now() + (requireFresh ? GIT_WORKFLOW_MESSAGE_POLL_TIMEOUT_MS : 0);
34189
+ let deadline = Date.now() + (requireFresh ? GIT_WORKFLOW_MESSAGE_POLL_TIMEOUT_MS : 0);
33766
34190
  const baseOutput = workflow.output || "Waiting for generated commit message files…";
33767
34191
  let attempt = 0;
33768
34192
  while (gitWorkflowMessageLoadIsCurrent(tabId, expectedRunId, expectedGenerationId)) {
@@ -33772,6 +34196,7 @@ async function loadGitWorkflowMessage({ requireFresh = false, generationId, runI
33772
34196
  if (!message || !gitWorkflowMessageLoadIsCurrent(tabId, expectedRunId, expectedGenerationId)) return;
33773
34197
  if (message.ready === false) {
33774
34198
  if (message.expired) throw new Error(message.reason || "This commit-message generation has expired. Regenerate the message files.");
34199
+ if (message.running === true) deadline = Date.now() + GIT_WORKFLOW_MESSAGE_POLL_TIMEOUT_MS;
33775
34200
  if (!requireFresh || Date.now() >= deadline) {
33776
34201
  throw new Error(`${message.reason || "Generated commit message files are not ready."} Regenerate, or use Preview current message files after verifying both files.`);
33777
34202
  }
@@ -33844,6 +34269,10 @@ async function createGitPrBranchManually(tabId = gitWorkflowActionTabId()) {
33844
34269
 
33845
34270
  async function runGitBranchNamePrompt(tabId = gitWorkflowActionTabId()) {
33846
34271
  const tabContext = activeTabContext(tabId);
34272
+ if (!hasLoadedRpcCommand("git-branch-name", { tabId })) {
34273
+ failGitWorkflow(new Error(guidedGitPromptCommandUnavailable("git-branch-name")), "message", { tabId });
34274
+ return;
34275
+ }
33847
34276
  const targetTab = tabs.find((tab) => tab.id === tabId);
33848
34277
  const targetBusy = tabId === activeTabId ? !!currentState?.isStreaming : activityForTab(targetTab).isWorking;
33849
34278
  if (targetBusy) {
@@ -34207,8 +34636,8 @@ async function runGitPrPrompt(tabId = gitWorkflowActionTabId(), { prefixOutput =
34207
34636
  failGitWorkflow(new Error("Pi is currently running. Wait for it to finish or abort before generating a PR description."), "push", { tabId });
34208
34637
  return;
34209
34638
  }
34210
- if (!hasAvailableCommand("pr")) {
34211
- failGitWorkflow(new Error(commandUnavailableMessage("pr")), "push", { tabId });
34639
+ if (!hasLoadedRpcCommand("pr", { tabId })) {
34640
+ failGitWorkflow(new Error(guidedGitPromptCommandUnavailable("pr")), "push", { tabId });
34212
34641
  return;
34213
34642
  }
34214
34643
  const workflow = gitWorkflowForTab(tabId, { create: false });
@@ -36659,11 +37088,8 @@ function assistantFailureDisplayMessage(message, base) {
36659
37088
  function assistantDisplayMessages(message) {
36660
37089
  if (message?.role !== "assistant") return [message];
36661
37090
  const failure = assistantFailureDisplayMessage(message, { timestamp: message.timestamp });
36662
- if (failure) {
36663
- const rest = assistantDisplayMessagesWithoutFailure({ ...message, stopReason: undefined });
36664
- return [...rest, failure];
36665
- }
36666
- return assistantDisplayMessagesWithoutFailure(message);
37091
+ const displayMessages = assistantDisplayMessagesWithoutFailure(failure ? { ...message, stopReason: undefined } : message);
37092
+ return groupConsecutiveThinkingMessages(failure ? [...displayMessages, failure] : displayMessages);
36667
37093
  }
36668
37094
 
36669
37095
  function assistantDisplayMessagesWithoutFailure(message) {
@@ -38729,6 +39155,24 @@ function groupWorkflowStatusTranscriptItems(items, toolResults) {
38729
39155
  return groupConsecutiveWorkflowStatusItems(projected);
38730
39156
  }
38731
39157
 
39158
+ function transcriptItemThinkingMessage(item) {
39159
+ if (!thinkingOutputVisible) return null;
39160
+ const message = item?.message;
39161
+ const displayMessages = message?.role === "assistant" ? assistantDisplayMessages(message) : [message];
39162
+ if (displayMessages.length !== 1 || displayMessages[0]?.role !== "thinking") return null;
39163
+ const candidate = displayMessages[0];
39164
+ const thinking = visibleThinkingText(candidate.thinking || textFromContent(candidate.content));
39165
+ return thinking ? { ...candidate, content: thinking, thinking } : null;
39166
+ }
39167
+
39168
+ function groupConsecutiveThinkingTranscriptItems(items) {
39169
+ return groupConsecutiveThinkingItems(items, transcriptItemThinkingMessage).map((item) => {
39170
+ if (!(item.thinkingGroupSourceCount > 1)) return item;
39171
+ const sourceKey = item.transcriptKey || `${item.transient ? "t" : "m"}:${item.messageIndex}:${item.order}`;
39172
+ return { ...item, messageIndex: -1, transcriptKey: `thinking-group:${sourceKey}` };
39173
+ });
39174
+ }
39175
+
38732
39176
  function orderedTranscriptItems() {
38733
39177
  const items = compactOutputActive() ? compactStoredTranscriptItems() : [];
38734
39178
  const assistantToolCallIds = buildAssistantToolCallIdSet(latestMessages);
@@ -38754,7 +39198,8 @@ function orderedTranscriptItems() {
38754
39198
  }
38755
39199
  }
38756
39200
  const ordered = items.sort((a, b) => a.timestampMs - b.timestampMs || a.order - b.order);
38757
- return groupWorkflowStatusTranscriptItems(ordered, toolResults);
39201
+ const groupedThinking = compactOutputActive() ? ordered : groupConsecutiveThinkingTranscriptItems(ordered);
39202
+ return groupWorkflowStatusTranscriptItems(groupedThinking, toolResults);
38758
39203
  }
38759
39204
 
38760
39205
  /**
@@ -40781,7 +41226,7 @@ function updateOptionalFeatureAvailability() {
40781
41226
  optionalFeatureAvailability.bangCommandAutocomplete = hasAvailableCommand("bang-status") || hasAvailableCommand("bang-refresh");
40782
41227
  optionalFeatureAvailability.fishUserBash = hasAvailableCommand("user-bash-shell");
40783
41228
  optionalFeatureAvailability.btwCommand = hasAvailableCommand("btw") || optionalFeatureAvailability.btwCommand || statusEntries.has(BTW_WEBUI_STATUS_KEY) || widgets.has(BTW_OUTPUT_WIDGET_KEY);
40784
- optionalFeatureAvailability.gitWorkflow = hasAvailableCommand("git-staged-msg");
41229
+ optionalFeatureAvailability.gitWorkflow = hasAvailableCommand("git-guided-workflow") || hasAvailableCommand("git-staged-msg");
40785
41230
  optionalFeatureAvailability.releaseNpm = hasAvailableCommand("release-npm");
40786
41231
  optionalFeatureAvailability.releaseAur = hasAvailableCommand("release-aur");
40787
41232
  optionalFeatureAvailability.aurReview = hasAvailableCommand("aur-review") || optionalFeatureAvailability.aurReview || widgets.has(AUR_REVIEW_RPC_WIDGET_KEY);
@@ -41008,7 +41453,7 @@ function renderOptionalFeatureSection(section, features) {
41008
41453
 
41009
41454
  function optionalFeatureSetupAvailable(feature) {
41010
41455
  switch (feature?.setup) {
41011
- case "git-workflow": return hasAvailableCommand("git-workflow-setup");
41456
+ case "git-workflow": return true;
41012
41457
  case "workflows": return hasLoadedRpcCommand("workflow-setup");
41013
41458
  case "safety-guard": return hasAvailableCommand("safety-guard-setup");
41014
41459
  case "skills": return hasLoadedRpcCommand("skills");
@@ -43108,21 +43553,50 @@ async function openNativeSessionSummarySetupDialog({ initialData = null, onSaved
43108
43553
  }, "primary");
43109
43554
  }
43110
43555
 
43111
- async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
43556
+ async function openNativeGitWorkflowSetupDialog({ onSaved, tabId = activeTabId, activationIsCurrent = () => true } = {}) {
43557
+ if (!tabId || !activationIsCurrent()) return "stale";
43558
+ nativeCommandTabId = tabId;
43112
43559
  openNativeCommandDialog({
43113
43560
  title: "/git-workflow-setup",
43114
43561
  message: "Configure the dedicated model and safe defaults used by Guided Git. The selected generation profile is applied only while commit, branch, or PR text is generated.",
43115
43562
  });
43116
43563
  renderNativeLoading("Loading guided Git preferences and available models…");
43117
43564
 
43565
+ const setupOwner = Symbol(tabId);
43566
+ guidedGitSetupDialogOwner = setupOwner;
43567
+ const setupOwnsDialog = () => guidedGitSetupDialogOwner === setupOwner;
43568
+ const closeOwnedSetupDialog = () => {
43569
+ if (setupOwnsDialog()) closeNativeCommandDialog({ force: true });
43570
+ };
43571
+ let setupSettled = false;
43572
+ let saveInFlight = false;
43573
+ let resolveSetup;
43574
+ const setupSettlement = new Promise((resolve) => { resolveSetup = resolve; });
43575
+ const settleSetup = (status) => {
43576
+ if (setupSettled) return;
43577
+ setupSettled = true;
43578
+ if (setupOwnsDialog()) guidedGitSetupDialogOwner = null;
43579
+ elements.nativeCommandDialog.removeEventListener("close", handleSetupClose);
43580
+ resolveSetup(status);
43581
+ };
43582
+ const handleSetupClose = () => {
43583
+ if (!saveInFlight) settleSetup("cancelled");
43584
+ };
43585
+ elements.nativeCommandDialog.addEventListener("close", handleSetupClose);
43586
+
43118
43587
  let data;
43119
43588
  try {
43120
- const response = await nativeCommandApi("/api/git-workflow/preferences");
43589
+ const response = await nativeCommandApi("/api/git-workflow/preferences", { tabId });
43121
43590
  data = response.data || {};
43122
43591
  } catch (error) {
43123
43592
  setNativeCommandError(error.message || String(error));
43124
43593
  elements.nativeCommandBody.replaceChildren();
43125
- return;
43594
+ return setupSettlement;
43595
+ }
43596
+ if (!activationIsCurrent()) {
43597
+ closeOwnedSetupDialog();
43598
+ settleSetup("stale");
43599
+ return setupSettlement;
43126
43600
  }
43127
43601
 
43128
43602
  const preferences = data.preferences || {};
@@ -43130,12 +43604,13 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
43130
43604
  if (!models.length) {
43131
43605
  setNativeCommandError("No authenticated Pi models are available. Run /login or configure a provider first.");
43132
43606
  elements.nativeCommandBody.replaceChildren();
43133
- return;
43607
+ return setupSettlement;
43134
43608
  }
43135
43609
 
43136
43610
  const configuredModelKey = `${preferences.generation?.provider || ""}/${preferences.generation?.modelId || ""}`;
43137
43611
  const configuredFallbackKey = `${preferences.generation?.fallback?.provider || ""}/${preferences.generation?.fallback?.modelId || ""}`;
43138
- const activeModelKey = gitWorkflowSetupModelKey(currentState?.model);
43612
+ const targetState = tabId === activeTabId ? currentState : tabStateCache.get(tabId);
43613
+ const activeModelKey = gitWorkflowSetupModelKey(targetState?.model);
43139
43614
  const modelKeys = new Set(models.map(gitWorkflowSetupModelKey));
43140
43615
  const initialModelKey = modelKeys.has(configuredModelKey)
43141
43616
  ? configuredModelKey
@@ -43231,9 +43706,15 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
43231
43706
  addNativeCommandAction("Cancel", closeNativeCommandDialog);
43232
43707
 
43233
43708
  const save = addNativeCommandAction("Save setup", async () => {
43709
+ saveInFlight = true;
43234
43710
  setNativeActionBusy(save, true, "Saving…");
43235
43711
  setNativeCommandError("");
43236
43712
  try {
43713
+ if (!activationIsCurrent()) {
43714
+ closeOwnedSetupDialog();
43715
+ settleSetup("stale");
43716
+ return;
43717
+ }
43237
43718
  const selectedModel = models.find((model) => gitWorkflowSetupModelKey(model) === controls.model.select.value);
43238
43719
  if (!selectedModel) throw new Error("Select an available primary Git-writing model.");
43239
43720
  const selectedFallback = models.find((model) => gitWorkflowSetupModelKey(model) === controls.fallbackModel.select.value) || null;
@@ -43242,6 +43723,7 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
43242
43723
  }
43243
43724
  const response = await nativeCommandApi("/api/git-workflow/preferences", {
43244
43725
  method: "POST",
43726
+ tabId,
43245
43727
  body: {
43246
43728
  preferences: {
43247
43729
  generation: {
@@ -43267,6 +43749,11 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
43267
43749
  },
43268
43750
  },
43269
43751
  });
43752
+ if (!activationIsCurrent()) {
43753
+ closeOwnedSetupDialog();
43754
+ settleSetup("stale");
43755
+ return;
43756
+ }
43270
43757
  gitWorkflowPreferences = response.data?.preferences || null;
43271
43758
  addTransientMessage({
43272
43759
  role: "native",
@@ -43274,14 +43761,25 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
43274
43761
  content: `Guided Git setup saved. Primary: ${gitWorkflowSetupModelKey(selectedModel)} at ${controls.thinking.select.value} effort. ${selectedFallback ? `Fallback: ${gitWorkflowSetupModelKey(selectedFallback)} at ${controls.fallbackThinking.select.value} effort (one attempt after a final primary generation failure).` : "Fallback: none."}`,
43275
43762
  level: "info",
43276
43763
  });
43277
- closeNativeCommandDialog();
43278
- if (typeof onSaved === "function") await onSaved(gitWorkflowPreferences);
43764
+ nativeSettingsDirty = false;
43765
+ closeOwnedSetupDialog();
43766
+ if (typeof onSaved === "function" && activationIsCurrent()) {
43767
+ try {
43768
+ await onSaved(gitWorkflowPreferences);
43769
+ } catch (error) {
43770
+ addEvent(`Guided Git could not continue after setup: ${error?.message || String(error)}`, "error");
43771
+ }
43772
+ }
43773
+ settleSetup(activationIsCurrent() ? "saved" : "stale");
43279
43774
  } catch (error) {
43280
43775
  setNativeCommandError(error.message || String(error));
43281
43776
  } finally {
43777
+ saveInFlight = false;
43282
43778
  setNativeActionBusy(save, false);
43779
+ if (!elements.nativeCommandDialog.open) settleSetup("cancelled");
43283
43780
  }
43284
43781
  }, "primary");
43782
+ return setupSettlement;
43285
43783
  }
43286
43784
 
43287
43785
  function normalizedWorkflowPolicyList(value) {
@@ -46451,7 +46949,7 @@ function commandPaletteCoreItems() {
46451
46949
  { kind: "Pi", label: "/tools", description: "Manage active tools", keywords: "capabilities", run: () => runNativeCommandMenu("/tools") },
46452
46950
  { kind: "Pi", label: "/skills", description: "Manage active skills", keywords: "system prompt", run: () => runNativeCommandMenu("/skills") },
46453
46951
  { kind: "Pi", label: "/theme", description: "Choose the Web UI theme", keywords: "dark light colors appearance", run: () => openNativeThemeSelector() },
46454
- { kind: "Git", label: "Guided Git workflow", description: "Stage, commit, push, or open a pull request step by step", keywords: "git commit push pr publish", run: () => startGitWorkflow() },
46952
+ { kind: "Git", label: "Guided Git workflow", description: "Stage, commit, push, or open a pull request step by step", keywords: "git commit push pr publish", run: () => launchGuidedGitWorkflow() },
46455
46953
  { kind: "Git", label: "Git changes", description: "Review and stage local changes with diffs", keywords: "git diff stage unstage discard status", run: () => openGitChangesDialog() },
46456
46954
  { kind: "Action", label: "Files panel", description: "Open the Files section of the Control Deck", keywords: "tree browse project explorer", run: () => revealSidePanelSectionById("files") },
46457
46955
  { kind: "Action", label: "Git panel", description: "Open the Git section of the Control Deck", keywords: "repository status history", run: () => revealSidePanelSectionById("git") },
@@ -47197,6 +47695,17 @@ function createBrowserPromptRequestId() {
47197
47695
  return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
47198
47696
  }
47199
47697
 
47698
+ function createBrowserGuidedGitLaunchId() {
47699
+ const generated = globalThis.crypto?.randomUUID?.();
47700
+ if (generated) return generated;
47701
+ const bytes = new Uint8Array(16);
47702
+ globalThis.crypto?.getRandomValues?.(bytes);
47703
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
47704
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
47705
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
47706
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
47707
+ }
47708
+
47200
47709
  async function retryMobileFailedSend() {
47201
47710
  const pending = mobileFailedSend;
47202
47711
  if (!pending || pending.retrying) return;
@@ -47257,8 +47766,24 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
47257
47766
  return;
47258
47767
  }
47259
47768
 
47260
- const targetWasStreaming = !!currentState?.isStreaming;
47261
- const targetWasCompacting = !!currentState?.isCompacting;
47769
+ const guidedGitExtensionLaunch = kind === "prompt"
47770
+ && attachments.length === 0
47771
+ && guidedGitWorkflowCommandForTabCatalog(commandCatalogForTab(targetTabId), originalMessage);
47772
+ let guidedGitPermitGranted = false;
47773
+ let guidedGitLaunchId = "";
47774
+ if (guidedGitExtensionLaunch) {
47775
+ if (!guidedGitLaunchAdmitted(targetTabId)) return;
47776
+ guidedGitLaunchId = createBrowserGuidedGitLaunchId();
47777
+ if (!guidedGitLaunchPermits.grant(targetTabId, guidedGitLaunchId)) {
47778
+ addEvent("Guided Git activation is already pending for this tab.", "warn");
47779
+ return;
47780
+ }
47781
+ guidedGitPermitGranted = true;
47782
+ }
47783
+
47784
+ const targetState = targetTabId === activeTabId ? currentState : tabStateCache.get(targetTabId);
47785
+ const targetWasStreaming = !!targetState?.isStreaming;
47786
+ const targetWasCompacting = !!targetState?.isCompacting;
47262
47787
  const targetWasBusy = targetWasStreaming || targetWasCompacting;
47263
47788
  const busyBehavior = normalizeBusyPromptBehavior(busyPromptBehavior);
47264
47789
  const startsRun = kind === "prompt" && !targetWasBusy;
@@ -47289,6 +47814,7 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
47289
47814
  // targetTabId. This implementation intentionally never retries an
47290
47815
  // ambiguous mutation automatically.
47291
47816
  if (kind === "prompt") bodyBase.requestId = createBrowserPromptRequestId();
47817
+ if (guidedGitLaunchId) bodyBase.guidedGitLaunchId = guidedGitLaunchId;
47292
47818
  if (prepared.images.length) bodyBase.images = prepared.images;
47293
47819
  if (!message.startsWith("/")) {
47294
47820
  rememberPromptHistory(message, { tabId: targetTabId });
@@ -47338,6 +47864,7 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
47338
47864
  scheduleRefreshTabs(300);
47339
47865
  }
47340
47866
  } catch (error) {
47867
+ if (guidedGitPermitGranted) guidedGitLaunchPermits.clearTab(targetTabId);
47341
47868
  restorePromptInputAfterRoutingError(inputMessage, { usesPromptInput, targetTabId, tabContext });
47342
47869
  if (dispatchedRequest?.kind === "prompt" && dispatchedRequest.body?.requestId && error?.backendOffline === true && isMobileShellV2Active()) {
47343
47870
  mobileFailedSend = { ...dispatchedRequest, retrying: false };
@@ -47382,6 +47909,7 @@ function removeQueuedDialogRequests(ids = []) {
47382
47909
  }
47383
47910
 
47384
47911
  function handleExtensionUiRequest(request) {
47912
+ if (handleGuidedGitActivationRequest(request)) return;
47385
47913
  request.tabId ||= activeTabId;
47386
47914
  switch (request.method) {
47387
47915
  case "notify": {
@@ -47945,6 +48473,7 @@ function scheduleSupervisorContinuityRefresh(event, { gap = false } = {}) {
47945
48473
  }
47946
48474
 
47947
48475
  function handleInactiveTabEvent(event) {
48476
+ if (handleGuidedGitActivationRequest(event)) return;
47948
48477
  if (event.type === "extension_ui_request" && EXTENSION_UI_BLOCKING_METHODS.has(event.method)) {
47949
48478
  if (!event.replayed) notifyBlockedTab(event.tabId, { request: event, count: event.pendingExtensionUiRequestCount });
47950
48479
  renderTabs();
@@ -48698,7 +49227,7 @@ elements.commandPaletteButton?.addEventListener("click", () => openCommandPalett
48698
49227
  elements.workspaceDashboardToggleButton?.addEventListener("click", () => setWorkspaceDashboardCollapsed(!workspaceDashboardCollapsed));
48699
49228
  elements.gitWorkflowButton.addEventListener("click", () => {
48700
49229
  setComposerActionsOpen(false);
48701
- startGitWorkflow();
49230
+ launchGuidedGitWorkflow();
48702
49231
  });
48703
49232
  const publishMenuContainer = elements.publishButton.parentElement;
48704
49233
  elements.publishButton.addEventListener("click", () => {
@@ -50055,6 +50584,7 @@ window.addEventListener("storage", (event) => {
50055
50584
  footerScopedModels = orderedFooterScopedModels();
50056
50585
  renderFooter();
50057
50586
  }
50587
+ if (event.key === FOOTER_SCOPED_MODEL_LAYOUT_STORAGE_KEY) setFooterScopedModelLayout(event.newValue, { persist: false });
50058
50588
  if (event.key === FILE_VIEWER_WIDTH_STORAGE_KEY) restoreFileViewerWidthPreference();
50059
50589
  });
50060
50590
  // Durable layout reconciliation runs on its own foreground/online lifecycle
@@ -50122,7 +50652,7 @@ window.addEventListener("keydown", (event) => {
50122
50652
  return;
50123
50653
  }
50124
50654
  if (isFooterPickerOpen()) {
50125
- setFooterModelPickerOpen(false);
50655
+ setFooterModelPickerOpen(false, { restoreFocus: footerModelPickerOpen });
50126
50656
  setFooterThinkingPickerOpen(false);
50127
50657
  setFooterBranchPickerOpen(false);
50128
50658
  return;
@@ -50401,7 +50931,7 @@ elements.controlVisibilitySetupCloseButton?.addEventListener("click", () => elem
50401
50931
  elements.controlVisibilitySetupDialog?.querySelector("form")?.addEventListener("submit", (event) => event.preventDefault());
50402
50932
  elements.controlVisibilitySetupDialog?.addEventListener("close", restoreControlVisibilitySetupFocus);
50403
50933
  elements.gitFooterContextMenu?.addEventListener("keydown", (event) => {
50404
- const items = [...elements.gitFooterContextMenu.querySelectorAll('[role="menuitem"]:not([disabled])')];
50934
+ const items = [...elements.gitFooterContextMenu.querySelectorAll('[role="menuitem"]:not([disabled]):not([hidden]), [role="menuitemcheckbox"]:not([disabled]):not([hidden])')];
50405
50935
  const index = items.indexOf(document.activeElement);
50406
50936
  if (event.key === "Escape") {
50407
50937
  event.preventDefault();
@@ -50422,6 +50952,7 @@ elements.gitFooterContextMenu?.addEventListener("click", (event) => {
50422
50952
  const action = button.dataset.gitFooterMenuAction;
50423
50953
  closeGitFooterContextMenu({ returnFocus: action !== "visibility" });
50424
50954
  if (action === "disable") void disableGitFooterContextChip(state.key, state.label);
50955
+ else if (action === "toggle-advanced" && state.key === "model") toggleFooterScopedModelLayout();
50425
50956
  else if (action === "visibility") openGitFooterVisibilityDialog();
50426
50957
  });
50427
50958
  elements.fileTreeNewFileButton?.addEventListener("click", () => createFileTreeEntry(null, "file").catch((error) => addEvent(error.message || String(error), "error")));