@firstpick/pi-package-webui 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/bin/pi-webui.mjs +908 -14
- package/lib/trust-boundaries.mjs +2 -0
- package/package.json +11 -7
- package/public/app.js +1259 -12
- package/public/index.html +80 -2
- package/public/styles.css +488 -15
- package/tests/fixtures/fake-pi.mjs +59 -3
- package/tests/http-endpoints-harness.test.mjs +212 -2
- package/tests/mobile-static.test.mjs +41 -6
- package/tests/native-parity.test.mjs +1 -0
- package/webui-rpc-helper.mjs +29 -0
package/public/app.js
CHANGED
|
@@ -175,6 +175,32 @@ const elements = {
|
|
|
175
175
|
optionalFeaturesBox: $("#optionalFeaturesBox"),
|
|
176
176
|
codexUsageBox: $("#codexUsageBox"),
|
|
177
177
|
refreshCodexUsageButton: $("#refreshCodexUsageButton"),
|
|
178
|
+
claudeUsageBox: $("#claudeUsageBox"),
|
|
179
|
+
refreshClaudeUsageButton: $("#refreshClaudeUsageButton"),
|
|
180
|
+
fileTreeCwd: $("#fileTreeCwd"),
|
|
181
|
+
fileTreeRoot: $("#fileTreeRoot"),
|
|
182
|
+
fileTreeStatus: $("#fileTreeStatus"),
|
|
183
|
+
fileTreeRefreshButton: $("#fileTreeRefreshButton"),
|
|
184
|
+
fileTreeSearchInput: $("#fileTreeSearchInput"),
|
|
185
|
+
fileTreeSearchClearButton: $("#fileTreeSearchClearButton"),
|
|
186
|
+
fileViewerPane: $("#fileViewerPane"),
|
|
187
|
+
fileViewerResizeHandle: $("#fileViewerResizeHandle"),
|
|
188
|
+
fileViewerTitle: $("#fileViewerTitle"),
|
|
189
|
+
fileViewerMeta: $("#fileViewerMeta"),
|
|
190
|
+
fileViewerOpenDefaultButton: $("#fileViewerOpenDefaultButton"),
|
|
191
|
+
fileViewerSaveButton: $("#fileViewerSaveButton"),
|
|
192
|
+
fileViewerCloseButton: $("#fileViewerCloseButton"),
|
|
193
|
+
fileViewerHelp: $("#fileViewerHelp"),
|
|
194
|
+
fileViewerSourceModeButton: $("#fileViewerSourceModeButton"),
|
|
195
|
+
fileViewerPreviewModeButton: $("#fileViewerPreviewModeButton"),
|
|
196
|
+
fileViewerEditor: $("#fileViewerEditor"),
|
|
197
|
+
fileViewerPreview: $("#fileViewerPreview"),
|
|
198
|
+
fileViewerStatus: $("#fileViewerStatus"),
|
|
199
|
+
fileSelectionBar: $("#fileSelectionBar"),
|
|
200
|
+
fileSelectionSummary: $("#fileSelectionSummary"),
|
|
201
|
+
fileSelectionCommentInput: $("#fileSelectionCommentInput"),
|
|
202
|
+
fileSelectionSendButton: $("#fileSelectionSendButton"),
|
|
203
|
+
fileContextMenu: $("#fileContextMenu"),
|
|
178
204
|
toggleSidePanelButton: $("#toggleSidePanelButton"),
|
|
179
205
|
sidePanelExpandButton: $("#sidePanelExpandButton"),
|
|
180
206
|
sidePanelBackdrop: $("#sidePanelBackdrop"),
|
|
@@ -271,6 +297,13 @@ let tabDrafts = new Map();
|
|
|
271
297
|
let tabAttachments = new Map();
|
|
272
298
|
let activeTextAttachmentEditor = null;
|
|
273
299
|
let activeSkillEditor = null;
|
|
300
|
+
let fileTreeState = { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial: 0, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0 };
|
|
301
|
+
let activeFileViewer = null;
|
|
302
|
+
let fileViewerSelection = null;
|
|
303
|
+
let fileContextMenuState = null;
|
|
304
|
+
let fileViewerResizeState = null;
|
|
305
|
+
let fileTreeSearchTimer = null;
|
|
306
|
+
let fileTreeSearchRequestSerial = 0;
|
|
274
307
|
let tabActivities = new Map();
|
|
275
308
|
let tabSeenCompletionSerials = new Map();
|
|
276
309
|
let streamBubble = null;
|
|
@@ -341,12 +374,16 @@ let availableCommands = [];
|
|
|
341
374
|
let rawAvailableCommands = [];
|
|
342
375
|
let commandSuggestions = [];
|
|
343
376
|
let pathSuggestions = [];
|
|
377
|
+
let bangSuggestions = [];
|
|
344
378
|
let suggestionMode = "none";
|
|
345
379
|
let commandSuggestIndex = 0;
|
|
346
380
|
let lastPointerPosition = null;
|
|
347
381
|
let pathSuggestActiveQuery = null;
|
|
348
382
|
let pathSuggestRequestSerial = 0;
|
|
349
383
|
let pathSuggestAbortController = null;
|
|
384
|
+
let bangSuggestActiveQuery = null;
|
|
385
|
+
let bangSuggestRequestSerial = 0;
|
|
386
|
+
let bangSuggestAbortController = null;
|
|
350
387
|
let latestStats = null;
|
|
351
388
|
let statsOverlayActiveTab = "overview";
|
|
352
389
|
let statsOverlayLoading = false;
|
|
@@ -372,6 +409,11 @@ let codexUsageError = null;
|
|
|
372
409
|
let codexUsageLoading = false;
|
|
373
410
|
let refreshCodexUsageTimer = null;
|
|
374
411
|
let codexUsageRenderTimer = null;
|
|
412
|
+
let latestClaudeUsage = null;
|
|
413
|
+
let claudeUsageError = null;
|
|
414
|
+
let claudeUsageLoading = false;
|
|
415
|
+
let refreshClaudeUsageTimer = null;
|
|
416
|
+
let claudeUsageRenderTimer = null;
|
|
375
417
|
let backendOffline = false;
|
|
376
418
|
let serverRestartInProgress = false;
|
|
377
419
|
let updateRequestInProgress = false;
|
|
@@ -522,6 +564,11 @@ const LAST_USER_PROMPT_STORAGE_KEY = "pi-webui-last-user-prompts";
|
|
|
522
564
|
const PROMPT_HISTORY_STORAGE_KEY = "pi-webui-prompt-history";
|
|
523
565
|
const PROMPT_LIST_STORAGE_KEY = "pi-webui-prompt-lists";
|
|
524
566
|
const WORKSPACE_DASHBOARD_STORAGE_KEY = "pi-webui-workspace-dashboard-collapsed";
|
|
567
|
+
const FILE_VIEWER_WIDTH_STORAGE_KEY = "pi-webui-file-viewer-width";
|
|
568
|
+
const FILE_VIEWER_WIDTH_DEFAULT_PX = 520;
|
|
569
|
+
const FILE_VIEWER_WIDTH_MIN_PX = 384;
|
|
570
|
+
const FILE_VIEWER_CONTEXT_RADIUS_LINES = 6;
|
|
571
|
+
const FILE_TREE_ROOT_PATH = "";
|
|
525
572
|
const POINTER_ACTIVATION_SELECTOR = "button, a[href], input, select, textarea, summary, [role='button'], [tabindex]:not([tabindex='-1'])";
|
|
526
573
|
const POINTER_ACTIVATION_RENDER_DEFER_MAX_MS = 1200;
|
|
527
574
|
const PROMPT_HISTORY_LIMIT_PER_TAB = 50;
|
|
@@ -562,6 +609,8 @@ const CHAT_PROGRAMMATIC_SCROLL_GRACE_MS = 500;
|
|
|
562
609
|
const CHAT_USER_SCROLL_INTENT_MS = 700;
|
|
563
610
|
const CODEX_USAGE_REFRESH_MS = 5 * 60 * 1000;
|
|
564
611
|
const CODEX_USAGE_RENDER_TICK_MS = 30 * 1000;
|
|
612
|
+
const CLAUDE_USAGE_REFRESH_MS = 5 * 60 * 1000;
|
|
613
|
+
const CLAUDE_USAGE_RENDER_TICK_MS = 30 * 1000;
|
|
565
614
|
const UPDATE_STATUS_REFRESH_MS = 6 * 60 * 60 * 1000;
|
|
566
615
|
const UPDATE_STATUS_INITIAL_DELAY_MS = 1800;
|
|
567
616
|
const RUN_INDICATOR_TICK_MS = 1000;
|
|
@@ -615,6 +664,8 @@ let liveToolRenderTimer = null;
|
|
|
615
664
|
// commands and live widget events), not npm package folders. This keeps local dev
|
|
616
665
|
// symlinks and independently installed packages working.
|
|
617
666
|
const optionalFeatureAvailability = {
|
|
667
|
+
bangCommandAutocomplete: false,
|
|
668
|
+
fishUserBash: false,
|
|
618
669
|
btwCommand: false,
|
|
619
670
|
gitWorkflow: false,
|
|
620
671
|
releaseNpm: false,
|
|
@@ -633,6 +684,20 @@ const optionalFeatureAvailability = {
|
|
|
633
684
|
const APP_RUNNER_CONTEXT_DEFAULT_LINES = 80;
|
|
634
685
|
const APP_RUNNER_CONTEXT_MAX_LINES = 1000;
|
|
635
686
|
const OPTIONAL_FEATURES = [
|
|
687
|
+
{
|
|
688
|
+
id: "bangCommandAutocomplete",
|
|
689
|
+
label: "! command autocomplete",
|
|
690
|
+
packageName: "@firstpick/pi-extension-bang-command-autocomplete",
|
|
691
|
+
capabilityLabel: "/bang-status or /bang-refresh",
|
|
692
|
+
description: "Autocomplete for native ! and !! shell commands in the Web UI composer.",
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
id: "fishUserBash",
|
|
696
|
+
label: "Fish user bash",
|
|
697
|
+
packageName: "@firstpick/pi-extension-fish-user-bash",
|
|
698
|
+
capabilityLabel: "/user-bash-shell",
|
|
699
|
+
description: "Run Web UI ! and !! shell commands through the user shell selected by fish-user-bash.",
|
|
700
|
+
},
|
|
636
701
|
{
|
|
637
702
|
id: "btwCommand",
|
|
638
703
|
label: "/btw side questions",
|
|
@@ -734,6 +799,9 @@ const OPTIONAL_FEATURES = [
|
|
|
734
799
|
];
|
|
735
800
|
const OPTIONAL_FEATURE_BY_ID = new Map(OPTIONAL_FEATURES.map((feature) => [feature.id, feature]));
|
|
736
801
|
const OPTIONAL_COMMAND_FEATURES = new Map([
|
|
802
|
+
["bang-refresh", "bangCommandAutocomplete"],
|
|
803
|
+
["bang-status", "bangCommandAutocomplete"],
|
|
804
|
+
["user-bash-shell", "fishUserBash"],
|
|
737
805
|
["btw", "btwCommand"],
|
|
738
806
|
["btw-transfer", "btwCommand"],
|
|
739
807
|
["btw-status", "btwCommand"],
|
|
@@ -2769,19 +2837,17 @@ async function submitEditRetry({ send = false } = {}) {
|
|
|
2769
2837
|
const forkMessage = await resolveForkMessageForEdit(message, messageIndex, tabContext.tabId);
|
|
2770
2838
|
setEditRetryStatus("Forking session…");
|
|
2771
2839
|
const result = await api("/api/fork", { method: "POST", body: { entryId: forkMessage.entryId }, tabId: tabContext.tabId });
|
|
2772
|
-
|
|
2773
|
-
|
|
2840
|
+
const forkTab = await switchToResponseTab(result);
|
|
2841
|
+
const forkTabId = forkTab?.id || activeTabId;
|
|
2774
2842
|
closeEditRetryDialog();
|
|
2775
|
-
await refreshAll(tabContext);
|
|
2776
|
-
if (!isCurrentTabContext(tabContext)) return;
|
|
2777
2843
|
if (send) {
|
|
2778
|
-
addEvent("forked session; sending edited prompt", "info");
|
|
2779
|
-
await sendPrompt("prompt", editedText, { targetTabId:
|
|
2844
|
+
addEvent("forked session in a new tab; sending edited prompt", "info");
|
|
2845
|
+
await sendPrompt("prompt", editedText, { targetTabId: forkTabId, throwOnError: true });
|
|
2780
2846
|
} else {
|
|
2781
2847
|
elements.promptInput.value = editedText;
|
|
2782
2848
|
resizePromptInput();
|
|
2783
2849
|
focusPromptInput({ defer: true });
|
|
2784
|
-
addEvent("forked session; edited prompt restored in composer", "info");
|
|
2850
|
+
addEvent("forked session in a new tab; edited prompt restored in composer", "info");
|
|
2785
2851
|
}
|
|
2786
2852
|
} catch (error) {
|
|
2787
2853
|
setEditRetryStatus(error.message || String(error), "error");
|
|
@@ -5294,6 +5360,797 @@ function isCurrentTabContext(context) {
|
|
|
5294
5360
|
return !!context && context.tabId === activeTabId && context.generation === activeTabGeneration;
|
|
5295
5361
|
}
|
|
5296
5362
|
|
|
5363
|
+
function normalizeFileTreePath(value = "") {
|
|
5364
|
+
return String(value || "").trim().replace(/\\/g, "/").replace(/^\.\/+/, "").replace(/^\/+/, "").replace(/\/+$/g, "");
|
|
5365
|
+
}
|
|
5366
|
+
|
|
5367
|
+
function fileApiPath(basePath, filePath = "") {
|
|
5368
|
+
const path = normalizeFileTreePath(filePath);
|
|
5369
|
+
if (!path) return basePath;
|
|
5370
|
+
const params = new URLSearchParams({ path });
|
|
5371
|
+
return `${basePath}?${params.toString()}`;
|
|
5372
|
+
}
|
|
5373
|
+
|
|
5374
|
+
function fileParentPath(filePath = "") {
|
|
5375
|
+
const normalized = normalizeFileTreePath(filePath);
|
|
5376
|
+
const index = normalized.lastIndexOf("/");
|
|
5377
|
+
return index === -1 ? FILE_TREE_ROOT_PATH : normalized.slice(0, index);
|
|
5378
|
+
}
|
|
5379
|
+
|
|
5380
|
+
function fileDisplayName(path = "") {
|
|
5381
|
+
const normalized = normalizeFileTreePath(path);
|
|
5382
|
+
return normalized ? normalized.split("/").pop() || normalized : ".";
|
|
5383
|
+
}
|
|
5384
|
+
|
|
5385
|
+
function fileEntryIcon(entry = {}) {
|
|
5386
|
+
if (entry.type === "directory") return "▸";
|
|
5387
|
+
if (entry.type === "file") return entry.extension === ".md" || entry.extension === ".markdown" ? "Md" : "TXT";
|
|
5388
|
+
if (entry.type === "error") return "!";
|
|
5389
|
+
return "·";
|
|
5390
|
+
}
|
|
5391
|
+
|
|
5392
|
+
function setFileTreeStatus(message = "", level = "muted") {
|
|
5393
|
+
if (!elements.fileTreeStatus) return;
|
|
5394
|
+
elements.fileTreeStatus.textContent = message;
|
|
5395
|
+
elements.fileTreeStatus.className = `file-tree-status ${level || "muted"}`;
|
|
5396
|
+
}
|
|
5397
|
+
|
|
5398
|
+
function setFileViewerStatus(message = "", level = "muted") {
|
|
5399
|
+
if (!elements.fileViewerStatus) return;
|
|
5400
|
+
elements.fileViewerStatus.textContent = message;
|
|
5401
|
+
elements.fileViewerStatus.className = `file-viewer-status ${level || "muted"}`;
|
|
5402
|
+
}
|
|
5403
|
+
|
|
5404
|
+
function emptyFileTreeState(requestSerial = 0) {
|
|
5405
|
+
return { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0 };
|
|
5406
|
+
}
|
|
5407
|
+
|
|
5408
|
+
function fileTreeSearchQueryText() {
|
|
5409
|
+
return String(elements.fileTreeSearchInput?.value || "").trim();
|
|
5410
|
+
}
|
|
5411
|
+
|
|
5412
|
+
function fileSearchApiPath(query = "") {
|
|
5413
|
+
const params = new URLSearchParams({ q: query });
|
|
5414
|
+
return `/api/files/search?${params.toString()}`;
|
|
5415
|
+
}
|
|
5416
|
+
|
|
5417
|
+
function fileTreeEntriesStatus(entries = [], { truncated = false, total = entries.length, searchQuery = "" } = {}) {
|
|
5418
|
+
const count = entries.length;
|
|
5419
|
+
if (searchQuery) {
|
|
5420
|
+
if (!count) return `0 matches for “${searchQuery}”.`;
|
|
5421
|
+
const label = count === 1 ? "match" : "matches";
|
|
5422
|
+
return truncated ? `Showing first ${count} ${label} for “${searchQuery}”.` : `${count} ${label} for “${searchQuery}”.`;
|
|
5423
|
+
}
|
|
5424
|
+
return truncated ? `Showing ${count} of ${total || count} entries.` : `${count} item${count === 1 ? "" : "s"}.`;
|
|
5425
|
+
}
|
|
5426
|
+
|
|
5427
|
+
function updateFileTreeSearchControls() {
|
|
5428
|
+
const query = fileTreeSearchQueryText();
|
|
5429
|
+
if (elements.fileTreeSearchClearButton) {
|
|
5430
|
+
elements.fileTreeSearchClearButton.hidden = !query;
|
|
5431
|
+
elements.fileTreeSearchClearButton.disabled = !query;
|
|
5432
|
+
}
|
|
5433
|
+
}
|
|
5434
|
+
|
|
5435
|
+
function resetFileTreeState() {
|
|
5436
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5437
|
+
fileTreeSearchTimer = null;
|
|
5438
|
+
fileTreeSearchRequestSerial += 1;
|
|
5439
|
+
fileTreeState = emptyFileTreeState(fileTreeState.requestSerial + 1);
|
|
5440
|
+
if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
|
|
5441
|
+
updateFileTreeSearchControls();
|
|
5442
|
+
renderFileTree();
|
|
5443
|
+
}
|
|
5444
|
+
|
|
5445
|
+
function fileEntryByPath(filePath = "") {
|
|
5446
|
+
const normalized = normalizeFileTreePath(filePath);
|
|
5447
|
+
if (!normalized) return { name: ".", path: "", type: "directory", directory: true };
|
|
5448
|
+
for (const entries of fileTreeState.entriesByPath.values()) {
|
|
5449
|
+
const found = entries.find((entry) => normalizeFileTreePath(entry.path) === normalized);
|
|
5450
|
+
if (found) return found;
|
|
5451
|
+
}
|
|
5452
|
+
return null;
|
|
5453
|
+
}
|
|
5454
|
+
|
|
5455
|
+
function renderFileTree() {
|
|
5456
|
+
const root = elements.fileTreeRoot;
|
|
5457
|
+
if (!root) return;
|
|
5458
|
+
root.replaceChildren();
|
|
5459
|
+
updateFileTreeSearchControls();
|
|
5460
|
+
if (elements.fileTreeCwd) elements.fileTreeCwd.textContent = fileTreeState.root || latestWorkspace?.displayCwd || activeTab()?.cwd || "";
|
|
5461
|
+
const searchQuery = fileTreeState.searchQuery || fileTreeSearchQueryText();
|
|
5462
|
+
root.classList.toggle("searching", !!searchQuery);
|
|
5463
|
+
if (searchQuery) {
|
|
5464
|
+
if (fileTreeState.searchLoading) {
|
|
5465
|
+
root.append(make("div", "file-tree-loading muted", `Searching for “${searchQuery}”…`));
|
|
5466
|
+
return;
|
|
5467
|
+
}
|
|
5468
|
+
if (!fileTreeState.searchEntries.length) {
|
|
5469
|
+
root.append(make("div", "file-tree-empty muted", `No files or folders match “${searchQuery}”.`));
|
|
5470
|
+
return;
|
|
5471
|
+
}
|
|
5472
|
+
const list = make("ul", "file-tree-list root search-results");
|
|
5473
|
+
list.setAttribute("role", "group");
|
|
5474
|
+
for (const entry of fileTreeState.searchEntries) appendFileSearchEntry(list, entry);
|
|
5475
|
+
root.append(list);
|
|
5476
|
+
return;
|
|
5477
|
+
}
|
|
5478
|
+
const entries = fileTreeState.entriesByPath.get(FILE_TREE_ROOT_PATH) || [];
|
|
5479
|
+
if (!entries.length) {
|
|
5480
|
+
root.append(make("div", "file-tree-empty muted", fileTreeState.loading.has(FILE_TREE_ROOT_PATH) ? "Loading files…" : "No files loaded."));
|
|
5481
|
+
return;
|
|
5482
|
+
}
|
|
5483
|
+
const list = make("ul", "file-tree-list root");
|
|
5484
|
+
list.setAttribute("role", "group");
|
|
5485
|
+
for (const entry of entries) appendFileTreeEntry(list, entry, 0);
|
|
5486
|
+
root.append(list);
|
|
5487
|
+
}
|
|
5488
|
+
|
|
5489
|
+
function appendFileSearchEntry(parent, entry) {
|
|
5490
|
+
const path = normalizeFileTreePath(entry.path);
|
|
5491
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5492
|
+
const item = make("li", `file-tree-node file-tree-search-node ${entry.type || "file"}${fileTreeState.selectedPath === path ? " selected" : ""}`);
|
|
5493
|
+
item.setAttribute("role", "none");
|
|
5494
|
+
const button = make("button", "file-tree-item file-tree-search-item");
|
|
5495
|
+
button.type = "button";
|
|
5496
|
+
button.dataset.path = path;
|
|
5497
|
+
button.dataset.type = entry.type || "file";
|
|
5498
|
+
button.style.setProperty("--file-tree-depth", "0");
|
|
5499
|
+
button.setAttribute("role", "treeitem");
|
|
5500
|
+
button.title = [path || ".", entry.error || ""].filter(Boolean).join("\n");
|
|
5501
|
+
const label = make("span", "file-tree-search-label");
|
|
5502
|
+
label.append(
|
|
5503
|
+
make("span", "file-tree-name", entry.name || fileDisplayName(path)),
|
|
5504
|
+
make("span", "file-tree-search-path", path || "."),
|
|
5505
|
+
);
|
|
5506
|
+
button.append(
|
|
5507
|
+
make("span", "file-tree-icon", fileEntryIcon(entry)),
|
|
5508
|
+
label,
|
|
5509
|
+
);
|
|
5510
|
+
if (entry.type === "file") button.append(make("span", "file-tree-kind", entry.extension || "file"));
|
|
5511
|
+
else if (entry.type && entry.type !== "directory") button.append(make("span", "file-tree-kind", entry.type));
|
|
5512
|
+
if (entry.error) button.append(make("span", "file-tree-error", entry.error));
|
|
5513
|
+
button.addEventListener("click", () => {
|
|
5514
|
+
fileTreeState.selectedPath = path;
|
|
5515
|
+
renderFileTree();
|
|
5516
|
+
});
|
|
5517
|
+
button.addEventListener("dblclick", (event) => {
|
|
5518
|
+
event.preventDefault();
|
|
5519
|
+
if (isDirectory) revealFileTreeEntry(entry).catch((error) => addEvent(error.message || String(error), "error"));
|
|
5520
|
+
else if (entry.type === "file") openFileInViewer(path);
|
|
5521
|
+
});
|
|
5522
|
+
button.addEventListener("contextmenu", (event) => showFileContextMenu(event, entry));
|
|
5523
|
+
item.append(button);
|
|
5524
|
+
parent.append(item);
|
|
5525
|
+
}
|
|
5526
|
+
|
|
5527
|
+
async function revealFileTreeEntry(entry = {}) {
|
|
5528
|
+
const targetPath = normalizeFileTreePath(entry.path || "");
|
|
5529
|
+
if (!targetPath && targetPath !== FILE_TREE_ROOT_PATH) return;
|
|
5530
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5531
|
+
const parentPath = isDirectory ? targetPath : fileParentPath(targetPath);
|
|
5532
|
+
clearFileTreeSearch();
|
|
5533
|
+
fileTreeState.selectedPath = targetPath;
|
|
5534
|
+
await loadFileTreeDirectory(FILE_TREE_ROOT_PATH);
|
|
5535
|
+
let currentPath = "";
|
|
5536
|
+
for (const part of parentPath.split("/").filter(Boolean)) {
|
|
5537
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
5538
|
+
fileTreeState.expanded.add(currentPath);
|
|
5539
|
+
renderFileTree();
|
|
5540
|
+
await loadFileTreeDirectory(currentPath);
|
|
5541
|
+
}
|
|
5542
|
+
if (isDirectory) {
|
|
5543
|
+
fileTreeState.expanded.add(targetPath);
|
|
5544
|
+
await loadFileTreeDirectory(targetPath);
|
|
5545
|
+
}
|
|
5546
|
+
fileTreeState.selectedPath = targetPath;
|
|
5547
|
+
renderFileTree();
|
|
5548
|
+
}
|
|
5549
|
+
|
|
5550
|
+
function appendFileTreeEntry(parent, entry, depth = 0) {
|
|
5551
|
+
const path = normalizeFileTreePath(entry.path);
|
|
5552
|
+
const isDirectory = entry.type === "directory" || entry.directory === true;
|
|
5553
|
+
const expanded = isDirectory && fileTreeState.expanded.has(path);
|
|
5554
|
+
const loading = isDirectory && fileTreeState.loading.has(path);
|
|
5555
|
+
const item = make("li", `file-tree-node ${entry.type || "file"}${expanded ? " expanded" : ""}${fileTreeState.selectedPath === path ? " selected" : ""}`);
|
|
5556
|
+
item.setAttribute("role", "none");
|
|
5557
|
+
const button = make("button", "file-tree-item");
|
|
5558
|
+
button.type = "button";
|
|
5559
|
+
button.dataset.path = path;
|
|
5560
|
+
button.dataset.type = entry.type || "file";
|
|
5561
|
+
button.style.setProperty("--file-tree-depth", String(depth));
|
|
5562
|
+
button.setAttribute("role", "treeitem");
|
|
5563
|
+
if (isDirectory) button.setAttribute("aria-expanded", expanded ? "true" : "false");
|
|
5564
|
+
button.title = [path || ".", entry.error || ""].filter(Boolean).join("\n");
|
|
5565
|
+
button.append(
|
|
5566
|
+
make("span", `file-tree-icon ${isDirectory && expanded ? "expanded" : ""}`, loading ? "…" : fileEntryIcon(entry)),
|
|
5567
|
+
make("span", "file-tree-name", entry.name || fileDisplayName(path)),
|
|
5568
|
+
);
|
|
5569
|
+
if (entry.type === "file") button.append(make("span", "file-tree-kind", entry.extension || "file"));
|
|
5570
|
+
if (entry.error) button.append(make("span", "file-tree-error", entry.error));
|
|
5571
|
+
button.addEventListener("click", () => {
|
|
5572
|
+
fileTreeState.selectedPath = path;
|
|
5573
|
+
if (isDirectory) toggleFileTreeDirectory(path);
|
|
5574
|
+
else renderFileTree();
|
|
5575
|
+
});
|
|
5576
|
+
button.addEventListener("dblclick", (event) => {
|
|
5577
|
+
event.preventDefault();
|
|
5578
|
+
if (isDirectory) toggleFileTreeDirectory(path, { force: true });
|
|
5579
|
+
else openFileInViewer(path);
|
|
5580
|
+
});
|
|
5581
|
+
button.addEventListener("contextmenu", (event) => showFileContextMenu(event, entry));
|
|
5582
|
+
item.append(button);
|
|
5583
|
+
if (isDirectory && expanded) {
|
|
5584
|
+
const children = fileTreeState.entriesByPath.get(path) || [];
|
|
5585
|
+
const childList = make("ul", "file-tree-list");
|
|
5586
|
+
childList.setAttribute("role", "group");
|
|
5587
|
+
if (loading) childList.append(make("li", "file-tree-loading muted", "Loading…"));
|
|
5588
|
+
else if (!children.length) childList.append(make("li", "file-tree-empty muted", "Empty"));
|
|
5589
|
+
else for (const child of children) appendFileTreeEntry(childList, child, depth + 1);
|
|
5590
|
+
item.append(childList);
|
|
5591
|
+
}
|
|
5592
|
+
parent.append(item);
|
|
5593
|
+
}
|
|
5594
|
+
|
|
5595
|
+
async function loadFileTreeDirectory(path = FILE_TREE_ROOT_PATH, { force = false } = {}) {
|
|
5596
|
+
const normalized = normalizeFileTreePath(path);
|
|
5597
|
+
if (!force && fileTreeState.entriesByPath.has(normalized)) return fileTreeState.entriesByPath.get(normalized);
|
|
5598
|
+
const tabContext = activeTabContext();
|
|
5599
|
+
if (!tabContext.tabId || fileTreeState.loading.has(normalized)) return [];
|
|
5600
|
+
const serial = ++fileTreeState.requestSerial;
|
|
5601
|
+
fileTreeState.loading.add(normalized);
|
|
5602
|
+
setFileTreeStatus(normalized ? `Loading ${normalized}…` : "Loading workspace files…");
|
|
5603
|
+
renderFileTree();
|
|
5604
|
+
try {
|
|
5605
|
+
const response = await api(fileApiPath("/api/files", normalized), { tabId: tabContext.tabId });
|
|
5606
|
+
if (!isCurrentTabContext(tabContext) || serial < fileTreeState.requestSerial) return [];
|
|
5607
|
+
const data = response.data || {};
|
|
5608
|
+
if (!normalized && data.root && data.root !== fileTreeState.root) {
|
|
5609
|
+
fileTreeState.root = data.root;
|
|
5610
|
+
fileTreeState.entriesByPath.clear();
|
|
5611
|
+
fileTreeState.expanded.clear();
|
|
5612
|
+
}
|
|
5613
|
+
const entries = Array.isArray(data.entries) ? data.entries : [];
|
|
5614
|
+
fileTreeState.entriesByPath.set(normalized, entries);
|
|
5615
|
+
setFileTreeStatus(fileTreeEntriesStatus(entries, { truncated: data.truncated, total: data.total || entries.length }));
|
|
5616
|
+
return entries;
|
|
5617
|
+
} catch (error) {
|
|
5618
|
+
if (isCurrentTabContext(tabContext)) {
|
|
5619
|
+
setFileTreeStatus(error.message || String(error), "error");
|
|
5620
|
+
addEvent(`file tree failed: ${error.message || String(error)}`, "error");
|
|
5621
|
+
}
|
|
5622
|
+
return [];
|
|
5623
|
+
} finally {
|
|
5624
|
+
fileTreeState.loading.delete(normalized);
|
|
5625
|
+
if (isCurrentTabContext(tabContext)) renderFileTree();
|
|
5626
|
+
}
|
|
5627
|
+
}
|
|
5628
|
+
|
|
5629
|
+
function clearFileTreeSearch({ focus = false } = {}) {
|
|
5630
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5631
|
+
fileTreeSearchTimer = null;
|
|
5632
|
+
fileTreeSearchRequestSerial += 1;
|
|
5633
|
+
if (elements.fileTreeSearchInput) elements.fileTreeSearchInput.value = "";
|
|
5634
|
+
fileTreeState.searchQuery = "";
|
|
5635
|
+
fileTreeState.searchEntries = [];
|
|
5636
|
+
fileTreeState.searchLoading = false;
|
|
5637
|
+
fileTreeState.searchTruncated = false;
|
|
5638
|
+
fileTreeState.searchTotal = 0;
|
|
5639
|
+
updateFileTreeSearchControls();
|
|
5640
|
+
const rootEntries = fileTreeState.entriesByPath.get(FILE_TREE_ROOT_PATH) || [];
|
|
5641
|
+
setFileTreeStatus(rootEntries.length ? fileTreeEntriesStatus(rootEntries) : "");
|
|
5642
|
+
renderFileTree();
|
|
5643
|
+
if (focus) elements.fileTreeSearchInput?.focus();
|
|
5644
|
+
}
|
|
5645
|
+
|
|
5646
|
+
async function runFileTreeSearch() {
|
|
5647
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5648
|
+
fileTreeSearchTimer = null;
|
|
5649
|
+
const query = fileTreeSearchQueryText();
|
|
5650
|
+
fileTreeSearchRequestSerial += 1;
|
|
5651
|
+
const serial = fileTreeSearchRequestSerial;
|
|
5652
|
+
if (!query) {
|
|
5653
|
+
clearFileTreeSearch();
|
|
5654
|
+
return [];
|
|
5655
|
+
}
|
|
5656
|
+
const tabContext = activeTabContext();
|
|
5657
|
+
if (!tabContext.tabId) return [];
|
|
5658
|
+
fileTreeState.searchQuery = query;
|
|
5659
|
+
fileTreeState.searchLoading = true;
|
|
5660
|
+
fileTreeState.searchEntries = [];
|
|
5661
|
+
fileTreeState.searchTruncated = false;
|
|
5662
|
+
fileTreeState.searchTotal = 0;
|
|
5663
|
+
setFileTreeStatus(`Searching for “${query}”…`);
|
|
5664
|
+
renderFileTree();
|
|
5665
|
+
try {
|
|
5666
|
+
const response = await api(fileSearchApiPath(query), { tabId: tabContext.tabId });
|
|
5667
|
+
if (!isCurrentTabContext(tabContext) || serial !== fileTreeSearchRequestSerial) return [];
|
|
5668
|
+
const data = response.data || {};
|
|
5669
|
+
const entries = Array.isArray(data.entries) ? data.entries : [];
|
|
5670
|
+
if (data.root) fileTreeState.root = data.root;
|
|
5671
|
+
fileTreeState.searchQuery = data.query || query;
|
|
5672
|
+
fileTreeState.searchEntries = entries;
|
|
5673
|
+
fileTreeState.searchLoading = false;
|
|
5674
|
+
fileTreeState.searchTruncated = !!data.truncated;
|
|
5675
|
+
fileTreeState.searchTotal = Number(data.total || entries.length) || entries.length;
|
|
5676
|
+
setFileTreeStatus(fileTreeEntriesStatus(entries, { truncated: data.truncated, total: data.total || entries.length, searchQuery: fileTreeState.searchQuery }), entries.length ? "success" : "muted");
|
|
5677
|
+
return entries;
|
|
5678
|
+
} catch (error) {
|
|
5679
|
+
if (isCurrentTabContext(tabContext) && serial === fileTreeSearchRequestSerial) {
|
|
5680
|
+
fileTreeState.searchLoading = false;
|
|
5681
|
+
fileTreeState.searchEntries = [];
|
|
5682
|
+
setFileTreeStatus(error.message || String(error), "error");
|
|
5683
|
+
addEvent(`file search failed: ${error.message || String(error)}`, "error");
|
|
5684
|
+
}
|
|
5685
|
+
return [];
|
|
5686
|
+
} finally {
|
|
5687
|
+
if (isCurrentTabContext(tabContext) && serial === fileTreeSearchRequestSerial) renderFileTree();
|
|
5688
|
+
}
|
|
5689
|
+
}
|
|
5690
|
+
|
|
5691
|
+
function scheduleFileTreeSearch(delay = 180) {
|
|
5692
|
+
clearTimeout(fileTreeSearchTimer);
|
|
5693
|
+
const query = fileTreeSearchQueryText();
|
|
5694
|
+
updateFileTreeSearchControls();
|
|
5695
|
+
if (!query) {
|
|
5696
|
+
clearFileTreeSearch();
|
|
5697
|
+
return;
|
|
5698
|
+
}
|
|
5699
|
+
fileTreeSearchRequestSerial += 1;
|
|
5700
|
+
fileTreeState.searchQuery = query;
|
|
5701
|
+
fileTreeState.searchLoading = true;
|
|
5702
|
+
setFileTreeStatus(`Searching for “${query}”…`);
|
|
5703
|
+
renderFileTree();
|
|
5704
|
+
fileTreeSearchTimer = setTimeout(() => {
|
|
5705
|
+
runFileTreeSearch().catch((error) => addEvent(error.message || String(error), "error"));
|
|
5706
|
+
}, delay);
|
|
5707
|
+
}
|
|
5708
|
+
|
|
5709
|
+
async function refreshFileTreeRoot(tabContext = activeTabContext()) {
|
|
5710
|
+
if (!tabContext.tabId || !elements.fileTreeRoot) return;
|
|
5711
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
5712
|
+
if (fileTreeSearchQueryText()) await runFileTreeSearch();
|
|
5713
|
+
else await loadFileTreeDirectory(FILE_TREE_ROOT_PATH, { force: true });
|
|
5714
|
+
}
|
|
5715
|
+
|
|
5716
|
+
async function toggleFileTreeDirectory(path = "", { force = false } = {}) {
|
|
5717
|
+
const normalized = normalizeFileTreePath(path);
|
|
5718
|
+
if (!normalized && normalized !== FILE_TREE_ROOT_PATH) return;
|
|
5719
|
+
const currentlyExpanded = fileTreeState.expanded.has(normalized);
|
|
5720
|
+
if (currentlyExpanded && !force) {
|
|
5721
|
+
fileTreeState.expanded.delete(normalized);
|
|
5722
|
+
renderFileTree();
|
|
5723
|
+
return;
|
|
5724
|
+
}
|
|
5725
|
+
fileTreeState.expanded.add(normalized);
|
|
5726
|
+
renderFileTree();
|
|
5727
|
+
await loadFileTreeDirectory(normalized);
|
|
5728
|
+
}
|
|
5729
|
+
|
|
5730
|
+
function closeFileContextMenu() {
|
|
5731
|
+
fileContextMenuState = null;
|
|
5732
|
+
if (elements.fileContextMenu) elements.fileContextMenu.hidden = true;
|
|
5733
|
+
}
|
|
5734
|
+
|
|
5735
|
+
function showFileContextMenu(event, entry) {
|
|
5736
|
+
if (!elements.fileContextMenu) return;
|
|
5737
|
+
event.preventDefault();
|
|
5738
|
+
event.stopPropagation();
|
|
5739
|
+
const path = normalizeFileTreePath(entry?.path || "");
|
|
5740
|
+
fileContextMenuState = { entry: { ...entry, path } };
|
|
5741
|
+
const menu = elements.fileContextMenu;
|
|
5742
|
+
const webui = menu.querySelector('[data-file-menu-action="open-webui"]');
|
|
5743
|
+
if (webui) webui.textContent = entry?.type === "directory" ? "Open in WebUI" : "Open in WebUI";
|
|
5744
|
+
menu.hidden = false;
|
|
5745
|
+
const rect = menu.getBoundingClientRect();
|
|
5746
|
+
const left = Math.min(event.clientX, Math.max(0, window.innerWidth - rect.width - 8));
|
|
5747
|
+
const top = Math.min(event.clientY, Math.max(0, window.innerHeight - rect.height - 8));
|
|
5748
|
+
menu.style.left = `${left}px`;
|
|
5749
|
+
menu.style.top = `${top}px`;
|
|
5750
|
+
}
|
|
5751
|
+
|
|
5752
|
+
function currentFileViewerPath() {
|
|
5753
|
+
return normalizeFileTreePath(activeFileViewer?.path || elements.fileViewerOpenDefaultButton?.dataset.path || "");
|
|
5754
|
+
}
|
|
5755
|
+
|
|
5756
|
+
async function openPathInDefaultEditor(path = currentFileViewerPath()) {
|
|
5757
|
+
const normalized = normalizeFileTreePath(path);
|
|
5758
|
+
if (!normalized) {
|
|
5759
|
+
addEvent("No file is currently open in the WebUI viewer.", "warn");
|
|
5760
|
+
return;
|
|
5761
|
+
}
|
|
5762
|
+
const tabContext = activeTabContext();
|
|
5763
|
+
try {
|
|
5764
|
+
const response = await api("/api/files/open-default", { method: "POST", body: { path: normalized }, tabId: tabContext.tabId });
|
|
5765
|
+
if (isCurrentTabContext(tabContext)) addEvent(`opened ${response.data?.path || normalized || "."} in the default editor`, "info");
|
|
5766
|
+
} catch (error) {
|
|
5767
|
+
if (isCurrentTabContext(tabContext)) addEvent(error.message || String(error), "error");
|
|
5768
|
+
}
|
|
5769
|
+
}
|
|
5770
|
+
|
|
5771
|
+
function readStoredFileViewerWidth() {
|
|
5772
|
+
try {
|
|
5773
|
+
const width = Number.parseFloat(localStorage.getItem(FILE_VIEWER_WIDTH_STORAGE_KEY) || "");
|
|
5774
|
+
return Number.isFinite(width) && width >= FILE_VIEWER_WIDTH_MIN_PX ? width : null;
|
|
5775
|
+
} catch {
|
|
5776
|
+
return null;
|
|
5777
|
+
}
|
|
5778
|
+
}
|
|
5779
|
+
|
|
5780
|
+
function persistFileViewerWidth(width) {
|
|
5781
|
+
try {
|
|
5782
|
+
localStorage.setItem(FILE_VIEWER_WIDTH_STORAGE_KEY, String(Math.round(width)));
|
|
5783
|
+
} catch {
|
|
5784
|
+
// Ignore storage failures; resizing should still work for this page load.
|
|
5785
|
+
}
|
|
5786
|
+
}
|
|
5787
|
+
|
|
5788
|
+
function fileViewerMaxWidth() {
|
|
5789
|
+
const layout = document.querySelector(".layout");
|
|
5790
|
+
const layoutRect = layout?.getBoundingClientRect?.();
|
|
5791
|
+
const layoutWidth = layoutRect?.width || window.innerWidth || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
5792
|
+
const layoutStyle = layout ? getComputedStyle(layout) : null;
|
|
5793
|
+
const gap = Number.parseFloat(layoutStyle?.columnGap || layoutStyle?.gap || "0") || 0;
|
|
5794
|
+
const sidePanelVisible = !document.body.classList.contains("side-panel-collapsed") && elements.sidePanel && getComputedStyle(elements.sidePanel).display !== "none";
|
|
5795
|
+
const sidePanelWidth = sidePanelVisible ? elements.sidePanel.getBoundingClientRect().width : 0;
|
|
5796
|
+
const splitOpen = document.body.classList.contains("terminal-split-open");
|
|
5797
|
+
const primaryMinWidth = splitOpen ? 560 : 320;
|
|
5798
|
+
const gapCount = splitOpen ? (sidePanelVisible ? 3 : 2) : (sidePanelVisible ? 2 : 1);
|
|
5799
|
+
const available = layoutWidth - sidePanelWidth - primaryMinWidth - (gap * gapCount);
|
|
5800
|
+
return Math.max(FILE_VIEWER_WIDTH_MIN_PX, Math.min(Math.floor(layoutWidth * 0.78), Math.floor(available)));
|
|
5801
|
+
}
|
|
5802
|
+
|
|
5803
|
+
function clampFileViewerWidth(width) {
|
|
5804
|
+
const number = Number(width);
|
|
5805
|
+
const max = fileViewerMaxWidth();
|
|
5806
|
+
const fallback = readStoredFileViewerWidth() || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
5807
|
+
return Math.max(FILE_VIEWER_WIDTH_MIN_PX, Math.min(max, Number.isFinite(number) ? number : fallback));
|
|
5808
|
+
}
|
|
5809
|
+
|
|
5810
|
+
function currentFileViewerWidth() {
|
|
5811
|
+
const width = elements.fileViewerPane?.getBoundingClientRect?.().width;
|
|
5812
|
+
return Number.isFinite(width) && width > 0 ? width : readStoredFileViewerWidth() || FILE_VIEWER_WIDTH_DEFAULT_PX;
|
|
5813
|
+
}
|
|
5814
|
+
|
|
5815
|
+
function updateFileViewerResizeHandle(width = currentFileViewerWidth()) {
|
|
5816
|
+
const handle = elements.fileViewerResizeHandle;
|
|
5817
|
+
if (!handle) return;
|
|
5818
|
+
const resizeAvailable = !!activeFileViewer && !isSidePanelOverlayView();
|
|
5819
|
+
handle.hidden = !resizeAvailable;
|
|
5820
|
+
handle.setAttribute("aria-valuemin", String(FILE_VIEWER_WIDTH_MIN_PX));
|
|
5821
|
+
handle.setAttribute("aria-valuemax", String(fileViewerMaxWidth()));
|
|
5822
|
+
handle.setAttribute("aria-valuenow", String(Math.round(width)));
|
|
5823
|
+
handle.setAttribute("aria-valuetext", `${Math.round(width)} pixels wide`);
|
|
5824
|
+
}
|
|
5825
|
+
|
|
5826
|
+
function applyFileViewerWidth(width, { persist = false } = {}) {
|
|
5827
|
+
const clamped = clampFileViewerWidth(width);
|
|
5828
|
+
document.documentElement.style.setProperty("--file-viewer-width", `${Math.round(clamped)}px`);
|
|
5829
|
+
updateFileViewerResizeHandle(clamped);
|
|
5830
|
+
if (persist) persistFileViewerWidth(clamped);
|
|
5831
|
+
return clamped;
|
|
5832
|
+
}
|
|
5833
|
+
|
|
5834
|
+
function restoreFileViewerWidthPreference() {
|
|
5835
|
+
const width = readStoredFileViewerWidth();
|
|
5836
|
+
if (width) document.documentElement.style.setProperty("--file-viewer-width", `${Math.round(width)}px`);
|
|
5837
|
+
updateFileViewerResizeHandle(width || FILE_VIEWER_WIDTH_DEFAULT_PX);
|
|
5838
|
+
}
|
|
5839
|
+
|
|
5840
|
+
function beginFileViewerResize(event) {
|
|
5841
|
+
if (!activeFileViewer || isSidePanelOverlayView()) return;
|
|
5842
|
+
if (event.button !== undefined && event.button !== 0) return;
|
|
5843
|
+
event.preventDefault();
|
|
5844
|
+
const startWidth = currentFileViewerWidth();
|
|
5845
|
+
fileViewerResizeState = { pointerId: event.pointerId, startX: event.clientX, startWidth, width: startWidth };
|
|
5846
|
+
document.body.classList.add("file-viewer-resizing");
|
|
5847
|
+
elements.fileViewerResizeHandle?.setPointerCapture?.(event.pointerId);
|
|
5848
|
+
window.addEventListener("pointermove", updateFileViewerResize, { passive: false });
|
|
5849
|
+
window.addEventListener("pointerup", finishFileViewerResize, { passive: false });
|
|
5850
|
+
window.addEventListener("pointercancel", finishFileViewerResize, { passive: false });
|
|
5851
|
+
}
|
|
5852
|
+
|
|
5853
|
+
function updateFileViewerResize(event) {
|
|
5854
|
+
const state = fileViewerResizeState;
|
|
5855
|
+
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
5856
|
+
event.preventDefault();
|
|
5857
|
+
state.width = applyFileViewerWidth(state.startWidth + (state.startX - event.clientX));
|
|
5858
|
+
}
|
|
5859
|
+
|
|
5860
|
+
function finishFileViewerResize(event) {
|
|
5861
|
+
const state = fileViewerResizeState;
|
|
5862
|
+
if (!state || (event.pointerId !== undefined && event.pointerId !== state.pointerId)) return;
|
|
5863
|
+
event.preventDefault?.();
|
|
5864
|
+
elements.fileViewerResizeHandle?.releasePointerCapture?.(state.pointerId);
|
|
5865
|
+
window.removeEventListener("pointermove", updateFileViewerResize);
|
|
5866
|
+
window.removeEventListener("pointerup", finishFileViewerResize);
|
|
5867
|
+
window.removeEventListener("pointercancel", finishFileViewerResize);
|
|
5868
|
+
document.body.classList.remove("file-viewer-resizing");
|
|
5869
|
+
applyFileViewerWidth(state.width, { persist: true });
|
|
5870
|
+
fileViewerResizeState = null;
|
|
5871
|
+
}
|
|
5872
|
+
|
|
5873
|
+
function handleFileViewerResizeKeydown(event) {
|
|
5874
|
+
if (!activeFileViewer || isSidePanelOverlayView()) return;
|
|
5875
|
+
const step = event.shiftKey ? 80 : 24;
|
|
5876
|
+
const current = currentFileViewerWidth();
|
|
5877
|
+
let next = current;
|
|
5878
|
+
if (event.key === "ArrowLeft") next = current + step;
|
|
5879
|
+
else if (event.key === "ArrowRight") next = current - step;
|
|
5880
|
+
else if (event.key === "Home") next = FILE_VIEWER_WIDTH_MIN_PX;
|
|
5881
|
+
else if (event.key === "End") next = fileViewerMaxWidth();
|
|
5882
|
+
else return;
|
|
5883
|
+
event.preventDefault();
|
|
5884
|
+
applyFileViewerWidth(next, { persist: true });
|
|
5885
|
+
}
|
|
5886
|
+
|
|
5887
|
+
function syncFileViewerWidthForViewport() {
|
|
5888
|
+
if (!activeFileViewer) {
|
|
5889
|
+
updateFileViewerResizeHandle();
|
|
5890
|
+
return;
|
|
5891
|
+
}
|
|
5892
|
+
if (isSidePanelOverlayView()) {
|
|
5893
|
+
updateFileViewerResizeHandle();
|
|
5894
|
+
return;
|
|
5895
|
+
}
|
|
5896
|
+
applyFileViewerWidth(currentFileViewerWidth());
|
|
5897
|
+
}
|
|
5898
|
+
|
|
5899
|
+
async function openFileTreeEntryInWebui(entry = fileContextMenuState?.entry) {
|
|
5900
|
+
if (!entry) return;
|
|
5901
|
+
const path = normalizeFileTreePath(entry.path || "");
|
|
5902
|
+
if (entry.type === "directory" || entry.directory === true) {
|
|
5903
|
+
if (fileTreeState.searchQuery || fileTreeSearchQueryText()) return revealFileTreeEntry(entry);
|
|
5904
|
+
fileTreeState.expanded.add(path);
|
|
5905
|
+
await loadFileTreeDirectory(path);
|
|
5906
|
+
return;
|
|
5907
|
+
}
|
|
5908
|
+
await openFileInViewer(path);
|
|
5909
|
+
}
|
|
5910
|
+
|
|
5911
|
+
function setFileViewerMode(mode = "source") {
|
|
5912
|
+
if (!activeFileViewer) return;
|
|
5913
|
+
const nextMode = mode === "preview" && activeFileViewer.language === "markdown" ? "preview" : "source";
|
|
5914
|
+
activeFileViewer.mode = nextMode;
|
|
5915
|
+
updateFileViewerUi();
|
|
5916
|
+
}
|
|
5917
|
+
|
|
5918
|
+
function setFileViewerDirty(dirty) {
|
|
5919
|
+
if (!activeFileViewer) return;
|
|
5920
|
+
activeFileViewer.dirty = !!dirty;
|
|
5921
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = !activeFileViewer.dirty;
|
|
5922
|
+
if (activeFileViewer.dirty) setFileViewerStatus("Unsaved file edits.", "warn");
|
|
5923
|
+
}
|
|
5924
|
+
|
|
5925
|
+
function updateFileViewerUi() {
|
|
5926
|
+
const open = !!activeFileViewer;
|
|
5927
|
+
document.body.classList.toggle("file-viewer-open", open);
|
|
5928
|
+
if (elements.fileViewerPane) elements.fileViewerPane.hidden = !open;
|
|
5929
|
+
updateFileViewerResizeHandle();
|
|
5930
|
+
if (!open) return;
|
|
5931
|
+
if (!isSidePanelOverlayView()) applyFileViewerWidth(currentFileViewerWidth());
|
|
5932
|
+
const viewer = activeFileViewer;
|
|
5933
|
+
const isMarkdown = viewer.language === "markdown";
|
|
5934
|
+
const mode = viewer.mode === "preview" && isMarkdown ? "preview" : "source";
|
|
5935
|
+
viewer.mode = mode;
|
|
5936
|
+
if (elements.fileViewerTitle) elements.fileViewerTitle.textContent = viewer.name || fileDisplayName(viewer.path);
|
|
5937
|
+
if (elements.fileViewerMeta) {
|
|
5938
|
+
const lineCount = textLineCount(viewer.content || "");
|
|
5939
|
+
elements.fileViewerMeta.textContent = [viewer.path, formatBytes(viewer.size), `${lineCount} ${lineCount === 1 ? "line" : "lines"}`].filter(Boolean).join(" · ");
|
|
5940
|
+
}
|
|
5941
|
+
if (elements.fileViewerSourceModeButton) {
|
|
5942
|
+
elements.fileViewerSourceModeButton.setAttribute("aria-pressed", mode === "source" ? "true" : "false");
|
|
5943
|
+
elements.fileViewerSourceModeButton.classList.toggle("active", mode === "source");
|
|
5944
|
+
}
|
|
5945
|
+
if (elements.fileViewerPreviewModeButton) {
|
|
5946
|
+
elements.fileViewerPreviewModeButton.hidden = !isMarkdown;
|
|
5947
|
+
elements.fileViewerPreviewModeButton.disabled = !isMarkdown;
|
|
5948
|
+
elements.fileViewerPreviewModeButton.setAttribute("aria-pressed", mode === "preview" ? "true" : "false");
|
|
5949
|
+
elements.fileViewerPreviewModeButton.classList.toggle("active", mode === "preview");
|
|
5950
|
+
}
|
|
5951
|
+
if (elements.fileViewerEditor) {
|
|
5952
|
+
elements.fileViewerEditor.hidden = mode !== "source";
|
|
5953
|
+
if (elements.fileViewerEditor.value !== viewer.content) elements.fileViewerEditor.value = viewer.content || "";
|
|
5954
|
+
}
|
|
5955
|
+
if (elements.fileViewerPreview) {
|
|
5956
|
+
elements.fileViewerPreview.hidden = mode !== "preview";
|
|
5957
|
+
if (mode === "preview") renderMarkdown(elements.fileViewerPreview, viewer.content || "");
|
|
5958
|
+
}
|
|
5959
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = !viewer.dirty;
|
|
5960
|
+
if (elements.fileViewerOpenDefaultButton) {
|
|
5961
|
+
const viewerPath = normalizeFileTreePath(viewer.path || "");
|
|
5962
|
+
elements.fileViewerOpenDefaultButton.dataset.path = viewerPath;
|
|
5963
|
+
elements.fileViewerOpenDefaultButton.disabled = !viewerPath;
|
|
5964
|
+
}
|
|
5965
|
+
renderFileViewerSelectionBar();
|
|
5966
|
+
}
|
|
5967
|
+
|
|
5968
|
+
function clearFileViewerSelection() {
|
|
5969
|
+
fileViewerSelection = null;
|
|
5970
|
+
renderFileViewerSelectionBar();
|
|
5971
|
+
}
|
|
5972
|
+
|
|
5973
|
+
function selectedTextFromEditor() {
|
|
5974
|
+
const editor = elements.fileViewerEditor;
|
|
5975
|
+
if (!editor || editor.hidden || !activeFileViewer) return null;
|
|
5976
|
+
const start = editor.selectionStart;
|
|
5977
|
+
const end = editor.selectionEnd;
|
|
5978
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return null;
|
|
5979
|
+
return { start, end, text: editor.value.slice(start, end) };
|
|
5980
|
+
}
|
|
5981
|
+
|
|
5982
|
+
function lineColumnForOffset(text, offset) {
|
|
5983
|
+
const prefix = String(text || "").slice(0, Math.max(0, offset));
|
|
5984
|
+
const lines = prefix.split("\n");
|
|
5985
|
+
return { line: lines.length, column: (lines.at(-1) || "").length + 1 };
|
|
5986
|
+
}
|
|
5987
|
+
|
|
5988
|
+
function fileSelectionLineRange(text, start, end) {
|
|
5989
|
+
const startPos = lineColumnForOffset(text, start);
|
|
5990
|
+
const endPos = lineColumnForOffset(text, end);
|
|
5991
|
+
return { startLine: startPos.line, endLine: endPos.line, startColumn: startPos.column, endColumn: endPos.column };
|
|
5992
|
+
}
|
|
5993
|
+
|
|
5994
|
+
function fileSelectionContext(text, start, end, radius = FILE_VIEWER_CONTEXT_RADIUS_LINES) {
|
|
5995
|
+
const value = String(text || "");
|
|
5996
|
+
const lines = value.split("\n");
|
|
5997
|
+
const range = fileSelectionLineRange(value, start, end);
|
|
5998
|
+
const fromLine = Math.max(1, range.startLine - radius);
|
|
5999
|
+
const toLine = Math.min(lines.length, range.endLine + radius);
|
|
6000
|
+
const contextLines = [];
|
|
6001
|
+
for (let line = fromLine; line <= toLine; line += 1) {
|
|
6002
|
+
contextLines.push(`${String(line).padStart(4, " ")}: ${lines[line - 1] || ""}`);
|
|
6003
|
+
}
|
|
6004
|
+
return { ...range, fromLine, toLine, context: contextLines.join("\n") };
|
|
6005
|
+
}
|
|
6006
|
+
|
|
6007
|
+
function updateFileViewerSelectionFromEditor() {
|
|
6008
|
+
if (!activeFileViewer) return;
|
|
6009
|
+
const selected = selectedTextFromEditor();
|
|
6010
|
+
if (!selected || !selected.text.trim()) {
|
|
6011
|
+
clearFileViewerSelection();
|
|
6012
|
+
return;
|
|
6013
|
+
}
|
|
6014
|
+
const context = fileSelectionContext(elements.fileViewerEditor.value || "", selected.start, selected.end);
|
|
6015
|
+
fileViewerSelection = { ...context, ...selected, path: activeFileViewer.path, fileName: activeFileViewer.name };
|
|
6016
|
+
renderFileViewerSelectionBar();
|
|
6017
|
+
}
|
|
6018
|
+
|
|
6019
|
+
function updateFileViewerSelectionFromPreview() {
|
|
6020
|
+
if (!activeFileViewer || elements.fileViewerPreview?.hidden) return;
|
|
6021
|
+
const selection = window.getSelection?.();
|
|
6022
|
+
const preview = elements.fileViewerPreview;
|
|
6023
|
+
if (!preview || !selection?.anchorNode || !selection?.focusNode || !preview.contains(selection.anchorNode) || !preview.contains(selection.focusNode)) return;
|
|
6024
|
+
const text = String(selection.toString?.() || "").trim();
|
|
6025
|
+
if (!text) {
|
|
6026
|
+
clearFileViewerSelection();
|
|
6027
|
+
return;
|
|
6028
|
+
}
|
|
6029
|
+
const content = activeFileViewer.content || "";
|
|
6030
|
+
const start = Math.max(0, content.indexOf(text));
|
|
6031
|
+
const end = start >= 0 ? start + text.length : start;
|
|
6032
|
+
const context = start >= 0
|
|
6033
|
+
? fileSelectionContext(content, start, end)
|
|
6034
|
+
: { startLine: 1, endLine: textLineCount(content), startColumn: 1, endColumn: 1, fromLine: 1, toLine: textLineCount(content), context: content.slice(0, 4000) };
|
|
6035
|
+
fileViewerSelection = { ...context, start, end, text, path: activeFileViewer.path, fileName: activeFileViewer.name };
|
|
6036
|
+
renderFileViewerSelectionBar();
|
|
6037
|
+
}
|
|
6038
|
+
|
|
6039
|
+
function renderFileViewerSelectionBar() {
|
|
6040
|
+
if (!elements.fileSelectionBar) return;
|
|
6041
|
+
const hasSelection = !!fileViewerSelection?.text;
|
|
6042
|
+
elements.fileSelectionBar.hidden = !hasSelection;
|
|
6043
|
+
if (!hasSelection) return;
|
|
6044
|
+
const lineLabel = fileViewerSelection.startLine === fileViewerSelection.endLine
|
|
6045
|
+
? `line ${fileViewerSelection.startLine}`
|
|
6046
|
+
: `lines ${fileViewerSelection.startLine}-${fileViewerSelection.endLine}`;
|
|
6047
|
+
if (elements.fileSelectionSummary) elements.fileSelectionSummary.textContent = `${lineLabel} · ${fileViewerSelection.text.length} chars selected`;
|
|
6048
|
+
}
|
|
6049
|
+
|
|
6050
|
+
function fileSelectionPrompt() {
|
|
6051
|
+
if (!activeFileViewer || !fileViewerSelection?.text) return "";
|
|
6052
|
+
const comment = (elements.fileSelectionCommentInput?.value || "").trim();
|
|
6053
|
+
const selection = fileViewerSelection;
|
|
6054
|
+
const range = selection.startLine === selection.endLine
|
|
6055
|
+
? `line ${selection.startLine}, columns ${selection.startColumn}-${selection.endColumn}`
|
|
6056
|
+
: `lines ${selection.startLine}-${selection.endLine}`;
|
|
6057
|
+
return [
|
|
6058
|
+
`File selection from ${activeFileViewer.path} (${range}).`,
|
|
6059
|
+
comment ? `User comment: ${comment}` : "User comment: <none>",
|
|
6060
|
+
"",
|
|
6061
|
+
"Selected text:",
|
|
6062
|
+
"```",
|
|
6063
|
+
selection.text,
|
|
6064
|
+
"```",
|
|
6065
|
+
"",
|
|
6066
|
+
`Surrounding context (${selection.fromLine}-${selection.toLine}):`,
|
|
6067
|
+
"```",
|
|
6068
|
+
selection.context || selection.text,
|
|
6069
|
+
"```",
|
|
6070
|
+
].join("\n");
|
|
6071
|
+
}
|
|
6072
|
+
|
|
6073
|
+
async function sendFileSelectionToSession() {
|
|
6074
|
+
const prompt = fileSelectionPrompt();
|
|
6075
|
+
if (!prompt) return;
|
|
6076
|
+
if (elements.fileSelectionSendButton) elements.fileSelectionSendButton.disabled = true;
|
|
6077
|
+
try {
|
|
6078
|
+
await sendPrompt("prompt", prompt, { targetTabId: activeTabId, throwOnError: true });
|
|
6079
|
+
if (elements.fileSelectionCommentInput) elements.fileSelectionCommentInput.value = "";
|
|
6080
|
+
setFileViewerStatus("Selection sent to the current Pi session.", "success");
|
|
6081
|
+
} catch (error) {
|
|
6082
|
+
setFileViewerStatus(error.message || String(error), "error");
|
|
6083
|
+
} finally {
|
|
6084
|
+
if (elements.fileSelectionSendButton) elements.fileSelectionSendButton.disabled = false;
|
|
6085
|
+
}
|
|
6086
|
+
}
|
|
6087
|
+
|
|
6088
|
+
function closeFileViewer() {
|
|
6089
|
+
activeFileViewer = null;
|
|
6090
|
+
clearFileViewerSelection();
|
|
6091
|
+
document.body.classList.remove("file-viewer-open");
|
|
6092
|
+
updateFileViewerResizeHandle();
|
|
6093
|
+
if (elements.fileViewerPane) elements.fileViewerPane.hidden = true;
|
|
6094
|
+
if (elements.fileViewerOpenDefaultButton) elements.fileViewerOpenDefaultButton.dataset.path = "";
|
|
6095
|
+
if (elements.fileViewerEditor) elements.fileViewerEditor.value = "";
|
|
6096
|
+
if (elements.fileViewerPreview) elements.fileViewerPreview.replaceChildren();
|
|
6097
|
+
setFileViewerStatus("");
|
|
6098
|
+
}
|
|
6099
|
+
|
|
6100
|
+
async function openFileInViewer(path = "") {
|
|
6101
|
+
const normalized = normalizeFileTreePath(path);
|
|
6102
|
+
if (!normalized) return;
|
|
6103
|
+
const tabContext = activeTabContext();
|
|
6104
|
+
fileTreeState.selectedPath = normalized;
|
|
6105
|
+
renderFileTree();
|
|
6106
|
+
setFileViewerStatus(`Opening ${normalized}…`);
|
|
6107
|
+
try {
|
|
6108
|
+
const response = await api(fileApiPath("/api/files/content", normalized), { tabId: tabContext.tabId });
|
|
6109
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
6110
|
+
const data = response.data || {};
|
|
6111
|
+
activeFileViewer = {
|
|
6112
|
+
path: normalizeFileTreePath(data.path || normalized),
|
|
6113
|
+
name: data.name || fileDisplayName(normalized),
|
|
6114
|
+
content: String(data.content || ""),
|
|
6115
|
+
size: Number(data.size) || 0,
|
|
6116
|
+
mtimeMs: Number(data.mtimeMs) || 0,
|
|
6117
|
+
extension: data.extension || "",
|
|
6118
|
+
language: data.language || "text",
|
|
6119
|
+
mode: data.language === "markdown" ? "preview" : "source",
|
|
6120
|
+
dirty: false,
|
|
6121
|
+
};
|
|
6122
|
+
if (elements.fileViewerEditor) elements.fileViewerEditor.value = activeFileViewer.content;
|
|
6123
|
+
clearFileViewerSelection();
|
|
6124
|
+
updateFileViewerUi();
|
|
6125
|
+
setFileViewerStatus("Opened in WebUI.", "success");
|
|
6126
|
+
} catch (error) {
|
|
6127
|
+
if (isCurrentTabContext(tabContext)) {
|
|
6128
|
+
setFileViewerStatus(error.message || String(error), "error");
|
|
6129
|
+
addEvent(`file open failed: ${error.message || String(error)}`, "error");
|
|
6130
|
+
}
|
|
6131
|
+
}
|
|
6132
|
+
}
|
|
6133
|
+
|
|
6134
|
+
async function saveActiveFileViewer() {
|
|
6135
|
+
if (!activeFileViewer || !elements.fileViewerEditor) return;
|
|
6136
|
+
const tabContext = activeTabContext();
|
|
6137
|
+
const content = elements.fileViewerEditor.value || "";
|
|
6138
|
+
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = true;
|
|
6139
|
+
setFileViewerStatus(`Saving ${activeFileViewer.path}…`);
|
|
6140
|
+
try {
|
|
6141
|
+
const response = await api("/api/files/content", { method: "POST", body: { path: activeFileViewer.path, content, mtimeMs: activeFileViewer.mtimeMs }, tabId: tabContext.tabId });
|
|
6142
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
6143
|
+
const data = response.data || {};
|
|
6144
|
+
activeFileViewer = { ...activeFileViewer, ...data, path: normalizeFileTreePath(data.path || activeFileViewer.path), content, dirty: false };
|
|
6145
|
+
updateFileViewerUi();
|
|
6146
|
+
await loadFileTreeDirectory(fileParentPath(activeFileViewer.path), { force: true });
|
|
6147
|
+
setFileViewerStatus("Saved.", "success");
|
|
6148
|
+
} catch (error) {
|
|
6149
|
+
if (isCurrentTabContext(tabContext)) setFileViewerStatus(error.message || String(error), "error");
|
|
6150
|
+
if (activeFileViewer && elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = false;
|
|
6151
|
+
}
|
|
6152
|
+
}
|
|
6153
|
+
|
|
5297
6154
|
function eventTargetsActiveTab(event) {
|
|
5298
6155
|
return !event?.tabId || event.tabId === activeTabId;
|
|
5299
6156
|
}
|
|
@@ -5398,6 +6255,23 @@ function applyResponseTab(response) {
|
|
|
5398
6255
|
return applyTabMetadata(response?.tab || response?.data?.tab);
|
|
5399
6256
|
}
|
|
5400
6257
|
|
|
6258
|
+
function syncResponseTabs(response) {
|
|
6259
|
+
const payload = response?.data || {};
|
|
6260
|
+
if (Array.isArray(payload.tabs)) {
|
|
6261
|
+
tabs = payload.tabs;
|
|
6262
|
+
syncTabMetadata(tabs);
|
|
6263
|
+
}
|
|
6264
|
+
const tab = response?.tab || payload.tab || null;
|
|
6265
|
+
if (tab) applyTabMetadata(tab);
|
|
6266
|
+
return tab;
|
|
6267
|
+
}
|
|
6268
|
+
|
|
6269
|
+
async function switchToResponseTab(response) {
|
|
6270
|
+
const tab = syncResponseTabs(response);
|
|
6271
|
+
if (tab?.id) await switchTab(tab.id);
|
|
6272
|
+
return tab;
|
|
6273
|
+
}
|
|
6274
|
+
|
|
5401
6275
|
function activityForTab(tab) {
|
|
5402
6276
|
if (!tab?.id) return normalizeTabActivity();
|
|
5403
6277
|
return tabActivities.get(tab.id) || setTabActivity(tab.id, tab.activity) || normalizeTabActivity();
|
|
@@ -5753,6 +6627,8 @@ function resetActiveTabUi() {
|
|
|
5753
6627
|
latestWorkspace = null;
|
|
5754
6628
|
latestMessages = [];
|
|
5755
6629
|
latestMessagesSessionKey = "";
|
|
6630
|
+
closeFileViewer();
|
|
6631
|
+
resetFileTreeState();
|
|
5756
6632
|
clearRunIndicatorActivity({ render: false });
|
|
5757
6633
|
statusEntries.clear();
|
|
5758
6634
|
restoreWidgetsForActiveTab();
|
|
@@ -10585,6 +11461,137 @@ function initializeCodexUsage() {
|
|
|
10585
11461
|
codexUsageRenderTimer = setInterval(renderCodexUsage, CODEX_USAGE_RENDER_TICK_MS);
|
|
10586
11462
|
}
|
|
10587
11463
|
|
|
11464
|
+
function claudeUsageResetDate(window) {
|
|
11465
|
+
const resetAt = window?.resetsAt ? new Date(window.resetsAt) : null;
|
|
11466
|
+
if (resetAt && Number.isFinite(resetAt.getTime())) return resetAt;
|
|
11467
|
+
const resetAfterSeconds = Number(window?.resetAfterSeconds);
|
|
11468
|
+
if (Number.isFinite(resetAfterSeconds) && resetAfterSeconds >= 0) return new Date(Date.now() + resetAfterSeconds * 1000);
|
|
11469
|
+
return null;
|
|
11470
|
+
}
|
|
11471
|
+
|
|
11472
|
+
function formatClaudeUsageReset(window) {
|
|
11473
|
+
const resetDate = claudeUsageResetDate(window);
|
|
11474
|
+
if (resetDate) {
|
|
11475
|
+
const diff = resetDate.getTime() - Date.now();
|
|
11476
|
+
if (diff <= 0) return "resetting now";
|
|
11477
|
+
return `resets in ${formatDurationParts(diff)}`;
|
|
11478
|
+
}
|
|
11479
|
+
return window?.resetText ? `resets ${window.resetText}` : "reset unknown";
|
|
11480
|
+
}
|
|
11481
|
+
|
|
11482
|
+
function renderClaudeUsageWindow(box, window) {
|
|
11483
|
+
const usedPercent = Number(window?.usedPercent);
|
|
11484
|
+
const fillPercent = Number.isFinite(usedPercent) ? Math.max(0, Math.min(100, usedPercent)) : 0;
|
|
11485
|
+
const item = make("div", "claude-usage-bucket");
|
|
11486
|
+
const row = make("div", "claude-usage-row");
|
|
11487
|
+
row.append(
|
|
11488
|
+
make("span", "claude-usage-label", window?.label || "Usage window"),
|
|
11489
|
+
make("strong", "claude-usage-percent", formatCodexPercent(usedPercent)),
|
|
11490
|
+
);
|
|
11491
|
+
const meter = make("div", "claude-usage-meter");
|
|
11492
|
+
const fill = make("span", "claude-usage-meter-fill");
|
|
11493
|
+
fill.style.width = `${fillPercent}%`;
|
|
11494
|
+
meter.append(fill);
|
|
11495
|
+
item.append(row, meter, make("div", "claude-usage-reset", formatClaudeUsageReset(window)));
|
|
11496
|
+
box.append(item);
|
|
11497
|
+
}
|
|
11498
|
+
|
|
11499
|
+
function renderClaudeUsageActivity(box, activity) {
|
|
11500
|
+
if (!Array.isArray(activity) || activity.length === 0) return;
|
|
11501
|
+
const title = make("div", "claude-usage-activity-title", latestClaudeUsage?.activityTitle || "What's contributing to your limits usage?");
|
|
11502
|
+
box.append(title);
|
|
11503
|
+
for (const item of activity.slice(0, 2)) {
|
|
11504
|
+
const group = make("div", "claude-usage-activity-group");
|
|
11505
|
+
const row = make("div", "claude-usage-row");
|
|
11506
|
+
row.append(
|
|
11507
|
+
make("span", "claude-usage-label", item.label || "Activity"),
|
|
11508
|
+
make("span", "claude-usage-reset", `${Number(item.requests || 0)} requests · ${Number(item.sessions || 0)} sessions`),
|
|
11509
|
+
);
|
|
11510
|
+
group.append(row);
|
|
11511
|
+
for (const detail of (Array.isArray(item.details) ? item.details : []).slice(0, 4)) {
|
|
11512
|
+
group.append(make("div", "claude-usage-detail", detail?.text || String(detail || "")));
|
|
11513
|
+
}
|
|
11514
|
+
box.append(group);
|
|
11515
|
+
}
|
|
11516
|
+
}
|
|
11517
|
+
|
|
11518
|
+
function renderClaudeUsage() {
|
|
11519
|
+
const box = elements.claudeUsageBox;
|
|
11520
|
+
if (!box) return;
|
|
11521
|
+
if (elements.refreshClaudeUsageButton) {
|
|
11522
|
+
elements.refreshClaudeUsageButton.disabled = claudeUsageLoading;
|
|
11523
|
+
elements.refreshClaudeUsageButton.textContent = claudeUsageLoading ? "Refreshing…" : "Refresh usage";
|
|
11524
|
+
}
|
|
11525
|
+
|
|
11526
|
+
box.replaceChildren();
|
|
11527
|
+
box.classList.toggle("muted", !latestClaudeUsage);
|
|
11528
|
+
|
|
11529
|
+
if (!latestClaudeUsage && claudeUsageLoading) {
|
|
11530
|
+
box.textContent = "Checking Claude usage…";
|
|
11531
|
+
return;
|
|
11532
|
+
}
|
|
11533
|
+
if (!latestClaudeUsage && claudeUsageError) {
|
|
11534
|
+
const title = make("div", "claude-usage-unavailable", "Usage unavailable");
|
|
11535
|
+
const detail = make("div", "claude-usage-detail", claudeUsageError.message || String(claudeUsageError));
|
|
11536
|
+
box.append(title, detail);
|
|
11537
|
+
return;
|
|
11538
|
+
}
|
|
11539
|
+
if (!latestClaudeUsage) {
|
|
11540
|
+
box.textContent = "Claude usage has not loaded yet.";
|
|
11541
|
+
return;
|
|
11542
|
+
}
|
|
11543
|
+
|
|
11544
|
+
const header = make("div", "claude-usage-summary");
|
|
11545
|
+
header.append(
|
|
11546
|
+
make("span", "claude-usage-plan", "Claude Code"),
|
|
11547
|
+
make("span", "claude-usage-fetched", latestClaudeUsage.fetchedAt ? `updated ${formatDurationParts(Date.now() - new Date(latestClaudeUsage.fetchedAt).getTime())} ago` : "updated now"),
|
|
11548
|
+
);
|
|
11549
|
+
box.append(header);
|
|
11550
|
+
|
|
11551
|
+
if (latestClaudeUsage.summary) box.append(make("div", "claude-usage-detail", latestClaudeUsage.summary));
|
|
11552
|
+
const windows = Array.isArray(latestClaudeUsage.windows) ? latestClaudeUsage.windows : [];
|
|
11553
|
+
if (windows.length === 0) {
|
|
11554
|
+
box.append(make("div", "claude-usage-detail", "No Claude usage windows were returned."));
|
|
11555
|
+
} else {
|
|
11556
|
+
for (const window of windows.slice(0, 6)) renderClaudeUsageWindow(box, window);
|
|
11557
|
+
}
|
|
11558
|
+
|
|
11559
|
+
renderClaudeUsageActivity(box, latestClaudeUsage.activity);
|
|
11560
|
+
if (claudeUsageError) {
|
|
11561
|
+
box.append(make("div", "claude-usage-detail", `Latest refresh failed: ${claudeUsageError.message || claudeUsageError}`));
|
|
11562
|
+
}
|
|
11563
|
+
}
|
|
11564
|
+
|
|
11565
|
+
async function refreshClaudeUsage() {
|
|
11566
|
+
if (claudeUsageLoading) return;
|
|
11567
|
+
claudeUsageLoading = true;
|
|
11568
|
+
renderClaudeUsage();
|
|
11569
|
+
try {
|
|
11570
|
+
const response = await api("/api/claude-usage", { scoped: false });
|
|
11571
|
+
latestClaudeUsage = response.data || null;
|
|
11572
|
+
claudeUsageError = null;
|
|
11573
|
+
} catch (error) {
|
|
11574
|
+
claudeUsageError = error;
|
|
11575
|
+
} finally {
|
|
11576
|
+
claudeUsageLoading = false;
|
|
11577
|
+
renderClaudeUsage();
|
|
11578
|
+
}
|
|
11579
|
+
}
|
|
11580
|
+
|
|
11581
|
+
function scheduleRefreshClaudeUsage(delay = CLAUDE_USAGE_REFRESH_MS) {
|
|
11582
|
+
clearTimeout(refreshClaudeUsageTimer);
|
|
11583
|
+
refreshClaudeUsageTimer = setTimeout(() => {
|
|
11584
|
+
refreshClaudeUsage().finally(() => scheduleRefreshClaudeUsage());
|
|
11585
|
+
}, delay);
|
|
11586
|
+
}
|
|
11587
|
+
|
|
11588
|
+
function initializeClaudeUsage() {
|
|
11589
|
+
renderClaudeUsage();
|
|
11590
|
+
refreshClaudeUsage().finally(() => scheduleRefreshClaudeUsage());
|
|
11591
|
+
clearInterval(claudeUsageRenderTimer);
|
|
11592
|
+
claudeUsageRenderTimer = setInterval(renderClaudeUsage, CLAUDE_USAGE_RENDER_TICK_MS);
|
|
11593
|
+
}
|
|
11594
|
+
|
|
10588
11595
|
function renderStatus() {
|
|
10589
11596
|
if (deferUiRenderDuringPointerActivation("status", renderStatus)) return;
|
|
10590
11597
|
const state = currentState;
|
|
@@ -16065,6 +17072,19 @@ function messageTitle(message) {
|
|
|
16065
17072
|
return message.role || "message";
|
|
16066
17073
|
}
|
|
16067
17074
|
|
|
17075
|
+
function isCompleteUserBashMessage(message) {
|
|
17076
|
+
if (message?.role !== "bashExecution") return false;
|
|
17077
|
+
const title = String(message.title || "").toLowerCase();
|
|
17078
|
+
if (title.includes("queued")) return false;
|
|
17079
|
+
if (title.includes("complete")) return true;
|
|
17080
|
+
if (message.exitCode !== undefined || message.cancelled !== undefined || message.truncated !== undefined || message.fullOutputPath) return true;
|
|
17081
|
+
return !title && message.output !== undefined;
|
|
17082
|
+
}
|
|
17083
|
+
|
|
17084
|
+
function shouldOpenMessageCollapseByDefault(message) {
|
|
17085
|
+
return !!message?.isError || toolOutputGloballyExpanded || isCompleteUserBashMessage(message);
|
|
17086
|
+
}
|
|
17087
|
+
|
|
16068
17088
|
function assistantThinkingText(part) {
|
|
16069
17089
|
if (!part || typeof part !== "object") return "";
|
|
16070
17090
|
if (part.type !== "thinking" && typeof part.thinking !== "string") return "";
|
|
@@ -17245,7 +18265,7 @@ function appendMessage(message, { streaming = false, messageIndex = -1, transien
|
|
|
17245
18265
|
|
|
17246
18266
|
if (isCollapsibleOutput) {
|
|
17247
18267
|
const details = make("details", "message-collapse");
|
|
17248
|
-
if (message
|
|
18268
|
+
if (shouldOpenMessageCollapseByDefault(message)) details.open = true;
|
|
17249
18269
|
details.append(header, body);
|
|
17250
18270
|
bubble.append(details);
|
|
17251
18271
|
if (message.role === "toolResult" && !message.isError) {
|
|
@@ -18251,6 +19271,8 @@ function requestGitFooterWebuiPayload(tabContext = activeTabContext(), { force =
|
|
|
18251
19271
|
}
|
|
18252
19272
|
|
|
18253
19273
|
function updateOptionalFeatureAvailability() {
|
|
19274
|
+
optionalFeatureAvailability.bangCommandAutocomplete = hasAvailableCommand("bang-status") || hasAvailableCommand("bang-refresh");
|
|
19275
|
+
optionalFeatureAvailability.fishUserBash = hasAvailableCommand("user-bash-shell");
|
|
18254
19276
|
optionalFeatureAvailability.btwCommand = hasAvailableCommand("btw") || optionalFeatureAvailability.btwCommand || statusEntries.has(BTW_WEBUI_STATUS_KEY) || widgets.has(BTW_OUTPUT_WIDGET_KEY);
|
|
18255
19277
|
optionalFeatureAvailability.gitWorkflow = hasAvailableCommand("git-staged-msg");
|
|
18256
19278
|
optionalFeatureAvailability.releaseNpm = hasAvailableCommand("release-npm");
|
|
@@ -19013,7 +20035,7 @@ async function openNativeSettingsDialog() {
|
|
|
19013
20035
|
showImages: nativeSettingToggle("Show terminal images", settings.showImages !== false, "Native TUI inline image rendering preference.", { label: "TUI", tone: "tui" }),
|
|
19014
20036
|
imageWidth: nativeSettingSelect("Terminal image width", settings.imageWidthCells || 60, SETTINGS_IMAGE_WIDTH_OPTIONS, "Native TUI inline image width in terminal cells.", { label: "TUI", tone: "tui" }),
|
|
19015
20037
|
skillCommands: nativeSettingToggle("Skill commands", settings.enableSkillCommands !== false, "Register skills as /skill:name commands.", { label: "reload", tone: "reload" }),
|
|
19016
|
-
anthropicWarning: nativeSettingToggle("Anthropic
|
|
20038
|
+
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" }),
|
|
19017
20039
|
collapseChangelog: nativeSettingToggle("Collapse changelog", settings.collapseChangelog === true, "Show condensed changelog after updates.", { label: "startup", tone: "startup" }),
|
|
19018
20040
|
quietStartup: nativeSettingToggle("Quiet startup", settings.quietStartup === true, "Disable verbose printing at startup.", { label: "startup", tone: "startup" }),
|
|
19019
20041
|
installTelemetry: nativeSettingToggle("Install telemetry", settings.enableInstallTelemetry !== false, "Send anonymous version/update ping after changelog-detected updates.", { label: "startup", tone: "startup" }),
|
|
@@ -19088,7 +20110,7 @@ async function openNativeForkSelector() {
|
|
|
19088
20110
|
setNativeCommandError("");
|
|
19089
20111
|
try {
|
|
19090
20112
|
const result = await nativeCommandApi("/api/fork", { method: "POST", body: { entryId: item.message.entryId } });
|
|
19091
|
-
|
|
20113
|
+
await switchToResponseTab(result);
|
|
19092
20114
|
const restoredText = result.data?.text || result.data?.result?.text || "";
|
|
19093
20115
|
if (restoredText) {
|
|
19094
20116
|
elements.promptInput.value = restoredText;
|
|
@@ -19097,7 +20119,6 @@ async function openNativeForkSelector() {
|
|
|
19097
20119
|
}
|
|
19098
20120
|
addTransientMessage({ role: "native", title: "/fork", content: result.data?.message || "Forked the current session.", level: "info" });
|
|
19099
20121
|
closeNativeCommandDialog();
|
|
19100
|
-
await refreshAll();
|
|
19101
20122
|
} catch (error) {
|
|
19102
20123
|
setNativeCommandError(error.message || String(error));
|
|
19103
20124
|
}
|
|
@@ -20596,6 +21617,26 @@ function normalizePathSuggestions(suggestions) {
|
|
|
20596
21617
|
});
|
|
20597
21618
|
}
|
|
20598
21619
|
|
|
21620
|
+
function normalizeBangSuggestions(suggestions) {
|
|
21621
|
+
const seen = new Set();
|
|
21622
|
+
return (suggestions || [])
|
|
21623
|
+
.map((suggestion) => {
|
|
21624
|
+
const insertText = String(suggestion.insertText || suggestion.value || "").trim().replace(/^!+/, "");
|
|
21625
|
+
const label = String(suggestion.label || `!${insertText}`).trim();
|
|
21626
|
+
return {
|
|
21627
|
+
insertText,
|
|
21628
|
+
label,
|
|
21629
|
+
description: String(suggestion.description || "shell command").trim(),
|
|
21630
|
+
kind: String(suggestion.kind || "command").trim(),
|
|
21631
|
+
};
|
|
21632
|
+
})
|
|
21633
|
+
.filter((suggestion) => {
|
|
21634
|
+
if (!suggestion.insertText || seen.has(suggestion.insertText)) return false;
|
|
21635
|
+
seen.add(suggestion.insertText);
|
|
21636
|
+
return true;
|
|
21637
|
+
});
|
|
21638
|
+
}
|
|
21639
|
+
|
|
20599
21640
|
function getCommandTrigger() {
|
|
20600
21641
|
const input = elements.promptInput;
|
|
20601
21642
|
const cursor = input.selectionStart ?? input.value.length;
|
|
@@ -20633,6 +21674,21 @@ function getPathTrigger() {
|
|
|
20633
21674
|
return { start: cursor - query.length - 1, end: cursor, query, quoted: false };
|
|
20634
21675
|
}
|
|
20635
21676
|
|
|
21677
|
+
function getBangTrigger() {
|
|
21678
|
+
const input = elements.promptInput;
|
|
21679
|
+
const cursor = input.selectionStart ?? input.value.length;
|
|
21680
|
+
const selectionEnd = input.selectionEnd ?? cursor;
|
|
21681
|
+
if (cursor !== selectionEnd) return null;
|
|
21682
|
+
|
|
21683
|
+
const beforeCursor = input.value.slice(0, cursor);
|
|
21684
|
+
const match = beforeCursor.match(/^\s*(!!?)([^\n]*)$/);
|
|
21685
|
+
if (!match) return null;
|
|
21686
|
+
const afterBang = match[2] || "";
|
|
21687
|
+
const leadingSpaceLength = afterBang.match(/^\s*/)?.[0]?.length || 0;
|
|
21688
|
+
const query = afterBang.slice(leadingSpaceLength);
|
|
21689
|
+
return { start: cursor - query.length, end: cursor, query, bangPrefix: match[1] };
|
|
21690
|
+
}
|
|
21691
|
+
|
|
20636
21692
|
function scoreCommandSuggestion(command, query) {
|
|
20637
21693
|
if (!query) return 0;
|
|
20638
21694
|
const q = query.toLowerCase();
|
|
@@ -20670,7 +21726,9 @@ function commandMatchesSearch(command, query) {
|
|
|
20670
21726
|
}
|
|
20671
21727
|
|
|
20672
21728
|
function activeSuggestionCount() {
|
|
20673
|
-
|
|
21729
|
+
if (suggestionMode === "path") return pathSuggestions.length;
|
|
21730
|
+
if (suggestionMode === "bang") return bangSuggestions.length;
|
|
21731
|
+
return commandSuggestions.length;
|
|
20674
21732
|
}
|
|
20675
21733
|
|
|
20676
21734
|
function abortPathSuggestionRequest() {
|
|
@@ -20684,13 +21742,26 @@ function cancelPathSuggestionRequest() {
|
|
|
20684
21742
|
abortPathSuggestionRequest();
|
|
20685
21743
|
}
|
|
20686
21744
|
|
|
21745
|
+
function abortBangSuggestionRequest() {
|
|
21746
|
+
bangSuggestAbortController?.abort();
|
|
21747
|
+
bangSuggestAbortController = null;
|
|
21748
|
+
}
|
|
21749
|
+
|
|
21750
|
+
function cancelBangSuggestionRequest() {
|
|
21751
|
+
bangSuggestRequestSerial++;
|
|
21752
|
+
bangSuggestActiveQuery = null;
|
|
21753
|
+
abortBangSuggestionRequest();
|
|
21754
|
+
}
|
|
21755
|
+
|
|
20687
21756
|
function hideCommandSuggestions() {
|
|
20688
21757
|
cancelPathSuggestionRequest();
|
|
21758
|
+
cancelBangSuggestionRequest();
|
|
20689
21759
|
elements.commandSuggest.hidden = true;
|
|
20690
21760
|
elements.commandSuggest.removeAttribute("aria-busy");
|
|
20691
21761
|
elements.commandSuggest.replaceChildren();
|
|
20692
21762
|
commandSuggestions = [];
|
|
20693
21763
|
pathSuggestions = [];
|
|
21764
|
+
bangSuggestions = [];
|
|
20694
21765
|
suggestionMode = "none";
|
|
20695
21766
|
commandSuggestIndex = 0;
|
|
20696
21767
|
scheduleDeferredUiFlushAfterDropdownClose();
|
|
@@ -20739,6 +21810,7 @@ function setActiveCommandSuggestionFromPointerMove(index, event) {
|
|
|
20739
21810
|
function renderCommandSuggestionItems(trigger, { keepIndex = false } = {}) {
|
|
20740
21811
|
suggestionMode = "command";
|
|
20741
21812
|
pathSuggestions = [];
|
|
21813
|
+
bangSuggestions = [];
|
|
20742
21814
|
commandSuggestions = getCommandMatches(trigger.query);
|
|
20743
21815
|
elements.commandSuggest.replaceChildren();
|
|
20744
21816
|
|
|
@@ -20781,6 +21853,7 @@ function formatPathReference(pathText, forceQuoted = false) {
|
|
|
20781
21853
|
function renderPathSuggestionItems(trigger, { keepIndex = false } = {}) {
|
|
20782
21854
|
suggestionMode = "path";
|
|
20783
21855
|
commandSuggestions = [];
|
|
21856
|
+
bangSuggestions = [];
|
|
20784
21857
|
elements.commandSuggest.replaceChildren();
|
|
20785
21858
|
|
|
20786
21859
|
if (pathSuggestions.length === 0) {
|
|
@@ -20811,6 +21884,7 @@ function renderPathSuggestionItems(trigger, { keepIndex = false } = {}) {
|
|
|
20811
21884
|
}
|
|
20812
21885
|
|
|
20813
21886
|
async function renderPathSuggestions(trigger, { keepIndex = false } = {}) {
|
|
21887
|
+
cancelBangSuggestionRequest();
|
|
20814
21888
|
if (suggestionMode === "path" && pathSuggestActiveQuery === trigger.query && !elements.commandSuggest.hidden) {
|
|
20815
21889
|
if (keepIndex && activeSuggestionCount() > 0) setActiveCommandSuggestion(commandSuggestIndex);
|
|
20816
21890
|
return;
|
|
@@ -20849,12 +21923,93 @@ async function renderPathSuggestions(trigger, { keepIndex = false } = {}) {
|
|
|
20849
21923
|
}
|
|
20850
21924
|
}
|
|
20851
21925
|
|
|
21926
|
+
function renderBangSuggestionItems(trigger, { keepIndex = false } = {}) {
|
|
21927
|
+
suggestionMode = "bang";
|
|
21928
|
+
commandSuggestions = [];
|
|
21929
|
+
pathSuggestions = [];
|
|
21930
|
+
elements.commandSuggest.replaceChildren();
|
|
21931
|
+
|
|
21932
|
+
if (bangSuggestions.length === 0) {
|
|
21933
|
+
elements.commandSuggest.append(make("div", "command-suggest-empty", `No shell command matches !${trigger.query}`));
|
|
21934
|
+
elements.commandSuggest.hidden = false;
|
|
21935
|
+
return;
|
|
21936
|
+
}
|
|
21937
|
+
|
|
21938
|
+
for (const [index, suggestion] of bangSuggestions.entries()) {
|
|
21939
|
+
const item = make("button", "command-suggest-item bang-suggest-item");
|
|
21940
|
+
item.type = "button";
|
|
21941
|
+
item.setAttribute("role", "option");
|
|
21942
|
+
item.addEventListener("mousedown", (event) => event.preventDefault());
|
|
21943
|
+
item.addEventListener("pointermove", (event) => setActiveCommandSuggestionFromPointerMove(index, event));
|
|
21944
|
+
item.addEventListener("click", () => insertBangSuggestion(index));
|
|
21945
|
+
|
|
21946
|
+
item.append(
|
|
21947
|
+
make("span", "command-suggest-name bang-suggest-name", suggestion.label || `!${suggestion.insertText}`),
|
|
21948
|
+
make("span", "command-suggest-desc", suggestion.description || "shell command"),
|
|
21949
|
+
make("span", "command-suggest-source", suggestion.kind || "command"),
|
|
21950
|
+
);
|
|
21951
|
+
elements.commandSuggest.append(item);
|
|
21952
|
+
}
|
|
21953
|
+
|
|
21954
|
+
elements.commandSuggest.hidden = false;
|
|
21955
|
+
setActiveCommandSuggestion(keepIndex ? commandSuggestIndex : 0);
|
|
21956
|
+
}
|
|
21957
|
+
|
|
21958
|
+
async function renderBangSuggestions(trigger, { keepIndex = false } = {}) {
|
|
21959
|
+
cancelPathSuggestionRequest();
|
|
21960
|
+
const activeQuery = `${trigger.bangPrefix}\0${trigger.query}`;
|
|
21961
|
+
if (suggestionMode === "bang" && bangSuggestActiveQuery === activeQuery && !elements.commandSuggest.hidden) {
|
|
21962
|
+
if (keepIndex && activeSuggestionCount() > 0) setActiveCommandSuggestion(commandSuggestIndex);
|
|
21963
|
+
return;
|
|
21964
|
+
}
|
|
21965
|
+
|
|
21966
|
+
const keepExistingBangMenu = suggestionMode === "bang" && !elements.commandSuggest.hidden && elements.commandSuggest.childElementCount > 0;
|
|
21967
|
+
abortBangSuggestionRequest();
|
|
21968
|
+
const requestSerial = ++bangSuggestRequestSerial;
|
|
21969
|
+
const controller = new AbortController();
|
|
21970
|
+
bangSuggestActiveQuery = activeQuery;
|
|
21971
|
+
bangSuggestAbortController = controller;
|
|
21972
|
+
suggestionMode = "bang";
|
|
21973
|
+
commandSuggestions = [];
|
|
21974
|
+
pathSuggestions = [];
|
|
21975
|
+
if (!keepExistingBangMenu) {
|
|
21976
|
+
bangSuggestions = [];
|
|
21977
|
+
elements.commandSuggest.replaceChildren(make("div", "command-suggest-empty", "Finding shell commands…"));
|
|
21978
|
+
}
|
|
21979
|
+
elements.commandSuggest.hidden = false;
|
|
21980
|
+
elements.commandSuggest.setAttribute("aria-busy", "true");
|
|
21981
|
+
|
|
21982
|
+
try {
|
|
21983
|
+
const response = await api(`/api/bang-suggestions?query=${encodeURIComponent(trigger.query)}`, { signal: controller.signal });
|
|
21984
|
+
if (requestSerial !== bangSuggestRequestSerial || document.activeElement !== elements.promptInput) return;
|
|
21985
|
+
bangSuggestions = normalizeBangSuggestions(response.data?.suggestions || []);
|
|
21986
|
+
renderBangSuggestionItems(trigger, { keepIndex });
|
|
21987
|
+
} catch (error) {
|
|
21988
|
+
if (error?.name === "AbortError" || requestSerial !== bangSuggestRequestSerial) return;
|
|
21989
|
+
bangSuggestions = [];
|
|
21990
|
+
elements.commandSuggest.replaceChildren(make("div", "command-suggest-empty", `Shell command suggestions unavailable: ${error.message}`));
|
|
21991
|
+
elements.commandSuggest.hidden = false;
|
|
21992
|
+
} finally {
|
|
21993
|
+
if (requestSerial === bangSuggestRequestSerial) {
|
|
21994
|
+
bangSuggestAbortController = null;
|
|
21995
|
+
elements.commandSuggest.removeAttribute("aria-busy");
|
|
21996
|
+
}
|
|
21997
|
+
}
|
|
21998
|
+
}
|
|
21999
|
+
|
|
20852
22000
|
function renderCommandSuggestions({ keepIndex = false } = {}) {
|
|
20853
22001
|
if (document.activeElement !== elements.promptInput) {
|
|
20854
22002
|
hideCommandSuggestions();
|
|
20855
22003
|
return;
|
|
20856
22004
|
}
|
|
20857
22005
|
|
|
22006
|
+
const bangTrigger = getBangTrigger();
|
|
22007
|
+
if (bangTrigger) {
|
|
22008
|
+
if (isOptionalFeatureEnabled("bangCommandAutocomplete")) renderBangSuggestions(bangTrigger, { keepIndex });
|
|
22009
|
+
else hideCommandSuggestions();
|
|
22010
|
+
return;
|
|
22011
|
+
}
|
|
22012
|
+
|
|
20858
22013
|
const pathTrigger = getPathTrigger();
|
|
20859
22014
|
if (pathTrigger) {
|
|
20860
22015
|
renderPathSuggestions(pathTrigger, { keepIndex });
|
|
@@ -20862,6 +22017,7 @@ function renderCommandSuggestions({ keepIndex = false } = {}) {
|
|
|
20862
22017
|
}
|
|
20863
22018
|
|
|
20864
22019
|
cancelPathSuggestionRequest();
|
|
22020
|
+
cancelBangSuggestionRequest();
|
|
20865
22021
|
const trigger = getCommandTrigger();
|
|
20866
22022
|
if (!trigger || availableCommands.length === 0) {
|
|
20867
22023
|
hideCommandSuggestions();
|
|
@@ -20873,6 +22029,7 @@ function renderCommandSuggestions({ keepIndex = false } = {}) {
|
|
|
20873
22029
|
|
|
20874
22030
|
function insertCommandSuggestion(index = commandSuggestIndex) {
|
|
20875
22031
|
if (suggestionMode === "path") return insertPathSuggestion(index);
|
|
22032
|
+
if (suggestionMode === "bang") return insertBangSuggestion(index);
|
|
20876
22033
|
const command = commandSuggestions[index];
|
|
20877
22034
|
const trigger = getCommandTrigger();
|
|
20878
22035
|
if (!command || !trigger) return false;
|
|
@@ -20895,6 +22052,26 @@ function insertCommandSuggestion(index = commandSuggestIndex) {
|
|
|
20895
22052
|
return true;
|
|
20896
22053
|
}
|
|
20897
22054
|
|
|
22055
|
+
function insertBangSuggestion(index = commandSuggestIndex) {
|
|
22056
|
+
const suggestion = bangSuggestions[index];
|
|
22057
|
+
const trigger = getBangTrigger();
|
|
22058
|
+
if (!suggestion || !trigger) return false;
|
|
22059
|
+
|
|
22060
|
+
const input = elements.promptInput;
|
|
22061
|
+
const value = input.value;
|
|
22062
|
+
const suffix = value.slice(trigger.end);
|
|
22063
|
+
const commandText = suggestion.insertText.replace(/^!+/, "");
|
|
22064
|
+
const separator = suggestion.kind === "line" || (suffix && /^\s/.test(suffix)) ? "" : " ";
|
|
22065
|
+
input.value = `${value.slice(0, trigger.start)}${commandText}${separator}${suffix}`;
|
|
22066
|
+
|
|
22067
|
+
const cursor = trigger.start + commandText.length + separator.length;
|
|
22068
|
+
input.setSelectionRange(cursor, cursor);
|
|
22069
|
+
input.focus();
|
|
22070
|
+
resizePromptInput();
|
|
22071
|
+
hideCommandSuggestions();
|
|
22072
|
+
return true;
|
|
22073
|
+
}
|
|
22074
|
+
|
|
20898
22075
|
function insertPathSuggestion(index = commandSuggestIndex) {
|
|
20899
22076
|
const suggestion = pathSuggestions[index];
|
|
20900
22077
|
const trigger = getPathTrigger();
|
|
@@ -21148,6 +22325,7 @@ async function refreshAll(tabContext = activeTabContext()) {
|
|
|
21148
22325
|
refreshNaturalConversationMode(tabContext),
|
|
21149
22326
|
refreshStats(tabContext),
|
|
21150
22327
|
refreshWorkspace(tabContext),
|
|
22328
|
+
refreshFileTreeRoot(tabContext),
|
|
21151
22329
|
refreshAppRunners(tabContext),
|
|
21152
22330
|
refreshNativeSettings(tabContext),
|
|
21153
22331
|
refreshNetworkStatus(),
|
|
@@ -21910,10 +23088,13 @@ function handleEvent(event) {
|
|
|
21910
23088
|
case "webui_cwd_changed":
|
|
21911
23089
|
addEvent(`${event.tabTitle || "terminal"} cwd changed to ${event.cwd}`);
|
|
21912
23090
|
setAppRunnerData(event.tabId || activeTabId, { cwd: event.cwd, activeRun: null, runners: [] });
|
|
23091
|
+
closeFileViewer();
|
|
23092
|
+
resetFileTreeState();
|
|
21913
23093
|
renderAppRunnerControls();
|
|
21914
23094
|
renderWidgets();
|
|
21915
23095
|
renderTabs();
|
|
21916
23096
|
refreshTabs().catch((error) => addEvent(error.message, "error"));
|
|
23097
|
+
refreshFileTreeRoot(tabContext).catch((error) => addEvent(error.message, "error"));
|
|
21917
23098
|
refreshAppRunners(tabContext).catch((error) => addEvent(error.message, "error"));
|
|
21918
23099
|
scheduleRefreshFooter();
|
|
21919
23100
|
break;
|
|
@@ -21995,6 +23176,7 @@ function handleEvent(event) {
|
|
|
21995
23176
|
scheduleRefreshMessages();
|
|
21996
23177
|
scheduleRefreshFooter();
|
|
21997
23178
|
scheduleRefreshCodexUsage(2200);
|
|
23179
|
+
scheduleRefreshClaudeUsage(2200);
|
|
21998
23180
|
renderFeedbackTray();
|
|
21999
23181
|
{
|
|
22000
23182
|
const workflowTabId = event.tabId || activeTabId;
|
|
@@ -22974,6 +24156,9 @@ document.addEventListener("pointerdown", (event) => {
|
|
|
22974
24156
|
setFooterThinkingPickerOpen(false);
|
|
22975
24157
|
setFooterBranchPickerOpen(false);
|
|
22976
24158
|
}
|
|
24159
|
+
if (elements.fileContextMenu && !elements.fileContextMenu.hidden && !event.target?.closest?.(".file-context-menu")) {
|
|
24160
|
+
closeFileContextMenu();
|
|
24161
|
+
}
|
|
22977
24162
|
}, { passive: true });
|
|
22978
24163
|
document.addEventListener("pointermove", (event) => {
|
|
22979
24164
|
if (openTerminalTabGroupKey && !event.target?.closest?.(".terminal-tab-group")) {
|
|
@@ -23168,6 +24353,7 @@ window.addEventListener("online", () => scheduleForegroundReconcile("network onl
|
|
|
23168
24353
|
window.addEventListener("storage", (event) => {
|
|
23169
24354
|
if (event.key === OPTIONAL_FEATURES_STORAGE_KEY) reconcileDisabledOptionalFeaturesFromStorage();
|
|
23170
24355
|
});
|
|
24356
|
+
window.addEventListener("resize", syncFileViewerWidthForViewport, { passive: true });
|
|
23171
24357
|
window.addEventListener("keydown", (event) => {
|
|
23172
24358
|
if (event.key !== "Escape") return;
|
|
23173
24359
|
if (event.defaultPrevented) return;
|
|
@@ -23295,6 +24481,65 @@ elements.gitChangesDialog?.addEventListener("close", () => {
|
|
|
23295
24481
|
elements.refreshCodexUsageButton?.addEventListener("click", () => {
|
|
23296
24482
|
refreshCodexUsage({ forceAuthRefresh: true }).finally(() => scheduleRefreshCodexUsage());
|
|
23297
24483
|
});
|
|
24484
|
+
elements.refreshClaudeUsageButton?.addEventListener("click", () => {
|
|
24485
|
+
refreshClaudeUsage().finally(() => scheduleRefreshClaudeUsage());
|
|
24486
|
+
});
|
|
24487
|
+
elements.fileTreeRefreshButton?.addEventListener("click", () => refreshFileTreeRoot().catch((error) => addEvent(error.message || String(error), "error")));
|
|
24488
|
+
elements.fileTreeSearchInput?.addEventListener("input", () => scheduleFileTreeSearch());
|
|
24489
|
+
elements.fileTreeSearchInput?.addEventListener("keydown", (event) => {
|
|
24490
|
+
if (event.key === "Enter") {
|
|
24491
|
+
event.preventDefault();
|
|
24492
|
+
runFileTreeSearch().catch((error) => addEvent(error.message || String(error), "error"));
|
|
24493
|
+
} else if (event.key === "Escape") {
|
|
24494
|
+
event.preventDefault();
|
|
24495
|
+
clearFileTreeSearch({ focus: true });
|
|
24496
|
+
}
|
|
24497
|
+
});
|
|
24498
|
+
elements.fileTreeSearchClearButton?.addEventListener("click", () => clearFileTreeSearch({ focus: true }));
|
|
24499
|
+
elements.fileContextMenu?.addEventListener("click", (event) => {
|
|
24500
|
+
const button = event.target?.closest?.("[data-file-menu-action]");
|
|
24501
|
+
if (!button) return;
|
|
24502
|
+
const entry = fileContextMenuState?.entry;
|
|
24503
|
+
closeFileContextMenu();
|
|
24504
|
+
if (!entry) return;
|
|
24505
|
+
const action = button.dataset.fileMenuAction || "";
|
|
24506
|
+
if (action === "open-default") openPathInDefaultEditor(entry.path).catch((error) => addEvent(error.message || String(error), "error"));
|
|
24507
|
+
else if (action === "open-webui") openFileTreeEntryInWebui(entry).catch((error) => addEvent(error.message || String(error), "error"));
|
|
24508
|
+
});
|
|
24509
|
+
elements.fileViewerOpenDefaultButton?.addEventListener("click", () => openPathInDefaultEditor(currentFileViewerPath()));
|
|
24510
|
+
elements.fileViewerResizeHandle?.addEventListener("pointerdown", beginFileViewerResize);
|
|
24511
|
+
elements.fileViewerResizeHandle?.addEventListener("keydown", handleFileViewerResizeKeydown);
|
|
24512
|
+
elements.fileViewerSaveButton?.addEventListener("click", () => saveActiveFileViewer());
|
|
24513
|
+
elements.fileViewerCloseButton?.addEventListener("click", closeFileViewer);
|
|
24514
|
+
elements.fileViewerSourceModeButton?.addEventListener("click", () => setFileViewerMode("source"));
|
|
24515
|
+
elements.fileViewerPreviewModeButton?.addEventListener("click", () => setFileViewerMode("preview"));
|
|
24516
|
+
elements.fileViewerEditor?.addEventListener("input", () => {
|
|
24517
|
+
if (!activeFileViewer) return;
|
|
24518
|
+
activeFileViewer.content = elements.fileViewerEditor.value || "";
|
|
24519
|
+
activeFileViewer.size = new Blob([activeFileViewer.content]).size;
|
|
24520
|
+
setFileViewerDirty(true);
|
|
24521
|
+
updateFileViewerSelectionFromEditor();
|
|
24522
|
+
});
|
|
24523
|
+
for (const eventName of ["select", "keyup", "mouseup"]) {
|
|
24524
|
+
elements.fileViewerEditor?.addEventListener(eventName, updateFileViewerSelectionFromEditor);
|
|
24525
|
+
}
|
|
24526
|
+
elements.fileViewerEditor?.addEventListener("keydown", (event) => {
|
|
24527
|
+
if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "s") return;
|
|
24528
|
+
event.preventDefault();
|
|
24529
|
+
if (!elements.fileViewerSaveButton?.disabled) saveActiveFileViewer();
|
|
24530
|
+
});
|
|
24531
|
+
for (const eventName of ["keyup", "mouseup"]) {
|
|
24532
|
+
elements.fileViewerPreview?.addEventListener(eventName, () => setTimeout(updateFileViewerSelectionFromPreview, 0));
|
|
24533
|
+
}
|
|
24534
|
+
document.addEventListener("selectionchange", () => {
|
|
24535
|
+
if (activeFileViewer && elements.fileViewerPreview && !elements.fileViewerPreview.hidden) updateFileViewerSelectionFromPreview();
|
|
24536
|
+
});
|
|
24537
|
+
elements.fileSelectionSendButton?.addEventListener("click", () => sendFileSelectionToSession());
|
|
24538
|
+
elements.fileSelectionCommentInput?.addEventListener("keydown", (event) => {
|
|
24539
|
+
if (event.key !== "Enter") return;
|
|
24540
|
+
event.preventDefault();
|
|
24541
|
+
sendFileSelectionToSession();
|
|
24542
|
+
});
|
|
23298
24543
|
elements.pathPickerCreateNameInput.addEventListener("input", updateCreateDirectoryControls);
|
|
23299
24544
|
elements.pathPickerCreateNameInput.addEventListener("keydown", (event) => {
|
|
23300
24545
|
if (event.key !== "Enter") return;
|
|
@@ -23401,6 +24646,7 @@ elements.promptInput.addEventListener("blur", () => {
|
|
|
23401
24646
|
});
|
|
23402
24647
|
|
|
23403
24648
|
resizePromptInput();
|
|
24649
|
+
restoreFileViewerWidthPreference();
|
|
23404
24650
|
focusPromptInput({ defer: true });
|
|
23405
24651
|
restoreStoredSkillUsage();
|
|
23406
24652
|
restoreBusyPromptBehaviorSetting();
|
|
@@ -23430,6 +24676,7 @@ restoreSidePanelSectionState();
|
|
|
23430
24676
|
bindSidePanelSectionToggles();
|
|
23431
24677
|
restoreSidePanelState();
|
|
23432
24678
|
initializeCodexUsage();
|
|
24679
|
+
initializeClaudeUsage();
|
|
23433
24680
|
initializeUpdateNotifications();
|
|
23434
24681
|
bindMobileViewChanges();
|
|
23435
24682
|
bindSidePanelOverlayViewChanges();
|