@firstpick/pi-package-webui 0.6.1 → 0.6.3
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 +459 -1
- package/package.json +13 -9
- package/public/app.js +341 -2
- package/public/index.html +14 -0
- package/public/styles.css +38 -13
- 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,8 @@ const elements = {
|
|
|
175
175
|
optionalFeaturesBox: $("#optionalFeaturesBox"),
|
|
176
176
|
codexUsageBox: $("#codexUsageBox"),
|
|
177
177
|
refreshCodexUsageButton: $("#refreshCodexUsageButton"),
|
|
178
|
+
claudeUsageBox: $("#claudeUsageBox"),
|
|
179
|
+
refreshClaudeUsageButton: $("#refreshClaudeUsageButton"),
|
|
178
180
|
toggleSidePanelButton: $("#toggleSidePanelButton"),
|
|
179
181
|
sidePanelExpandButton: $("#sidePanelExpandButton"),
|
|
180
182
|
sidePanelBackdrop: $("#sidePanelBackdrop"),
|
|
@@ -341,12 +343,16 @@ let availableCommands = [];
|
|
|
341
343
|
let rawAvailableCommands = [];
|
|
342
344
|
let commandSuggestions = [];
|
|
343
345
|
let pathSuggestions = [];
|
|
346
|
+
let bangSuggestions = [];
|
|
344
347
|
let suggestionMode = "none";
|
|
345
348
|
let commandSuggestIndex = 0;
|
|
346
349
|
let lastPointerPosition = null;
|
|
347
350
|
let pathSuggestActiveQuery = null;
|
|
348
351
|
let pathSuggestRequestSerial = 0;
|
|
349
352
|
let pathSuggestAbortController = null;
|
|
353
|
+
let bangSuggestActiveQuery = null;
|
|
354
|
+
let bangSuggestRequestSerial = 0;
|
|
355
|
+
let bangSuggestAbortController = null;
|
|
350
356
|
let latestStats = null;
|
|
351
357
|
let statsOverlayActiveTab = "overview";
|
|
352
358
|
let statsOverlayLoading = false;
|
|
@@ -372,6 +378,11 @@ let codexUsageError = null;
|
|
|
372
378
|
let codexUsageLoading = false;
|
|
373
379
|
let refreshCodexUsageTimer = null;
|
|
374
380
|
let codexUsageRenderTimer = null;
|
|
381
|
+
let latestClaudeUsage = null;
|
|
382
|
+
let claudeUsageError = null;
|
|
383
|
+
let claudeUsageLoading = false;
|
|
384
|
+
let refreshClaudeUsageTimer = null;
|
|
385
|
+
let claudeUsageRenderTimer = null;
|
|
375
386
|
let backendOffline = false;
|
|
376
387
|
let serverRestartInProgress = false;
|
|
377
388
|
let updateRequestInProgress = false;
|
|
@@ -562,6 +573,8 @@ const CHAT_PROGRAMMATIC_SCROLL_GRACE_MS = 500;
|
|
|
562
573
|
const CHAT_USER_SCROLL_INTENT_MS = 700;
|
|
563
574
|
const CODEX_USAGE_REFRESH_MS = 5 * 60 * 1000;
|
|
564
575
|
const CODEX_USAGE_RENDER_TICK_MS = 30 * 1000;
|
|
576
|
+
const CLAUDE_USAGE_REFRESH_MS = 5 * 60 * 1000;
|
|
577
|
+
const CLAUDE_USAGE_RENDER_TICK_MS = 30 * 1000;
|
|
565
578
|
const UPDATE_STATUS_REFRESH_MS = 6 * 60 * 60 * 1000;
|
|
566
579
|
const UPDATE_STATUS_INITIAL_DELAY_MS = 1800;
|
|
567
580
|
const RUN_INDICATOR_TICK_MS = 1000;
|
|
@@ -615,6 +628,8 @@ let liveToolRenderTimer = null;
|
|
|
615
628
|
// commands and live widget events), not npm package folders. This keeps local dev
|
|
616
629
|
// symlinks and independently installed packages working.
|
|
617
630
|
const optionalFeatureAvailability = {
|
|
631
|
+
bangCommandAutocomplete: false,
|
|
632
|
+
fishUserBash: false,
|
|
618
633
|
btwCommand: false,
|
|
619
634
|
gitWorkflow: false,
|
|
620
635
|
releaseNpm: false,
|
|
@@ -633,6 +648,20 @@ const optionalFeatureAvailability = {
|
|
|
633
648
|
const APP_RUNNER_CONTEXT_DEFAULT_LINES = 80;
|
|
634
649
|
const APP_RUNNER_CONTEXT_MAX_LINES = 1000;
|
|
635
650
|
const OPTIONAL_FEATURES = [
|
|
651
|
+
{
|
|
652
|
+
id: "bangCommandAutocomplete",
|
|
653
|
+
label: "! command autocomplete",
|
|
654
|
+
packageName: "@firstpick/pi-extension-bang-command-autocomplete",
|
|
655
|
+
capabilityLabel: "/bang-status or /bang-refresh",
|
|
656
|
+
description: "Autocomplete for native ! and !! shell commands in the Web UI composer.",
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
id: "fishUserBash",
|
|
660
|
+
label: "Fish user bash",
|
|
661
|
+
packageName: "@firstpick/pi-extension-fish-user-bash",
|
|
662
|
+
capabilityLabel: "/user-bash-shell",
|
|
663
|
+
description: "Run Web UI ! and !! shell commands through the user shell selected by fish-user-bash.",
|
|
664
|
+
},
|
|
636
665
|
{
|
|
637
666
|
id: "btwCommand",
|
|
638
667
|
label: "/btw side questions",
|
|
@@ -734,6 +763,9 @@ const OPTIONAL_FEATURES = [
|
|
|
734
763
|
];
|
|
735
764
|
const OPTIONAL_FEATURE_BY_ID = new Map(OPTIONAL_FEATURES.map((feature) => [feature.id, feature]));
|
|
736
765
|
const OPTIONAL_COMMAND_FEATURES = new Map([
|
|
766
|
+
["bang-refresh", "bangCommandAutocomplete"],
|
|
767
|
+
["bang-status", "bangCommandAutocomplete"],
|
|
768
|
+
["user-bash-shell", "fishUserBash"],
|
|
737
769
|
["btw", "btwCommand"],
|
|
738
770
|
["btw-transfer", "btwCommand"],
|
|
739
771
|
["btw-status", "btwCommand"],
|
|
@@ -10585,6 +10617,137 @@ function initializeCodexUsage() {
|
|
|
10585
10617
|
codexUsageRenderTimer = setInterval(renderCodexUsage, CODEX_USAGE_RENDER_TICK_MS);
|
|
10586
10618
|
}
|
|
10587
10619
|
|
|
10620
|
+
function claudeUsageResetDate(window) {
|
|
10621
|
+
const resetAt = window?.resetsAt ? new Date(window.resetsAt) : null;
|
|
10622
|
+
if (resetAt && Number.isFinite(resetAt.getTime())) return resetAt;
|
|
10623
|
+
const resetAfterSeconds = Number(window?.resetAfterSeconds);
|
|
10624
|
+
if (Number.isFinite(resetAfterSeconds) && resetAfterSeconds >= 0) return new Date(Date.now() + resetAfterSeconds * 1000);
|
|
10625
|
+
return null;
|
|
10626
|
+
}
|
|
10627
|
+
|
|
10628
|
+
function formatClaudeUsageReset(window) {
|
|
10629
|
+
const resetDate = claudeUsageResetDate(window);
|
|
10630
|
+
if (resetDate) {
|
|
10631
|
+
const diff = resetDate.getTime() - Date.now();
|
|
10632
|
+
if (diff <= 0) return "resetting now";
|
|
10633
|
+
return `resets in ${formatDurationParts(diff)}`;
|
|
10634
|
+
}
|
|
10635
|
+
return window?.resetText ? `resets ${window.resetText}` : "reset unknown";
|
|
10636
|
+
}
|
|
10637
|
+
|
|
10638
|
+
function renderClaudeUsageWindow(box, window) {
|
|
10639
|
+
const usedPercent = Number(window?.usedPercent);
|
|
10640
|
+
const fillPercent = Number.isFinite(usedPercent) ? Math.max(0, Math.min(100, usedPercent)) : 0;
|
|
10641
|
+
const item = make("div", "claude-usage-bucket");
|
|
10642
|
+
const row = make("div", "claude-usage-row");
|
|
10643
|
+
row.append(
|
|
10644
|
+
make("span", "claude-usage-label", window?.label || "Usage window"),
|
|
10645
|
+
make("strong", "claude-usage-percent", formatCodexPercent(usedPercent)),
|
|
10646
|
+
);
|
|
10647
|
+
const meter = make("div", "claude-usage-meter");
|
|
10648
|
+
const fill = make("span", "claude-usage-meter-fill");
|
|
10649
|
+
fill.style.width = `${fillPercent}%`;
|
|
10650
|
+
meter.append(fill);
|
|
10651
|
+
item.append(row, meter, make("div", "claude-usage-reset", formatClaudeUsageReset(window)));
|
|
10652
|
+
box.append(item);
|
|
10653
|
+
}
|
|
10654
|
+
|
|
10655
|
+
function renderClaudeUsageActivity(box, activity) {
|
|
10656
|
+
if (!Array.isArray(activity) || activity.length === 0) return;
|
|
10657
|
+
const title = make("div", "claude-usage-activity-title", latestClaudeUsage?.activityTitle || "What's contributing to your limits usage?");
|
|
10658
|
+
box.append(title);
|
|
10659
|
+
for (const item of activity.slice(0, 2)) {
|
|
10660
|
+
const group = make("div", "claude-usage-activity-group");
|
|
10661
|
+
const row = make("div", "claude-usage-row");
|
|
10662
|
+
row.append(
|
|
10663
|
+
make("span", "claude-usage-label", item.label || "Activity"),
|
|
10664
|
+
make("span", "claude-usage-reset", `${Number(item.requests || 0)} requests · ${Number(item.sessions || 0)} sessions`),
|
|
10665
|
+
);
|
|
10666
|
+
group.append(row);
|
|
10667
|
+
for (const detail of (Array.isArray(item.details) ? item.details : []).slice(0, 4)) {
|
|
10668
|
+
group.append(make("div", "claude-usage-detail", detail?.text || String(detail || "")));
|
|
10669
|
+
}
|
|
10670
|
+
box.append(group);
|
|
10671
|
+
}
|
|
10672
|
+
}
|
|
10673
|
+
|
|
10674
|
+
function renderClaudeUsage() {
|
|
10675
|
+
const box = elements.claudeUsageBox;
|
|
10676
|
+
if (!box) return;
|
|
10677
|
+
if (elements.refreshClaudeUsageButton) {
|
|
10678
|
+
elements.refreshClaudeUsageButton.disabled = claudeUsageLoading;
|
|
10679
|
+
elements.refreshClaudeUsageButton.textContent = claudeUsageLoading ? "Refreshing…" : "Refresh usage";
|
|
10680
|
+
}
|
|
10681
|
+
|
|
10682
|
+
box.replaceChildren();
|
|
10683
|
+
box.classList.toggle("muted", !latestClaudeUsage);
|
|
10684
|
+
|
|
10685
|
+
if (!latestClaudeUsage && claudeUsageLoading) {
|
|
10686
|
+
box.textContent = "Checking Claude usage…";
|
|
10687
|
+
return;
|
|
10688
|
+
}
|
|
10689
|
+
if (!latestClaudeUsage && claudeUsageError) {
|
|
10690
|
+
const title = make("div", "claude-usage-unavailable", "Usage unavailable");
|
|
10691
|
+
const detail = make("div", "claude-usage-detail", claudeUsageError.message || String(claudeUsageError));
|
|
10692
|
+
box.append(title, detail);
|
|
10693
|
+
return;
|
|
10694
|
+
}
|
|
10695
|
+
if (!latestClaudeUsage) {
|
|
10696
|
+
box.textContent = "Claude usage has not loaded yet.";
|
|
10697
|
+
return;
|
|
10698
|
+
}
|
|
10699
|
+
|
|
10700
|
+
const header = make("div", "claude-usage-summary");
|
|
10701
|
+
header.append(
|
|
10702
|
+
make("span", "claude-usage-plan", "Claude Code"),
|
|
10703
|
+
make("span", "claude-usage-fetched", latestClaudeUsage.fetchedAt ? `updated ${formatDurationParts(Date.now() - new Date(latestClaudeUsage.fetchedAt).getTime())} ago` : "updated now"),
|
|
10704
|
+
);
|
|
10705
|
+
box.append(header);
|
|
10706
|
+
|
|
10707
|
+
if (latestClaudeUsage.summary) box.append(make("div", "claude-usage-detail", latestClaudeUsage.summary));
|
|
10708
|
+
const windows = Array.isArray(latestClaudeUsage.windows) ? latestClaudeUsage.windows : [];
|
|
10709
|
+
if (windows.length === 0) {
|
|
10710
|
+
box.append(make("div", "claude-usage-detail", "No Claude usage windows were returned."));
|
|
10711
|
+
} else {
|
|
10712
|
+
for (const window of windows.slice(0, 6)) renderClaudeUsageWindow(box, window);
|
|
10713
|
+
}
|
|
10714
|
+
|
|
10715
|
+
renderClaudeUsageActivity(box, latestClaudeUsage.activity);
|
|
10716
|
+
if (claudeUsageError) {
|
|
10717
|
+
box.append(make("div", "claude-usage-detail", `Latest refresh failed: ${claudeUsageError.message || claudeUsageError}`));
|
|
10718
|
+
}
|
|
10719
|
+
}
|
|
10720
|
+
|
|
10721
|
+
async function refreshClaudeUsage() {
|
|
10722
|
+
if (claudeUsageLoading) return;
|
|
10723
|
+
claudeUsageLoading = true;
|
|
10724
|
+
renderClaudeUsage();
|
|
10725
|
+
try {
|
|
10726
|
+
const response = await api("/api/claude-usage", { scoped: false });
|
|
10727
|
+
latestClaudeUsage = response.data || null;
|
|
10728
|
+
claudeUsageError = null;
|
|
10729
|
+
} catch (error) {
|
|
10730
|
+
claudeUsageError = error;
|
|
10731
|
+
} finally {
|
|
10732
|
+
claudeUsageLoading = false;
|
|
10733
|
+
renderClaudeUsage();
|
|
10734
|
+
}
|
|
10735
|
+
}
|
|
10736
|
+
|
|
10737
|
+
function scheduleRefreshClaudeUsage(delay = CLAUDE_USAGE_REFRESH_MS) {
|
|
10738
|
+
clearTimeout(refreshClaudeUsageTimer);
|
|
10739
|
+
refreshClaudeUsageTimer = setTimeout(() => {
|
|
10740
|
+
refreshClaudeUsage().finally(() => scheduleRefreshClaudeUsage());
|
|
10741
|
+
}, delay);
|
|
10742
|
+
}
|
|
10743
|
+
|
|
10744
|
+
function initializeClaudeUsage() {
|
|
10745
|
+
renderClaudeUsage();
|
|
10746
|
+
refreshClaudeUsage().finally(() => scheduleRefreshClaudeUsage());
|
|
10747
|
+
clearInterval(claudeUsageRenderTimer);
|
|
10748
|
+
claudeUsageRenderTimer = setInterval(renderClaudeUsage, CLAUDE_USAGE_RENDER_TICK_MS);
|
|
10749
|
+
}
|
|
10750
|
+
|
|
10588
10751
|
function renderStatus() {
|
|
10589
10752
|
if (deferUiRenderDuringPointerActivation("status", renderStatus)) return;
|
|
10590
10753
|
const state = currentState;
|
|
@@ -16065,6 +16228,19 @@ function messageTitle(message) {
|
|
|
16065
16228
|
return message.role || "message";
|
|
16066
16229
|
}
|
|
16067
16230
|
|
|
16231
|
+
function isCompleteUserBashMessage(message) {
|
|
16232
|
+
if (message?.role !== "bashExecution") return false;
|
|
16233
|
+
const title = String(message.title || "").toLowerCase();
|
|
16234
|
+
if (title.includes("queued")) return false;
|
|
16235
|
+
if (title.includes("complete")) return true;
|
|
16236
|
+
if (message.exitCode !== undefined || message.cancelled !== undefined || message.truncated !== undefined || message.fullOutputPath) return true;
|
|
16237
|
+
return !title && message.output !== undefined;
|
|
16238
|
+
}
|
|
16239
|
+
|
|
16240
|
+
function shouldOpenMessageCollapseByDefault(message) {
|
|
16241
|
+
return !!message?.isError || toolOutputGloballyExpanded || isCompleteUserBashMessage(message);
|
|
16242
|
+
}
|
|
16243
|
+
|
|
16068
16244
|
function assistantThinkingText(part) {
|
|
16069
16245
|
if (!part || typeof part !== "object") return "";
|
|
16070
16246
|
if (part.type !== "thinking" && typeof part.thinking !== "string") return "";
|
|
@@ -17245,7 +17421,7 @@ function appendMessage(message, { streaming = false, messageIndex = -1, transien
|
|
|
17245
17421
|
|
|
17246
17422
|
if (isCollapsibleOutput) {
|
|
17247
17423
|
const details = make("details", "message-collapse");
|
|
17248
|
-
if (message
|
|
17424
|
+
if (shouldOpenMessageCollapseByDefault(message)) details.open = true;
|
|
17249
17425
|
details.append(header, body);
|
|
17250
17426
|
bubble.append(details);
|
|
17251
17427
|
if (message.role === "toolResult" && !message.isError) {
|
|
@@ -18251,6 +18427,8 @@ function requestGitFooterWebuiPayload(tabContext = activeTabContext(), { force =
|
|
|
18251
18427
|
}
|
|
18252
18428
|
|
|
18253
18429
|
function updateOptionalFeatureAvailability() {
|
|
18430
|
+
optionalFeatureAvailability.bangCommandAutocomplete = hasAvailableCommand("bang-status") || hasAvailableCommand("bang-refresh");
|
|
18431
|
+
optionalFeatureAvailability.fishUserBash = hasAvailableCommand("user-bash-shell");
|
|
18254
18432
|
optionalFeatureAvailability.btwCommand = hasAvailableCommand("btw") || optionalFeatureAvailability.btwCommand || statusEntries.has(BTW_WEBUI_STATUS_KEY) || widgets.has(BTW_OUTPUT_WIDGET_KEY);
|
|
18255
18433
|
optionalFeatureAvailability.gitWorkflow = hasAvailableCommand("git-staged-msg");
|
|
18256
18434
|
optionalFeatureAvailability.releaseNpm = hasAvailableCommand("release-npm");
|
|
@@ -20596,6 +20774,26 @@ function normalizePathSuggestions(suggestions) {
|
|
|
20596
20774
|
});
|
|
20597
20775
|
}
|
|
20598
20776
|
|
|
20777
|
+
function normalizeBangSuggestions(suggestions) {
|
|
20778
|
+
const seen = new Set();
|
|
20779
|
+
return (suggestions || [])
|
|
20780
|
+
.map((suggestion) => {
|
|
20781
|
+
const insertText = String(suggestion.insertText || suggestion.value || "").trim().replace(/^!+/, "");
|
|
20782
|
+
const label = String(suggestion.label || `!${insertText}`).trim();
|
|
20783
|
+
return {
|
|
20784
|
+
insertText,
|
|
20785
|
+
label,
|
|
20786
|
+
description: String(suggestion.description || "shell command").trim(),
|
|
20787
|
+
kind: String(suggestion.kind || "command").trim(),
|
|
20788
|
+
};
|
|
20789
|
+
})
|
|
20790
|
+
.filter((suggestion) => {
|
|
20791
|
+
if (!suggestion.insertText || seen.has(suggestion.insertText)) return false;
|
|
20792
|
+
seen.add(suggestion.insertText);
|
|
20793
|
+
return true;
|
|
20794
|
+
});
|
|
20795
|
+
}
|
|
20796
|
+
|
|
20599
20797
|
function getCommandTrigger() {
|
|
20600
20798
|
const input = elements.promptInput;
|
|
20601
20799
|
const cursor = input.selectionStart ?? input.value.length;
|
|
@@ -20633,6 +20831,21 @@ function getPathTrigger() {
|
|
|
20633
20831
|
return { start: cursor - query.length - 1, end: cursor, query, quoted: false };
|
|
20634
20832
|
}
|
|
20635
20833
|
|
|
20834
|
+
function getBangTrigger() {
|
|
20835
|
+
const input = elements.promptInput;
|
|
20836
|
+
const cursor = input.selectionStart ?? input.value.length;
|
|
20837
|
+
const selectionEnd = input.selectionEnd ?? cursor;
|
|
20838
|
+
if (cursor !== selectionEnd) return null;
|
|
20839
|
+
|
|
20840
|
+
const beforeCursor = input.value.slice(0, cursor);
|
|
20841
|
+
const match = beforeCursor.match(/^\s*(!!?)([^\n]*)$/);
|
|
20842
|
+
if (!match) return null;
|
|
20843
|
+
const afterBang = match[2] || "";
|
|
20844
|
+
const leadingSpaceLength = afterBang.match(/^\s*/)?.[0]?.length || 0;
|
|
20845
|
+
const query = afterBang.slice(leadingSpaceLength);
|
|
20846
|
+
return { start: cursor - query.length, end: cursor, query, bangPrefix: match[1] };
|
|
20847
|
+
}
|
|
20848
|
+
|
|
20636
20849
|
function scoreCommandSuggestion(command, query) {
|
|
20637
20850
|
if (!query) return 0;
|
|
20638
20851
|
const q = query.toLowerCase();
|
|
@@ -20670,7 +20883,9 @@ function commandMatchesSearch(command, query) {
|
|
|
20670
20883
|
}
|
|
20671
20884
|
|
|
20672
20885
|
function activeSuggestionCount() {
|
|
20673
|
-
|
|
20886
|
+
if (suggestionMode === "path") return pathSuggestions.length;
|
|
20887
|
+
if (suggestionMode === "bang") return bangSuggestions.length;
|
|
20888
|
+
return commandSuggestions.length;
|
|
20674
20889
|
}
|
|
20675
20890
|
|
|
20676
20891
|
function abortPathSuggestionRequest() {
|
|
@@ -20684,13 +20899,26 @@ function cancelPathSuggestionRequest() {
|
|
|
20684
20899
|
abortPathSuggestionRequest();
|
|
20685
20900
|
}
|
|
20686
20901
|
|
|
20902
|
+
function abortBangSuggestionRequest() {
|
|
20903
|
+
bangSuggestAbortController?.abort();
|
|
20904
|
+
bangSuggestAbortController = null;
|
|
20905
|
+
}
|
|
20906
|
+
|
|
20907
|
+
function cancelBangSuggestionRequest() {
|
|
20908
|
+
bangSuggestRequestSerial++;
|
|
20909
|
+
bangSuggestActiveQuery = null;
|
|
20910
|
+
abortBangSuggestionRequest();
|
|
20911
|
+
}
|
|
20912
|
+
|
|
20687
20913
|
function hideCommandSuggestions() {
|
|
20688
20914
|
cancelPathSuggestionRequest();
|
|
20915
|
+
cancelBangSuggestionRequest();
|
|
20689
20916
|
elements.commandSuggest.hidden = true;
|
|
20690
20917
|
elements.commandSuggest.removeAttribute("aria-busy");
|
|
20691
20918
|
elements.commandSuggest.replaceChildren();
|
|
20692
20919
|
commandSuggestions = [];
|
|
20693
20920
|
pathSuggestions = [];
|
|
20921
|
+
bangSuggestions = [];
|
|
20694
20922
|
suggestionMode = "none";
|
|
20695
20923
|
commandSuggestIndex = 0;
|
|
20696
20924
|
scheduleDeferredUiFlushAfterDropdownClose();
|
|
@@ -20739,6 +20967,7 @@ function setActiveCommandSuggestionFromPointerMove(index, event) {
|
|
|
20739
20967
|
function renderCommandSuggestionItems(trigger, { keepIndex = false } = {}) {
|
|
20740
20968
|
suggestionMode = "command";
|
|
20741
20969
|
pathSuggestions = [];
|
|
20970
|
+
bangSuggestions = [];
|
|
20742
20971
|
commandSuggestions = getCommandMatches(trigger.query);
|
|
20743
20972
|
elements.commandSuggest.replaceChildren();
|
|
20744
20973
|
|
|
@@ -20781,6 +21010,7 @@ function formatPathReference(pathText, forceQuoted = false) {
|
|
|
20781
21010
|
function renderPathSuggestionItems(trigger, { keepIndex = false } = {}) {
|
|
20782
21011
|
suggestionMode = "path";
|
|
20783
21012
|
commandSuggestions = [];
|
|
21013
|
+
bangSuggestions = [];
|
|
20784
21014
|
elements.commandSuggest.replaceChildren();
|
|
20785
21015
|
|
|
20786
21016
|
if (pathSuggestions.length === 0) {
|
|
@@ -20811,6 +21041,7 @@ function renderPathSuggestionItems(trigger, { keepIndex = false } = {}) {
|
|
|
20811
21041
|
}
|
|
20812
21042
|
|
|
20813
21043
|
async function renderPathSuggestions(trigger, { keepIndex = false } = {}) {
|
|
21044
|
+
cancelBangSuggestionRequest();
|
|
20814
21045
|
if (suggestionMode === "path" && pathSuggestActiveQuery === trigger.query && !elements.commandSuggest.hidden) {
|
|
20815
21046
|
if (keepIndex && activeSuggestionCount() > 0) setActiveCommandSuggestion(commandSuggestIndex);
|
|
20816
21047
|
return;
|
|
@@ -20849,12 +21080,93 @@ async function renderPathSuggestions(trigger, { keepIndex = false } = {}) {
|
|
|
20849
21080
|
}
|
|
20850
21081
|
}
|
|
20851
21082
|
|
|
21083
|
+
function renderBangSuggestionItems(trigger, { keepIndex = false } = {}) {
|
|
21084
|
+
suggestionMode = "bang";
|
|
21085
|
+
commandSuggestions = [];
|
|
21086
|
+
pathSuggestions = [];
|
|
21087
|
+
elements.commandSuggest.replaceChildren();
|
|
21088
|
+
|
|
21089
|
+
if (bangSuggestions.length === 0) {
|
|
21090
|
+
elements.commandSuggest.append(make("div", "command-suggest-empty", `No shell command matches !${trigger.query}`));
|
|
21091
|
+
elements.commandSuggest.hidden = false;
|
|
21092
|
+
return;
|
|
21093
|
+
}
|
|
21094
|
+
|
|
21095
|
+
for (const [index, suggestion] of bangSuggestions.entries()) {
|
|
21096
|
+
const item = make("button", "command-suggest-item bang-suggest-item");
|
|
21097
|
+
item.type = "button";
|
|
21098
|
+
item.setAttribute("role", "option");
|
|
21099
|
+
item.addEventListener("mousedown", (event) => event.preventDefault());
|
|
21100
|
+
item.addEventListener("pointermove", (event) => setActiveCommandSuggestionFromPointerMove(index, event));
|
|
21101
|
+
item.addEventListener("click", () => insertBangSuggestion(index));
|
|
21102
|
+
|
|
21103
|
+
item.append(
|
|
21104
|
+
make("span", "command-suggest-name bang-suggest-name", suggestion.label || `!${suggestion.insertText}`),
|
|
21105
|
+
make("span", "command-suggest-desc", suggestion.description || "shell command"),
|
|
21106
|
+
make("span", "command-suggest-source", suggestion.kind || "command"),
|
|
21107
|
+
);
|
|
21108
|
+
elements.commandSuggest.append(item);
|
|
21109
|
+
}
|
|
21110
|
+
|
|
21111
|
+
elements.commandSuggest.hidden = false;
|
|
21112
|
+
setActiveCommandSuggestion(keepIndex ? commandSuggestIndex : 0);
|
|
21113
|
+
}
|
|
21114
|
+
|
|
21115
|
+
async function renderBangSuggestions(trigger, { keepIndex = false } = {}) {
|
|
21116
|
+
cancelPathSuggestionRequest();
|
|
21117
|
+
const activeQuery = `${trigger.bangPrefix}\0${trigger.query}`;
|
|
21118
|
+
if (suggestionMode === "bang" && bangSuggestActiveQuery === activeQuery && !elements.commandSuggest.hidden) {
|
|
21119
|
+
if (keepIndex && activeSuggestionCount() > 0) setActiveCommandSuggestion(commandSuggestIndex);
|
|
21120
|
+
return;
|
|
21121
|
+
}
|
|
21122
|
+
|
|
21123
|
+
const keepExistingBangMenu = suggestionMode === "bang" && !elements.commandSuggest.hidden && elements.commandSuggest.childElementCount > 0;
|
|
21124
|
+
abortBangSuggestionRequest();
|
|
21125
|
+
const requestSerial = ++bangSuggestRequestSerial;
|
|
21126
|
+
const controller = new AbortController();
|
|
21127
|
+
bangSuggestActiveQuery = activeQuery;
|
|
21128
|
+
bangSuggestAbortController = controller;
|
|
21129
|
+
suggestionMode = "bang";
|
|
21130
|
+
commandSuggestions = [];
|
|
21131
|
+
pathSuggestions = [];
|
|
21132
|
+
if (!keepExistingBangMenu) {
|
|
21133
|
+
bangSuggestions = [];
|
|
21134
|
+
elements.commandSuggest.replaceChildren(make("div", "command-suggest-empty", "Finding shell commands…"));
|
|
21135
|
+
}
|
|
21136
|
+
elements.commandSuggest.hidden = false;
|
|
21137
|
+
elements.commandSuggest.setAttribute("aria-busy", "true");
|
|
21138
|
+
|
|
21139
|
+
try {
|
|
21140
|
+
const response = await api(`/api/bang-suggestions?query=${encodeURIComponent(trigger.query)}`, { signal: controller.signal });
|
|
21141
|
+
if (requestSerial !== bangSuggestRequestSerial || document.activeElement !== elements.promptInput) return;
|
|
21142
|
+
bangSuggestions = normalizeBangSuggestions(response.data?.suggestions || []);
|
|
21143
|
+
renderBangSuggestionItems(trigger, { keepIndex });
|
|
21144
|
+
} catch (error) {
|
|
21145
|
+
if (error?.name === "AbortError" || requestSerial !== bangSuggestRequestSerial) return;
|
|
21146
|
+
bangSuggestions = [];
|
|
21147
|
+
elements.commandSuggest.replaceChildren(make("div", "command-suggest-empty", `Shell command suggestions unavailable: ${error.message}`));
|
|
21148
|
+
elements.commandSuggest.hidden = false;
|
|
21149
|
+
} finally {
|
|
21150
|
+
if (requestSerial === bangSuggestRequestSerial) {
|
|
21151
|
+
bangSuggestAbortController = null;
|
|
21152
|
+
elements.commandSuggest.removeAttribute("aria-busy");
|
|
21153
|
+
}
|
|
21154
|
+
}
|
|
21155
|
+
}
|
|
21156
|
+
|
|
20852
21157
|
function renderCommandSuggestions({ keepIndex = false } = {}) {
|
|
20853
21158
|
if (document.activeElement !== elements.promptInput) {
|
|
20854
21159
|
hideCommandSuggestions();
|
|
20855
21160
|
return;
|
|
20856
21161
|
}
|
|
20857
21162
|
|
|
21163
|
+
const bangTrigger = getBangTrigger();
|
|
21164
|
+
if (bangTrigger) {
|
|
21165
|
+
if (isOptionalFeatureEnabled("bangCommandAutocomplete")) renderBangSuggestions(bangTrigger, { keepIndex });
|
|
21166
|
+
else hideCommandSuggestions();
|
|
21167
|
+
return;
|
|
21168
|
+
}
|
|
21169
|
+
|
|
20858
21170
|
const pathTrigger = getPathTrigger();
|
|
20859
21171
|
if (pathTrigger) {
|
|
20860
21172
|
renderPathSuggestions(pathTrigger, { keepIndex });
|
|
@@ -20862,6 +21174,7 @@ function renderCommandSuggestions({ keepIndex = false } = {}) {
|
|
|
20862
21174
|
}
|
|
20863
21175
|
|
|
20864
21176
|
cancelPathSuggestionRequest();
|
|
21177
|
+
cancelBangSuggestionRequest();
|
|
20865
21178
|
const trigger = getCommandTrigger();
|
|
20866
21179
|
if (!trigger || availableCommands.length === 0) {
|
|
20867
21180
|
hideCommandSuggestions();
|
|
@@ -20873,6 +21186,7 @@ function renderCommandSuggestions({ keepIndex = false } = {}) {
|
|
|
20873
21186
|
|
|
20874
21187
|
function insertCommandSuggestion(index = commandSuggestIndex) {
|
|
20875
21188
|
if (suggestionMode === "path") return insertPathSuggestion(index);
|
|
21189
|
+
if (suggestionMode === "bang") return insertBangSuggestion(index);
|
|
20876
21190
|
const command = commandSuggestions[index];
|
|
20877
21191
|
const trigger = getCommandTrigger();
|
|
20878
21192
|
if (!command || !trigger) return false;
|
|
@@ -20895,6 +21209,26 @@ function insertCommandSuggestion(index = commandSuggestIndex) {
|
|
|
20895
21209
|
return true;
|
|
20896
21210
|
}
|
|
20897
21211
|
|
|
21212
|
+
function insertBangSuggestion(index = commandSuggestIndex) {
|
|
21213
|
+
const suggestion = bangSuggestions[index];
|
|
21214
|
+
const trigger = getBangTrigger();
|
|
21215
|
+
if (!suggestion || !trigger) return false;
|
|
21216
|
+
|
|
21217
|
+
const input = elements.promptInput;
|
|
21218
|
+
const value = input.value;
|
|
21219
|
+
const suffix = value.slice(trigger.end);
|
|
21220
|
+
const commandText = suggestion.insertText.replace(/^!+/, "");
|
|
21221
|
+
const separator = suggestion.kind === "line" || (suffix && /^\s/.test(suffix)) ? "" : " ";
|
|
21222
|
+
input.value = `${value.slice(0, trigger.start)}${commandText}${separator}${suffix}`;
|
|
21223
|
+
|
|
21224
|
+
const cursor = trigger.start + commandText.length + separator.length;
|
|
21225
|
+
input.setSelectionRange(cursor, cursor);
|
|
21226
|
+
input.focus();
|
|
21227
|
+
resizePromptInput();
|
|
21228
|
+
hideCommandSuggestions();
|
|
21229
|
+
return true;
|
|
21230
|
+
}
|
|
21231
|
+
|
|
20898
21232
|
function insertPathSuggestion(index = commandSuggestIndex) {
|
|
20899
21233
|
const suggestion = pathSuggestions[index];
|
|
20900
21234
|
const trigger = getPathTrigger();
|
|
@@ -21995,6 +22329,7 @@ function handleEvent(event) {
|
|
|
21995
22329
|
scheduleRefreshMessages();
|
|
21996
22330
|
scheduleRefreshFooter();
|
|
21997
22331
|
scheduleRefreshCodexUsage(2200);
|
|
22332
|
+
scheduleRefreshClaudeUsage(2200);
|
|
21998
22333
|
renderFeedbackTray();
|
|
21999
22334
|
{
|
|
22000
22335
|
const workflowTabId = event.tabId || activeTabId;
|
|
@@ -23295,6 +23630,9 @@ elements.gitChangesDialog?.addEventListener("close", () => {
|
|
|
23295
23630
|
elements.refreshCodexUsageButton?.addEventListener("click", () => {
|
|
23296
23631
|
refreshCodexUsage({ forceAuthRefresh: true }).finally(() => scheduleRefreshCodexUsage());
|
|
23297
23632
|
});
|
|
23633
|
+
elements.refreshClaudeUsageButton?.addEventListener("click", () => {
|
|
23634
|
+
refreshClaudeUsage().finally(() => scheduleRefreshClaudeUsage());
|
|
23635
|
+
});
|
|
23298
23636
|
elements.pathPickerCreateNameInput.addEventListener("input", updateCreateDirectoryControls);
|
|
23299
23637
|
elements.pathPickerCreateNameInput.addEventListener("keydown", (event) => {
|
|
23300
23638
|
if (event.key !== "Enter") return;
|
|
@@ -23430,6 +23768,7 @@ restoreSidePanelSectionState();
|
|
|
23430
23768
|
bindSidePanelSectionToggles();
|
|
23431
23769
|
restoreSidePanelState();
|
|
23432
23770
|
initializeCodexUsage();
|
|
23771
|
+
initializeClaudeUsage();
|
|
23433
23772
|
initializeUpdateNotifications();
|
|
23434
23773
|
bindMobileViewChanges();
|
|
23435
23774
|
bindSidePanelOverlayViewChanges();
|
package/public/index.html
CHANGED
|
@@ -488,6 +488,20 @@
|
|
|
488
488
|
<div id="codexUsageBox" class="codex-usage-box muted">Checking Codex usage…</div>
|
|
489
489
|
</div>
|
|
490
490
|
</section>
|
|
491
|
+
<section class="side-panel-section collapsed" data-side-panel-section="claude-usage">
|
|
492
|
+
<h2>
|
|
493
|
+
<button id="sidePanelSectionToggleClaudeUsage" class="side-panel-section-toggle" type="button" aria-expanded="false" aria-controls="sidePanelSectionClaudeUsage" aria-label="Expand Claude Usage section" title="Expand Claude Usage section" data-side-panel-section-toggle="claude-usage">
|
|
494
|
+
<span class="side-panel-section-label">Claude Usage</span>
|
|
495
|
+
<span class="side-panel-section-chevron" aria-hidden="true">›</span>
|
|
496
|
+
</button>
|
|
497
|
+
</h2>
|
|
498
|
+
<div id="sidePanelSectionClaudeUsage" class="side-panel-section-content" hidden>
|
|
499
|
+
<div class="claude-usage-actions">
|
|
500
|
+
<button id="refreshClaudeUsageButton" type="button">Refresh usage</button>
|
|
501
|
+
</div>
|
|
502
|
+
<div id="claudeUsageBox" class="claude-usage-box muted">Checking Claude usage…</div>
|
|
503
|
+
</div>
|
|
504
|
+
</section>
|
|
491
505
|
<section class="side-panel-section collapsed" data-side-panel-section="session">
|
|
492
506
|
<h2>
|
|
493
507
|
<button id="sidePanelSectionToggleSession" class="side-panel-section-toggle" type="button" aria-expanded="false" aria-controls="sidePanelSectionSession" aria-label="Expand Session section" title="Expand Session section" data-side-panel-section-toggle="session">
|
package/public/styles.css
CHANGED
|
@@ -1300,17 +1300,20 @@ body.embedded-split .side-panel-backdrop {
|
|
|
1300
1300
|
background: rgba(var(--ctp-crust-rgb), 0.46);
|
|
1301
1301
|
box-shadow: inset 0 1px 0 rgba(255,255,255,0.035), 0 0 1rem rgba(148, 226, 213, 0.05);
|
|
1302
1302
|
}
|
|
1303
|
-
.codex-usage-actions
|
|
1303
|
+
.codex-usage-actions,
|
|
1304
|
+
.claude-usage-actions {
|
|
1304
1305
|
display: flex;
|
|
1305
1306
|
justify-content: flex-end;
|
|
1306
1307
|
margin-bottom: 0.48rem;
|
|
1307
1308
|
}
|
|
1308
|
-
.codex-usage-actions button
|
|
1309
|
+
.codex-usage-actions button,
|
|
1310
|
+
.claude-usage-actions button {
|
|
1309
1311
|
min-height: 34px;
|
|
1310
1312
|
padding: 0.32rem 0.58rem;
|
|
1311
1313
|
font-size: 0.72rem;
|
|
1312
1314
|
}
|
|
1313
|
-
.codex-usage-box
|
|
1315
|
+
.codex-usage-box,
|
|
1316
|
+
.claude-usage-box {
|
|
1314
1317
|
display: grid;
|
|
1315
1318
|
gap: 0.58rem;
|
|
1316
1319
|
padding: 0.72rem;
|
|
@@ -1319,58 +1322,80 @@ body.embedded-split .side-panel-backdrop {
|
|
|
1319
1322
|
background: rgba(var(--ctp-crust-rgb), 0.50);
|
|
1320
1323
|
box-shadow: inset 0 1px 0 rgba(255,255,255,0.035), 0 0 1rem rgba(203, 166, 247, 0.05);
|
|
1321
1324
|
}
|
|
1322
|
-
.codex-usage-summary
|
|
1325
|
+
.codex-usage-summary,
|
|
1326
|
+
.claude-usage-summary {
|
|
1323
1327
|
display: flex;
|
|
1324
1328
|
flex-wrap: wrap;
|
|
1325
1329
|
justify-content: space-between;
|
|
1326
1330
|
gap: 0.35rem 0.55rem;
|
|
1327
1331
|
align-items: baseline;
|
|
1328
1332
|
}
|
|
1329
|
-
.codex-usage-plan
|
|
1333
|
+
.codex-usage-plan,
|
|
1334
|
+
.claude-usage-plan {
|
|
1330
1335
|
color: rgba(var(--ctp-text-rgb), 0.94);
|
|
1331
1336
|
font-weight: 900;
|
|
1332
1337
|
}
|
|
1333
1338
|
.codex-usage-fetched,
|
|
1334
1339
|
.codex-usage-detail,
|
|
1335
|
-
.codex-usage-reset
|
|
1340
|
+
.codex-usage-reset,
|
|
1341
|
+
.claude-usage-fetched,
|
|
1342
|
+
.claude-usage-detail,
|
|
1343
|
+
.claude-usage-reset {
|
|
1336
1344
|
color: rgba(var(--ctp-subtext-rgb), 0.70);
|
|
1337
1345
|
font-size: 0.72rem;
|
|
1338
1346
|
line-height: 1.35;
|
|
1339
1347
|
}
|
|
1340
1348
|
.codex-usage-unavailable,
|
|
1341
|
-
.codex-usage-warning
|
|
1349
|
+
.codex-usage-warning,
|
|
1350
|
+
.claude-usage-unavailable,
|
|
1351
|
+
.claude-usage-warning {
|
|
1342
1352
|
color: var(--ctp-yellow);
|
|
1343
1353
|
font-weight: 800;
|
|
1344
1354
|
}
|
|
1345
|
-
.codex-usage-bucket
|
|
1355
|
+
.codex-usage-bucket,
|
|
1356
|
+
.claude-usage-bucket,
|
|
1357
|
+
.claude-usage-activity-group {
|
|
1346
1358
|
display: grid;
|
|
1347
1359
|
gap: 0.32rem;
|
|
1348
1360
|
}
|
|
1349
|
-
.
|
|
1361
|
+
.claude-usage-activity-group {
|
|
1362
|
+
padding-top: 0.12rem;
|
|
1363
|
+
}
|
|
1364
|
+
.codex-usage-row,
|
|
1365
|
+
.claude-usage-row {
|
|
1350
1366
|
display: flex;
|
|
1351
1367
|
justify-content: space-between;
|
|
1352
1368
|
gap: 0.6rem;
|
|
1353
1369
|
align-items: center;
|
|
1354
1370
|
}
|
|
1355
|
-
.codex-usage-label
|
|
1371
|
+
.codex-usage-label,
|
|
1372
|
+
.claude-usage-label,
|
|
1373
|
+
.claude-usage-activity-title {
|
|
1356
1374
|
min-width: 0;
|
|
1357
1375
|
color: rgba(var(--ctp-text-rgb), 0.86);
|
|
1358
1376
|
font-size: 0.78rem;
|
|
1359
1377
|
font-weight: 800;
|
|
1360
1378
|
overflow-wrap: anywhere;
|
|
1361
1379
|
}
|
|
1362
|
-
.
|
|
1380
|
+
.claude-usage-activity-title {
|
|
1381
|
+
color: var(--ctp-lavender);
|
|
1382
|
+
font-size: 0.74rem;
|
|
1383
|
+
}
|
|
1384
|
+
.codex-usage-percent,
|
|
1385
|
+
.claude-usage-percent {
|
|
1363
1386
|
color: var(--ctp-teal);
|
|
1364
1387
|
font-size: 0.82rem;
|
|
1365
1388
|
}
|
|
1366
|
-
.codex-usage-meter
|
|
1389
|
+
.codex-usage-meter,
|
|
1390
|
+
.claude-usage-meter {
|
|
1367
1391
|
overflow: hidden;
|
|
1368
1392
|
height: 0.5rem;
|
|
1369
1393
|
border: 1px solid rgba(180, 190, 254, 0.14);
|
|
1370
1394
|
border-radius: 999px;
|
|
1371
1395
|
background: rgba(var(--ctp-surface-rgb), 0.26);
|
|
1372
1396
|
}
|
|
1373
|
-
.codex-usage-meter-fill
|
|
1397
|
+
.codex-usage-meter-fill,
|
|
1398
|
+
.claude-usage-meter-fill {
|
|
1374
1399
|
display: block;
|
|
1375
1400
|
height: 100%;
|
|
1376
1401
|
border-radius: inherit;
|