@firstpick/pi-package-webui 0.6.3 → 0.6.5
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/bin/pi-webui.mjs +1522 -53
- package/lib/git-worktrees.mjs +42 -0
- package/lib/trust-boundaries.mjs +4 -0
- package/package.json +3 -3
- package/public/app.js +3048 -164
- package/public/index.html +91 -3
- package/public/styles.css +991 -25
- package/tests/fixtures/fake-pi.mjs +59 -3
- package/tests/http-endpoints-harness.test.mjs +602 -2
- package/tests/mobile-static.test.mjs +3 -0
package/public/app.js
CHANGED
|
@@ -112,6 +112,7 @@ const elements = {
|
|
|
112
112
|
optionsForkButton: $("#optionsForkButton"),
|
|
113
113
|
optionsTreeButton: $("#optionsTreeButton"),
|
|
114
114
|
optionsStatsButton: $("#optionsStatsButton"),
|
|
115
|
+
optionsFooterVisibilityButton: $("#optionsFooterVisibilityButton"),
|
|
115
116
|
gitWorkflowPanel: $("#gitWorkflowPanel"),
|
|
116
117
|
gitWorkflowKicker: $("#gitWorkflowKicker"),
|
|
117
118
|
gitWorkflowTitle: $("#gitWorkflowTitle"),
|
|
@@ -132,6 +133,7 @@ const elements = {
|
|
|
132
133
|
gitChangesStatus: $("#gitChangesStatus"),
|
|
133
134
|
gitChangesBody: $("#gitChangesBody"),
|
|
134
135
|
gitChangesRefreshButton: $("#gitChangesRefreshButton"),
|
|
136
|
+
gitChangesFetchButton: $("#gitChangesFetchButton"),
|
|
135
137
|
gitChangesPullButton: $("#gitChangesPullButton"),
|
|
136
138
|
gitChangesCloseButton: $("#gitChangesCloseButton"),
|
|
137
139
|
modelControlLabel: $("#modelControlLabel"),
|
|
@@ -177,6 +179,30 @@ const elements = {
|
|
|
177
179
|
refreshCodexUsageButton: $("#refreshCodexUsageButton"),
|
|
178
180
|
claudeUsageBox: $("#claudeUsageBox"),
|
|
179
181
|
refreshClaudeUsageButton: $("#refreshClaudeUsageButton"),
|
|
182
|
+
fileTreeCwd: $("#fileTreeCwd"),
|
|
183
|
+
fileTreeRoot: $("#fileTreeRoot"),
|
|
184
|
+
fileTreeStatus: $("#fileTreeStatus"),
|
|
185
|
+
fileTreeRefreshButton: $("#fileTreeRefreshButton"),
|
|
186
|
+
fileTreeSearchInput: $("#fileTreeSearchInput"),
|
|
187
|
+
fileTreeSearchClearButton: $("#fileTreeSearchClearButton"),
|
|
188
|
+
fileViewerPane: $("#fileViewerPane"),
|
|
189
|
+
fileViewerResizeHandle: $("#fileViewerResizeHandle"),
|
|
190
|
+
fileViewerTitle: $("#fileViewerTitle"),
|
|
191
|
+
fileViewerMeta: $("#fileViewerMeta"),
|
|
192
|
+
fileViewerOpenDefaultButton: $("#fileViewerOpenDefaultButton"),
|
|
193
|
+
fileViewerSaveButton: $("#fileViewerSaveButton"),
|
|
194
|
+
fileViewerCloseButton: $("#fileViewerCloseButton"),
|
|
195
|
+
fileViewerHelp: $("#fileViewerHelp"),
|
|
196
|
+
fileViewerSourceModeButton: $("#fileViewerSourceModeButton"),
|
|
197
|
+
fileViewerPreviewModeButton: $("#fileViewerPreviewModeButton"),
|
|
198
|
+
fileViewerEditor: $("#fileViewerEditor"),
|
|
199
|
+
fileViewerPreview: $("#fileViewerPreview"),
|
|
200
|
+
fileViewerStatus: $("#fileViewerStatus"),
|
|
201
|
+
fileSelectionBar: $("#fileSelectionBar"),
|
|
202
|
+
fileSelectionSummary: $("#fileSelectionSummary"),
|
|
203
|
+
fileSelectionCommentInput: $("#fileSelectionCommentInput"),
|
|
204
|
+
fileSelectionSendButton: $("#fileSelectionSendButton"),
|
|
205
|
+
fileContextMenu: $("#fileContextMenu"),
|
|
180
206
|
toggleSidePanelButton: $("#toggleSidePanelButton"),
|
|
181
207
|
sidePanelExpandButton: $("#sidePanelExpandButton"),
|
|
182
208
|
sidePanelBackdrop: $("#sidePanelBackdrop"),
|
|
@@ -254,6 +280,14 @@ const elements = {
|
|
|
254
280
|
appRunnerInfoDialog: $("#appRunnerInfoDialog"),
|
|
255
281
|
appRunnerInfoBody: $("#appRunnerInfoBody"),
|
|
256
282
|
appRunnerInfoCloseButton: $("#appRunnerInfoCloseButton"),
|
|
283
|
+
gitFooterVisibilityDialog: $("#gitFooterVisibilityDialog"),
|
|
284
|
+
gitFooterVisibilityBody: $("#gitFooterVisibilityBody"),
|
|
285
|
+
gitFooterVisibilityStatus: $("#gitFooterVisibilityStatus"),
|
|
286
|
+
gitFooterVisibilitySelectAllButton: $("#gitFooterVisibilitySelectAllButton"),
|
|
287
|
+
gitFooterVisibilitySelectNoneButton: $("#gitFooterVisibilitySelectNoneButton"),
|
|
288
|
+
gitFooterVisibilityCloseButton: $("#gitFooterVisibilityCloseButton"),
|
|
289
|
+
gitFooterVisibilityResetButton: $("#gitFooterVisibilityResetButton"),
|
|
290
|
+
gitFooterVisibilityApplyButton: $("#gitFooterVisibilityApplyButton"),
|
|
257
291
|
statsOverlayDialog: $("#statsOverlayDialog"),
|
|
258
292
|
statsOverlaySubtitle: $("#statsOverlaySubtitle"),
|
|
259
293
|
statsOverlayScope: $("#statsOverlayScope"),
|
|
@@ -273,6 +307,14 @@ let tabDrafts = new Map();
|
|
|
273
307
|
let tabAttachments = new Map();
|
|
274
308
|
let activeTextAttachmentEditor = null;
|
|
275
309
|
let activeSkillEditor = null;
|
|
310
|
+
let fileTreeState = { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial: 0, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0, gitStatusRoot: "", gitStatusByPath: new Map() };
|
|
311
|
+
let activeFileViewer = null;
|
|
312
|
+
let fileViewerSelection = null;
|
|
313
|
+
let fileContextMenuState = null;
|
|
314
|
+
let fileTreeDragState = null;
|
|
315
|
+
let fileViewerResizeState = null;
|
|
316
|
+
let fileTreeSearchTimer = null;
|
|
317
|
+
let fileTreeSearchRequestSerial = 0;
|
|
276
318
|
let tabActivities = new Map();
|
|
277
319
|
let tabSeenCompletionSerials = new Map();
|
|
278
320
|
let streamBubble = null;
|
|
@@ -315,7 +357,8 @@ let foregroundReconcileTimer = null;
|
|
|
315
357
|
let eventSource = null;
|
|
316
358
|
let activeDialog = null;
|
|
317
359
|
let activeGitPrDialogResolve = null;
|
|
318
|
-
let gitChangesState = { loading: false, pulling: false, error: "", message: "", pullResult: null, data: null, tabId: null };
|
|
360
|
+
let gitChangesState = { loading: false, pulling: false, fetching: false, error: "", errorCode: "", errorHint: "", message: "", pullResult: null, data: null, operation: null, lastFetch: null, tabId: null };
|
|
361
|
+
let gitToolsState = { tabId: null, openSections: new Set(), cache: {}, busy: new Set(), notice: {} };
|
|
319
362
|
let gitChangesRequestSerial = 0;
|
|
320
363
|
const gitChangesUntrackedContentRequests = new Set();
|
|
321
364
|
let nativeCommandTabId = null;
|
|
@@ -510,6 +553,58 @@ const GIT_FOOTER_WEBUI_PAYLOAD_TYPE = "firstpick.git-footer-status.footer";
|
|
|
510
553
|
const GIT_FOOTER_WEBUI_PAYLOAD_VERSION = 1;
|
|
511
554
|
const GIT_FOOTER_WEBUI_PAYLOAD_CACHE_KEY = "pi-webui-git-footer-webui-payload-cache";
|
|
512
555
|
const GIT_FOOTER_STATUS_SETUP_STORAGE_KEY = "pi-webui-git-footer-status-setup";
|
|
556
|
+
const GIT_FOOTER_WEBUI_VISIBILITY_DEFAULTS = Object.freeze({
|
|
557
|
+
tokens: true,
|
|
558
|
+
cache: true,
|
|
559
|
+
pi: true,
|
|
560
|
+
speed: true,
|
|
561
|
+
cost: true,
|
|
562
|
+
context: true,
|
|
563
|
+
model: true,
|
|
564
|
+
thinking: true,
|
|
565
|
+
cwd: true,
|
|
566
|
+
"cwd-branch": true,
|
|
567
|
+
"git-status": true,
|
|
568
|
+
"extension-statuses": true,
|
|
569
|
+
git: true,
|
|
570
|
+
"git-state": true,
|
|
571
|
+
sync: true,
|
|
572
|
+
changes: true,
|
|
573
|
+
"git-extra": true,
|
|
574
|
+
worktree: true,
|
|
575
|
+
"context-meta": true,
|
|
576
|
+
"git-branch-indicator": false,
|
|
577
|
+
"git-detached": true,
|
|
578
|
+
"git-operation": true,
|
|
579
|
+
"git-ahead": true,
|
|
580
|
+
"git-behind": true,
|
|
581
|
+
"git-upstream": true,
|
|
582
|
+
"git-staged": true,
|
|
583
|
+
"git-unstaged": true,
|
|
584
|
+
"git-untracked": true,
|
|
585
|
+
"git-conflicted": true,
|
|
586
|
+
"git-clean": true,
|
|
587
|
+
"git-stash": true,
|
|
588
|
+
"git-submodules": true,
|
|
589
|
+
"git-worktrees": true,
|
|
590
|
+
"git-tag": true,
|
|
591
|
+
"git-last-commit-age": true,
|
|
592
|
+
"git-signing-mismatch": true,
|
|
593
|
+
"webui-fetch-state": true,
|
|
594
|
+
"webui-refresh-button": true,
|
|
595
|
+
"webui-details-button": true,
|
|
596
|
+
"webui-cwd-picker": true,
|
|
597
|
+
"webui-pi-calibration": true,
|
|
598
|
+
"webui-context-auto-compaction": true,
|
|
599
|
+
"webui-branch-picker": true,
|
|
600
|
+
"webui-git-init": true,
|
|
601
|
+
"webui-sync-push": true,
|
|
602
|
+
"webui-changes-modal": true,
|
|
603
|
+
"webui-git-tools-modal": true,
|
|
604
|
+
"webui-model-picker": true,
|
|
605
|
+
"webui-thinking-picker": true,
|
|
606
|
+
"webui-changed-files-popover": true,
|
|
607
|
+
});
|
|
513
608
|
const GIT_INIT_STACK_STORAGE_KEY = "pi-webui-git-init-stack";
|
|
514
609
|
const STATS_WEBUI_STATUS_KEY = "stats-webui";
|
|
515
610
|
const STATS_WEBUI_PAYLOAD_TYPE = "firstpick.pi-extension-stats.overlay";
|
|
@@ -533,6 +628,12 @@ const LAST_USER_PROMPT_STORAGE_KEY = "pi-webui-last-user-prompts";
|
|
|
533
628
|
const PROMPT_HISTORY_STORAGE_KEY = "pi-webui-prompt-history";
|
|
534
629
|
const PROMPT_LIST_STORAGE_KEY = "pi-webui-prompt-lists";
|
|
535
630
|
const WORKSPACE_DASHBOARD_STORAGE_KEY = "pi-webui-workspace-dashboard-collapsed";
|
|
631
|
+
const FILE_VIEWER_WIDTH_STORAGE_KEY = "pi-webui-file-viewer-width";
|
|
632
|
+
const FILE_VIEWER_WIDTH_DEFAULT_PX = 520;
|
|
633
|
+
const FILE_VIEWER_WIDTH_MIN_PX = 384;
|
|
634
|
+
const FILE_VIEWER_CONTEXT_RADIUS_LINES = 6;
|
|
635
|
+
const FILE_TREE_ROOT_PATH = "";
|
|
636
|
+
const FILE_TREE_DRAG_MIME = "application/x-pi-webui-file-path";
|
|
536
637
|
const POINTER_ACTIVATION_SELECTOR = "button, a[href], input, select, textarea, summary, [role='button'], [tabindex]:not([tabindex='-1'])";
|
|
537
638
|
const POINTER_ACTIVATION_RENDER_DEFER_MAX_MS = 1200;
|
|
538
639
|
const PROMPT_HISTORY_LIMIT_PER_TAB = 50;
|
|
@@ -762,6 +863,38 @@ const OPTIONAL_FEATURES = [
|
|
|
762
863
|
},
|
|
763
864
|
];
|
|
764
865
|
const OPTIONAL_FEATURE_BY_ID = new Map(OPTIONAL_FEATURES.map((feature) => [feature.id, feature]));
|
|
866
|
+
const OPTIONAL_FEATURE_SECTIONS = [
|
|
867
|
+
{
|
|
868
|
+
id: "composer-commands",
|
|
869
|
+
label: "Composer & commands",
|
|
870
|
+
description: "Input helpers and lightweight commands that change how prompts and shell actions are launched.",
|
|
871
|
+
featureIds: ["bangCommandAutocomplete", "fishUserBash", "btwCommand"],
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
id: "workflows-releases",
|
|
875
|
+
label: "Workflows & releases",
|
|
876
|
+
description: "Guided workflows, task runners, and publishing actions with visible execution state.",
|
|
877
|
+
featureIds: ["gitWorkflow", "workflows", "releaseNpm", "releaseAur"],
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
id: "safety-access",
|
|
881
|
+
label: "Safety & access",
|
|
882
|
+
description: "Guardrails and network-facing helpers that affect trust boundaries.",
|
|
883
|
+
featureIds: ["safetyGuard", "remoteWebui"],
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
id: "widgets-native-parity",
|
|
887
|
+
label: "UI widgets & native parity",
|
|
888
|
+
description: "Status widgets, dashboards, themes, and browser access to terminal-native controls.",
|
|
889
|
+
featureIds: ["tuiSkillsCommand", "todoProgressWidget", "tuiToolsCommand", "gitFooterStatus", "statsCommand", "themeBundle"],
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
id: "conversation",
|
|
893
|
+
label: "Conversation",
|
|
894
|
+
description: "Talk and voice-oriented interaction modes.",
|
|
895
|
+
featureIds: ["naturalConversation"],
|
|
896
|
+
},
|
|
897
|
+
];
|
|
765
898
|
const OPTIONAL_COMMAND_FEATURES = new Map([
|
|
766
899
|
["bang-refresh", "bangCommandAutocomplete"],
|
|
767
900
|
["bang-status", "bangCommandAutocomplete"],
|
|
@@ -785,6 +918,7 @@ const OPTIONAL_COMMAND_FEATURES = new Map([
|
|
|
785
918
|
["conversation", "naturalConversation"],
|
|
786
919
|
["stats", "statsCommand"],
|
|
787
920
|
["git-footer-refresh", "gitFooterStatus"],
|
|
921
|
+
["git-footer-visibility", "gitFooterStatus"],
|
|
788
922
|
["todo-progress-status", "todoProgressWidget"],
|
|
789
923
|
]);
|
|
790
924
|
const HIDDEN_COMMAND_NAMES = new Set(["webui-tree-navigate", "webui-helper"]);
|
|
@@ -819,6 +953,8 @@ let optionalFeaturePackageStatusError = "";
|
|
|
819
953
|
const gitFooterPayloadRefreshInFlightByTab = new Set();
|
|
820
954
|
const gitFooterSyncPushInFlightByTab = new Set();
|
|
821
955
|
const gitFooterPiCalibrationInFlightByTab = new Set();
|
|
956
|
+
let gitFooterVisibilityApplyInFlight = false;
|
|
957
|
+
let gitFooterVisibilityDirty = false;
|
|
822
958
|
|
|
823
959
|
function createGitWorkflowActionsDone(patch = {}) {
|
|
824
960
|
return {
|
|
@@ -2801,19 +2937,17 @@ async function submitEditRetry({ send = false } = {}) {
|
|
|
2801
2937
|
const forkMessage = await resolveForkMessageForEdit(message, messageIndex, tabContext.tabId);
|
|
2802
2938
|
setEditRetryStatus("Forking session…");
|
|
2803
2939
|
const result = await api("/api/fork", { method: "POST", body: { entryId: forkMessage.entryId }, tabId: tabContext.tabId });
|
|
2804
|
-
|
|
2805
|
-
|
|
2940
|
+
const forkTab = await switchToResponseTab(result);
|
|
2941
|
+
const forkTabId = forkTab?.id || activeTabId;
|
|
2806
2942
|
closeEditRetryDialog();
|
|
2807
|
-
await refreshAll(tabContext);
|
|
2808
|
-
if (!isCurrentTabContext(tabContext)) return;
|
|
2809
2943
|
if (send) {
|
|
2810
|
-
addEvent("forked session; sending edited prompt", "info");
|
|
2811
|
-
await sendPrompt("prompt", editedText, { targetTabId:
|
|
2944
|
+
addEvent("forked session in a new tab; sending edited prompt", "info");
|
|
2945
|
+
await sendPrompt("prompt", editedText, { targetTabId: forkTabId, throwOnError: true });
|
|
2812
2946
|
} else {
|
|
2813
2947
|
elements.promptInput.value = editedText;
|
|
2814
2948
|
resizePromptInput();
|
|
2815
2949
|
focusPromptInput({ defer: true });
|
|
2816
|
-
addEvent("forked session; edited prompt restored in composer", "info");
|
|
2950
|
+
addEvent("forked session in a new tab; edited prompt restored in composer", "info");
|
|
2817
2951
|
}
|
|
2818
2952
|
} catch (error) {
|
|
2819
2953
|
setEditRetryStatus(error.message || String(error), "error");
|
|
@@ -5326,6 +5460,1216 @@ function isCurrentTabContext(context) {
|
|
|
5326
5460
|
return !!context && context.tabId === activeTabId && context.generation === activeTabGeneration;
|
|
5327
5461
|
}
|
|
5328
5462
|
|
|
5463
|
+
function normalizeFileTreePath(value = "") {
|
|
5464
|
+
return String(value || "").trim().replace(/\\/g, "/").replace(/^\.\/+/, "").replace(/^\/+/, "").replace(/\/+$/g, "");
|
|
5465
|
+
}
|
|
5466
|
+
|
|
5467
|
+
function fileApiPath(basePath, filePath = "") {
|
|
5468
|
+
const path = normalizeFileTreePath(filePath);
|
|
5469
|
+
if (!path) return basePath;
|
|
5470
|
+
const params = new URLSearchParams({ path });
|
|
5471
|
+
return `${basePath}?${params.toString()}`;
|
|
5472
|
+
}
|
|
5473
|
+
|
|
5474
|
+
function fileParentPath(filePath = "") {
|
|
5475
|
+
const normalized = normalizeFileTreePath(filePath);
|
|
5476
|
+
const index = normalized.lastIndexOf("/");
|
|
5477
|
+
return index === -1 ? FILE_TREE_ROOT_PATH : normalized.slice(0, index);
|
|
5478
|
+
}
|
|
5479
|
+
|
|
5480
|
+
function fileDisplayName(path = "") {
|
|
5481
|
+
const normalized = normalizeFileTreePath(path);
|
|
5482
|
+
return normalized ? normalized.split("/").pop() || normalized : ".";
|
|
5483
|
+
}
|
|
5484
|
+
|
|
5485
|
+
function fileEntryIcon(entry = {}) {
|
|
5486
|
+
if (entry.type === "directory") return "▸";
|
|
5487
|
+
if (entry.type === "file") return entry.extension === ".md" || entry.extension === ".markdown" ? "Md" : "TXT";
|
|
5488
|
+
if (entry.type === "error") return "!";
|
|
5489
|
+
return "·";
|
|
5490
|
+
}
|
|
5491
|
+
|
|
5492
|
+
function normalizeFileTreeGitStatus(status = {}) {
|
|
5493
|
+
if (!status || status.changed !== true) return null;
|
|
5494
|
+
const kind = ["changed", "modified", "staged", "untracked", "conflicted"].includes(String(status.kind || "")) ? String(status.kind) : "changed";
|
|
5495
|
+
return {
|
|
5496
|
+
changed: true,
|
|
5497
|
+
kind,
|
|
5498
|
+
status: String(status.status || "").slice(0, 4),
|
|
5499
|
+
direct: status.direct === true,
|
|
5500
|
+
changedDescendants: Math.max(0, Number(status.changedDescendants || 0) || 0),
|
|
5501
|
+
};
|
|
5502
|
+
}
|
|
5503
|
+
|
|
5504
|
+
function fileTreeGitStatusForEntry(entry = {}) {
|
|
5505
|
+
const own = normalizeFileTreeGitStatus(entry.gitStatus);
|
|
5506
|
+
if (own) return own;
|
|
5507
|
+
return fileTreeState.gitStatusByPath.get(normalizeFileTreePath(entry.path || "")) || null;
|
|
5508
|
+
}
|
|
5509
|
+
|
|
5510
|
+
function fileTreeGitStatusClasses(status) {
|
|
5511
|
+
const normalized = normalizeFileTreeGitStatus(status);
|
|
5512
|
+
if (!normalized) return "";
|
|
5513
|
+
return `git-changed git-${normalized.kind} ${normalized.direct ? "git-direct" : "git-descendants"}`;
|
|
5514
|
+
}
|
|
5515
|
+
|
|
5516
|
+
function fileTreeGitStatusTitle(status) {
|
|
5517
|
+
const normalized = normalizeFileTreeGitStatus(status);
|
|
5518
|
+
if (!normalized) return "";
|
|
5519
|
+
if (normalized.direct) {
|
|
5520
|
+
const state = normalized.status ? ` (${normalized.status})` : "";
|
|
5521
|
+
return `Git ${normalized.kind}${state}`;
|
|
5522
|
+
}
|
|
5523
|
+
const count = normalized.changedDescendants || 0;
|
|
5524
|
+
return count > 0 ? `Git changes in ${count} descendant${count === 1 ? "" : "s"}` : "Git changes in this folder";
|
|
5525
|
+
}
|
|
5526
|
+
|
|
5527
|
+
function fileTreeGitStatusBadge(status) {
|
|
5528
|
+
const normalized = normalizeFileTreeGitStatus(status);
|
|
5529
|
+
if (!normalized) return null;
|
|
5530
|
+
const label = normalized.direct ? (normalized.status || "●") : (normalized.changedDescendants > 1 ? `Δ${normalized.changedDescendants}` : "Δ");
|
|
5531
|
+
const badge = make("span", `file-tree-git-badge ${normalized.kind} ${normalized.direct ? "direct" : "descendants"}`, label);
|
|
5532
|
+
badge.title = fileTreeGitStatusTitle(normalized);
|
|
5533
|
+
badge.setAttribute("aria-label", badge.title);
|
|
5534
|
+
return badge;
|
|
5535
|
+
}
|
|
5536
|
+
|
|
5537
|
+
function updateFileTreeGitStatus(gitStatus, entries = []) {
|
|
5538
|
+
const next = new Map();
|
|
5539
|
+
for (const status of Array.isArray(gitStatus?.entries) ? gitStatus.entries : []) {
|
|
5540
|
+
const path = normalizeFileTreePath(status.path || "");
|
|
5541
|
+
const normalized = normalizeFileTreeGitStatus(status);
|
|
5542
|
+
if (path && normalized) next.set(path, normalized);
|
|
5543
|
+
}
|
|
5544
|
+
for (const entry of entries) {
|
|
5545
|
+
const path = normalizeFileTreePath(entry?.path || "");
|
|
5546
|
+
const normalized = normalizeFileTreeGitStatus(entry?.gitStatus);
|
|
5547
|
+
if (path && normalized) next.set(path, normalized);
|
|
5548
|
+
}
|
|
5549
|
+
fileTreeState.gitStatusRoot = String(gitStatus?.root || "");
|
|
5550
|
+
fileTreeState.gitStatusByPath = next;
|
|
5551
|
+
}
|
|
5552
|
+
|
|
5553
|
+
function setFileTreeStatus(message = "", level = "muted") {
|
|
5554
|
+
if (!elements.fileTreeStatus) return;
|
|
5555
|
+
elements.fileTreeStatus.textContent = message;
|
|
5556
|
+
elements.fileTreeStatus.className = `file-tree-status ${level || "muted"}`;
|
|
5557
|
+
}
|
|
5558
|
+
|
|
5559
|
+
function setFileViewerStatus(message = "", level = "muted") {
|
|
5560
|
+
if (!elements.fileViewerStatus) return;
|
|
5561
|
+
elements.fileViewerStatus.textContent = message;
|
|
5562
|
+
elements.fileViewerStatus.className = `file-viewer-status ${level || "muted"}`;
|
|
5563
|
+
}
|
|
5564
|
+
|
|
5565
|
+
function emptyFileTreeState(requestSerial = 0) {
|
|
5566
|
+
return { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0, gitStatusRoot: "", gitStatusByPath: new Map() };
|
|
5567
|
+
}
|
|
5568
|
+
|
|
5569
|
+
function fileTreeSearchQueryText() {
|
|
5570
|
+
return String(elements.fileTreeSearchInput?.value || "").trim();
|
|
5571
|
+
}
|
|
5572
|
+
|
|
5573
|
+
function fileSearchApiPath(query = "") {
|
|
5574
|
+
const params = new URLSearchParams({ q: query });
|
|
5575
|
+
return `/api/files/search?${params.toString()}`;
|
|
5576
|
+
}
|
|
5577
|
+
|
|
5578
|
+
function fileTreeEntriesStatus(entries = [], { truncated = false, total = entries.length, searchQuery = "" } = {}) {
|
|
5579
|
+
const count = entries.length;
|
|
5580
|
+
if (searchQuery) {
|
|
5581
|
+
if (!count) return `0 matches for “${searchQuery}”.`;
|
|
5582
|
+
const label = count === 1 ? "match" : "matches";
|
|
5583
|
+
return truncated ? `Showing first ${count} ${label} for “${searchQuery}”.` : `${count} ${label} for “${searchQuery}”.`;
|
|
5584
|
+
}
|
|
5585
|
+
return truncated ? `Showing ${count} of ${total || count} entries.` : `${count} item${count === 1 ? "" : "s"}.`;
|
|
5586
|
+
}
|
|
5587
|
+
|
|
5588
|
+
function updateFileTreeSearchControls() {
|
|
5589
|
+
const query = fileTreeSearchQueryText();
|
|
5590
|
+
if (elements.fileTreeSearchClearButton) {
|
|
5591
|
+
elements.fileTreeSearchClearButton.hidden = !query;
|
|
5592
|
+
elements.fileTreeSearchClearButton.disabled = !query;
|
|
5593
|
+
}
|
|
5594
|
+
}
|
|
5595
|
+
|
|
5596
|
+
function resetFileTreeState() {
|
|
5597
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5598
|
+
fileTreeSearchTimer = null;
|
|
5599
|
+
fileTreeSearchRequestSerial += 1;
|
|
5600
|
+
fileTreeState = emptyFileTreeState(fileTreeState.requestSerial + 1);
|
|
5601
|
+
if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
|
|
5602
|
+
updateFileTreeSearchControls();
|
|
5603
|
+
renderFileTree();
|
|
5604
|
+
}
|
|
5605
|
+
|
|
5606
|
+
function fileEntryByPath(filePath = "") {
|
|
5607
|
+
const normalized = normalizeFileTreePath(filePath);
|
|
5608
|
+
if (!normalized) return { name: ".", path: "", type: "directory", directory: true };
|
|
5609
|
+
for (const entries of fileTreeState.entriesByPath.values()) {
|
|
5610
|
+
const found = entries.find((entry) => normalizeFileTreePath(entry.path) === normalized);
|
|
5611
|
+
if (found) return found;
|
|
5612
|
+
}
|
|
5613
|
+
return null;
|
|
5614
|
+
}
|
|
5615
|
+
|
|
5616
|
+
function renderFileTree() {
|
|
5617
|
+
const root = elements.fileTreeRoot;
|
|
5618
|
+
if (!root) return;
|
|
5619
|
+
root.replaceChildren();
|
|
5620
|
+
updateFileTreeSearchControls();
|
|
5621
|
+
if (elements.fileTreeCwd) elements.fileTreeCwd.textContent = fileTreeState.root || latestWorkspace?.displayCwd || activeTab()?.cwd || "";
|
|
5622
|
+
const searchQuery = fileTreeState.searchQuery || fileTreeSearchQueryText();
|
|
5623
|
+
root.classList.toggle("searching", !!searchQuery);
|
|
5624
|
+
if (searchQuery) {
|
|
5625
|
+
if (fileTreeState.searchLoading) {
|
|
5626
|
+
root.append(make("div", "file-tree-loading muted", `Searching for “${searchQuery}”…`));
|
|
5627
|
+
return;
|
|
5628
|
+
}
|
|
5629
|
+
if (!fileTreeState.searchEntries.length) {
|
|
5630
|
+
root.append(make("div", "file-tree-empty muted", `No files or folders match “${searchQuery}”.`));
|
|
5631
|
+
return;
|
|
5632
|
+
}
|
|
5633
|
+
const list = make("ul", "file-tree-list root search-results");
|
|
5634
|
+
list.setAttribute("role", "group");
|
|
5635
|
+
for (const entry of fileTreeState.searchEntries) appendFileSearchEntry(list, entry);
|
|
5636
|
+
root.append(list);
|
|
5637
|
+
return;
|
|
5638
|
+
}
|
|
5639
|
+
const entries = fileTreeState.entriesByPath.get(FILE_TREE_ROOT_PATH) || [];
|
|
5640
|
+
if (!entries.length) {
|
|
5641
|
+
root.append(make("div", "file-tree-empty muted", fileTreeState.loading.has(FILE_TREE_ROOT_PATH) ? "Loading files…" : "No files loaded."));
|
|
5642
|
+
return;
|
|
5643
|
+
}
|
|
5644
|
+
const list = make("ul", "file-tree-list root");
|
|
5645
|
+
list.setAttribute("role", "group");
|
|
5646
|
+
for (const entry of entries) appendFileTreeEntry(list, entry, 0);
|
|
5647
|
+
root.append(list);
|
|
5648
|
+
}
|
|
5649
|
+
|
|
5650
|
+
function appendFileSearchEntry(parent, entry) {
|
|
5651
|
+
const path = normalizeFileTreePath(entry.path);
|
|
5652
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5653
|
+
const gitStatus = fileTreeGitStatusForEntry(entry);
|
|
5654
|
+
const gitStatusClasses = fileTreeGitStatusClasses(gitStatus);
|
|
5655
|
+
const item = make("li", `file-tree-node file-tree-search-node ${entry.type || "file"}${gitStatusClasses ? ` ${gitStatusClasses}` : ""}${fileTreeState.selectedPath === path ? " selected" : ""}`);
|
|
5656
|
+
item.setAttribute("role", "none");
|
|
5657
|
+
const button = make("button", "file-tree-item file-tree-search-item");
|
|
5658
|
+
button.type = "button";
|
|
5659
|
+
button.dataset.path = path;
|
|
5660
|
+
button.dataset.type = entry.type || "file";
|
|
5661
|
+
button.style.setProperty("--file-tree-depth", "0");
|
|
5662
|
+
button.setAttribute("role", "treeitem");
|
|
5663
|
+
button.title = [path || ".", fileTreeGitStatusTitle(gitStatus), entry.error || ""].filter(Boolean).join("\n");
|
|
5664
|
+
const label = make("span", "file-tree-search-label");
|
|
5665
|
+
label.append(
|
|
5666
|
+
make("span", "file-tree-name", entry.name || fileDisplayName(path)),
|
|
5667
|
+
make("span", "file-tree-search-path", path || "."),
|
|
5668
|
+
);
|
|
5669
|
+
button.append(
|
|
5670
|
+
make("span", "file-tree-icon", fileEntryIcon(entry)),
|
|
5671
|
+
label,
|
|
5672
|
+
);
|
|
5673
|
+
const gitBadge = fileTreeGitStatusBadge(gitStatus);
|
|
5674
|
+
if (gitBadge) button.append(gitBadge);
|
|
5675
|
+
if (entry.type === "file") button.append(make("span", "file-tree-kind", entry.extension || "file"));
|
|
5676
|
+
else if (entry.type && entry.type !== "directory") button.append(make("span", "file-tree-kind", entry.type));
|
|
5677
|
+
if (entry.error) button.append(make("span", "file-tree-error", entry.error));
|
|
5678
|
+
button.addEventListener("click", () => {
|
|
5679
|
+
fileTreeState.selectedPath = path;
|
|
5680
|
+
renderFileTree();
|
|
5681
|
+
});
|
|
5682
|
+
button.addEventListener("dblclick", (event) => {
|
|
5683
|
+
event.preventDefault();
|
|
5684
|
+
if (isDirectory) revealFileTreeEntry(entry).catch((error) => addEvent(error.message || String(error), "error"));
|
|
5685
|
+
else if (entry.type === "file") openFileInViewer(path);
|
|
5686
|
+
});
|
|
5687
|
+
button.addEventListener("contextmenu", (event) => showFileContextMenu(event, entry));
|
|
5688
|
+
bindFileTreeDragAndDrop(button, item, entry);
|
|
5689
|
+
item.append(button);
|
|
5690
|
+
parent.append(item);
|
|
5691
|
+
}
|
|
5692
|
+
|
|
5693
|
+
async function revealFileTreeEntry(entry = {}) {
|
|
5694
|
+
const targetPath = normalizeFileTreePath(entry.path || "");
|
|
5695
|
+
if (!targetPath && targetPath !== FILE_TREE_ROOT_PATH) return;
|
|
5696
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5697
|
+
const parentPath = isDirectory ? targetPath : fileParentPath(targetPath);
|
|
5698
|
+
clearFileTreeSearch();
|
|
5699
|
+
fileTreeState.selectedPath = targetPath;
|
|
5700
|
+
await loadFileTreeDirectory(FILE_TREE_ROOT_PATH);
|
|
5701
|
+
let currentPath = "";
|
|
5702
|
+
for (const part of parentPath.split("/").filter(Boolean)) {
|
|
5703
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
5704
|
+
fileTreeState.expanded.add(currentPath);
|
|
5705
|
+
renderFileTree();
|
|
5706
|
+
await loadFileTreeDirectory(currentPath);
|
|
5707
|
+
}
|
|
5708
|
+
if (isDirectory) {
|
|
5709
|
+
fileTreeState.expanded.add(targetPath);
|
|
5710
|
+
await loadFileTreeDirectory(targetPath);
|
|
5711
|
+
}
|
|
5712
|
+
fileTreeState.selectedPath = targetPath;
|
|
5713
|
+
renderFileTree();
|
|
5714
|
+
}
|
|
5715
|
+
|
|
5716
|
+
function appendFileTreeEntry(parent, entry, depth = 0) {
|
|
5717
|
+
const path = normalizeFileTreePath(entry.path);
|
|
5718
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5719
|
+
const expanded = isDirectory && fileTreeState.expanded.has(path);
|
|
5720
|
+
const loading = isDirectory && fileTreeState.loading.has(path);
|
|
5721
|
+
const gitStatus = fileTreeGitStatusForEntry(entry);
|
|
5722
|
+
const gitStatusClasses = fileTreeGitStatusClasses(gitStatus);
|
|
5723
|
+
const item = make("li", `file-tree-node ${entry.type || "file"}${gitStatusClasses ? ` ${gitStatusClasses}` : ""}${expanded ? " expanded" : ""}${fileTreeState.selectedPath === path ? " selected" : ""}`);
|
|
5724
|
+
item.setAttribute("role", "none");
|
|
5725
|
+
const button = make("button", "file-tree-item");
|
|
5726
|
+
button.type = "button";
|
|
5727
|
+
button.dataset.path = path;
|
|
5728
|
+
button.dataset.type = entry.type || "file";
|
|
5729
|
+
button.style.setProperty("--file-tree-depth", String(depth));
|
|
5730
|
+
button.setAttribute("role", "treeitem");
|
|
5731
|
+
if (isDirectory) button.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
5732
|
+
button.title = [path || ".", fileTreeGitStatusTitle(gitStatus), entry.error || ""].filter(Boolean).join("\n");
|
|
5733
|
+
button.append(
|
|
5734
|
+
make("span", `file-tree-icon ${isDirectory && expanded ? "expanded" : ""}`, loading ? "…" : fileEntryIcon(entry)),
|
|
5735
|
+
make("span", "file-tree-name", entry.name || fileDisplayName(path)),
|
|
5736
|
+
);
|
|
5737
|
+
const gitBadge = fileTreeGitStatusBadge(gitStatus);
|
|
5738
|
+
if (gitBadge) button.append(gitBadge);
|
|
5739
|
+
if (entry.type === "file") button.append(make("span", "file-tree-kind", entry.extension || "file"));
|
|
5740
|
+
if (entry.error) button.append(make("span", "file-tree-error", entry.error));
|
|
5741
|
+
button.addEventListener("click", () => {
|
|
5742
|
+
fileTreeState.selectedPath = path;
|
|
5743
|
+
if (isDirectory) toggleFileTreeDirectory(path);
|
|
5744
|
+
else renderFileTree();
|
|
5745
|
+
});
|
|
5746
|
+
button.addEventListener("dblclick", (event) => {
|
|
5747
|
+
event.preventDefault();
|
|
5748
|
+
if (isDirectory) toggleFileTreeDirectory(path, { force: true });
|
|
5749
|
+
else openFileInViewer(path);
|
|
5750
|
+
});
|
|
5751
|
+
button.addEventListener("contextmenu", (event) => showFileContextMenu(event, entry));
|
|
5752
|
+
bindFileTreeDragAndDrop(button, item, entry);
|
|
5753
|
+
item.append(button);
|
|
5754
|
+
if (isDirectory && expanded) {
|
|
5755
|
+
const children = fileTreeState.entriesByPath.get(path) || [];
|
|
5756
|
+
const childList = make("ul", "file-tree-list");
|
|
5757
|
+
childList.setAttribute("role", "group");
|
|
5758
|
+
if (loading) childList.append(make("li", "file-tree-loading muted", "Loading…"));
|
|
5759
|
+
else if (!children.length) childList.append(make("li", "file-tree-empty muted", "Empty"));
|
|
5760
|
+
else for (const child of children) appendFileTreeEntry(childList, child, depth + 1);
|
|
5761
|
+
item.append(childList);
|
|
5762
|
+
}
|
|
5763
|
+
parent.append(item);
|
|
5764
|
+
}
|
|
5765
|
+
|
|
5766
|
+
async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false } = {}) {
|
|
5767
|
+
const normalized = normalizeFileTreePath(path);
|
|
5768
|
+
if (!force && fileTreeState.entriesByPath.has(normalized)) return fileTreeState.entriesByPath.get(normalized);
|
|
5769
|
+
const tabContext = activeTabContext();
|
|
5770
|
+
if (!tabContext.tabId || fileTreeState.loading.has(normalized)) return [];
|
|
5771
|
+
const serial = ++fileTreeState.requestSerial;
|
|
5772
|
+
fileTreeState.loading.add(normalized);
|
|
5773
|
+
setFileTreeStatus(normalized ? `Loading ${normalized}…` : "Loading workspace files…");
|
|
5774
|
+
renderFileTree();
|
|
5775
|
+
try {
|
|
5776
|
+
const response = await api(fileApiPath("/api/files", normalized), { tabId: tabContext.tabId });
|
|
5777
|
+
if (!isCurrentTabContext(tabContext) || serial < fileTreeState.requestSerial) return [];
|
|
5778
|
+
const data = response.data || {};
|
|
5779
|
+
if (!normalized && data.root && data.root !== fileTreeState.root) {
|
|
5780
|
+
fileTreeState.root = data.root;
|
|
5781
|
+
fileTreeState.entriesByPath.clear();
|
|
5782
|
+
fileTreeState.expanded.clear();
|
|
5783
|
+
}
|
|
5784
|
+
const entries = Array.isArray(data.entries) ? data.entries : [];
|
|
5785
|
+
updateFileTreeGitStatus(data.gitStatus, entries);
|
|
5786
|
+
fileTreeState.entriesByPath.set(normalized, entries);
|
|
5787
|
+
setFileTreeStatus(fileTreeEntriesStatus(entries, { truncated: data.truncated, total: data.total || entries.length }));
|
|
5788
|
+
return entries;
|
|
5789
|
+
} catch (error) {
|
|
5790
|
+
if (isCurrentTabContext(tabContext)) {
|
|
5791
|
+
setFileTreeStatus(error.message || String(error), "error");
|
|
5792
|
+
addEvent(`file tree failed: ${error.message || String(error)}`, "error");
|
|
5793
|
+
}
|
|
5794
|
+
return [];
|
|
5795
|
+
} finally {
|
|
5796
|
+
fileTreeState.loading.delete(normalized);
|
|
5797
|
+
if (isCurrentTabContext(tabContext)) renderFileTree();
|
|
5798
|
+
}
|
|
5799
|
+
}
|
|
5800
|
+
|
|
5801
|
+
function clearFileTreeSearch({ focus = false } = {}) {
|
|
5802
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5803
|
+
fileTreeSearchTimer = null;
|
|
5804
|
+
fileTreeSearchRequestSerial += 1;
|
|
5805
|
+
if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
|
|
5806
|
+
fileTreeState.searchQuery = "";
|
|
5807
|
+
fileTreeState.searchEntries = [];
|
|
5808
|
+
fileTreeState.searchLoading = false;
|
|
5809
|
+
fileTreeState.searchTruncated = false;
|
|
5810
|
+
fileTreeState.searchTotal = 0;
|
|
5811
|
+
updateFileTreeSearchControls();
|
|
5812
|
+
const rootEntries = fileTreeState.entriesByPath.get(FILE_TREE_ROOT_PATH) || [];
|
|
5813
|
+
setFileTreeStatus(rootEntries.length ? fileTreeEntriesStatus(rootEntries) : "");
|
|
5814
|
+
renderFileTree();
|
|
5815
|
+
if (focus) elements.fileTreeSearchInput?.focus();
|
|
5816
|
+
}
|
|
5817
|
+
|
|
5818
|
+
async function runFileTreeSearch() {
|
|
5819
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5820
|
+
fileTreeSearchTimer = null;
|
|
5821
|
+
const query = fileTreeSearchQueryText();
|
|
5822
|
+
fileTreeSearchRequestSerial += 1;
|
|
5823
|
+
const serial = fileTreeSearchRequestSerial;
|
|
5824
|
+
if (!query) {
|
|
5825
|
+
clearFileTreeSearch();
|
|
5826
|
+
return [];
|
|
5827
|
+
}
|
|
5828
|
+
const tabContext = activeTabContext();
|
|
5829
|
+
if (!tabContext.tabId) return [];
|
|
5830
|
+
fileTreeState.searchQuery = query;
|
|
5831
|
+
fileTreeState.searchLoading = true;
|
|
5832
|
+
fileTreeState.searchEntries = [];
|
|
5833
|
+
fileTreeState.searchTruncated = false;
|
|
5834
|
+
fileTreeState.searchTotal = 0;
|
|
5835
|
+
setFileTreeStatus(`Searching for “${query}”…`);
|
|
5836
|
+
renderFileTree();
|
|
5837
|
+
try {
|
|
5838
|
+
const response = await api(fileSearchApiPath(query), { tabId: tabContext.tabId });
|
|
5839
|
+
if (!isCurrentTabContext(tabContext) || serial !== fileTreeSearchRequestSerial) return [];
|
|
5840
|
+
const data = response.data || {};
|
|
5841
|
+
const entries = Array.isArray(data.entries) ? data.entries : [];
|
|
5842
|
+
if (data.root) fileTreeState.root = data.root;
|
|
5843
|
+
updateFileTreeGitStatus(data.gitStatus, entries);
|
|
5844
|
+
fileTreeState.searchQuery = data.query || query;
|
|
5845
|
+
fileTreeState.searchEntries = entries;
|
|
5846
|
+
fileTreeState.searchLoading = false;
|
|
5847
|
+
fileTreeState.searchTruncated = !!data.truncated;
|
|
5848
|
+
fileTreeState.searchTotal = Number(data.total || entries.length) || entries.length;
|
|
5849
|
+
setFileTreeStatus(fileTreeEntriesStatus(entries, { truncated: data.truncated, total: data.total || entries.length, searchQuery: fileTreeState.searchQuery }), entries.length ? "success" : "muted");
|
|
5850
|
+
return entries;
|
|
5851
|
+
} catch (error) {
|
|
5852
|
+
if (isCurrentTabContext(tabContext) && serial === fileTreeSearchRequestSerial) {
|
|
5853
|
+
fileTreeState.searchLoading = false;
|
|
5854
|
+
fileTreeState.searchEntries = [];
|
|
5855
|
+
setFileTreeStatus(error.message || String(error), "error");
|
|
5856
|
+
addEvent(`file search failed: ${error.message || String(error)}`, "error");
|
|
5857
|
+
}
|
|
5858
|
+
return [];
|
|
5859
|
+
} finally {
|
|
5860
|
+
if (isCurrentTabContext(tabContext) && serial === fileTreeSearchRequestSerial) renderFileTree();
|
|
5861
|
+
}
|
|
5862
|
+
}
|
|
5863
|
+
|
|
5864
|
+
function scheduleFileTreeSearch(delay = 180) {
|
|
5865
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5866
|
+
const query = fileTreeSearchQueryText();
|
|
5867
|
+
updateFileTreeSearchControls();
|
|
5868
|
+
if (!query) {
|
|
5869
|
+
clearFileTreeSearch();
|
|
5870
|
+
return;
|
|
5871
|
+
}
|
|
5872
|
+
fileTreeSearchRequestSerial += 1;
|
|
5873
|
+
fileTreeState.searchQuery = query;
|
|
5874
|
+
fileTreeState.searchLoading = true;
|
|
5875
|
+
setFileTreeStatus(`Searching for “${query}”…`);
|
|
5876
|
+
renderFileTree();
|
|
5877
|
+
fileTreeSearchTimer = setTimeout(() => {
|
|
5878
|
+
runFileTreeSearch().catch((error) => addEvent(error.message || String(error), "error"));
|
|
5879
|
+
}, delay);
|
|
5880
|
+
}
|
|
5881
|
+
|
|
5882
|
+
async function refreshFileTreeRoot(tabContext = activeTabContext()) {
|
|
5883
|
+
if (!tabContext.tabId || !elements.fileTreeRoot) return;
|
|
5884
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
5885
|
+
if (fileTreeSearchQueryText()) await runFileTreeSearch();
|
|
5886
|
+
else await loadFileTreeDirectory(FILE_TREE_ROOT_PATH, { force: true });
|
|
5887
|
+
}
|
|
5888
|
+
|
|
5889
|
+
async function toggleFileTreeDirectory(path = "", { force = false } = {}) {
|
|
5890
|
+
const normalized = normalizeFileTreePath(path);
|
|
5891
|
+
if (!normalized && normalized !== FILE_TREE_ROOT_PATH) return;
|
|
5892
|
+
const currentlyExpanded = fileTreeState.expanded.has(normalized);
|
|
5893
|
+
if (currentlyExpanded && !force) {
|
|
5894
|
+
fileTreeState.expanded.delete(normalized);
|
|
5895
|
+
renderFileTree();
|
|
5896
|
+
return;
|
|
5897
|
+
}
|
|
5898
|
+
fileTreeState.expanded.add(normalized);
|
|
5899
|
+
renderFileTree();
|
|
5900
|
+
await loadFileTreeDirectory(normalized);
|
|
5901
|
+
}
|
|
5902
|
+
|
|
5903
|
+
function closeFileContextMenu() {
|
|
5904
|
+
fileContextMenuState = null;
|
|
5905
|
+
if (elements.fileContextMenu) elements.fileContextMenu.hidden = true;
|
|
5906
|
+
}
|
|
5907
|
+
|
|
5908
|
+
function showFileContextMenu(event, entry) {
|
|
5909
|
+
if (!elements.fileContextMenu) return;
|
|
5910
|
+
event.preventDefault();
|
|
5911
|
+
event.stopPropagation();
|
|
5912
|
+
const path = normalizeFileTreePath(entry?.path || "");
|
|
5913
|
+
fileContextMenuState = { entry: { ...entry, path } };
|
|
5914
|
+
const menu = elements.fileContextMenu;
|
|
5915
|
+
const webui = menu.querySelector('[data-file-menu-action="open-webui"]');
|
|
5916
|
+
if (webui) webui.textContent = entry?.type === "directory" ? "Open in WebUI" : "Open in WebUI";
|
|
5917
|
+
menu.hidden = false;
|
|
5918
|
+
const rect = menu.getBoundingClientRect();
|
|
5919
|
+
const left = Math.min(event.clientX, Math.max(0, window.innerWidth - rect.width - 8));
|
|
5920
|
+
const top = Math.min(event.clientY, Math.max(0, window.innerHeight - rect.height - 8));
|
|
5921
|
+
menu.style.left = `${left}px`;
|
|
5922
|
+
menu.style.top = `${top}px`;
|
|
5923
|
+
}
|
|
5924
|
+
|
|
5925
|
+
function currentFileViewerPath() {
|
|
5926
|
+
return normalizeFileTreePath(activeFileViewer?.path || elements.fileViewerOpenDefaultButton?.dataset.path || "");
|
|
5927
|
+
}
|
|
5928
|
+
|
|
5929
|
+
async function openPathInDefaultEditor(path = currentFileViewerPath()) {
|
|
5930
|
+
const normalized = normalizeFileTreePath(path);
|
|
5931
|
+
if (!normalized) {
|
|
5932
|
+
addEvent("No file is currently open in the WebUI viewer.", "warn");
|
|
5933
|
+
return;
|
|
5934
|
+
}
|
|
5935
|
+
const tabContext = activeTabContext();
|
|
5936
|
+
try {
|
|
5937
|
+
const response = await api("/api/files/open-default", { method: "POST", body: { path: normalized }, tabId: tabContext.tabId });
|
|
5938
|
+
if (isCurrentTabContext(tabContext)) addEvent(`opened ${response.data?.path || normalized || "."} in the default editor`, "info");
|
|
5939
|
+
} catch (error) {
|
|
5940
|
+
if (isCurrentTabContext(tabContext)) addEvent(error.message || String(error), "error");
|
|
5941
|
+
}
|
|
5942
|
+
}
|
|
5943
|
+
|
|
5944
|
+
function filePathWithinOrEqual(filePath = "", parentPath = "") {
|
|
5945
|
+
const path = normalizeFileTreePath(filePath);
|
|
5946
|
+
const parent = normalizeFileTreePath(parentPath);
|
|
5947
|
+
if (!parent) return path === parent;
|
|
5948
|
+
return path === parent || path.startsWith(`${parent}/`);
|
|
5949
|
+
}
|
|
5950
|
+
|
|
5951
|
+
function remapFileTreePathAfterMove(filePath = "", sourcePath = "", destinationPath = "") {
|
|
5952
|
+
const path = normalizeFileTreePath(filePath);
|
|
5953
|
+
const source = normalizeFileTreePath(sourcePath);
|
|
5954
|
+
const destination = normalizeFileTreePath(destinationPath);
|
|
5955
|
+
if (!path || !source || !destination) return path;
|
|
5956
|
+
if (path === source) return destination;
|
|
5957
|
+
return path.startsWith(`${source}/`) ? `${destination}/${path.slice(source.length + 1)}` : path;
|
|
5958
|
+
}
|
|
5959
|
+
|
|
5960
|
+
function fileExtensionForPath(filePath = "") {
|
|
5961
|
+
const name = fileDisplayName(filePath);
|
|
5962
|
+
const dot = name.lastIndexOf(".");
|
|
5963
|
+
return dot > 0 ? name.slice(dot).toLowerCase() : "";
|
|
5964
|
+
}
|
|
5965
|
+
|
|
5966
|
+
function fileLanguageForPath(filePath = "") {
|
|
5967
|
+
const extension = fileExtensionForPath(filePath);
|
|
5968
|
+
return extension === ".md" || extension === ".markdown" ? "markdown" : "text";
|
|
5969
|
+
}
|
|
5970
|
+
|
|
5971
|
+
function fileOperationTypeLabel(entry = {}) {
|
|
5972
|
+
if (entry.type === "directory" || entry.directory === true) return "directory";
|
|
5973
|
+
if (entry.type === "file" || entry.file === true) return "file";
|
|
5974
|
+
return "entry";
|
|
5975
|
+
}
|
|
5976
|
+
|
|
5977
|
+
function fileTreeEntryIsMovable(entry = {}) {
|
|
5978
|
+
const path = normalizeFileTreePath(entry.path || "");
|
|
5979
|
+
return !!path && (entry.type === "file" || entry.file === true || entry.type === "directory" || entry.directory === true);
|
|
5980
|
+
}
|
|
5981
|
+
|
|
5982
|
+
function fileTreeEntryIsDirectory(entry = {}) {
|
|
5983
|
+
return entry.type === "directory" || entry.directory === true;
|
|
5984
|
+
}
|
|
5985
|
+
|
|
5986
|
+
function fileTreeDragSourceFromEvent(event) {
|
|
5987
|
+
const statePath = normalizeFileTreePath(fileTreeDragState?.sourcePath || "");
|
|
5988
|
+
return statePath ? { path: statePath, type: fileTreeDragState?.sourceType || "entry", entry: fileTreeDragState?.entry || null } : null;
|
|
5989
|
+
}
|
|
5990
|
+
|
|
5991
|
+
function fileTreeEntryFromElement(element) {
|
|
5992
|
+
const path = normalizeFileTreePath(element?.dataset?.path || "");
|
|
5993
|
+
const type = element?.dataset?.type || "";
|
|
5994
|
+
return path || type ? { path, type, directory: type === "directory", file: type === "file" } : null;
|
|
5995
|
+
}
|
|
5996
|
+
|
|
5997
|
+
function fileTreeDropTargetFromEvent(event) {
|
|
5998
|
+
const button = event?.target?.closest?.(".file-tree-item");
|
|
5999
|
+
if (!button || !elements.fileTreeRoot?.contains?.(button)) return null;
|
|
6000
|
+
const entry = fileTreeEntryFromElement(button);
|
|
6001
|
+
if (!entry || !fileTreeEntryIsDirectory(entry)) return null;
|
|
6002
|
+
return { entry, item: button.closest(".file-tree-node"), button };
|
|
6003
|
+
}
|
|
6004
|
+
|
|
6005
|
+
function fileTreeCanDropOnDirectory(sourcePath = "", targetDirectoryPath = "", sourceEntry = fileTreeDragState?.entry) {
|
|
6006
|
+
const source = normalizeFileTreePath(sourcePath);
|
|
6007
|
+
const target = normalizeFileTreePath(targetDirectoryPath);
|
|
6008
|
+
if (!source) return false;
|
|
6009
|
+
if (fileParentPath(source) === target) return false;
|
|
6010
|
+
if (fileTreeEntryIsDirectory(sourceEntry || {}) && (target === source || target.startsWith(`${source}/`))) return false;
|
|
6011
|
+
return true;
|
|
6012
|
+
}
|
|
6013
|
+
|
|
6014
|
+
function clearFileTreeDragVisuals() {
|
|
6015
|
+
for (const node of document.querySelectorAll(".file-tree-node.dragging, .file-tree-node.drop-target, .file-tree-node.drop-blocked")) {
|
|
6016
|
+
node.classList.remove("dragging", "drop-target", "drop-blocked");
|
|
6017
|
+
}
|
|
6018
|
+
elements.fileTreeRoot?.classList.remove("drag-root-drop", "drop-blocked");
|
|
6019
|
+
}
|
|
6020
|
+
|
|
6021
|
+
function finishFileTreeDrag() {
|
|
6022
|
+
clearFileTreeDragVisuals();
|
|
6023
|
+
fileTreeDragState = null;
|
|
6024
|
+
}
|
|
6025
|
+
|
|
6026
|
+
function beginFileTreeDrag(event, entry = {}, item) {
|
|
6027
|
+
if (!fileTreeEntryIsMovable(entry)) {
|
|
6028
|
+
event.preventDefault();
|
|
6029
|
+
return;
|
|
6030
|
+
}
|
|
6031
|
+
const sourcePath = normalizeFileTreePath(entry.path || "");
|
|
6032
|
+
closeFileContextMenu();
|
|
6033
|
+
fileTreeDragState = { sourcePath, sourceType: fileOperationTypeLabel(entry), entry: { ...entry, path: sourcePath } };
|
|
6034
|
+
event.dataTransfer.effectAllowed = "move";
|
|
6035
|
+
event.dataTransfer.setData(FILE_TREE_DRAG_MIME, sourcePath);
|
|
6036
|
+
event.dataTransfer.setData("text/plain", sourcePath);
|
|
6037
|
+
item?.classList.add("dragging");
|
|
6038
|
+
setFileTreeStatus(`Drag ${sourcePath} onto a folder or empty file-tree space to move it.`);
|
|
6039
|
+
}
|
|
6040
|
+
|
|
6041
|
+
function updateFileTreeDropTarget(event, entry = {}, item) {
|
|
6042
|
+
const source = fileTreeDragSourceFromEvent(event);
|
|
6043
|
+
if (!source || !fileTreeEntryIsDirectory(entry)) return false;
|
|
6044
|
+
const targetPath = normalizeFileTreePath(entry.path || "");
|
|
6045
|
+
const allowed = fileTreeCanDropOnDirectory(source.path, targetPath, source.entry);
|
|
6046
|
+
for (const node of document.querySelectorAll(".file-tree-node.drop-target, .file-tree-node.drop-blocked")) node.classList.remove("drop-target", "drop-blocked");
|
|
6047
|
+
elements.fileTreeRoot?.classList.remove("drag-root-drop", "drop-blocked");
|
|
6048
|
+
if (!allowed) {
|
|
6049
|
+
item?.classList.add("drop-blocked");
|
|
6050
|
+
event.dataTransfer.dropEffect = "none";
|
|
6051
|
+
return false;
|
|
6052
|
+
}
|
|
6053
|
+
event.preventDefault();
|
|
6054
|
+
event.stopPropagation();
|
|
6055
|
+
event.dataTransfer.dropEffect = "move";
|
|
6056
|
+
item?.classList.add("drop-target");
|
|
6057
|
+
if (fileTreeDragState) fileTreeDragState.targetPath = targetPath;
|
|
6058
|
+
return true;
|
|
6059
|
+
}
|
|
6060
|
+
|
|
6061
|
+
function clearFileTreeDropTarget(event, item) {
|
|
6062
|
+
if (!item?.contains?.(event.relatedTarget)) item?.classList.remove("drop-target", "drop-blocked");
|
|
6063
|
+
}
|
|
6064
|
+
|
|
6065
|
+
async function dropFileTreeEntry(event, entry = {}) {
|
|
6066
|
+
const source = fileTreeDragSourceFromEvent(event);
|
|
6067
|
+
if (!source || !fileTreeEntryIsDirectory(entry)) return;
|
|
6068
|
+
const targetPath = normalizeFileTreePath(entry.path || "");
|
|
6069
|
+
if (!fileTreeCanDropOnDirectory(source.path, targetPath, source.entry)) return;
|
|
6070
|
+
event.preventDefault();
|
|
6071
|
+
event.stopPropagation();
|
|
6072
|
+
finishFileTreeDrag();
|
|
6073
|
+
await moveFileTreeEntryToDestination(source.entry || { path: source.path, type: source.type }, targetPath, { viaDragDrop: true });
|
|
6074
|
+
}
|
|
6075
|
+
|
|
6076
|
+
function bindFileTreeDragAndDrop(button, item, entry = {}) {
|
|
6077
|
+
if (!button || !item) return;
|
|
6078
|
+
const movable = fileTreeEntryIsMovable(entry);
|
|
6079
|
+
button.draggable = movable;
|
|
6080
|
+
button.classList.toggle("file-tree-draggable", movable);
|
|
6081
|
+
if (movable) {
|
|
6082
|
+
button.addEventListener("dragstart", (event) => beginFileTreeDrag(event, entry, item));
|
|
6083
|
+
button.addEventListener("dragend", finishFileTreeDrag);
|
|
6084
|
+
}
|
|
6085
|
+
if (fileTreeEntryIsDirectory(entry)) {
|
|
6086
|
+
for (const target of [button, item]) {
|
|
6087
|
+
target.addEventListener("dragenter", (event) => updateFileTreeDropTarget(event, entry, item));
|
|
6088
|
+
target.addEventListener("dragover", (event) => updateFileTreeDropTarget(event, entry, item));
|
|
6089
|
+
target.addEventListener("dragleave", (event) => clearFileTreeDropTarget(event, item));
|
|
6090
|
+
target.addEventListener("drop", (event) => dropFileTreeEntry(event, entry).catch((error) => addEvent(error.message || String(error), "error")));
|
|
6091
|
+
}
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
|
|
6095
|
+
function handleFileTreeRootDragOver(event) {
|
|
6096
|
+
const delegatedTarget = fileTreeDropTargetFromEvent(event);
|
|
6097
|
+
if (delegatedTarget) {
|
|
6098
|
+
updateFileTreeDropTarget(event, delegatedTarget.entry, delegatedTarget.item);
|
|
6099
|
+
return;
|
|
6100
|
+
}
|
|
6101
|
+
const source = fileTreeDragSourceFromEvent(event);
|
|
6102
|
+
if (!source) return;
|
|
6103
|
+
const allowed = fileTreeCanDropOnDirectory(source.path, FILE_TREE_ROOT_PATH, source.entry);
|
|
6104
|
+
elements.fileTreeRoot?.classList.toggle("drop-blocked", !allowed);
|
|
6105
|
+
if (!allowed) {
|
|
6106
|
+
event.dataTransfer.dropEffect = "none";
|
|
6107
|
+
return;
|
|
6108
|
+
}
|
|
6109
|
+
event.preventDefault();
|
|
6110
|
+
event.dataTransfer.dropEffect = "move";
|
|
6111
|
+
elements.fileTreeRoot?.classList.add("drag-root-drop");
|
|
6112
|
+
}
|
|
6113
|
+
|
|
6114
|
+
function handleFileTreeRootDragLeave(event) {
|
|
6115
|
+
if (elements.fileTreeRoot?.contains?.(event.relatedTarget)) return;
|
|
6116
|
+
elements.fileTreeRoot?.classList.remove("drag-root-drop", "drop-blocked");
|
|
6117
|
+
}
|
|
6118
|
+
|
|
6119
|
+
async function handleFileTreeRootDrop(event) {
|
|
6120
|
+
const delegatedTarget = fileTreeDropTargetFromEvent(event);
|
|
6121
|
+
if (delegatedTarget) {
|
|
6122
|
+
await dropFileTreeEntry(event, delegatedTarget.entry);
|
|
6123
|
+
return;
|
|
6124
|
+
}
|
|
6125
|
+
const source = fileTreeDragSourceFromEvent(event);
|
|
6126
|
+
if (!source || !fileTreeCanDropOnDirectory(source.path, FILE_TREE_ROOT_PATH, source.entry)) return;
|
|
6127
|
+
event.preventDefault();
|
|
6128
|
+
finishFileTreeDrag();
|
|
6129
|
+
await moveFileTreeEntryToDestination(source.entry || { path: source.path, type: source.type }, FILE_TREE_ROOT_PATH, { viaDragDrop: true });
|
|
6130
|
+
}
|
|
6131
|
+
|
|
6132
|
+
function clearFileTreeEntryCache(filePath = "") {
|
|
6133
|
+
const normalized = normalizeFileTreePath(filePath);
|
|
6134
|
+
if (!normalized) {
|
|
6135
|
+
fileTreeState.entriesByPath.clear();
|
|
6136
|
+
fileTreeState.expanded.clear();
|
|
6137
|
+
fileTreeState.loading.clear();
|
|
6138
|
+
return;
|
|
6139
|
+
}
|
|
6140
|
+
for (const key of [...fileTreeState.entriesByPath.keys()]) {
|
|
6141
|
+
if (key === normalized || key.startsWith(`${normalized}/`)) fileTreeState.entriesByPath.delete(key);
|
|
6142
|
+
}
|
|
6143
|
+
for (const key of [...fileTreeState.expanded]) {
|
|
6144
|
+
if (key === normalized || key.startsWith(`${normalized}/`)) fileTreeState.expanded.delete(key);
|
|
6145
|
+
}
|
|
6146
|
+
for (const key of [...fileTreeState.loading]) {
|
|
6147
|
+
if (key === normalized || key.startsWith(`${normalized}/`)) fileTreeState.loading.delete(key);
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
|
|
6151
|
+
async function refreshFileTreeAfterOperation(paths = []) {
|
|
6152
|
+
if (fileTreeSearchQueryText()) {
|
|
6153
|
+
await runFileTreeSearch();
|
|
6154
|
+
return;
|
|
6155
|
+
}
|
|
6156
|
+
const uniquePaths = [...new Set(paths.map((item) => normalizeFileTreePath(item)))];
|
|
6157
|
+
if (!uniquePaths.length) {
|
|
6158
|
+
renderFileTree();
|
|
6159
|
+
return;
|
|
6160
|
+
}
|
|
6161
|
+
for (const path of uniquePaths) await loadFileTreeDirectory(path, { force: true });
|
|
6162
|
+
renderFileTree();
|
|
6163
|
+
}
|
|
6164
|
+
|
|
6165
|
+
function updateActiveFileViewerAfterMove(sourcePath = "", destinationPath = "") {
|
|
6166
|
+
if (!activeFileViewer) return;
|
|
6167
|
+
const currentPath = normalizeFileTreePath(activeFileViewer.path || "");
|
|
6168
|
+
const nextPath = remapFileTreePathAfterMove(currentPath, sourcePath, destinationPath);
|
|
6169
|
+
if (!nextPath || nextPath === currentPath) return;
|
|
6170
|
+
const language = fileLanguageForPath(nextPath);
|
|
6171
|
+
activeFileViewer = {
|
|
6172
|
+
...activeFileViewer,
|
|
6173
|
+
path: nextPath,
|
|
6174
|
+
name: fileDisplayName(nextPath),
|
|
6175
|
+
extension: fileExtensionForPath(nextPath),
|
|
6176
|
+
language,
|
|
6177
|
+
mode: activeFileViewer.mode === "preview" && language === "markdown" ? "preview" : "source",
|
|
6178
|
+
};
|
|
6179
|
+
if (fileViewerSelection) fileViewerSelection = { ...fileViewerSelection, path: nextPath, fileName: activeFileViewer.name };
|
|
6180
|
+
updateFileViewerUi();
|
|
6181
|
+
}
|
|
6182
|
+
|
|
6183
|
+
function closeActiveFileViewerIfDeleted(deletedPath = "") {
|
|
6184
|
+
if (!activeFileViewer || !filePathWithinOrEqual(activeFileViewer.path, deletedPath)) return false;
|
|
6185
|
+
closeFileViewer();
|
|
6186
|
+
return true;
|
|
6187
|
+
}
|
|
6188
|
+
|
|
6189
|
+
async function deleteFileTreeEntry(entry = fileContextMenuState?.entry) {
|
|
6190
|
+
if (!entry) return;
|
|
6191
|
+
const sourcePath = normalizeFileTreePath(entry.path || "");
|
|
6192
|
+
if (!sourcePath) {
|
|
6193
|
+
addEvent("Workspace root cannot be deleted from the Files panel.", "warn");
|
|
6194
|
+
return;
|
|
6195
|
+
}
|
|
6196
|
+
const typeLabel = fileOperationTypeLabel(entry);
|
|
6197
|
+
const dirtyWarning = activeFileViewer?.dirty && filePathWithinOrEqual(activeFileViewer.path, sourcePath)
|
|
6198
|
+
? "\n\nThe currently open file has unsaved edits that will be discarded from the viewer."
|
|
6199
|
+
: "";
|
|
6200
|
+
const recursiveWarning = typeLabel === "directory" ? "\n\nThis permanently deletes the directory and all of its contents." : "";
|
|
6201
|
+
if (!window.confirm(`Delete ${typeLabel} ${sourcePath}?${recursiveWarning}${dirtyWarning}\n\nThis cannot be undone.`)) return;
|
|
6202
|
+
const tabContext = activeTabContext();
|
|
6203
|
+
setFileTreeStatus(`Deleting ${sourcePath}…`);
|
|
6204
|
+
try {
|
|
6205
|
+
const response = await api("/api/files", { method: "DELETE", body: { path: sourcePath, confirmed: true }, tabId: tabContext.tabId });
|
|
6206
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
6207
|
+
const data = response.data || {};
|
|
6208
|
+
closeActiveFileViewerIfDeleted(sourcePath);
|
|
6209
|
+
clearFileTreeEntryCache(sourcePath);
|
|
6210
|
+
fileTreeState.selectedPath = "";
|
|
6211
|
+
await refreshFileTreeAfterOperation([data.parentPath ?? fileParentPath(sourcePath)]);
|
|
6212
|
+
setFileTreeStatus(`Deleted ${data.path || sourcePath}.`, "success");
|
|
6213
|
+
addEvent(`deleted ${data.path || sourcePath}`, "warn");
|
|
6214
|
+
} catch (error) {
|
|
6215
|
+
if (isCurrentTabContext(tabContext)) {
|
|
6216
|
+
setFileTreeStatus(error.message || String(error), "error");
|
|
6217
|
+
addEvent(`file delete failed: ${error.message || String(error)}`, "error");
|
|
6218
|
+
}
|
|
6219
|
+
}
|
|
6220
|
+
}
|
|
6221
|
+
|
|
6222
|
+
async function moveFileTreeEntryToDestination(entry = {}, destinationPath = "", { viaDragDrop = false, confirmMove = false } = {}) {
|
|
6223
|
+
const sourcePath = normalizeFileTreePath(entry.path || "");
|
|
6224
|
+
const normalizedDestination = normalizeFileTreePath(destinationPath);
|
|
6225
|
+
if (!sourcePath) {
|
|
6226
|
+
addEvent("Workspace root cannot be moved from the Files panel.", "warn");
|
|
6227
|
+
return;
|
|
6228
|
+
}
|
|
6229
|
+
if (!normalizedDestination && normalizedDestination !== FILE_TREE_ROOT_PATH) {
|
|
6230
|
+
addEvent("Destination path is required.", "warn");
|
|
6231
|
+
return;
|
|
6232
|
+
}
|
|
6233
|
+
const typeLabel = fileOperationTypeLabel(entry);
|
|
6234
|
+
if (confirmMove && !window.confirm(`Move ${typeLabel}?\n\nFrom: ${sourcePath}\nTo: ${normalizedDestination || "."}\n\nExisting destination paths are refused.`)) return;
|
|
6235
|
+
const tabContext = activeTabContext();
|
|
6236
|
+
const isDirectory = fileTreeEntryIsDirectory(entry);
|
|
6237
|
+
const restoreSourceExpanded = isDirectory && fileTreeState.expanded.has(sourcePath) && !fileTreeSearchQueryText();
|
|
6238
|
+
const expandDestinationDirectory = viaDragDrop && !fileTreeSearchQueryText();
|
|
6239
|
+
setFileTreeStatus(`Moving ${sourcePath}…`);
|
|
6240
|
+
try {
|
|
6241
|
+
const response = await api("/api/files/move", { method: "POST", body: { path: sourcePath, toPath: normalizedDestination || ".", confirmed: true }, tabId: tabContext.tabId });
|
|
6242
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
6243
|
+
const data = response.data || {};
|
|
6244
|
+
const nextPath = normalizeFileTreePath(data.destination || normalizedDestination);
|
|
6245
|
+
const sourceParent = data.parentPath ?? fileParentPath(sourcePath);
|
|
6246
|
+
const destinationParent = data.destinationParentPath ?? fileParentPath(nextPath);
|
|
6247
|
+
clearFileTreeEntryCache(sourcePath);
|
|
6248
|
+
clearFileTreeEntryCache(nextPath);
|
|
6249
|
+
if (restoreSourceExpanded && nextPath) fileTreeState.expanded.add(nextPath);
|
|
6250
|
+
if (expandDestinationDirectory) fileTreeState.expanded.add(normalizedDestination);
|
|
6251
|
+
fileTreeState.selectedPath = nextPath;
|
|
6252
|
+
updateActiveFileViewerAfterMove(sourcePath, nextPath);
|
|
6253
|
+
await refreshFileTreeAfterOperation([sourceParent, destinationParent]);
|
|
6254
|
+
if (restoreSourceExpanded && nextPath) await loadFileTreeDirectory(nextPath, { force: true });
|
|
6255
|
+
if (expandDestinationDirectory) await loadFileTreeDirectory(normalizedDestination, { force: true });
|
|
6256
|
+
renderFileTree();
|
|
6257
|
+
setFileTreeStatus(`Moved ${sourcePath} to ${nextPath}.`, "success");
|
|
6258
|
+
addEvent(`${viaDragDrop ? "drag-moved" : "moved"} ${sourcePath} to ${nextPath}`, "info");
|
|
6259
|
+
} catch (error) {
|
|
6260
|
+
if (isCurrentTabContext(tabContext)) {
|
|
6261
|
+
setFileTreeStatus(error.message || String(error), "error");
|
|
6262
|
+
addEvent(`file move failed: ${error.message || String(error)}`, "error");
|
|
6263
|
+
}
|
|
6264
|
+
}
|
|
6265
|
+
}
|
|
6266
|
+
|
|
6267
|
+
async function moveFileTreeEntry(entry = fileContextMenuState?.entry) {
|
|
6268
|
+
if (!entry) return;
|
|
6269
|
+
const sourcePath = normalizeFileTreePath(entry.path || "");
|
|
6270
|
+
if (!sourcePath) {
|
|
6271
|
+
addEvent("Workspace root cannot be moved from the Files panel.", "warn");
|
|
6272
|
+
return;
|
|
6273
|
+
}
|
|
6274
|
+
const typeLabel = fileOperationTypeLabel(entry);
|
|
6275
|
+
const destinationInput = window.prompt([
|
|
6276
|
+
`Move/rename ${typeLabel} ${sourcePath}`,
|
|
6277
|
+
"",
|
|
6278
|
+
"Enter a destination path inside the current workspace.",
|
|
6279
|
+
`Existing directories receive the ${typeLabel} as a child.`,
|
|
6280
|
+
].join("\n"), sourcePath);
|
|
6281
|
+
if (destinationInput === null) return;
|
|
6282
|
+
const destinationPath = String(destinationInput || "").trim();
|
|
6283
|
+
if (!destinationPath) {
|
|
6284
|
+
addEvent("Destination path is required.", "warn");
|
|
6285
|
+
return;
|
|
6286
|
+
}
|
|
6287
|
+
await moveFileTreeEntryToDestination(entry, destinationPath, { confirmMove: true });
|
|
6288
|
+
}
|
|
6289
|
+
|
|
6290
|
+
function readStoredFileViewerWidth() {
|
|
6291
|
+
try {
|
|
6292
|
+
const width = Number.parseFloat(localStorage.getItem(FILE_VIEWER_WIDTH_STORAGE_KEY) || "");
|
|
6293
|
+
return Number.isFinite(width) && width >= FILE_VIEWER_WIDTH_MIN_PX ? width : null;
|
|
6294
|
+
} catch {
|
|
6295
|
+
return null;
|
|
6296
|
+
}
|
|
6297
|
+
}
|
|
6298
|
+
|
|
6299
|
+
function persistFileViewerWidth(width) {
|
|
6300
|
+
try {
|
|
6301
|
+
localStorage.setItem(FILE_VIEWER_WIDTH_STORAGE_KEY, String(Math.round(width)));
|
|
6302
|
+
} catch {
|
|
6303
|
+
// Ignore storage failures; resizing should still work for this page load.
|
|
6304
|
+
}
|
|
6305
|
+
}
|
|
6306
|
+
|
|
6307
|
+
function fileViewerMaxWidth() {
|
|
6308
|
+
const layout = document.querySelector(".layout");
|
|
6309
|
+
const layoutRect = layout?.getBoundingClientRect?.();
|
|
6310
|
+
const layoutWidth = layoutRect?.width || window.innerWidth || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
6311
|
+
const layoutStyle = layout ? getComputedStyle(layout) : null;
|
|
6312
|
+
const gap = Number.parseFloat(layoutStyle?.columnGap || layoutStyle?.gap || "0") || 0;
|
|
6313
|
+
const sidePanelVisible = !document.body.classList.contains("side-panel-collapsed") && elements.sidePanel && getComputedStyle(elements.sidePanel).display !== "none";
|
|
6314
|
+
const sidePanelWidth = sidePanelVisible ? elements.sidePanel.getBoundingClientRect().width : 0;
|
|
6315
|
+
const splitOpen = document.body.classList.contains("terminal-split-open");
|
|
6316
|
+
const primaryMinWidth = splitOpen ? 560 : 320;
|
|
6317
|
+
const gapCount = splitOpen ? (sidePanelVisible ? 3 : 2) : (sidePanelVisible ? 2 : 1);
|
|
6318
|
+
const available = layoutWidth - sidePanelWidth - primaryMinWidth - (gap * gapCount);
|
|
6319
|
+
return Math.max(FILE_VIEWER_WIDTH_MIN_PX, Math.min(Math.floor(layoutWidth * 0.78), Math.floor(available)));
|
|
6320
|
+
}
|
|
6321
|
+
|
|
6322
|
+
function clampFileViewerWidth(width) {
|
|
6323
|
+
const number = Number(width);
|
|
6324
|
+
const max = fileViewerMaxWidth();
|
|
6325
|
+
const fallback = readStoredFileViewerWidth() || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
6326
|
+
return Math.max(FILE_VIEWER_WIDTH_MIN_PX, Math.min(max, Number.isFinite(number) ? number : fallback));
|
|
6327
|
+
}
|
|
6328
|
+
|
|
6329
|
+
function currentFileViewerWidth() {
|
|
6330
|
+
const width = elements.fileViewerPane?.getBoundingClientRect?.().width;
|
|
6331
|
+
return Number.isFinite(width) && width > 0 ? width : readStoredFileViewerWidth() || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
6332
|
+
}
|
|
6333
|
+
|
|
6334
|
+
function updateFileViewerResizeHandle(width = currentFileViewerWidth()) {
|
|
6335
|
+
const handle = elements.fileViewerResizeHandle;
|
|
6336
|
+
if (!handle) return;
|
|
6337
|
+
const resizeAvailable = !!activeFileViewer && !isSidePanelOverlayView();
|
|
6338
|
+
handle.hidden = !resizeAvailable;
|
|
6339
|
+
handle.setAttribute("aria-valuemin", String(FILE_VIEWER_WIDTH_MIN_PX));
|
|
6340
|
+
handle.setAttribute("aria-valuemax", String(fileViewerMaxWidth()));
|
|
6341
|
+
handle.setAttribute("aria-valuenow", String(Math.round(width)));
|
|
6342
|
+
handle.setAttribute("aria-valuetext", `${Math.round(width)} pixels wide`);
|
|
6343
|
+
}
|
|
6344
|
+
|
|
6345
|
+
function applyFileViewerWidth(width, { persist = false } = {}) {
|
|
6346
|
+
const clamped = clampFileViewerWidth(width);
|
|
6347
|
+
document.documentElement.style.setProperty("--file-viewer-width", `${Math.round(clamped)}px`);
|
|
6348
|
+
updateFileViewerResizeHandle(clamped);
|
|
6349
|
+
if (persist) persistFileViewerWidth(clamped);
|
|
6350
|
+
return clamped;
|
|
6351
|
+
}
|
|
6352
|
+
|
|
6353
|
+
function restoreFileViewerWidthPreference() {
|
|
6354
|
+
const width = readStoredFileViewerWidth();
|
|
6355
|
+
if (width) document.documentElement.style.setProperty("--file-viewer-width", `${Math.round(width)}px`);
|
|
6356
|
+
updateFileViewerResizeHandle(width || FILE_VIEWER_WIDTH_DEFAULT_PX);
|
|
6357
|
+
}
|
|
6358
|
+
|
|
6359
|
+
function beginFileViewerResize(event) {
|
|
6360
|
+
if (!activeFileViewer || isSidePanelOverlayView()) return;
|
|
6361
|
+
if (event.button !== undefined && event.button !== 0) return;
|
|
6362
|
+
event.preventDefault();
|
|
6363
|
+
const startWidth = currentFileViewerWidth();
|
|
6364
|
+
fileViewerResizeState = { pointerId: event.pointerId, startX: event.clientX, startWidth, width: startWidth };
|
|
6365
|
+
document.body.classList.add("file-viewer-resizing");
|
|
6366
|
+
elements.fileViewerResizeHandle?.setPointerCapture?.(event.pointerId);
|
|
6367
|
+
window.addEventListener("pointermove", updateFileViewerResize, { passive: false });
|
|
6368
|
+
window.addEventListener("pointerup", finishFileViewerResize, { passive: false });
|
|
6369
|
+
window.addEventListener("pointercancel", finishFileViewerResize, { passive: false });
|
|
6370
|
+
}
|
|
6371
|
+
|
|
6372
|
+
function updateFileViewerResize(event) {
|
|
6373
|
+
const state = fileViewerResizeState;
|
|
6374
|
+
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
6375
|
+
event.preventDefault();
|
|
6376
|
+
state.width = applyFileViewerWidth(state.startWidth + (state.startX - event.clientX));
|
|
6377
|
+
}
|
|
6378
|
+
|
|
6379
|
+
function finishFileViewerResize(event) {
|
|
6380
|
+
const state = fileViewerResizeState;
|
|
6381
|
+
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
6382
|
+
event.preventDefault?.();
|
|
6383
|
+
elements.fileViewerResizeHandle?.releasePointerCapture?.(state.pointerId);
|
|
6384
|
+
window.removeEventListener("pointermove", updateFileViewerResize);
|
|
6385
|
+
window.removeEventListener("pointerup", finishFileViewerResize);
|
|
6386
|
+
window.removeEventListener("pointercancel", finishFileViewerResize);
|
|
6387
|
+
document.body.classList.remove("file-viewer-resizing");
|
|
6388
|
+
applyFileViewerWidth(state.width, { persist: true });
|
|
6389
|
+
fileViewerResizeState = null;
|
|
6390
|
+
}
|
|
6391
|
+
|
|
6392
|
+
function handleFileViewerResizeKeydown(event) {
|
|
6393
|
+
if (!activeFileViewer || isSidePanelOverlayView()) return;
|
|
6394
|
+
const step = event.shiftKey ? 80 : 24;
|
|
6395
|
+
const current = currentFileViewerWidth();
|
|
6396
|
+
let next = current;
|
|
6397
|
+
if (event.key === "ArrowLeft") next = current + step;
|
|
6398
|
+
else if (event.key === "ArrowRight") next = current - step;
|
|
6399
|
+
else if (event.key === "Home") next = FILE_VIEWER_WIDTH_MIN_PX;
|
|
6400
|
+
else if (event.key === "End") next = fileViewerMaxWidth();
|
|
6401
|
+
else return;
|
|
6402
|
+
event.preventDefault();
|
|
6403
|
+
applyFileViewerWidth(next, { persist: true });
|
|
6404
|
+
}
|
|
6405
|
+
|
|
6406
|
+
function syncFileViewerWidthForViewport() {
|
|
6407
|
+
if (!activeFileViewer) {
|
|
6408
|
+
updateFileViewerResizeHandle();
|
|
6409
|
+
return;
|
|
6410
|
+
}
|
|
6411
|
+
if (isSidePanelOverlayView()) {
|
|
6412
|
+
updateFileViewerResizeHandle();
|
|
6413
|
+
return;
|
|
6414
|
+
}
|
|
6415
|
+
applyFileViewerWidth(currentFileViewerWidth());
|
|
6416
|
+
}
|
|
6417
|
+
|
|
6418
|
+
async function openFileTreeEntryInWebui(entry = fileContextMenuState?.entry) {
|
|
6419
|
+
if (!entry) return;
|
|
6420
|
+
const path = normalizeFileTreePath(entry.path || "");
|
|
6421
|
+
if (entry.type === "directory" || entry.directory === true) {
|
|
6422
|
+
if (fileTreeState.searchQuery || fileTreeSearchQueryText()) return revealFileTreeEntry(entry);
|
|
6423
|
+
fileTreeState.expanded.add(path);
|
|
6424
|
+
await loadFileTreeDirectory(path);
|
|
6425
|
+
return;
|
|
6426
|
+
}
|
|
6427
|
+
await openFileInViewer(path);
|
|
6428
|
+
}
|
|
6429
|
+
|
|
6430
|
+
function setFileViewerMode(mode = "source") {
|
|
6431
|
+
if (!activeFileViewer) return;
|
|
6432
|
+
const nextMode = mode === "preview" && activeFileViewer.language === "markdown" ? "preview" : "source";
|
|
6433
|
+
activeFileViewer.mode = nextMode;
|
|
6434
|
+
updateFileViewerUi();
|
|
6435
|
+
}
|
|
6436
|
+
|
|
6437
|
+
function setFileViewerDirty(dirty) {
|
|
6438
|
+
if (!activeFileViewer) return;
|
|
6439
|
+
activeFileViewer.dirty = !!dirty;
|
|
6440
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = !activeFileViewer.dirty;
|
|
6441
|
+
if (activeFileViewer.dirty) setFileViewerStatus("Unsaved file edits.", "warn");
|
|
6442
|
+
}
|
|
6443
|
+
|
|
6444
|
+
function updateFileViewerUi() {
|
|
6445
|
+
const open = !!activeFileViewer;
|
|
6446
|
+
document.body.classList.toggle("file-viewer-open", open);
|
|
6447
|
+
if (elements.fileViewerPane) elements.fileViewerPane.hidden = !open;
|
|
6448
|
+
updateFileViewerResizeHandle();
|
|
6449
|
+
if (!open) return;
|
|
6450
|
+
if (!isSidePanelOverlayView()) applyFileViewerWidth(currentFileViewerWidth());
|
|
6451
|
+
const viewer = activeFileViewer;
|
|
6452
|
+
const isMarkdown = viewer.language === "markdown";
|
|
6453
|
+
const mode = viewer.mode === "preview" && isMarkdown ? "preview" : "source";
|
|
6454
|
+
viewer.mode = mode;
|
|
6455
|
+
if (elements.fileViewerTitle) elements.fileViewerTitle.textContent = viewer.name || fileDisplayName(viewer.path);
|
|
6456
|
+
if (elements.fileViewerMeta) {
|
|
6457
|
+
const lineCount = textLineCount(viewer.content || "");
|
|
6458
|
+
elements.fileViewerMeta.textContent = [viewer.path, formatBytes(viewer.size), `${lineCount} ${lineCount === 1 ? "line" : "lines"}`].filter(Boolean).join(" · ");
|
|
6459
|
+
}
|
|
6460
|
+
if (elements.fileViewerSourceModeButton) {
|
|
6461
|
+
elements.fileViewerSourceModeButton.setAttribute("aria-pressed", mode === "source" ? "true" : "false");
|
|
6462
|
+
elements.fileViewerSourceModeButton.classList.toggle("active", mode === "source");
|
|
6463
|
+
}
|
|
6464
|
+
if (elements.fileViewerPreviewModeButton) {
|
|
6465
|
+
elements.fileViewerPreviewModeButton.hidden = !isMarkdown;
|
|
6466
|
+
elements.fileViewerPreviewModeButton.disabled = !isMarkdown;
|
|
6467
|
+
elements.fileViewerPreviewModeButton.setAttribute("aria-pressed", mode === "preview" ? "true" : "false");
|
|
6468
|
+
elements.fileViewerPreviewModeButton.classList.toggle("active", mode === "preview");
|
|
6469
|
+
}
|
|
6470
|
+
if (elements.fileViewerEditor) {
|
|
6471
|
+
elements.fileViewerEditor.hidden = mode !== "source";
|
|
6472
|
+
if (elements.fileViewerEditor.value !== viewer.content) elements.fileViewerEditor.value = viewer.content || "";
|
|
6473
|
+
}
|
|
6474
|
+
if (elements.fileViewerPreview) {
|
|
6475
|
+
elements.fileViewerPreview.hidden = mode !== "preview";
|
|
6476
|
+
if (mode === "preview") renderMarkdown(elements.fileViewerPreview, viewer.content || "");
|
|
6477
|
+
}
|
|
6478
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = !viewer.dirty;
|
|
6479
|
+
if (elements.fileViewerOpenDefaultButton) {
|
|
6480
|
+
const viewerPath = normalizeFileTreePath(viewer.path || "");
|
|
6481
|
+
elements.fileViewerOpenDefaultButton.dataset.path = viewerPath;
|
|
6482
|
+
elements.fileViewerOpenDefaultButton.disabled = !viewerPath;
|
|
6483
|
+
}
|
|
6484
|
+
renderFileViewerSelectionBar();
|
|
6485
|
+
}
|
|
6486
|
+
|
|
6487
|
+
function clearFileViewerSelection() {
|
|
6488
|
+
fileViewerSelection = null;
|
|
6489
|
+
renderFileViewerSelectionBar();
|
|
6490
|
+
}
|
|
6491
|
+
|
|
6492
|
+
function selectedTextFromEditor() {
|
|
6493
|
+
const editor = elements.fileViewerEditor;
|
|
6494
|
+
if (!editor || editor.hidden || !activeFileViewer) return null;
|
|
6495
|
+
const start = editor.selectionStart;
|
|
6496
|
+
const end = editor.selectionEnd;
|
|
6497
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return null;
|
|
6498
|
+
return { start, end, text: editor.value.slice(start, end) };
|
|
6499
|
+
}
|
|
6500
|
+
|
|
6501
|
+
function lineColumnForOffset(text, offset) {
|
|
6502
|
+
const prefix = String(text || "").slice(0, Math.max(0, offset));
|
|
6503
|
+
const lines = prefix.split("\n");
|
|
6504
|
+
return { line: lines.length, column: (lines.at(-1) || "").length + 1 };
|
|
6505
|
+
}
|
|
6506
|
+
|
|
6507
|
+
function fileSelectionLineRange(text, start, end) {
|
|
6508
|
+
const startPos = lineColumnForOffset(text, start);
|
|
6509
|
+
const endPos = lineColumnForOffset(text, end);
|
|
6510
|
+
return { startLine: startPos.line, endLine: endPos.line, startColumn: startPos.column, endColumn: endPos.column };
|
|
6511
|
+
}
|
|
6512
|
+
|
|
6513
|
+
function fileSelectionContext(text, start, end, radius = FILE_VIEWER_CONTEXT_RADIUS_LINES) {
|
|
6514
|
+
const value = String(text || "");
|
|
6515
|
+
const lines = value.split("\n");
|
|
6516
|
+
const range = fileSelectionLineRange(value, start, end);
|
|
6517
|
+
const fromLine = Math.max(1, range.startLine - radius);
|
|
6518
|
+
const toLine = Math.min(lines.length, range.endLine + radius);
|
|
6519
|
+
const contextLines = [];
|
|
6520
|
+
for (let line = fromLine; line <= toLine; line += 1) {
|
|
6521
|
+
contextLines.push(`${String(line).padStart(4, " ")}: ${lines[line - 1] || ""}`);
|
|
6522
|
+
}
|
|
6523
|
+
return { ...range, fromLine, toLine, context: contextLines.join("\n") };
|
|
6524
|
+
}
|
|
6525
|
+
|
|
6526
|
+
function updateFileViewerSelectionFromEditor() {
|
|
6527
|
+
if (!activeFileViewer) return;
|
|
6528
|
+
const selected = selectedTextFromEditor();
|
|
6529
|
+
if (!selected || !selected.text.trim()) {
|
|
6530
|
+
clearFileViewerSelection();
|
|
6531
|
+
return;
|
|
6532
|
+
}
|
|
6533
|
+
const context = fileSelectionContext(elements.fileViewerEditor.value || "", selected.start, selected.end);
|
|
6534
|
+
fileViewerSelection = { ...context, ...selected, path: activeFileViewer.path, fileName: activeFileViewer.name };
|
|
6535
|
+
renderFileViewerSelectionBar();
|
|
6536
|
+
}
|
|
6537
|
+
|
|
6538
|
+
function updateFileViewerSelectionFromPreview() {
|
|
6539
|
+
if (!activeFileViewer || elements.fileViewerPreview?.hidden) return;
|
|
6540
|
+
const selection = window.getSelection?.();
|
|
6541
|
+
const preview = elements.fileViewerPreview;
|
|
6542
|
+
if (!preview || !selection?.anchorNode || !selection?.focusNode || !preview.contains(selection.anchorNode) || !preview.contains(selection.focusNode)) return;
|
|
6543
|
+
const text = String(selection.toString?.() || "").trim();
|
|
6544
|
+
if (!text) {
|
|
6545
|
+
clearFileViewerSelection();
|
|
6546
|
+
return;
|
|
6547
|
+
}
|
|
6548
|
+
const content = activeFileViewer.content || "";
|
|
6549
|
+
const start = Math.max(0, content.indexOf(text));
|
|
6550
|
+
const end = start >= 0 ? start + text.length : start;
|
|
6551
|
+
const context = start >= 0
|
|
6552
|
+
? fileSelectionContext(content, start, end)
|
|
6553
|
+
: { startLine: 1, endLine: textLineCount(content), startColumn: 1, endColumn: 1, fromLine: 1, toLine: textLineCount(content), context: content.slice(0, 4000) };
|
|
6554
|
+
fileViewerSelection = { ...context, start, end, text, path: activeFileViewer.path, fileName: activeFileViewer.name };
|
|
6555
|
+
renderFileViewerSelectionBar();
|
|
6556
|
+
}
|
|
6557
|
+
|
|
6558
|
+
function renderFileViewerSelectionBar() {
|
|
6559
|
+
if (!elements.fileSelectionBar) return;
|
|
6560
|
+
const hasSelection = !!fileViewerSelection?.text;
|
|
6561
|
+
elements.fileSelectionBar.hidden = !hasSelection;
|
|
6562
|
+
if (!hasSelection) return;
|
|
6563
|
+
const lineLabel = fileViewerSelection.startLine === fileViewerSelection.endLine
|
|
6564
|
+
? `line ${fileViewerSelection.startLine}`
|
|
6565
|
+
: `lines ${fileViewerSelection.startLine}-${fileViewerSelection.endLine}`;
|
|
6566
|
+
if (elements.fileSelectionSummary) elements.fileSelectionSummary.textContent = `${lineLabel} · ${fileViewerSelection.text.length} chars selected`;
|
|
6567
|
+
}
|
|
6568
|
+
|
|
6569
|
+
function fileSelectionPrompt() {
|
|
6570
|
+
if (!activeFileViewer || !fileViewerSelection?.text) return "";
|
|
6571
|
+
const comment = (elements.fileSelectionCommentInput?.value || "").trim();
|
|
6572
|
+
const selection = fileViewerSelection;
|
|
6573
|
+
const range = selection.startLine === selection.endLine
|
|
6574
|
+
? `line ${selection.startLine}, columns ${selection.startColumn}-${selection.endColumn}`
|
|
6575
|
+
: `lines ${selection.startLine}-${selection.endLine}`;
|
|
6576
|
+
return [
|
|
6577
|
+
`File selection from ${activeFileViewer.path} (${range}).`,
|
|
6578
|
+
comment ? `User comment: ${comment}` : "User comment: <none>",
|
|
6579
|
+
"",
|
|
6580
|
+
"Selected text:",
|
|
6581
|
+
"```",
|
|
6582
|
+
selection.text,
|
|
6583
|
+
"```",
|
|
6584
|
+
"",
|
|
6585
|
+
`Surrounding context (${selection.fromLine}-${selection.toLine}):`,
|
|
6586
|
+
"```",
|
|
6587
|
+
selection.context || selection.text,
|
|
6588
|
+
"```",
|
|
6589
|
+
].join("\n");
|
|
6590
|
+
}
|
|
6591
|
+
|
|
6592
|
+
async function sendFileSelectionToSession() {
|
|
6593
|
+
const prompt = fileSelectionPrompt();
|
|
6594
|
+
if (!prompt) return;
|
|
6595
|
+
if (elements.fileSelectionSendButton) elements.fileSelectionSendButton.disabled = true;
|
|
6596
|
+
try {
|
|
6597
|
+
await sendPrompt("prompt", prompt, { targetTabId: activeTabId, throwOnError: true });
|
|
6598
|
+
if (elements.fileSelectionCommentInput) elements.fileSelectionCommentInput.value = "";
|
|
6599
|
+
setFileViewerStatus("Selection sent to the current Pi session.", "success");
|
|
6600
|
+
} catch (error) {
|
|
6601
|
+
setFileViewerStatus(error.message || String(error), "error");
|
|
6602
|
+
} finally {
|
|
6603
|
+
if (elements.fileSelectionSendButton) elements.fileSelectionSendButton.disabled = false;
|
|
6604
|
+
}
|
|
6605
|
+
}
|
|
6606
|
+
|
|
6607
|
+
function closeFileViewer() {
|
|
6608
|
+
activeFileViewer = null;
|
|
6609
|
+
clearFileViewerSelection();
|
|
6610
|
+
document.body.classList.remove("file-viewer-open");
|
|
6611
|
+
updateFileViewerResizeHandle();
|
|
6612
|
+
if (elements.fileViewerPane) elements.fileViewerPane.hidden = true;
|
|
6613
|
+
if (elements.fileViewerOpenDefaultButton) elements.fileViewerOpenDefaultButton.dataset.path = "";
|
|
6614
|
+
if (elements.fileViewerEditor) elements.fileViewerEditor.value = "";
|
|
6615
|
+
if (elements.fileViewerPreview) elements.fileViewerPreview.replaceChildren();
|
|
6616
|
+
setFileViewerStatus("");
|
|
6617
|
+
}
|
|
6618
|
+
|
|
6619
|
+
async function openFileInViewer(path = "") {
|
|
6620
|
+
const normalized = normalizeFileTreePath(path);
|
|
6621
|
+
if (!normalized) return;
|
|
6622
|
+
const tabContext = activeTabContext();
|
|
6623
|
+
fileTreeState.selectedPath = normalized;
|
|
6624
|
+
renderFileTree();
|
|
6625
|
+
setFileViewerStatus(`Opening ${normalized}…`);
|
|
6626
|
+
try {
|
|
6627
|
+
const response = await api(fileApiPath("/api/files/content", normalized), { tabId: tabContext.tabId });
|
|
6628
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
6629
|
+
const data = response.data || {};
|
|
6630
|
+
activeFileViewer = {
|
|
6631
|
+
path: normalizeFileTreePath(data.path || normalized),
|
|
6632
|
+
name: data.name || fileDisplayName(normalized),
|
|
6633
|
+
content: String(data.content || ""),
|
|
6634
|
+
size: Number(data.size) || 0,
|
|
6635
|
+
mtimeMs: Number(data.mtimeMs) || 0,
|
|
6636
|
+
extension: data.extension || "",
|
|
6637
|
+
language: data.language || "text",
|
|
6638
|
+
mode: data.language === "markdown" ? "preview" : "source",
|
|
6639
|
+
dirty: false,
|
|
6640
|
+
};
|
|
6641
|
+
if (elements.fileViewerEditor) elements.fileViewerEditor.value = activeFileViewer.content;
|
|
6642
|
+
clearFileViewerSelection();
|
|
6643
|
+
updateFileViewerUi();
|
|
6644
|
+
setFileViewerStatus("Opened in WebUI.", "success");
|
|
6645
|
+
} catch (error) {
|
|
6646
|
+
if (isCurrentTabContext(tabContext)) {
|
|
6647
|
+
setFileViewerStatus(error.message || String(error), "error");
|
|
6648
|
+
addEvent(`file open failed: ${error.message || String(error)}`, "error");
|
|
6649
|
+
}
|
|
6650
|
+
}
|
|
6651
|
+
}
|
|
6652
|
+
|
|
6653
|
+
async function saveActiveFileViewer() {
|
|
6654
|
+
if (!activeFileViewer || !elements.fileViewerEditor) return;
|
|
6655
|
+
const tabContext = activeTabContext();
|
|
6656
|
+
const content = elements.fileViewerEditor.value || "";
|
|
6657
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = true;
|
|
6658
|
+
setFileViewerStatus(`Saving ${activeFileViewer.path}…`);
|
|
6659
|
+
try {
|
|
6660
|
+
const response = await api("/api/files/content", { method: "POST", body: { path: activeFileViewer.path, content, mtimeMs: activeFileViewer.mtimeMs }, tabId: tabContext.tabId });
|
|
6661
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
6662
|
+
const data = response.data || {};
|
|
6663
|
+
activeFileViewer = { ...activeFileViewer, ...data, path: normalizeFileTreePath(data.path || activeFileViewer.path), content, dirty: false };
|
|
6664
|
+
updateFileViewerUi();
|
|
6665
|
+
await loadFileTreeDirectory(fileParentPath(activeFileViewer.path), { force: true });
|
|
6666
|
+
setFileViewerStatus("Saved.", "success");
|
|
6667
|
+
} catch (error) {
|
|
6668
|
+
if (isCurrentTabContext(tabContext)) setFileViewerStatus(error.message || String(error), "error");
|
|
6669
|
+
if (activeFileViewer && elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = false;
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
|
|
5329
6673
|
function eventTargetsActiveTab(event) {
|
|
5330
6674
|
return !event?.tabId || event.tabId === activeTabId;
|
|
5331
6675
|
}
|
|
@@ -5430,6 +6774,23 @@ function applyResponseTab(response) {
|
|
|
5430
6774
|
return applyTabMetadata(response?.tab || response?.data?.tab);
|
|
5431
6775
|
}
|
|
5432
6776
|
|
|
6777
|
+
function syncResponseTabs(response) {
|
|
6778
|
+
const payload = response?.data || {};
|
|
6779
|
+
if (Array.isArray(payload.tabs)) {
|
|
6780
|
+
tabs = payload.tabs;
|
|
6781
|
+
syncTabMetadata(tabs);
|
|
6782
|
+
}
|
|
6783
|
+
const tab = response?.tab || payload.tab || null;
|
|
6784
|
+
if (tab) applyTabMetadata(tab);
|
|
6785
|
+
return tab;
|
|
6786
|
+
}
|
|
6787
|
+
|
|
6788
|
+
async function switchToResponseTab(response) {
|
|
6789
|
+
const tab = syncResponseTabs(response);
|
|
6790
|
+
if (tab?.id) await switchTab(tab.id);
|
|
6791
|
+
return tab;
|
|
6792
|
+
}
|
|
6793
|
+
|
|
5433
6794
|
function activityForTab(tab) {
|
|
5434
6795
|
if (!tab?.id) return normalizeTabActivity();
|
|
5435
6796
|
return tabActivities.get(tab.id) || setTabActivity(tab.id, tab.activity) || normalizeTabActivity();
|
|
@@ -5640,7 +7001,7 @@ function restoreActiveDraft() {
|
|
|
5640
7001
|
|
|
5641
7002
|
function focusPromptInput({ defer = false } = {}) {
|
|
5642
7003
|
const focus = () => {
|
|
5643
|
-
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.promptListDialog?.open || elements.attachmentTextDialog?.open || elements.skillEditorDialog?.open || document.visibilityState === "hidden") return;
|
|
7004
|
+
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.promptListDialog?.open || elements.attachmentTextDialog?.open || elements.skillEditorDialog?.open || document.visibilityState === "hidden") return;
|
|
5644
7005
|
try {
|
|
5645
7006
|
elements.promptInput.focus({ preventScroll: true });
|
|
5646
7007
|
} catch {
|
|
@@ -5785,6 +7146,8 @@ function resetActiveTabUi() {
|
|
|
5785
7146
|
latestWorkspace = null;
|
|
5786
7147
|
latestMessages = [];
|
|
5787
7148
|
latestMessagesSessionKey = "";
|
|
7149
|
+
closeFileViewer();
|
|
7150
|
+
resetFileTreeState();
|
|
5788
7151
|
clearRunIndicatorActivity({ render: false });
|
|
5789
7152
|
statusEntries.clear();
|
|
5790
7153
|
restoreWidgetsForActiveTab();
|
|
@@ -5803,6 +7166,7 @@ function resetActiveTabUi() {
|
|
|
5803
7166
|
hideCommandSuggestions();
|
|
5804
7167
|
cancelPendingDialogs();
|
|
5805
7168
|
if (elements.nativeCommandDialog.open) closeNativeCommandDialog();
|
|
7169
|
+
if (elements.gitFooterVisibilityDialog?.open) closeGitFooterVisibilityDialog();
|
|
5806
7170
|
if (pathPickerState) closePathPicker(null);
|
|
5807
7171
|
bindGitWorkflowToActiveTab();
|
|
5808
7172
|
resetChatOutput();
|
|
@@ -7485,6 +8849,297 @@ const GIT_FOOTER_TOOLTIP_COPY = {
|
|
|
7485
8849
|
thinking: "Reasoning/thinking effort for this tab.",
|
|
7486
8850
|
};
|
|
7487
8851
|
|
|
8852
|
+
const GIT_FOOTER_VISIBILITY_GROUPS = Object.freeze([
|
|
8853
|
+
{
|
|
8854
|
+
label: "Cards & chips",
|
|
8855
|
+
description: "Main footer cards and extra status chips rendered in the browser footer.",
|
|
8856
|
+
keys: ["tokens", "cache", "pi", "speed", "cost", "context", "cwd", "git", "git-state", "sync", "changes", "git-extra", "worktree", "model", "thinking", "context-meta"],
|
|
8857
|
+
},
|
|
8858
|
+
{
|
|
8859
|
+
label: "Git subitems",
|
|
8860
|
+
description: "Fine-grained pieces inside the Git branch, sync, changes, and git+ chips.",
|
|
8861
|
+
keys: ["git-branch-indicator", "git-detached", "git-operation", "git-ahead", "git-behind", "git-upstream", "git-staged", "git-unstaged", "git-untracked", "git-conflicted", "git-clean", "git-stash", "git-submodules", "git-worktrees", "git-tag", "git-last-commit-age", "git-signing-mismatch", "webui-fetch-state"],
|
|
8862
|
+
},
|
|
8863
|
+
{
|
|
8864
|
+
label: "WebUI actions & modals",
|
|
8865
|
+
description: "Buttons, pickers, popovers, and modal affordances attached to footer chips.",
|
|
8866
|
+
keys: ["webui-refresh-button", "webui-details-button", "webui-cwd-picker", "webui-pi-calibration", "webui-context-auto-compaction", "webui-branch-picker", "webui-git-init", "webui-sync-push", "webui-changes-modal", "webui-git-tools-modal", "webui-model-picker", "webui-thinking-picker", "webui-changed-files-popover"],
|
|
8867
|
+
},
|
|
8868
|
+
{
|
|
8869
|
+
label: "Native parity keys",
|
|
8870
|
+
description: "Keys shared with the native footer command set; these are kept for parity even when they have little browser-visible effect.",
|
|
8871
|
+
keys: ["cwd-branch", "git-status", "extension-statuses"],
|
|
8872
|
+
},
|
|
8873
|
+
]);
|
|
8874
|
+
const GIT_FOOTER_VISIBILITY_GROUPED_KEYS = new Set(GIT_FOOTER_VISIBILITY_GROUPS.flatMap((group) => group.keys));
|
|
8875
|
+
const GIT_FOOTER_VISIBILITY_DIALOG_KEYS = Object.freeze([
|
|
8876
|
+
...GIT_FOOTER_VISIBILITY_GROUPS.flatMap((group) => group.keys),
|
|
8877
|
+
...Object.keys(GIT_FOOTER_WEBUI_VISIBILITY_DEFAULTS).filter((key) => !GIT_FOOTER_VISIBILITY_GROUPED_KEYS.has(key)),
|
|
8878
|
+
]);
|
|
8879
|
+
const GIT_FOOTER_VISIBILITY_LABELS = Object.freeze({
|
|
8880
|
+
tokens: "Tokens card",
|
|
8881
|
+
cache: "Cache card",
|
|
8882
|
+
pi: "PI estimate card",
|
|
8883
|
+
speed: "Speed card",
|
|
8884
|
+
cost: "Cost card",
|
|
8885
|
+
context: "Context card",
|
|
8886
|
+
cwd: "Working directory chip",
|
|
8887
|
+
git: "Git branch chip",
|
|
8888
|
+
"git-state": "Git state chip",
|
|
8889
|
+
sync: "Sync chip",
|
|
8890
|
+
changes: "Changes chip",
|
|
8891
|
+
"git-extra": "Git+ chip",
|
|
8892
|
+
worktree: "Worktree chip",
|
|
8893
|
+
model: "Model chip",
|
|
8894
|
+
thinking: "Thinking chip",
|
|
8895
|
+
"context-meta": "Context meta chip",
|
|
8896
|
+
"git-branch-indicator": "Branch indicator",
|
|
8897
|
+
"git-detached": "Detached marker",
|
|
8898
|
+
"git-operation": "Operation marker",
|
|
8899
|
+
"git-ahead": "Ahead count",
|
|
8900
|
+
"git-behind": "Behind count",
|
|
8901
|
+
"git-upstream": "Upstream name",
|
|
8902
|
+
"git-staged": "Staged count",
|
|
8903
|
+
"git-unstaged": "Unstaged count",
|
|
8904
|
+
"git-untracked": "Untracked count",
|
|
8905
|
+
"git-conflicted": "Conflicted count",
|
|
8906
|
+
"git-clean": "Clean marker",
|
|
8907
|
+
"git-stash": "Stash count",
|
|
8908
|
+
"git-submodules": "Submodule state",
|
|
8909
|
+
"git-worktrees": "Worktree count",
|
|
8910
|
+
"git-tag": "HEAD tag",
|
|
8911
|
+
"git-last-commit-age": "Last commit age",
|
|
8912
|
+
"git-signing-mismatch": "Signing mismatch",
|
|
8913
|
+
"webui-fetch-state": "Fetch state",
|
|
8914
|
+
"webui-refresh-button": "Refresh button",
|
|
8915
|
+
"webui-details-button": "Details button",
|
|
8916
|
+
"webui-cwd-picker": "CWD picker",
|
|
8917
|
+
"webui-pi-calibration": "PI calibration action",
|
|
8918
|
+
"webui-context-auto-compaction": "Auto-compaction action",
|
|
8919
|
+
"webui-branch-picker": "Branch/worktree picker",
|
|
8920
|
+
"webui-git-init": "Git init affordance",
|
|
8921
|
+
"webui-sync-push": "Sync push action",
|
|
8922
|
+
"webui-changes-modal": "Changes modal",
|
|
8923
|
+
"webui-git-tools-modal": "Git tools modal",
|
|
8924
|
+
"webui-model-picker": "Model picker",
|
|
8925
|
+
"webui-thinking-picker": "Thinking picker",
|
|
8926
|
+
"webui-changed-files-popover": "Changed-files popover",
|
|
8927
|
+
"cwd-branch": "CWD branch suffix",
|
|
8928
|
+
"git-status": "Native git status line",
|
|
8929
|
+
"extension-statuses": "Extension status line",
|
|
8930
|
+
});
|
|
8931
|
+
const GIT_FOOTER_VISIBILITY_HINTS = Object.freeze({
|
|
8932
|
+
"context-meta": "Secondary context chip shown in the footer details row.",
|
|
8933
|
+
"git-branch-indicator": "Optional branch glyph/name inside the generated git state section; off by default in WebUI.",
|
|
8934
|
+
"git-detached": "Detached-HEAD warning inside the git state chip.",
|
|
8935
|
+
"git-operation": "Merge/rebase/cherry-pick/revert/bisect operation text inside the git state chip.",
|
|
8936
|
+
"git-ahead": "Outgoing commit count inside the sync chip.",
|
|
8937
|
+
"git-behind": "Incoming commit count inside the sync/changes chips.",
|
|
8938
|
+
"git-upstream": "Tracked upstream branch name inside the sync chip.",
|
|
8939
|
+
"git-staged": "Staged-file count inside the changes chip.",
|
|
8940
|
+
"git-unstaged": "Modified-but-unstaged count inside the changes chip.",
|
|
8941
|
+
"git-untracked": "Untracked-file count inside the changes chip.",
|
|
8942
|
+
"git-conflicted": "Conflict count inside the changes chip.",
|
|
8943
|
+
"git-clean": "Clean working-tree checkmark inside the changes chip.",
|
|
8944
|
+
"git-stash": "Stash count inside the git+ chip.",
|
|
8945
|
+
"git-submodules": "Dirty submodule count inside the git+ chip.",
|
|
8946
|
+
"git-worktrees": "Repository worktree count inside the git+ chip.",
|
|
8947
|
+
"git-tag": "Tag at HEAD inside the git+ chip.",
|
|
8948
|
+
"git-last-commit-age": "Last-commit age inside the git+ chip.",
|
|
8949
|
+
"git-signing-mismatch": "Signing-key mismatch marker inside the git+ chip.",
|
|
8950
|
+
"webui-fetch-state": "Fetch progress/success/error marker in the changes chip.",
|
|
8951
|
+
"webui-refresh-button": "Floating footer refresh button.",
|
|
8952
|
+
"webui-details-button": "Mobile/details-row expander button.",
|
|
8953
|
+
"webui-cwd-picker": "Click action on the working-directory chip.",
|
|
8954
|
+
"webui-pi-calibration": "Click action on the PI card for calibration/probe commands.",
|
|
8955
|
+
"webui-context-auto-compaction": "Click action on context chips for auto-compaction.",
|
|
8956
|
+
"webui-branch-picker": "Click action on the git branch/worktree chips.",
|
|
8957
|
+
"webui-git-init": "Git initialization affordance when a tab has no repository.",
|
|
8958
|
+
"webui-sync-push": "Click-to-push action on outgoing sync chips.",
|
|
8959
|
+
"webui-changes-modal": "Click action opening the changes/conflicts modal.",
|
|
8960
|
+
"webui-git-tools-modal": "Click action opening extra git tools.",
|
|
8961
|
+
"webui-model-picker": "Click action opening the footer model picker.",
|
|
8962
|
+
"webui-thinking-picker": "Click action opening the thinking-effort picker.",
|
|
8963
|
+
"webui-changed-files-popover": "Hover/focus popover listing changed files from the changes chip.",
|
|
8964
|
+
"cwd-branch": "Native footer branch suffix for the cwd text; included here for command parity.",
|
|
8965
|
+
"git-status": "Native footer git status status-entry gate; included here for command parity.",
|
|
8966
|
+
"extension-statuses": "Native footer extension-status gate; included here for command parity.",
|
|
8967
|
+
});
|
|
8968
|
+
|
|
8969
|
+
function gitFooterVisibilityLabel(key) {
|
|
8970
|
+
return GIT_FOOTER_VISIBILITY_LABELS[key] || String(key).split("-").map((part) => part ? `${part[0].toUpperCase()}${part.slice(1)}` : part).join(" ");
|
|
8971
|
+
}
|
|
8972
|
+
|
|
8973
|
+
function gitFooterVisibilityHint(key) {
|
|
8974
|
+
return GIT_FOOTER_VISIBILITY_HINTS[key] || GIT_FOOTER_TOOLTIP_COPY[key] || `Controls the ${key} footer visibility key for the Web UI.`;
|
|
8975
|
+
}
|
|
8976
|
+
|
|
8977
|
+
function gitFooterVisibilityCommandName() {
|
|
8978
|
+
return resolveAvailableCommandName("git-footer-visibility", { rpcOnly: true });
|
|
8979
|
+
}
|
|
8980
|
+
|
|
8981
|
+
function gitFooterVisibilityCommandAvailable() {
|
|
8982
|
+
return !!gitFooterVisibilityCommandName();
|
|
8983
|
+
}
|
|
8984
|
+
|
|
8985
|
+
function currentGitFooterVisibilityState() {
|
|
8986
|
+
return normalizeGitFooterWebuiVisibility(parseGitFooterWebuiPayload()?.visibility);
|
|
8987
|
+
}
|
|
8988
|
+
|
|
8989
|
+
function setGitFooterVisibilityStatus(message = "", level = "muted") {
|
|
8990
|
+
if (!elements.gitFooterVisibilityStatus) return;
|
|
8991
|
+
elements.gitFooterVisibilityStatus.textContent = message;
|
|
8992
|
+
elements.gitFooterVisibilityStatus.className = `git-footer-visibility-status ${level || "muted"}`;
|
|
8993
|
+
elements.gitFooterVisibilityStatus.hidden = !message;
|
|
8994
|
+
}
|
|
8995
|
+
|
|
8996
|
+
function setGitFooterVisibilityBusy(busy) {
|
|
8997
|
+
gitFooterVisibilityApplyInFlight = !!busy;
|
|
8998
|
+
const commandAvailable = gitFooterVisibilityCommandAvailable();
|
|
8999
|
+
for (const button of [elements.gitFooterVisibilityApplyButton, elements.gitFooterVisibilityResetButton]) {
|
|
9000
|
+
if (button) button.disabled = gitFooterVisibilityApplyInFlight || !commandAvailable;
|
|
9001
|
+
}
|
|
9002
|
+
const inputs = elements.gitFooterVisibilityBody?.querySelectorAll("input[data-git-footer-visibility-key]") || [];
|
|
9003
|
+
for (const input of inputs) input.disabled = gitFooterVisibilityApplyInFlight || !commandAvailable;
|
|
9004
|
+
for (const button of [elements.gitFooterVisibilitySelectAllButton, elements.gitFooterVisibilitySelectNoneButton]) {
|
|
9005
|
+
if (button) button.disabled = gitFooterVisibilityApplyInFlight || !commandAvailable;
|
|
9006
|
+
}
|
|
9007
|
+
if (elements.gitFooterVisibilityCloseButton) elements.gitFooterVisibilityCloseButton.disabled = gitFooterVisibilityApplyInFlight;
|
|
9008
|
+
}
|
|
9009
|
+
|
|
9010
|
+
function renderGitFooterVisibilityToggle(key, visibility) {
|
|
9011
|
+
const label = make("label", "toggle-control git-footer-visibility-toggle");
|
|
9012
|
+
const input = make("input");
|
|
9013
|
+
input.type = "checkbox";
|
|
9014
|
+
input.checked = visibility[key] ?? true;
|
|
9015
|
+
input.dataset.gitFooterVisibilityKey = key;
|
|
9016
|
+
input.addEventListener("change", () => {
|
|
9017
|
+
gitFooterVisibilityDirty = true;
|
|
9018
|
+
setGitFooterVisibilityStatus("Unsaved WebUI footer visibility changes.", "warn");
|
|
9019
|
+
});
|
|
9020
|
+
const text = make("span", "git-footer-visibility-toggle-text");
|
|
9021
|
+
text.append(
|
|
9022
|
+
make("span", "toggle-control-label", gitFooterVisibilityLabel(key)),
|
|
9023
|
+
make("span", "toggle-control-hint", gitFooterVisibilityHint(key)),
|
|
9024
|
+
make("code", "git-footer-visibility-key", key),
|
|
9025
|
+
);
|
|
9026
|
+
label.append(input, text);
|
|
9027
|
+
return label;
|
|
9028
|
+
}
|
|
9029
|
+
|
|
9030
|
+
function renderGitFooterVisibilityDialog() {
|
|
9031
|
+
if (!elements.gitFooterVisibilityBody) return;
|
|
9032
|
+
const visibility = currentGitFooterVisibilityState();
|
|
9033
|
+
elements.gitFooterVisibilityBody.replaceChildren();
|
|
9034
|
+
for (const group of GIT_FOOTER_VISIBILITY_GROUPS) {
|
|
9035
|
+
const section = make("section", "git-footer-visibility-group");
|
|
9036
|
+
const header = make("div", "git-footer-visibility-group-header");
|
|
9037
|
+
header.append(make("h3", "", group.label), make("p", "muted", group.description));
|
|
9038
|
+
const grid = make("div", "git-footer-visibility-grid");
|
|
9039
|
+
for (const key of group.keys) grid.append(renderGitFooterVisibilityToggle(key, visibility));
|
|
9040
|
+
section.append(header, grid);
|
|
9041
|
+
elements.gitFooterVisibilityBody.append(section);
|
|
9042
|
+
}
|
|
9043
|
+
setGitFooterVisibilityBusy(gitFooterVisibilityApplyInFlight);
|
|
9044
|
+
if (!gitFooterVisibilityDirty) {
|
|
9045
|
+
setGitFooterVisibilityStatus(
|
|
9046
|
+
gitFooterVisibilityCommandAvailable()
|
|
9047
|
+
? "Runtime changes last until Pi/package restart. Use PI_GIT_FOOTER_WEBUI_HIDE or per-key env vars for persistence."
|
|
9048
|
+
: commandUnavailableMessage("git-footer-visibility"),
|
|
9049
|
+
gitFooterVisibilityCommandAvailable() ? "muted" : "warn",
|
|
9050
|
+
);
|
|
9051
|
+
}
|
|
9052
|
+
}
|
|
9053
|
+
|
|
9054
|
+
function readGitFooterVisibilitySelection() {
|
|
9055
|
+
const next = currentGitFooterVisibilityState();
|
|
9056
|
+
const inputs = elements.gitFooterVisibilityBody?.querySelectorAll("input[data-git-footer-visibility-key]") || [];
|
|
9057
|
+
for (const input of inputs) {
|
|
9058
|
+
const key = input.dataset.gitFooterVisibilityKey;
|
|
9059
|
+
if (key && key in next) next[key] = input.checked;
|
|
9060
|
+
}
|
|
9061
|
+
return next;
|
|
9062
|
+
}
|
|
9063
|
+
|
|
9064
|
+
async function runGitFooterVisibilityCommand(action, keys = []) {
|
|
9065
|
+
const commandName = gitFooterVisibilityCommandName();
|
|
9066
|
+
if (!commandName) throw new Error(commandUnavailableMessage("git-footer-visibility"));
|
|
9067
|
+
const suffix = keys.length > 0 ? ` ${keys.join(" ")}` : "";
|
|
9068
|
+
await sendPrompt("prompt", `/${commandName} ${action} webui${suffix}`, { targetTabId: activeTabId, throwOnError: true });
|
|
9069
|
+
}
|
|
9070
|
+
|
|
9071
|
+
async function applyGitFooterVisibilityDialog() {
|
|
9072
|
+
if (gitFooterVisibilityApplyInFlight) return;
|
|
9073
|
+
const current = currentGitFooterVisibilityState();
|
|
9074
|
+
const next = readGitFooterVisibilitySelection();
|
|
9075
|
+
const show = [];
|
|
9076
|
+
const hide = [];
|
|
9077
|
+
for (const key of GIT_FOOTER_VISIBILITY_DIALOG_KEYS) {
|
|
9078
|
+
if (next[key] === current[key]) continue;
|
|
9079
|
+
if (next[key]) show.push(key);
|
|
9080
|
+
else hide.push(key);
|
|
9081
|
+
}
|
|
9082
|
+
if (show.length === 0 && hide.length === 0) {
|
|
9083
|
+
gitFooterVisibilityDirty = false;
|
|
9084
|
+
setGitFooterVisibilityStatus("No footer visibility changes to apply.", "muted");
|
|
9085
|
+
return;
|
|
9086
|
+
}
|
|
9087
|
+
|
|
9088
|
+
setGitFooterVisibilityBusy(true);
|
|
9089
|
+
setGitFooterVisibilityStatus("Applying WebUI footer visibility…", "muted");
|
|
9090
|
+
try {
|
|
9091
|
+
if (hide.length) await runGitFooterVisibilityCommand("hide", hide);
|
|
9092
|
+
if (show.length) await runGitFooterVisibilityCommand("show", show);
|
|
9093
|
+
gitFooterVisibilityDirty = false;
|
|
9094
|
+
setGitFooterVisibilityStatus(`Applied ${hide.length + show.length} WebUI footer visibility change${hide.length + show.length === 1 ? "" : "s"}.`, "success");
|
|
9095
|
+
requestGitFooterWebuiPayload(activeTabContext(), { force: true, allowDuringRun: true });
|
|
9096
|
+
renderFooter();
|
|
9097
|
+
} catch (error) {
|
|
9098
|
+
setGitFooterVisibilityStatus(error.message || String(error), "error");
|
|
9099
|
+
} finally {
|
|
9100
|
+
setGitFooterVisibilityBusy(false);
|
|
9101
|
+
}
|
|
9102
|
+
}
|
|
9103
|
+
|
|
9104
|
+
async function resetGitFooterVisibilityDialog() {
|
|
9105
|
+
if (gitFooterVisibilityApplyInFlight) return;
|
|
9106
|
+
setGitFooterVisibilityBusy(true);
|
|
9107
|
+
setGitFooterVisibilityStatus("Resetting WebUI footer visibility…", "muted");
|
|
9108
|
+
try {
|
|
9109
|
+
await runGitFooterVisibilityCommand("reset");
|
|
9110
|
+
gitFooterVisibilityDirty = false;
|
|
9111
|
+
setGitFooterVisibilityStatus("Reset WebUI footer visibility overrides.", "success");
|
|
9112
|
+
requestGitFooterWebuiPayload(activeTabContext(), { force: true, allowDuringRun: true });
|
|
9113
|
+
} catch (error) {
|
|
9114
|
+
setGitFooterVisibilityStatus(error.message || String(error), "error");
|
|
9115
|
+
} finally {
|
|
9116
|
+
setGitFooterVisibilityBusy(false);
|
|
9117
|
+
}
|
|
9118
|
+
}
|
|
9119
|
+
|
|
9120
|
+
function setGitFooterVisibilitySelection(checked) {
|
|
9121
|
+
const inputs = elements.gitFooterVisibilityBody?.querySelectorAll("input[data-git-footer-visibility-key]") || [];
|
|
9122
|
+
for (const input of inputs) input.checked = !!checked;
|
|
9123
|
+
gitFooterVisibilityDirty = true;
|
|
9124
|
+
setGitFooterVisibilityStatus(checked ? "Selected all WebUI footer options." : "Deselected all WebUI footer options.", "warn");
|
|
9125
|
+
}
|
|
9126
|
+
|
|
9127
|
+
function openGitFooterVisibilityDialog() {
|
|
9128
|
+
if (!elements.gitFooterVisibilityDialog) return;
|
|
9129
|
+
setOptionsMenuOpen(false);
|
|
9130
|
+
hideFooterTooltip();
|
|
9131
|
+
gitFooterVisibilityDirty = false;
|
|
9132
|
+
renderGitFooterVisibilityDialog();
|
|
9133
|
+
if (!elements.gitFooterVisibilityDialog.open) elements.gitFooterVisibilityDialog.showModal();
|
|
9134
|
+
queueMicrotask(() => elements.gitFooterVisibilityBody?.querySelector("input")?.focus());
|
|
9135
|
+
}
|
|
9136
|
+
|
|
9137
|
+
function closeGitFooterVisibilityDialog() {
|
|
9138
|
+
gitFooterVisibilityDirty = false;
|
|
9139
|
+
gitFooterVisibilityApplyInFlight = false;
|
|
9140
|
+
if (elements.gitFooterVisibilityDialog?.open) elements.gitFooterVisibilityDialog.close();
|
|
9141
|
+
}
|
|
9142
|
+
|
|
7488
9143
|
function cleanFooterPayloadText(value, fallback = "", maxLength = 240) {
|
|
7489
9144
|
const text = cleanStatusText(value).slice(0, maxLength);
|
|
7490
9145
|
return text || fallback;
|
|
@@ -7505,6 +9160,30 @@ function normalizeFooterPayloadChangedFile(value) {
|
|
|
7505
9160
|
return file;
|
|
7506
9161
|
}
|
|
7507
9162
|
|
|
9163
|
+
function normalizeGitFooterWebuiVisibility(value) {
|
|
9164
|
+
const visibility = { ...GIT_FOOTER_WEBUI_VISIBILITY_DEFAULTS };
|
|
9165
|
+
if (!value || typeof value !== "object") return visibility;
|
|
9166
|
+
for (const key of Object.keys(visibility)) {
|
|
9167
|
+
if (typeof value[key] === "boolean") visibility[key] = value[key];
|
|
9168
|
+
}
|
|
9169
|
+
return visibility;
|
|
9170
|
+
}
|
|
9171
|
+
|
|
9172
|
+
function gitFooterPayloadVisible(payload, key) {
|
|
9173
|
+
if (!key) return true;
|
|
9174
|
+
if (typeof payload?.visibility?.[key] === "boolean") return payload.visibility[key];
|
|
9175
|
+
return GIT_FOOTER_WEBUI_VISIBILITY_DEFAULTS[key] ?? true;
|
|
9176
|
+
}
|
|
9177
|
+
|
|
9178
|
+
function currentGitFooterPayloadVisible(key) {
|
|
9179
|
+
return gitFooterPayloadVisible(parseGitFooterWebuiPayload(), key);
|
|
9180
|
+
}
|
|
9181
|
+
|
|
9182
|
+
function gitFooterPayloadVisibilityKey(payload) {
|
|
9183
|
+
const visibility = normalizeGitFooterWebuiVisibility(payload?.visibility);
|
|
9184
|
+
return Object.keys(visibility).sort().map((key) => `${key}:${visibility[key] ? 1 : 0}`).join("|");
|
|
9185
|
+
}
|
|
9186
|
+
|
|
7508
9187
|
function normalizeFooterPayloadChip(value, index) {
|
|
7509
9188
|
if (!value || typeof value !== "object") return null;
|
|
7510
9189
|
const key = cleanFooterPayloadText(value.key, `item-${index}`).replace(/[^a-z0-9_.:-]/gi, "-").slice(0, 64) || `item-${index}`;
|
|
@@ -7520,7 +9199,14 @@ function normalizeFooterPayloadChip(value, index) {
|
|
|
7520
9199
|
if (FOOTER_PAYLOAD_ACTIONS.has(value.action)) chip.action = value.action;
|
|
7521
9200
|
if (Array.isArray(value.files)) {
|
|
7522
9201
|
const files = value.files.map(normalizeFooterPayloadChangedFile).filter(Boolean).slice(0, 80);
|
|
7523
|
-
if (files.length)
|
|
9202
|
+
if (files.length) {
|
|
9203
|
+
chip.files = files;
|
|
9204
|
+
const filesTotal = Number(value.filesTotal);
|
|
9205
|
+
if (value.filesTruncated === true && Number.isFinite(filesTotal) && filesTotal > files.length) {
|
|
9206
|
+
chip.filesTotal = filesTotal;
|
|
9207
|
+
chip.filesTruncated = true;
|
|
9208
|
+
}
|
|
9209
|
+
}
|
|
7524
9210
|
}
|
|
7525
9211
|
if (value.contextUsage && typeof value.contextUsage === "object") {
|
|
7526
9212
|
const percent = typeof value.contextUsage.percent === "number" ? value.contextUsage.percent : Number.NaN;
|
|
@@ -7545,8 +9231,9 @@ function parseGitFooterWebuiPayloadRaw(raw) {
|
|
|
7545
9231
|
if (!parsed || parsed.type !== GIT_FOOTER_WEBUI_PAYLOAD_TYPE || parsed.version !== GIT_FOOTER_WEBUI_PAYLOAD_VERSION) return null;
|
|
7546
9232
|
const main = Array.isArray(parsed.main) ? parsed.main.map(normalizeFooterPayloadChip).filter(Boolean).slice(0, 8) : [];
|
|
7547
9233
|
const meta = Array.isArray(parsed.meta) ? parsed.meta.map(normalizeFooterPayloadChip).filter(Boolean).slice(0, 10) : [];
|
|
7548
|
-
|
|
7549
|
-
|
|
9234
|
+
const visibility = normalizeGitFooterWebuiVisibility(parsed.visibility);
|
|
9235
|
+
if (!main.length && !meta.length && !parsed.visibility) return null;
|
|
9236
|
+
return { main, meta, visibility };
|
|
7550
9237
|
} catch {
|
|
7551
9238
|
return null;
|
|
7552
9239
|
}
|
|
@@ -7649,14 +9336,23 @@ function parseGitFooterWebuiPayload() {
|
|
|
7649
9336
|
return parseGitFooterWebuiPayloadRaw(readCachedGitFooterWebuiPayloadRaw());
|
|
7650
9337
|
}
|
|
7651
9338
|
|
|
9339
|
+
function footerPayloadChipVisible(payload, chip, area = "main") {
|
|
9340
|
+
if (!chip?.key) return true;
|
|
9341
|
+
if (area === "meta" && chip.key === "context") return gitFooterPayloadVisible(payload, "context-meta");
|
|
9342
|
+
return gitFooterPayloadVisible(payload, chip.key);
|
|
9343
|
+
}
|
|
9344
|
+
|
|
7652
9345
|
function footerPayloadWithLiveModel(payload) {
|
|
7653
9346
|
if (!payload) return payload;
|
|
9347
|
+
const visible = (key) => gitFooterPayloadVisible(payload, key);
|
|
9348
|
+
const mainSource = payload.main.filter((chip) => footerPayloadChipVisible(payload, chip, "main"));
|
|
9349
|
+
const metaSource = payload.meta.filter((chip) => footerPayloadChipVisible(payload, chip, "meta"));
|
|
7654
9350
|
const model = currentState?.model ? shortModelLabel(currentState.model) : "";
|
|
7655
9351
|
const effort = footerThinkingDisplay();
|
|
7656
9352
|
const workspace = normalizeGitWorkspaceInfo(activeTab()?.gitWorkspace);
|
|
7657
9353
|
const worktreeLabel = gitWorkspaceBadgeLabel(workspace);
|
|
7658
|
-
const hasThinkingChip = [...
|
|
7659
|
-
const hasWorktreeChip = [...
|
|
9354
|
+
const hasThinkingChip = [...mainSource, ...metaSource].some((chip) => chip?.key === "thinking");
|
|
9355
|
+
const hasWorktreeChip = [...mainSource, ...metaSource].some((chip) => chip?.key === "worktree");
|
|
7660
9356
|
const contextChip = (chip) => {
|
|
7661
9357
|
const usageUnknown = contextUsageUnknownAfterCompaction();
|
|
7662
9358
|
const value = usageUnknown ? footerContextDisplayWithAuto(unknownFooterContextText(chip?.contextUsage)) : footerContextDisplayWithAuto(chip?.value);
|
|
@@ -7667,16 +9363,17 @@ function footerPayloadWithLiveModel(payload) {
|
|
|
7667
9363
|
const worktreeChip = () => ({ key: "worktree", label: "worktree", value: worktreeLabel, icon: "🌳", tone: workspace?.isMainWorktree ? "teal" : "green", title: workspace?.worktreePath || "Git worktree" });
|
|
7668
9364
|
const splitChip = (chip) => {
|
|
7669
9365
|
if (chip?.key === "context") return [contextChip(chip)];
|
|
7670
|
-
if (chip?.key === "thinking") return [effortChip(chip)];
|
|
9366
|
+
if (chip?.key === "thinking") return visible("thinking") ? [effortChip(chip)] : [];
|
|
7671
9367
|
if (chip?.key !== "model" || !model) return [chip];
|
|
7672
9368
|
const modelChip = { ...chip, value: model, title: `model: ${model}` };
|
|
7673
|
-
return hasThinkingChip ? [modelChip] : [modelChip, effortChip(chip)];
|
|
9369
|
+
return hasThinkingChip || !visible("thinking") ? [modelChip] : [modelChip, effortChip(chip)];
|
|
7674
9370
|
};
|
|
7675
|
-
const meta =
|
|
7676
|
-
if (worktreeLabel && !hasWorktreeChip) meta.splice(Math.min(meta.length, 2), 0, worktreeChip());
|
|
9371
|
+
const meta = metaSource.flatMap(splitChip);
|
|
9372
|
+
if (visible("worktree") && worktreeLabel && !hasWorktreeChip) meta.splice(Math.min(meta.length, 2), 0, worktreeChip());
|
|
7677
9373
|
return {
|
|
7678
|
-
main:
|
|
9374
|
+
main: mainSource.flatMap(splitChip),
|
|
7679
9375
|
meta,
|
|
9376
|
+
visibility: payload.visibility,
|
|
7680
9377
|
};
|
|
7681
9378
|
}
|
|
7682
9379
|
|
|
@@ -7793,26 +9490,29 @@ function renderChangedFilesGroup(kind, files) {
|
|
|
7793
9490
|
return group;
|
|
7794
9491
|
}
|
|
7795
9492
|
|
|
7796
|
-
function applyFooterChangedFilesDropdown(node, chip) {
|
|
7797
|
-
if (chip?.key !== "changes" || !Array.isArray(chip.files) || chip.files.length === 0) return node;
|
|
9493
|
+
function applyFooterChangedFilesDropdown(node, chip, payload) {
|
|
9494
|
+
if (!gitFooterPayloadVisible(payload, "webui-changed-files-popover") || chip?.key !== "changes" || !Array.isArray(chip.files) || chip.files.length === 0) return node;
|
|
7798
9495
|
node.classList.add("footer-changes-with-files");
|
|
7799
9496
|
node.tabIndex = 0;
|
|
7800
9497
|
node.removeAttribute("data-tooltip");
|
|
7801
9498
|
node.setAttribute("aria-label", `changes: ${chip.value}. Hover or focus to choose changed files. Click a file to add it as an @ reference.`);
|
|
7802
9499
|
|
|
7803
9500
|
const popover = make("span", "footer-changed-files-popover");
|
|
7804
|
-
popover.append(make("span", "footer-changed-files-title", "Changed files"));
|
|
9501
|
+
popover.append(make("span", "footer-changed-files-title", chip.filesTruncated ? `Changed files (showing ${chip.files.length} of ${chip.filesTotal})` : "Changed files"));
|
|
7805
9502
|
for (const kind of FOOTER_CHANGED_FILE_KIND_ORDER) {
|
|
7806
9503
|
const group = renderChangedFilesGroup(kind, chip.files.filter((file) => file.kind === kind));
|
|
7807
9504
|
if (group) popover.append(group);
|
|
7808
9505
|
}
|
|
9506
|
+
if (chip.filesTruncated) popover.append(make("span", "footer-changed-files-truncated", `${chip.filesTotal - chip.files.length} more files not shown; open the Git Changes dialog for the full list.`));
|
|
7809
9507
|
node.append(popover);
|
|
7810
9508
|
return node;
|
|
7811
9509
|
}
|
|
7812
9510
|
|
|
7813
|
-
function renderGitFooterPayloadMetric(chip) {
|
|
9511
|
+
function renderGitFooterPayloadMetric(chip, payload) {
|
|
7814
9512
|
const options = { tooltipAlign: gitFooterTooltipAlign(chip) };
|
|
7815
|
-
const
|
|
9513
|
+
const piAction = gitFooterPayloadVisible(payload, "webui-pi-calibration") ? applyGitFooterPiCalibrationOptions(chip, options) : "";
|
|
9514
|
+
const contextAction = gitFooterPayloadVisible(payload, "webui-context-auto-compaction") ? applyGitFooterContextToggleOptions(chip, options) : "";
|
|
9515
|
+
const action = piAction || contextAction;
|
|
7816
9516
|
options.title = gitFooterPayloadTooltip(chip, { action });
|
|
7817
9517
|
const node = footerMetric(chip.icon || "•", chip.label, chip.value, chip.tone ? `tone-${chip.tone}` : "", options);
|
|
7818
9518
|
return chip.contextUsage ? applyFooterContextUsage(node, chip.contextUsage) : node;
|
|
@@ -7827,6 +9527,12 @@ function gitFooterSyncChipHasOutgoing(chip) {
|
|
|
7827
9527
|
return chip?.key === "sync" && gitFooterSyncOutgoingCount(chip.value) > 0;
|
|
7828
9528
|
}
|
|
7829
9529
|
|
|
9530
|
+
function gitFooterCurrentBranch() {
|
|
9531
|
+
const gitChip = parseGitFooterWebuiPayload()?.meta?.find((chip) => chip.key === "git");
|
|
9532
|
+
const value = cleanFooterPayloadText(gitChip?.value, "").toLowerCase();
|
|
9533
|
+
return value && value !== "no repo" ? cleanFooterPayloadText(gitChip.value, "") : "";
|
|
9534
|
+
}
|
|
9535
|
+
|
|
7830
9536
|
async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
7831
9537
|
if (!tabId || gitFooterSyncPushInFlightByTab.has(tabId)) return;
|
|
7832
9538
|
const outgoing = gitFooterSyncOutgoingCount(syncValue);
|
|
@@ -7835,14 +9541,47 @@ async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
|
7835
9541
|
const tab = tabs.find((item) => item.id === tabId);
|
|
7836
9542
|
const target = tab?.title || tab?.cwd || "this tab";
|
|
7837
9543
|
hideFooterTooltip();
|
|
7838
|
-
|
|
9544
|
+
const branch = gitFooterCurrentBranch();
|
|
9545
|
+
const protectedWarning = ["main", "master"].includes(branch)
|
|
9546
|
+
? `\n\nWarning: ${branch} is usually a protected/shared branch. Consider pushing a feature branch and opening a PR instead.`
|
|
9547
|
+
: "";
|
|
9548
|
+
if (!window.confirm(`Run git push for ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"} in ${target}?${protectedWarning}`)) return;
|
|
7839
9549
|
|
|
7840
9550
|
gitFooterSyncPushInFlightByTab.add(tabId);
|
|
7841
9551
|
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
7842
9552
|
try {
|
|
7843
9553
|
const response = await api("/api/git-workflow/push", { method: "POST", body: {}, tabId });
|
|
7844
9554
|
if (!response.ok) {
|
|
7845
|
-
|
|
9555
|
+
if (response.code === "NO_UPSTREAM") {
|
|
9556
|
+
const publish = window.confirm(`${response.error}\n\n${response.hint || ""}\n\nRun git push -u to publish ${branch || "the current branch"} and set its upstream?`);
|
|
9557
|
+
if (publish) {
|
|
9558
|
+
const upstreamResponse = await api("/api/git-workflow/push", { method: "POST", body: { setUpstream: true }, tabId });
|
|
9559
|
+
if (!upstreamResponse.ok) throw new Error([upstreamResponse.error, upstreamResponse.hint].filter(Boolean).join("\n"));
|
|
9560
|
+
addEvent(`Published ${upstreamResponse.data?.branch || "branch"} to ${upstreamResponse.data?.remote || "the remote"} and set its upstream.`, "success");
|
|
9561
|
+
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
9562
|
+
return;
|
|
9563
|
+
}
|
|
9564
|
+
throw new Error([response.error, response.hint].filter(Boolean).join("\n"));
|
|
9565
|
+
}
|
|
9566
|
+
if (response.code === "NON_FAST_FORWARD") {
|
|
9567
|
+
const forcePush = window.confirm([
|
|
9568
|
+
response.error,
|
|
9569
|
+
"",
|
|
9570
|
+
response.hint || "",
|
|
9571
|
+
"",
|
|
9572
|
+
"Recommended: open the Git Changes dialog, fetch, and review the incoming diff first.",
|
|
9573
|
+
`DANGER: force-push ${branch || "the current branch"} with --force-with-lease instead? This rewrites the remote branch (but still refuses if the remote moved past what you fetched).`,
|
|
9574
|
+
].join("\n"));
|
|
9575
|
+
if (forcePush) {
|
|
9576
|
+
const forceResponse = await api("/api/git-workflow/push", { method: "POST", body: { forceWithLease: true, confirmed: true }, tabId });
|
|
9577
|
+
if (!forceResponse.ok) throw new Error([forceResponse.error, forceResponse.hint].filter(Boolean).join("\n"));
|
|
9578
|
+
addEvent("Force-pushed with --force-with-lease.", "success");
|
|
9579
|
+
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
9580
|
+
return;
|
|
9581
|
+
}
|
|
9582
|
+
throw new Error([response.error, response.hint].filter(Boolean).join("\n"));
|
|
9583
|
+
}
|
|
9584
|
+
const detail = [response.error, response.hint, formatGitCommandResult(response.data)].filter(Boolean).join("\n\n").trim();
|
|
7846
9585
|
throw new Error(detail || "git push failed");
|
|
7847
9586
|
}
|
|
7848
9587
|
addEvent(`Pushed ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"}.`, "success");
|
|
@@ -7855,43 +9594,51 @@ async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
|
7855
9594
|
}
|
|
7856
9595
|
}
|
|
7857
9596
|
|
|
7858
|
-
function renderGitFooterPayloadMeta(chip, tab) {
|
|
9597
|
+
function renderGitFooterPayloadMeta(chip, tab, payload) {
|
|
7859
9598
|
const options = {};
|
|
9599
|
+
const visible = (key) => gitFooterPayloadVisible(payload, key);
|
|
7860
9600
|
let action = "";
|
|
7861
|
-
if (chip.key === "cwd" && tab) {
|
|
9601
|
+
if (chip.key === "cwd" && tab && visible("webui-cwd-picker")) {
|
|
7862
9602
|
options.onClick = changeActiveTabCwd;
|
|
7863
9603
|
action = `Click to change the working directory for ${tab.title}.`;
|
|
7864
|
-
} else if (chip.key === "git" && cleanFooterPayloadText(chip.value, "").toLowerCase() === "no repo") {
|
|
9604
|
+
} else if (chip.key === "git" && cleanFooterPayloadText(chip.value, "").toLowerCase() === "no repo" && visible("webui-git-init")) {
|
|
7865
9605
|
options.onClick = () => startGitInitWorkflow();
|
|
7866
9606
|
action = "No Git repository detected. Click to initialize a repo, create README.md, add origin, and push main.";
|
|
7867
|
-
} else if (chip.key === "git") {
|
|
9607
|
+
} else if (chip.key === "git" && visible("webui-branch-picker")) {
|
|
7868
9608
|
options.onClick = () => setFooterBranchPickerOpen(!footerBranchPickerOpen);
|
|
7869
9609
|
action = "Click to open, create, or switch branches. Worktree actions are the safe default for parallel work.";
|
|
7870
|
-
} else if (chip.key === "worktree") {
|
|
9610
|
+
} else if (chip.key === "worktree" && visible("webui-branch-picker")) {
|
|
7871
9611
|
options.onClick = () => setFooterBranchPickerOpen(!footerBranchPickerOpen);
|
|
7872
9612
|
action = "Click to manage branch worktrees for this repository.";
|
|
7873
|
-
} else if (chip.key === "sync" && gitFooterSyncChipHasOutgoing(chip)) {
|
|
9613
|
+
} else if (chip.key === "sync" && visible("webui-sync-push") && gitFooterSyncChipHasOutgoing(chip)) {
|
|
7874
9614
|
const tabId = tab?.id || activeTabId;
|
|
7875
9615
|
const inFlight = tabId ? gitFooterSyncPushInFlightByTab.has(tabId) : false;
|
|
7876
9616
|
options.onClick = () => pushGitFooterSync(tabId, chip.value);
|
|
7877
9617
|
options.ariaBusy = inFlight;
|
|
7878
9618
|
options.disabled = inFlight;
|
|
7879
9619
|
action = inFlight ? "Pushing local commits to the configured remote." : "Click to push local commits to the configured remote.";
|
|
7880
|
-
} else if (chip.key === "changes") {
|
|
9620
|
+
} else if (chip.key === "changes" && visible("webui-changes-modal")) {
|
|
7881
9621
|
options.onClick = openGitChangesDialog;
|
|
7882
9622
|
action = "Click to view the current git diff.";
|
|
7883
|
-
} else if (chip.key === "
|
|
9623
|
+
} else if (chip.key === "git-state" && visible("webui-changes-modal")) {
|
|
9624
|
+
options.onClick = openGitChangesDialog;
|
|
9625
|
+
action = "Click to open the conflicts and operation panel with continue/abort actions.";
|
|
9626
|
+
} else if (chip.key === "git-extra" && visible("webui-git-tools-modal")) {
|
|
9627
|
+
const toolsSection = gitToolsSectionForExtraChip(chip.value);
|
|
9628
|
+
options.onClick = () => openGitToolsFromFooter(toolsSection);
|
|
9629
|
+
action = `Click to open git tools (${toolsSection} first): stash, worktrees, undo, submodules, tags, signing.`;
|
|
9630
|
+
} else if (chip.key === "model" && visible("webui-model-picker")) {
|
|
7884
9631
|
options.onClick = () => setFooterModelPickerOpen(!footerModelPickerOpen);
|
|
7885
9632
|
action = "Click to choose another model.";
|
|
7886
|
-
} else if (chip.key === "thinking") {
|
|
9633
|
+
} else if (chip.key === "thinking" && visible("webui-thinking-picker")) {
|
|
7887
9634
|
options.onClick = () => setFooterThinkingPickerOpen(!footerThinkingPickerOpen);
|
|
7888
9635
|
action = "Click to change thinking effort.";
|
|
7889
9636
|
}
|
|
7890
|
-
action = applyGitFooterContextToggleOptions(chip, options) || action;
|
|
9637
|
+
action = (visible("webui-context-auto-compaction") ? applyGitFooterContextToggleOptions(chip, options) : "") || action;
|
|
7891
9638
|
options.title = gitFooterPayloadTooltip(chip, { action });
|
|
7892
9639
|
options.tooltipAlign = gitFooterTooltipAlign(chip);
|
|
7893
9640
|
const node = footerMeta(chip.label, chip.value, footerMetaClassForPayload(chip), options);
|
|
7894
|
-
applyFooterChangedFilesDropdown(node, chip);
|
|
9641
|
+
applyFooterChangedFilesDropdown(node, chip, payload);
|
|
7895
9642
|
if (["git", "worktree"].includes(chip.key) && options.onClick && cleanFooterPayloadText(chip.value, "").toLowerCase() !== "no repo") {
|
|
7896
9643
|
node.setAttribute("aria-haspopup", "listbox");
|
|
7897
9644
|
node.setAttribute("aria-expanded", footerBranchPickerOpen ? "true" : "false");
|
|
@@ -7915,12 +9662,12 @@ function gitFooterChipShapeKey(chip) {
|
|
|
7915
9662
|
return JSON.stringify(shape);
|
|
7916
9663
|
}
|
|
7917
9664
|
|
|
7918
|
-
function gitFooterPickerStateKey() {
|
|
9665
|
+
function gitFooterPickerStateKey(payload) {
|
|
7919
9666
|
const tabContext = activeTabContext();
|
|
7920
9667
|
const refreshInFlight = tabContext.tabId ? gitFooterPayloadRefreshInFlightByTab.has(tabContext.tabId) : false;
|
|
7921
9668
|
const syncPushInFlight = tabContext.tabId ? gitFooterSyncPushInFlightByTab.has(tabContext.tabId) : false;
|
|
7922
9669
|
const refreshAvailable = hasLoadedRpcCommand("git-footer-refresh");
|
|
7923
|
-
return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${syncPushInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}`;
|
|
9670
|
+
return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${syncPushInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}|${gitFooterPayloadVisibilityKey(payload)}`;
|
|
7924
9671
|
}
|
|
7925
9672
|
|
|
7926
9673
|
function updateGitFooterChipNodeValue(node, chip, valueSelector) {
|
|
@@ -7972,7 +9719,11 @@ function renderGitFooterRefreshButton() {
|
|
|
7972
9719
|
|
|
7973
9720
|
function renderGitFooterPayload(payload) {
|
|
7974
9721
|
const tab = activeTab();
|
|
7975
|
-
|
|
9722
|
+
if (!gitFooterPayloadVisible(payload, "webui-details-button")) mobileFooterExpanded = false;
|
|
9723
|
+
if (!gitFooterPayloadVisible(payload, "webui-model-picker")) footerModelPickerOpen = false;
|
|
9724
|
+
if (!gitFooterPayloadVisible(payload, "webui-thinking-picker")) footerThinkingPickerOpen = false;
|
|
9725
|
+
if (!gitFooterPayloadVisible(payload, "webui-branch-picker")) footerBranchPickerOpen = false;
|
|
9726
|
+
const pickerKey = gitFooterPickerStateKey(payload);
|
|
7976
9727
|
const mainKeys = payload.main.map(gitFooterChipShapeKey);
|
|
7977
9728
|
const metaKeys = payload.meta.map(gitFooterChipShapeKey);
|
|
7978
9729
|
|
|
@@ -8003,23 +9754,28 @@ function renderGitFooterPayload(payload) {
|
|
|
8003
9754
|
elements.statusBar.classList.add("statusbar-git-footer");
|
|
8004
9755
|
document.body.classList.toggle("footer-model-picker-open", isFooterPickerOpen());
|
|
8005
9756
|
|
|
8006
|
-
const mainNodes = payload.main.map(renderGitFooterPayloadMetric);
|
|
9757
|
+
const mainNodes = payload.main.map((chip) => renderGitFooterPayloadMetric(chip, payload));
|
|
8007
9758
|
const row1 = make("div", "footer-line footer-line-main");
|
|
8008
9759
|
row1.append(...mainNodes);
|
|
8009
9760
|
|
|
8010
|
-
const
|
|
8011
|
-
footerToggle.type = "button";
|
|
8012
|
-
footerToggle.setAttribute("aria-expanded", mobileFooterExpanded ? "true" : "false");
|
|
8013
|
-
footerToggle.addEventListener("click", () => setMobileFooterExpanded(!mobileFooterExpanded));
|
|
8014
|
-
|
|
8015
|
-
const metaNodes = payload.meta.map((chip) => renderGitFooterPayloadMeta(chip, tab));
|
|
9761
|
+
const metaNodes = payload.meta.map((chip) => renderGitFooterPayloadMeta(chip, tab, payload));
|
|
8016
9762
|
const row2 = make("div", "footer-line footer-line-meta");
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
9763
|
+
const row2Children = [...metaNodes];
|
|
9764
|
+
if (gitFooterPayloadVisible(payload, "webui-details-button")) {
|
|
9765
|
+
const footerToggle = make("button", "footer-details-toggle", mobileFooterExpanded ? "Less" : "Details");
|
|
9766
|
+
footerToggle.type = "button";
|
|
9767
|
+
footerToggle.setAttribute("aria-expanded", mobileFooterExpanded ? "true" : "false");
|
|
9768
|
+
footerToggle.addEventListener("click", () => setMobileFooterExpanded(!mobileFooterExpanded));
|
|
9769
|
+
row2Children.push(footerToggle);
|
|
9770
|
+
}
|
|
9771
|
+
row2.append(...row2Children);
|
|
9772
|
+
|
|
9773
|
+
const statusChildren = [row1, row2];
|
|
9774
|
+
if (gitFooterPayloadVisible(payload, "webui-refresh-button")) statusChildren.push(renderGitFooterRefreshButton());
|
|
9775
|
+
elements.statusBar.append(...statusChildren);
|
|
9776
|
+
if (footerModelPickerOpen && gitFooterPayloadVisible(payload, "webui-model-picker")) elements.statusBar.append(renderFooterModelPicker());
|
|
9777
|
+
if (footerThinkingPickerOpen && gitFooterPayloadVisible(payload, "webui-thinking-picker")) elements.statusBar.append(renderFooterThinkingPicker());
|
|
9778
|
+
if (footerBranchPickerOpen && gitFooterPayloadVisible(payload, "webui-branch-picker")) elements.statusBar.append(renderFooterBranchPicker());
|
|
8023
9779
|
gitFooterRenderCache = { pickerKey, mainKeys, metaKeys, mainNodes, metaNodes };
|
|
8024
9780
|
setMobileFooterExpanded(mobileFooterExpanded);
|
|
8025
9781
|
updateFooterModelPickerPosition();
|
|
@@ -8213,7 +9969,81 @@ function renderGitDiffGrid(file) {
|
|
|
8213
9969
|
return grid;
|
|
8214
9970
|
}
|
|
8215
9971
|
|
|
8216
|
-
function
|
|
9972
|
+
function gitFileActionButtons(actions) {
|
|
9973
|
+
if (!actions?.length) return null;
|
|
9974
|
+
const wrap = make("span", "git-file-actions");
|
|
9975
|
+
for (const action of actions) {
|
|
9976
|
+
const button = make("button", `git-file-action ${action.className || ""}`.trim(), action.label);
|
|
9977
|
+
button.type = "button";
|
|
9978
|
+
button.title = action.title || action.label;
|
|
9979
|
+
button.addEventListener("click", (event) => {
|
|
9980
|
+
event.preventDefault();
|
|
9981
|
+
event.stopPropagation();
|
|
9982
|
+
action.onClick();
|
|
9983
|
+
});
|
|
9984
|
+
wrap.append(button);
|
|
9985
|
+
}
|
|
9986
|
+
return wrap;
|
|
9987
|
+
}
|
|
9988
|
+
|
|
9989
|
+
function copyGitTextToClipboard(text, label = "text") {
|
|
9990
|
+
navigator.clipboard?.writeText(text)
|
|
9991
|
+
.then(() => addEvent(`Copied ${label}: ${text}`, "info"))
|
|
9992
|
+
.catch(() => addEvent(`Clipboard unavailable; copy the ${label} manually.`, "error"));
|
|
9993
|
+
}
|
|
9994
|
+
|
|
9995
|
+
function copyGitPathToClipboard(path) {
|
|
9996
|
+
copyGitTextToClipboard(path, "path");
|
|
9997
|
+
}
|
|
9998
|
+
|
|
9999
|
+
// Git paths are repo-root-relative; the file viewer resolves against the tab
|
|
10000
|
+
// cwd. Translate when the tab sits at (or above within) the repo root.
|
|
10001
|
+
async function openGitFileFromChanges(repoRelPath) {
|
|
10002
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
10003
|
+
const root = gitChangesState.data?.root || "";
|
|
10004
|
+
const tab = tabs.find((item) => item.id === tabId);
|
|
10005
|
+
let viewerPath = repoRelPath;
|
|
10006
|
+
if (root && tab?.cwd) {
|
|
10007
|
+
const absolute = `${root.replace(/\/+$/, "")}/${repoRelPath}`;
|
|
10008
|
+
const cwd = tab.cwd.replace(/\/+$/, "");
|
|
10009
|
+
if (absolute.startsWith(`${cwd}/`)) viewerPath = absolute.slice(cwd.length + 1);
|
|
10010
|
+
else if (root !== cwd) {
|
|
10011
|
+
addEvent(`Cannot open ${repoRelPath}: it is outside this tab's working directory.`, "error");
|
|
10012
|
+
return;
|
|
10013
|
+
}
|
|
10014
|
+
}
|
|
10015
|
+
closeGitChangesDialog();
|
|
10016
|
+
setSidePanelCollapsed(false);
|
|
10017
|
+
await openFileInViewer(viewerPath);
|
|
10018
|
+
}
|
|
10019
|
+
|
|
10020
|
+
function gitChangesCommonFileActions(path) {
|
|
10021
|
+
return [
|
|
10022
|
+
{ label: "Open", title: "Open this file in the WebUI file viewer", onClick: () => openGitFileFromChanges(path) },
|
|
10023
|
+
{ label: "Copy path", title: "Copy the repo-relative path", onClick: () => copyGitPathToClipboard(path) },
|
|
10024
|
+
];
|
|
10025
|
+
}
|
|
10026
|
+
|
|
10027
|
+
function gitChangesFileActionsFor(sectionKey, path) {
|
|
10028
|
+
if (!path || gitChangesState.loading || gitChangesState.pulling || gitChangesState.fetching) return [];
|
|
10029
|
+
if (sectionKey === "unstaged") {
|
|
10030
|
+
return [
|
|
10031
|
+
{ label: "Stage", title: `git add -- ${path}`, onClick: () => runGitFileAction("stage", path) },
|
|
10032
|
+
...gitChangesCommonFileActions(path),
|
|
10033
|
+
{ label: "Discard", className: "danger", title: `git restore -- ${path} (destructive)`, onClick: () => runGitFileAction("discard", path) },
|
|
10034
|
+
];
|
|
10035
|
+
}
|
|
10036
|
+
if (sectionKey === "staged") {
|
|
10037
|
+
return [
|
|
10038
|
+
{ label: "Unstage", title: `git restore --staged -- ${path}`, onClick: () => runGitFileAction("unstage", path) },
|
|
10039
|
+
...gitChangesCommonFileActions(path),
|
|
10040
|
+
];
|
|
10041
|
+
}
|
|
10042
|
+
if (sectionKey === "incoming") return [{ label: "Copy path", title: "Copy the repo-relative path", onClick: () => copyGitPathToClipboard(path) }];
|
|
10043
|
+
return [];
|
|
10044
|
+
}
|
|
10045
|
+
|
|
10046
|
+
function renderGitDiffFile(file, actions = []) {
|
|
8217
10047
|
const details = make("details", `git-diff-file ${file.className || ""}`.trim());
|
|
8218
10048
|
details.open = true;
|
|
8219
10049
|
details.dataset.gitDiffFile = file.path || "diff";
|
|
@@ -8222,6 +10052,8 @@ function renderGitDiffFile(file) {
|
|
|
8222
10052
|
make("span", "git-diff-file-name", file.path || "diff"),
|
|
8223
10053
|
make("span", "git-diff-file-stats", file.statsText || `+${file.additions || 0} −${file.deletions || 0}`),
|
|
8224
10054
|
);
|
|
10055
|
+
const actionButtons = gitFileActionButtons(actions);
|
|
10056
|
+
if (actionButtons) summary.append(actionButtons);
|
|
8225
10057
|
details.append(summary);
|
|
8226
10058
|
if (file.hunks?.length) {
|
|
8227
10059
|
details.append(renderGitDiffGrid(file));
|
|
@@ -8239,7 +10071,20 @@ function renderGitDiffSection(section, files) {
|
|
|
8239
10071
|
make("div", "git-diff-section-title", section?.label || "Git diff"),
|
|
8240
10072
|
make("div", "git-diff-section-meta", `${files.length} file${files.length === 1 ? "" : "s"} · ${section?.command || "git diff"}`),
|
|
8241
10073
|
);
|
|
8242
|
-
wrapper.append(header
|
|
10074
|
+
wrapper.append(header);
|
|
10075
|
+
if (section?.truncated) {
|
|
10076
|
+
const notice = make("div", "git-diff-truncated-notice");
|
|
10077
|
+
const fullCommand = String(section?.command || "git diff").replace(/\s--unified=0\b/, "");
|
|
10078
|
+
notice.append(make("span", undefined, `Diff truncated at ${formatBytes(section.capBytes || 0)} — showing the tail. Use the per-file Open buttons for full contents, or run the full command in a terminal:`));
|
|
10079
|
+
notice.append(make("code", "git-tools-command", fullCommand));
|
|
10080
|
+
const copy = make("button", "git-file-action", "Copy command");
|
|
10081
|
+
copy.type = "button";
|
|
10082
|
+
copy.title = "Copy the full diff command";
|
|
10083
|
+
copy.addEventListener("click", () => copyGitTextToClipboard(fullCommand, "command"));
|
|
10084
|
+
notice.append(copy);
|
|
10085
|
+
wrapper.append(notice);
|
|
10086
|
+
}
|
|
10087
|
+
wrapper.append(...files.map((file) => renderGitDiffFile(file, gitChangesFileActionsFor(section?.key, file.path))));
|
|
8243
10088
|
return wrapper;
|
|
8244
10089
|
}
|
|
8245
10090
|
|
|
@@ -8313,9 +10158,21 @@ function renderGitUntrackedLoadingFile(entry) {
|
|
|
8313
10158
|
}
|
|
8314
10159
|
|
|
8315
10160
|
function renderGitUntrackedFile(entry) {
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
10161
|
+
const node = entry.contentMissing
|
|
10162
|
+
? renderGitUntrackedLoadingFile(entry)
|
|
10163
|
+
: entry.error || entry.binary
|
|
10164
|
+
? renderGitUntrackedRawFile(entry)
|
|
10165
|
+
: renderGitDiffFile(gitUntrackedEntryToDiffFile(entry));
|
|
10166
|
+
if (!gitChangesState.loading && !gitChangesState.pulling && !gitChangesState.fetching) {
|
|
10167
|
+
const summary = node.querySelector("summary");
|
|
10168
|
+
const actions = gitFileActionButtons([
|
|
10169
|
+
{ label: "Stage", title: `git add -- ${entry.path}`, onClick: () => runGitFileAction("stage", entry.path) },
|
|
10170
|
+
...gitChangesCommonFileActions(entry.path),
|
|
10171
|
+
{ label: "Delete", className: "danger", title: "Delete this untracked file from disk (destructive)", onClick: () => runGitFileAction("delete-untracked", entry.path) },
|
|
10172
|
+
]);
|
|
10173
|
+
if (summary && actions) summary.append(actions);
|
|
10174
|
+
}
|
|
10175
|
+
return node;
|
|
8319
10176
|
}
|
|
8320
10177
|
|
|
8321
10178
|
function replaceGitUntrackedEntry(entry, tabId = gitChangesState.tabId) {
|
|
@@ -8566,9 +10423,12 @@ function renderGitPullResultPanel(result) {
|
|
|
8566
10423
|
|
|
8567
10424
|
function renderGitChangesDialog() {
|
|
8568
10425
|
if (!elements.gitChangesDialog || !elements.gitChangesBody) return;
|
|
8569
|
-
const { loading, pulling, error, message, pullResult, data } = gitChangesState;
|
|
10426
|
+
const { loading, pulling, fetching, error, message, pullResult, data, operation } = gitChangesState;
|
|
10427
|
+
const busyAction = pulling || fetching;
|
|
8570
10428
|
const behind = Number(data?.remote?.behind ?? data?.summary?.behind ?? 0) || 0;
|
|
8571
|
-
const
|
|
10429
|
+
const diverged = data?.remote?.diverged === true;
|
|
10430
|
+
const canPull = behind > 0 && data?.remote?.canPull !== false && !diverged;
|
|
10431
|
+
const hasOperation = Boolean(operation?.operation);
|
|
8572
10432
|
const remoteNotice = !error && data?.remote?.error ? `Incoming diff unavailable: ${data.remote.error}` : "";
|
|
8573
10433
|
if (elements.gitChangesTitle) elements.gitChangesTitle.textContent = "Git Changes";
|
|
8574
10434
|
if (elements.gitChangesSubtitle) {
|
|
@@ -8576,16 +10436,25 @@ function renderGitChangesDialog() {
|
|
|
8576
10436
|
elements.gitChangesSubtitle.textContent = data?.remote?.upstream ? `${base} · upstream ${data.remote.upstream}` : base;
|
|
8577
10437
|
}
|
|
8578
10438
|
if (elements.gitChangesRefreshButton) {
|
|
8579
|
-
elements.gitChangesRefreshButton.disabled = loading ||
|
|
10439
|
+
elements.gitChangesRefreshButton.disabled = loading || busyAction;
|
|
8580
10440
|
elements.gitChangesRefreshButton.textContent = loading ? "Refreshing…" : "Refresh";
|
|
8581
10441
|
}
|
|
10442
|
+
if (elements.gitChangesFetchButton) {
|
|
10443
|
+
elements.gitChangesFetchButton.disabled = loading || busyAction || !data?.root;
|
|
10444
|
+
elements.gitChangesFetchButton.textContent = fetching ? "Fetching…" : "Fetch";
|
|
10445
|
+
elements.gitChangesFetchButton.title = "Run git fetch --prune to refresh remote tracking state";
|
|
10446
|
+
}
|
|
8582
10447
|
if (elements.gitChangesPullButton) {
|
|
8583
|
-
elements.gitChangesPullButton.disabled = loading ||
|
|
10448
|
+
elements.gitChangesPullButton.disabled = loading || busyAction || !canPull;
|
|
8584
10449
|
elements.gitChangesPullButton.textContent = pulling ? "Pulling…" : behind > 0 ? `Pull ↓${behind}` : "Pull";
|
|
8585
|
-
elements.gitChangesPullButton.title = canPull
|
|
10450
|
+
elements.gitChangesPullButton.title = canPull
|
|
10451
|
+
? "Run git pull --ff-only for the current repository"
|
|
10452
|
+
: diverged
|
|
10453
|
+
? "Local and remote branches have diverged; use the integrate actions below instead of one-click pull."
|
|
10454
|
+
: "No remote commits to pull";
|
|
8586
10455
|
}
|
|
8587
10456
|
if (elements.gitChangesStatus) {
|
|
8588
|
-
const statusText = error || (pulling ? "Pulling changes…" : loading ? "Loading git diff…" : message || remoteNotice || (data ? gitChangesGeneratedLabel(data) : ""));
|
|
10457
|
+
const statusText = error || (pulling ? "Pulling changes…" : fetching ? "Fetching from remote…" : loading ? "Loading git diff…" : message || remoteNotice || (data ? gitChangesGeneratedLabel(data) : ""));
|
|
8589
10458
|
elements.gitChangesStatus.className = `git-changes-status ${error || remoteNotice ? "error" : message ? "success" : "muted"}`;
|
|
8590
10459
|
elements.gitChangesStatus.textContent = statusText;
|
|
8591
10460
|
elements.gitChangesStatus.hidden = !elements.gitChangesStatus.textContent;
|
|
@@ -8607,7 +10476,18 @@ function renderGitChangesDialog() {
|
|
|
8607
10476
|
}
|
|
8608
10477
|
|
|
8609
10478
|
if (pullResult) body.append(renderGitPullResultPanel(pullResult));
|
|
10479
|
+
if (hasOperation) {
|
|
10480
|
+
const panel = renderGitOperationPanel(operation);
|
|
10481
|
+
if (panel) body.append(panel);
|
|
10482
|
+
}
|
|
8610
10483
|
body.append(renderGitChangesOverview(data));
|
|
10484
|
+
const fetchStateLines = gitChangesFetchStateLines();
|
|
10485
|
+
if (fetchStateLines.length) {
|
|
10486
|
+
const fetchNote = make("div", "git-tools-note git-fetch-state-note");
|
|
10487
|
+
for (const line of fetchStateLines) fetchNote.append(make("div", undefined, line));
|
|
10488
|
+
body.append(fetchNote);
|
|
10489
|
+
}
|
|
10490
|
+
if (diverged && !hasOperation) body.append(renderGitDivergedBar(data));
|
|
8611
10491
|
const parsedSections = (Array.isArray(data.sections) ? data.sections : [])
|
|
8612
10492
|
.map((section) => ({ section, files: parseGitUnifiedDiff(section.diff || "") }))
|
|
8613
10493
|
.filter((entry) => entry.files.length > 0);
|
|
@@ -8620,23 +10500,40 @@ function renderGitChangesDialog() {
|
|
|
8620
10500
|
}
|
|
8621
10501
|
for (const entry of parsedSections) body.append(renderGitDiffSection(entry.section, entry.files));
|
|
8622
10502
|
if (untracked.length) body.append(renderGitUntrackedSection(untracked));
|
|
8623
|
-
if (!hasVisibleFiles) {
|
|
10503
|
+
if (!hasVisibleFiles && !hasOperation) {
|
|
8624
10504
|
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.";
|
|
8625
10505
|
body.append(make("div", "git-changes-empty success", emptyMessage));
|
|
8626
10506
|
}
|
|
10507
|
+
body.append(renderGitToolsSection());
|
|
8627
10508
|
if (hasVisibleFiles) requestAnimationFrame(updateGitChangesCurrentFileHeader);
|
|
8628
10509
|
}
|
|
8629
10510
|
|
|
8630
10511
|
async function loadGitChangesDialog(tabContext = activeTabContext()) {
|
|
8631
10512
|
const requestSerial = ++gitChangesRequestSerial;
|
|
8632
10513
|
gitChangesUntrackedContentRequests.clear();
|
|
8633
|
-
gitChangesState = { ...gitChangesState, loading: true, error: "", message: "", pullResult: null, tabId: tabContext.tabId || activeTabId };
|
|
10514
|
+
gitChangesState = { ...gitChangesState, loading: true, error: "", errorCode: "", errorHint: "", message: "", pullResult: null, tabId: tabContext.tabId || activeTabId };
|
|
8634
10515
|
renderGitChangesDialog();
|
|
8635
10516
|
try {
|
|
8636
|
-
const response = await
|
|
10517
|
+
const [response, operationResponse] = await Promise.all([
|
|
10518
|
+
api("/api/git-changes", { tabId: tabContext.tabId }),
|
|
10519
|
+
api("/api/git-operation", { tabId: tabContext.tabId }).catch(() => null),
|
|
10520
|
+
]);
|
|
8637
10521
|
if (requestSerial !== gitChangesRequestSerial) return;
|
|
8638
10522
|
if (!response.ok) throw new Error(response.error || "Failed to load git changes");
|
|
8639
|
-
gitChangesState = {
|
|
10523
|
+
gitChangesState = {
|
|
10524
|
+
...gitChangesState,
|
|
10525
|
+
loading: false,
|
|
10526
|
+
pulling: false,
|
|
10527
|
+
fetching: false,
|
|
10528
|
+
error: "",
|
|
10529
|
+
errorCode: "",
|
|
10530
|
+
errorHint: "",
|
|
10531
|
+
message: "",
|
|
10532
|
+
pullResult: null,
|
|
10533
|
+
data: response.data || null,
|
|
10534
|
+
operation: operationResponse?.ok ? operationResponse.data : null,
|
|
10535
|
+
tabId: tabContext.tabId || activeTabId,
|
|
10536
|
+
};
|
|
8640
10537
|
} catch (error) {
|
|
8641
10538
|
if (requestSerial !== gitChangesRequestSerial) return;
|
|
8642
10539
|
gitChangesState = { ...gitChangesState, loading: false, error: error.message || String(error) };
|
|
@@ -8649,7 +10546,22 @@ function openGitChangesDialog() {
|
|
|
8649
10546
|
hideFooterTooltip();
|
|
8650
10547
|
const tabContext = activeTabContext();
|
|
8651
10548
|
const tabId = tabContext.tabId || activeTabId;
|
|
8652
|
-
|
|
10549
|
+
if (gitToolsState.tabId !== tabId) resetGitToolsState(tabId);
|
|
10550
|
+
gitChangesState = {
|
|
10551
|
+
...gitChangesState,
|
|
10552
|
+
loading: true,
|
|
10553
|
+
pulling: false,
|
|
10554
|
+
fetching: false,
|
|
10555
|
+
error: "",
|
|
10556
|
+
errorCode: "",
|
|
10557
|
+
errorHint: "",
|
|
10558
|
+
message: "",
|
|
10559
|
+
pullResult: null,
|
|
10560
|
+
data: gitChangesState.tabId === tabId ? gitChangesState.data : null,
|
|
10561
|
+
operation: gitChangesState.tabId === tabId ? gitChangesState.operation : null,
|
|
10562
|
+
lastFetch: gitChangesState.tabId === tabId ? gitChangesState.lastFetch : null,
|
|
10563
|
+
tabId,
|
|
10564
|
+
};
|
|
8653
10565
|
renderGitChangesDialog();
|
|
8654
10566
|
if (!elements.gitChangesDialog.open) elements.gitChangesDialog.showModal();
|
|
8655
10567
|
loadGitChangesDialog(tabContext).catch((error) => addEvent(error.message || String(error), "error"));
|
|
@@ -8663,25 +10575,30 @@ function refreshGitChangesDialog() {
|
|
|
8663
10575
|
async function pullGitChangesDialog() {
|
|
8664
10576
|
const tabContext = { tabId: gitChangesState.tabId || activeTabId };
|
|
8665
10577
|
const behind = Number(gitChangesState.data?.remote?.behind ?? gitChangesState.data?.summary?.behind ?? 0) || 0;
|
|
8666
|
-
if (behind <= 0 || gitChangesState.pulling || gitChangesState.loading) return;
|
|
10578
|
+
if (behind <= 0 || gitChangesState.pulling || gitChangesState.loading || gitChangesState.fetching) return;
|
|
10579
|
+
if (gitChangesState.data?.remote?.diverged === true) return;
|
|
8667
10580
|
const root = gitChangesState.data?.root || "the current repository";
|
|
8668
10581
|
if (!window.confirm(`Run git pull --ff-only in ${root}?`)) return;
|
|
8669
10582
|
|
|
8670
10583
|
const requestSerial = ++gitChangesRequestSerial;
|
|
8671
|
-
gitChangesState = { ...gitChangesState, pulling: true, loading: false, error: "", message: "", pullResult: null, tabId: tabContext.tabId };
|
|
10584
|
+
gitChangesState = { ...gitChangesState, pulling: true, loading: false, error: "", errorCode: "", errorHint: "", message: "", pullResult: null, tabId: tabContext.tabId };
|
|
8672
10585
|
renderGitChangesDialog();
|
|
8673
10586
|
try {
|
|
8674
10587
|
const response = await api("/api/git-changes/pull", { method: "POST", body: {}, tabId: tabContext.tabId });
|
|
8675
10588
|
if (requestSerial !== gitChangesRequestSerial) return;
|
|
8676
10589
|
if (!response.ok) {
|
|
8677
|
-
|
|
10590
|
+
gitChangesState = { ...gitChangesState, errorCode: response.code || "" };
|
|
10591
|
+
const detail = [response.error, response.hint].filter(Boolean).join("\n").trim();
|
|
8678
10592
|
throw new Error(detail || "Failed to pull git changes");
|
|
8679
10593
|
}
|
|
8680
10594
|
const pullResult = normalizeGitPullResult(response.data || {});
|
|
8681
10595
|
gitChangesState = {
|
|
10596
|
+
...gitChangesState,
|
|
8682
10597
|
loading: false,
|
|
8683
10598
|
pulling: false,
|
|
8684
10599
|
error: "",
|
|
10600
|
+
errorCode: "",
|
|
10601
|
+
errorHint: "",
|
|
8685
10602
|
message: gitPullResultStatus(pullResult),
|
|
8686
10603
|
pullResult,
|
|
8687
10604
|
data: response.data?.changes || gitChangesState.data,
|
|
@@ -8700,10 +10617,742 @@ async function pullGitChangesDialog() {
|
|
|
8700
10617
|
function closeGitChangesDialog() {
|
|
8701
10618
|
gitChangesRequestSerial += 1;
|
|
8702
10619
|
gitChangesUntrackedContentRequests.clear();
|
|
8703
|
-
gitChangesState = { ...gitChangesState, loading: false, pulling: false };
|
|
10620
|
+
gitChangesState = { ...gitChangesState, loading: false, pulling: false, fetching: false };
|
|
8704
10621
|
if (elements.gitChangesDialog?.open) elements.gitChangesDialog.close();
|
|
8705
10622
|
}
|
|
8706
10623
|
|
|
10624
|
+
async function fetchGitChangesDialog() {
|
|
10625
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
10626
|
+
if (gitChangesState.fetching || gitChangesState.loading || gitChangesState.pulling) return;
|
|
10627
|
+
const requestSerial = ++gitChangesRequestSerial;
|
|
10628
|
+
gitChangesState = { ...gitChangesState, fetching: true, error: "", errorCode: "", errorHint: "", message: "", pullResult: null };
|
|
10629
|
+
renderGitChangesDialog();
|
|
10630
|
+
try {
|
|
10631
|
+
const response = await api("/api/git-fetch", { method: "POST", body: {}, tabId });
|
|
10632
|
+
if (requestSerial !== gitChangesRequestSerial) return;
|
|
10633
|
+
if (!response.ok) {
|
|
10634
|
+
gitChangesState = { ...gitChangesState, errorCode: response.code || "" };
|
|
10635
|
+
throw new Error([response.error, response.hint].filter(Boolean).join("\n") || "git fetch failed");
|
|
10636
|
+
}
|
|
10637
|
+
const summaryLine = String(response.data?.summary || "").split(/\r?\n/).map((line) => line.trim()).filter(Boolean).slice(-1)[0] || "";
|
|
10638
|
+
gitChangesState = {
|
|
10639
|
+
...gitChangesState,
|
|
10640
|
+
fetching: false,
|
|
10641
|
+
data: response.data?.changes || gitChangesState.data,
|
|
10642
|
+
lastFetch: { at: Date.now(), summary: summaryLine, error: "" },
|
|
10643
|
+
message: summaryLine && !/^fetching/i.test(summaryLine) ? `Fetched (--prune). ${summaryLine}` : "Fetched remote state (git fetch --prune).",
|
|
10644
|
+
};
|
|
10645
|
+
addEvent("Fetched remote state (git fetch --prune).", "success");
|
|
10646
|
+
requestGitFooterWebuiPayload(activeTabContext(tabId), { force: true });
|
|
10647
|
+
} catch (error) {
|
|
10648
|
+
if (requestSerial !== gitChangesRequestSerial) return;
|
|
10649
|
+
gitChangesState = { ...gitChangesState, fetching: false, error: error.message || String(error), lastFetch: { at: Date.now(), summary: "", error: error.message || String(error) } };
|
|
10650
|
+
}
|
|
10651
|
+
renderGitChangesDialog();
|
|
10652
|
+
}
|
|
10653
|
+
|
|
10654
|
+
// Fetch state lines shown inside the dialog: the extension's startup/tab fetch
|
|
10655
|
+
// state (from the changes-chip tooltip payload) plus this dialog's last fetch.
|
|
10656
|
+
function gitChangesFetchStateLines() {
|
|
10657
|
+
const lines = [];
|
|
10658
|
+
const chip = parseGitFooterWebuiPayload()?.meta?.find((item) => item.key === "changes");
|
|
10659
|
+
const extensionLine = String(chip?.title || "").split("\n").find((line) => /git fetch/i.test(line));
|
|
10660
|
+
if (extensionLine) lines.push(`Tab fetch state: ${extensionLine.trim()}`);
|
|
10661
|
+
const lastFetch = gitChangesState.lastFetch;
|
|
10662
|
+
if (lastFetch?.at) {
|
|
10663
|
+
const time = new Date(lastFetch.at).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" });
|
|
10664
|
+
lines.push(lastFetch.error ? `Last fetch from this dialog at ${time} failed: ${lastFetch.error}` : `Last fetch from this dialog at ${time}${lastFetch.summary ? ` — ${lastFetch.summary}` : " completed."}`);
|
|
10665
|
+
}
|
|
10666
|
+
return lines;
|
|
10667
|
+
}
|
|
10668
|
+
|
|
10669
|
+
async function integrateGitChangesDialog(mode) {
|
|
10670
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
10671
|
+
const data = gitChangesState.data;
|
|
10672
|
+
const upstream = data?.remote?.upstream || "@{upstream}";
|
|
10673
|
+
const command = mode === "merge" ? `git merge --no-edit ${upstream}` : `git rebase ${upstream}`;
|
|
10674
|
+
if (!window.confirm([
|
|
10675
|
+
`${mode === "merge" ? "Merge" : "Rebase onto"} ${upstream} in ${data?.root || "the current repository"}?`,
|
|
10676
|
+
"",
|
|
10677
|
+
`Command: ${command}`,
|
|
10678
|
+
mode === "rebase" ? "Rebase rewrites local commits. Conflicts open the conflicts panel." : "Conflicts open the conflicts panel.",
|
|
10679
|
+
"For risky integration, prefer a separate worktree instead.",
|
|
10680
|
+
].join("\n"))) return;
|
|
10681
|
+
gitChangesState = { ...gitChangesState, pulling: true, error: "", errorCode: "", errorHint: "", message: "", pullResult: null };
|
|
10682
|
+
renderGitChangesDialog();
|
|
10683
|
+
try {
|
|
10684
|
+
const response = await api("/api/git-changes/integrate", { method: "POST", body: { mode, confirmed: true }, tabId });
|
|
10685
|
+
if (!response.ok) {
|
|
10686
|
+
const errText = [response.error, response.hint].filter(Boolean).join("\n") || `git ${mode} failed`;
|
|
10687
|
+
gitChangesState = { ...gitChangesState, pulling: false };
|
|
10688
|
+
await loadGitChangesDialog({ tabId });
|
|
10689
|
+
gitChangesState = { ...gitChangesState, error: errText, errorCode: response.code || "" };
|
|
10690
|
+
renderGitChangesDialog();
|
|
10691
|
+
return;
|
|
10692
|
+
}
|
|
10693
|
+
gitChangesState = { ...gitChangesState, pulling: false, message: `Integrated ${upstream} via ${mode}.`, data: response.data?.changes || gitChangesState.data };
|
|
10694
|
+
addEvent(`Integrated ${upstream} via ${mode}.`, "success");
|
|
10695
|
+
renderGitChangesDialog();
|
|
10696
|
+
requestGitFooterWebuiPayload(activeTabContext(tabId), { force: true });
|
|
10697
|
+
} catch (error) {
|
|
10698
|
+
gitChangesState = { ...gitChangesState, pulling: false, error: error.message || String(error) };
|
|
10699
|
+
renderGitChangesDialog();
|
|
10700
|
+
}
|
|
10701
|
+
}
|
|
10702
|
+
|
|
10703
|
+
async function runGitFileAction(action, path) {
|
|
10704
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
10705
|
+
const root = gitChangesState.data?.root || "the repository";
|
|
10706
|
+
const config = {
|
|
10707
|
+
stage: { url: "/api/git-changes/stage-file", body: { path }, label: `Staged ${path}.` },
|
|
10708
|
+
unstage: { url: "/api/git-changes/unstage-file", body: { path }, label: `Unstaged ${path}.` },
|
|
10709
|
+
discard: {
|
|
10710
|
+
url: "/api/git-changes/discard-file",
|
|
10711
|
+
body: { path, confirmed: true },
|
|
10712
|
+
label: `Discarded changes in ${path}.`,
|
|
10713
|
+
confirm: `Discard working tree changes in ${path}?\n\nRepository: ${root}\nCommand: git restore -- ${path}\n\nThis permanently reverts unstaged edits to this file.`,
|
|
10714
|
+
},
|
|
10715
|
+
"delete-untracked": {
|
|
10716
|
+
url: "/api/git-changes/delete-untracked",
|
|
10717
|
+
body: { path, confirmed: true },
|
|
10718
|
+
label: `Deleted untracked file ${path}.`,
|
|
10719
|
+
confirm: `Delete untracked file ${path}?\n\nRepository: ${root}\n\nThis permanently removes the file from disk.`,
|
|
10720
|
+
},
|
|
10721
|
+
}[action];
|
|
10722
|
+
if (!config) return;
|
|
10723
|
+
if (config.confirm && !window.confirm(config.confirm)) return;
|
|
10724
|
+
try {
|
|
10725
|
+
const response = await api(config.url, { method: "POST", body: config.body, tabId });
|
|
10726
|
+
if (!response.ok) throw new Error([response.error, response.hint].filter(Boolean).join("\n") || `git ${action} failed`);
|
|
10727
|
+
gitChangesState = { ...gitChangesState, data: response.data?.changes || gitChangesState.data, message: config.label, error: "", errorCode: "", errorHint: "" };
|
|
10728
|
+
addEvent(config.label, "success");
|
|
10729
|
+
renderGitChangesDialog();
|
|
10730
|
+
requestGitFooterWebuiPayload(activeTabContext(tabId), { force: true });
|
|
10731
|
+
} catch (error) {
|
|
10732
|
+
gitChangesState = { ...gitChangesState, error: error.message || String(error) };
|
|
10733
|
+
renderGitChangesDialog();
|
|
10734
|
+
addEvent(error.message || String(error), "error");
|
|
10735
|
+
}
|
|
10736
|
+
}
|
|
10737
|
+
|
|
10738
|
+
const GIT_OPERATION_TITLES = {
|
|
10739
|
+
merge: "Merge in progress",
|
|
10740
|
+
rebase: "Rebase in progress",
|
|
10741
|
+
"cherry-pick": "Cherry-pick in progress",
|
|
10742
|
+
revert: "Revert in progress",
|
|
10743
|
+
bisect: "Bisect in progress",
|
|
10744
|
+
};
|
|
10745
|
+
|
|
10746
|
+
function renderGitConflictPreview(preview) {
|
|
10747
|
+
if (!preview) return null;
|
|
10748
|
+
if (preview.kind === "binary") return make("pre", "git-conflict-preview muted", `Binary file (${formatBytes(preview.size || 0)}); resolve it with an external tool, then mark it resolved.`);
|
|
10749
|
+
if (preview.kind === "large") return make("pre", "git-conflict-preview muted", `File too large to preview (${formatBytes(preview.size || 0)}).`);
|
|
10750
|
+
if (preview.kind === "missing") return make("pre", "git-conflict-preview muted", "File is missing in the working tree (deleted on one side).");
|
|
10751
|
+
if (preview.kind === "error") return make("pre", "git-conflict-preview muted", preview.error || "Preview unavailable.");
|
|
10752
|
+
if (preview.kind !== "text") return null;
|
|
10753
|
+
if (!preview.hunks?.length) {
|
|
10754
|
+
return make("pre", "git-conflict-preview muted", preview.hasMarkers ? "Conflict markers present." : "No conflict markers found; the file may already be resolved — mark it resolved to stage it.");
|
|
10755
|
+
}
|
|
10756
|
+
const text = preview.hunks.map((hunk) => hunk.lines.join("\n") + (hunk.truncated ? "\n…" : "")).join("\n⋯\n");
|
|
10757
|
+
return make("pre", "git-conflict-preview", text);
|
|
10758
|
+
}
|
|
10759
|
+
|
|
10760
|
+
async function runGitOperationRequest(url, body, successLabel) {
|
|
10761
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
10762
|
+
gitToolsState.busy.add("operation");
|
|
10763
|
+
renderGitChangesDialog();
|
|
10764
|
+
try {
|
|
10765
|
+
const response = await api(url, { method: "POST", body, tabId });
|
|
10766
|
+
if (!response.ok) throw new Error([response.error, response.hint].filter(Boolean).join("\n") || "git operation failed");
|
|
10767
|
+
gitToolsState.busy.delete("operation");
|
|
10768
|
+
addEvent(`${successLabel}.`, "success");
|
|
10769
|
+
await loadGitChangesDialog({ tabId });
|
|
10770
|
+
gitChangesState = { ...gitChangesState, message: `${successLabel}.` };
|
|
10771
|
+
renderGitChangesDialog();
|
|
10772
|
+
requestGitFooterWebuiPayload(activeTabContext(tabId), { force: true });
|
|
10773
|
+
} catch (error) {
|
|
10774
|
+
gitToolsState.busy.delete("operation");
|
|
10775
|
+
gitChangesState = { ...gitChangesState, error: error.message || String(error) };
|
|
10776
|
+
renderGitChangesDialog();
|
|
10777
|
+
}
|
|
10778
|
+
}
|
|
10779
|
+
|
|
10780
|
+
function renderGitOperationPanel(operation) {
|
|
10781
|
+
const kind = operation?.operation;
|
|
10782
|
+
if (!kind) return null;
|
|
10783
|
+
const busy = gitToolsState.busy.has("operation") || gitChangesState.loading || gitChangesState.pulling || gitChangesState.fetching;
|
|
10784
|
+
const conflicts = operation.conflicts || [];
|
|
10785
|
+
const panel = make("section", "git-operation-panel");
|
|
10786
|
+
const header = make("div", "git-operation-header");
|
|
10787
|
+
header.append(
|
|
10788
|
+
make("strong", "git-operation-title", GIT_OPERATION_TITLES[kind] || `${kind} in progress`),
|
|
10789
|
+
make("span", "git-operation-meta", `${conflicts.length} conflicted file${conflicts.length === 1 ? "" : "s"} · ${operation.root || ""}`),
|
|
10790
|
+
);
|
|
10791
|
+
panel.append(header);
|
|
10792
|
+
|
|
10793
|
+
if (kind === "bisect") {
|
|
10794
|
+
if (operation.bisect?.log) panel.append(make("pre", "git-conflict-preview", operation.bisect.log));
|
|
10795
|
+
const row = make("div", "git-operation-actions");
|
|
10796
|
+
for (const verdict of ["good", "bad", "skip"]) {
|
|
10797
|
+
const button = make("button", "git-operation-button", `bisect ${verdict}`);
|
|
10798
|
+
button.type = "button";
|
|
10799
|
+
button.disabled = busy;
|
|
10800
|
+
button.title = `git bisect ${verdict}`;
|
|
10801
|
+
button.addEventListener("click", () => runGitOperationRequest("/api/git-operation/bisect", { verdict }, `Marked the current revision as ${verdict}`));
|
|
10802
|
+
row.append(button);
|
|
10803
|
+
}
|
|
10804
|
+
const reset = make("button", "git-operation-button danger", "Reset bisect");
|
|
10805
|
+
reset.type = "button";
|
|
10806
|
+
reset.disabled = busy;
|
|
10807
|
+
reset.title = "git bisect reset";
|
|
10808
|
+
reset.addEventListener("click", () => {
|
|
10809
|
+
if (!window.confirm(`Reset the bisect session in ${operation.root}?\n\nCommand: git bisect reset\nThis returns to the pre-bisect checkout.`)) return;
|
|
10810
|
+
runGitOperationRequest("/api/git-operation/bisect", { verdict: "reset", confirmed: true }, "Reset the bisect session");
|
|
10811
|
+
});
|
|
10812
|
+
row.append(reset);
|
|
10813
|
+
panel.append(row);
|
|
10814
|
+
return panel;
|
|
10815
|
+
}
|
|
10816
|
+
|
|
10817
|
+
if (conflicts.length) {
|
|
10818
|
+
const list = make("div", "git-conflict-list");
|
|
10819
|
+
for (const conflict of conflicts) {
|
|
10820
|
+
const item = make("details", "git-conflict-file");
|
|
10821
|
+
item.open = conflicts.length <= 3;
|
|
10822
|
+
const summary = make("summary", "git-conflict-summary");
|
|
10823
|
+
summary.append(
|
|
10824
|
+
make("span", "git-conflict-status", conflict.status || "UU"),
|
|
10825
|
+
make("span", "git-conflict-path", conflict.path),
|
|
10826
|
+
);
|
|
10827
|
+
const actions = gitFileActionButtons([
|
|
10828
|
+
{
|
|
10829
|
+
label: "Mark resolved",
|
|
10830
|
+
title: `git add -- ${conflict.path}`,
|
|
10831
|
+
onClick: () => runGitOperationRequest("/api/git-operation/stage-file", { path: conflict.path }, `Marked ${conflict.path} as resolved`),
|
|
10832
|
+
},
|
|
10833
|
+
]);
|
|
10834
|
+
if (actions) summary.append(actions);
|
|
10835
|
+
item.append(summary);
|
|
10836
|
+
const preview = renderGitConflictPreview(conflict.preview);
|
|
10837
|
+
if (preview) item.append(preview);
|
|
10838
|
+
list.append(item);
|
|
10839
|
+
}
|
|
10840
|
+
panel.append(list);
|
|
10841
|
+
} else {
|
|
10842
|
+
panel.append(make("div", "git-changes-empty success", "No unmerged paths remain. Continue to finish the operation."));
|
|
10843
|
+
}
|
|
10844
|
+
|
|
10845
|
+
const row = make("div", "git-operation-actions");
|
|
10846
|
+
const refresh = make("button", "git-operation-button", "Refresh conflicts");
|
|
10847
|
+
refresh.type = "button";
|
|
10848
|
+
refresh.disabled = busy;
|
|
10849
|
+
refresh.addEventListener("click", refreshGitChangesDialog);
|
|
10850
|
+
row.append(refresh);
|
|
10851
|
+
|
|
10852
|
+
const cont = make("button", "git-operation-button primary", kind === "merge" ? "Continue (commit merge)" : "Continue");
|
|
10853
|
+
cont.type = "button";
|
|
10854
|
+
cont.disabled = busy || operation.canContinue !== true;
|
|
10855
|
+
cont.title = operation.canContinue ? operation.commands?.continue || "" : "Resolve and stage every conflicted file first.";
|
|
10856
|
+
cont.addEventListener("click", () => runGitOperationRequest("/api/git-operation/continue", {}, `Continued the ${kind}`));
|
|
10857
|
+
row.append(cont);
|
|
10858
|
+
|
|
10859
|
+
if (operation.canSkip) {
|
|
10860
|
+
const skip = make("button", "git-operation-button", "Skip");
|
|
10861
|
+
skip.type = "button";
|
|
10862
|
+
skip.disabled = busy;
|
|
10863
|
+
skip.title = operation.commands?.skip || "";
|
|
10864
|
+
skip.addEventListener("click", () => {
|
|
10865
|
+
if (!window.confirm(`Skip the current ${kind} step?\n\nCommand: ${operation.commands?.skip || `git ${kind} --skip`}\nThe skipped commit is left out of the result.`)) return;
|
|
10866
|
+
runGitOperationRequest("/api/git-operation/skip", {}, `Skipped the current ${kind} step`);
|
|
10867
|
+
});
|
|
10868
|
+
row.append(skip);
|
|
10869
|
+
}
|
|
10870
|
+
|
|
10871
|
+
const abort = make("button", "git-operation-button danger", "Abort");
|
|
10872
|
+
abort.type = "button";
|
|
10873
|
+
abort.disabled = busy;
|
|
10874
|
+
abort.title = operation.commands?.abort || "";
|
|
10875
|
+
abort.addEventListener("click", () => {
|
|
10876
|
+
const summary = operation.summary || {};
|
|
10877
|
+
if (!window.confirm([
|
|
10878
|
+
`Abort the ${kind} in ${operation.root}?`,
|
|
10879
|
+
"",
|
|
10880
|
+
`Command: ${operation.commands?.abort || `git ${kind} --abort`}`,
|
|
10881
|
+
`Working tree: ${summary.staged || 0} staged · ${summary.unstaged || 0} unstaged · ${conflicts.length} conflicted`,
|
|
10882
|
+
"",
|
|
10883
|
+
"This discards the in-progress operation state and returns to the pre-operation HEAD.",
|
|
10884
|
+
].join("\n"))) return;
|
|
10885
|
+
runGitOperationRequest("/api/git-operation/abort", { confirmed: true }, `Aborted the ${kind}`);
|
|
10886
|
+
});
|
|
10887
|
+
row.append(abort);
|
|
10888
|
+
panel.append(row);
|
|
10889
|
+
return panel;
|
|
10890
|
+
}
|
|
10891
|
+
|
|
10892
|
+
function renderGitDivergedBar(data) {
|
|
10893
|
+
const remote = data?.remote || {};
|
|
10894
|
+
const bar = make("section", "git-diverged-bar");
|
|
10895
|
+
bar.append(make("strong", "git-diverged-title", `Diverged from ${remote.upstream || "upstream"}: ↑${remote.ahead || 0} local · ↓${remote.behind || 0} remote.`));
|
|
10896
|
+
bar.append(make("div", "git-tools-note", "One-click pull is disabled. Review the incoming diff below, then integrate explicitly — a separate worktree is the safest place for risky integration."));
|
|
10897
|
+
const row = make("div", "git-operation-actions");
|
|
10898
|
+
const busy = gitChangesState.loading || gitChangesState.pulling || gitChangesState.fetching;
|
|
10899
|
+
const addButton = (label, className, title, handler) => {
|
|
10900
|
+
const button = make("button", `git-operation-button ${className}`.trim(), label);
|
|
10901
|
+
button.type = "button";
|
|
10902
|
+
button.disabled = busy;
|
|
10903
|
+
button.title = title;
|
|
10904
|
+
button.addEventListener("click", handler);
|
|
10905
|
+
row.append(button);
|
|
10906
|
+
};
|
|
10907
|
+
addButton("Merge upstream…", "", `git merge --no-edit ${remote.upstream || "@{upstream}"}`, () => integrateGitChangesDialog("merge"));
|
|
10908
|
+
addButton("Rebase onto upstream…", "", `git rebase ${remote.upstream || "@{upstream}"}`, () => integrateGitChangesDialog("rebase"));
|
|
10909
|
+
addButton("Create integration worktree", "", "Open the branch picker to integrate in a separate worktree tab", () => {
|
|
10910
|
+
closeGitChangesDialog();
|
|
10911
|
+
openBranchWorktreePicker();
|
|
10912
|
+
});
|
|
10913
|
+
bar.append(row);
|
|
10914
|
+
return bar;
|
|
10915
|
+
}
|
|
10916
|
+
|
|
10917
|
+
// ---- Git tools (stash, undo, worktrees, submodules, tags, signing) ----
|
|
10918
|
+
|
|
10919
|
+
const GIT_TOOLS_SECTIONS = [
|
|
10920
|
+
{ key: "stash", title: "Stash", detail: "List, apply, pop, drop, or create stashes." },
|
|
10921
|
+
{ key: "undo", title: "Undo & recovery", detail: "Undo the last unpushed commit, amend its message, review recent HEAD history." },
|
|
10922
|
+
{ key: "worktrees", title: "Worktrees", detail: "Health, removal, and pruning of git worktrees." },
|
|
10923
|
+
{ key: "submodules", title: "Submodules", detail: "Status and recursive update." },
|
|
10924
|
+
{ key: "tags", title: "Tags", detail: "Recent tags and annotated tag creation." },
|
|
10925
|
+
{ key: "signing", title: "Signing", detail: "Commit signing configuration and diagnostics." },
|
|
10926
|
+
];
|
|
10927
|
+
|
|
10928
|
+
const GIT_TOOLS_ENDPOINTS = {
|
|
10929
|
+
stash: "/api/git-stash",
|
|
10930
|
+
undo: "/api/git-undo",
|
|
10931
|
+
worktrees: "/api/git-worktrees",
|
|
10932
|
+
submodules: "/api/git-submodules",
|
|
10933
|
+
tags: "/api/git-tags",
|
|
10934
|
+
signing: "/api/git-signing",
|
|
10935
|
+
};
|
|
10936
|
+
|
|
10937
|
+
function resetGitToolsState(tabId) {
|
|
10938
|
+
gitToolsState = { tabId, openSections: new Set(), cache: {}, busy: new Set(), notice: {} };
|
|
10939
|
+
}
|
|
10940
|
+
|
|
10941
|
+
async function loadGitToolsSection(key, { force = false } = {}) {
|
|
10942
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
10943
|
+
if (!force && gitToolsState.cache[key]) return;
|
|
10944
|
+
if (gitToolsState.busy.has(`load:${key}`)) return;
|
|
10945
|
+
gitToolsState.busy.add(`load:${key}`);
|
|
10946
|
+
try {
|
|
10947
|
+
const response = await api(GIT_TOOLS_ENDPOINTS[key], { tabId });
|
|
10948
|
+
if (!response.ok) throw new Error(response.error || `Failed to load ${key}`);
|
|
10949
|
+
gitToolsState.cache[key] = response.data;
|
|
10950
|
+
if (key === "undo") {
|
|
10951
|
+
const reflog = await api("/api/git-reflog", { tabId }).catch(() => null);
|
|
10952
|
+
gitToolsState.cache.reflog = reflog?.ok ? reflog.data : null;
|
|
10953
|
+
}
|
|
10954
|
+
gitToolsState.notice[key] = "";
|
|
10955
|
+
} catch (error) {
|
|
10956
|
+
gitToolsState.notice[key] = error.message || String(error);
|
|
10957
|
+
} finally {
|
|
10958
|
+
gitToolsState.busy.delete(`load:${key}`);
|
|
10959
|
+
renderGitChangesDialog();
|
|
10960
|
+
}
|
|
10961
|
+
}
|
|
10962
|
+
|
|
10963
|
+
async function runGitToolAction(sectionKey, { url, method = "POST", body, confirm, success, successMessage, refreshChanges = false }) {
|
|
10964
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
10965
|
+
if (confirm && !window.confirm(confirm)) return;
|
|
10966
|
+
gitToolsState.busy.add(sectionKey);
|
|
10967
|
+
renderGitChangesDialog();
|
|
10968
|
+
try {
|
|
10969
|
+
const response = await api(url, { method, body, tabId });
|
|
10970
|
+
if (!response.ok) throw new Error([response.error, response.hint].filter(Boolean).join("\n") || "git action failed");
|
|
10971
|
+
const finalMessage = (typeof successMessage === "function" ? successMessage(response) : "") || success;
|
|
10972
|
+
gitToolsState.notice[sectionKey] = "";
|
|
10973
|
+
gitToolsState.busy.delete(sectionKey);
|
|
10974
|
+
addEvent(finalMessage, "success");
|
|
10975
|
+
await loadGitToolsSection(sectionKey, { force: true });
|
|
10976
|
+
if (refreshChanges) await loadGitChangesDialog({ tabId });
|
|
10977
|
+
gitChangesState = { ...gitChangesState, message: finalMessage };
|
|
10978
|
+
renderGitChangesDialog();
|
|
10979
|
+
requestGitFooterWebuiPayload(activeTabContext(tabId), { force: true });
|
|
10980
|
+
} catch (error) {
|
|
10981
|
+
gitToolsState.busy.delete(sectionKey);
|
|
10982
|
+
gitToolsState.notice[sectionKey] = error.message || String(error);
|
|
10983
|
+
renderGitChangesDialog();
|
|
10984
|
+
}
|
|
10985
|
+
}
|
|
10986
|
+
|
|
10987
|
+
function gitToolsButton(label, { className = "", disabled = false, title = "" } = {}, handler) {
|
|
10988
|
+
const button = make("button", `git-operation-button ${className}`.trim(), label);
|
|
10989
|
+
button.type = "button";
|
|
10990
|
+
button.disabled = disabled;
|
|
10991
|
+
if (title) button.title = title;
|
|
10992
|
+
button.addEventListener("click", handler);
|
|
10993
|
+
return button;
|
|
10994
|
+
}
|
|
10995
|
+
|
|
10996
|
+
// Apply/pop/drop always show the stash's --stat preview in the confirmation,
|
|
10997
|
+
// so no stash is modified sight-unseen.
|
|
10998
|
+
async function confirmGitStashActionWithPreview(stash, question) {
|
|
10999
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
11000
|
+
let statText = "";
|
|
11001
|
+
try {
|
|
11002
|
+
const preview = await api(`/api/git-stash/show?ref=${encodeURIComponent(stash.ref)}`, { tabId });
|
|
11003
|
+
statText = preview?.ok ? String(preview.data?.stat || "").trim() : "";
|
|
11004
|
+
} catch {
|
|
11005
|
+
// Preview is best-effort; the confirmation still shows the stash subject.
|
|
11006
|
+
}
|
|
11007
|
+
return window.confirm([
|
|
11008
|
+
question,
|
|
11009
|
+
"",
|
|
11010
|
+
stash.subject || stash.ref,
|
|
11011
|
+
"",
|
|
11012
|
+
statText ? `Preview (git stash show --stat):\n${statText.slice(0, 2000)}` : "Preview unavailable.",
|
|
11013
|
+
].join("\n"));
|
|
11014
|
+
}
|
|
11015
|
+
|
|
11016
|
+
function renderGitStashTools(body, data, busy) {
|
|
11017
|
+
const row = make("div", "git-operation-actions");
|
|
11018
|
+
row.append(
|
|
11019
|
+
gitToolsButton("Stash tracked changes", { disabled: busy, title: "git stash push" }, () =>
|
|
11020
|
+
runGitToolAction("stash", { url: "/api/git-stash/save", body: {}, success: "Stashed tracked changes.", refreshChanges: true })),
|
|
11021
|
+
gitToolsButton("Stash incl. untracked", { disabled: busy, title: "git stash push --include-untracked" }, () =>
|
|
11022
|
+
runGitToolAction("stash", { url: "/api/git-stash/save", body: { includeUntracked: true }, success: "Stashed tracked and untracked changes.", refreshChanges: true })),
|
|
11023
|
+
);
|
|
11024
|
+
body.append(row);
|
|
11025
|
+
const stashes = data.stashes || [];
|
|
11026
|
+
if (!stashes.length) {
|
|
11027
|
+
body.append(make("div", "git-changes-empty", "No stashes."));
|
|
11028
|
+
return body;
|
|
11029
|
+
}
|
|
11030
|
+
for (const stash of stashes) {
|
|
11031
|
+
const item = make("details", "git-tools-item");
|
|
11032
|
+
const summary = make("summary", "git-tools-item-summary");
|
|
11033
|
+
summary.append(make("span", "git-tools-item-ref", stash.ref), make("span", "git-tools-item-subject", stash.subject || ""));
|
|
11034
|
+
const actions = gitFileActionButtons([
|
|
11035
|
+
{
|
|
11036
|
+
label: "Apply",
|
|
11037
|
+
title: `git stash apply ${stash.ref}`,
|
|
11038
|
+
onClick: () => confirmGitStashActionWithPreview(stash, `Apply ${stash.ref} to the working tree?`).then((confirmed) => {
|
|
11039
|
+
if (confirmed) runGitToolAction("stash", { url: "/api/git-stash/apply", body: { ref: stash.ref }, success: `Applied ${stash.ref}.`, refreshChanges: true });
|
|
11040
|
+
}),
|
|
11041
|
+
},
|
|
11042
|
+
{
|
|
11043
|
+
label: "Pop",
|
|
11044
|
+
title: `git stash pop ${stash.ref}`,
|
|
11045
|
+
onClick: () => confirmGitStashActionWithPreview(stash, `Pop ${stash.ref}? This applies the stash and removes the entry on success.`).then((confirmed) => {
|
|
11046
|
+
if (confirmed) runGitToolAction("stash", { url: "/api/git-stash/pop", body: { ref: stash.ref }, success: `Popped ${stash.ref}.`, refreshChanges: true });
|
|
11047
|
+
}),
|
|
11048
|
+
},
|
|
11049
|
+
{
|
|
11050
|
+
label: "Drop",
|
|
11051
|
+
className: "danger",
|
|
11052
|
+
title: `git stash drop ${stash.ref}`,
|
|
11053
|
+
onClick: () => confirmGitStashActionWithPreview(stash, `Drop ${stash.ref}? This permanently deletes the stash entry.`).then((confirmed) => {
|
|
11054
|
+
if (confirmed) runGitToolAction("stash", { url: "/api/git-stash/drop", body: { ref: stash.ref, confirmed: true }, success: `Dropped ${stash.ref}.` });
|
|
11055
|
+
}),
|
|
11056
|
+
},
|
|
11057
|
+
]);
|
|
11058
|
+
if (actions) summary.append(actions);
|
|
11059
|
+
item.append(summary);
|
|
11060
|
+
item.addEventListener("toggle", async () => {
|
|
11061
|
+
if (!item.open || item.dataset.previewLoaded) return;
|
|
11062
|
+
item.dataset.previewLoaded = "1";
|
|
11063
|
+
const placeholder = make("pre", "git-conflict-preview muted", "Loading stash preview…");
|
|
11064
|
+
item.append(placeholder);
|
|
11065
|
+
const preview = await api(`/api/git-stash/show?ref=${encodeURIComponent(stash.ref)}`, { tabId: gitChangesState.tabId || activeTabId }).catch(() => null);
|
|
11066
|
+
const text = preview?.ok ? [preview.data?.stat, preview.data?.patch].filter(Boolean).join("\n\n") : "Preview unavailable.";
|
|
11067
|
+
placeholder.textContent = text || "Empty stash preview.";
|
|
11068
|
+
placeholder.classList.toggle("muted", !preview?.ok);
|
|
11069
|
+
});
|
|
11070
|
+
body.append(item);
|
|
11071
|
+
}
|
|
11072
|
+
return body;
|
|
11073
|
+
}
|
|
11074
|
+
|
|
11075
|
+
function renderGitUndoTools(body, data, busy) {
|
|
11076
|
+
const last = data.lastCommit;
|
|
11077
|
+
body.append(make("div", "git-tools-note", last ? `Last commit: ${last.hash} ${last.subject}` : "No commits yet."));
|
|
11078
|
+
const row = make("div", "git-operation-actions");
|
|
11079
|
+
row.append(gitToolsButton(
|
|
11080
|
+
"Undo last commit (keep changes)",
|
|
11081
|
+
{ disabled: busy || !data.canUndoLastCommit, title: data.canUndoLastCommit ? "git reset --soft HEAD~1" : "Requires an unpushed commit with a parent and no operation in progress." },
|
|
11082
|
+
() => runGitToolAction("undo", {
|
|
11083
|
+
url: "/api/git-undo/last-commit",
|
|
11084
|
+
body: { confirmed: true },
|
|
11085
|
+
confirm: [
|
|
11086
|
+
`Undo the last commit in ${data.root}?`,
|
|
11087
|
+
"",
|
|
11088
|
+
`Commit: ${last?.hash || ""} ${last?.subject || ""}`,
|
|
11089
|
+
"Command: git reset --soft HEAD~1 (the commit's changes stay staged)",
|
|
11090
|
+
"Restore afterwards with: git reset --soft ORIG_HEAD",
|
|
11091
|
+
].join("\n"),
|
|
11092
|
+
success: "Undid the last commit; its changes remain staged.",
|
|
11093
|
+
successMessage: (response) => {
|
|
11094
|
+
const undone = response.data?.undoneCommit;
|
|
11095
|
+
const restore = response.data?.restoreCommand || "git reset --soft ORIG_HEAD";
|
|
11096
|
+
return `Undid commit ${undone?.hash || ""} "${undone?.subject || ""}"; its changes remain staged. Restore with: ${restore}`;
|
|
11097
|
+
},
|
|
11098
|
+
refreshChanges: true,
|
|
11099
|
+
}),
|
|
11100
|
+
));
|
|
11101
|
+
row.append(gitToolsButton(
|
|
11102
|
+
"Amend last commit message",
|
|
11103
|
+
{ disabled: busy || !data.canAmendMessage, title: data.canAmendMessage ? "git commit --amend -m <message>" : "Requires an unpushed commit and an empty staging area." },
|
|
11104
|
+
() => {
|
|
11105
|
+
const message = window.prompt("New commit message:", last?.subject || "");
|
|
11106
|
+
if (!message || !message.trim()) return;
|
|
11107
|
+
runGitToolAction("undo", {
|
|
11108
|
+
url: "/api/git-undo/amend-message",
|
|
11109
|
+
body: { confirmed: true, message: message.trim() },
|
|
11110
|
+
confirm: `Rewrite the last commit message?\n\nOld: ${last?.subject || ""}\nNew: ${message.trim()}`,
|
|
11111
|
+
success: "Amended the last commit message.",
|
|
11112
|
+
successMessage: (response) => {
|
|
11113
|
+
const previous = response.data?.previousCommit;
|
|
11114
|
+
const restore = response.data?.restoreCommand || "git reset --soft ORIG_HEAD";
|
|
11115
|
+
return `Amended the last commit message${previous?.hash ? ` (was ${previous.hash} "${previous.subject}")` : ""}. Restore with: ${restore}`;
|
|
11116
|
+
},
|
|
11117
|
+
});
|
|
11118
|
+
},
|
|
11119
|
+
));
|
|
11120
|
+
body.append(row);
|
|
11121
|
+
const reflog = gitToolsState.cache.reflog;
|
|
11122
|
+
if (reflog?.entries?.length) {
|
|
11123
|
+
const details = make("details", "git-tools-item");
|
|
11124
|
+
details.append(make("summary", "git-tools-item-summary", `Recent HEAD history (${reflog.entries.length})`));
|
|
11125
|
+
details.append(make("pre", "git-conflict-preview", reflog.entries.map((entry) => `${entry.selector}\t${entry.hash}\t${entry.subject}`).join("\n")));
|
|
11126
|
+
body.append(details);
|
|
11127
|
+
body.append(make("div", "git-tools-note", "Recovery from here is read-only: copy a hash and use git reset/cherry-pick in a terminal."));
|
|
11128
|
+
}
|
|
11129
|
+
return body;
|
|
11130
|
+
}
|
|
11131
|
+
|
|
11132
|
+
function renderGitWorktreeTools(body, data, busy) {
|
|
11133
|
+
const worktrees = data.worktrees || [];
|
|
11134
|
+
for (const worktree of worktrees) {
|
|
11135
|
+
const item = make("div", "git-tools-row");
|
|
11136
|
+
const health = [
|
|
11137
|
+
worktree.isMainWorktree ? "main" : "",
|
|
11138
|
+
worktree.current ? "current" : "",
|
|
11139
|
+
worktree.detached ? "detached" : "",
|
|
11140
|
+
worktree.locked ? `locked${worktree.lockedReason ? `: ${worktree.lockedReason}` : ""}` : "",
|
|
11141
|
+
worktree.prunable ? "prunable" : "",
|
|
11142
|
+
].filter(Boolean).join(" · ");
|
|
11143
|
+
item.append(
|
|
11144
|
+
make("span", "git-tools-item-ref", worktree.branch || "detached"),
|
|
11145
|
+
make("span", "git-tools-item-subject", `${normalizeDisplayPath(worktree.path)}${health ? ` · ${health}` : ""}`),
|
|
11146
|
+
);
|
|
11147
|
+
if (!worktree.isMainWorktree && !worktree.current) {
|
|
11148
|
+
const actions = gitFileActionButtons([
|
|
11149
|
+
{
|
|
11150
|
+
label: "Remove",
|
|
11151
|
+
className: "danger",
|
|
11152
|
+
title: `git worktree remove ${worktree.path}`,
|
|
11153
|
+
onClick: () => runGitToolAction("worktrees", {
|
|
11154
|
+
method: "DELETE",
|
|
11155
|
+
url: "/api/git-worktrees",
|
|
11156
|
+
body: { path: worktree.path, confirmed: true },
|
|
11157
|
+
confirm: [
|
|
11158
|
+
`Remove worktree ${worktree.path}?`,
|
|
11159
|
+
"",
|
|
11160
|
+
`Branch: ${worktree.branch || "detached"}`,
|
|
11161
|
+
"This deletes the checkout directory. Dirty worktrees and worktrees with open tabs are refused.",
|
|
11162
|
+
].join("\n"),
|
|
11163
|
+
success: `Removed worktree ${worktree.path}.`,
|
|
11164
|
+
}),
|
|
11165
|
+
},
|
|
11166
|
+
]);
|
|
11167
|
+
if (actions) item.append(actions);
|
|
11168
|
+
}
|
|
11169
|
+
body.append(item);
|
|
11170
|
+
}
|
|
11171
|
+
const row = make("div", "git-operation-actions");
|
|
11172
|
+
row.append(gitToolsButton("Prune stale worktrees…", { disabled: busy, title: "git worktree prune (with dry-run preview)" }, async () => {
|
|
11173
|
+
const tabId = gitChangesState.tabId || activeTabId;
|
|
11174
|
+
try {
|
|
11175
|
+
const preview = await api("/api/git-worktrees/prune", { tabId });
|
|
11176
|
+
const previewData = preview?.data || preview || {};
|
|
11177
|
+
const output = String(previewData.output || "").trim();
|
|
11178
|
+
const prunable = previewData.prunable || [];
|
|
11179
|
+
if (!output && !prunable.length) {
|
|
11180
|
+
window.alert("No stale worktree records to prune.");
|
|
11181
|
+
return;
|
|
11182
|
+
}
|
|
11183
|
+
const lines = prunable.map((item) => `${item.path}${item.reason ? ` (${item.reason})` : ""}`).join("\n");
|
|
11184
|
+
runGitToolAction("worktrees", {
|
|
11185
|
+
url: "/api/git-worktrees/prune",
|
|
11186
|
+
body: { confirmed: true },
|
|
11187
|
+
confirm: `Prune stale worktree records?\n\nDry run:\n${output || lines || "(no output)"}\n\nThis removes administrative records for worktree directories that no longer exist.`,
|
|
11188
|
+
success: "Pruned stale worktree records.",
|
|
11189
|
+
});
|
|
11190
|
+
} catch (error) {
|
|
11191
|
+
gitToolsState.notice.worktrees = error.message || String(error);
|
|
11192
|
+
renderGitChangesDialog();
|
|
11193
|
+
}
|
|
11194
|
+
}));
|
|
11195
|
+
body.append(row);
|
|
11196
|
+
return body;
|
|
11197
|
+
}
|
|
11198
|
+
|
|
11199
|
+
function renderGitSubmoduleTools(body, data, busy) {
|
|
11200
|
+
if (!data.hasSubmodules) {
|
|
11201
|
+
body.append(make("div", "git-changes-empty", "This repository has no submodules."));
|
|
11202
|
+
return body;
|
|
11203
|
+
}
|
|
11204
|
+
for (const submodule of data.submodules || []) {
|
|
11205
|
+
const item = make("div", "git-tools-row");
|
|
11206
|
+
item.append(
|
|
11207
|
+
make("span", "git-tools-item-ref", submodule.state),
|
|
11208
|
+
make("span", "git-tools-item-subject", `${submodule.path} · ${String(submodule.sha || "").slice(0, 10)}${submodule.describe ? ` · ${submodule.describe}` : ""}`),
|
|
11209
|
+
);
|
|
11210
|
+
const actions = gitFileActionButtons([
|
|
11211
|
+
{
|
|
11212
|
+
label: "Open tab",
|
|
11213
|
+
title: "Open a Web UI tab rooted at this submodule",
|
|
11214
|
+
onClick: () => {
|
|
11215
|
+
const root = String(data.root || "").replace(/\/+$/, "");
|
|
11216
|
+
closeGitChangesDialog();
|
|
11217
|
+
createTerminalTab(`${root}/${submodule.path}`).catch((error) => addEvent(error.message || String(error), "error"));
|
|
11218
|
+
},
|
|
11219
|
+
},
|
|
11220
|
+
{ label: "Copy path", title: "Copy the submodule path", onClick: () => copyGitPathToClipboard(submodule.path) },
|
|
11221
|
+
]);
|
|
11222
|
+
if (actions) item.append(actions);
|
|
11223
|
+
body.append(item);
|
|
11224
|
+
}
|
|
11225
|
+
const row = make("div", "git-operation-actions");
|
|
11226
|
+
row.append(gitToolsButton("Update / init recursively…", { disabled: busy, title: "git submodule update --init --recursive" }, () =>
|
|
11227
|
+
runGitToolAction("submodules", {
|
|
11228
|
+
url: "/api/git-submodules/update",
|
|
11229
|
+
body: { confirmed: true },
|
|
11230
|
+
confirm: "Run git submodule update --init --recursive?\n\nThis can check out new commits in every submodule and may take a while.",
|
|
11231
|
+
success: "Updated submodules recursively.",
|
|
11232
|
+
refreshChanges: true,
|
|
11233
|
+
})));
|
|
11234
|
+
body.append(row);
|
|
11235
|
+
return body;
|
|
11236
|
+
}
|
|
11237
|
+
|
|
11238
|
+
function renderGitTagTools(body, data, busy) {
|
|
11239
|
+
const tags = data.tags || [];
|
|
11240
|
+
if (!tags.length) body.append(make("div", "git-changes-empty", "No tags."));
|
|
11241
|
+
for (const tag of tags.slice(0, 15)) {
|
|
11242
|
+
const item = make("div", "git-tools-row");
|
|
11243
|
+
item.append(
|
|
11244
|
+
make("span", "git-tools-item-ref", tag.name),
|
|
11245
|
+
make("span", "git-tools-item-subject", [tag.annotated ? "annotated" : "lightweight", tag.target ? `@ ${tag.target}` : "", tag.atHead ? "at HEAD" : "", tag.date || ""].filter(Boolean).join(" · ")),
|
|
11246
|
+
);
|
|
11247
|
+
body.append(item);
|
|
11248
|
+
}
|
|
11249
|
+
const row = make("div", "git-operation-actions");
|
|
11250
|
+
row.append(gitToolsButton("Create annotated tag…", { disabled: busy, title: "git tag -a <name> -m <message> (never pushed automatically)" }, () => {
|
|
11251
|
+
const name = window.prompt("Tag name (annotated tag at HEAD):", "");
|
|
11252
|
+
if (!name || !name.trim()) return;
|
|
11253
|
+
const message = window.prompt("Tag message:", name.trim());
|
|
11254
|
+
if (message === null) return;
|
|
11255
|
+
runGitToolAction("tags", {
|
|
11256
|
+
url: "/api/git-tags/create",
|
|
11257
|
+
body: { confirmed: true, name: name.trim(), message: (message || name).trim() },
|
|
11258
|
+
confirm: `Create annotated tag ${name.trim()} at HEAD?\n\nTags are not pushed automatically; push explicitly with: git push origin ${name.trim()}`,
|
|
11259
|
+
success: `Created tag ${name.trim()}.`,
|
|
11260
|
+
});
|
|
11261
|
+
}));
|
|
11262
|
+
body.append(row);
|
|
11263
|
+
return body;
|
|
11264
|
+
}
|
|
11265
|
+
|
|
11266
|
+
function renderGitSigningTools(body, data) {
|
|
11267
|
+
body.append(make("div", "git-tools-note", `commit.gpgsign: ${data.commitSignRequired ? "true" : "false"} · gpg.format: ${data.gpgFormat} · user.signingkey: ${data.signingKey}`));
|
|
11268
|
+
if (data.lastCommit) body.append(make("div", "git-tools-note", `Last commit ${data.lastCommit.hash}: signature state ${data.lastCommit.signState}${data.lastCommit.signer ? ` (${data.lastCommit.signer})` : ""}`));
|
|
11269
|
+
body.append(make("div", `git-tools-note${data.mismatch ? " error" : ""}`, data.mismatch ? "Signing mismatch: signing is required but the last commit is not validly signed." : "No signing mismatch detected."));
|
|
11270
|
+
for (const suggestion of data.suggestions || []) {
|
|
11271
|
+
const item = make("div", "git-tools-row");
|
|
11272
|
+
item.append(make("span", "git-tools-item-subject", suggestion.label), make("code", "git-tools-command", suggestion.command));
|
|
11273
|
+
const actions = gitFileActionButtons([
|
|
11274
|
+
{ label: "Copy", title: "Copy this command", onClick: () => navigator.clipboard?.writeText(suggestion.command).catch(() => {}) },
|
|
11275
|
+
]);
|
|
11276
|
+
if (actions) item.append(actions);
|
|
11277
|
+
body.append(item);
|
|
11278
|
+
}
|
|
11279
|
+
body.append(make("div", "git-tools-note", "Commands are copyable only; config is never rewritten automatically."));
|
|
11280
|
+
return body;
|
|
11281
|
+
}
|
|
11282
|
+
|
|
11283
|
+
function renderGitToolsSectionBody(key) {
|
|
11284
|
+
const body = make("div", "git-tools-body");
|
|
11285
|
+
const notice = gitToolsState.notice[key];
|
|
11286
|
+
if (notice) body.append(make("div", "git-changes-empty error", notice));
|
|
11287
|
+
const data = gitToolsState.cache[key];
|
|
11288
|
+
const busy = gitToolsState.busy.has(key) || gitToolsState.busy.has(`load:${key}`);
|
|
11289
|
+
if (!data) {
|
|
11290
|
+
if (!notice) body.append(make("div", "git-changes-empty", "Loading…"));
|
|
11291
|
+
return body;
|
|
11292
|
+
}
|
|
11293
|
+
switch (key) {
|
|
11294
|
+
case "stash":
|
|
11295
|
+
return renderGitStashTools(body, data, busy);
|
|
11296
|
+
case "undo":
|
|
11297
|
+
return renderGitUndoTools(body, data, busy);
|
|
11298
|
+
case "worktrees":
|
|
11299
|
+
return renderGitWorktreeTools(body, data, busy);
|
|
11300
|
+
case "submodules":
|
|
11301
|
+
return renderGitSubmoduleTools(body, data, busy);
|
|
11302
|
+
case "tags":
|
|
11303
|
+
return renderGitTagTools(body, data, busy);
|
|
11304
|
+
case "signing":
|
|
11305
|
+
return renderGitSigningTools(body, data);
|
|
11306
|
+
default:
|
|
11307
|
+
return body;
|
|
11308
|
+
}
|
|
11309
|
+
}
|
|
11310
|
+
|
|
11311
|
+
function renderGitToolsSection() {
|
|
11312
|
+
const wrapper = make("section", "git-tools");
|
|
11313
|
+
wrapper.append(make("div", "git-diff-section-heading git-tools-heading", "Git tools"));
|
|
11314
|
+
for (const section of GIT_TOOLS_SECTIONS) {
|
|
11315
|
+
const details = make("details", "git-tools-section");
|
|
11316
|
+
details.dataset.gitTools = section.key;
|
|
11317
|
+
details.open = gitToolsState.openSections.has(section.key);
|
|
11318
|
+
const summary = make("summary", "git-tools-summary");
|
|
11319
|
+
summary.append(make("span", "git-tools-title", section.title), make("span", "git-tools-detail", section.detail));
|
|
11320
|
+
details.append(summary);
|
|
11321
|
+
if (details.open) details.append(renderGitToolsSectionBody(section.key));
|
|
11322
|
+
details.addEventListener("toggle", () => {
|
|
11323
|
+
if (details.open) {
|
|
11324
|
+
if (gitToolsState.openSections.has(section.key)) return;
|
|
11325
|
+
gitToolsState.openSections.add(section.key);
|
|
11326
|
+
loadGitToolsSection(section.key);
|
|
11327
|
+
renderGitChangesDialog();
|
|
11328
|
+
} else {
|
|
11329
|
+
gitToolsState.openSections.delete(section.key);
|
|
11330
|
+
}
|
|
11331
|
+
});
|
|
11332
|
+
wrapper.append(details);
|
|
11333
|
+
}
|
|
11334
|
+
return wrapper;
|
|
11335
|
+
}
|
|
11336
|
+
|
|
11337
|
+
// Route the git+ chip to the tools section matching its leading indicator
|
|
11338
|
+
// (📦 stash, 🧩 submodules, 🔓 signing, 🏷 tag, 🌳 worktrees).
|
|
11339
|
+
function gitToolsSectionForExtraChip(value = "") {
|
|
11340
|
+
const text = String(value || "");
|
|
11341
|
+
if (text.includes("📦")) return "stash";
|
|
11342
|
+
if (text.includes("🧩")) return "submodules";
|
|
11343
|
+
if (text.includes("🔓")) return "signing";
|
|
11344
|
+
if (text.includes("🏷")) return "tags";
|
|
11345
|
+
if (text.includes("🌳")) return "worktrees";
|
|
11346
|
+
return "stash";
|
|
11347
|
+
}
|
|
11348
|
+
|
|
11349
|
+
function openGitToolsFromFooter(section = "stash") {
|
|
11350
|
+
openGitChangesDialog();
|
|
11351
|
+
gitToolsState.openSections.add(section);
|
|
11352
|
+
loadGitToolsSection(section);
|
|
11353
|
+
renderGitChangesDialog();
|
|
11354
|
+
}
|
|
11355
|
+
|
|
8707
11356
|
function gitFooterFallbackMessage() {
|
|
8708
11357
|
if (isOptionalFeatureDisabled("gitFooterStatus")) return "";
|
|
8709
11358
|
const tabContext = activeTabContext();
|
|
@@ -9166,6 +11815,7 @@ function applyOptimisticGitFooterBranch(branch, tabContext = activeTabContext())
|
|
|
9166
11815
|
generatedAt: Date.now(),
|
|
9167
11816
|
main: payload.main,
|
|
9168
11817
|
meta: payload.meta.map((chip) => chip.key === "git" ? { ...chip, value: nextBranch, title: `git branch: ${nextBranch}` } : chip),
|
|
11818
|
+
visibility: payload.visibility,
|
|
9169
11819
|
};
|
|
9170
11820
|
const nextRaw = JSON.stringify(nextPayload);
|
|
9171
11821
|
statusEntries.set(GIT_FOOTER_WEBUI_STATUS_KEY, nextRaw);
|
|
@@ -9264,15 +11914,33 @@ function footerBranchAgentWarningLines(tabContext = activeTabContext()) {
|
|
|
9264
11914
|
];
|
|
9265
11915
|
}
|
|
9266
11916
|
|
|
11917
|
+
function footerBranchDirtySummaryLines() {
|
|
11918
|
+
const changesChip = parseGitFooterWebuiPayload()?.meta?.find((chip) => chip.key === "changes");
|
|
11919
|
+
const files = Array.isArray(changesChip?.files) ? changesChip.files : [];
|
|
11920
|
+
if (!files.length) return [];
|
|
11921
|
+
const counts = {};
|
|
11922
|
+
for (const file of files) counts[file.kind] = (counts[file.kind] || 0) + 1;
|
|
11923
|
+
const parts = FOOTER_CHANGED_FILE_KIND_ORDER
|
|
11924
|
+
.filter((kind) => counts[kind])
|
|
11925
|
+
.map((kind) => `${counts[kind]} ${FOOTER_CHANGED_FILE_KIND_LABELS[kind]?.toLowerCase() || kind}`);
|
|
11926
|
+
const total = changesChip?.filesTruncated && changesChip?.filesTotal ? changesChip.filesTotal : files.length;
|
|
11927
|
+
return [
|
|
11928
|
+
`Dirty working tree: ${total} changed file${total === 1 ? "" : "s"} (${parts.join(", ")}).`,
|
|
11929
|
+
"Switching branches carries these changes along; consider a worktree instead.",
|
|
11930
|
+
];
|
|
11931
|
+
}
|
|
11932
|
+
|
|
9267
11933
|
function confirmFooterGitBranchAction(branch, { create = false, requireConfirm = false, tabContext = activeTabContext() } = {}) {
|
|
9268
11934
|
const branchName = cleanStatusText(branch);
|
|
9269
11935
|
const warningLines = footerBranchAgentWarningLines(tabContext);
|
|
9270
|
-
|
|
11936
|
+
const dirtyLines = footerBranchDirtySummaryLines();
|
|
11937
|
+
if (!requireConfirm && warningLines.length === 0 && dirtyLines.length === 0) return true;
|
|
9271
11938
|
const action = create ? "Create and switch to new git branch" : "Switch git branch";
|
|
9272
11939
|
const message = [
|
|
9273
11940
|
`${action}: ${branchName}?`,
|
|
9274
11941
|
"",
|
|
9275
11942
|
`Repository: ${footerBranchPickerState.root || currentGitFooterCacheCwd(tabContext.tabId) || "current tab"}`,
|
|
11943
|
+
...dirtyLines,
|
|
9276
11944
|
...warningLines,
|
|
9277
11945
|
"",
|
|
9278
11946
|
"Continue?",
|
|
@@ -9659,23 +12327,91 @@ function renderFooterBranchOption(branch, state = footerBranchPickerState) {
|
|
|
9659
12327
|
return row;
|
|
9660
12328
|
}
|
|
9661
12329
|
|
|
12330
|
+
async function removeFooterGitWorktree(worktree, tabContext = activeTabContext()) {
|
|
12331
|
+
const tabId = tabContext.tabId || activeTabId;
|
|
12332
|
+
if (!window.confirm([
|
|
12333
|
+
`Remove worktree ${worktree.path}?`,
|
|
12334
|
+
"",
|
|
12335
|
+
`Branch: ${worktree.branch || "detached"}`,
|
|
12336
|
+
"Command: git worktree remove",
|
|
12337
|
+
"This deletes the checkout directory. Dirty worktrees and worktrees with open tabs are refused.",
|
|
12338
|
+
].join("\n"))) return;
|
|
12339
|
+
footerBranchPickerState = { ...footerBranchPickerState, loading: true, error: "" };
|
|
12340
|
+
renderFooter();
|
|
12341
|
+
try {
|
|
12342
|
+
const response = await api("/api/git-worktrees", { method: "DELETE", body: { path: worktree.path, confirmed: true }, tabId });
|
|
12343
|
+
if (!response.ok) throw new Error(response.error || "Failed to remove the worktree");
|
|
12344
|
+
addEvent(`Removed worktree ${worktree.path}.`, "success");
|
|
12345
|
+
} catch (error) {
|
|
12346
|
+
addEvent(error.message || String(error), "error");
|
|
12347
|
+
}
|
|
12348
|
+
await loadFooterBranchPicker(tabContext).catch(() => {});
|
|
12349
|
+
}
|
|
12350
|
+
|
|
12351
|
+
async function pruneFooterGitWorktrees(tabContext = activeTabContext()) {
|
|
12352
|
+
const tabId = tabContext.tabId || activeTabId;
|
|
12353
|
+
try {
|
|
12354
|
+
const preview = await api("/api/git-worktrees/prune", { tabId });
|
|
12355
|
+
const previewData = preview?.data || {};
|
|
12356
|
+
const prunable = previewData.prunable || [];
|
|
12357
|
+
const output = String(previewData.output || "").trim();
|
|
12358
|
+
if (!prunable.length && !output) {
|
|
12359
|
+
addEvent("No stale worktree records to prune.", "info");
|
|
12360
|
+
return;
|
|
12361
|
+
}
|
|
12362
|
+
const lines = prunable.map((item) => `${item.path}${item.reason ? ` (${item.reason})` : ""}`).join("\n");
|
|
12363
|
+
if (!window.confirm(`Prune stale worktree records?\n\nDry run:\n${output || lines || "(no output)"}\n\nThis removes administrative records for worktree directories that no longer exist.`)) return;
|
|
12364
|
+
const response = await api("/api/git-worktrees/prune", { method: "POST", body: { confirmed: true }, tabId });
|
|
12365
|
+
if (!response.ok) throw new Error(response.error || "Failed to prune worktrees");
|
|
12366
|
+
addEvent("Pruned stale worktree records.", "success");
|
|
12367
|
+
} catch (error) {
|
|
12368
|
+
addEvent(error.message || String(error), "error");
|
|
12369
|
+
}
|
|
12370
|
+
await loadFooterBranchPicker(tabContext).catch(() => {});
|
|
12371
|
+
}
|
|
12372
|
+
|
|
9662
12373
|
function renderFooterWorktreeList(state = footerBranchPickerState) {
|
|
9663
|
-
const
|
|
9664
|
-
|
|
12374
|
+
const allWorktrees = (state.worktrees || []).filter((item) => item.path);
|
|
12375
|
+
const worktrees = allWorktrees.filter((item) => !item.prunable);
|
|
12376
|
+
const prunableCount = allWorktrees.length - worktrees.length;
|
|
12377
|
+
if (worktrees.length <= 1 && prunableCount === 0) return null;
|
|
12378
|
+
const busy = state.loading || !!state.switching;
|
|
9665
12379
|
const section = make("div", "footer-branch-worktree-section");
|
|
9666
12380
|
section.append(make("div", "footer-branch-section-title", `Open worktrees (${worktrees.length})`));
|
|
9667
12381
|
for (const worktree of worktrees.slice(0, 8)) {
|
|
9668
12382
|
const selected = worktree.current || worktree.path === state.currentWorktreePath;
|
|
12383
|
+
const row = make("div", "footer-branch-option-row");
|
|
9669
12384
|
const button = make("button", `footer-model-option footer-worktree-option${selected ? " active" : ""}`);
|
|
9670
12385
|
button.type = "button";
|
|
9671
|
-
button.disabled = selected ||
|
|
12386
|
+
button.disabled = selected || busy;
|
|
9672
12387
|
button.title = selected ? `Current worktree: ${worktree.path}` : `Open worktree: ${worktree.path}`;
|
|
12388
|
+
const health = [
|
|
12389
|
+
worktree.detached ? "detached" : "",
|
|
12390
|
+
worktree.locked ? `locked${worktree.lockedReason ? `: ${worktree.lockedReason}` : ""}` : "",
|
|
12391
|
+
].filter(Boolean).join(" · ");
|
|
9673
12392
|
button.append(
|
|
9674
12393
|
make("span", "footer-model-option-main", worktree.branch || "detached"),
|
|
9675
|
-
make("span", "footer-model-option-name", `${selected ? "current" : "open"} · ${normalizeDisplayPath(worktree.path)}`),
|
|
12394
|
+
make("span", "footer-model-option-name", `${selected ? "current" : "open"}${health ? ` · ${health}` : ""} · ${normalizeDisplayPath(worktree.path)}`),
|
|
9676
12395
|
);
|
|
9677
12396
|
if (!button.disabled) button.addEventListener("click", () => openFooterGitWorktree(worktree.path, { branchName: worktree.branch || "", skipConfirm: true }));
|
|
9678
|
-
|
|
12397
|
+
row.append(button);
|
|
12398
|
+
if (!selected && !worktree.isMainWorktree) {
|
|
12399
|
+
const remove = make("button", "footer-branch-advanced-action footer-worktree-remove", "Remove");
|
|
12400
|
+
remove.type = "button";
|
|
12401
|
+
remove.disabled = busy || worktree.locked;
|
|
12402
|
+
remove.title = worktree.locked ? `Worktree is locked${worktree.lockedReason ? `: ${worktree.lockedReason}` : ""}` : `git worktree remove ${worktree.path}`;
|
|
12403
|
+
remove.addEventListener("click", () => removeFooterGitWorktree(worktree));
|
|
12404
|
+
row.append(remove);
|
|
12405
|
+
}
|
|
12406
|
+
section.append(row);
|
|
12407
|
+
}
|
|
12408
|
+
if (prunableCount > 0) {
|
|
12409
|
+
const prune = make("button", "footer-branch-advanced-action footer-worktree-prune", `Prune ${prunableCount} stale worktree record${prunableCount === 1 ? "" : "s"}…`);
|
|
12410
|
+
prune.type = "button";
|
|
12411
|
+
prune.disabled = busy;
|
|
12412
|
+
prune.title = "git worktree prune (with dry-run preview)";
|
|
12413
|
+
prune.addEventListener("click", () => pruneFooterGitWorktrees());
|
|
12414
|
+
section.append(prune);
|
|
9679
12415
|
}
|
|
9680
12416
|
return section;
|
|
9681
12417
|
}
|
|
@@ -16248,13 +18984,33 @@ function assistantThinkingText(part) {
|
|
|
16248
18984
|
return typeof part.content === "string" ? part.content : "";
|
|
16249
18985
|
}
|
|
16250
18986
|
|
|
18987
|
+
function stripEmptyHtmlComments(text) {
|
|
18988
|
+
return String(text || "")
|
|
18989
|
+
.replace(/^[^\S\n]*<!--[\s\r\n]*-->[^\S\n]*(?:\n|$)/gm, "")
|
|
18990
|
+
.replace(/<!--[\s\r\n]*-->/g, "")
|
|
18991
|
+
.replace(/\n[^\S\n]*(?:\n[^\S\n]*){2,}/g, "\n\n");
|
|
18992
|
+
}
|
|
18993
|
+
|
|
16251
18994
|
function visibleThinkingText(text) {
|
|
16252
|
-
const value =
|
|
18995
|
+
const value = stripEmptyHtmlComments(text);
|
|
16253
18996
|
const trimmed = value.trim();
|
|
16254
18997
|
if (!trimmed || trimmed === UNEXPOSED_THINKING_TEXT) return "";
|
|
16255
18998
|
return value;
|
|
16256
18999
|
}
|
|
16257
19000
|
|
|
19001
|
+
function renderThinkingMarkdown(block, text) {
|
|
19002
|
+
if (!block) return;
|
|
19003
|
+
block._rawThinkingText = String(text || "");
|
|
19004
|
+
renderMarkdown(block, block._rawThinkingText);
|
|
19005
|
+
}
|
|
19006
|
+
|
|
19007
|
+
function appendThinkingMarkdown(parent, text) {
|
|
19008
|
+
const block = appendMarkdown(parent, text);
|
|
19009
|
+
block.classList.add("thinking-text");
|
|
19010
|
+
block._rawThinkingText = String(text || "");
|
|
19011
|
+
return block;
|
|
19012
|
+
}
|
|
19013
|
+
|
|
16258
19014
|
function escapeRegExp(value) {
|
|
16259
19015
|
return String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
16260
19016
|
}
|
|
@@ -17410,7 +20166,7 @@ function appendMessage(message, { streaming = false, messageIndex = -1, transien
|
|
|
17410
20166
|
bubble._toolRenderSignature = toolExecutionRenderSignature(message);
|
|
17411
20167
|
} else if (message.role === "thinking") {
|
|
17412
20168
|
const thinkingText = visibleThinkingText(message.thinking || textFromContent(message.content));
|
|
17413
|
-
if (thinkingOutputVisible && thinkingText)
|
|
20169
|
+
if (thinkingOutputVisible && thinkingText) appendThinkingMarkdown(body, thinkingText);
|
|
17414
20170
|
} else if (message.role === "toolCall") {
|
|
17415
20171
|
renderToolCallMessageBody(body, message);
|
|
17416
20172
|
} else if (message.role === "assistantEvent") {
|
|
@@ -18436,7 +21192,7 @@ function updateOptionalFeatureAvailability() {
|
|
|
18436
21192
|
optionalFeatureAvailability.workflows = hasAvailableCommand("workflow") || hasAvailableCommand("workflow-clear") || optionalFeatureAvailability.workflows || widgets.has("workflow") || widgets.has("workflow:subprocess");
|
|
18437
21193
|
optionalFeatureAvailability.safetyGuard = hasAvailableCommand("safety-guard") || optionalFeatureAvailability.safetyGuard || statusEntries.has("safety-guard");
|
|
18438
21194
|
optionalFeatureAvailability.statsCommand = hasAvailableCommand("stats");
|
|
18439
|
-
optionalFeatureAvailability.gitFooterStatus = hasAvailableCommand("git-footer-refresh") || optionalFeatureAvailability.gitFooterStatus || statusEntries.has("git-footer") || statusEntries.has(GIT_FOOTER_WEBUI_STATUS_KEY);
|
|
21195
|
+
optionalFeatureAvailability.gitFooterStatus = hasAvailableCommand("git-footer-refresh") || hasAvailableCommand("git-footer-visibility") || optionalFeatureAvailability.gitFooterStatus || statusEntries.has("git-footer") || statusEntries.has(GIT_FOOTER_WEBUI_STATUS_KEY);
|
|
18440
21196
|
optionalFeatureAvailability.tuiSkillsCommand = hasLoadedRpcCommand("skills");
|
|
18441
21197
|
optionalFeatureAvailability.todoProgressWidget = hasAvailableCommand("todo-progress-status") || optionalFeatureAvailability.todoProgressWidget || widgets.has("todo-progress");
|
|
18442
21198
|
optionalFeatureAvailability.tuiToolsCommand = hasLoadedRpcCommand("tools");
|
|
@@ -18530,81 +21286,118 @@ function renderOptionalFeaturePanel() {
|
|
|
18530
21286
|
elements.optionalFeaturesBox.append(notice);
|
|
18531
21287
|
}
|
|
18532
21288
|
|
|
18533
|
-
|
|
18534
|
-
|
|
18535
|
-
const
|
|
18536
|
-
|
|
18537
|
-
|
|
18538
|
-
|
|
18539
|
-
const
|
|
18540
|
-
|
|
18541
|
-
|
|
18542
|
-
|
|
18543
|
-
|
|
18544
|
-
|
|
18545
|
-
|
|
18546
|
-
|
|
18547
|
-
|
|
18548
|
-
|
|
18549
|
-
|
|
18550
|
-
|
|
18551
|
-
|
|
18552
|
-
|
|
18553
|
-
|
|
18554
|
-
|
|
18555
|
-
|
|
18556
|
-
if (installing) {
|
|
18557
|
-
const progress = make("div", "optional-feature-progress");
|
|
18558
|
-
progress.setAttribute("aria-hidden", "true");
|
|
18559
|
-
progress.append(make("span"));
|
|
18560
|
-
main.append(progress);
|
|
18561
|
-
}
|
|
18562
|
-
if (status.hint) main.append(make("div", "optional-feature-hint", status.hint));
|
|
18563
|
-
if (status.command) {
|
|
18564
|
-
const command = make("div", "optional-feature-command");
|
|
18565
|
-
command.append(make("code", undefined, status.command));
|
|
18566
|
-
main.append(command);
|
|
18567
|
-
}
|
|
18568
|
-
if (failed && installState?.outputTail) main.append(make("pre", "optional-feature-error-output", installState.outputTail));
|
|
18569
|
-
|
|
18570
|
-
const actions = make("div", "optional-feature-actions");
|
|
18571
|
-
const action = make("button", "optional-feature-action");
|
|
18572
|
-
action.type = "button";
|
|
18573
|
-
action.disabled = installing;
|
|
18574
|
-
if (installing) {
|
|
18575
|
-
action.textContent = installState?.actionLabel === "Update" ? "Updating…" : "Installing…";
|
|
18576
|
-
action.setAttribute("aria-busy", "true");
|
|
18577
|
-
} else if (failed) {
|
|
18578
|
-
const retryAsUpdate = installState?.actionLabel === "Update" || packageStatus?.updateAvailable;
|
|
18579
|
-
action.textContent = "Retry…";
|
|
18580
|
-
action.classList.add(retryAsUpdate ? "update" : "install");
|
|
18581
|
-
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: retryAsUpdate }));
|
|
18582
|
-
} else if (packageStatus?.updateAvailable) {
|
|
18583
|
-
action.textContent = "Update…";
|
|
18584
|
-
action.classList.add("update");
|
|
18585
|
-
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: true }));
|
|
18586
|
-
} else if (detected) {
|
|
18587
|
-
action.textContent = enabled ? "Disable" : "Enable";
|
|
18588
|
-
action.addEventListener("click", () => setOptionalFeatureDisabled(feature.id, enabled));
|
|
18589
|
-
} else if (packageStatus?.installed) {
|
|
18590
|
-
action.textContent = "Reload";
|
|
18591
|
-
action.addEventListener("click", () => sendPrompt("prompt", "/reload"));
|
|
18592
|
-
} else {
|
|
18593
|
-
action.textContent = "Install…";
|
|
18594
|
-
action.classList.add("install");
|
|
18595
|
-
action.addEventListener("click", () => installOptionalFeature(feature.id));
|
|
18596
|
-
}
|
|
18597
|
-
actions.append(action);
|
|
18598
|
-
if (status.command) {
|
|
18599
|
-
const copyCommand = make("button", "optional-feature-action copy-command", "Copy cmd");
|
|
18600
|
-
copyCommand.type = "button";
|
|
18601
|
-
copyCommand.addEventListener("click", () => copyOptionalFeatureInstallCommand(feature.id));
|
|
18602
|
-
actions.append(copyCommand);
|
|
18603
|
-
}
|
|
21289
|
+
const renderedFeatureIds = new Set();
|
|
21290
|
+
for (const section of OPTIONAL_FEATURE_SECTIONS) {
|
|
21291
|
+
const sectionFeatures = section.featureIds
|
|
21292
|
+
.map((featureId) => OPTIONAL_FEATURE_BY_ID.get(featureId))
|
|
21293
|
+
.filter(Boolean);
|
|
21294
|
+
if (!sectionFeatures.length) continue;
|
|
21295
|
+
for (const feature of sectionFeatures) renderedFeatureIds.add(feature.id);
|
|
21296
|
+
renderOptionalFeatureSection(section, sectionFeatures);
|
|
21297
|
+
}
|
|
21298
|
+
|
|
21299
|
+
const uncategorizedFeatures = OPTIONAL_FEATURES.filter((feature) => !renderedFeatureIds.has(feature.id));
|
|
21300
|
+
if (uncategorizedFeatures.length) {
|
|
21301
|
+
renderOptionalFeatureSection({
|
|
21302
|
+
id: "other",
|
|
21303
|
+
label: "Other",
|
|
21304
|
+
description: "Optional companions that have not been assigned to a type section yet.",
|
|
21305
|
+
}, uncategorizedFeatures);
|
|
21306
|
+
}
|
|
21307
|
+
}
|
|
21308
|
+
|
|
21309
|
+
function renderOptionalFeatureSection(section, features) {
|
|
21310
|
+
const sectionNode = make("section", "optional-feature-section");
|
|
21311
|
+
sectionNode.dataset.optionalFeatureSection = section.id;
|
|
18604
21312
|
|
|
18605
|
-
|
|
18606
|
-
|
|
21313
|
+
const header = make("div", "optional-feature-section-header");
|
|
21314
|
+
header.append(
|
|
21315
|
+
make("div", "optional-feature-section-title", section.label),
|
|
21316
|
+
make("span", "optional-feature-section-count", String(features.length)),
|
|
21317
|
+
);
|
|
21318
|
+
sectionNode.append(header);
|
|
21319
|
+
if (section.description) sectionNode.append(make("div", "optional-feature-section-description", section.description));
|
|
21320
|
+
|
|
21321
|
+
const list = make("div", "optional-feature-section-list");
|
|
21322
|
+
for (const feature of features) list.append(renderOptionalFeatureRow(feature));
|
|
21323
|
+
sectionNode.append(list);
|
|
21324
|
+
elements.optionalFeaturesBox.append(sectionNode);
|
|
21325
|
+
}
|
|
21326
|
+
|
|
21327
|
+
function renderOptionalFeatureRow(feature) {
|
|
21328
|
+
const detected = isOptionalFeatureDetected(feature.id);
|
|
21329
|
+
const enabled = isOptionalFeatureEnabled(feature.id);
|
|
21330
|
+
const installState = optionalFeatureInstallState(feature.id);
|
|
21331
|
+
const installing = optionalFeatureInstallInProgress.has(feature.id) || optionalFeatureInstallIsActive(installState);
|
|
21332
|
+
const failed = installState?.phase === "failed";
|
|
21333
|
+
const packageStatus = optionalFeaturePackageStatus(feature.id);
|
|
21334
|
+
const status = optionalFeatureStatus(feature.id);
|
|
21335
|
+
const row = make("div", `optional-feature-row ${status.className}`);
|
|
21336
|
+
const tooltip = optionalFeatureTooltip(feature, status);
|
|
21337
|
+
row.dataset.tooltip = tooltip;
|
|
21338
|
+
row.setAttribute("aria-label", tooltip.replace(/\s+/g, " "));
|
|
21339
|
+
row.tabIndex = 0;
|
|
21340
|
+
|
|
21341
|
+
const main = make("div", "optional-feature-main");
|
|
21342
|
+
const title = make("div", "optional-feature-title");
|
|
21343
|
+
title.append(make("strong", undefined, feature.label), make("span", `optional-feature-pill ${status.className}`, status.label));
|
|
21344
|
+
main.append(title);
|
|
21345
|
+
if (status.detail) {
|
|
21346
|
+
const detail = make("div", `optional-feature-detail ${status.className === "failed" ? "error" : ""}`.trim(), status.detail);
|
|
21347
|
+
detail.setAttribute("aria-live", installing ? "polite" : "off");
|
|
21348
|
+
main.append(detail);
|
|
21349
|
+
}
|
|
21350
|
+
if (installing) {
|
|
21351
|
+
const progress = make("div", "optional-feature-progress");
|
|
21352
|
+
progress.setAttribute("aria-hidden", "true");
|
|
21353
|
+
progress.append(make("span"));
|
|
21354
|
+
main.append(progress);
|
|
21355
|
+
}
|
|
21356
|
+
if (status.hint) main.append(make("div", "optional-feature-hint", status.hint));
|
|
21357
|
+
if (status.command) {
|
|
21358
|
+
const command = make("div", "optional-feature-command");
|
|
21359
|
+
command.append(make("code", undefined, status.command));
|
|
21360
|
+
main.append(command);
|
|
21361
|
+
}
|
|
21362
|
+
if (failed && installState?.outputTail) main.append(make("pre", "optional-feature-error-output", installState.outputTail));
|
|
21363
|
+
|
|
21364
|
+
const actions = make("div", "optional-feature-actions");
|
|
21365
|
+
const action = make("button", "optional-feature-action");
|
|
21366
|
+
action.type = "button";
|
|
21367
|
+
action.disabled = installing;
|
|
21368
|
+
if (installing) {
|
|
21369
|
+
action.textContent = installState?.actionLabel === "Update" ? "Updating…" : "Installing…";
|
|
21370
|
+
action.setAttribute("aria-busy", "true");
|
|
21371
|
+
} else if (failed) {
|
|
21372
|
+
const retryAsUpdate = installState?.actionLabel === "Update" || packageStatus?.updateAvailable;
|
|
21373
|
+
action.textContent = "Retry…";
|
|
21374
|
+
action.classList.add(retryAsUpdate ? "update" : "install");
|
|
21375
|
+
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: retryAsUpdate }));
|
|
21376
|
+
} else if (packageStatus?.updateAvailable) {
|
|
21377
|
+
action.textContent = "Update…";
|
|
21378
|
+
action.classList.add("update");
|
|
21379
|
+
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: true }));
|
|
21380
|
+
} else if (detected) {
|
|
21381
|
+
action.textContent = enabled ? "Disable" : "Enable";
|
|
21382
|
+
action.addEventListener("click", () => setOptionalFeatureDisabled(feature.id, enabled));
|
|
21383
|
+
} else if (packageStatus?.installed) {
|
|
21384
|
+
action.textContent = "Reload";
|
|
21385
|
+
action.addEventListener("click", () => sendPrompt("prompt", "/reload"));
|
|
21386
|
+
} else {
|
|
21387
|
+
action.textContent = "Install…";
|
|
21388
|
+
action.classList.add("install");
|
|
21389
|
+
action.addEventListener("click", () => installOptionalFeature(feature.id));
|
|
21390
|
+
}
|
|
21391
|
+
actions.append(action);
|
|
21392
|
+
if (status.command) {
|
|
21393
|
+
const copyCommand = make("button", "optional-feature-action copy-command", "Copy cmd");
|
|
21394
|
+
copyCommand.type = "button";
|
|
21395
|
+
copyCommand.addEventListener("click", () => copyOptionalFeatureInstallCommand(feature.id));
|
|
21396
|
+
actions.append(copyCommand);
|
|
18607
21397
|
}
|
|
21398
|
+
|
|
21399
|
+
row.append(main, actions);
|
|
21400
|
+
return row;
|
|
18608
21401
|
}
|
|
18609
21402
|
|
|
18610
21403
|
function renderOptionalFeatureControls() {
|
|
@@ -18662,6 +21455,16 @@ function renderOptionalFeatureControls() {
|
|
|
18662
21455
|
);
|
|
18663
21456
|
}
|
|
18664
21457
|
|
|
21458
|
+
const hasGitFooterVisibility = isOptionalFeatureEnabled("gitFooterStatus") && gitFooterVisibilityCommandAvailable();
|
|
21459
|
+
if (elements.optionsFooterVisibilityButton) {
|
|
21460
|
+
elements.optionsFooterVisibilityButton.hidden = !hasGitFooterVisibility;
|
|
21461
|
+
setOptionalControlState(
|
|
21462
|
+
elements.optionsFooterVisibilityButton,
|
|
21463
|
+
hasGitFooterVisibility,
|
|
21464
|
+
commandUnavailableMessage("git-footer-visibility"),
|
|
21465
|
+
);
|
|
21466
|
+
}
|
|
21467
|
+
|
|
18665
21468
|
const hasNaturalConversation = isOptionalFeatureEnabled("naturalConversation") || activeConversationMode().enabled;
|
|
18666
21469
|
if (elements.optionsConversationModeButton) {
|
|
18667
21470
|
elements.optionsConversationModeButton.hidden = !hasNaturalConversation;
|
|
@@ -19191,7 +21994,7 @@ async function openNativeSettingsDialog() {
|
|
|
19191
21994
|
showImages: nativeSettingToggle("Show terminal images", settings.showImages !== false, "Native TUI inline image rendering preference.", { label: "TUI", tone: "tui" }),
|
|
19192
21995
|
imageWidth: nativeSettingSelect("Terminal image width", settings.imageWidthCells || 60, SETTINGS_IMAGE_WIDTH_OPTIONS, "Native TUI inline image width in terminal cells.", { label: "TUI", tone: "tui" }),
|
|
19193
21996
|
skillCommands: nativeSettingToggle("Skill commands", settings.enableSkillCommands !== false, "Register skills as /skill:name commands.", { label: "reload", tone: "reload" }),
|
|
19194
|
-
anthropicWarning: nativeSettingToggle("Anthropic
|
|
21997
|
+
anthropicWarning: nativeSettingToggle("Anthropic Agent SDK usage", settings.warnings?.anthropicExtraUsage !== false, "Native TUI setting for the suppressed Anthropic Agent SDK billing-path warning.", { label: "safety", tone: "safety" }),
|
|
19195
21998
|
collapseChangelog: nativeSettingToggle("Collapse changelog", settings.collapseChangelog === true, "Show condensed changelog after updates.", { label: "startup", tone: "startup" }),
|
|
19196
21999
|
quietStartup: nativeSettingToggle("Quiet startup", settings.quietStartup === true, "Disable verbose printing at startup.", { label: "startup", tone: "startup" }),
|
|
19197
22000
|
installTelemetry: nativeSettingToggle("Install telemetry", settings.enableInstallTelemetry !== false, "Send anonymous version/update ping after changelog-detected updates.", { label: "startup", tone: "startup" }),
|
|
@@ -19266,7 +22069,7 @@ async function openNativeForkSelector() {
|
|
|
19266
22069
|
setNativeCommandError("");
|
|
19267
22070
|
try {
|
|
19268
22071
|
const result = await nativeCommandApi("/api/fork", { method: "POST", body: { entryId: item.message.entryId } });
|
|
19269
|
-
|
|
22072
|
+
await switchToResponseTab(result);
|
|
19270
22073
|
const restoredText = result.data?.text || result.data?.result?.text || "";
|
|
19271
22074
|
if (restoredText) {
|
|
19272
22075
|
elements.promptInput.value = restoredText;
|
|
@@ -19275,7 +22078,6 @@ async function openNativeForkSelector() {
|
|
|
19275
22078
|
}
|
|
19276
22079
|
addTransientMessage({ role: "native", title: "/fork", content: result.data?.message || "Forked the current session.", level: "info" });
|
|
19277
22080
|
closeNativeCommandDialog();
|
|
19278
|
-
await refreshAll();
|
|
19279
22081
|
} catch (error) {
|
|
19280
22082
|
setNativeCommandError(error.message || String(error));
|
|
19281
22083
|
}
|
|
@@ -20001,7 +22803,8 @@ function ensureStreamingThinkingBubble() {
|
|
|
20001
22803
|
if (streamThinkingBubble?.parentElement === elements.chat) return true;
|
|
20002
22804
|
const created = appendMessage({ role: "thinking", title: "thinking", timestamp: Date.now(), content: "" }, { streaming: true });
|
|
20003
22805
|
streamThinkingBubble = created.bubble;
|
|
20004
|
-
streamThinking =
|
|
22806
|
+
streamThinking = make("div", "markdown-body thinking-text");
|
|
22807
|
+
created.body.append(streamThinking);
|
|
20005
22808
|
renderRunIndicator({ scroll: false });
|
|
20006
22809
|
scrollChatToBottom();
|
|
20007
22810
|
return true;
|
|
@@ -20009,7 +22812,7 @@ function ensureStreamingThinkingBubble() {
|
|
|
20009
22812
|
|
|
20010
22813
|
function showStreamingThinking(initialText = "") {
|
|
20011
22814
|
if (!ensureStreamingThinkingBubble()) return;
|
|
20012
|
-
if (initialText && !streamThinking.textContent) streamThinking
|
|
22815
|
+
if (initialText && !streamThinking.textContent) renderThinkingMarkdown(streamThinking, initialText);
|
|
20013
22816
|
}
|
|
20014
22817
|
|
|
20015
22818
|
function resetStreamBubble() {
|
|
@@ -20039,7 +22842,7 @@ function liveStreamRenderActive() {
|
|
|
20039
22842
|
* re-append the live thinking/text bubbles so no partial output is lost.
|
|
20040
22843
|
*/
|
|
20041
22844
|
function restoreStreamRenderAfterChatRebuild() {
|
|
20042
|
-
const thinkingText = streamThinking?.textContent || "";
|
|
22845
|
+
const thinkingText = streamThinking?._rawThinkingText || streamThinking?.textContent || "";
|
|
20043
22846
|
const thinkingComplete = streamThinkingBubble?.classList.contains("complete") === true;
|
|
20044
22847
|
const toolCallWasVisible = !!(streamToolCallBubble?.parentElement === elements.chat || streamToolCallRawArguments || streamToolCallName);
|
|
20045
22848
|
streamBubble = null;
|
|
@@ -20156,7 +22959,7 @@ function setStreamingThinkingText(text) {
|
|
|
20156
22959
|
const thinking = visibleThinkingText(text);
|
|
20157
22960
|
if (!thinkingOutputVisible || !thinking) return false;
|
|
20158
22961
|
showStreamingThinking("");
|
|
20159
|
-
if (streamThinking) streamThinking
|
|
22962
|
+
if (streamThinking) renderThinkingMarkdown(streamThinking, thinking);
|
|
20160
22963
|
return true;
|
|
20161
22964
|
}
|
|
20162
22965
|
|
|
@@ -20215,8 +23018,7 @@ function handleMessageUpdate(event) {
|
|
|
20215
23018
|
const synced = syncStreamingThinkingFromUpdate(event, update);
|
|
20216
23019
|
if (thinkingOutputVisible && delta && (!synced || !streamThinking?.textContent)) {
|
|
20217
23020
|
showStreamingThinking("");
|
|
20218
|
-
if (streamThinking
|
|
20219
|
-
if (streamThinking) streamThinking.textContent += delta;
|
|
23021
|
+
if (streamThinking) renderThinkingMarkdown(streamThinking, `${streamThinking._rawThinkingText || ""}${delta}`);
|
|
20220
23022
|
}
|
|
20221
23023
|
scheduleChatFollowScroll();
|
|
20222
23024
|
} else if (update.type === "thinking_end") {
|
|
@@ -21482,6 +24284,7 @@ async function refreshAll(tabContext = activeTabContext()) {
|
|
|
21482
24284
|
refreshNaturalConversationMode(tabContext),
|
|
21483
24285
|
refreshStats(tabContext),
|
|
21484
24286
|
refreshWorkspace(tabContext),
|
|
24287
|
+
refreshFileTreeRoot(tabContext),
|
|
21485
24288
|
refreshAppRunners(tabContext),
|
|
21486
24289
|
refreshNativeSettings(tabContext),
|
|
21487
24290
|
refreshNetworkStatus(),
|
|
@@ -22244,10 +25047,13 @@ function handleEvent(event) {
|
|
|
22244
25047
|
case "webui_cwd_changed":
|
|
22245
25048
|
addEvent(`${event.tabTitle || "terminal"} cwd changed to ${event.cwd}`);
|
|
22246
25049
|
setAppRunnerData(event.tabId || activeTabId, { cwd: event.cwd, activeRun: null, runners: [] });
|
|
25050
|
+
closeFileViewer();
|
|
25051
|
+
resetFileTreeState();
|
|
22247
25052
|
renderAppRunnerControls();
|
|
22248
25053
|
renderWidgets();
|
|
22249
25054
|
renderTabs();
|
|
22250
25055
|
refreshTabs().catch((error) => addEvent(error.message, "error"));
|
|
25056
|
+
refreshFileTreeRoot(tabContext).catch((error) => addEvent(error.message, "error"));
|
|
22251
25057
|
refreshAppRunners(tabContext).catch((error) => addEvent(error.message, "error"));
|
|
22252
25058
|
scheduleRefreshFooter();
|
|
22253
25059
|
break;
|
|
@@ -22801,6 +25607,17 @@ elements.optionsExportButton.addEventListener("click", () => runNativeCommandMen
|
|
|
22801
25607
|
elements.optionsForkButton.addEventListener("click", () => runNativeCommandMenu("/fork"));
|
|
22802
25608
|
elements.optionsTreeButton.addEventListener("click", () => runNativeCommandMenu("/tree"));
|
|
22803
25609
|
elements.optionsStatsButton?.addEventListener("click", () => openStatsOverlay({ refresh: true }));
|
|
25610
|
+
elements.optionsFooterVisibilityButton?.addEventListener("click", openGitFooterVisibilityDialog);
|
|
25611
|
+
elements.gitFooterVisibilitySelectAllButton?.addEventListener("click", () => setGitFooterVisibilitySelection(true));
|
|
25612
|
+
elements.gitFooterVisibilitySelectNoneButton?.addEventListener("click", () => setGitFooterVisibilitySelection(false));
|
|
25613
|
+
elements.gitFooterVisibilityCloseButton?.addEventListener("click", closeGitFooterVisibilityDialog);
|
|
25614
|
+
elements.gitFooterVisibilityResetButton?.addEventListener("click", () => resetGitFooterVisibilityDialog());
|
|
25615
|
+
elements.gitFooterVisibilityApplyButton?.addEventListener("click", () => applyGitFooterVisibilityDialog());
|
|
25616
|
+
elements.gitFooterVisibilityDialog?.querySelector("form")?.addEventListener("submit", (event) => event.preventDefault());
|
|
25617
|
+
elements.gitFooterVisibilityDialog?.addEventListener("close", () => {
|
|
25618
|
+
gitFooterVisibilityDirty = false;
|
|
25619
|
+
gitFooterVisibilityApplyInFlight = false;
|
|
25620
|
+
});
|
|
22804
25621
|
elements.statsOverlayRefreshButton?.addEventListener("click", () => requestStatsOverlayRefresh());
|
|
22805
25622
|
elements.statsOverlayScope?.addEventListener("change", () => {
|
|
22806
25623
|
const custom = elements.statsOverlayScope?.value === "custom";
|
|
@@ -23309,6 +26126,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
23309
26126
|
setFooterThinkingPickerOpen(false);
|
|
23310
26127
|
setFooterBranchPickerOpen(false);
|
|
23311
26128
|
}
|
|
26129
|
+
if (elements.fileContextMenu && !elements.fileContextMenu.hidden && !event.target?.closest?.(".file-context-menu")) {
|
|
26130
|
+
closeFileContextMenu();
|
|
26131
|
+
}
|
|
23312
26132
|
}, { passive: true });
|
|
23313
26133
|
document.addEventListener("pointermove", (event) => {
|
|
23314
26134
|
if (openTerminalTabGroupKey && !event.target?.closest?.(".terminal-tab-group")) {
|
|
@@ -23503,6 +26323,7 @@ window.addEventListener("online", () => scheduleForegroundReconcile("network onl
|
|
|
23503
26323
|
window.addEventListener("storage", (event) => {
|
|
23504
26324
|
if (event.key === OPTIONAL_FEATURES_STORAGE_KEY) reconcileDisabledOptionalFeaturesFromStorage();
|
|
23505
26325
|
});
|
|
26326
|
+
window.addEventListener("resize", syncFileViewerWidthForViewport, { passive: true });
|
|
23506
26327
|
window.addEventListener("keydown", (event) => {
|
|
23507
26328
|
if (event.key !== "Escape") return;
|
|
23508
26329
|
if (event.defaultPrevented) return;
|
|
@@ -23596,6 +26417,7 @@ window.addEventListener("blur", () => {
|
|
|
23596
26417
|
});
|
|
23597
26418
|
|
|
23598
26419
|
elements.gitChangesRefreshButton?.addEventListener("click", refreshGitChangesDialog);
|
|
26420
|
+
elements.gitChangesFetchButton?.addEventListener("click", () => fetchGitChangesDialog().catch((error) => addEvent(error.message || String(error), "error")));
|
|
23599
26421
|
elements.gitChangesPullButton?.addEventListener("click", () => pullGitChangesDialog().catch((error) => addEvent(error.message || String(error), "error")));
|
|
23600
26422
|
elements.gitChangesCloseButton?.addEventListener("click", closeGitChangesDialog);
|
|
23601
26423
|
elements.gitChangesBody?.addEventListener("scroll", updateGitChangesCurrentFileHeader, { passive: true });
|
|
@@ -23633,6 +26455,67 @@ elements.refreshCodexUsageButton?.addEventListener("click", () => {
|
|
|
23633
26455
|
elements.refreshClaudeUsageButton?.addEventListener("click", () => {
|
|
23634
26456
|
refreshClaudeUsage().finally(() => scheduleRefreshClaudeUsage());
|
|
23635
26457
|
});
|
|
26458
|
+
elements.fileTreeRefreshButton?.addEventListener("click", () => refreshFileTreeRoot().catch((error) => addEvent(error.message || String(error), "error")));
|
|
26459
|
+
elements.fileTreeRoot?.addEventListener("dragover", handleFileTreeRootDragOver);
|
|
26460
|
+
elements.fileTreeRoot?.addEventListener("dragleave", handleFileTreeRootDragLeave);
|
|
26461
|
+
elements.fileTreeRoot?.addEventListener("drop", (event) => handleFileTreeRootDrop(event).catch((error) => addEvent(error.message || String(error), "error")));
|
|
26462
|
+
elements.fileTreeSearchInput?.addEventListener("input", () => scheduleFileTreeSearch());
|
|
26463
|
+
elements.fileTreeSearchInput?.addEventListener("keydown", (event) => {
|
|
26464
|
+
if (event.key === "Enter") {
|
|
26465
|
+
event.preventDefault();
|
|
26466
|
+
runFileTreeSearch().catch((error) => addEvent(error.message || String(error), "error"));
|
|
26467
|
+
} else if (event.key === "Escape") {
|
|
26468
|
+
event.preventDefault();
|
|
26469
|
+
clearFileTreeSearch({ focus: true });
|
|
26470
|
+
}
|
|
26471
|
+
});
|
|
26472
|
+
elements.fileTreeSearchClearButton?.addEventListener("click", () => clearFileTreeSearch({ focus: true }));
|
|
26473
|
+
elements.fileContextMenu?.addEventListener("click", (event) => {
|
|
26474
|
+
const button = event.target?.closest?.("[data-file-menu-action]");
|
|
26475
|
+
if (!button) return;
|
|
26476
|
+
const entry = fileContextMenuState?.entry;
|
|
26477
|
+
closeFileContextMenu();
|
|
26478
|
+
if (!entry) return;
|
|
26479
|
+
const action = button.dataset.fileMenuAction || "";
|
|
26480
|
+
if (action === "open-default") openPathInDefaultEditor(entry.path).catch((error) => addEvent(error.message || String(error), "error"));
|
|
26481
|
+
else if (action === "open-webui") openFileTreeEntryInWebui(entry).catch((error) => addEvent(error.message || String(error), "error"));
|
|
26482
|
+
else if (action === "move") moveFileTreeEntry(entry).catch((error) => addEvent(error.message || String(error), "error"));
|
|
26483
|
+
else if (action === "delete") deleteFileTreeEntry(entry).catch((error) => addEvent(error.message || String(error), "error"));
|
|
26484
|
+
});
|
|
26485
|
+
elements.fileViewerOpenDefaultButton?.addEventListener("click", () => openPathInDefaultEditor(currentFileViewerPath()));
|
|
26486
|
+
elements.fileViewerResizeHandle?.addEventListener("pointerdown", beginFileViewerResize);
|
|
26487
|
+
elements.fileViewerResizeHandle?.addEventListener("keydown", handleFileViewerResizeKeydown);
|
|
26488
|
+
elements.fileViewerSaveButton?.addEventListener("click", () => saveActiveFileViewer());
|
|
26489
|
+
elements.fileViewerCloseButton?.addEventListener("click", closeFileViewer);
|
|
26490
|
+
elements.fileViewerSourceModeButton?.addEventListener("click", () => setFileViewerMode("source"));
|
|
26491
|
+
elements.fileViewerPreviewModeButton?.addEventListener("click", () => setFileViewerMode("preview"));
|
|
26492
|
+
elements.fileViewerEditor?.addEventListener("input", () => {
|
|
26493
|
+
if (!activeFileViewer) return;
|
|
26494
|
+
activeFileViewer.content = elements.fileViewerEditor.value || "";
|
|
26495
|
+
activeFileViewer.size = new Blob([activeFileViewer.content]).size;
|
|
26496
|
+
setFileViewerDirty(true);
|
|
26497
|
+
updateFileViewerSelectionFromEditor();
|
|
26498
|
+
});
|
|
26499
|
+
for (const eventName of ["select", "keyup", "mouseup"]) {
|
|
26500
|
+
elements.fileViewerEditor?.addEventListener(eventName, updateFileViewerSelectionFromEditor);
|
|
26501
|
+
}
|
|
26502
|
+
elements.fileViewerEditor?.addEventListener("keydown", (event) => {
|
|
26503
|
+
if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "s") return;
|
|
26504
|
+
event.preventDefault();
|
|
26505
|
+
if (!elements.fileViewerSaveButton?.disabled) saveActiveFileViewer();
|
|
26506
|
+
});
|
|
26507
|
+
for (const eventName of ["keyup", "mouseup"]) {
|
|
26508
|
+
elements.fileViewerPreview?.addEventListener(eventName, () => setTimeout(updateFileViewerSelectionFromPreview, 0));
|
|
26509
|
+
}
|
|
26510
|
+
document.addEventListener("selectionchange", () => {
|
|
26511
|
+
if (activeFileViewer && elements.fileViewerPreview && !elements.fileViewerPreview.hidden) updateFileViewerSelectionFromPreview();
|
|
26512
|
+
});
|
|
26513
|
+
elements.fileSelectionSendButton?.addEventListener("click", () => sendFileSelectionToSession());
|
|
26514
|
+
elements.fileSelectionCommentInput?.addEventListener("keydown", (event) => {
|
|
26515
|
+
if (event.key !== "Enter") return;
|
|
26516
|
+
event.preventDefault();
|
|
26517
|
+
sendFileSelectionToSession();
|
|
26518
|
+
});
|
|
23636
26519
|
elements.pathPickerCreateNameInput.addEventListener("input", updateCreateDirectoryControls);
|
|
23637
26520
|
elements.pathPickerCreateNameInput.addEventListener("keydown", (event) => {
|
|
23638
26521
|
if (event.key !== "Enter") return;
|
|
@@ -23739,6 +26622,7 @@ elements.promptInput.addEventListener("blur", () => {
|
|
|
23739
26622
|
});
|
|
23740
26623
|
|
|
23741
26624
|
resizePromptInput();
|
|
26625
|
+
restoreFileViewerWidthPreference();
|
|
23742
26626
|
focusPromptInput({ defer: true });
|
|
23743
26627
|
restoreStoredSkillUsage();
|
|
23744
26628
|
restoreBusyPromptBehaviorSetting();
|