@firstpick/pi-package-webui 0.6.5 → 0.6.7
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 +22 -10
- package/bin/pi-webui.mjs +627 -58
- package/index.ts +124 -0
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/git-workflow-preferences.mjs +153 -0
- package/lib/update-commands.mjs +20 -0
- package/package.json +4 -4
- package/public/app.js +790 -45
- package/public/index.html +26 -7
- package/public/styles.css +277 -2
- package/tests/document-artifact-static.test.mjs +18 -0
- package/tests/fixtures/fake-pi.mjs +65 -0
- package/tests/git-workflow-preferences.test.mjs +67 -0
- package/tests/http-endpoints-harness.test.mjs +62 -0
- package/tests/markdown-links.test.mjs +113 -0
- package/tests/mobile-static.test.mjs +74 -24
- package/tests/native-parity-harness.test.mjs +1 -1
- package/tests/native-parity.test.mjs +1 -0
- package/tests/remote-auth-settings-harness.test.mjs +41 -0
- package/tests/subagents-helper.test.mjs +210 -0
- package/tests/theme-scheme-mode.test.mjs +5 -5
- package/tests/update-commands.test.mjs +44 -0
- package/webui-rpc-helper.mjs +536 -2
package/public/app.js
CHANGED
|
@@ -108,6 +108,7 @@ const elements = {
|
|
|
108
108
|
optionsNameButton: $("#optionsNameButton"),
|
|
109
109
|
optionsCloneButton: $("#optionsCloneButton"),
|
|
110
110
|
optionsSettingsButton: $("#optionsSettingsButton"),
|
|
111
|
+
optionsGitWorkflowSetupButton: $("#optionsGitWorkflowSetupButton"),
|
|
111
112
|
optionsExportButton: $("#optionsExportButton"),
|
|
112
113
|
optionsForkButton: $("#optionsForkButton"),
|
|
113
114
|
optionsTreeButton: $("#optionsTreeButton"),
|
|
@@ -208,6 +209,9 @@ const elements = {
|
|
|
208
209
|
sidePanelBackdrop: $("#sidePanelBackdrop"),
|
|
209
210
|
sidePanel: $("#sidePanel"),
|
|
210
211
|
stateDetails: $("#stateDetails"),
|
|
212
|
+
subagentsStatus: $("#subagentsStatus"),
|
|
213
|
+
subagentsBox: $("#subagentsBox"),
|
|
214
|
+
subagentCountBadge: $("#subagentCountBadge"),
|
|
211
215
|
queueBox: $("#queueBox"),
|
|
212
216
|
queueCountBadge: $("#queueCountBadge"),
|
|
213
217
|
createPromptListButton: $("#createPromptListButton"),
|
|
@@ -405,7 +409,7 @@ let statsOverlayCalibrationMessage = "";
|
|
|
405
409
|
let statsOverlayCalibrationBusy = "";
|
|
406
410
|
let latestStatsOverlayPayload = null;
|
|
407
411
|
let latestBtwWidgetPayload = null;
|
|
408
|
-
|
|
412
|
+
const btwWidgetDismissedIdsByTab = new Map();
|
|
409
413
|
let btwWidgetComposerOpen = false;
|
|
410
414
|
let btwWidgetInputDraft = "";
|
|
411
415
|
let btwWidgetFocusAfterRender = false;
|
|
@@ -426,6 +430,16 @@ let claudeUsageError = null;
|
|
|
426
430
|
let claudeUsageLoading = false;
|
|
427
431
|
let refreshClaudeUsageTimer = null;
|
|
428
432
|
let claudeUsageRenderTimer = null;
|
|
433
|
+
let latestSubagents = null;
|
|
434
|
+
let subagentsError = null;
|
|
435
|
+
let subagentsLoading = false;
|
|
436
|
+
let refreshSubagentsTimer = null;
|
|
437
|
+
let subagentOverlaySelection = null;
|
|
438
|
+
let subagentOverlayData = null;
|
|
439
|
+
let subagentOverlayError = "";
|
|
440
|
+
let subagentOverlayLoading = false;
|
|
441
|
+
let subagentOverlayRefreshTimer = null;
|
|
442
|
+
let subagentOverlayRequestSerial = 0;
|
|
429
443
|
let backendOffline = false;
|
|
430
444
|
let serverRestartInProgress = false;
|
|
431
445
|
let updateRequestInProgress = false;
|
|
@@ -676,6 +690,10 @@ const CODEX_USAGE_REFRESH_MS = 5 * 60 * 1000;
|
|
|
676
690
|
const CODEX_USAGE_RENDER_TICK_MS = 30 * 1000;
|
|
677
691
|
const CLAUDE_USAGE_REFRESH_MS = 5 * 60 * 1000;
|
|
678
692
|
const CLAUDE_USAGE_RENDER_TICK_MS = 30 * 1000;
|
|
693
|
+
const SUBAGENTS_ACTIVE_REFRESH_MS = 1500;
|
|
694
|
+
const SUBAGENTS_IDLE_REFRESH_MS = 4000;
|
|
695
|
+
const SUBAGENTS_HIDDEN_REFRESH_MS = 10_000;
|
|
696
|
+
const SUBAGENT_OVERLAY_REFRESH_MS = 1000;
|
|
679
697
|
const UPDATE_STATUS_REFRESH_MS = 6 * 60 * 60 * 1000;
|
|
680
698
|
const UPDATE_STATUS_INITIAL_DELAY_MS = 1800;
|
|
681
699
|
const RUN_INDICATOR_TICK_MS = 1000;
|
|
@@ -925,8 +943,8 @@ const HIDDEN_COMMAND_NAMES = new Set(["webui-tree-navigate", "webui-helper"]);
|
|
|
925
943
|
HIDDEN_COMMAND_NAMES.add("stats-webui");
|
|
926
944
|
HIDDEN_COMMAND_NAMES.add("btw-status");
|
|
927
945
|
HIDDEN_COMMAND_NAMES.add("btw-transfer");
|
|
928
|
-
const NATIVE_SELECTOR_COMMANDS = new Set(["model", "settings", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"]);
|
|
929
|
-
const SETTINGS_THINKING_OPTIONS = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
946
|
+
const NATIVE_SELECTOR_COMMANDS = new Set(["model", "settings", "git-workflow-setup", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"]);
|
|
947
|
+
const SETTINGS_THINKING_OPTIONS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
930
948
|
const SETTINGS_TRANSPORT_OPTIONS = ["sse", "websocket", "websocket-cached", "auto"];
|
|
931
949
|
const SETTINGS_HTTP_IDLE_TIMEOUT_OPTIONS = [
|
|
932
950
|
{ value: "30000", label: "30 sec" },
|
|
@@ -1023,11 +1041,14 @@ function createGitWorkflowState() {
|
|
|
1023
1041
|
prBranch: "",
|
|
1024
1042
|
pr: null,
|
|
1025
1043
|
prRequestedAt: 0,
|
|
1044
|
+
preferences: null,
|
|
1045
|
+
verificationConfirmed: false,
|
|
1026
1046
|
};
|
|
1027
1047
|
}
|
|
1028
1048
|
|
|
1029
1049
|
const gitWorkflowsByTab = new Map();
|
|
1030
1050
|
let gitWorkflow = createGitWorkflowState();
|
|
1051
|
+
let gitWorkflowPreferences = null;
|
|
1031
1052
|
|
|
1032
1053
|
function gitWorkflowForTab(tabId = activeTabId, { create = true } = {}) {
|
|
1033
1054
|
if (!tabId) return null;
|
|
@@ -3275,9 +3296,9 @@ function renderUpdateNotification(status = latestUpdateStatus, { force = false }
|
|
|
3275
3296
|
if (elements.updateNotificationMessage) {
|
|
3276
3297
|
let message = "Updates are available. Direct Web UI updates are only enabled from localhost on the host machine.";
|
|
3277
3298
|
if (canRunUpdate) {
|
|
3278
|
-
if (hasPiUpdate && hasPackageUpdate) message = "Run pi update for Pi only, or update all to include Web UI, Optional Features, configured Pi packages, and detected Pi package roots, then restart this Web UI server automatically.";
|
|
3279
|
-
else if (hasPackageUpdate) message = "Update all
|
|
3280
|
-
else message = "Run pi update for Pi only, then restart this Web UI server automatically.";
|
|
3299
|
+
if (hasPiUpdate && hasPackageUpdate) message = "Run pi update --self for Pi only, or update all to use pi update --all when supported and include Web UI, Optional Features, configured Pi packages, and detected Pi package roots, then restart this Web UI server automatically.";
|
|
3300
|
+
else if (hasPackageUpdate) message = "Update all checks for pi update --all support, then refreshes Web UI/package entries, Optional Features, configured Pi packages, and detected Pi package roots before restarting this Web UI server automatically.";
|
|
3301
|
+
else message = "Run pi update --self for Pi only, then restart this Web UI server automatically.";
|
|
3281
3302
|
}
|
|
3282
3303
|
elements.updateNotificationMessage.textContent = message;
|
|
3283
3304
|
}
|
|
@@ -3331,10 +3352,10 @@ function piUpdateConfirmationText({ all = false } = {}) {
|
|
|
3331
3352
|
const items = updateNotificationItems();
|
|
3332
3353
|
const workingWarning = hasWorkingTab() ? "\n\nOne or more Pi tabs look busy or blocked. Finish or abort in-flight work before updating if you need to preserve it." : "";
|
|
3333
3354
|
const versionText = items.length ? `\n\nDetected update: ${items.join(" · ")}.` : "";
|
|
3334
|
-
const
|
|
3355
|
+
const commandText = all ? '"pi update --all" when supported, otherwise "pi update --self" followed by "pi update --extensions"' : '"pi update --self"';
|
|
3335
3356
|
const scope = all ? "Pi, configured packages, Optional Features, and detected Pi package roots" : "Pi only";
|
|
3336
3357
|
const extra = all ? " It will also run npm/bun package updates for detected Web UI, Optional Feature, agent, project, and global Pi package roots." : "";
|
|
3337
|
-
return `Run ${scope} now?${versionText}\n\nThis will run
|
|
3358
|
+
return `Run ${scope} now?${versionText}\n\nThis will run ${commandText} on the Web UI host.${extra} After it finishes, Pi Web UI will restart itself. Browser clients will briefly disconnect, and managed Pi tabs/RPC processes will be restarted from saved session state when possible.${workingWarning}`;
|
|
3338
3359
|
}
|
|
3339
3360
|
|
|
3340
3361
|
async function runPiUpdateAndRestart({ all = false } = {}) {
|
|
@@ -4984,7 +5005,7 @@ function setOptionalFeatureDisabled(featureId, disabled) {
|
|
|
4984
5005
|
widgets.delete(BTW_OUTPUT_WIDGET_KEY);
|
|
4985
5006
|
widgets.delete(BTW_FOOTER_WIDGET_KEY);
|
|
4986
5007
|
latestBtwWidgetPayload = null;
|
|
4987
|
-
|
|
5008
|
+
btwWidgetDismissedIdsByTab.delete(activeTabId);
|
|
4988
5009
|
btwWidgetComposerOpen = false;
|
|
4989
5010
|
btwWidgetInputDraft = "";
|
|
4990
5011
|
}
|
|
@@ -7001,7 +7022,7 @@ function restoreActiveDraft() {
|
|
|
7001
7022
|
|
|
7002
7023
|
function focusPromptInput({ defer = false } = {}) {
|
|
7003
7024
|
const focus = () => {
|
|
7004
|
-
if (!elements.promptInput || elements.dialog.open || elements.pathPickerDialog.open || elements.gitChangesDialog?.open || elements.commandPaletteDialog?.open || elements.editRetryDialog?.open || elements.nativeCommandDialog.open || elements.remoteQrDialog?.open || elements.appRunnerInfoDialog?.open || elements.gitFooterVisibilityDialog?.open || elements.promptListDialog?.open || elements.attachmentTextDialog?.open || elements.skillEditorDialog?.open || document.visibilityState === "hidden") return;
|
|
7025
|
+
if (!elements.promptInput || elements.dialog.open || elements.pathPickerDialog.open || elements.gitChangesDialog?.open || elements.commandPaletteDialog?.open || elements.editRetryDialog?.open || elements.nativeCommandDialog.open || elements.remoteQrDialog?.open || elements.appRunnerInfoDialog?.open || elements.gitFooterVisibilityDialog?.open || elements.statsOverlayDialog?.open || elements.promptListDialog?.open || elements.attachmentTextDialog?.open || elements.skillEditorDialog?.open || document.visibilityState === "hidden") return;
|
|
7005
7026
|
try {
|
|
7006
7027
|
elements.promptInput.focus({ preventScroll: true });
|
|
7007
7028
|
} catch {
|
|
@@ -7140,7 +7161,6 @@ function resetActiveTabUi() {
|
|
|
7140
7161
|
latestStats = null;
|
|
7141
7162
|
latestStatsOverlayPayload = null;
|
|
7142
7163
|
latestBtwWidgetPayload = null;
|
|
7143
|
-
btwWidgetDismissedId = "";
|
|
7144
7164
|
btwWidgetComposerOpen = false;
|
|
7145
7165
|
btwWidgetInputDraft = "";
|
|
7146
7166
|
latestWorkspace = null;
|
|
@@ -7835,6 +7855,7 @@ async function closeTerminalTabs(tabIds, { label = "selected terminal tabs" } =
|
|
|
7835
7855
|
clearGitWorkflowForTab(id);
|
|
7836
7856
|
appRunnerDataByTab.delete(id);
|
|
7837
7857
|
tabMessagesCache.delete(id);
|
|
7858
|
+
btwWidgetDismissedIdsByTab.delete(id);
|
|
7838
7859
|
}
|
|
7839
7860
|
syncTerminalCustomGroupsWithTabs(tabs);
|
|
7840
7861
|
clearOpenTerminalTabGroup(null, { force: true });
|
|
@@ -8386,7 +8407,7 @@ function applyOptimisticThinkingSelection(data, tabContext = activeTabContext())
|
|
|
8386
8407
|
|
|
8387
8408
|
function footerThinkingLevels() {
|
|
8388
8409
|
const levels = Array.from(elements.thinkingSelect?.options || []).map((option) => option.value).filter(Boolean);
|
|
8389
|
-
return levels.length ? levels : ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
8410
|
+
return levels.length ? levels : ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
8390
8411
|
}
|
|
8391
8412
|
|
|
8392
8413
|
function formatFooterTokenCount(value) {
|
|
@@ -13484,6 +13505,320 @@ function initializeClaudeUsage() {
|
|
|
13484
13505
|
claudeUsageRenderTimer = setInterval(renderClaudeUsage, CLAUDE_USAGE_RENDER_TICK_MS);
|
|
13485
13506
|
}
|
|
13486
13507
|
|
|
13508
|
+
function subagentTabsWithRunningAgents() {
|
|
13509
|
+
return (Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : [])
|
|
13510
|
+
.filter((tab) => Number(tab?.agentCount || 0) > 0)
|
|
13511
|
+
.sort((a, b) => Number(a.tabIndex || 0) - Number(b.tabIndex || 0) || String(a.tabTitle || "").localeCompare(String(b.tabTitle || "")));
|
|
13512
|
+
}
|
|
13513
|
+
|
|
13514
|
+
function subagentSessionFileName(value) {
|
|
13515
|
+
return String(value || "").split(/[\\/]/).filter(Boolean).pop() || "";
|
|
13516
|
+
}
|
|
13517
|
+
|
|
13518
|
+
function subagentTabMeta(tab) {
|
|
13519
|
+
const sessionName = String(tab?.sessionName || "").trim();
|
|
13520
|
+
const title = String(tab?.tabTitle || "").trim();
|
|
13521
|
+
if (sessionName && sessionName !== title) return sessionName;
|
|
13522
|
+
return subagentSessionFileName(tab?.sessionFile) || normalizeDisplayPath(tab?.cwd || "") || "session";
|
|
13523
|
+
}
|
|
13524
|
+
|
|
13525
|
+
function subagentRunElapsed(run) {
|
|
13526
|
+
const startedAt = Number(run?.startedAt);
|
|
13527
|
+
return Number.isFinite(startedAt) ? formatDuration(Math.max(0, Date.now() - startedAt)) : "";
|
|
13528
|
+
}
|
|
13529
|
+
|
|
13530
|
+
function subagentOverlayOutputLines(data = subagentOverlayData) {
|
|
13531
|
+
const agent = data?.agent || subagentOverlaySelection?.agent || {};
|
|
13532
|
+
const output = (Array.isArray(agent.recentOutput) ? agent.recentOutput : [])
|
|
13533
|
+
.flatMap((line) => stripAnsi(String(line ?? "")).replace(/\r/g, "").split("\n"));
|
|
13534
|
+
if (output.length) return output;
|
|
13535
|
+
const tools = (Array.isArray(agent.recentTools) ? agent.recentTools : [])
|
|
13536
|
+
.map((entry) => `✓ ${entry.tool || "tool"}${entry.args ? ` ${entry.args}` : ""}`);
|
|
13537
|
+
if (agent.currentTool) tools.push(`▶ ${agent.currentTool}${agent.currentToolArgs ? ` ${agent.currentToolArgs}` : ""}`);
|
|
13538
|
+
return tools;
|
|
13539
|
+
}
|
|
13540
|
+
|
|
13541
|
+
function appendSubagentOutputWaitingIndicator(parent) {
|
|
13542
|
+
const row = make("div", "release-npm-line subagent-output-waiting");
|
|
13543
|
+
row.setAttribute("role", "status");
|
|
13544
|
+
row.setAttribute("aria-label", "Waiting for agent output");
|
|
13545
|
+
row.append(
|
|
13546
|
+
make("span", "subagent-output-waiting-dot", "."),
|
|
13547
|
+
make("span", "subagent-output-waiting-dot", "."),
|
|
13548
|
+
make("span", "subagent-output-waiting-dot", "."),
|
|
13549
|
+
);
|
|
13550
|
+
parent.append(row);
|
|
13551
|
+
}
|
|
13552
|
+
|
|
13553
|
+
function subagentOverlayStateFacts(data = subagentOverlayData) {
|
|
13554
|
+
const agent = data?.agent || subagentOverlaySelection?.agent || {};
|
|
13555
|
+
return [
|
|
13556
|
+
agent.status || "running",
|
|
13557
|
+
data?.mode || subagentOverlaySelection?.run?.mode,
|
|
13558
|
+
data?.source || subagentOverlaySelection?.run?.source,
|
|
13559
|
+
agent.nested ? "nested" : "",
|
|
13560
|
+
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
13561
|
+
Number.isFinite(agent.turnCount) ? `${agent.turnCount} turns` : "",
|
|
13562
|
+
Number.isFinite(agent.toolCount) ? `${agent.toolCount} tools` : "",
|
|
13563
|
+
Number.isFinite(agent.tokens) ? `${Number(agent.tokens).toLocaleString()} tokens` : "",
|
|
13564
|
+
].filter(Boolean);
|
|
13565
|
+
}
|
|
13566
|
+
|
|
13567
|
+
function subagentOverlayMeaningfulSignature() {
|
|
13568
|
+
return JSON.stringify({
|
|
13569
|
+
selection: subagentOverlaySelection ? {
|
|
13570
|
+
tabId: subagentOverlaySelection.tabId,
|
|
13571
|
+
runId: subagentOverlaySelection.runId,
|
|
13572
|
+
agentId: subagentOverlaySelection.agentId,
|
|
13573
|
+
finished: subagentOverlaySelection.finished === true,
|
|
13574
|
+
} : null,
|
|
13575
|
+
data: subagentOverlayData ? { ...subagentOverlayData, updatedAt: undefined } : null,
|
|
13576
|
+
error: subagentOverlayError,
|
|
13577
|
+
});
|
|
13578
|
+
}
|
|
13579
|
+
|
|
13580
|
+
function renderSubagentOverlayWidget() {
|
|
13581
|
+
const selection = subagentOverlaySelection;
|
|
13582
|
+
if (!selection || selection.tabId !== activeTabId) return null;
|
|
13583
|
+
const data = subagentOverlayData;
|
|
13584
|
+
const agent = data?.agent || selection.agent || {};
|
|
13585
|
+
const tab = tabs.find((item) => item.id === selection.tabId) || selection.tab;
|
|
13586
|
+
const running = !selection.finished && (agent.status === "running" || agent.status === "queued" || agent.status === "pending" || !agent.status);
|
|
13587
|
+
const lines = subagentOverlayOutputLines(data);
|
|
13588
|
+
const shownLines = lines.length ? lines : running && agent.currentTool ? [] : [running ? "Waiting for the first agent activity…" : "No recent output was captured."];
|
|
13589
|
+
const widget = make("section", `widget release-npm-widget app-runner-widget subagent-overlay-widget${running ? " app-runner-live-widget" : " app-runner-log-widget"}`);
|
|
13590
|
+
widget.setAttribute("aria-label", `Live output for subagent ${agent.name || "subagent"}`);
|
|
13591
|
+
|
|
13592
|
+
const header = make("div", "release-npm-header");
|
|
13593
|
+
const titleWrap = make("div", "release-npm-title-wrap");
|
|
13594
|
+
titleWrap.append(make("span", "release-npm-kicker", "subagent"), make("strong", "release-npm-title", agent.name || "subagent"));
|
|
13595
|
+
const meta = make("div", "release-npm-meta");
|
|
13596
|
+
for (const fact of subagentOverlayStateFacts(data)) meta.append(make("span", "release-npm-pill", fact));
|
|
13597
|
+
header.append(titleWrap, meta);
|
|
13598
|
+
|
|
13599
|
+
const streamHeader = releaseNpmStreamHeader(running ? "Live agent output" : "Agent output", shownLines.length, { live: running });
|
|
13600
|
+
const terminal = make("div", "release-npm-terminal subagent-overlay-terminal");
|
|
13601
|
+
terminal.setAttribute("role", "log");
|
|
13602
|
+
terminal.setAttribute("aria-live", running ? "polite" : "off");
|
|
13603
|
+
for (const line of shownLines) appendReleaseNpmTerminalLine(terminal, line);
|
|
13604
|
+
if (running && agent.currentTool) appendSubagentOutputWaitingIndicator(terminal);
|
|
13605
|
+
|
|
13606
|
+
const controls = make("div", "release-npm-controls subagent-overlay-output-controls");
|
|
13607
|
+
const actions = make("div", "app-runner-output-actions");
|
|
13608
|
+
const copyButton = appRunnerActionButton("Copy output", copySubagentOverlayOutput, "subagent-overlay-copy-action");
|
|
13609
|
+
copyButton.disabled = subagentOverlayOutputLines(data).length === 0;
|
|
13610
|
+
const refreshButton = appRunnerActionButton(subagentOverlayLoading ? "Refreshing…" : "Refresh", () => {
|
|
13611
|
+
refreshSubagentOverlay().finally(() => scheduleSubagentOverlayRefresh());
|
|
13612
|
+
}, "subagent-overlay-refresh-action");
|
|
13613
|
+
refreshButton.disabled = subagentOverlayLoading || selection.finished;
|
|
13614
|
+
actions.append(copyButton, refreshButton, appRunnerActionButton("Close", closeSubagentOverlay, "subagent-overlay-close-action"));
|
|
13615
|
+
const details = [
|
|
13616
|
+
`${tab?.title || `Terminal ${selection.tabIndex || "?"}`} · run ${selection.runId}`,
|
|
13617
|
+
agent.currentPath ? `path: ${agent.currentPath}` : "",
|
|
13618
|
+
agent.activityState ? `activity: ${agent.activityState}` : "",
|
|
13619
|
+
agent.error ? `status warning: ${agent.error}` : "",
|
|
13620
|
+
subagentOverlayError,
|
|
13621
|
+
].filter(Boolean);
|
|
13622
|
+
controls.append(actions, make("span", `app-runner-output-meta${subagentOverlayError ? " warning" : ""}`, details.join(" · ")));
|
|
13623
|
+
const outputDetails = renderReleaseNpmOutputDetails(`subagent:${selection.tabId}:${selection.agentId}`, streamHeader, terminal, controls);
|
|
13624
|
+
widget.append(header, outputDetails);
|
|
13625
|
+
requestAnimationFrame(() => { if (outputDetails.open) terminal.scrollTop = terminal.scrollHeight; });
|
|
13626
|
+
return widget;
|
|
13627
|
+
}
|
|
13628
|
+
|
|
13629
|
+
function scheduleSubagentOverlayRefresh(delay = SUBAGENT_OVERLAY_REFRESH_MS) {
|
|
13630
|
+
clearTimeout(subagentOverlayRefreshTimer);
|
|
13631
|
+
if (!subagentOverlaySelection || subagentOverlaySelection.finished) return;
|
|
13632
|
+
subagentOverlayRefreshTimer = setTimeout(() => {
|
|
13633
|
+
refreshSubagentOverlay().finally(() => scheduleSubagentOverlayRefresh());
|
|
13634
|
+
}, delay);
|
|
13635
|
+
}
|
|
13636
|
+
|
|
13637
|
+
async function refreshSubagentOverlay() {
|
|
13638
|
+
const selection = subagentOverlaySelection;
|
|
13639
|
+
if (!selection || subagentOverlayLoading) return;
|
|
13640
|
+
const requestSerial = ++subagentOverlayRequestSerial;
|
|
13641
|
+
const previousSignature = subagentOverlayMeaningfulSignature();
|
|
13642
|
+
subagentOverlayLoading = true;
|
|
13643
|
+
try {
|
|
13644
|
+
const query = new URLSearchParams({ tab: selection.tabId, run: selection.runId, agent: selection.agentId });
|
|
13645
|
+
const response = await api(`/api/subagents/output?${query}`, { scoped: false });
|
|
13646
|
+
if (requestSerial !== subagentOverlayRequestSerial || subagentOverlaySelection !== selection) return;
|
|
13647
|
+
subagentOverlayData = response.data || null;
|
|
13648
|
+
subagentOverlayError = "";
|
|
13649
|
+
} catch (error) {
|
|
13650
|
+
if (requestSerial !== subagentOverlayRequestSerial || subagentOverlaySelection !== selection) return;
|
|
13651
|
+
if (error?.statusCode === 404) selection.finished = true;
|
|
13652
|
+
subagentOverlayError = error?.statusCode === 404
|
|
13653
|
+
? "This subagent has finished or is no longer tracked. Showing the last captured output."
|
|
13654
|
+
: `Subagent output refresh failed: ${error.message || String(error)}`;
|
|
13655
|
+
} finally {
|
|
13656
|
+
if (requestSerial === subagentOverlayRequestSerial && subagentOverlaySelection === selection) {
|
|
13657
|
+
subagentOverlayLoading = false;
|
|
13658
|
+
if (selection.tabId === activeTabId && previousSignature !== subagentOverlayMeaningfulSignature()) renderWidgets();
|
|
13659
|
+
}
|
|
13660
|
+
}
|
|
13661
|
+
}
|
|
13662
|
+
|
|
13663
|
+
async function openSubagentOverlay(tab, run, agent) {
|
|
13664
|
+
if (!tab?.tabId || !run?.id || !agent?.id) return;
|
|
13665
|
+
try {
|
|
13666
|
+
if (activeTabId !== tab.tabId) await switchTab(tab.tabId);
|
|
13667
|
+
subagentOverlaySelection = {
|
|
13668
|
+
tabId: tab.tabId,
|
|
13669
|
+
tabIndex: tab.tabIndex,
|
|
13670
|
+
tab,
|
|
13671
|
+
run,
|
|
13672
|
+
agent,
|
|
13673
|
+
runId: run.id,
|
|
13674
|
+
agentId: agent.id,
|
|
13675
|
+
finished: false,
|
|
13676
|
+
};
|
|
13677
|
+
subagentOverlayData = null;
|
|
13678
|
+
subagentOverlayError = "";
|
|
13679
|
+
subagentOverlayRequestSerial += 1;
|
|
13680
|
+
renderWidgets();
|
|
13681
|
+
await refreshSubagentOverlay();
|
|
13682
|
+
scheduleSubagentOverlayRefresh();
|
|
13683
|
+
} catch (error) {
|
|
13684
|
+
addEvent(`could not open subagent output: ${error.message || String(error)}`, "error");
|
|
13685
|
+
}
|
|
13686
|
+
}
|
|
13687
|
+
|
|
13688
|
+
function closeSubagentOverlay() {
|
|
13689
|
+
clearTimeout(subagentOverlayRefreshTimer);
|
|
13690
|
+
subagentOverlayRefreshTimer = null;
|
|
13691
|
+
subagentOverlayRequestSerial += 1;
|
|
13692
|
+
subagentOverlaySelection = null;
|
|
13693
|
+
subagentOverlayData = null;
|
|
13694
|
+
subagentOverlayError = "";
|
|
13695
|
+
subagentOverlayLoading = false;
|
|
13696
|
+
renderWidgets();
|
|
13697
|
+
}
|
|
13698
|
+
|
|
13699
|
+
async function copySubagentOverlayOutput() {
|
|
13700
|
+
const text = subagentOverlayOutputLines().join("\n").trimEnd();
|
|
13701
|
+
if (!text) {
|
|
13702
|
+
addEvent("subagent output is empty", "warn");
|
|
13703
|
+
return;
|
|
13704
|
+
}
|
|
13705
|
+
try {
|
|
13706
|
+
await copyText(text);
|
|
13707
|
+
addEvent("copied subagent output", "info");
|
|
13708
|
+
} catch (error) {
|
|
13709
|
+
addEvent(`subagent output copy failed: ${error.message || String(error)}`, "warn");
|
|
13710
|
+
}
|
|
13711
|
+
}
|
|
13712
|
+
|
|
13713
|
+
function renderSubagentAgent(tab, run, agent) {
|
|
13714
|
+
const row = make("button", `subagent-agent-row${agent?.nested ? " nested" : ""}`);
|
|
13715
|
+
row.type = "button";
|
|
13716
|
+
const dot = make("span", "subagent-running-dot");
|
|
13717
|
+
dot.setAttribute("aria-hidden", "true");
|
|
13718
|
+
const content = make("div", "subagent-agent-content");
|
|
13719
|
+
content.append(make("strong", "subagent-agent-name", agent?.name || "subagent"));
|
|
13720
|
+
const elapsed = subagentRunElapsed(run);
|
|
13721
|
+
const facts = [
|
|
13722
|
+
agent?.nested ? "nested" : "",
|
|
13723
|
+
run?.mode && run.mode !== "single" ? run.mode : "",
|
|
13724
|
+
run?.source === "foreground" ? "foreground" : "async",
|
|
13725
|
+
agent?.currentTool ? `tool: ${agent.currentTool}` : "",
|
|
13726
|
+
elapsed ? `running ${elapsed}` : "",
|
|
13727
|
+
].filter(Boolean);
|
|
13728
|
+
content.append(make("span", "subagent-agent-meta", facts.join(" · ")));
|
|
13729
|
+
row.append(dot, content);
|
|
13730
|
+
row.title = `${agent?.name || "subagent"} · ${facts.join(" · ")} · run ${run?.id || "unknown"} · open live output`;
|
|
13731
|
+
row.setAttribute("aria-label", `Open live output for ${agent?.name || "subagent"} in ${tab?.tabTitle || `Terminal ${tab?.tabIndex || "?"}`}`);
|
|
13732
|
+
row.addEventListener("click", () => openSubagentOverlay(tab, run, agent));
|
|
13733
|
+
return row;
|
|
13734
|
+
}
|
|
13735
|
+
|
|
13736
|
+
function renderSubagentTabGroup(tab) {
|
|
13737
|
+
const group = make("section", `subagent-tab-group${tab.tabId === activeTabId ? " active" : ""}`);
|
|
13738
|
+
const header = make("button", "subagent-tab-header");
|
|
13739
|
+
header.type = "button";
|
|
13740
|
+
header.setAttribute("aria-label", `Open ${tab.tabTitle || `Terminal ${tab.tabIndex || ""}`}`);
|
|
13741
|
+
const title = make("span", "subagent-tab-title");
|
|
13742
|
+
title.append(
|
|
13743
|
+
make("strong", undefined, tab.tabTitle || `Terminal ${tab.tabIndex || "?"}`),
|
|
13744
|
+
make("span", "subagent-tab-session", `Terminal ${tab.tabIndex || "?"} · ${subagentTabMeta(tab)}`),
|
|
13745
|
+
);
|
|
13746
|
+
header.append(title, make("span", "subagent-tab-count", String(tab.agentCount || 0)));
|
|
13747
|
+
header.addEventListener("click", () => switchTab(tab.tabId));
|
|
13748
|
+
group.append(header);
|
|
13749
|
+
|
|
13750
|
+
const list = make("div", "subagent-agent-list");
|
|
13751
|
+
const runs = (Array.isArray(tab.runs) ? tab.runs : [])
|
|
13752
|
+
.slice()
|
|
13753
|
+
.sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0) || String(a.id || "").localeCompare(String(b.id || "")));
|
|
13754
|
+
for (const run of runs) {
|
|
13755
|
+
const agents = (Array.isArray(run.agents) ? run.agents : [])
|
|
13756
|
+
.filter((agent) => agent?.status === "running")
|
|
13757
|
+
.sort((a, b) => Number(a.index || 0) - Number(b.index || 0) || String(a.name || "").localeCompare(String(b.name || "")));
|
|
13758
|
+
for (const agent of agents) list.append(renderSubagentAgent(tab, run, agent));
|
|
13759
|
+
}
|
|
13760
|
+
group.append(list);
|
|
13761
|
+
return group;
|
|
13762
|
+
}
|
|
13763
|
+
|
|
13764
|
+
function renderSubagents() {
|
|
13765
|
+
const box = elements.subagentsBox;
|
|
13766
|
+
if (!box) return;
|
|
13767
|
+
const activeTabs = subagentTabsWithRunningAgents();
|
|
13768
|
+
const totalAgents = activeTabs.reduce((count, tab) => count + Number(tab.agentCount || 0), 0);
|
|
13769
|
+
if (elements.subagentCountBadge) {
|
|
13770
|
+
elements.subagentCountBadge.textContent = String(totalAgents);
|
|
13771
|
+
elements.subagentCountBadge.hidden = totalAgents === 0;
|
|
13772
|
+
}
|
|
13773
|
+
if (elements.subagentsStatus) {
|
|
13774
|
+
elements.subagentsStatus.textContent = totalAgents > 0
|
|
13775
|
+
? `${totalAgents} running across ${activeTabs.length} ${activeTabs.length === 1 ? "terminal" : "terminals"}`
|
|
13776
|
+
: subagentsLoading && !latestSubagents
|
|
13777
|
+
? "Checking running subagents…"
|
|
13778
|
+
: "No running subagents.";
|
|
13779
|
+
}
|
|
13780
|
+
|
|
13781
|
+
box.replaceChildren();
|
|
13782
|
+
box.classList.toggle("muted", totalAgents === 0);
|
|
13783
|
+
box.classList.toggle("has-items", totalAgents > 0);
|
|
13784
|
+
if (totalAgents === 0) {
|
|
13785
|
+
box.append(make("div", "subagents-empty", subagentsError ? `Subagent status unavailable: ${subagentsError.message || subagentsError}` : "Running subagents will appear here, grouped by terminal and session."));
|
|
13786
|
+
return;
|
|
13787
|
+
}
|
|
13788
|
+
for (const tab of activeTabs) box.append(renderSubagentTabGroup(tab));
|
|
13789
|
+
if (subagentsError) box.append(make("div", "subagents-stale muted", `Latest refresh failed: ${subagentsError.message || subagentsError}`));
|
|
13790
|
+
}
|
|
13791
|
+
|
|
13792
|
+
async function refreshSubagents() {
|
|
13793
|
+
if (subagentsLoading) return;
|
|
13794
|
+
subagentsLoading = true;
|
|
13795
|
+
renderSubagents();
|
|
13796
|
+
try {
|
|
13797
|
+
const response = await api("/api/subagents", { scoped: false });
|
|
13798
|
+
latestSubagents = response.data || null;
|
|
13799
|
+
subagentsError = null;
|
|
13800
|
+
} catch (error) {
|
|
13801
|
+
subagentsError = error;
|
|
13802
|
+
} finally {
|
|
13803
|
+
subagentsLoading = false;
|
|
13804
|
+
renderSubagents();
|
|
13805
|
+
}
|
|
13806
|
+
}
|
|
13807
|
+
|
|
13808
|
+
function scheduleRefreshSubagents(delay) {
|
|
13809
|
+
clearTimeout(refreshSubagentsTimer);
|
|
13810
|
+
const totalAgents = Number(latestSubagents?.totalAgents || 0);
|
|
13811
|
+
const nextDelay = delay ?? (document.visibilityState === "hidden" ? SUBAGENTS_HIDDEN_REFRESH_MS : totalAgents > 0 ? SUBAGENTS_ACTIVE_REFRESH_MS : SUBAGENTS_IDLE_REFRESH_MS);
|
|
13812
|
+
refreshSubagentsTimer = setTimeout(() => {
|
|
13813
|
+
refreshSubagents().finally(() => scheduleRefreshSubagents());
|
|
13814
|
+
}, nextDelay);
|
|
13815
|
+
}
|
|
13816
|
+
|
|
13817
|
+
function initializeSubagents() {
|
|
13818
|
+
renderSubagents();
|
|
13819
|
+
refreshSubagents().finally(() => scheduleRefreshSubagents());
|
|
13820
|
+
}
|
|
13821
|
+
|
|
13487
13822
|
function renderStatus() {
|
|
13488
13823
|
if (deferUiRenderDuringPointerActivation("status", renderStatus)) return;
|
|
13489
13824
|
const state = currentState;
|
|
@@ -15377,7 +15712,7 @@ function currentBtwWidgetPayload() {
|
|
|
15377
15712
|
if (isOptionalFeatureDisabled("btwCommand")) return null;
|
|
15378
15713
|
const outputLines = widgets.get(BTW_OUTPUT_WIDGET_KEY)?.widgetLines || [];
|
|
15379
15714
|
const payload = parseBtwWidgetPayload(outputLines) || parseBtwWebuiPayloadRaw(statusEntries.get(BTW_WEBUI_STATUS_KEY)) || latestBtwWidgetPayload;
|
|
15380
|
-
if (payload?.id && payload.id ===
|
|
15715
|
+
if (payload?.id && payload.id === btwWidgetDismissedIdsByTab.get(activeTabId)) return null;
|
|
15381
15716
|
return payload;
|
|
15382
15717
|
}
|
|
15383
15718
|
|
|
@@ -15408,7 +15743,7 @@ function focusBtwWidgetInput() {
|
|
|
15408
15743
|
|
|
15409
15744
|
function openBtwComposerWidget() {
|
|
15410
15745
|
btwWidgetComposerOpen = true;
|
|
15411
|
-
|
|
15746
|
+
btwWidgetDismissedIdsByTab.delete(activeTabId);
|
|
15412
15747
|
btwWidgetFocusAfterRender = true;
|
|
15413
15748
|
setComposerActionsOpen(false);
|
|
15414
15749
|
setPublishMenuOpen(false);
|
|
@@ -15420,7 +15755,7 @@ function openBtwComposerWidget() {
|
|
|
15420
15755
|
|
|
15421
15756
|
function closeBtwOutputWidget() {
|
|
15422
15757
|
const payload = currentBtwWidgetPayload();
|
|
15423
|
-
if (payload?.id)
|
|
15758
|
+
if (payload?.id && activeTabId) btwWidgetDismissedIdsByTab.set(activeTabId, payload.id);
|
|
15424
15759
|
widgets.delete(BTW_OUTPUT_WIDGET_KEY);
|
|
15425
15760
|
widgets.delete(BTW_FOOTER_WIDGET_KEY);
|
|
15426
15761
|
statusEntries.delete(BTW_WEBUI_STATUS_KEY);
|
|
@@ -15989,6 +16324,8 @@ function renderWidgets() {
|
|
|
15989
16324
|
if (workflowSubprocessWidget) elements.widgetArea.append(workflowSubprocessWidget);
|
|
15990
16325
|
const appRunnerWidget = renderAppRunnerWidget();
|
|
15991
16326
|
if (appRunnerWidget) elements.widgetArea.append(appRunnerWidget);
|
|
16327
|
+
const subagentWidget = renderSubagentOverlayWidget();
|
|
16328
|
+
if (subagentWidget) elements.widgetArea.append(subagentWidget);
|
|
15992
16329
|
const btwWidget = renderBtwOutputWidget();
|
|
15993
16330
|
if (btwWidget) elements.widgetArea.append(btwWidget);
|
|
15994
16331
|
|
|
@@ -16541,7 +16878,7 @@ function gitWorkflowTitle() {
|
|
|
16541
16878
|
case "remoteAdding": return "Adding origin remote";
|
|
16542
16879
|
case "initialPush": return "Push main upstream";
|
|
16543
16880
|
case "initialPushing": return "Pushing main";
|
|
16544
|
-
case "add": return "Stage all changes";
|
|
16881
|
+
case "add": return (gitWorkflow.preferences || gitWorkflowPreferences)?.stagingPolicy === "all" ? "Stage all changes" : "Review staged changes";
|
|
16545
16882
|
case "generate": return "Generate staged commit message";
|
|
16546
16883
|
case "generating": return "Waiting for /git-staged-msg";
|
|
16547
16884
|
case "message": return gitWorkflow.prMode ? "Choose PR branch commit message" : "Choose commit message";
|
|
@@ -16578,7 +16915,9 @@ function gitWorkflowHint() {
|
|
|
16578
16915
|
case "remoteAdding": return "Adding the GitHub origin remote.";
|
|
16579
16916
|
case "initialPush": return "Step 7: run git push -u origin main.";
|
|
16580
16917
|
case "initialPushing": return "Pushing main upstream. Authentication must already be available to git.";
|
|
16581
|
-
case "add": return
|
|
16918
|
+
case "add": return (gitWorkflow.preferences || gitWorkflowPreferences)?.stagingPolicy === "all"
|
|
16919
|
+
? "Step 1: explicitly stage all changes with git add ."
|
|
16920
|
+
: "Step 1: review changes, stage only intended files, then accept the current staged set.";
|
|
16582
16921
|
case "generate": return "Step 2: run /git-staged-msg, or type a commit message and use Commit input.";
|
|
16583
16922
|
case "generating": return "Pi is generating dev/COMMIT/staged-commit-short.txt and staged-commit-long.txt.";
|
|
16584
16923
|
case "message": return gitWorkflow.prMode ? `Worktree branch ${gitWorkflow.prBranch || "created"}: choose short, long, or typed input before opening a PR.` : "Step 3/4: preview the native g-msg output, type a commit message if needed, commit here, or create a PR branch worktree first.";
|
|
@@ -16692,8 +17031,17 @@ function renderGitWorkflow() {
|
|
|
16692
17031
|
return;
|
|
16693
17032
|
}
|
|
16694
17033
|
|
|
17034
|
+
const preferences = gitWorkflow.preferences || gitWorkflowPreferences || {};
|
|
16695
17035
|
if (gitWorkflow.step === "add") {
|
|
16696
|
-
|
|
17036
|
+
if (preferences.stagingPolicy === "all") {
|
|
17037
|
+
addGitWorkflowAction("Run git add .", () => runGitAdd(), "primary", false);
|
|
17038
|
+
} else if (preferences.stagingPolicy === "preserve") {
|
|
17039
|
+
addGitWorkflowAction("Use current staged set", () => acceptCurrentGitStaging(), "primary", false);
|
|
17040
|
+
addGitWorkflowAction("Review/select changes", () => openGitChangesDialog(), "", false);
|
|
17041
|
+
} else {
|
|
17042
|
+
addGitWorkflowAction("Review/select changes", () => openGitChangesDialog(), "primary", false);
|
|
17043
|
+
addGitWorkflowAction("Use current staged set", () => acceptCurrentGitStaging(), "", false);
|
|
17044
|
+
}
|
|
16697
17045
|
} else if (gitWorkflow.step === "generate") {
|
|
16698
17046
|
const commitInputButton = renderGitWorkflowManualCommitInput({ appendCommitButton: false });
|
|
16699
17047
|
addGitWorkflowAction("Run /git-staged-msg", () => runGitMessagePrompt(), "primary", false);
|
|
@@ -16702,13 +17050,16 @@ function renderGitWorkflow() {
|
|
|
16702
17050
|
} else if (gitWorkflow.step === "generating") {
|
|
16703
17051
|
addGitWorkflowAction("Refresh message preview", () => loadGitWorkflowMessage({ requireFresh: true }), "", false);
|
|
16704
17052
|
} else if (gitWorkflow.step === "message") {
|
|
17053
|
+
const deliveryMode = preferences.deliveryMode || "ask";
|
|
17054
|
+
const preferredVariant = preferences.commit?.defaultVariant || "short";
|
|
16705
17055
|
if (!gitWorkflow.prMode) {
|
|
16706
|
-
addGitWorkflowAction("Create PR worktree", () => createGitPrBranch(), "primary", false, GIT_WORKFLOW_CREATE_PR_TOOLTIP);
|
|
17056
|
+
addGitWorkflowAction("Create PR worktree", () => createGitPrBranch(), deliveryMode === "pr-worktree" ? "primary" : "", false, GIT_WORKFLOW_CREATE_PR_TOOLTIP);
|
|
16707
17057
|
addGitWorkflowAction("Manual worktree", () => createGitPrBranchManually(), "", false, GIT_WORKFLOW_MANUAL_BRANCH_TOOLTIP);
|
|
16708
17058
|
}
|
|
16709
17059
|
const commitInputButton = renderGitWorkflowManualCommitInput({ appendCommitButton: false });
|
|
16710
|
-
|
|
16711
|
-
addGitWorkflowAction(
|
|
17060
|
+
const highlightCommit = gitWorkflow.prMode || deliveryMode !== "pr-worktree";
|
|
17061
|
+
addGitWorkflowAction(`Commit short${preferredVariant === "short" ? " (default)" : ""}`, () => commitGitWorkflow("short"), highlightCommit && preferredVariant === "short" ? "primary" : "", false);
|
|
17062
|
+
addGitWorkflowAction(`Commit long${preferredVariant === "long" ? " (default)" : ""}`, () => commitGitWorkflow("long"), highlightCommit && preferredVariant === "long" ? "primary" : "", false);
|
|
16712
17063
|
addGitWorkflowAction("Regenerate", () => runGitMessagePrompt(), "", false);
|
|
16713
17064
|
elements.gitWorkflowActions.append(commitInputButton);
|
|
16714
17065
|
} else if (gitWorkflow.step === "branchNaming") {
|
|
@@ -16767,7 +17118,18 @@ function failGitWorkflow(error, step, { tabId = activeTabId } = {}) {
|
|
|
16767
17118
|
}, { tabId });
|
|
16768
17119
|
}
|
|
16769
17120
|
|
|
16770
|
-
function
|
|
17121
|
+
function gitWorkflowStagingReadyMessage(preferences) {
|
|
17122
|
+
switch (preferences?.stagingPolicy) {
|
|
17123
|
+
case "preserve":
|
|
17124
|
+
return "Using the repository's current staged set. Review it before generating a message.";
|
|
17125
|
+
case "all":
|
|
17126
|
+
return "Ready to stage all working-tree changes with git add .";
|
|
17127
|
+
default:
|
|
17128
|
+
return "Review changes and stage only the files intended for this commit, then continue with the current staged set.";
|
|
17129
|
+
}
|
|
17130
|
+
}
|
|
17131
|
+
|
|
17132
|
+
async function startGitWorkflow(tabId = activeTabId, { skipSetup = false } = {}) {
|
|
16771
17133
|
if (!tabId) return;
|
|
16772
17134
|
if (!isOptionalFeatureEnabled("gitWorkflow")) {
|
|
16773
17135
|
const tabContext = activeTabContext(tabId);
|
|
@@ -16777,8 +17139,29 @@ function startGitWorkflow(tabId = activeTabId) {
|
|
|
16777
17139
|
});
|
|
16778
17140
|
return;
|
|
16779
17141
|
}
|
|
17142
|
+
|
|
17143
|
+
let setupData;
|
|
17144
|
+
try {
|
|
17145
|
+
const response = await api("/api/git-workflow/preferences", { tabId });
|
|
17146
|
+
setupData = response.data || {};
|
|
17147
|
+
gitWorkflowPreferences = setupData.preferences || null;
|
|
17148
|
+
} catch (error) {
|
|
17149
|
+
addEvent(`guided Git setup could not be loaded: ${error.message || String(error)}`, "error");
|
|
17150
|
+
return;
|
|
17151
|
+
}
|
|
17152
|
+
if (!setupData.configured) {
|
|
17153
|
+
if (skipSetup) {
|
|
17154
|
+
addEvent("Guided Git setup is incomplete.", "warn");
|
|
17155
|
+
return;
|
|
17156
|
+
}
|
|
17157
|
+
addEvent("Complete Guided Git Setup before starting the workflow.", "info");
|
|
17158
|
+
await openNativeGitWorkflowSetupDialog({ onSaved: () => startGitWorkflow(tabId, { skipSetup: true }) });
|
|
17159
|
+
return;
|
|
17160
|
+
}
|
|
17161
|
+
|
|
16780
17162
|
const workflow = gitWorkflowForTab(tabId);
|
|
16781
17163
|
if (workflow.active && !["done", "cancelled", "error"].includes(workflow.step) && !confirm("Restart the active git workflow?")) return;
|
|
17164
|
+
const preferences = setupData.preferences;
|
|
16782
17165
|
workflow.runId += 1;
|
|
16783
17166
|
setGitWorkflow({
|
|
16784
17167
|
active: true,
|
|
@@ -16786,7 +17169,7 @@ function startGitWorkflow(tabId = activeTabId) {
|
|
|
16786
17169
|
step: "add",
|
|
16787
17170
|
process: "stage",
|
|
16788
17171
|
busy: false,
|
|
16789
|
-
output:
|
|
17172
|
+
output: `${gitWorkflowStagingReadyMessage(preferences)}\n\nGit text will use ${preferences.generation.provider}/${preferences.generation.modelId} at ${preferences.generation.thinkingLevel} effort. The active tab model is restored after generation.`,
|
|
16790
17173
|
error: "",
|
|
16791
17174
|
githubUsername: "",
|
|
16792
17175
|
repoName: "",
|
|
@@ -16806,6 +17189,8 @@ function startGitWorkflow(tabId = activeTabId) {
|
|
|
16806
17189
|
prBranch: "",
|
|
16807
17190
|
pr: null,
|
|
16808
17191
|
prRequestedAt: 0,
|
|
17192
|
+
preferences,
|
|
17193
|
+
verificationConfirmed: false,
|
|
16809
17194
|
}, { tabId });
|
|
16810
17195
|
}
|
|
16811
17196
|
|
|
@@ -17139,6 +17524,31 @@ async function runGitAdd(tabId = gitWorkflowActionTabId()) {
|
|
|
17139
17524
|
}
|
|
17140
17525
|
}
|
|
17141
17526
|
|
|
17527
|
+
async function acceptCurrentGitStaging(tabId = gitWorkflowActionTabId()) {
|
|
17528
|
+
const tabContext = activeTabContext(tabId);
|
|
17529
|
+
const workflow = gitWorkflowForTab(tabId, { create: false });
|
|
17530
|
+
if (!workflow) return;
|
|
17531
|
+
const runId = workflow.runId;
|
|
17532
|
+
setGitWorkflow({ step: "add", busy: true, error: "", output: "Checking the current staged set…" }, { tabId });
|
|
17533
|
+
try {
|
|
17534
|
+
const response = await api("/api/git-changes", { tabId });
|
|
17535
|
+
const staged = Number(response.data?.summary?.staged || 0);
|
|
17536
|
+
if (staged <= 0) throw new Error("No staged files are available. Use Review/select changes to stage the intended files first.");
|
|
17537
|
+
setGitWorkflow({
|
|
17538
|
+
step: "generate",
|
|
17539
|
+
process: "message",
|
|
17540
|
+
busy: false,
|
|
17541
|
+
...resetGitWorkflowManualCommitDefaultPatch(),
|
|
17542
|
+
...gitWorkflowActionDonePatch(workflow, "stage"),
|
|
17543
|
+
output: `Using the current staged set (${staged} file${staged === 1 ? "" : "s"}). Review the staged diff, then generate or type a commit message.`,
|
|
17544
|
+
}, { tabId });
|
|
17545
|
+
loadGitWorkflowDefaultCommitMessage({ runId, tabId });
|
|
17546
|
+
if (isCurrentTabContext(tabContext)) scheduleRefreshFooter();
|
|
17547
|
+
} catch (error) {
|
|
17548
|
+
if (isCurrentGitWorkflowRun(runId, tabId)) failGitWorkflow(error, "add", { tabId });
|
|
17549
|
+
}
|
|
17550
|
+
}
|
|
17551
|
+
|
|
17142
17552
|
async function loadGitWorkflowDefaultCommitMessage({ runId, tabId = activeTabId } = {}) {
|
|
17143
17553
|
const workflow = gitWorkflowForTab(tabId, { create: false });
|
|
17144
17554
|
const expectedRunId = runId ?? workflow?.runId;
|
|
@@ -17190,9 +17600,9 @@ async function runGitMessagePrompt(tabId = gitWorkflowActionTabId()) {
|
|
|
17190
17600
|
}, { tabId });
|
|
17191
17601
|
if (isCurrentTabContext(tabContext)) setRunIndicatorActivity("Sending /git-staged-msg to Pi…");
|
|
17192
17602
|
try {
|
|
17193
|
-
await
|
|
17194
|
-
if (!isCurrentGitWorkflowRun(runId, tabId)) return;
|
|
17195
|
-
appendGitWorkflowOutput(
|
|
17603
|
+
const generation = await gitWorkflowRequest("/api/git-workflow/generate", { body: { kind: "commit" }, runId, tabId });
|
|
17604
|
+
if (!generation || !isCurrentGitWorkflowRun(runId, tabId)) return;
|
|
17605
|
+
appendGitWorkflowOutput(`/git-staged-msg accepted with ${generation.generation.provider}/${generation.generation.modelId} at ${generation.generation.thinkingLevel} effort. Waiting for agent_end, then the message files will be loaded.`, { tabId });
|
|
17196
17606
|
if (isCurrentTabContext(tabContext)) scheduleRefreshState(120, tabContext);
|
|
17197
17607
|
setTimeout(() => {
|
|
17198
17608
|
const currentWorkflow = gitWorkflowForTab(tabId, { create: false });
|
|
@@ -17286,9 +17696,9 @@ async function runGitBranchNamePrompt(tabId = gitWorkflowActionTabId()) {
|
|
|
17286
17696
|
}, { tabId });
|
|
17287
17697
|
if (isCurrentTabContext(tabContext)) setRunIndicatorActivity("Sending branch-name request to Pi…");
|
|
17288
17698
|
try {
|
|
17289
|
-
await
|
|
17290
|
-
if (!isCurrentGitWorkflowRun(runId, tabId)) return;
|
|
17291
|
-
appendGitWorkflowOutput(
|
|
17699
|
+
const generation = await gitWorkflowRequest("/api/git-workflow/generate", { body: { kind: "branch" }, runId, tabId });
|
|
17700
|
+
if (!generation || !isCurrentGitWorkflowRun(runId, tabId)) return;
|
|
17701
|
+
appendGitWorkflowOutput(`Branch-name request accepted with ${generation.generation.provider}/${generation.generation.modelId} at ${generation.generation.thinkingLevel} effort. Waiting for agent_end, then the branch name will be loaded.`, { tabId });
|
|
17292
17702
|
if (isCurrentTabContext(tabContext)) scheduleRefreshState(120, tabContext);
|
|
17293
17703
|
setTimeout(() => {
|
|
17294
17704
|
const currentWorkflow = gitWorkflowForTab(tabId, { create: false });
|
|
@@ -17412,6 +17822,8 @@ async function createGitPrBranchWithSuggestion(suggestion, tabId = gitWorkflowAc
|
|
|
17412
17822
|
prBranch: prBranch || branch,
|
|
17413
17823
|
pr: null,
|
|
17414
17824
|
prRequestedAt: 0,
|
|
17825
|
+
preferences: sourceWorkflow.preferences || gitWorkflowPreferences,
|
|
17826
|
+
verificationConfirmed: false,
|
|
17415
17827
|
};
|
|
17416
17828
|
if (targetTabId !== tabId) {
|
|
17417
17829
|
setGitWorkflow({ step: "message", prMode: false, prBranch: "", branchName: prBranch || branch, busy: false, output: `${formatCommitMessagePreview(sourceWorkflow.message)}\n\nOpened PR branch worktree ${prBranch || branch} in ${result.tab?.title || "a new tab"}. Continue the commit and PR flow there; this checkout stayed on its current branch.` }, { tabId });
|
|
@@ -17434,6 +17846,18 @@ async function commitGitWorkflow(variant, tabId = gitWorkflowActionTabId()) {
|
|
|
17434
17846
|
const runId = workflow.runId;
|
|
17435
17847
|
const failureStep = variant === "input" && workflow.step === "generate" ? "generate" : "message";
|
|
17436
17848
|
const inputMessage = variant === "input" ? gitWorkflowManualCommitInputMessage(workflow) : "";
|
|
17849
|
+
if (workflow.preferences?.verificationPolicy === "ask" && !workflow.verificationConfirmed) {
|
|
17850
|
+
const proceed = window.confirm([
|
|
17851
|
+
"Pre-commit verification reminder",
|
|
17852
|
+
"",
|
|
17853
|
+
"Review the staged diff and any relevant test, lint, or build results before committing.",
|
|
17854
|
+
"Git hooks and signing configuration will still run normally.",
|
|
17855
|
+
"",
|
|
17856
|
+
"Continue with this commit?",
|
|
17857
|
+
].join("\n"));
|
|
17858
|
+
if (!proceed) return;
|
|
17859
|
+
workflow.verificationConfirmed = true;
|
|
17860
|
+
}
|
|
17437
17861
|
if (variant === "input" && !inputMessage) {
|
|
17438
17862
|
failGitWorkflow(new Error("Type a commit message, or stage exactly one created/updated/deleted file to use the default."), failureStep, { tabId });
|
|
17439
17863
|
return;
|
|
@@ -17459,6 +17883,7 @@ async function pushGitWorkflow(tabId = gitWorkflowActionTabId()) {
|
|
|
17459
17883
|
const tabContext = activeTabContext(tabId);
|
|
17460
17884
|
const workflow = gitWorkflowForTab(tabId, { create: false });
|
|
17461
17885
|
if (!workflow) return;
|
|
17886
|
+
if (!window.confirm("Push the committed changes to the configured upstream?\n\nGuided Git never force-pushes automatically.")) return;
|
|
17462
17887
|
const runId = workflow.runId;
|
|
17463
17888
|
setGitWorkflow({ step: "pushing", busy: true, error: "", output: "Running git push…" }, { tabId });
|
|
17464
17889
|
try {
|
|
@@ -17496,9 +17921,9 @@ async function runGitPrPrompt(tabId = gitWorkflowActionTabId(), { prefixOutput =
|
|
|
17496
17921
|
}, { tabId });
|
|
17497
17922
|
if (isCurrentTabContext(tabContext)) setRunIndicatorActivity("Sending /pr to Pi…");
|
|
17498
17923
|
try {
|
|
17499
|
-
await
|
|
17500
|
-
if (!isCurrentGitWorkflowRun(runId, tabId)) return;
|
|
17501
|
-
appendGitWorkflowOutput(
|
|
17924
|
+
const generation = await gitWorkflowRequest("/api/git-workflow/generate", { body: { kind: "pr" }, runId, tabId });
|
|
17925
|
+
if (!generation || !isCurrentGitWorkflowRun(runId, tabId)) return;
|
|
17926
|
+
appendGitWorkflowOutput(`/pr accepted with ${generation.generation.provider}/${generation.generation.modelId} at ${generation.generation.thinkingLevel} effort. Waiting for agent_end, then the PR description will be loaded.`, { tabId });
|
|
17502
17927
|
if (isCurrentTabContext(tabContext)) scheduleRefreshState(120, tabContext);
|
|
17503
17928
|
setTimeout(() => {
|
|
17504
17929
|
const currentWorkflow = gitWorkflowForTab(tabId, { create: false });
|
|
@@ -17549,8 +17974,9 @@ async function pushAndCreatePrGitWorkflow(tabId = gitWorkflowActionTabId()) {
|
|
|
17549
17974
|
const tabContext = activeTabContext(tabId);
|
|
17550
17975
|
const workflow = gitWorkflowForTab(tabId, { create: false });
|
|
17551
17976
|
if (!workflow) return;
|
|
17552
|
-
const runId = workflow.runId;
|
|
17553
17977
|
const branch = workflow.prBranch || "current branch";
|
|
17978
|
+
if (!window.confirm(`Push ${branch} and continue to generated PR review?\n\nThe pull request is still created only after a second explicit review/confirmation.`)) return;
|
|
17979
|
+
const runId = workflow.runId;
|
|
17554
17980
|
setGitWorkflow({ step: "pushing", busy: true, error: "", output: `Pushing PR branch ${branch}…` }, { tabId });
|
|
17555
17981
|
try {
|
|
17556
17982
|
const result = await gitWorkflowRequest("/api/git-workflow/push", { body: { setUpstream: true, branch: workflow.prBranch }, runId, tabId });
|
|
@@ -18124,14 +18550,101 @@ function appendText(parent, text, className = "text-block") {
|
|
|
18124
18550
|
return block;
|
|
18125
18551
|
}
|
|
18126
18552
|
|
|
18553
|
+
function markdownFilePathFromHref(url) {
|
|
18554
|
+
const href = String(url || "").trim();
|
|
18555
|
+
if (!href || href.startsWith("#") || /[\u0000-\u001f\u007f]/.test(href)) return "";
|
|
18556
|
+
if (/^(?:https?:|mailto:)/i.test(href)) return "";
|
|
18557
|
+
if (/^file:/i.test(href)) {
|
|
18558
|
+
try {
|
|
18559
|
+
const parsed = new URL(href);
|
|
18560
|
+
if (parsed.protocol !== "file:" || (parsed.hostname && parsed.hostname.toLowerCase() !== "localhost")) return "";
|
|
18561
|
+
let pathname = decodeURIComponent(parsed.pathname || "");
|
|
18562
|
+
if (/^\/[A-Za-z]:\//.test(pathname)) pathname = pathname.slice(1);
|
|
18563
|
+
return pathname.replace(/\\/g, "/");
|
|
18564
|
+
} catch {
|
|
18565
|
+
return "";
|
|
18566
|
+
}
|
|
18567
|
+
}
|
|
18568
|
+
if (/^[A-Za-z][A-Za-z\d+.-]*:/.test(href) && !/^[A-Za-z]:[\\/]/.test(href)) return "";
|
|
18569
|
+
if (/^(?:\/\/|\\\\)/.test(href)) return "";
|
|
18570
|
+
const pathText = href.replace(/[?#].*$/, "");
|
|
18571
|
+
try {
|
|
18572
|
+
return decodeURIComponent(pathText).replace(/\\/g, "/");
|
|
18573
|
+
} catch {
|
|
18574
|
+
return pathText.replace(/\\/g, "/");
|
|
18575
|
+
}
|
|
18576
|
+
}
|
|
18577
|
+
|
|
18127
18578
|
function safeMarkdownLinkHref(url) {
|
|
18128
18579
|
const href = String(url || "").trim();
|
|
18129
18580
|
if (!href || /[\u0000-\u001f\u007f]/.test(href)) return "";
|
|
18130
18581
|
if (/^(?:https?:|mailto:)/i.test(href)) return href;
|
|
18131
|
-
if (
|
|
18582
|
+
if (href.startsWith("#") || markdownFilePathFromHref(href)) return href;
|
|
18132
18583
|
return "";
|
|
18133
18584
|
}
|
|
18134
18585
|
|
|
18586
|
+
function normalizeMarkdownWorkspacePath(value) {
|
|
18587
|
+
const parts = [];
|
|
18588
|
+
for (const part of String(value || "").replace(/\\/g, "/").split("/")) {
|
|
18589
|
+
if (!part || part === ".") continue;
|
|
18590
|
+
if (part === "..") {
|
|
18591
|
+
if (!parts.length) return "";
|
|
18592
|
+
parts.pop();
|
|
18593
|
+
continue;
|
|
18594
|
+
}
|
|
18595
|
+
parts.push(part);
|
|
18596
|
+
}
|
|
18597
|
+
return parts.join("/");
|
|
18598
|
+
}
|
|
18599
|
+
|
|
18600
|
+
function markdownWorkspaceFilePath(url, cwd = "", basePath = "") {
|
|
18601
|
+
let target = markdownFilePathFromHref(url);
|
|
18602
|
+
if (!target) return "";
|
|
18603
|
+
const absoluteTarget = target.startsWith("/") || /^[A-Za-z]:\//.test(target);
|
|
18604
|
+
if (absoluteTarget) {
|
|
18605
|
+
const normalizedCwd = String(cwd || "").trim().replace(/\\/g, "/");
|
|
18606
|
+
const workspaceRoot = normalizedCwd.replace(/\/+$/, "") || (normalizedCwd.startsWith("/") ? "/" : "");
|
|
18607
|
+
if (!workspaceRoot) return "";
|
|
18608
|
+
const windowsPath = /^[A-Za-z]:\//.test(target) && /^[A-Za-z]:(?:\/|$)/.test(workspaceRoot);
|
|
18609
|
+
const comparableTarget = windowsPath ? target.toLowerCase() : target;
|
|
18610
|
+
const comparableRoot = windowsPath ? workspaceRoot.toLowerCase() : workspaceRoot;
|
|
18611
|
+
const prefix = comparableRoot === "/" ? "/" : `${comparableRoot}/`;
|
|
18612
|
+
if (!comparableTarget.startsWith(prefix)) return "";
|
|
18613
|
+
target = target.slice(prefix.length);
|
|
18614
|
+
} else if (basePath) {
|
|
18615
|
+
target = `${basePath}/${target}`;
|
|
18616
|
+
}
|
|
18617
|
+
return normalizeMarkdownWorkspacePath(target);
|
|
18618
|
+
}
|
|
18619
|
+
|
|
18620
|
+
function configureMarkdownLink(link, href) {
|
|
18621
|
+
const filePath = markdownFilePathFromHref(href);
|
|
18622
|
+
if (!filePath) {
|
|
18623
|
+
link.href = href;
|
|
18624
|
+
if (/^https?:/i.test(href)) {
|
|
18625
|
+
link.target = "_blank";
|
|
18626
|
+
link.rel = "noopener noreferrer";
|
|
18627
|
+
}
|
|
18628
|
+
return;
|
|
18629
|
+
}
|
|
18630
|
+
link.href = "#";
|
|
18631
|
+
link.classList.add("markdown-file-link");
|
|
18632
|
+
link.dataset.markdownFileHref = href;
|
|
18633
|
+
link.title = `Open ${filePath} in the WebUI file viewer`;
|
|
18634
|
+
link.addEventListener("click", (event) => {
|
|
18635
|
+
event.preventDefault();
|
|
18636
|
+
const cwd = latestWorkspace?.cwd || activeTab()?.cwd || "";
|
|
18637
|
+
const basePath = link.closest?.(".file-viewer-preview") && activeFileViewer ? fileParentPath(activeFileViewer.path) : "";
|
|
18638
|
+
const workspacePath = markdownWorkspaceFilePath(href, cwd, basePath);
|
|
18639
|
+
if (!workspacePath) {
|
|
18640
|
+
addEvent(`Cannot open Markdown link outside this tab's working directory: ${filePath}`, "error");
|
|
18641
|
+
return;
|
|
18642
|
+
}
|
|
18643
|
+
setSidePanelCollapsed(false);
|
|
18644
|
+
openFileInViewer(workspacePath).catch((error) => addEvent(error.message || String(error), "error"));
|
|
18645
|
+
});
|
|
18646
|
+
}
|
|
18647
|
+
|
|
18135
18648
|
function appendInlineMarkdown(parent, text, depth = 0) {
|
|
18136
18649
|
const value = String(text || "");
|
|
18137
18650
|
if (!value) return;
|
|
@@ -18162,11 +18675,7 @@ function appendInlineMarkdown(parent, text, depth = 0) {
|
|
|
18162
18675
|
const href = safeMarkdownLinkHref(value.slice(labelEnd + 2, linkEnd));
|
|
18163
18676
|
if (href) {
|
|
18164
18677
|
const link = make("a");
|
|
18165
|
-
link
|
|
18166
|
-
if (/^https?:/i.test(href)) {
|
|
18167
|
-
link.target = "_blank";
|
|
18168
|
-
link.rel = "noopener noreferrer";
|
|
18169
|
-
}
|
|
18678
|
+
configureMarkdownLink(link, href);
|
|
18170
18679
|
appendInlineMarkdown(link, label, depth + 1);
|
|
18171
18680
|
parent.append(link);
|
|
18172
18681
|
} else {
|
|
@@ -19876,10 +20385,83 @@ function renderLsToolExecution(parent, tool) {
|
|
|
19876
20385
|
appendToolWarnings(parent, tool.details);
|
|
19877
20386
|
}
|
|
19878
20387
|
|
|
20388
|
+
let documentArtifactDialog = null;
|
|
20389
|
+
|
|
20390
|
+
function addDocumentArtifactPageToComposer(artifact, pageNum) {
|
|
20391
|
+
const reference = `[Document artifact ${artifact.id}${artifact.revisionId ? ` revision ${artifact.revisionId}` : ""}, page ${pageNum}]`;
|
|
20392
|
+
const current = elements.promptInput.value.trim();
|
|
20393
|
+
elements.promptInput.value = [current, reference].filter(Boolean).join("\n\n");
|
|
20394
|
+
resizePromptInput();
|
|
20395
|
+
renderCommandSuggestions();
|
|
20396
|
+
focusPromptInput({ defer: true });
|
|
20397
|
+
}
|
|
20398
|
+
|
|
20399
|
+
function ensureDocumentArtifactDialog() {
|
|
20400
|
+
if (documentArtifactDialog?.isConnected) return documentArtifactDialog;
|
|
20401
|
+
const dialog = make("dialog", "document-artifact-dialog");
|
|
20402
|
+
dialog.addEventListener("click", (event) => { if (event.target === dialog) dialog.close(); });
|
|
20403
|
+
document.body.append(dialog);
|
|
20404
|
+
documentArtifactDialog = dialog;
|
|
20405
|
+
return dialog;
|
|
20406
|
+
}
|
|
20407
|
+
|
|
20408
|
+
async function openDocumentArtifact(artifact) {
|
|
20409
|
+
const dialog = ensureDocumentArtifactDialog();
|
|
20410
|
+
dialog.replaceChildren(make("div", "document-artifact-loading", "Loading document artifact…"));
|
|
20411
|
+
if (!dialog.open) dialog.showModal();
|
|
20412
|
+
try {
|
|
20413
|
+
const response = await api(artifact.manifestUrl);
|
|
20414
|
+
const manifest = response.data || {}, pages = Array.isArray(manifest.pages) ? manifest.pages : [];
|
|
20415
|
+
let pageIndex = 0, zoom = 1, rotation = 0;
|
|
20416
|
+
const shell = make("section", "document-artifact-shell"), header = make("header", "document-artifact-header"), title = make("div", "document-artifact-title"), actions = make("div", "document-artifact-actions"), body = make("div", "document-artifact-body"), sidebar = make("aside", "document-artifact-sidebar"), stage = make("main", "document-artifact-stage"), image = make("img", "document-artifact-page"), toolbar = make("div", "document-artifact-toolbar"), meta = make("span", "document-artifact-meta"), search = make("input", "document-artifact-search"), semantic = make("details", "document-artifact-semantic");
|
|
20417
|
+
title.append(make("strong", undefined, artifact.title || "Document"), make("span", "muted", `${artifact.pageCount || pages.length || 0} page${Number(artifact.pageCount || pages.length) === 1 ? "" : "s"} · ${manifest.renderer?.engine || "document artifact"}`));
|
|
20418
|
+
const close = make("button", undefined, "Close"); close.type = "button"; close.addEventListener("click", () => dialog.close());
|
|
20419
|
+
if (artifact.downloadUrl) { const download = make("a", "button-like", "Download"); download.href = artifact.downloadUrl; download.download = artifact.title || "document"; actions.append(download); }
|
|
20420
|
+
actions.append(close); header.append(title, actions);
|
|
20421
|
+
search.type = "search"; search.placeholder = "Search outline, comments, revisions, or metadata";
|
|
20422
|
+
const previous = make("button", undefined, "Previous"), next = make("button", undefined, "Next"), zoomOut = make("button", undefined, "−"), zoomIn = make("button", undefined, "+"), fit = make("button", undefined, "Fit"), rotate = make("button", undefined, "Rotate"), send = make("button", undefined, "Send page to composer");
|
|
20423
|
+
for (const button of [previous, next, zoomOut, zoomIn, fit, rotate, send]) button.type = "button";
|
|
20424
|
+
const renderPage = () => {
|
|
20425
|
+
const page = pages[pageIndex];
|
|
20426
|
+
image.hidden = !page;
|
|
20427
|
+
if (page) { image.src = page.imageUrl; image.alt = `Rendered page ${page.pageNum} of ${artifact.title || "document"}`; image.style.transform = `scale(${zoom}) rotate(${rotation}deg)`; meta.textContent = `Page ${page.pageNum} of ${artifact.pageCount || pages.length} · ${Math.round(zoom * 100)}% · ${rotation}°`; }
|
|
20428
|
+
else meta.textContent = "No rendered pages are available";
|
|
20429
|
+
previous.disabled = pageIndex <= 0; next.disabled = pageIndex >= pages.length - 1; send.disabled = !page;
|
|
20430
|
+
for (const [index, button] of [...sidebar.querySelectorAll("button")].entries()) button.classList.toggle("active", index === pageIndex);
|
|
20431
|
+
};
|
|
20432
|
+
previous.addEventListener("click", () => { pageIndex = Math.max(0, pageIndex - 1); renderPage(); });
|
|
20433
|
+
next.addEventListener("click", () => { pageIndex = Math.min(pages.length - 1, pageIndex + 1); renderPage(); });
|
|
20434
|
+
zoomOut.addEventListener("click", () => { zoom = Math.max(0.25, zoom - 0.25); renderPage(); });
|
|
20435
|
+
zoomIn.addEventListener("click", () => { zoom = Math.min(3, zoom + 0.25); renderPage(); });
|
|
20436
|
+
fit.addEventListener("click", () => { zoom = 1; renderPage(); });
|
|
20437
|
+
rotate.addEventListener("click", () => { rotation = (rotation + 90) % 360; renderPage(); });
|
|
20438
|
+
send.addEventListener("click", () => { const page = pages[pageIndex]; if (page) { addDocumentArtifactPageToComposer(artifact, page.pageNum); dialog.close(); } });
|
|
20439
|
+
toolbar.append(previous, next, zoomOut, zoomIn, fit, rotate, send, meta);
|
|
20440
|
+
for (const [index, page] of pages.entries()) { const button = make("button", "document-artifact-thumbnail"); button.type = "button"; const thumb = make("img"); thumb.src = page.imageUrl; thumb.alt = ""; button.append(thumb, make("span", undefined, `Page ${page.pageNum}`)); button.addEventListener("click", () => { pageIndex = index; renderPage(); }); sidebar.append(button); }
|
|
20441
|
+
const semanticData = { outline: manifest.outline || [], comments: manifest.comments || [], revisions: manifest.revisions || [], warnings: manifest.warnings || [], diff: manifest.diff || undefined, renderer: manifest.renderer || undefined };
|
|
20442
|
+
semantic.append(make("summary", undefined, "Semantic structure, revisions, warnings, and diff"), make("pre", undefined, JSON.stringify(semanticData, null, 2)));
|
|
20443
|
+
search.addEventListener("input", () => { const query = search.value.trim().toLocaleLowerCase(); semantic.hidden = !!query && !JSON.stringify(semanticData).toLocaleLowerCase().includes(query); if (query && semantic.hidden) search.setCustomValidity("No semantic match"); else search.setCustomValidity(""); });
|
|
20444
|
+
stage.append(toolbar, search, image, semantic); body.append(sidebar, stage); shell.append(header, body); dialog.replaceChildren(shell); renderPage();
|
|
20445
|
+
} catch (error) {
|
|
20446
|
+
const close = make("button", undefined, "Close"); close.type = "button"; close.addEventListener("click", () => dialog.close());
|
|
20447
|
+
dialog.replaceChildren(make("div", "document-artifact-error", `Document artifact is stale or unavailable: ${error.message || error}`), close);
|
|
20448
|
+
}
|
|
20449
|
+
}
|
|
20450
|
+
|
|
20451
|
+
function appendDocumentArtifact(parent, artifact) {
|
|
20452
|
+
if (artifact?.schema !== "pi.artifact/v1" || artifact?.kind !== "document") return;
|
|
20453
|
+
const card = make("div", `document-artifact-card${artifact.unavailable ? " unavailable" : ""}`), text = make("div"), actions = make("div", "document-artifact-card-actions");
|
|
20454
|
+
text.append(make("strong", undefined, artifact.title || "Document artifact"), make("span", "muted", artifact.unavailable ? "Preview unavailable" : `${artifact.pageCount || 0} page${Number(artifact.pageCount) === 1 ? "" : "s"}`));
|
|
20455
|
+
if (!artifact.unavailable && artifact.manifestUrl) { const open = make("button", undefined, "Open viewer"); open.type = "button"; open.addEventListener("click", () => openDocumentArtifact(artifact)); actions.append(open); }
|
|
20456
|
+
if (!artifact.unavailable && artifact.downloadUrl) { const download = make("a", "button-like", "Download"); download.href = artifact.downloadUrl; download.download = artifact.title || "document"; actions.append(download); }
|
|
20457
|
+
card.append(text, actions); parent.append(card);
|
|
20458
|
+
}
|
|
20459
|
+
|
|
19879
20460
|
function renderGenericToolExecution(parent, tool) {
|
|
19880
20461
|
appendToolTitle(parent, tool.name, "", toolStateMeta(tool));
|
|
19881
20462
|
appendToolOutput(parent, JSON.stringify(tool.args ?? {}, null, 2), { label: "arguments", previewLines: 12 });
|
|
19882
20463
|
appendToolImages(parent, tool.result);
|
|
20464
|
+
appendDocumentArtifact(parent, tool.details?.artifact);
|
|
19883
20465
|
appendToolOutput(parent, tool.text, { label: "result", previewLines: 10, open: tool.isError });
|
|
19884
20466
|
appendToolWarnings(parent, tool.details);
|
|
19885
20467
|
}
|
|
@@ -20884,7 +21466,7 @@ async function sendBtwQuestion(question, { clearComposerDraft = false } = {}) {
|
|
|
20884
21466
|
const message = /^\/btw(?:\s|$)/.test(cleanQuestion) ? cleanQuestion : `/btw ${cleanQuestion}`;
|
|
20885
21467
|
const targetTabId = activeTabId;
|
|
20886
21468
|
btwWidgetComposerOpen = true;
|
|
20887
|
-
|
|
21469
|
+
btwWidgetDismissedIdsByTab.delete(targetTabId);
|
|
20888
21470
|
try {
|
|
20889
21471
|
await sendPrompt("prompt", message, { targetTabId, throwOnError: true });
|
|
20890
21472
|
} catch {
|
|
@@ -22051,6 +22633,159 @@ async function openNativeSettingsDialog() {
|
|
|
22051
22633
|
const save = addNativeCommandAction("Apply", () => applySettings(false, save), "primary");
|
|
22052
22634
|
}
|
|
22053
22635
|
|
|
22636
|
+
function replaceNativeSettingSelectOptions(select, options, preferredValue) {
|
|
22637
|
+
const normalized = normalizedSettingOptions(options);
|
|
22638
|
+
select.replaceChildren();
|
|
22639
|
+
for (const option of normalized) {
|
|
22640
|
+
const element = make("option", undefined, option.label);
|
|
22641
|
+
element.value = option.value;
|
|
22642
|
+
select.append(element);
|
|
22643
|
+
}
|
|
22644
|
+
const values = normalized.map((option) => option.value);
|
|
22645
|
+
select.value = values.includes(String(preferredValue)) ? String(preferredValue) : values[0] || "";
|
|
22646
|
+
}
|
|
22647
|
+
|
|
22648
|
+
function gitWorkflowSetupModelKey(model) {
|
|
22649
|
+
return model?.provider && model?.id ? `${model.provider}/${model.id}` : "";
|
|
22650
|
+
}
|
|
22651
|
+
|
|
22652
|
+
async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
|
|
22653
|
+
openNativeCommandDialog({
|
|
22654
|
+
title: "/git-workflow-setup",
|
|
22655
|
+
message: "Configure the dedicated model and safe defaults used by Guided Git. The selected generation profile is applied only while commit, branch, or PR text is generated.",
|
|
22656
|
+
});
|
|
22657
|
+
renderNativeLoading("Loading guided Git preferences and available models…");
|
|
22658
|
+
|
|
22659
|
+
let data;
|
|
22660
|
+
try {
|
|
22661
|
+
const response = await nativeCommandApi("/api/git-workflow/preferences");
|
|
22662
|
+
data = response.data || {};
|
|
22663
|
+
} catch (error) {
|
|
22664
|
+
setNativeCommandError(error.message || String(error));
|
|
22665
|
+
elements.nativeCommandBody.replaceChildren();
|
|
22666
|
+
return;
|
|
22667
|
+
}
|
|
22668
|
+
|
|
22669
|
+
const preferences = data.preferences || {};
|
|
22670
|
+
const models = Array.isArray(data.models) ? data.models : [];
|
|
22671
|
+
if (!models.length) {
|
|
22672
|
+
setNativeCommandError("No authenticated Pi models are available. Run /login or configure a provider first.");
|
|
22673
|
+
elements.nativeCommandBody.replaceChildren();
|
|
22674
|
+
return;
|
|
22675
|
+
}
|
|
22676
|
+
|
|
22677
|
+
const configuredModelKey = `${preferences.generation?.provider || ""}/${preferences.generation?.modelId || ""}`;
|
|
22678
|
+
const activeModelKey = gitWorkflowSetupModelKey(currentState?.model);
|
|
22679
|
+
const modelKeys = new Set(models.map(gitWorkflowSetupModelKey));
|
|
22680
|
+
const initialModelKey = modelKeys.has(configuredModelKey)
|
|
22681
|
+
? configuredModelKey
|
|
22682
|
+
: modelKeys.has(activeModelKey)
|
|
22683
|
+
? activeModelKey
|
|
22684
|
+
: gitWorkflowSetupModelKey(models[0]);
|
|
22685
|
+
const modelOptions = models.map((model) => ({
|
|
22686
|
+
value: gitWorkflowSetupModelKey(model),
|
|
22687
|
+
label: `${gitWorkflowSetupModelKey(model)}${model.name && model.name !== model.id ? ` · ${model.name}` : ""}`,
|
|
22688
|
+
}));
|
|
22689
|
+
|
|
22690
|
+
const controls = {
|
|
22691
|
+
model: nativeSettingSelect("Git-writing model", initialModelKey, modelOptions, "Exact authenticated provider/model used for commit messages, branch names, and PR descriptions.", { label: "required", tone: "safety" }),
|
|
22692
|
+
thinking: nativeSettingSelect("Reasoning effort", preferences.generation?.thinkingLevel || "low", SETTINGS_THINKING_OPTIONS, "Only levels supported by the selected model are shown. Low is recommended for routine commit messages.", { label: "required", tone: "safety" }),
|
|
22693
|
+
language: nativeSettingSelect("Generated language", preferences.commit?.language || "en", [
|
|
22694
|
+
{ value: "en", label: "English" },
|
|
22695
|
+
{ value: "de", label: "German" },
|
|
22696
|
+
], "Language for generated commit and PR text.", { label: "saved", tone: "browser" }),
|
|
22697
|
+
defaultVariant: nativeSettingSelect("Default message", preferences.commit?.defaultVariant || "short", [
|
|
22698
|
+
{ value: "short", label: "Short subject" },
|
|
22699
|
+
{ value: "long", label: "Long subject + body" },
|
|
22700
|
+
], "Highlights the preferred commit choice; committing always remains explicit.", { label: "saved", tone: "browser" }),
|
|
22701
|
+
scope: nativeSettingSelect("Conventional scope", preferences.commit?.scope || "auto", [
|
|
22702
|
+
{ value: "auto", label: "Auto-detect when clear" },
|
|
22703
|
+
{ value: "never", label: "Never include a scope" },
|
|
22704
|
+
{ value: "required", label: "Always include a scope" },
|
|
22705
|
+
], "Controls type(scope): subject generation.", { label: "saved", tone: "browser" }),
|
|
22706
|
+
staging: nativeSettingSelect("Staging behavior", preferences.stagingPolicy || "review", [
|
|
22707
|
+
{ value: "review", label: "Review/select files" },
|
|
22708
|
+
{ value: "preserve", label: "Use current staged set" },
|
|
22709
|
+
{ value: "all", label: "Stage all with git add ." },
|
|
22710
|
+
], "Review/select is the safe default and opens Git Changes for per-file staging.", { label: "safety", tone: "safety" }),
|
|
22711
|
+
delivery: nativeSettingSelect("Delivery path", preferences.deliveryMode || "ask", [
|
|
22712
|
+
{ value: "ask", label: "Ask each workflow" },
|
|
22713
|
+
{ value: "current", label: "Prefer current branch" },
|
|
22714
|
+
{ value: "pr-worktree", label: "Prefer PR worktree" },
|
|
22715
|
+
], "Controls which explicit commit/PR action is highlighted.", { label: "saved", tone: "browser" }),
|
|
22716
|
+
verification: nativeSettingSelect("Pre-commit verification", preferences.verificationPolicy || "ask", [
|
|
22717
|
+
{ value: "ask", label: "Show verification reminder" },
|
|
22718
|
+
{ value: "none", label: "No reminder" },
|
|
22719
|
+
], "The reminder never claims tests were run and does not bypass Git hooks.", { label: "safety", tone: "safety" }),
|
|
22720
|
+
};
|
|
22721
|
+
|
|
22722
|
+
const thinkingLevelsForModel = (modelKey) => {
|
|
22723
|
+
const levels = data.modelThinkingLevels?.[modelKey];
|
|
22724
|
+
return Array.isArray(levels) && levels.length ? levels : ["off"];
|
|
22725
|
+
};
|
|
22726
|
+
const syncThinkingLevels = () => {
|
|
22727
|
+
const current = controls.thinking.select.value || preferences.generation?.thinkingLevel || "low";
|
|
22728
|
+
const levels = thinkingLevelsForModel(controls.model.select.value);
|
|
22729
|
+
replaceNativeSettingSelectOptions(controls.thinking.select, levels, current);
|
|
22730
|
+
};
|
|
22731
|
+
controls.model.select.addEventListener("change", syncThinkingLevels);
|
|
22732
|
+
syncThinkingLevels();
|
|
22733
|
+
|
|
22734
|
+
const body = make("div", "native-settings-panel");
|
|
22735
|
+
body.append(
|
|
22736
|
+
nativeSettingsNote("Persistence", `Saved globally in ${data.path || "the Pi Web UI settings file"}. Credentials are never stored here.`),
|
|
22737
|
+
nativeSettingsSection("Generation profile", "Required model and effort for generated Git text.", [controls.model, controls.thinking], { open: true }),
|
|
22738
|
+
nativeSettingsSection("Commit style", "Conventional Commit output preferences.", [controls.language, controls.defaultVariant, controls.scope], { open: true }),
|
|
22739
|
+
nativeSettingsSection("Workflow safety", "Staging, delivery, and verification defaults; push and PR confirmation remain mandatory.", [controls.staging, controls.delivery, controls.verification], { open: true }),
|
|
22740
|
+
);
|
|
22741
|
+
elements.nativeCommandBody.replaceChildren(body);
|
|
22742
|
+
elements.nativeCommandActions.replaceChildren();
|
|
22743
|
+
addNativeCommandAction("Cancel", closeNativeCommandDialog);
|
|
22744
|
+
|
|
22745
|
+
const save = addNativeCommandAction("Save setup", async () => {
|
|
22746
|
+
setNativeActionBusy(save, true, "Saving…");
|
|
22747
|
+
setNativeCommandError("");
|
|
22748
|
+
try {
|
|
22749
|
+
const selectedModel = models.find((model) => gitWorkflowSetupModelKey(model) === controls.model.select.value);
|
|
22750
|
+
if (!selectedModel) throw new Error("Select an available Git-writing model.");
|
|
22751
|
+
const response = await nativeCommandApi("/api/git-workflow/preferences", {
|
|
22752
|
+
method: "POST",
|
|
22753
|
+
body: {
|
|
22754
|
+
preferences: {
|
|
22755
|
+
generation: {
|
|
22756
|
+
provider: selectedModel.provider,
|
|
22757
|
+
modelId: selectedModel.id,
|
|
22758
|
+
thinkingLevel: controls.thinking.select.value,
|
|
22759
|
+
unavailablePolicy: "ask",
|
|
22760
|
+
},
|
|
22761
|
+
commit: {
|
|
22762
|
+
language: controls.language.select.value,
|
|
22763
|
+
defaultVariant: controls.defaultVariant.select.value,
|
|
22764
|
+
scope: controls.scope.select.value,
|
|
22765
|
+
},
|
|
22766
|
+
stagingPolicy: controls.staging.select.value,
|
|
22767
|
+
deliveryMode: controls.delivery.select.value,
|
|
22768
|
+
verificationPolicy: controls.verification.select.value,
|
|
22769
|
+
},
|
|
22770
|
+
},
|
|
22771
|
+
});
|
|
22772
|
+
gitWorkflowPreferences = response.data?.preferences || null;
|
|
22773
|
+
addTransientMessage({
|
|
22774
|
+
role: "native",
|
|
22775
|
+
title: "/git-workflow-setup",
|
|
22776
|
+
content: `Guided Git setup saved for ${gitWorkflowSetupModelKey(selectedModel)} at ${controls.thinking.select.value} effort.`,
|
|
22777
|
+
level: "info",
|
|
22778
|
+
});
|
|
22779
|
+
closeNativeCommandDialog();
|
|
22780
|
+
if (typeof onSaved === "function") await onSaved(gitWorkflowPreferences);
|
|
22781
|
+
} catch (error) {
|
|
22782
|
+
setNativeCommandError(error.message || String(error));
|
|
22783
|
+
} finally {
|
|
22784
|
+
setNativeActionBusy(save, false);
|
|
22785
|
+
}
|
|
22786
|
+
}, "primary");
|
|
22787
|
+
}
|
|
22788
|
+
|
|
22054
22789
|
async function openNativeForkSelector() {
|
|
22055
22790
|
openNativeCommandDialog({ title: "/fork", message: "Choose a previous user message to fork before.", searchPlaceholder: "Filter fork points…" });
|
|
22056
22791
|
renderNativeLoading("Loading fork points…");
|
|
@@ -22563,6 +23298,9 @@ async function handleNativeSlashSelectorCommand(message, { usesPromptInput = fal
|
|
|
22563
23298
|
case "settings":
|
|
22564
23299
|
await openNativeSettingsDialog();
|
|
22565
23300
|
return true;
|
|
23301
|
+
case "git-workflow-setup":
|
|
23302
|
+
await openNativeGitWorkflowSetupDialog();
|
|
23303
|
+
return true;
|
|
22566
23304
|
case "theme":
|
|
22567
23305
|
openNativeThemeSelector();
|
|
22568
23306
|
return true;
|
|
@@ -24362,8 +25100,8 @@ function updateServerActionButton() {
|
|
|
24362
25100
|
button.textContent = action === "restart" ? "Restart" : action === "update" || action === "update-all" ? "Update" : action === "stop" ? "Stop" : "Run";
|
|
24363
25101
|
button.classList.toggle("danger", action === "stop");
|
|
24364
25102
|
if (action === "restart") setServerActionStatus("Ready to restart the Web UI server.", "info");
|
|
24365
|
-
else if (action === "update") setServerActionStatus("Ready to run pi update for Pi only, then restart the Web UI server.", "info");
|
|
24366
|
-
else if (action === "update-all") setServerActionStatus("Ready to
|
|
25103
|
+
else if (action === "update") setServerActionStatus("Ready to run pi update --self for Pi only, then restart the Web UI server.", "info");
|
|
25104
|
+
else if (action === "update-all") setServerActionStatus("Ready to check pi update --all support, use the compatible fallback when needed, update detected Web UI/Optional Feature Pi package roots, then restart the Web UI server.", "info");
|
|
24367
25105
|
else if (action === "stop") setServerActionStatus("Ready to stop the Web UI server.", "info");
|
|
24368
25106
|
else setServerActionStatus();
|
|
24369
25107
|
}
|
|
@@ -25012,7 +25750,7 @@ function handleEvent(event) {
|
|
|
25012
25750
|
statusEntries.clear();
|
|
25013
25751
|
clearWidgetsForTab(event.tabId || activeTabId);
|
|
25014
25752
|
latestBtwWidgetPayload = null;
|
|
25015
|
-
|
|
25753
|
+
btwWidgetDismissedIdsByTab.delete(event.tabId || activeTabId);
|
|
25016
25754
|
btwWidgetComposerOpen = false;
|
|
25017
25755
|
btwWidgetInputDraft = "";
|
|
25018
25756
|
resetOptionalFeatureAvailability();
|
|
@@ -25603,6 +26341,7 @@ elements.optionsRemoteButton.addEventListener("click", () => runNativeCommandMen
|
|
|
25603
26341
|
elements.optionsNameButton.addEventListener("click", () => runNativeCommandMenu("/name"));
|
|
25604
26342
|
elements.optionsCloneButton.addEventListener("click", () => runNativeCommandMenu("/clone"));
|
|
25605
26343
|
elements.optionsSettingsButton.addEventListener("click", () => runNativeCommandMenu("/settings"));
|
|
26344
|
+
elements.optionsGitWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/git-workflow-setup"));
|
|
25606
26345
|
elements.optionsExportButton.addEventListener("click", () => runNativeCommandMenu("/export"));
|
|
25607
26346
|
elements.optionsForkButton.addEventListener("click", () => runNativeCommandMenu("/fork"));
|
|
25608
26347
|
elements.optionsTreeButton.addEventListener("click", () => runNativeCommandMenu("/tree"));
|
|
@@ -26314,8 +27053,13 @@ window.addEventListener("keydown", (event) => {
|
|
|
26314
27053
|
|
|
26315
27054
|
window.addEventListener("keydown", handleNativeAppShortcut, { capture: true });
|
|
26316
27055
|
document.addEventListener("visibilitychange", () => {
|
|
26317
|
-
if (document.visibilityState === "visible")
|
|
26318
|
-
|
|
27056
|
+
if (document.visibilityState === "visible") {
|
|
27057
|
+
scheduleForegroundReconcile("visibility resume", 0);
|
|
27058
|
+
refreshSubagents().finally(() => scheduleRefreshSubagents());
|
|
27059
|
+
} else {
|
|
27060
|
+
resetAbortLongPressAffordance();
|
|
27061
|
+
scheduleRefreshSubagents();
|
|
27062
|
+
}
|
|
26319
27063
|
});
|
|
26320
27064
|
window.addEventListener("pageshow", () => scheduleForegroundReconcile("page show", 0));
|
|
26321
27065
|
window.addEventListener("focus", () => scheduleForegroundReconcile("window focus"));
|
|
@@ -26653,6 +27397,7 @@ bindSidePanelSectionToggles();
|
|
|
26653
27397
|
restoreSidePanelState();
|
|
26654
27398
|
initializeCodexUsage();
|
|
26655
27399
|
initializeClaudeUsage();
|
|
27400
|
+
initializeSubagents();
|
|
26656
27401
|
initializeUpdateNotifications();
|
|
26657
27402
|
bindMobileViewChanges();
|
|
26658
27403
|
bindSidePanelOverlayViewChanges();
|