@firstpick/pi-package-webui 0.8.9 → 0.9.1
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 +222 -19
- package/bin/pi-webui.mjs +24 -7
- package/lib/app-runner-terminal.mjs +40 -0
- package/package.json +2 -2
- package/public/app.js +348 -72
- package/public/index.html +1 -0
- package/public/styles.css +48 -7
- package/tests/app-runner-terminal-static.test.mjs +28 -0
- package/tests/app-runner-terminal.test.mjs +65 -0
- package/tests/browser/interaction-continuity.spec.mjs +94 -0
- package/tests/browser/search-match-highlighting.spec.mjs +104 -0
- package/tests/chat-scroll-intent-static.test.mjs +1 -1
- package/tests/file-viewer-search-static.test.mjs +7 -2
- package/tests/footer-provider-usage-visual-static.test.mjs +10 -8
- package/tests/foreground-transcript-catch-up-static.test.mjs +91 -0
- package/tests/http-endpoints-harness.test.mjs +29 -0
- package/tests/mobile-static.test.mjs +12 -4
- package/tests/search-match-highlighting-static.test.mjs +27 -0
- package/tests/stream-output-isolation-static.test.mjs +1 -1
package/public/app.js
CHANGED
|
@@ -9,7 +9,7 @@ import { buildIssuePayload, createIssueWizardCatalog, createIssueWizardState, ge
|
|
|
9
9
|
import { createIssueBotClient, readIssueBotRuntimeConfig } from "./issue-bot-client.mjs";
|
|
10
10
|
import { MOBILE_SHELL_STORAGE_KEY, TABLET_SHELL_STORAGE_KEY, createMobileShellState, isMobileShellV2Enabled, mobileNavigationTargetFromSearch, normalizeMobileNavigationTarget, reduceMobileShellState, resolveMobileShellFeatureMode, resolveTabletShellFeatureMode } from "./mobile-shell-state.mjs";
|
|
11
11
|
import { createTranscriptRenderer } from "./transcript-renderer.mjs";
|
|
12
|
-
import { createStreamOutputController } from "./stream-output-controller.mjs";
|
|
12
|
+
import { classifyTranscriptStreamEvent, createStreamOutputController } from "./stream-output-controller.mjs";
|
|
13
13
|
import { installMiddleButtonDragScroll } from "./middle-button-drag-scroll.mjs";
|
|
14
14
|
import { PI_THEME_EXPORT_FIELDS, THEME_TOKEN_GROUPS, canonicalizeTheme, serializeTheme, themeColorToRgb, validateTheme } from "./theme-contract.mjs";
|
|
15
15
|
import {
|
|
@@ -318,6 +318,7 @@ const elements = {
|
|
|
318
318
|
fileViewerSourceModeButton: $("#fileViewerSourceModeButton"),
|
|
319
319
|
fileViewerPreviewModeButton: $("#fileViewerPreviewModeButton"),
|
|
320
320
|
fileViewerEditor: $("#fileViewerEditor"),
|
|
321
|
+
fileViewerSearchOverlay: $("#fileViewerSearchOverlay"),
|
|
321
322
|
fileViewerPreview: $("#fileViewerPreview"),
|
|
322
323
|
fileViewerChanges: $("#fileViewerChanges"),
|
|
323
324
|
fileViewerStatus: $("#fileViewerStatus"),
|
|
@@ -574,7 +575,6 @@ let fileViewerSearchMatches = [];
|
|
|
574
575
|
let fileViewerSearchIndex = -1;
|
|
575
576
|
let fileViewerSearchTruncated = false;
|
|
576
577
|
let fileViewerSearchTimer = null;
|
|
577
|
-
let fileViewerSearchHighlightElement = null;
|
|
578
578
|
let fileContextMenuState = null;
|
|
579
579
|
let sidePanelContextMenuState = null;
|
|
580
580
|
let gitFooterContextMenuState = null;
|
|
@@ -760,6 +760,12 @@ let refreshFooterTimer = null;
|
|
|
760
760
|
let refreshTabsTimer = null;
|
|
761
761
|
let tabsRenderFrame = null;
|
|
762
762
|
let foregroundReconcileTimer = null;
|
|
763
|
+
let foregroundSupplementalRefreshCancel = null;
|
|
764
|
+
let foregroundTranscriptCatchUpRequired = document.visibilityState === "hidden";
|
|
765
|
+
let foregroundTranscriptSuppressedEvents = 0;
|
|
766
|
+
let eventStreamPausedForBackground = false;
|
|
767
|
+
let backgroundReconnectSnapshotFresh = false;
|
|
768
|
+
let foregroundReconnectSnapshotFreshUntil = 0;
|
|
763
769
|
let eventSource = null;
|
|
764
770
|
const supervisorEventCursors = new Map();
|
|
765
771
|
const supervisorRetiredEpochs = new Map();
|
|
@@ -2466,6 +2472,7 @@ const OPTIONAL_FEATURES = [
|
|
|
2466
2472
|
packageName: "@firstpick/pi-prompts-git-pr",
|
|
2467
2473
|
capabilityLabel: "/git-staged-msg",
|
|
2468
2474
|
description: "Generate staged commit messages for the guided Git workflow.",
|
|
2475
|
+
setup: "git-workflow",
|
|
2469
2476
|
},
|
|
2470
2477
|
{
|
|
2471
2478
|
id: "releaseNpm",
|
|
@@ -2494,6 +2501,7 @@ const OPTIONAL_FEATURES = [
|
|
|
2494
2501
|
packageName: "@firstpick/pi-extension-workflows",
|
|
2495
2502
|
capabilityLabel: "/workflow or workflow subprocess widget event",
|
|
2496
2503
|
description: "Modular workflow runner with live subprocess output shown in a non-blocking Web UI widget.",
|
|
2504
|
+
setup: "workflows",
|
|
2497
2505
|
},
|
|
2498
2506
|
{
|
|
2499
2507
|
id: "featureSystemPrompt",
|
|
@@ -2508,6 +2516,7 @@ const OPTIONAL_FEATURES = [
|
|
|
2508
2516
|
packageName: "@firstpick/pi-extension-safety-guard",
|
|
2509
2517
|
capabilityLabel: "/safety-guard or /safety-guard-setup command",
|
|
2510
2518
|
description: "Configurable guardrails for dangerous bash commands and protected file edits.",
|
|
2519
|
+
setup: "safety-guard",
|
|
2511
2520
|
},
|
|
2512
2521
|
{
|
|
2513
2522
|
id: "tuiSkillsCommand",
|
|
@@ -2544,6 +2553,7 @@ const OPTIONAL_FEATURES = [
|
|
|
2544
2553
|
capabilityLabel: "questionnaire tool in /tools",
|
|
2545
2554
|
description: "Native TUI and WebUI single- or multi-select question series with Other answers and resumable clarification.",
|
|
2546
2555
|
manageWith: "tools",
|
|
2556
|
+
setup: "tools",
|
|
2547
2557
|
},
|
|
2548
2558
|
{
|
|
2549
2559
|
id: "naturalConversation",
|
|
@@ -8843,6 +8853,8 @@ function loadDisabledOptionalFeatures() {
|
|
|
8843
8853
|
}
|
|
8844
8854
|
|
|
8845
8855
|
let disabledOptionalFeatures = new Set(loadDisabledOptionalFeatures());
|
|
8856
|
+
const optionalFeatureManagedAccessEnabled = new Map();
|
|
8857
|
+
const optionalFeatureAccessInProgress = new Set();
|
|
8846
8858
|
|
|
8847
8859
|
function storeDisabledOptionalFeatures() {
|
|
8848
8860
|
try {
|
|
@@ -8874,6 +8886,10 @@ function isOptionalFeatureDetected(featureId) {
|
|
|
8874
8886
|
}
|
|
8875
8887
|
|
|
8876
8888
|
function isOptionalFeatureDisabled(featureId) {
|
|
8889
|
+
const feature = OPTIONAL_FEATURE_BY_ID.get(featureId);
|
|
8890
|
+
if (feature?.manageWith === "tools" && optionalFeatureManagedAccessEnabled.has(featureId)) {
|
|
8891
|
+
return optionalFeatureManagedAccessEnabled.get(featureId) === false;
|
|
8892
|
+
}
|
|
8877
8893
|
return disabledOptionalFeatures.has(featureId);
|
|
8878
8894
|
}
|
|
8879
8895
|
|
|
@@ -12926,16 +12942,84 @@ function textOffsetPosition(root, offset) {
|
|
|
12926
12942
|
return null;
|
|
12927
12943
|
}
|
|
12928
12944
|
|
|
12945
|
+
function textOffsetRange(root, match) {
|
|
12946
|
+
const start = textOffsetPosition(root, match.start);
|
|
12947
|
+
const end = textOffsetPosition(root, match.end);
|
|
12948
|
+
if (!start || !end) return null;
|
|
12949
|
+
const range = document.createRange();
|
|
12950
|
+
range.setStart(start.node, start.offset);
|
|
12951
|
+
range.setEnd(end.node, end.offset);
|
|
12952
|
+
return range;
|
|
12953
|
+
}
|
|
12954
|
+
|
|
12955
|
+
function syncFileViewerSearchOverlayScroll() {
|
|
12956
|
+
const editor = elements.fileViewerEditor;
|
|
12957
|
+
const overlay = elements.fileViewerSearchOverlay;
|
|
12958
|
+
if (!editor || !overlay || overlay.hidden) return;
|
|
12959
|
+
overlay.scrollTop = editor.scrollTop;
|
|
12960
|
+
overlay.scrollLeft = editor.scrollLeft;
|
|
12961
|
+
}
|
|
12962
|
+
|
|
12929
12963
|
function clearFileViewerSearchHighlight() {
|
|
12964
|
+
globalThis.CSS?.highlights?.delete("file-viewer-search-match");
|
|
12930
12965
|
globalThis.CSS?.highlights?.delete("file-viewer-search-current");
|
|
12931
|
-
|
|
12932
|
-
|
|
12966
|
+
for (const surface of [elements.fileViewerPreview, elements.fileViewerChanges]) {
|
|
12967
|
+
for (const node of surface?.querySelectorAll(".file-viewer-search-match-fallback, .file-viewer-search-current-fallback") || []) {
|
|
12968
|
+
node.classList.remove("file-viewer-search-match-fallback", "file-viewer-search-current-fallback");
|
|
12969
|
+
}
|
|
12970
|
+
}
|
|
12971
|
+
const overlay = elements.fileViewerSearchOverlay;
|
|
12972
|
+
if (overlay) {
|
|
12973
|
+
overlay.hidden = true;
|
|
12974
|
+
overlay.replaceChildren();
|
|
12975
|
+
}
|
|
12976
|
+
elements.fileViewerEditor?.closest(".file-viewer-content")?.classList.remove("search-highlights-source");
|
|
12977
|
+
}
|
|
12978
|
+
|
|
12979
|
+
function renderFileViewerSourceSearchHighlights() {
|
|
12980
|
+
const editor = elements.fileViewerEditor;
|
|
12981
|
+
const overlay = elements.fileViewerSearchOverlay;
|
|
12982
|
+
if (!editor || !overlay || !fileViewerSearchMatches.length) return;
|
|
12983
|
+
const text = fileViewerSearchText();
|
|
12984
|
+
const fragment = document.createDocumentFragment();
|
|
12985
|
+
let offset = 0;
|
|
12986
|
+
fileViewerSearchMatches.forEach((match, index) => {
|
|
12987
|
+
if (match.start > offset) fragment.append(document.createTextNode(text.slice(offset, match.start)));
|
|
12988
|
+
const mark = make("mark", `file-viewer-search-match${index === fileViewerSearchIndex ? " current" : ""}`, text.slice(match.start, match.end));
|
|
12989
|
+
fragment.append(mark);
|
|
12990
|
+
offset = match.end;
|
|
12991
|
+
});
|
|
12992
|
+
if (offset < text.length) fragment.append(document.createTextNode(text.slice(offset)));
|
|
12993
|
+
overlay.replaceChildren(fragment);
|
|
12994
|
+
overlay.hidden = false;
|
|
12995
|
+
editor.closest(".file-viewer-content")?.classList.add("search-highlights-source");
|
|
12996
|
+
syncFileViewerSearchOverlayScroll();
|
|
12997
|
+
}
|
|
12998
|
+
|
|
12999
|
+
function renderFileViewerSearchHighlights() {
|
|
13000
|
+
clearFileViewerSearchHighlight();
|
|
13001
|
+
const surface = fileViewerSearchSurface();
|
|
13002
|
+
if (!surface || !fileViewerSearchMatches.length) return;
|
|
13003
|
+
if (surface === elements.fileViewerEditor) {
|
|
13004
|
+
renderFileViewerSourceSearchHighlights();
|
|
13005
|
+
return;
|
|
13006
|
+
}
|
|
13007
|
+
const ranges = fileViewerSearchMatches.map((match) => textOffsetRange(surface, match)).filter(Boolean);
|
|
13008
|
+
const currentRange = textOffsetRange(surface, fileViewerSearchMatches[fileViewerSearchIndex]);
|
|
13009
|
+
const HighlightConstructor = globalThis.Highlight;
|
|
13010
|
+
if (globalThis.CSS?.highlights && typeof HighlightConstructor === "function") {
|
|
13011
|
+
if (ranges.length) globalThis.CSS.highlights.set("file-viewer-search-match", new HighlightConstructor(...ranges));
|
|
13012
|
+
if (currentRange) globalThis.CSS.highlights.set("file-viewer-search-current", new HighlightConstructor(currentRange));
|
|
13013
|
+
return;
|
|
13014
|
+
}
|
|
13015
|
+
for (const match of fileViewerSearchMatches) textOffsetPosition(surface, match.start)?.node.parentElement?.classList.add("file-viewer-search-match-fallback");
|
|
13016
|
+
textOffsetPosition(surface, fileViewerSearchMatches[fileViewerSearchIndex]?.start)?.node.parentElement?.classList.add("file-viewer-search-current-fallback");
|
|
12933
13017
|
}
|
|
12934
13018
|
|
|
12935
13019
|
function focusFileViewerSearchMatch() {
|
|
12936
13020
|
const match = fileViewerSearchMatches[fileViewerSearchIndex];
|
|
12937
13021
|
const surface = fileViewerSearchSurface();
|
|
12938
|
-
|
|
13022
|
+
renderFileViewerSearchHighlights();
|
|
12939
13023
|
if (!match || !surface) return;
|
|
12940
13024
|
if (surface === elements.fileViewerEditor) {
|
|
12941
13025
|
surface.setSelectionRange(match.start, match.end);
|
|
@@ -12945,22 +13029,9 @@ function focusFileViewerSearchMatch() {
|
|
|
12945
13029
|
const fontSize = Number.parseFloat(computedStyle.fontSize) || 14;
|
|
12946
13030
|
const lineHeight = !parsedLineHeight ? fontSize * 1.45 : parsedLineHeight < 8 ? parsedLineHeight * fontSize : parsedLineHeight;
|
|
12947
13031
|
surface.scrollTop = Math.max(0, (lineIndex * lineHeight) - (surface.clientHeight / 2));
|
|
13032
|
+
syncFileViewerSearchOverlayScroll();
|
|
12948
13033
|
} else {
|
|
12949
|
-
|
|
12950
|
-
const end = textOffsetPosition(surface, match.end);
|
|
12951
|
-
if (start && end) {
|
|
12952
|
-
const range = document.createRange();
|
|
12953
|
-
range.setStart(start.node, start.offset);
|
|
12954
|
-
range.setEnd(end.node, end.offset);
|
|
12955
|
-
const HighlightConstructor = globalThis.Highlight;
|
|
12956
|
-
if (globalThis.CSS?.highlights && typeof HighlightConstructor === "function") {
|
|
12957
|
-
globalThis.CSS.highlights.set("file-viewer-search-current", new HighlightConstructor(range));
|
|
12958
|
-
} else {
|
|
12959
|
-
fileViewerSearchHighlightElement = start.node.parentElement;
|
|
12960
|
-
fileViewerSearchHighlightElement?.classList.add("file-viewer-search-current-fallback");
|
|
12961
|
-
}
|
|
12962
|
-
start.node.parentElement?.scrollIntoView({ block: "center", behavior: "instant" });
|
|
12963
|
-
}
|
|
13034
|
+
textOffsetPosition(surface, match.start)?.node.parentElement?.scrollIntoView({ block: "center", behavior: "instant" });
|
|
12964
13035
|
}
|
|
12965
13036
|
elements.fileViewerSearchInput?.focus({ preventScroll: true });
|
|
12966
13037
|
updateFileViewerSearchCount();
|
|
@@ -12976,6 +13047,7 @@ function runFileViewerSearch({ navigate = false } = {}) {
|
|
|
12976
13047
|
else if (fileViewerSearchIndex < 0 || fileViewerSearchIndex >= fileViewerSearchMatches.length) fileViewerSearchIndex = 0;
|
|
12977
13048
|
updateFileViewerSearchCount();
|
|
12978
13049
|
if (navigate) focusFileViewerSearchMatch();
|
|
13050
|
+
else renderFileViewerSearchHighlights();
|
|
12979
13051
|
}
|
|
12980
13052
|
|
|
12981
13053
|
function stepFileViewerSearch(step) {
|
|
@@ -16650,17 +16722,17 @@ function applyFooterContextUsage(node, contextUsage) {
|
|
|
16650
16722
|
return node;
|
|
16651
16723
|
}
|
|
16652
16724
|
|
|
16653
|
-
// Dedicated Usage visual apply path: sets
|
|
16654
|
-
// primary/first window, bottom = secondary/second window) plus a
|
|
16655
|
-
// active foreground/glow reusing the Context color interpolation.
|
|
16656
|
-
//
|
|
16725
|
+
// Dedicated Usage visual apply path: sets available independent lane widths
|
|
16726
|
+
// (top = primary/first window, bottom = secondary/second window) plus a
|
|
16727
|
+
// max-window active foreground/glow reusing the Context color interpolation.
|
|
16728
|
+
// Missing lanes remain empty; exact text and tooltip remain untouched.
|
|
16657
16729
|
function applyFooterUsageWindows(node, usageWindows) {
|
|
16658
16730
|
node.classList.add("footer-usage-card");
|
|
16659
16731
|
const primaryPercent = typeof usageWindows?.primaryPercent === "number" ? usageWindows.primaryPercent : Number.NaN;
|
|
16660
16732
|
const secondaryPercent = typeof usageWindows?.secondaryPercent === "number" ? usageWindows.secondaryPercent : Number.NaN;
|
|
16661
|
-
if (Number.isFinite(primaryPercent)
|
|
16662
|
-
const clampedPrimary = Math.min(100, Math.max(0, primaryPercent));
|
|
16663
|
-
const clampedSecondary = Math.min(100, Math.max(0, secondaryPercent));
|
|
16733
|
+
if (Number.isFinite(primaryPercent) || Number.isFinite(secondaryPercent)) {
|
|
16734
|
+
const clampedPrimary = Number.isFinite(primaryPercent) ? Math.min(100, Math.max(0, primaryPercent)) : 0;
|
|
16735
|
+
const clampedSecondary = Number.isFinite(secondaryPercent) ? Math.min(100, Math.max(0, secondaryPercent)) : 0;
|
|
16664
16736
|
const activeColor = contextUsageActiveColor(Math.max(clampedPrimary, clampedSecondary));
|
|
16665
16737
|
node.classList.add("has-usage-windows");
|
|
16666
16738
|
node.style.setProperty("--usage-primary", `${clampedPrimary.toFixed(1)}%`);
|
|
@@ -16758,7 +16830,7 @@ const GIT_FOOTER_TOOLTIP_COPY = {
|
|
|
16758
16830
|
speed: "Assistant streaming speed. Shows live output tokens for the current reply and current or last tokens per second.",
|
|
16759
16831
|
cost: "Estimated session cost. sub means subscription-backed provider; api means metered API usage.",
|
|
16760
16832
|
context: "Context window pressure. Shows percent used over the model limit; auto means auto-compaction is enabled.",
|
|
16761
|
-
usage: "Provider subscription usage. Shows the used share of
|
|
16833
|
+
usage: "Provider subscription usage. Shows the used share of every available provider-reported rate window.",
|
|
16762
16834
|
cwd: "Active working directory for this Web UI tab.",
|
|
16763
16835
|
git: "Current Git branch. detached means HEAD is not on a branch; no repo means the cwd is outside a Git work tree.",
|
|
16764
16836
|
"git-state": "Active Git operation or detached state. Finish or abort rebase/merge/cherry-pick/revert/bisect before normal commits.",
|
|
@@ -17200,8 +17272,11 @@ function normalizeFooterPayloadChip(value, index) {
|
|
|
17200
17272
|
if (value.usageWindows && typeof value.usageWindows === "object") {
|
|
17201
17273
|
const primaryPercent = typeof value.usageWindows.primaryPercent === "number" ? value.usageWindows.primaryPercent : Number.NaN;
|
|
17202
17274
|
const secondaryPercent = typeof value.usageWindows.secondaryPercent === "number" ? value.usageWindows.secondaryPercent : Number.NaN;
|
|
17203
|
-
if (Number.isFinite(primaryPercent)
|
|
17204
|
-
chip.usageWindows = {
|
|
17275
|
+
if (Number.isFinite(primaryPercent) || Number.isFinite(secondaryPercent)) {
|
|
17276
|
+
chip.usageWindows = {
|
|
17277
|
+
...(Number.isFinite(primaryPercent) ? { primaryPercent } : {}),
|
|
17278
|
+
...(Number.isFinite(secondaryPercent) ? { secondaryPercent } : {}),
|
|
17279
|
+
};
|
|
17205
17280
|
}
|
|
17206
17281
|
}
|
|
17207
17282
|
return chip;
|
|
@@ -30890,7 +30965,7 @@ async function pushGitWorkflow(tabId = gitWorkflowActionTabId()) {
|
|
|
30890
30965
|
const tabContext = activeTabContext(tabId);
|
|
30891
30966
|
const workflow = gitWorkflowForTab(tabId, { create: false });
|
|
30892
30967
|
if (!workflow) return;
|
|
30893
|
-
if (!(await appConfirmText("Push the committed changes to the
|
|
30968
|
+
if (!(await appConfirmText("Push the committed changes from the current checked-out branch to the same-named remote branch and track it as the upstream?\n\nGuided Git never force-pushes automatically.", { affected: "The same-named remote Git branch and local upstream tracking", confirmLabel: "Push commits" }))) return;
|
|
30894
30969
|
const runId = workflow.runId;
|
|
30895
30970
|
setGitWorkflow({ step: "pushing", busy: true, error: "", output: "Running git push…" }, { tabId });
|
|
30896
30971
|
try {
|
|
@@ -35729,6 +35804,7 @@ function scheduleChatFollowScroll({ settle = true } = {}) {
|
|
|
35729
35804
|
|
|
35730
35805
|
function resumeChatAutoFollow() {
|
|
35731
35806
|
chatUserScrollAwayIntentUntil = 0;
|
|
35807
|
+
chatPausedScrollRestoreUntil = 0;
|
|
35732
35808
|
autoFollowChat = true;
|
|
35733
35809
|
}
|
|
35734
35810
|
|
|
@@ -36234,6 +36310,7 @@ function setOptionalControlState(button, available, unavailableTitle) {
|
|
|
36234
36310
|
function resetOptionalFeatureAvailability() {
|
|
36235
36311
|
for (const key of Object.keys(optionalFeatureAvailability)) optionalFeatureAvailability[key] = false;
|
|
36236
36312
|
optionalFeatureAvailability.themeBundle = availableThemes.length > 0;
|
|
36313
|
+
optionalFeatureManagedAccessEnabled.clear();
|
|
36237
36314
|
renderOptionalFeatureControls();
|
|
36238
36315
|
if (activeTabId) queueMicrotask(() => refreshQuestionnaireFeatureAvailability());
|
|
36239
36316
|
}
|
|
@@ -36909,13 +36986,18 @@ async function refreshQuestionnaireFeatureAvailability(tabContext = activeTabCon
|
|
|
36909
36986
|
try {
|
|
36910
36987
|
const response = await api("/api/tools?scope=session", { tabId: tabContext.tabId });
|
|
36911
36988
|
if (!isCurrentTabContext(tabContext)) return false;
|
|
36912
|
-
|
|
36913
|
-
|
|
36989
|
+
const questionnaireTool = Array.isArray(response.data?.tools)
|
|
36990
|
+
? response.data.tools.find((tool) => tool?.name === "questionnaire")
|
|
36991
|
+
: null;
|
|
36992
|
+
optionalFeatureAvailability.questionnaire = !!questionnaireTool;
|
|
36993
|
+
if (questionnaireTool) optionalFeatureManagedAccessEnabled.set("questionnaire", questionnaireTool.enabled !== false);
|
|
36994
|
+
else optionalFeatureManagedAccessEnabled.delete("questionnaire");
|
|
36914
36995
|
renderOptionalFeatureControls();
|
|
36915
36996
|
return true;
|
|
36916
36997
|
} catch {
|
|
36917
36998
|
if (isCurrentTabContext(tabContext)) {
|
|
36918
36999
|
optionalFeatureAvailability.questionnaire = false;
|
|
37000
|
+
optionalFeatureManagedAccessEnabled.delete("questionnaire");
|
|
36919
37001
|
renderOptionalFeatureControls();
|
|
36920
37002
|
}
|
|
36921
37003
|
return false;
|
|
@@ -37047,7 +37129,7 @@ function optionalFeatureStatus(featureId) {
|
|
|
37047
37129
|
const feature = OPTIONAL_FEATURE_BY_ID.get(featureId);
|
|
37048
37130
|
const detected = isOptionalFeatureDetected(featureId);
|
|
37049
37131
|
const managedWithTools = feature?.manageWith === "tools";
|
|
37050
|
-
const disabled =
|
|
37132
|
+
const disabled = isOptionalFeatureDisabled(featureId);
|
|
37051
37133
|
const packageStatus = optionalFeaturePackageStatus(featureId);
|
|
37052
37134
|
const installMessage = optionalFeatureInstallMessages.get(featureId);
|
|
37053
37135
|
const installState = optionalFeatureInstallState(featureId);
|
|
@@ -37073,7 +37155,7 @@ function optionalFeatureStatus(featureId) {
|
|
|
37073
37155
|
};
|
|
37074
37156
|
}
|
|
37075
37157
|
const doneDetail = installState?.phase === "done" ? optionalFeatureInstallDetail(installState, installMessage) : "";
|
|
37076
|
-
if (disabled) return {
|
|
37158
|
+
if (disabled && !managedWithTools) return {
|
|
37077
37159
|
label: "Disabled",
|
|
37078
37160
|
className: "disabled",
|
|
37079
37161
|
detail: `Disabled in this browser and excluded from migration selection${versionSuffix}`,
|
|
@@ -37087,7 +37169,13 @@ function optionalFeatureStatus(featureId) {
|
|
|
37087
37169
|
hint: "Do not install again. Keep either the package entry or the extensions/skills/prompts/themes alias, not both.",
|
|
37088
37170
|
};
|
|
37089
37171
|
if (packageStatus?.updateAvailable) return { label: "Update available", className: "updating", detail: packageStatus.updateReason || `Installed package is older than the Web UI expects${versionSuffix}` };
|
|
37090
|
-
if (
|
|
37172
|
+
if (disabled && managedWithTools) return {
|
|
37173
|
+
label: "Disabled",
|
|
37174
|
+
className: "disabled",
|
|
37175
|
+
detail: `Tool access is disabled for the active Pi session${versionSuffix}`,
|
|
37176
|
+
hint: "Enable it here for this session, or use Setup to manage session and global tool defaults.",
|
|
37177
|
+
};
|
|
37178
|
+
if (detected && managedWithTools) return { label: "Enabled", className: "enabled", detail: doneDetail || `Tool access is enabled for the active Pi session${versionSuffix}`, hint: "Use Setup to manage session and global tool defaults.", command: installState?.command || "" };
|
|
37091
37179
|
if (detected && !disabled) return { label: "Enabled", className: "enabled", detail: doneDetail || `Detected and enabled in Web UI${versionSuffix}`, command: installState?.command || "" };
|
|
37092
37180
|
if (detected && disabled) return { label: "Disabled", className: "disabled", detail: `Detected, but disabled in Web UI${versionSuffix}` };
|
|
37093
37181
|
if (packageStatus?.locallyConfigured) return { label: "Available locally", className: "installed", detail: doneDetail || `Enabled as a top-level Pi resource; reload this tab if the capability is not detected yet${versionSuffix}` };
|
|
@@ -37243,9 +37331,64 @@ function renderOptionalFeatureSection(section, features) {
|
|
|
37243
37331
|
elements.optionalFeaturesBox.append(sectionNode);
|
|
37244
37332
|
}
|
|
37245
37333
|
|
|
37334
|
+
function optionalFeatureSetupAvailable(feature) {
|
|
37335
|
+
switch (feature?.setup) {
|
|
37336
|
+
case "git-workflow": return hasAvailableCommand("git-workflow-setup");
|
|
37337
|
+
case "workflows": return hasLoadedRpcCommand("workflow-setup");
|
|
37338
|
+
case "safety-guard": return hasAvailableCommand("safety-guard-setup");
|
|
37339
|
+
case "tools": return feature.manageWith !== "tools" || isOptionalFeatureDetected(feature.id);
|
|
37340
|
+
default: return false;
|
|
37341
|
+
}
|
|
37342
|
+
}
|
|
37343
|
+
|
|
37344
|
+
function openOptionalFeatureSetup(feature) {
|
|
37345
|
+
switch (feature?.setup) {
|
|
37346
|
+
case "git-workflow": return openNativeGitWorkflowSetupDialog();
|
|
37347
|
+
case "workflows": return openNativeWorkflowSetupDialog();
|
|
37348
|
+
case "safety-guard": return openNativeSafetyGuardSetupDialog();
|
|
37349
|
+
case "tools": return openNativeToolsSelector();
|
|
37350
|
+
default: return undefined;
|
|
37351
|
+
}
|
|
37352
|
+
}
|
|
37353
|
+
|
|
37354
|
+
async function setToolManagedOptionalFeatureEnabled(feature, enabled) {
|
|
37355
|
+
const toolName = feature?.manageWith === "tools" ? String(feature.managedToolName || feature.id) : "";
|
|
37356
|
+
const tabContext = activeTabContext();
|
|
37357
|
+
if (!toolName || !tabContext.tabId || optionalFeatureAccessInProgress.has(feature.id)) return;
|
|
37358
|
+
optionalFeatureAccessInProgress.add(feature.id);
|
|
37359
|
+
renderOptionalFeatureControls();
|
|
37360
|
+
try {
|
|
37361
|
+
const current = await api("/api/tools?scope=session", { tabId: tabContext.tabId });
|
|
37362
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
37363
|
+
const tools = Array.isArray(current.data?.tools) ? current.data.tools : [];
|
|
37364
|
+
if (!tools.some((tool) => tool?.name === toolName)) throw new Error(`${toolName} is not available in this Pi tab`);
|
|
37365
|
+
const enabledTools = new Set(tools.filter((tool) => tool?.enabled !== false).map((tool) => tool.name));
|
|
37366
|
+
if (enabled) enabledTools.add(toolName);
|
|
37367
|
+
else enabledTools.delete(toolName);
|
|
37368
|
+
const response = await api("/api/tools", {
|
|
37369
|
+
method: "POST",
|
|
37370
|
+
body: { enabledTools: [...enabledTools], scope: "session" },
|
|
37371
|
+
tabId: tabContext.tabId,
|
|
37372
|
+
});
|
|
37373
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
37374
|
+
const nextTools = Array.isArray(response.data?.tools) ? response.data.tools : [];
|
|
37375
|
+
const nextTool = nextTools.find((tool) => tool?.name === toolName);
|
|
37376
|
+
optionalFeatureAvailability[feature.id] = !!nextTool;
|
|
37377
|
+
if (nextTool) optionalFeatureManagedAccessEnabled.set(feature.id, nextTool.enabled !== false);
|
|
37378
|
+
else optionalFeatureManagedAccessEnabled.delete(feature.id);
|
|
37379
|
+
addEvent(`${feature.label} was ${enabled ? "enabled" : "disabled"} for this session.`, "success");
|
|
37380
|
+
} catch (error) {
|
|
37381
|
+
if (isCurrentTabContext(tabContext)) addEvent(`${feature.label} access was not changed: ${error.message || String(error)}`, "error");
|
|
37382
|
+
} finally {
|
|
37383
|
+
optionalFeatureAccessInProgress.delete(feature.id);
|
|
37384
|
+
if (isCurrentTabContext(tabContext)) renderOptionalFeatureControls();
|
|
37385
|
+
}
|
|
37386
|
+
}
|
|
37387
|
+
|
|
37246
37388
|
function renderOptionalFeatureRow(feature) {
|
|
37247
37389
|
const detected = isOptionalFeatureDetected(feature.id);
|
|
37248
37390
|
const enabled = isOptionalFeatureEnabled(feature.id);
|
|
37391
|
+
const accessChanging = optionalFeatureAccessInProgress.has(feature.id);
|
|
37249
37392
|
const installState = optionalFeatureInstallState(feature.id);
|
|
37250
37393
|
const installing = optionalFeatureInstallInProgress.has(feature.id) || optionalFeatureInstallIsActive(installState);
|
|
37251
37394
|
const failed = installState?.phase === "failed";
|
|
@@ -37255,7 +37398,7 @@ function renderOptionalFeatureRow(feature) {
|
|
|
37255
37398
|
const tooltip = optionalFeatureTooltip(feature, status);
|
|
37256
37399
|
row.dataset.tooltip = tooltip;
|
|
37257
37400
|
row.setAttribute("aria-label", tooltip.replace(/\s+/g, " "));
|
|
37258
|
-
if (installing) row.setAttribute("aria-busy", "true");
|
|
37401
|
+
if (installing || accessChanging) row.setAttribute("aria-busy", "true");
|
|
37259
37402
|
row.tabIndex = 0;
|
|
37260
37403
|
|
|
37261
37404
|
const main = make("div", "optional-feature-main");
|
|
@@ -37285,8 +37428,11 @@ function renderOptionalFeatureRow(feature) {
|
|
|
37285
37428
|
const actions = make("div", "optional-feature-actions");
|
|
37286
37429
|
const action = make("button", "optional-feature-action");
|
|
37287
37430
|
action.type = "button";
|
|
37288
|
-
action.disabled = installing || optionalFeatureBatchIsActive() || (!optionalFeaturePackageStatusesLoaded && !detected);
|
|
37289
|
-
if (
|
|
37431
|
+
action.disabled = accessChanging || installing || optionalFeatureBatchIsActive() || (!optionalFeaturePackageStatusesLoaded && !detected);
|
|
37432
|
+
if (accessChanging) {
|
|
37433
|
+
action.textContent = enabled ? "Disabling…" : "Enabling…";
|
|
37434
|
+
action.setAttribute("aria-busy", "true");
|
|
37435
|
+
} else if (installing) {
|
|
37290
37436
|
action.textContent = installState?.actionLabel === "Update" ? "Updating…" : "Installing…";
|
|
37291
37437
|
action.setAttribute("aria-busy", "true");
|
|
37292
37438
|
} else if (failed) {
|
|
@@ -37294,9 +37440,6 @@ function renderOptionalFeatureRow(feature) {
|
|
|
37294
37440
|
action.textContent = "Retry…";
|
|
37295
37441
|
action.classList.add(retryAsUpdate ? "update" : "install");
|
|
37296
37442
|
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: retryAsUpdate }));
|
|
37297
|
-
} else if (isOptionalFeatureDisabled(feature.id)) {
|
|
37298
|
-
action.textContent = "Enable";
|
|
37299
|
-
action.addEventListener("click", () => setOptionalFeatureDisabled(feature.id, false));
|
|
37300
37443
|
} else if (packageStatus?.resourceConflict) {
|
|
37301
37444
|
action.textContent = "Conflict";
|
|
37302
37445
|
action.disabled = true;
|
|
@@ -37305,8 +37448,11 @@ function renderOptionalFeatureRow(feature) {
|
|
|
37305
37448
|
action.classList.add("update");
|
|
37306
37449
|
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: true }));
|
|
37307
37450
|
} else if (detected && feature.manageWith === "tools") {
|
|
37308
|
-
action.textContent = "
|
|
37309
|
-
action.addEventListener("click", () =>
|
|
37451
|
+
action.textContent = enabled ? "Disable" : "Enable";
|
|
37452
|
+
action.addEventListener("click", () => setToolManagedOptionalFeatureEnabled(feature, !enabled));
|
|
37453
|
+
} else if (isOptionalFeatureDisabled(feature.id)) {
|
|
37454
|
+
action.textContent = "Enable";
|
|
37455
|
+
action.addEventListener("click", () => setOptionalFeatureDisabled(feature.id, false));
|
|
37310
37456
|
} else if (detected) {
|
|
37311
37457
|
action.textContent = enabled ? "Disable" : "Enable";
|
|
37312
37458
|
action.addEventListener("click", async () => {
|
|
@@ -37344,6 +37490,14 @@ function renderOptionalFeatureRow(feature) {
|
|
|
37344
37490
|
action.addEventListener("click", () => installOptionalFeature(feature.id));
|
|
37345
37491
|
}
|
|
37346
37492
|
actions.append(action);
|
|
37493
|
+
if (detected && feature.setup) {
|
|
37494
|
+
const setup = make("button", "optional-feature-action setup", "Setup");
|
|
37495
|
+
setup.type = "button";
|
|
37496
|
+
setup.disabled = accessChanging || installing || optionalFeatureBatchIsActive() || !optionalFeatureSetupAvailable(feature);
|
|
37497
|
+
setup.setAttribute("aria-label", `Set up ${feature.label}`);
|
|
37498
|
+
setup.addEventListener("click", () => openOptionalFeatureSetup(feature));
|
|
37499
|
+
actions.append(setup);
|
|
37500
|
+
}
|
|
37347
37501
|
if (failed) {
|
|
37348
37502
|
const retryFailed = make("button", "optional-feature-action install", "Retry failed");
|
|
37349
37503
|
retryFailed.type = "button";
|
|
@@ -42269,11 +42423,8 @@ async function executeCommandPaletteItem(item = commandPaletteItems[commandPalet
|
|
|
42269
42423
|
}
|
|
42270
42424
|
}
|
|
42271
42425
|
|
|
42272
|
-
|
|
42273
|
-
|
|
42274
|
-
const results = await Promise.allSettled([
|
|
42275
|
-
refreshState(tabContext),
|
|
42276
|
-
refreshMessages(tabContext),
|
|
42426
|
+
function supplementalRefreshRequests(tabContext) {
|
|
42427
|
+
return [
|
|
42277
42428
|
refreshModels(tabContext),
|
|
42278
42429
|
refreshCommands(tabContext),
|
|
42279
42430
|
refreshNaturalConversationMode(tabContext),
|
|
@@ -42285,14 +42436,47 @@ async function refreshAll(tabContext = activeTabContext()) {
|
|
|
42285
42436
|
refreshNativeSettings(tabContext),
|
|
42286
42437
|
refreshNetworkStatus(),
|
|
42287
42438
|
refreshWebuiVersion(),
|
|
42288
|
-
]
|
|
42289
|
-
|
|
42439
|
+
];
|
|
42440
|
+
}
|
|
42441
|
+
|
|
42442
|
+
function reportRefreshFailures(results, prefix = "") {
|
|
42290
42443
|
for (const result of results) {
|
|
42291
|
-
if (result.status
|
|
42444
|
+
if (result.status !== "rejected") continue;
|
|
42445
|
+
addEvent(`${prefix}${result.reason?.message || String(result.reason)}`, "error");
|
|
42292
42446
|
}
|
|
42447
|
+
}
|
|
42448
|
+
|
|
42449
|
+
async function refreshAll(tabContext = activeTabContext()) {
|
|
42450
|
+
if (!tabContext.tabId) return;
|
|
42451
|
+
const results = await Promise.allSettled([
|
|
42452
|
+
refreshState(tabContext),
|
|
42453
|
+
refreshMessages(tabContext),
|
|
42454
|
+
...supplementalRefreshRequests(tabContext),
|
|
42455
|
+
]);
|
|
42456
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
42457
|
+
reportRefreshFailures(results);
|
|
42293
42458
|
resumeGitWorkflowForActiveTab(tabContext);
|
|
42294
42459
|
}
|
|
42295
42460
|
|
|
42461
|
+
function scheduleForegroundSupplementalRefresh(tabContext) {
|
|
42462
|
+
foregroundSupplementalRefreshCancel?.();
|
|
42463
|
+
const run = async () => {
|
|
42464
|
+
foregroundSupplementalRefreshCancel = null;
|
|
42465
|
+
if (document.visibilityState === "hidden" || !isCurrentTabContext(tabContext)) return;
|
|
42466
|
+
const results = await Promise.allSettled(supplementalRefreshRequests(tabContext));
|
|
42467
|
+
if (!isCurrentTabContext(tabContext)) return;
|
|
42468
|
+
reportRefreshFailures(results, "foreground refresh failed: ");
|
|
42469
|
+
resumeGitWorkflowForActiveTab(tabContext);
|
|
42470
|
+
};
|
|
42471
|
+
if (typeof globalThis.requestIdleCallback === "function") {
|
|
42472
|
+
const handle = globalThis.requestIdleCallback(run, { timeout: 1_200 });
|
|
42473
|
+
foregroundSupplementalRefreshCancel = () => globalThis.cancelIdleCallback?.(handle);
|
|
42474
|
+
} else {
|
|
42475
|
+
const handle = setTimeout(run, 250);
|
|
42476
|
+
foregroundSupplementalRefreshCancel = () => clearTimeout(handle);
|
|
42477
|
+
}
|
|
42478
|
+
}
|
|
42479
|
+
|
|
42296
42480
|
function ensureActiveEventStream(tabContext = activeTabContext()) {
|
|
42297
42481
|
if (!tabContext.tabId || !isCurrentTabContext(tabContext)) return;
|
|
42298
42482
|
if (!eventSource || eventSource.readyState === EventSource.CLOSED) connectEvents(tabContext);
|
|
@@ -42302,16 +42486,35 @@ async function reconcileForegroundState(reason = "resume") {
|
|
|
42302
42486
|
if (document.visibilityState === "hidden") return;
|
|
42303
42487
|
|
|
42304
42488
|
const wasAway = mobileConnectionState === "away";
|
|
42489
|
+
const transcriptCatchUpRequired = foregroundTranscriptCatchUpRequired;
|
|
42305
42490
|
mobileConnectionState = navigator.onLine === false ? "offline" : "reconnecting";
|
|
42306
42491
|
mobileConnectionLabel = mobileConnectionState === "offline" ? "Paused/offline" : "Reconnecting";
|
|
42307
42492
|
recordMobileDiagnostic("foreground reconcile", reason);
|
|
42308
42493
|
renderMobilePhoneExperience();
|
|
42309
42494
|
const tabResult = await Promise.allSettled([refreshTabs()]);
|
|
42310
42495
|
const tabContext = activeTabContext();
|
|
42311
|
-
ensureActiveEventStream(tabContext);
|
|
42312
42496
|
|
|
42313
42497
|
const results = [...tabResult];
|
|
42314
|
-
if (tabContext.tabId
|
|
42498
|
+
if (tabContext.tabId && transcriptCatchUpRequired) {
|
|
42499
|
+
const criticalResults = await Promise.allSettled([
|
|
42500
|
+
refreshState(tabContext),
|
|
42501
|
+
refreshMessages(tabContext, { authoritative: true }),
|
|
42502
|
+
]);
|
|
42503
|
+
results.push(...criticalResults);
|
|
42504
|
+
if (isCurrentTabContext(tabContext)) {
|
|
42505
|
+
if (foregroundTranscriptSuppressedEvents > 0) {
|
|
42506
|
+
recordMobileDiagnostic("foreground output coalesced", `${foregroundTranscriptSuppressedEvents} raw transcript updates replaced by one authoritative snapshot`);
|
|
42507
|
+
}
|
|
42508
|
+
backgroundReconnectSnapshotFresh = ![...tabResult, ...criticalResults].some((result) => result.status === "rejected");
|
|
42509
|
+
foregroundTranscriptCatchUpRequired = false;
|
|
42510
|
+
foregroundTranscriptSuppressedEvents = 0;
|
|
42511
|
+
ensureActiveEventStream(tabContext);
|
|
42512
|
+
scheduleForegroundSupplementalRefresh(tabContext);
|
|
42513
|
+
}
|
|
42514
|
+
} else if (tabContext.tabId) {
|
|
42515
|
+
ensureActiveEventStream(tabContext);
|
|
42516
|
+
results.push(...(await Promise.allSettled([refreshAll(tabContext)])));
|
|
42517
|
+
}
|
|
42315
42518
|
if (!isCurrentTabContext(tabContext)) return;
|
|
42316
42519
|
|
|
42317
42520
|
const failed = results.some((result) => result.status === "rejected");
|
|
@@ -43547,7 +43750,25 @@ const TRANSCRIPT_STREAM_BARRIER_EVENT_TYPES = new Set([
|
|
|
43547
43750
|
"pi_process_error",
|
|
43548
43751
|
]);
|
|
43549
43752
|
|
|
43753
|
+
function beginForegroundTranscriptCatchUp() {
|
|
43754
|
+
foregroundTranscriptCatchUpRequired = true;
|
|
43755
|
+
backgroundReconnectSnapshotFresh = false;
|
|
43756
|
+
streamOutputController.cancel();
|
|
43757
|
+
if (!eventSource) return;
|
|
43758
|
+
eventStreamPausedForBackground = true;
|
|
43759
|
+
const source = eventSource;
|
|
43760
|
+
eventSource = null;
|
|
43761
|
+
source.close();
|
|
43762
|
+
}
|
|
43763
|
+
|
|
43550
43764
|
function dispatchTranscriptStreamEvent(event) {
|
|
43765
|
+
const classification = classifyTranscriptStreamEvent(event);
|
|
43766
|
+
if (classification && (document.visibilityState === "hidden" || foregroundTranscriptCatchUpRequired)) {
|
|
43767
|
+
foregroundTranscriptCatchUpRequired = true;
|
|
43768
|
+
foregroundTranscriptSuppressedEvents += 1;
|
|
43769
|
+
streamOutputController.cancel();
|
|
43770
|
+
return true;
|
|
43771
|
+
}
|
|
43551
43772
|
return streamOutputController.dispatch(event, {
|
|
43552
43773
|
owner: transcriptStreamOwner(event?.tabId || activeTabId),
|
|
43553
43774
|
});
|
|
@@ -43598,6 +43819,10 @@ function handleEvent(event) {
|
|
|
43598
43819
|
switch (event.type) {
|
|
43599
43820
|
case "webui_connected": {
|
|
43600
43821
|
const connectedTabId = event.tabId || activeTabId;
|
|
43822
|
+
const resumedWithFreshSnapshot = eventStreamPausedForBackground && backgroundReconnectSnapshotFresh;
|
|
43823
|
+
eventStreamPausedForBackground = false;
|
|
43824
|
+
backgroundReconnectSnapshotFresh = false;
|
|
43825
|
+
if (resumedWithFreshSnapshot) foregroundReconnectSnapshotFreshUntil = performance.now() + 2_000;
|
|
43601
43826
|
clearFeatureDecisionStateForTab(connectedTabId, { render: true });
|
|
43602
43827
|
acceptOutputModeAcknowledgement(event);
|
|
43603
43828
|
setWebuiVersion(event.version);
|
|
@@ -43609,16 +43834,16 @@ function handleEvent(event) {
|
|
|
43609
43834
|
renderWidgets();
|
|
43610
43835
|
}
|
|
43611
43836
|
addEvent(`connected to ${event.tabTitle || "terminal"} for ${event.cwd}`);
|
|
43612
|
-
if (event.supervisorReplayGap === true) scheduleSupervisorContinuityRefresh(event, { gap: true });
|
|
43613
|
-
scheduleForegroundReconcile("event stream reconnect", 0);
|
|
43837
|
+
if (event.supervisorReplayGap === true && !resumedWithFreshSnapshot) scheduleSupervisorContinuityRefresh(event, { gap: true });
|
|
43838
|
+
if (!resumedWithFreshSnapshot) scheduleForegroundReconcile("event stream reconnect", 0);
|
|
43614
43839
|
break;
|
|
43615
43840
|
}
|
|
43616
43841
|
case "webui_supervisor_reconnected":
|
|
43617
43842
|
addEvent("reconnected to the running Pi session");
|
|
43618
|
-
scheduleSupervisorContinuityRefresh(event);
|
|
43843
|
+
if (performance.now() > foregroundReconnectSnapshotFreshUntil) scheduleSupervisorContinuityRefresh(event);
|
|
43619
43844
|
break;
|
|
43620
43845
|
case "webui_supervisor_replay_gap":
|
|
43621
|
-
scheduleSupervisorContinuityRefresh(event, { gap: true });
|
|
43846
|
+
if (performance.now() > foregroundReconnectSnapshotFreshUntil) scheduleSupervisorContinuityRefresh(event, { gap: true });
|
|
43622
43847
|
break;
|
|
43623
43848
|
case "webui_output_mode":
|
|
43624
43849
|
applyOutputModeControl(event, tabContext);
|
|
@@ -43964,7 +44189,7 @@ function connectEvents(tabContext = activeTabContext(), { requestedMode = "auto"
|
|
|
43964
44189
|
eventSource = source;
|
|
43965
44190
|
source.onopen = () => {
|
|
43966
44191
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
43967
|
-
refreshOptionalFeaturePackageStatuses().catch(() => {});
|
|
44192
|
+
if (!eventStreamPausedForBackground) refreshOptionalFeaturePackageStatuses().catch(() => {});
|
|
43968
44193
|
};
|
|
43969
44194
|
source.onmessage = (message) => {
|
|
43970
44195
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
@@ -45196,27 +45421,60 @@ function handleNativeAppShortcut(event) {
|
|
|
45196
45421
|
}
|
|
45197
45422
|
}
|
|
45198
45423
|
|
|
45199
|
-
// --- Transcript search (Ctrl/Cmd+F) ---
|
|
45424
|
+
// --- Transcript and live agent-output search (Ctrl/Cmd+F) ---
|
|
45425
|
+
const CHAT_SEARCH_MATCH_LIMIT = 10_000;
|
|
45200
45426
|
let chatSearchMatches = [];
|
|
45201
45427
|
let chatSearchIndex = -1;
|
|
45202
45428
|
let chatSearchTimer = null;
|
|
45429
|
+
let chatSearchRefreshTimer = null;
|
|
45203
45430
|
|
|
45204
45431
|
function chatSearchQueryText() {
|
|
45205
45432
|
return (elements.chatSearchInput?.value || "").trim().toLowerCase();
|
|
45206
45433
|
}
|
|
45207
45434
|
|
|
45435
|
+
function chatSearchRoot() {
|
|
45436
|
+
return elements.subagentTerminalView?.hidden === false ? elements.subagentTerminalTranscript : elements.chat;
|
|
45437
|
+
}
|
|
45438
|
+
|
|
45208
45439
|
function collectChatSearchMatches(query) {
|
|
45209
45440
|
if (!query) return [];
|
|
45210
45441
|
const matches = [];
|
|
45211
|
-
for (const bubble of
|
|
45442
|
+
for (const bubble of chatSearchRoot()?.querySelectorAll(".message") || []) {
|
|
45212
45443
|
if (bubble === runIndicatorBubble || bubble.classList.contains("runIndicator")) continue;
|
|
45213
|
-
|
|
45444
|
+
const text = (bubble.textContent || "").toLowerCase();
|
|
45445
|
+
let offset = 0;
|
|
45446
|
+
while (matches.length < CHAT_SEARCH_MATCH_LIMIT) {
|
|
45447
|
+
const start = text.indexOf(query, offset);
|
|
45448
|
+
if (start < 0) break;
|
|
45449
|
+
matches.push({ bubble, start, end: start + query.length });
|
|
45450
|
+
offset = start + query.length;
|
|
45451
|
+
}
|
|
45452
|
+
if (matches.length >= CHAT_SEARCH_MATCH_LIMIT) break;
|
|
45214
45453
|
}
|
|
45215
45454
|
return matches;
|
|
45216
45455
|
}
|
|
45217
45456
|
|
|
45218
45457
|
function clearChatSearchHighlights() {
|
|
45219
|
-
|
|
45458
|
+
globalThis.CSS?.highlights?.delete("chat-search-match");
|
|
45459
|
+
globalThis.CSS?.highlights?.delete("chat-search-current");
|
|
45460
|
+
for (const root of [elements.chat, elements.subagentTerminalTranscript]) {
|
|
45461
|
+
for (const bubble of root?.querySelectorAll(".message.search-match, .message.search-current") || []) bubble.classList.remove("search-match", "search-current");
|
|
45462
|
+
}
|
|
45463
|
+
}
|
|
45464
|
+
|
|
45465
|
+
function renderChatSearchHighlights() {
|
|
45466
|
+
clearChatSearchHighlights();
|
|
45467
|
+
const ranges = chatSearchMatches.map((match) => textOffsetRange(match.bubble, match)).filter(Boolean);
|
|
45468
|
+
const current = chatSearchMatches[chatSearchIndex];
|
|
45469
|
+
const currentRange = current ? textOffsetRange(current.bubble, current) : null;
|
|
45470
|
+
const HighlightConstructor = globalThis.Highlight;
|
|
45471
|
+
if (globalThis.CSS?.highlights && typeof HighlightConstructor === "function") {
|
|
45472
|
+
if (ranges.length) globalThis.CSS.highlights.set("chat-search-match", new HighlightConstructor(...ranges));
|
|
45473
|
+
if (currentRange) globalThis.CSS.highlights.set("chat-search-current", new HighlightConstructor(currentRange));
|
|
45474
|
+
return;
|
|
45475
|
+
}
|
|
45476
|
+
for (const match of chatSearchMatches) match.bubble.classList.add("search-match");
|
|
45477
|
+
current?.bubble.classList.add("search-current");
|
|
45220
45478
|
}
|
|
45221
45479
|
|
|
45222
45480
|
function updateChatSearchCount() {
|
|
@@ -45226,36 +45484,39 @@ function updateChatSearchCount() {
|
|
|
45226
45484
|
}
|
|
45227
45485
|
|
|
45228
45486
|
function focusChatSearchMatch() {
|
|
45229
|
-
const
|
|
45487
|
+
const match = chatSearchMatches[chatSearchIndex];
|
|
45488
|
+
const bubble = match?.bubble;
|
|
45230
45489
|
if (!bubble) return;
|
|
45231
45490
|
if (!bubble.isConnected) {
|
|
45232
45491
|
runChatSearch({ navigate: false });
|
|
45233
45492
|
return;
|
|
45234
45493
|
}
|
|
45235
|
-
clearChatSearchHighlights();
|
|
45236
|
-
bubble.classList.add("search-current");
|
|
45237
45494
|
const query = chatSearchQueryText();
|
|
45238
45495
|
for (const details of bubble.querySelectorAll("details")) {
|
|
45239
45496
|
if (!details.open && (details.textContent || "").toLowerCase().includes(query)) details.open = true;
|
|
45240
45497
|
}
|
|
45241
|
-
|
|
45242
|
-
|
|
45498
|
+
renderChatSearchHighlights();
|
|
45499
|
+
if (chatSearchRoot() === elements.chat) {
|
|
45500
|
+
autoFollowChat = false;
|
|
45501
|
+
lastChatProgrammaticScrollAt = performance.now();
|
|
45502
|
+
updateJumpToLatestButton();
|
|
45503
|
+
}
|
|
45243
45504
|
bubble.scrollIntoView({ block: "center", behavior: "instant" });
|
|
45244
|
-
updateJumpToLatestButton();
|
|
45245
45505
|
updateChatSearchCount();
|
|
45246
45506
|
}
|
|
45247
45507
|
|
|
45248
45508
|
function runChatSearch({ navigate = false } = {}) {
|
|
45249
45509
|
const query = chatSearchQueryText();
|
|
45250
|
-
clearChatSearchHighlights();
|
|
45251
45510
|
chatSearchMatches = collectChatSearchMatches(query);
|
|
45252
|
-
if (
|
|
45511
|
+
if (!chatSearchMatches.length) chatSearchIndex = -1;
|
|
45512
|
+
else if (chatSearchIndex >= chatSearchMatches.length || chatSearchIndex < 0) chatSearchIndex = chatSearchMatches.length - 1;
|
|
45253
45513
|
updateChatSearchCount();
|
|
45254
45514
|
if (navigate) focusChatSearchMatch();
|
|
45515
|
+
else renderChatSearchHighlights();
|
|
45255
45516
|
}
|
|
45256
45517
|
|
|
45257
45518
|
function stepChatSearch(step) {
|
|
45258
|
-
if (chatSearchMatches.some((
|
|
45519
|
+
if (chatSearchMatches.some((match) => !match.bubble.isConnected)) runChatSearch();
|
|
45259
45520
|
if (!chatSearchMatches.length) {
|
|
45260
45521
|
runChatSearch();
|
|
45261
45522
|
if (!chatSearchMatches.length) return;
|
|
@@ -45267,6 +45528,10 @@ function stepChatSearch(step) {
|
|
|
45267
45528
|
function openChatSearch() {
|
|
45268
45529
|
if (!elements.chatSearchBar) return;
|
|
45269
45530
|
closeFileViewerSearch({ restoreFocus: false });
|
|
45531
|
+
const searchesAgentOutput = chatSearchRoot() === elements.subagentTerminalTranscript;
|
|
45532
|
+
elements.chatSearchInput.placeholder = searchesAgentOutput ? "Search agent output…" : "Search transcript…";
|
|
45533
|
+
elements.chatSearchInput.setAttribute("aria-label", searchesAgentOutput ? "Search agent output" : "Search transcript");
|
|
45534
|
+
if (chatSearchRoot()?.id) elements.chatSearchInput.setAttribute("aria-controls", chatSearchRoot().id);
|
|
45270
45535
|
elements.chatSearchBar.hidden = false;
|
|
45271
45536
|
elements.chatSearchInput?.focus();
|
|
45272
45537
|
elements.chatSearchInput?.select();
|
|
@@ -45282,6 +45547,15 @@ function closeChatSearch() {
|
|
|
45282
45547
|
updateChatSearchCount();
|
|
45283
45548
|
}
|
|
45284
45549
|
|
|
45550
|
+
const chatSearchObserver = typeof MutationObserver === "function" ? new MutationObserver(() => {
|
|
45551
|
+
if (elements.chatSearchBar?.hidden || !chatSearchQueryText()) return;
|
|
45552
|
+
clearTimeout(chatSearchRefreshTimer);
|
|
45553
|
+
chatSearchRefreshTimer = setTimeout(() => runChatSearch({ navigate: false }), 50);
|
|
45554
|
+
}) : null;
|
|
45555
|
+
for (const root of [elements.chat, elements.subagentTerminalTranscript]) {
|
|
45556
|
+
if (root && chatSearchObserver) chatSearchObserver.observe(root, { childList: true, subtree: true, characterData: true });
|
|
45557
|
+
}
|
|
45558
|
+
|
|
45285
45559
|
elements.chatSearchInput?.addEventListener("input", () => {
|
|
45286
45560
|
clearTimeout(chatSearchTimer);
|
|
45287
45561
|
chatSearchTimer = setTimeout(() => {
|
|
@@ -45316,6 +45590,7 @@ document.addEventListener("visibilitychange", () => {
|
|
|
45316
45590
|
scheduleForegroundReconcile("visibility resume", 0);
|
|
45317
45591
|
refreshSubagents().finally(() => scheduleRefreshSubagents());
|
|
45318
45592
|
} else {
|
|
45593
|
+
beginForegroundTranscriptCatchUp();
|
|
45319
45594
|
mobileConnectionState = "away";
|
|
45320
45595
|
mobileConnectionLabel = "Backgrounded · run state unverified";
|
|
45321
45596
|
persistMobileContinuityState();
|
|
@@ -45637,6 +45912,7 @@ elements.fileViewerSearchInput?.addEventListener("keydown", (event) => {
|
|
|
45637
45912
|
elements.fileViewerSearchPrevButton?.addEventListener("click", () => stepFileViewerSearch(-1));
|
|
45638
45913
|
elements.fileViewerSearchNextButton?.addEventListener("click", () => stepFileViewerSearch(1));
|
|
45639
45914
|
elements.fileViewerSearchCloseButton?.addEventListener("click", () => closeFileViewerSearch());
|
|
45915
|
+
elements.fileViewerEditor?.addEventListener("scroll", syncFileViewerSearchOverlayScroll);
|
|
45640
45916
|
elements.fileViewerEditor?.addEventListener("input", () => {
|
|
45641
45917
|
if (!activeFileViewer) return;
|
|
45642
45918
|
activeFileViewer.content = elements.fileViewerEditor.value || "";
|