@firstpick/pi-package-webui 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/bin/pi-webui.mjs +243 -1
- package/index.ts +4 -0
- package/lib/subagent-gate.mjs +618 -0
- package/package.json +10 -9
- package/public/app.js +1250 -81
- package/public/index.html +72 -1
- package/public/styles.css +586 -18
- package/tests/fixtures/fake-pi.mjs +21 -4
- package/tests/git-panel-render-stability-static.test.mjs +43 -0
- package/tests/http-endpoints-harness.test.mjs +77 -1
- package/tests/mobile-static.test.mjs +119 -12
- package/tests/subagent-gate.test.mjs +300 -0
- package/tests/subagents-helper.test.mjs +34 -3
- package/webui-rpc-helper.mjs +165 -11
package/public/app.js
CHANGED
|
@@ -44,6 +44,14 @@ const elements = {
|
|
|
44
44
|
copyServerCommandButton: $("#copyServerCommandButton"),
|
|
45
45
|
retryServerConnectionButton: $("#retryServerConnectionButton"),
|
|
46
46
|
widgetArea: $("#widgetArea"),
|
|
47
|
+
subagentTerminalView: $("#subagentTerminalView"),
|
|
48
|
+
subagentTerminalTitle: $("#subagentTerminalTitle"),
|
|
49
|
+
subagentTerminalMeta: $("#subagentTerminalMeta"),
|
|
50
|
+
subagentTerminalTranscript: $("#subagentTerminalTranscript"),
|
|
51
|
+
subagentTerminalStatus: $("#subagentTerminalStatus"),
|
|
52
|
+
subagentTerminalCopyButton: $("#subagentTerminalCopyButton"),
|
|
53
|
+
subagentTerminalRefreshButton: $("#subagentTerminalRefreshButton"),
|
|
54
|
+
subagentTerminalInput: $("#subagentTerminalInput"),
|
|
47
55
|
stickyUserPromptButton: $("#stickyUserPromptButton"),
|
|
48
56
|
chat: $("#chat"),
|
|
49
57
|
chatSearchBar: $("#chatSearchBar"),
|
|
@@ -195,6 +203,10 @@ const elements = {
|
|
|
195
203
|
fileTreeRefreshButton: $("#fileTreeRefreshButton"),
|
|
196
204
|
fileTreeSearchInput: $("#fileTreeSearchInput"),
|
|
197
205
|
fileTreeSearchClearButton: $("#fileTreeSearchClearButton"),
|
|
206
|
+
gitPanelGroups: $("#gitPanelGroups"),
|
|
207
|
+
gitPanelStatus: $("#gitPanelStatus"),
|
|
208
|
+
gitPanelCountBadge: $("#gitPanelCountBadge"),
|
|
209
|
+
gitPanelContextMenu: $("#gitPanelContextMenu"),
|
|
198
210
|
fileViewerPane: $("#fileViewerPane"),
|
|
199
211
|
fileViewerResizeHandle: $("#fileViewerResizeHandle"),
|
|
200
212
|
fileViewerTitle: $("#fileViewerTitle"),
|
|
@@ -221,6 +233,8 @@ const elements = {
|
|
|
221
233
|
subagentsStatus: $("#subagentsStatus"),
|
|
222
234
|
subagentsBox: $("#subagentsBox"),
|
|
223
235
|
subagentCountBadge: $("#subagentCountBadge"),
|
|
236
|
+
subagentOpenModeSelect: $("#subagentOpenModeSelect"),
|
|
237
|
+
subagentOpenModeStatus: $("#subagentOpenModeStatus"),
|
|
224
238
|
queueBox: $("#queueBox"),
|
|
225
239
|
queueCountBadge: $("#queueCountBadge"),
|
|
226
240
|
createPromptListButton: $("#createPromptListButton"),
|
|
@@ -263,6 +277,12 @@ const elements = {
|
|
|
263
277
|
confirmationUndo: $("#confirmationUndo"),
|
|
264
278
|
confirmationCancelButton: $("#confirmationCancelButton"),
|
|
265
279
|
confirmationConfirmButton: $("#confirmationConfirmButton"),
|
|
280
|
+
gitWorktreeBaseDialog: $("#gitWorktreeBaseDialog"),
|
|
281
|
+
gitWorktreeBaseBranch: $("#gitWorktreeBaseBranch"),
|
|
282
|
+
gitWorktreeBaseOriginMain: $("#gitWorktreeBaseOriginMain"),
|
|
283
|
+
gitWorktreeBaseCurrentHead: $("#gitWorktreeBaseCurrentHead"),
|
|
284
|
+
gitWorktreeBaseCancelButton: $("#gitWorktreeBaseCancelButton"),
|
|
285
|
+
gitWorktreeBaseCreateButton: $("#gitWorktreeBaseCreateButton"),
|
|
266
286
|
piReleaseNotesDialog: $("#piReleaseNotesDialog"),
|
|
267
287
|
piReleaseNotesTitle: $("#piReleaseNotesTitle"),
|
|
268
288
|
piReleaseNotesStatus: $("#piReleaseNotesStatus"),
|
|
@@ -390,14 +410,26 @@ let foregroundReconcileTimer = null;
|
|
|
390
410
|
let eventSource = null;
|
|
391
411
|
let activeDialog = null;
|
|
392
412
|
let activeConfirmationResolve = null;
|
|
413
|
+
let activeGitWorktreeBaseResolve = null;
|
|
393
414
|
let activeUndoAction = null;
|
|
394
415
|
let undoToastTimer = null;
|
|
395
416
|
let undoToastFocusReturn = null;
|
|
396
417
|
const modalSurfaceState = new WeakMap();
|
|
397
418
|
let activeDrawerModal = null;
|
|
398
419
|
let activeGitPrDialogResolve = null;
|
|
399
|
-
let gitChangesState = { loading: false, pulling: false, fetching: false, error: "", errorCode: "", errorHint: "", message: "", pullResult: null, data: null, operation: null, lastFetch: null, tabId: null };
|
|
420
|
+
let gitChangesState = { loading: false, pulling: false, fetching: false, error: "", errorCode: "", errorHint: "", message: "", pullResult: null, data: null, operation: null, lastFetch: null, tabId: null, mode: "changes", commit: null };
|
|
400
421
|
let gitToolsState = { tabId: null, openSections: new Set(), cache: {}, busy: new Set(), notice: {} };
|
|
422
|
+
let gitPanelState = {
|
|
423
|
+
expandedCardKey: "",
|
|
424
|
+
discovery: new Map(),
|
|
425
|
+
repositories: new Map(),
|
|
426
|
+
activeViews: new Map(),
|
|
427
|
+
openFolders: new Map(),
|
|
428
|
+
busy: new Set(),
|
|
429
|
+
requestSerial: 0,
|
|
430
|
+
};
|
|
431
|
+
let gitPanelContextMenuState = null;
|
|
432
|
+
let gitPanelRenderSignature = null;
|
|
401
433
|
let gitChangesRequestSerial = 0;
|
|
402
434
|
const gitChangesUntrackedContentRequests = new Set();
|
|
403
435
|
let nativeCommandTabId = null;
|
|
@@ -478,6 +510,10 @@ let subagentOverlayError = "";
|
|
|
478
510
|
let subagentOverlayLoading = false;
|
|
479
511
|
let subagentOverlayRefreshTimer = null;
|
|
480
512
|
let subagentOverlayRequestSerial = 0;
|
|
513
|
+
let subagentOpenMode = "overlay";
|
|
514
|
+
const subagentTerminalViews = new Map();
|
|
515
|
+
let activeSubagentTerminalId = null;
|
|
516
|
+
let subagentTerminalRefreshTimer = null;
|
|
481
517
|
let backendOffline = false;
|
|
482
518
|
let serverRestartInProgress = false;
|
|
483
519
|
let updateRequestInProgress = false;
|
|
@@ -587,6 +623,7 @@ const THINKING_VISIBILITY_STORAGE_KEY = "pi-webui-thinking-visible";
|
|
|
587
623
|
const BUSY_PROMPT_BEHAVIOR_STORAGE_KEY = "pi-webui-busy-prompt-behavior";
|
|
588
624
|
const SKILL_USAGE_STORAGE_KEY = "pi-webui-skill-usage-v1";
|
|
589
625
|
const TERMINAL_TABS_LAYOUT_STORAGE_KEY = "pi-webui-terminal-tabs-layout";
|
|
626
|
+
const SUBAGENT_OPEN_MODE_STORAGE_KEY = "pi-webui-subagent-open-mode";
|
|
590
627
|
const TERMINAL_CUSTOM_GROUPS_STORAGE_KEY = "pi-webui-terminal-custom-groups-v1";
|
|
591
628
|
const TERMINAL_TAB_DRAG_MIME = "application/x-pi-terminal-tab-id";
|
|
592
629
|
const FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY = "pi-webui-footer-scoped-model-order-v1";
|
|
@@ -691,6 +728,7 @@ const AUR_REVIEW_RPC_PAYLOAD_TYPE = "firstpick.pi-extension-aur-review.review";
|
|
|
691
728
|
const AUR_REVIEW_RPC_PAYLOAD_VERSION = 3;
|
|
692
729
|
const GIT_CHANGES_RENDER_ROW_LIMIT = 4000;
|
|
693
730
|
const GIT_PULL_RESULT_FILE_LIMIT = 48;
|
|
731
|
+
const GIT_PANEL_CACHE_MAX_AGE_MS = 5 * 60 * 1000;
|
|
694
732
|
const LAST_USER_PROMPT_STORAGE_KEY = "pi-webui-last-user-prompts";
|
|
695
733
|
const PROMPT_HISTORY_STORAGE_KEY = "pi-webui-prompt-history";
|
|
696
734
|
const PROMPT_LIST_STORAGE_KEY = "pi-webui-prompt-lists";
|
|
@@ -727,6 +765,8 @@ const THEME_SCHEME_MODES = new Set(["light", "dark", "auto"]);
|
|
|
727
765
|
let themeSchemeMode = "light"; // "light" | "dark" | "auto"; finalized in initializeThemes
|
|
728
766
|
const TERMINAL_TABS_LAYOUTS = new Set(["top", "left"]);
|
|
729
767
|
const TERMINAL_TABS_LAYOUT_LABELS = { top: "Top bar", left: "Left sidebar" };
|
|
768
|
+
const SUBAGENT_OPEN_MODES = new Set(["overlay", "tab"]);
|
|
769
|
+
const SUBAGENT_OPEN_MODE_LABELS = { overlay: "Overlay", tab: "Tab / terminal" };
|
|
730
770
|
const BUSY_PROMPT_BEHAVIOR_VALUES = new Set(["followUp", "steer"]);
|
|
731
771
|
const BUSY_PROMPT_BEHAVIOR_LABELS = { followUp: "Follow-up", steer: "Steer" };
|
|
732
772
|
const SKILL_TAG_MAX_VISIBLE = 6;
|
|
@@ -1494,6 +1534,12 @@ function setSidePanelSectionCollapsed(record, collapsed, { persist = true } = {}
|
|
|
1494
1534
|
record.button.setAttribute("aria-expanded", collapsed ? "false" : "true");
|
|
1495
1535
|
record.button.setAttribute("aria-label", `${collapsed ? "Expand" : "Collapse"} ${label} section`);
|
|
1496
1536
|
record.button.setAttribute("title", `${collapsed ? "Expand" : "Collapse"} ${label} section`);
|
|
1537
|
+
if (!collapsed && record.id === "git") {
|
|
1538
|
+
queueMicrotask(() => {
|
|
1539
|
+
renderGitPanel();
|
|
1540
|
+
ensureGitPanelRepositoriesDiscovered({ retryUnavailable: true });
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1497
1543
|
if (persist) persistSidePanelSectionState();
|
|
1498
1544
|
}
|
|
1499
1545
|
|
|
@@ -1681,6 +1727,44 @@ function restoreTerminalTabsLayoutSetting() {
|
|
|
1681
1727
|
setTerminalTabsLayout(readStoredTerminalTabsLayout(), { persist: false });
|
|
1682
1728
|
}
|
|
1683
1729
|
|
|
1730
|
+
function normalizeSubagentOpenMode(value) {
|
|
1731
|
+
return SUBAGENT_OPEN_MODES.has(value) ? value : "overlay";
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
function readStoredSubagentOpenMode() {
|
|
1735
|
+
try {
|
|
1736
|
+
return normalizeSubagentOpenMode(localStorage.getItem(SUBAGENT_OPEN_MODE_STORAGE_KEY));
|
|
1737
|
+
} catch {
|
|
1738
|
+
return "overlay";
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
function persistSubagentOpenMode(mode) {
|
|
1743
|
+
try {
|
|
1744
|
+
localStorage.setItem(SUBAGENT_OPEN_MODE_STORAGE_KEY, normalizeSubagentOpenMode(mode));
|
|
1745
|
+
} catch {
|
|
1746
|
+
// Ignore storage failures; the opening mode still applies for this page load.
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
function renderSubagentOpenModeControl() {
|
|
1751
|
+
const mode = normalizeSubagentOpenMode(subagentOpenMode);
|
|
1752
|
+
if (elements.subagentOpenModeSelect) elements.subagentOpenModeSelect.value = mode;
|
|
1753
|
+
if (elements.subagentOpenModeStatus) elements.subagentOpenModeStatus.textContent = `${SUBAGENT_OPEN_MODE_LABELS[mode]} · saved in this browser`;
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
function setSubagentOpenMode(mode, { persist = true, announce = false } = {}) {
|
|
1757
|
+
subagentOpenMode = normalizeSubagentOpenMode(mode);
|
|
1758
|
+
if (persist) persistSubagentOpenMode(subagentOpenMode);
|
|
1759
|
+
renderSubagentOpenModeControl();
|
|
1760
|
+
renderSubagents();
|
|
1761
|
+
if (announce) addEvent(`subagents now open in ${SUBAGENT_OPEN_MODE_LABELS[subagentOpenMode].toLowerCase()}`);
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
function restoreSubagentOpenModeSetting() {
|
|
1765
|
+
setSubagentOpenMode(readStoredSubagentOpenMode(), { persist: false });
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1684
1768
|
function normalizeTerminalCustomGroupTitle(value, fallback = "Custom group") {
|
|
1685
1769
|
const title = String(value || "").replace(/\s+/g, " ").trim();
|
|
1686
1770
|
return (title || fallback).slice(0, 40);
|
|
@@ -1941,6 +2025,7 @@ function setThinkingOutputVisible(visible, { announce = false } = {}) {
|
|
|
1941
2025
|
if (!thinkingOutputVisible) removeStreamingThinkingBubble();
|
|
1942
2026
|
renderAllMessages({ preserveScroll: true });
|
|
1943
2027
|
if (subagentOverlaySelection?.tabId === activeTabId) renderWidgets();
|
|
2028
|
+
if (activeSubagentTerminalId) renderSubagentTerminalView();
|
|
1944
2029
|
if (announce) addEvent(thinkingOutputVisible ? "thinking output shown" : "thinking output hidden", thinkingOutputVisible ? "info" : "warn");
|
|
1945
2030
|
}
|
|
1946
2031
|
|
|
@@ -2762,6 +2847,31 @@ function appConfirmText(message, options = {}) {
|
|
|
2762
2847
|
});
|
|
2763
2848
|
}
|
|
2764
2849
|
|
|
2850
|
+
function finishGitWorktreeBaseChoice(baseRef = null) {
|
|
2851
|
+
const resolve = activeGitWorktreeBaseResolve;
|
|
2852
|
+
activeGitWorktreeBaseResolve = null;
|
|
2853
|
+
if (elements.gitWorktreeBaseDialog?.open) elements.gitWorktreeBaseDialog.close();
|
|
2854
|
+
resolve?.(baseRef);
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
function chooseGitWorktreeBase(branch) {
|
|
2858
|
+
const branchName = cleanStatusText(branch) || "the new branch";
|
|
2859
|
+
if (!elements.gitWorktreeBaseDialog?.showModal) {
|
|
2860
|
+
const choice = window.prompt(`Create ${branchName} from:\n1. origin/main (default)\n2. Current workspace HEAD\n\nEnter 1 or 2. Cancel to abort.`, "1");
|
|
2861
|
+
if (choice === null) return Promise.resolve(null);
|
|
2862
|
+
return Promise.resolve(String(choice).trim() === "2" ? "HEAD" : "origin/main");
|
|
2863
|
+
}
|
|
2864
|
+
if (activeGitWorktreeBaseResolve) finishGitWorktreeBaseChoice(null);
|
|
2865
|
+
elements.gitWorktreeBaseBranch.textContent = branchName;
|
|
2866
|
+
elements.gitWorktreeBaseOriginMain.checked = true;
|
|
2867
|
+
elements.gitWorktreeBaseCurrentHead.checked = false;
|
|
2868
|
+
return new Promise((resolve) => {
|
|
2869
|
+
activeGitWorktreeBaseResolve = resolve;
|
|
2870
|
+
elements.gitWorktreeBaseDialog.showModal();
|
|
2871
|
+
queueMicrotask(() => elements.gitWorktreeBaseOriginMain?.focus());
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2765
2875
|
function handleDrawerModalKeydown(event) {
|
|
2766
2876
|
if (!activeDrawerModal || event.defaultPrevented) return;
|
|
2767
2877
|
if (event.key === "Escape") {
|
|
@@ -6523,6 +6633,7 @@ function showFileContextMenu(event, entry) {
|
|
|
6523
6633
|
if (!elements.fileContextMenu) return;
|
|
6524
6634
|
event.preventDefault();
|
|
6525
6635
|
event.stopPropagation();
|
|
6636
|
+
closeGitPanelContextMenu({ returnFocus: false });
|
|
6526
6637
|
const path = normalizeFileTreePath(entry?.path || "");
|
|
6527
6638
|
fileContextMenuState = { entry: { ...entry, path }, trigger: event.currentTarget || document.activeElement };
|
|
6528
6639
|
const menu = elements.fileContextMenu;
|
|
@@ -7709,6 +7820,11 @@ function requestedTabIdFromUrl() {
|
|
|
7709
7820
|
}
|
|
7710
7821
|
|
|
7711
7822
|
function updateDocumentTitle() {
|
|
7823
|
+
const subagentView = activeSubagentTerminalView();
|
|
7824
|
+
if (subagentView) {
|
|
7825
|
+
document.title = `Pi Web UI · ${subagentTerminalViewTitle(subagentView)} · Subagent`;
|
|
7826
|
+
return;
|
|
7827
|
+
}
|
|
7712
7828
|
const tab = activeTab();
|
|
7713
7829
|
document.title = tab ? `Pi Web UI · ${tab.title}` : "Pi Web UI";
|
|
7714
7830
|
}
|
|
@@ -7727,7 +7843,7 @@ function restoreActiveDraft() {
|
|
|
7727
7843
|
|
|
7728
7844
|
function focusPromptInput({ defer = false } = {}) {
|
|
7729
7845
|
const focus = () => {
|
|
7730
|
-
if (!elements.promptInput || elements.dialog.open || elements.pathPickerDialog.open || elements.gitChangesDialog?.open || elements.commandPaletteDialog?.open || elements.editRetryDialog?.open || elements.nativeCommandDialog.open || elements.remoteQrDialog?.open || elements.appRunnerInfoDialog?.open || elements.gitFooterVisibilityDialog?.open || elements.statsOverlayDialog?.open || elements.promptListDialog?.open || elements.attachmentTextDialog?.open || elements.skillEditorDialog?.open || document.visibilityState === "hidden") return;
|
|
7846
|
+
if (activeSubagentTerminalId || !elements.promptInput || elements.dialog.open || elements.pathPickerDialog.open || elements.gitChangesDialog?.open || elements.commandPaletteDialog?.open || elements.editRetryDialog?.open || elements.nativeCommandDialog.open || elements.remoteQrDialog?.open || elements.appRunnerInfoDialog?.open || elements.gitFooterVisibilityDialog?.open || elements.statsOverlayDialog?.open || elements.promptListDialog?.open || elements.attachmentTextDialog?.open || elements.skillEditorDialog?.open || document.visibilityState === "hidden") return;
|
|
7731
7847
|
try {
|
|
7732
7848
|
elements.promptInput.focus({ preventScroll: true });
|
|
7733
7849
|
} catch {
|
|
@@ -7996,6 +8112,583 @@ function terminalDisplayGroupDetail(group, fallback = "group") {
|
|
|
7996
8112
|
return `${cwdLabels[0]} + ${cwdLabels.length - 1} cwd${cwdLabels.length === 2 ? "" : "s"}`;
|
|
7997
8113
|
}
|
|
7998
8114
|
|
|
8115
|
+
function gitPanelSectionExpanded() {
|
|
8116
|
+
const section = elements.sidePanel?.querySelector('[data-side-panel-section="git"]');
|
|
8117
|
+
return Boolean(section && !section.classList.contains("collapsed"));
|
|
8118
|
+
}
|
|
8119
|
+
|
|
8120
|
+
function gitPanelTerminalGroups() {
|
|
8121
|
+
const cwdGroups = tabCwdGroups();
|
|
8122
|
+
const groups = [];
|
|
8123
|
+
for (const group of cwdGroups) {
|
|
8124
|
+
if (shouldRenderTerminalTabGroup(group, cwdGroups.length)) {
|
|
8125
|
+
groups.push({ ...group, title: terminalDisplayGroupTitle(group), detail: terminalDisplayGroupDetail(group) });
|
|
8126
|
+
continue;
|
|
8127
|
+
}
|
|
8128
|
+
for (const tab of group.tabs || []) {
|
|
8129
|
+
groups.push({
|
|
8130
|
+
key: `tab:${tab.id}`,
|
|
8131
|
+
custom: false,
|
|
8132
|
+
cwd: tab.cwd || "",
|
|
8133
|
+
tabs: [tab],
|
|
8134
|
+
title: tabGroupTitle(tab.cwd, "Working directory"),
|
|
8135
|
+
detail: normalizeDisplayPath(tab.cwd || ""),
|
|
8136
|
+
});
|
|
8137
|
+
}
|
|
8138
|
+
}
|
|
8139
|
+
return groups;
|
|
8140
|
+
}
|
|
8141
|
+
|
|
8142
|
+
function gitPanelCandidates(groups = gitPanelTerminalGroups()) {
|
|
8143
|
+
const byCwd = new Map();
|
|
8144
|
+
for (const group of groups) {
|
|
8145
|
+
for (const tab of group.tabs || []) {
|
|
8146
|
+
const cwd = String(tab.cwd || "").trim();
|
|
8147
|
+
if (!cwd || byCwd.has(cwd)) continue;
|
|
8148
|
+
byCwd.set(cwd, {
|
|
8149
|
+
key: `cwd:${cwd}`,
|
|
8150
|
+
cwd,
|
|
8151
|
+
tabId: tab.id,
|
|
8152
|
+
tabTitle: tabGroupTitle(cwd, "Working directory"),
|
|
8153
|
+
});
|
|
8154
|
+
}
|
|
8155
|
+
}
|
|
8156
|
+
return [...byCwd.values()];
|
|
8157
|
+
}
|
|
8158
|
+
|
|
8159
|
+
function gitPanelRepositoryCards(groups = gitPanelTerminalGroups()) {
|
|
8160
|
+
const byIdentity = new Map();
|
|
8161
|
+
for (const candidate of gitPanelCandidates(groups)) {
|
|
8162
|
+
const discovery = gitPanelState.discovery.get(candidate.key);
|
|
8163
|
+
const root = String(discovery?.root || "");
|
|
8164
|
+
const identity = root ? `root:${root}` : candidate.key;
|
|
8165
|
+
let card = byIdentity.get(identity);
|
|
8166
|
+
if (!card) {
|
|
8167
|
+
card = {
|
|
8168
|
+
key: identity,
|
|
8169
|
+
root,
|
|
8170
|
+
cwd: candidate.cwd,
|
|
8171
|
+
tabId: candidate.tabId,
|
|
8172
|
+
candidates: [],
|
|
8173
|
+
discovery,
|
|
8174
|
+
};
|
|
8175
|
+
byIdentity.set(identity, card);
|
|
8176
|
+
}
|
|
8177
|
+
card.candidates.push(candidate);
|
|
8178
|
+
if (!card.discovery && discovery) card.discovery = discovery;
|
|
8179
|
+
}
|
|
8180
|
+
return [...byIdentity.values()];
|
|
8181
|
+
}
|
|
8182
|
+
|
|
8183
|
+
function gitPanelRootLabel(root, fallback = "Repository") {
|
|
8184
|
+
const normalized = normalizeDisplayPath(root || "").replace(/\/+$/, "");
|
|
8185
|
+
return normalized.split("/").filter(Boolean).pop() || normalized || fallback;
|
|
8186
|
+
}
|
|
8187
|
+
|
|
8188
|
+
function gitPanelSnapshot(root) {
|
|
8189
|
+
return root ? gitPanelState.repositories.get(root) || null : null;
|
|
8190
|
+
}
|
|
8191
|
+
|
|
8192
|
+
function gitPanelSnapshotFresh(snapshot) {
|
|
8193
|
+
return Boolean(snapshot?.data && Date.now() - Number(snapshot.loadedAt || 0) < GIT_PANEL_CACHE_MAX_AGE_MS);
|
|
8194
|
+
}
|
|
8195
|
+
|
|
8196
|
+
async function discoverGitPanelCandidate(candidate, { force = false } = {}) {
|
|
8197
|
+
const current = gitPanelState.discovery.get(candidate.key);
|
|
8198
|
+
if (current?.loading || (!force && (current?.root || current?.resolved))) return;
|
|
8199
|
+
const requestSerial = ++gitPanelState.requestSerial;
|
|
8200
|
+
gitPanelState.discovery.set(candidate.key, { loading: true, resolved: false, requestSerial, root: "", error: "" });
|
|
8201
|
+
renderGitPanel();
|
|
8202
|
+
try {
|
|
8203
|
+
const response = await api("/api/git-root", { tabId: candidate.tabId });
|
|
8204
|
+
const latest = gitPanelState.discovery.get(candidate.key);
|
|
8205
|
+
if (latest?.requestSerial !== requestSerial) return;
|
|
8206
|
+
if (!response.ok || !response.data?.root) throw new Error(response.error || "Not a Git repository");
|
|
8207
|
+
gitPanelState.discovery.set(candidate.key, { loading: false, resolved: true, requestSerial, checkedAt: Date.now(), root: response.data.root, error: "" });
|
|
8208
|
+
} catch (error) {
|
|
8209
|
+
const latest = gitPanelState.discovery.get(candidate.key);
|
|
8210
|
+
if (latest?.requestSerial !== requestSerial) return;
|
|
8211
|
+
gitPanelState.discovery.set(candidate.key, { loading: false, resolved: true, requestSerial, checkedAt: Date.now(), root: "", error: error.message || String(error) });
|
|
8212
|
+
}
|
|
8213
|
+
renderGitPanel();
|
|
8214
|
+
}
|
|
8215
|
+
|
|
8216
|
+
function ensureGitPanelRepositoriesDiscovered({ retryUnavailable = false } = {}) {
|
|
8217
|
+
if (!gitPanelSectionExpanded()) return;
|
|
8218
|
+
for (const candidate of gitPanelCandidates()) {
|
|
8219
|
+
const discovery = gitPanelState.discovery.get(candidate.key);
|
|
8220
|
+
if (!discovery || (!discovery.loading && !discovery.resolved)) {
|
|
8221
|
+
void discoverGitPanelCandidate(candidate);
|
|
8222
|
+
} else if (retryUnavailable && !discovery.loading && !discovery.root) {
|
|
8223
|
+
void discoverGitPanelCandidate(candidate, { force: true });
|
|
8224
|
+
}
|
|
8225
|
+
}
|
|
8226
|
+
}
|
|
8227
|
+
|
|
8228
|
+
async function loadGitPanelRepository(card, { force = false } = {}) {
|
|
8229
|
+
if (!card?.root || !card.tabId) return;
|
|
8230
|
+
const existing = gitPanelSnapshot(card.root);
|
|
8231
|
+
if (!force && gitPanelSnapshotFresh(existing)) return;
|
|
8232
|
+
if (existing?.loading) return;
|
|
8233
|
+
const requestSerial = ++gitPanelState.requestSerial;
|
|
8234
|
+
gitPanelState.repositories.set(card.root, { ...existing, loading: true, error: "", requestSerial });
|
|
8235
|
+
renderGitPanel();
|
|
8236
|
+
try {
|
|
8237
|
+
const response = await api("/api/git-panel", { tabId: card.tabId });
|
|
8238
|
+
const latest = gitPanelSnapshot(card.root);
|
|
8239
|
+
if (latest?.requestSerial !== requestSerial) return;
|
|
8240
|
+
if (!response.ok || !response.data?.root) throw new Error(response.error || "Failed to load Git repository");
|
|
8241
|
+
gitPanelState.repositories.set(card.root, {
|
|
8242
|
+
loading: false,
|
|
8243
|
+
error: "",
|
|
8244
|
+
requestSerial,
|
|
8245
|
+
loadedAt: Date.now(),
|
|
8246
|
+
data: response.data,
|
|
8247
|
+
});
|
|
8248
|
+
} catch (error) {
|
|
8249
|
+
const latest = gitPanelSnapshot(card.root);
|
|
8250
|
+
if (latest?.requestSerial !== requestSerial) return;
|
|
8251
|
+
gitPanelState.repositories.set(card.root, {
|
|
8252
|
+
...latest,
|
|
8253
|
+
loading: false,
|
|
8254
|
+
error: error.message || String(error),
|
|
8255
|
+
requestSerial,
|
|
8256
|
+
});
|
|
8257
|
+
}
|
|
8258
|
+
renderGitPanel();
|
|
8259
|
+
}
|
|
8260
|
+
|
|
8261
|
+
function toggleGitPanelRepository(card) {
|
|
8262
|
+
if (!card?.root) return;
|
|
8263
|
+
if (gitPanelState.expandedCardKey === card.key) {
|
|
8264
|
+
gitPanelState.expandedCardKey = "";
|
|
8265
|
+
renderGitPanel();
|
|
8266
|
+
return;
|
|
8267
|
+
}
|
|
8268
|
+
gitPanelState.expandedCardKey = card.key;
|
|
8269
|
+
renderGitPanel();
|
|
8270
|
+
const snapshot = gitPanelSnapshot(card.root);
|
|
8271
|
+
if (!gitPanelSnapshotFresh(snapshot)) void loadGitPanelRepository(card);
|
|
8272
|
+
}
|
|
8273
|
+
|
|
8274
|
+
function gitPanelChangeCount(data) {
|
|
8275
|
+
return Array.isArray(data?.changes) ? data.changes.length : 0;
|
|
8276
|
+
}
|
|
8277
|
+
|
|
8278
|
+
function gitPanelStatsText(entry = {}, category = "") {
|
|
8279
|
+
const prefix = category === "staged" ? "staged" : category === "changes" ? "unstaged" : "";
|
|
8280
|
+
const binary = prefix ? entry[`${prefix}Binary`] === true : entry.binary === true;
|
|
8281
|
+
if (binary) return "binary";
|
|
8282
|
+
const additions = Number(prefix ? entry[`${prefix}Additions`] : entry.additions || 0) || 0;
|
|
8283
|
+
const deletions = Number(prefix ? entry[`${prefix}Deletions`] : entry.deletions || 0) || 0;
|
|
8284
|
+
if (!additions && !deletions) return entry.untracked ? "new" : "";
|
|
8285
|
+
return `${additions ? `+${additions}` : "+0"} ${deletions ? `−${deletions}` : "−0"}`;
|
|
8286
|
+
}
|
|
8287
|
+
|
|
8288
|
+
function gitPanelTree(entries = []) {
|
|
8289
|
+
const root = { name: "", path: "", folders: new Map(), files: [] };
|
|
8290
|
+
for (const entry of entries) {
|
|
8291
|
+
const parts = String(entry.path || "").split("/").filter(Boolean);
|
|
8292
|
+
if (!parts.length) continue;
|
|
8293
|
+
const fileName = parts.pop();
|
|
8294
|
+
let node = root;
|
|
8295
|
+
let currentPath = "";
|
|
8296
|
+
for (const part of parts) {
|
|
8297
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
8298
|
+
if (!node.folders.has(part)) node.folders.set(part, { name: part, path: currentPath, folders: new Map(), files: [] });
|
|
8299
|
+
node = node.folders.get(part);
|
|
8300
|
+
}
|
|
8301
|
+
node.files.push({ ...entry, name: fileName });
|
|
8302
|
+
}
|
|
8303
|
+
return root;
|
|
8304
|
+
}
|
|
8305
|
+
|
|
8306
|
+
function closeGitPanelContextMenu({ returnFocus = true } = {}) {
|
|
8307
|
+
const trigger = gitPanelContextMenuState?.trigger;
|
|
8308
|
+
gitPanelContextMenuState = null;
|
|
8309
|
+
if (elements.gitPanelContextMenu) elements.gitPanelContextMenu.hidden = true;
|
|
8310
|
+
if (returnFocus && trigger?.isConnected) queueMicrotask(() => trigger.focus({ preventScroll: true }));
|
|
8311
|
+
}
|
|
8312
|
+
|
|
8313
|
+
function gitPanelContextMenuItems(context) {
|
|
8314
|
+
const { card, category = "", kind = "file", path = "" } = context || {};
|
|
8315
|
+
if (!card?.root) return [];
|
|
8316
|
+
if (kind === "repository") {
|
|
8317
|
+
const snapshot = gitPanelSnapshot(card.root);
|
|
8318
|
+
return [
|
|
8319
|
+
{ label: "View Diff", run: () => openGitChangesDialog(card.tabId) },
|
|
8320
|
+
{ label: snapshot?.loading ? "Refreshing…" : "Refresh", disabled: snapshot?.loading, run: () => loadGitPanelRepository(card, { force: true }) },
|
|
8321
|
+
{ label: "Stage All", disabled: gitPanelActionBusy(card, "stage-all"), run: () => runGitPanelAction(card, "stage-all") },
|
|
8322
|
+
{ label: "Unstage All", disabled: gitPanelActionBusy(card, "unstage-all"), run: () => runGitPanelAction(card, "unstage-all") },
|
|
8323
|
+
];
|
|
8324
|
+
}
|
|
8325
|
+
const target = kind === "folder" ? "folder" : "file";
|
|
8326
|
+
if (category === "staged") {
|
|
8327
|
+
return [{ label: `Unstage ${target}`, disabled: gitPanelActionBusy(card, "unstage", path), run: () => runGitPanelAction(card, "unstage", path) }];
|
|
8328
|
+
}
|
|
8329
|
+
const stageLabel = category === "conflicted" ? `Stage ${target} / mark resolved` : `Stage ${target}`;
|
|
8330
|
+
const items = [{ label: stageLabel, disabled: gitPanelActionBusy(card, "stage", path), run: () => runGitPanelAction(card, "stage", path) }];
|
|
8331
|
+
if (kind === "file" && category === "changes") {
|
|
8332
|
+
items.push({ label: "Discard changes…", danger: true, disabled: gitPanelActionBusy(card, "discard", path), run: () => runGitPanelAction(card, "discard", path) });
|
|
8333
|
+
}
|
|
8334
|
+
if (kind === "file" && category === "untracked") {
|
|
8335
|
+
items.push({ label: "Delete file…", danger: true, disabled: gitPanelActionBusy(card, "delete", path), run: () => runGitPanelAction(card, "delete", path) });
|
|
8336
|
+
}
|
|
8337
|
+
return items;
|
|
8338
|
+
}
|
|
8339
|
+
|
|
8340
|
+
function showGitPanelContextMenu(event, context) {
|
|
8341
|
+
if (!elements.gitPanelContextMenu) return;
|
|
8342
|
+
event.preventDefault();
|
|
8343
|
+
event.stopPropagation();
|
|
8344
|
+
closeFileContextMenu({ returnFocus: false });
|
|
8345
|
+
closeGitPanelContextMenu({ returnFocus: false });
|
|
8346
|
+
const menu = elements.gitPanelContextMenu;
|
|
8347
|
+
const items = gitPanelContextMenuItems(context);
|
|
8348
|
+
if (!items.length) return;
|
|
8349
|
+
const trigger = event.currentTarget || document.activeElement;
|
|
8350
|
+
gitPanelContextMenuState = { ...context, trigger };
|
|
8351
|
+
const labelText = context.kind === "repository" ? gitPanelRootLabel(context.card.root) : context.path;
|
|
8352
|
+
const label = make("div", "git-side-panel-context-label", labelText);
|
|
8353
|
+
const buttons = items.map((item) => {
|
|
8354
|
+
const button = make("button", item.danger ? "danger" : "", item.label);
|
|
8355
|
+
button.type = "button";
|
|
8356
|
+
button.setAttribute("role", "menuitem");
|
|
8357
|
+
button.disabled = Boolean(item.disabled);
|
|
8358
|
+
button.addEventListener("click", () => {
|
|
8359
|
+
closeGitPanelContextMenu();
|
|
8360
|
+
void item.run();
|
|
8361
|
+
});
|
|
8362
|
+
return button;
|
|
8363
|
+
});
|
|
8364
|
+
menu.replaceChildren(label, ...buttons);
|
|
8365
|
+
menu.hidden = false;
|
|
8366
|
+
const rect = menu.getBoundingClientRect();
|
|
8367
|
+
const left = Math.min(event.clientX, Math.max(8, window.innerWidth - rect.width - 8));
|
|
8368
|
+
const top = Math.min(event.clientY, Math.max(8, window.innerHeight - rect.height - 8));
|
|
8369
|
+
menu.style.left = `${Math.max(8, left)}px`;
|
|
8370
|
+
menu.style.top = `${Math.max(8, top)}px`;
|
|
8371
|
+
menu.querySelector('[role="menuitem"]:not([disabled])')?.focus({ preventScroll: true });
|
|
8372
|
+
}
|
|
8373
|
+
|
|
8374
|
+
function bindGitPanelContextMenu(trigger, context) {
|
|
8375
|
+
trigger.setAttribute("aria-haspopup", "menu");
|
|
8376
|
+
trigger.addEventListener("contextmenu", (event) => showGitPanelContextMenu(event, context));
|
|
8377
|
+
trigger.addEventListener("keydown", (event) => {
|
|
8378
|
+
if (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10")) return;
|
|
8379
|
+
const rect = trigger.getBoundingClientRect();
|
|
8380
|
+
showGitPanelContextMenu({
|
|
8381
|
+
preventDefault: () => event.preventDefault(),
|
|
8382
|
+
stopPropagation: () => event.stopPropagation(),
|
|
8383
|
+
clientX: rect.left + Math.min(rect.width, 24),
|
|
8384
|
+
clientY: rect.bottom,
|
|
8385
|
+
currentTarget: trigger,
|
|
8386
|
+
}, context);
|
|
8387
|
+
});
|
|
8388
|
+
}
|
|
8389
|
+
|
|
8390
|
+
function gitPanelActionBusy(card, action, path = "") {
|
|
8391
|
+
return gitPanelState.busy.has(`${card.root}\u0000${action}\u0000${path}`);
|
|
8392
|
+
}
|
|
8393
|
+
|
|
8394
|
+
async function runGitPanelAction(card, action, path = "") {
|
|
8395
|
+
const config = {
|
|
8396
|
+
stage: { url: "/api/git-changes/stage-file", body: { path }, past: `Staged ${path}.` },
|
|
8397
|
+
unstage: { url: "/api/git-changes/unstage-file", body: { path }, past: `Unstaged ${path}.` },
|
|
8398
|
+
"stage-all": { url: "/api/git-changes/stage-all", body: {}, past: `Staged all changes in ${card.root}.` },
|
|
8399
|
+
"unstage-all": { url: "/api/git-changes/unstage-all", body: {}, past: `Unstaged all changes in ${card.root}.` },
|
|
8400
|
+
discard: {
|
|
8401
|
+
url: "/api/git-changes/discard-file",
|
|
8402
|
+
body: { path, confirmed: true },
|
|
8403
|
+
past: `Discarded tracked changes in ${path}.`,
|
|
8404
|
+
confirm: `Discard tracked working-tree changes in ${path}?\n\nRepository: ${card.root}\nCommand: git restore -- ${path}\n\nThis permanently reverts unstaged edits to this path.`,
|
|
8405
|
+
confirmLabel: "Discard changes",
|
|
8406
|
+
},
|
|
8407
|
+
delete: {
|
|
8408
|
+
url: "/api/git-changes/delete-untracked",
|
|
8409
|
+
body: { path, confirmed: true },
|
|
8410
|
+
past: `Deleted untracked file ${path}.`,
|
|
8411
|
+
confirm: `Delete untracked file ${path}?\n\nRepository: ${card.root}\n\nThis permanently removes the file from disk.`,
|
|
8412
|
+
confirmLabel: "Delete file",
|
|
8413
|
+
},
|
|
8414
|
+
}[action];
|
|
8415
|
+
if (!config || !card?.root || !card.tabId) return;
|
|
8416
|
+
if (config.confirm && !(await appConfirmText(config.confirm, { affected: path || card.root, confirmLabel: config.confirmLabel }))) return;
|
|
8417
|
+
const busyKey = `${card.root}\u0000${action}\u0000${path}`;
|
|
8418
|
+
if (gitPanelState.busy.has(busyKey)) return;
|
|
8419
|
+
gitPanelState.busy.add(busyKey);
|
|
8420
|
+
renderGitPanel();
|
|
8421
|
+
try {
|
|
8422
|
+
const response = await api(config.url, { method: "POST", body: config.body, tabId: card.tabId });
|
|
8423
|
+
if (!response.ok) throw new Error([response.error, response.hint].filter(Boolean).join("\n") || `Git ${action} failed`);
|
|
8424
|
+
addEvent(config.past, "success");
|
|
8425
|
+
await loadGitPanelRepository(card, { force: true });
|
|
8426
|
+
requestGitFooterWebuiPayload({ tabId: card.tabId }, { force: true });
|
|
8427
|
+
} catch (error) {
|
|
8428
|
+
addEvent(error.message || String(error), "error");
|
|
8429
|
+
const snapshot = gitPanelSnapshot(card.root);
|
|
8430
|
+
gitPanelState.repositories.set(card.root, { ...snapshot, error: error.message || String(error), loading: false });
|
|
8431
|
+
} finally {
|
|
8432
|
+
gitPanelState.busy.delete(busyKey);
|
|
8433
|
+
renderGitPanel();
|
|
8434
|
+
}
|
|
8435
|
+
}
|
|
8436
|
+
|
|
8437
|
+
function renderGitPanelFolder(node, card, category, depth = 0) {
|
|
8438
|
+
const details = make("details", "git-side-panel-folder");
|
|
8439
|
+
const folderKey = `${card.root}\u0000${category}\u0000${node.path}`;
|
|
8440
|
+
const defaultOpen = depth === 0;
|
|
8441
|
+
details.open = gitPanelState.openFolders.has(folderKey) ? gitPanelState.openFolders.get(folderKey) : defaultOpen;
|
|
8442
|
+
details.addEventListener("toggle", () => {
|
|
8443
|
+
if (details.open === defaultOpen) gitPanelState.openFolders.delete(folderKey);
|
|
8444
|
+
else gitPanelState.openFolders.set(folderKey, details.open);
|
|
8445
|
+
});
|
|
8446
|
+
const summary = make("summary", "git-side-panel-folder-summary");
|
|
8447
|
+
summary.title = `${node.path} · Right-click for Git actions`;
|
|
8448
|
+
const chevron = make("span", "git-side-panel-folder-chevron", "›");
|
|
8449
|
+
chevron.setAttribute("aria-hidden", "true");
|
|
8450
|
+
summary.append(chevron, make("span", "git-side-panel-folder-name", node.name));
|
|
8451
|
+
const folderEntries = [];
|
|
8452
|
+
const collect = (current) => {
|
|
8453
|
+
folderEntries.push(...current.files);
|
|
8454
|
+
for (const child of current.folders.values()) collect(child);
|
|
8455
|
+
};
|
|
8456
|
+
collect(node);
|
|
8457
|
+
summary.append(make("span", "git-side-panel-folder-count", String(folderEntries.length)));
|
|
8458
|
+
bindGitPanelContextMenu(summary, { card, category, kind: "folder", path: node.path });
|
|
8459
|
+
details.append(summary);
|
|
8460
|
+
const body = make("div", "git-side-panel-folder-body");
|
|
8461
|
+
for (const child of [...node.folders.values()].sort((a, b) => a.name.localeCompare(b.name))) body.append(renderGitPanelFolder(child, card, category, depth + 1));
|
|
8462
|
+
for (const file of [...node.files].sort((a, b) => a.name.localeCompare(b.name))) body.append(renderGitPanelFile(file, card, category));
|
|
8463
|
+
details.append(body);
|
|
8464
|
+
return details;
|
|
8465
|
+
}
|
|
8466
|
+
|
|
8467
|
+
function renderGitPanelFile(entry, card, category) {
|
|
8468
|
+
const row = make("div", `git-side-panel-file ${category}`);
|
|
8469
|
+
const fullPath = entry.oldPath ? `${entry.oldPath} → ${entry.path}` : entry.path;
|
|
8470
|
+
row.title = `${fullPath} · Right-click for Git actions`;
|
|
8471
|
+
row.tabIndex = 0;
|
|
8472
|
+
row.setAttribute("aria-label", `${entry.name || entry.path}, ${gitPanelStatsText(entry, category) || "no line statistics"}`);
|
|
8473
|
+
const status = make("span", "git-side-panel-file-status", entry.status?.trim() || (entry.untracked ? "?" : "•"));
|
|
8474
|
+
const name = make("span", "git-side-panel-file-name", entry.name || entry.path);
|
|
8475
|
+
const statsText = gitPanelStatsText(entry, category);
|
|
8476
|
+
const stats = make("span", "git-side-panel-file-stats", statsText);
|
|
8477
|
+
stats.hidden = !statsText;
|
|
8478
|
+
bindGitPanelContextMenu(row, { card, category, kind: "file", path: entry.path });
|
|
8479
|
+
row.append(status, name, stats);
|
|
8480
|
+
return row;
|
|
8481
|
+
}
|
|
8482
|
+
|
|
8483
|
+
function renderGitPanelTreeSection(label, category, entries, card) {
|
|
8484
|
+
if (!entries.length) return null;
|
|
8485
|
+
const section = make("section", `git-side-panel-tree-section ${category}`);
|
|
8486
|
+
const heading = make("div", "git-side-panel-tree-heading");
|
|
8487
|
+
heading.append(make("strong", undefined, label), make("span", undefined, String(entries.length)));
|
|
8488
|
+
section.append(heading);
|
|
8489
|
+
const tree = gitPanelTree(entries);
|
|
8490
|
+
const body = make("div", "git-side-panel-tree", undefined);
|
|
8491
|
+
body.setAttribute("aria-label", `${label} files`);
|
|
8492
|
+
for (const folder of [...tree.folders.values()].sort((a, b) => a.name.localeCompare(b.name))) body.append(renderGitPanelFolder(folder, card, category));
|
|
8493
|
+
for (const file of [...tree.files].sort((a, b) => a.name.localeCompare(b.name))) body.append(renderGitPanelFile(file, card, category));
|
|
8494
|
+
section.append(body);
|
|
8495
|
+
return section;
|
|
8496
|
+
}
|
|
8497
|
+
|
|
8498
|
+
function renderGitPanelChanges(card, data) {
|
|
8499
|
+
const wrapper = make("div", "git-side-panel-changes");
|
|
8500
|
+
const changes = Array.isArray(data?.changes) ? data.changes : [];
|
|
8501
|
+
const categories = [
|
|
8502
|
+
["Conflicts", "conflicted", changes.filter((entry) => entry.conflicted)],
|
|
8503
|
+
["Staged", "staged", changes.filter((entry) => entry.staged && !entry.conflicted)],
|
|
8504
|
+
["Changes", "changes", changes.filter((entry) => entry.unstaged && !entry.untracked && !entry.conflicted)],
|
|
8505
|
+
["Untracked", "untracked", changes.filter((entry) => entry.untracked)],
|
|
8506
|
+
];
|
|
8507
|
+
for (const [label, category, entries] of categories) {
|
|
8508
|
+
const section = renderGitPanelTreeSection(label, category, entries, card);
|
|
8509
|
+
if (section) wrapper.append(section);
|
|
8510
|
+
}
|
|
8511
|
+
if (!changes.length) wrapper.append(make("p", "git-side-panel-empty success", "Working tree clean."));
|
|
8512
|
+
return wrapper;
|
|
8513
|
+
}
|
|
8514
|
+
|
|
8515
|
+
function gitPanelHistoryDate(value) {
|
|
8516
|
+
const date = new Date(value || "");
|
|
8517
|
+
return Number.isNaN(date.getTime()) ? String(value || "") : date.toLocaleString();
|
|
8518
|
+
}
|
|
8519
|
+
|
|
8520
|
+
function renderGitPanelHistory(card, data) {
|
|
8521
|
+
const wrapper = make("div", "git-side-panel-history");
|
|
8522
|
+
const history = Array.isArray(data?.history) ? data.history : [];
|
|
8523
|
+
if (!history.length) {
|
|
8524
|
+
wrapper.append(make("p", "git-side-panel-empty", "No commits yet."));
|
|
8525
|
+
return wrapper;
|
|
8526
|
+
}
|
|
8527
|
+
for (const commit of history) {
|
|
8528
|
+
const button = make("button", "git-side-panel-commit");
|
|
8529
|
+
button.type = "button";
|
|
8530
|
+
button.title = `View commit ${commit.hash}`;
|
|
8531
|
+
button.append(
|
|
8532
|
+
make("code", "git-side-panel-commit-hash", commit.shortHash || String(commit.hash || "").slice(0, 12)),
|
|
8533
|
+
make("span", "git-side-panel-commit-subject", commit.subject || "(no subject)"),
|
|
8534
|
+
make("span", "git-side-panel-commit-meta", [commit.author, gitPanelHistoryDate(commit.authoredAt)].filter(Boolean).join(" · ")),
|
|
8535
|
+
);
|
|
8536
|
+
button.addEventListener("click", () => openGitCommitDialog(card.tabId, commit));
|
|
8537
|
+
wrapper.append(button);
|
|
8538
|
+
}
|
|
8539
|
+
return wrapper;
|
|
8540
|
+
}
|
|
8541
|
+
|
|
8542
|
+
function renderGitPanelRepositoryContent(card, snapshot) {
|
|
8543
|
+
const content = make("div", "git-side-panel-repository-content");
|
|
8544
|
+
if (snapshot?.error) content.append(make("p", "git-side-panel-error", snapshot.error));
|
|
8545
|
+
if (snapshot?.loading && !snapshot?.data) {
|
|
8546
|
+
content.append(make("p", "git-side-panel-empty", "Loading local Git status and history…"));
|
|
8547
|
+
return content;
|
|
8548
|
+
}
|
|
8549
|
+
const data = snapshot?.data;
|
|
8550
|
+
if (!data) {
|
|
8551
|
+
content.append(make("p", "git-side-panel-empty", "Expand this repository to load Git status."));
|
|
8552
|
+
return content;
|
|
8553
|
+
}
|
|
8554
|
+
const tabs = make("div", "git-side-panel-tabs");
|
|
8555
|
+
tabs.setAttribute("role", "tablist");
|
|
8556
|
+
tabs.setAttribute("aria-label", `${gitPanelRootLabel(card.root)} repository view`);
|
|
8557
|
+
const views = ["changes", "history"];
|
|
8558
|
+
const activeView = gitPanelState.activeViews.get(card.root) || "changes";
|
|
8559
|
+
for (const view of views) {
|
|
8560
|
+
const label = view === "changes" ? `Changes (${gitPanelChangeCount(data)})` : `History (${data.history?.length || 0})`;
|
|
8561
|
+
const button = make("button", "git-side-panel-tab", label);
|
|
8562
|
+
button.id = `git-side-panel-${view}-tab`;
|
|
8563
|
+
button.type = "button";
|
|
8564
|
+
button.setAttribute("role", "tab");
|
|
8565
|
+
button.setAttribute("aria-controls", `git-side-panel-${view}-panel`);
|
|
8566
|
+
button.setAttribute("aria-selected", activeView === view ? "true" : "false");
|
|
8567
|
+
button.tabIndex = activeView === view ? 0 : -1;
|
|
8568
|
+
button.addEventListener("click", () => {
|
|
8569
|
+
gitPanelState.activeViews.set(card.root, view);
|
|
8570
|
+
renderGitPanel();
|
|
8571
|
+
});
|
|
8572
|
+
tabs.append(button);
|
|
8573
|
+
}
|
|
8574
|
+
tabs.addEventListener("keydown", (event) => {
|
|
8575
|
+
const currentIndex = views.indexOf(gitPanelState.activeViews.get(card.root) || "changes");
|
|
8576
|
+
let nextIndex = -1;
|
|
8577
|
+
if (event.key === "ArrowRight") nextIndex = (currentIndex + 1) % views.length;
|
|
8578
|
+
else if (event.key === "ArrowLeft") nextIndex = (currentIndex - 1 + views.length) % views.length;
|
|
8579
|
+
else if (event.key === "Home") nextIndex = 0;
|
|
8580
|
+
else if (event.key === "End") nextIndex = views.length - 1;
|
|
8581
|
+
if (nextIndex < 0) return;
|
|
8582
|
+
event.preventDefault();
|
|
8583
|
+
const nextView = views[nextIndex];
|
|
8584
|
+
gitPanelState.activeViews.set(card.root, nextView);
|
|
8585
|
+
renderGitPanel();
|
|
8586
|
+
queueMicrotask(() => document.getElementById(`git-side-panel-${nextView}-tab`)?.focus({ preventScroll: true }));
|
|
8587
|
+
});
|
|
8588
|
+
const meta = make("div", "git-side-panel-repository-meta");
|
|
8589
|
+
meta.append(
|
|
8590
|
+
make("strong", undefined, data.branch || "detached"),
|
|
8591
|
+
make("span", undefined, snapshot.loading ? "Refreshing…" : `Updated ${gitPanelHistoryDate(data.generatedAt)}`),
|
|
8592
|
+
);
|
|
8593
|
+
const changesPanel = renderGitPanelChanges(card, data);
|
|
8594
|
+
changesPanel.id = "git-side-panel-changes-panel";
|
|
8595
|
+
changesPanel.setAttribute("role", "tabpanel");
|
|
8596
|
+
changesPanel.setAttribute("aria-labelledby", "git-side-panel-changes-tab");
|
|
8597
|
+
changesPanel.hidden = activeView !== "changes";
|
|
8598
|
+
const historyPanel = renderGitPanelHistory(card, data);
|
|
8599
|
+
historyPanel.id = "git-side-panel-history-panel";
|
|
8600
|
+
historyPanel.setAttribute("role", "tabpanel");
|
|
8601
|
+
historyPanel.setAttribute("aria-labelledby", "git-side-panel-history-tab");
|
|
8602
|
+
historyPanel.hidden = activeView !== "history";
|
|
8603
|
+
content.append(tabs, meta, changesPanel, historyPanel);
|
|
8604
|
+
return content;
|
|
8605
|
+
}
|
|
8606
|
+
|
|
8607
|
+
function renderGitPanelRepositoryCard(card) {
|
|
8608
|
+
const discovery = card.discovery;
|
|
8609
|
+
if (!card.root) {
|
|
8610
|
+
const row = make("div", `git-side-panel-repository unavailable${discovery?.loading ? " loading" : ""}`);
|
|
8611
|
+
row.append(
|
|
8612
|
+
make("strong", undefined, gitPanelRootLabel(card.cwd, card.tabTitle)),
|
|
8613
|
+
make("span", "git-side-panel-repository-path", card.cwd),
|
|
8614
|
+
make("span", "git-side-panel-repository-state", discovery?.loading ? "Discovering repository…" : discovery?.error || "Waiting for repository discovery…"),
|
|
8615
|
+
);
|
|
8616
|
+
return row;
|
|
8617
|
+
}
|
|
8618
|
+
const snapshot = gitPanelSnapshot(card.root);
|
|
8619
|
+
const expanded = gitPanelState.expandedCardKey === card.key;
|
|
8620
|
+
const section = make("section", `git-side-panel-repository${expanded ? " expanded" : ""}`);
|
|
8621
|
+
const button = make("button", "git-side-panel-repository-toggle");
|
|
8622
|
+
button.type = "button";
|
|
8623
|
+
button.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
8624
|
+
button.title = `${expanded ? "Collapse" : "Expand"} ${card.root} · Right-click for repository actions`;
|
|
8625
|
+
const count = gitPanelChangeCount(snapshot?.data);
|
|
8626
|
+
button.append(
|
|
8627
|
+
make("span", "git-side-panel-repository-chevron", "›"),
|
|
8628
|
+
make("span", "git-side-panel-repository-copy", undefined),
|
|
8629
|
+
make("span", "git-side-panel-repository-count", String(count)),
|
|
8630
|
+
);
|
|
8631
|
+
const copy = button.querySelector(".git-side-panel-repository-copy");
|
|
8632
|
+
copy.append(make("strong", undefined, gitPanelRootLabel(card.root)), make("span", undefined, card.root));
|
|
8633
|
+
button.addEventListener("click", () => toggleGitPanelRepository(card));
|
|
8634
|
+
bindGitPanelContextMenu(button, { card, kind: "repository", path: card.root });
|
|
8635
|
+
section.append(button);
|
|
8636
|
+
if (expanded) section.append(renderGitPanelRepositoryContent(card, snapshot));
|
|
8637
|
+
return section;
|
|
8638
|
+
}
|
|
8639
|
+
|
|
8640
|
+
function renderGitPanel() {
|
|
8641
|
+
if (!elements.gitPanelGroups || !gitPanelSectionExpanded()) return;
|
|
8642
|
+
if (gitPanelContextMenuState && !elements.gitPanelContextMenu?.hidden) return;
|
|
8643
|
+
const groups = gitPanelTerminalGroups();
|
|
8644
|
+
const candidates = gitPanelCandidates(groups);
|
|
8645
|
+
const cards = gitPanelRepositoryCards(groups);
|
|
8646
|
+
const liveCandidateKeys = new Set(candidates.map((candidate) => candidate.key));
|
|
8647
|
+
const liveRoots = new Set(cards.map((card) => card.root).filter(Boolean));
|
|
8648
|
+
for (const key of [...gitPanelState.discovery.keys()]) if (!liveCandidateKeys.has(key)) gitPanelState.discovery.delete(key);
|
|
8649
|
+
for (const key of [...gitPanelState.activeViews.keys()]) if (!liveRoots.has(key)) gitPanelState.activeViews.delete(key);
|
|
8650
|
+
for (const key of [...gitPanelState.repositories.keys()]) if (!liveRoots.has(key)) gitPanelState.repositories.delete(key);
|
|
8651
|
+
for (const key of [...gitPanelState.openFolders.keys()]) if (!liveRoots.has(key.split("\u0000", 1)[0])) gitPanelState.openFolders.delete(key);
|
|
8652
|
+
const liveCardKeys = new Set(cards.filter((card) => card.root).map((card) => card.key));
|
|
8653
|
+
if (gitPanelState.expandedCardKey && !liveCardKeys.has(gitPanelState.expandedCardKey)) gitPanelState.expandedCardKey = "";
|
|
8654
|
+
closeGitPanelContextMenu({ returnFocus: false });
|
|
8655
|
+
const repositoryCount = cards.filter((card) => card.root).length;
|
|
8656
|
+
const discovering = [...gitPanelState.discovery.values()].some((entry) => entry.loading);
|
|
8657
|
+
const signature = JSON.stringify({
|
|
8658
|
+
expandedCardKey: gitPanelState.expandedCardKey,
|
|
8659
|
+
groups: groups.map((group) => [group.key, group.cwd, group.title, group.detail]),
|
|
8660
|
+
candidates: candidates.map((candidate) => {
|
|
8661
|
+
const discovery = gitPanelState.discovery.get(candidate.key);
|
|
8662
|
+
return [candidate.key, candidate.cwd, candidate.tabId, candidate.tabTitle, discovery?.root || "", !!discovery?.loading, discovery?.error || ""];
|
|
8663
|
+
}),
|
|
8664
|
+
cards: cards.map((card) => {
|
|
8665
|
+
const snapshot = gitPanelSnapshot(card.root);
|
|
8666
|
+
const data = snapshot?.data;
|
|
8667
|
+
return [card.key, card.root, card.cwd, card.tabId, snapshot?.loadedAt || 0, !!snapshot?.loading, snapshot?.error || "", gitPanelChangeCount(data), data?.history?.length || 0, data?.branch || "", data?.generatedAt || "", gitPanelState.activeViews.get(card.root) || "changes"];
|
|
8668
|
+
}),
|
|
8669
|
+
repositoryCount,
|
|
8670
|
+
discovering,
|
|
8671
|
+
});
|
|
8672
|
+
if (signature === gitPanelRenderSignature && elements.gitPanelGroups.childElementCount === cards.length) {
|
|
8673
|
+
ensureGitPanelRepositoriesDiscovered();
|
|
8674
|
+
return;
|
|
8675
|
+
}
|
|
8676
|
+
gitPanelRenderSignature = signature;
|
|
8677
|
+
elements.gitPanelGroups.replaceChildren(...cards.map(renderGitPanelRepositoryCard));
|
|
8678
|
+
if (elements.gitPanelCountBadge) {
|
|
8679
|
+
elements.gitPanelCountBadge.textContent = String(repositoryCount);
|
|
8680
|
+
elements.gitPanelCountBadge.hidden = repositoryCount === 0;
|
|
8681
|
+
}
|
|
8682
|
+
if (elements.gitPanelStatus) {
|
|
8683
|
+
elements.gitPanelStatus.textContent = !groups.length
|
|
8684
|
+
? "No terminal tabs are open."
|
|
8685
|
+
: discovering
|
|
8686
|
+
? "Discovering repositories…"
|
|
8687
|
+
: `${repositoryCount} Git ${repositoryCount === 1 ? "repository" : "repositories"} · Right-click for actions`;
|
|
8688
|
+
}
|
|
8689
|
+
ensureGitPanelRepositoriesDiscovered();
|
|
8690
|
+
}
|
|
8691
|
+
|
|
7999
8692
|
function tabAppRunnerRun(tab) {
|
|
8000
8693
|
if (!tab?.id) return null;
|
|
8001
8694
|
const cached = appRunnerDataByTab.get(tab.id);
|
|
@@ -8055,11 +8748,12 @@ function terminalTabMeta(tab, indicator) {
|
|
|
8055
8748
|
return parts.join(" · ");
|
|
8056
8749
|
}
|
|
8057
8750
|
|
|
8058
|
-
function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false, workflowModeActive = false, workflowCount = 0 }) {
|
|
8751
|
+
function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false, workflowModeActive = false, workflowCount = 0, subagent = false }) {
|
|
8059
8752
|
const titleRow = make("span", "terminal-tab-title-row");
|
|
8060
8753
|
const indicatorDot = make("span", "terminal-tab-activity-indicator");
|
|
8061
8754
|
indicatorDot.setAttribute("aria-hidden", "true");
|
|
8062
8755
|
titleRow.append(indicatorDot, make("span", "terminal-tab-title", title));
|
|
8756
|
+
if (subagent) titleRow.append(make("span", "terminal-tab-subagent-indicator", "subagent"));
|
|
8063
8757
|
if (appRunnerIsRunning(appRunnerRun)) titleRow.append(make("span", "terminal-tab-app-runner-indicator", "app"));
|
|
8064
8758
|
if (conversationModeActive) titleRow.append(make("span", "terminal-tab-conversation-indicator", "voice"));
|
|
8065
8759
|
if (workflowModeActive || workflowCount) titleRow.append(make("span", "terminal-tab-workflow-indicator", workflowCount ? `wf ${workflowCount}` : "wf"));
|
|
@@ -8068,7 +8762,7 @@ function appendTerminalTabContent(button, { title, indicator, meta, count = null
|
|
|
8068
8762
|
}
|
|
8069
8763
|
|
|
8070
8764
|
function renderTerminalTab(tab) {
|
|
8071
|
-
const isActive = tab.id === activeTabId;
|
|
8765
|
+
const isActive = tab.id === activeTabId && !activeSubagentTerminalId;
|
|
8072
8766
|
const indicator = tabIndicator(tab);
|
|
8073
8767
|
const appRunnerRun = tabAppRunnerRunningRun(tab);
|
|
8074
8768
|
const appRunnerLabel = appRunnerRun ? terminalAppRunnerLabel(appRunnerRun) : "";
|
|
@@ -8108,7 +8802,7 @@ function renderTerminalTab(tab) {
|
|
|
8108
8802
|
}
|
|
8109
8803
|
|
|
8110
8804
|
function renderTerminalTabGroupItem(tab, group) {
|
|
8111
|
-
const isActive = tab.id === activeTabId;
|
|
8805
|
+
const isActive = tab.id === activeTabId && !activeSubagentTerminalId;
|
|
8112
8806
|
const indicator = tabIndicator(tab);
|
|
8113
8807
|
const appRunnerRun = tabAppRunnerRunningRun(tab);
|
|
8114
8808
|
const appRunnerLabel = appRunnerRun ? terminalAppRunnerLabel(appRunnerRun) : "";
|
|
@@ -8158,7 +8852,7 @@ function shouldRenderTerminalTabGroup(group, groupCount) {
|
|
|
8158
8852
|
function renderTerminalTabGroup(group, groupCount = 1) {
|
|
8159
8853
|
const groupTabs = group.tabs;
|
|
8160
8854
|
const activeGroupTab = groupTabs.find((tab) => tab.id === activeTabId) || groupTabs[0];
|
|
8161
|
-
const isActive = groupTabs.some((tab) => tab.id === activeTabId);
|
|
8855
|
+
const isActive = !activeSubagentTerminalId && groupTabs.some((tab) => tab.id === activeTabId);
|
|
8162
8856
|
const isStopped = groupTabs.every((tab) => !tab.running);
|
|
8163
8857
|
const indicator = tabGroupIndicator(groupTabs);
|
|
8164
8858
|
const appRunnerRun = tabGroupAppRunnerRunningRun(groupTabs);
|
|
@@ -8301,15 +8995,18 @@ function scheduleTabsRender() {
|
|
|
8301
8995
|
|
|
8302
8996
|
function renderTabs() {
|
|
8303
8997
|
if (deferUiRenderDuringPointerActivation("tabs", renderTabs)) return;
|
|
8304
|
-
const
|
|
8305
|
-
const
|
|
8306
|
-
|
|
8307
|
-
const
|
|
8998
|
+
const activeSubagent = activeSubagentTerminalView();
|
|
8999
|
+
const active = activeSubagent || activeTab();
|
|
9000
|
+
const activeIndicator = activeSubagent ? { glyph: "◉", label: "Subagent view" } : active ? tabIndicator(active) : null;
|
|
9001
|
+
const activeTitle = activeSubagent ? subagentTerminalViewTitle(activeSubagent) : active?.title;
|
|
9002
|
+
const totalTabCount = tabs.length + subagentTerminalViews.size;
|
|
9003
|
+
elements.terminalTabsToggleButton.textContent = active ? `${activeIndicator.glyph} ${activeTitle}${totalTabCount > 1 ? ` · ${totalTabCount}` : ""}` : "Tabs";
|
|
9004
|
+
const toggleTooltip = active ? `Show terminal tabs · active: ${activeTitle} · ${activeIndicator.label}` : "Show terminal tabs";
|
|
8308
9005
|
applyStyledTooltip(elements.terminalTabsToggleButton, toggleTooltip, { ariaLabel: toggleTooltip });
|
|
8309
9006
|
if (footerTooltipTarget && elements.tabBar.contains(footerTooltipTarget)) hideFooterTooltip();
|
|
8310
9007
|
elements.tabBar.replaceChildren();
|
|
8311
|
-
elements.tabBar.dataset.tabCount = String(
|
|
8312
|
-
elements.tabBar.classList.toggle("terminal-tabs-dense",
|
|
9008
|
+
elements.tabBar.dataset.tabCount = String(totalTabCount);
|
|
9009
|
+
elements.tabBar.classList.toggle("terminal-tabs-dense", totalTabCount >= 10);
|
|
8313
9010
|
const groups = tabCwdGroups();
|
|
8314
9011
|
const renderedGroupKeys = new Set(groups.filter((group) => shouldRenderTerminalTabGroup(group, groups.length)).map((group) => group.key));
|
|
8315
9012
|
if (openTerminalTabGroupKey && !renderedGroupKeys.has(openTerminalTabGroupKey)) openTerminalTabGroupKey = null;
|
|
@@ -8320,6 +9017,9 @@ function renderTabs() {
|
|
|
8320
9017
|
for (const tab of group.tabs) elements.tabBar.append(renderTerminalTab(tab));
|
|
8321
9018
|
}
|
|
8322
9019
|
}
|
|
9020
|
+
for (const view of [...subagentTerminalViews.values()].sort((a, b) => a.openedAt - b.openedAt)) {
|
|
9021
|
+
elements.tabBar.append(renderSubagentTerminalTab(view));
|
|
9022
|
+
}
|
|
8323
9023
|
elements.tabBar.append(elements.newTabMenu);
|
|
8324
9024
|
elements.closeAllTabsButton.disabled = tabs.length === 0;
|
|
8325
9025
|
updateTerminalTabGroupOpenState();
|
|
@@ -8328,6 +9028,7 @@ function renderTabs() {
|
|
|
8328
9028
|
updateDocumentTitle();
|
|
8329
9029
|
renderWorkspaceDashboard();
|
|
8330
9030
|
renderContextMeter();
|
|
9031
|
+
renderGitPanel();
|
|
8331
9032
|
if (elements.commandPaletteDialog?.open) renderCommandPalette({ preserveScroll: true });
|
|
8332
9033
|
syncTabPolling();
|
|
8333
9034
|
}
|
|
@@ -8337,6 +9038,10 @@ async function refreshTabs({ selectStored = false } = {}) {
|
|
|
8337
9038
|
const response = await api("/api/tabs", { scoped: false });
|
|
8338
9039
|
tabs = response.data?.tabs || [];
|
|
8339
9040
|
syncTabMetadata(tabs);
|
|
9041
|
+
const liveParentTabIds = new Set(tabs.map((tab) => tab.id));
|
|
9042
|
+
for (const view of [...subagentTerminalViews.values()]) {
|
|
9043
|
+
if (!liveParentTabIds.has(view.parentTabId)) removeSubagentTerminalViewsForParent(view.parentTabId);
|
|
9044
|
+
}
|
|
8340
9045
|
syncBlockedTabNotificationsFromTabs(tabs, previousTabs);
|
|
8341
9046
|
syncAgentDoneNotificationsFromTabs(tabs, previousTabs);
|
|
8342
9047
|
const requested = selectStored ? requestedTabIdFromUrl() : null;
|
|
@@ -8351,7 +9056,12 @@ async function refreshTabs({ selectStored = false } = {}) {
|
|
|
8351
9056
|
}
|
|
8352
9057
|
|
|
8353
9058
|
async function switchTab(tabId) {
|
|
8354
|
-
if (!tabId ||
|
|
9059
|
+
if (!tabId || !tabs.some((tab) => tab.id === tabId)) return;
|
|
9060
|
+
if (tabId === activeTabId) {
|
|
9061
|
+
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ focusParent: true });
|
|
9062
|
+
return;
|
|
9063
|
+
}
|
|
9064
|
+
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ render: false });
|
|
8355
9065
|
clearOpenTerminalTabGroup(null, { force: true });
|
|
8356
9066
|
setMobileTabsExpanded(false);
|
|
8357
9067
|
footerModelPickerOpen = false;
|
|
@@ -8581,6 +9291,7 @@ async function closeTerminalTabs(tabIds, { label = "selected terminal tabs" } =
|
|
|
8581
9291
|
appRunnerDataByTab.delete(id);
|
|
8582
9292
|
tabMessagesCache.delete(id);
|
|
8583
9293
|
btwWidgetDismissedIdsByTab.delete(id);
|
|
9294
|
+
removeSubagentTerminalViewsForParent(id);
|
|
8584
9295
|
}
|
|
8585
9296
|
syncTerminalCustomGroupsWithTabs(tabs);
|
|
8586
9297
|
clearOpenTerminalTabGroup(null, { force: true });
|
|
@@ -10842,7 +11553,7 @@ function gitChangesFileActionsFor(sectionKey, path) {
|
|
|
10842
11553
|
...gitChangesCommonFileActions(path),
|
|
10843
11554
|
];
|
|
10844
11555
|
}
|
|
10845
|
-
if (sectionKey === "incoming") return [{ label: "Copy path", title: "Copy the repo-relative path", onClick: () => copyGitPathToClipboard(path) }];
|
|
11556
|
+
if (sectionKey === "incoming" || sectionKey === "commit") return [{ label: "Copy path", title: "Copy the repo-relative path", onClick: () => copyGitPathToClipboard(path) }];
|
|
10846
11557
|
return [];
|
|
10847
11558
|
}
|
|
10848
11559
|
|
|
@@ -11226,28 +11937,34 @@ function renderGitPullResultPanel(result) {
|
|
|
11226
11937
|
|
|
11227
11938
|
function renderGitChangesDialog() {
|
|
11228
11939
|
if (!elements.gitChangesDialog || !elements.gitChangesBody) return;
|
|
11229
|
-
const { loading, pulling, fetching, error, message, pullResult, data, operation } = gitChangesState;
|
|
11940
|
+
const { loading, pulling, fetching, error, message, pullResult, data, operation, mode, commit } = gitChangesState;
|
|
11941
|
+
const commitView = mode === "commit";
|
|
11230
11942
|
const busyAction = pulling || fetching;
|
|
11231
11943
|
const behind = Number(data?.remote?.behind ?? data?.summary?.behind ?? 0) || 0;
|
|
11232
11944
|
const diverged = data?.remote?.diverged === true;
|
|
11233
11945
|
const canPull = behind > 0 && data?.remote?.canPull !== false && !diverged;
|
|
11234
|
-
const hasOperation = Boolean(operation?.operation);
|
|
11235
|
-
const remoteNotice = !error && data?.remote?.error ? `Incoming diff unavailable: ${data.remote.error}` : "";
|
|
11236
|
-
if (elements.gitChangesTitle) elements.gitChangesTitle.textContent = "Git Changes";
|
|
11946
|
+
const hasOperation = !commitView && Boolean(operation?.operation);
|
|
11947
|
+
const remoteNotice = !commitView && !error && data?.remote?.error ? `Incoming diff unavailable: ${data.remote.error}` : "";
|
|
11948
|
+
if (elements.gitChangesTitle) elements.gitChangesTitle.textContent = commitView ? "Git Commit" : "Git Changes";
|
|
11237
11949
|
if (elements.gitChangesSubtitle) {
|
|
11238
|
-
const
|
|
11239
|
-
|
|
11950
|
+
const commitData = data?.commit || commit;
|
|
11951
|
+
const base = commitView
|
|
11952
|
+
? [commitData?.shortHash || String(commitData?.hash || "").slice(0, 12), commitData?.subject, data?.root].filter(Boolean).join(" · ") || "Commit diff"
|
|
11953
|
+
: data?.root ? `${data.branch || "detached"} · ${data.root}` : "Current tab git diff";
|
|
11954
|
+
elements.gitChangesSubtitle.textContent = !commitView && data?.remote?.upstream ? `${base} · upstream ${data.remote.upstream}` : base;
|
|
11240
11955
|
}
|
|
11241
11956
|
if (elements.gitChangesRefreshButton) {
|
|
11242
11957
|
elements.gitChangesRefreshButton.disabled = loading || busyAction;
|
|
11243
|
-
elements.gitChangesRefreshButton.textContent = loading ? "Refreshing…" : "Refresh";
|
|
11958
|
+
elements.gitChangesRefreshButton.textContent = loading ? "Refreshing…" : commitView ? "Reload" : "Refresh";
|
|
11244
11959
|
}
|
|
11245
11960
|
if (elements.gitChangesFetchButton) {
|
|
11961
|
+
elements.gitChangesFetchButton.hidden = commitView;
|
|
11246
11962
|
elements.gitChangesFetchButton.disabled = loading || busyAction || !data?.root;
|
|
11247
11963
|
elements.gitChangesFetchButton.textContent = fetching ? "Fetching…" : "Fetch";
|
|
11248
11964
|
elements.gitChangesFetchButton.title = "Run git fetch --prune to refresh remote tracking state";
|
|
11249
11965
|
}
|
|
11250
11966
|
if (elements.gitChangesPullButton) {
|
|
11967
|
+
elements.gitChangesPullButton.hidden = commitView;
|
|
11251
11968
|
elements.gitChangesPullButton.disabled = loading || busyAction || !canPull;
|
|
11252
11969
|
elements.gitChangesPullButton.textContent = pulling ? "Pulling…" : behind > 0 ? `Pull ↓${behind}` : "Pull";
|
|
11253
11970
|
elements.gitChangesPullButton.title = canPull
|
|
@@ -11257,7 +11974,7 @@ function renderGitChangesDialog() {
|
|
|
11257
11974
|
: "No remote commits to pull";
|
|
11258
11975
|
}
|
|
11259
11976
|
if (elements.gitChangesStatus) {
|
|
11260
|
-
const statusText = error || (pulling ? "Pulling changes…" : fetching ? "Fetching from remote…" : loading ?
|
|
11977
|
+
const statusText = error || (pulling ? "Pulling changes…" : fetching ? "Fetching from remote…" : loading ? `Loading ${commitView ? "commit" : "git"} diff…` : message || remoteNotice || (data ? gitChangesGeneratedLabel(data) : ""));
|
|
11261
11978
|
elements.gitChangesStatus.className = `git-changes-status ${error || remoteNotice ? "error" : message ? "success" : "muted"}`;
|
|
11262
11979
|
elements.gitChangesStatus.textContent = statusText;
|
|
11263
11980
|
elements.gitChangesStatus.hidden = !elements.gitChangesStatus.textContent;
|
|
@@ -11278,19 +11995,21 @@ function renderGitChangesDialog() {
|
|
|
11278
11995
|
return;
|
|
11279
11996
|
}
|
|
11280
11997
|
|
|
11281
|
-
if (pullResult) body.append(renderGitPullResultPanel(pullResult));
|
|
11998
|
+
if (pullResult && !commitView) body.append(renderGitPullResultPanel(pullResult));
|
|
11282
11999
|
if (hasOperation) {
|
|
11283
12000
|
const panel = renderGitOperationPanel(operation);
|
|
11284
12001
|
if (panel) body.append(panel);
|
|
11285
12002
|
}
|
|
11286
|
-
|
|
11287
|
-
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
|
|
12003
|
+
if (!commitView) {
|
|
12004
|
+
body.append(renderGitChangesOverview(data));
|
|
12005
|
+
const fetchStateLines = gitChangesFetchStateLines();
|
|
12006
|
+
if (fetchStateLines.length) {
|
|
12007
|
+
const fetchNote = make("div", "git-tools-note git-fetch-state-note");
|
|
12008
|
+
for (const line of fetchStateLines) fetchNote.append(make("div", undefined, line));
|
|
12009
|
+
body.append(fetchNote);
|
|
12010
|
+
}
|
|
12011
|
+
if (diverged && !hasOperation) body.append(renderGitDivergedBar(data));
|
|
11292
12012
|
}
|
|
11293
|
-
if (diverged && !hasOperation) body.append(renderGitDivergedBar(data));
|
|
11294
12013
|
const parsedSections = (Array.isArray(data.sections) ? data.sections : [])
|
|
11295
12014
|
.map((section) => ({ section, files: parseGitUnifiedDiff(section.diff || "") }))
|
|
11296
12015
|
.filter((entry) => entry.files.length > 0);
|
|
@@ -11307,14 +12026,14 @@ function renderGitChangesDialog() {
|
|
|
11307
12026
|
const emptyMessage = behind > 0 ? "No textual incoming diff was available for the remote commits." : "Working tree is clean. No staged, unstaged, untracked, or incoming diff.";
|
|
11308
12027
|
body.append(make("div", "git-changes-empty success", emptyMessage));
|
|
11309
12028
|
}
|
|
11310
|
-
body.append(renderGitToolsSection());
|
|
12029
|
+
if (!commitView) body.append(renderGitToolsSection());
|
|
11311
12030
|
if (hasVisibleFiles) requestAnimationFrame(updateGitChangesCurrentFileHeader);
|
|
11312
12031
|
}
|
|
11313
12032
|
|
|
11314
12033
|
async function loadGitChangesDialog(tabContext = activeTabContext()) {
|
|
11315
12034
|
const requestSerial = ++gitChangesRequestSerial;
|
|
11316
12035
|
gitChangesUntrackedContentRequests.clear();
|
|
11317
|
-
gitChangesState = { ...gitChangesState, loading: true, error: "", errorCode: "", errorHint: "", message: "", pullResult: null, tabId: tabContext.tabId || activeTabId };
|
|
12036
|
+
gitChangesState = { ...gitChangesState, loading: true, error: "", errorCode: "", errorHint: "", message: "", pullResult: null, tabId: tabContext.tabId || activeTabId, mode: "changes", commit: null };
|
|
11318
12037
|
renderGitChangesDialog();
|
|
11319
12038
|
try {
|
|
11320
12039
|
const [response, operationResponse] = await Promise.all([
|
|
@@ -11344,10 +12063,10 @@ async function loadGitChangesDialog(tabContext = activeTabContext()) {
|
|
|
11344
12063
|
renderGitChangesDialog();
|
|
11345
12064
|
}
|
|
11346
12065
|
|
|
11347
|
-
function openGitChangesDialog() {
|
|
12066
|
+
function openGitChangesDialog(requestedTabId = activeTabId) {
|
|
11348
12067
|
if (!elements.gitChangesDialog) return;
|
|
11349
12068
|
hideFooterTooltip();
|
|
11350
|
-
const tabContext = activeTabContext();
|
|
12069
|
+
const tabContext = activeTabContext(requestedTabId);
|
|
11351
12070
|
const tabId = tabContext.tabId || activeTabId;
|
|
11352
12071
|
if (gitToolsState.tabId !== tabId) resetGitToolsState(tabId);
|
|
11353
12072
|
gitChangesState = {
|
|
@@ -11364,15 +12083,47 @@ function openGitChangesDialog() {
|
|
|
11364
12083
|
operation: gitChangesState.tabId === tabId ? gitChangesState.operation : null,
|
|
11365
12084
|
lastFetch: gitChangesState.tabId === tabId ? gitChangesState.lastFetch : null,
|
|
11366
12085
|
tabId,
|
|
12086
|
+
mode: "changes",
|
|
12087
|
+
commit: null,
|
|
11367
12088
|
};
|
|
11368
12089
|
renderGitChangesDialog();
|
|
11369
12090
|
if (!elements.gitChangesDialog.open) elements.gitChangesDialog.showModal();
|
|
11370
12091
|
loadGitChangesDialog(tabContext).catch((error) => addEvent(error.message || String(error), "error"));
|
|
11371
12092
|
}
|
|
11372
12093
|
|
|
12094
|
+
async function loadGitCommitDialog(tabId, commit) {
|
|
12095
|
+
const requestSerial = ++gitChangesRequestSerial;
|
|
12096
|
+
const hash = String(commit?.hash || "");
|
|
12097
|
+
gitChangesState = { ...gitChangesState, loading: true, error: "", message: "", data: null, operation: null, tabId, mode: "commit", commit };
|
|
12098
|
+
renderGitChangesDialog();
|
|
12099
|
+
try {
|
|
12100
|
+
const response = await api(`/api/git-commit?hash=${encodeURIComponent(hash)}`, { tabId });
|
|
12101
|
+
if (requestSerial !== gitChangesRequestSerial) return;
|
|
12102
|
+
if (!response.ok) throw new Error(response.error || "Failed to load Git commit");
|
|
12103
|
+
gitChangesState = { ...gitChangesState, loading: false, error: "", data: response.data || null, tabId, mode: "commit", commit: response.data?.commit || commit };
|
|
12104
|
+
} catch (error) {
|
|
12105
|
+
if (requestSerial !== gitChangesRequestSerial) return;
|
|
12106
|
+
gitChangesState = { ...gitChangesState, loading: false, error: error.message || String(error), tabId, mode: "commit", commit };
|
|
12107
|
+
}
|
|
12108
|
+
renderGitChangesDialog();
|
|
12109
|
+
}
|
|
12110
|
+
|
|
12111
|
+
function openGitCommitDialog(tabId, commit) {
|
|
12112
|
+
if (!elements.gitChangesDialog || !tabId || !commit?.hash) return;
|
|
12113
|
+
hideFooterTooltip();
|
|
12114
|
+
gitChangesState = { ...gitChangesState, loading: true, pulling: false, fetching: false, error: "", message: "", data: null, operation: null, tabId, mode: "commit", commit };
|
|
12115
|
+
renderGitChangesDialog();
|
|
12116
|
+
if (!elements.gitChangesDialog.open) elements.gitChangesDialog.showModal();
|
|
12117
|
+
loadGitCommitDialog(tabId, commit).catch((error) => addEvent(error.message || String(error), "error"));
|
|
12118
|
+
}
|
|
12119
|
+
|
|
11373
12120
|
function refreshGitChangesDialog() {
|
|
11374
|
-
const
|
|
11375
|
-
|
|
12121
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
12122
|
+
if (gitChangesState.mode === "commit" && gitChangesState.commit?.hash) {
|
|
12123
|
+
loadGitCommitDialog(tabId, gitChangesState.commit).catch((error) => addEvent(error.message || String(error), "error"));
|
|
12124
|
+
return;
|
|
12125
|
+
}
|
|
12126
|
+
loadGitChangesDialog({ tabId }).catch((error) => addEvent(error.message || String(error), "error"));
|
|
11376
12127
|
}
|
|
11377
12128
|
|
|
11378
12129
|
async function pullGitChangesDialog() {
|
|
@@ -12303,20 +13054,29 @@ async function requestManualCompaction({ triggerButton = null } = {}) {
|
|
|
12303
13054
|
}
|
|
12304
13055
|
}
|
|
12305
13056
|
|
|
13057
|
+
let contextMeterSignature = null;
|
|
13058
|
+
|
|
12306
13059
|
function renderContextMeter() {
|
|
12307
13060
|
if (deferUiRenderDuringPointerActivation("context-meter", renderContextMeter)) return;
|
|
12308
13061
|
const root = elements.contextMeterBar;
|
|
12309
13062
|
if (!root) return;
|
|
12310
13063
|
const tab = activeTab();
|
|
12311
|
-
if (!tab) {
|
|
12312
|
-
root.hidden = true;
|
|
12313
|
-
root.replaceChildren();
|
|
12314
|
-
return;
|
|
12315
|
-
}
|
|
12316
|
-
root.hidden = false;
|
|
12317
13064
|
const snapshot = contextUsageSnapshot();
|
|
12318
|
-
|
|
12319
|
-
|
|
13065
|
+
const visible = Boolean(tab && snapshot && typeof snapshot.percent === "number" && snapshot.percent > 50);
|
|
13066
|
+
const autoCompactionEnabled = footerAutoCompactionEnabled();
|
|
13067
|
+
const signature = JSON.stringify({
|
|
13068
|
+
tabId: tab?.id || "",
|
|
13069
|
+
visible,
|
|
13070
|
+
snapshot,
|
|
13071
|
+
isCompacting: !!currentState?.isCompacting,
|
|
13072
|
+
autoCompactionEnabled,
|
|
13073
|
+
autoCompactionToggleInFlight: footerAutoCompactionToggleInFlight,
|
|
13074
|
+
theme: [currentThemeName, effectiveScheme()],
|
|
13075
|
+
});
|
|
13076
|
+
if (signature === contextMeterSignature && root.hidden === !visible && (!visible || root.childElementCount > 0)) return;
|
|
13077
|
+
contextMeterSignature = signature;
|
|
13078
|
+
root.hidden = !visible;
|
|
13079
|
+
if (!visible) {
|
|
12320
13080
|
root.replaceChildren();
|
|
12321
13081
|
return;
|
|
12322
13082
|
}
|
|
@@ -12335,9 +13095,9 @@ function renderContextMeter() {
|
|
|
12335
13095
|
compact.disabled = !!currentState?.isCompacting;
|
|
12336
13096
|
compact.title = "Manually compact this tab's conversation context";
|
|
12337
13097
|
compact.addEventListener("click", () => requestManualCompaction({ triggerButton: compact }));
|
|
12338
|
-
const auto = make("button", "context-meter-auto",
|
|
13098
|
+
const auto = make("button", "context-meter-auto", autoCompactionEnabled ? "Auto on" : "Auto off");
|
|
12339
13099
|
auto.type = "button";
|
|
12340
|
-
auto.setAttribute("aria-pressed",
|
|
13100
|
+
auto.setAttribute("aria-pressed", autoCompactionEnabled ? "true" : "false");
|
|
12341
13101
|
auto.disabled = footerAutoCompactionToggleInFlight;
|
|
12342
13102
|
auto.title = footerAutoCompactionToggleInFlight ? "Updating auto-compaction…" : footerAutoCompactionToggleAction();
|
|
12343
13103
|
auto.addEventListener("click", () => toggleFooterAutoCompaction());
|
|
@@ -12450,11 +13210,14 @@ function renderWorkspaceDashboard() {
|
|
|
12450
13210
|
queueCount,
|
|
12451
13211
|
modelLabel,
|
|
12452
13212
|
modelTitle: currentState?.model ? shortModelLabel(currentState.model) : "Model loading…",
|
|
13213
|
+
hasModel: !!currentState?.model,
|
|
12453
13214
|
thinking: currentState?.thinkingLevel || "",
|
|
12454
|
-
context: { display: contextUsageDisplay(snapshot), detail: contextUsageDetail(snapshot), tone: contextDashboardTone(snapshot) },
|
|
13215
|
+
context: { snapshot, display: contextUsageDisplay(snapshot), detail: contextUsageDetail(snapshot), tone: contextDashboardTone(snapshot) },
|
|
13216
|
+
theme: [currentThemeName, effectiveScheme()],
|
|
12455
13217
|
session: sessionSummary,
|
|
13218
|
+
hasSession: !!(currentState?.sessionId || currentState?.sessionName),
|
|
12456
13219
|
activeTabId,
|
|
12457
|
-
tabs: tabs.slice(0, 8).map((item) => ({ id: item.id, title: item.title,
|
|
13220
|
+
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) : "" })),
|
|
12458
13221
|
overflow: tabs.length > 8 ? tabs.length - 8 : 0,
|
|
12459
13222
|
});
|
|
12460
13223
|
if (signature === workspaceDashboardSignature && root.childElementCount > 0) return;
|
|
@@ -12851,8 +13614,8 @@ function footerBranchCreateWorktreePathPreview(branch = footerBranchCreateName()
|
|
|
12851
13614
|
return `${root.replace(/\/+$/, "")}/${slugifyWorktreePathPart(branch || footerBranchCreatePreviewName())}`;
|
|
12852
13615
|
}
|
|
12853
13616
|
|
|
12854
|
-
function gitWorktreeCreateCommandDisplay(branch, state = footerBranchPickerState) {
|
|
12855
|
-
return `git worktree add -b ${quoteGitBranchForDisplay(branch)} ${quoteGitBranchForDisplay(footerBranchCreateWorktreePathPreview(branch, state))}`;
|
|
13617
|
+
function gitWorktreeCreateCommandDisplay(branch, state = footerBranchPickerState, baseRef = "origin/main") {
|
|
13618
|
+
return `git worktree add -b ${quoteGitBranchForDisplay(branch)} ${quoteGitBranchForDisplay(footerBranchCreateWorktreePathPreview(branch, state))} ${quoteGitBranchForDisplay(baseRef)}`;
|
|
12856
13619
|
}
|
|
12857
13620
|
|
|
12858
13621
|
function gitWorktreeOpenCommandDisplay(path) {
|
|
@@ -12868,7 +13631,7 @@ function footerBranchCreateTooltip(branchName = footerBranchCreateName(), state
|
|
|
12868
13631
|
`This will run roughly: ${command}`,
|
|
12869
13632
|
"",
|
|
12870
13633
|
"What happens:",
|
|
12871
|
-
"•
|
|
13634
|
+
"• asks whether to base the new branch on origin/main (default) or this workspace's current HEAD",
|
|
12872
13635
|
"• opens a separate Pi tab rooted at that worktree",
|
|
12873
13636
|
"• does not switch this tab's branch, commit, push, or delete anything",
|
|
12874
13637
|
"",
|
|
@@ -12910,18 +13673,20 @@ async function openWorktreeResponseTab(response, { branchName = "", action = "op
|
|
|
12910
13673
|
requestGitFooterWebuiPayload(activeTabContext(), { force: true });
|
|
12911
13674
|
}
|
|
12912
13675
|
|
|
12913
|
-
async function createFooterGitBranchWorktree(branch = footerBranchCreateName(), { tabContext = activeTabContext(), skipConfirm = false } = {}) {
|
|
13676
|
+
async function createFooterGitBranchWorktree(branch = footerBranchCreateName(), { tabContext = activeTabContext(), skipConfirm = false, chooseBase = true } = {}) {
|
|
12914
13677
|
const branchName = cleanStatusText(branch);
|
|
12915
13678
|
if (!branchName) {
|
|
12916
13679
|
addEvent("Enter a branch name before creating a branch worktree.", "warn");
|
|
12917
13680
|
return;
|
|
12918
13681
|
}
|
|
12919
13682
|
if (!skipConfirm && !(await confirmFooterGitWorktreeAction(branchName, { create: true, requireConfirm: true }))) return;
|
|
13683
|
+
const baseRef = chooseBase ? await chooseGitWorktreeBase(branchName) : "HEAD";
|
|
13684
|
+
if (baseRef === null) return;
|
|
12920
13685
|
const tabId = tabContext.tabId || activeTabId;
|
|
12921
13686
|
try {
|
|
12922
13687
|
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: branchName, tabId };
|
|
12923
13688
|
renderFooter();
|
|
12924
|
-
const response = await api("/api/git-worktrees", { method: "POST", body: { branchName, sessionMode: "fork-current", openTab: true }, tabId });
|
|
13689
|
+
const response = await api("/api/git-worktrees", { method: "POST", body: { branchName, baseRef, sessionMode: "fork-current", openTab: true }, tabId });
|
|
12925
13690
|
await openWorktreeResponseTab(response, { branchName, action: "create" });
|
|
12926
13691
|
} catch (error) {
|
|
12927
13692
|
if (isCurrentTabContext(tabContext)) {
|
|
@@ -13120,7 +13885,7 @@ function footerBranchOptionDetail(branch, state, { selected, worktreePath } = {}
|
|
|
13120
13885
|
function openFooterBranchOption(branch, state = footerBranchPickerState) {
|
|
13121
13886
|
const worktreePath = footerBranchWorktreePath(branch, state);
|
|
13122
13887
|
if (worktreePath && !branch.worktreeCurrent) return openFooterGitWorktree(worktreePath, { branchName: branch.name, skipConfirm: true });
|
|
13123
|
-
return createFooterGitBranchWorktree(branch.name, { skipConfirm: true });
|
|
13888
|
+
return createFooterGitBranchWorktree(branch.name, { skipConfirm: true, chooseBase: false });
|
|
13124
13889
|
}
|
|
13125
13890
|
|
|
13126
13891
|
function renderFooterBranchOption(branch, state = footerBranchPickerState) {
|
|
@@ -13275,7 +14040,7 @@ function renderFooterBranchPicker() {
|
|
|
13275
14040
|
const hasOtherBranches = state.branches.some((branch) => !branch.current && branch.name !== state.current);
|
|
13276
14041
|
if (!state.loading && !hasOtherBranches) {
|
|
13277
14042
|
const empty = make("div", "footer-model-picker-empty muted");
|
|
13278
|
-
empty.append(make("strong", undefined, "No other local branches available."), make("span", undefined, " Create a branch worktree from the current HEAD to continue."));
|
|
14043
|
+
empty.append(make("strong", undefined, "No other local branches available."), make("span", undefined, " Create a branch worktree from origin/main or the current workspace HEAD to continue."));
|
|
13279
14044
|
picker.append(empty);
|
|
13280
14045
|
}
|
|
13281
14046
|
|
|
@@ -14315,7 +15080,7 @@ function initializeClaudeUsage() {
|
|
|
14315
15080
|
|
|
14316
15081
|
function subagentTabsWithRunningAgents() {
|
|
14317
15082
|
return (Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : [])
|
|
14318
|
-
.filter((tab) => Number(tab?.agentCount || 0) > 0)
|
|
15083
|
+
.filter((tab) => Number(tab?.agentCount || 0) > 0 || Number(tab?.gateCount || 0) > 0)
|
|
14319
15084
|
.sort((a, b) => Number(a.tabIndex || 0) - Number(b.tabIndex || 0) || String(a.tabTitle || "").localeCompare(String(b.tabTitle || "")));
|
|
14320
15085
|
}
|
|
14321
15086
|
|
|
@@ -14335,6 +15100,16 @@ function subagentRunElapsed(run) {
|
|
|
14335
15100
|
return Number.isFinite(startedAt) ? formatDuration(Math.max(0, Date.now() - startedAt)) : "";
|
|
14336
15101
|
}
|
|
14337
15102
|
|
|
15103
|
+
function subagentExecutionFacts(agent = {}) {
|
|
15104
|
+
const thinking = String(agent?.thinking || "").trim();
|
|
15105
|
+
let model = String(agent?.model || "").trim();
|
|
15106
|
+
const suffixIndex = model.lastIndexOf(":");
|
|
15107
|
+
if (thinking && suffixIndex > model.indexOf("/") && model.slice(suffixIndex + 1).toLowerCase() === thinking.toLowerCase()) {
|
|
15108
|
+
model = model.slice(0, suffixIndex);
|
|
15109
|
+
}
|
|
15110
|
+
return [`model ${model || "unknown"}`, `reasoning ${thinking || "unknown"}`];
|
|
15111
|
+
}
|
|
15112
|
+
|
|
14338
15113
|
function subagentOverlayTranscriptMessages(data = subagentOverlayData) {
|
|
14339
15114
|
const agent = data?.agent || subagentOverlaySelection?.agent || {};
|
|
14340
15115
|
return (Array.isArray(agent.transcript) ? agent.transcript : [])
|
|
@@ -14412,20 +15187,42 @@ function subagentOverlayEmptyTranscriptText(messages) {
|
|
|
14412
15187
|
: "No visible output was captured.";
|
|
14413
15188
|
}
|
|
14414
15189
|
|
|
14415
|
-
function
|
|
14416
|
-
const
|
|
15190
|
+
function subagentRunIndicatorActivity(agent = {}) {
|
|
15191
|
+
const currentTool = cleanStatusText(agent.currentTool || "");
|
|
15192
|
+
const currentToolArgs = cleanStatusText(agent.currentToolArgs || "");
|
|
15193
|
+
const activityState = cleanStatusText(agent.activityState || "");
|
|
15194
|
+
return currentTool
|
|
15195
|
+
? `${currentTool}${currentToolArgs ? ` · ${currentToolArgs}` : ""}`
|
|
15196
|
+
: activityState || "Waiting for output or action…";
|
|
15197
|
+
}
|
|
15198
|
+
|
|
15199
|
+
function updateSubagentRunIndicatorElapsed(parent, run) {
|
|
15200
|
+
const elapsedNode = parent?.querySelector?.(".subagent-run-indicator-elapsed");
|
|
15201
|
+
if (!elapsedNode) return false;
|
|
15202
|
+
const elapsed = subagentRunElapsed(run);
|
|
15203
|
+
const text = elapsed ? `· run time ${elapsed}` : "";
|
|
15204
|
+
if (elapsedNode.textContent !== text) elapsedNode.textContent = text;
|
|
15205
|
+
return true;
|
|
15206
|
+
}
|
|
15207
|
+
|
|
15208
|
+
function appendSubagentRunIndicator(parent, { agent = {}, run } = {}) {
|
|
15209
|
+
const bubble = make("article", "message runIndicator run-indicator-message streaming subagent-run-indicator");
|
|
14417
15210
|
bubble.setAttribute("role", "status");
|
|
14418
|
-
bubble.setAttribute("aria-
|
|
15211
|
+
bubble.setAttribute("aria-live", "polite");
|
|
15212
|
+
bubble.setAttribute("aria-label", "Agent is running:");
|
|
14419
15213
|
const body = make("div", "message-body");
|
|
14420
15214
|
const row = make("div", "run-indicator-row");
|
|
14421
|
-
|
|
14422
|
-
|
|
14423
|
-
|
|
14424
|
-
|
|
14425
|
-
);
|
|
15215
|
+
const pulse = make("span", "run-indicator-pulse");
|
|
15216
|
+
pulse.setAttribute("aria-hidden", "true");
|
|
15217
|
+
const headline = make("span", "run-indicator-text", "Agent is running:");
|
|
15218
|
+
const activity = make("span", "run-indicator-meta", subagentRunIndicatorActivity(agent));
|
|
15219
|
+
const elapsed = make("span", "run-indicator-meta subagent-run-indicator-elapsed");
|
|
15220
|
+
elapsed.setAttribute("aria-hidden", "true");
|
|
15221
|
+
row.append(pulse, headline, activity, elapsed);
|
|
14426
15222
|
body.append(row);
|
|
14427
15223
|
bubble.append(body);
|
|
14428
15224
|
parent.append(bubble);
|
|
15225
|
+
updateSubagentRunIndicatorElapsed(parent, run);
|
|
14429
15226
|
}
|
|
14430
15227
|
|
|
14431
15228
|
function appendSubagentOverlayTranscript(parent, messages) {
|
|
@@ -14446,6 +15243,7 @@ function subagentOverlayStateFacts(data = subagentOverlayData) {
|
|
|
14446
15243
|
data?.mode || subagentOverlaySelection?.run?.mode,
|
|
14447
15244
|
data?.source || subagentOverlaySelection?.run?.source,
|
|
14448
15245
|
agent.nested ? "nested" : "",
|
|
15246
|
+
...subagentExecutionFacts(agent),
|
|
14449
15247
|
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
14450
15248
|
Number.isFinite(agent.turnCount) ? `${agent.turnCount} turns` : "",
|
|
14451
15249
|
Number.isFinite(agent.toolCount) ? `${agent.toolCount} tools` : "",
|
|
@@ -14534,7 +15332,7 @@ function renderSubagentOverlayWidget() {
|
|
|
14534
15332
|
bubble.classList.add("subagent-overlay-message", "subagent-overlay-empty-fallback");
|
|
14535
15333
|
output.append(bubble);
|
|
14536
15334
|
}
|
|
14537
|
-
if (running
|
|
15335
|
+
if (running) appendSubagentRunIndicator(output, { agent, run: selection.run });
|
|
14538
15336
|
|
|
14539
15337
|
const controls = make("div", "release-npm-controls subagent-overlay-output-controls");
|
|
14540
15338
|
const actions = make("div", "app-runner-output-actions");
|
|
@@ -14595,6 +15393,7 @@ async function refreshSubagentOverlay() {
|
|
|
14595
15393
|
|
|
14596
15394
|
async function openSubagentOverlay(tab, run, agent) {
|
|
14597
15395
|
if (!tab?.tabId || !run?.id || !agent?.id) return;
|
|
15396
|
+
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ render: false });
|
|
14598
15397
|
try {
|
|
14599
15398
|
if (activeTabId !== tab.tabId) await switchTab(tab.tabId);
|
|
14600
15399
|
subagentOverlaySelection = {
|
|
@@ -14643,6 +15442,276 @@ async function copySubagentOverlayOutput() {
|
|
|
14643
15442
|
}
|
|
14644
15443
|
}
|
|
14645
15444
|
|
|
15445
|
+
function subagentTerminalViewId(tab, run, agent) {
|
|
15446
|
+
return JSON.stringify([tab?.tabId || "", run?.id || "", agent?.id || ""]);
|
|
15447
|
+
}
|
|
15448
|
+
|
|
15449
|
+
function activeSubagentTerminalView() {
|
|
15450
|
+
return activeSubagentTerminalId ? subagentTerminalViews.get(activeSubagentTerminalId) || null : null;
|
|
15451
|
+
}
|
|
15452
|
+
|
|
15453
|
+
function subagentTerminalViewTitle(view) {
|
|
15454
|
+
return String(view?.data?.agent?.name || view?.agent?.name || "subagent").trim() || "subagent";
|
|
15455
|
+
}
|
|
15456
|
+
|
|
15457
|
+
function subagentTerminalViewIsRunning(view) {
|
|
15458
|
+
const status = view?.data?.agent?.status || view?.agent?.status || "running";
|
|
15459
|
+
return view?.finished !== true && ["running", "queued", "pending"].includes(status);
|
|
15460
|
+
}
|
|
15461
|
+
|
|
15462
|
+
function subagentTerminalViewMeaningfulSignature(view) {
|
|
15463
|
+
const data = view?.data ? { ...view.data, updatedAt: undefined } : null;
|
|
15464
|
+
return JSON.stringify({ data, error: view?.error || "", finished: view?.finished === true });
|
|
15465
|
+
}
|
|
15466
|
+
|
|
15467
|
+
function updateSubagentTerminalRefreshState(view, { running = subagentTerminalViewIsRunning(view) } = {}) {
|
|
15468
|
+
if (!view || view.id !== activeSubagentTerminalId) return;
|
|
15469
|
+
const status = [
|
|
15470
|
+
view.loading ? "Refreshing…" : running ? "Live view · refreshes automatically" : "View retained after the child stopped being tracked",
|
|
15471
|
+
view.error,
|
|
15472
|
+
].filter(Boolean).join(" · ");
|
|
15473
|
+
elements.subagentTerminalStatus.setAttribute("aria-live", view.error ? "polite" : "off");
|
|
15474
|
+
elements.subagentTerminalStatus.textContent = status;
|
|
15475
|
+
elements.subagentTerminalStatus.classList.toggle("warning", !!view.error);
|
|
15476
|
+
elements.subagentTerminalRefreshButton.disabled = view.loading || view.finished === true;
|
|
15477
|
+
elements.subagentTerminalRefreshButton.textContent = view.loading ? "Refreshing…" : "Refresh";
|
|
15478
|
+
}
|
|
15479
|
+
|
|
15480
|
+
function renderSubagentTerminalView() {
|
|
15481
|
+
const view = activeSubagentTerminalView();
|
|
15482
|
+
const active = !!view;
|
|
15483
|
+
document.body.classList.toggle("subagent-terminal-active", active);
|
|
15484
|
+
if (!elements.subagentTerminalView) return;
|
|
15485
|
+
elements.subagentTerminalView.hidden = !active;
|
|
15486
|
+
if (!view) return;
|
|
15487
|
+
|
|
15488
|
+
const agent = view.data?.agent || view.agent || {};
|
|
15489
|
+
const running = subagentTerminalViewIsRunning(view);
|
|
15490
|
+
const transcriptMessages = subagentOverlayTranscriptMessages({ agent });
|
|
15491
|
+
const hasStructuredTranscript = transcriptMessages.length > 0;
|
|
15492
|
+
const outputText = subagentOverlayOutputText({ agent });
|
|
15493
|
+
const fallbackText = outputText || (running && agent.currentTool ? "" : running ? "Waiting for the first agent activity…" : "No recent output was captured.");
|
|
15494
|
+
const parent = tabs.find((tab) => tab.id === view.parentTabId);
|
|
15495
|
+
const facts = [
|
|
15496
|
+
view.finished ? "finished" : running ? "running" : agent.status || "finished",
|
|
15497
|
+
view.run?.mode,
|
|
15498
|
+
view.run?.source === "foreground" ? "foreground" : "async",
|
|
15499
|
+
agent.nested ? "nested" : "",
|
|
15500
|
+
...subagentExecutionFacts(agent),
|
|
15501
|
+
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
15502
|
+
].filter(Boolean);
|
|
15503
|
+
|
|
15504
|
+
elements.subagentTerminalTitle.textContent = subagentTerminalViewTitle(view);
|
|
15505
|
+
elements.subagentTerminalMeta.textContent = `${facts.join(" · ")} · parent ${parent?.title || view.parentTitle || "terminal"} · run ${view.runId}`;
|
|
15506
|
+
const shouldFollowOutput = elements.subagentTerminalTranscript.scrollHeight - elements.subagentTerminalTranscript.clientHeight - elements.subagentTerminalTranscript.scrollTop < CHAT_BOTTOM_THRESHOLD_PX;
|
|
15507
|
+
elements.subagentTerminalTranscript.replaceChildren();
|
|
15508
|
+
elements.subagentTerminalTranscript.setAttribute("aria-live", running ? "polite" : "off");
|
|
15509
|
+
const rendered = appendSubagentOverlayTranscript(elements.subagentTerminalTranscript, transcriptMessages);
|
|
15510
|
+
const emptyTranscriptFallback = hasStructuredTranscript && rendered === 0 ? subagentOverlayEmptyTranscriptText(transcriptMessages) : "";
|
|
15511
|
+
const visibleFallbackText = !hasStructuredTranscript ? fallbackText : emptyTranscriptFallback;
|
|
15512
|
+
if (visibleFallbackText) {
|
|
15513
|
+
const { bubble } = createMessageBubble({
|
|
15514
|
+
role: "assistant",
|
|
15515
|
+
title: "subagent output",
|
|
15516
|
+
timestamp: view.data?.updatedAt || Date.now(),
|
|
15517
|
+
content: visibleFallbackText,
|
|
15518
|
+
}, { streaming: running && !hasStructuredTranscript, transient: true });
|
|
15519
|
+
bubble.classList.add("subagent-overlay-message", "subagent-overlay-empty-fallback");
|
|
15520
|
+
elements.subagentTerminalTranscript.append(bubble);
|
|
15521
|
+
}
|
|
15522
|
+
if (running) appendSubagentRunIndicator(elements.subagentTerminalTranscript, { agent, run: view.run });
|
|
15523
|
+
|
|
15524
|
+
updateSubagentTerminalRefreshState(view, { running });
|
|
15525
|
+
elements.subagentTerminalCopyButton.disabled = !outputText;
|
|
15526
|
+
if (shouldFollowOutput) requestAnimationFrame(() => { elements.subagentTerminalTranscript.scrollTop = elements.subagentTerminalTranscript.scrollHeight; });
|
|
15527
|
+
}
|
|
15528
|
+
|
|
15529
|
+
function scheduleSubagentTerminalRefresh(delay = SUBAGENT_OVERLAY_REFRESH_MS) {
|
|
15530
|
+
clearTimeout(subagentTerminalRefreshTimer);
|
|
15531
|
+
const view = activeSubagentTerminalView();
|
|
15532
|
+
if (!view || view.finished) return;
|
|
15533
|
+
subagentTerminalRefreshTimer = setTimeout(() => {
|
|
15534
|
+
refreshSubagentTerminalView(view.id).finally(() => scheduleSubagentTerminalRefresh());
|
|
15535
|
+
}, delay);
|
|
15536
|
+
}
|
|
15537
|
+
|
|
15538
|
+
async function refreshSubagentTerminalView(viewId = activeSubagentTerminalId, { showLoading = false } = {}) {
|
|
15539
|
+
const view = viewId ? subagentTerminalViews.get(viewId) : null;
|
|
15540
|
+
if (!view || view.loading || view.finished) return;
|
|
15541
|
+
const requestSerial = (view.requestSerial || 0) + 1;
|
|
15542
|
+
const previousSignature = subagentTerminalViewMeaningfulSignature(view);
|
|
15543
|
+
view.requestSerial = requestSerial;
|
|
15544
|
+
view.loading = true;
|
|
15545
|
+
if (showLoading) updateSubagentTerminalRefreshState(view);
|
|
15546
|
+
try {
|
|
15547
|
+
const query = new URLSearchParams({ tab: view.parentTabId, run: view.runId, agent: view.agentId });
|
|
15548
|
+
const response = await api(`/api/subagents/output?${query}`, { scoped: false });
|
|
15549
|
+
if (view.requestSerial !== requestSerial || !subagentTerminalViews.has(view.id)) return;
|
|
15550
|
+
view.data = response.data || null;
|
|
15551
|
+
view.error = "";
|
|
15552
|
+
} catch (error) {
|
|
15553
|
+
if (view.requestSerial !== requestSerial || !subagentTerminalViews.has(view.id)) return;
|
|
15554
|
+
if (error?.statusCode === 404) view.finished = true;
|
|
15555
|
+
view.error = error?.statusCode === 404
|
|
15556
|
+
? "This subagent has finished or is no longer tracked. Showing the last captured output."
|
|
15557
|
+
: `Subagent output refresh failed: ${error.message || String(error)}`;
|
|
15558
|
+
} finally {
|
|
15559
|
+
if (view.requestSerial === requestSerial && subagentTerminalViews.has(view.id)) {
|
|
15560
|
+
view.loading = false;
|
|
15561
|
+
const meaningfulChange = previousSignature !== subagentTerminalViewMeaningfulSignature(view);
|
|
15562
|
+
if (view.id === activeSubagentTerminalId) {
|
|
15563
|
+
if (meaningfulChange) {
|
|
15564
|
+
renderSubagentTerminalView();
|
|
15565
|
+
renderTabs();
|
|
15566
|
+
} else {
|
|
15567
|
+
if (showLoading) updateSubagentTerminalRefreshState(view);
|
|
15568
|
+
updateSubagentRunIndicatorElapsed(elements.subagentTerminalTranscript, view.run);
|
|
15569
|
+
}
|
|
15570
|
+
}
|
|
15571
|
+
}
|
|
15572
|
+
}
|
|
15573
|
+
}
|
|
15574
|
+
|
|
15575
|
+
function deactivateSubagentTerminalView({ render = true, focusParent = false } = {}) {
|
|
15576
|
+
clearTimeout(subagentTerminalRefreshTimer);
|
|
15577
|
+
subagentTerminalRefreshTimer = null;
|
|
15578
|
+
activeSubagentTerminalId = null;
|
|
15579
|
+
renderSubagentTerminalView();
|
|
15580
|
+
if (render) renderTabs();
|
|
15581
|
+
updateDocumentTitle();
|
|
15582
|
+
if (focusParent) focusPromptInput({ defer: true });
|
|
15583
|
+
}
|
|
15584
|
+
|
|
15585
|
+
async function activateSubagentTerminalView(viewId) {
|
|
15586
|
+
const view = subagentTerminalViews.get(viewId);
|
|
15587
|
+
if (!view) return;
|
|
15588
|
+
if (activeTabId !== view.parentTabId) await switchTab(view.parentTabId);
|
|
15589
|
+
closeSubagentOverlay();
|
|
15590
|
+
activeSubagentTerminalId = view.id;
|
|
15591
|
+
renderSubagentTerminalView();
|
|
15592
|
+
renderTabs();
|
|
15593
|
+
updateDocumentTitle();
|
|
15594
|
+
if (isSidePanelOverlayView()) setSidePanelCollapsed(true, { persist: false });
|
|
15595
|
+
await refreshSubagentTerminalView(view.id);
|
|
15596
|
+
scheduleSubagentTerminalRefresh();
|
|
15597
|
+
}
|
|
15598
|
+
|
|
15599
|
+
async function openSubagentTerminal(tab, run, agent) {
|
|
15600
|
+
if (!tab?.tabId || !run?.id || !agent?.id) return;
|
|
15601
|
+
const id = subagentTerminalViewId(tab, run, agent);
|
|
15602
|
+
const existing = subagentTerminalViews.get(id);
|
|
15603
|
+
if (existing) {
|
|
15604
|
+
existing.tab = tab;
|
|
15605
|
+
existing.run = run;
|
|
15606
|
+
existing.agent = agent;
|
|
15607
|
+
existing.parentTitle = tab.tabTitle;
|
|
15608
|
+
} else {
|
|
15609
|
+
subagentTerminalViews.set(id, {
|
|
15610
|
+
id,
|
|
15611
|
+
parentTabId: tab.tabId,
|
|
15612
|
+
parentTitle: tab.tabTitle,
|
|
15613
|
+
tabIndex: tab.tabIndex,
|
|
15614
|
+
tab,
|
|
15615
|
+
run,
|
|
15616
|
+
agent,
|
|
15617
|
+
runId: run.id,
|
|
15618
|
+
agentId: agent.id,
|
|
15619
|
+
data: null,
|
|
15620
|
+
error: "",
|
|
15621
|
+
loading: false,
|
|
15622
|
+
finished: false,
|
|
15623
|
+
requestSerial: 0,
|
|
15624
|
+
openedAt: Date.now(),
|
|
15625
|
+
});
|
|
15626
|
+
}
|
|
15627
|
+
try {
|
|
15628
|
+
await activateSubagentTerminalView(id);
|
|
15629
|
+
} catch (error) {
|
|
15630
|
+
addEvent(`could not open subagent terminal: ${error.message || String(error)}`, "error");
|
|
15631
|
+
}
|
|
15632
|
+
}
|
|
15633
|
+
|
|
15634
|
+
function closeSubagentTerminalTab(viewId) {
|
|
15635
|
+
const view = subagentTerminalViews.get(viewId);
|
|
15636
|
+
if (!view) return;
|
|
15637
|
+
view.requestSerial += 1;
|
|
15638
|
+
subagentTerminalViews.delete(viewId);
|
|
15639
|
+
if (activeSubagentTerminalId === viewId) deactivateSubagentTerminalView({ render: false, focusParent: true });
|
|
15640
|
+
renderTabs();
|
|
15641
|
+
addEvent(`closed subagent view for ${subagentTerminalViewTitle(view)}; the child run was not stopped`, "info");
|
|
15642
|
+
}
|
|
15643
|
+
|
|
15644
|
+
async function copySubagentTerminalOutput() {
|
|
15645
|
+
const view = activeSubagentTerminalView();
|
|
15646
|
+
const text = view ? subagentOverlayOutputText(view.data || { agent: view.agent }) : "";
|
|
15647
|
+
if (!text) {
|
|
15648
|
+
addEvent("subagent output is empty", "warn");
|
|
15649
|
+
return;
|
|
15650
|
+
}
|
|
15651
|
+
try {
|
|
15652
|
+
await copyText(text);
|
|
15653
|
+
addEvent("copied subagent output", "info");
|
|
15654
|
+
} catch (error) {
|
|
15655
|
+
addEvent(`subagent output copy failed: ${error.message || String(error)}`, "warn");
|
|
15656
|
+
}
|
|
15657
|
+
}
|
|
15658
|
+
|
|
15659
|
+
function removeSubagentTerminalViewsForParent(parentTabId) {
|
|
15660
|
+
for (const [viewId, view] of subagentTerminalViews) {
|
|
15661
|
+
if (view.parentTabId !== parentTabId) continue;
|
|
15662
|
+
view.requestSerial += 1;
|
|
15663
|
+
subagentTerminalViews.delete(viewId);
|
|
15664
|
+
if (activeSubagentTerminalId === viewId) deactivateSubagentTerminalView({ render: false });
|
|
15665
|
+
}
|
|
15666
|
+
}
|
|
15667
|
+
|
|
15668
|
+
function syncSubagentTerminalViewsFromOverview() {
|
|
15669
|
+
for (const view of subagentTerminalViews.values()) {
|
|
15670
|
+
const tab = (Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : []).find((candidate) => candidate.tabId === view.parentTabId);
|
|
15671
|
+
const run = (Array.isArray(tab?.runs) ? tab.runs : []).find((candidate) => candidate.id === view.runId);
|
|
15672
|
+
const agent = (Array.isArray(run?.agents) ? run.agents : []).find((candidate) => candidate.id === view.agentId);
|
|
15673
|
+
if (tab) {
|
|
15674
|
+
view.tab = tab;
|
|
15675
|
+
view.parentTitle = tab.tabTitle;
|
|
15676
|
+
}
|
|
15677
|
+
if (run) view.run = run;
|
|
15678
|
+
if (agent) view.agent = agent;
|
|
15679
|
+
}
|
|
15680
|
+
}
|
|
15681
|
+
|
|
15682
|
+
function renderSubagentTerminalTab(view) {
|
|
15683
|
+
const active = view.id === activeSubagentTerminalId;
|
|
15684
|
+
const running = subagentTerminalViewIsRunning(view);
|
|
15685
|
+
const stateClass = running ? "activity-working" : view.error && !view.data ? "stopped" : "activity-done";
|
|
15686
|
+
const wrapper = make("div", `terminal-tab terminal-tab-subagent ${stateClass}${active ? " active" : ""}`);
|
|
15687
|
+
wrapper.dataset.subagentViewId = view.id;
|
|
15688
|
+
const button = make("button", "terminal-tab-button");
|
|
15689
|
+
button.type = "button";
|
|
15690
|
+
button.setAttribute("role", "tab");
|
|
15691
|
+
button.setAttribute("aria-selected", active ? "true" : "false");
|
|
15692
|
+
button.setAttribute("aria-label", `${subagentTerminalViewTitle(view)} subagent view, parent ${view.parentTitle || "terminal"}`);
|
|
15693
|
+
appendTerminalTabContent(button, {
|
|
15694
|
+
title: subagentTerminalViewTitle(view),
|
|
15695
|
+
indicator: { state: running ? "working" : "done" },
|
|
15696
|
+
meta: ["Subagent", ...subagentExecutionFacts(view.data?.agent || view.agent), view.parentTitle || "parent terminal"].join(" · "),
|
|
15697
|
+
subagent: true,
|
|
15698
|
+
});
|
|
15699
|
+
button.addEventListener("click", () => activateSubagentTerminalView(view.id));
|
|
15700
|
+
const close = make("button", "terminal-tab-close", "×");
|
|
15701
|
+
close.type = "button";
|
|
15702
|
+
applyStyledTooltip(close, `Close ${subagentTerminalViewTitle(view)} view without stopping the subagent`, { ariaLabel: `Close ${subagentTerminalViewTitle(view)} subagent view` });
|
|
15703
|
+
close.addEventListener("click", (event) => {
|
|
15704
|
+
event.stopPropagation();
|
|
15705
|
+
closeSubagentTerminalTab(view.id);
|
|
15706
|
+
});
|
|
15707
|
+
wrapper.append(button, close);
|
|
15708
|
+
return wrapper;
|
|
15709
|
+
}
|
|
15710
|
+
|
|
15711
|
+
function openSubagentOutput(tab, run, agent) {
|
|
15712
|
+
return subagentOpenMode === "tab" ? openSubagentTerminal(tab, run, agent) : openSubagentOverlay(tab, run, agent);
|
|
15713
|
+
}
|
|
15714
|
+
|
|
14646
15715
|
function renderSubagentAgent(tab, run, agent) {
|
|
14647
15716
|
const row = make("button", `subagent-agent-row${agent?.nested ? " nested" : ""}`);
|
|
14648
15717
|
row.type = "button";
|
|
@@ -14655,17 +15724,63 @@ function renderSubagentAgent(tab, run, agent) {
|
|
|
14655
15724
|
agent?.nested ? "nested" : "",
|
|
14656
15725
|
run?.mode && run.mode !== "single" ? run.mode : "",
|
|
14657
15726
|
run?.source === "foreground" ? "foreground" : "async",
|
|
15727
|
+
...subagentExecutionFacts(agent),
|
|
14658
15728
|
agent?.currentTool ? `tool: ${agent.currentTool}` : "",
|
|
14659
15729
|
elapsed ? `running ${elapsed}` : "",
|
|
14660
15730
|
].filter(Boolean);
|
|
14661
15731
|
content.append(make("span", "subagent-agent-meta", facts.join(" · ")));
|
|
14662
15732
|
row.append(dot, content);
|
|
14663
|
-
|
|
14664
|
-
row.
|
|
14665
|
-
row.
|
|
15733
|
+
const destination = subagentOpenMode === "tab" ? "subagent tab" : "live output overlay";
|
|
15734
|
+
row.title = `${agent?.name || "subagent"} · ${facts.join(" · ")} · run ${run?.id || "unknown"} · open ${destination}`;
|
|
15735
|
+
row.setAttribute("aria-label", `Open ${destination} for ${agent?.name || "subagent"} in ${tab?.tabTitle || `Terminal ${tab?.tabIndex || "?"}`}`);
|
|
15736
|
+
row.addEventListener("click", () => openSubagentOutput(tab, run, agent));
|
|
14666
15737
|
return row;
|
|
14667
15738
|
}
|
|
14668
15739
|
|
|
15740
|
+
function subagentGateStatusLabel(status) {
|
|
15741
|
+
return status === "satisfied" ? "satisfied" : status === "running" ? "running" : status === "cancelled" ? "cancelled" : "failed";
|
|
15742
|
+
}
|
|
15743
|
+
|
|
15744
|
+
function renderSubagentGateAttempt(attempt) {
|
|
15745
|
+
const row = make("div", `subagent-gate-attempt ${attempt?.status || "failed"}`);
|
|
15746
|
+
const marker = make("span", "subagent-gate-attempt-marker");
|
|
15747
|
+
marker.setAttribute("aria-hidden", "true");
|
|
15748
|
+
const content = make("div", "subagent-gate-attempt-content");
|
|
15749
|
+
const title = attempt?.label || attempt?.agent || "subagent";
|
|
15750
|
+
content.append(make("strong", undefined, `${title} · attempt ${attempt?.attempt || 1}/${attempt?.maxAttempts || 1}`));
|
|
15751
|
+
const facts = [
|
|
15752
|
+
attempt?.status,
|
|
15753
|
+
attempt?.phase ? `phase ${attempt.phase}` : "",
|
|
15754
|
+
attempt?.provider ? `provider ${attempt.provider}` : "provider unknown",
|
|
15755
|
+
attempt?.model ? `model ${attempt.model}` : "model unknown",
|
|
15756
|
+
attempt?.retrySafety,
|
|
15757
|
+
attempt?.failureKind ? `failure ${attempt.failureKind}` : "",
|
|
15758
|
+
attempt?.runId ? `run ${attempt.runId}` : "",
|
|
15759
|
+
].filter(Boolean);
|
|
15760
|
+
content.append(make("span", "subagent-gate-attempt-meta", facts.join(" · ")));
|
|
15761
|
+
if (attempt?.error) content.append(make("span", "subagent-gate-attempt-error", attempt.error));
|
|
15762
|
+
row.append(marker, content);
|
|
15763
|
+
return row;
|
|
15764
|
+
}
|
|
15765
|
+
|
|
15766
|
+
function renderSubagentGate(gate) {
|
|
15767
|
+
const status = subagentGateStatusLabel(gate?.status);
|
|
15768
|
+
const card = make("section", `subagent-gate-card ${status}`);
|
|
15769
|
+
const header = make("div", "subagent-gate-header");
|
|
15770
|
+
const title = make("div", "subagent-gate-title");
|
|
15771
|
+
title.append(
|
|
15772
|
+
make("strong", undefined, `Retry gate · ${gate?.qualifyingSuccesses || 0}/${gate?.requiredSuccesses || 1}`),
|
|
15773
|
+
make("span", undefined, `${status}${gate?.requireDistinctProviders ? " · distinct providers" : ""}`),
|
|
15774
|
+
);
|
|
15775
|
+
header.append(title, make("span", `subagent-gate-status ${status}`, status));
|
|
15776
|
+
card.append(header);
|
|
15777
|
+
const attempts = make("div", "subagent-gate-attempts");
|
|
15778
|
+
for (const attempt of Array.isArray(gate?.attempts) ? gate.attempts : []) attempts.append(renderSubagentGateAttempt(attempt));
|
|
15779
|
+
if (!attempts.childElementCount) attempts.append(make("div", "subagents-empty", "Waiting for the first attempt…"));
|
|
15780
|
+
card.append(attempts);
|
|
15781
|
+
return card;
|
|
15782
|
+
}
|
|
15783
|
+
|
|
14669
15784
|
function renderSubagentTabGroup(tab) {
|
|
14670
15785
|
const group = make("section", `subagent-tab-group${tab.tabId === activeTabId ? " active" : ""}`);
|
|
14671
15786
|
const header = make("button", "subagent-tab-header");
|
|
@@ -14676,7 +15791,8 @@ function renderSubagentTabGroup(tab) {
|
|
|
14676
15791
|
make("strong", undefined, tab.tabTitle || `Terminal ${tab.tabIndex || "?"}`),
|
|
14677
15792
|
make("span", "subagent-tab-session", `Terminal ${tab.tabIndex || "?"} · ${subagentTabMeta(tab)}`),
|
|
14678
15793
|
);
|
|
14679
|
-
|
|
15794
|
+
const countLabel = Number(tab.gateCount || 0) > 0 ? `${tab.agentCount || 0} agents · ${tab.gateCount} gates` : String(tab.agentCount || 0);
|
|
15795
|
+
header.append(title, make("span", "subagent-tab-count", countLabel));
|
|
14680
15796
|
header.addEventListener("click", () => switchTab(tab.tabId));
|
|
14681
15797
|
group.append(header);
|
|
14682
15798
|
|
|
@@ -14690,6 +15806,9 @@ function renderSubagentTabGroup(tab) {
|
|
|
14690
15806
|
.sort((a, b) => Number(a.index || 0) - Number(b.index || 0) || String(a.name || "").localeCompare(String(b.name || "")));
|
|
14691
15807
|
for (const agent of agents) list.append(renderSubagentAgent(tab, run, agent));
|
|
14692
15808
|
}
|
|
15809
|
+
for (const gate of (Array.isArray(tab.gates) ? tab.gates : []).slice().sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0))) {
|
|
15810
|
+
list.append(renderSubagentGate(gate));
|
|
15811
|
+
}
|
|
14693
15812
|
group.append(list);
|
|
14694
15813
|
return group;
|
|
14695
15814
|
}
|
|
@@ -14699,23 +15818,25 @@ function renderSubagents() {
|
|
|
14699
15818
|
if (!box) return;
|
|
14700
15819
|
const activeTabs = subagentTabsWithRunningAgents();
|
|
14701
15820
|
const totalAgents = activeTabs.reduce((count, tab) => count + Number(tab.agentCount || 0), 0);
|
|
15821
|
+
const totalGates = activeTabs.reduce((count, tab) => count + Number(tab.gateCount || 0), 0);
|
|
15822
|
+
const totalItems = totalAgents + totalGates;
|
|
14702
15823
|
if (elements.subagentCountBadge) {
|
|
14703
|
-
elements.subagentCountBadge.textContent = String(
|
|
14704
|
-
elements.subagentCountBadge.hidden =
|
|
15824
|
+
elements.subagentCountBadge.textContent = String(totalItems);
|
|
15825
|
+
elements.subagentCountBadge.hidden = totalItems === 0;
|
|
14705
15826
|
}
|
|
14706
15827
|
if (elements.subagentsStatus) {
|
|
14707
|
-
elements.subagentsStatus.textContent =
|
|
14708
|
-
? `${totalAgents} running across ${activeTabs.length} ${activeTabs.length === 1 ? "terminal" : "terminals"}`
|
|
15828
|
+
elements.subagentsStatus.textContent = totalItems > 0
|
|
15829
|
+
? [`${totalAgents} running`, totalGates ? `${totalGates} retry ${totalGates === 1 ? "gate" : "gates"}` : "", `across ${activeTabs.length} ${activeTabs.length === 1 ? "terminal" : "terminals"}`].filter(Boolean).join(" · ")
|
|
14709
15830
|
: subagentsLoading && !latestSubagents
|
|
14710
|
-
? "Checking
|
|
14711
|
-
: "No running subagents.";
|
|
15831
|
+
? "Checking subagents and retry gates…"
|
|
15832
|
+
: "No running subagents or retained retry gates.";
|
|
14712
15833
|
}
|
|
14713
15834
|
|
|
14714
15835
|
box.replaceChildren();
|
|
14715
|
-
box.classList.toggle("muted",
|
|
14716
|
-
box.classList.toggle("has-items",
|
|
14717
|
-
if (
|
|
14718
|
-
box.append(make("div", "subagents-empty", subagentsError ? `Subagent status unavailable: ${subagentsError.message || subagentsError}` : "Running subagents will appear here, grouped by terminal and session."));
|
|
15836
|
+
box.classList.toggle("muted", totalItems === 0);
|
|
15837
|
+
box.classList.toggle("has-items", totalItems > 0);
|
|
15838
|
+
if (totalItems === 0) {
|
|
15839
|
+
box.append(make("div", "subagents-empty", subagentsError ? `Subagent status unavailable: ${subagentsError.message || subagentsError}` : "Running subagents and retry-gate attempts will appear here, grouped by terminal and session."));
|
|
14719
15840
|
return;
|
|
14720
15841
|
}
|
|
14721
15842
|
for (const tab of activeTabs) box.append(renderSubagentTabGroup(tab));
|
|
@@ -14729,6 +15850,7 @@ async function refreshSubagents() {
|
|
|
14729
15850
|
try {
|
|
14730
15851
|
const response = await api("/api/subagents", { scoped: false });
|
|
14731
15852
|
latestSubagents = response.data || null;
|
|
15853
|
+
syncSubagentTerminalViewsFromOverview();
|
|
14732
15854
|
subagentsError = null;
|
|
14733
15855
|
} catch (error) {
|
|
14734
15856
|
subagentsError = error;
|
|
@@ -14741,7 +15863,8 @@ async function refreshSubagents() {
|
|
|
14741
15863
|
function scheduleRefreshSubagents(delay) {
|
|
14742
15864
|
clearTimeout(refreshSubagentsTimer);
|
|
14743
15865
|
const totalAgents = Number(latestSubagents?.totalAgents || 0);
|
|
14744
|
-
const
|
|
15866
|
+
const hasRunningGate = (Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : []).some((tab) => (Array.isArray(tab?.gates) ? tab.gates : []).some((gate) => gate?.status === "running"));
|
|
15867
|
+
const nextDelay = delay ?? (document.visibilityState === "hidden" ? SUBAGENTS_HIDDEN_REFRESH_MS : totalAgents > 0 || hasRunningGate ? SUBAGENTS_ACTIVE_REFRESH_MS : SUBAGENTS_IDLE_REFRESH_MS);
|
|
14745
15868
|
refreshSubagentsTimer = setTimeout(() => {
|
|
14746
15869
|
refreshSubagents().finally(() => scheduleRefreshSubagents());
|
|
14747
15870
|
}, nextDelay);
|
|
@@ -19359,6 +20482,11 @@ async function createGitPrBranchWithSuggestion(suggestion, tabId = gitWorkflowAc
|
|
|
19359
20482
|
failGitWorkflow(new Error("Branch name is required to create a PR branch worktree."), "message", { tabId });
|
|
19360
20483
|
return;
|
|
19361
20484
|
}
|
|
20485
|
+
const baseRef = await chooseGitWorktreeBase(branch);
|
|
20486
|
+
if (baseRef === null) {
|
|
20487
|
+
setGitWorkflow({ step: "message", busy: false, output: `${formatCommitMessagePreview(sourceWorkflow.message)}\n\nPR branch worktree creation cancelled before choosing a base.` }, { tabId });
|
|
20488
|
+
return;
|
|
20489
|
+
}
|
|
19362
20490
|
let expectedStagedContentHash;
|
|
19363
20491
|
try {
|
|
19364
20492
|
expectedStagedContentHash = await assertGuidedGitStagedContentBinding(tabId, "PR worktree creation");
|
|
@@ -19369,7 +20497,7 @@ async function createGitPrBranchWithSuggestion(suggestion, tabId = gitWorkflowAc
|
|
|
19369
20497
|
const runId = workflow.runId;
|
|
19370
20498
|
setGitWorkflow({ step: "branching", prMode: true, prBranch: branch, branchName: branch, busy: true, error: "", output: `${formatCommitMessagePreview(sourceWorkflow.message)}\n\nCreating or opening branch worktree ${branch}…` }, { tabId });
|
|
19371
20499
|
try {
|
|
19372
|
-
const result = await gitWorkflowRequest("/api/git-workflow/branch", { body: { branch, sessionMode: "fork-current", openTab: true, ...(expectedStagedContentHash ? { expectedStagedContentHash } : {}) }, runId, tabId });
|
|
20500
|
+
const result = await gitWorkflowRequest("/api/git-workflow/branch", { body: { branch, baseRef, sessionMode: "fork-current", openTab: true, ...(expectedStagedContentHash ? { expectedStagedContentHash } : {}) }, runId, tabId });
|
|
19373
20501
|
if (!result) return;
|
|
19374
20502
|
syncGitWorkflowWorktreeTabs(result);
|
|
19375
20503
|
const targetTabId = result.tab?.id && tabs.some((tab) => tab.id === result.tab.id) ? result.tab.id : tabId;
|
|
@@ -28606,6 +29734,19 @@ elements.confirmationDialog?.addEventListener("cancel", (event) => {
|
|
|
28606
29734
|
elements.confirmationDialog?.addEventListener("close", () => {
|
|
28607
29735
|
if (activeConfirmationResolve) finishApplicationConfirmation(false);
|
|
28608
29736
|
});
|
|
29737
|
+
elements.gitWorktreeBaseCancelButton?.addEventListener("click", () => finishGitWorktreeBaseChoice(null));
|
|
29738
|
+
elements.gitWorktreeBaseCreateButton?.addEventListener("click", () => finishGitWorktreeBaseChoice(elements.gitWorktreeBaseCurrentHead?.checked ? "HEAD" : "origin/main"));
|
|
29739
|
+
elements.gitWorktreeBaseDialog?.querySelector("form")?.addEventListener("submit", (event) => {
|
|
29740
|
+
event.preventDefault();
|
|
29741
|
+
finishGitWorktreeBaseChoice(elements.gitWorktreeBaseCurrentHead?.checked ? "HEAD" : "origin/main");
|
|
29742
|
+
});
|
|
29743
|
+
elements.gitWorktreeBaseDialog?.addEventListener("cancel", (event) => {
|
|
29744
|
+
event.preventDefault();
|
|
29745
|
+
finishGitWorktreeBaseChoice(null);
|
|
29746
|
+
});
|
|
29747
|
+
elements.gitWorktreeBaseDialog?.addEventListener("close", () => {
|
|
29748
|
+
if (activeGitWorktreeBaseResolve) finishGitWorktreeBaseChoice(null);
|
|
29749
|
+
});
|
|
28609
29750
|
elements.commandPaletteDialog?.querySelector("form")?.addEventListener("submit", (event) => event.preventDefault());
|
|
28610
29751
|
elements.commandPaletteDialog?.addEventListener("cancel", (event) => {
|
|
28611
29752
|
event.preventDefault();
|
|
@@ -29010,6 +30151,15 @@ if (elements.terminalTabsLayoutSelect) {
|
|
|
29010
30151
|
setTerminalTabsLayout(elements.terminalTabsLayoutSelect.value, { announce: true });
|
|
29011
30152
|
});
|
|
29012
30153
|
}
|
|
30154
|
+
if (elements.subagentOpenModeSelect) {
|
|
30155
|
+
elements.subagentOpenModeSelect.addEventListener("change", () => {
|
|
30156
|
+
setSubagentOpenMode(elements.subagentOpenModeSelect.value, { announce: true });
|
|
30157
|
+
});
|
|
30158
|
+
}
|
|
30159
|
+
elements.subagentTerminalCopyButton?.addEventListener("click", () => copySubagentTerminalOutput());
|
|
30160
|
+
elements.subagentTerminalRefreshButton?.addEventListener("click", () => {
|
|
30161
|
+
refreshSubagentTerminalView(activeSubagentTerminalId, { showLoading: true }).finally(() => scheduleSubagentTerminalRefresh());
|
|
30162
|
+
});
|
|
29013
30163
|
elements.piVersionButton?.addEventListener("click", () => {
|
|
29014
30164
|
openPiReleaseNotes().catch((error) => addEvent(error.message || String(error), "error"));
|
|
29015
30165
|
});
|
|
@@ -29082,6 +30232,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
29082
30232
|
if (elements.fileContextMenu && !elements.fileContextMenu.hidden && !event.target?.closest?.(".file-context-menu")) {
|
|
29083
30233
|
closeFileContextMenu();
|
|
29084
30234
|
}
|
|
30235
|
+
if (elements.gitPanelContextMenu && !elements.gitPanelContextMenu.hidden && !event.target?.closest?.(".git-side-panel-context-menu")) {
|
|
30236
|
+
closeGitPanelContextMenu();
|
|
30237
|
+
}
|
|
29085
30238
|
}, { passive: true });
|
|
29086
30239
|
document.addEventListener("pointermove", (event) => {
|
|
29087
30240
|
if (openTerminalTabGroupKey && !event.target?.closest?.(".terminal-tab-group")) {
|
|
@@ -29444,6 +30597,21 @@ elements.fileContextMenu?.addEventListener("keydown", (event) => {
|
|
|
29444
30597
|
items[event.key === "Home" ? 0 : items.length - 1]?.focus({ preventScroll: true });
|
|
29445
30598
|
}
|
|
29446
30599
|
});
|
|
30600
|
+
elements.gitPanelContextMenu?.addEventListener("keydown", (event) => {
|
|
30601
|
+
const items = [...elements.gitPanelContextMenu.querySelectorAll('[role="menuitem"]:not([disabled])')];
|
|
30602
|
+
const index = items.indexOf(document.activeElement);
|
|
30603
|
+
if (event.key === "Escape") {
|
|
30604
|
+
event.preventDefault();
|
|
30605
|
+
closeGitPanelContextMenu();
|
|
30606
|
+
} else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
30607
|
+
event.preventDefault();
|
|
30608
|
+
const direction = event.key === "ArrowDown" ? 1 : -1;
|
|
30609
|
+
items[(Math.max(0, index) + direction + items.length) % items.length]?.focus({ preventScroll: true });
|
|
30610
|
+
} else if (event.key === "Home" || event.key === "End") {
|
|
30611
|
+
event.preventDefault();
|
|
30612
|
+
items[event.key === "Home" ? 0 : items.length - 1]?.focus({ preventScroll: true });
|
|
30613
|
+
}
|
|
30614
|
+
});
|
|
29447
30615
|
elements.fileContextMenu?.addEventListener("click", (event) => {
|
|
29448
30616
|
const button = event.target?.closest?.("[data-file-menu-action]");
|
|
29449
30617
|
if (!button) return;
|
|
@@ -29619,6 +30787,7 @@ initializeFastPicks().catch((error) => addEvent(`failed to initialize path fast
|
|
|
29619
30787
|
restoreAgentDoneNotificationsSetting();
|
|
29620
30788
|
restoreThinkingVisibilitySetting();
|
|
29621
30789
|
restoreTerminalTabsLayoutSetting();
|
|
30790
|
+
restoreSubagentOpenModeSetting();
|
|
29622
30791
|
restoreTerminalCustomGroups();
|
|
29623
30792
|
restoreToolOutputExpansionSetting();
|
|
29624
30793
|
restoreWorkspaceDashboardState();
|