@firstpick/pi-package-webui 0.7.1 → 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 -1
- package/bin/pi-webui.mjs +243 -1
- package/index.ts +4 -0
- package/lib/subagent-gate.mjs +618 -0
- package/package.json +5 -4
- package/public/app.js +785 -50
- package/public/index.html +22 -1
- package/public/styles.css +388 -0
- 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 +51 -0
- package/tests/mobile-static.test.mjs +51 -2
- 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
|
@@ -203,6 +203,10 @@ const elements = {
|
|
|
203
203
|
fileTreeRefreshButton: $("#fileTreeRefreshButton"),
|
|
204
204
|
fileTreeSearchInput: $("#fileTreeSearchInput"),
|
|
205
205
|
fileTreeSearchClearButton: $("#fileTreeSearchClearButton"),
|
|
206
|
+
gitPanelGroups: $("#gitPanelGroups"),
|
|
207
|
+
gitPanelStatus: $("#gitPanelStatus"),
|
|
208
|
+
gitPanelCountBadge: $("#gitPanelCountBadge"),
|
|
209
|
+
gitPanelContextMenu: $("#gitPanelContextMenu"),
|
|
206
210
|
fileViewerPane: $("#fileViewerPane"),
|
|
207
211
|
fileViewerResizeHandle: $("#fileViewerResizeHandle"),
|
|
208
212
|
fileViewerTitle: $("#fileViewerTitle"),
|
|
@@ -413,8 +417,19 @@ let undoToastFocusReturn = null;
|
|
|
413
417
|
const modalSurfaceState = new WeakMap();
|
|
414
418
|
let activeDrawerModal = null;
|
|
415
419
|
let activeGitPrDialogResolve = null;
|
|
416
|
-
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 };
|
|
417
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;
|
|
418
433
|
let gitChangesRequestSerial = 0;
|
|
419
434
|
const gitChangesUntrackedContentRequests = new Set();
|
|
420
435
|
let nativeCommandTabId = null;
|
|
@@ -713,6 +728,7 @@ const AUR_REVIEW_RPC_PAYLOAD_TYPE = "firstpick.pi-extension-aur-review.review";
|
|
|
713
728
|
const AUR_REVIEW_RPC_PAYLOAD_VERSION = 3;
|
|
714
729
|
const GIT_CHANGES_RENDER_ROW_LIMIT = 4000;
|
|
715
730
|
const GIT_PULL_RESULT_FILE_LIMIT = 48;
|
|
731
|
+
const GIT_PANEL_CACHE_MAX_AGE_MS = 5 * 60 * 1000;
|
|
716
732
|
const LAST_USER_PROMPT_STORAGE_KEY = "pi-webui-last-user-prompts";
|
|
717
733
|
const PROMPT_HISTORY_STORAGE_KEY = "pi-webui-prompt-history";
|
|
718
734
|
const PROMPT_LIST_STORAGE_KEY = "pi-webui-prompt-lists";
|
|
@@ -1518,6 +1534,12 @@ function setSidePanelSectionCollapsed(record, collapsed, { persist = true } = {}
|
|
|
1518
1534
|
record.button.setAttribute("aria-expanded", collapsed ? "false" : "true");
|
|
1519
1535
|
record.button.setAttribute("aria-label", `${collapsed ? "Expand" : "Collapse"} ${label} section`);
|
|
1520
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
|
+
}
|
|
1521
1543
|
if (persist) persistSidePanelSectionState();
|
|
1522
1544
|
}
|
|
1523
1545
|
|
|
@@ -6611,6 +6633,7 @@ function showFileContextMenu(event, entry) {
|
|
|
6611
6633
|
if (!elements.fileContextMenu) return;
|
|
6612
6634
|
event.preventDefault();
|
|
6613
6635
|
event.stopPropagation();
|
|
6636
|
+
closeGitPanelContextMenu({ returnFocus: false });
|
|
6614
6637
|
const path = normalizeFileTreePath(entry?.path || "");
|
|
6615
6638
|
fileContextMenuState = { entry: { ...entry, path }, trigger: event.currentTarget || document.activeElement };
|
|
6616
6639
|
const menu = elements.fileContextMenu;
|
|
@@ -8089,6 +8112,583 @@ function terminalDisplayGroupDetail(group, fallback = "group") {
|
|
|
8089
8112
|
return `${cwdLabels[0]} + ${cwdLabels.length - 1} cwd${cwdLabels.length === 2 ? "" : "s"}`;
|
|
8090
8113
|
}
|
|
8091
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
|
+
|
|
8092
8692
|
function tabAppRunnerRun(tab) {
|
|
8093
8693
|
if (!tab?.id) return null;
|
|
8094
8694
|
const cached = appRunnerDataByTab.get(tab.id);
|
|
@@ -8428,6 +9028,7 @@ function renderTabs() {
|
|
|
8428
9028
|
updateDocumentTitle();
|
|
8429
9029
|
renderWorkspaceDashboard();
|
|
8430
9030
|
renderContextMeter();
|
|
9031
|
+
renderGitPanel();
|
|
8431
9032
|
if (elements.commandPaletteDialog?.open) renderCommandPalette({ preserveScroll: true });
|
|
8432
9033
|
syncTabPolling();
|
|
8433
9034
|
}
|
|
@@ -10952,7 +11553,7 @@ function gitChangesFileActionsFor(sectionKey, path) {
|
|
|
10952
11553
|
...gitChangesCommonFileActions(path),
|
|
10953
11554
|
];
|
|
10954
11555
|
}
|
|
10955
|
-
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) }];
|
|
10956
11557
|
return [];
|
|
10957
11558
|
}
|
|
10958
11559
|
|
|
@@ -11336,28 +11937,34 @@ function renderGitPullResultPanel(result) {
|
|
|
11336
11937
|
|
|
11337
11938
|
function renderGitChangesDialog() {
|
|
11338
11939
|
if (!elements.gitChangesDialog || !elements.gitChangesBody) return;
|
|
11339
|
-
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";
|
|
11340
11942
|
const busyAction = pulling || fetching;
|
|
11341
11943
|
const behind = Number(data?.remote?.behind ?? data?.summary?.behind ?? 0) || 0;
|
|
11342
11944
|
const diverged = data?.remote?.diverged === true;
|
|
11343
11945
|
const canPull = behind > 0 && data?.remote?.canPull !== false && !diverged;
|
|
11344
|
-
const hasOperation = Boolean(operation?.operation);
|
|
11345
|
-
const remoteNotice = !error && data?.remote?.error ? `Incoming diff unavailable: ${data.remote.error}` : "";
|
|
11346
|
-
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";
|
|
11347
11949
|
if (elements.gitChangesSubtitle) {
|
|
11348
|
-
const
|
|
11349
|
-
|
|
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;
|
|
11350
11955
|
}
|
|
11351
11956
|
if (elements.gitChangesRefreshButton) {
|
|
11352
11957
|
elements.gitChangesRefreshButton.disabled = loading || busyAction;
|
|
11353
|
-
elements.gitChangesRefreshButton.textContent = loading ? "Refreshing…" : "Refresh";
|
|
11958
|
+
elements.gitChangesRefreshButton.textContent = loading ? "Refreshing…" : commitView ? "Reload" : "Refresh";
|
|
11354
11959
|
}
|
|
11355
11960
|
if (elements.gitChangesFetchButton) {
|
|
11961
|
+
elements.gitChangesFetchButton.hidden = commitView;
|
|
11356
11962
|
elements.gitChangesFetchButton.disabled = loading || busyAction || !data?.root;
|
|
11357
11963
|
elements.gitChangesFetchButton.textContent = fetching ? "Fetching…" : "Fetch";
|
|
11358
11964
|
elements.gitChangesFetchButton.title = "Run git fetch --prune to refresh remote tracking state";
|
|
11359
11965
|
}
|
|
11360
11966
|
if (elements.gitChangesPullButton) {
|
|
11967
|
+
elements.gitChangesPullButton.hidden = commitView;
|
|
11361
11968
|
elements.gitChangesPullButton.disabled = loading || busyAction || !canPull;
|
|
11362
11969
|
elements.gitChangesPullButton.textContent = pulling ? "Pulling…" : behind > 0 ? `Pull ↓${behind}` : "Pull";
|
|
11363
11970
|
elements.gitChangesPullButton.title = canPull
|
|
@@ -11367,7 +11974,7 @@ function renderGitChangesDialog() {
|
|
|
11367
11974
|
: "No remote commits to pull";
|
|
11368
11975
|
}
|
|
11369
11976
|
if (elements.gitChangesStatus) {
|
|
11370
|
-
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) : ""));
|
|
11371
11978
|
elements.gitChangesStatus.className = `git-changes-status ${error || remoteNotice ? "error" : message ? "success" : "muted"}`;
|
|
11372
11979
|
elements.gitChangesStatus.textContent = statusText;
|
|
11373
11980
|
elements.gitChangesStatus.hidden = !elements.gitChangesStatus.textContent;
|
|
@@ -11388,19 +11995,21 @@ function renderGitChangesDialog() {
|
|
|
11388
11995
|
return;
|
|
11389
11996
|
}
|
|
11390
11997
|
|
|
11391
|
-
if (pullResult) body.append(renderGitPullResultPanel(pullResult));
|
|
11998
|
+
if (pullResult && !commitView) body.append(renderGitPullResultPanel(pullResult));
|
|
11392
11999
|
if (hasOperation) {
|
|
11393
12000
|
const panel = renderGitOperationPanel(operation);
|
|
11394
12001
|
if (panel) body.append(panel);
|
|
11395
12002
|
}
|
|
11396
|
-
|
|
11397
|
-
|
|
11398
|
-
|
|
11399
|
-
|
|
11400
|
-
|
|
11401
|
-
|
|
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));
|
|
11402
12012
|
}
|
|
11403
|
-
if (diverged && !hasOperation) body.append(renderGitDivergedBar(data));
|
|
11404
12013
|
const parsedSections = (Array.isArray(data.sections) ? data.sections : [])
|
|
11405
12014
|
.map((section) => ({ section, files: parseGitUnifiedDiff(section.diff || "") }))
|
|
11406
12015
|
.filter((entry) => entry.files.length > 0);
|
|
@@ -11417,14 +12026,14 @@ function renderGitChangesDialog() {
|
|
|
11417
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.";
|
|
11418
12027
|
body.append(make("div", "git-changes-empty success", emptyMessage));
|
|
11419
12028
|
}
|
|
11420
|
-
body.append(renderGitToolsSection());
|
|
12029
|
+
if (!commitView) body.append(renderGitToolsSection());
|
|
11421
12030
|
if (hasVisibleFiles) requestAnimationFrame(updateGitChangesCurrentFileHeader);
|
|
11422
12031
|
}
|
|
11423
12032
|
|
|
11424
12033
|
async function loadGitChangesDialog(tabContext = activeTabContext()) {
|
|
11425
12034
|
const requestSerial = ++gitChangesRequestSerial;
|
|
11426
12035
|
gitChangesUntrackedContentRequests.clear();
|
|
11427
|
-
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 };
|
|
11428
12037
|
renderGitChangesDialog();
|
|
11429
12038
|
try {
|
|
11430
12039
|
const [response, operationResponse] = await Promise.all([
|
|
@@ -11454,10 +12063,10 @@ async function loadGitChangesDialog(tabContext = activeTabContext()) {
|
|
|
11454
12063
|
renderGitChangesDialog();
|
|
11455
12064
|
}
|
|
11456
12065
|
|
|
11457
|
-
function openGitChangesDialog() {
|
|
12066
|
+
function openGitChangesDialog(requestedTabId = activeTabId) {
|
|
11458
12067
|
if (!elements.gitChangesDialog) return;
|
|
11459
12068
|
hideFooterTooltip();
|
|
11460
|
-
const tabContext = activeTabContext();
|
|
12069
|
+
const tabContext = activeTabContext(requestedTabId);
|
|
11461
12070
|
const tabId = tabContext.tabId || activeTabId;
|
|
11462
12071
|
if (gitToolsState.tabId !== tabId) resetGitToolsState(tabId);
|
|
11463
12072
|
gitChangesState = {
|
|
@@ -11474,15 +12083,47 @@ function openGitChangesDialog() {
|
|
|
11474
12083
|
operation: gitChangesState.tabId === tabId ? gitChangesState.operation : null,
|
|
11475
12084
|
lastFetch: gitChangesState.tabId === tabId ? gitChangesState.lastFetch : null,
|
|
11476
12085
|
tabId,
|
|
12086
|
+
mode: "changes",
|
|
12087
|
+
commit: null,
|
|
11477
12088
|
};
|
|
11478
12089
|
renderGitChangesDialog();
|
|
11479
12090
|
if (!elements.gitChangesDialog.open) elements.gitChangesDialog.showModal();
|
|
11480
12091
|
loadGitChangesDialog(tabContext).catch((error) => addEvent(error.message || String(error), "error"));
|
|
11481
12092
|
}
|
|
11482
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
|
+
|
|
11483
12120
|
function refreshGitChangesDialog() {
|
|
11484
|
-
const
|
|
11485
|
-
|
|
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"));
|
|
11486
12127
|
}
|
|
11487
12128
|
|
|
11488
12129
|
async function pullGitChangesDialog() {
|
|
@@ -12413,20 +13054,29 @@ async function requestManualCompaction({ triggerButton = null } = {}) {
|
|
|
12413
13054
|
}
|
|
12414
13055
|
}
|
|
12415
13056
|
|
|
13057
|
+
let contextMeterSignature = null;
|
|
13058
|
+
|
|
12416
13059
|
function renderContextMeter() {
|
|
12417
13060
|
if (deferUiRenderDuringPointerActivation("context-meter", renderContextMeter)) return;
|
|
12418
13061
|
const root = elements.contextMeterBar;
|
|
12419
13062
|
if (!root) return;
|
|
12420
13063
|
const tab = activeTab();
|
|
12421
|
-
if (!tab) {
|
|
12422
|
-
root.hidden = true;
|
|
12423
|
-
root.replaceChildren();
|
|
12424
|
-
return;
|
|
12425
|
-
}
|
|
12426
|
-
root.hidden = false;
|
|
12427
13064
|
const snapshot = contextUsageSnapshot();
|
|
12428
|
-
|
|
12429
|
-
|
|
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) {
|
|
12430
13080
|
root.replaceChildren();
|
|
12431
13081
|
return;
|
|
12432
13082
|
}
|
|
@@ -12445,9 +13095,9 @@ function renderContextMeter() {
|
|
|
12445
13095
|
compact.disabled = !!currentState?.isCompacting;
|
|
12446
13096
|
compact.title = "Manually compact this tab's conversation context";
|
|
12447
13097
|
compact.addEventListener("click", () => requestManualCompaction({ triggerButton: compact }));
|
|
12448
|
-
const auto = make("button", "context-meter-auto",
|
|
13098
|
+
const auto = make("button", "context-meter-auto", autoCompactionEnabled ? "Auto on" : "Auto off");
|
|
12449
13099
|
auto.type = "button";
|
|
12450
|
-
auto.setAttribute("aria-pressed",
|
|
13100
|
+
auto.setAttribute("aria-pressed", autoCompactionEnabled ? "true" : "false");
|
|
12451
13101
|
auto.disabled = footerAutoCompactionToggleInFlight;
|
|
12452
13102
|
auto.title = footerAutoCompactionToggleInFlight ? "Updating auto-compaction…" : footerAutoCompactionToggleAction();
|
|
12453
13103
|
auto.addEventListener("click", () => toggleFooterAutoCompaction());
|
|
@@ -12560,11 +13210,14 @@ function renderWorkspaceDashboard() {
|
|
|
12560
13210
|
queueCount,
|
|
12561
13211
|
modelLabel,
|
|
12562
13212
|
modelTitle: currentState?.model ? shortModelLabel(currentState.model) : "Model loading…",
|
|
13213
|
+
hasModel: !!currentState?.model,
|
|
12563
13214
|
thinking: currentState?.thinkingLevel || "",
|
|
12564
|
-
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()],
|
|
12565
13217
|
session: sessionSummary,
|
|
13218
|
+
hasSession: !!(currentState?.sessionId || currentState?.sessionName),
|
|
12566
13219
|
activeTabId,
|
|
12567
|
-
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) : "" })),
|
|
12568
13221
|
overflow: tabs.length > 8 ? tabs.length - 8 : 0,
|
|
12569
13222
|
});
|
|
12570
13223
|
if (signature === workspaceDashboardSignature && root.childElementCount > 0) return;
|
|
@@ -14427,7 +15080,7 @@ function initializeClaudeUsage() {
|
|
|
14427
15080
|
|
|
14428
15081
|
function subagentTabsWithRunningAgents() {
|
|
14429
15082
|
return (Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : [])
|
|
14430
|
-
.filter((tab) => Number(tab?.agentCount || 0) > 0)
|
|
15083
|
+
.filter((tab) => Number(tab?.agentCount || 0) > 0 || Number(tab?.gateCount || 0) > 0)
|
|
14431
15084
|
.sort((a, b) => Number(a.tabIndex || 0) - Number(b.tabIndex || 0) || String(a.tabTitle || "").localeCompare(String(b.tabTitle || "")));
|
|
14432
15085
|
}
|
|
14433
15086
|
|
|
@@ -14447,6 +15100,16 @@ function subagentRunElapsed(run) {
|
|
|
14447
15100
|
return Number.isFinite(startedAt) ? formatDuration(Math.max(0, Date.now() - startedAt)) : "";
|
|
14448
15101
|
}
|
|
14449
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
|
+
|
|
14450
15113
|
function subagentOverlayTranscriptMessages(data = subagentOverlayData) {
|
|
14451
15114
|
const agent = data?.agent || subagentOverlaySelection?.agent || {};
|
|
14452
15115
|
return (Array.isArray(agent.transcript) ? agent.transcript : [])
|
|
@@ -14580,6 +15243,7 @@ function subagentOverlayStateFacts(data = subagentOverlayData) {
|
|
|
14580
15243
|
data?.mode || subagentOverlaySelection?.run?.mode,
|
|
14581
15244
|
data?.source || subagentOverlaySelection?.run?.source,
|
|
14582
15245
|
agent.nested ? "nested" : "",
|
|
15246
|
+
...subagentExecutionFacts(agent),
|
|
14583
15247
|
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
14584
15248
|
Number.isFinite(agent.turnCount) ? `${agent.turnCount} turns` : "",
|
|
14585
15249
|
Number.isFinite(agent.toolCount) ? `${agent.toolCount} tools` : "",
|
|
@@ -14833,6 +15497,7 @@ function renderSubagentTerminalView() {
|
|
|
14833
15497
|
view.run?.mode,
|
|
14834
15498
|
view.run?.source === "foreground" ? "foreground" : "async",
|
|
14835
15499
|
agent.nested ? "nested" : "",
|
|
15500
|
+
...subagentExecutionFacts(agent),
|
|
14836
15501
|
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
14837
15502
|
].filter(Boolean);
|
|
14838
15503
|
|
|
@@ -15028,7 +15693,7 @@ function renderSubagentTerminalTab(view) {
|
|
|
15028
15693
|
appendTerminalTabContent(button, {
|
|
15029
15694
|
title: subagentTerminalViewTitle(view),
|
|
15030
15695
|
indicator: { state: running ? "working" : "done" },
|
|
15031
|
-
meta:
|
|
15696
|
+
meta: ["Subagent", ...subagentExecutionFacts(view.data?.agent || view.agent), view.parentTitle || "parent terminal"].join(" · "),
|
|
15032
15697
|
subagent: true,
|
|
15033
15698
|
});
|
|
15034
15699
|
button.addEventListener("click", () => activateSubagentTerminalView(view.id));
|
|
@@ -15059,6 +15724,7 @@ function renderSubagentAgent(tab, run, agent) {
|
|
|
15059
15724
|
agent?.nested ? "nested" : "",
|
|
15060
15725
|
run?.mode && run.mode !== "single" ? run.mode : "",
|
|
15061
15726
|
run?.source === "foreground" ? "foreground" : "async",
|
|
15727
|
+
...subagentExecutionFacts(agent),
|
|
15062
15728
|
agent?.currentTool ? `tool: ${agent.currentTool}` : "",
|
|
15063
15729
|
elapsed ? `running ${elapsed}` : "",
|
|
15064
15730
|
].filter(Boolean);
|
|
@@ -15071,6 +15737,50 @@ function renderSubagentAgent(tab, run, agent) {
|
|
|
15071
15737
|
return row;
|
|
15072
15738
|
}
|
|
15073
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
|
+
|
|
15074
15784
|
function renderSubagentTabGroup(tab) {
|
|
15075
15785
|
const group = make("section", `subagent-tab-group${tab.tabId === activeTabId ? " active" : ""}`);
|
|
15076
15786
|
const header = make("button", "subagent-tab-header");
|
|
@@ -15081,7 +15791,8 @@ function renderSubagentTabGroup(tab) {
|
|
|
15081
15791
|
make("strong", undefined, tab.tabTitle || `Terminal ${tab.tabIndex || "?"}`),
|
|
15082
15792
|
make("span", "subagent-tab-session", `Terminal ${tab.tabIndex || "?"} · ${subagentTabMeta(tab)}`),
|
|
15083
15793
|
);
|
|
15084
|
-
|
|
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));
|
|
15085
15796
|
header.addEventListener("click", () => switchTab(tab.tabId));
|
|
15086
15797
|
group.append(header);
|
|
15087
15798
|
|
|
@@ -15095,6 +15806,9 @@ function renderSubagentTabGroup(tab) {
|
|
|
15095
15806
|
.sort((a, b) => Number(a.index || 0) - Number(b.index || 0) || String(a.name || "").localeCompare(String(b.name || "")));
|
|
15096
15807
|
for (const agent of agents) list.append(renderSubagentAgent(tab, run, agent));
|
|
15097
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
|
+
}
|
|
15098
15812
|
group.append(list);
|
|
15099
15813
|
return group;
|
|
15100
15814
|
}
|
|
@@ -15104,23 +15818,25 @@ function renderSubagents() {
|
|
|
15104
15818
|
if (!box) return;
|
|
15105
15819
|
const activeTabs = subagentTabsWithRunningAgents();
|
|
15106
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;
|
|
15107
15823
|
if (elements.subagentCountBadge) {
|
|
15108
|
-
elements.subagentCountBadge.textContent = String(
|
|
15109
|
-
elements.subagentCountBadge.hidden =
|
|
15824
|
+
elements.subagentCountBadge.textContent = String(totalItems);
|
|
15825
|
+
elements.subagentCountBadge.hidden = totalItems === 0;
|
|
15110
15826
|
}
|
|
15111
15827
|
if (elements.subagentsStatus) {
|
|
15112
|
-
elements.subagentsStatus.textContent =
|
|
15113
|
-
? `${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(" · ")
|
|
15114
15830
|
: subagentsLoading && !latestSubagents
|
|
15115
|
-
? "Checking
|
|
15116
|
-
: "No running subagents.";
|
|
15831
|
+
? "Checking subagents and retry gates…"
|
|
15832
|
+
: "No running subagents or retained retry gates.";
|
|
15117
15833
|
}
|
|
15118
15834
|
|
|
15119
15835
|
box.replaceChildren();
|
|
15120
|
-
box.classList.toggle("muted",
|
|
15121
|
-
box.classList.toggle("has-items",
|
|
15122
|
-
if (
|
|
15123
|
-
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."));
|
|
15124
15840
|
return;
|
|
15125
15841
|
}
|
|
15126
15842
|
for (const tab of activeTabs) box.append(renderSubagentTabGroup(tab));
|
|
@@ -15147,7 +15863,8 @@ async function refreshSubagents() {
|
|
|
15147
15863
|
function scheduleRefreshSubagents(delay) {
|
|
15148
15864
|
clearTimeout(refreshSubagentsTimer);
|
|
15149
15865
|
const totalAgents = Number(latestSubagents?.totalAgents || 0);
|
|
15150
|
-
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);
|
|
15151
15868
|
refreshSubagentsTimer = setTimeout(() => {
|
|
15152
15869
|
refreshSubagents().finally(() => scheduleRefreshSubagents());
|
|
15153
15870
|
}, nextDelay);
|
|
@@ -29515,6 +30232,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
29515
30232
|
if (elements.fileContextMenu && !elements.fileContextMenu.hidden && !event.target?.closest?.(".file-context-menu")) {
|
|
29516
30233
|
closeFileContextMenu();
|
|
29517
30234
|
}
|
|
30235
|
+
if (elements.gitPanelContextMenu && !elements.gitPanelContextMenu.hidden && !event.target?.closest?.(".git-side-panel-context-menu")) {
|
|
30236
|
+
closeGitPanelContextMenu();
|
|
30237
|
+
}
|
|
29518
30238
|
}, { passive: true });
|
|
29519
30239
|
document.addEventListener("pointermove", (event) => {
|
|
29520
30240
|
if (openTerminalTabGroupKey && !event.target?.closest?.(".terminal-tab-group")) {
|
|
@@ -29877,6 +30597,21 @@ elements.fileContextMenu?.addEventListener("keydown", (event) => {
|
|
|
29877
30597
|
items[event.key === "Home" ? 0 : items.length - 1]?.focus({ preventScroll: true });
|
|
29878
30598
|
}
|
|
29879
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
|
+
});
|
|
29880
30615
|
elements.fileContextMenu?.addEventListener("click", (event) => {
|
|
29881
30616
|
const button = event.target?.closest?.("[data-file-menu-action]");
|
|
29882
30617
|
if (!button) return;
|