@firstpick/pi-package-webui 0.7.8 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/bin/pi-webui.mjs +696 -69
- package/lib/git-workflow-preferences.mjs +16 -0
- package/lib/git-worktrees.mjs +43 -4
- package/lib/queue-mutation.mjs +109 -0
- package/lib/scoped-models.mjs +19 -0
- package/lib/webui-workspaces.mjs +265 -0
- package/package.json +4 -2
- package/public/app.js +2074 -188
- package/public/index.html +105 -4
- package/public/service-worker.js +1 -1
- package/public/styles.css +618 -73
- package/public/voice-conversation.mjs +1 -1
- package/tests/boot-failure-diagnostics.test.mjs +2 -2
- package/tests/codex-fast-mode-static.test.mjs +56 -0
- package/tests/compaction-mutation-contract.test.mjs +166 -0
- package/tests/compaction-resume-harness.test.mjs +113 -2
- package/tests/compaction-static.test.mjs +5 -0
- package/tests/composer-skill-tag-layout.test.mjs +70 -0
- package/tests/cwd-footer-reliability-static.test.mjs +5 -0
- package/tests/fast-mode-client-static.test.mjs +8 -8
- package/tests/file-selection-overlay-static.test.mjs +21 -0
- package/tests/file-viewer-search-static.test.mjs +65 -0
- package/tests/fixtures/fake-pi.mjs +216 -43
- package/tests/git-panel-file-preview-static.test.mjs +20 -5
- package/tests/git-workflow-preferences.test.mjs +8 -0
- package/tests/guided-git-publication-backend-static.test.mjs +40 -0
- package/tests/http-endpoints-harness.test.mjs +422 -2
- package/tests/mobile-static.test.mjs +111 -42
- package/tests/native-parity.test.mjs +1 -1
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/queue-edit-reorder-static.test.mjs +101 -0
- package/tests/queue-mutation-contract.test.mjs +143 -0
- package/tests/scoped-models.test.mjs +42 -0
- package/tests/side-panel-resize-static.test.mjs +8 -1
- package/tests/subagents-helper.test.mjs +216 -3
- package/tests/terminal-tab-workspace-static.test.mjs +4 -2
- package/tests/webui-workspaces-harness.test.mjs +223 -0
- package/tests/webui-workspaces.test.mjs +106 -0
- package/tests/workspace-save-load-static.test.mjs +69 -0
- package/webui-rpc-helper.mjs +300 -41
package/public/app.js
CHANGED
|
@@ -17,6 +17,7 @@ const elements = {
|
|
|
17
17
|
tabBar: $("#tabBar"),
|
|
18
18
|
terminalTabsToggleButton: $("#terminalTabsToggleButton"),
|
|
19
19
|
splitTabButton: $("#splitTabButton"),
|
|
20
|
+
workspaceSaveButton: $("#workspaceSaveButton"),
|
|
20
21
|
newTabMenu: $("#newTabMenu"),
|
|
21
22
|
newTabButton: $("#newTabButton"),
|
|
22
23
|
newTabMenuPanel: $("#newTabMenuPanel"),
|
|
@@ -57,7 +58,15 @@ const elements = {
|
|
|
57
58
|
subagentTerminalStatus: $("#subagentTerminalStatus"),
|
|
58
59
|
subagentTerminalCopyButton: $("#subagentTerminalCopyButton"),
|
|
59
60
|
subagentTerminalRefreshButton: $("#subagentTerminalRefreshButton"),
|
|
61
|
+
subagentTerminalCancelButton: $("#subagentTerminalCancelButton"),
|
|
60
62
|
subagentTerminalInput: $("#subagentTerminalInput"),
|
|
63
|
+
subagentCancelDialog: $("#subagentCancelDialog"),
|
|
64
|
+
subagentCancelDialogSubtitle: $("#subagentCancelDialogSubtitle"),
|
|
65
|
+
subagentCancelReason: $("#subagentCancelReason"),
|
|
66
|
+
subagentCancelNote: $("#subagentCancelNote"),
|
|
67
|
+
subagentCancelStatus: $("#subagentCancelStatus"),
|
|
68
|
+
subagentCancelKeepRunningButton: $("#subagentCancelKeepRunningButton"),
|
|
69
|
+
subagentCancelSubmitButton: $("#subagentCancelSubmitButton"),
|
|
61
70
|
stickyUserPromptButton: $("#stickyUserPromptButton"),
|
|
62
71
|
chat: $("#chat"),
|
|
63
72
|
chatSearchBar: $("#chatSearchBar"),
|
|
@@ -75,6 +84,13 @@ const elements = {
|
|
|
75
84
|
composerActionsButton: $("#composerActionsButton"),
|
|
76
85
|
composerActionsPanel: $("#composerActionsPanel"),
|
|
77
86
|
promptInput: $("#promptInput"),
|
|
87
|
+
followUpQueueTrigger: $("#followUpQueueTrigger"),
|
|
88
|
+
followUpQueueTriggerCount: $("#followUpQueueTriggerCount"),
|
|
89
|
+
followUpQueueOverlay: $("#followUpQueueOverlay"),
|
|
90
|
+
followUpQueueOverlayCount: $("#followUpQueueOverlayCount"),
|
|
91
|
+
followUpQueueRows: $("#followUpQueueRows"),
|
|
92
|
+
followUpQueueStatus: $("#followUpQueueStatus"),
|
|
93
|
+
followUpQueueCloseButton: $("#followUpQueueCloseButton"),
|
|
78
94
|
busyPromptBehaviorTag: $("#busyPromptBehaviorTag"),
|
|
79
95
|
busyPromptBehaviorMenu: $("#busyPromptBehaviorMenu"),
|
|
80
96
|
sessionSkillTags: $("#sessionSkillTags"),
|
|
@@ -208,6 +224,9 @@ const elements = {
|
|
|
208
224
|
optionalFeaturesBox: $("#optionalFeaturesBox"),
|
|
209
225
|
codexUsageBox: $("#codexUsageBox"),
|
|
210
226
|
refreshCodexUsageButton: $("#refreshCodexUsageButton"),
|
|
227
|
+
codexFastModeSelect: $("#codexFastModeSelect"),
|
|
228
|
+
setCodexFastModeButton: $("#setCodexFastModeButton"),
|
|
229
|
+
codexFastModeStatus: $("#codexFastModeStatus"),
|
|
211
230
|
claudeUsageBox: $("#claudeUsageBox"),
|
|
212
231
|
refreshClaudeUsageButton: $("#refreshClaudeUsageButton"),
|
|
213
232
|
fileTreeCwd: $("#fileTreeCwd"),
|
|
@@ -235,6 +254,12 @@ const elements = {
|
|
|
235
254
|
fileViewerPreview: $("#fileViewerPreview"),
|
|
236
255
|
fileViewerChanges: $("#fileViewerChanges"),
|
|
237
256
|
fileViewerStatus: $("#fileViewerStatus"),
|
|
257
|
+
fileViewerSearchBar: $("#fileViewerSearchBar"),
|
|
258
|
+
fileViewerSearchInput: $("#fileViewerSearchInput"),
|
|
259
|
+
fileViewerSearchCount: $("#fileViewerSearchCount"),
|
|
260
|
+
fileViewerSearchPrevButton: $("#fileViewerSearchPrevButton"),
|
|
261
|
+
fileViewerSearchNextButton: $("#fileViewerSearchNextButton"),
|
|
262
|
+
fileViewerSearchCloseButton: $("#fileViewerSearchCloseButton"),
|
|
238
263
|
fileSelectionBar: $("#fileSelectionBar"),
|
|
239
264
|
fileSelectionSummary: $("#fileSelectionSummary"),
|
|
240
265
|
fileSelectionCommentInput: $("#fileSelectionCommentInput"),
|
|
@@ -326,6 +351,19 @@ const elements = {
|
|
|
326
351
|
confirmationUndo: $("#confirmationUndo"),
|
|
327
352
|
confirmationCancelButton: $("#confirmationCancelButton"),
|
|
328
353
|
confirmationConfirmButton: $("#confirmationConfirmButton"),
|
|
354
|
+
workspaceLoadDialog: $("#workspaceLoadDialog"),
|
|
355
|
+
workspaceLoadDialogCloseButton: $("#workspaceLoadDialogCloseButton"),
|
|
356
|
+
workspaceLoadDialogStatus: $("#workspaceLoadDialogStatus"),
|
|
357
|
+
workspaceLoadDialogList: $("#workspaceLoadDialogList"),
|
|
358
|
+
workspaceReplaceDialog: $("#workspaceReplaceDialog"),
|
|
359
|
+
workspaceReplaceTargetName: $("#workspaceReplaceTargetName"),
|
|
360
|
+
workspaceReplaceCurrentTabsCount: $("#workspaceReplaceCurrentTabsCount"),
|
|
361
|
+
workspaceReplaceCurrentTabsList: $("#workspaceReplaceCurrentTabsList"),
|
|
362
|
+
workspaceReplaceSaveName: $("#workspaceReplaceSaveName"),
|
|
363
|
+
workspaceReplaceDialogStatus: $("#workspaceReplaceDialogStatus"),
|
|
364
|
+
workspaceReplaceCancelButton: $("#workspaceReplaceCancelButton"),
|
|
365
|
+
workspaceReplaceDiscardButton: $("#workspaceReplaceDiscardButton"),
|
|
366
|
+
workspaceReplaceSaveButton: $("#workspaceReplaceSaveButton"),
|
|
329
367
|
gitWorktreeBaseDialog: $("#gitWorktreeBaseDialog"),
|
|
330
368
|
gitWorktreeBaseBranch: $("#gitWorktreeBaseBranch"),
|
|
331
369
|
gitWorktreeBaseOriginMain: $("#gitWorktreeBaseOriginMain"),
|
|
@@ -411,14 +449,22 @@ let activeTextAttachmentEditor = null;
|
|
|
411
449
|
let activeSkillEditor = null;
|
|
412
450
|
let fileTreeState = { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial: 0, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0, gitStatusRoot: "", gitStatusByPath: new Map() };
|
|
413
451
|
let activeFileViewer = null;
|
|
452
|
+
let fileViewersByTab = new Map();
|
|
414
453
|
let fileViewerOpenRequestSerial = 0;
|
|
415
454
|
let fileViewerGitChangesRequestSerial = 0;
|
|
416
455
|
let fileViewerSelection = null;
|
|
456
|
+
let fileViewerSelectionsByTab = new Map();
|
|
457
|
+
let fileViewerSearchMatches = [];
|
|
458
|
+
let fileViewerSearchIndex = -1;
|
|
459
|
+
let fileViewerSearchTruncated = false;
|
|
460
|
+
let fileViewerSearchTimer = null;
|
|
461
|
+
let fileViewerSearchHighlightElement = null;
|
|
417
462
|
let fileContextMenuState = null;
|
|
418
463
|
let sidePanelContextMenuState = null;
|
|
419
464
|
let fileTreeDragState = null;
|
|
420
465
|
let fileViewerResizeState = null;
|
|
421
466
|
let sidePanelResizeState = null;
|
|
467
|
+
let sidePanelWidthPreferenceRevision = 0;
|
|
422
468
|
let fileTreeSearchTimer = null;
|
|
423
469
|
let fileTreeSearchRequestSerial = 0;
|
|
424
470
|
let tabActivities = new Map();
|
|
@@ -482,6 +528,8 @@ const supervisorContinuityRefreshes = new Map();
|
|
|
482
528
|
const supervisorEnvelopeWarnings = new Set();
|
|
483
529
|
let activeDialog = null;
|
|
484
530
|
let activeConfirmationResolve = null;
|
|
531
|
+
let activeWorkspaceReplacementResolve = null;
|
|
532
|
+
let workspaceLoadPickerFocusReturn = null;
|
|
485
533
|
let activeGitWorktreeBaseResolve = null;
|
|
486
534
|
let activeUndoAction = null;
|
|
487
535
|
let undoToastTimer = null;
|
|
@@ -515,6 +563,11 @@ let mobileTabsExpanded = false;
|
|
|
515
563
|
let openTerminalTabGroupKey = null;
|
|
516
564
|
let terminalCustomGroups = new Map();
|
|
517
565
|
let terminalCustomGroupSerial = 1;
|
|
566
|
+
let savedWorkspaces = [];
|
|
567
|
+
let savedWorkspacesLoaded = false;
|
|
568
|
+
let savedWorkspacesLoading = false;
|
|
569
|
+
let savedWorkspacesError = "";
|
|
570
|
+
let savedWorkspacesRefreshPromise = null;
|
|
518
571
|
let terminalTabDragId = null;
|
|
519
572
|
let splitTabId = null;
|
|
520
573
|
let newTabMenuOpen = false;
|
|
@@ -587,7 +640,10 @@ let subagentOverlayLoading = false;
|
|
|
587
640
|
let subagentOverlayRefreshTimer = null;
|
|
588
641
|
let subagentOverlayRequestSerial = 0;
|
|
589
642
|
let subagentOpenMode = "overlay";
|
|
643
|
+
let subagentCancelSelection = null;
|
|
644
|
+
let subagentCancelSubmitting = false;
|
|
590
645
|
const subagentTerminalViews = new Map();
|
|
646
|
+
const subagentTerminalRestoredParentTabs = new Set();
|
|
591
647
|
let activeSubagentTerminalId = null;
|
|
592
648
|
let subagentTerminalRefreshTimer = null;
|
|
593
649
|
let subagentLaunchSlotConfig = null;
|
|
@@ -666,7 +722,7 @@ let footerModelPickerOpen = false;
|
|
|
666
722
|
let footerThinkingPickerOpen = false;
|
|
667
723
|
let footerAutoCompactionToggleInFlight = false;
|
|
668
724
|
let footerBranchPickerOpen = false;
|
|
669
|
-
let footerBranchPickerState = { loading: false, error: "", branches: [], current: "", root: "", repoRoot: "", currentWorktreePath: "", defaultWorktreesRoot: "", worktrees: [], occupiedBranches: [], switching: "", tabId: null };
|
|
725
|
+
let footerBranchPickerState = { loading: false, error: "", branches: [], current: "", root: "", repoRoot: "", currentWorktreePath: "", defaultWorktreesRoot: "", worktrees: [], occupiedBranches: [], switching: "", switchingKey: "", tabId: null };
|
|
670
726
|
let footerBranchCreateDraft = { type: "", name: "" };
|
|
671
727
|
let footerBranchPickerRequestSerial = 0;
|
|
672
728
|
let footerScopedModelDragKey = "";
|
|
@@ -679,6 +735,12 @@ let abortRequestInFlight = false;
|
|
|
679
735
|
let userBashByTab = new Map();
|
|
680
736
|
let userBashQueuesByTab = new Map();
|
|
681
737
|
let latestQueuedMessagesByTab = new Map();
|
|
738
|
+
let followUpQueueOpen = false;
|
|
739
|
+
const followUpQueueMutationsInFlightByTab = new Set();
|
|
740
|
+
let followUpQueueStatus = { text: "", level: "" };
|
|
741
|
+
let followUpQueueRestoreFocus = null;
|
|
742
|
+
let followUpQueueDrag = null;
|
|
743
|
+
let followUpQueueSuppressBlurFor = null;
|
|
682
744
|
let loadedPromptList = null;
|
|
683
745
|
let promptListRunning = false;
|
|
684
746
|
let workspaceDashboardCollapsed = false;
|
|
@@ -794,6 +856,7 @@ const STATS_WEBUI_PAYLOAD_TYPE = "firstpick.pi-extension-stats.overlay";
|
|
|
794
856
|
const STATS_WEBUI_PAYLOAD_VERSION = 1;
|
|
795
857
|
const NATURAL_CONVERSATION_STATUS_KEY = "natural-conversation";
|
|
796
858
|
const NATURAL_CONVERSATION_COMMAND_NAMES = ["talk", "voice", "conversation"];
|
|
859
|
+
const CODEX_FAST_MODE_STATUS_KEY = "codex-fast-mode";
|
|
797
860
|
const REMOTE_WEBUI_CONTROLS_STATUS_KEY = "pi-remote-webui:controls";
|
|
798
861
|
const REMOTE_WEBUI_CONTROLS_PAYLOAD_TYPE = "firstpick.pi-package-remote-webui.controls";
|
|
799
862
|
const REMOTE_WEBUI_CONTROLS_PAYLOAD_VERSION = 1;
|
|
@@ -832,6 +895,7 @@ const FILE_VIEWER_WIDTH_MIN_PX = 384;
|
|
|
832
895
|
const SIDE_PANEL_WIDTH_STORAGE_KEY = "pi-webui-side-panel-width";
|
|
833
896
|
const SIDE_PANEL_WIDTH_DEFAULT_PX = 384;
|
|
834
897
|
const SIDE_PANEL_WIDTH_MIN_PX = 320;
|
|
898
|
+
const SIDE_PANEL_WIDTH_MAX_PX = 4096;
|
|
835
899
|
const FILE_VIEWER_CONTEXT_RADIUS_LINES = 6;
|
|
836
900
|
const FILE_TREE_ROOT_PATH = "";
|
|
837
901
|
const FILE_TREE_DRAG_MIME = "application/x-pi-webui-file-path";
|
|
@@ -865,7 +929,6 @@ const SUBAGENT_OPEN_MODES = new Set(["overlay", "tab"]);
|
|
|
865
929
|
const SUBAGENT_OPEN_MODE_LABELS = { overlay: "Overlay", tab: "Tab / terminal" };
|
|
866
930
|
const BUSY_PROMPT_BEHAVIOR_VALUES = new Set(["followUp", "steer"]);
|
|
867
931
|
const BUSY_PROMPT_BEHAVIOR_LABELS = { followUp: "Follow-up", steer: "Steer" };
|
|
868
|
-
const SKILL_TAG_MAX_VISIBLE = 6;
|
|
869
932
|
const SKILL_USAGE_LIMIT_PER_TAB = 32;
|
|
870
933
|
const MOBILE_VIEW_QUERY = "(max-width: 720px), (max-device-width: 720px), (pointer: coarse) and (hover: none)";
|
|
871
934
|
const SIDE_PANEL_OVERLAY_QUERY = "(max-width: 1050px), (max-device-width: 720px), (pointer: coarse) and (hover: none)";
|
|
@@ -962,6 +1025,7 @@ const optionalFeatureAvailability = {
|
|
|
962
1025
|
tuiToolsCommand: false,
|
|
963
1026
|
remoteWebui: false,
|
|
964
1027
|
naturalConversation: false,
|
|
1028
|
+
codexFastMode: false,
|
|
965
1029
|
themeBundle: false,
|
|
966
1030
|
};
|
|
967
1031
|
const APP_RUNNER_CONTEXT_DEFAULT_LINES = 80;
|
|
@@ -1080,6 +1144,13 @@ const OPTIONAL_FEATURES = [
|
|
|
1080
1144
|
capabilityLabel: "/stats",
|
|
1081
1145
|
description: "Token and cost usage analytics commands plus the browser dashboard overlay.",
|
|
1082
1146
|
},
|
|
1147
|
+
{
|
|
1148
|
+
id: "codexFastMode",
|
|
1149
|
+
label: "Codex Fast mode",
|
|
1150
|
+
packageName: "@firstpick/pi-extension-codex-fast-mode",
|
|
1151
|
+
capabilityLabel: "/fast-mode",
|
|
1152
|
+
description: "Session-scoped Codex subscription Fast mode selector in the Codex Usage panel. Spends extra subscription credits while enabled.",
|
|
1153
|
+
},
|
|
1083
1154
|
{
|
|
1084
1155
|
id: "themeBundle",
|
|
1085
1156
|
label: "Theme bundle",
|
|
@@ -1089,6 +1160,11 @@ const OPTIONAL_FEATURES = [
|
|
|
1089
1160
|
},
|
|
1090
1161
|
];
|
|
1091
1162
|
const OPTIONAL_FEATURE_BY_ID = new Map(OPTIONAL_FEATURES.map((feature) => [feature.id, feature]));
|
|
1163
|
+
// Optional features that arm a paid or stateful runtime mode must turn it off before the browser
|
|
1164
|
+
// stops managing them, so a stale mode can never keep spending credits after a Disable click.
|
|
1165
|
+
const OPTIONAL_FEATURE_DISABLE_PREREQUISITES = new Map([
|
|
1166
|
+
["codexFastMode", () => disableCodexFastModeIntegration()],
|
|
1167
|
+
]);
|
|
1092
1168
|
|
|
1093
1169
|
let issueWizardCatalog = null;
|
|
1094
1170
|
let issueWizardState = createIssueWizardState();
|
|
@@ -1532,6 +1608,7 @@ const OPTIONAL_COMMAND_FEATURES = new Map([
|
|
|
1532
1608
|
["git-footer-refresh", "gitFooterStatus"],
|
|
1533
1609
|
["git-footer-visibility", "gitFooterStatus"],
|
|
1534
1610
|
["todo-progress-status", "todoProgressWidget"],
|
|
1611
|
+
["fast-mode", "codexFastMode"],
|
|
1535
1612
|
]);
|
|
1536
1613
|
const HIDDEN_COMMAND_NAMES = new Set(["webui-tree-navigate", "webui-helper"]);
|
|
1537
1614
|
HIDDEN_COMMAND_NAMES.add("stats-webui");
|
|
@@ -1869,6 +1946,7 @@ function isInteractiveDropdownOpen() {
|
|
|
1869
1946
|
|| optionsMenuOpen
|
|
1870
1947
|
|| conversationVoiceMenuOpen
|
|
1871
1948
|
|| busyPromptBehaviorMenuOpen
|
|
1949
|
+
|| followUpQueueOpen
|
|
1872
1950
|
|| newTabMenuOpen
|
|
1873
1951
|
|| isFooterPickerOpen()
|
|
1874
1952
|
|| elements.commandSuggest?.hidden === false
|
|
@@ -2362,7 +2440,9 @@ function setSubagentOpenMode(mode, { persist = true, announce = false } = {}) {
|
|
|
2362
2440
|
subagentOpenMode = normalizeSubagentOpenMode(mode);
|
|
2363
2441
|
if (persist) persistSubagentOpenMode(subagentOpenMode);
|
|
2364
2442
|
renderSubagentOpenModeControl();
|
|
2443
|
+
const materializedTerminalViews = subagentOpenMode === "tab" && materializeRetainedSubagentTerminalViews();
|
|
2365
2444
|
renderSubagents();
|
|
2445
|
+
if (materializedTerminalViews) renderTabs();
|
|
2366
2446
|
if (announce) addEvent(`subagents now open in ${SUBAGENT_OPEN_MODE_LABELS[subagentOpenMode].toLowerCase()}`);
|
|
2367
2447
|
}
|
|
2368
2448
|
|
|
@@ -2433,6 +2513,384 @@ function persistTerminalCustomGroups() {
|
|
|
2433
2513
|
}
|
|
2434
2514
|
}
|
|
2435
2515
|
|
|
2516
|
+
function workspaceGroupsForSave() {
|
|
2517
|
+
const liveTabIds = new Set(tabs.map((tab) => tab.id).filter(Boolean));
|
|
2518
|
+
return [...terminalCustomGroups.values()].map((group) => ({
|
|
2519
|
+
title: normalizeTerminalCustomGroupTitle(group.title),
|
|
2520
|
+
tabIds: normalizeTerminalCustomGroupTabIds(group.tabIds).filter((tabId) => liveTabIds.has(tabId)),
|
|
2521
|
+
})).filter((group) => group.tabIds.length >= 2);
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
function workspaceDefaultName() {
|
|
2525
|
+
const cwd = String(activeTab()?.cwd || tabs[0]?.cwd || "workspace").replace(/[\\/]+$/, "");
|
|
2526
|
+
const base = cwd.split(/[\\/]/).pop() || "workspace";
|
|
2527
|
+
return `${base} ${new Date().toISOString().slice(0, 10)}`;
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
function setSavedWorkspaces(workspaces) {
|
|
2531
|
+
savedWorkspaces = Array.isArray(workspaces) ? workspaces.filter((workspace) => workspace?.id && workspace?.name) : [];
|
|
2532
|
+
savedWorkspacesLoaded = true;
|
|
2533
|
+
savedWorkspacesError = "";
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
async function refreshSavedWorkspaces({ force = false } = {}) {
|
|
2537
|
+
if (!force && savedWorkspacesLoaded) return savedWorkspaces;
|
|
2538
|
+
if (savedWorkspacesRefreshPromise) return savedWorkspacesRefreshPromise;
|
|
2539
|
+
savedWorkspacesLoading = true;
|
|
2540
|
+
savedWorkspacesError = "";
|
|
2541
|
+
renderWorkspaceDashboard();
|
|
2542
|
+
savedWorkspacesRefreshPromise = api("/api/workspaces", { scoped: false })
|
|
2543
|
+
.then((response) => {
|
|
2544
|
+
setSavedWorkspaces(response.data?.workspaces);
|
|
2545
|
+
return savedWorkspaces;
|
|
2546
|
+
})
|
|
2547
|
+
.catch((error) => {
|
|
2548
|
+
savedWorkspacesError = error.message || String(error);
|
|
2549
|
+
throw error;
|
|
2550
|
+
})
|
|
2551
|
+
.finally(() => {
|
|
2552
|
+
savedWorkspacesLoading = false;
|
|
2553
|
+
savedWorkspacesRefreshPromise = null;
|
|
2554
|
+
renderWorkspaceDashboard();
|
|
2555
|
+
});
|
|
2556
|
+
return savedWorkspacesRefreshPromise;
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
function installLoadedWorkspaceGroups(groups, idMap = {}) {
|
|
2560
|
+
const liveTabIds = new Set(tabs.map((tab) => tab.id).filter(Boolean));
|
|
2561
|
+
const claimedTabIds = new Set();
|
|
2562
|
+
terminalCustomGroups = new Map();
|
|
2563
|
+
terminalCustomGroupSerial = 1;
|
|
2564
|
+
for (const savedGroup of Array.isArray(groups) ? groups : []) {
|
|
2565
|
+
const tabIds = normalizeTerminalCustomGroupTabIds(savedGroup?.tabIds)
|
|
2566
|
+
.map((tabId) => idMap?.[tabId] || tabId)
|
|
2567
|
+
.filter((tabId) => liveTabIds.has(tabId) && !claimedTabIds.has(tabId));
|
|
2568
|
+
if (tabIds.length < 2) continue;
|
|
2569
|
+
for (const tabId of tabIds) claimedTabIds.add(tabId);
|
|
2570
|
+
let id = nextTerminalCustomGroupId();
|
|
2571
|
+
while (terminalCustomGroups.has(id)) id = nextTerminalCustomGroupId();
|
|
2572
|
+
terminalCustomGroups.set(id, {
|
|
2573
|
+
id,
|
|
2574
|
+
title: normalizeTerminalCustomGroupTitle(savedGroup?.title, `Group ${terminalCustomGroups.size + 1}`),
|
|
2575
|
+
tabIds,
|
|
2576
|
+
});
|
|
2577
|
+
}
|
|
2578
|
+
persistTerminalCustomGroups();
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
function workspaceRestoreSummary(restoredCount, warnings) {
|
|
2582
|
+
const restored = `${restoredCount} tab${restoredCount === 1 ? "" : "s"} restored`;
|
|
2583
|
+
if (!warnings.length) return restored;
|
|
2584
|
+
return `${restored}; ${warnings.length} warning${warnings.length === 1 ? "" : "s"}`;
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
async function hydrateLoadedWorkspaceActiveTab(requestedTabId) {
|
|
2588
|
+
const targetTabId = requestedTabId && tabs.some((tab) => tab.id === requestedTabId) ? requestedTabId : tabs[0]?.id || null;
|
|
2589
|
+
if (!targetTabId) return;
|
|
2590
|
+
if (targetTabId !== activeTabId) {
|
|
2591
|
+
await switchTab(targetTabId);
|
|
2592
|
+
return;
|
|
2593
|
+
}
|
|
2594
|
+
const tabContext = setActiveTabId(targetTabId, { remember: true });
|
|
2595
|
+
resetActiveTabUi();
|
|
2596
|
+
renderTabs();
|
|
2597
|
+
restoreActiveDraft();
|
|
2598
|
+
focusPromptInput({ defer: true });
|
|
2599
|
+
connectEvents(tabContext);
|
|
2600
|
+
await refreshAll(tabContext);
|
|
2601
|
+
if (isCurrentTabContext(tabContext)) markTabOutputSeen();
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
async function saveWebuiWorkspace({ triggerButton = elements.workspaceSaveButton } = {}) {
|
|
2605
|
+
if (!tabs.length) return;
|
|
2606
|
+
const promptedName = window.prompt("Save workspace as:", workspaceDefaultName());
|
|
2607
|
+
if (promptedName === null) return;
|
|
2608
|
+
const body = {
|
|
2609
|
+
name: promptedName.trim() || workspaceDefaultName(),
|
|
2610
|
+
groups: workspaceGroupsForSave(),
|
|
2611
|
+
activeTabId,
|
|
2612
|
+
};
|
|
2613
|
+
const controls = new Set([elements.workspaceSaveButton, triggerButton].filter(Boolean));
|
|
2614
|
+
for (const control of controls) control.disabled = true;
|
|
2615
|
+
try {
|
|
2616
|
+
let response;
|
|
2617
|
+
try {
|
|
2618
|
+
response = await api("/api/workspaces", { method: "POST", body, scoped: false });
|
|
2619
|
+
} catch (error) {
|
|
2620
|
+
if (error.statusCode !== 409) throw error;
|
|
2621
|
+
const overwrite = await appConfirm({
|
|
2622
|
+
title: "Overwrite saved workspace?",
|
|
2623
|
+
summary: `A workspace named “${body.name || workspaceDefaultName()}” already exists.`,
|
|
2624
|
+
affected: "The existing saved workspace will be replaced with the current tabs and groups.",
|
|
2625
|
+
confirmLabel: "Overwrite",
|
|
2626
|
+
});
|
|
2627
|
+
if (!overwrite) return;
|
|
2628
|
+
response = await api("/api/workspaces", { method: "POST", body: { ...body, overwrite: true }, scoped: false });
|
|
2629
|
+
}
|
|
2630
|
+
const data = response.data || {};
|
|
2631
|
+
setSavedWorkspaces(data.workspaces);
|
|
2632
|
+
const saved = data.workspace;
|
|
2633
|
+
const evicted = Array.isArray(data.evicted) ? data.evicted : [];
|
|
2634
|
+
const message = `Saved workspace ${saved?.name || "workspace"} (${saved?.tabCount || tabs.length} tabs).`;
|
|
2635
|
+
settleUndoToast(evicted.length ? `${message} Oldest saved workspace removed.` : message);
|
|
2636
|
+
addEvent(message, "success");
|
|
2637
|
+
if (evicted.length) addEvent(`Removed ${evicted.length} oldest saved workspace${evicted.length === 1 ? "" : "s"} to keep the saved-workspace limit.`, "warn");
|
|
2638
|
+
} catch (error) {
|
|
2639
|
+
const message = `Could not save workspace: ${error.message || String(error)}`;
|
|
2640
|
+
settleUndoToast(message, { error: true, timeoutMs: 7000 });
|
|
2641
|
+
addEvent(message, "error");
|
|
2642
|
+
} finally {
|
|
2643
|
+
for (const control of controls) control.disabled = control === elements.workspaceSaveButton ? tabs.length === 0 : false;
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
function renderWorkspaceLoadDialog() {
|
|
2648
|
+
const list = elements.workspaceLoadDialogList;
|
|
2649
|
+
const status = elements.workspaceLoadDialogStatus;
|
|
2650
|
+
if (!list || !status) return;
|
|
2651
|
+
list.replaceChildren();
|
|
2652
|
+
if (savedWorkspacesLoading) {
|
|
2653
|
+
status.textContent = "Loading saved workspaces…";
|
|
2654
|
+
return;
|
|
2655
|
+
}
|
|
2656
|
+
if (savedWorkspacesError) {
|
|
2657
|
+
status.textContent = `Could not load saved workspaces: ${savedWorkspacesError}`;
|
|
2658
|
+
const retry = make("button", "workspace-load-dialog-retry", "Retry");
|
|
2659
|
+
retry.type = "button";
|
|
2660
|
+
retry.addEventListener("click", () => refreshWorkspaceLoadDialog());
|
|
2661
|
+
list.append(retry);
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
2664
|
+
if (!savedWorkspaces.length) {
|
|
2665
|
+
status.textContent = tabs.length
|
|
2666
|
+
? "No saved workspaces yet. Use Save workspace to capture the current tabs."
|
|
2667
|
+
: "No saved workspaces yet. Open tabs, then use Save workspace.";
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
status.textContent = `${savedWorkspaces.length} saved workspace${savedWorkspaces.length === 1 ? "" : "s"} available.`;
|
|
2671
|
+
for (const workspace of savedWorkspaces) {
|
|
2672
|
+
const row = make("article", "workspace-load-dialog-item");
|
|
2673
|
+
const copy = make("div", "workspace-load-dialog-item-copy");
|
|
2674
|
+
const title = make("strong", "workspace-load-dialog-item-name", workspace.name);
|
|
2675
|
+
title.title = workspace.name;
|
|
2676
|
+
const detail = [
|
|
2677
|
+
formatDate(workspace.savedAt),
|
|
2678
|
+
`${workspace.tabCount || 0} tab${workspace.tabCount === 1 ? "" : "s"}`,
|
|
2679
|
+
workspace.groupCount ? `${workspace.groupCount} group${workspace.groupCount === 1 ? "" : "s"}` : "",
|
|
2680
|
+
Array.isArray(workspace.cwds) && workspace.cwds.length ? normalizeDisplayPath(workspace.cwds[0]) : "",
|
|
2681
|
+
].filter(Boolean).join(" · ");
|
|
2682
|
+
copy.append(title, make("span", "workspace-load-dialog-item-detail", detail));
|
|
2683
|
+
const actions = make("div", "workspace-load-dialog-item-actions");
|
|
2684
|
+
const load = make("button", "workspace-load-dialog-item-load primary", "Load");
|
|
2685
|
+
load.type = "button";
|
|
2686
|
+
load.setAttribute("aria-label", `Load workspace ${workspace.name}`);
|
|
2687
|
+
load.addEventListener("click", async () => {
|
|
2688
|
+
const focusReturn = workspaceLoadPickerFocusReturn;
|
|
2689
|
+
closeWorkspaceLoadDialog({ restoreFocus: false });
|
|
2690
|
+
const result = await loadWebuiWorkspace(workspace.id, { triggerButton: load });
|
|
2691
|
+
if (result === "cancelled") await openWorkspaceLoadPicker({ triggerButton: focusReturn });
|
|
2692
|
+
else if (result === "error" && focusReturn instanceof HTMLElement && focusReturn.isConnected) focusReturn.focus({ preventScroll: true });
|
|
2693
|
+
});
|
|
2694
|
+
const remove = make("button", "workspace-load-dialog-item-delete danger", "Delete");
|
|
2695
|
+
remove.type = "button";
|
|
2696
|
+
remove.setAttribute("aria-label", `Delete workspace ${workspace.name}`);
|
|
2697
|
+
remove.addEventListener("click", async () => {
|
|
2698
|
+
if (!(await deleteWebuiWorkspace(workspace))) return;
|
|
2699
|
+
renderWorkspaceLoadDialog();
|
|
2700
|
+
queueMicrotask(() => elements.workspaceLoadDialogCloseButton?.focus({ preventScroll: true }));
|
|
2701
|
+
});
|
|
2702
|
+
actions.append(load, remove);
|
|
2703
|
+
row.append(copy, actions);
|
|
2704
|
+
list.append(row);
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
async function refreshWorkspaceLoadDialog() {
|
|
2709
|
+
const refresh = refreshSavedWorkspaces({ force: true });
|
|
2710
|
+
renderWorkspaceLoadDialog();
|
|
2711
|
+
try {
|
|
2712
|
+
await refresh;
|
|
2713
|
+
} catch {
|
|
2714
|
+
// The picker renders the saved error state from refreshSavedWorkspaces.
|
|
2715
|
+
}
|
|
2716
|
+
renderWorkspaceLoadDialog();
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
function closeWorkspaceLoadDialog({ restoreFocus = true } = {}) {
|
|
2720
|
+
const dialog = elements.workspaceLoadDialog;
|
|
2721
|
+
if (!restoreFocus) workspaceLoadPickerFocusReturn = null;
|
|
2722
|
+
if (dialog?.open) dialog.close();
|
|
2723
|
+
const target = workspaceLoadPickerFocusReturn;
|
|
2724
|
+
workspaceLoadPickerFocusReturn = null;
|
|
2725
|
+
if (restoreFocus && target instanceof HTMLElement && target.isConnected) queueMicrotask(() => target.focus());
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
async function openWorkspaceLoadPicker({ triggerButton = null } = {}) {
|
|
2729
|
+
const dialog = elements.workspaceLoadDialog;
|
|
2730
|
+
if (!dialog?.showModal) {
|
|
2731
|
+
setWorkspaceDashboardCollapsed(false, { persist: false });
|
|
2732
|
+
await refreshSavedWorkspaces({ force: true }).catch(() => {});
|
|
2733
|
+
return;
|
|
2734
|
+
}
|
|
2735
|
+
workspaceLoadPickerFocusReturn = triggerButton instanceof HTMLElement ? triggerButton : document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
2736
|
+
renderWorkspaceLoadDialog();
|
|
2737
|
+
if (!dialog.open) dialog.showModal();
|
|
2738
|
+
queueMicrotask(() => elements.workspaceLoadDialogCloseButton?.focus());
|
|
2739
|
+
await refreshWorkspaceLoadDialog();
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
function finishWorkspaceReplacement(choice = null) {
|
|
2743
|
+
const resolve = activeWorkspaceReplacementResolve;
|
|
2744
|
+
activeWorkspaceReplacementResolve = null;
|
|
2745
|
+
if (elements.workspaceReplaceDialog?.open) elements.workspaceReplaceDialog.close();
|
|
2746
|
+
resolve?.(choice);
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
function workspaceReplacementTabRow(tab) {
|
|
2750
|
+
const indicator = tabIndicator(tab);
|
|
2751
|
+
const item = make("li", `workspace-replace-current-tab activity-${indicator.state}`);
|
|
2752
|
+
const title = make("strong", "workspace-replace-current-tab-title", tab.title || "Untitled tab");
|
|
2753
|
+
const detail = [
|
|
2754
|
+
tab.id === activeTabId ? "Active" : "",
|
|
2755
|
+
indicator.label,
|
|
2756
|
+
normalizeDisplayPath(tab.cwd || ""),
|
|
2757
|
+
].filter(Boolean).join(" · ");
|
|
2758
|
+
item.append(title, make("span", "workspace-replace-current-tab-detail", detail));
|
|
2759
|
+
return item;
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
function workspaceSaveCurrentDecision(name = elements.workspaceReplaceSaveName?.value) {
|
|
2763
|
+
return {
|
|
2764
|
+
replaceOpenTabs: true,
|
|
2765
|
+
saveCurrent: {
|
|
2766
|
+
name: String(name || "").trim() || workspaceDefaultName(),
|
|
2767
|
+
groups: workspaceGroupsForSave(),
|
|
2768
|
+
activeTabId,
|
|
2769
|
+
},
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
function chooseWorkspaceReplacement(workspace) {
|
|
2774
|
+
if (!tabs.length) return Promise.resolve({});
|
|
2775
|
+
const dialog = elements.workspaceReplaceDialog;
|
|
2776
|
+
if (!dialog?.showModal) {
|
|
2777
|
+
const discard = window.confirm(`Loading ${workspace?.name || "this workspace"} will terminate ${tabs.length} current Pi process${tabs.length === 1 ? "" : "es"}. Choose OK to load without saving, or Cancel to save first.`);
|
|
2778
|
+
if (discard) return Promise.resolve({ replaceOpenTabs: true, discardCurrent: true });
|
|
2779
|
+
const name = window.prompt("Save current workspace as:", workspaceDefaultName());
|
|
2780
|
+
if (name === null) return Promise.resolve(null);
|
|
2781
|
+
return Promise.resolve(workspaceSaveCurrentDecision(name));
|
|
2782
|
+
}
|
|
2783
|
+
if (activeWorkspaceReplacementResolve) finishWorkspaceReplacement(null);
|
|
2784
|
+
if (elements.workspaceReplaceTargetName) elements.workspaceReplaceTargetName.textContent = workspace?.name || "this workspace";
|
|
2785
|
+
if (elements.workspaceReplaceCurrentTabsCount) elements.workspaceReplaceCurrentTabsCount.textContent = `${tabs.length} tab${tabs.length === 1 ? "" : "s"}`;
|
|
2786
|
+
elements.workspaceReplaceCurrentTabsList?.replaceChildren(...tabs.map(workspaceReplacementTabRow));
|
|
2787
|
+
if (elements.workspaceReplaceSaveName) elements.workspaceReplaceSaveName.value = workspaceDefaultName();
|
|
2788
|
+
if (elements.workspaceReplaceDialogStatus) elements.workspaceReplaceDialogStatus.textContent = "Cancel leaves every current tab unchanged.";
|
|
2789
|
+
return new Promise((resolve) => {
|
|
2790
|
+
activeWorkspaceReplacementResolve = resolve;
|
|
2791
|
+
dialog.showModal();
|
|
2792
|
+
queueMicrotask(() => elements.workspaceReplaceCancelButton?.focus());
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
function retireClosedWorkspaceTabContexts(closedIds) {
|
|
2797
|
+
const closed = new Set(Array.isArray(closedIds) ? closedIds.filter((id) => typeof id === "string" && id) : []);
|
|
2798
|
+
if (!closed.size) return;
|
|
2799
|
+
tabs = tabs.filter((tab) => !closed.has(tab.id));
|
|
2800
|
+
syncTabMetadata(tabs);
|
|
2801
|
+
for (const id of closed) {
|
|
2802
|
+
tabDrafts.delete(id);
|
|
2803
|
+
clearAttachments(id);
|
|
2804
|
+
fileViewersByTab.delete(id);
|
|
2805
|
+
fileViewerSelectionsByTab.delete(id);
|
|
2806
|
+
btwWidgetDismissedIdsByTab.delete(id);
|
|
2807
|
+
removeSubagentTerminalViewsForParent(id);
|
|
2808
|
+
}
|
|
2809
|
+
syncTerminalCustomGroupsWithTabs(tabs);
|
|
2810
|
+
clearOpenTerminalTabGroup(null, { force: true });
|
|
2811
|
+
if (closed.has(activeTabId)) setActiveTabId(null, { remember: true });
|
|
2812
|
+
}
|
|
2813
|
+
|
|
2814
|
+
async function loadWebuiWorkspace(workspaceId, { triggerButton = null } = {}) {
|
|
2815
|
+
const decision = await chooseWorkspaceReplacement(savedWorkspaces.find((workspace) => workspace.id === workspaceId));
|
|
2816
|
+
if (decision === null) return "cancelled";
|
|
2817
|
+
const controls = new Set([triggerButton].filter(Boolean));
|
|
2818
|
+
for (const control of controls) control.disabled = true;
|
|
2819
|
+
try {
|
|
2820
|
+
let response;
|
|
2821
|
+
try {
|
|
2822
|
+
response = await api(`/api/workspaces/${encodeURIComponent(workspaceId)}/load`, {
|
|
2823
|
+
method: "POST",
|
|
2824
|
+
...(Object.keys(decision).length ? { body: decision } : {}),
|
|
2825
|
+
scoped: false,
|
|
2826
|
+
});
|
|
2827
|
+
} catch (error) {
|
|
2828
|
+
const saveCurrent = decision.saveCurrent;
|
|
2829
|
+
if (!saveCurrent || error.statusCode !== 409 || !/workspace with that name already exists/i.test(error.message || "")) throw error;
|
|
2830
|
+
const overwrite = await appConfirm({
|
|
2831
|
+
title: "Overwrite saved workspace?",
|
|
2832
|
+
summary: `A workspace named “${saveCurrent.name || workspaceDefaultName()}” already exists.`,
|
|
2833
|
+
affected: "The existing saved workspace will be replaced before the current tabs are closed.",
|
|
2834
|
+
confirmLabel: "Overwrite & load",
|
|
2835
|
+
});
|
|
2836
|
+
if (!overwrite) return "cancelled";
|
|
2837
|
+
response = await api(`/api/workspaces/${encodeURIComponent(workspaceId)}/load`, {
|
|
2838
|
+
method: "POST",
|
|
2839
|
+
body: { ...decision, saveCurrent: { ...saveCurrent, overwrite: true } },
|
|
2840
|
+
scoped: false,
|
|
2841
|
+
});
|
|
2842
|
+
}
|
|
2843
|
+
const data = response.data || {};
|
|
2844
|
+
const closedIds = Array.isArray(data.closedIds) ? data.closedIds : [];
|
|
2845
|
+
retireClosedWorkspaceTabContexts(closedIds);
|
|
2846
|
+
if (Array.isArray(data.savedCurrent?.workspaces)) setSavedWorkspaces(data.savedCurrent.workspaces);
|
|
2847
|
+
const evicted = Array.isArray(data.savedCurrent?.evicted) ? data.savedCurrent.evicted : [];
|
|
2848
|
+
if (evicted.length) addEvent(`Removed ${evicted.length} oldest saved workspace${evicted.length === 1 ? "" : "s"} to keep the saved-workspace limit.`, "warn");
|
|
2849
|
+
await refreshTabs();
|
|
2850
|
+
installLoadedWorkspaceGroups(data.groups, data.idMap);
|
|
2851
|
+
await hydrateLoadedWorkspaceActiveTab(data.activeTabId);
|
|
2852
|
+
const warnings = Array.isArray(data.warnings) ? data.warnings : [];
|
|
2853
|
+
const restoredCount = Array.isArray(data.tabs) ? data.tabs.length : tabs.length;
|
|
2854
|
+
const replacement = closedIds.length ? `Replaced ${closedIds.length} current tab${closedIds.length === 1 ? "" : "s"}; ` : "";
|
|
2855
|
+
const message = `${replacement}${workspaceRestoreSummary(restoredCount, warnings)}`;
|
|
2856
|
+
settleUndoToast(message, { error: warnings.length > 0, timeoutMs: warnings.length ? 7000 : 3500 });
|
|
2857
|
+
addEvent(message, warnings.length ? "warn" : "success");
|
|
2858
|
+
for (const warning of warnings) addEvent(`Workspace restore: ${warning.message || "A saved tab could not be fully restored."}`, "warn");
|
|
2859
|
+
return "loaded";
|
|
2860
|
+
} catch (error) {
|
|
2861
|
+
const message = `Could not load workspace: ${error.message || String(error)}`;
|
|
2862
|
+
settleUndoToast(message, { error: true, timeoutMs: 7000 });
|
|
2863
|
+
addEvent(message, "error");
|
|
2864
|
+
return "error";
|
|
2865
|
+
} finally {
|
|
2866
|
+
for (const control of controls) control.disabled = false;
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
async function deleteWebuiWorkspace(workspace) {
|
|
2871
|
+
if (!workspace?.id) return false;
|
|
2872
|
+
const confirmed = await appConfirm({
|
|
2873
|
+
title: "Delete saved workspace?",
|
|
2874
|
+
summary: `Delete “${workspace.name}” from the saved workspace list?`,
|
|
2875
|
+
affected: "The saved tab constellation will be permanently removed; open tabs are unchanged.",
|
|
2876
|
+
confirmLabel: "Delete",
|
|
2877
|
+
});
|
|
2878
|
+
if (!confirmed) return false;
|
|
2879
|
+
try {
|
|
2880
|
+
const response = await api(`/api/workspaces/${encodeURIComponent(workspace.id)}`, { method: "DELETE", scoped: false });
|
|
2881
|
+
setSavedWorkspaces(response.data?.workspaces);
|
|
2882
|
+
const message = `Deleted saved workspace ${workspace.name}.`;
|
|
2883
|
+
settleUndoToast(message);
|
|
2884
|
+
addEvent(message, "success");
|
|
2885
|
+
return true;
|
|
2886
|
+
} catch (error) {
|
|
2887
|
+
const message = `Could not delete workspace: ${error.message || String(error)}`;
|
|
2888
|
+
settleUndoToast(message, { error: true, timeoutMs: 7000 });
|
|
2889
|
+
addEvent(message, "error");
|
|
2890
|
+
return false;
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2436
2894
|
function terminalCustomGroupByTabId() {
|
|
2437
2895
|
const map = new Map();
|
|
2438
2896
|
for (const [groupId, group] of terminalCustomGroups) {
|
|
@@ -2822,6 +3280,74 @@ function skillKindsLabel(entry) {
|
|
|
2822
3280
|
return entry?.kinds?.has("read") ? "context read" : "tracked";
|
|
2823
3281
|
}
|
|
2824
3282
|
|
|
3283
|
+
let sessionSkillTagLayoutFrame = 0;
|
|
3284
|
+
let sessionSkillTagResizeObserver = null;
|
|
3285
|
+
|
|
3286
|
+
function fitSessionSkillTags() {
|
|
3287
|
+
const container = elements.sessionSkillTags;
|
|
3288
|
+
if (!container || container.hidden) return;
|
|
3289
|
+
const tags = [...container.querySelectorAll("button.composer-skill-tag")];
|
|
3290
|
+
const overflow = container.querySelector(".composer-skill-tag.overflow");
|
|
3291
|
+
if (!tags.length || !overflow) return;
|
|
3292
|
+
|
|
3293
|
+
const availableWidth = container.clientWidth;
|
|
3294
|
+
if (availableWidth <= 0) return;
|
|
3295
|
+
|
|
3296
|
+
for (const tag of tags) tag.hidden = false;
|
|
3297
|
+
overflow.hidden = false;
|
|
3298
|
+
|
|
3299
|
+
const containerStyle = getComputedStyle(container);
|
|
3300
|
+
const gap = Number.parseFloat(containerStyle.columnGap || containerStyle.gap) || 0;
|
|
3301
|
+
const tagWidths = tags.map((tag) => tag.getBoundingClientRect().width);
|
|
3302
|
+
const overflowWidths = new Map();
|
|
3303
|
+
const maxOverflowDigits = String(tags.length).length;
|
|
3304
|
+
for (let digits = 1; digits <= maxOverflowDigits; digits += 1) {
|
|
3305
|
+
overflow.textContent = `+${"0".repeat(digits)}`;
|
|
3306
|
+
overflowWidths.set(digits, overflow.getBoundingClientRect().width);
|
|
3307
|
+
}
|
|
3308
|
+
let visibleCount = 0;
|
|
3309
|
+
|
|
3310
|
+
for (let count = tags.length; count >= 0; count -= 1) {
|
|
3311
|
+
const hiddenCount = tags.length - count;
|
|
3312
|
+
const itemCount = count + (hiddenCount ? 1 : 0);
|
|
3313
|
+
const tagsWidth = tagWidths.slice(0, count).reduce((total, width) => total + width, 0);
|
|
3314
|
+
const overflowWidth = hiddenCount ? overflowWidths.get(String(hiddenCount).length) || 0 : 0;
|
|
3315
|
+
const requiredWidth = tagsWidth + overflowWidth + Math.max(0, itemCount - 1) * gap;
|
|
3316
|
+
if (requiredWidth <= availableWidth + 0.5) {
|
|
3317
|
+
visibleCount = count;
|
|
3318
|
+
break;
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
|
|
3322
|
+
tags.forEach((tag, index) => { tag.hidden = index >= visibleCount; });
|
|
3323
|
+
const hiddenCount = tags.length - visibleCount;
|
|
3324
|
+
overflow.hidden = hiddenCount === 0;
|
|
3325
|
+
if (hiddenCount) {
|
|
3326
|
+
overflow.textContent = `+${hiddenCount}`;
|
|
3327
|
+
overflow.title = `${hiddenCount} more tracked skill${hiddenCount === 1 ? "" : "s"}.`;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
function scheduleSessionSkillTagLayout() {
|
|
3332
|
+
if (sessionSkillTagLayoutFrame) return;
|
|
3333
|
+
sessionSkillTagLayoutFrame = requestAnimationFrame(() => {
|
|
3334
|
+
sessionSkillTagLayoutFrame = 0;
|
|
3335
|
+
fitSessionSkillTags();
|
|
3336
|
+
});
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
function installSessionSkillTagResizeHandling() {
|
|
3340
|
+
const container = elements.sessionSkillTags;
|
|
3341
|
+
if (!container) return;
|
|
3342
|
+
if (typeof ResizeObserver === "function") {
|
|
3343
|
+
sessionSkillTagResizeObserver = new ResizeObserver(scheduleSessionSkillTagLayout);
|
|
3344
|
+
sessionSkillTagResizeObserver.observe(container);
|
|
3345
|
+
if (container.parentElement) sessionSkillTagResizeObserver.observe(container.parentElement);
|
|
3346
|
+
} else {
|
|
3347
|
+
window.addEventListener("resize", scheduleSessionSkillTagLayout, { passive: true });
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
|
|
2825
3351
|
function renderSessionSkillTags(tabId = activeTabId) {
|
|
2826
3352
|
const container = elements.sessionSkillTags;
|
|
2827
3353
|
if (!container) return;
|
|
@@ -2831,8 +3357,7 @@ function renderSessionSkillTags(tabId = activeTabId) {
|
|
|
2831
3357
|
container.hidden = true;
|
|
2832
3358
|
return;
|
|
2833
3359
|
}
|
|
2834
|
-
const
|
|
2835
|
-
for (const entry of visible) {
|
|
3360
|
+
for (const entry of entries) {
|
|
2836
3361
|
const classes = ["composer-skill-tag", "read"];
|
|
2837
3362
|
const tag = make("button", classes.join(" "), entry.name);
|
|
2838
3363
|
tag.type = "button";
|
|
@@ -2843,12 +3368,11 @@ function renderSessionSkillTags(tabId = activeTabId) {
|
|
|
2843
3368
|
tag.addEventListener("click", () => openSkillEditor(entry));
|
|
2844
3369
|
container.append(tag);
|
|
2845
3370
|
}
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
container.append(overflow);
|
|
2850
|
-
}
|
|
3371
|
+
const overflow = make("span", "composer-skill-tag overflow", `+${entries.length}`);
|
|
3372
|
+
overflow.hidden = true;
|
|
3373
|
+
container.append(overflow);
|
|
2851
3374
|
container.hidden = false;
|
|
3375
|
+
scheduleSessionSkillTagLayout();
|
|
2852
3376
|
}
|
|
2853
3377
|
|
|
2854
3378
|
function normalizeFeatureCategory(value) {
|
|
@@ -3096,6 +3620,7 @@ function renderBusyPromptBehaviorTag() {
|
|
|
3096
3620
|
}
|
|
3097
3621
|
|
|
3098
3622
|
function setBusyPromptBehaviorMenuOpen(open, { focusCurrent = false } = {}) {
|
|
3623
|
+
if (open && followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
3099
3624
|
busyPromptBehaviorMenuOpen = !!open;
|
|
3100
3625
|
elements.busyPromptBehaviorTag?.setAttribute("aria-expanded", busyPromptBehaviorMenuOpen ? "true" : "false");
|
|
3101
3626
|
elements.busyPromptBehaviorTag?.classList.toggle("menu-open", busyPromptBehaviorMenuOpen);
|
|
@@ -3164,6 +3689,7 @@ async function refreshNativeSettings(tabContext = activeTabContext()) {
|
|
|
3164
3689
|
|
|
3165
3690
|
function setComposerActionsOpen(open) {
|
|
3166
3691
|
const shouldOpen = open && isMobileView();
|
|
3692
|
+
if (shouldOpen && followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
3167
3693
|
document.body.classList.toggle("composer-actions-open", shouldOpen);
|
|
3168
3694
|
elements.composerActionsButton.setAttribute("aria-expanded", shouldOpen ? "true" : "false");
|
|
3169
3695
|
if (!shouldOpen) {
|
|
@@ -4925,17 +5451,18 @@ function isFileDrag(event) {
|
|
|
4925
5451
|
}
|
|
4926
5452
|
|
|
4927
5453
|
function handleComposerDragOver(event) {
|
|
4928
|
-
if (!isFileDrag(event)) return;
|
|
5454
|
+
if (event.target?.closest?.("#followUpQueueOverlay") || !isFileDrag(event)) return;
|
|
4929
5455
|
event.preventDefault();
|
|
4930
5456
|
elements.composer.classList.add("drag-over");
|
|
4931
5457
|
}
|
|
4932
5458
|
|
|
4933
5459
|
function handleComposerDragLeave(event) {
|
|
5460
|
+
if (event.target?.closest?.("#followUpQueueOverlay")) return;
|
|
4934
5461
|
if (!elements.composer.contains(event.relatedTarget)) elements.composer.classList.remove("drag-over");
|
|
4935
5462
|
}
|
|
4936
5463
|
|
|
4937
5464
|
function handleComposerDrop(event) {
|
|
4938
|
-
if (!isFileDrag(event)) return;
|
|
5465
|
+
if (event.target?.closest?.("#followUpQueueOverlay") || !isFileDrag(event)) return;
|
|
4939
5466
|
event.preventDefault();
|
|
4940
5467
|
elements.composer.classList.remove("drag-over");
|
|
4941
5468
|
addAttachmentFiles(event.dataTransfer?.files, "drop");
|
|
@@ -5744,6 +6271,7 @@ let conversationVoicePending = null;
|
|
|
5744
6271
|
// panel (hover/focus-within still work on desktop via CSS), so it also works
|
|
5745
6272
|
// on touch devices where :hover never fires.
|
|
5746
6273
|
function setConversationVoiceMenuOpen(open) {
|
|
6274
|
+
if (open && followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
5747
6275
|
conversationVoiceMenuOpen = !!open;
|
|
5748
6276
|
elements.conversationVoiceButton?.setAttribute("aria-expanded", conversationVoiceMenuOpen ? "true" : "false");
|
|
5749
6277
|
elements.conversationVoiceButton?.classList.toggle("menu-open", conversationVoiceMenuOpen);
|
|
@@ -6366,6 +6894,16 @@ function setOptionalFeatureDisabled(featureId, disabled) {
|
|
|
6366
6894
|
statusEntries.delete(NATURAL_CONVERSATION_STATUS_KEY);
|
|
6367
6895
|
updateConversationModeForTab(activeTabId, { available: false, enabled: false, uiState: "off", statusText: "" }, { render: false });
|
|
6368
6896
|
}
|
|
6897
|
+
if (featureId === "codexFastMode") {
|
|
6898
|
+
if (disabled) {
|
|
6899
|
+
statusEntries.delete(CODEX_FAST_MODE_STATUS_KEY);
|
|
6900
|
+
codexFastModeState = { ...codexFastModeState, available: false, enabled: false, statusKnown: false, busy: false };
|
|
6901
|
+
codexFastModeNotice = "";
|
|
6902
|
+
renderCodexFastModeControl();
|
|
6903
|
+
} else {
|
|
6904
|
+
refreshCodexFastMode().catch(() => null);
|
|
6905
|
+
}
|
|
6906
|
+
}
|
|
6369
6907
|
storeDisabledOptionalFeatures();
|
|
6370
6908
|
renderOptionalFeatureDependentDisplays();
|
|
6371
6909
|
const tabContext = activeTabContext();
|
|
@@ -7633,6 +8171,7 @@ function updateActiveFileViewerAfterMove(sourcePath = "", destinationPath = "")
|
|
|
7633
8171
|
gitChanges: null,
|
|
7634
8172
|
};
|
|
7635
8173
|
if (fileViewerSelection) fileViewerSelection = { ...fileViewerSelection, path: nextPath, fileName: activeFileViewer.name };
|
|
8174
|
+
cacheActiveFileViewerForTab();
|
|
7636
8175
|
updateFileViewerUi();
|
|
7637
8176
|
}
|
|
7638
8177
|
|
|
@@ -7767,20 +8306,31 @@ async function moveFileTreeEntry(entry = fileContextMenuState?.entry) {
|
|
|
7767
8306
|
function readStoredSidePanelWidth() {
|
|
7768
8307
|
try {
|
|
7769
8308
|
const width = Number.parseFloat(localStorage.getItem(SIDE_PANEL_WIDTH_STORAGE_KEY) || "");
|
|
7770
|
-
return Number.isFinite(width) && width >= SIDE_PANEL_WIDTH_MIN_PX ? width : null;
|
|
8309
|
+
return Number.isFinite(width) && width >= SIDE_PANEL_WIDTH_MIN_PX && width <= SIDE_PANEL_WIDTH_MAX_PX ? width : null;
|
|
7771
8310
|
} catch {
|
|
7772
8311
|
return null;
|
|
7773
8312
|
}
|
|
7774
8313
|
}
|
|
7775
8314
|
|
|
7776
|
-
function
|
|
8315
|
+
function cacheSidePanelWidth(width) {
|
|
7777
8316
|
try {
|
|
7778
8317
|
localStorage.setItem(SIDE_PANEL_WIDTH_STORAGE_KEY, String(Math.round(width)));
|
|
7779
8318
|
} catch {
|
|
7780
|
-
//
|
|
8319
|
+
// Browser storage is only a local fallback for the user-scoped preference.
|
|
7781
8320
|
}
|
|
7782
8321
|
}
|
|
7783
8322
|
|
|
8323
|
+
function persistSidePanelWidth(width) {
|
|
8324
|
+
const rounded = Math.round(width);
|
|
8325
|
+
sidePanelWidthPreferenceRevision += 1;
|
|
8326
|
+
cacheSidePanelWidth(rounded);
|
|
8327
|
+
api("/api/interface-preferences", {
|
|
8328
|
+
method: "PUT",
|
|
8329
|
+
body: { sidePanelWidth: rounded },
|
|
8330
|
+
scoped: false,
|
|
8331
|
+
}).catch((error) => addEvent(`Could not save Control Deck width for this user: ${error.message || String(error)}`, "warn"));
|
|
8332
|
+
}
|
|
8333
|
+
|
|
7784
8334
|
function sidePanelMaxWidth() {
|
|
7785
8335
|
const layout = document.querySelector(".layout");
|
|
7786
8336
|
const layoutRect = layout?.getBoundingClientRect?.();
|
|
@@ -7829,11 +8379,28 @@ function applySidePanelWidth(width, { persist = false } = {}) {
|
|
|
7829
8379
|
return clamped;
|
|
7830
8380
|
}
|
|
7831
8381
|
|
|
7832
|
-
function restoreSidePanelWidthPreference() {
|
|
7833
|
-
const
|
|
7834
|
-
if (
|
|
7835
|
-
if (!isSidePanelOverlayView()) applySidePanelWidth(
|
|
7836
|
-
else updateSidePanelResizeHandle(
|
|
8382
|
+
async function restoreSidePanelWidthPreference() {
|
|
8383
|
+
const localWidth = readStoredSidePanelWidth();
|
|
8384
|
+
if (localWidth) document.documentElement.style.setProperty("--side-panel-width", `${Math.round(localWidth)}px`);
|
|
8385
|
+
if (!isSidePanelOverlayView()) applySidePanelWidth(localWidth || SIDE_PANEL_WIDTH_DEFAULT_PX);
|
|
8386
|
+
else updateSidePanelResizeHandle(localWidth || SIDE_PANEL_WIDTH_DEFAULT_PX);
|
|
8387
|
+
|
|
8388
|
+
const restoreRevision = sidePanelWidthPreferenceRevision;
|
|
8389
|
+
try {
|
|
8390
|
+
const response = await api("/api/interface-preferences", { scoped: false });
|
|
8391
|
+
if (restoreRevision !== sidePanelWidthPreferenceRevision) return;
|
|
8392
|
+
const userWidth = Number(response.data?.preferences?.sidePanelWidth);
|
|
8393
|
+
if (Number.isFinite(userWidth) && userWidth >= SIDE_PANEL_WIDTH_MIN_PX) {
|
|
8394
|
+
cacheSidePanelWidth(userWidth);
|
|
8395
|
+
document.documentElement.style.setProperty("--side-panel-width", `${Math.round(userWidth)}px`);
|
|
8396
|
+
if (!isSidePanelOverlayView()) applySidePanelWidth(userWidth);
|
|
8397
|
+
else updateSidePanelResizeHandle(userWidth);
|
|
8398
|
+
} else if (localWidth) {
|
|
8399
|
+
persistSidePanelWidth(localWidth);
|
|
8400
|
+
}
|
|
8401
|
+
} catch {
|
|
8402
|
+
// Keep the browser-local fallback when user settings cannot be loaded.
|
|
8403
|
+
}
|
|
7837
8404
|
}
|
|
7838
8405
|
|
|
7839
8406
|
function beginSidePanelResize(event) {
|
|
@@ -8052,6 +8619,10 @@ function setFileViewerMode(mode = "source") {
|
|
|
8052
8619
|
activeFileViewer.mode = resolveFileViewerMode({ ...activeFileViewer, mode });
|
|
8053
8620
|
if (activeFileViewer.mode === "changes" && previousMode !== "changes") clearFileViewerSelection();
|
|
8054
8621
|
updateFileViewerUi();
|
|
8622
|
+
if (elements.fileViewerSearchBar && !elements.fileViewerSearchBar.hidden) {
|
|
8623
|
+
fileViewerSearchIndex = -1;
|
|
8624
|
+
runFileViewerSearch({ navigate: true });
|
|
8625
|
+
}
|
|
8055
8626
|
}
|
|
8056
8627
|
|
|
8057
8628
|
function setFileViewerDirty(dirty) {
|
|
@@ -8067,7 +8638,10 @@ function updateFileViewerUi() {
|
|
|
8067
8638
|
if (elements.fileViewerPane) elements.fileViewerPane.hidden = !open;
|
|
8068
8639
|
requestAnimationFrame(syncResizablePanelWidthsForViewport);
|
|
8069
8640
|
updateFileViewerResizeHandle();
|
|
8070
|
-
if (!open)
|
|
8641
|
+
if (!open) {
|
|
8642
|
+
closeFileViewerSearch({ restoreFocus: false });
|
|
8643
|
+
return;
|
|
8644
|
+
}
|
|
8071
8645
|
if (!isSidePanelOverlayView()) applyFileViewerWidth(currentFileViewerWidth());
|
|
8072
8646
|
const viewer = activeFileViewer;
|
|
8073
8647
|
const isMarkdown = viewer.language === "markdown";
|
|
@@ -8120,6 +8694,158 @@ function updateFileViewerUi() {
|
|
|
8120
8694
|
elements.fileViewerOpenDefaultButton.disabled = viewer.readOnly === true || !viewerPath;
|
|
8121
8695
|
}
|
|
8122
8696
|
renderFileViewerSelectionBar();
|
|
8697
|
+
if (elements.fileViewerSearchBar && !elements.fileViewerSearchBar.hidden) {
|
|
8698
|
+
fileViewerSearchIndex = -1;
|
|
8699
|
+
runFileViewerSearch({ navigate: false });
|
|
8700
|
+
}
|
|
8701
|
+
}
|
|
8702
|
+
|
|
8703
|
+
const FILE_VIEWER_SEARCH_MATCH_LIMIT = 10_000;
|
|
8704
|
+
|
|
8705
|
+
function fileViewerSearchQueryText() {
|
|
8706
|
+
return String(elements.fileViewerSearchInput?.value || "");
|
|
8707
|
+
}
|
|
8708
|
+
|
|
8709
|
+
function fileViewerSearchSurface() {
|
|
8710
|
+
const mode = resolveFileViewerMode(activeFileViewer);
|
|
8711
|
+
if (mode === "preview") return elements.fileViewerPreview;
|
|
8712
|
+
if (mode === "changes") return elements.fileViewerChanges;
|
|
8713
|
+
return elements.fileViewerEditor;
|
|
8714
|
+
}
|
|
8715
|
+
|
|
8716
|
+
function fileViewerSearchText() {
|
|
8717
|
+
const surface = fileViewerSearchSurface();
|
|
8718
|
+
if (surface === elements.fileViewerEditor) return String(surface?.value ?? activeFileViewer?.content ?? "");
|
|
8719
|
+
return String(surface?.textContent || "");
|
|
8720
|
+
}
|
|
8721
|
+
|
|
8722
|
+
function collectFileViewerSearchMatches(query = fileViewerSearchQueryText()) {
|
|
8723
|
+
const haystack = fileViewerSearchText().toLowerCase();
|
|
8724
|
+
const needle = String(query || "").toLowerCase();
|
|
8725
|
+
if (!needle) return { matches: [], truncated: false };
|
|
8726
|
+
const matches = [];
|
|
8727
|
+
let offset = 0;
|
|
8728
|
+
while (matches.length < FILE_VIEWER_SEARCH_MATCH_LIMIT) {
|
|
8729
|
+
const index = haystack.indexOf(needle, offset);
|
|
8730
|
+
if (index < 0) return { matches, truncated: false };
|
|
8731
|
+
matches.push({ start: index, end: index + needle.length });
|
|
8732
|
+
offset = index + needle.length;
|
|
8733
|
+
}
|
|
8734
|
+
return { matches, truncated: haystack.indexOf(needle, offset) >= 0 };
|
|
8735
|
+
}
|
|
8736
|
+
|
|
8737
|
+
function updateFileViewerSearchCount() {
|
|
8738
|
+
if (!elements.fileViewerSearchCount) return;
|
|
8739
|
+
const query = fileViewerSearchQueryText();
|
|
8740
|
+
if (!query) elements.fileViewerSearchCount.textContent = "";
|
|
8741
|
+
else if (!fileViewerSearchMatches.length) elements.fileViewerSearchCount.textContent = "0/0";
|
|
8742
|
+
else elements.fileViewerSearchCount.textContent = `${fileViewerSearchIndex + 1}/${fileViewerSearchMatches.length}${fileViewerSearchTruncated ? "+" : ""}`;
|
|
8743
|
+
}
|
|
8744
|
+
|
|
8745
|
+
function textOffsetPosition(root, offset) {
|
|
8746
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
8747
|
+
let remaining = Math.max(0, offset);
|
|
8748
|
+
let node = walker.nextNode();
|
|
8749
|
+
while (node) {
|
|
8750
|
+
const length = node.nodeValue?.length || 0;
|
|
8751
|
+
if (remaining <= length) return { node, offset: remaining };
|
|
8752
|
+
remaining -= length;
|
|
8753
|
+
node = walker.nextNode();
|
|
8754
|
+
}
|
|
8755
|
+
return null;
|
|
8756
|
+
}
|
|
8757
|
+
|
|
8758
|
+
function clearFileViewerSearchHighlight() {
|
|
8759
|
+
globalThis.CSS?.highlights?.delete("file-viewer-search-current");
|
|
8760
|
+
fileViewerSearchHighlightElement?.classList.remove("file-viewer-search-current-fallback");
|
|
8761
|
+
fileViewerSearchHighlightElement = null;
|
|
8762
|
+
}
|
|
8763
|
+
|
|
8764
|
+
function focusFileViewerSearchMatch() {
|
|
8765
|
+
const match = fileViewerSearchMatches[fileViewerSearchIndex];
|
|
8766
|
+
const surface = fileViewerSearchSurface();
|
|
8767
|
+
clearFileViewerSearchHighlight();
|
|
8768
|
+
if (!match || !surface) return;
|
|
8769
|
+
if (surface === elements.fileViewerEditor) {
|
|
8770
|
+
surface.setSelectionRange(match.start, match.end);
|
|
8771
|
+
const lineIndex = surface.value.slice(0, match.start).split("\n").length - 1;
|
|
8772
|
+
const computedStyle = getComputedStyle(surface);
|
|
8773
|
+
const parsedLineHeight = Number.parseFloat(computedStyle.lineHeight);
|
|
8774
|
+
const fontSize = Number.parseFloat(computedStyle.fontSize) || 14;
|
|
8775
|
+
const lineHeight = !parsedLineHeight ? fontSize * 1.45 : parsedLineHeight < 8 ? parsedLineHeight * fontSize : parsedLineHeight;
|
|
8776
|
+
surface.scrollTop = Math.max(0, (lineIndex * lineHeight) - (surface.clientHeight / 2));
|
|
8777
|
+
} else {
|
|
8778
|
+
const start = textOffsetPosition(surface, match.start);
|
|
8779
|
+
const end = textOffsetPosition(surface, match.end);
|
|
8780
|
+
if (start && end) {
|
|
8781
|
+
const range = document.createRange();
|
|
8782
|
+
range.setStart(start.node, start.offset);
|
|
8783
|
+
range.setEnd(end.node, end.offset);
|
|
8784
|
+
const HighlightConstructor = globalThis.Highlight;
|
|
8785
|
+
if (globalThis.CSS?.highlights && typeof HighlightConstructor === "function") {
|
|
8786
|
+
globalThis.CSS.highlights.set("file-viewer-search-current", new HighlightConstructor(range));
|
|
8787
|
+
} else {
|
|
8788
|
+
fileViewerSearchHighlightElement = start.node.parentElement;
|
|
8789
|
+
fileViewerSearchHighlightElement?.classList.add("file-viewer-search-current-fallback");
|
|
8790
|
+
}
|
|
8791
|
+
start.node.parentElement?.scrollIntoView({ block: "center", behavior: "instant" });
|
|
8792
|
+
}
|
|
8793
|
+
}
|
|
8794
|
+
elements.fileViewerSearchInput?.focus({ preventScroll: true });
|
|
8795
|
+
updateFileViewerSearchCount();
|
|
8796
|
+
}
|
|
8797
|
+
|
|
8798
|
+
function runFileViewerSearch({ navigate = false } = {}) {
|
|
8799
|
+
const surface = fileViewerSearchSurface();
|
|
8800
|
+
if (surface?.id) elements.fileViewerSearchInput?.setAttribute("aria-controls", surface.id);
|
|
8801
|
+
const result = collectFileViewerSearchMatches();
|
|
8802
|
+
fileViewerSearchMatches = result.matches;
|
|
8803
|
+
fileViewerSearchTruncated = result.truncated;
|
|
8804
|
+
if (!fileViewerSearchMatches.length) fileViewerSearchIndex = -1;
|
|
8805
|
+
else if (fileViewerSearchIndex < 0 || fileViewerSearchIndex >= fileViewerSearchMatches.length) fileViewerSearchIndex = 0;
|
|
8806
|
+
updateFileViewerSearchCount();
|
|
8807
|
+
if (navigate) focusFileViewerSearchMatch();
|
|
8808
|
+
}
|
|
8809
|
+
|
|
8810
|
+
function stepFileViewerSearch(step) {
|
|
8811
|
+
if (!fileViewerSearchMatches.length) runFileViewerSearch();
|
|
8812
|
+
if (!fileViewerSearchMatches.length) return;
|
|
8813
|
+
fileViewerSearchIndex = (fileViewerSearchIndex + step + fileViewerSearchMatches.length) % fileViewerSearchMatches.length;
|
|
8814
|
+
focusFileViewerSearchMatch();
|
|
8815
|
+
}
|
|
8816
|
+
|
|
8817
|
+
function openFileViewerSearch() {
|
|
8818
|
+
if (!activeFileViewer || !elements.fileViewerSearchBar) return;
|
|
8819
|
+
closeChatSearch();
|
|
8820
|
+
const editor = fileViewerSearchSurface() === elements.fileViewerEditor ? elements.fileViewerEditor : null;
|
|
8821
|
+
const selectedText = editor && editor.selectionEnd > editor.selectionStart
|
|
8822
|
+
? editor.value.slice(editor.selectionStart, editor.selectionEnd)
|
|
8823
|
+
: "";
|
|
8824
|
+
if (selectedText && !selectedText.includes("\n") && selectedText.length <= 200 && !fileViewerSearchQueryText()) {
|
|
8825
|
+
elements.fileViewerSearchInput.value = selectedText;
|
|
8826
|
+
}
|
|
8827
|
+
elements.fileViewerSearchBar.hidden = false;
|
|
8828
|
+
fileViewerSearchIndex = -1;
|
|
8829
|
+
runFileViewerSearch({ navigate: !!fileViewerSearchQueryText() });
|
|
8830
|
+
elements.fileViewerSearchInput?.focus({ preventScroll: true });
|
|
8831
|
+
elements.fileViewerSearchInput?.select();
|
|
8832
|
+
}
|
|
8833
|
+
|
|
8834
|
+
function closeFileViewerSearch({ restoreFocus = true } = {}) {
|
|
8835
|
+
if (!elements.fileViewerSearchBar || elements.fileViewerSearchBar.hidden) return;
|
|
8836
|
+
clearTimeout(fileViewerSearchTimer);
|
|
8837
|
+
fileViewerSearchTimer = null;
|
|
8838
|
+
clearFileViewerSearchHighlight();
|
|
8839
|
+
elements.fileViewerSearchBar.hidden = true;
|
|
8840
|
+
fileViewerSearchMatches = [];
|
|
8841
|
+
fileViewerSearchIndex = -1;
|
|
8842
|
+
fileViewerSearchTruncated = false;
|
|
8843
|
+
updateFileViewerSearchCount();
|
|
8844
|
+
if (!restoreFocus) return;
|
|
8845
|
+
const mode = resolveFileViewerMode(activeFileViewer);
|
|
8846
|
+
if (mode === "preview") elements.fileViewerPreview?.focus({ preventScroll: true });
|
|
8847
|
+
else if (mode === "changes") elements.fileViewerChanges?.focus({ preventScroll: true });
|
|
8848
|
+
else elements.fileViewerEditor?.focus({ preventScroll: true });
|
|
8123
8849
|
}
|
|
8124
8850
|
|
|
8125
8851
|
function fileViewerChangesNotice(text, level = "") {
|
|
@@ -8311,7 +9037,15 @@ async function sendFileSelectionToSession() {
|
|
|
8311
9037
|
}
|
|
8312
9038
|
}
|
|
8313
9039
|
|
|
8314
|
-
function
|
|
9040
|
+
function cacheActiveFileViewerForTab(tabId = activeTabId) {
|
|
9041
|
+
if (!tabId) return;
|
|
9042
|
+
if (activeFileViewer) fileViewersByTab.set(tabId, activeFileViewer);
|
|
9043
|
+
else fileViewersByTab.delete(tabId);
|
|
9044
|
+
if (fileViewerSelection) fileViewerSelectionsByTab.set(tabId, fileViewerSelection);
|
|
9045
|
+
else fileViewerSelectionsByTab.delete(tabId);
|
|
9046
|
+
}
|
|
9047
|
+
|
|
9048
|
+
function resetFileViewerUi() {
|
|
8315
9049
|
fileViewerOpenRequestSerial += 1;
|
|
8316
9050
|
activeFileViewer = null;
|
|
8317
9051
|
clearFileViewerSelection();
|
|
@@ -8332,6 +9066,22 @@ function closeFileViewer() {
|
|
|
8332
9066
|
setFileViewerStatus("");
|
|
8333
9067
|
}
|
|
8334
9068
|
|
|
9069
|
+
function restoreFileViewerForActiveTab() {
|
|
9070
|
+
activeFileViewer = activeTabId ? fileViewersByTab.get(activeTabId) || null : null;
|
|
9071
|
+
fileViewerSelection = activeTabId ? fileViewerSelectionsByTab.get(activeTabId) || null : null;
|
|
9072
|
+
updateFileViewerUi();
|
|
9073
|
+
if (activeFileViewer?.dirty) setFileViewerStatus("Unsaved file edits.", "warn");
|
|
9074
|
+
else if (activeFileViewer) setFileViewerStatus("Restored for this terminal.", "success");
|
|
9075
|
+
}
|
|
9076
|
+
|
|
9077
|
+
function closeFileViewer() {
|
|
9078
|
+
if (activeTabId) {
|
|
9079
|
+
fileViewersByTab.delete(activeTabId);
|
|
9080
|
+
fileViewerSelectionsByTab.delete(activeTabId);
|
|
9081
|
+
}
|
|
9082
|
+
resetFileViewerUi();
|
|
9083
|
+
}
|
|
9084
|
+
|
|
8335
9085
|
// Side-panel Git categories are UI labels; the read API uses its own allowlist.
|
|
8336
9086
|
const GIT_FILE_DIFF_CATEGORY_BY_PANEL = Object.freeze({
|
|
8337
9087
|
staged: "staged",
|
|
@@ -8376,10 +9126,10 @@ function gitFileChangesPlaceholder(category, repoRelPath, requestSerial) {
|
|
|
8376
9126
|
|
|
8377
9127
|
async function applyGitFileChangesSnapshot(request, tabContext, viewerPath, requestSerial) {
|
|
8378
9128
|
const snapshot = await request;
|
|
8379
|
-
|
|
8380
|
-
if (!
|
|
8381
|
-
|
|
8382
|
-
updateFileViewerUi();
|
|
9129
|
+
const viewer = tabContext.tabId === activeTabId ? activeFileViewer : fileViewersByTab.get(tabContext.tabId);
|
|
9130
|
+
if (!viewer?.gitChanges?.loading || viewer.path !== viewerPath || viewer.gitChanges.requestSerial !== requestSerial) return;
|
|
9131
|
+
viewer.gitChanges = snapshot;
|
|
9132
|
+
if (viewer === activeFileViewer) updateFileViewerUi();
|
|
8383
9133
|
}
|
|
8384
9134
|
|
|
8385
9135
|
async function openFileInViewer(path = "", { gitCategory = "", gitPath = "" } = {}) {
|
|
@@ -8415,6 +9165,7 @@ async function openFileInViewer(path = "", { gitCategory = "", gitPath = "" } =
|
|
|
8415
9165
|
};
|
|
8416
9166
|
if (elements.fileViewerEditor) elements.fileViewerEditor.value = activeFileViewer.content;
|
|
8417
9167
|
clearFileViewerSelection();
|
|
9168
|
+
cacheActiveFileViewerForTab();
|
|
8418
9169
|
updateFileViewerUi();
|
|
8419
9170
|
setFileViewerStatus("Opened in WebUI.", "success");
|
|
8420
9171
|
if (changesRequest) void applyGitFileChangesSnapshot(changesRequest, tabContext, activeFileViewer.path, changesRequestSerial);
|
|
@@ -8440,6 +9191,7 @@ async function openFileInViewer(path = "", { gitCategory = "", gitPath = "" } =
|
|
|
8440
9191
|
};
|
|
8441
9192
|
if (elements.fileViewerEditor) elements.fileViewerEditor.value = "";
|
|
8442
9193
|
clearFileViewerSelection();
|
|
9194
|
+
cacheActiveFileViewerForTab();
|
|
8443
9195
|
updateFileViewerUi();
|
|
8444
9196
|
setFileViewerStatus("File content unavailable; showing Git changes (read-only).", "warn");
|
|
8445
9197
|
return;
|
|
@@ -8474,6 +9226,7 @@ async function openAurReviewReportInViewer(path = "", repoRoot = "") {
|
|
|
8474
9226
|
};
|
|
8475
9227
|
if (elements.fileViewerEditor) elements.fileViewerEditor.value = activeFileViewer.content;
|
|
8476
9228
|
clearFileViewerSelection();
|
|
9229
|
+
cacheActiveFileViewerForTab();
|
|
8477
9230
|
updateFileViewerUi();
|
|
8478
9231
|
setFileViewerStatus("Report opened in WebUI (read-only).", "success");
|
|
8479
9232
|
} catch (error) {
|
|
@@ -8499,6 +9252,7 @@ async function saveActiveFileViewer() {
|
|
|
8499
9252
|
if (!isCurrentTabContext(tabContext)) return;
|
|
8500
9253
|
const data = response.data || {};
|
|
8501
9254
|
activeFileViewer = { ...activeFileViewer, ...data, path: normalizeFileTreePath(data.path || activeFileViewer.path), content, dirty: false };
|
|
9255
|
+
cacheActiveFileViewerForTab();
|
|
8502
9256
|
updateFileViewerUi();
|
|
8503
9257
|
await loadFileTreeDirectory(fileParentPath(activeFileViewer.path), { force: true });
|
|
8504
9258
|
setFileViewerStatus("Saved.", "success");
|
|
@@ -9017,8 +9771,9 @@ function resetActiveTabUi() {
|
|
|
9017
9771
|
latestWorkspace = null;
|
|
9018
9772
|
latestMessages = [];
|
|
9019
9773
|
latestMessagesSessionKey = "";
|
|
9020
|
-
|
|
9774
|
+
resetFileViewerUi();
|
|
9021
9775
|
resetFileTreeState();
|
|
9776
|
+
restoreFileViewerForActiveTab();
|
|
9022
9777
|
clearRunIndicatorActivity({ render: false });
|
|
9023
9778
|
statusEntries.clear();
|
|
9024
9779
|
restoreWidgetsForActiveTab();
|
|
@@ -9915,8 +10670,6 @@ function terminalTabGroupTooltip(group, groupTitle = terminalDisplayGroupTitle(g
|
|
|
9915
10670
|
return lines.join("\n");
|
|
9916
10671
|
}
|
|
9917
10672
|
|
|
9918
|
-
let terminalTabGroupSummarySerial = 0;
|
|
9919
|
-
|
|
9920
10673
|
function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false, workflowModeActive = false, workflowCount = 0, subagent = false }) {
|
|
9921
10674
|
const titleRow = make("span", "terminal-tab-title-row");
|
|
9922
10675
|
const indicatorDot = make("span", "terminal-tab-activity-indicator");
|
|
@@ -10050,6 +10803,7 @@ function renderTerminalTabGroup(group, groupCount = 1) {
|
|
|
10050
10803
|
button.setAttribute("aria-haspopup", "true");
|
|
10051
10804
|
button.setAttribute("aria-expanded", group.key === openTerminalTabGroupKey ? "true" : "false");
|
|
10052
10805
|
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}`);
|
|
10806
|
+
applyStyledTooltip(button, terminalTabGroupTooltip(group, groupTitle), { ariaLabel: false, description: true, placement: "right", variant: "workspace" });
|
|
10053
10807
|
appendTerminalTabContent(button, { title: activeTitle, indicator, meta: `${groupTitle} · ${indicator.meta}${groupAppRunnerMeta ? ` · ${groupAppRunnerMeta}` : ""}${workflowModeActive ? " · workflow mode" : ""}${workflowCount ? ` · ${workflowCount} workflows` : ""}`, appRunnerRun, count: groupTabs.length, workflowModeActive, workflowCount });
|
|
10054
10808
|
button.addEventListener("click", () => switchTab(activeGroupTab.id));
|
|
10055
10809
|
wrapper.append(button);
|
|
@@ -10070,10 +10824,6 @@ function renderTerminalTabGroup(group, groupCount = 1) {
|
|
|
10070
10824
|
const menu = make("div", "terminal-tab-group-menu");
|
|
10071
10825
|
menu.setAttribute("role", "group");
|
|
10072
10826
|
menu.setAttribute("aria-label", `${groupTitle} tabs`);
|
|
10073
|
-
const summary = make("div", "terminal-tab-group-summary", terminalTabGroupTooltip(group, groupTitle));
|
|
10074
|
-
summary.id = `terminalTabGroupSummary${++terminalTabGroupSummarySerial}`;
|
|
10075
|
-
button.setAttribute("aria-describedby", summary.id);
|
|
10076
|
-
menu.append(summary);
|
|
10077
10827
|
for (const tab of groupTabs) menu.append(renderTerminalTabGroupItem(tab, group));
|
|
10078
10828
|
|
|
10079
10829
|
const add = make("button", "terminal-tab-group-add", "+ Tab");
|
|
@@ -10112,6 +10862,7 @@ function clearOpenTerminalTabGroup(groupKey, { force = false } = {}) {
|
|
|
10112
10862
|
}
|
|
10113
10863
|
|
|
10114
10864
|
function setNewTabMenuOpen(open) {
|
|
10865
|
+
if (open && followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
10115
10866
|
newTabMenuOpen = !!open;
|
|
10116
10867
|
elements.newTabButton?.setAttribute("aria-expanded", newTabMenuOpen ? "true" : "false");
|
|
10117
10868
|
elements.newTabButton?.classList.toggle("menu-open", newTabMenuOpen);
|
|
@@ -10190,6 +10941,13 @@ function renderTabs() {
|
|
|
10190
10941
|
}
|
|
10191
10942
|
elements.tabBar.append(elements.newTabMenu);
|
|
10192
10943
|
elements.closeAllTabsButton.disabled = tabs.length === 0;
|
|
10944
|
+
if (elements.workspaceSaveButton) {
|
|
10945
|
+
const canSave = tabs.length > 0;
|
|
10946
|
+
elements.workspaceSaveButton.disabled = !canSave;
|
|
10947
|
+
applyStyledTooltip(elements.workspaceSaveButton, canSave
|
|
10948
|
+
? "Save workspace:\n• Captures all open tabs, sessions, order, custom groups, and the active tab."
|
|
10949
|
+
: "Save workspace is available after you open a tab.", { ariaLabel: canSave ? "Save workspace" : "Save workspace (no open tabs)", floating: false });
|
|
10950
|
+
}
|
|
10193
10951
|
updateTerminalTabGroupOpenState();
|
|
10194
10952
|
reconcileTerminalSplitState();
|
|
10195
10953
|
setMobileTabsExpanded(mobileTabsExpanded);
|
|
@@ -10218,6 +10976,11 @@ async function refreshTabs({ selectStored = false } = {}) {
|
|
|
10218
10976
|
setActiveTabId((requested && tabs.some((tab) => tab.id === requested) ? requested : stored && tabs.some((tab) => tab.id === stored) ? stored : tabs[0]?.id) || null, { remember: true });
|
|
10219
10977
|
}
|
|
10220
10978
|
rememberServerStartCwd(tabs.find((tab) => tab.id === activeTabId)?.cwd || tabs[0]?.cwd);
|
|
10979
|
+
if (!tabs.length && previousTabs.length) {
|
|
10980
|
+
savedWorkspacesLoaded = false;
|
|
10981
|
+
savedWorkspacesError = "";
|
|
10982
|
+
setWorkspaceDashboardCollapsed(false, { persist: false });
|
|
10983
|
+
}
|
|
10221
10984
|
renderSessionSkillTags(activeTabId);
|
|
10222
10985
|
renderTabs();
|
|
10223
10986
|
return tabs;
|
|
@@ -10231,6 +10994,8 @@ async function switchTab(tabId) {
|
|
|
10231
10994
|
}
|
|
10232
10995
|
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ render: false });
|
|
10233
10996
|
clearOpenTerminalTabGroup(null, { force: true });
|
|
10997
|
+
setFollowUpQueueOpen(false);
|
|
10998
|
+
setFollowUpQueueStatus("");
|
|
10234
10999
|
setMobileTabsExpanded(false);
|
|
10235
11000
|
footerModelPickerOpen = false;
|
|
10236
11001
|
footerThinkingPickerOpen = false;
|
|
@@ -10240,6 +11005,7 @@ async function switchTab(tabId) {
|
|
|
10240
11005
|
saveActiveDraft();
|
|
10241
11006
|
cacheMessagesForTab(activeTabId);
|
|
10242
11007
|
cacheWidgetsForTab(activeTabId);
|
|
11008
|
+
cacheActiveFileViewerForTab(activeTabId);
|
|
10243
11009
|
const tabContext = setActiveTabId(tabId, { remember: true });
|
|
10244
11010
|
if (voiceConversation && voiceConversationTabId !== tabId) stopVoiceConversationLoop();
|
|
10245
11011
|
resetActiveTabUi();
|
|
@@ -10443,7 +11209,7 @@ async function confirmCloseTerminalTabs(targetTabs, label) {
|
|
|
10443
11209
|
});
|
|
10444
11210
|
}
|
|
10445
11211
|
|
|
10446
|
-
async function closeTerminalTabs(tabIds, { label = "selected terminal tabs" } = {}) {
|
|
11212
|
+
async function closeTerminalTabs(tabIds, { label = "selected terminal tabs", allowEmpty = false } = {}) {
|
|
10447
11213
|
const targetIds = [...new Set(tabIds.filter(Boolean))];
|
|
10448
11214
|
const targetTabs = targetIds.map((id) => tabs.find((item) => item.id === id)).filter(Boolean);
|
|
10449
11215
|
if (!targetTabs.length) return;
|
|
@@ -10453,7 +11219,7 @@ async function closeTerminalTabs(tabIds, { label = "selected terminal tabs" } =
|
|
|
10453
11219
|
const fallbackTabId = tabs.find((item) => !targetIds.includes(item.id))?.id || null;
|
|
10454
11220
|
try {
|
|
10455
11221
|
if (closedActiveTab) eventSource?.close();
|
|
10456
|
-
const response = await api("/api/tabs/close", { method: "POST", body: { ids: targetIds }, scoped: false });
|
|
11222
|
+
const response = await api("/api/tabs/close", { method: "POST", body: { ids: targetIds, allowEmpty }, scoped: false });
|
|
10457
11223
|
const closedIds = response.data?.closedIds || targetIds;
|
|
10458
11224
|
tabs = response.data?.tabs || tabs.filter((item) => !closedIds.includes(item.id));
|
|
10459
11225
|
syncTabMetadata(tabs);
|
|
@@ -10465,11 +11231,14 @@ async function closeTerminalTabs(tabIds, { label = "selected terminal tabs" } =
|
|
|
10465
11231
|
commandCatalogsByTab.delete(id);
|
|
10466
11232
|
appRunnerDataByTab.delete(id);
|
|
10467
11233
|
tabMessagesCache.delete(id);
|
|
11234
|
+
fileViewersByTab.delete(id);
|
|
11235
|
+
fileViewerSelectionsByTab.delete(id);
|
|
10468
11236
|
btwWidgetDismissedIdsByTab.delete(id);
|
|
10469
11237
|
removeSubagentTerminalViewsForParent(id);
|
|
10470
11238
|
}
|
|
10471
11239
|
syncTerminalCustomGroupsWithTabs(tabs);
|
|
10472
11240
|
clearOpenTerminalTabGroup(null, { force: true });
|
|
11241
|
+
if (!tabs.length) setWorkspaceDashboardCollapsed(false, { persist: false });
|
|
10473
11242
|
|
|
10474
11243
|
const activeTabNeedsFallback = closedIds.includes(activeTabId) || !tabs.some((item) => item.id === activeTabId);
|
|
10475
11244
|
if (activeTabNeedsFallback) {
|
|
@@ -10506,7 +11275,7 @@ async function closeTerminalTabGroup(group) {
|
|
|
10506
11275
|
}
|
|
10507
11276
|
|
|
10508
11277
|
async function closeAllTerminalTabs() {
|
|
10509
|
-
await closeTerminalTabs(tabs.map((tab) => tab.id), { label: "all terminal tabs" });
|
|
11278
|
+
await closeTerminalTabs(tabs.map((tab) => tab.id), { label: "all terminal tabs", allowEmpty: true });
|
|
10510
11279
|
}
|
|
10511
11280
|
|
|
10512
11281
|
async function initializeTabs() {
|
|
@@ -10515,7 +11284,12 @@ async function initializeTabs() {
|
|
|
10515
11284
|
renderTabs();
|
|
10516
11285
|
restoreActiveDraft();
|
|
10517
11286
|
if (!loadedTabs.length) {
|
|
10518
|
-
|
|
11287
|
+
setWorkspaceDashboardCollapsed(false, { persist: false });
|
|
11288
|
+
const saved = await refreshSavedWorkspaces().catch((error) => {
|
|
11289
|
+
addEvent(`Could not list saved workspaces: ${error.message || String(error)}`, "error");
|
|
11290
|
+
return [];
|
|
11291
|
+
});
|
|
11292
|
+
if (!saved.length) await createFirstTerminalTabFromChosenDirectory();
|
|
10519
11293
|
return;
|
|
10520
11294
|
}
|
|
10521
11295
|
focusPromptInput({ defer: true });
|
|
@@ -11358,13 +12132,21 @@ function positionFooterTooltip(target) {
|
|
|
11358
12132
|
const width = footerTooltipNode.offsetWidth;
|
|
11359
12133
|
const height = footerTooltipNode.offsetHeight;
|
|
11360
12134
|
const align = target.getAttribute("data-tooltip-align") || "center";
|
|
11361
|
-
|
|
11362
|
-
|
|
11363
|
-
|
|
12135
|
+
const placement = target.getAttribute("data-tooltip-placement") || "top";
|
|
12136
|
+
let left;
|
|
12137
|
+
let top;
|
|
12138
|
+
if (placement === "right") {
|
|
12139
|
+
left = rect.right + gap;
|
|
12140
|
+
if (left + width > window.innerWidth - margin) left = rect.left - gap - width;
|
|
12141
|
+
top = rect.top;
|
|
12142
|
+
} else {
|
|
12143
|
+
left = rect.left + rect.width / 2 - width / 2;
|
|
12144
|
+
if (align === "start") left = rect.left;
|
|
12145
|
+
if (align === "end") left = rect.right - width;
|
|
12146
|
+
top = rect.top - gap - height;
|
|
12147
|
+
if (top < margin) top = rect.bottom + gap;
|
|
12148
|
+
}
|
|
11364
12149
|
left = Math.min(Math.max(margin, left), Math.max(margin, window.innerWidth - margin - width));
|
|
11365
|
-
|
|
11366
|
-
let top = rect.top - gap - height;
|
|
11367
|
-
if (top < margin) top = rect.bottom + gap;
|
|
11368
12150
|
top = Math.min(Math.max(margin, top), window.innerHeight - margin - height);
|
|
11369
12151
|
|
|
11370
12152
|
footerTooltipNode.style.left = `${Math.round(left)}px`;
|
|
@@ -11448,6 +12230,7 @@ function applyStyledTooltip(node, tooltip, options = {}) {
|
|
|
11448
12230
|
node.setAttribute("aria-describedby", describedBy);
|
|
11449
12231
|
}
|
|
11450
12232
|
if (options.align) node.setAttribute("data-tooltip-align", options.align);
|
|
12233
|
+
if (options.placement) node.setAttribute("data-tooltip-placement", options.placement);
|
|
11451
12234
|
if (options.variant) node.setAttribute("data-tooltip-variant", options.variant);
|
|
11452
12235
|
if (options.floating !== false) bindStyledTooltipEvents(node);
|
|
11453
12236
|
return node;
|
|
@@ -12420,13 +13203,20 @@ function gitFooterChipShapeKey(chip) {
|
|
|
12420
13203
|
return JSON.stringify(shape);
|
|
12421
13204
|
}
|
|
12422
13205
|
|
|
13206
|
+
function footerBranchPickerRenderKey() {
|
|
13207
|
+
// Branch data arrives asynchronously after the picker opens. Include its full
|
|
13208
|
+
// serializable state so the footer fast path cannot leave the initial loading
|
|
13209
|
+
// card mounted after fresher branch/worktree data has arrived.
|
|
13210
|
+
return footerBranchPickerOpen ? JSON.stringify(footerBranchPickerState) : "";
|
|
13211
|
+
}
|
|
13212
|
+
|
|
12423
13213
|
function gitFooterPickerStateKey(payload) {
|
|
12424
13214
|
const tabContext = activeTabContext();
|
|
12425
13215
|
const refreshInFlight = tabContext.tabId ? gitFooterPayloadRefreshInFlightByTab.has(tabContext.tabId) : false;
|
|
12426
13216
|
const syncPushInFlight = tabContext.tabId ? gitFooterSyncPushInFlightByTab.has(tabContext.tabId) : false;
|
|
12427
13217
|
const piCalibrationInFlight = tabContext.tabId ? gitFooterPiCalibrationInFlightByTab.has(tabContext.tabId) : false;
|
|
12428
13218
|
const refreshAvailable = hasLoadedRpcCommand("git-footer-refresh");
|
|
12429
|
-
return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${syncPushInFlight ? 1 : 0}|${piCalibrationInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}|${gitFooterPayloadVisibilityKey(payload)}`;
|
|
13219
|
+
return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${footerBranchPickerRenderKey()}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${syncPushInFlight ? 1 : 0}|${piCalibrationInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}|${gitFooterPayloadVisibilityKey(payload)}`;
|
|
12430
13220
|
}
|
|
12431
13221
|
|
|
12432
13222
|
function updateGitFooterChipNodeValue(node, chip, valueSelector) {
|
|
@@ -14510,6 +15300,9 @@ function renderWorkspaceDashboard() {
|
|
|
14510
15300
|
activeTabId,
|
|
14511
15301
|
tabs: tabs.slice(0, 8).map((item) => ({ id: item.id, title: item.title, indicator: tabIndicator(item), active: item.id === activeTabId, cwd: item.cwd ? normalizeDisplayPath(item.cwd) : "" })),
|
|
14512
15302
|
overflow: tabs.length > 8 ? tabs.length - 8 : 0,
|
|
15303
|
+
savedWorkspaces: !tabs.length ? savedWorkspaces.map((workspace) => ({ id: workspace.id, name: workspace.name, savedAt: workspace.savedAt, tabCount: workspace.tabCount, groupCount: workspace.groupCount, cwds: workspace.cwds })) : [],
|
|
15304
|
+
savedWorkspacesLoading,
|
|
15305
|
+
savedWorkspacesError,
|
|
14513
15306
|
});
|
|
14514
15307
|
if (signature === workspaceDashboardSignature && root.childElementCount > 0) return;
|
|
14515
15308
|
workspaceDashboardSignature = signature;
|
|
@@ -14548,11 +15341,16 @@ function renderWorkspaceDashboard() {
|
|
|
14548
15341
|
actions.append(
|
|
14549
15342
|
dashboardAction("Command palette", () => openCommandPalette(), "primary"),
|
|
14550
15343
|
dashboardAction("New tab", () => createTerminalTab()),
|
|
14551
|
-
dashboardAction("Branch worktree", () => openBranchWorktreePicker(), "worktree"),
|
|
14552
|
-
dashboardAction("Resume", () => runNativeCommandMenu("/resume")),
|
|
14553
|
-
dashboardAction("Model", () => runNativeCommandMenu("/model")),
|
|
14554
|
-
dashboardAction("Settings", () => runNativeCommandMenu("/settings")),
|
|
14555
15344
|
);
|
|
15345
|
+
if (tabs.length) {
|
|
15346
|
+
actions.append(
|
|
15347
|
+
dashboardAction("Load workspace", () => openWorkspaceLoadPicker(), "primary"),
|
|
15348
|
+
dashboardAction("Branch worktree", () => openBranchWorktreePicker(), "worktree"),
|
|
15349
|
+
dashboardAction("Resume", () => runNativeCommandMenu("/resume")),
|
|
15350
|
+
dashboardAction("Model", () => runNativeCommandMenu("/model")),
|
|
15351
|
+
dashboardAction("Settings", () => runNativeCommandMenu("/settings")),
|
|
15352
|
+
);
|
|
15353
|
+
}
|
|
14556
15354
|
header.append(title, actions);
|
|
14557
15355
|
|
|
14558
15356
|
const metrics = make("div", "workspace-dashboard-metrics");
|
|
@@ -14599,7 +15397,70 @@ function renderWorkspaceDashboard() {
|
|
|
14599
15397
|
if (tabs.length > 8) tabList.append(make("span", "workspace-dashboard-tab-more", `+${tabs.length - 8} more`));
|
|
14600
15398
|
tabsPanel.append(tabList);
|
|
14601
15399
|
|
|
15400
|
+
const savedWorkspacePanel = !tabs.length ? renderSavedWorkspacePicker() : null;
|
|
14602
15401
|
root.append(header, metrics, tabsPanel);
|
|
15402
|
+
if (savedWorkspacePanel) root.append(savedWorkspacePanel);
|
|
15403
|
+
}
|
|
15404
|
+
|
|
15405
|
+
function renderSavedWorkspacePicker() {
|
|
15406
|
+
if (!savedWorkspacesLoaded && !savedWorkspacesLoading && !savedWorkspacesError) {
|
|
15407
|
+
queueMicrotask(() => refreshSavedWorkspaces().catch((error) => addEvent(`Could not list saved workspaces: ${error.message || String(error)}`, "error")));
|
|
15408
|
+
}
|
|
15409
|
+
const panel = make("section", "workspace-saved-workspaces");
|
|
15410
|
+
panel.setAttribute("aria-label", "Saved workspaces");
|
|
15411
|
+
const heading = make("div", "workspace-saved-workspaces-heading");
|
|
15412
|
+
heading.append(
|
|
15413
|
+
make("span", "workspace-dashboard-kicker", "Saved workspaces"),
|
|
15414
|
+
make("span", "workspace-saved-workspaces-hint", "Load a complete saved tab constellation"),
|
|
15415
|
+
);
|
|
15416
|
+
panel.append(heading);
|
|
15417
|
+
if (savedWorkspacesLoading) {
|
|
15418
|
+
const status = make("p", "workspace-saved-workspaces-empty muted", "Loading saved workspaces…");
|
|
15419
|
+
status.setAttribute("role", "status");
|
|
15420
|
+
panel.append(status);
|
|
15421
|
+
return panel;
|
|
15422
|
+
}
|
|
15423
|
+
if (savedWorkspacesError) {
|
|
15424
|
+
const status = make("p", "workspace-saved-workspaces-empty error", `Could not load saved workspaces: ${savedWorkspacesError}`);
|
|
15425
|
+
status.setAttribute("role", "status");
|
|
15426
|
+
const retry = make("button", "workspace-saved-workspaces-retry", "Retry");
|
|
15427
|
+
retry.type = "button";
|
|
15428
|
+
retry.addEventListener("click", () => refreshSavedWorkspaces({ force: true }).catch((error) => addEvent(`Could not list saved workspaces: ${error.message || String(error)}`, "error")));
|
|
15429
|
+
panel.append(status, retry);
|
|
15430
|
+
return panel;
|
|
15431
|
+
}
|
|
15432
|
+
if (!savedWorkspaces.length) {
|
|
15433
|
+
panel.append(make("p", "workspace-saved-workspaces-empty muted", "No saved workspaces yet. Open tabs, then use Save workspace."));
|
|
15434
|
+
return panel;
|
|
15435
|
+
}
|
|
15436
|
+
const list = make("div", "workspace-saved-workspaces-list");
|
|
15437
|
+
for (const workspace of savedWorkspaces) {
|
|
15438
|
+
const row = make("article", "workspace-saved-workspace");
|
|
15439
|
+
const copy = make("div", "workspace-saved-workspace-copy");
|
|
15440
|
+
const title = make("strong", "workspace-saved-workspace-name", workspace.name);
|
|
15441
|
+
title.title = workspace.name;
|
|
15442
|
+
const detail = [
|
|
15443
|
+
formatDate(workspace.savedAt),
|
|
15444
|
+
`${workspace.tabCount || 0} tab${workspace.tabCount === 1 ? "" : "s"}`,
|
|
15445
|
+
workspace.groupCount ? `${workspace.groupCount} group${workspace.groupCount === 1 ? "" : "s"}` : "",
|
|
15446
|
+
Array.isArray(workspace.cwds) && workspace.cwds.length ? normalizeDisplayPath(workspace.cwds[0]) : "",
|
|
15447
|
+
].filter(Boolean).join(" · ");
|
|
15448
|
+
copy.append(title, make("span", "workspace-saved-workspace-detail", detail));
|
|
15449
|
+
const actions = make("div", "workspace-saved-workspace-actions");
|
|
15450
|
+
const load = make("button", "workspace-saved-workspace-load primary", "Load");
|
|
15451
|
+
load.type = "button";
|
|
15452
|
+
load.setAttribute("aria-label", `Load workspace ${workspace.name}`);
|
|
15453
|
+
load.addEventListener("click", () => loadWebuiWorkspace(workspace.id, { triggerButton: load }));
|
|
15454
|
+
const remove = make("button", "workspace-saved-workspace-delete", "Delete");
|
|
15455
|
+
remove.type = "button";
|
|
15456
|
+
remove.setAttribute("aria-label", `Delete workspace ${workspace.name}`);
|
|
15457
|
+
remove.addEventListener("click", () => deleteWebuiWorkspace(workspace));
|
|
15458
|
+
actions.append(load, remove);
|
|
15459
|
+
row.append(copy, actions);
|
|
15460
|
+
list.append(row);
|
|
15461
|
+
}
|
|
15462
|
+
panel.append(list);
|
|
15463
|
+
return panel;
|
|
14603
15464
|
}
|
|
14604
15465
|
|
|
14605
15466
|
function setFooterModelPickerOpen(open) {
|
|
@@ -14642,22 +15503,54 @@ function setFooterThinkingPickerOpen(open) {
|
|
|
14642
15503
|
if (wasOpen && !footerThinkingPickerOpen) scheduleDeferredUiFlushAfterDropdownClose();
|
|
14643
15504
|
}
|
|
14644
15505
|
|
|
15506
|
+
function footerGitBranchKey(item = {}) {
|
|
15507
|
+
// Remote-only rows stay distinct per exact remote ref so same-named branches
|
|
15508
|
+
// from different remotes never collapse into a single row.
|
|
15509
|
+
return item.remote ? `remote:${item.remoteRef}` : `local:${item.name}`;
|
|
15510
|
+
}
|
|
15511
|
+
|
|
15512
|
+
function footerBranchOptionLabel(branch = {}) {
|
|
15513
|
+
return cleanStatusText(branch.displayName) || cleanStatusText(branch.name);
|
|
15514
|
+
}
|
|
15515
|
+
|
|
14645
15516
|
function normalizeFooterGitBranches(data = {}) {
|
|
14646
15517
|
const current = cleanStatusText(data.current || data.currentBranch || "");
|
|
15518
|
+
const rawBranches = Array.isArray(data.branches) ? data.branches : [];
|
|
15519
|
+
const localNames = new Set(
|
|
15520
|
+
rawBranches
|
|
15521
|
+
.filter((item) => typeof item === "string" || item?.remote !== true)
|
|
15522
|
+
.map((item) => cleanStatusText(typeof item === "string" ? item : item?.name))
|
|
15523
|
+
.filter(Boolean),
|
|
15524
|
+
);
|
|
14647
15525
|
const seen = new Set();
|
|
14648
15526
|
const branches = [];
|
|
14649
|
-
for (const item of
|
|
15527
|
+
for (const item of rawBranches) {
|
|
14650
15528
|
const name = cleanStatusText(typeof item === "string" ? item : item?.name);
|
|
14651
|
-
if (!name
|
|
14652
|
-
|
|
14653
|
-
|
|
15529
|
+
if (!name) continue;
|
|
15530
|
+
const remoteRef = cleanFooterPayloadText(item?.remoteRef, "", 4000);
|
|
15531
|
+
const remote = item?.remote === true;
|
|
15532
|
+
// Never downgrade a remote record without an exact ref into a local row: the
|
|
15533
|
+
// browser must not infer a Git command from display text alone.
|
|
15534
|
+
if (remote && !remoteRef) continue;
|
|
15535
|
+
// A local branch always represents the local name; remote rows for that
|
|
15536
|
+
// same name stay hidden until they are materialized locally.
|
|
15537
|
+
if (remote && localNames.has(name)) continue;
|
|
15538
|
+
const branch = {
|
|
14654
15539
|
name,
|
|
14655
|
-
|
|
14656
|
-
|
|
14657
|
-
|
|
14658
|
-
|
|
14659
|
-
|
|
14660
|
-
|
|
15540
|
+
remote,
|
|
15541
|
+
remoteRef: remote ? remoteRef : "",
|
|
15542
|
+
remoteName: remote ? cleanStatusText(item?.remoteName) : "",
|
|
15543
|
+
displayName: remote ? cleanFooterPayloadText(item?.displayName, remoteRef, 4000) : name,
|
|
15544
|
+
current: !remote && (Boolean(item?.current) || (!!current && name === current)),
|
|
15545
|
+
occupied: !remote && Boolean(item?.occupied),
|
|
15546
|
+
worktreePath: remote ? "" : cleanFooterPayloadText(item?.worktreePath, "", 4000),
|
|
15547
|
+
worktreeCurrent: !remote && Boolean(item?.worktreeCurrent),
|
|
15548
|
+
mainWorktree: !remote && Boolean(item?.mainWorktree),
|
|
15549
|
+
};
|
|
15550
|
+
const key = footerGitBranchKey(branch);
|
|
15551
|
+
if (seen.has(key)) continue;
|
|
15552
|
+
seen.add(key);
|
|
15553
|
+
branches.push({ key, ...branch });
|
|
14661
15554
|
}
|
|
14662
15555
|
const worktrees = (Array.isArray(data.worktrees) ? data.worktrees : [])
|
|
14663
15556
|
.map((item) => ({
|
|
@@ -14726,6 +15619,7 @@ async function loadFooterBranchPicker(tabContext = activeTabContext()) {
|
|
|
14726
15619
|
worktrees: preserveState.worktrees || [],
|
|
14727
15620
|
occupiedBranches: preserveState.occupiedBranches || [],
|
|
14728
15621
|
switching: "",
|
|
15622
|
+
switchingKey: "",
|
|
14729
15623
|
tabId,
|
|
14730
15624
|
};
|
|
14731
15625
|
if (isCurrentTabContext(tabContext)) {
|
|
@@ -14736,10 +15630,10 @@ async function loadFooterBranchPicker(tabContext = activeTabContext()) {
|
|
|
14736
15630
|
const response = await api("/api/git-branches", { tabId });
|
|
14737
15631
|
if (requestSerial !== footerBranchPickerRequestSerial || !footerBranchPickerOpen || !isCurrentTabContext(tabContext)) return;
|
|
14738
15632
|
if (!response.ok) throw new Error(response.error || "Failed to load git branches");
|
|
14739
|
-
footerBranchPickerState = { loading: false, error: "", switching: "", tabId, ...normalizeFooterGitBranches(response.data || {}) };
|
|
15633
|
+
footerBranchPickerState = { loading: false, error: "", switching: "", switchingKey: "", tabId, ...normalizeFooterGitBranches(response.data || {}) };
|
|
14740
15634
|
} catch (error) {
|
|
14741
15635
|
if (requestSerial !== footerBranchPickerRequestSerial || !footerBranchPickerOpen || !isCurrentTabContext(tabContext)) return;
|
|
14742
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", error: error.message || String(error) };
|
|
15636
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", switchingKey: "", error: error.message || String(error) };
|
|
14743
15637
|
}
|
|
14744
15638
|
if (isCurrentTabContext(tabContext)) {
|
|
14745
15639
|
renderFooter();
|
|
@@ -14817,32 +15711,36 @@ function footerBranchDirtySummaryLines() {
|
|
|
14817
15711
|
];
|
|
14818
15712
|
}
|
|
14819
15713
|
|
|
14820
|
-
async function confirmFooterGitBranchAction(branch, { create = false, requireConfirm = false, tabContext = activeTabContext() } = {}) {
|
|
15714
|
+
async function confirmFooterGitBranchAction(branch, { create = false, requireConfirm = false, tabContext = activeTabContext(), remoteRef = "" } = {}) {
|
|
14821
15715
|
const branchName = cleanStatusText(branch);
|
|
15716
|
+
const trackedRemoteRef = cleanStatusText(remoteRef);
|
|
14822
15717
|
const warningLines = footerBranchAgentWarningLines(tabContext);
|
|
14823
15718
|
const dirtyLines = footerBranchDirtySummaryLines();
|
|
14824
15719
|
if (!requireConfirm && warningLines.length === 0 && dirtyLines.length === 0) return true;
|
|
14825
|
-
const action = create ? "Create and switch to new git branch" : "Switch git branch";
|
|
15720
|
+
const action = trackedRemoteRef ? "Create local tracking branch and switch to it" : create ? "Create and switch to new git branch" : "Switch git branch";
|
|
14826
15721
|
const message = [
|
|
14827
15722
|
`${action}: ${branchName}?`,
|
|
14828
15723
|
"",
|
|
14829
15724
|
`Repository: ${footerBranchPickerState.root || currentGitFooterCacheCwd(tabContext.tabId) || "current tab"}`,
|
|
15725
|
+
...(trackedRemoteRef ? [`Remote ref: ${trackedRemoteRef}`, `Command: git switch --track -c ${branchName} ${trackedRemoteRef}`] : []),
|
|
14830
15726
|
...dirtyLines,
|
|
14831
15727
|
...warningLines,
|
|
14832
15728
|
"",
|
|
14833
15729
|
"Continue?",
|
|
14834
15730
|
].join("\n");
|
|
14835
|
-
return appConfirmText(message, { affected: branchName || "the current branch", confirmLabel: create ? "Create branch" : "Switch branch" });
|
|
15731
|
+
return appConfirmText(message, { affected: branchName || "the current branch", confirmLabel: trackedRemoteRef ? "Create tracking branch" : create ? "Create branch" : "Switch branch" });
|
|
14836
15732
|
}
|
|
14837
15733
|
|
|
14838
|
-
async function confirmFooterGitWorktreeAction(branch, { path = "", create = false, requireConfirm = false } = {}) {
|
|
15734
|
+
async function confirmFooterGitWorktreeAction(branch, { path = "", create = false, requireConfirm = false, remoteRef = "" } = {}) {
|
|
14839
15735
|
const branchName = cleanStatusText(branch);
|
|
14840
15736
|
if (!requireConfirm) return true;
|
|
15737
|
+
const trackedRemoteRef = cleanStatusText(remoteRef);
|
|
14841
15738
|
const targetPath = cleanFooterPayloadText(path, "", 4000);
|
|
14842
15739
|
const message = [
|
|
14843
15740
|
`${create ? "Create" : "Open"} branch worktree: ${branchName || targetPath}?`,
|
|
14844
15741
|
"",
|
|
14845
15742
|
`Repository: ${footerBranchPickerState.repoRoot || footerBranchPickerState.root || currentGitFooterCacheCwd() || "current tab"}`,
|
|
15743
|
+
...(trackedRemoteRef ? [`Remote ref: ${trackedRemoteRef}`, `Creates local branch ${branchName} tracking ${trackedRemoteRef}.`] : []),
|
|
14846
15744
|
targetPath ? `Worktree: ${targetPath}` : `Default location: ${footerBranchPickerState.defaultWorktreesRoot || "repo sibling .worktrees directory"}`,
|
|
14847
15745
|
"",
|
|
14848
15746
|
"This opens a separate checkout in a separate Pi tab and does not switch this tab's branch.",
|
|
@@ -14955,7 +15853,7 @@ async function openWorktreeResponseTab(response, { branchName = "", action = "op
|
|
|
14955
15853
|
if (payload.tab) applyTabMetadata(payload.tab);
|
|
14956
15854
|
footerBranchPickerOpen = false;
|
|
14957
15855
|
footerBranchPickerRequestSerial += 1;
|
|
14958
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "" };
|
|
15856
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", switchingKey: "" };
|
|
14959
15857
|
renderTabs();
|
|
14960
15858
|
const targetTab = payload.tab;
|
|
14961
15859
|
if (targetTab?.id) await switchTab(targetTab.id);
|
|
@@ -14968,24 +15866,29 @@ async function openWorktreeResponseTab(response, { branchName = "", action = "op
|
|
|
14968
15866
|
requestGitFooterWebuiPayload(activeTabContext(), { force: true });
|
|
14969
15867
|
}
|
|
14970
15868
|
|
|
14971
|
-
async function createFooterGitBranchWorktree(branch = footerBranchCreateName(), { tabContext = activeTabContext(), skipConfirm = false, chooseBase = true } = {}) {
|
|
15869
|
+
async function createFooterGitBranchWorktree(branch = footerBranchCreateName(), { tabContext = activeTabContext(), skipConfirm = false, chooseBase = true, remoteRef = "", switchingLabel = "", switchingKey = "" } = {}) {
|
|
14972
15870
|
const branchName = cleanStatusText(branch);
|
|
14973
15871
|
if (!branchName) {
|
|
14974
15872
|
addEvent("Enter a branch name before creating a branch worktree.", "warn");
|
|
14975
15873
|
return;
|
|
14976
15874
|
}
|
|
14977
|
-
|
|
14978
|
-
|
|
15875
|
+
const trackedRemoteRef = cleanFooterPayloadText(remoteRef, "", 4000);
|
|
15876
|
+
if (!skipConfirm && !(await confirmFooterGitWorktreeAction(branchName, { create: true, requireConfirm: true, remoteRef: trackedRemoteRef }))) return;
|
|
15877
|
+
const baseRef = trackedRemoteRef ? "" : chooseBase ? await chooseGitWorktreeBase(branchName) : "HEAD";
|
|
14979
15878
|
if (baseRef === null) return;
|
|
14980
15879
|
const tabId = tabContext.tabId || activeTabId;
|
|
14981
15880
|
try {
|
|
14982
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: branchName, tabId };
|
|
15881
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: switchingLabel || branchName, switchingKey, tabId };
|
|
14983
15882
|
renderFooter();
|
|
14984
|
-
|
|
15883
|
+
// Remote-only creation submits the exact advertised remote ref instead of a
|
|
15884
|
+
// base ref; the server re-verifies it and creates a local tracking branch.
|
|
15885
|
+
const response = trackedRemoteRef
|
|
15886
|
+
? await api("/api/git-worktrees", { method: "POST", body: { branchName, remoteRef: trackedRemoteRef, sessionMode: "fork-current", openTab: true }, tabId })
|
|
15887
|
+
: await api("/api/git-worktrees", { method: "POST", body: { branchName, baseRef, sessionMode: "fork-current", openTab: true }, tabId });
|
|
14985
15888
|
await openWorktreeResponseTab(response, { branchName, action: "create" });
|
|
14986
15889
|
} catch (error) {
|
|
14987
15890
|
if (isCurrentTabContext(tabContext)) {
|
|
14988
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", error: error.message || String(error) };
|
|
15891
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", switchingKey: "", error: error.message || String(error) };
|
|
14989
15892
|
renderFooter();
|
|
14990
15893
|
updateFooterModelPickerPosition();
|
|
14991
15894
|
}
|
|
@@ -14993,19 +15896,19 @@ async function createFooterGitBranchWorktree(branch = footerBranchCreateName(),
|
|
|
14993
15896
|
}
|
|
14994
15897
|
}
|
|
14995
15898
|
|
|
14996
|
-
async function openFooterGitWorktree(path, { branchName = "", tabContext = activeTabContext(), skipConfirm = false } = {}) {
|
|
15899
|
+
async function openFooterGitWorktree(path, { branchName = "", tabContext = activeTabContext(), skipConfirm = false, switchingKey = "" } = {}) {
|
|
14997
15900
|
const worktreePath = cleanFooterPayloadText(path, "", 4000);
|
|
14998
15901
|
if (!worktreePath) return;
|
|
14999
15902
|
if (!skipConfirm && !(await confirmFooterGitWorktreeAction(branchName, { path: worktreePath, requireConfirm: false }))) return;
|
|
15000
15903
|
const tabId = tabContext.tabId || activeTabId;
|
|
15001
15904
|
try {
|
|
15002
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: branchName || worktreePath, tabId };
|
|
15905
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: branchName || worktreePath, switchingKey, tabId };
|
|
15003
15906
|
renderFooter();
|
|
15004
15907
|
const response = await api("/api/git-worktrees/open", { method: "POST", body: { path: worktreePath, sessionMode: "fork-current", openTab: true }, tabId });
|
|
15005
15908
|
await openWorktreeResponseTab(response, { branchName, action: "open" });
|
|
15006
15909
|
} catch (error) {
|
|
15007
15910
|
if (isCurrentTabContext(tabContext)) {
|
|
15008
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", error: error.message || String(error) };
|
|
15911
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", switchingKey: "", error: error.message || String(error) };
|
|
15009
15912
|
renderFooter();
|
|
15010
15913
|
updateFooterModelPickerPosition();
|
|
15011
15914
|
}
|
|
@@ -15013,28 +15916,33 @@ async function openFooterGitWorktree(path, { branchName = "", tabContext = activ
|
|
|
15013
15916
|
}
|
|
15014
15917
|
}
|
|
15015
15918
|
|
|
15016
|
-
async function applyFooterGitBranch(branch, { create = false, tabContext = activeTabContext(), skipConfirm = false } = {}) {
|
|
15919
|
+
async function applyFooterGitBranch(branch, { create = false, tabContext = activeTabContext(), skipConfirm = false, remoteRef = "", switchingLabel = "", switchingKey = "" } = {}) {
|
|
15017
15920
|
const branchName = cleanStatusText(branch);
|
|
15018
15921
|
if (!branchName) return;
|
|
15019
15922
|
const tabId = tabContext.tabId || activeTabId;
|
|
15020
|
-
|
|
15923
|
+
const trackedRemoteRef = cleanFooterPayloadText(remoteRef, "", 4000);
|
|
15924
|
+
if (!skipConfirm && !(await confirmFooterGitBranchAction(branchName, { create, tabContext, remoteRef: trackedRemoteRef }))) return;
|
|
15021
15925
|
try {
|
|
15022
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: branchName, tabId };
|
|
15926
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: switchingLabel || branchName, switchingKey, tabId };
|
|
15023
15927
|
renderFooter();
|
|
15024
|
-
|
|
15928
|
+
// Remote-only switching sends the exact remote ref plus the intended local
|
|
15929
|
+
// branch; the server creates a tracking branch instead of detaching HEAD.
|
|
15930
|
+
const response = trackedRemoteRef
|
|
15931
|
+
? await api("/api/git-branch", { method: "POST", body: { branch: branchName, create, remoteRef: trackedRemoteRef }, tabId })
|
|
15932
|
+
: await api("/api/git-branch", { method: "POST", body: { branch: branchName, create }, tabId });
|
|
15025
15933
|
if (!isCurrentTabContext(tabContext)) return;
|
|
15026
|
-
if (!response.ok) throw new Error(response.error || `Failed to ${create ? "create and switch to" : "switch to"} ${branchName}`);
|
|
15934
|
+
if (!response.ok) throw new Error(response.error || (trackedRemoteRef ? `Failed to create local branch ${branchName} tracking ${trackedRemoteRef}` : `Failed to ${create ? "create and switch to" : "switch to"} ${branchName}`));
|
|
15027
15935
|
const switchedBranch = cleanStatusText(response.data?.branch || branchName);
|
|
15028
15936
|
footerBranchPickerOpen = false;
|
|
15029
15937
|
footerBranchPickerRequestSerial += 1;
|
|
15030
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", current: switchedBranch };
|
|
15938
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", switchingKey: "", current: switchedBranch };
|
|
15031
15939
|
if (create) updateFooterBranchCreateDraft({ name: "" });
|
|
15032
15940
|
applyOptimisticGitFooterBranch(switchedBranch, tabContext);
|
|
15033
|
-
addEvent(response.data?.created ? `Created and switched to git branch ${switchedBranch}.` : response.data?.switched === false ? `Already on git branch ${switchedBranch}.` : `Switched git branch to ${switchedBranch}.`, "info");
|
|
15941
|
+
addEvent(trackedRemoteRef ? `Created local branch ${switchedBranch} tracking ${trackedRemoteRef} and switched this checkout.` : response.data?.created ? `Created and switched to git branch ${switchedBranch}.` : response.data?.switched === false ? `Already on git branch ${switchedBranch}.` : `Switched git branch to ${switchedBranch}.`, "info");
|
|
15034
15942
|
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
15035
15943
|
} catch (error) {
|
|
15036
15944
|
if (isCurrentTabContext(tabContext)) {
|
|
15037
|
-
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", error: error.message || String(error) };
|
|
15945
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: false, switching: "", switchingKey: "", error: error.message || String(error) };
|
|
15038
15946
|
addEvent(error.message || String(error), "error");
|
|
15039
15947
|
}
|
|
15040
15948
|
} finally {
|
|
@@ -15165,52 +16073,95 @@ function renderFooterBranchCreateForm(state = footerBranchPickerState) {
|
|
|
15165
16073
|
}
|
|
15166
16074
|
|
|
15167
16075
|
function footerBranchWorktreePath(branch, state = footerBranchPickerState) {
|
|
16076
|
+
// Remote-only rows have no checkout yet and must never inherit the worktree
|
|
16077
|
+
// of an unrelated same-named local branch.
|
|
16078
|
+
if (branch?.remote) return "";
|
|
15168
16079
|
const direct = cleanFooterPayloadText(branch?.worktreePath, "", 4000);
|
|
15169
16080
|
if (direct) return direct;
|
|
15170
16081
|
return cleanFooterPayloadText(state.occupiedBranches?.find((item) => item.branch === branch?.name)?.path, "", 4000);
|
|
15171
16082
|
}
|
|
15172
16083
|
|
|
15173
16084
|
function footerBranchOptionDetail(branch, state, { selected, worktreePath } = {}) {
|
|
15174
|
-
if (state.switching === branch
|
|
16085
|
+
if (state.switchingKey ? state.switchingKey === branch.key : state.switching === footerBranchOptionLabel(branch)) return "opening…";
|
|
15175
16086
|
if (selected) return branch.worktreeCurrent ? "current branch in this worktree" : "current branch";
|
|
16087
|
+
if (branch.remote) return `remote-only · creates local branch ${branch.name} tracking ${branch.remoteRef}`;
|
|
15176
16088
|
if (worktreePath) return branch.mainWorktree ? "checked out in main worktree · open tab" : "checked out in another worktree · open tab";
|
|
15177
16089
|
return "open branch in a new worktree tab";
|
|
15178
16090
|
}
|
|
15179
16091
|
|
|
15180
16092
|
function openFooterBranchOption(branch, state = footerBranchPickerState) {
|
|
16093
|
+
if (branch.remote) return createFooterGitBranchWorktree(branch.name, { skipConfirm: true, chooseBase: false, remoteRef: branch.remoteRef, switchingLabel: footerBranchOptionLabel(branch), switchingKey: branch.key });
|
|
15181
16094
|
const worktreePath = footerBranchWorktreePath(branch, state);
|
|
15182
|
-
if (worktreePath && !branch.worktreeCurrent) return openFooterGitWorktree(worktreePath, { branchName: branch.name, skipConfirm: true });
|
|
15183
|
-
return createFooterGitBranchWorktree(branch.name, { skipConfirm: true, chooseBase: false });
|
|
16095
|
+
if (worktreePath && !branch.worktreeCurrent) return openFooterGitWorktree(worktreePath, { branchName: branch.name, skipConfirm: true, switchingKey: branch.key });
|
|
16096
|
+
return createFooterGitBranchWorktree(branch.name, { skipConfirm: true, chooseBase: false, switchingKey: branch.key });
|
|
16097
|
+
}
|
|
16098
|
+
|
|
16099
|
+
function footerBranchSwitchAvailability(branch = {}, state = {}, worktreePath = "") {
|
|
16100
|
+
if (state.switching) {
|
|
16101
|
+
return {
|
|
16102
|
+
disabled: true,
|
|
16103
|
+
label: "Action running…",
|
|
16104
|
+
reason: `Cannot switch this checkout while the branch action for ${state.switching} is still running.`,
|
|
16105
|
+
};
|
|
16106
|
+
}
|
|
16107
|
+
if (state.loading) {
|
|
16108
|
+
return {
|
|
16109
|
+
disabled: true,
|
|
16110
|
+
label: "Refreshing…",
|
|
16111
|
+
reason: "Cannot switch this checkout until the latest branch and worktree information finishes loading.",
|
|
16112
|
+
};
|
|
16113
|
+
}
|
|
16114
|
+
if (worktreePath) {
|
|
16115
|
+
const location = branch.mainWorktree ? "the main worktree" : "another worktree";
|
|
16116
|
+
return {
|
|
16117
|
+
disabled: true,
|
|
16118
|
+
label: branch.mainWorktree ? "In main worktree" : "In another worktree",
|
|
16119
|
+
reason: `Cannot switch this checkout because ${branch.name} is already checked out in ${location} at ${worktreePath}. Open that worktree instead.`,
|
|
16120
|
+
};
|
|
16121
|
+
}
|
|
16122
|
+
return { disabled: false, label: "Switch here", reason: "" };
|
|
15184
16123
|
}
|
|
15185
16124
|
|
|
15186
16125
|
function renderFooterBranchOption(branch, state = footerBranchPickerState) {
|
|
15187
|
-
const selected = branch.current || (!!state.current && branch.name === state.current);
|
|
16126
|
+
const selected = !branch.remote && (branch.current || (!!state.current && branch.name === state.current));
|
|
15188
16127
|
const worktreePath = footerBranchWorktreePath(branch, state);
|
|
15189
16128
|
const busy = state.loading || !!state.switching;
|
|
15190
16129
|
const primaryDisabled = busy || selected;
|
|
15191
|
-
const row = make("div", `footer-branch-option-row${selected ? " active" : ""}${worktreePath && !branch.worktreeCurrent ? " worktree-occupied" : ""}`);
|
|
16130
|
+
const row = make("div", `footer-branch-option-row${selected ? " active" : ""}${branch.remote ? " remote-only" : ""}${worktreePath && !branch.worktreeCurrent ? " worktree-occupied" : ""}`);
|
|
15192
16131
|
row.setAttribute("role", "option");
|
|
15193
16132
|
row.setAttribute("aria-selected", selected ? "true" : "false");
|
|
15194
16133
|
|
|
15195
16134
|
const primary = make("button", "footer-model-option footer-branch-option footer-branch-primary-action");
|
|
15196
16135
|
primary.type = "button";
|
|
15197
16136
|
primary.disabled = primaryDisabled;
|
|
15198
|
-
primary.title = selected
|
|
16137
|
+
primary.title = selected
|
|
16138
|
+
? `Current branch: ${branch.name}`
|
|
16139
|
+
: branch.remote
|
|
16140
|
+
? `Remote-only branch ${branch.remoteRef}: create local branch ${branch.name} tracking it and open a new Git worktree tab`
|
|
16141
|
+
: worktreePath ? `Open existing worktree: ${worktreePath}` : `Open ${branch.name} in a new Git worktree tab`;
|
|
15199
16142
|
primary.append(
|
|
15200
|
-
make("span", "footer-model-option-main", branch
|
|
16143
|
+
make("span", "footer-model-option-main", footerBranchOptionLabel(branch)),
|
|
15201
16144
|
make("span", "footer-model-option-name", footerBranchOptionDetail(branch, state, { selected, worktreePath })),
|
|
15202
16145
|
);
|
|
15203
16146
|
if (!primaryDisabled) primary.addEventListener("click", () => openFooterBranchOption(branch, state));
|
|
15204
16147
|
row.append(primary);
|
|
15205
16148
|
|
|
15206
16149
|
if (!selected) {
|
|
15207
|
-
const
|
|
16150
|
+
const availability = footerBranchSwitchAvailability(branch, state, worktreePath);
|
|
16151
|
+
const advanced = make("button", "footer-branch-advanced-action", availability.label);
|
|
15208
16152
|
advanced.type = "button";
|
|
15209
|
-
advanced.disabled =
|
|
15210
|
-
advanced.title =
|
|
15211
|
-
?
|
|
15212
|
-
: `Advanced: git switch ${branch.name} in this checkout
|
|
15213
|
-
|
|
16153
|
+
advanced.disabled = availability.disabled;
|
|
16154
|
+
advanced.title = availability.reason || (branch.remote
|
|
16155
|
+
? `Advanced: git switch --track -c ${branch.name} ${branch.remoteRef} in this checkout`
|
|
16156
|
+
: `Advanced: git switch ${branch.name} in this checkout`);
|
|
16157
|
+
if (availability.reason) {
|
|
16158
|
+
advanced.dataset.disabledReason = availability.reason;
|
|
16159
|
+
advanced.setAttribute("aria-label", `${availability.label}. ${availability.reason}`);
|
|
16160
|
+
} else {
|
|
16161
|
+
advanced.addEventListener("click", () => branch.remote
|
|
16162
|
+
? applyFooterGitBranch(branch.name, { remoteRef: branch.remoteRef, switchingLabel: footerBranchOptionLabel(branch), switchingKey: branch.key })
|
|
16163
|
+
: applyFooterGitBranch(branch.name, { switchingKey: branch.key }));
|
|
16164
|
+
}
|
|
15214
16165
|
row.append(advanced);
|
|
15215
16166
|
}
|
|
15216
16167
|
return row;
|
|
@@ -15328,14 +16279,14 @@ function renderFooterBranchPicker() {
|
|
|
15328
16279
|
return picker;
|
|
15329
16280
|
}
|
|
15330
16281
|
if (state.loading && state.branches.length === 0) {
|
|
15331
|
-
picker.append(make("div", "footer-model-picker-empty muted", "Loading
|
|
16282
|
+
picker.append(make("div", "footer-model-picker-empty muted", "Loading local and fetched remote branches and worktrees… Worktree creation is available once branch data loads."), renderFooterBranchCreateForm(state));
|
|
15332
16283
|
return picker;
|
|
15333
16284
|
}
|
|
15334
16285
|
|
|
15335
|
-
const hasOtherBranches = state.branches.some((branch) => !branch.current && branch.name !== state.current);
|
|
16286
|
+
const hasOtherBranches = state.branches.some((branch) => branch.remote || (!branch.current && branch.name !== state.current));
|
|
15336
16287
|
if (!state.loading && !hasOtherBranches) {
|
|
15337
16288
|
const empty = make("div", "footer-model-picker-empty muted");
|
|
15338
|
-
empty.append(make("strong", undefined, "No other local branches available."), make("span", undefined, "
|
|
16289
|
+
empty.append(make("strong", undefined, "No other local or fetched remote branches available."), make("span", undefined, " Fetch to list remote branches, or create a branch worktree from origin/main or the current workspace HEAD to continue."));
|
|
15339
16290
|
picker.append(empty);
|
|
15340
16291
|
}
|
|
15341
16292
|
|
|
@@ -16021,6 +16972,7 @@ async function changeActiveTabCwd() {
|
|
|
16021
16972
|
return;
|
|
16022
16973
|
}
|
|
16023
16974
|
|
|
16975
|
+
if (response.data?.changed !== false) closeFileViewer();
|
|
16024
16976
|
const nextContext = setActiveTabId(response.data?.tab?.id || activeTabId);
|
|
16025
16977
|
resetActiveTabUi();
|
|
16026
16978
|
renderTabs();
|
|
@@ -16252,6 +17204,180 @@ async function refreshCodexUsage({ forceAuthRefresh = false } = {}) {
|
|
|
16252
17204
|
}
|
|
16253
17205
|
}
|
|
16254
17206
|
|
|
17207
|
+
// Codex subscription Fast mode is owned by the optional pi-extension-codex-fast-mode package. The
|
|
17208
|
+
// browser only reads the sanitized tab-scoped server snapshot and asks the server to run the
|
|
17209
|
+
// package-owned /fast-mode command; it never sees ChatGPT credentials or request payloads.
|
|
17210
|
+
let codexFastModeState = { available: false, enabled: false, statusKnown: false, busy: false, model: null, modelEligible: false, unavailableReason: "", creditNotice: "" };
|
|
17211
|
+
let codexFastModeLoaded = false;
|
|
17212
|
+
let codexFastModeBusy = false;
|
|
17213
|
+
let codexFastModeNotice = "";
|
|
17214
|
+
let codexFastModeSelection = "normal";
|
|
17215
|
+
|
|
17216
|
+
function codexFastModeControlDisabled() {
|
|
17217
|
+
return !codexFastModeLoaded
|
|
17218
|
+
|| !codexFastModeState.available
|
|
17219
|
+
|| !isOptionalFeatureEnabled("codexFastMode")
|
|
17220
|
+
|| codexFastModeBusy
|
|
17221
|
+
|| codexFastModeState.busy === true;
|
|
17222
|
+
}
|
|
17223
|
+
|
|
17224
|
+
function codexFastModeStatusText() {
|
|
17225
|
+
if (codexFastModeNotice) return codexFastModeNotice;
|
|
17226
|
+
if (!isOptionalFeatureEnabled("codexFastMode")) return optionalFeatureUnavailableMessage("codexFastMode");
|
|
17227
|
+
if (!codexFastModeLoaded) return "Checking Codex Fast mode…";
|
|
17228
|
+
if (!codexFastModeState.available) return codexFastModeState.unavailableReason || optionalFeatureUnavailableMessage("codexFastMode");
|
|
17229
|
+
const parts = [];
|
|
17230
|
+
parts.push(codexFastModeState.statusKnown
|
|
17231
|
+
? `Session mode: ${codexFastModeState.enabled ? "Fast" : "Normal"}.`
|
|
17232
|
+
: "Session mode: unknown until /fast-mode reports status.");
|
|
17233
|
+
if (codexFastModeState.busy) parts.push("This tab is busy; the mode cannot change during a running turn.");
|
|
17234
|
+
if (codexFastModeState.model && !codexFastModeState.modelEligible) {
|
|
17235
|
+
parts.push(`Active model ${codexFastModeState.model.provider}/${codexFastModeState.model.id} is not a subscription-backed openai-codex model, so Fast mode stays armed but unused.`);
|
|
17236
|
+
}
|
|
17237
|
+
if (codexFastModeState.creditNotice) parts.push(codexFastModeState.creditNotice);
|
|
17238
|
+
return parts.join(" ");
|
|
17239
|
+
}
|
|
17240
|
+
|
|
17241
|
+
function renderCodexFastModeControl({ syncSelection = true } = {}) {
|
|
17242
|
+
if (!elements.codexFastModeSelect || !elements.setCodexFastModeButton || !elements.codexFastModeStatus) return;
|
|
17243
|
+
if (syncSelection) {
|
|
17244
|
+
codexFastModeSelection = codexFastModeState.enabled ? "fast" : "normal";
|
|
17245
|
+
elements.codexFastModeSelect.value = codexFastModeSelection;
|
|
17246
|
+
}
|
|
17247
|
+
const controlDisabled = codexFastModeControlDisabled();
|
|
17248
|
+
elements.codexFastModeSelect.disabled = controlDisabled;
|
|
17249
|
+
elements.setCodexFastModeButton.disabled = controlDisabled
|
|
17250
|
+
|| elements.codexFastModeSelect.value === (codexFastModeState.enabled ? "fast" : "normal");
|
|
17251
|
+
elements.setCodexFastModeButton.textContent = codexFastModeBusy ? "Applying…" : "Apply";
|
|
17252
|
+
elements.codexFastModeStatus.textContent = codexFastModeStatusText();
|
|
17253
|
+
const warn = !!codexFastModeNotice
|
|
17254
|
+
|| (codexFastModeLoaded && !codexFastModeState.available)
|
|
17255
|
+
|| codexFastModeState.busy === true
|
|
17256
|
+
|| !isOptionalFeatureEnabled("codexFastMode");
|
|
17257
|
+
elements.codexFastModeStatus.classList.toggle("warning", warn);
|
|
17258
|
+
}
|
|
17259
|
+
|
|
17260
|
+
function applyCodexFastModeData(data) {
|
|
17261
|
+
codexFastModeState = {
|
|
17262
|
+
available: data?.available === true,
|
|
17263
|
+
enabled: data?.enabled === true,
|
|
17264
|
+
statusKnown: data?.statusKnown === true,
|
|
17265
|
+
busy: data?.busy === true,
|
|
17266
|
+
model: data?.model || null,
|
|
17267
|
+
modelEligible: data?.modelEligible === true,
|
|
17268
|
+
unavailableReason: data?.unavailableReason || "",
|
|
17269
|
+
creditNotice: data?.creditNotice || "",
|
|
17270
|
+
};
|
|
17271
|
+
if (codexFastModeState.available) optionalFeatureAvailability.codexFastMode = true;
|
|
17272
|
+
}
|
|
17273
|
+
|
|
17274
|
+
function codexFastModeConfirmedOff(data) {
|
|
17275
|
+
return data?.statusKnown === true && data?.enabled !== true;
|
|
17276
|
+
}
|
|
17277
|
+
|
|
17278
|
+
function applyCodexFastModeStatus(statusText) {
|
|
17279
|
+
const status = String(statusText || "").trim().toLowerCase();
|
|
17280
|
+
if (status !== "on" && status !== "off") return false;
|
|
17281
|
+
codexFastModeState = {
|
|
17282
|
+
...codexFastModeState,
|
|
17283
|
+
available: true,
|
|
17284
|
+
enabled: status === "on",
|
|
17285
|
+
statusKnown: true,
|
|
17286
|
+
};
|
|
17287
|
+
codexFastModeLoaded = true;
|
|
17288
|
+
codexFastModeNotice = "";
|
|
17289
|
+
renderCodexFastModeControl();
|
|
17290
|
+
if (status === "on" && !isOptionalFeatureEnabled("codexFastMode")) {
|
|
17291
|
+
const tabContext = activeTabContext();
|
|
17292
|
+
queueMicrotask(() => refreshCodexFastMode(tabContext).catch((error) => {
|
|
17293
|
+
if (isCurrentTabContext(tabContext)) addEvent(`Disabled Codex Fast mode could not be disarmed: ${error.message || String(error)}`, "error");
|
|
17294
|
+
}));
|
|
17295
|
+
}
|
|
17296
|
+
return true;
|
|
17297
|
+
}
|
|
17298
|
+
|
|
17299
|
+
async function refreshCodexFastMode(tabContext = activeTabContext()) {
|
|
17300
|
+
if (!elements.codexFastModeSelect || !tabContext.tabId) return codexFastModeState;
|
|
17301
|
+
const featureEnabled = isOptionalFeatureEnabled("codexFastMode");
|
|
17302
|
+
try {
|
|
17303
|
+
let response = await api("/api/codex-fast-mode", { tabId: tabContext.tabId });
|
|
17304
|
+
let data = response.data || {};
|
|
17305
|
+
// Browser disable is global while extension state is session/branch local. Keep querying even
|
|
17306
|
+
// when hidden and disarm a restored branch before it can silently remain on.
|
|
17307
|
+
if (!featureEnabled && data.available && !codexFastModeConfirmedOff(data)) {
|
|
17308
|
+
if (data.busy) throw new Error("this tab is busy; Fast mode will be disarmed when it becomes idle");
|
|
17309
|
+
response = await api("/api/codex-fast-mode", { method: "PUT", body: { enabled: false }, tabId: tabContext.tabId });
|
|
17310
|
+
data = response.data || {};
|
|
17311
|
+
if (!codexFastModeConfirmedOff(data)) throw new Error("the extension did not confirm Fast mode off");
|
|
17312
|
+
}
|
|
17313
|
+
if (!isCurrentTabContext(tabContext)) return codexFastModeState;
|
|
17314
|
+
applyCodexFastModeData(data);
|
|
17315
|
+
codexFastModeNotice = "";
|
|
17316
|
+
} catch (error) {
|
|
17317
|
+
if (!isCurrentTabContext(tabContext)) return codexFastModeState;
|
|
17318
|
+
codexFastModeState = { ...codexFastModeState, available: false, busy: false, unavailableReason: `Codex Fast mode unavailable: ${error.message || String(error)}.` };
|
|
17319
|
+
if (!featureEnabled) throw error;
|
|
17320
|
+
} finally {
|
|
17321
|
+
if (isCurrentTabContext(tabContext)) {
|
|
17322
|
+
codexFastModeLoaded = true;
|
|
17323
|
+
renderCodexFastModeControl();
|
|
17324
|
+
}
|
|
17325
|
+
}
|
|
17326
|
+
return codexFastModeState;
|
|
17327
|
+
}
|
|
17328
|
+
|
|
17329
|
+
async function applyCodexFastMode() {
|
|
17330
|
+
if (!elements.codexFastModeSelect || codexFastModeBusy) return;
|
|
17331
|
+
const tabContext = activeTabContext();
|
|
17332
|
+
if (!tabContext.tabId) return;
|
|
17333
|
+
const enabled = elements.codexFastModeSelect.value === "fast";
|
|
17334
|
+
if (enabled === codexFastModeState.enabled) return;
|
|
17335
|
+
codexFastModeBusy = true;
|
|
17336
|
+
codexFastModeNotice = "";
|
|
17337
|
+
renderCodexFastModeControl({ syncSelection: false });
|
|
17338
|
+
try {
|
|
17339
|
+
const response = await api("/api/codex-fast-mode", { method: "PUT", body: { enabled }, tabId: tabContext.tabId });
|
|
17340
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
17341
|
+
applyCodexFastModeData(response.data);
|
|
17342
|
+
addEvent(enabled
|
|
17343
|
+
? "Codex Fast mode requested for this session. It asks supported Codex models for about 1.5x faster responses and may spend 2x credits on GPT-5.4 or 2.5x on GPT-5.5/5.6."
|
|
17344
|
+
: "Codex Fast mode turned off for this session; requests return to the standard tier.", "info");
|
|
17345
|
+
} catch (error) {
|
|
17346
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
17347
|
+
codexFastModeNotice = `Failed to change Codex Fast mode: ${error.message || String(error)}. You can retry.`;
|
|
17348
|
+
addEvent(codexFastModeNotice, "error");
|
|
17349
|
+
} finally {
|
|
17350
|
+
codexFastModeBusy = false;
|
|
17351
|
+
if (isCurrentTabContext(tabContext)) renderCodexFastModeControl();
|
|
17352
|
+
}
|
|
17353
|
+
}
|
|
17354
|
+
|
|
17355
|
+
// Optional-features Disable is browser-global while Fast mode is tab/session scoped. Disarm every
|
|
17356
|
+
// live tab first and abort the browser-side disable if any armed or unknown instance cannot confirm
|
|
17357
|
+
// off. Future branch restores are handled by refreshCodexFastMode even while the control is hidden.
|
|
17358
|
+
async function disableCodexFastModeIntegration() {
|
|
17359
|
+
const tabIds = [...new Set(tabs.filter((tab) => tab?.id && tab.running !== false).map((tab) => tab.id))];
|
|
17360
|
+
const snapshots = await Promise.all(tabIds.map(async (tabId) => {
|
|
17361
|
+
const response = await api("/api/codex-fast-mode", { tabId });
|
|
17362
|
+
return { tabId, data: response.data || {} };
|
|
17363
|
+
}));
|
|
17364
|
+
|
|
17365
|
+
for (const { tabId, data } of snapshots) {
|
|
17366
|
+
if (!data.available) {
|
|
17367
|
+
if (data.statusKnown && data.enabled) throw new Error(`tab ${tabId} still reports Fast mode on but /fast-mode is unavailable`);
|
|
17368
|
+
continue;
|
|
17369
|
+
}
|
|
17370
|
+
if (data.busy && !codexFastModeConfirmedOff(data)) throw new Error(`tab ${tabId} is busy; wait for it to finish before disabling Codex Fast mode`);
|
|
17371
|
+
}
|
|
17372
|
+
|
|
17373
|
+
for (const { tabId, data } of snapshots) {
|
|
17374
|
+
if (!data.available || codexFastModeConfirmedOff(data)) continue;
|
|
17375
|
+
const response = await api("/api/codex-fast-mode", { method: "PUT", body: { enabled: false }, tabId });
|
|
17376
|
+
if (!codexFastModeConfirmedOff(response.data)) throw new Error(`tab ${tabId} did not confirm Codex Fast mode off`);
|
|
17377
|
+
if (tabId === activeTabId) applyCodexFastModeData(response.data);
|
|
17378
|
+
}
|
|
17379
|
+
}
|
|
17380
|
+
|
|
16255
17381
|
function scheduleRefreshCodexUsage(delay = CODEX_USAGE_REFRESH_MS) {
|
|
16256
17382
|
clearTimeout(refreshCodexUsageTimer);
|
|
16257
17383
|
refreshCodexUsageTimer = setTimeout(() => {
|
|
@@ -16405,7 +17531,7 @@ function subagentTabsWithRunningAgents() {
|
|
|
16405
17531
|
const gates = visibleSubagentGates(tab, dismissedSubagentGateKeys, now);
|
|
16406
17532
|
return { ...tab, gates, gateCount: gates.length };
|
|
16407
17533
|
})
|
|
16408
|
-
.filter((tab) =>
|
|
17534
|
+
.filter((tab) => (Array.isArray(tab?.runs) && tab.runs.length > 0) || Number(tab?.gateCount || 0) > 0)
|
|
16409
17535
|
.sort((a, b) => Number(a.tabIndex || 0) - Number(b.tabIndex || 0) || String(a.tabTitle || "").localeCompare(String(b.tabTitle || "")));
|
|
16410
17536
|
}
|
|
16411
17537
|
|
|
@@ -16439,6 +17565,116 @@ function subagentExecutionFacts(agent = {}) {
|
|
|
16439
17565
|
return [`model ${model || "unknown"}`, `reasoning ${thinking || "unknown"}`];
|
|
16440
17566
|
}
|
|
16441
17567
|
|
|
17568
|
+
function subagentRunIsRunning(run = {}, agent = null) {
|
|
17569
|
+
if (run?.status && run.status !== "running") return false;
|
|
17570
|
+
const status = String(agent?.status || "").trim();
|
|
17571
|
+
return !status || ["running", "queued", "pending"].includes(status);
|
|
17572
|
+
}
|
|
17573
|
+
|
|
17574
|
+
function subagentRunCanCancel(run = {}, agent = null) {
|
|
17575
|
+
return run?.source !== "workflow" && subagentRunIsRunning(run, agent);
|
|
17576
|
+
}
|
|
17577
|
+
|
|
17578
|
+
function subagentRunStateLabel(run = {}) {
|
|
17579
|
+
if (run?.status === "cancelled") return "cancelled by you";
|
|
17580
|
+
if (run?.status === "failed") return "failed";
|
|
17581
|
+
if (run?.status === "done") return "done";
|
|
17582
|
+
return "running";
|
|
17583
|
+
}
|
|
17584
|
+
|
|
17585
|
+
function setSubagentCancelStatus(message = "", level = "muted") {
|
|
17586
|
+
if (!elements.subagentCancelStatus) return;
|
|
17587
|
+
elements.subagentCancelStatus.textContent = message;
|
|
17588
|
+
elements.subagentCancelStatus.className = `subagent-cancel-status ${message ? level : "muted"}`;
|
|
17589
|
+
elements.subagentCancelStatus.hidden = !message;
|
|
17590
|
+
}
|
|
17591
|
+
|
|
17592
|
+
function setSubagentCancelSubmitting(submitting) {
|
|
17593
|
+
subagentCancelSubmitting = !!submitting;
|
|
17594
|
+
if (elements.subagentCancelSubmitButton) {
|
|
17595
|
+
elements.subagentCancelSubmitButton.disabled = subagentCancelSubmitting;
|
|
17596
|
+
elements.subagentCancelSubmitButton.textContent = subagentCancelSubmitting ? "Cancelling…" : "Cancel subagent";
|
|
17597
|
+
}
|
|
17598
|
+
if (elements.subagentCancelKeepRunningButton) elements.subagentCancelKeepRunningButton.disabled = subagentCancelSubmitting;
|
|
17599
|
+
}
|
|
17600
|
+
|
|
17601
|
+
function subagentCancelTargetLabel(selection = subagentCancelSelection) {
|
|
17602
|
+
if (!selection) return "subagent run";
|
|
17603
|
+
return `run ${selection.runId}`;
|
|
17604
|
+
}
|
|
17605
|
+
|
|
17606
|
+
function openSubagentCancelDialog(tab, run, agent = null) {
|
|
17607
|
+
if (!tab?.tabId || !run?.id || !subagentRunCanCancel(run, agent) || !elements.subagentCancelDialog) return;
|
|
17608
|
+
const agentCount = Array.isArray(run.agents) ? run.agents.length : 0;
|
|
17609
|
+
subagentCancelSelection = {
|
|
17610
|
+
tabId: tab.tabId,
|
|
17611
|
+
runId: run.id,
|
|
17612
|
+
agentCount,
|
|
17613
|
+
};
|
|
17614
|
+
if (elements.subagentCancelDialogSubtitle) {
|
|
17615
|
+
const scope = agentCount > 1 ? ` and all ${agentCount} agents in it` : "";
|
|
17616
|
+
elements.subagentCancelDialogSubtitle.textContent = `Cancel ${subagentCancelTargetLabel()}${scope}? The entire run will be stopped and the parent agent will be notified.`;
|
|
17617
|
+
}
|
|
17618
|
+
if (elements.subagentCancelReason) elements.subagentCancelReason.value = "";
|
|
17619
|
+
if (elements.subagentCancelNote) elements.subagentCancelNote.value = "";
|
|
17620
|
+
setSubagentCancelStatus();
|
|
17621
|
+
setSubagentCancelSubmitting(false);
|
|
17622
|
+
if (!elements.subagentCancelDialog.open) elements.subagentCancelDialog.showModal();
|
|
17623
|
+
queueMicrotask(() => elements.subagentCancelReason?.focus());
|
|
17624
|
+
}
|
|
17625
|
+
|
|
17626
|
+
function closeSubagentCancelDialog() {
|
|
17627
|
+
if (subagentCancelSubmitting) return;
|
|
17628
|
+
if (elements.subagentCancelDialog?.open) elements.subagentCancelDialog.close();
|
|
17629
|
+
}
|
|
17630
|
+
|
|
17631
|
+
async function submitSubagentCancel() {
|
|
17632
|
+
const selection = subagentCancelSelection;
|
|
17633
|
+
if (!selection || subagentCancelSubmitting) return;
|
|
17634
|
+
const reason = String(elements.subagentCancelReason?.value || "").trim();
|
|
17635
|
+
const note = String(elements.subagentCancelNote?.value || "").trim();
|
|
17636
|
+
setSubagentCancelSubmitting(true);
|
|
17637
|
+
setSubagentCancelStatus("Cancelling subagent…");
|
|
17638
|
+
try {
|
|
17639
|
+
await api("/api/subagents/cancel", {
|
|
17640
|
+
method: "POST",
|
|
17641
|
+
scoped: false,
|
|
17642
|
+
body: {
|
|
17643
|
+
tab: selection.tabId,
|
|
17644
|
+
runId: selection.runId,
|
|
17645
|
+
...(reason ? { reason } : {}),
|
|
17646
|
+
...(note ? { note } : {}),
|
|
17647
|
+
},
|
|
17648
|
+
});
|
|
17649
|
+
if (elements.subagentCancelDialog?.open) elements.subagentCancelDialog.close();
|
|
17650
|
+
addEvent(`cancelled ${subagentCancelTargetLabel(selection)}; the parent agent was notified`, "info");
|
|
17651
|
+
await refreshSubagents();
|
|
17652
|
+
scheduleRefreshSubagents();
|
|
17653
|
+
} catch (error) {
|
|
17654
|
+
const message = `subagent cancel failed: ${error.message || String(error)}`;
|
|
17655
|
+
setSubagentCancelStatus(message, "error");
|
|
17656
|
+
addEvent(message, "error");
|
|
17657
|
+
} finally {
|
|
17658
|
+
setSubagentCancelSubmitting(false);
|
|
17659
|
+
}
|
|
17660
|
+
}
|
|
17661
|
+
|
|
17662
|
+
async function dismissSubagentRun(tab, run) {
|
|
17663
|
+
if (!tab?.tabId || !run?.id || subagentRunIsRunning(run)) return;
|
|
17664
|
+
try {
|
|
17665
|
+
await api("/api/subagents/dismiss", {
|
|
17666
|
+
method: "POST",
|
|
17667
|
+
scoped: false,
|
|
17668
|
+
body: { tab: tab.tabId, runId: run.id },
|
|
17669
|
+
});
|
|
17670
|
+
addEvent(`dismissed finished subagent run ${run.id}`, "info");
|
|
17671
|
+
await refreshSubagents();
|
|
17672
|
+
scheduleRefreshSubagents();
|
|
17673
|
+
} catch (error) {
|
|
17674
|
+
addEvent(`subagent dismiss failed: ${error.message || String(error)}`, "error");
|
|
17675
|
+
}
|
|
17676
|
+
}
|
|
17677
|
+
|
|
16442
17678
|
function subagentOverlayTranscriptMessages(data = subagentOverlayData) {
|
|
16443
17679
|
const agent = data?.agent || subagentOverlaySelection?.agent || {};
|
|
16444
17680
|
return (Array.isArray(agent.transcript) ? agent.transcript : [])
|
|
@@ -16567,10 +17803,11 @@ function appendSubagentOverlayTranscript(parent, messages) {
|
|
|
16567
17803
|
|
|
16568
17804
|
function subagentOverlayStateFacts(data = subagentOverlayData) {
|
|
16569
17805
|
const agent = data?.agent || subagentOverlaySelection?.agent || {};
|
|
17806
|
+
const run = subagentOverlaySelection?.run || {};
|
|
16570
17807
|
return [
|
|
16571
|
-
agent.status || "running",
|
|
16572
|
-
data?.mode ||
|
|
16573
|
-
subagentSourceLabel(data?.source ||
|
|
17808
|
+
subagentRunIsRunning(run, agent) ? agent.status || "running" : subagentRunStateLabel(run),
|
|
17809
|
+
data?.mode || run.mode,
|
|
17810
|
+
subagentSourceLabel(data?.source || run.source),
|
|
16574
17811
|
agent.nested ? "nested" : "",
|
|
16575
17812
|
...subagentExecutionFacts(agent),
|
|
16576
17813
|
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
@@ -16626,7 +17863,7 @@ function renderSubagentOverlayWidget() {
|
|
|
16626
17863
|
const data = subagentOverlayData;
|
|
16627
17864
|
const agent = data?.agent || selection.agent || {};
|
|
16628
17865
|
const tab = tabs.find((item) => item.id === selection.tabId) || selection.tab;
|
|
16629
|
-
const running = !selection.finished && (
|
|
17866
|
+
const running = !selection.finished && subagentRunIsRunning(selection.run, agent);
|
|
16630
17867
|
const transcriptMessages = subagentOverlayTranscriptMessages(data);
|
|
16631
17868
|
const hasStructuredTranscript = transcriptMessages.length > 0;
|
|
16632
17869
|
const outputText = subagentOverlayOutputText(data);
|
|
@@ -16671,6 +17908,9 @@ function renderSubagentOverlayWidget() {
|
|
|
16671
17908
|
refreshSubagentOverlay().finally(() => scheduleSubagentOverlayRefresh());
|
|
16672
17909
|
}, "subagent-overlay-refresh-action");
|
|
16673
17910
|
refreshButton.disabled = subagentOverlayLoading || selection.finished;
|
|
17911
|
+
if (subagentRunCanCancel(selection.run, agent)) {
|
|
17912
|
+
actions.append(appRunnerActionButton("Cancel…", () => openSubagentCancelDialog(tab, selection.run, agent), "subagent-overlay-cancel-action danger"));
|
|
17913
|
+
}
|
|
16674
17914
|
actions.append(copyButton, refreshButton, appRunnerActionButton("Close", closeSubagentOverlay, "subagent-overlay-close-action"));
|
|
16675
17915
|
const details = [
|
|
16676
17916
|
`${tab?.title || `Terminal ${selection.tabIndex || "?"}`} · run ${selection.runId}`,
|
|
@@ -16688,7 +17928,8 @@ function renderSubagentOverlayWidget() {
|
|
|
16688
17928
|
|
|
16689
17929
|
function scheduleSubagentOverlayRefresh(delay = SUBAGENT_OVERLAY_REFRESH_MS) {
|
|
16690
17930
|
clearTimeout(subagentOverlayRefreshTimer);
|
|
16691
|
-
|
|
17931
|
+
const agent = subagentOverlayData?.agent || subagentOverlaySelection?.agent || null;
|
|
17932
|
+
if (!subagentOverlaySelection || subagentOverlaySelection.finished || !subagentRunIsRunning(subagentOverlaySelection.run, agent)) return;
|
|
16692
17933
|
subagentOverlayRefreshTimer = setTimeout(() => {
|
|
16693
17934
|
refreshSubagentOverlay().finally(() => scheduleSubagentOverlayRefresh());
|
|
16694
17935
|
}, delay);
|
|
@@ -16784,8 +18025,8 @@ function subagentTerminalViewTitle(view) {
|
|
|
16784
18025
|
}
|
|
16785
18026
|
|
|
16786
18027
|
function subagentTerminalViewIsRunning(view) {
|
|
16787
|
-
const
|
|
16788
|
-
return view?.finished !== true &&
|
|
18028
|
+
const agent = view?.data?.agent || view?.agent || null;
|
|
18029
|
+
return view?.finished !== true && subagentRunIsRunning(view?.run, agent);
|
|
16789
18030
|
}
|
|
16790
18031
|
|
|
16791
18032
|
function subagentTerminalViewMeaningfulSignature(view) {
|
|
@@ -16796,7 +18037,7 @@ function subagentTerminalViewMeaningfulSignature(view) {
|
|
|
16796
18037
|
function updateSubagentTerminalRefreshState(view, { running = subagentTerminalViewIsRunning(view) } = {}) {
|
|
16797
18038
|
if (!view || view.id !== activeSubagentTerminalId) return;
|
|
16798
18039
|
const status = [
|
|
16799
|
-
view.loading ? "Refreshing…" : running ? "Live view · refreshes automatically" : "View retained after the child stopped being tracked",
|
|
18040
|
+
view.loading ? "Refreshing…" : running ? "Live view · refreshes automatically" : view.finished ? "View retained after the child stopped being tracked" : "View retained after the run finished",
|
|
16800
18041
|
view.error,
|
|
16801
18042
|
].filter(Boolean).join(" · ");
|
|
16802
18043
|
elements.subagentTerminalStatus.setAttribute("aria-live", view.error ? "polite" : "off");
|
|
@@ -16822,7 +18063,7 @@ function renderSubagentTerminalView() {
|
|
|
16822
18063
|
const fallbackText = outputText || (running && agent.currentTool ? "" : running ? "Waiting for the first agent activity…" : "No recent output was captured.");
|
|
16823
18064
|
const parent = tabs.find((tab) => tab.id === view.parentTabId);
|
|
16824
18065
|
const facts = [
|
|
16825
|
-
view.finished ? "finished" : running ? "running" :
|
|
18066
|
+
view.finished ? "finished" : running ? "running" : subagentRunStateLabel(view.run),
|
|
16826
18067
|
view.run?.mode,
|
|
16827
18068
|
subagentSourceLabel(view.data?.source || view.run?.source),
|
|
16828
18069
|
agent.nested ? "nested" : "",
|
|
@@ -16852,13 +18093,18 @@ function renderSubagentTerminalView() {
|
|
|
16852
18093
|
|
|
16853
18094
|
updateSubagentTerminalRefreshState(view, { running });
|
|
16854
18095
|
elements.subagentTerminalCopyButton.disabled = !outputText;
|
|
18096
|
+
if (elements.subagentTerminalCancelButton) {
|
|
18097
|
+
const cancellable = subagentRunCanCancel(view.run, agent);
|
|
18098
|
+
elements.subagentTerminalCancelButton.hidden = !cancellable;
|
|
18099
|
+
elements.subagentTerminalCancelButton.disabled = !cancellable;
|
|
18100
|
+
}
|
|
16855
18101
|
if (shouldFollowOutput) requestAnimationFrame(() => { elements.subagentTerminalTranscript.scrollTop = elements.subagentTerminalTranscript.scrollHeight; });
|
|
16856
18102
|
}
|
|
16857
18103
|
|
|
16858
18104
|
function scheduleSubagentTerminalRefresh(delay = SUBAGENT_OVERLAY_REFRESH_MS) {
|
|
16859
18105
|
clearTimeout(subagentTerminalRefreshTimer);
|
|
16860
18106
|
const view = activeSubagentTerminalView();
|
|
16861
|
-
if (!view || view.finished) return;
|
|
18107
|
+
if (!view || view.finished || !subagentTerminalViewIsRunning(view)) return;
|
|
16862
18108
|
subagentTerminalRefreshTimer = setTimeout(() => {
|
|
16863
18109
|
refreshSubagentTerminalView(view.id).finally(() => scheduleSubagentTerminalRefresh());
|
|
16864
18110
|
}, delay);
|
|
@@ -16925,8 +18171,8 @@ async function activateSubagentTerminalView(viewId) {
|
|
|
16925
18171
|
scheduleSubagentTerminalRefresh();
|
|
16926
18172
|
}
|
|
16927
18173
|
|
|
16928
|
-
|
|
16929
|
-
if (!tab?.tabId || !run?.id || !agent?.id) return;
|
|
18174
|
+
function ensureSubagentTerminalView(tab, run, agent) {
|
|
18175
|
+
if (!tab?.tabId || !run?.id || !agent?.id) return null;
|
|
16930
18176
|
const id = subagentTerminalViewId(tab, run, agent);
|
|
16931
18177
|
const existing = subagentTerminalViews.get(id);
|
|
16932
18178
|
if (existing) {
|
|
@@ -16934,27 +18180,34 @@ async function openSubagentTerminal(tab, run, agent) {
|
|
|
16934
18180
|
existing.run = run;
|
|
16935
18181
|
existing.agent = agent;
|
|
16936
18182
|
existing.parentTitle = tab.tabTitle;
|
|
16937
|
-
|
|
16938
|
-
subagentTerminalViews.set(id, {
|
|
16939
|
-
id,
|
|
16940
|
-
parentTabId: tab.tabId,
|
|
16941
|
-
parentTitle: tab.tabTitle,
|
|
16942
|
-
tabIndex: tab.tabIndex,
|
|
16943
|
-
tab,
|
|
16944
|
-
run,
|
|
16945
|
-
agent,
|
|
16946
|
-
runId: run.id,
|
|
16947
|
-
agentId: agent.id,
|
|
16948
|
-
data: null,
|
|
16949
|
-
error: "",
|
|
16950
|
-
loading: false,
|
|
16951
|
-
finished: false,
|
|
16952
|
-
requestSerial: 0,
|
|
16953
|
-
openedAt: Date.now(),
|
|
16954
|
-
});
|
|
18183
|
+
return existing;
|
|
16955
18184
|
}
|
|
18185
|
+
const view = {
|
|
18186
|
+
id,
|
|
18187
|
+
parentTabId: tab.tabId,
|
|
18188
|
+
parentTitle: tab.tabTitle,
|
|
18189
|
+
tabIndex: tab.tabIndex,
|
|
18190
|
+
tab,
|
|
18191
|
+
run,
|
|
18192
|
+
agent,
|
|
18193
|
+
runId: run.id,
|
|
18194
|
+
agentId: agent.id,
|
|
18195
|
+
data: null,
|
|
18196
|
+
error: "",
|
|
18197
|
+
loading: false,
|
|
18198
|
+
finished: false,
|
|
18199
|
+
requestSerial: 0,
|
|
18200
|
+
openedAt: Date.now(),
|
|
18201
|
+
};
|
|
18202
|
+
subagentTerminalViews.set(id, view);
|
|
18203
|
+
return view;
|
|
18204
|
+
}
|
|
18205
|
+
|
|
18206
|
+
async function openSubagentTerminal(tab, run, agent) {
|
|
18207
|
+
const view = ensureSubagentTerminalView(tab, run, agent);
|
|
18208
|
+
if (!view) return;
|
|
16956
18209
|
try {
|
|
16957
|
-
await activateSubagentTerminalView(id);
|
|
18210
|
+
await activateSubagentTerminalView(view.id);
|
|
16958
18211
|
} catch (error) {
|
|
16959
18212
|
addEvent(`could not open subagent terminal: ${error.message || String(error)}`, "error");
|
|
16960
18213
|
}
|
|
@@ -16986,6 +18239,9 @@ async function copySubagentTerminalOutput() {
|
|
|
16986
18239
|
}
|
|
16987
18240
|
|
|
16988
18241
|
function removeSubagentTerminalViewsForParent(parentTabId) {
|
|
18242
|
+
for (const key of subagentTerminalRestoredParentTabs) {
|
|
18243
|
+
if (key.startsWith(`${parentTabId}\u0000`)) subagentTerminalRestoredParentTabs.delete(key);
|
|
18244
|
+
}
|
|
16989
18245
|
for (const [viewId, view] of subagentTerminalViews) {
|
|
16990
18246
|
if (view.parentTabId !== parentTabId) continue;
|
|
16991
18247
|
view.requestSerial += 1;
|
|
@@ -16995,17 +18251,64 @@ function removeSubagentTerminalViewsForParent(parentTabId) {
|
|
|
16995
18251
|
}
|
|
16996
18252
|
|
|
16997
18253
|
function syncSubagentTerminalViewsFromOverview() {
|
|
18254
|
+
let changed = false;
|
|
18255
|
+
const overviewTabs = Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : [];
|
|
16998
18256
|
for (const view of subagentTerminalViews.values()) {
|
|
16999
|
-
const tab =
|
|
18257
|
+
const tab = overviewTabs.find((candidate) => candidate.tabId === view.parentTabId);
|
|
17000
18258
|
const run = (Array.isArray(tab?.runs) ? tab.runs : []).find((candidate) => candidate.id === view.runId);
|
|
17001
18259
|
const agent = (Array.isArray(run?.agents) ? run.agents : []).find((candidate) => candidate.id === view.agentId);
|
|
17002
18260
|
if (tab) {
|
|
17003
18261
|
view.tab = tab;
|
|
17004
18262
|
view.parentTitle = tab.tabTitle;
|
|
18263
|
+
changed = true;
|
|
18264
|
+
}
|
|
18265
|
+
if (run) {
|
|
18266
|
+
view.run = run;
|
|
18267
|
+
changed = true;
|
|
18268
|
+
}
|
|
18269
|
+
if (agent) {
|
|
18270
|
+
view.agent = agent;
|
|
18271
|
+
if (view.data?.agent) view.data = { ...view.data, agent: { ...view.data.agent, ...agent } };
|
|
18272
|
+
changed = true;
|
|
17005
18273
|
}
|
|
17006
|
-
if (run) view.run = run;
|
|
17007
|
-
if (agent) view.agent = agent;
|
|
17008
18274
|
}
|
|
18275
|
+
const selection = subagentOverlaySelection;
|
|
18276
|
+
if (selection) {
|
|
18277
|
+
const tab = overviewTabs.find((candidate) => candidate.tabId === selection.tabId);
|
|
18278
|
+
const run = (Array.isArray(tab?.runs) ? tab.runs : []).find((candidate) => candidate.id === selection.runId);
|
|
18279
|
+
const agent = (Array.isArray(run?.agents) ? run.agents : []).find((candidate) => candidate.id === selection.agentId);
|
|
18280
|
+
if (tab) selection.tab = tab;
|
|
18281
|
+
if (run) {
|
|
18282
|
+
selection.run = run;
|
|
18283
|
+
changed = true;
|
|
18284
|
+
}
|
|
18285
|
+
if (agent) {
|
|
18286
|
+
selection.agent = agent;
|
|
18287
|
+
if (subagentOverlayData?.agent) subagentOverlayData = { ...subagentOverlayData, agent: { ...subagentOverlayData.agent, ...agent } };
|
|
18288
|
+
changed = true;
|
|
18289
|
+
}
|
|
18290
|
+
}
|
|
18291
|
+
return changed;
|
|
18292
|
+
}
|
|
18293
|
+
|
|
18294
|
+
function materializeRetainedSubagentTerminalViews() {
|
|
18295
|
+
if (subagentOpenMode !== "tab") return false;
|
|
18296
|
+
let materialized = false;
|
|
18297
|
+
for (const tab of Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : []) {
|
|
18298
|
+
if (tab?.available !== true || !tab?.tabId) continue;
|
|
18299
|
+
const restoreKey = `${tab.tabId}\u0000${tab.sessionFile || ""}`;
|
|
18300
|
+
if (subagentTerminalRestoredParentTabs.has(restoreKey)) continue;
|
|
18301
|
+
subagentTerminalRestoredParentTabs.add(restoreKey);
|
|
18302
|
+
for (const run of Array.isArray(tab.runs) ? tab.runs : []) {
|
|
18303
|
+
if (run?.status === "running" || run?.source === "workflow") continue;
|
|
18304
|
+
for (const agent of Array.isArray(run.agents) ? run.agents : []) {
|
|
18305
|
+
const id = subagentTerminalViewId(tab, run, agent);
|
|
18306
|
+
if (subagentTerminalViews.has(id)) continue;
|
|
18307
|
+
if (ensureSubagentTerminalView(tab, run, agent)) materialized = true;
|
|
18308
|
+
}
|
|
18309
|
+
}
|
|
18310
|
+
}
|
|
18311
|
+
return materialized;
|
|
17009
18312
|
}
|
|
17010
18313
|
|
|
17011
18314
|
function renderSubagentTerminalTab(view) {
|
|
@@ -17042,9 +18345,10 @@ function openSubagentOutput(tab, run, agent) {
|
|
|
17042
18345
|
}
|
|
17043
18346
|
|
|
17044
18347
|
function renderSubagentAgent(tab, run, agent) {
|
|
17045
|
-
const
|
|
18348
|
+
const running = subagentRunIsRunning(run, agent);
|
|
18349
|
+
const row = make("button", `subagent-agent-row${agent?.nested ? " nested" : ""}${running ? " running" : " finished"}`);
|
|
17046
18350
|
row.type = "button";
|
|
17047
|
-
const dot = make("span", "subagent-running-dot");
|
|
18351
|
+
const dot = make("span", running ? "subagent-running-dot" : `subagent-state-dot ${agent?.status || "done"}`);
|
|
17048
18352
|
dot.setAttribute("aria-hidden", "true");
|
|
17049
18353
|
const content = make("div", "subagent-agent-content");
|
|
17050
18354
|
content.append(make("strong", "subagent-agent-name", agent?.name || "subagent"));
|
|
@@ -17055,17 +18359,55 @@ function renderSubagentAgent(tab, run, agent) {
|
|
|
17055
18359
|
subagentSourceLabel(run?.source),
|
|
17056
18360
|
...subagentExecutionFacts(agent),
|
|
17057
18361
|
agent?.currentTool ? `tool: ${agent.currentTool}` : "",
|
|
17058
|
-
elapsed ? `running ${elapsed}` :
|
|
18362
|
+
running && elapsed ? `running ${elapsed}` : agent?.status || subagentRunStateLabel(run),
|
|
17059
18363
|
].filter(Boolean);
|
|
17060
18364
|
content.append(make("span", "subagent-agent-meta", facts.join(" · ")));
|
|
17061
18365
|
row.append(dot, content);
|
|
17062
|
-
const destination = subagentOpenMode === "tab" ? "subagent tab" : "
|
|
18366
|
+
const destination = subagentOpenMode === "tab" ? "subagent tab" : "output overlay";
|
|
17063
18367
|
row.title = `${agent?.name || "subagent"} · ${facts.join(" · ")} · run ${run?.id || "unknown"} · open ${destination}`;
|
|
17064
18368
|
row.setAttribute("aria-label", `Open ${destination} for ${agent?.name || "subagent"} in ${tab?.tabTitle || `Terminal ${tab?.tabIndex || "?"}`}`);
|
|
17065
18369
|
row.addEventListener("click", () => openSubagentOutput(tab, run, agent));
|
|
17066
18370
|
return row;
|
|
17067
18371
|
}
|
|
17068
18372
|
|
|
18373
|
+
function renderSubagentRun(tab, run) {
|
|
18374
|
+
const running = subagentRunIsRunning(run);
|
|
18375
|
+
const card = make("section", `subagent-run ${running ? "running" : run?.status || "done"}`);
|
|
18376
|
+
const header = make("div", "subagent-run-header");
|
|
18377
|
+
const title = make("div", "subagent-run-title");
|
|
18378
|
+
const elapsed = subagentRunElapsed(run);
|
|
18379
|
+
title.append(
|
|
18380
|
+
make("strong", undefined, `Run ${run?.id || "unknown"}`),
|
|
18381
|
+
make("span", "subagent-run-meta", [subagentSourceLabel(run?.source), run?.mode, running && elapsed ? `running ${elapsed}` : ""].filter(Boolean).join(" · ")),
|
|
18382
|
+
);
|
|
18383
|
+
const actions = make("div", "subagent-run-actions");
|
|
18384
|
+
if (subagentRunCanCancel(run)) {
|
|
18385
|
+
const cancel = make("button", "subagent-run-cancel", "Cancel…");
|
|
18386
|
+
cancel.type = "button";
|
|
18387
|
+
cancel.addEventListener("click", () => openSubagentCancelDialog(tab, run));
|
|
18388
|
+
actions.append(cancel);
|
|
18389
|
+
} else if (!running) {
|
|
18390
|
+
actions.append(make("span", `subagent-run-state ${run?.status || "done"}`, subagentRunStateLabel(run)));
|
|
18391
|
+
if (run?.source !== "workflow") {
|
|
18392
|
+
const dismiss = make("button", "subagent-run-dismiss", "×");
|
|
18393
|
+
dismiss.type = "button";
|
|
18394
|
+
applyStyledTooltip(dismiss, "Dismiss finished run", { ariaLabel: "Dismiss finished run" });
|
|
18395
|
+
dismiss.addEventListener("click", () => dismissSubagentRun(tab, run));
|
|
18396
|
+
actions.append(dismiss);
|
|
18397
|
+
}
|
|
18398
|
+
}
|
|
18399
|
+
header.append(title, actions);
|
|
18400
|
+
card.append(header);
|
|
18401
|
+
const agents = (Array.isArray(run?.agents) ? run.agents : [])
|
|
18402
|
+
.slice()
|
|
18403
|
+
.sort((a, b) => Number(a.index || 0) - Number(b.index || 0) || String(a.name || "").localeCompare(String(b.name || "")));
|
|
18404
|
+
const list = make("div", "subagent-run-agents");
|
|
18405
|
+
for (const agent of agents) list.append(renderSubagentAgent(tab, run, agent));
|
|
18406
|
+
if (!list.childElementCount) list.append(make("div", "subagents-empty", "No agent details were captured for this run."));
|
|
18407
|
+
card.append(list);
|
|
18408
|
+
return card;
|
|
18409
|
+
}
|
|
18410
|
+
|
|
17069
18411
|
function subagentGateStatusLabel(status) {
|
|
17070
18412
|
return status === "satisfied" ? "satisfied" : status === "running" ? "running" : status === "cancelled" ? "cancelled" : "failed";
|
|
17071
18413
|
}
|
|
@@ -17137,21 +18479,22 @@ function renderSubagentTabGroup(tab) {
|
|
|
17137
18479
|
make("strong", undefined, tab.tabTitle || `Terminal ${tab.tabIndex || "?"}`),
|
|
17138
18480
|
make("span", "subagent-tab-session", `Terminal ${tab.tabIndex || "?"} · ${subagentTabMeta(tab)}`),
|
|
17139
18481
|
);
|
|
17140
|
-
const
|
|
18482
|
+
const runs = (Array.isArray(tab.runs) ? tab.runs : [])
|
|
18483
|
+
.slice()
|
|
18484
|
+
.sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0) || String(a.id || "").localeCompare(String(b.id || "")));
|
|
18485
|
+
const runningAgents = Number(tab.runningAgents || 0);
|
|
18486
|
+
const retainedRuns = runs.filter((run) => run?.status !== "running").length;
|
|
18487
|
+
const countLabel = [
|
|
18488
|
+
`${runningAgents} running`,
|
|
18489
|
+
retainedRuns ? `${retainedRuns} retained` : "",
|
|
18490
|
+
Number(tab.gateCount || 0) ? `${tab.gateCount} gates` : "",
|
|
18491
|
+
].filter(Boolean).join(" · ");
|
|
17141
18492
|
header.append(title, make("span", "subagent-tab-count", countLabel));
|
|
17142
18493
|
header.addEventListener("click", () => switchTab(tab.tabId));
|
|
17143
18494
|
group.append(header);
|
|
17144
18495
|
|
|
17145
18496
|
const list = make("div", "subagent-agent-list");
|
|
17146
|
-
const
|
|
17147
|
-
.slice()
|
|
17148
|
-
.sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0) || String(a.id || "").localeCompare(String(b.id || "")));
|
|
17149
|
-
for (const run of runs) {
|
|
17150
|
-
const agents = (Array.isArray(run.agents) ? run.agents : [])
|
|
17151
|
-
.filter((agent) => agent?.status === "running")
|
|
17152
|
-
.sort((a, b) => Number(a.index || 0) - Number(b.index || 0) || String(a.name || "").localeCompare(String(b.name || "")));
|
|
17153
|
-
for (const agent of agents) list.append(renderSubagentAgent(tab, run, agent));
|
|
17154
|
-
}
|
|
18497
|
+
for (const run of runs) list.append(renderSubagentRun(tab, run));
|
|
17155
18498
|
for (const gate of (Array.isArray(tab.gates) ? tab.gates : []).slice().sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0))) {
|
|
17156
18499
|
list.append(renderSubagentGate(tab, gate));
|
|
17157
18500
|
}
|
|
@@ -17163,26 +18506,29 @@ function renderSubagents() {
|
|
|
17163
18506
|
const box = elements.subagentsBox;
|
|
17164
18507
|
if (!box) return;
|
|
17165
18508
|
const activeTabs = subagentTabsWithRunningAgents();
|
|
17166
|
-
const totalAgents = activeTabs.reduce((count, tab) => count + Number(tab.
|
|
18509
|
+
const totalAgents = Number(latestSubagents?.runningAgents ?? activeTabs.reduce((count, tab) => count + Number(tab.runningAgents || 0), 0));
|
|
18510
|
+
const totalRuns = Number(latestSubagents?.totalRuns || 0);
|
|
18511
|
+
const runningRuns = Number(latestSubagents?.runningRuns || 0);
|
|
18512
|
+
const retainedRuns = Math.max(0, totalRuns - runningRuns);
|
|
17167
18513
|
const totalGates = activeTabs.reduce((count, tab) => count + Number(tab.gateCount || 0), 0);
|
|
17168
|
-
const
|
|
18514
|
+
const hasItems = activeTabs.length > 0;
|
|
17169
18515
|
if (elements.subagentCountBadge) {
|
|
17170
|
-
elements.subagentCountBadge.textContent = String(
|
|
17171
|
-
elements.subagentCountBadge.hidden =
|
|
18516
|
+
elements.subagentCountBadge.textContent = String(totalAgents);
|
|
18517
|
+
elements.subagentCountBadge.hidden = totalAgents === 0;
|
|
17172
18518
|
}
|
|
17173
18519
|
if (elements.subagentsStatus) {
|
|
17174
|
-
elements.subagentsStatus.textContent =
|
|
17175
|
-
? [`${totalAgents} running`, totalGates ? `${totalGates} retry ${totalGates === 1 ? "gate" : "gates"}` : "", `across ${activeTabs.length} ${activeTabs.length === 1 ? "terminal" : "terminals"}`].filter(Boolean).join(" · ")
|
|
18520
|
+
elements.subagentsStatus.textContent = hasItems
|
|
18521
|
+
? [`${totalAgents} running`, retainedRuns ? `${retainedRuns} retained ${retainedRuns === 1 ? "run" : "runs"}` : "", totalGates ? `${totalGates} retry ${totalGates === 1 ? "gate" : "gates"}` : "", `across ${activeTabs.length} ${activeTabs.length === 1 ? "terminal" : "terminals"}`].filter(Boolean).join(" · ")
|
|
17176
18522
|
: subagentsLoading && !latestSubagents
|
|
17177
18523
|
? "Checking subagents and retry gates…"
|
|
17178
|
-
: "No running subagents or
|
|
18524
|
+
: "No running subagents, retained runs, or retry gates.";
|
|
17179
18525
|
}
|
|
17180
18526
|
|
|
17181
18527
|
box.replaceChildren();
|
|
17182
|
-
box.classList.toggle("muted",
|
|
17183
|
-
box.classList.toggle("has-items",
|
|
17184
|
-
if (
|
|
17185
|
-
box.append(make("div", "subagents-empty", subagentsError ? `Subagent status unavailable: ${subagentsError.message || subagentsError}` : "Running
|
|
18528
|
+
box.classList.toggle("muted", !hasItems);
|
|
18529
|
+
box.classList.toggle("has-items", hasItems);
|
|
18530
|
+
if (!hasItems) {
|
|
18531
|
+
box.append(make("div", "subagents-empty", subagentsError ? `Subagent status unavailable: ${subagentsError.message || subagentsError}` : "Running and retained subagents will appear here, grouped by terminal and session."));
|
|
17186
18532
|
return;
|
|
17187
18533
|
}
|
|
17188
18534
|
for (const tab of activeTabs) box.append(renderSubagentTabGroup(tab));
|
|
@@ -17191,25 +18537,34 @@ function renderSubagents() {
|
|
|
17191
18537
|
|
|
17192
18538
|
async function refreshSubagents() {
|
|
17193
18539
|
if (subagentsLoading) return;
|
|
18540
|
+
let subagentViewsChanged = false;
|
|
18541
|
+
let materializedTerminalViews = false;
|
|
17194
18542
|
subagentsLoading = true;
|
|
17195
18543
|
renderSubagents();
|
|
17196
18544
|
try {
|
|
17197
18545
|
const response = await api("/api/subagents", { scoped: false });
|
|
17198
18546
|
latestSubagents = response.data || null;
|
|
17199
18547
|
pruneDismissedSubagentGateKeys(latestSubagents?.tabs, dismissedSubagentGateKeys);
|
|
17200
|
-
syncSubagentTerminalViewsFromOverview();
|
|
18548
|
+
subagentViewsChanged = syncSubagentTerminalViewsFromOverview();
|
|
18549
|
+
materializedTerminalViews = materializeRetainedSubagentTerminalViews();
|
|
17201
18550
|
subagentsError = null;
|
|
17202
18551
|
} catch (error) {
|
|
17203
18552
|
subagentsError = error;
|
|
17204
18553
|
} finally {
|
|
17205
18554
|
subagentsLoading = false;
|
|
17206
18555
|
renderSubagents();
|
|
18556
|
+
if (subagentOverlaySelection?.tabId === activeTabId) renderWidgets();
|
|
18557
|
+
if (activeSubagentTerminalId) {
|
|
18558
|
+
renderSubagentTerminalView();
|
|
18559
|
+
scheduleSubagentTerminalRefresh();
|
|
18560
|
+
}
|
|
18561
|
+
if (subagentViewsChanged || materializedTerminalViews) renderTabs();
|
|
17207
18562
|
}
|
|
17208
18563
|
}
|
|
17209
18564
|
|
|
17210
18565
|
function scheduleRefreshSubagents(delay) {
|
|
17211
18566
|
clearTimeout(refreshSubagentsTimer);
|
|
17212
|
-
const totalAgents = Number(latestSubagents?.
|
|
18567
|
+
const totalAgents = Number(latestSubagents?.runningAgents || 0);
|
|
17213
18568
|
const hasRunningGate = (Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : []).some((tab) => (Array.isArray(tab?.gates) ? tab.gates : []).some((gate) => gate?.status === "running"));
|
|
17214
18569
|
const nextDelay = delay ?? (document.visibilityState === "hidden" ? SUBAGENTS_HIDDEN_REFRESH_MS : totalAgents > 0 || hasRunningGate ? SUBAGENTS_ACTIVE_REFRESH_MS : SUBAGENTS_IDLE_REFRESH_MS);
|
|
17215
18570
|
refreshSubagentsTimer = setTimeout(() => {
|
|
@@ -21757,7 +23112,11 @@ async function gitWorkflowRequest(path, { method = "POST", body = {}, runId, tab
|
|
|
21757
23112
|
if (!response.ok) {
|
|
21758
23113
|
const hint = response.hint ? `\n\nHint: ${response.hint}` : "";
|
|
21759
23114
|
const detail = response.data ? `\n\n${formatGitCommandResult(response.data)}` : "";
|
|
21760
|
-
|
|
23115
|
+
const failure = new Error(`${response.error || "Git workflow request failed"}${hint}${detail}`);
|
|
23116
|
+
if (response.code) failure.code = response.code;
|
|
23117
|
+
if (response.hint) failure.hint = response.hint;
|
|
23118
|
+
if (response.data) failure.data = response.data;
|
|
23119
|
+
throw failure;
|
|
21761
23120
|
}
|
|
21762
23121
|
return response.data;
|
|
21763
23122
|
}
|
|
@@ -22867,6 +24226,82 @@ async function commitGitWorkflow(variant, tabId = gitWorkflowActionTabId()) {
|
|
|
22867
24226
|
}
|
|
22868
24227
|
}
|
|
22869
24228
|
|
|
24229
|
+
function cleanGitPublishVisibilityInput(value) {
|
|
24230
|
+
const visibility = String(value ?? "").trim().toLowerCase();
|
|
24231
|
+
if (visibility !== "public" && visibility !== "private") {
|
|
24232
|
+
throw new Error("Repository visibility must be typed as exactly 'public' or 'private'. There is no default; nothing was published.");
|
|
24233
|
+
}
|
|
24234
|
+
return visibility;
|
|
24235
|
+
}
|
|
24236
|
+
|
|
24237
|
+
function promptGitPublishRepoName(tabId = activeTabId) {
|
|
24238
|
+
const targetTab = tabs.find((tab) => tab.id === tabId) || activeTab();
|
|
24239
|
+
const value = window.prompt("GitHub repository name to create", defaultGitInitRepoName(targetTab));
|
|
24240
|
+
if (value === null) return null;
|
|
24241
|
+
return cleanGitHubRepoNameInput(value);
|
|
24242
|
+
}
|
|
24243
|
+
|
|
24244
|
+
function promptGitPublishVisibility(repoName) {
|
|
24245
|
+
const value = window.prompt(`Visibility for GitHub repository ${repoName} — type public or private (no default)`, "");
|
|
24246
|
+
if (value === null) return null;
|
|
24247
|
+
return cleanGitPublishVisibilityInput(value);
|
|
24248
|
+
}
|
|
24249
|
+
|
|
24250
|
+
async function publishGitWorkflowRepository(tabId, failure) {
|
|
24251
|
+
const tabContext = activeTabContext(tabId);
|
|
24252
|
+
const workflow = gitWorkflowForTab(tabId, { create: false });
|
|
24253
|
+
if (!workflow) return false;
|
|
24254
|
+
const runId = workflow.runId;
|
|
24255
|
+
const branch = failure?.data?.branch || gitFooterCurrentBranch() || "the current branch";
|
|
24256
|
+
const publishRequested = await appConfirmText([
|
|
24257
|
+
failure?.message || "git push found no configured push destination.",
|
|
24258
|
+
"",
|
|
24259
|
+
"Publish this repository to GitHub with the authenticated GitHub CLI (gh) account instead?",
|
|
24260
|
+
"Nothing is created until you choose a name, choose visibility explicitly, and confirm the final summary.",
|
|
24261
|
+
].join("\n"), { affected: "A new GitHub repository and the origin remote", confirmLabel: "Choose publication details", danger: false });
|
|
24262
|
+
if (!publishRequested) return false;
|
|
24263
|
+
let repoName;
|
|
24264
|
+
let visibility;
|
|
24265
|
+
try {
|
|
24266
|
+
repoName = promptGitPublishRepoName(tabId);
|
|
24267
|
+
if (!repoName) return false;
|
|
24268
|
+
visibility = promptGitPublishVisibility(repoName);
|
|
24269
|
+
if (!visibility) return false;
|
|
24270
|
+
} catch (error) {
|
|
24271
|
+
addEvent(error.message || String(error), "error");
|
|
24272
|
+
return false;
|
|
24273
|
+
}
|
|
24274
|
+
const confirmed = await appConfirmText([
|
|
24275
|
+
"Publish this repository to GitHub?",
|
|
24276
|
+
"",
|
|
24277
|
+
`Repository name: ${repoName}`,
|
|
24278
|
+
`Visibility: ${visibility}`,
|
|
24279
|
+
`Branch to push: ${branch}`,
|
|
24280
|
+
"Resulting remote: origin",
|
|
24281
|
+
"",
|
|
24282
|
+
"This creates a new GitHub repository owned by the authenticated gh account, configures origin, and pushes the current branch. Guided Git never force-pushes.",
|
|
24283
|
+
].join("\n"), { affected: `New ${visibility} GitHub repository ${repoName}`, confirmLabel: "Publish repository" });
|
|
24284
|
+
if (!confirmed) return false;
|
|
24285
|
+
setGitWorkflow({ step: "pushing", busy: true, error: "", output: `Creating ${visibility} GitHub repository ${repoName} and pushing ${branch}…` }, { tabId });
|
|
24286
|
+
const result = await gitWorkflowRequest("/api/git-workflow/publish", { body: { repoName, visibility, confirmed: true }, runId, tabId });
|
|
24287
|
+
if (!result) return true;
|
|
24288
|
+
setGitWorkflow({
|
|
24289
|
+
step: "done",
|
|
24290
|
+
busy: false,
|
|
24291
|
+
...gitWorkflowActionDonePatch(workflow, "push"),
|
|
24292
|
+
output: [
|
|
24293
|
+
`Published ${result.repoName || repoName} as ${result.visibility || visibility}.`,
|
|
24294
|
+
`Remote: ${result.remote || "origin"}`,
|
|
24295
|
+
`Branch: ${result.branch || branch}`,
|
|
24296
|
+
...(result.protectedBranch ? [`Note: ${result.branch || branch} is usually a protected/shared branch name.`] : []),
|
|
24297
|
+
"",
|
|
24298
|
+
formatGitCommandResult(result) || "gh repo create finished.",
|
|
24299
|
+
].join("\n"),
|
|
24300
|
+
}, { tabId });
|
|
24301
|
+
if (isCurrentTabContext(tabContext)) scheduleRefreshFooter();
|
|
24302
|
+
return true;
|
|
24303
|
+
}
|
|
24304
|
+
|
|
22870
24305
|
async function pushGitWorkflow(tabId = gitWorkflowActionTabId()) {
|
|
22871
24306
|
const tabContext = activeTabContext(tabId);
|
|
22872
24307
|
const workflow = gitWorkflowForTab(tabId, { create: false });
|
|
@@ -22880,6 +24315,15 @@ async function pushGitWorkflow(tabId = gitWorkflowActionTabId()) {
|
|
|
22880
24315
|
setGitWorkflow({ step: "done", busy: false, ...gitWorkflowActionDonePatch(workflow, "push"), output: formatGitCommandResult(result) || "git push finished." }, { tabId });
|
|
22881
24316
|
if (isCurrentTabContext(tabContext)) scheduleRefreshFooter();
|
|
22882
24317
|
} catch (error) {
|
|
24318
|
+
if (!isCurrentGitWorkflowRun(runId, tabId)) return;
|
|
24319
|
+
if (error?.code === "NO_REMOTE") {
|
|
24320
|
+
try {
|
|
24321
|
+
if (await publishGitWorkflowRepository(tabId, error)) return;
|
|
24322
|
+
} catch (publishError) {
|
|
24323
|
+
if (isCurrentGitWorkflowRun(runId, tabId)) failGitWorkflow(publishError, "push", { tabId });
|
|
24324
|
+
return;
|
|
24325
|
+
}
|
|
24326
|
+
}
|
|
22883
24327
|
if (isCurrentGitWorkflowRun(runId, tabId)) failGitWorkflow(error, "push", { tabId });
|
|
22884
24328
|
}
|
|
22885
24329
|
}
|
|
@@ -23050,12 +24494,20 @@ function resumeGitWorkflowForActiveTab(tabContext = activeTabContext()) {
|
|
|
23050
24494
|
|
|
23051
24495
|
function normalizeQueuedMessages(event) {
|
|
23052
24496
|
const normalize = (items) => (Array.isArray(items) ? items.map((item) => String(item || "")).filter((item) => item.trim()) : []);
|
|
24497
|
+
const source = event?.source === "webui-compaction" ? "webui-compaction" : "pi-runtime";
|
|
23053
24498
|
return {
|
|
24499
|
+
source,
|
|
24500
|
+
revision: source === "webui-compaction" && Number.isSafeInteger(event?.revision) && event.revision >= 0 ? event.revision : undefined,
|
|
24501
|
+
draining: source === "webui-compaction" && event?.draining === true,
|
|
23054
24502
|
steering: normalize(event?.steering),
|
|
23055
24503
|
followUp: normalize(event?.followUp),
|
|
23056
24504
|
};
|
|
23057
24505
|
}
|
|
23058
24506
|
|
|
24507
|
+
function queuedSnapshotForTab(tabId = activeTabId) {
|
|
24508
|
+
return tabId ? latestQueuedMessagesByTab.get(tabId) || normalizeQueuedMessages({}) : normalizeQueuedMessages({});
|
|
24509
|
+
}
|
|
24510
|
+
|
|
23059
24511
|
function queueMessageCount(snapshot) {
|
|
23060
24512
|
return (snapshot?.steering?.length || 0) + (snapshot?.followUp?.length || 0);
|
|
23061
24513
|
}
|
|
@@ -23073,13 +24525,331 @@ function queueSummaryPill(label, count, tone) {
|
|
|
23073
24525
|
return pill;
|
|
23074
24526
|
}
|
|
23075
24527
|
|
|
24528
|
+
function followUpQueueMutationInFlight(tabId = activeTabId) {
|
|
24529
|
+
return !!tabId && followUpQueueMutationsInFlightByTab.has(tabId);
|
|
24530
|
+
}
|
|
24531
|
+
|
|
24532
|
+
function setFollowUpQueueStatus(text = "", level = "") {
|
|
24533
|
+
followUpQueueStatus = { text, level };
|
|
24534
|
+
if (!elements.followUpQueueStatus) return;
|
|
24535
|
+
elements.followUpQueueStatus.textContent = text;
|
|
24536
|
+
elements.followUpQueueStatus.className = `follow-up-queue-status${level ? ` ${level}` : ""}`;
|
|
24537
|
+
}
|
|
24538
|
+
|
|
24539
|
+
function syncFollowUpQueueMutationControls() {
|
|
24540
|
+
const tabId = activeTabId;
|
|
24541
|
+
const locked = followUpQueueMutationInFlight(tabId);
|
|
24542
|
+
const draining = queuedSnapshotForTab(tabId).draining;
|
|
24543
|
+
elements.followUpQueueOverlay?.classList.toggle("is-busy", locked);
|
|
24544
|
+
elements.followUpQueueOverlay?.classList.toggle("is-draining", draining);
|
|
24545
|
+
for (const textarea of elements.followUpQueueRows?.querySelectorAll("textarea") || []) textarea.disabled = locked || draining;
|
|
24546
|
+
for (const control of elements.followUpQueueRows?.querySelectorAll("[data-follow-up-queue-mutation-control]") || []) control.disabled = locked || draining || control.dataset.queueBoundary === "true";
|
|
24547
|
+
for (const row of elements.followUpQueueRows?.querySelectorAll(".follow-up-queue-row") || []) row.draggable = false;
|
|
24548
|
+
for (const handle of elements.followUpQueueRows?.querySelectorAll(".follow-up-queue-drag-handle") || []) handle.draggable = !locked && !draining;
|
|
24549
|
+
}
|
|
24550
|
+
|
|
24551
|
+
function setFollowUpQueueMutationInFlight(tabId, inFlight) {
|
|
24552
|
+
if (!tabId) return;
|
|
24553
|
+
if (inFlight) followUpQueueMutationsInFlightByTab.add(tabId);
|
|
24554
|
+
else followUpQueueMutationsInFlightByTab.delete(tabId);
|
|
24555
|
+
if (tabId === activeTabId) syncFollowUpQueueMutationControls();
|
|
24556
|
+
}
|
|
24557
|
+
|
|
24558
|
+
function preservedFocusedFollowUpQueueDraft(draft, followUps) {
|
|
24559
|
+
if (!draft || !Array.isArray(followUps) || !Number.isSafeInteger(draft.index) || draft.index < 0) return null;
|
|
24560
|
+
const authoritativeText = String(draft.authoritativeText ?? "");
|
|
24561
|
+
const value = String(draft.value ?? "");
|
|
24562
|
+
if (value === authoritativeText || followUps[draft.index] !== authoritativeText) return null;
|
|
24563
|
+
const selectionStart = Math.max(0, Math.min(value.length, Number.isSafeInteger(draft.selectionStart) ? draft.selectionStart : value.length));
|
|
24564
|
+
const selectionEnd = Math.max(selectionStart, Math.min(value.length, Number.isSafeInteger(draft.selectionEnd) ? draft.selectionEnd : selectionStart));
|
|
24565
|
+
return { index: draft.index, value, selectionStart, selectionEnd };
|
|
24566
|
+
}
|
|
24567
|
+
|
|
24568
|
+
function focusedFollowUpQueueDraft() {
|
|
24569
|
+
const textarea = document.activeElement;
|
|
24570
|
+
if (!textarea?.matches?.("textarea.follow-up-queue-textarea") || !elements.followUpQueueRows?.contains(textarea)) return null;
|
|
24571
|
+
const index = Number(textarea.closest(".follow-up-queue-row")?.dataset.followUpIndex);
|
|
24572
|
+
if (!Number.isSafeInteger(index) || index < 0) return null;
|
|
24573
|
+
const authoritativeText = String(textarea.dataset.followUpQueueAuthoritativeText ?? "");
|
|
24574
|
+
if (textarea.value === authoritativeText) return null;
|
|
24575
|
+
return {
|
|
24576
|
+
textarea,
|
|
24577
|
+
index,
|
|
24578
|
+
authoritativeText,
|
|
24579
|
+
value: textarea.value,
|
|
24580
|
+
selectionStart: textarea.selectionStart,
|
|
24581
|
+
selectionEnd: textarea.selectionEnd,
|
|
24582
|
+
};
|
|
24583
|
+
}
|
|
24584
|
+
|
|
24585
|
+
function queueTabContext(tabId = activeTabId) {
|
|
24586
|
+
const tab = tabs.find((item) => item.id === tabId);
|
|
24587
|
+
return {
|
|
24588
|
+
...activeTabContext(tabId),
|
|
24589
|
+
sessionFile: typeof tab?.sessionFile === "string" && tab.sessionFile ? tab.sessionFile : null,
|
|
24590
|
+
startedAt: typeof tab?.startedAt === "string" && tab.startedAt ? tab.startedAt : null,
|
|
24591
|
+
};
|
|
24592
|
+
}
|
|
24593
|
+
|
|
24594
|
+
function queuedSnapshotTargetsCurrentTab(tabContext, currentTabId = activeTabId, currentTabs = tabs) {
|
|
24595
|
+
if (!tabContext?.tabId || tabContext.tabId !== currentTabId || !Array.isArray(currentTabs)) return false;
|
|
24596
|
+
const currentTab = currentTabs.find((tab) => tab?.id === tabContext.tabId);
|
|
24597
|
+
if (!currentTab) return false;
|
|
24598
|
+
const sessionFile = typeof tabContext.sessionFile === "string" && tabContext.sessionFile ? tabContext.sessionFile : null;
|
|
24599
|
+
const currentSessionFile = typeof currentTab.sessionFile === "string" && currentTab.sessionFile ? currentTab.sessionFile : null;
|
|
24600
|
+
if (sessionFile && currentSessionFile && sessionFile !== currentSessionFile) return false;
|
|
24601
|
+
const startedAt = typeof tabContext.startedAt === "string" && tabContext.startedAt ? tabContext.startedAt : null;
|
|
24602
|
+
const currentStartedAt = typeof currentTab.startedAt === "string" && currentTab.startedAt ? currentTab.startedAt : null;
|
|
24603
|
+
return !(startedAt && currentStartedAt && startedAt !== currentStartedAt);
|
|
24604
|
+
}
|
|
24605
|
+
|
|
24606
|
+
function setFollowUpQueueOpen(open, { restoreFocus = false } = {}) {
|
|
24607
|
+
const snapshot = queuedSnapshotForTab();
|
|
24608
|
+
const shouldOpen = !!open && snapshot.followUp.length > 0;
|
|
24609
|
+
if (shouldOpen && !followUpQueueOpen) {
|
|
24610
|
+
followUpQueueRestoreFocus = document.activeElement instanceof HTMLElement ? document.activeElement : elements.followUpQueueTrigger;
|
|
24611
|
+
setComposerActionsOpen(false);
|
|
24612
|
+
setPublishMenuOpen(false);
|
|
24613
|
+
setNativeCommandMenuOpen(false);
|
|
24614
|
+
setAppRunnerMenuOpen(false);
|
|
24615
|
+
setOptionsMenuOpen(false);
|
|
24616
|
+
setConversationVoiceMenuOpen(false);
|
|
24617
|
+
setBusyPromptBehaviorMenuOpen(false);
|
|
24618
|
+
setNewTabMenuOpen(false);
|
|
24619
|
+
}
|
|
24620
|
+
followUpQueueOpen = shouldOpen;
|
|
24621
|
+
elements.followUpQueueTrigger?.setAttribute("aria-expanded", shouldOpen ? "true" : "false");
|
|
24622
|
+
if (elements.followUpQueueOverlay) elements.followUpQueueOverlay.hidden = !shouldOpen;
|
|
24623
|
+
if (!shouldOpen) {
|
|
24624
|
+
followUpQueueDrag = null;
|
|
24625
|
+
scheduleDeferredUiFlushAfterDropdownClose();
|
|
24626
|
+
if (restoreFocus) {
|
|
24627
|
+
const focusTarget = followUpQueueRestoreFocus?.isConnected ? followUpQueueRestoreFocus : elements.followUpQueueTrigger;
|
|
24628
|
+
requestAnimationFrame(() => focusTarget?.focus({ preventScroll: true }));
|
|
24629
|
+
}
|
|
24630
|
+
followUpQueueRestoreFocus = null;
|
|
24631
|
+
return;
|
|
24632
|
+
}
|
|
24633
|
+
renderFollowUpQueueOverlay();
|
|
24634
|
+
}
|
|
24635
|
+
|
|
24636
|
+
function queueMutationBody(snapshot, operation) {
|
|
24637
|
+
const body = {
|
|
24638
|
+
source: snapshot.source,
|
|
24639
|
+
kind: "followUp",
|
|
24640
|
+
expected: { steering: [...snapshot.steering], followUp: [...snapshot.followUp] },
|
|
24641
|
+
operation,
|
|
24642
|
+
};
|
|
24643
|
+
if (snapshot.source === "webui-compaction") body.revision = snapshot.revision;
|
|
24644
|
+
return body;
|
|
24645
|
+
}
|
|
24646
|
+
|
|
24647
|
+
function applyAuthoritativeQueuedSnapshot(tabContext, queue) {
|
|
24648
|
+
if (!tabContext?.tabId || !queue) return;
|
|
24649
|
+
const snapshot = normalizeQueuedMessages(queue);
|
|
24650
|
+
latestQueuedMessagesByTab.set(tabContext.tabId, snapshot);
|
|
24651
|
+
if (queuedSnapshotTargetsCurrentTab(tabContext)) renderQueue({ tabId: tabContext.tabId, ...snapshot });
|
|
24652
|
+
}
|
|
24653
|
+
|
|
24654
|
+
async function mutateQueuedFollowUp(operation, tabId = activeTabId) {
|
|
24655
|
+
if (!tabId || followUpQueueMutationInFlight(tabId)) return false;
|
|
24656
|
+
const tabContext = queueTabContext(tabId);
|
|
24657
|
+
const snapshot = queuedSnapshotForTab(tabId);
|
|
24658
|
+
if (!snapshot.followUp.length || snapshot.draining) {
|
|
24659
|
+
if (isCurrentTabContext(tabContext)) setFollowUpQueueStatus("Queue is draining; follow-ups can no longer be changed.", "warn");
|
|
24660
|
+
return false;
|
|
24661
|
+
}
|
|
24662
|
+
setFollowUpQueueMutationInFlight(tabId, true);
|
|
24663
|
+
if (isCurrentTabContext(tabContext)) setFollowUpQueueStatus(operation.type === "edit" ? "Saving queued follow-up…" : "Reordering queued follow-ups…");
|
|
24664
|
+
try {
|
|
24665
|
+
const response = await api("/api/queue/mutate", { method: "POST", body: queueMutationBody(snapshot, operation), tabId });
|
|
24666
|
+
const result = response?.data || {};
|
|
24667
|
+
if (result.queue) applyAuthoritativeQueuedSnapshot(tabContext, result.queue);
|
|
24668
|
+
if (!result.mutated) {
|
|
24669
|
+
if (isCurrentTabContext(tabContext)) setFollowUpQueueStatus("Queue changed before the update could be applied.", "warn");
|
|
24670
|
+
return false;
|
|
24671
|
+
}
|
|
24672
|
+
if (isCurrentTabContext(tabContext)) {
|
|
24673
|
+
const message = operation.type === "edit"
|
|
24674
|
+
? `Saved queued follow-up ${operation.index + 1}.`
|
|
24675
|
+
: `Moved queued follow-up ${operation.from + 1} to position ${operation.to + 1}.`;
|
|
24676
|
+
setFollowUpQueueStatus(message, "success");
|
|
24677
|
+
}
|
|
24678
|
+
return true;
|
|
24679
|
+
} catch (error) {
|
|
24680
|
+
const result = error?.data?.data || {};
|
|
24681
|
+
if (result.queue) applyAuthoritativeQueuedSnapshot(tabContext, result.queue);
|
|
24682
|
+
if (isCurrentTabContext(tabContext)) {
|
|
24683
|
+
if (error?.statusCode === 409) setFollowUpQueueStatus(result.reason === "queue-draining" ? "Queue is draining; refreshed the authoritative queue." : "Queue changed elsewhere; refreshed the authoritative queue.", "warn");
|
|
24684
|
+
else setFollowUpQueueStatus(error.message || "Unable to update the queued follow-up.", "error");
|
|
24685
|
+
}
|
|
24686
|
+
return false;
|
|
24687
|
+
} finally {
|
|
24688
|
+
setFollowUpQueueMutationInFlight(tabId, false);
|
|
24689
|
+
if (isCurrentTabContext(tabContext)) renderFollowUpQueueOverlay();
|
|
24690
|
+
}
|
|
24691
|
+
}
|
|
24692
|
+
|
|
24693
|
+
function saveQueuedFollowUpText(index, expectedText, value) {
|
|
24694
|
+
const text = String(value ?? "");
|
|
24695
|
+
if (text === expectedText) return;
|
|
24696
|
+
if (!text.trim()) {
|
|
24697
|
+
setFollowUpQueueStatus("Queued follow-ups cannot be empty; restored the authoritative text.", "warn");
|
|
24698
|
+
renderFollowUpQueueOverlay();
|
|
24699
|
+
return;
|
|
24700
|
+
}
|
|
24701
|
+
void mutateQueuedFollowUp({ type: "edit", index, expectedText, text });
|
|
24702
|
+
}
|
|
24703
|
+
|
|
24704
|
+
function clearFollowUpQueueDragVisuals() {
|
|
24705
|
+
for (const row of elements.followUpQueueRows?.querySelectorAll(".follow-up-queue-row.is-dragging, .follow-up-queue-row.is-drop-target") || []) {
|
|
24706
|
+
row.classList.remove("is-dragging", "is-drop-target");
|
|
24707
|
+
}
|
|
24708
|
+
}
|
|
24709
|
+
|
|
24710
|
+
function renderFollowUpQueueOverlay() {
|
|
24711
|
+
if (deferUiRenderDuringPointerActivation("follow-up-queue", renderFollowUpQueueOverlay)) return;
|
|
24712
|
+
const snapshot = queuedSnapshotForTab();
|
|
24713
|
+
const followUps = snapshot.followUp;
|
|
24714
|
+
const count = followUps.length;
|
|
24715
|
+
const trigger = elements.followUpQueueTrigger;
|
|
24716
|
+
if (trigger) {
|
|
24717
|
+
trigger.hidden = count === 0;
|
|
24718
|
+
trigger.setAttribute("aria-expanded", followUpQueueOpen && count ? "true" : "false");
|
|
24719
|
+
trigger.setAttribute("aria-label", `${count} queued follow-up${count === 1 ? "" : "s"}`);
|
|
24720
|
+
}
|
|
24721
|
+
if (elements.followUpQueueTriggerCount) elements.followUpQueueTriggerCount.textContent = String(count);
|
|
24722
|
+
if (elements.followUpQueueOverlayCount) elements.followUpQueueOverlayCount.textContent = String(count);
|
|
24723
|
+
if (!count) {
|
|
24724
|
+
if (followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
24725
|
+
if (elements.followUpQueueRows) elements.followUpQueueRows.replaceChildren();
|
|
24726
|
+
return;
|
|
24727
|
+
}
|
|
24728
|
+
if (!followUpQueueOpen || !elements.followUpQueueRows) return;
|
|
24729
|
+
|
|
24730
|
+
const locked = followUpQueueMutationInFlight();
|
|
24731
|
+
const unavailable = locked || snapshot.draining;
|
|
24732
|
+
const focusedDraft = focusedFollowUpQueueDraft();
|
|
24733
|
+
const preservedDraft = preservedFocusedFollowUpQueueDraft(focusedDraft, followUps);
|
|
24734
|
+
const rows = followUps.map((item, index) => {
|
|
24735
|
+
const row = make("article", "follow-up-queue-row");
|
|
24736
|
+
row.dataset.followUpIndex = String(index);
|
|
24737
|
+
row.draggable = false;
|
|
24738
|
+
const dragHandle = make("span", "follow-up-queue-drag-handle", "⠿");
|
|
24739
|
+
dragHandle.draggable = !unavailable;
|
|
24740
|
+
dragHandle.setAttribute("aria-hidden", "true");
|
|
24741
|
+
dragHandle.title = "Drag to reorder";
|
|
24742
|
+
const textarea = make("textarea", "follow-up-queue-textarea");
|
|
24743
|
+
const textareaDraft = preservedDraft?.index === index ? preservedDraft : null;
|
|
24744
|
+
textarea.value = textareaDraft ? textareaDraft.value : item;
|
|
24745
|
+
textarea.dataset.followUpQueueAuthoritativeText = item;
|
|
24746
|
+
textarea.rows = Math.max(2, Math.min(6, item.split("\n").length + 1));
|
|
24747
|
+
textarea.disabled = unavailable;
|
|
24748
|
+
textarea.setAttribute("aria-label", `Queued follow-up ${index + 1}`);
|
|
24749
|
+
textarea.dataset.followUpQueueMutationControl = "true";
|
|
24750
|
+
textarea.addEventListener("blur", () => {
|
|
24751
|
+
if (textarea === followUpQueueSuppressBlurFor) return;
|
|
24752
|
+
saveQueuedFollowUpText(index, item, textarea.value);
|
|
24753
|
+
});
|
|
24754
|
+
textarea.addEventListener("keydown", (event) => {
|
|
24755
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key === "Enter") {
|
|
24756
|
+
event.preventDefault();
|
|
24757
|
+
saveQueuedFollowUpText(index, item, textarea.value);
|
|
24758
|
+
return;
|
|
24759
|
+
}
|
|
24760
|
+
if (event.key !== "Escape") return;
|
|
24761
|
+
event.preventDefault();
|
|
24762
|
+
event.stopPropagation();
|
|
24763
|
+
if (textarea.value !== item) {
|
|
24764
|
+
textarea.value = item;
|
|
24765
|
+
setFollowUpQueueStatus(`Restored queued follow-up ${index + 1}.`, "warn");
|
|
24766
|
+
} else {
|
|
24767
|
+
setFollowUpQueueOpen(false, { restoreFocus: true });
|
|
24768
|
+
}
|
|
24769
|
+
});
|
|
24770
|
+
const controls = make("div", "follow-up-queue-row-controls");
|
|
24771
|
+
const moveUp = make("button", "follow-up-queue-move-button", "↑");
|
|
24772
|
+
moveUp.type = "button";
|
|
24773
|
+
moveUp.dataset.followUpQueueMutationControl = "true";
|
|
24774
|
+
moveUp.dataset.queueBoundary = index === 0 ? "true" : "false";
|
|
24775
|
+
moveUp.disabled = unavailable || index === 0;
|
|
24776
|
+
moveUp.title = `Move queued follow-up ${index + 1} up`;
|
|
24777
|
+
moveUp.setAttribute("aria-label", `Move queued follow-up ${index + 1} up`);
|
|
24778
|
+
moveUp.addEventListener("click", () => void mutateQueuedFollowUp({ type: "move", from: index, to: index - 1, expectedText: item }));
|
|
24779
|
+
const moveDown = make("button", "follow-up-queue-move-button", "↓");
|
|
24780
|
+
moveDown.type = "button";
|
|
24781
|
+
moveDown.dataset.followUpQueueMutationControl = "true";
|
|
24782
|
+
moveDown.dataset.queueBoundary = index === followUps.length - 1 ? "true" : "false";
|
|
24783
|
+
moveDown.disabled = unavailable || index === followUps.length - 1;
|
|
24784
|
+
moveDown.title = `Move queued follow-up ${index + 1} down`;
|
|
24785
|
+
moveDown.setAttribute("aria-label", `Move queued follow-up ${index + 1} down`);
|
|
24786
|
+
moveDown.addEventListener("click", () => void mutateQueuedFollowUp({ type: "move", from: index, to: index + 1, expectedText: item }));
|
|
24787
|
+
controls.append(moveUp, moveDown);
|
|
24788
|
+
row.append(dragHandle, textarea, controls);
|
|
24789
|
+
row.addEventListener("dragstart", (event) => {
|
|
24790
|
+
if (unavailable || event.target?.closest?.(".follow-up-queue-drag-handle") !== dragHandle) {
|
|
24791
|
+
event.preventDefault();
|
|
24792
|
+
return;
|
|
24793
|
+
}
|
|
24794
|
+
followUpQueueDrag = { tabId: activeTabId, index, expectedText: item };
|
|
24795
|
+
event.dataTransfer?.setData("application/x-pi-webui-follow-up", JSON.stringify(followUpQueueDrag));
|
|
24796
|
+
if (event.dataTransfer) event.dataTransfer.effectAllowed = "move";
|
|
24797
|
+
row.classList.add("is-dragging");
|
|
24798
|
+
});
|
|
24799
|
+
row.addEventListener("dragover", (event) => {
|
|
24800
|
+
if (!followUpQueueDrag || followUpQueueDrag.tabId !== activeTabId || unavailable || isFileDrag(event)) return;
|
|
24801
|
+
event.preventDefault();
|
|
24802
|
+
event.stopPropagation();
|
|
24803
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = "move";
|
|
24804
|
+
clearFollowUpQueueDragVisuals();
|
|
24805
|
+
row.classList.add("is-drop-target");
|
|
24806
|
+
});
|
|
24807
|
+
row.addEventListener("dragleave", (event) => {
|
|
24808
|
+
if (!row.contains(event.relatedTarget)) row.classList.remove("is-drop-target");
|
|
24809
|
+
});
|
|
24810
|
+
row.addEventListener("drop", (event) => {
|
|
24811
|
+
if (!followUpQueueDrag || followUpQueueDrag.tabId !== activeTabId || unavailable || isFileDrag(event)) return;
|
|
24812
|
+
event.preventDefault();
|
|
24813
|
+
event.stopPropagation();
|
|
24814
|
+
const drag = followUpQueueDrag;
|
|
24815
|
+
clearFollowUpQueueDragVisuals();
|
|
24816
|
+
followUpQueueDrag = null;
|
|
24817
|
+
if (drag.index !== index) void mutateQueuedFollowUp({ type: "move", from: drag.index, to: index, expectedText: drag.expectedText });
|
|
24818
|
+
});
|
|
24819
|
+
row.addEventListener("dragend", () => {
|
|
24820
|
+
followUpQueueDrag = null;
|
|
24821
|
+
clearFollowUpQueueDragVisuals();
|
|
24822
|
+
});
|
|
24823
|
+
return row;
|
|
24824
|
+
});
|
|
24825
|
+
followUpQueueSuppressBlurFor = focusedDraft?.textarea || null;
|
|
24826
|
+
try {
|
|
24827
|
+
elements.followUpQueueRows.replaceChildren(...rows);
|
|
24828
|
+
} finally {
|
|
24829
|
+
followUpQueueSuppressBlurFor = null;
|
|
24830
|
+
}
|
|
24831
|
+
if (preservedDraft && !unavailable) {
|
|
24832
|
+
requestAnimationFrame(() => {
|
|
24833
|
+
if (!followUpQueueOpen || activeTabId === null) return;
|
|
24834
|
+
const activeElement = document.activeElement;
|
|
24835
|
+
if (activeElement && activeElement !== document.body && activeElement !== document.documentElement) return;
|
|
24836
|
+
const textarea = elements.followUpQueueRows?.querySelector(`.follow-up-queue-row[data-follow-up-index="${preservedDraft.index}"] textarea`);
|
|
24837
|
+
if (!textarea) return;
|
|
24838
|
+
textarea.focus({ preventScroll: true });
|
|
24839
|
+
textarea.setSelectionRange(preservedDraft.selectionStart, preservedDraft.selectionEnd);
|
|
24840
|
+
});
|
|
24841
|
+
}
|
|
24842
|
+
setFollowUpQueueStatus(followUpQueueStatus.text, followUpQueueStatus.level);
|
|
24843
|
+
syncFollowUpQueueMutationControls();
|
|
24844
|
+
}
|
|
24845
|
+
|
|
23076
24846
|
async function removeQueuedFollowUpPrompt(index, message, tabId = activeTabId) {
|
|
23077
|
-
if (!tabId) return false;
|
|
23078
|
-
const tabContext =
|
|
24847
|
+
if (!tabId || queuedSnapshotForTab(tabId).source !== "pi-runtime") return false;
|
|
24848
|
+
const tabContext = queueTabContext(tabId);
|
|
23079
24849
|
try {
|
|
23080
24850
|
const response = await api("/api/queue/remove", { method: "POST", body: { kind: "followUp", index, message }, tabId });
|
|
23081
24851
|
const data = response?.data || {};
|
|
23082
|
-
if (data.queue
|
|
24852
|
+
if (data.queue) applyAuthoritativeQueuedSnapshot(tabContext, data.queue);
|
|
23083
24853
|
if (data.removed) {
|
|
23084
24854
|
if (isCurrentTabContext(tabContext)) addEvent(`removed queued follow-up #${index + 1}`);
|
|
23085
24855
|
scheduleRefreshState(120, tabContext);
|
|
@@ -23129,6 +24899,7 @@ function renderQueue(event) {
|
|
|
23129
24899
|
const snapshot = normalizeQueuedMessages(event);
|
|
23130
24900
|
const tabId = event?.tabId || activeTabId;
|
|
23131
24901
|
if (tabId) latestQueuedMessagesByTab.set(tabId, snapshot);
|
|
24902
|
+
if (tabId && tabId !== activeTabId) return;
|
|
23132
24903
|
const steering = snapshot.steering;
|
|
23133
24904
|
const followUp = snapshot.followUp;
|
|
23134
24905
|
const total = queueMessageCount(snapshot);
|
|
@@ -23138,6 +24909,7 @@ function renderQueue(event) {
|
|
|
23138
24909
|
elements.queueBox.classList.toggle("has-items", total > 0);
|
|
23139
24910
|
if (total === 0) {
|
|
23140
24911
|
elements.queueBox.append(make("div", "queue-empty", "No queued messages."));
|
|
24912
|
+
if (tabId === activeTabId) renderFollowUpQueueOverlay();
|
|
23141
24913
|
updateStickyUserPromptButton();
|
|
23142
24914
|
return;
|
|
23143
24915
|
}
|
|
@@ -23151,19 +24923,16 @@ function renderQueue(event) {
|
|
|
23151
24923
|
|
|
23152
24924
|
elements.queueBox.append(summary);
|
|
23153
24925
|
if (steering.length) elements.queueBox.append(renderQueueGroup("Steering", steering, "steering", { tabId }));
|
|
23154
|
-
if (followUp.length) elements.queueBox.append(renderQueueGroup("Follow-up", followUp, "follow-up", { removable:
|
|
23155
|
-
elements.queueBox.append(make("div", "queue-hint",
|
|
24926
|
+
if (followUp.length) elements.queueBox.append(renderQueueGroup("Follow-up", followUp, "follow-up", { removable: snapshot.source === "pi-runtime", tabId }));
|
|
24927
|
+
elements.queueBox.append(make("div", "queue-hint", snapshot.source === "pi-runtime"
|
|
24928
|
+
? "Alt+Up restores this queue snapshot to the composer without clearing Pi's queue. Use Remove beside follow-ups to drop them from the queue."
|
|
24929
|
+
: "Alt+Up restores this queue snapshot to the composer without clearing Pi's queue. Edit and reorder compaction-held follow-ups with the composer Queue control."));
|
|
24930
|
+
if (tabId === activeTabId) renderFollowUpQueueOverlay();
|
|
23156
24931
|
updateStickyUserPromptButton();
|
|
23157
24932
|
}
|
|
23158
24933
|
|
|
23159
|
-
function nextQueuedFollowUpPrompt(tabId = activeTabId) {
|
|
23160
|
-
const snapshot = tabId ? latestQueuedMessagesByTab.get(tabId) : null;
|
|
23161
|
-
const next = Array.isArray(snapshot?.followUp) ? snapshot.followUp.find((item) => String(item || "").trim()) : null;
|
|
23162
|
-
return next ? stickyUserPromptPreviewText(next) : "";
|
|
23163
|
-
}
|
|
23164
|
-
|
|
23165
24934
|
function queuedMessagesForComposer(tabId = activeTabId) {
|
|
23166
|
-
const snapshot =
|
|
24935
|
+
const snapshot = queuedSnapshotForTab(tabId);
|
|
23167
24936
|
return [...(snapshot.steering || []), ...(snapshot.followUp || [])].map((item) => String(item || "").trim()).filter(Boolean);
|
|
23168
24937
|
}
|
|
23169
24938
|
|
|
@@ -25019,6 +26788,12 @@ function renderEmptyStartState() {
|
|
|
25019
26788
|
className: "primary",
|
|
25020
26789
|
onClick: (button) => createTerminalTabFromChosenDirectory({ triggerButton: button }),
|
|
25021
26790
|
}),
|
|
26791
|
+
emptyStartAction({
|
|
26792
|
+
title: "Load workspace",
|
|
26793
|
+
description: "Restore a saved tab constellation",
|
|
26794
|
+
symbol: "⇱",
|
|
26795
|
+
onClick: (button) => openWorkspaceLoadPicker({ triggerButton: button }),
|
|
26796
|
+
}),
|
|
25022
26797
|
emptyStartAction({
|
|
25023
26798
|
title: "Resume session",
|
|
25024
26799
|
description: "Continue previous work and context",
|
|
@@ -25121,21 +26896,15 @@ function updateStickyUserPromptButton() {
|
|
|
25121
26896
|
button.dataset.compacted = target.compacted ? "true" : "false";
|
|
25122
26897
|
if (Number.isInteger(target.index) && target.index >= 0) button.dataset.messageIndex = String(target.index);
|
|
25123
26898
|
else button.removeAttribute("data-message-index");
|
|
25124
|
-
const nextFollowUp = nextQueuedFollowUpPrompt();
|
|
25125
26899
|
const baseTitle = target.compacted ? `Prompt was compacted; jump to compaction summary: ${target.preview}` : `Jump to ${label.toLowerCase()}: ${target.preview}`;
|
|
25126
26900
|
const baseAriaLabel = target.compacted ? `Prompt was compacted; jump to compaction summary: ${target.preview}` : `Jump to ${label.toLowerCase()} (${ordinal} of ${targets.length}): ${target.preview}`;
|
|
25127
|
-
button.title =
|
|
25128
|
-
button.setAttribute("aria-label",
|
|
26901
|
+
button.title = baseTitle;
|
|
26902
|
+
button.setAttribute("aria-label", baseAriaLabel);
|
|
25129
26903
|
const children = [
|
|
25130
26904
|
make("span", "sticky-user-prompt-label", label),
|
|
25131
26905
|
make("span", "sticky-user-prompt-text", target.preview),
|
|
25132
26906
|
make("span", "sticky-user-prompt-meta", meta),
|
|
25133
26907
|
];
|
|
25134
|
-
if (nextFollowUp) {
|
|
25135
|
-
const followUp = make("span", "sticky-user-follow-up-prompt");
|
|
25136
|
-
followUp.append(make("span", "sticky-user-follow-up-label", "Next follow-up"), make("span", "sticky-user-follow-up-text", nextFollowUp));
|
|
25137
|
-
children.push(followUp);
|
|
25138
|
-
}
|
|
25139
26908
|
button.replaceChildren(...children);
|
|
25140
26909
|
}
|
|
25141
26910
|
|
|
@@ -25878,7 +27647,7 @@ function jumpToStickyUserPrompt() {
|
|
|
25878
27647
|
function renderCompactTranscriptBody(body, message) {
|
|
25879
27648
|
if (message.role !== "assistant") return false;
|
|
25880
27649
|
const output = stripTodoProgressLines(textFromContent(message.content));
|
|
25881
|
-
const block = appendMarkdown(body, output || "_[non-text output omitted in
|
|
27650
|
+
const block = appendMarkdown(body, output || "_[non-text output omitted in compact mode]_");
|
|
25882
27651
|
block.classList.add("compact-transcript-text");
|
|
25883
27652
|
return true;
|
|
25884
27653
|
}
|
|
@@ -25936,7 +27705,7 @@ function createMessageBubble(message, { streaming = false, messageIndex = -1, tr
|
|
|
25936
27705
|
const body = make("div", "message-body");
|
|
25937
27706
|
|
|
25938
27707
|
if (compactTranscript && renderCompactTranscriptBody(body, message)) {
|
|
25939
|
-
//
|
|
27708
|
+
// Compact mode preserves final Markdown while omitting reconciled tool history.
|
|
25940
27709
|
} else if (message.role === "bashExecution") {
|
|
25941
27710
|
appendText(body, `$ ${message.command || ""}\n\n${message.output || ""}`, "code-block");
|
|
25942
27711
|
} else if (message.role === "compactionSummary") {
|
|
@@ -26924,6 +28693,7 @@ async function sendBtwPromptFromButton() {
|
|
|
26924
28693
|
}
|
|
26925
28694
|
|
|
26926
28695
|
function setPublishMenuOpen(open) {
|
|
28696
|
+
if (open && followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
26927
28697
|
publishMenuOpen = !!open;
|
|
26928
28698
|
elements.publishButton.setAttribute("aria-expanded", publishMenuOpen ? "true" : "false");
|
|
26929
28699
|
elements.publishButton.classList.toggle("menu-open", publishMenuOpen);
|
|
@@ -26933,6 +28703,7 @@ function setPublishMenuOpen(open) {
|
|
|
26933
28703
|
}
|
|
26934
28704
|
|
|
26935
28705
|
function setNativeCommandMenuOpen(open) {
|
|
28706
|
+
if (open && followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
26936
28707
|
nativeCommandMenuOpen = !!open;
|
|
26937
28708
|
elements.nativeCommandMenuButton.setAttribute("aria-expanded", nativeCommandMenuOpen ? "true" : "false");
|
|
26938
28709
|
elements.nativeCommandMenuButton.classList.toggle("menu-open", nativeCommandMenuOpen);
|
|
@@ -26942,6 +28713,7 @@ function setNativeCommandMenuOpen(open) {
|
|
|
26942
28713
|
}
|
|
26943
28714
|
|
|
26944
28715
|
function setAppRunnerMenuOpen(open) {
|
|
28716
|
+
if (open && followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
26945
28717
|
appRunnerMenuOpen = !!open;
|
|
26946
28718
|
elements.appRunnerMenuButton?.setAttribute("aria-expanded", appRunnerMenuOpen ? "true" : "false");
|
|
26947
28719
|
elements.appRunnerMenuButton?.classList.toggle("menu-open", appRunnerMenuOpen);
|
|
@@ -26951,6 +28723,7 @@ function setAppRunnerMenuOpen(open) {
|
|
|
26951
28723
|
}
|
|
26952
28724
|
|
|
26953
28725
|
function setOptionsMenuOpen(open) {
|
|
28726
|
+
if (open && followUpQueueOpen) setFollowUpQueueOpen(false);
|
|
26954
28727
|
optionsMenuOpen = !!open;
|
|
26955
28728
|
elements.optionsMenuButton.setAttribute("aria-expanded", optionsMenuOpen ? "true" : "false");
|
|
26956
28729
|
elements.optionsMenuButton.classList.toggle("menu-open", optionsMenuOpen);
|
|
@@ -27265,6 +29038,7 @@ function updateOptionalFeatureAvailability() {
|
|
|
27265
29038
|
optionalFeatureAvailability.tuiToolsCommand = hasLoadedRpcCommand("tools");
|
|
27266
29039
|
optionalFeatureAvailability.remoteWebui = hasAvailableCommand("remote") || optionalFeatureAvailability.remoteWebui || statusEntries.has("pi-remote-webui") || statusEntries.has(REMOTE_WEBUI_CONTROLS_STATUS_KEY) || widgets.has("pi-remote-webui");
|
|
27267
29040
|
optionalFeatureAvailability.naturalConversation = NATURAL_CONVERSATION_COMMAND_NAMES.some((name) => hasAvailableCommand(name)) || optionalFeatureAvailability.naturalConversation || statusEntries.has(NATURAL_CONVERSATION_STATUS_KEY) || activeConversationMode().available;
|
|
29041
|
+
optionalFeatureAvailability.codexFastMode = hasAvailableCommand("fast-mode") || optionalFeatureAvailability.codexFastMode || statusEntries.has(CODEX_FAST_MODE_STATUS_KEY) || codexFastModeState.available === true;
|
|
27268
29042
|
optionalFeatureAvailability.themeBundle = availableThemes.length > 0;
|
|
27269
29043
|
requestGitFooterWebuiPayload();
|
|
27270
29044
|
renderOptionalFeatureControls();
|
|
@@ -27447,8 +29221,25 @@ function renderOptionalFeatureRow(feature) {
|
|
|
27447
29221
|
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: true }));
|
|
27448
29222
|
} else if (detected) {
|
|
27449
29223
|
action.textContent = enabled ? "Disable" : "Enable";
|
|
27450
|
-
action.addEventListener("click", () => {
|
|
29224
|
+
action.addEventListener("click", async () => {
|
|
27451
29225
|
const disabled = enabled;
|
|
29226
|
+
// Features that arm a paid or stateful runtime mode must turn that mode off before the
|
|
29227
|
+
// browser stops managing them; a failed turn-off aborts the disable instead of hiding it.
|
|
29228
|
+
if (disabled) {
|
|
29229
|
+
const turnOff = OPTIONAL_FEATURE_DISABLE_PREREQUISITES.get(feature.id);
|
|
29230
|
+
if (turnOff) {
|
|
29231
|
+
action.disabled = true;
|
|
29232
|
+
try {
|
|
29233
|
+
await turnOff();
|
|
29234
|
+
} catch (error) {
|
|
29235
|
+
action.disabled = false;
|
|
29236
|
+
addEvent(`${feature.label} was not disabled: ${error.message || String(error)}. Turn the mode off manually, then retry.`, "error");
|
|
29237
|
+
renderOptionalFeatureControls();
|
|
29238
|
+
return;
|
|
29239
|
+
}
|
|
29240
|
+
action.disabled = false;
|
|
29241
|
+
}
|
|
29242
|
+
}
|
|
27452
29243
|
setOptionalFeatureDisabled(feature.id, disabled);
|
|
27453
29244
|
offerUndo({
|
|
27454
29245
|
message: `${feature.label} was ${disabled ? "disabled" : "enabled"}.`,
|
|
@@ -28093,7 +29884,7 @@ async function refreshSidebarOutputMode() {
|
|
|
28093
29884
|
sidebarOutputModeMetadata = normalizeWebuiOutputModeMetadata(response.data);
|
|
28094
29885
|
} catch (error) {
|
|
28095
29886
|
sidebarOutputModeMetadata = normalizeWebuiOutputModeMetadata();
|
|
28096
|
-
sidebarOutputModeDiagnostic = `
|
|
29887
|
+
sidebarOutputModeDiagnostic = `Compact-mode control unavailable: ${error.message || String(error)}. Using the normal default.`;
|
|
28097
29888
|
} finally {
|
|
28098
29889
|
sidebarOutputModeLoaded = true;
|
|
28099
29890
|
renderSidebarOutputModeControl();
|
|
@@ -28114,10 +29905,10 @@ async function applySidebarOutputMode() {
|
|
|
28114
29905
|
scoped: false,
|
|
28115
29906
|
});
|
|
28116
29907
|
await refreshSidebarOutputMode();
|
|
28117
|
-
addEvent(outputModeDefault === "compact-v1" ? "
|
|
29908
|
+
addEvent(outputModeDefault === "compact-v1" ? "Compact output mode enabled for auto-negotiated Web UI connections." : "Normal output processing restored for auto-negotiated Web UI connections.", "info");
|
|
28118
29909
|
} catch (error) {
|
|
28119
29910
|
sidebarOutputModeDiagnostic = "";
|
|
28120
|
-
sidebarOutputModeNotice = `Failed to update
|
|
29911
|
+
sidebarOutputModeNotice = `Failed to update compact mode: ${error.message || String(error)}. You can retry.`;
|
|
28121
29912
|
sidebarOutputModeLoaded = true;
|
|
28122
29913
|
addEvent(sidebarOutputModeNotice, "error");
|
|
28123
29914
|
} finally {
|
|
@@ -28211,7 +30002,7 @@ async function openNativeSettingsDialog() {
|
|
|
28211
30002
|
autocompleteMax: nativeSettingSelect("Autocomplete max items", settings.autocompleteMaxVisible ?? autocompleteMaxVisible, SETTINGS_AUTOCOMPLETE_OPTIONS, "Maximum visible slash/path suggestions.", { label: "browser", tone: "browser" }),
|
|
28212
30003
|
doubleEscape: nativeSettingSelect("Double-escape action", settings.doubleEscapeAction || doubleEscapeAction, SETTINGS_DOUBLE_ESCAPE_OPTIONS, "Action when pressing Escape twice with an empty composer.", { label: "browser", tone: "browser" }),
|
|
28213
30004
|
treeFilter: nativeSettingSelect("Tree filter mode", settings.treeFilterMode || treeFilterMode, SETTINGS_TREE_FILTER_OPTIONS, "Default filter when opening /tree.", { label: "browser", tone: "browser" }),
|
|
28214
|
-
outputMode: nativeSettingSelect("Output processing", outputModeMetadata.persistedDefault, SETTINGS_OUTPUT_MODE_OPTIONS, "Server default for new and auto-negotiated Web UI connections.
|
|
30005
|
+
outputMode: nativeSettingSelect("Output processing", outputModeMetadata.persistedDefault, SETTINGS_OUTPUT_MODE_OPTIONS, "Server default for new and auto-negotiated Web UI connections. Compact mode preserves Markdown final output, keeps live thinking expanded, groups stored thinking in one collapsed disclosure per turn, shows only the current tool status transiently, and does not change model inference or token generation. Changes use server barriers without restarting Pi.", { label: "server", tone: "startup" }),
|
|
28215
30006
|
autoResizeImages: nativeSettingToggle("Auto-resize images", settings.autoResizeImages !== false, "Resize large images to 2000x2000 max for better model compatibility.", { label: "reload", tone: "reload" }),
|
|
28216
30007
|
blockImages: nativeSettingToggle("Block images", settings.blockImages === true, "Prevent images from being sent to LLM providers.", { label: "reload", tone: "reload" }),
|
|
28217
30008
|
showImages: nativeSettingToggle("Show terminal images", settings.showImages !== false, "Native TUI inline image rendering preference.", { label: "TUI", tone: "tui" }),
|
|
@@ -31413,6 +33204,10 @@ function commandPaletteCoreItems() {
|
|
|
31413
33204
|
{ kind: "Pi", label: "/tools", description: "Manage active tools", keywords: "capabilities", run: () => runNativeCommandMenu("/tools") },
|
|
31414
33205
|
{ kind: "Pi", label: "/skills", description: "Manage active skills", keywords: "system prompt", run: () => runNativeCommandMenu("/skills") },
|
|
31415
33206
|
];
|
|
33207
|
+
if (tabs.length) {
|
|
33208
|
+
items.push({ kind: "Workspace", label: "Workspace: Save", description: "Capture all open tabs, sessions, groups, and the active tab", keywords: "workspace snapshot save sessions groups", run: () => saveWebuiWorkspace({ triggerButton: elements.commandPaletteButton }) });
|
|
33209
|
+
}
|
|
33210
|
+
items.push({ kind: "Workspace", label: "Workspace: Load…", description: tabs.length ? "Choose a saved workspace and decide whether to save current tabs" : "Show saved workspaces to restore", keywords: "workspace restore saved sessions groups", run: () => openWorkspaceLoadPicker({ triggerButton: elements.commandPaletteButton }) });
|
|
31416
33211
|
if (isOptionalFeatureEnabled("statsCommand")) items.push({ kind: "Pi", label: "/stats-webui", description: "Open usage dashboard", keywords: "tokens cost budget", run: () => openStatsOverlay({ refresh: true }) });
|
|
31417
33212
|
return items;
|
|
31418
33213
|
}
|
|
@@ -31556,6 +33351,7 @@ async function refreshAll(tabContext = activeTabContext()) {
|
|
|
31556
33351
|
refreshModels(tabContext),
|
|
31557
33352
|
refreshCommands(tabContext),
|
|
31558
33353
|
refreshNaturalConversationMode(tabContext),
|
|
33354
|
+
refreshCodexFastMode(tabContext),
|
|
31559
33355
|
refreshStats(tabContext),
|
|
31560
33356
|
refreshWorkspace(tabContext),
|
|
31561
33357
|
refreshFileTreeRoot(tabContext),
|
|
@@ -32161,6 +33957,7 @@ function handleExtensionUiRequest(request) {
|
|
|
32161
33957
|
if (statusKey === STATS_WEBUI_STATUS_KEY) handleStatsWebuiStatus(request.statusText);
|
|
32162
33958
|
if (statusKey === BTW_WEBUI_STATUS_KEY) handleBtwWebuiStatus(request.statusText);
|
|
32163
33959
|
if (statusKey === NATURAL_CONVERSATION_STATUS_KEY) handleNaturalConversationStatus(request.statusText, request.tabId || activeTabId);
|
|
33960
|
+
if (statusKey === CODEX_FAST_MODE_STATUS_KEY && (request.tabId || activeTabId) === activeTabId) applyCodexFastModeStatus(request.statusText);
|
|
32164
33961
|
if (statusKey === WORKFLOW_MODE_STATUS_KEY) handleWorkflowModeStatus(request.statusText, request.tabId || activeTabId);
|
|
32165
33962
|
if (statusKey === "pi-remote-webui") handleRemoteWebuiStatus(request.statusText);
|
|
32166
33963
|
updateOptionalFeatureAvailability();
|
|
@@ -32942,6 +34739,7 @@ function handleEvent(event) {
|
|
|
32942
34739
|
scheduleRefreshFooter();
|
|
32943
34740
|
scheduleRefreshCodexUsage(2200);
|
|
32944
34741
|
scheduleRefreshClaudeUsage(2200);
|
|
34742
|
+
refreshCodexFastMode(tabContext).catch((error) => addEvent(`Codex Fast mode refresh failed: ${error.message || String(error)}`, "warn"));
|
|
32945
34743
|
renderFeedbackTray();
|
|
32946
34744
|
{
|
|
32947
34745
|
const workflowTabId = event.tabId || activeTabId;
|
|
@@ -33103,6 +34901,10 @@ elements.composer.addEventListener("submit", (event) => {
|
|
|
33103
34901
|
event.preventDefault();
|
|
33104
34902
|
sendPrompt("prompt");
|
|
33105
34903
|
});
|
|
34904
|
+
elements.followUpQueueTrigger?.addEventListener("click", () => {
|
|
34905
|
+
setFollowUpQueueOpen(!followUpQueueOpen);
|
|
34906
|
+
});
|
|
34907
|
+
elements.followUpQueueCloseButton?.addEventListener("click", () => setFollowUpQueueOpen(false, { restoreFocus: true }));
|
|
33106
34908
|
elements.composerActionsButton.addEventListener("click", () => {
|
|
33107
34909
|
setComposerActionsOpen(!document.body.classList.contains("composer-actions-open"));
|
|
33108
34910
|
});
|
|
@@ -33205,6 +35007,7 @@ elements.newTabCurrentDirectoryButton?.addEventListener("click", () => createTer
|
|
|
33205
35007
|
elements.newTabChooseDirectoryButton?.addEventListener("click", () => createTerminalTabFromChosenDirectory({ triggerButton: elements.newTabChooseDirectoryButton }));
|
|
33206
35008
|
elements.newTabWorktreeButton?.addEventListener("click", () => openBranchWorktreePicker());
|
|
33207
35009
|
elements.splitTabButton?.addEventListener("click", () => splitActiveTerminalTab());
|
|
35010
|
+
elements.workspaceSaveButton?.addEventListener("click", () => saveWebuiWorkspace());
|
|
33208
35011
|
elements.terminalSplitCloseButton?.addEventListener("click", () => closeTerminalSplitView());
|
|
33209
35012
|
elements.closeAllTabsButton.addEventListener("click", () => closeAllTerminalTabs());
|
|
33210
35013
|
elements.commandPaletteButton?.addEventListener("click", () => openCommandPalette());
|
|
@@ -33449,6 +35252,30 @@ elements.confirmationDialog?.addEventListener("cancel", (event) => {
|
|
|
33449
35252
|
elements.confirmationDialog?.addEventListener("close", () => {
|
|
33450
35253
|
if (activeConfirmationResolve) finishApplicationConfirmation(false);
|
|
33451
35254
|
});
|
|
35255
|
+
elements.workspaceLoadDialogCloseButton?.addEventListener("click", () => closeWorkspaceLoadDialog());
|
|
35256
|
+
elements.workspaceLoadDialog?.addEventListener("cancel", (event) => {
|
|
35257
|
+
event.preventDefault();
|
|
35258
|
+
closeWorkspaceLoadDialog();
|
|
35259
|
+
});
|
|
35260
|
+
elements.workspaceLoadDialog?.addEventListener("close", () => {
|
|
35261
|
+
const target = workspaceLoadPickerFocusReturn;
|
|
35262
|
+
workspaceLoadPickerFocusReturn = null;
|
|
35263
|
+
if (target instanceof HTMLElement && target.isConnected) queueMicrotask(() => target.focus());
|
|
35264
|
+
});
|
|
35265
|
+
elements.workspaceReplaceCancelButton?.addEventListener("click", () => finishWorkspaceReplacement(null));
|
|
35266
|
+
elements.workspaceReplaceDiscardButton?.addEventListener("click", () => finishWorkspaceReplacement({ replaceOpenTabs: true, discardCurrent: true }));
|
|
35267
|
+
elements.workspaceReplaceSaveButton?.addEventListener("click", () => finishWorkspaceReplacement(workspaceSaveCurrentDecision()));
|
|
35268
|
+
elements.workspaceReplaceDialog?.querySelector("form")?.addEventListener("submit", (event) => {
|
|
35269
|
+
event.preventDefault();
|
|
35270
|
+
finishWorkspaceReplacement(workspaceSaveCurrentDecision());
|
|
35271
|
+
});
|
|
35272
|
+
elements.workspaceReplaceDialog?.addEventListener("cancel", (event) => {
|
|
35273
|
+
event.preventDefault();
|
|
35274
|
+
finishWorkspaceReplacement(null);
|
|
35275
|
+
});
|
|
35276
|
+
elements.workspaceReplaceDialog?.addEventListener("close", () => {
|
|
35277
|
+
if (activeWorkspaceReplacementResolve) finishWorkspaceReplacement(null);
|
|
35278
|
+
});
|
|
33452
35279
|
elements.gitWorktreeBaseCancelButton?.addEventListener("click", () => finishGitWorktreeBaseChoice(null));
|
|
33453
35280
|
elements.gitWorktreeBaseCreateButton?.addEventListener("click", () => finishGitWorktreeBaseChoice(elements.gitWorktreeBaseCurrentHead?.checked ? "HEAD" : "origin/main"));
|
|
33454
35281
|
elements.gitWorktreeBaseDialog?.querySelector("form")?.addEventListener("submit", (event) => {
|
|
@@ -33866,6 +35693,11 @@ elements.fastOutputModeSelect?.addEventListener("change", () => {
|
|
|
33866
35693
|
renderSidebarOutputModeControl({ syncSelection: false });
|
|
33867
35694
|
});
|
|
33868
35695
|
elements.setFastOutputModeButton?.addEventListener("click", () => applySidebarOutputMode().catch((error) => addEvent(error.message || String(error), "error")));
|
|
35696
|
+
elements.codexFastModeSelect?.addEventListener("change", () => {
|
|
35697
|
+
codexFastModeNotice = "";
|
|
35698
|
+
renderCodexFastModeControl({ syncSelection: false });
|
|
35699
|
+
});
|
|
35700
|
+
elements.setCodexFastModeButton?.addEventListener("click", () => applyCodexFastMode().catch((error) => addEvent(error.message || String(error), "error")));
|
|
33869
35701
|
if (elements.terminalTabsLayoutSelect) {
|
|
33870
35702
|
elements.terminalTabsLayoutSelect.addEventListener("change", () => {
|
|
33871
35703
|
setTerminalTabsLayout(elements.terminalTabsLayoutSelect.value, { announce: true });
|
|
@@ -33915,6 +35747,23 @@ elements.subagentTerminalCopyButton?.addEventListener("click", () => copySubagen
|
|
|
33915
35747
|
elements.subagentTerminalRefreshButton?.addEventListener("click", () => {
|
|
33916
35748
|
refreshSubagentTerminalView(activeSubagentTerminalId, { showLoading: true }).finally(() => scheduleSubagentTerminalRefresh());
|
|
33917
35749
|
});
|
|
35750
|
+
elements.subagentTerminalCancelButton?.addEventListener("click", () => {
|
|
35751
|
+
const view = activeSubagentTerminalView();
|
|
35752
|
+
if (view) openSubagentCancelDialog(view.tab || { tabId: view.parentTabId, tabTitle: view.parentTitle }, view.run, view.data?.agent || view.agent);
|
|
35753
|
+
});
|
|
35754
|
+
elements.subagentCancelKeepRunningButton?.addEventListener("click", closeSubagentCancelDialog);
|
|
35755
|
+
elements.subagentCancelDialog?.querySelector("form")?.addEventListener("submit", (event) => {
|
|
35756
|
+
event.preventDefault();
|
|
35757
|
+
void submitSubagentCancel();
|
|
35758
|
+
});
|
|
35759
|
+
elements.subagentCancelDialog?.addEventListener("cancel", (event) => {
|
|
35760
|
+
if (subagentCancelSubmitting) event.preventDefault();
|
|
35761
|
+
});
|
|
35762
|
+
elements.subagentCancelDialog?.addEventListener("close", () => {
|
|
35763
|
+
subagentCancelSelection = null;
|
|
35764
|
+
setSubagentCancelSubmitting(false);
|
|
35765
|
+
setSubagentCancelStatus();
|
|
35766
|
+
});
|
|
33918
35767
|
elements.piVersionButton?.addEventListener("click", () => {
|
|
33919
35768
|
openPiReleaseNotes().catch((error) => addEvent(error.message || String(error), "error"));
|
|
33920
35769
|
});
|
|
@@ -33961,6 +35810,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
33961
35810
|
if (document.body.classList.contains("composer-actions-open") && !elements.composer.contains(event.target)) {
|
|
33962
35811
|
setComposerActionsOpen(false);
|
|
33963
35812
|
}
|
|
35813
|
+
if (followUpQueueOpen && !event.target?.closest?.("#followUpQueueOverlay, #followUpQueueTrigger")) {
|
|
35814
|
+
setFollowUpQueueOpen(false, { restoreFocus: true });
|
|
35815
|
+
}
|
|
33964
35816
|
if (publishMenuOpen && !event.target?.closest?.(".composer-publish-menu")) {
|
|
33965
35817
|
setPublishMenuOpen(false);
|
|
33966
35818
|
}
|
|
@@ -34138,6 +35990,7 @@ function stepChatSearch(step) {
|
|
|
34138
35990
|
|
|
34139
35991
|
function openChatSearch() {
|
|
34140
35992
|
if (!elements.chatSearchBar) return;
|
|
35993
|
+
closeFileViewerSearch({ restoreFocus: false });
|
|
34141
35994
|
elements.chatSearchBar.hidden = false;
|
|
34142
35995
|
elements.chatSearchInput?.focus();
|
|
34143
35996
|
elements.chatSearchInput?.select();
|
|
@@ -34176,7 +36029,8 @@ elements.chatSearchCloseButton?.addEventListener("click", closeChatSearch);
|
|
|
34176
36029
|
window.addEventListener("keydown", (event) => {
|
|
34177
36030
|
if ((event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey && event.key.toLowerCase() === "f") {
|
|
34178
36031
|
event.preventDefault();
|
|
34179
|
-
|
|
36032
|
+
if (activeFileViewer && elements.fileViewerPane?.contains(event.target)) openFileViewerSearch();
|
|
36033
|
+
else openChatSearch();
|
|
34180
36034
|
}
|
|
34181
36035
|
});
|
|
34182
36036
|
|
|
@@ -34196,12 +36050,21 @@ window.addEventListener("online", () => scheduleForegroundReconcile("network onl
|
|
|
34196
36050
|
window.addEventListener("storage", (event) => {
|
|
34197
36051
|
if (event.key === OPTIONAL_FEATURES_STORAGE_KEY) reconcileDisabledOptionalFeaturesFromStorage();
|
|
34198
36052
|
if (event.key === SIDE_PANEL_SECTION_VISIBILITY_STORAGE_KEY) restoreSidePanelSectionVisibility();
|
|
36053
|
+
if (event.key === SIDE_PANEL_WIDTH_STORAGE_KEY) {
|
|
36054
|
+
const width = readStoredSidePanelWidth();
|
|
36055
|
+
if (width && !isSidePanelOverlayView()) applySidePanelWidth(width);
|
|
36056
|
+
}
|
|
34199
36057
|
});
|
|
34200
36058
|
window.addEventListener("resize", syncResizablePanelWidthsForViewport, { passive: true });
|
|
34201
36059
|
window.addEventListener("keydown", (event) => {
|
|
34202
36060
|
if (event.key !== "Escape") return;
|
|
34203
36061
|
if (event.defaultPrevented) return;
|
|
34204
36062
|
if (elements.dialog?.open || elements.pathPickerDialog?.open || elements.gitChangesDialog?.open || elements.commandPaletteDialog?.open || elements.editRetryDialog?.open) return;
|
|
36063
|
+
if (followUpQueueOpen) {
|
|
36064
|
+
event.preventDefault();
|
|
36065
|
+
setFollowUpQueueOpen(false, { restoreFocus: true });
|
|
36066
|
+
return;
|
|
36067
|
+
}
|
|
34205
36068
|
if (publishMenuOpen) {
|
|
34206
36069
|
setPublishMenuOpen(false);
|
|
34207
36070
|
return;
|
|
@@ -34412,12 +36275,33 @@ elements.fileViewerCloseButton?.addEventListener("click", closeFileViewer);
|
|
|
34412
36275
|
elements.fileViewerChangesModeButton?.addEventListener("click", () => setFileViewerMode("changes"));
|
|
34413
36276
|
elements.fileViewerSourceModeButton?.addEventListener("click", () => setFileViewerMode("source"));
|
|
34414
36277
|
elements.fileViewerPreviewModeButton?.addEventListener("click", () => setFileViewerMode("preview"));
|
|
36278
|
+
elements.fileViewerSearchInput?.addEventListener("input", () => {
|
|
36279
|
+
clearTimeout(fileViewerSearchTimer);
|
|
36280
|
+
fileViewerSearchTimer = setTimeout(() => {
|
|
36281
|
+
fileViewerSearchIndex = -1;
|
|
36282
|
+
runFileViewerSearch({ navigate: true });
|
|
36283
|
+
}, 150);
|
|
36284
|
+
});
|
|
36285
|
+
elements.fileViewerSearchInput?.addEventListener("keydown", (event) => {
|
|
36286
|
+
if (event.key === "Enter") {
|
|
36287
|
+
event.preventDefault();
|
|
36288
|
+
stepFileViewerSearch(event.shiftKey ? -1 : 1);
|
|
36289
|
+
} else if (event.key === "Escape") {
|
|
36290
|
+
event.preventDefault();
|
|
36291
|
+
event.stopPropagation();
|
|
36292
|
+
closeFileViewerSearch();
|
|
36293
|
+
}
|
|
36294
|
+
});
|
|
36295
|
+
elements.fileViewerSearchPrevButton?.addEventListener("click", () => stepFileViewerSearch(-1));
|
|
36296
|
+
elements.fileViewerSearchNextButton?.addEventListener("click", () => stepFileViewerSearch(1));
|
|
36297
|
+
elements.fileViewerSearchCloseButton?.addEventListener("click", () => closeFileViewerSearch());
|
|
34415
36298
|
elements.fileViewerEditor?.addEventListener("input", () => {
|
|
34416
36299
|
if (!activeFileViewer) return;
|
|
34417
36300
|
activeFileViewer.content = elements.fileViewerEditor.value || "";
|
|
34418
36301
|
activeFileViewer.size = new Blob([activeFileViewer.content]).size;
|
|
34419
36302
|
setFileViewerDirty(true);
|
|
34420
36303
|
updateFileViewerSelectionFromEditor();
|
|
36304
|
+
if (elements.fileViewerSearchBar && !elements.fileViewerSearchBar.hidden) runFileViewerSearch();
|
|
34421
36305
|
});
|
|
34422
36306
|
for (const eventName of ["select", "keyup", "mouseup"]) {
|
|
34423
36307
|
elements.fileViewerEditor?.addEventListener(eventName, updateFileViewerSelectionFromEditor);
|
|
@@ -34553,6 +36437,7 @@ focusPromptInput({ defer: true });
|
|
|
34553
36437
|
restoreStoredSkillUsage();
|
|
34554
36438
|
restoreBusyPromptBehaviorSetting();
|
|
34555
36439
|
updateComposerModeButtons();
|
|
36440
|
+
installSessionSkillTagResizeHandling();
|
|
34556
36441
|
updateOptionalFeatureAvailability();
|
|
34557
36442
|
refreshOptionalFeaturePackageStatuses({ announce: true });
|
|
34558
36443
|
renderAppRunnerControls();
|
|
@@ -34590,4 +36475,5 @@ bindSidePanelOverlayViewChanges();
|
|
|
34590
36475
|
registerPwaServiceWorker();
|
|
34591
36476
|
renderServerOfflinePanel();
|
|
34592
36477
|
refreshSidebarOutputMode().catch((error) => addEvent(error.message || String(error), "error"));
|
|
36478
|
+
refreshCodexFastMode().catch((error) => addEvent(error.message || String(error), "error"));
|
|
34593
36479
|
initializeTabs().catch((error) => addEvent(error.message, "error"));
|