@firstpick/pi-package-webui 0.7.5 → 0.7.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 +37 -4
- package/bin/pi-webui-rpc-supervisor.mjs +518 -0
- package/bin/pi-webui.mjs +1003 -82
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/rpc-supervisor-client.mjs +301 -0
- package/lib/rpc-supervisor-protocol.mjs +236 -0
- package/lib/rpc-supervisor-state.mjs +165 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/package.json +2 -2
- package/public/app.js +1243 -87
- package/public/index.html +334 -24
- package/public/service-worker.js +6 -1
- package/public/styles.css +642 -41
- package/public/subagent-gate-visibility.mjs +36 -0
- package/public/workflow-status-stack.mjs +69 -0
- package/tests/app-runner-process-tree-harness.test.mjs +37 -3
- package/tests/boot-failure-diagnostics.test.mjs +180 -0
- package/tests/compact-sections-static.test.mjs +111 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +252 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/fixtures/compacting-pi.mjs +0 -0
- package/tests/fixtures/fake-pi.mjs +81 -2
- package/tests/git-panel-file-preview-static.test.mjs +221 -0
- package/tests/http-endpoints-harness.test.mjs +458 -33
- package/tests/mobile-static.test.mjs +77 -9
- package/tests/native-parity-harness.test.mjs +2 -1
- package/tests/native-parity.test.mjs +11 -0
- package/tests/numpad-decimal-input-static.test.mjs +128 -0
- package/tests/prompt-routing-input-clear-static.test.mjs +34 -0
- package/tests/prompt-routing-tab-status.test.mjs +103 -0
- package/tests/rpc-supervisor-host.test.mjs +275 -0
- package/tests/rpc-supervisor-protocol.test.mjs +67 -0
- package/tests/rpc-supervisor-state.test.mjs +62 -0
- package/tests/run-all.mjs +4 -1
- package/tests/streaming-ui-coupling.test.mjs +15 -0
- package/tests/subagent-gate-visibility.test.mjs +66 -0
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagents-helper.test.mjs +145 -8
- package/tests/workflow-status-stack.test.mjs +87 -0
- package/webui-rpc-helper.mjs +164 -4
package/public/app.js
CHANGED
|
@@ -3,6 +3,8 @@ import { guidedGitReviewAvailableForTabCatalog, resolveCommandForTabCatalog, res
|
|
|
3
3
|
import { guidedGitReviewCanRequestStagedContent, guidedGitReviewHasApprovedBinding, guidedGitReviewProcessNavigationAllowed, guidedGitReviewProcessSelectionPatch, guidedGitReviewTransition, guidedGitReviewWidgetRemovalTransition } from "./guided-git-review-state.mjs";
|
|
4
4
|
import { createFastOutputLiveState, createSustainedFlushScheduler, fastOutputLiveTextAndThinking, reduceFastOutputLiveEvent, seedFastOutputLiveState, shouldConsumeFastOutputLiveEvent } from "./fast-output-live.mjs";
|
|
5
5
|
import { addLaunchSlot, cloneLaunchSlotRoles, launchSlotRolesEqual, removeLaunchSlot, updateLaunchSlot } from "./subagent-launch-slot-state.mjs";
|
|
6
|
+
import { pruneDismissedSubagentGateKeys, subagentGateIsTerminal, subagentGateKey, visibleSubagentGates } from "./subagent-gate-visibility.mjs";
|
|
7
|
+
import { groupConsecutiveWorkflowStatusItems, isCompletedWorkflowStatusExecution, workflowStatusSnapshot } from "./workflow-status-stack.mjs";
|
|
6
8
|
|
|
7
9
|
const $ = (selector) => document.querySelector(selector);
|
|
8
10
|
|
|
@@ -129,6 +131,7 @@ const elements = {
|
|
|
129
131
|
optionsNameButton: $("#optionsNameButton"),
|
|
130
132
|
optionsCloneButton: $("#optionsCloneButton"),
|
|
131
133
|
optionsSettingsButton: $("#optionsSettingsButton"),
|
|
134
|
+
optionsWorkflowSetupButton: $("#optionsWorkflowSetupButton"),
|
|
132
135
|
optionsSafetyGuardSetupButton: $("#optionsSafetyGuardSetupButton"),
|
|
133
136
|
optionsGitWorkflowSetupButton: $("#optionsGitWorkflowSetupButton"),
|
|
134
137
|
optionsExportButton: $("#optionsExportButton"),
|
|
@@ -223,10 +226,12 @@ const elements = {
|
|
|
223
226
|
fileViewerSaveButton: $("#fileViewerSaveButton"),
|
|
224
227
|
fileViewerCloseButton: $("#fileViewerCloseButton"),
|
|
225
228
|
fileViewerHelp: $("#fileViewerHelp"),
|
|
229
|
+
fileViewerChangesModeButton: $("#fileViewerChangesModeButton"),
|
|
226
230
|
fileViewerSourceModeButton: $("#fileViewerSourceModeButton"),
|
|
227
231
|
fileViewerPreviewModeButton: $("#fileViewerPreviewModeButton"),
|
|
228
232
|
fileViewerEditor: $("#fileViewerEditor"),
|
|
229
233
|
fileViewerPreview: $("#fileViewerPreview"),
|
|
234
|
+
fileViewerChanges: $("#fileViewerChanges"),
|
|
230
235
|
fileViewerStatus: $("#fileViewerStatus"),
|
|
231
236
|
fileSelectionBar: $("#fileSelectionBar"),
|
|
232
237
|
fileSelectionSummary: $("#fileSelectionSummary"),
|
|
@@ -386,6 +391,8 @@ let activeTextAttachmentEditor = null;
|
|
|
386
391
|
let activeSkillEditor = null;
|
|
387
392
|
let fileTreeState = { root: "", entriesByPath: new Map(), expanded: new Set(), loading: new Set(), selectedPath: "", requestSerial: 0, searchQuery: "", searchEntries: [], searchLoading: false, searchTruncated: false, searchTotal: 0, gitStatusRoot: "", gitStatusByPath: new Map() };
|
|
388
393
|
let activeFileViewer = null;
|
|
394
|
+
let fileViewerOpenRequestSerial = 0;
|
|
395
|
+
let fileViewerGitChangesRequestSerial = 0;
|
|
389
396
|
let fileViewerSelection = null;
|
|
390
397
|
let fileContextMenuState = null;
|
|
391
398
|
let sidePanelContextMenuState = null;
|
|
@@ -395,6 +402,7 @@ let sidePanelResizeState = null;
|
|
|
395
402
|
let fileTreeSearchTimer = null;
|
|
396
403
|
let fileTreeSearchRequestSerial = 0;
|
|
397
404
|
let tabActivities = new Map();
|
|
405
|
+
const promptRoutingTabs = new Set();
|
|
398
406
|
let tabSeenCompletionSerials = new Map();
|
|
399
407
|
let streamBubble = null;
|
|
400
408
|
let streamText = null;
|
|
@@ -447,6 +455,11 @@ let refreshTabsTimer = null;
|
|
|
447
455
|
let tabsRenderFrame = null;
|
|
448
456
|
let foregroundReconcileTimer = null;
|
|
449
457
|
let eventSource = null;
|
|
458
|
+
const supervisorEventCursors = new Map();
|
|
459
|
+
const supervisorRetiredEpochs = new Map();
|
|
460
|
+
const supervisorGapWarnings = new Set();
|
|
461
|
+
const supervisorContinuityRefreshes = new Map();
|
|
462
|
+
const supervisorEnvelopeWarnings = new Set();
|
|
450
463
|
let activeDialog = null;
|
|
451
464
|
let activeConfirmationResolve = null;
|
|
452
465
|
let activeGitWorktreeBaseResolve = null;
|
|
@@ -492,6 +505,9 @@ const skillUsageByTab = new Map();
|
|
|
492
505
|
let appRunnerCustomDraft = { id: "", label: "", command: "./", path: "", args: "" };
|
|
493
506
|
let appRunnerCustomFeedback = { type: "", message: "" };
|
|
494
507
|
let appRunnerFileBrowserState = { open: false, loading: false, path: "", data: null, error: "" };
|
|
508
|
+
let appRunnerSearchPathDraft = "";
|
|
509
|
+
let appRunnerSearchPathFeedback = { type: "", message: "" };
|
|
510
|
+
let appRunnerDirectoryBrowserState = { open: false, loading: false, path: "", data: null, error: "" };
|
|
495
511
|
let optionsMenuOpen = false;
|
|
496
512
|
let availableCommands = [];
|
|
497
513
|
let rawAvailableCommands = [];
|
|
@@ -543,6 +559,7 @@ let latestSubagents = null;
|
|
|
543
559
|
let subagentsError = null;
|
|
544
560
|
let subagentsLoading = false;
|
|
545
561
|
let refreshSubagentsTimer = null;
|
|
562
|
+
const dismissedSubagentGateKeys = new Set();
|
|
546
563
|
let subagentOverlaySelection = null;
|
|
547
564
|
let subagentOverlayData = null;
|
|
548
565
|
let subagentOverlayError = "";
|
|
@@ -927,6 +944,7 @@ const optionalFeatureAvailability = {
|
|
|
927
944
|
};
|
|
928
945
|
const APP_RUNNER_CONTEXT_DEFAULT_LINES = 80;
|
|
929
946
|
const APP_RUNNER_CONTEXT_MAX_LINES = 1000;
|
|
947
|
+
const APP_RUNNER_SEARCH_PATH_LIMIT = 24;
|
|
930
948
|
const OPTIONAL_FEATURES = [
|
|
931
949
|
{
|
|
932
950
|
id: "bangCommandAutocomplete",
|
|
@@ -1096,6 +1114,7 @@ const OPTIONAL_COMMAND_FEATURES = new Map([
|
|
|
1096
1114
|
["aur-review", "aurReview"],
|
|
1097
1115
|
["workflow", "workflows"],
|
|
1098
1116
|
["workflow-clear", "workflows"],
|
|
1117
|
+
["workflow-setup", "workflows"],
|
|
1099
1118
|
["safety-guard", "safetyGuard"],
|
|
1100
1119
|
["safety-guard-setup", "safetyGuard"],
|
|
1101
1120
|
["skills", "tuiSkillsCommand"],
|
|
@@ -1113,7 +1132,7 @@ const HIDDEN_COMMAND_NAMES = new Set(["webui-tree-navigate", "webui-helper"]);
|
|
|
1113
1132
|
HIDDEN_COMMAND_NAMES.add("stats-webui");
|
|
1114
1133
|
HIDDEN_COMMAND_NAMES.add("btw-status");
|
|
1115
1134
|
HIDDEN_COMMAND_NAMES.add("btw-transfer");
|
|
1116
|
-
const NATIVE_SELECTOR_COMMANDS = new Set(["model", "settings", "safety-guard-setup", "git-workflow-setup", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"]);
|
|
1135
|
+
const NATIVE_SELECTOR_COMMANDS = new Set(["model", "settings", "workflow-setup", "safety-guard-setup", "git-workflow-setup", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"]);
|
|
1117
1136
|
const SETTINGS_THINKING_OPTIONS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
1118
1137
|
const SETTINGS_TRANSPORT_OPTIONS = ["sse", "websocket", "websocket-cached", "auto"];
|
|
1119
1138
|
const SETTINGS_HTTP_IDLE_TIMEOUT_OPTIONS = [
|
|
@@ -5114,6 +5133,7 @@ function workflowOverlayHasContent() {
|
|
|
5114
5133
|
if (!isOptionalFeatureEnabled("workflows")) return false;
|
|
5115
5134
|
const inspector = activeWorkflowInspectorPayload();
|
|
5116
5135
|
if (inspector?.runs?.length) return true;
|
|
5136
|
+
if (getWidgetLines("workflow").length) return true;
|
|
5117
5137
|
return !!parseWorkflowSubprocessPayload(getWidgetLines("workflow:subprocess"));
|
|
5118
5138
|
}
|
|
5119
5139
|
|
|
@@ -5123,7 +5143,11 @@ function workflowOverlayIsMinimized() {
|
|
|
5123
5143
|
|
|
5124
5144
|
function renderWorkflowOverlayControls() {
|
|
5125
5145
|
const openAvailable = workflowOverlayHasContent() && workflowOverlayIsMinimized();
|
|
5126
|
-
if (elements.workflowOverlayOpenButton)
|
|
5146
|
+
if (elements.workflowOverlayOpenButton) {
|
|
5147
|
+
elements.workflowOverlayOpenButton.hidden = !openAvailable;
|
|
5148
|
+
elements.workflowOverlayOpenButton.setAttribute("aria-expanded", openAvailable ? "false" : "true");
|
|
5149
|
+
applyStyledTooltip(elements.workflowOverlayOpenButton, "Open the minimized workflow overlay.", { ariaLabel: true, align: "end" });
|
|
5150
|
+
}
|
|
5127
5151
|
if (elements.workflowModeControls) {
|
|
5128
5152
|
elements.workflowModeControls.hidden = Boolean(elements.workflowModeButton?.hidden) && !openAvailable;
|
|
5129
5153
|
elements.workflowModeControls.classList.toggle("has-open-control", openAvailable);
|
|
@@ -5160,12 +5184,14 @@ function renderWorkflowModeControls() {
|
|
|
5160
5184
|
elements.workflowModeButton.disabled = !commandName || pending;
|
|
5161
5185
|
elements.workflowModeButton.classList.toggle("active", active);
|
|
5162
5186
|
elements.workflowModeButton.setAttribute("aria-pressed", active ? "true" : "false");
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
const tooltip =
|
|
5166
|
-
?
|
|
5167
|
-
:
|
|
5168
|
-
|
|
5187
|
+
if (pending) elements.workflowModeButton.setAttribute("aria-busy", "true");
|
|
5188
|
+
else elements.workflowModeButton.removeAttribute("aria-busy");
|
|
5189
|
+
const tooltip = pending
|
|
5190
|
+
? "Updating JavaScript Workflow Mode for this Pi tab."
|
|
5191
|
+
: commandName
|
|
5192
|
+
? `${active ? "Disable" : "Enable"} JavaScript Workflow Mode for this Pi tab via /${commandName} mode ${active ? "off" : "on"}.`
|
|
5193
|
+
: "Workflow Mode is unavailable because the /workflow command is not loaded.";
|
|
5194
|
+
applyStyledTooltip(elements.workflowModeButton, tooltip, { ariaLabel: true, align: "end" });
|
|
5169
5195
|
}
|
|
5170
5196
|
renderWorkflowOverlayControls();
|
|
5171
5197
|
|
|
@@ -7188,6 +7214,8 @@ function updateActiveFileViewerAfterMove(sourcePath = "", destinationPath = "")
|
|
|
7188
7214
|
extension: fileExtensionForPath(nextPath),
|
|
7189
7215
|
language,
|
|
7190
7216
|
mode: activeFileViewer.mode === "preview" && language === "markdown" ? "preview" : "source",
|
|
7217
|
+
// The open-time diff snapshot belongs to the previous path.
|
|
7218
|
+
gitChanges: null,
|
|
7191
7219
|
};
|
|
7192
7220
|
if (fileViewerSelection) fileViewerSelection = { ...fileViewerSelection, path: nextPath, fileName: activeFileViewer.name };
|
|
7193
7221
|
updateFileViewerUi();
|
|
@@ -7593,10 +7621,21 @@ async function openFileTreeEntryInWebui(entry = fileContextMenuState?.entry) {
|
|
|
7593
7621
|
await openFileInViewer(path);
|
|
7594
7622
|
}
|
|
7595
7623
|
|
|
7624
|
+
// Changes mode only exists for Git-originated opens; every other viewer keeps
|
|
7625
|
+
// the original Source/Markdown-Preview behavior.
|
|
7626
|
+
function resolveFileViewerMode(viewer) {
|
|
7627
|
+
if (!viewer) return "source";
|
|
7628
|
+
const hasChanges = !!viewer.gitChanges;
|
|
7629
|
+
if (viewer.mode === "changes") return hasChanges ? "changes" : "source";
|
|
7630
|
+
if (viewer.sourceAvailable === false) return hasChanges ? "changes" : "source";
|
|
7631
|
+
return viewer.mode === "preview" && viewer.language === "markdown" ? "preview" : "source";
|
|
7632
|
+
}
|
|
7633
|
+
|
|
7596
7634
|
function setFileViewerMode(mode = "source") {
|
|
7597
7635
|
if (!activeFileViewer) return;
|
|
7598
|
-
const
|
|
7599
|
-
activeFileViewer.mode =
|
|
7636
|
+
const previousMode = activeFileViewer.mode;
|
|
7637
|
+
activeFileViewer.mode = resolveFileViewerMode({ ...activeFileViewer, mode });
|
|
7638
|
+
if (activeFileViewer.mode === "changes" && previousMode !== "changes") clearFileViewerSelection();
|
|
7600
7639
|
updateFileViewerUi();
|
|
7601
7640
|
}
|
|
7602
7641
|
|
|
@@ -7617,20 +7656,31 @@ function updateFileViewerUi() {
|
|
|
7617
7656
|
if (!isSidePanelOverlayView()) applyFileViewerWidth(currentFileViewerWidth());
|
|
7618
7657
|
const viewer = activeFileViewer;
|
|
7619
7658
|
const isMarkdown = viewer.language === "markdown";
|
|
7620
|
-
const
|
|
7659
|
+
const hasChanges = !!viewer.gitChanges;
|
|
7660
|
+
const sourceAvailable = viewer.sourceAvailable !== false;
|
|
7661
|
+
const mode = resolveFileViewerMode(viewer);
|
|
7621
7662
|
viewer.mode = mode;
|
|
7622
7663
|
if (elements.fileViewerTitle) elements.fileViewerTitle.textContent = viewer.name || fileDisplayName(viewer.path);
|
|
7623
7664
|
if (elements.fileViewerMeta) {
|
|
7624
7665
|
const lineCount = textLineCount(viewer.content || "");
|
|
7625
|
-
|
|
7666
|
+
const sourceMeta = sourceAvailable ? [formatBytes(viewer.size), `${lineCount} ${lineCount === 1 ? "line" : "lines"}`] : ["source unavailable"];
|
|
7667
|
+
elements.fileViewerMeta.textContent = [viewer.path, ...sourceMeta].filter(Boolean).join(" · ");
|
|
7668
|
+
}
|
|
7669
|
+
if (elements.fileViewerChangesModeButton) {
|
|
7670
|
+
elements.fileViewerChangesModeButton.hidden = !hasChanges;
|
|
7671
|
+
elements.fileViewerChangesModeButton.disabled = !hasChanges;
|
|
7672
|
+
elements.fileViewerChangesModeButton.setAttribute("aria-pressed", mode === "changes" ? "true" : "false");
|
|
7673
|
+
elements.fileViewerChangesModeButton.classList.toggle("active", mode === "changes");
|
|
7674
|
+
elements.fileViewerChangesModeButton.title = hasChanges ? `${viewer.gitChanges.label || "Git"} changes for this file` : "";
|
|
7626
7675
|
}
|
|
7627
7676
|
if (elements.fileViewerSourceModeButton) {
|
|
7677
|
+
elements.fileViewerSourceModeButton.disabled = !sourceAvailable;
|
|
7628
7678
|
elements.fileViewerSourceModeButton.setAttribute("aria-pressed", mode === "source" ? "true" : "false");
|
|
7629
7679
|
elements.fileViewerSourceModeButton.classList.toggle("active", mode === "source");
|
|
7630
7680
|
}
|
|
7631
7681
|
if (elements.fileViewerPreviewModeButton) {
|
|
7632
7682
|
elements.fileViewerPreviewModeButton.hidden = !isMarkdown;
|
|
7633
|
-
elements.fileViewerPreviewModeButton.disabled = !isMarkdown;
|
|
7683
|
+
elements.fileViewerPreviewModeButton.disabled = !isMarkdown || !sourceAvailable;
|
|
7634
7684
|
elements.fileViewerPreviewModeButton.setAttribute("aria-pressed", mode === "preview" ? "true" : "false");
|
|
7635
7685
|
elements.fileViewerPreviewModeButton.classList.toggle("active", mode === "preview");
|
|
7636
7686
|
}
|
|
@@ -7643,6 +7693,11 @@ function updateFileViewerUi() {
|
|
|
7643
7693
|
elements.fileViewerPreview.hidden = mode !== "preview";
|
|
7644
7694
|
if (mode === "preview") renderMarkdown(elements.fileViewerPreview, viewer.content || "");
|
|
7645
7695
|
}
|
|
7696
|
+
if (elements.fileViewerChanges) {
|
|
7697
|
+
elements.fileViewerChanges.hidden = mode !== "changes";
|
|
7698
|
+
if (mode === "changes") renderFileViewerChanges(viewer.gitChanges);
|
|
7699
|
+
else elements.fileViewerChanges.replaceChildren();
|
|
7700
|
+
}
|
|
7646
7701
|
if (elements.fileViewerSaveButton) elements.fileViewerSaveButton.disabled = viewer.readOnly === true || !viewer.dirty;
|
|
7647
7702
|
if (elements.fileViewerOpenDefaultButton) {
|
|
7648
7703
|
const viewerPath = normalizeFileTreePath(viewer.path || "");
|
|
@@ -7652,6 +7707,75 @@ function updateFileViewerUi() {
|
|
|
7652
7707
|
renderFileViewerSelectionBar();
|
|
7653
7708
|
}
|
|
7654
7709
|
|
|
7710
|
+
function fileViewerChangesNotice(text, level = "") {
|
|
7711
|
+
return make("p", `file-viewer-changes-notice ${level}`.trim(), text);
|
|
7712
|
+
}
|
|
7713
|
+
|
|
7714
|
+
function fileViewerChangesHeading(snapshot) {
|
|
7715
|
+
const heading = make("div", "git-diff-section-heading");
|
|
7716
|
+
heading.append(
|
|
7717
|
+
make("div", "git-diff-section-title", `${snapshot.label || "Git"} changes`),
|
|
7718
|
+
make("div", "git-diff-section-meta", snapshot.command || "git diff"),
|
|
7719
|
+
);
|
|
7720
|
+
return heading;
|
|
7721
|
+
}
|
|
7722
|
+
|
|
7723
|
+
// git diff --cc emits combined "@@@" hunks that the two-column parser cannot
|
|
7724
|
+
// represent, so those diffs fall back to readable raw text.
|
|
7725
|
+
function gitFileDiffUsesCombinedSyntax(diffText = "") {
|
|
7726
|
+
return /^@@@+ /m.test(String(diffText || ""));
|
|
7727
|
+
}
|
|
7728
|
+
|
|
7729
|
+
function renderFileViewerUntrackedChanges(snapshot) {
|
|
7730
|
+
const entry = normalizeGitUntrackedEntry({
|
|
7731
|
+
path: snapshot.path || "file",
|
|
7732
|
+
size: snapshot.size,
|
|
7733
|
+
binary: snapshot.binary,
|
|
7734
|
+
error: snapshot.contentError,
|
|
7735
|
+
...(typeof snapshot.content === "string" ? { content: snapshot.content } : {}),
|
|
7736
|
+
});
|
|
7737
|
+
if (!entry) return fileViewerChangesNotice("Untracked file content is unavailable.", "error");
|
|
7738
|
+
if (entry.contentMissing) return fileViewerChangesNotice("Untracked file content is unavailable.", "error");
|
|
7739
|
+
if (entry.error || entry.binary) return renderGitUntrackedRawFile(entry);
|
|
7740
|
+
return renderGitDiffFile(gitUntrackedEntryToDiffFile(entry));
|
|
7741
|
+
}
|
|
7742
|
+
|
|
7743
|
+
function renderFileViewerTrackedChanges(snapshot) {
|
|
7744
|
+
const diff = String(snapshot.diff || "");
|
|
7745
|
+
if (!diff.trim()) return fileViewerChangesNotice(`No ${String(snapshot.label || "Git").toLowerCase()} changes for this file.`);
|
|
7746
|
+
if (gitFileDiffUsesCombinedSyntax(diff)) return make("pre", "git-diff-raw", diff);
|
|
7747
|
+
const files = parseGitUnifiedDiff(diff);
|
|
7748
|
+
if (!files.length) return make("pre", "git-diff-raw", diff);
|
|
7749
|
+
const fragment = document.createDocumentFragment();
|
|
7750
|
+
for (const file of files) fragment.append(renderGitDiffFile(file));
|
|
7751
|
+
return fragment;
|
|
7752
|
+
}
|
|
7753
|
+
|
|
7754
|
+
function renderFileViewerChangesTruncation(snapshot) {
|
|
7755
|
+
const notice = make("div", "git-diff-truncated-notice");
|
|
7756
|
+
notice.append(make("span", undefined, `Diff truncated at ${formatBytes(snapshot.capBytes || 0)} — showing the bounded snapshot. Run the full command in a terminal for the complete diff:`));
|
|
7757
|
+
notice.append(make("code", "git-tools-command", snapshot.command || "git diff"));
|
|
7758
|
+
return notice;
|
|
7759
|
+
}
|
|
7760
|
+
|
|
7761
|
+
function renderFileViewerChanges(snapshot = activeFileViewer?.gitChanges) {
|
|
7762
|
+
const container = elements.fileViewerChanges;
|
|
7763
|
+
if (!container) return;
|
|
7764
|
+
if (!snapshot) {
|
|
7765
|
+
container.replaceChildren();
|
|
7766
|
+
return;
|
|
7767
|
+
}
|
|
7768
|
+
const wrapper = make("section", `git-diff-section file-viewer-changes-section ${snapshot.category || ""}`.trim());
|
|
7769
|
+
wrapper.append(fileViewerChangesHeading(snapshot));
|
|
7770
|
+
if (snapshot.loading) wrapper.append(fileViewerChangesNotice("Loading Git changes…"));
|
|
7771
|
+
else if (snapshot.error) wrapper.append(fileViewerChangesNotice(snapshot.error, "error"));
|
|
7772
|
+
else {
|
|
7773
|
+
wrapper.append(snapshot.category === "untracked" ? renderFileViewerUntrackedChanges(snapshot) : renderFileViewerTrackedChanges(snapshot));
|
|
7774
|
+
if (snapshot.truncated) wrapper.append(renderFileViewerChangesTruncation(snapshot));
|
|
7775
|
+
}
|
|
7776
|
+
container.replaceChildren(wrapper);
|
|
7777
|
+
}
|
|
7778
|
+
|
|
7655
7779
|
function clearFileViewerSelection() {
|
|
7656
7780
|
fileViewerSelection = null;
|
|
7657
7781
|
renderFileViewerSelectionBar();
|
|
@@ -7773,6 +7897,7 @@ async function sendFileSelectionToSession() {
|
|
|
7773
7897
|
}
|
|
7774
7898
|
|
|
7775
7899
|
function closeFileViewer() {
|
|
7900
|
+
fileViewerOpenRequestSerial += 1;
|
|
7776
7901
|
activeFileViewer = null;
|
|
7777
7902
|
clearFileViewerSelection();
|
|
7778
7903
|
document.body.classList.remove("file-viewer-open");
|
|
@@ -7785,20 +7910,80 @@ function closeFileViewer() {
|
|
|
7785
7910
|
elements.fileViewerEditor.readOnly = false;
|
|
7786
7911
|
}
|
|
7787
7912
|
if (elements.fileViewerPreview) elements.fileViewerPreview.replaceChildren();
|
|
7913
|
+
if (elements.fileViewerChanges) {
|
|
7914
|
+
elements.fileViewerChanges.hidden = true;
|
|
7915
|
+
elements.fileViewerChanges.replaceChildren();
|
|
7916
|
+
}
|
|
7788
7917
|
setFileViewerStatus("");
|
|
7789
7918
|
}
|
|
7790
7919
|
|
|
7791
|
-
|
|
7920
|
+
// Side-panel Git categories are UI labels; the read API uses its own allowlist.
|
|
7921
|
+
const GIT_FILE_DIFF_CATEGORY_BY_PANEL = Object.freeze({
|
|
7922
|
+
staged: "staged",
|
|
7923
|
+
changes: "unstaged",
|
|
7924
|
+
conflicted: "conflicted",
|
|
7925
|
+
untracked: "untracked",
|
|
7926
|
+
});
|
|
7927
|
+
|
|
7928
|
+
function gitFileDiffCategory(panelCategory = "") {
|
|
7929
|
+
return GIT_FILE_DIFF_CATEGORY_BY_PANEL[String(panelCategory || "").trim()] || "";
|
|
7930
|
+
}
|
|
7931
|
+
|
|
7932
|
+
// The changes view is the bounded snapshot loaded when the file was opened;
|
|
7933
|
+
// reopening the Git row refreshes it. Failures become a visible viewer state
|
|
7934
|
+
// instead of a rejected open.
|
|
7935
|
+
async function loadGitFileChangesSnapshot(repoRelPath, category, tabId) {
|
|
7936
|
+
const snapshot = { category, path: repoRelPath, label: "", command: "", diff: "", truncated: false, capBytes: 0, error: "" };
|
|
7937
|
+
try {
|
|
7938
|
+
const params = new URLSearchParams({ path: repoRelPath, category });
|
|
7939
|
+
const response = await api(`/api/git-file-diff?${params.toString()}`, { tabId });
|
|
7940
|
+
if (!response.ok) throw new Error(response.error || "Failed to load Git changes for this file");
|
|
7941
|
+
const data = response.data || {};
|
|
7942
|
+
return {
|
|
7943
|
+
...snapshot,
|
|
7944
|
+
...data,
|
|
7945
|
+
category,
|
|
7946
|
+
path: data.path || repoRelPath,
|
|
7947
|
+
diff: String(data.diff || ""),
|
|
7948
|
+
truncated: data.truncated === true,
|
|
7949
|
+
capBytes: Number(data.capBytes) || 0,
|
|
7950
|
+
contentError: data.error ? String(data.error) : "",
|
|
7951
|
+
error: "",
|
|
7952
|
+
};
|
|
7953
|
+
} catch (error) {
|
|
7954
|
+
return { ...snapshot, error: error.message || String(error) };
|
|
7955
|
+
}
|
|
7956
|
+
}
|
|
7957
|
+
|
|
7958
|
+
function gitFileChangesPlaceholder(category, repoRelPath, requestSerial) {
|
|
7959
|
+
return { category, path: repoRelPath, label: "", command: "", diff: "", truncated: false, capBytes: 0, loading: true, requestSerial, error: "" };
|
|
7960
|
+
}
|
|
7961
|
+
|
|
7962
|
+
async function applyGitFileChangesSnapshot(request, tabContext, viewerPath, requestSerial) {
|
|
7963
|
+
const snapshot = await request;
|
|
7964
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
7965
|
+
if (!activeFileViewer?.gitChanges?.loading || activeFileViewer.path !== viewerPath || activeFileViewer.gitChanges.requestSerial !== requestSerial) return;
|
|
7966
|
+
activeFileViewer.gitChanges = snapshot;
|
|
7967
|
+
updateFileViewerUi();
|
|
7968
|
+
}
|
|
7969
|
+
|
|
7970
|
+
async function openFileInViewer(path = "", { gitCategory = "", gitPath = "" } = {}) {
|
|
7792
7971
|
const normalized = normalizeFileTreePath(path);
|
|
7793
7972
|
if (!normalized) return;
|
|
7973
|
+
const openRequestSerial = ++fileViewerOpenRequestSerial;
|
|
7794
7974
|
const tabContext = activeTabContext();
|
|
7795
7975
|
fileTreeState.selectedPath = normalized;
|
|
7796
7976
|
renderFileTree();
|
|
7797
7977
|
setFileViewerStatus(`Opening ${normalized}…`);
|
|
7978
|
+
const category = gitFileDiffCategory(gitCategory);
|
|
7979
|
+
const changesPath = normalizeFileTreePath(gitPath) || normalized;
|
|
7980
|
+
const changesRequestSerial = category ? ++fileViewerGitChangesRequestSerial : 0;
|
|
7981
|
+
const changesRequest = category ? loadGitFileChangesSnapshot(changesPath, category, tabContext.tabId) : null;
|
|
7798
7982
|
try {
|
|
7799
7983
|
const response = await api(fileApiPath("/api/files/content", normalized), { tabId: tabContext.tabId });
|
|
7800
|
-
if (!isCurrentTabContext(tabContext)) return;
|
|
7984
|
+
if (!isCurrentTabContext(tabContext) || openRequestSerial !== fileViewerOpenRequestSerial) return;
|
|
7801
7985
|
const data = response.data || {};
|
|
7986
|
+
const gitChanges = changesRequest ? gitFileChangesPlaceholder(category, changesPath, changesRequestSerial) : null;
|
|
7802
7987
|
activeFileViewer = {
|
|
7803
7988
|
path: normalizeFileTreePath(data.path || normalized),
|
|
7804
7989
|
name: data.name || fileDisplayName(normalized),
|
|
@@ -7807,19 +7992,45 @@ async function openFileInViewer(path = "") {
|
|
|
7807
7992
|
mtimeMs: Number(data.mtimeMs) || 0,
|
|
7808
7993
|
extension: data.extension || "",
|
|
7809
7994
|
language: data.language || "text",
|
|
7810
|
-
mode: data.language === "markdown" ? "preview" : "source",
|
|
7995
|
+
mode: gitChanges ? "changes" : data.language === "markdown" ? "preview" : "source",
|
|
7811
7996
|
dirty: false,
|
|
7812
7997
|
readOnly: false,
|
|
7998
|
+
sourceAvailable: true,
|
|
7999
|
+
gitChanges,
|
|
7813
8000
|
};
|
|
7814
8001
|
if (elements.fileViewerEditor) elements.fileViewerEditor.value = activeFileViewer.content;
|
|
7815
8002
|
clearFileViewerSelection();
|
|
7816
8003
|
updateFileViewerUi();
|
|
7817
8004
|
setFileViewerStatus("Opened in WebUI.", "success");
|
|
8005
|
+
if (changesRequest) void applyGitFileChangesSnapshot(changesRequest, tabContext, activeFileViewer.path, changesRequestSerial);
|
|
7818
8006
|
} catch (error) {
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
8007
|
+
const message = error.message || String(error);
|
|
8008
|
+
// A deleted tracked file has no live source but still has a diff worth showing.
|
|
8009
|
+
const gitChanges = changesRequest ? await changesRequest : null;
|
|
8010
|
+
if (!isCurrentTabContext(tabContext) || openRequestSerial !== fileViewerOpenRequestSerial) return;
|
|
8011
|
+
if (gitChanges && !gitChanges.error) {
|
|
8012
|
+
activeFileViewer = {
|
|
8013
|
+
path: normalized,
|
|
8014
|
+
name: fileDisplayName(normalized),
|
|
8015
|
+
content: "",
|
|
8016
|
+
size: 0,
|
|
8017
|
+
mtimeMs: 0,
|
|
8018
|
+
extension: fileExtensionForPath(normalized),
|
|
8019
|
+
language: fileLanguageForPath(normalized),
|
|
8020
|
+
mode: "changes",
|
|
8021
|
+
dirty: false,
|
|
8022
|
+
readOnly: true,
|
|
8023
|
+
sourceAvailable: false,
|
|
8024
|
+
gitChanges,
|
|
8025
|
+
};
|
|
8026
|
+
if (elements.fileViewerEditor) elements.fileViewerEditor.value = "";
|
|
8027
|
+
clearFileViewerSelection();
|
|
8028
|
+
updateFileViewerUi();
|
|
8029
|
+
setFileViewerStatus("File content unavailable; showing Git changes (read-only).", "warn");
|
|
8030
|
+
return;
|
|
7822
8031
|
}
|
|
8032
|
+
setFileViewerStatus(message, "error");
|
|
8033
|
+
addEvent(`file open failed: ${message}`, "error");
|
|
7823
8034
|
}
|
|
7824
8035
|
}
|
|
7825
8036
|
|
|
@@ -7931,6 +8142,7 @@ function setTabActivity(tabId, activity = {}) {
|
|
|
7931
8142
|
if (!tabId) return null;
|
|
7932
8143
|
const previous = tabActivities.get(tabId);
|
|
7933
8144
|
const normalized = normalizeTabActivity(activity);
|
|
8145
|
+
if (promptRoutingTabs.has(tabId) && previous?.isWorking && !normalized.isWorking) return previous;
|
|
7934
8146
|
tabActivities.set(tabId, normalized);
|
|
7935
8147
|
if (!tabSeenCompletionSerials.has(tabId) || (previous && normalized.completionSerial < previous.completionSerial)) {
|
|
7936
8148
|
tabSeenCompletionSerials.set(tabId, normalized.completionSerial);
|
|
@@ -8069,7 +8281,8 @@ function markTabWorkingLocally(tabId = activeTabId) {
|
|
|
8069
8281
|
const tab = tabs.find((item) => item.id === tabId);
|
|
8070
8282
|
if (!tab) return false;
|
|
8071
8283
|
const previous = activityForTab(tab);
|
|
8072
|
-
const
|
|
8284
|
+
const timestamp = new Date().toISOString();
|
|
8285
|
+
const next = normalizeTabActivity({ ...previous, status: "working", isWorking: true, lastStartedAt: timestamp, lastChangedAt: timestamp });
|
|
8073
8286
|
tabActivities.set(tabId, next);
|
|
8074
8287
|
if (tabActivityStateChanged(previous, next)) scheduleTabsRender();
|
|
8075
8288
|
return true;
|
|
@@ -8086,6 +8299,7 @@ function markTabIdleLocally(tabId = activeTabId) {
|
|
|
8086
8299
|
}
|
|
8087
8300
|
|
|
8088
8301
|
function markTabDoneLocally(tabId = activeTabId) {
|
|
8302
|
+
if (promptRoutingTabs.has(tabId)) return false;
|
|
8089
8303
|
const tab = tabs.find((item) => item.id === tabId);
|
|
8090
8304
|
if (!tab) return false;
|
|
8091
8305
|
const previous = activityForTab(tab);
|
|
@@ -8889,9 +9103,18 @@ function renderGitPanelFolder(node, card, category, depth = 0) {
|
|
|
8889
9103
|
function renderGitPanelFile(entry, card, category) {
|
|
8890
9104
|
const row = make("div", `git-side-panel-file ${category}`);
|
|
8891
9105
|
const fullPath = entry.oldPath ? `${entry.oldPath} → ${entry.path}` : entry.path;
|
|
8892
|
-
row.title = `${fullPath} · Right-click for Git actions`;
|
|
9106
|
+
row.title = `${fullPath} · Open in WebUI · Right-click for Git actions`;
|
|
8893
9107
|
row.tabIndex = 0;
|
|
8894
|
-
row.setAttribute("
|
|
9108
|
+
row.setAttribute("role", "button");
|
|
9109
|
+
row.setAttribute("aria-label", `Open ${entry.name || entry.path} in WebUI, ${gitPanelStatsText(entry, category) || "no line statistics"}`);
|
|
9110
|
+
const open = () => openGitFileInViewer(entry.path, { root: card.root, candidates: card.candidates, category })
|
|
9111
|
+
.catch((error) => addEvent(error.message || String(error), "error"));
|
|
9112
|
+
row.addEventListener("click", open);
|
|
9113
|
+
row.addEventListener("keydown", (event) => {
|
|
9114
|
+
if (event.repeat || (event.key !== "Enter" && event.key !== " ")) return;
|
|
9115
|
+
event.preventDefault();
|
|
9116
|
+
open();
|
|
9117
|
+
});
|
|
8895
9118
|
const status = make("span", "git-side-panel-file-status", entry.status?.trim() || (entry.untracked ? "?" : "•"));
|
|
8896
9119
|
const name = make("span", "git-side-panel-file-name", entry.name || entry.path);
|
|
8897
9120
|
const statsText = gitPanelStatsText(entry, category);
|
|
@@ -10682,7 +10905,7 @@ function applyStyledTooltip(node, tooltip, options = {}) {
|
|
|
10682
10905
|
node.setAttribute("aria-label", ariaLabel);
|
|
10683
10906
|
}
|
|
10684
10907
|
if (options.align) node.setAttribute("data-tooltip-align", options.align);
|
|
10685
|
-
bindStyledTooltipEvents(node);
|
|
10908
|
+
if (options.floating !== false) bindStyledTooltipEvents(node);
|
|
10686
10909
|
return node;
|
|
10687
10910
|
}
|
|
10688
10911
|
|
|
@@ -11997,25 +12220,59 @@ function copyGitPathToClipboard(path) {
|
|
|
11997
12220
|
copyGitTextToClipboard(path, "path");
|
|
11998
12221
|
}
|
|
11999
12222
|
|
|
12000
|
-
// Git paths are repo-root-relative; the file viewer resolves against
|
|
12001
|
-
// cwd.
|
|
12223
|
+
// Git paths are repo-root-relative; the file viewer resolves against a tab's
|
|
12224
|
+
// cwd. Prefer the active tab when it contains the file, otherwise use another
|
|
12225
|
+
// tab that exposes the repository path.
|
|
12226
|
+
function gitFileViewerTarget(repoRelPath, root, candidates = []) {
|
|
12227
|
+
const path = normalizeFileTreePath(repoRelPath);
|
|
12228
|
+
const normalizedRoot = String(root || "").trim().replace(/\\/g, "/");
|
|
12229
|
+
const repoRoot = normalizedRoot === "/" ? "/" : normalizedRoot.replace(/\/+$/, "");
|
|
12230
|
+
if (!path || !repoRoot) return null;
|
|
12231
|
+
const absolute = `${repoRoot === "/" ? "/" : `${repoRoot}/`}${path}`;
|
|
12232
|
+
const current = activeTab();
|
|
12233
|
+
const ordered = [current ? { tabId: current.id, cwd: current.cwd } : null, ...candidates].filter(Boolean);
|
|
12234
|
+
const seen = new Set();
|
|
12235
|
+
for (const candidate of ordered) {
|
|
12236
|
+
const tabId = String(candidate?.tabId || candidate?.id || "");
|
|
12237
|
+
const normalizedCwd = String(candidate?.cwd || "").trim().replace(/\\/g, "/");
|
|
12238
|
+
const cwd = normalizedCwd === "/" ? "/" : normalizedCwd.replace(/\/+$/, "");
|
|
12239
|
+
if (!tabId || !cwd || seen.has(tabId)) continue;
|
|
12240
|
+
seen.add(tabId);
|
|
12241
|
+
const prefix = cwd === "/" ? "/" : `${cwd}/`;
|
|
12242
|
+
const caseInsensitive = /^[a-z]:\//i.test(absolute) && /^[a-z]:\//i.test(prefix);
|
|
12243
|
+
const comparableAbsolute = caseInsensitive ? absolute.toLowerCase() : absolute;
|
|
12244
|
+
const comparablePrefix = caseInsensitive ? prefix.toLowerCase() : prefix;
|
|
12245
|
+
if (!comparableAbsolute.startsWith(comparablePrefix)) continue;
|
|
12246
|
+
const viewerPath = absolute.slice(prefix.length);
|
|
12247
|
+
if (viewerPath) return { tabId, path: viewerPath };
|
|
12248
|
+
}
|
|
12249
|
+
return null;
|
|
12250
|
+
}
|
|
12251
|
+
|
|
12252
|
+
async function openGitFileInViewer(repoRelPath, { root = "", candidates = [], closeChanges = false, category = "" } = {}) {
|
|
12253
|
+
const target = gitFileViewerTarget(repoRelPath, root, candidates);
|
|
12254
|
+
if (!target) {
|
|
12255
|
+
addEvent(`Cannot open ${repoRelPath}: it is outside the available tab working directories.`, "error");
|
|
12256
|
+
return;
|
|
12257
|
+
}
|
|
12258
|
+
if (closeChanges) closeGitChangesDialog();
|
|
12259
|
+
if (target.tabId !== activeTabId) await switchTab(target.tabId);
|
|
12260
|
+
if (target.tabId !== activeTabId) {
|
|
12261
|
+
addEvent(`Cannot open ${repoRelPath}: its terminal tab is no longer available.`, "error");
|
|
12262
|
+
return;
|
|
12263
|
+
}
|
|
12264
|
+
setSidePanelCollapsed(false);
|
|
12265
|
+
await openFileInViewer(target.path, { gitCategory: category, gitPath: normalizeFileTreePath(repoRelPath) });
|
|
12266
|
+
}
|
|
12267
|
+
|
|
12002
12268
|
async function openGitFileFromChanges(repoRelPath) {
|
|
12003
12269
|
const tabId = gitChangesState.tabId || activeTabId;
|
|
12004
|
-
const root = gitChangesState.data?.root || "";
|
|
12005
12270
|
const tab = tabs.find((item) => item.id === tabId);
|
|
12006
|
-
|
|
12007
|
-
|
|
12008
|
-
|
|
12009
|
-
|
|
12010
|
-
|
|
12011
|
-
else if (root !== cwd) {
|
|
12012
|
-
addEvent(`Cannot open ${repoRelPath}: it is outside this tab's working directory.`, "error");
|
|
12013
|
-
return;
|
|
12014
|
-
}
|
|
12015
|
-
}
|
|
12016
|
-
closeGitChangesDialog();
|
|
12017
|
-
setSidePanelCollapsed(false);
|
|
12018
|
-
await openFileInViewer(viewerPath);
|
|
12271
|
+
await openGitFileInViewer(repoRelPath, {
|
|
12272
|
+
root: gitChangesState.data?.root || "",
|
|
12273
|
+
candidates: tab ? [{ tabId: tab.id, cwd: tab.cwd }] : [],
|
|
12274
|
+
closeChanges: true,
|
|
12275
|
+
});
|
|
12019
12276
|
}
|
|
12020
12277
|
|
|
12021
12278
|
function gitChangesCommonFileActions(path) {
|
|
@@ -13735,7 +13992,11 @@ function renderWorkspaceDashboard() {
|
|
|
13735
13992
|
make("span", "workspace-dashboard-chip", `${tabs.length} tab${tabs.length === 1 ? "" : "s"}`),
|
|
13736
13993
|
make("span", `workspace-dashboard-chip ${queueCount ? "attention" : ""}`.trim(), queueCount ? `${queueCount} queued` : "queue clear"),
|
|
13737
13994
|
);
|
|
13738
|
-
|
|
13995
|
+
const summary = make("div", "workspace-dashboard-summary-row");
|
|
13996
|
+
summary.append(make("span", "workspace-dashboard-kicker", "Workspace"), meta);
|
|
13997
|
+
const identity = make("div", "workspace-dashboard-identity");
|
|
13998
|
+
identity.append(heading, cwd);
|
|
13999
|
+
title.append(summary, identity);
|
|
13739
14000
|
const actions = make("div", "workspace-dashboard-actions");
|
|
13740
14001
|
actions.append(
|
|
13741
14002
|
dashboardAction("Command palette", () => openCommandPalette(), "primary"),
|
|
@@ -15566,7 +15827,13 @@ function initializeClaudeUsage() {
|
|
|
15566
15827
|
}
|
|
15567
15828
|
|
|
15568
15829
|
function subagentTabsWithRunningAgents() {
|
|
15830
|
+
const serverNow = Number(latestSubagents?.updatedAt);
|
|
15831
|
+
const now = Number.isFinite(serverNow) ? serverNow : Date.now();
|
|
15569
15832
|
return (Array.isArray(latestSubagents?.tabs) ? latestSubagents.tabs : [])
|
|
15833
|
+
.map((tab) => {
|
|
15834
|
+
const gates = visibleSubagentGates(tab, dismissedSubagentGateKeys, now);
|
|
15835
|
+
return { ...tab, gates, gateCount: gates.length };
|
|
15836
|
+
})
|
|
15570
15837
|
.filter((tab) => Number(tab?.agentCount || 0) > 0 || Number(tab?.gateCount || 0) > 0)
|
|
15571
15838
|
.sort((a, b) => Number(a.tabIndex || 0) - Number(b.tabIndex || 0) || String(a.tabTitle || "").localeCompare(String(b.tabTitle || "")));
|
|
15572
15839
|
}
|
|
@@ -15587,6 +15854,10 @@ function subagentRunElapsed(run) {
|
|
|
15587
15854
|
return Number.isFinite(startedAt) ? formatDuration(Math.max(0, Date.now() - startedAt)) : "";
|
|
15588
15855
|
}
|
|
15589
15856
|
|
|
15857
|
+
function subagentSourceLabel(source = "") {
|
|
15858
|
+
return source === "foreground" || source === "workflow" ? source : "async";
|
|
15859
|
+
}
|
|
15860
|
+
|
|
15590
15861
|
function subagentExecutionFacts(agent = {}) {
|
|
15591
15862
|
const thinking = String(agent?.thinking || "").trim();
|
|
15592
15863
|
let model = String(agent?.model || "").trim();
|
|
@@ -15728,7 +15999,7 @@ function subagentOverlayStateFacts(data = subagentOverlayData) {
|
|
|
15728
15999
|
return [
|
|
15729
16000
|
agent.status || "running",
|
|
15730
16001
|
data?.mode || subagentOverlaySelection?.run?.mode,
|
|
15731
|
-
data?.source || subagentOverlaySelection?.run?.source,
|
|
16002
|
+
subagentSourceLabel(data?.source || subagentOverlaySelection?.run?.source),
|
|
15732
16003
|
agent.nested ? "nested" : "",
|
|
15733
16004
|
...subagentExecutionFacts(agent),
|
|
15734
16005
|
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
@@ -15982,7 +16253,7 @@ function renderSubagentTerminalView() {
|
|
|
15982
16253
|
const facts = [
|
|
15983
16254
|
view.finished ? "finished" : running ? "running" : agent.status || "finished",
|
|
15984
16255
|
view.run?.mode,
|
|
15985
|
-
view.
|
|
16256
|
+
subagentSourceLabel(view.data?.source || view.run?.source),
|
|
15986
16257
|
agent.nested ? "nested" : "",
|
|
15987
16258
|
...subagentExecutionFacts(agent),
|
|
15988
16259
|
agent.currentTool ? `tool ${agent.currentTool}` : "",
|
|
@@ -16180,7 +16451,7 @@ function renderSubagentTerminalTab(view) {
|
|
|
16180
16451
|
appendTerminalTabContent(button, {
|
|
16181
16452
|
title: subagentTerminalViewTitle(view),
|
|
16182
16453
|
indicator: { state: running ? "working" : "done" },
|
|
16183
|
-
meta: ["Subagent", ...subagentExecutionFacts(view.data?.agent || view.agent), view.parentTitle || "parent terminal"].join(" · "),
|
|
16454
|
+
meta: ["Subagent", subagentSourceLabel(view.data?.source || view.run?.source), ...subagentExecutionFacts(view.data?.agent || view.agent), view.parentTitle || "parent terminal"].join(" · "),
|
|
16184
16455
|
subagent: true,
|
|
16185
16456
|
});
|
|
16186
16457
|
button.addEventListener("click", () => activateSubagentTerminalView(view.id));
|
|
@@ -16210,7 +16481,7 @@ function renderSubagentAgent(tab, run, agent) {
|
|
|
16210
16481
|
const facts = [
|
|
16211
16482
|
agent?.nested ? "nested" : "",
|
|
16212
16483
|
run?.mode && run.mode !== "single" ? run.mode : "",
|
|
16213
|
-
run?.source
|
|
16484
|
+
subagentSourceLabel(run?.source),
|
|
16214
16485
|
...subagentExecutionFacts(agent),
|
|
16215
16486
|
agent?.currentTool ? `tool: ${agent.currentTool}` : "",
|
|
16216
16487
|
elapsed ? `running ${elapsed}` : "",
|
|
@@ -16250,7 +16521,7 @@ function renderSubagentGateAttempt(attempt) {
|
|
|
16250
16521
|
return row;
|
|
16251
16522
|
}
|
|
16252
16523
|
|
|
16253
|
-
function renderSubagentGate(gate) {
|
|
16524
|
+
function renderSubagentGate(tab, gate) {
|
|
16254
16525
|
const status = subagentGateStatusLabel(gate?.status);
|
|
16255
16526
|
const card = make("section", `subagent-gate-card ${status}`);
|
|
16256
16527
|
const header = make("div", "subagent-gate-header");
|
|
@@ -16259,7 +16530,24 @@ function renderSubagentGate(gate) {
|
|
|
16259
16530
|
make("strong", undefined, `Retry gate · ${gate?.qualifyingSuccesses || 0}/${gate?.requiredSuccesses || 1}`),
|
|
16260
16531
|
make("span", undefined, `${status}${gate?.requireDistinctProviders ? " · distinct providers" : ""}`),
|
|
16261
16532
|
);
|
|
16262
|
-
|
|
16533
|
+
const actions = make("div", "subagent-gate-actions");
|
|
16534
|
+
actions.append(make("span", `subagent-gate-status ${status}`, status));
|
|
16535
|
+
if (subagentGateIsTerminal(gate)) {
|
|
16536
|
+
const close = make("button", "subagent-gate-close", "×");
|
|
16537
|
+
close.type = "button";
|
|
16538
|
+
applyStyledTooltip(close, "Hide finished retry gate", { ariaLabel: "Hide finished retry gate" });
|
|
16539
|
+
close.addEventListener("click", (event) => {
|
|
16540
|
+
const key = subagentGateKey(tab?.tabId, gate?.id);
|
|
16541
|
+
if (key) dismissedSubagentGateKeys.add(key);
|
|
16542
|
+
renderSubagents();
|
|
16543
|
+
if (event.detail === 0) {
|
|
16544
|
+
const focusTarget = elements.subagentsBox?.querySelector(".subagent-gate-close") || document.querySelector("#sidePanelSectionToggleSubagents");
|
|
16545
|
+
focusTarget?.focus({ preventScroll: true });
|
|
16546
|
+
}
|
|
16547
|
+
});
|
|
16548
|
+
actions.append(close);
|
|
16549
|
+
}
|
|
16550
|
+
header.append(title, actions);
|
|
16263
16551
|
card.append(header);
|
|
16264
16552
|
const attempts = make("div", "subagent-gate-attempts");
|
|
16265
16553
|
for (const attempt of Array.isArray(gate?.attempts) ? gate.attempts : []) attempts.append(renderSubagentGateAttempt(attempt));
|
|
@@ -16294,7 +16582,7 @@ function renderSubagentTabGroup(tab) {
|
|
|
16294
16582
|
for (const agent of agents) list.append(renderSubagentAgent(tab, run, agent));
|
|
16295
16583
|
}
|
|
16296
16584
|
for (const gate of (Array.isArray(tab.gates) ? tab.gates : []).slice().sort((a, b) => Number(a.startedAt || 0) - Number(b.startedAt || 0))) {
|
|
16297
|
-
list.append(renderSubagentGate(gate));
|
|
16585
|
+
list.append(renderSubagentGate(tab, gate));
|
|
16298
16586
|
}
|
|
16299
16587
|
group.append(list);
|
|
16300
16588
|
return group;
|
|
@@ -16337,6 +16625,7 @@ async function refreshSubagents() {
|
|
|
16337
16625
|
try {
|
|
16338
16626
|
const response = await api("/api/subagents", { scoped: false });
|
|
16339
16627
|
latestSubagents = response.data || null;
|
|
16628
|
+
pruneDismissedSubagentGateKeys(latestSubagents?.tabs, dismissedSubagentGateKeys);
|
|
16340
16629
|
syncSubagentTerminalViewsFromOverview();
|
|
16341
16630
|
subagentsError = null;
|
|
16342
16631
|
} catch (error) {
|
|
@@ -16982,7 +17271,10 @@ function textLines(raw) {
|
|
|
16982
17271
|
}
|
|
16983
17272
|
|
|
16984
17273
|
function stripTodoProgressLines(text, { streaming = false } = {}) {
|
|
16985
|
-
|
|
17274
|
+
// Checklist text is transport for the todo-progress extension, not final
|
|
17275
|
+
// assistant output. Keep filtering it when the widget UI is user-disabled;
|
|
17276
|
+
// disabling the renderer does not unload the extension or its prompt policy.
|
|
17277
|
+
if (!isOptionalFeatureDetected("todoProgressWidget")) return String(text || "");
|
|
16986
17278
|
let inFence = false;
|
|
16987
17279
|
const kept = [];
|
|
16988
17280
|
const raw = String(text || "");
|
|
@@ -18180,6 +18472,7 @@ const APP_RUNNER_SUPPORTED_ITEMS = [
|
|
|
18180
18472
|
"C/C++: CMake, cc/c++ main files",
|
|
18181
18473
|
"Docker Compose: docker compose up",
|
|
18182
18474
|
"Shell scripts: bash/zsh/fish in root, dev/, scripts/, dev/scripts/",
|
|
18475
|
+
"Project discovery paths: shell and Python scripts directly inside directories you configure",
|
|
18183
18476
|
"Deno, make, just, and plain Node entry files",
|
|
18184
18477
|
];
|
|
18185
18478
|
const APP_RUNNER_SUPPORTED_TOOLTIP = [
|
|
@@ -18195,7 +18488,12 @@ function appRunnerMenuCanOpen() {
|
|
|
18195
18488
|
}
|
|
18196
18489
|
|
|
18197
18490
|
function activeAppRunnerCustomConfig() {
|
|
18198
|
-
return activeAppRunnerData().customRunnerConfig || { runners: [], projectRoot: "", displayProjectRoot: "", displayConfigFile: "" };
|
|
18491
|
+
return activeAppRunnerData().customRunnerConfig || { runners: [], searchPaths: [], projectRoot: "", displayProjectRoot: "", displayConfigFile: "" };
|
|
18492
|
+
}
|
|
18493
|
+
|
|
18494
|
+
function activeAppRunnerSearchPaths() {
|
|
18495
|
+
const config = activeAppRunnerCustomConfig();
|
|
18496
|
+
return Array.isArray(config.searchPaths) ? config.searchPaths.filter((item) => typeof item === "string" && item) : [];
|
|
18199
18497
|
}
|
|
18200
18498
|
|
|
18201
18499
|
function resetAppRunnerCustomDraft({ clearFeedback = true } = {}) {
|
|
@@ -18214,6 +18512,13 @@ function appRunnerRelativeDir(filePath) {
|
|
|
18214
18512
|
return index === -1 ? "" : normalized.slice(0, index);
|
|
18215
18513
|
}
|
|
18216
18514
|
|
|
18515
|
+
function appRunnerSourceLabel(runner = {}, displayCommand = "") {
|
|
18516
|
+
const projectFile = String(runner.projectFile || "").replace(/\\/g, "/");
|
|
18517
|
+
if (!projectFile) return "";
|
|
18518
|
+
if (String(displayCommand || "").includes(projectFile)) return "";
|
|
18519
|
+
return `from ${projectFile}`;
|
|
18520
|
+
}
|
|
18521
|
+
|
|
18217
18522
|
function appRunnerCustomArgsText(args) {
|
|
18218
18523
|
return Array.isArray(args) ? args.join(" ") : String(args || "");
|
|
18219
18524
|
}
|
|
@@ -18335,6 +18640,270 @@ async function deleteAppRunnerCustomRunner(runner = {}) {
|
|
|
18335
18640
|
}
|
|
18336
18641
|
}
|
|
18337
18642
|
|
|
18643
|
+
function setAppRunnerSearchPathFeedback(type, message) {
|
|
18644
|
+
appRunnerSearchPathFeedback = { type, message: cleanStatusText(message || "") };
|
|
18645
|
+
}
|
|
18646
|
+
|
|
18647
|
+
function normalizeAppRunnerSearchPathInput(value) {
|
|
18648
|
+
const raw = String(value || "").replace(/\\/g, "/").trim();
|
|
18649
|
+
if (!raw) return "";
|
|
18650
|
+
if (raw === "." || /^\.\/+$/.test(raw)) return ".";
|
|
18651
|
+
const trimmed = raw.replace(/^\.\/+/, "").replace(/\/+$/g, "");
|
|
18652
|
+
return trimmed || ".";
|
|
18653
|
+
}
|
|
18654
|
+
|
|
18655
|
+
function appRunnerSearchPathLabel(searchPath) {
|
|
18656
|
+
return searchPath === "." ? "Project root (.)" : searchPath;
|
|
18657
|
+
}
|
|
18658
|
+
|
|
18659
|
+
async function saveAppRunnerSearchPaths(searchPaths, { successMessage = "Saved project discovery paths.", eventMessage = "saved app runner discovery paths", onSuccess = null } = {}) {
|
|
18660
|
+
const tabContext = activeTabContext();
|
|
18661
|
+
try {
|
|
18662
|
+
const response = await api("/api/app-runner-config", { method: "POST", body: { searchPaths }, tabId: tabContext.tabId });
|
|
18663
|
+
if (!isCurrentTabContext(tabContext)) return false;
|
|
18664
|
+
setAppRunnerData(tabContext.tabId, response.data || {});
|
|
18665
|
+
setAppRunnerSearchPathFeedback("success", successMessage);
|
|
18666
|
+
onSuccess?.(tabContext);
|
|
18667
|
+
renderAppRunnerControls();
|
|
18668
|
+
renderWidgets();
|
|
18669
|
+
renderAppRunnerInfoDialog();
|
|
18670
|
+
addEvent(eventMessage, "info");
|
|
18671
|
+
return true;
|
|
18672
|
+
} catch (error) {
|
|
18673
|
+
if (!isCurrentTabContext(tabContext)) return false;
|
|
18674
|
+
const message = error.message || String(error);
|
|
18675
|
+
setAppRunnerSearchPathFeedback("error", `Project discovery paths were not saved: ${message}`);
|
|
18676
|
+
renderAppRunnerInfoDialog();
|
|
18677
|
+
addEvent(`app runner discovery paths were not saved: ${message}`, "error");
|
|
18678
|
+
return false;
|
|
18679
|
+
}
|
|
18680
|
+
}
|
|
18681
|
+
|
|
18682
|
+
async function addAppRunnerSearchPath(container) {
|
|
18683
|
+
const input = container?.querySelector("#appRunnerSearchPathInput");
|
|
18684
|
+
if (input) appRunnerSearchPathDraft = input.value || "";
|
|
18685
|
+
const searchPath = normalizeAppRunnerSearchPathInput(appRunnerSearchPathDraft);
|
|
18686
|
+
const focusInput = () => requestAnimationFrame(() => document.querySelector("#appRunnerSearchPathInput")?.focus());
|
|
18687
|
+
if (!searchPath) {
|
|
18688
|
+
setAppRunnerSearchPathFeedback("warning", "Enter a project-relative directory, or . for the project root.");
|
|
18689
|
+
renderAppRunnerInfoDialog();
|
|
18690
|
+
focusInput();
|
|
18691
|
+
addEvent("app runner discovery path is required", "warn");
|
|
18692
|
+
return;
|
|
18693
|
+
}
|
|
18694
|
+
const current = activeAppRunnerSearchPaths();
|
|
18695
|
+
if (current.includes(searchPath)) {
|
|
18696
|
+
setAppRunnerSearchPathFeedback("warning", `${appRunnerSearchPathLabel(searchPath)} is already configured.`);
|
|
18697
|
+
renderAppRunnerInfoDialog();
|
|
18698
|
+
focusInput();
|
|
18699
|
+
return;
|
|
18700
|
+
}
|
|
18701
|
+
if (current.length >= APP_RUNNER_SEARCH_PATH_LIMIT) {
|
|
18702
|
+
setAppRunnerSearchPathFeedback("warning", `Project discovery path limit reached (${APP_RUNNER_SEARCH_PATH_LIMIT}). Remove a path first.`);
|
|
18703
|
+
renderAppRunnerInfoDialog();
|
|
18704
|
+
return;
|
|
18705
|
+
}
|
|
18706
|
+
await saveAppRunnerSearchPaths([...current, searchPath], {
|
|
18707
|
+
successMessage: `Added ${appRunnerSearchPathLabel(searchPath)}. Supported shell scripts directly inside it now appear in the Run menu.`,
|
|
18708
|
+
eventMessage: `added app runner discovery path ${searchPath}`,
|
|
18709
|
+
onSuccess: () => {
|
|
18710
|
+
appRunnerSearchPathDraft = "";
|
|
18711
|
+
appRunnerDirectoryBrowserState = { open: false, loading: false, path: "", data: null, error: "" };
|
|
18712
|
+
},
|
|
18713
|
+
});
|
|
18714
|
+
}
|
|
18715
|
+
|
|
18716
|
+
async function removeAppRunnerSearchPath(searchPath) {
|
|
18717
|
+
const current = activeAppRunnerSearchPaths();
|
|
18718
|
+
if (!current.includes(searchPath)) return;
|
|
18719
|
+
const tabContext = activeTabContext();
|
|
18720
|
+
const saved = await saveAppRunnerSearchPaths(current.filter((item) => item !== searchPath), {
|
|
18721
|
+
successMessage: `Removed ${appRunnerSearchPathLabel(searchPath)}.`,
|
|
18722
|
+
eventMessage: `removed app runner discovery path ${searchPath}`,
|
|
18723
|
+
});
|
|
18724
|
+
if (!saved) return;
|
|
18725
|
+
offerUndo({
|
|
18726
|
+
message: `Removed project discovery path “${appRunnerSearchPathLabel(searchPath)}”.`,
|
|
18727
|
+
undo: async () => {
|
|
18728
|
+
const restored = await api("/api/app-runner-config", { method: "POST", body: { searchPaths: current }, tabId: tabContext.tabId });
|
|
18729
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
18730
|
+
setAppRunnerData(tabContext.tabId, restored.data || {});
|
|
18731
|
+
setAppRunnerSearchPathFeedback("success", `Restored ${appRunnerSearchPathLabel(searchPath)}.`);
|
|
18732
|
+
renderAppRunnerControls();
|
|
18733
|
+
renderWidgets();
|
|
18734
|
+
renderAppRunnerInfoDialog();
|
|
18735
|
+
},
|
|
18736
|
+
successMessage: `Restored project discovery path “${appRunnerSearchPathLabel(searchPath)}”.`,
|
|
18737
|
+
});
|
|
18738
|
+
}
|
|
18739
|
+
|
|
18740
|
+
async function loadAppRunnerDirectoryBrowser(relativePath = "") {
|
|
18741
|
+
const tabContext = activeTabContext();
|
|
18742
|
+
const path = String(relativePath || "").replace(/^\.\/+/, "").replace(/\/+$/g, "");
|
|
18743
|
+
appRunnerDirectoryBrowserState = { open: true, loading: true, path, data: null, error: "" };
|
|
18744
|
+
renderAppRunnerInfoDialog();
|
|
18745
|
+
try {
|
|
18746
|
+
const response = await api(`/api/app-runner-files?path=${encodeURIComponent(path)}`, { tabId: tabContext.tabId });
|
|
18747
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
18748
|
+
appRunnerDirectoryBrowserState = { open: true, loading: false, path, data: response.data || {}, error: "" };
|
|
18749
|
+
renderAppRunnerInfoDialog();
|
|
18750
|
+
} catch (error) {
|
|
18751
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
18752
|
+
appRunnerDirectoryBrowserState = { open: true, loading: false, path, data: null, error: error.message || String(error) };
|
|
18753
|
+
renderAppRunnerInfoDialog();
|
|
18754
|
+
}
|
|
18755
|
+
}
|
|
18756
|
+
|
|
18757
|
+
function chooseAppRunnerSearchPath(relativeDir) {
|
|
18758
|
+
const searchPath = normalizeAppRunnerSearchPathInput(relativeDir) || ".";
|
|
18759
|
+
appRunnerSearchPathDraft = searchPath;
|
|
18760
|
+
appRunnerDirectoryBrowserState = { open: false, loading: false, path: "", data: null, error: "" };
|
|
18761
|
+
setAppRunnerSearchPathFeedback("info", `Selected ${appRunnerSearchPathLabel(searchPath)}. Choose Add path to save it.`);
|
|
18762
|
+
renderAppRunnerInfoDialog();
|
|
18763
|
+
requestAnimationFrame(() => document.querySelector("#appRunnerSearchPathAddButton")?.focus());
|
|
18764
|
+
}
|
|
18765
|
+
|
|
18766
|
+
function renderAppRunnerDirectoryBrowser() {
|
|
18767
|
+
if (!appRunnerDirectoryBrowserState.open) return null;
|
|
18768
|
+
const browser = make("div", "app-runner-file-browser app-runner-directory-browser");
|
|
18769
|
+
if (appRunnerDirectoryBrowserState.loading) {
|
|
18770
|
+
browser.append(make("div", "muted", "Loading project directories…"));
|
|
18771
|
+
return browser;
|
|
18772
|
+
}
|
|
18773
|
+
if (appRunnerDirectoryBrowserState.error) {
|
|
18774
|
+
browser.append(make("div", "path-picker-error", appRunnerDirectoryBrowserState.error));
|
|
18775
|
+
return browser;
|
|
18776
|
+
}
|
|
18777
|
+
const data = appRunnerDirectoryBrowserState.data || {};
|
|
18778
|
+
const currentDir = normalizeAppRunnerSearchPathInput(data.relativeDir || "") || ".";
|
|
18779
|
+
const header = make("div", "app-runner-file-browser-header");
|
|
18780
|
+
header.append(make("strong", "", data.displayRelativeDir || "."));
|
|
18781
|
+
const headerActions = make("div", "app-runner-directory-browser-actions");
|
|
18782
|
+
const use = make("button", "app-runner-directory-use", "Use this directory");
|
|
18783
|
+
use.type = "button";
|
|
18784
|
+
use.title = `Use ${appRunnerSearchPathLabel(currentDir)} as a project discovery path`;
|
|
18785
|
+
use.addEventListener("click", () => chooseAppRunnerSearchPath(currentDir));
|
|
18786
|
+
const close = make("button", "app-runner-file-browser-close", "Hide browser");
|
|
18787
|
+
close.type = "button";
|
|
18788
|
+
close.addEventListener("click", () => {
|
|
18789
|
+
appRunnerDirectoryBrowserState = { open: false, loading: false, path: "", data: null, error: "" };
|
|
18790
|
+
renderAppRunnerInfoDialog();
|
|
18791
|
+
});
|
|
18792
|
+
headerActions.append(use, close);
|
|
18793
|
+
header.append(headerActions);
|
|
18794
|
+
browser.append(header);
|
|
18795
|
+
|
|
18796
|
+
const roots = make("div", "path-picker-roots app-runner-file-browser-roots");
|
|
18797
|
+
if (data.parent !== null && data.parent !== undefined) roots.append(pathPickerButton("↑ Parent", data.parent || ".", () => loadAppRunnerDirectoryBrowser(data.parent || ""), "path-picker-root-button"));
|
|
18798
|
+
roots.append(pathPickerButton("Project root", data.displayProjectRoot || "Project root", () => loadAppRunnerDirectoryBrowser(""), "path-picker-root-button"));
|
|
18799
|
+
browser.append(roots);
|
|
18800
|
+
|
|
18801
|
+
const list = make("div", "path-picker-list app-runner-file-browser-list");
|
|
18802
|
+
const directories = Array.isArray(data.directories) ? data.directories : [];
|
|
18803
|
+
for (const directory of directories) {
|
|
18804
|
+
const row = make("div", "app-runner-directory-row");
|
|
18805
|
+
row.append(pathPickerButton(`${directory.name}/`, directory.path, () => loadAppRunnerDirectoryBrowser(directory.path), `path-picker-directory${directory.hidden ? " hidden-directory" : ""}`));
|
|
18806
|
+
const choose = make("button", "app-runner-directory-choose", "Use");
|
|
18807
|
+
choose.type = "button";
|
|
18808
|
+
choose.title = `Use ${directory.path} as a project discovery path`;
|
|
18809
|
+
choose.setAttribute("aria-label", `Use ${directory.path} as a project discovery path`);
|
|
18810
|
+
choose.addEventListener("click", () => chooseAppRunnerSearchPath(directory.path));
|
|
18811
|
+
row.append(choose);
|
|
18812
|
+
list.append(row);
|
|
18813
|
+
}
|
|
18814
|
+
if (!directories.length) list.append(make("div", "path-picker-empty muted", "No subdirectories here. Use this directory to scan it directly."));
|
|
18815
|
+
browser.append(list);
|
|
18816
|
+
if (data.truncated) browser.append(make("div", "path-picker-error", "Showing the first project entries only."));
|
|
18817
|
+
return browser;
|
|
18818
|
+
}
|
|
18819
|
+
|
|
18820
|
+
function renderAppRunnerSearchPathSection() {
|
|
18821
|
+
const config = activeAppRunnerCustomConfig();
|
|
18822
|
+
const searchPaths = activeAppRunnerSearchPaths();
|
|
18823
|
+
const section = make("section", "app-runner-info-section app-runner-search-path-section");
|
|
18824
|
+
const titleRow = make("div", "app-runner-section-title-row");
|
|
18825
|
+
titleRow.append(make("h3", "", "Project discovery paths"));
|
|
18826
|
+
if (config.displayProjectRoot) titleRow.append(make("code", "", config.displayProjectRoot));
|
|
18827
|
+
section.append(titleRow);
|
|
18828
|
+
section.append(make("p", "muted", "Scan extra project directories for runnable shell and Python scripts. Paths are project-local, relative to the project root, saved in .pi-webui-runners.json, and scanned one level deep only (no subdirectories). Supported scripts are .sh, .bash, .zsh, .fish, and .py files plus extensionless files with a bash/sh, zsh, fish, or Python shebang. Python scripts use uv and/or python3/python when available, and all discovered scripts run from the project root."));
|
|
18829
|
+
|
|
18830
|
+
const list = make("div", "app-runner-custom-list app-runner-search-path-list");
|
|
18831
|
+
if (!searchPaths.length) {
|
|
18832
|
+
list.append(make("div", "app-runner-custom-empty muted", "No project discovery paths configured. Built-in root, dev/, scripts/, and dev/scripts/ detection still applies."));
|
|
18833
|
+
} else {
|
|
18834
|
+
for (const searchPath of searchPaths) {
|
|
18835
|
+
const row = make("div", "app-runner-custom-item app-runner-search-path-item");
|
|
18836
|
+
const details = make("div", "app-runner-custom-item-details");
|
|
18837
|
+
details.append(make("code", "", appRunnerSearchPathLabel(searchPath)));
|
|
18838
|
+
const diagnostic = (Array.isArray(config.diagnostics) ? config.diagnostics : []).find((item) => item?.message && item.path === searchPath);
|
|
18839
|
+
if (diagnostic) {
|
|
18840
|
+
row.classList.add("unavailable");
|
|
18841
|
+
details.append(make("span", "app-runner-custom-warning", diagnostic.message));
|
|
18842
|
+
}
|
|
18843
|
+
const actions = make("div", "app-runner-custom-item-actions");
|
|
18844
|
+
const remove = make("button", "danger", "Remove");
|
|
18845
|
+
remove.type = "button";
|
|
18846
|
+
remove.title = `Stop scanning ${appRunnerSearchPathLabel(searchPath)}`;
|
|
18847
|
+
remove.setAttribute("aria-label", `Remove project discovery path ${appRunnerSearchPathLabel(searchPath)}`);
|
|
18848
|
+
remove.addEventListener("click", () => removeAppRunnerSearchPath(searchPath));
|
|
18849
|
+
actions.append(remove);
|
|
18850
|
+
row.append(details, actions);
|
|
18851
|
+
list.append(row);
|
|
18852
|
+
}
|
|
18853
|
+
}
|
|
18854
|
+
section.append(list);
|
|
18855
|
+
|
|
18856
|
+
const form = make("div", "app-runner-custom-form app-runner-search-path-form");
|
|
18857
|
+
const field = make("label", "app-runner-custom-field");
|
|
18858
|
+
field.setAttribute("for", "appRunnerSearchPathInput");
|
|
18859
|
+
field.append(make("span", "", "Project-relative directory"));
|
|
18860
|
+
const input = make("input", "dialog-input");
|
|
18861
|
+
input.id = "appRunnerSearchPathInput";
|
|
18862
|
+
input.type = "text";
|
|
18863
|
+
input.value = appRunnerSearchPathDraft;
|
|
18864
|
+
input.placeholder = "tools";
|
|
18865
|
+
input.autocomplete = "off";
|
|
18866
|
+
input.spellcheck = false;
|
|
18867
|
+
input.setAttribute("aria-label", "Project-relative directory to scan for shell and Python scripts");
|
|
18868
|
+
field.append(input);
|
|
18869
|
+
field.append(make("small", "muted", `Use . for the project root. Up to ${APP_RUNNER_SEARCH_PATH_LIMIT} paths; absolute paths and .. segments are rejected.`));
|
|
18870
|
+
input.addEventListener("input", () => { appRunnerSearchPathDraft = input.value; });
|
|
18871
|
+
input.addEventListener("keydown", (event) => {
|
|
18872
|
+
if (event.key !== "Enter") return;
|
|
18873
|
+
event.preventDefault();
|
|
18874
|
+
addAppRunnerSearchPath(form);
|
|
18875
|
+
});
|
|
18876
|
+
const pathRow = make("div", "app-runner-custom-path-row");
|
|
18877
|
+
pathRow.append(field);
|
|
18878
|
+
const browse = make("button", "app-runner-custom-browse", "Browse…");
|
|
18879
|
+
browse.type = "button";
|
|
18880
|
+
browse.title = "Browse project directories";
|
|
18881
|
+
browse.addEventListener("click", () => loadAppRunnerDirectoryBrowser(normalizeAppRunnerSearchPathInput(appRunnerSearchPathDraft) === "." ? "" : normalizeAppRunnerSearchPathInput(appRunnerSearchPathDraft)));
|
|
18882
|
+
pathRow.append(browse);
|
|
18883
|
+
form.append(pathRow);
|
|
18884
|
+
|
|
18885
|
+
const formActions = make("div", "app-runner-custom-form-actions");
|
|
18886
|
+
const add = make("button", "primary", "Add path");
|
|
18887
|
+
add.id = "appRunnerSearchPathAddButton";
|
|
18888
|
+
add.type = "button";
|
|
18889
|
+
add.addEventListener("click", () => addAppRunnerSearchPath(form));
|
|
18890
|
+
const clear = make("button", "", "Reset");
|
|
18891
|
+
clear.type = "button";
|
|
18892
|
+
clear.addEventListener("click", () => {
|
|
18893
|
+
appRunnerSearchPathDraft = "";
|
|
18894
|
+
appRunnerDirectoryBrowserState = { open: false, loading: false, path: "", data: null, error: "" };
|
|
18895
|
+
setAppRunnerSearchPathFeedback("", "");
|
|
18896
|
+
renderAppRunnerInfoDialog();
|
|
18897
|
+
});
|
|
18898
|
+
formActions.append(add, clear);
|
|
18899
|
+
form.append(formActions);
|
|
18900
|
+
if (appRunnerSearchPathFeedback.message) form.append(make("div", `app-runner-custom-feedback ${appRunnerSearchPathFeedback.type || "info"}`, appRunnerSearchPathFeedback.message));
|
|
18901
|
+
const browser = renderAppRunnerDirectoryBrowser();
|
|
18902
|
+
if (browser) form.append(browser);
|
|
18903
|
+
section.append(form);
|
|
18904
|
+
return section;
|
|
18905
|
+
}
|
|
18906
|
+
|
|
18338
18907
|
async function loadAppRunnerFileBrowser(relativePath = "") {
|
|
18339
18908
|
const tabContext = activeTabContext();
|
|
18340
18909
|
const path = String(relativePath || "").replace(/^\.\/+/, "").replace(/\/+$/g, "");
|
|
@@ -18487,9 +19056,14 @@ function renderAppRunnerControls() {
|
|
|
18487
19056
|
const running = appRunnerIsRunning(activeRun);
|
|
18488
19057
|
menu.hidden = false;
|
|
18489
19058
|
menu.classList.toggle("has-runners", runners.length > 0);
|
|
19059
|
+
menu.classList.toggle("no-runners", runners.length === 0);
|
|
18490
19060
|
if (elements.appRunnerInfoButton) {
|
|
18491
|
-
elements.appRunnerInfoButton.hidden =
|
|
18492
|
-
elements.appRunnerInfoButton.disabled =
|
|
19061
|
+
elements.appRunnerInfoButton.hidden = false;
|
|
19062
|
+
elements.appRunnerInfoButton.disabled = false;
|
|
19063
|
+
elements.appRunnerInfoButton.title = runners.length
|
|
19064
|
+
? "Explain app runners and configure project discovery paths"
|
|
19065
|
+
: "No app runners detected: configure project discovery paths or custom runners";
|
|
19066
|
+
elements.appRunnerInfoButton.setAttribute("aria-label", elements.appRunnerInfoButton.title);
|
|
18493
19067
|
}
|
|
18494
19068
|
button.disabled = running;
|
|
18495
19069
|
button.title = running
|
|
@@ -18507,7 +19081,8 @@ function renderAppRunnerControls() {
|
|
|
18507
19081
|
item.type = "button";
|
|
18508
19082
|
item.setAttribute("role", "menuitem");
|
|
18509
19083
|
const runnerDisplayCommand = runner.shortDisplayCommand || runner.displayCommand;
|
|
18510
|
-
|
|
19084
|
+
const runnerSource = appRunnerSourceLabel(runner, runnerDisplayCommand);
|
|
19085
|
+
item.title = [runnerDisplayCommand, runnerSource, runner.description].filter(Boolean).join("\n");
|
|
18511
19086
|
item.addEventListener("click", () => runAppRunner(runner.id));
|
|
18512
19087
|
const label = make("span", "app-runner-menu-item-label", runner.label || runnerDisplayCommand);
|
|
18513
19088
|
const command = make("span", "app-runner-menu-item-command", runnerDisplayCommand);
|
|
@@ -18534,6 +19109,8 @@ function renderAppRunnerInfoDialog() {
|
|
|
18534
19109
|
make("strong", "", runner.label || command || "runner"),
|
|
18535
19110
|
make("code", "", command || "detected command"),
|
|
18536
19111
|
);
|
|
19112
|
+
const source = appRunnerSourceLabel(runner, command);
|
|
19113
|
+
if (source) item.append(make("span", "app-runner-info-source muted", source));
|
|
18537
19114
|
if (runner.description) item.append(make("span", "", runner.description));
|
|
18538
19115
|
list.append(item);
|
|
18539
19116
|
}
|
|
@@ -18551,6 +19128,7 @@ function renderAppRunnerInfoDialog() {
|
|
|
18551
19128
|
"Starting a runner keeps live output pinned above the chat/terminal area.",
|
|
18552
19129
|
"While a runner is active, the widget can send line-oriented stdin to interactive scripts.",
|
|
18553
19130
|
"Only one app runner can be active per tab; Close/Stop terminates the process/server.",
|
|
19131
|
+
"Project discovery paths are project-local, relative to the project root, and scanned one level deep only.",
|
|
18554
19132
|
]) howList.append(make("li", "", line));
|
|
18555
19133
|
how.append(howList);
|
|
18556
19134
|
|
|
@@ -18560,7 +19138,7 @@ function renderAppRunnerInfoDialog() {
|
|
|
18560
19138
|
for (const itemText of APP_RUNNER_SUPPORTED_ITEMS) supportedList.append(make("li", "", itemText));
|
|
18561
19139
|
supported.append(supportedList);
|
|
18562
19140
|
|
|
18563
|
-
body.append(current, renderAppRunnerCustomSection(), how, supported);
|
|
19141
|
+
body.append(current, renderAppRunnerSearchPathSection(), renderAppRunnerCustomSection(), how, supported);
|
|
18564
19142
|
}
|
|
18565
19143
|
|
|
18566
19144
|
function openAppRunnerInfoDialog() {
|
|
@@ -18588,6 +19166,7 @@ function renderAppRunnerInputForm(run) {
|
|
|
18588
19166
|
input.setAttribute("aria-label", "Send input to app runner stdin");
|
|
18589
19167
|
input.addEventListener("input", () => { appRunnerInputDraftByRun.set(key, input.value); });
|
|
18590
19168
|
input.addEventListener("keydown", (event) => {
|
|
19169
|
+
if (insertNumpadDecimal(event)) return;
|
|
18591
19170
|
if (event.key !== "Enter" || event.shiftKey) return;
|
|
18592
19171
|
event.preventDefault();
|
|
18593
19172
|
form.requestSubmit();
|
|
@@ -19798,6 +20377,7 @@ function renderWidgets() {
|
|
|
19798
20377
|
for (const [key, value] of widgets) {
|
|
19799
20378
|
const widgetFeatureId = optionalFeatureWidgetFeatureId(key);
|
|
19800
20379
|
if (widgetFeatureId && !isOptionalFeatureEnabled(widgetFeatureId)) continue;
|
|
20380
|
+
if (widgetFeatureId === "workflows" && workflowOverlayIsMinimized()) continue;
|
|
19801
20381
|
if (widgetFeatureId && optionalFeatureWidgetHasSpecializedRenderer(key)) continue;
|
|
19802
20382
|
const lines = Array.isArray(value.widgetLines) ? value.widgetLines : [];
|
|
19803
20383
|
if (key === "pi-remote-webui") continue;
|
|
@@ -24430,13 +25010,64 @@ const WEBUI_TOOL_RENDERERS = {
|
|
|
24430
25010
|
ls: renderLsToolExecution,
|
|
24431
25011
|
};
|
|
24432
25012
|
|
|
24433
|
-
function
|
|
25013
|
+
function renderSingleToolExecution(parent, message) {
|
|
24434
25014
|
const tool = normalizeToolExecution(message);
|
|
24435
25015
|
const renderer = WEBUI_TOOL_RENDERERS[tool.name] || renderGenericToolExecution;
|
|
24436
25016
|
renderer(parent, tool);
|
|
24437
25017
|
appendToolRawDetails(parent, tool);
|
|
24438
25018
|
}
|
|
24439
25019
|
|
|
25020
|
+
function renderWorkflowStatusStack(parent, message) {
|
|
25021
|
+
const updates = Array.isArray(message?.workflowStatusUpdates) ? message.workflowStatusUpdates : [];
|
|
25022
|
+
const latest = updates.at(-1);
|
|
25023
|
+
if (!latest) return;
|
|
25024
|
+
const snapshot = workflowStatusSnapshot(toolResultText(toolExecutionResult(latest)));
|
|
25025
|
+
const hasStructuredSnapshot = snapshot.workflow || snapshot.run || snapshot.status || snapshot.tasks;
|
|
25026
|
+
const countLabel = `${updates.length} update${updates.length === 1 ? "" : "s"}`;
|
|
25027
|
+
const snapshotFields = [["Workflow", snapshot.workflow], ["Run", snapshot.run], ["Status", snapshot.status], ["Tasks", snapshot.tasks]];
|
|
25028
|
+
const latestLabel = hasStructuredSnapshot
|
|
25029
|
+
? `latest ${snapshotFields.filter(([, value]) => value).map(([label, value]) => `${label} ${value}`).join(", ")}`
|
|
25030
|
+
: `latest ${snapshot.fallback}`;
|
|
25031
|
+
|
|
25032
|
+
const details = make("details", "workflow-status-stack-details");
|
|
25033
|
+
details.open = !!message.isError;
|
|
25034
|
+
const summary = make("summary", "workflow-status-stack-summary");
|
|
25035
|
+
summary.setAttribute("aria-label", `Workflow status updates, ${countLabel}; ${latestLabel}${message.isError ? "; contains an error" : ""}`);
|
|
25036
|
+
const heading = make("span", "workflow-status-stack-heading");
|
|
25037
|
+
heading.append(make("span", "tool-name", "workflow_status"), make("span", "workflow-status-stack-count", countLabel));
|
|
25038
|
+
if (message.isError) heading.append(make("span", "workflow-status-stack-error", "contains error"));
|
|
25039
|
+
const snapshotLine = make("span", "workflow-status-stack-snapshot");
|
|
25040
|
+
if (hasStructuredSnapshot) {
|
|
25041
|
+
for (const [label, value] of snapshotFields) {
|
|
25042
|
+
if (value) snapshotLine.append(make("span", "workflow-status-stack-field", `${label}: ${value}`));
|
|
25043
|
+
}
|
|
25044
|
+
} else {
|
|
25045
|
+
snapshotLine.append(make("span", "workflow-status-stack-field", snapshot.fallback));
|
|
25046
|
+
}
|
|
25047
|
+
summary.append(heading, snapshotLine);
|
|
25048
|
+
|
|
25049
|
+
const members = make("div", "workflow-status-stack-members");
|
|
25050
|
+
updates.forEach((update, index) => {
|
|
25051
|
+
const member = make("section", `workflow-status-stack-member${update?.isError || update?.result?.isError ? " error" : ""}`);
|
|
25052
|
+
const memberTitleText = [`Update ${index + 1} of ${updates.length}`, formatDate(update?.timestamp), toolExecutionStatus(update)].filter(Boolean).join(" · ");
|
|
25053
|
+
const memberTitle = make("div", "workflow-status-stack-member-title", memberTitleText);
|
|
25054
|
+
const memberBody = make("div", "workflow-status-stack-member-body");
|
|
25055
|
+
renderSingleToolExecution(memberBody, update);
|
|
25056
|
+
member.append(memberTitle, memberBody);
|
|
25057
|
+
members.append(member);
|
|
25058
|
+
});
|
|
25059
|
+
details.append(summary, members);
|
|
25060
|
+
parent.append(details);
|
|
25061
|
+
}
|
|
25062
|
+
|
|
25063
|
+
function renderToolExecution(parent, message) {
|
|
25064
|
+
if (message?.role === "workflowStatusStack") {
|
|
25065
|
+
renderWorkflowStatusStack(parent, message);
|
|
25066
|
+
return;
|
|
25067
|
+
}
|
|
25068
|
+
renderSingleToolExecution(parent, message);
|
|
25069
|
+
}
|
|
25070
|
+
|
|
24440
25071
|
function liveToolRunMessage(run) {
|
|
24441
25072
|
return {
|
|
24442
25073
|
role: "toolExecution",
|
|
@@ -24745,6 +25376,9 @@ function createMessageBubble(message, { streaming = false, messageIndex = -1, tr
|
|
|
24745
25376
|
} else if (message.role === "toolExecution") {
|
|
24746
25377
|
renderToolExecution(body, message);
|
|
24747
25378
|
bubble._toolRenderSignature = toolExecutionRenderSignature(message);
|
|
25379
|
+
} else if (message.role === "workflowStatusStack") {
|
|
25380
|
+
renderToolExecution(body, message);
|
|
25381
|
+
if (message.isError) bubble.classList.add("error");
|
|
24748
25382
|
} else if (message.role === "thinking") {
|
|
24749
25383
|
const thinkingText = visibleThinkingText(message.thinking || textFromContent(message.content));
|
|
24750
25384
|
if (thinkingOutputVisible && thinkingText) appendThinkingMarkdown(body, thinkingText);
|
|
@@ -24775,7 +25409,7 @@ function createMessageBubble(message, { streaming = false, messageIndex = -1, tr
|
|
|
24775
25409
|
} else {
|
|
24776
25410
|
bubble.append(header, body);
|
|
24777
25411
|
}
|
|
24778
|
-
attachMessageCopyButton(bubble, message, body);
|
|
25412
|
+
if (message.role !== "workflowStatusStack") attachMessageCopyButton(bubble, message, body);
|
|
24779
25413
|
attachMessageEditRetryButton(bubble, message, messageIndex, { streaming, transient });
|
|
24780
25414
|
if (!streaming && !transient) renderActionFeedbackControls(bubble, message, messageIndex);
|
|
24781
25415
|
return { bubble, body };
|
|
@@ -24799,6 +25433,27 @@ function appendMessage(message, options = {}) {
|
|
|
24799
25433
|
return created;
|
|
24800
25434
|
}
|
|
24801
25435
|
|
|
25436
|
+
function appendOptimisticUserPrompt(message, attachmentCount = 0) {
|
|
25437
|
+
const text = String(message || "").trim() || `${attachmentCount} attachment${attachmentCount === 1 ? "" : "s"}`;
|
|
25438
|
+
appendMessage({ role: "user", title: "you", timestamp: Date.now(), content: text }, { transient: true, animateEntry: true });
|
|
25439
|
+
if (autoFollowChat || isChatNearBottom()) scrollChatToBottom({ force: true });
|
|
25440
|
+
}
|
|
25441
|
+
|
|
25442
|
+
function toolExecutionMessageFromCall(displayMessage, { result = toolResultForCallId(displayMessage?.toolCallId), liveRun = liveToolRuns.get(displayMessage?.toolCallId) } = {}) {
|
|
25443
|
+
return {
|
|
25444
|
+
...displayMessage,
|
|
25445
|
+
role: "toolExecution",
|
|
25446
|
+
title: `tool: ${displayMessage?.toolName || "unknown"}`,
|
|
25447
|
+
arguments: liveRun?.arguments ?? displayMessage?.arguments,
|
|
25448
|
+
result: result || liveRun?.result || null,
|
|
25449
|
+
isPartial: !result && !!liveRun?.isPartial,
|
|
25450
|
+
isError: !!(result?.isError || liveRun?.isError),
|
|
25451
|
+
startedAt: liveRun?.startedAt || null,
|
|
25452
|
+
endedAt: liveRun?.endedAt || null,
|
|
25453
|
+
live: !!liveRun && !result,
|
|
25454
|
+
};
|
|
25455
|
+
}
|
|
25456
|
+
|
|
24802
25457
|
function appendTranscriptMessage(message, { streaming = false, messageIndex = -1, transient = false, animateEntry = false, reusableToolCards = null, itemKey = "" } = {}) {
|
|
24803
25458
|
if (streaming || transient || message?.role !== "assistant") {
|
|
24804
25459
|
return appendMessage(message, { streaming, messageIndex, transient, animateEntry, reusableToolCards, itemKey });
|
|
@@ -24810,20 +25465,7 @@ function appendTranscriptMessage(message, { streaming = false, messageIndex = -1
|
|
|
24810
25465
|
displayMessages.forEach((displayMessage) => {
|
|
24811
25466
|
let transcriptMessage = displayMessage;
|
|
24812
25467
|
if (displayMessage.role === "toolCall" && displayMessage.toolCallId) {
|
|
24813
|
-
|
|
24814
|
-
const liveRun = liveToolRuns.get(displayMessage.toolCallId);
|
|
24815
|
-
transcriptMessage = {
|
|
24816
|
-
...displayMessage,
|
|
24817
|
-
role: "toolExecution",
|
|
24818
|
-
title: `tool: ${displayMessage.toolName || "unknown"}`,
|
|
24819
|
-
arguments: liveRun?.arguments ?? displayMessage.arguments,
|
|
24820
|
-
result: result || liveRun?.result || null,
|
|
24821
|
-
isPartial: !result && !!liveRun?.isPartial,
|
|
24822
|
-
isError: !!(result?.isError || liveRun?.isError),
|
|
24823
|
-
startedAt: liveRun?.startedAt || null,
|
|
24824
|
-
endedAt: liveRun?.endedAt || null,
|
|
24825
|
-
live: !!liveRun && !result,
|
|
24826
|
-
};
|
|
25468
|
+
transcriptMessage = toolExecutionMessageFromCall(displayMessage);
|
|
24827
25469
|
}
|
|
24828
25470
|
if (compactTranscript && transcriptMessage.role !== "assistant") return;
|
|
24829
25471
|
if (transcriptMessage.role === "thinking" && !thinkingOutputVisible) return;
|
|
@@ -25175,6 +25817,29 @@ function compactStoredTranscriptItems() {
|
|
|
25175
25817
|
return items;
|
|
25176
25818
|
}
|
|
25177
25819
|
|
|
25820
|
+
function workflowStatusExecutionFromTranscriptItem(item, toolResults) {
|
|
25821
|
+
const message = item?.message;
|
|
25822
|
+
if (isCompletedWorkflowStatusExecution(message)) return message;
|
|
25823
|
+
if (message?.role !== "assistant") return null;
|
|
25824
|
+
const visibleMessages = assistantDisplayMessages(message)
|
|
25825
|
+
.filter((displayMessage) => displayMessage.role !== "thinking" || thinkingOutputVisible);
|
|
25826
|
+
if (visibleMessages.length !== 1) return null;
|
|
25827
|
+
const toolCall = visibleMessages[0];
|
|
25828
|
+
if (toolCall.role !== "toolCall" || toolCall.toolName !== "workflow_status" || !toolCall.toolCallId) return null;
|
|
25829
|
+
const result = toolResults instanceof Map ? toolResults.get(toolCall.toolCallId) : toolResultForCallId(toolCall.toolCallId);
|
|
25830
|
+
if (!result) return null;
|
|
25831
|
+
return toolExecutionMessageFromCall(toolCall, { result, liveRun: liveToolRuns.get(toolCall.toolCallId) });
|
|
25832
|
+
}
|
|
25833
|
+
|
|
25834
|
+
function groupWorkflowStatusTranscriptItems(items, toolResults) {
|
|
25835
|
+
if (compactOutputActive()) return items;
|
|
25836
|
+
const projected = items.map((item) => {
|
|
25837
|
+
const execution = workflowStatusExecutionFromTranscriptItem(item, toolResults);
|
|
25838
|
+
return execution ? { ...item, message: execution } : item;
|
|
25839
|
+
});
|
|
25840
|
+
return groupConsecutiveWorkflowStatusItems(projected);
|
|
25841
|
+
}
|
|
25842
|
+
|
|
25178
25843
|
function orderedTranscriptItems() {
|
|
25179
25844
|
const items = compactOutputActive() ? compactStoredTranscriptItems() : [];
|
|
25180
25845
|
const assistantToolCallIds = buildAssistantToolCallIdSet(latestMessages);
|
|
@@ -25195,7 +25860,8 @@ function orderedTranscriptItems() {
|
|
|
25195
25860
|
items.push({ message, messageIndex: -1, transient: true, timestampMs: messageTimestampMs(message), order: liveOrder++ });
|
|
25196
25861
|
}
|
|
25197
25862
|
}
|
|
25198
|
-
|
|
25863
|
+
const ordered = items.sort((a, b) => a.timestampMs - b.timestampMs || a.order - b.order);
|
|
25864
|
+
return groupWorkflowStatusTranscriptItems(ordered, toolResults);
|
|
25199
25865
|
}
|
|
25200
25866
|
|
|
25201
25867
|
/**
|
|
@@ -25299,6 +25965,8 @@ function messageStaticSignature(message) {
|
|
|
25299
25965
|
contentSignature(message.result?.content),
|
|
25300
25966
|
String(safeJsonLength(message.arguments)),
|
|
25301
25967
|
);
|
|
25968
|
+
} else if (message.role === "workflowStatusStack") {
|
|
25969
|
+
for (const update of message.workflowStatusUpdates || []) sig.push(messageStaticSignature(update));
|
|
25302
25970
|
}
|
|
25303
25971
|
const joined = sig.join("|");
|
|
25304
25972
|
if (cacheable) messageStaticSignatureCache.set(message, joined);
|
|
@@ -26209,6 +26877,16 @@ function renderOptionalFeatureControls() {
|
|
|
26209
26877
|
);
|
|
26210
26878
|
if (!hasNativeCommandMenu && nativeCommandMenuOpen) setNativeCommandMenuOpen(false);
|
|
26211
26879
|
|
|
26880
|
+
const hasWorkflowSetup = isOptionalFeatureEnabled("workflows") && hasLoadedRpcCommand("workflow-setup");
|
|
26881
|
+
if (elements.optionsWorkflowSetupButton) {
|
|
26882
|
+
elements.optionsWorkflowSetupButton.hidden = !hasWorkflowSetup;
|
|
26883
|
+
setOptionalControlState(
|
|
26884
|
+
elements.optionsWorkflowSetupButton,
|
|
26885
|
+
hasWorkflowSetup,
|
|
26886
|
+
commandUnavailableMessage("workflow-setup"),
|
|
26887
|
+
);
|
|
26888
|
+
}
|
|
26889
|
+
|
|
26212
26890
|
const hasSafetyGuardSetup = isOptionalFeatureEnabled("safetyGuard") && hasAvailableCommand("safety-guard-setup");
|
|
26213
26891
|
if (elements.optionsSafetyGuardSetupButton) {
|
|
26214
26892
|
elements.optionsSafetyGuardSetupButton.hidden = !hasSafetyGuardSetup;
|
|
@@ -26971,7 +27649,7 @@ async function openNativeSettingsDialog() {
|
|
|
26971
27649
|
autoCompact: state.autoCompactionEnabled !== false,
|
|
26972
27650
|
steering: state.steeringMode || "one-at-a-time",
|
|
26973
27651
|
followUp: state.followUpMode || "one-at-a-time",
|
|
26974
|
-
busyBehavior,
|
|
27652
|
+
busyBehavior: busyPromptBehavior,
|
|
26975
27653
|
density: interfaceDensity,
|
|
26976
27654
|
doneNotifications: agentDoneNotificationsEnabled,
|
|
26977
27655
|
});
|
|
@@ -27334,6 +28012,331 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
|
|
|
27334
28012
|
}, "primary");
|
|
27335
28013
|
}
|
|
27336
28014
|
|
|
28015
|
+
function normalizedWorkflowPolicyList(value) {
|
|
28016
|
+
return [...new Set(String(value || "").split("\n").map((entry) => entry.trim()).filter(Boolean))].sort();
|
|
28017
|
+
}
|
|
28018
|
+
|
|
28019
|
+
function parseWorkflowPolicyVerificationCommands(value) {
|
|
28020
|
+
const commands = [];
|
|
28021
|
+
for (const [index, line] of String(value || "").split("\n").entries()) {
|
|
28022
|
+
if (!line.trim()) continue;
|
|
28023
|
+
let command;
|
|
28024
|
+
try {
|
|
28025
|
+
command = JSON.parse(line);
|
|
28026
|
+
} catch (error) {
|
|
28027
|
+
throw new Error(`Verification command line ${index + 1} is not valid JSON: ${error.message || String(error)}`);
|
|
28028
|
+
}
|
|
28029
|
+
if (!Array.isArray(command) || command.length === 0 || command.some((part) => typeof part !== "string" || part.length === 0)) {
|
|
28030
|
+
throw new Error(`Verification command line ${index + 1} must be a non-empty JSON string argv array.`);
|
|
28031
|
+
}
|
|
28032
|
+
commands.push(command);
|
|
28033
|
+
}
|
|
28034
|
+
return commands;
|
|
28035
|
+
}
|
|
28036
|
+
|
|
28037
|
+
function normalizeWorkflowPolicySuggestions(value) {
|
|
28038
|
+
const empty = { shellAllowlist: [], networkAllowlist: [], verificationCommands: [] };
|
|
28039
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return empty;
|
|
28040
|
+
|
|
28041
|
+
const normalizeStringGroup = (group) => {
|
|
28042
|
+
if (!Array.isArray(group) || group.some((item) => (
|
|
28043
|
+
typeof item !== "string"
|
|
28044
|
+
|| !item
|
|
28045
|
+
|| item.trim() !== item
|
|
28046
|
+
|| item.includes("\n")
|
|
28047
|
+
|| item.includes("\r")
|
|
28048
|
+
))) return [];
|
|
28049
|
+
return [...new Set(group)];
|
|
28050
|
+
};
|
|
28051
|
+
const normalizeVerificationGroup = (group) => {
|
|
28052
|
+
if (!Array.isArray(group) || group.some((command) => (
|
|
28053
|
+
!Array.isArray(command)
|
|
28054
|
+
|| command.length === 0
|
|
28055
|
+
|| command.some((part) => typeof part !== "string" || part.length === 0)
|
|
28056
|
+
))) return [];
|
|
28057
|
+
return [...new Set(group.map((command) => JSON.stringify(command)))];
|
|
28058
|
+
};
|
|
28059
|
+
|
|
28060
|
+
return {
|
|
28061
|
+
shellAllowlist: normalizeStringGroup(value.shellAllowlist),
|
|
28062
|
+
networkAllowlist: normalizeStringGroup(value.networkAllowlist),
|
|
28063
|
+
verificationCommands: normalizeVerificationGroup(value.verificationCommands),
|
|
28064
|
+
};
|
|
28065
|
+
}
|
|
28066
|
+
|
|
28067
|
+
function workflowPolicyPresentSuggestionLines(textarea, kind) {
|
|
28068
|
+
if (kind !== "verification") return new Set(normalizedWorkflowPolicyList(textarea.value));
|
|
28069
|
+
const present = new Set();
|
|
28070
|
+
for (const line of String(textarea.value || "").split("\n")) {
|
|
28071
|
+
if (!line.trim()) continue;
|
|
28072
|
+
try {
|
|
28073
|
+
const command = JSON.parse(line);
|
|
28074
|
+
if (Array.isArray(command) && command.length > 0 && command.every((part) => typeof part === "string" && part.length > 0)) {
|
|
28075
|
+
present.add(JSON.stringify(command));
|
|
28076
|
+
}
|
|
28077
|
+
} catch {
|
|
28078
|
+
// Invalid manual lines remain editable and are reported by the normalized preview.
|
|
28079
|
+
}
|
|
28080
|
+
}
|
|
28081
|
+
return present;
|
|
28082
|
+
}
|
|
28083
|
+
|
|
28084
|
+
function appendWorkflowPolicySuggestion(textarea, line) {
|
|
28085
|
+
const separator = textarea.value && !textarea.value.endsWith("\n") ? "\n" : "";
|
|
28086
|
+
textarea.value = `${textarea.value}${separator}${line}`;
|
|
28087
|
+
textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
28088
|
+
textarea.focus();
|
|
28089
|
+
}
|
|
28090
|
+
|
|
28091
|
+
function workflowPolicySuggestionGroup(label, textarea, suggestions, kind, id) {
|
|
28092
|
+
if (!suggestions.length) return null;
|
|
28093
|
+
const group = make("div", "workflow-policy-suggestions");
|
|
28094
|
+
group.setAttribute("role", "group");
|
|
28095
|
+
const labelNode = make("span", "workflow-policy-suggestions-label", label);
|
|
28096
|
+
labelNode.id = `${id}SuggestionsLabel`;
|
|
28097
|
+
group.setAttribute("aria-labelledby", labelNode.id);
|
|
28098
|
+
group.append(labelNode);
|
|
28099
|
+
|
|
28100
|
+
const buttons = suggestions.map((line) => {
|
|
28101
|
+
const button = make("button", "workflow-policy-suggestion", `Add ${line}`);
|
|
28102
|
+
button.type = "button";
|
|
28103
|
+
button.setAttribute("aria-label", `${label}: add ${line}`);
|
|
28104
|
+
button.addEventListener("click", () => appendWorkflowPolicySuggestion(textarea, line));
|
|
28105
|
+
group.append(button);
|
|
28106
|
+
return { button, line };
|
|
28107
|
+
});
|
|
28108
|
+
const sync = () => {
|
|
28109
|
+
const present = workflowPolicyPresentSuggestionLines(textarea, kind);
|
|
28110
|
+
for (const { button, line } of buttons) button.disabled = present.has(line);
|
|
28111
|
+
};
|
|
28112
|
+
textarea.addEventListener("input", sync);
|
|
28113
|
+
sync();
|
|
28114
|
+
return { element: group, sync };
|
|
28115
|
+
}
|
|
28116
|
+
|
|
28117
|
+
function workflowPolicyTextarea(label, value, hint, id, { suggestions = [], suggestionLabel = "Suggestions", kind = "list" } = {}) {
|
|
28118
|
+
const field = make("div", "native-settings-field workflow-policy-field");
|
|
28119
|
+
const labelNode = make("label", "native-settings-label", label);
|
|
28120
|
+
labelNode.htmlFor = id;
|
|
28121
|
+
field.append(labelNode);
|
|
28122
|
+
const textarea = make("textarea", "workflow-policy-textarea");
|
|
28123
|
+
textarea.id = id;
|
|
28124
|
+
textarea.value = value;
|
|
28125
|
+
textarea.rows = 5;
|
|
28126
|
+
textarea.autocomplete = "off";
|
|
28127
|
+
textarea.spellcheck = false;
|
|
28128
|
+
const hintNode = make("span", "native-settings-hint", hint);
|
|
28129
|
+
hintNode.id = `${id}Hint`;
|
|
28130
|
+
textarea.setAttribute("aria-describedby", hintNode.id);
|
|
28131
|
+
const suggestionGroup = workflowPolicySuggestionGroup(suggestionLabel, textarea, suggestions, kind, id);
|
|
28132
|
+
field.append(textarea);
|
|
28133
|
+
if (suggestionGroup) field.append(suggestionGroup.element);
|
|
28134
|
+
field.append(hintNode);
|
|
28135
|
+
return { field, textarea, syncSuggestions: suggestionGroup?.sync || (() => {}) };
|
|
28136
|
+
}
|
|
28137
|
+
|
|
28138
|
+
function workflowPolicyDraftSignature(controls) {
|
|
28139
|
+
return JSON.stringify({
|
|
28140
|
+
permissions: {
|
|
28141
|
+
write: controls.write.input.checked,
|
|
28142
|
+
shell: controls.shell.input.checked,
|
|
28143
|
+
network: controls.network.input.checked,
|
|
28144
|
+
},
|
|
28145
|
+
shellAllowlist: controls.shellAllowlist.textarea.value,
|
|
28146
|
+
networkAllowlist: controls.networkAllowlist.textarea.value,
|
|
28147
|
+
verificationCommands: controls.verificationCommands.textarea.value,
|
|
28148
|
+
});
|
|
28149
|
+
}
|
|
28150
|
+
|
|
28151
|
+
function collectWorkflowPolicyFromControls(controls) {
|
|
28152
|
+
return {
|
|
28153
|
+
schemaVersion: 1,
|
|
28154
|
+
permissions: {
|
|
28155
|
+
write: controls.write.input.checked,
|
|
28156
|
+
shell: controls.shell.input.checked,
|
|
28157
|
+
network: controls.network.input.checked,
|
|
28158
|
+
},
|
|
28159
|
+
shellAllowlist: normalizedWorkflowPolicyList(controls.shellAllowlist.textarea.value),
|
|
28160
|
+
networkAllowlist: normalizedWorkflowPolicyList(controls.networkAllowlist.textarea.value),
|
|
28161
|
+
verificationCommands: parseWorkflowPolicyVerificationCommands(controls.verificationCommands.textarea.value),
|
|
28162
|
+
};
|
|
28163
|
+
}
|
|
28164
|
+
|
|
28165
|
+
function applyDeniedWorkflowPolicyControls(controls) {
|
|
28166
|
+
controls.write.input.checked = false;
|
|
28167
|
+
controls.shell.input.checked = false;
|
|
28168
|
+
controls.network.input.checked = false;
|
|
28169
|
+
controls.shellAllowlist.textarea.value = "";
|
|
28170
|
+
controls.networkAllowlist.textarea.value = "";
|
|
28171
|
+
controls.verificationCommands.textarea.value = "";
|
|
28172
|
+
}
|
|
28173
|
+
|
|
28174
|
+
async function openNativeWorkflowSetupDialog() {
|
|
28175
|
+
openNativeCommandDialog({
|
|
28176
|
+
title: "/workflow-setup",
|
|
28177
|
+
message: "Review and save the global workflow permission ceiling. This browser flow never starts an agent turn.",
|
|
28178
|
+
});
|
|
28179
|
+
renderNativeLoading("Loading workflow permission ceiling…");
|
|
28180
|
+
|
|
28181
|
+
let data;
|
|
28182
|
+
try {
|
|
28183
|
+
const response = await api("/api/workflow-policy", { scoped: false });
|
|
28184
|
+
data = response.data || {};
|
|
28185
|
+
} catch (error) {
|
|
28186
|
+
setNativeCommandError(`Could not load workflow policy: ${error.message || String(error)}`);
|
|
28187
|
+
elements.nativeCommandBody.replaceChildren();
|
|
28188
|
+
return;
|
|
28189
|
+
}
|
|
28190
|
+
|
|
28191
|
+
const deniedPolicy = {
|
|
28192
|
+
schemaVersion: 1,
|
|
28193
|
+
permissions: { write: false, shell: false, network: false },
|
|
28194
|
+
shellAllowlist: [],
|
|
28195
|
+
networkAllowlist: [],
|
|
28196
|
+
verificationCommands: [],
|
|
28197
|
+
};
|
|
28198
|
+
const policy = data.policy || deniedPolicy;
|
|
28199
|
+
const suggestions = normalizeWorkflowPolicySuggestions(data.suggestions);
|
|
28200
|
+
const controls = {
|
|
28201
|
+
write: nativeSettingToggle("Allow write", policy.permissions?.write === true, "Ceiling for workflow write capability; each workflow still has to request it.", { label: "global", tone: "safety" }),
|
|
28202
|
+
shell: nativeSettingToggle("Allow shell", policy.permissions?.shell === true, "Ceiling for workflow shell capability; the executable allowlist is not a sandbox.", { label: "global", tone: "safety" }),
|
|
28203
|
+
network: nativeSettingToggle("Allow network", policy.permissions?.network === true, "Ceiling for workflow network capability; each workflow still has to request it.", { label: "global", tone: "safety" }),
|
|
28204
|
+
shellAllowlist: workflowPolicyTextarea(
|
|
28205
|
+
"Shell executable allowlist",
|
|
28206
|
+
Array.isArray(policy.shellAllowlist) ? policy.shellAllowlist.join("\n") : "",
|
|
28207
|
+
"One executable entry per line. Entries are trimmed, deduplicated, and sorted in the preview. This is not an OS sandbox.",
|
|
28208
|
+
"workflowPolicyShellAllowlist",
|
|
28209
|
+
{ suggestions: suggestions.shellAllowlist, suggestionLabel: "Shell executable suggestions" },
|
|
28210
|
+
),
|
|
28211
|
+
networkAllowlist: workflowPolicyTextarea(
|
|
28212
|
+
"Network host allowlist",
|
|
28213
|
+
Array.isArray(policy.networkAllowlist) ? policy.networkAllowlist.join("\n") : "",
|
|
28214
|
+
"One host entry per line. Entries are trimmed, deduplicated, and sorted in the preview.",
|
|
28215
|
+
"workflowPolicyNetworkAllowlist",
|
|
28216
|
+
{ suggestions: suggestions.networkAllowlist, suggestionLabel: "Network host suggestions" },
|
|
28217
|
+
),
|
|
28218
|
+
verificationCommands: workflowPolicyTextarea(
|
|
28219
|
+
"Verification commands",
|
|
28220
|
+
Array.isArray(policy.verificationCommands) ? policy.verificationCommands.map((command) => JSON.stringify(command)).join("\n") : "",
|
|
28221
|
+
'One JSON argv array per line, in execution order; for example ["npm","test"]. Blank lines are ignored.',
|
|
28222
|
+
"workflowPolicyVerificationCommands",
|
|
28223
|
+
{ suggestions: suggestions.verificationCommands, suggestionLabel: "Verification command suggestions", kind: "verification" },
|
|
28224
|
+
),
|
|
28225
|
+
};
|
|
28226
|
+
|
|
28227
|
+
const preview = make("pre", "workflow-policy-preview");
|
|
28228
|
+
preview.tabIndex = 0;
|
|
28229
|
+
preview.setAttribute("aria-label", "Exact normalized workflow policy JSON preview");
|
|
28230
|
+
const verificationStatus = make("p", "workflow-policy-verification-status muted");
|
|
28231
|
+
verificationStatus.setAttribute("role", "status");
|
|
28232
|
+
verificationStatus.setAttribute("aria-live", "polite");
|
|
28233
|
+
const previewSection = make("section", "workflow-policy-review");
|
|
28234
|
+
previewSection.append(make("h3", undefined, "Exact normalized JSON preview"), preview, verificationStatus);
|
|
28235
|
+
|
|
28236
|
+
const body = make("div", "native-settings-panel workflow-policy-panel");
|
|
28237
|
+
body.append(
|
|
28238
|
+
nativeSettingsNote("Authorization ceiling", "This ceiling is not blanket authority. Every workflow and agent call must still request its own capabilities, and all runtime restrictions still apply."),
|
|
28239
|
+
nativeSettingsNote("Shell safety", "The shell executable allowlist limits admitted commands only; it is not an OS sandbox."),
|
|
28240
|
+
nativeSettingsNote("Persistence", `${data.exists ? "Loaded" : "No file exists yet; Save is required to create"} ${data.filePath || "~/.pi/agent/workflow-policy.json"}. Browser data cannot choose another target.`),
|
|
28241
|
+
nativeSettingsSection("Permission toggles", "Lists may stay populated while a permission is off, but runtime authority remains off.", [controls.write, controls.shell, controls.network], { open: true }),
|
|
28242
|
+
nativeSettingsSection("Shell and network allowlists", "Enter one canonicalizable value per line.", [controls.shellAllowlist, controls.networkAllowlist], { open: true }),
|
|
28243
|
+
nativeSettingsSection("Ordered verification", "Each nonblank line is one JSON argv array. Line order is preserved.", [controls.verificationCommands], { open: true }),
|
|
28244
|
+
previewSection,
|
|
28245
|
+
);
|
|
28246
|
+
elements.nativeCommandBody.replaceChildren(body);
|
|
28247
|
+
elements.nativeCommandActions.replaceChildren();
|
|
28248
|
+
addNativeCommandAction("Cancel", closeNativeCommandDialog);
|
|
28249
|
+
|
|
28250
|
+
const initialDraftSignature = workflowPolicyDraftSignature(controls);
|
|
28251
|
+
let candidatePolicy = null;
|
|
28252
|
+
let saveButton;
|
|
28253
|
+
const renderPreview = () => {
|
|
28254
|
+
controls.shellAllowlist.syncSuggestions();
|
|
28255
|
+
controls.networkAllowlist.syncSuggestions();
|
|
28256
|
+
controls.verificationCommands.syncSuggestions();
|
|
28257
|
+
nativeSettingsDirty = workflowPolicyDraftSignature(controls) !== initialDraftSignature;
|
|
28258
|
+
try {
|
|
28259
|
+
candidatePolicy = collectWorkflowPolicyFromControls(controls);
|
|
28260
|
+
preview.textContent = JSON.stringify(candidatePolicy, null, 2);
|
|
28261
|
+
setNativeCommandError("");
|
|
28262
|
+
verificationStatus.textContent = candidatePolicy.verificationCommands.length
|
|
28263
|
+
? `${candidatePolicy.verificationCommands.length} ordered verification command${candidatePolicy.verificationCommands.length === 1 ? "" : "s"} configured.`
|
|
28264
|
+
: "No verification commands are configured. Applying workflow worktrees will require an explicit empty-verification waiver.";
|
|
28265
|
+
verificationStatus.classList.toggle("warning", candidatePolicy.verificationCommands.length === 0);
|
|
28266
|
+
if (saveButton) saveButton.disabled = false;
|
|
28267
|
+
} catch (error) {
|
|
28268
|
+
candidatePolicy = null;
|
|
28269
|
+
preview.textContent = "Normalized preview unavailable until the editor error is fixed.";
|
|
28270
|
+
verificationStatus.textContent = "Fix the verification editor before review and save.";
|
|
28271
|
+
verificationStatus.classList.add("warning");
|
|
28272
|
+
setNativeCommandError(error.message || String(error));
|
|
28273
|
+
if (saveButton) saveButton.disabled = true;
|
|
28274
|
+
}
|
|
28275
|
+
};
|
|
28276
|
+
body.addEventListener("input", renderPreview);
|
|
28277
|
+
body.addEventListener("change", renderPreview);
|
|
28278
|
+
|
|
28279
|
+
addNativeCommandAction("Reset to all deny", () => {
|
|
28280
|
+
applyDeniedWorkflowPolicyControls(controls);
|
|
28281
|
+
renderPreview();
|
|
28282
|
+
controls.write.input.focus();
|
|
28283
|
+
});
|
|
28284
|
+
|
|
28285
|
+
saveButton = addNativeCommandAction("Review and save", async () => {
|
|
28286
|
+
renderPreview();
|
|
28287
|
+
if (!candidatePolicy) return;
|
|
28288
|
+
const policyToSave = candidatePolicy;
|
|
28289
|
+
const normalizedPreview = JSON.stringify(policyToSave, null, 2);
|
|
28290
|
+
const verificationReview = policyToSave.verificationCommands.length
|
|
28291
|
+
? `Verification commands: ${policyToSave.verificationCommands.length} configured in the shown order.`
|
|
28292
|
+
: "Verification commands: none — applying workflow worktrees will require an explicit empty-verification waiver.";
|
|
28293
|
+
const reviewed = await appConfirm({
|
|
28294
|
+
title: "Save reviewed workflow permission ceiling?",
|
|
28295
|
+
summary: [
|
|
28296
|
+
`Target: ${data.filePath}`,
|
|
28297
|
+
`Expected revision: ${data.revision ?? "missing (the file is created only after Save)"}`,
|
|
28298
|
+
"This is an authorization ceiling, not blanket authority.",
|
|
28299
|
+
"The shell allowlist is not an OS sandbox.",
|
|
28300
|
+
verificationReview,
|
|
28301
|
+
"",
|
|
28302
|
+
"Exact normalized JSON:",
|
|
28303
|
+
normalizedPreview,
|
|
28304
|
+
].join("\n"),
|
|
28305
|
+
affected: data.filePath || "The global workflow policy",
|
|
28306
|
+
undoable: false,
|
|
28307
|
+
confirmLabel: "Save reviewed policy",
|
|
28308
|
+
});
|
|
28309
|
+
if (!reviewed) return;
|
|
28310
|
+
|
|
28311
|
+
setNativeActionBusy(saveButton, true, "Saving…");
|
|
28312
|
+
setNativeCommandError("");
|
|
28313
|
+
try {
|
|
28314
|
+
const response = await api("/api/workflow-policy", {
|
|
28315
|
+
method: "POST",
|
|
28316
|
+
body: { policy: policyToSave, expectedRevision: data.revision ?? null },
|
|
28317
|
+
scoped: false,
|
|
28318
|
+
});
|
|
28319
|
+
const saved = response.data || {};
|
|
28320
|
+
addTransientMessage({
|
|
28321
|
+
role: "native",
|
|
28322
|
+
title: "/workflow-setup",
|
|
28323
|
+
content: `Saved the global workflow permission ceiling to ${saved.filePath || data.filePath}. No agent turn was started.`,
|
|
28324
|
+
level: "info",
|
|
28325
|
+
});
|
|
28326
|
+
nativeSettingsDirty = false;
|
|
28327
|
+
closeNativeCommandDialog({ force: true });
|
|
28328
|
+
} catch (error) {
|
|
28329
|
+
const message = error.message || String(error);
|
|
28330
|
+
setNativeCommandError(error.statusCode === 409
|
|
28331
|
+
? `${message} Reload /workflow-setup and review the latest policy before saving again.`
|
|
28332
|
+
: `Workflow policy save failed: ${message}`);
|
|
28333
|
+
} finally {
|
|
28334
|
+
setNativeActionBusy(saveButton, false);
|
|
28335
|
+
}
|
|
28336
|
+
}, "primary");
|
|
28337
|
+
renderPreview();
|
|
28338
|
+
}
|
|
28339
|
+
|
|
27337
28340
|
async function openNativeForkSelector() {
|
|
27338
28341
|
openNativeCommandDialog({ title: "/fork", message: "Choose a previous user message to fork before.", searchPlaceholder: "Filter fork points…" });
|
|
27339
28342
|
renderNativeLoading("Loading fork points…");
|
|
@@ -27888,6 +28891,14 @@ async function handleNativeSlashSelectorCommand(message, { usesPromptInput = fal
|
|
|
27888
28891
|
const name = slashCommandName(message);
|
|
27889
28892
|
if (!NATIVE_SELECTOR_COMMANDS.has(name)) return false;
|
|
27890
28893
|
const featureId = optionalFeatureIdForCommand(name);
|
|
28894
|
+
if (name === "workflow-setup" && !hasLoadedRpcCommand(name)) {
|
|
28895
|
+
const tabContext = activeTabContext();
|
|
28896
|
+
addEvent(commandUnavailableMessage(name), "warn");
|
|
28897
|
+
refreshCommands(tabContext).catch((error) => {
|
|
28898
|
+
if (isCurrentTabContext(tabContext)) addEvent(error.message || String(error), "error");
|
|
28899
|
+
});
|
|
28900
|
+
return true;
|
|
28901
|
+
}
|
|
27891
28902
|
if (featureId && !isOptionalFeatureEnabled(featureId)) {
|
|
27892
28903
|
const tabContext = activeTabContext();
|
|
27893
28904
|
addEvent(commandUnavailableMessage(name), "warn");
|
|
@@ -27909,6 +28920,9 @@ async function handleNativeSlashSelectorCommand(message, { usesPromptInput = fal
|
|
|
27909
28920
|
case "settings":
|
|
27910
28921
|
await openNativeSettingsDialog();
|
|
27911
28922
|
return true;
|
|
28923
|
+
case "workflow-setup":
|
|
28924
|
+
await openNativeWorkflowSetupDialog();
|
|
28925
|
+
return true;
|
|
27912
28926
|
case "safety-guard-setup":
|
|
27913
28927
|
await openNativeSafetyGuardSetupDialog();
|
|
27914
28928
|
return true;
|
|
@@ -27957,6 +28971,21 @@ function shouldSendPromptFromEnter(event) {
|
|
|
27957
28971
|
return !isMobileView();
|
|
27958
28972
|
}
|
|
27959
28973
|
|
|
28974
|
+
function insertNumpadDecimal(event) {
|
|
28975
|
+
const isNumpadDecimal = event.code === "NumpadDecimal"
|
|
28976
|
+
|| event.keyCode === 110
|
|
28977
|
+
|| (event.location === 3 && [".", ",", "Decimal", "Delete"].includes(event.key));
|
|
28978
|
+
if (event.defaultPrevented || !isNumpadDecimal || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || event.isComposing) return false;
|
|
28979
|
+
const input = event.currentTarget;
|
|
28980
|
+
if (!input || input.disabled || input.readOnly || typeof input.setRangeText !== "function") return false;
|
|
28981
|
+
const start = input.selectionStart ?? input.value.length;
|
|
28982
|
+
const end = input.selectionEnd ?? start;
|
|
28983
|
+
event.preventDefault();
|
|
28984
|
+
input.setRangeText(".", start, end, "end");
|
|
28985
|
+
input.dispatchEvent(new InputEvent("input", { bubbles: true, data: ".", inputType: "insertText" }));
|
|
28986
|
+
return true;
|
|
28987
|
+
}
|
|
28988
|
+
|
|
27960
28989
|
function renderMessages(messages) {
|
|
27961
28990
|
latestMessages = messages || [];
|
|
27962
28991
|
cleanupLiveToolRunsForMessages(latestMessages);
|
|
@@ -28882,12 +29911,12 @@ function mergeMessagesDelta(previous, data) {
|
|
|
28882
29911
|
return previous.slice(0, since).concat(data.messages);
|
|
28883
29912
|
}
|
|
28884
29913
|
|
|
28885
|
-
async function refreshMessages(tabContext = activeTabContext()) {
|
|
29914
|
+
async function refreshMessages(tabContext = activeTabContext(), { authoritative = false } = {}) {
|
|
28886
29915
|
if (!tabContext.tabId) return;
|
|
28887
29916
|
const previousMessages = latestMessages;
|
|
28888
29917
|
const sessionKey = resolveMessagesSessionKey(tabContext.tabId);
|
|
28889
29918
|
let nextMessages = null;
|
|
28890
|
-
if (previousMessages.length > 1 && sessionKey === latestMessagesSessionKey) {
|
|
29919
|
+
if (!authoritative && previousMessages.length > 1 && sessionKey === latestMessagesSessionKey) {
|
|
28891
29920
|
// Delta fetch with a one-message overlap: the last known message is
|
|
28892
29921
|
// re-requested so retroactive changes are detected via mergeMessagesDelta.
|
|
28893
29922
|
const response = await api(`/api/messages?since=${previousMessages.length - 1}`, { tabId: tabContext.tabId });
|
|
@@ -30312,10 +31341,32 @@ async function sendUserBashCommand(parsed, { usesPromptInput = false, targetTabI
|
|
|
30312
31341
|
await runUserBashCommand(parsed, { usesPromptInput, targetTabId });
|
|
30313
31342
|
}
|
|
30314
31343
|
|
|
31344
|
+
function clearPromptInputForRouting({ usesPromptInput, targetTabId, tabContext }) {
|
|
31345
|
+
if (!usesPromptInput) return;
|
|
31346
|
+
tabDrafts.set(targetTabId, "");
|
|
31347
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
31348
|
+
elements.promptInput.value = "";
|
|
31349
|
+
resizePromptInput();
|
|
31350
|
+
hideCommandSuggestions();
|
|
31351
|
+
}
|
|
31352
|
+
|
|
31353
|
+
function restorePromptInputAfterRoutingError(message, { usesPromptInput, targetTabId, tabContext }) {
|
|
31354
|
+
if (!usesPromptInput) return;
|
|
31355
|
+
if (isCurrentTabContext(tabContext)) {
|
|
31356
|
+
if (elements.promptInput.value) return;
|
|
31357
|
+
elements.promptInput.value = message;
|
|
31358
|
+
resizePromptInput();
|
|
31359
|
+
tabDrafts.set(targetTabId, message);
|
|
31360
|
+
return;
|
|
31361
|
+
}
|
|
31362
|
+
if (!tabDrafts.get(targetTabId)) tabDrafts.set(targetTabId, message);
|
|
31363
|
+
}
|
|
31364
|
+
|
|
30315
31365
|
async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = activeTabId, throwOnError = false, streamingBehavior } = {}) {
|
|
30316
31366
|
const usesPromptInput = explicitMessage === undefined;
|
|
30317
31367
|
const rawMessage = usesPromptInput ? elements.promptInput.value : explicitMessage;
|
|
30318
|
-
const
|
|
31368
|
+
const inputMessage = String(rawMessage || "");
|
|
31369
|
+
const originalMessage = inputMessage.trim();
|
|
30319
31370
|
if (!targetTabId) return;
|
|
30320
31371
|
if (voiceConversationActiveFor(targetTabId)) voiceConversation.handleUserActivity();
|
|
30321
31372
|
const tabContext = activeTabContext(targetTabId);
|
|
@@ -30333,12 +31384,17 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
30333
31384
|
const targetWasBusy = targetWasStreaming || targetWasCompacting;
|
|
30334
31385
|
const busyBehavior = normalizeBusyPromptBehavior(busyPromptBehavior);
|
|
30335
31386
|
const startsRun = kind === "prompt" && !targetWasBusy;
|
|
31387
|
+
clearPromptInputForRouting({ usesPromptInput, targetTabId, tabContext });
|
|
30336
31388
|
resumeChatAutoFollow();
|
|
30337
31389
|
updateJumpToLatestButton();
|
|
30338
31390
|
setComposerActionsOpen(false);
|
|
30339
31391
|
if (startsRun) {
|
|
31392
|
+
promptRoutingTabs.add(targetTabId);
|
|
30340
31393
|
markTabWorkingLocally(targetTabId);
|
|
30341
|
-
|
|
31394
|
+
if (isCurrentTabContext(tabContext)) {
|
|
31395
|
+
appendOptimisticUserPrompt(originalMessage, attachments.length);
|
|
31396
|
+
setRunIndicatorActivity(attachments.length ? "Preparing attachments for routing…" : "Routing prompt to the selected agent…");
|
|
31397
|
+
}
|
|
30342
31398
|
}
|
|
30343
31399
|
|
|
30344
31400
|
let message = originalMessage;
|
|
@@ -30354,7 +31410,7 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
30354
31410
|
rememberPromptHistory(message, { tabId: targetTabId });
|
|
30355
31411
|
if (kind === "prompt") rememberLastUserPrompt(message, { tabId: targetTabId });
|
|
30356
31412
|
}
|
|
30357
|
-
if (startsRun && isCurrentTabContext(tabContext)) setRunIndicatorActivity("
|
|
31413
|
+
if (startsRun && isCurrentTabContext(tabContext)) setRunIndicatorActivity("Routing complete; starting agent…");
|
|
30358
31414
|
|
|
30359
31415
|
let response;
|
|
30360
31416
|
if (kind === "steer") {
|
|
@@ -30367,6 +31423,7 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
30367
31423
|
response = await api("/api/prompt", { method: "POST", body, tabId: targetTabId });
|
|
30368
31424
|
}
|
|
30369
31425
|
applyResponseTab(response);
|
|
31426
|
+
if (startsRun) promptRoutingTabs.delete(targetTabId);
|
|
30370
31427
|
if (response?.command === "native_slash_command" && /^\/new(?:\s|$)/.test(message)) forgetLastUserPrompt(targetTabId);
|
|
30371
31428
|
const targetStillActive = isCurrentTabContext(tabContext);
|
|
30372
31429
|
if (startsRun && response?.command === "native_slash_command") {
|
|
@@ -30383,15 +31440,7 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
30383
31440
|
if (targetStillActive && response?.command === "native_slash_command") {
|
|
30384
31441
|
applyNativeSlashCommandEffects(response, message, tabContext);
|
|
30385
31442
|
}
|
|
30386
|
-
if (usesPromptInput)
|
|
30387
|
-
clearAttachments(targetTabId);
|
|
30388
|
-
if (targetStillActive) {
|
|
30389
|
-
elements.promptInput.value = "";
|
|
30390
|
-
resizePromptInput();
|
|
30391
|
-
} else {
|
|
30392
|
-
tabDrafts.set(targetTabId, "");
|
|
30393
|
-
}
|
|
30394
|
-
}
|
|
31443
|
+
if (usesPromptInput) clearAttachments(targetTabId);
|
|
30395
31444
|
if (targetStillActive) {
|
|
30396
31445
|
hideCommandSuggestions();
|
|
30397
31446
|
if (response?.command !== "native_slash_command") scheduleRefreshState(120, tabContext);
|
|
@@ -30399,7 +31448,9 @@ async function sendPrompt(kind = "prompt", explicitMessage, { targetTabId = acti
|
|
|
30399
31448
|
scheduleRefreshTabs(300);
|
|
30400
31449
|
}
|
|
30401
31450
|
} catch (error) {
|
|
31451
|
+
restorePromptInputAfterRoutingError(inputMessage, { usesPromptInput, targetTabId, tabContext });
|
|
30402
31452
|
if (startsRun) {
|
|
31453
|
+
promptRoutingTabs.delete(targetTabId);
|
|
30403
31454
|
markTabIdleLocally(targetTabId);
|
|
30404
31455
|
if (isCurrentTabContext(tabContext)) clearRunIndicatorActivity();
|
|
30405
31456
|
}
|
|
@@ -30814,6 +31865,99 @@ function showNextDialog() {
|
|
|
30814
31865
|
elements.dialog.showModal();
|
|
30815
31866
|
}
|
|
30816
31867
|
|
|
31868
|
+
function supervisorEventEnvelope(event, fallbackTabId = activeTabId) {
|
|
31869
|
+
if (!event || typeof event !== "object") return null;
|
|
31870
|
+
const fields = ["supervisorScopeId", "supervisorEpoch", "supervisorSeq"];
|
|
31871
|
+
const present = fields.map((field) => Object.prototype.hasOwnProperty.call(event, field));
|
|
31872
|
+
if (!present.some(Boolean)) return null;
|
|
31873
|
+
const scopeId = String(event.supervisorScopeId || "").trim();
|
|
31874
|
+
const epoch = String(event.supervisorEpoch || "").trim();
|
|
31875
|
+
const tabId = String(event.tabId || fallbackTabId || "").trim();
|
|
31876
|
+
const sequenceText = present[2] ? String(event.supervisorSeq ?? "").trim() : null;
|
|
31877
|
+
const sequenceValid = sequenceText === null || /^(?:0|[1-9]\d*)$/.test(sequenceText);
|
|
31878
|
+
return {
|
|
31879
|
+
valid: present[0] && present[1] && scopeId.length > 0 && epoch.length > 0 && tabId.length > 0 && sequenceValid,
|
|
31880
|
+
scopeId,
|
|
31881
|
+
epoch,
|
|
31882
|
+
tabId,
|
|
31883
|
+
sequence: sequenceText === null || !sequenceValid ? null : BigInt(sequenceText),
|
|
31884
|
+
};
|
|
31885
|
+
}
|
|
31886
|
+
|
|
31887
|
+
function supervisorCursorKey(envelope) {
|
|
31888
|
+
return JSON.stringify([envelope.scopeId, envelope.tabId]);
|
|
31889
|
+
}
|
|
31890
|
+
|
|
31891
|
+
function acceptSupervisorEvent(event, fallbackTabId = activeTabId) {
|
|
31892
|
+
const envelope = supervisorEventEnvelope(event, fallbackTabId);
|
|
31893
|
+
if (!envelope) return true;
|
|
31894
|
+
if (!envelope.valid) {
|
|
31895
|
+
const warningKey = String(event?.type || "unknown");
|
|
31896
|
+
if (!supervisorEnvelopeWarnings.has(warningKey)) {
|
|
31897
|
+
supervisorEnvelopeWarnings.add(warningKey);
|
|
31898
|
+
addEvent(`ignored malformed supervisor event (${warningKey})`, "warn");
|
|
31899
|
+
}
|
|
31900
|
+
return false;
|
|
31901
|
+
}
|
|
31902
|
+
|
|
31903
|
+
const key = supervisorCursorKey(envelope);
|
|
31904
|
+
const cursor = supervisorEventCursors.get(key);
|
|
31905
|
+
if (!cursor) {
|
|
31906
|
+
supervisorEventCursors.set(key, { epoch: envelope.epoch, sequence: envelope.sequence });
|
|
31907
|
+
return true;
|
|
31908
|
+
}
|
|
31909
|
+
|
|
31910
|
+
if (cursor.epoch !== envelope.epoch) {
|
|
31911
|
+
const retired = supervisorRetiredEpochs.get(key) || new Set();
|
|
31912
|
+
if (retired.has(envelope.epoch)) return false;
|
|
31913
|
+
retired.add(cursor.epoch);
|
|
31914
|
+
supervisorRetiredEpochs.set(key, retired);
|
|
31915
|
+
supervisorEventCursors.set(key, { epoch: envelope.epoch, sequence: envelope.sequence });
|
|
31916
|
+
return true;
|
|
31917
|
+
}
|
|
31918
|
+
|
|
31919
|
+
if (envelope.sequence === null) return true;
|
|
31920
|
+
if (cursor.sequence !== null && envelope.sequence <= cursor.sequence) return false;
|
|
31921
|
+
cursor.sequence = envelope.sequence;
|
|
31922
|
+
return true;
|
|
31923
|
+
}
|
|
31924
|
+
|
|
31925
|
+
function supervisorContinuityKey(event, fallbackTabId = activeTabId) {
|
|
31926
|
+
const envelope = supervisorEventEnvelope(event, fallbackTabId);
|
|
31927
|
+
return envelope?.valid ? `${supervisorCursorKey(envelope)}|${envelope.epoch}` : "";
|
|
31928
|
+
}
|
|
31929
|
+
|
|
31930
|
+
function scheduleSupervisorContinuityRefresh(event, { gap = false } = {}) {
|
|
31931
|
+
const tabContext = activeTabContext(event?.tabId || activeTabId);
|
|
31932
|
+
const key = supervisorContinuityKey(event, tabContext.tabId);
|
|
31933
|
+
if (!key || !tabContext.tabId || !isCurrentTabContext(tabContext)) return;
|
|
31934
|
+
|
|
31935
|
+
if (gap && !supervisorGapWarnings.has(key)) {
|
|
31936
|
+
supervisorGapWarnings.add(key);
|
|
31937
|
+
addEvent("Buffered live output may be incomplete; refreshing tabs, state, and transcript from Pi.", "warn");
|
|
31938
|
+
}
|
|
31939
|
+
if (supervisorContinuityRefreshes.has(key)) return;
|
|
31940
|
+
|
|
31941
|
+
const timer = setTimeout(async () => {
|
|
31942
|
+
try {
|
|
31943
|
+
const results = await Promise.allSettled([refreshTabs()]);
|
|
31944
|
+
if (isCurrentTabContext(tabContext)) {
|
|
31945
|
+
results.push(...(await Promise.allSettled([
|
|
31946
|
+
refreshState(tabContext),
|
|
31947
|
+
refreshMessages(tabContext, { authoritative: true }),
|
|
31948
|
+
])));
|
|
31949
|
+
}
|
|
31950
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
31951
|
+
for (const result of results) {
|
|
31952
|
+
if (result.status === "rejected") addEvent(`continuity refresh failed: ${result.reason?.message || String(result.reason)}`, "error");
|
|
31953
|
+
}
|
|
31954
|
+
} finally {
|
|
31955
|
+
supervisorContinuityRefreshes.delete(key);
|
|
31956
|
+
}
|
|
31957
|
+
}, 25);
|
|
31958
|
+
supervisorContinuityRefreshes.set(key, timer);
|
|
31959
|
+
}
|
|
31960
|
+
|
|
30817
31961
|
function handleInactiveTabEvent(event) {
|
|
30818
31962
|
if (event.type === "extension_ui_request" && EXTENSION_UI_BLOCKING_METHODS.has(event.method)) {
|
|
30819
31963
|
if (!event.replayed) notifyBlockedTab(event.tabId, { request: event, count: event.pendingExtensionUiRequestCount });
|
|
@@ -30866,9 +32010,17 @@ function handleEvent(event) {
|
|
|
30866
32010
|
renderWidgets();
|
|
30867
32011
|
}
|
|
30868
32012
|
addEvent(`connected to ${event.tabTitle || "terminal"} for ${event.cwd}`);
|
|
32013
|
+
if (event.supervisorReplayGap === true) scheduleSupervisorContinuityRefresh(event, { gap: true });
|
|
30869
32014
|
scheduleForegroundReconcile("event stream reconnect", 0);
|
|
30870
32015
|
break;
|
|
30871
32016
|
}
|
|
32017
|
+
case "webui_supervisor_reconnected":
|
|
32018
|
+
addEvent("reconnected to the running Pi session");
|
|
32019
|
+
scheduleSupervisorContinuityRefresh(event);
|
|
32020
|
+
break;
|
|
32021
|
+
case "webui_supervisor_replay_gap":
|
|
32022
|
+
scheduleSupervisorContinuityRefresh(event, { gap: true });
|
|
32023
|
+
break;
|
|
30872
32024
|
case "webui_output_mode":
|
|
30873
32025
|
applyOutputModeControl(event, tabContext);
|
|
30874
32026
|
break;
|
|
@@ -31218,7 +32370,9 @@ function connectEvents(tabContext = activeTabContext(), { requestedMode = "auto"
|
|
|
31218
32370
|
source.onmessage = (message) => {
|
|
31219
32371
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
31220
32372
|
try {
|
|
31221
|
-
|
|
32373
|
+
const event = JSON.parse(message.data);
|
|
32374
|
+
if (!acceptSupervisorEvent(event, tabContext.tabId)) return;
|
|
32375
|
+
handleEvent(event);
|
|
31222
32376
|
} catch (error) {
|
|
31223
32377
|
if (isCurrentTabContext(tabContext)) addEvent(error.message, "error");
|
|
31224
32378
|
}
|
|
@@ -31552,6 +32706,7 @@ elements.optionsRemoteButton.addEventListener("click", () => runNativeCommandMen
|
|
|
31552
32706
|
elements.optionsNameButton.addEventListener("click", () => runNativeCommandMenu("/name"));
|
|
31553
32707
|
elements.optionsCloneButton.addEventListener("click", () => runNativeCommandMenu("/clone"));
|
|
31554
32708
|
elements.optionsSettingsButton.addEventListener("click", () => runNativeCommandMenu("/settings"));
|
|
32709
|
+
elements.optionsWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/workflow-setup"));
|
|
31555
32710
|
elements.optionsSafetyGuardSetupButton?.addEventListener("click", () => runNativeCommandMenu("/safety-guard-setup"));
|
|
31556
32711
|
elements.optionsGitWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/git-workflow-setup"));
|
|
31557
32712
|
elements.optionsExportButton.addEventListener("click", () => runNativeCommandMenu("/export"));
|
|
@@ -32594,6 +33749,7 @@ elements.fileViewerResizeHandle?.addEventListener("pointerdown", beginFileViewer
|
|
|
32594
33749
|
elements.fileViewerResizeHandle?.addEventListener("keydown", handleFileViewerResizeKeydown);
|
|
32595
33750
|
elements.fileViewerSaveButton?.addEventListener("click", () => saveActiveFileViewer());
|
|
32596
33751
|
elements.fileViewerCloseButton?.addEventListener("click", closeFileViewer);
|
|
33752
|
+
elements.fileViewerChangesModeButton?.addEventListener("click", () => setFileViewerMode("changes"));
|
|
32597
33753
|
elements.fileViewerSourceModeButton?.addEventListener("click", () => setFileViewerMode("source"));
|
|
32598
33754
|
elements.fileViewerPreviewModeButton?.addEventListener("click", () => setFileViewerMode("preview"));
|
|
32599
33755
|
elements.fileViewerEditor?.addEventListener("input", () => {
|
|
@@ -32662,7 +33818,7 @@ elements.composer.addEventListener("dragleave", handleComposerDragLeave);
|
|
|
32662
33818
|
elements.composer.addEventListener("drop", handleComposerDrop);
|
|
32663
33819
|
|
|
32664
33820
|
elements.promptInput.addEventListener("keydown", (event) => {
|
|
32665
|
-
if (event.defaultPrevented) return;
|
|
33821
|
+
if (event.defaultPrevented || insertNumpadDecimal(event)) return;
|
|
32666
33822
|
if (shouldSendPromptFromEnter(event)) {
|
|
32667
33823
|
event.preventDefault();
|
|
32668
33824
|
hideCommandSuggestions();
|