@firstpick/pi-package-webui 0.7.0 → 0.7.1
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 +1 -0
- package/package.json +6 -6
- package/public/app.js +466 -32
- package/public/index.html +50 -0
- package/public/styles.css +198 -18
- package/tests/http-endpoints-harness.test.mjs +26 -1
- package/tests/mobile-static.test.mjs +68 -10
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"),
|
|
@@ -221,6 +229,8 @@ const elements = {
|
|
|
221
229
|
subagentsStatus: $("#subagentsStatus"),
|
|
222
230
|
subagentsBox: $("#subagentsBox"),
|
|
223
231
|
subagentCountBadge: $("#subagentCountBadge"),
|
|
232
|
+
subagentOpenModeSelect: $("#subagentOpenModeSelect"),
|
|
233
|
+
subagentOpenModeStatus: $("#subagentOpenModeStatus"),
|
|
224
234
|
queueBox: $("#queueBox"),
|
|
225
235
|
queueCountBadge: $("#queueCountBadge"),
|
|
226
236
|
createPromptListButton: $("#createPromptListButton"),
|
|
@@ -263,6 +273,12 @@ const elements = {
|
|
|
263
273
|
confirmationUndo: $("#confirmationUndo"),
|
|
264
274
|
confirmationCancelButton: $("#confirmationCancelButton"),
|
|
265
275
|
confirmationConfirmButton: $("#confirmationConfirmButton"),
|
|
276
|
+
gitWorktreeBaseDialog: $("#gitWorktreeBaseDialog"),
|
|
277
|
+
gitWorktreeBaseBranch: $("#gitWorktreeBaseBranch"),
|
|
278
|
+
gitWorktreeBaseOriginMain: $("#gitWorktreeBaseOriginMain"),
|
|
279
|
+
gitWorktreeBaseCurrentHead: $("#gitWorktreeBaseCurrentHead"),
|
|
280
|
+
gitWorktreeBaseCancelButton: $("#gitWorktreeBaseCancelButton"),
|
|
281
|
+
gitWorktreeBaseCreateButton: $("#gitWorktreeBaseCreateButton"),
|
|
266
282
|
piReleaseNotesDialog: $("#piReleaseNotesDialog"),
|
|
267
283
|
piReleaseNotesTitle: $("#piReleaseNotesTitle"),
|
|
268
284
|
piReleaseNotesStatus: $("#piReleaseNotesStatus"),
|
|
@@ -390,6 +406,7 @@ let foregroundReconcileTimer = null;
|
|
|
390
406
|
let eventSource = null;
|
|
391
407
|
let activeDialog = null;
|
|
392
408
|
let activeConfirmationResolve = null;
|
|
409
|
+
let activeGitWorktreeBaseResolve = null;
|
|
393
410
|
let activeUndoAction = null;
|
|
394
411
|
let undoToastTimer = null;
|
|
395
412
|
let undoToastFocusReturn = null;
|
|
@@ -478,6 +495,10 @@ let subagentOverlayError = "";
|
|
|
478
495
|
let subagentOverlayLoading = false;
|
|
479
496
|
let subagentOverlayRefreshTimer = null;
|
|
480
497
|
let subagentOverlayRequestSerial = 0;
|
|
498
|
+
let subagentOpenMode = "overlay";
|
|
499
|
+
const subagentTerminalViews = new Map();
|
|
500
|
+
let activeSubagentTerminalId = null;
|
|
501
|
+
let subagentTerminalRefreshTimer = null;
|
|
481
502
|
let backendOffline = false;
|
|
482
503
|
let serverRestartInProgress = false;
|
|
483
504
|
let updateRequestInProgress = false;
|
|
@@ -587,6 +608,7 @@ const THINKING_VISIBILITY_STORAGE_KEY = "pi-webui-thinking-visible";
|
|
|
587
608
|
const BUSY_PROMPT_BEHAVIOR_STORAGE_KEY = "pi-webui-busy-prompt-behavior";
|
|
588
609
|
const SKILL_USAGE_STORAGE_KEY = "pi-webui-skill-usage-v1";
|
|
589
610
|
const TERMINAL_TABS_LAYOUT_STORAGE_KEY = "pi-webui-terminal-tabs-layout";
|
|
611
|
+
const SUBAGENT_OPEN_MODE_STORAGE_KEY = "pi-webui-subagent-open-mode";
|
|
590
612
|
const TERMINAL_CUSTOM_GROUPS_STORAGE_KEY = "pi-webui-terminal-custom-groups-v1";
|
|
591
613
|
const TERMINAL_TAB_DRAG_MIME = "application/x-pi-terminal-tab-id";
|
|
592
614
|
const FOOTER_SCOPED_MODEL_ORDER_STORAGE_KEY = "pi-webui-footer-scoped-model-order-v1";
|
|
@@ -727,6 +749,8 @@ const THEME_SCHEME_MODES = new Set(["light", "dark", "auto"]);
|
|
|
727
749
|
let themeSchemeMode = "light"; // "light" | "dark" | "auto"; finalized in initializeThemes
|
|
728
750
|
const TERMINAL_TABS_LAYOUTS = new Set(["top", "left"]);
|
|
729
751
|
const TERMINAL_TABS_LAYOUT_LABELS = { top: "Top bar", left: "Left sidebar" };
|
|
752
|
+
const SUBAGENT_OPEN_MODES = new Set(["overlay", "tab"]);
|
|
753
|
+
const SUBAGENT_OPEN_MODE_LABELS = { overlay: "Overlay", tab: "Tab / terminal" };
|
|
730
754
|
const BUSY_PROMPT_BEHAVIOR_VALUES = new Set(["followUp", "steer"]);
|
|
731
755
|
const BUSY_PROMPT_BEHAVIOR_LABELS = { followUp: "Follow-up", steer: "Steer" };
|
|
732
756
|
const SKILL_TAG_MAX_VISIBLE = 6;
|
|
@@ -1681,6 +1705,44 @@ function restoreTerminalTabsLayoutSetting() {
|
|
|
1681
1705
|
setTerminalTabsLayout(readStoredTerminalTabsLayout(), { persist: false });
|
|
1682
1706
|
}
|
|
1683
1707
|
|
|
1708
|
+
function normalizeSubagentOpenMode(value) {
|
|
1709
|
+
return SUBAGENT_OPEN_MODES.has(value) ? value : "overlay";
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
function readStoredSubagentOpenMode() {
|
|
1713
|
+
try {
|
|
1714
|
+
return normalizeSubagentOpenMode(localStorage.getItem(SUBAGENT_OPEN_MODE_STORAGE_KEY));
|
|
1715
|
+
} catch {
|
|
1716
|
+
return "overlay";
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
function persistSubagentOpenMode(mode) {
|
|
1721
|
+
try {
|
|
1722
|
+
localStorage.setItem(SUBAGENT_OPEN_MODE_STORAGE_KEY, normalizeSubagentOpenMode(mode));
|
|
1723
|
+
} catch {
|
|
1724
|
+
// Ignore storage failures; the opening mode still applies for this page load.
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
function renderSubagentOpenModeControl() {
|
|
1729
|
+
const mode = normalizeSubagentOpenMode(subagentOpenMode);
|
|
1730
|
+
if (elements.subagentOpenModeSelect) elements.subagentOpenModeSelect.value = mode;
|
|
1731
|
+
if (elements.subagentOpenModeStatus) elements.subagentOpenModeStatus.textContent = `${SUBAGENT_OPEN_MODE_LABELS[mode]} · saved in this browser`;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
function setSubagentOpenMode(mode, { persist = true, announce = false } = {}) {
|
|
1735
|
+
subagentOpenMode = normalizeSubagentOpenMode(mode);
|
|
1736
|
+
if (persist) persistSubagentOpenMode(subagentOpenMode);
|
|
1737
|
+
renderSubagentOpenModeControl();
|
|
1738
|
+
renderSubagents();
|
|
1739
|
+
if (announce) addEvent(`subagents now open in ${SUBAGENT_OPEN_MODE_LABELS[subagentOpenMode].toLowerCase()}`);
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
function restoreSubagentOpenModeSetting() {
|
|
1743
|
+
setSubagentOpenMode(readStoredSubagentOpenMode(), { persist: false });
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1684
1746
|
function normalizeTerminalCustomGroupTitle(value, fallback = "Custom group") {
|
|
1685
1747
|
const title = String(value || "").replace(/\s+/g, " ").trim();
|
|
1686
1748
|
return (title || fallback).slice(0, 40);
|
|
@@ -1941,6 +2003,7 @@ function setThinkingOutputVisible(visible, { announce = false } = {}) {
|
|
|
1941
2003
|
if (!thinkingOutputVisible) removeStreamingThinkingBubble();
|
|
1942
2004
|
renderAllMessages({ preserveScroll: true });
|
|
1943
2005
|
if (subagentOverlaySelection?.tabId === activeTabId) renderWidgets();
|
|
2006
|
+
if (activeSubagentTerminalId) renderSubagentTerminalView();
|
|
1944
2007
|
if (announce) addEvent(thinkingOutputVisible ? "thinking output shown" : "thinking output hidden", thinkingOutputVisible ? "info" : "warn");
|
|
1945
2008
|
}
|
|
1946
2009
|
|
|
@@ -2762,6 +2825,31 @@ function appConfirmText(message, options = {}) {
|
|
|
2762
2825
|
});
|
|
2763
2826
|
}
|
|
2764
2827
|
|
|
2828
|
+
function finishGitWorktreeBaseChoice(baseRef = null) {
|
|
2829
|
+
const resolve = activeGitWorktreeBaseResolve;
|
|
2830
|
+
activeGitWorktreeBaseResolve = null;
|
|
2831
|
+
if (elements.gitWorktreeBaseDialog?.open) elements.gitWorktreeBaseDialog.close();
|
|
2832
|
+
resolve?.(baseRef);
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
function chooseGitWorktreeBase(branch) {
|
|
2836
|
+
const branchName = cleanStatusText(branch) || "the new branch";
|
|
2837
|
+
if (!elements.gitWorktreeBaseDialog?.showModal) {
|
|
2838
|
+
const choice = window.prompt(`Create ${branchName} from:\n1. origin/main (default)\n2. Current workspace HEAD\n\nEnter 1 or 2. Cancel to abort.`, "1");
|
|
2839
|
+
if (choice === null) return Promise.resolve(null);
|
|
2840
|
+
return Promise.resolve(String(choice).trim() === "2" ? "HEAD" : "origin/main");
|
|
2841
|
+
}
|
|
2842
|
+
if (activeGitWorktreeBaseResolve) finishGitWorktreeBaseChoice(null);
|
|
2843
|
+
elements.gitWorktreeBaseBranch.textContent = branchName;
|
|
2844
|
+
elements.gitWorktreeBaseOriginMain.checked = true;
|
|
2845
|
+
elements.gitWorktreeBaseCurrentHead.checked = false;
|
|
2846
|
+
return new Promise((resolve) => {
|
|
2847
|
+
activeGitWorktreeBaseResolve = resolve;
|
|
2848
|
+
elements.gitWorktreeBaseDialog.showModal();
|
|
2849
|
+
queueMicrotask(() => elements.gitWorktreeBaseOriginMain?.focus());
|
|
2850
|
+
});
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2765
2853
|
function handleDrawerModalKeydown(event) {
|
|
2766
2854
|
if (!activeDrawerModal || event.defaultPrevented) return;
|
|
2767
2855
|
if (event.key === "Escape") {
|
|
@@ -7709,6 +7797,11 @@ function requestedTabIdFromUrl() {
|
|
|
7709
7797
|
}
|
|
7710
7798
|
|
|
7711
7799
|
function updateDocumentTitle() {
|
|
7800
|
+
const subagentView = activeSubagentTerminalView();
|
|
7801
|
+
if (subagentView) {
|
|
7802
|
+
document.title = `Pi Web UI · ${subagentTerminalViewTitle(subagentView)} · Subagent`;
|
|
7803
|
+
return;
|
|
7804
|
+
}
|
|
7712
7805
|
const tab = activeTab();
|
|
7713
7806
|
document.title = tab ? `Pi Web UI · ${tab.title}` : "Pi Web UI";
|
|
7714
7807
|
}
|
|
@@ -7727,7 +7820,7 @@ function restoreActiveDraft() {
|
|
|
7727
7820
|
|
|
7728
7821
|
function focusPromptInput({ defer = false } = {}) {
|
|
7729
7822
|
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;
|
|
7823
|
+
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
7824
|
try {
|
|
7732
7825
|
elements.promptInput.focus({ preventScroll: true });
|
|
7733
7826
|
} catch {
|
|
@@ -8055,11 +8148,12 @@ function terminalTabMeta(tab, indicator) {
|
|
|
8055
8148
|
return parts.join(" · ");
|
|
8056
8149
|
}
|
|
8057
8150
|
|
|
8058
|
-
function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false, workflowModeActive = false, workflowCount = 0 }) {
|
|
8151
|
+
function appendTerminalTabContent(button, { title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false, workflowModeActive = false, workflowCount = 0, subagent = false }) {
|
|
8059
8152
|
const titleRow = make("span", "terminal-tab-title-row");
|
|
8060
8153
|
const indicatorDot = make("span", "terminal-tab-activity-indicator");
|
|
8061
8154
|
indicatorDot.setAttribute("aria-hidden", "true");
|
|
8062
8155
|
titleRow.append(indicatorDot, make("span", "terminal-tab-title", title));
|
|
8156
|
+
if (subagent) titleRow.append(make("span", "terminal-tab-subagent-indicator", "subagent"));
|
|
8063
8157
|
if (appRunnerIsRunning(appRunnerRun)) titleRow.append(make("span", "terminal-tab-app-runner-indicator", "app"));
|
|
8064
8158
|
if (conversationModeActive) titleRow.append(make("span", "terminal-tab-conversation-indicator", "voice"));
|
|
8065
8159
|
if (workflowModeActive || workflowCount) titleRow.append(make("span", "terminal-tab-workflow-indicator", workflowCount ? `wf ${workflowCount}` : "wf"));
|
|
@@ -8068,7 +8162,7 @@ function appendTerminalTabContent(button, { title, indicator, meta, count = null
|
|
|
8068
8162
|
}
|
|
8069
8163
|
|
|
8070
8164
|
function renderTerminalTab(tab) {
|
|
8071
|
-
const isActive = tab.id === activeTabId;
|
|
8165
|
+
const isActive = tab.id === activeTabId && !activeSubagentTerminalId;
|
|
8072
8166
|
const indicator = tabIndicator(tab);
|
|
8073
8167
|
const appRunnerRun = tabAppRunnerRunningRun(tab);
|
|
8074
8168
|
const appRunnerLabel = appRunnerRun ? terminalAppRunnerLabel(appRunnerRun) : "";
|
|
@@ -8108,7 +8202,7 @@ function renderTerminalTab(tab) {
|
|
|
8108
8202
|
}
|
|
8109
8203
|
|
|
8110
8204
|
function renderTerminalTabGroupItem(tab, group) {
|
|
8111
|
-
const isActive = tab.id === activeTabId;
|
|
8205
|
+
const isActive = tab.id === activeTabId && !activeSubagentTerminalId;
|
|
8112
8206
|
const indicator = tabIndicator(tab);
|
|
8113
8207
|
const appRunnerRun = tabAppRunnerRunningRun(tab);
|
|
8114
8208
|
const appRunnerLabel = appRunnerRun ? terminalAppRunnerLabel(appRunnerRun) : "";
|
|
@@ -8158,7 +8252,7 @@ function shouldRenderTerminalTabGroup(group, groupCount) {
|
|
|
8158
8252
|
function renderTerminalTabGroup(group, groupCount = 1) {
|
|
8159
8253
|
const groupTabs = group.tabs;
|
|
8160
8254
|
const activeGroupTab = groupTabs.find((tab) => tab.id === activeTabId) || groupTabs[0];
|
|
8161
|
-
const isActive = groupTabs.some((tab) => tab.id === activeTabId);
|
|
8255
|
+
const isActive = !activeSubagentTerminalId && groupTabs.some((tab) => tab.id === activeTabId);
|
|
8162
8256
|
const isStopped = groupTabs.every((tab) => !tab.running);
|
|
8163
8257
|
const indicator = tabGroupIndicator(groupTabs);
|
|
8164
8258
|
const appRunnerRun = tabGroupAppRunnerRunningRun(groupTabs);
|
|
@@ -8301,15 +8395,18 @@ function scheduleTabsRender() {
|
|
|
8301
8395
|
|
|
8302
8396
|
function renderTabs() {
|
|
8303
8397
|
if (deferUiRenderDuringPointerActivation("tabs", renderTabs)) return;
|
|
8304
|
-
const
|
|
8305
|
-
const
|
|
8306
|
-
|
|
8307
|
-
const
|
|
8398
|
+
const activeSubagent = activeSubagentTerminalView();
|
|
8399
|
+
const active = activeSubagent || activeTab();
|
|
8400
|
+
const activeIndicator = activeSubagent ? { glyph: "◉", label: "Subagent view" } : active ? tabIndicator(active) : null;
|
|
8401
|
+
const activeTitle = activeSubagent ? subagentTerminalViewTitle(activeSubagent) : active?.title;
|
|
8402
|
+
const totalTabCount = tabs.length + subagentTerminalViews.size;
|
|
8403
|
+
elements.terminalTabsToggleButton.textContent = active ? `${activeIndicator.glyph} ${activeTitle}${totalTabCount > 1 ? ` · ${totalTabCount}` : ""}` : "Tabs";
|
|
8404
|
+
const toggleTooltip = active ? `Show terminal tabs · active: ${activeTitle} · ${activeIndicator.label}` : "Show terminal tabs";
|
|
8308
8405
|
applyStyledTooltip(elements.terminalTabsToggleButton, toggleTooltip, { ariaLabel: toggleTooltip });
|
|
8309
8406
|
if (footerTooltipTarget && elements.tabBar.contains(footerTooltipTarget)) hideFooterTooltip();
|
|
8310
8407
|
elements.tabBar.replaceChildren();
|
|
8311
|
-
elements.tabBar.dataset.tabCount = String(
|
|
8312
|
-
elements.tabBar.classList.toggle("terminal-tabs-dense",
|
|
8408
|
+
elements.tabBar.dataset.tabCount = String(totalTabCount);
|
|
8409
|
+
elements.tabBar.classList.toggle("terminal-tabs-dense", totalTabCount >= 10);
|
|
8313
8410
|
const groups = tabCwdGroups();
|
|
8314
8411
|
const renderedGroupKeys = new Set(groups.filter((group) => shouldRenderTerminalTabGroup(group, groups.length)).map((group) => group.key));
|
|
8315
8412
|
if (openTerminalTabGroupKey && !renderedGroupKeys.has(openTerminalTabGroupKey)) openTerminalTabGroupKey = null;
|
|
@@ -8320,6 +8417,9 @@ function renderTabs() {
|
|
|
8320
8417
|
for (const tab of group.tabs) elements.tabBar.append(renderTerminalTab(tab));
|
|
8321
8418
|
}
|
|
8322
8419
|
}
|
|
8420
|
+
for (const view of [...subagentTerminalViews.values()].sort((a, b) => a.openedAt - b.openedAt)) {
|
|
8421
|
+
elements.tabBar.append(renderSubagentTerminalTab(view));
|
|
8422
|
+
}
|
|
8323
8423
|
elements.tabBar.append(elements.newTabMenu);
|
|
8324
8424
|
elements.closeAllTabsButton.disabled = tabs.length === 0;
|
|
8325
8425
|
updateTerminalTabGroupOpenState();
|
|
@@ -8337,6 +8437,10 @@ async function refreshTabs({ selectStored = false } = {}) {
|
|
|
8337
8437
|
const response = await api("/api/tabs", { scoped: false });
|
|
8338
8438
|
tabs = response.data?.tabs || [];
|
|
8339
8439
|
syncTabMetadata(tabs);
|
|
8440
|
+
const liveParentTabIds = new Set(tabs.map((tab) => tab.id));
|
|
8441
|
+
for (const view of [...subagentTerminalViews.values()]) {
|
|
8442
|
+
if (!liveParentTabIds.has(view.parentTabId)) removeSubagentTerminalViewsForParent(view.parentTabId);
|
|
8443
|
+
}
|
|
8340
8444
|
syncBlockedTabNotificationsFromTabs(tabs, previousTabs);
|
|
8341
8445
|
syncAgentDoneNotificationsFromTabs(tabs, previousTabs);
|
|
8342
8446
|
const requested = selectStored ? requestedTabIdFromUrl() : null;
|
|
@@ -8351,7 +8455,12 @@ async function refreshTabs({ selectStored = false } = {}) {
|
|
|
8351
8455
|
}
|
|
8352
8456
|
|
|
8353
8457
|
async function switchTab(tabId) {
|
|
8354
|
-
if (!tabId ||
|
|
8458
|
+
if (!tabId || !tabs.some((tab) => tab.id === tabId)) return;
|
|
8459
|
+
if (tabId === activeTabId) {
|
|
8460
|
+
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ focusParent: true });
|
|
8461
|
+
return;
|
|
8462
|
+
}
|
|
8463
|
+
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ render: false });
|
|
8355
8464
|
clearOpenTerminalTabGroup(null, { force: true });
|
|
8356
8465
|
setMobileTabsExpanded(false);
|
|
8357
8466
|
footerModelPickerOpen = false;
|
|
@@ -8581,6 +8690,7 @@ async function closeTerminalTabs(tabIds, { label = "selected terminal tabs" } =
|
|
|
8581
8690
|
appRunnerDataByTab.delete(id);
|
|
8582
8691
|
tabMessagesCache.delete(id);
|
|
8583
8692
|
btwWidgetDismissedIdsByTab.delete(id);
|
|
8693
|
+
removeSubagentTerminalViewsForParent(id);
|
|
8584
8694
|
}
|
|
8585
8695
|
syncTerminalCustomGroupsWithTabs(tabs);
|
|
8586
8696
|
clearOpenTerminalTabGroup(null, { force: true });
|
|
@@ -12851,8 +12961,8 @@ function footerBranchCreateWorktreePathPreview(branch = footerBranchCreateName()
|
|
|
12851
12961
|
return `${root.replace(/\/+$/, "")}/${slugifyWorktreePathPart(branch || footerBranchCreatePreviewName())}`;
|
|
12852
12962
|
}
|
|
12853
12963
|
|
|
12854
|
-
function gitWorktreeCreateCommandDisplay(branch, state = footerBranchPickerState) {
|
|
12855
|
-
return `git worktree add -b ${quoteGitBranchForDisplay(branch)} ${quoteGitBranchForDisplay(footerBranchCreateWorktreePathPreview(branch, state))}`;
|
|
12964
|
+
function gitWorktreeCreateCommandDisplay(branch, state = footerBranchPickerState, baseRef = "origin/main") {
|
|
12965
|
+
return `git worktree add -b ${quoteGitBranchForDisplay(branch)} ${quoteGitBranchForDisplay(footerBranchCreateWorktreePathPreview(branch, state))} ${quoteGitBranchForDisplay(baseRef)}`;
|
|
12856
12966
|
}
|
|
12857
12967
|
|
|
12858
12968
|
function gitWorktreeOpenCommandDisplay(path) {
|
|
@@ -12868,7 +12978,7 @@ function footerBranchCreateTooltip(branchName = footerBranchCreateName(), state
|
|
|
12868
12978
|
`This will run roughly: ${command}`,
|
|
12869
12979
|
"",
|
|
12870
12980
|
"What happens:",
|
|
12871
|
-
"•
|
|
12981
|
+
"• asks whether to base the new branch on origin/main (default) or this workspace's current HEAD",
|
|
12872
12982
|
"• opens a separate Pi tab rooted at that worktree",
|
|
12873
12983
|
"• does not switch this tab's branch, commit, push, or delete anything",
|
|
12874
12984
|
"",
|
|
@@ -12910,18 +13020,20 @@ async function openWorktreeResponseTab(response, { branchName = "", action = "op
|
|
|
12910
13020
|
requestGitFooterWebuiPayload(activeTabContext(), { force: true });
|
|
12911
13021
|
}
|
|
12912
13022
|
|
|
12913
|
-
async function createFooterGitBranchWorktree(branch = footerBranchCreateName(), { tabContext = activeTabContext(), skipConfirm = false } = {}) {
|
|
13023
|
+
async function createFooterGitBranchWorktree(branch = footerBranchCreateName(), { tabContext = activeTabContext(), skipConfirm = false, chooseBase = true } = {}) {
|
|
12914
13024
|
const branchName = cleanStatusText(branch);
|
|
12915
13025
|
if (!branchName) {
|
|
12916
13026
|
addEvent("Enter a branch name before creating a branch worktree.", "warn");
|
|
12917
13027
|
return;
|
|
12918
13028
|
}
|
|
12919
13029
|
if (!skipConfirm && !(await confirmFooterGitWorktreeAction(branchName, { create: true, requireConfirm: true }))) return;
|
|
13030
|
+
const baseRef = chooseBase ? await chooseGitWorktreeBase(branchName) : "HEAD";
|
|
13031
|
+
if (baseRef === null) return;
|
|
12920
13032
|
const tabId = tabContext.tabId || activeTabId;
|
|
12921
13033
|
try {
|
|
12922
13034
|
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "", switching: branchName, tabId };
|
|
12923
13035
|
renderFooter();
|
|
12924
|
-
const response = await api("/api/git-worktrees", { method: "POST", body: { branchName, sessionMode: "fork-current", openTab: true }, tabId });
|
|
13036
|
+
const response = await api("/api/git-worktrees", { method: "POST", body: { branchName, baseRef, sessionMode: "fork-current", openTab: true }, tabId });
|
|
12925
13037
|
await openWorktreeResponseTab(response, { branchName, action: "create" });
|
|
12926
13038
|
} catch (error) {
|
|
12927
13039
|
if (isCurrentTabContext(tabContext)) {
|
|
@@ -13120,7 +13232,7 @@ function footerBranchOptionDetail(branch, state, { selected, worktreePath } = {}
|
|
|
13120
13232
|
function openFooterBranchOption(branch, state = footerBranchPickerState) {
|
|
13121
13233
|
const worktreePath = footerBranchWorktreePath(branch, state);
|
|
13122
13234
|
if (worktreePath && !branch.worktreeCurrent) return openFooterGitWorktree(worktreePath, { branchName: branch.name, skipConfirm: true });
|
|
13123
|
-
return createFooterGitBranchWorktree(branch.name, { skipConfirm: true });
|
|
13235
|
+
return createFooterGitBranchWorktree(branch.name, { skipConfirm: true, chooseBase: false });
|
|
13124
13236
|
}
|
|
13125
13237
|
|
|
13126
13238
|
function renderFooterBranchOption(branch, state = footerBranchPickerState) {
|
|
@@ -13275,7 +13387,7 @@ function renderFooterBranchPicker() {
|
|
|
13275
13387
|
const hasOtherBranches = state.branches.some((branch) => !branch.current && branch.name !== state.current);
|
|
13276
13388
|
if (!state.loading && !hasOtherBranches) {
|
|
13277
13389
|
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."));
|
|
13390
|
+
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
13391
|
picker.append(empty);
|
|
13280
13392
|
}
|
|
13281
13393
|
|
|
@@ -14412,20 +14524,42 @@ function subagentOverlayEmptyTranscriptText(messages) {
|
|
|
14412
14524
|
: "No visible output was captured.";
|
|
14413
14525
|
}
|
|
14414
14526
|
|
|
14415
|
-
function
|
|
14416
|
-
const
|
|
14527
|
+
function subagentRunIndicatorActivity(agent = {}) {
|
|
14528
|
+
const currentTool = cleanStatusText(agent.currentTool || "");
|
|
14529
|
+
const currentToolArgs = cleanStatusText(agent.currentToolArgs || "");
|
|
14530
|
+
const activityState = cleanStatusText(agent.activityState || "");
|
|
14531
|
+
return currentTool
|
|
14532
|
+
? `${currentTool}${currentToolArgs ? ` · ${currentToolArgs}` : ""}`
|
|
14533
|
+
: activityState || "Waiting for output or action…";
|
|
14534
|
+
}
|
|
14535
|
+
|
|
14536
|
+
function updateSubagentRunIndicatorElapsed(parent, run) {
|
|
14537
|
+
const elapsedNode = parent?.querySelector?.(".subagent-run-indicator-elapsed");
|
|
14538
|
+
if (!elapsedNode) return false;
|
|
14539
|
+
const elapsed = subagentRunElapsed(run);
|
|
14540
|
+
const text = elapsed ? `· run time ${elapsed}` : "";
|
|
14541
|
+
if (elapsedNode.textContent !== text) elapsedNode.textContent = text;
|
|
14542
|
+
return true;
|
|
14543
|
+
}
|
|
14544
|
+
|
|
14545
|
+
function appendSubagentRunIndicator(parent, { agent = {}, run } = {}) {
|
|
14546
|
+
const bubble = make("article", "message runIndicator run-indicator-message streaming subagent-run-indicator");
|
|
14417
14547
|
bubble.setAttribute("role", "status");
|
|
14418
|
-
bubble.setAttribute("aria-
|
|
14548
|
+
bubble.setAttribute("aria-live", "polite");
|
|
14549
|
+
bubble.setAttribute("aria-label", "Agent is running:");
|
|
14419
14550
|
const body = make("div", "message-body");
|
|
14420
14551
|
const row = make("div", "run-indicator-row");
|
|
14421
|
-
|
|
14422
|
-
|
|
14423
|
-
|
|
14424
|
-
|
|
14425
|
-
);
|
|
14552
|
+
const pulse = make("span", "run-indicator-pulse");
|
|
14553
|
+
pulse.setAttribute("aria-hidden", "true");
|
|
14554
|
+
const headline = make("span", "run-indicator-text", "Agent is running:");
|
|
14555
|
+
const activity = make("span", "run-indicator-meta", subagentRunIndicatorActivity(agent));
|
|
14556
|
+
const elapsed = make("span", "run-indicator-meta subagent-run-indicator-elapsed");
|
|
14557
|
+
elapsed.setAttribute("aria-hidden", "true");
|
|
14558
|
+
row.append(pulse, headline, activity, elapsed);
|
|
14426
14559
|
body.append(row);
|
|
14427
14560
|
bubble.append(body);
|
|
14428
14561
|
parent.append(bubble);
|
|
14562
|
+
updateSubagentRunIndicatorElapsed(parent, run);
|
|
14429
14563
|
}
|
|
14430
14564
|
|
|
14431
14565
|
function appendSubagentOverlayTranscript(parent, messages) {
|
|
@@ -14534,7 +14668,7 @@ function renderSubagentOverlayWidget() {
|
|
|
14534
14668
|
bubble.classList.add("subagent-overlay-message", "subagent-overlay-empty-fallback");
|
|
14535
14669
|
output.append(bubble);
|
|
14536
14670
|
}
|
|
14537
|
-
if (running
|
|
14671
|
+
if (running) appendSubagentRunIndicator(output, { agent, run: selection.run });
|
|
14538
14672
|
|
|
14539
14673
|
const controls = make("div", "release-npm-controls subagent-overlay-output-controls");
|
|
14540
14674
|
const actions = make("div", "app-runner-output-actions");
|
|
@@ -14595,6 +14729,7 @@ async function refreshSubagentOverlay() {
|
|
|
14595
14729
|
|
|
14596
14730
|
async function openSubagentOverlay(tab, run, agent) {
|
|
14597
14731
|
if (!tab?.tabId || !run?.id || !agent?.id) return;
|
|
14732
|
+
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ render: false });
|
|
14598
14733
|
try {
|
|
14599
14734
|
if (activeTabId !== tab.tabId) await switchTab(tab.tabId);
|
|
14600
14735
|
subagentOverlaySelection = {
|
|
@@ -14643,6 +14778,275 @@ async function copySubagentOverlayOutput() {
|
|
|
14643
14778
|
}
|
|
14644
14779
|
}
|
|
14645
14780
|
|
|
14781
|
+
function subagentTerminalViewId(tab, run, agent) {
|
|
14782
|
+
return JSON.stringify([tab?.tabId || "", run?.id || "", agent?.id || ""]);
|
|
14783
|
+
}
|
|
14784
|
+
|
|
14785
|
+
function activeSubagentTerminalView() {
|
|
14786
|
+
return activeSubagentTerminalId ? subagentTerminalViews.get(activeSubagentTerminalId) || null : null;
|
|
14787
|
+
}
|
|
14788
|
+
|
|
14789
|
+
function subagentTerminalViewTitle(view) {
|
|
14790
|
+
return String(view?.data?.agent?.name || view?.agent?.name || "subagent").trim() || "subagent";
|
|
14791
|
+
}
|
|
14792
|
+
|
|
14793
|
+
function subagentTerminalViewIsRunning(view) {
|
|
14794
|
+
const status = view?.data?.agent?.status || view?.agent?.status || "running";
|
|
14795
|
+
return view?.finished !== true && ["running", "queued", "pending"].includes(status);
|
|
14796
|
+
}
|
|
14797
|
+
|
|
14798
|
+
function subagentTerminalViewMeaningfulSignature(view) {
|
|
14799
|
+
const data = view?.data ? { ...view.data, updatedAt: undefined } : null;
|
|
14800
|
+
return JSON.stringify({ data, error: view?.error || "", finished: view?.finished === true });
|
|
14801
|
+
}
|
|
14802
|
+
|
|
14803
|
+
function updateSubagentTerminalRefreshState(view, { running = subagentTerminalViewIsRunning(view) } = {}) {
|
|
14804
|
+
if (!view || view.id !== activeSubagentTerminalId) return;
|
|
14805
|
+
const status = [
|
|
14806
|
+
view.loading ? "Refreshing…" : running ? "Live view · refreshes automatically" : "View retained after the child stopped being tracked",
|
|
14807
|
+
view.error,
|
|
14808
|
+
].filter(Boolean).join(" · ");
|
|
14809
|
+
elements.subagentTerminalStatus.setAttribute("aria-live", view.error ? "polite" : "off");
|
|
14810
|
+
elements.subagentTerminalStatus.textContent = status;
|
|
14811
|
+
elements.subagentTerminalStatus.classList.toggle("warning", !!view.error);
|
|
14812
|
+
elements.subagentTerminalRefreshButton.disabled = view.loading || view.finished === true;
|
|
14813
|
+
elements.subagentTerminalRefreshButton.textContent = view.loading ? "Refreshing…" : "Refresh";
|
|
14814
|
+
}
|
|
14815
|
+
|
|
14816
|
+
function renderSubagentTerminalView() {
|
|
14817
|
+
const view = activeSubagentTerminalView();
|
|
14818
|
+
const active = !!view;
|
|
14819
|
+
document.body.classList.toggle("subagent-terminal-active", active);
|
|
14820
|
+
if (!elements.subagentTerminalView) return;
|
|
14821
|
+
elements.subagentTerminalView.hidden = !active;
|
|
14822
|
+
if (!view) return;
|
|
14823
|
+
|
|
14824
|
+
const agent = view.data?.agent || view.agent || {};
|
|
14825
|
+
const running = subagentTerminalViewIsRunning(view);
|
|
14826
|
+
const transcriptMessages = subagentOverlayTranscriptMessages({ agent });
|
|
14827
|
+
const hasStructuredTranscript = transcriptMessages.length > 0;
|
|
14828
|
+
const outputText = subagentOverlayOutputText({ agent });
|
|
14829
|
+
const fallbackText = outputText || (running && agent.currentTool ? "" : running ? "Waiting for the first agent activity…" : "No recent output was captured.");
|
|
14830
|
+
const parent = tabs.find((tab) => tab.id === view.parentTabId);
|
|
14831
|
+
const facts = [
|
|
14832
|
+
view.finished ? "finished" : running ? "running" : agent.status || "finished",
|
|
14833
|
+
view.run?.mode,
|
|
14834
|
+
view.run?.source === "foreground" ? "foreground" : "async",
|
|
14835
|
+
agent.nested ? "nested" : "",
|
|
14836
|
+
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
14837
|
+
].filter(Boolean);
|
|
14838
|
+
|
|
14839
|
+
elements.subagentTerminalTitle.textContent = subagentTerminalViewTitle(view);
|
|
14840
|
+
elements.subagentTerminalMeta.textContent = `${facts.join(" · ")} · parent ${parent?.title || view.parentTitle || "terminal"} · run ${view.runId}`;
|
|
14841
|
+
const shouldFollowOutput = elements.subagentTerminalTranscript.scrollHeight - elements.subagentTerminalTranscript.clientHeight - elements.subagentTerminalTranscript.scrollTop < CHAT_BOTTOM_THRESHOLD_PX;
|
|
14842
|
+
elements.subagentTerminalTranscript.replaceChildren();
|
|
14843
|
+
elements.subagentTerminalTranscript.setAttribute("aria-live", running ? "polite" : "off");
|
|
14844
|
+
const rendered = appendSubagentOverlayTranscript(elements.subagentTerminalTranscript, transcriptMessages);
|
|
14845
|
+
const emptyTranscriptFallback = hasStructuredTranscript && rendered === 0 ? subagentOverlayEmptyTranscriptText(transcriptMessages) : "";
|
|
14846
|
+
const visibleFallbackText = !hasStructuredTranscript ? fallbackText : emptyTranscriptFallback;
|
|
14847
|
+
if (visibleFallbackText) {
|
|
14848
|
+
const { bubble } = createMessageBubble({
|
|
14849
|
+
role: "assistant",
|
|
14850
|
+
title: "subagent output",
|
|
14851
|
+
timestamp: view.data?.updatedAt || Date.now(),
|
|
14852
|
+
content: visibleFallbackText,
|
|
14853
|
+
}, { streaming: running && !hasStructuredTranscript, transient: true });
|
|
14854
|
+
bubble.classList.add("subagent-overlay-message", "subagent-overlay-empty-fallback");
|
|
14855
|
+
elements.subagentTerminalTranscript.append(bubble);
|
|
14856
|
+
}
|
|
14857
|
+
if (running) appendSubagentRunIndicator(elements.subagentTerminalTranscript, { agent, run: view.run });
|
|
14858
|
+
|
|
14859
|
+
updateSubagentTerminalRefreshState(view, { running });
|
|
14860
|
+
elements.subagentTerminalCopyButton.disabled = !outputText;
|
|
14861
|
+
if (shouldFollowOutput) requestAnimationFrame(() => { elements.subagentTerminalTranscript.scrollTop = elements.subagentTerminalTranscript.scrollHeight; });
|
|
14862
|
+
}
|
|
14863
|
+
|
|
14864
|
+
function scheduleSubagentTerminalRefresh(delay = SUBAGENT_OVERLAY_REFRESH_MS) {
|
|
14865
|
+
clearTimeout(subagentTerminalRefreshTimer);
|
|
14866
|
+
const view = activeSubagentTerminalView();
|
|
14867
|
+
if (!view || view.finished) return;
|
|
14868
|
+
subagentTerminalRefreshTimer = setTimeout(() => {
|
|
14869
|
+
refreshSubagentTerminalView(view.id).finally(() => scheduleSubagentTerminalRefresh());
|
|
14870
|
+
}, delay);
|
|
14871
|
+
}
|
|
14872
|
+
|
|
14873
|
+
async function refreshSubagentTerminalView(viewId = activeSubagentTerminalId, { showLoading = false } = {}) {
|
|
14874
|
+
const view = viewId ? subagentTerminalViews.get(viewId) : null;
|
|
14875
|
+
if (!view || view.loading || view.finished) return;
|
|
14876
|
+
const requestSerial = (view.requestSerial || 0) + 1;
|
|
14877
|
+
const previousSignature = subagentTerminalViewMeaningfulSignature(view);
|
|
14878
|
+
view.requestSerial = requestSerial;
|
|
14879
|
+
view.loading = true;
|
|
14880
|
+
if (showLoading) updateSubagentTerminalRefreshState(view);
|
|
14881
|
+
try {
|
|
14882
|
+
const query = new URLSearchParams({ tab: view.parentTabId, run: view.runId, agent: view.agentId });
|
|
14883
|
+
const response = await api(`/api/subagents/output?${query}`, { scoped: false });
|
|
14884
|
+
if (view.requestSerial !== requestSerial || !subagentTerminalViews.has(view.id)) return;
|
|
14885
|
+
view.data = response.data || null;
|
|
14886
|
+
view.error = "";
|
|
14887
|
+
} catch (error) {
|
|
14888
|
+
if (view.requestSerial !== requestSerial || !subagentTerminalViews.has(view.id)) return;
|
|
14889
|
+
if (error?.statusCode === 404) view.finished = true;
|
|
14890
|
+
view.error = error?.statusCode === 404
|
|
14891
|
+
? "This subagent has finished or is no longer tracked. Showing the last captured output."
|
|
14892
|
+
: `Subagent output refresh failed: ${error.message || String(error)}`;
|
|
14893
|
+
} finally {
|
|
14894
|
+
if (view.requestSerial === requestSerial && subagentTerminalViews.has(view.id)) {
|
|
14895
|
+
view.loading = false;
|
|
14896
|
+
const meaningfulChange = previousSignature !== subagentTerminalViewMeaningfulSignature(view);
|
|
14897
|
+
if (view.id === activeSubagentTerminalId) {
|
|
14898
|
+
if (meaningfulChange) {
|
|
14899
|
+
renderSubagentTerminalView();
|
|
14900
|
+
renderTabs();
|
|
14901
|
+
} else {
|
|
14902
|
+
if (showLoading) updateSubagentTerminalRefreshState(view);
|
|
14903
|
+
updateSubagentRunIndicatorElapsed(elements.subagentTerminalTranscript, view.run);
|
|
14904
|
+
}
|
|
14905
|
+
}
|
|
14906
|
+
}
|
|
14907
|
+
}
|
|
14908
|
+
}
|
|
14909
|
+
|
|
14910
|
+
function deactivateSubagentTerminalView({ render = true, focusParent = false } = {}) {
|
|
14911
|
+
clearTimeout(subagentTerminalRefreshTimer);
|
|
14912
|
+
subagentTerminalRefreshTimer = null;
|
|
14913
|
+
activeSubagentTerminalId = null;
|
|
14914
|
+
renderSubagentTerminalView();
|
|
14915
|
+
if (render) renderTabs();
|
|
14916
|
+
updateDocumentTitle();
|
|
14917
|
+
if (focusParent) focusPromptInput({ defer: true });
|
|
14918
|
+
}
|
|
14919
|
+
|
|
14920
|
+
async function activateSubagentTerminalView(viewId) {
|
|
14921
|
+
const view = subagentTerminalViews.get(viewId);
|
|
14922
|
+
if (!view) return;
|
|
14923
|
+
if (activeTabId !== view.parentTabId) await switchTab(view.parentTabId);
|
|
14924
|
+
closeSubagentOverlay();
|
|
14925
|
+
activeSubagentTerminalId = view.id;
|
|
14926
|
+
renderSubagentTerminalView();
|
|
14927
|
+
renderTabs();
|
|
14928
|
+
updateDocumentTitle();
|
|
14929
|
+
if (isSidePanelOverlayView()) setSidePanelCollapsed(true, { persist: false });
|
|
14930
|
+
await refreshSubagentTerminalView(view.id);
|
|
14931
|
+
scheduleSubagentTerminalRefresh();
|
|
14932
|
+
}
|
|
14933
|
+
|
|
14934
|
+
async function openSubagentTerminal(tab, run, agent) {
|
|
14935
|
+
if (!tab?.tabId || !run?.id || !agent?.id) return;
|
|
14936
|
+
const id = subagentTerminalViewId(tab, run, agent);
|
|
14937
|
+
const existing = subagentTerminalViews.get(id);
|
|
14938
|
+
if (existing) {
|
|
14939
|
+
existing.tab = tab;
|
|
14940
|
+
existing.run = run;
|
|
14941
|
+
existing.agent = agent;
|
|
14942
|
+
existing.parentTitle = tab.tabTitle;
|
|
14943
|
+
} else {
|
|
14944
|
+
subagentTerminalViews.set(id, {
|
|
14945
|
+
id,
|
|
14946
|
+
parentTabId: tab.tabId,
|
|
14947
|
+
parentTitle: tab.tabTitle,
|
|
14948
|
+
tabIndex: tab.tabIndex,
|
|
14949
|
+
tab,
|
|
14950
|
+
run,
|
|
14951
|
+
agent,
|
|
14952
|
+
runId: run.id,
|
|
14953
|
+
agentId: agent.id,
|
|
14954
|
+
data: null,
|
|
14955
|
+
error: "",
|
|
14956
|
+
loading: false,
|
|
14957
|
+
finished: false,
|
|
14958
|
+
requestSerial: 0,
|
|
14959
|
+
openedAt: Date.now(),
|
|
14960
|
+
});
|
|
14961
|
+
}
|
|
14962
|
+
try {
|
|
14963
|
+
await activateSubagentTerminalView(id);
|
|
14964
|
+
} catch (error) {
|
|
14965
|
+
addEvent(`could not open subagent terminal: ${error.message || String(error)}`, "error");
|
|
14966
|
+
}
|
|
14967
|
+
}
|
|
14968
|
+
|
|
14969
|
+
function closeSubagentTerminalTab(viewId) {
|
|
14970
|
+
const view = subagentTerminalViews.get(viewId);
|
|
14971
|
+
if (!view) return;
|
|
14972
|
+
view.requestSerial += 1;
|
|
14973
|
+
subagentTerminalViews.delete(viewId);
|
|
14974
|
+
if (activeSubagentTerminalId === viewId) deactivateSubagentTerminalView({ render: false, focusParent: true });
|
|
14975
|
+
renderTabs();
|
|
14976
|
+
addEvent(`closed subagent view for ${subagentTerminalViewTitle(view)}; the child run was not stopped`, "info");
|
|
14977
|
+
}
|
|
14978
|
+
|
|
14979
|
+
async function copySubagentTerminalOutput() {
|
|
14980
|
+
const view = activeSubagentTerminalView();
|
|
14981
|
+
const text = view ? subagentOverlayOutputText(view.data || { agent: view.agent }) : "";
|
|
14982
|
+
if (!text) {
|
|
14983
|
+
addEvent("subagent output is empty", "warn");
|
|
14984
|
+
return;
|
|
14985
|
+
}
|
|
14986
|
+
try {
|
|
14987
|
+
await copyText(text);
|
|
14988
|
+
addEvent("copied subagent output", "info");
|
|
14989
|
+
} catch (error) {
|
|
14990
|
+
addEvent(`subagent output copy failed: ${error.message || String(error)}`, "warn");
|
|
14991
|
+
}
|
|
14992
|
+
}
|
|
14993
|
+
|
|
14994
|
+
function removeSubagentTerminalViewsForParent(parentTabId) {
|
|
14995
|
+
for (const [viewId, view] of subagentTerminalViews) {
|
|
14996
|
+
if (view.parentTabId !== parentTabId) continue;
|
|
14997
|
+
view.requestSerial += 1;
|
|
14998
|
+
subagentTerminalViews.delete(viewId);
|
|
14999
|
+
if (activeSubagentTerminalId === viewId) deactivateSubagentTerminalView({ render: false });
|
|
15000
|
+
}
|
|
15001
|
+
}
|
|
15002
|
+
|
|
15003
|
+
function syncSubagentTerminalViewsFromOverview() {
|
|
15004
|
+
for (const view of subagentTerminalViews.values()) {
|
|
15005
|
+
const tab = (Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : []).find((candidate) => candidate.tabId === view.parentTabId);
|
|
15006
|
+
const run = (Array.isArray(tab?.runs) ? tab.runs : []).find((candidate) => candidate.id === view.runId);
|
|
15007
|
+
const agent = (Array.isArray(run?.agents) ? run.agents : []).find((candidate) => candidate.id === view.agentId);
|
|
15008
|
+
if (tab) {
|
|
15009
|
+
view.tab = tab;
|
|
15010
|
+
view.parentTitle = tab.tabTitle;
|
|
15011
|
+
}
|
|
15012
|
+
if (run) view.run = run;
|
|
15013
|
+
if (agent) view.agent = agent;
|
|
15014
|
+
}
|
|
15015
|
+
}
|
|
15016
|
+
|
|
15017
|
+
function renderSubagentTerminalTab(view) {
|
|
15018
|
+
const active = view.id === activeSubagentTerminalId;
|
|
15019
|
+
const running = subagentTerminalViewIsRunning(view);
|
|
15020
|
+
const stateClass = running ? "activity-working" : view.error && !view.data ? "stopped" : "activity-done";
|
|
15021
|
+
const wrapper = make("div", `terminal-tab terminal-tab-subagent ${stateClass}${active ? " active" : ""}`);
|
|
15022
|
+
wrapper.dataset.subagentViewId = view.id;
|
|
15023
|
+
const button = make("button", "terminal-tab-button");
|
|
15024
|
+
button.type = "button";
|
|
15025
|
+
button.setAttribute("role", "tab");
|
|
15026
|
+
button.setAttribute("aria-selected", active ? "true" : "false");
|
|
15027
|
+
button.setAttribute("aria-label", `${subagentTerminalViewTitle(view)} subagent view, parent ${view.parentTitle || "terminal"}`);
|
|
15028
|
+
appendTerminalTabContent(button, {
|
|
15029
|
+
title: subagentTerminalViewTitle(view),
|
|
15030
|
+
indicator: { state: running ? "working" : "done" },
|
|
15031
|
+
meta: `Subagent · ${view.parentTitle || "parent terminal"}`,
|
|
15032
|
+
subagent: true,
|
|
15033
|
+
});
|
|
15034
|
+
button.addEventListener("click", () => activateSubagentTerminalView(view.id));
|
|
15035
|
+
const close = make("button", "terminal-tab-close", "×");
|
|
15036
|
+
close.type = "button";
|
|
15037
|
+
applyStyledTooltip(close, `Close ${subagentTerminalViewTitle(view)} view without stopping the subagent`, { ariaLabel: `Close ${subagentTerminalViewTitle(view)} subagent view` });
|
|
15038
|
+
close.addEventListener("click", (event) => {
|
|
15039
|
+
event.stopPropagation();
|
|
15040
|
+
closeSubagentTerminalTab(view.id);
|
|
15041
|
+
});
|
|
15042
|
+
wrapper.append(button, close);
|
|
15043
|
+
return wrapper;
|
|
15044
|
+
}
|
|
15045
|
+
|
|
15046
|
+
function openSubagentOutput(tab, run, agent) {
|
|
15047
|
+
return subagentOpenMode === "tab" ? openSubagentTerminal(tab, run, agent) : openSubagentOverlay(tab, run, agent);
|
|
15048
|
+
}
|
|
15049
|
+
|
|
14646
15050
|
function renderSubagentAgent(tab, run, agent) {
|
|
14647
15051
|
const row = make("button", `subagent-agent-row${agent?.nested ? " nested" : ""}`);
|
|
14648
15052
|
row.type = "button";
|
|
@@ -14660,9 +15064,10 @@ function renderSubagentAgent(tab, run, agent) {
|
|
|
14660
15064
|
].filter(Boolean);
|
|
14661
15065
|
content.append(make("span", "subagent-agent-meta", facts.join(" · ")));
|
|
14662
15066
|
row.append(dot, content);
|
|
14663
|
-
|
|
14664
|
-
row.
|
|
14665
|
-
row.
|
|
15067
|
+
const destination = subagentOpenMode === "tab" ? "subagent tab" : "live output overlay";
|
|
15068
|
+
row.title = `${agent?.name || "subagent"} · ${facts.join(" · ")} · run ${run?.id || "unknown"} · open ${destination}`;
|
|
15069
|
+
row.setAttribute("aria-label", `Open ${destination} for ${agent?.name || "subagent"} in ${tab?.tabTitle || `Terminal ${tab?.tabIndex || "?"}`}`);
|
|
15070
|
+
row.addEventListener("click", () => openSubagentOutput(tab, run, agent));
|
|
14666
15071
|
return row;
|
|
14667
15072
|
}
|
|
14668
15073
|
|
|
@@ -14729,6 +15134,7 @@ async function refreshSubagents() {
|
|
|
14729
15134
|
try {
|
|
14730
15135
|
const response = await api("/api/subagents", { scoped: false });
|
|
14731
15136
|
latestSubagents = response.data || null;
|
|
15137
|
+
syncSubagentTerminalViewsFromOverview();
|
|
14732
15138
|
subagentsError = null;
|
|
14733
15139
|
} catch (error) {
|
|
14734
15140
|
subagentsError = error;
|
|
@@ -19359,6 +19765,11 @@ async function createGitPrBranchWithSuggestion(suggestion, tabId = gitWorkflowAc
|
|
|
19359
19765
|
failGitWorkflow(new Error("Branch name is required to create a PR branch worktree."), "message", { tabId });
|
|
19360
19766
|
return;
|
|
19361
19767
|
}
|
|
19768
|
+
const baseRef = await chooseGitWorktreeBase(branch);
|
|
19769
|
+
if (baseRef === null) {
|
|
19770
|
+
setGitWorkflow({ step: "message", busy: false, output: `${formatCommitMessagePreview(sourceWorkflow.message)}\n\nPR branch worktree creation cancelled before choosing a base.` }, { tabId });
|
|
19771
|
+
return;
|
|
19772
|
+
}
|
|
19362
19773
|
let expectedStagedContentHash;
|
|
19363
19774
|
try {
|
|
19364
19775
|
expectedStagedContentHash = await assertGuidedGitStagedContentBinding(tabId, "PR worktree creation");
|
|
@@ -19369,7 +19780,7 @@ async function createGitPrBranchWithSuggestion(suggestion, tabId = gitWorkflowAc
|
|
|
19369
19780
|
const runId = workflow.runId;
|
|
19370
19781
|
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
19782
|
try {
|
|
19372
|
-
const result = await gitWorkflowRequest("/api/git-workflow/branch", { body: { branch, sessionMode: "fork-current", openTab: true, ...(expectedStagedContentHash ? { expectedStagedContentHash } : {}) }, runId, tabId });
|
|
19783
|
+
const result = await gitWorkflowRequest("/api/git-workflow/branch", { body: { branch, baseRef, sessionMode: "fork-current", openTab: true, ...(expectedStagedContentHash ? { expectedStagedContentHash } : {}) }, runId, tabId });
|
|
19373
19784
|
if (!result) return;
|
|
19374
19785
|
syncGitWorkflowWorktreeTabs(result);
|
|
19375
19786
|
const targetTabId = result.tab?.id && tabs.some((tab) => tab.id === result.tab.id) ? result.tab.id : tabId;
|
|
@@ -28606,6 +29017,19 @@ elements.confirmationDialog?.addEventListener("cancel", (event) => {
|
|
|
28606
29017
|
elements.confirmationDialog?.addEventListener("close", () => {
|
|
28607
29018
|
if (activeConfirmationResolve) finishApplicationConfirmation(false);
|
|
28608
29019
|
});
|
|
29020
|
+
elements.gitWorktreeBaseCancelButton?.addEventListener("click", () => finishGitWorktreeBaseChoice(null));
|
|
29021
|
+
elements.gitWorktreeBaseCreateButton?.addEventListener("click", () => finishGitWorktreeBaseChoice(elements.gitWorktreeBaseCurrentHead?.checked ? "HEAD" : "origin/main"));
|
|
29022
|
+
elements.gitWorktreeBaseDialog?.querySelector("form")?.addEventListener("submit", (event) => {
|
|
29023
|
+
event.preventDefault();
|
|
29024
|
+
finishGitWorktreeBaseChoice(elements.gitWorktreeBaseCurrentHead?.checked ? "HEAD" : "origin/main");
|
|
29025
|
+
});
|
|
29026
|
+
elements.gitWorktreeBaseDialog?.addEventListener("cancel", (event) => {
|
|
29027
|
+
event.preventDefault();
|
|
29028
|
+
finishGitWorktreeBaseChoice(null);
|
|
29029
|
+
});
|
|
29030
|
+
elements.gitWorktreeBaseDialog?.addEventListener("close", () => {
|
|
29031
|
+
if (activeGitWorktreeBaseResolve) finishGitWorktreeBaseChoice(null);
|
|
29032
|
+
});
|
|
28609
29033
|
elements.commandPaletteDialog?.querySelector("form")?.addEventListener("submit", (event) => event.preventDefault());
|
|
28610
29034
|
elements.commandPaletteDialog?.addEventListener("cancel", (event) => {
|
|
28611
29035
|
event.preventDefault();
|
|
@@ -29010,6 +29434,15 @@ if (elements.terminalTabsLayoutSelect) {
|
|
|
29010
29434
|
setTerminalTabsLayout(elements.terminalTabsLayoutSelect.value, { announce: true });
|
|
29011
29435
|
});
|
|
29012
29436
|
}
|
|
29437
|
+
if (elements.subagentOpenModeSelect) {
|
|
29438
|
+
elements.subagentOpenModeSelect.addEventListener("change", () => {
|
|
29439
|
+
setSubagentOpenMode(elements.subagentOpenModeSelect.value, { announce: true });
|
|
29440
|
+
});
|
|
29441
|
+
}
|
|
29442
|
+
elements.subagentTerminalCopyButton?.addEventListener("click", () => copySubagentTerminalOutput());
|
|
29443
|
+
elements.subagentTerminalRefreshButton?.addEventListener("click", () => {
|
|
29444
|
+
refreshSubagentTerminalView(activeSubagentTerminalId, { showLoading: true }).finally(() => scheduleSubagentTerminalRefresh());
|
|
29445
|
+
});
|
|
29013
29446
|
elements.piVersionButton?.addEventListener("click", () => {
|
|
29014
29447
|
openPiReleaseNotes().catch((error) => addEvent(error.message || String(error), "error"));
|
|
29015
29448
|
});
|
|
@@ -29619,6 +30052,7 @@ initializeFastPicks().catch((error) => addEvent(`failed to initialize path fast
|
|
|
29619
30052
|
restoreAgentDoneNotificationsSetting();
|
|
29620
30053
|
restoreThinkingVisibilitySetting();
|
|
29621
30054
|
restoreTerminalTabsLayoutSetting();
|
|
30055
|
+
restoreSubagentOpenModeSetting();
|
|
29622
30056
|
restoreTerminalCustomGroups();
|
|
29623
30057
|
restoreToolOutputExpansionSetting();
|
|
29624
30058
|
restoreWorkspaceDashboardState();
|