@firstpick/pi-package-webui 0.8.5 → 0.8.6
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 +23 -1
- package/bin/pi-webui.mjs +375 -30
- package/index.ts +8 -1
- package/lib/git-workflow-preferences.mjs +3 -0
- package/lib/session-summary-core.mjs +4 -3
- package/lib/trust-boundaries.mjs +13 -0
- package/lib/workspace-session-summaries.mjs +400 -0
- package/package.json +2 -2
- package/public/app.js +1197 -267
- package/public/index.html +76 -3
- package/public/service-worker.js +3 -1
- package/public/stream-output-controller.mjs +327 -0
- package/public/styles.css +249 -70
- package/public/theme-contract.mjs +244 -0
- package/session-summary.ts +164 -4
- package/tests/aur-review-widget-static.test.mjs +2 -1
- package/tests/browser/interaction-continuity.spec.mjs +2 -2
- package/tests/browser/session-summary.spec.mjs +131 -3
- package/tests/browser/stream-output-isolation.spec.mjs +510 -0
- package/tests/codex-fast-mode-static.test.mjs +1 -1
- package/tests/composer-action-grid-reorder-static.test.mjs +1 -1
- package/tests/fast-mode-client-static.test.mjs +2 -1
- package/tests/fixtures/fake-pi.mjs +203 -2
- package/tests/git-workflow-preferences.test.mjs +7 -1
- package/tests/guided-git-aur-review.test.mjs +4 -3
- package/tests/http-endpoints-harness.test.mjs +207 -6
- package/tests/mobile-continuity-tablet-static.test.mjs +1 -1
- package/tests/mobile-foundation-static.test.mjs +2 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +62 -29
- package/tests/native-parity.test.mjs +1 -1
- package/tests/open-issue-wizard-static.test.mjs +2 -3
- package/tests/persistent-ui-layout-static.test.mjs +1 -1
- package/tests/questionnaire-dialog.test.mjs +1 -1
- package/tests/remote-auth-settings-harness.test.mjs +9 -0
- package/tests/session-summary-core.test.mjs +183 -1
- package/tests/side-panel-section-reorder-static.test.mjs +1 -1
- package/tests/stream-lifecycle-core.test.mjs +134 -0
- package/tests/stream-output-controller.test.mjs +252 -0
- package/tests/stream-output-isolation-static.test.mjs +89 -0
- package/tests/streaming-ui-coupling.test.mjs +50 -0
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/theme-contract.test.mjs +104 -0
- package/tests/theme-customizer-static.test.mjs +82 -0
- package/tests/theme-scheme-mode.test.mjs +15 -0
- package/tests/workspace-session-summaries.test.mjs +288 -0
package/public/app.js
CHANGED
|
@@ -9,6 +9,8 @@ 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";
|
|
13
|
+
import { PI_THEME_EXPORT_FIELDS, THEME_TOKEN_GROUPS, canonicalizeTheme, serializeTheme, themeColorToRgb, validateTheme } from "./theme-contract.mjs";
|
|
12
14
|
|
|
13
15
|
const $ = (selector) => document.querySelector(selector);
|
|
14
16
|
|
|
@@ -18,9 +20,7 @@ const elements = {
|
|
|
18
20
|
webuiDevBadge: $("#webuiDevBadge"),
|
|
19
21
|
tabBar: $("#tabBar"),
|
|
20
22
|
terminalTabsToggleButton: $("#terminalTabsToggleButton"),
|
|
21
|
-
splitTabButton: $("#splitTabButton"),
|
|
22
23
|
workspaceSaveButton: $("#workspaceSaveButton"),
|
|
23
|
-
summaryHeaderButton: $("#summaryHeaderButton"),
|
|
24
24
|
newTabMenu: $("#newTabMenu"),
|
|
25
25
|
newTabButton: $("#newTabButton"),
|
|
26
26
|
newTabMenuPanel: $("#newTabMenuPanel"),
|
|
@@ -140,7 +140,6 @@ const elements = {
|
|
|
140
140
|
remoteMicStreamingConsentButton: $("#remoteMicStreamingConsentButton"),
|
|
141
141
|
newSessionButton: $("#newSessionButton"),
|
|
142
142
|
compactButton: $("#compactButton"),
|
|
143
|
-
summaryActionButton: $("#summaryActionButton"),
|
|
144
143
|
workflowModeControls: $("#workflowModeControls"),
|
|
145
144
|
workflowModeButton: $("#workflowModeButton"),
|
|
146
145
|
workflowOverlayOpenButton: $("#workflowOverlayOpenButton"),
|
|
@@ -218,6 +217,26 @@ const elements = {
|
|
|
218
217
|
themeSearchResults: $("#themeSearchResults"),
|
|
219
218
|
themeSelect: $("#themeSelect"),
|
|
220
219
|
themeSchemeToggle: $("#themeSchemeToggle"),
|
|
220
|
+
themeCustomizeButton: $("#themeCustomizeButton"),
|
|
221
|
+
themeCustomizerDialog: $("#themeCustomizerDialog"),
|
|
222
|
+
themeCustomizerName: $("#themeCustomizerName"),
|
|
223
|
+
themeCustomizerScope: $("#themeCustomizerScope"),
|
|
224
|
+
themeCustomizerProjectOption: $("#themeCustomizerProjectOption"),
|
|
225
|
+
themeCustomizerScopeHint: $("#themeCustomizerScopeHint"),
|
|
226
|
+
themeCustomizerSourceBadge: $("#themeCustomizerSourceBadge"),
|
|
227
|
+
themeCustomizerVisualFields: $("#themeCustomizerVisualFields"),
|
|
228
|
+
themeCustomizerThinkingMax: $("#themeCustomizerThinkingMax"),
|
|
229
|
+
themeCustomizerVars: $("#themeCustomizerVars"),
|
|
230
|
+
themeCustomizerExportFields: $("#themeCustomizerExportFields"),
|
|
231
|
+
themeCustomizerJson: $("#themeCustomizerJson"),
|
|
232
|
+
themeCustomizerPreview: $("#themeCustomizerPreview"),
|
|
233
|
+
themeCustomizerStatus: $("#themeCustomizerStatus"),
|
|
234
|
+
themeCustomizerOverwrite: $("#themeCustomizerOverwrite"),
|
|
235
|
+
themeCustomizerOverwriteMessage: $("#themeCustomizerOverwriteMessage"),
|
|
236
|
+
themeCustomizerOverwriteButton: $("#themeCustomizerOverwriteButton"),
|
|
237
|
+
themeCustomizerCancelButton: $("#themeCustomizerCancelButton"),
|
|
238
|
+
themeCustomizerResetButton: $("#themeCustomizerResetButton"),
|
|
239
|
+
themeCustomizerSaveButton: $("#themeCustomizerSaveButton"),
|
|
221
240
|
backgroundInput: $("#backgroundInput"),
|
|
222
241
|
backgroundChooseButton: $("#backgroundChooseButton"),
|
|
223
242
|
backgroundClearButton: $("#backgroundClearButton"),
|
|
@@ -543,8 +562,6 @@ let streamThinkingRawText = "";
|
|
|
543
562
|
let streamDerivedTextCache = { rawText: null, assistantText: "", thinkingFormat: null, finalText: "" };
|
|
544
563
|
let streamBubbleVisibleSince = 0;
|
|
545
564
|
let streamBubbleHideTimer = null;
|
|
546
|
-
let streamTextRenderTimer = null;
|
|
547
|
-
let streamTextRenderFrame = null;
|
|
548
565
|
let streamToolCallSeen = false;
|
|
549
566
|
let streamToolCallBubble = null;
|
|
550
567
|
let streamToolCallText = null;
|
|
@@ -568,6 +585,97 @@ let outputModeAcknowledged = false;
|
|
|
568
585
|
let eventSourceOutputModeRequest = "auto";
|
|
569
586
|
let eventSourceOutputModeFallbackAttempted = false;
|
|
570
587
|
const compactLiveScheduler = createSustainedFlushScheduler({ flush: () => flushCompactLiveOutput() });
|
|
588
|
+
const STREAM_ISOLATION_DEBUG_LIMIT = 4096;
|
|
589
|
+
const STREAM_ISOLATION_DEBUG_ENABLED = globalThis.__PI_STREAM_ISOLATION_DEBUG__ === true
|
|
590
|
+
|| new URLSearchParams(window.location.search).get("streamIsolationDebug") === "1";
|
|
591
|
+
const streamIsolationDebugLedger = STREAM_ISOLATION_DEBUG_ENABLED ? {
|
|
592
|
+
version: 1,
|
|
593
|
+
counters: {
|
|
594
|
+
receivedEvents: 0,
|
|
595
|
+
appliedEvents: 0,
|
|
596
|
+
sinkCalls: 0,
|
|
597
|
+
batches: 0,
|
|
598
|
+
barriers: 0,
|
|
599
|
+
overflows: 0,
|
|
600
|
+
unknownEvents: 0,
|
|
601
|
+
staleEvents: 0,
|
|
602
|
+
highWaterPendingCount: 0,
|
|
603
|
+
highWaterPendingBytes: 0,
|
|
604
|
+
},
|
|
605
|
+
receivedIndexes: [],
|
|
606
|
+
appliedIndexes: [],
|
|
607
|
+
records: [],
|
|
608
|
+
unknownEvidence: [],
|
|
609
|
+
} : null;
|
|
610
|
+
const UNKNOWN_TRANSCRIPT_EVIDENCE_LIMIT = 32;
|
|
611
|
+
const UNKNOWN_TRANSCRIPT_EVIDENCE_TEXT_LIMIT = 512;
|
|
612
|
+
const unknownTranscriptEvidence = [];
|
|
613
|
+
const unknownTranscriptOwnersPendingReconcile = new Set();
|
|
614
|
+
|
|
615
|
+
function appendBoundedStreamDiagnostic(list, value, limit = STREAM_ISOLATION_DEBUG_LIMIT) {
|
|
616
|
+
list.push(value);
|
|
617
|
+
if (list.length > limit) list.splice(0, list.length - limit);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function recordStreamIsolationDiagnostic(record) {
|
|
621
|
+
const ledger = streamIsolationDebugLedger;
|
|
622
|
+
if (!ledger || !record) return;
|
|
623
|
+
const counters = ledger.counters;
|
|
624
|
+
if (record.type === "receipt") {
|
|
625
|
+
counters.receivedEvents += 1;
|
|
626
|
+
if (Number.isSafeInteger(record.index)) appendBoundedStreamDiagnostic(ledger.receivedIndexes, record.index);
|
|
627
|
+
} else if (record.type === "apply") {
|
|
628
|
+
if (record.applied) {
|
|
629
|
+
counters.appliedEvents += Number(record.sourceCount) || 0;
|
|
630
|
+
counters.sinkCalls += 1;
|
|
631
|
+
for (const index of record.sourceIndexes || []) {
|
|
632
|
+
if (Number.isSafeInteger(index)) appendBoundedStreamDiagnostic(ledger.appliedIndexes, index);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (record.kind === "unknown-message-update") counters.unknownEvents += Number(record.sourceCount) || 1;
|
|
636
|
+
} else if (record.type === "batch") {
|
|
637
|
+
counters.batches += 1;
|
|
638
|
+
} else if (record.type === "barrier") {
|
|
639
|
+
counters.barriers += 1;
|
|
640
|
+
} else if (record.type === "overflow") {
|
|
641
|
+
counters.overflows += 1;
|
|
642
|
+
} else if (record.type === "stale") {
|
|
643
|
+
counters.staleEvents += 1;
|
|
644
|
+
}
|
|
645
|
+
if (record.type === "queued") {
|
|
646
|
+
counters.highWaterPendingCount = Math.max(counters.highWaterPendingCount, Number(record.pendingCount) || 0);
|
|
647
|
+
counters.highWaterPendingBytes = Math.max(counters.highWaterPendingBytes, Number(record.pendingBytes) || 0);
|
|
648
|
+
}
|
|
649
|
+
appendBoundedStreamDiagnostic(ledger.records, {
|
|
650
|
+
...record,
|
|
651
|
+
sourceIndexes: Array.isArray(record.sourceIndexes) ? [...record.sourceIndexes] : undefined,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
if (streamIsolationDebugLedger) {
|
|
656
|
+
Object.defineProperty(globalThis, "__piStreamIsolationDebug", {
|
|
657
|
+
configurable: true,
|
|
658
|
+
enumerable: false,
|
|
659
|
+
value: streamIsolationDebugLedger,
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const streamOutputController = createStreamOutputController({
|
|
664
|
+
isOwnerCurrent: (owner) => owner === transcriptStreamOwner(),
|
|
665
|
+
applyTextUpdate: (event) => handleMessageUpdate(event),
|
|
666
|
+
applyThinkingUpdate: (event) => handleMessageUpdate(event),
|
|
667
|
+
applyToolCallUpdate: (event) => handleMessageUpdate(event),
|
|
668
|
+
applyToolExecutionUpdate: (event) => {
|
|
669
|
+
if (!compactOutputActive()) applyTranscriptToolExecutionUpdate(event);
|
|
670
|
+
},
|
|
671
|
+
applyStreamError: (event) => handleMessageUpdate(event),
|
|
672
|
+
applyFollowScroll: () => {
|
|
673
|
+
if (compactOutputActive()) flushCompactLiveOutput();
|
|
674
|
+
scheduleChatFollowScroll();
|
|
675
|
+
},
|
|
676
|
+
onUnknownStreamEvent: preserveUnknownTranscriptEvidence,
|
|
677
|
+
onDiagnostic: streamIsolationDebugLedger ? recordStreamIsolationDiagnostic : undefined,
|
|
678
|
+
});
|
|
571
679
|
let assistantErrorSurfacedThisRun = false;
|
|
572
680
|
let runIndicatorBubble = null;
|
|
573
681
|
let runIndicatorText = null;
|
|
@@ -577,6 +685,29 @@ let runIndicatorRenderFrame = null;
|
|
|
577
685
|
let runIndicatorRenderScroll = false;
|
|
578
686
|
let runIndicatorGraceCheckTimer = null;
|
|
579
687
|
let runIndicatorLastStateCheckAt = 0;
|
|
688
|
+
// Lifecycle ownership is deliberately separate from the transcript-owned
|
|
689
|
+
// activity label: the transcript ticker only repaints its own elapsed-time
|
|
690
|
+
// node, while this watchdog owns the low-frequency canonical state recheck.
|
|
691
|
+
let lifecycleStateWatchdogTimer = null;
|
|
692
|
+
let lifecycleComposerSignature = null;
|
|
693
|
+
// Bounded dedupe of semantic tool-boundary records (skill tags, event log),
|
|
694
|
+
// partitioned by agent-run epoch so provider tool IDs may be reused next turn.
|
|
695
|
+
const TOOL_BOUNDARY_RECORD_LIMIT = 400;
|
|
696
|
+
const recordedToolBoundaryKeys = new Set();
|
|
697
|
+
const toolBoundaryRunEpochByTab = new Map();
|
|
698
|
+
// Dirty flags owned by the coalesced semantic reconciler. Requests remain
|
|
699
|
+
// partitioned by originating tab generation; raw stream deltas never reach it.
|
|
700
|
+
const SEMANTIC_RECONCILE_FLAGS = Object.freeze([
|
|
701
|
+
"messages",
|
|
702
|
+
"state",
|
|
703
|
+
"footer",
|
|
704
|
+
"footerData",
|
|
705
|
+
"feedback",
|
|
706
|
+
"usage",
|
|
707
|
+
"workflow",
|
|
708
|
+
]);
|
|
709
|
+
const semanticReconcilePending = new Map();
|
|
710
|
+
let semanticReconcileFrame = null;
|
|
580
711
|
let runIndicatorLocallyActive = false;
|
|
581
712
|
let runIndicatorRemovalDeferred = false;
|
|
582
713
|
let runIndicatorStartedAt = null;
|
|
@@ -624,6 +755,7 @@ let nativeCommandTabId = null;
|
|
|
624
755
|
let nativeSettingsDirty = false;
|
|
625
756
|
let sessionSummaryOverlayTabId = null;
|
|
626
757
|
let sessionSummaryOverlayFocusReturn = null;
|
|
758
|
+
let sessionSummaryOverlayFocusReturnKey = "";
|
|
627
759
|
const sessionSummaryByTab = new Map();
|
|
628
760
|
let pathPickerState = null;
|
|
629
761
|
let firstTerminalCwdPromptShown = false;
|
|
@@ -656,6 +788,7 @@ let optionsMenuOpen = false;
|
|
|
656
788
|
let availableCommands = [];
|
|
657
789
|
let rawAvailableCommands = [];
|
|
658
790
|
const commandCatalogsByTab = new Map();
|
|
791
|
+
const commandCatalogRefreshesByTab = new Map();
|
|
659
792
|
let commandSuggestions = [];
|
|
660
793
|
let pathSuggestions = [];
|
|
661
794
|
let bangSuggestions = [];
|
|
@@ -787,9 +920,6 @@ let chatFollowFrame = null;
|
|
|
787
920
|
let chatFollowSettleTimer = null;
|
|
788
921
|
let chatFollowNeedsSettle = false;
|
|
789
922
|
let liveWidgetRenderFrame = null;
|
|
790
|
-
let liveTodoProgressSyncFrame = null;
|
|
791
|
-
let liveTodoProgressPendingText = "";
|
|
792
|
-
let liveTodoProgressPendingTabId = null;
|
|
793
923
|
let lastChatProgrammaticScrollAt = 0;
|
|
794
924
|
let chatUserScrollIntentUntil = 0;
|
|
795
925
|
let chatUserScrollAwayIntentUntil = 0;
|
|
@@ -1020,6 +1150,9 @@ const THEME_LIGHT_DEFAULT = "catppuccin-latte";
|
|
|
1020
1150
|
const THEME_DARK_DEFAULT = "catppuccin-mocha";
|
|
1021
1151
|
const THEME_SCHEME_MODES = new Set(["light", "dark", "auto"]);
|
|
1022
1152
|
let themeSchemeMode = "light"; // "light" | "dark" | "auto"; finalized in initializeThemes
|
|
1153
|
+
let themeCatalogScopes = { global: { available: true }, project: { available: false, trusted: false } };
|
|
1154
|
+
let themeCustomizerGeneration = 0;
|
|
1155
|
+
let themeCustomizerState = null;
|
|
1023
1156
|
const TERMINAL_TABS_LAYOUTS = new Set(["top", "left"]);
|
|
1024
1157
|
const TERMINAL_TABS_LAYOUT_LABELS = { top: "Top bar", left: "Left sidebar" };
|
|
1025
1158
|
const SUBAGENT_OPEN_MODES = new Set(["overlay", "tab"]);
|
|
@@ -1054,9 +1187,7 @@ const ABORT_LONG_PRESS_TICK_MS = 100;
|
|
|
1054
1187
|
const ABORT_LONG_PRESS_RELEASE_GRACE_MS = 350;
|
|
1055
1188
|
const EMPTY_PROMPT_ESCAPE_AFTER_ABORT_GRACE_MS = 1000;
|
|
1056
1189
|
const STREAM_OUTPUT_HIDE_DELAY_MS = 300;
|
|
1057
|
-
const STREAM_OUTPUT_TOOLCALL_GUARD_MS = 220;
|
|
1058
1190
|
const STREAM_OUTPUT_MIN_VISIBLE_MS = 900;
|
|
1059
|
-
const TOOL_LIVE_UPDATE_THROTTLE_MS = 80;
|
|
1060
1191
|
const UNEXPOSED_THINKING_TEXT = "No thinking content was exposed by the provider.";
|
|
1061
1192
|
const THINKING_FORMAT_OPEN_TAG_REGEX = /^<think\b[^>]*>/i;
|
|
1062
1193
|
const THINKING_FORMAT_CLOSE_TAG_REGEX = /<\/think\s*>/i;
|
|
@@ -2204,8 +2335,6 @@ const appRunnerContextLineDraftByRun = new Map();
|
|
|
2204
2335
|
const scopedScrollContinuityByKey = new Map();
|
|
2205
2336
|
const liveToolRuns = new Map();
|
|
2206
2337
|
const liveToolCards = new Map();
|
|
2207
|
-
const liveToolRenderQueue = new Map();
|
|
2208
|
-
let liveToolRenderTimer = null;
|
|
2209
2338
|
// Optional feature detection intentionally checks loaded Pi capabilities (RPC-visible
|
|
2210
2339
|
// commands and live widget events), not npm package folders. This keeps local dev
|
|
2211
2340
|
// symlinks and independently installed packages working.
|
|
@@ -2884,7 +3013,7 @@ const gitFooterPayloadRefreshInFlightByTab = new Set();
|
|
|
2884
3013
|
const gitFooterPayloadStateByTab = new Map();
|
|
2885
3014
|
const gitFooterPayloadSettlementTimersByTab = new Map();
|
|
2886
3015
|
const gitFooterPayloadRequestSerialByTab = new Map();
|
|
2887
|
-
const
|
|
3016
|
+
const gitFooterSyncInFlightByTab = new Set();
|
|
2888
3017
|
const gitFooterPiCalibrationInFlightByTab = new Set();
|
|
2889
3018
|
let gitFooterVisibilityApplyInFlight = false;
|
|
2890
3019
|
let gitFooterVisibilityDirty = false;
|
|
@@ -5061,7 +5190,7 @@ function bindTerminalTabDragAndDrop(element, { sourceTabId = "", target = null }
|
|
|
5061
5190
|
element.draggable = true;
|
|
5062
5191
|
element.dataset.dragTabId = sourceTabId;
|
|
5063
5192
|
element.addEventListener("dragstart", (event) => {
|
|
5064
|
-
if (event.target?.closest?.(".terminal-tab-close, .terminal-tab-group-add")) {
|
|
5193
|
+
if (event.target?.closest?.(".terminal-tab-close, .terminal-tab-actions, .terminal-tab-group-add")) {
|
|
5065
5194
|
event.preventDefault();
|
|
5066
5195
|
return;
|
|
5067
5196
|
}
|
|
@@ -5602,29 +5731,31 @@ function trackSkillsFromText(tabId, text, { kind = "used", source = "" } = {}) {
|
|
|
5602
5731
|
}
|
|
5603
5732
|
|
|
5604
5733
|
function trackSkillsFromValue(tabId, value, { keyHint = "", kind = "used", source = "", depth = 0 } = {}) {
|
|
5605
|
-
if (!tabId || value === undefined || value === null || depth > 5) return;
|
|
5734
|
+
if (!tabId || value === undefined || value === null || depth > 5) return 0;
|
|
5606
5735
|
if (Array.isArray(value)) {
|
|
5607
|
-
|
|
5608
|
-
return;
|
|
5736
|
+
return value.reduce((count, item) => count + trackSkillsFromValue(tabId, item, { keyHint, kind, source, depth: depth + 1 }), 0);
|
|
5609
5737
|
}
|
|
5610
5738
|
if (typeof value === "string") {
|
|
5611
5739
|
const skillInfo = skillInfoFromPath(value);
|
|
5612
|
-
if (skillInfo)
|
|
5613
|
-
|
|
5740
|
+
if (!skillInfo) return 0;
|
|
5741
|
+
trackSkillUsage(tabId, skillInfo.name, "read", source, { path: skillInfo.path });
|
|
5742
|
+
return 1;
|
|
5614
5743
|
}
|
|
5615
|
-
if (typeof value !== "object") return;
|
|
5744
|
+
if (typeof value !== "object") return 0;
|
|
5745
|
+
let tracked = 0;
|
|
5616
5746
|
for (const [key, nested] of Object.entries(value)) {
|
|
5617
5747
|
const hint = String(key || "").toLowerCase();
|
|
5618
|
-
trackSkillsFromValue(tabId, nested, { keyHint: hint, kind, source, depth: depth + 1 });
|
|
5748
|
+
tracked += trackSkillsFromValue(tabId, nested, { keyHint: hint, kind, source, depth: depth + 1 });
|
|
5619
5749
|
}
|
|
5750
|
+
return tracked;
|
|
5620
5751
|
}
|
|
5621
5752
|
|
|
5622
5753
|
function trackSkillsFromToolInvocation(tabId, toolName, args, { sourcePrefix = "tool" } = {}) {
|
|
5623
|
-
if (!tabId) return;
|
|
5754
|
+
if (!tabId) return false;
|
|
5624
5755
|
const name = String(toolName || "").trim();
|
|
5625
|
-
if (name.toLowerCase() !== "read") return;
|
|
5756
|
+
if (name.toLowerCase() !== "read") return false;
|
|
5626
5757
|
const source = `${sourcePrefix}:${name}`;
|
|
5627
|
-
trackSkillsFromValue(tabId, args, { kind: "read", source });
|
|
5758
|
+
return trackSkillsFromValue(tabId, args, { kind: "read", source }) > 0;
|
|
5628
5759
|
}
|
|
5629
5760
|
|
|
5630
5761
|
function trackSkillsFromMessage(tabId, message) {
|
|
@@ -5651,26 +5782,67 @@ function assistantMessageUpdateType(event) {
|
|
|
5651
5782
|
return event?.assistantMessageEvent?.type || "";
|
|
5652
5783
|
}
|
|
5653
5784
|
|
|
5785
|
+
// Skill usage is recorded only at semantic tool boundaries. Argument/output
|
|
5786
|
+
// delta cadence (`toolcall_*`, `tool_execution_update`) must never enter skill
|
|
5787
|
+
// tracking: those raw fragments are transcript-owned stream content.
|
|
5654
5788
|
function eventMayAffectSkillUsage(event) {
|
|
5655
5789
|
const type = event?.type || "";
|
|
5656
|
-
return ["tool_execution_start", "
|
|
5657
|
-
|| (type === "message_update" && assistantMessageUpdateType(event) === "toolcall_start")
|
|
5790
|
+
return ["tool_execution_start", "tool_execution_end"].includes(type)
|
|
5658
5791
|
|| (type === "response" && event.command === "new_session");
|
|
5659
5792
|
}
|
|
5660
5793
|
|
|
5794
|
+
function beginToolBoundaryRun(event) {
|
|
5795
|
+
const tabId = event?.tabId || activeTabId || "";
|
|
5796
|
+
if (!tabId || event?.replayed === true) return;
|
|
5797
|
+
toolBoundaryRunEpochByTab.set(tabId, (toolBoundaryRunEpochByTab.get(tabId) || 0) + 1);
|
|
5798
|
+
}
|
|
5799
|
+
|
|
5800
|
+
function toolBoundaryRunIdentity(event, tabId) {
|
|
5801
|
+
const explicit = String(event?.agentRunId || event?.turnId || "").trim();
|
|
5802
|
+
return explicit || `epoch-${toolBoundaryRunEpochByTab.get(tabId) || 0}`;
|
|
5803
|
+
}
|
|
5804
|
+
|
|
5805
|
+
function toolBoundaryRecordKey(event, phase) {
|
|
5806
|
+
const tabId = event?.tabId || activeTabId || "";
|
|
5807
|
+
const toolCallId = String(event?.toolCallId || event?.id || "").trim();
|
|
5808
|
+
if (!toolCallId) return "";
|
|
5809
|
+
return `${tabId}:${toolBoundaryRunIdentity(event, tabId)}:${toolCallId}:${phase}`;
|
|
5810
|
+
}
|
|
5811
|
+
|
|
5812
|
+
function rememberToolBoundaryRecordKey(key) {
|
|
5813
|
+
if (!key || recordedToolBoundaryKeys.has(key)) return false;
|
|
5814
|
+
recordedToolBoundaryKeys.add(key);
|
|
5815
|
+
while (recordedToolBoundaryKeys.size > TOOL_BOUNDARY_RECORD_LIMIT) {
|
|
5816
|
+
const oldest = recordedToolBoundaryKeys.values().next().value;
|
|
5817
|
+
if (oldest === undefined) break;
|
|
5818
|
+
recordedToolBoundaryKeys.delete(oldest);
|
|
5819
|
+
}
|
|
5820
|
+
return true;
|
|
5821
|
+
}
|
|
5822
|
+
|
|
5823
|
+
// One record per tool boundary within an agent run. Redelivered or replayed
|
|
5824
|
+
// boundaries must not duplicate skill tags or event-log lines.
|
|
5825
|
+
function claimToolBoundaryRecord(event, phase) {
|
|
5826
|
+
const key = toolBoundaryRecordKey(event, phase);
|
|
5827
|
+
return key ? rememberToolBoundaryRecordKey(key) : true;
|
|
5828
|
+
}
|
|
5829
|
+
|
|
5661
5830
|
function trackSkillsFromEvent(event) {
|
|
5662
5831
|
const tabId = event?.tabId || activeTabId;
|
|
5663
5832
|
if (!tabId || !event) return;
|
|
5664
|
-
if (["tool_execution_start", "
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
const
|
|
5670
|
-
trackSkillsFromToolInvocation(tabId,
|
|
5833
|
+
if (["tool_execution_start", "tool_execution_end"].includes(event.type)) {
|
|
5834
|
+
// Start is preferred, but unusable start args do not consume the claim;
|
|
5835
|
+
// completion may still provide the authoritative invocation arguments.
|
|
5836
|
+
const key = toolBoundaryRecordKey(event, "skills");
|
|
5837
|
+
if (key && recordedToolBoundaryKeys.has(key)) return;
|
|
5838
|
+
const args = event.args ?? event.arguments ?? event.invocation?.args;
|
|
5839
|
+
const tracked = trackSkillsFromToolInvocation(tabId, event.toolName, args, { sourcePrefix: `event:${event.type}` });
|
|
5840
|
+
if (tracked && key) rememberToolBoundaryRecordKey(key);
|
|
5671
5841
|
return;
|
|
5672
5842
|
}
|
|
5673
5843
|
if (event.type === "response" && event.command === "new_session") {
|
|
5844
|
+
recordedToolBoundaryKeys.clear();
|
|
5845
|
+
toolBoundaryRunEpochByTab.delete(tabId);
|
|
5674
5846
|
clearSkillUsageForTab(tabId);
|
|
5675
5847
|
}
|
|
5676
5848
|
}
|
|
@@ -9270,7 +9442,6 @@ function renderOptionalFeatureDependentDisplays() {
|
|
|
9270
9442
|
renderWidgets();
|
|
9271
9443
|
renderStatus();
|
|
9272
9444
|
renderCommands();
|
|
9273
|
-
cancelStreamingAssistantTextRender();
|
|
9274
9445
|
cancelStreamBubbleHide();
|
|
9275
9446
|
streamBubble?.remove();
|
|
9276
9447
|
streamBubble = null;
|
|
@@ -9335,7 +9506,14 @@ function displayThemeName(name) {
|
|
|
9335
9506
|
}
|
|
9336
9507
|
|
|
9337
9508
|
function resolveThemeValue(theme, value, fallback, seen = new Set()) {
|
|
9338
|
-
|
|
9509
|
+
if (Number.isInteger(value)) {
|
|
9510
|
+
try {
|
|
9511
|
+
return themeColorToRgb(value, theme?.vars || {}, fallback);
|
|
9512
|
+
} catch {
|
|
9513
|
+
return fallback;
|
|
9514
|
+
}
|
|
9515
|
+
}
|
|
9516
|
+
const raw = String(value ?? "").trim();
|
|
9339
9517
|
if (!raw) return fallback;
|
|
9340
9518
|
if (/^(#|rgb\(|rgba\(|hsl\(|hsla\()/i.test(raw)) return raw;
|
|
9341
9519
|
if (seen.has(raw)) return fallback;
|
|
@@ -9646,7 +9824,10 @@ function renderThemeSearchResults(themes = []) {
|
|
|
9646
9824
|
button.title = themeSearchText(theme);
|
|
9647
9825
|
const title = make("span", "theme-search-result-title");
|
|
9648
9826
|
title.append(make("span", "model-search-result-main", themeDisplayLabel(theme)));
|
|
9649
|
-
|
|
9827
|
+
const badges = make("span", "theme-search-result-badges");
|
|
9828
|
+
badges.append(make("span", `theme-search-result-scheme ${themeIsLight(theme) ? "light" : "dark"}`, themeIsLight(theme) ? "Light" : "Dark"));
|
|
9829
|
+
if (theme.custom) badges.append(make("span", `theme-scope-badge ${theme.scope}`, themeScopeLabel(theme.scope)));
|
|
9830
|
+
title.append(badges);
|
|
9650
9831
|
button.append(title);
|
|
9651
9832
|
button.addEventListener("click", () => {
|
|
9652
9833
|
if (elements.themeSelect) elements.themeSelect.value = theme.name;
|
|
@@ -9696,6 +9877,422 @@ function toggleThemeSearchInput() {
|
|
|
9696
9877
|
else hideThemeSearchInput();
|
|
9697
9878
|
}
|
|
9698
9879
|
|
|
9880
|
+
function themeScopeLabel(scope) {
|
|
9881
|
+
if (scope === "project") return "Project";
|
|
9882
|
+
if (scope === "global") return "Global";
|
|
9883
|
+
return "Bundled";
|
|
9884
|
+
}
|
|
9885
|
+
|
|
9886
|
+
function cloneThemeDraft(theme) {
|
|
9887
|
+
return JSON.parse(JSON.stringify(theme));
|
|
9888
|
+
}
|
|
9889
|
+
|
|
9890
|
+
function themeDraftFromCatalog(theme, name = theme?.name) {
|
|
9891
|
+
return {
|
|
9892
|
+
name,
|
|
9893
|
+
...(theme?.vars && Object.keys(theme.vars).length ? { vars: cloneThemeDraft(theme.vars) } : {}),
|
|
9894
|
+
colors: cloneThemeDraft(theme?.colors || {}),
|
|
9895
|
+
...(theme?.export && Object.keys(theme.export).length ? { export: cloneThemeDraft(theme.export) } : {}),
|
|
9896
|
+
};
|
|
9897
|
+
}
|
|
9898
|
+
|
|
9899
|
+
function themeCustomizerValue(raw) {
|
|
9900
|
+
const value = String(raw ?? "").trim();
|
|
9901
|
+
if (/^(?:0|[1-9]\d{0,2})$/.test(value)) return Number(value);
|
|
9902
|
+
return value;
|
|
9903
|
+
}
|
|
9904
|
+
|
|
9905
|
+
function themeCustomizerDraftSignature(state = themeCustomizerState) {
|
|
9906
|
+
if (!state?.validTheme) return "";
|
|
9907
|
+
return JSON.stringify({
|
|
9908
|
+
scope: elements.themeCustomizerScope?.value || "",
|
|
9909
|
+
fileName: `${elements.themeCustomizerName?.value.trim() || ""}.json`,
|
|
9910
|
+
theme: state.validTheme,
|
|
9911
|
+
});
|
|
9912
|
+
}
|
|
9913
|
+
|
|
9914
|
+
function setThemeCustomizerStatus(message, kind = "muted") {
|
|
9915
|
+
if (!elements.themeCustomizerStatus) return;
|
|
9916
|
+
const urgent = kind === "error";
|
|
9917
|
+
elements.themeCustomizerStatus.textContent = message;
|
|
9918
|
+
elements.themeCustomizerStatus.className = `theme-customizer-status ${kind}`;
|
|
9919
|
+
elements.themeCustomizerStatus.setAttribute("role", urgent ? "alert" : "status");
|
|
9920
|
+
elements.themeCustomizerStatus.setAttribute("aria-live", urgent ? "assertive" : "polite");
|
|
9921
|
+
}
|
|
9922
|
+
|
|
9923
|
+
function invalidateThemeCustomizerOverwrite() {
|
|
9924
|
+
if (themeCustomizerState) themeCustomizerState.overwrite = null;
|
|
9925
|
+
if (elements.themeCustomizerOverwrite) elements.themeCustomizerOverwrite.hidden = true;
|
|
9926
|
+
}
|
|
9927
|
+
|
|
9928
|
+
function updateThemeCustomizerActions() {
|
|
9929
|
+
const state = themeCustomizerState;
|
|
9930
|
+
const name = elements.themeCustomizerName?.value.trim() || "";
|
|
9931
|
+
const validName = /^[A-Za-z0-9][A-Za-z0-9._-]{0,74}$/.test(name) && !name.includes("..");
|
|
9932
|
+
const scope = elements.themeCustomizerScope?.value;
|
|
9933
|
+
const projectUnavailable = scope === "project" && !themeCatalogScopes.project?.trusted;
|
|
9934
|
+
if (elements.themeCustomizerSaveButton) {
|
|
9935
|
+
elements.themeCustomizerSaveButton.disabled = !state?.draftValid || !validName || projectUnavailable || !!state?.saving || !!state?.overwrite;
|
|
9936
|
+
elements.themeCustomizerSaveButton.textContent = state?.saving ? "Saving…" : "Save theme";
|
|
9937
|
+
}
|
|
9938
|
+
if (elements.themeCustomizerOverwriteButton) elements.themeCustomizerOverwriteButton.disabled = !!state?.saving;
|
|
9939
|
+
if (elements.themeCustomizerCancelButton) elements.themeCustomizerCancelButton.disabled = !!state?.saving;
|
|
9940
|
+
if (elements.themeCustomizerResetButton) elements.themeCustomizerResetButton.disabled = !!state?.saving;
|
|
9941
|
+
if (!validName) setThemeCustomizerStatus("Use 1–75 letters, numbers, dots, underscores, or hyphens; consecutive dots are not allowed.", "error");
|
|
9942
|
+
else if (projectUnavailable) setThemeCustomizerStatus("This project is not saved as trusted in Pi. Choose Global themes or trust the project in Pi first.", "warn");
|
|
9943
|
+
}
|
|
9944
|
+
|
|
9945
|
+
function themeCustomizerColor(theme, token) {
|
|
9946
|
+
try {
|
|
9947
|
+
return themeColorToRgb(theme.colors[token], theme.vars || {}, "#000000");
|
|
9948
|
+
} catch {
|
|
9949
|
+
return "#000000";
|
|
9950
|
+
}
|
|
9951
|
+
}
|
|
9952
|
+
|
|
9953
|
+
function renderThemeCustomizerVisualFields(theme) {
|
|
9954
|
+
const container = elements.themeCustomizerVisualFields;
|
|
9955
|
+
if (!container || !theme) return;
|
|
9956
|
+
const groups = THEME_TOKEN_GROUPS.map((group) => {
|
|
9957
|
+
const fieldset = make("fieldset", "theme-token-group");
|
|
9958
|
+
fieldset.dataset.themeTokenGroup = group.id;
|
|
9959
|
+
fieldset.append(make("legend", undefined, group.label));
|
|
9960
|
+
const grid = make("div", "theme-token-grid");
|
|
9961
|
+
for (const { name, label } of group.tokens) {
|
|
9962
|
+
const row = make("div", "theme-token-row");
|
|
9963
|
+
row.dataset.themeToken = name;
|
|
9964
|
+
const inputId = `theme-token-${name}`;
|
|
9965
|
+
const copy = document.createElement("label");
|
|
9966
|
+
copy.className = "theme-token-label";
|
|
9967
|
+
copy.htmlFor = inputId;
|
|
9968
|
+
copy.append(document.createTextNode(label), make("code", undefined, name));
|
|
9969
|
+
const swatch = document.createElement("input");
|
|
9970
|
+
swatch.className = "theme-token-swatch";
|
|
9971
|
+
swatch.type = "color";
|
|
9972
|
+
const value = document.createElement("input");
|
|
9973
|
+
value.id = inputId;
|
|
9974
|
+
value.className = "theme-token-value";
|
|
9975
|
+
value.type = "text";
|
|
9976
|
+
value.autocomplete = "off";
|
|
9977
|
+
value.spellcheck = false;
|
|
9978
|
+
value.value = String(theme.colors[name] ?? "");
|
|
9979
|
+
value.setAttribute("aria-label", `${label} value`);
|
|
9980
|
+
const swatchNote = make("span", "theme-token-swatch-note");
|
|
9981
|
+
const syncSwatch = () => {
|
|
9982
|
+
const raw = value.value.trim();
|
|
9983
|
+
const directValue = themeCustomizerValue(raw);
|
|
9984
|
+
const direct = /^#[0-9a-f]{6}$/i.test(raw) || (typeof directValue === "number" && directValue >= 0 && directValue <= 255);
|
|
9985
|
+
swatch.disabled = !direct;
|
|
9986
|
+
swatch.value = direct ? themeColorToRgb(directValue, {}, "#000000") : themeCustomizerColor(theme, name);
|
|
9987
|
+
swatch.setAttribute("aria-label", direct
|
|
9988
|
+
? `Choose ${label} color`
|
|
9989
|
+
: `${label} uses ${raw ? `variable ${raw}` : "the terminal default"}. Edit the raw value to replace it with a color.`);
|
|
9990
|
+
swatchNote.hidden = direct;
|
|
9991
|
+
swatchNote.textContent = raw ? `Variable ${raw}; edit the value to replace it.` : "Terminal default; edit the value to replace it.";
|
|
9992
|
+
};
|
|
9993
|
+
value.addEventListener("input", () => {
|
|
9994
|
+
syncSwatch();
|
|
9995
|
+
updateThemeCustomizerFromVisual();
|
|
9996
|
+
});
|
|
9997
|
+
swatch.addEventListener("input", () => {
|
|
9998
|
+
value.value = swatch.value;
|
|
9999
|
+
syncSwatch();
|
|
10000
|
+
updateThemeCustomizerFromVisual();
|
|
10001
|
+
});
|
|
10002
|
+
syncSwatch();
|
|
10003
|
+
row.append(copy, swatch, value, swatchNote);
|
|
10004
|
+
grid.append(row);
|
|
10005
|
+
}
|
|
10006
|
+
fieldset.append(grid);
|
|
10007
|
+
return fieldset;
|
|
10008
|
+
});
|
|
10009
|
+
container.replaceChildren(...groups);
|
|
10010
|
+
}
|
|
10011
|
+
|
|
10012
|
+
function renderThemeCustomizerOptionalFields(theme) {
|
|
10013
|
+
if (!theme) return;
|
|
10014
|
+
if (elements.themeCustomizerThinkingMax) elements.themeCustomizerThinkingMax.value = String(theme.colors.thinkingMax ?? "");
|
|
10015
|
+
if (elements.themeCustomizerVars) elements.themeCustomizerVars.value = JSON.stringify(theme.vars || {}, null, 2);
|
|
10016
|
+
if (elements.themeCustomizerExportFields) {
|
|
10017
|
+
const fields = PI_THEME_EXPORT_FIELDS.map((name) => {
|
|
10018
|
+
const label = document.createElement("label");
|
|
10019
|
+
label.textContent = name;
|
|
10020
|
+
const input = document.createElement("input");
|
|
10021
|
+
input.type = "text";
|
|
10022
|
+
input.autocomplete = "off";
|
|
10023
|
+
input.spellcheck = false;
|
|
10024
|
+
input.dataset.themeExport = name;
|
|
10025
|
+
input.value = String(theme.export?.[name] ?? "");
|
|
10026
|
+
input.addEventListener("input", updateThemeCustomizerFromVisual);
|
|
10027
|
+
label.append(input);
|
|
10028
|
+
return label;
|
|
10029
|
+
});
|
|
10030
|
+
elements.themeCustomizerExportFields.replaceChildren(...fields);
|
|
10031
|
+
}
|
|
10032
|
+
}
|
|
10033
|
+
|
|
10034
|
+
function themeCustomizerCandidateFromVisual() {
|
|
10035
|
+
const state = themeCustomizerState;
|
|
10036
|
+
if (!state?.validTheme) throw new Error("No valid theme draft is available.");
|
|
10037
|
+
const candidate = cloneThemeDraft(state.validTheme);
|
|
10038
|
+
candidate.name = elements.themeCustomizerName.value.trim();
|
|
10039
|
+
candidate.colors = { ...candidate.colors };
|
|
10040
|
+
for (const input of elements.themeCustomizerVisualFields.querySelectorAll("[data-theme-token] .theme-token-value")) {
|
|
10041
|
+
candidate.colors[input.closest("[data-theme-token]").dataset.themeToken] = themeCustomizerValue(input.value);
|
|
10042
|
+
}
|
|
10043
|
+
const thinkingMax = elements.themeCustomizerThinkingMax.value.trim();
|
|
10044
|
+
if (thinkingMax) candidate.colors.thinkingMax = themeCustomizerValue(thinkingMax);
|
|
10045
|
+
else delete candidate.colors.thinkingMax;
|
|
10046
|
+
let vars;
|
|
10047
|
+
try {
|
|
10048
|
+
vars = JSON.parse(elements.themeCustomizerVars.value || "{}");
|
|
10049
|
+
} catch (error) {
|
|
10050
|
+
throw new Error(`Variables JSON is invalid: ${error.message}`);
|
|
10051
|
+
}
|
|
10052
|
+
if (!vars || typeof vars !== "object" || Array.isArray(vars)) throw new Error("Variables must be a JSON object.");
|
|
10053
|
+
if (Object.keys(vars).length) candidate.vars = vars;
|
|
10054
|
+
else delete candidate.vars;
|
|
10055
|
+
const exportColors = {};
|
|
10056
|
+
for (const input of elements.themeCustomizerExportFields.querySelectorAll("[data-theme-export]")) {
|
|
10057
|
+
if (input.value.trim()) exportColors[input.dataset.themeExport] = themeCustomizerValue(input.value);
|
|
10058
|
+
}
|
|
10059
|
+
if (Object.keys(exportColors).length) candidate.export = exportColors;
|
|
10060
|
+
else delete candidate.export;
|
|
10061
|
+
return candidate;
|
|
10062
|
+
}
|
|
10063
|
+
|
|
10064
|
+
function acceptThemeCustomizerDraft(candidate, { syncJson = true, syncControls = false } = {}) {
|
|
10065
|
+
const state = themeCustomizerState;
|
|
10066
|
+
if (!state) return false;
|
|
10067
|
+
const validation = validateTheme(candidate, { allowWebuiExport: true });
|
|
10068
|
+
if (!validation.ok) {
|
|
10069
|
+
state.draftValid = false;
|
|
10070
|
+
invalidateThemeCustomizerOverwrite();
|
|
10071
|
+
setThemeCustomizerStatus(validation.issues.map(({ path, message }) => `${path}: ${message}`).join(" · "), "error");
|
|
10072
|
+
updateThemeCustomizerActions();
|
|
10073
|
+
return false;
|
|
10074
|
+
}
|
|
10075
|
+
const canonical = canonicalizeTheme(candidate, { allowWebuiExport: true });
|
|
10076
|
+
state.validTheme = canonical;
|
|
10077
|
+
state.draftValid = true;
|
|
10078
|
+
invalidateThemeCustomizerOverwrite();
|
|
10079
|
+
if (syncJson && elements.themeCustomizerJson) elements.themeCustomizerJson.value = serializeTheme(canonical, { allowWebuiExport: true });
|
|
10080
|
+
if (syncControls) {
|
|
10081
|
+
elements.themeCustomizerName.value = canonical.name;
|
|
10082
|
+
renderThemeCustomizerVisualFields(canonical);
|
|
10083
|
+
renderThemeCustomizerOptionalFields(canonical);
|
|
10084
|
+
}
|
|
10085
|
+
applyTheme(canonical, { persist: false });
|
|
10086
|
+
setThemeCustomizerStatus("Valid draft previewed. Nothing has been written to browser storage or disk.", "success");
|
|
10087
|
+
updateThemeCustomizerActions();
|
|
10088
|
+
return true;
|
|
10089
|
+
}
|
|
10090
|
+
|
|
10091
|
+
function updateThemeCustomizerFromVisual() {
|
|
10092
|
+
if (!themeCustomizerState) return;
|
|
10093
|
+
invalidateThemeCustomizerOverwrite();
|
|
10094
|
+
try {
|
|
10095
|
+
acceptThemeCustomizerDraft(themeCustomizerCandidateFromVisual(), { syncJson: true });
|
|
10096
|
+
} catch (error) {
|
|
10097
|
+
themeCustomizerState.draftValid = false;
|
|
10098
|
+
setThemeCustomizerStatus(error.message || String(error), "error");
|
|
10099
|
+
updateThemeCustomizerActions();
|
|
10100
|
+
}
|
|
10101
|
+
}
|
|
10102
|
+
|
|
10103
|
+
function updateThemeCustomizerFromJson() {
|
|
10104
|
+
if (!themeCustomizerState) return;
|
|
10105
|
+
invalidateThemeCustomizerOverwrite();
|
|
10106
|
+
let candidate;
|
|
10107
|
+
try {
|
|
10108
|
+
candidate = JSON.parse(elements.themeCustomizerJson.value);
|
|
10109
|
+
} catch (error) {
|
|
10110
|
+
themeCustomizerState.draftValid = false;
|
|
10111
|
+
setThemeCustomizerStatus(`Advanced JSON is invalid: ${error.message}. The last valid preview remains active.`, "error");
|
|
10112
|
+
updateThemeCustomizerActions();
|
|
10113
|
+
return;
|
|
10114
|
+
}
|
|
10115
|
+
acceptThemeCustomizerDraft(candidate, { syncJson: false, syncControls: true });
|
|
10116
|
+
}
|
|
10117
|
+
|
|
10118
|
+
function restoreThemeCustomizerOpeningState(generation) {
|
|
10119
|
+
const state = themeCustomizerState;
|
|
10120
|
+
if (!state || state.generation !== generation || state.restored) return;
|
|
10121
|
+
state.restored = true;
|
|
10122
|
+
applyTheme(state.opening.theme, { persist: false });
|
|
10123
|
+
setCustomBackgroundRecord(state.opening.background);
|
|
10124
|
+
customBackgroundLoading = false;
|
|
10125
|
+
applyCustomBackgroundOverride();
|
|
10126
|
+
renderThemeSelect();
|
|
10127
|
+
}
|
|
10128
|
+
|
|
10129
|
+
function closeThemeCustomizer({ restore = true } = {}) {
|
|
10130
|
+
const state = themeCustomizerState;
|
|
10131
|
+
if (!state) {
|
|
10132
|
+
if (elements.themeCustomizerDialog?.open) elements.themeCustomizerDialog.close();
|
|
10133
|
+
return;
|
|
10134
|
+
}
|
|
10135
|
+
if (state.saving) {
|
|
10136
|
+
setThemeCustomizerStatus("Wait for the theme save to finish before closing or switching tabs.", "warn");
|
|
10137
|
+
return false;
|
|
10138
|
+
}
|
|
10139
|
+
const generation = state.generation;
|
|
10140
|
+
state.closing = true;
|
|
10141
|
+
if (restore) restoreThemeCustomizerOpeningState(generation);
|
|
10142
|
+
themeCustomizerState = null;
|
|
10143
|
+
if (elements.themeCustomizerDialog?.open) elements.themeCustomizerDialog.close();
|
|
10144
|
+
return true;
|
|
10145
|
+
}
|
|
10146
|
+
|
|
10147
|
+
function themeCustomizerNameForSource(theme) {
|
|
10148
|
+
const raw = theme?.custom ? theme.name : `${theme?.name || "custom-theme"}-custom`;
|
|
10149
|
+
return raw.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^[^A-Za-z0-9]+/, "").slice(0, 75) || "custom-theme";
|
|
10150
|
+
}
|
|
10151
|
+
|
|
10152
|
+
function installThemeCatalog(data) {
|
|
10153
|
+
availableThemes = Array.isArray(data?.themes) ? data.themes : [];
|
|
10154
|
+
themeCatalogScopes = data?.scopes && typeof data.scopes === "object" ? data.scopes : themeCatalogScopes;
|
|
10155
|
+
optionalFeatureAvailability.themeBundle = availableThemes.length > 0;
|
|
10156
|
+
renderOptionalFeatureControls();
|
|
10157
|
+
renderThemeSelect();
|
|
10158
|
+
}
|
|
10159
|
+
|
|
10160
|
+
async function refreshThemeCatalog(tabContext = activeTabContext()) {
|
|
10161
|
+
const response = await api("/api/themes", { tabId: tabContext.tabId });
|
|
10162
|
+
if (tabContext.tabId && !isCurrentTabContext(tabContext)) return response.data;
|
|
10163
|
+
installThemeCatalog(response.data || {});
|
|
10164
|
+
return response.data || {};
|
|
10165
|
+
}
|
|
10166
|
+
|
|
10167
|
+
async function openThemeCustomizer() {
|
|
10168
|
+
if (!elements.themeCustomizerDialog || !availableThemes.length) return;
|
|
10169
|
+
const generation = ++themeCustomizerGeneration;
|
|
10170
|
+
const tabContext = activeTabContext();
|
|
10171
|
+
const openingTheme = availableThemes.find((theme) => theme.name === currentThemeName) || availableThemes[0];
|
|
10172
|
+
const opening = {
|
|
10173
|
+
theme: cloneThemeDraft(openingTheme),
|
|
10174
|
+
background: customBackground ? cloneThemeDraft(customBackground) : null,
|
|
10175
|
+
};
|
|
10176
|
+
themeCustomizerState = { generation, tabContext, opening, validTheme: null, draftValid: false, initialTheme: null, overwrite: null, saving: false, restored: false };
|
|
10177
|
+
setThemeCustomizerStatus("Loading project and global theme destinations…");
|
|
10178
|
+
try {
|
|
10179
|
+
await refreshThemeCatalog(tabContext);
|
|
10180
|
+
} catch (error) {
|
|
10181
|
+
if (themeCustomizerState?.generation === generation) setThemeCustomizerStatus(`Theme catalog refresh failed: ${error.message || String(error)}`, "warn");
|
|
10182
|
+
}
|
|
10183
|
+
if (themeCustomizerState?.generation !== generation) return;
|
|
10184
|
+
const source = availableThemes.find((theme) => theme.name === openingTheme.name) || openingTheme;
|
|
10185
|
+
const draft = canonicalizeTheme(themeDraftFromCatalog(source, themeCustomizerNameForSource(source)), { allowWebuiExport: true });
|
|
10186
|
+
themeCustomizerState.source = source;
|
|
10187
|
+
themeCustomizerState.initialTheme = cloneThemeDraft(draft);
|
|
10188
|
+
const projectTrusted = themeCatalogScopes.project?.trusted === true;
|
|
10189
|
+
elements.themeCustomizerProjectOption.disabled = !projectTrusted;
|
|
10190
|
+
elements.themeCustomizerScope.value = source.custom ? source.scope : projectTrusted ? "project" : "global";
|
|
10191
|
+
elements.themeCustomizerScopeHint.textContent = projectTrusted
|
|
10192
|
+
? "Project saves use this active trusted tab’s .pi/themes directory; global saves use Pi’s agent themes directory."
|
|
10193
|
+
: "This active project is not saved as trusted in Pi, so only Global themes is available.";
|
|
10194
|
+
elements.themeCustomizerSourceBadge.textContent = `${themeScopeLabel(source.scope)} source`;
|
|
10195
|
+
elements.themeCustomizerSourceBadge.className = `theme-scope-badge ${source.scope || "bundled"}`;
|
|
10196
|
+
elements.themeCustomizerName.value = draft.name;
|
|
10197
|
+
renderThemeCustomizerVisualFields(draft);
|
|
10198
|
+
renderThemeCustomizerOptionalFields(draft);
|
|
10199
|
+
elements.themeCustomizerJson.value = serializeTheme(draft, { allowWebuiExport: true });
|
|
10200
|
+
themeCustomizerState.validTheme = draft;
|
|
10201
|
+
themeCustomizerState.draftValid = true;
|
|
10202
|
+
invalidateThemeCustomizerOverwrite();
|
|
10203
|
+
applyTheme(draft, { persist: false });
|
|
10204
|
+
setThemeCustomizerStatus("Valid draft previewed. Nothing has been written to browser storage or disk.", "success");
|
|
10205
|
+
updateThemeCustomizerActions();
|
|
10206
|
+
if (!elements.themeCustomizerDialog.open) elements.themeCustomizerDialog.showModal();
|
|
10207
|
+
queueMicrotask(() => elements.themeCustomizerName?.focus({ preventScroll: true }));
|
|
10208
|
+
}
|
|
10209
|
+
|
|
10210
|
+
function showThemeCustomizerOverwrite(details) {
|
|
10211
|
+
const state = themeCustomizerState;
|
|
10212
|
+
if (!state) return;
|
|
10213
|
+
const scope = details?.scope;
|
|
10214
|
+
const fileName = details?.fileName;
|
|
10215
|
+
if (scope !== elements.themeCustomizerScope.value || fileName !== `${elements.themeCustomizerName.value.trim()}.json` || !Number.isFinite(details?.mtimeMs)) {
|
|
10216
|
+
setThemeCustomizerStatus("The server returned conflict details for a different target. Refresh the catalog and try again.", "error");
|
|
10217
|
+
return;
|
|
10218
|
+
}
|
|
10219
|
+
state.overwrite = { signature: themeCustomizerDraftSignature(state), scope, fileName, mtimeMs: details.mtimeMs };
|
|
10220
|
+
elements.themeCustomizerOverwriteMessage.textContent = `${themeScopeLabel(scope)} themes / ${fileName} already exists. Replace only this file with the current unchanged draft?`;
|
|
10221
|
+
elements.themeCustomizerOverwrite.hidden = false;
|
|
10222
|
+
setThemeCustomizerStatus("Review the exact target, then confirm replacement. Any draft, name, or destination change cancels this confirmation.", "warn");
|
|
10223
|
+
updateThemeCustomizerActions();
|
|
10224
|
+
elements.themeCustomizerOverwriteButton.focus();
|
|
10225
|
+
}
|
|
10226
|
+
|
|
10227
|
+
async function saveThemeCustomizer({ overwrite = false } = {}) {
|
|
10228
|
+
const state = themeCustomizerState;
|
|
10229
|
+
if (!state?.draftValid || !state.validTheme || state.saving) return;
|
|
10230
|
+
if (!isCurrentTabContext(state.tabContext)) {
|
|
10231
|
+
setThemeCustomizerStatus("The active tab changed. Cancel and reopen Customize so the project destination is bound to the intended tab.", "warn");
|
|
10232
|
+
return;
|
|
10233
|
+
}
|
|
10234
|
+
const confirmation = state.overwrite;
|
|
10235
|
+
if (overwrite && (!confirmation || confirmation.signature !== themeCustomizerDraftSignature(state))) {
|
|
10236
|
+
invalidateThemeCustomizerOverwrite();
|
|
10237
|
+
setThemeCustomizerStatus("The overwrite confirmation no longer matches this target and draft. Save again to request a fresh confirmation.", "warn");
|
|
10238
|
+
updateThemeCustomizerActions();
|
|
10239
|
+
return;
|
|
10240
|
+
}
|
|
10241
|
+
const name = elements.themeCustomizerName.value.trim();
|
|
10242
|
+
const scope = elements.themeCustomizerScope.value;
|
|
10243
|
+
state.saving = true;
|
|
10244
|
+
updateThemeCustomizerActions();
|
|
10245
|
+
try {
|
|
10246
|
+
const response = await api("/api/themes/custom", {
|
|
10247
|
+
method: "POST",
|
|
10248
|
+
tabId: state.tabContext.tabId,
|
|
10249
|
+
body: {
|
|
10250
|
+
scope,
|
|
10251
|
+
fileName: `${name}.json`,
|
|
10252
|
+
theme: state.validTheme,
|
|
10253
|
+
overwrite,
|
|
10254
|
+
expectedMtimeMs: overwrite ? confirmation.mtimeMs : null,
|
|
10255
|
+
},
|
|
10256
|
+
});
|
|
10257
|
+
if (themeCustomizerState?.generation !== state.generation) return;
|
|
10258
|
+
invalidateThemeCustomizerOverwrite();
|
|
10259
|
+
await refreshThemeCatalog(state.tabContext);
|
|
10260
|
+
if (themeCustomizerState?.generation !== state.generation) return;
|
|
10261
|
+
applyTheme(state.validTheme, { persist: false });
|
|
10262
|
+
elements.themeCustomizerSourceBadge.textContent = `${themeScopeLabel(scope)} saved`;
|
|
10263
|
+
elements.themeCustomizerSourceBadge.className = `theme-scope-badge ${scope}`;
|
|
10264
|
+
setThemeCustomizerStatus(`Saved ${response.data?.fileName || `${name}.json`} to ${themeScopeLabel(scope)} themes. The WebUI catalog is refreshed. In Pi TUI, run /reload or restart, then choose it with /theme. No Pi or browser theme setting was changed.`, "success");
|
|
10265
|
+
} catch (error) {
|
|
10266
|
+
if (themeCustomizerState?.generation !== state.generation) return;
|
|
10267
|
+
const code = error.data?.code;
|
|
10268
|
+
if (code === "THEME_EXISTS") showThemeCustomizerOverwrite(error.data?.details);
|
|
10269
|
+
else if (code === "THEME_CHANGED") {
|
|
10270
|
+
invalidateThemeCustomizerOverwrite();
|
|
10271
|
+
setThemeCustomizerStatus("The target changed after confirmation and was not overwritten. Review the current file, then save again for a fresh target-bound confirmation.", "error");
|
|
10272
|
+
} else {
|
|
10273
|
+
const issues = error.data?.details?.issues;
|
|
10274
|
+
setThemeCustomizerStatus(Array.isArray(issues) && issues.length
|
|
10275
|
+
? issues.map(({ path, message }) => `${path}: ${message}`).join(" · ")
|
|
10276
|
+
: error.message || String(error), "error");
|
|
10277
|
+
}
|
|
10278
|
+
} finally {
|
|
10279
|
+
if (themeCustomizerState?.generation === state.generation) {
|
|
10280
|
+
state.saving = false;
|
|
10281
|
+
updateThemeCustomizerActions();
|
|
10282
|
+
}
|
|
10283
|
+
}
|
|
10284
|
+
}
|
|
10285
|
+
|
|
10286
|
+
function resetThemeCustomizerDraft() {
|
|
10287
|
+
const state = themeCustomizerState;
|
|
10288
|
+
if (!state?.initialTheme) return;
|
|
10289
|
+
const reset = cloneThemeDraft(state.initialTheme);
|
|
10290
|
+
elements.themeCustomizerName.value = reset.name;
|
|
10291
|
+
renderThemeCustomizerVisualFields(reset);
|
|
10292
|
+
renderThemeCustomizerOptionalFields(reset);
|
|
10293
|
+
acceptThemeCustomizerDraft(reset, { syncJson: true });
|
|
10294
|
+
}
|
|
10295
|
+
|
|
9699
10296
|
function renderThemeSelect({ unavailableLabel = "Theme bundle unavailable" } = {}) {
|
|
9700
10297
|
if (!elements.themeSelect) return;
|
|
9701
10298
|
elements.themeSelect.replaceChildren();
|
|
@@ -9704,6 +10301,7 @@ function renderThemeSelect({ unavailableLabel = "Theme bundle unavailable" } = {
|
|
|
9704
10301
|
option.value = "";
|
|
9705
10302
|
elements.themeSelect.append(option);
|
|
9706
10303
|
elements.themeSelect.disabled = true;
|
|
10304
|
+
if (elements.themeCustomizeButton) elements.themeCustomizeButton.disabled = true;
|
|
9707
10305
|
return;
|
|
9708
10306
|
}
|
|
9709
10307
|
if (!availableThemes.length) {
|
|
@@ -9711,11 +10309,14 @@ function renderThemeSelect({ unavailableLabel = "Theme bundle unavailable" } = {
|
|
|
9711
10309
|
option.value = "";
|
|
9712
10310
|
elements.themeSelect.append(option);
|
|
9713
10311
|
elements.themeSelect.disabled = true;
|
|
10312
|
+
if (elements.themeCustomizeButton) elements.themeCustomizeButton.disabled = true;
|
|
9714
10313
|
return;
|
|
9715
10314
|
}
|
|
9716
10315
|
elements.themeSelect.disabled = false;
|
|
10316
|
+
if (elements.themeCustomizeButton) elements.themeCustomizeButton.disabled = false;
|
|
9717
10317
|
for (const theme of availableThemes) {
|
|
9718
|
-
const
|
|
10318
|
+
const suffix = theme.custom ? ` · ${themeScopeLabel(theme.scope)}` : "";
|
|
10319
|
+
const option = make("option", undefined, `${theme.label || displayThemeName(theme.name) || theme.name}${suffix}`);
|
|
9719
10320
|
option.value = theme.name;
|
|
9720
10321
|
elements.themeSelect.append(option);
|
|
9721
10322
|
}
|
|
@@ -9750,6 +10351,7 @@ async function initializeThemes() {
|
|
|
9750
10351
|
throw error;
|
|
9751
10352
|
}
|
|
9752
10353
|
availableThemes = Array.isArray(response.data?.themes) ? response.data.themes : [];
|
|
10354
|
+
themeCatalogScopes = response.data?.scopes && typeof response.data.scopes === "object" ? response.data.scopes : themeCatalogScopes;
|
|
9753
10355
|
optionalFeatureAvailability.themeBundle = availableThemes.length > 0;
|
|
9754
10356
|
renderOptionalFeatureControls();
|
|
9755
10357
|
themeSchemeMode = storedThemeMode() ?? seedThemeSchemeFromStoredTheme();
|
|
@@ -9768,6 +10370,53 @@ function activeTabContext(tabId = activeTabId) {
|
|
|
9768
10370
|
return { tabId: tabId || null, generation: activeTabGeneration };
|
|
9769
10371
|
}
|
|
9770
10372
|
|
|
10373
|
+
function transcriptStreamOwner(tabId = activeTabId, generation = activeTabGeneration) {
|
|
10374
|
+
return `${tabId || ""}:${generation}`;
|
|
10375
|
+
}
|
|
10376
|
+
|
|
10377
|
+
function unknownTranscriptEvidenceText(event) {
|
|
10378
|
+
const update = event?.assistantMessageEvent || {};
|
|
10379
|
+
const value = update.delta ?? update.content ?? update.text ?? update.thinking ?? "";
|
|
10380
|
+
if (typeof value === "string") return value.slice(0, UNKNOWN_TRANSCRIPT_EVIDENCE_TEXT_LIMIT);
|
|
10381
|
+
try {
|
|
10382
|
+
return JSON.stringify(value).slice(0, UNKNOWN_TRANSCRIPT_EVIDENCE_TEXT_LIMIT);
|
|
10383
|
+
} catch {
|
|
10384
|
+
return "[unserializable transcript evidence]";
|
|
10385
|
+
}
|
|
10386
|
+
}
|
|
10387
|
+
|
|
10388
|
+
function preserveUnknownTranscriptEvidence(event, classification, owner) {
|
|
10389
|
+
const update = event?.assistantMessageEvent || {};
|
|
10390
|
+
const evidence = {
|
|
10391
|
+
owner: String(owner || ""),
|
|
10392
|
+
subtype: classification?.subtype || "(missing)",
|
|
10393
|
+
fields: Object.keys(update).slice(0, 16),
|
|
10394
|
+
text: unknownTranscriptEvidenceText(event),
|
|
10395
|
+
receivedAt: Date.now(),
|
|
10396
|
+
};
|
|
10397
|
+
appendBoundedStreamDiagnostic(unknownTranscriptEvidence, evidence, UNKNOWN_TRANSCRIPT_EVIDENCE_LIMIT);
|
|
10398
|
+
if (owner) {
|
|
10399
|
+
unknownTranscriptOwnersPendingReconcile.add(owner);
|
|
10400
|
+
while (unknownTranscriptOwnersPendingReconcile.size > UNKNOWN_TRANSCRIPT_EVIDENCE_LIMIT) {
|
|
10401
|
+
const oldest = unknownTranscriptOwnersPendingReconcile.values().next().value;
|
|
10402
|
+
if (oldest === undefined) break;
|
|
10403
|
+
unknownTranscriptOwnersPendingReconcile.delete(oldest);
|
|
10404
|
+
}
|
|
10405
|
+
}
|
|
10406
|
+
if (streamIsolationDebugLedger) {
|
|
10407
|
+
appendBoundedStreamDiagnostic(streamIsolationDebugLedger.unknownEvidence, evidence, UNKNOWN_TRANSCRIPT_EVIDENCE_LIMIT);
|
|
10408
|
+
}
|
|
10409
|
+
}
|
|
10410
|
+
|
|
10411
|
+
function reconcileUnknownTranscriptEvidenceAtBarrier(event) {
|
|
10412
|
+
const tabContext = activeTabContext(event?.tabId || activeTabId);
|
|
10413
|
+
const owner = transcriptStreamOwner(tabContext.tabId, tabContext.generation);
|
|
10414
|
+
if (!unknownTranscriptOwnersPendingReconcile.delete(owner)) return false;
|
|
10415
|
+
if (!isCurrentTabContext(tabContext)) return false;
|
|
10416
|
+
scheduleSemanticReconcile({ messages: true }, tabContext);
|
|
10417
|
+
return true;
|
|
10418
|
+
}
|
|
10419
|
+
|
|
9771
10420
|
function setActiveTabId(tabId, { remember = false } = {}) {
|
|
9772
10421
|
const nextTabId = tabId || null;
|
|
9773
10422
|
if (nextTabId !== activeTabId) {
|
|
@@ -12918,7 +13567,6 @@ function clearWidgetsForTab(tabId = activeTabId) {
|
|
|
12918
13567
|
|
|
12919
13568
|
function resetActiveTabUi() {
|
|
12920
13569
|
clearRefreshTimers();
|
|
12921
|
-
clearLiveToolRenderQueue();
|
|
12922
13570
|
eventSource?.close();
|
|
12923
13571
|
eventSource = null;
|
|
12924
13572
|
currentState = null;
|
|
@@ -12966,10 +13614,11 @@ function resetActiveTabUi() {
|
|
|
12966
13614
|
renderAppRunnerControls();
|
|
12967
13615
|
renderWidgets();
|
|
12968
13616
|
renderGitWorkflow();
|
|
12969
|
-
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
13617
|
+
// renderMessages() is transcript-only, so tab-level chrome is rendered here
|
|
13618
|
+
// explicitly whether or not a cached transcript was restored.
|
|
13619
|
+
restoreCachedMessagesForActiveTab();
|
|
13620
|
+
renderFooter();
|
|
13621
|
+
renderFeedbackTray();
|
|
12973
13622
|
}
|
|
12974
13623
|
|
|
12975
13624
|
function tabGroupStatusRank(state) {
|
|
@@ -13891,7 +14540,7 @@ function renderTerminalTab(tab) {
|
|
|
13891
14540
|
applyStyledTooltip(button, terminalTabTooltip(tab), { ariaLabel: false, align: "start", description: true, variant: "workspace", targetKey: `terminal-tab:${tab.id}:switch` });
|
|
13892
14541
|
appendTerminalTabContent(button, { title: tab.title, indicator, meta: terminalTabMeta(tab, indicator), appRunnerRun, conversationModeActive, workflowModeActive, workflowCount });
|
|
13893
14542
|
button.addEventListener("click", () => switchTab(tab.id));
|
|
13894
|
-
wrapper.append(button);
|
|
14543
|
+
wrapper.append(button, createTerminalTabActions(tab));
|
|
13895
14544
|
|
|
13896
14545
|
if (tabs.length > 1) {
|
|
13897
14546
|
const close = make("button", "terminal-tab-close", "×");
|
|
@@ -13933,7 +14582,7 @@ function renderTerminalTabGroupItem(tab, group) {
|
|
|
13933
14582
|
event.stopPropagation();
|
|
13934
14583
|
switchTab(tab.id);
|
|
13935
14584
|
});
|
|
13936
|
-
item.append(button);
|
|
14585
|
+
item.append(button, createTerminalTabActions(tab));
|
|
13937
14586
|
|
|
13938
14587
|
if (tabs.length > 1) {
|
|
13939
14588
|
const close = make("button", "terminal-tab-close terminal-tab-group-item-close", "×");
|
|
@@ -14059,7 +14708,6 @@ function setNewTabMenuOpen(open) {
|
|
|
14059
14708
|
|
|
14060
14709
|
function initializeTerminalHeaderTooltips() {
|
|
14061
14710
|
applyStyledTooltip(elements.newTabButton, "Start a separate isolated Pi terminal", { ariaLabel: "Start a separate isolated Pi terminal" });
|
|
14062
|
-
applyStyledTooltip(elements.splitTabButton, "Split the active terminal to the right", { ariaLabel: "Split the active terminal to the right" });
|
|
14063
14711
|
applyStyledTooltip(elements.closeAllTabsButton, "Close all terminal tabs", { ariaLabel: "Close all terminal tabs" });
|
|
14064
14712
|
}
|
|
14065
14713
|
|
|
@@ -14104,6 +14752,8 @@ function terminalTabControlKey(node) {
|
|
|
14104
14752
|
const tabId = node?.closest?.("[data-tab-id]")?.dataset?.tabId;
|
|
14105
14753
|
if (tabId) {
|
|
14106
14754
|
if (node.classList.contains("terminal-tab-close")) return `terminal-tab:${tabId}:close`;
|
|
14755
|
+
if (node.classList.contains("terminal-tab-split-button")) return `terminal-tab:${tabId}:split`;
|
|
14756
|
+
if (node.classList.contains("terminal-tab-summary-button")) return `terminal-tab:${tabId}:summary`;
|
|
14107
14757
|
if (node.classList.contains("terminal-tab-button")) return `terminal-tab:${tabId}:switch`;
|
|
14108
14758
|
}
|
|
14109
14759
|
const groupKey = node?.closest?.("[data-group-key]")?.dataset?.groupKey;
|
|
@@ -14172,6 +14822,18 @@ function renderTabs() {
|
|
|
14172
14822
|
if (mobilePhoneExperienceInstalled && isMobileShellV2Active()) renderMobilePhoneExperience();
|
|
14173
14823
|
}
|
|
14174
14824
|
|
|
14825
|
+
function prefetchInactiveTabCommandCatalogs() {
|
|
14826
|
+
for (const tab of tabs) {
|
|
14827
|
+
if (!tab?.id || tab.id === activeTabId || commandCatalogsByTab.has(tab.id) || commandCatalogRefreshesByTab.has(tab.id)) continue;
|
|
14828
|
+
const refresh = refreshCommands(activeTabContext(tab.id))
|
|
14829
|
+
.catch(() => {})
|
|
14830
|
+
.finally(() => {
|
|
14831
|
+
if (commandCatalogRefreshesByTab.get(tab.id) === refresh) commandCatalogRefreshesByTab.delete(tab.id);
|
|
14832
|
+
});
|
|
14833
|
+
commandCatalogRefreshesByTab.set(tab.id, refresh);
|
|
14834
|
+
}
|
|
14835
|
+
}
|
|
14836
|
+
|
|
14175
14837
|
async function refreshTabs({ selectStored = false } = {}) {
|
|
14176
14838
|
const previousTabs = tabs;
|
|
14177
14839
|
const response = await api("/api/tabs", { scoped: false });
|
|
@@ -14196,6 +14858,7 @@ async function refreshTabs({ selectStored = false } = {}) {
|
|
|
14196
14858
|
}
|
|
14197
14859
|
renderSessionSkillTags(activeTabId);
|
|
14198
14860
|
renderTabs();
|
|
14861
|
+
prefetchInactiveTabCommandCatalogs();
|
|
14199
14862
|
return tabs;
|
|
14200
14863
|
}
|
|
14201
14864
|
|
|
@@ -14205,7 +14868,12 @@ async function switchTab(tabId) {
|
|
|
14205
14868
|
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ focusParent: true });
|
|
14206
14869
|
return;
|
|
14207
14870
|
}
|
|
14871
|
+
if (themeCustomizerState?.saving) {
|
|
14872
|
+
setThemeCustomizerStatus("Wait for the theme save to finish before switching tabs.", "warn");
|
|
14873
|
+
return;
|
|
14874
|
+
}
|
|
14208
14875
|
if (activeSubagentTerminalId) deactivateSubagentTerminalView({ render: false });
|
|
14876
|
+
if (themeCustomizerState) closeThemeCustomizer({ restore: true });
|
|
14209
14877
|
clearOpenTerminalTabGroup(null, { force: true });
|
|
14210
14878
|
setFollowUpQueueOpen(false);
|
|
14211
14879
|
setFollowUpQueueStatus("");
|
|
@@ -14228,6 +14896,7 @@ async function switchTab(tabId) {
|
|
|
14228
14896
|
connectEvents(tabContext);
|
|
14229
14897
|
await refreshAll(tabContext);
|
|
14230
14898
|
if (isCurrentTabContext(tabContext)) markTabOutputSeen();
|
|
14899
|
+
await refreshThemeCatalog(tabContext).catch((error) => addEvent(`Custom theme catalog refresh failed: ${error.message || String(error)}`, "warn"));
|
|
14231
14900
|
if (!subagentLaunchSlotDraftIsDirty()) {
|
|
14232
14901
|
loadSubagentLaunchSlotConfig({ tabId }).catch(() => {});
|
|
14233
14902
|
} else {
|
|
@@ -14250,19 +14919,28 @@ function terminalSplitFrameUrl(tabId) {
|
|
|
14250
14919
|
return `${url.pathname}${url.search}`;
|
|
14251
14920
|
}
|
|
14252
14921
|
|
|
14922
|
+
function updateTerminalSplitControls(canShowSplit, splitTab = terminalSplitTab()) {
|
|
14923
|
+
elements.tabBar?.querySelectorAll(".terminal-tab-split-button").forEach((button) => {
|
|
14924
|
+
const tabId = button.closest("[data-tab-id]")?.dataset?.tabId || "";
|
|
14925
|
+
const tab = tabs.find((candidate) => candidate.id === tabId);
|
|
14926
|
+
const isOpenSplit = canShowSplit && tabId === splitTab?.id;
|
|
14927
|
+
button.disabled = embeddedSplitMode || isSidePanelOverlayView() || !tab;
|
|
14928
|
+
button.setAttribute("aria-pressed", isOpenSplit ? "true" : "false");
|
|
14929
|
+
button.dataset.splitState = isOpenSplit ? "unsplit" : "split";
|
|
14930
|
+
const label = isOpenSplit
|
|
14931
|
+
? `Close split view for ${tab?.title || "Pi terminal"}`
|
|
14932
|
+
: `Split ${tab?.title || "Pi terminal"} to the right`;
|
|
14933
|
+
applyStyledTooltip(button, label, { ariaLabel: label, targetKey: tabId ? `terminal-tab:${tabId}:split` : "" });
|
|
14934
|
+
});
|
|
14935
|
+
}
|
|
14936
|
+
|
|
14253
14937
|
function updateTerminalSplitUi() {
|
|
14254
14938
|
const tab = terminalSplitTab();
|
|
14255
14939
|
const canShowSplit = !!tab && !embeddedSplitMode && !isSidePanelOverlayView();
|
|
14256
14940
|
document.body.classList.toggle("terminal-split-open", canShowSplit);
|
|
14257
14941
|
if (elements.terminalSplitShell) elements.terminalSplitShell.hidden = !canShowSplit;
|
|
14258
14942
|
requestAnimationFrame(syncResizablePanelWidthsForViewport);
|
|
14259
|
-
|
|
14260
|
-
elements.splitTabButton.disabled = embeddedSplitMode || isSidePanelOverlayView() || !activeTab();
|
|
14261
|
-
elements.splitTabButton.setAttribute("aria-pressed", canShowSplit ? "true" : "false");
|
|
14262
|
-
elements.splitTabButton.dataset.splitState = canShowSplit ? "unsplit" : "split";
|
|
14263
|
-
const label = canShowSplit ? `Close split view for ${tab.title}` : "Split the active terminal to the right";
|
|
14264
|
-
applyStyledTooltip(elements.splitTabButton, label, { ariaLabel: label });
|
|
14265
|
-
}
|
|
14943
|
+
updateTerminalSplitControls(canShowSplit, tab);
|
|
14266
14944
|
if (!canShowSplit) return;
|
|
14267
14945
|
if (elements.terminalSplitTitle) elements.terminalSplitTitle.textContent = tab.title || "Split terminal";
|
|
14268
14946
|
if (elements.terminalSplitMeta) elements.terminalSplitMeta.textContent = [tab.running ? `pid ${tab.pid || "starting"}` : "stopped", normalizeDisplayPath(tab.cwd || "")].filter(Boolean).join(" · ");
|
|
@@ -14295,22 +14973,23 @@ function reconcileTerminalSplitState() {
|
|
|
14295
14973
|
updateTerminalSplitUi();
|
|
14296
14974
|
}
|
|
14297
14975
|
|
|
14298
|
-
async function
|
|
14976
|
+
async function splitTerminalTab(tabId, { triggerButton = null } = {}) {
|
|
14299
14977
|
if (embeddedSplitMode) return;
|
|
14300
|
-
if (splitTabId) {
|
|
14978
|
+
if (splitTabId === tabId) {
|
|
14301
14979
|
closeTerminalSplitView();
|
|
14302
14980
|
return;
|
|
14303
14981
|
}
|
|
14304
|
-
const sourceTab =
|
|
14305
|
-
|
|
14982
|
+
const sourceTab = tabs.find((tab) => tab.id === tabId);
|
|
14983
|
+
if (!sourceTab) return;
|
|
14984
|
+
if (splitTabId) closeTerminalSplitView();
|
|
14985
|
+
let resolvedCwd = sourceTab.cwd || latestWorkspace?.cwd || currentDirectoryForNewTab();
|
|
14306
14986
|
setMobileTabsExpanded(false);
|
|
14307
14987
|
setNewTabMenuOpen(false);
|
|
14308
14988
|
if (!resolvedCwd) {
|
|
14309
|
-
resolvedCwd = await pickCwd(sourceTab
|
|
14989
|
+
resolvedCwd = await pickCwd(sourceTab, "", { title: "Choose CWD for split terminal" });
|
|
14310
14990
|
if (!resolvedCwd) return;
|
|
14311
14991
|
}
|
|
14312
|
-
|
|
14313
|
-
for (const button of disabledButtons) button.disabled = true;
|
|
14992
|
+
if (triggerButton) triggerButton.disabled = true;
|
|
14314
14993
|
try {
|
|
14315
14994
|
const response = await api("/api/tabs", { method: "POST", body: { cwd: resolvedCwd }, scoped: false });
|
|
14316
14995
|
tabs = response.data?.tabs || tabs;
|
|
@@ -14319,12 +14998,12 @@ async function splitActiveTerminalTab({ triggerButton = elements.splitTabButton
|
|
|
14319
14998
|
if (tab?.id) {
|
|
14320
14999
|
setTerminalSplitTab(tab.id);
|
|
14321
15000
|
renderTabs();
|
|
14322
|
-
addEvent(`split ${sourceTab
|
|
15001
|
+
addEvent(`split ${sourceTab.title || "terminal"} into independent ${tab.title}`, "info");
|
|
14323
15002
|
}
|
|
14324
15003
|
} catch (error) {
|
|
14325
15004
|
addEvent(error.message, "error");
|
|
14326
15005
|
} finally {
|
|
14327
|
-
|
|
15006
|
+
if (triggerButton) triggerButton.disabled = false;
|
|
14328
15007
|
updateTerminalSplitUi();
|
|
14329
15008
|
}
|
|
14330
15009
|
}
|
|
@@ -14508,6 +15187,7 @@ async function initializeTabs() {
|
|
|
14508
15187
|
return [];
|
|
14509
15188
|
});
|
|
14510
15189
|
if (!saved.length) await createFirstTerminalTabFromChosenDirectory();
|
|
15190
|
+
await refreshThemeCatalog(activeTabContext()).catch((error) => addEvent(`Custom theme catalog refresh failed: ${error.message || String(error)}`, "warn"));
|
|
14511
15191
|
return;
|
|
14512
15192
|
}
|
|
14513
15193
|
focusPromptInput({ defer: true });
|
|
@@ -14519,6 +15199,7 @@ async function initializeTabs() {
|
|
|
14519
15199
|
if (!subagentLaunchSlotDraftIsDirty() || subagentLaunchSlotConfigTabId !== activeTabId) {
|
|
14520
15200
|
loadSubagentLaunchSlotConfig().catch(() => {});
|
|
14521
15201
|
}
|
|
15202
|
+
await refreshThemeCatalog(tabContext).catch((error) => addEvent(`Custom theme catalog refresh failed: ${error.message || String(error)}`, "warn"));
|
|
14522
15203
|
}
|
|
14523
15204
|
}
|
|
14524
15205
|
|
|
@@ -15633,7 +16314,7 @@ const GIT_FOOTER_TOOLTIP_COPY = {
|
|
|
15633
16314
|
cwd: "Active working directory for this Web UI tab.",
|
|
15634
16315
|
git: "Current Git branch. detached means HEAD is not on a branch; no repo means the cwd is outside a Git work tree.",
|
|
15635
16316
|
"git-state": "Active Git operation or detached state. Finish or abort rebase/merge/cherry-pick/revert/bisect before normal commits.",
|
|
15636
|
-
sync: "Remote tracking divergence. ↑ means local commits
|
|
16317
|
+
sync: "Remote tracking divergence. ↑ means local commits to push; ↓ means remote commits to pull. Incoming-only Sync pulls from origin; outgoing Sync uses the confirmed push flow, including the guarded force-with-lease fallback when needed.",
|
|
15637
16318
|
changes: "Working tree and fetched remote summary. 🟢 staged, ✏️ modified unstaged, ➕ untracked, ⚠️ conflicted; ⬇️ means fetched remote commits to pull; 🔄/✓/⚠️ fetch shows the tab git fetch state; ✅ means no changes.",
|
|
15638
16319
|
"git-extra": "Extra Git signals. 📦 stash, 🧩 dirty submodules, 🌳 worktrees, 🏷️ tag at HEAD, 🕒 last commit age, 🔓 signing mismatch.",
|
|
15639
16320
|
worktree: "Git worktree checkout for this tab. Use branch worktrees to work on branches in parallel without switching this checkout.",
|
|
@@ -15710,7 +16391,7 @@ const GIT_FOOTER_VISIBILITY_LABELS = Object.freeze({
|
|
|
15710
16391
|
"webui-context-auto-compaction": "Auto-compaction action",
|
|
15711
16392
|
"webui-branch-picker": "Branch/worktree picker",
|
|
15712
16393
|
"webui-git-init": "Git init affordance",
|
|
15713
|
-
"webui-sync-push": "Sync push action",
|
|
16394
|
+
"webui-sync-push": "Sync pull/push action",
|
|
15714
16395
|
"webui-changes-modal": "Changes modal",
|
|
15715
16396
|
"webui-git-tools-modal": "Git tools modal",
|
|
15716
16397
|
"webui-model-picker": "Model picker",
|
|
@@ -15747,7 +16428,7 @@ const GIT_FOOTER_VISIBILITY_HINTS = Object.freeze({
|
|
|
15747
16428
|
"webui-context-auto-compaction": "Click action on context chips for auto-compaction.",
|
|
15748
16429
|
"webui-branch-picker": "Click action on the git branch/worktree chips.",
|
|
15749
16430
|
"webui-git-init": "Git initialization affordance when a tab has no repository.",
|
|
15750
|
-
"webui-sync-push": "
|
|
16431
|
+
"webui-sync-push": "Compatibility visibility key for incoming pull and outgoing push actions on Sync chips.",
|
|
15751
16432
|
"webui-changes-modal": "Click action opening the changes/conflicts modal.",
|
|
15752
16433
|
"webui-git-tools-modal": "Click action opening extra git tools.",
|
|
15753
16434
|
"webui-model-picker": "Click action opening the footer model picker.",
|
|
@@ -16322,13 +17003,22 @@ function renderGitFooterPayloadMetric(chip, payload) {
|
|
|
16322
17003
|
return node;
|
|
16323
17004
|
}
|
|
16324
17005
|
|
|
16325
|
-
function
|
|
16326
|
-
const
|
|
16327
|
-
|
|
17006
|
+
function gitFooterSyncCounts(value) {
|
|
17007
|
+
const text = String(value || "");
|
|
17008
|
+
const aheadMatch = text.match(/[↑⇡]\s*(\d+)/u);
|
|
17009
|
+
const behindMatch = text.match(/[↓⇣]\s*(\d+)/u);
|
|
17010
|
+
return {
|
|
17011
|
+
ahead: aheadMatch ? Number.parseInt(aheadMatch[1] || "0", 10) || 0 : 0,
|
|
17012
|
+
behind: behindMatch ? Number.parseInt(behindMatch[1] || "0", 10) || 0 : 0,
|
|
17013
|
+
};
|
|
16328
17014
|
}
|
|
16329
17015
|
|
|
16330
|
-
function
|
|
16331
|
-
|
|
17016
|
+
function gitFooterSyncAction(chip) {
|
|
17017
|
+
if (chip?.key !== "sync") return "";
|
|
17018
|
+
const { ahead, behind } = gitFooterSyncCounts(chip.value);
|
|
17019
|
+
if (behind > 0 && ahead === 0) return "pull";
|
|
17020
|
+
if (ahead > 0) return "push";
|
|
17021
|
+
return "";
|
|
16332
17022
|
}
|
|
16333
17023
|
|
|
16334
17024
|
function gitFooterCurrentBranch() {
|
|
@@ -16337,9 +17027,31 @@ function gitFooterCurrentBranch() {
|
|
|
16337
17027
|
return value && value !== "no repo" ? cleanFooterPayloadText(gitChip.value, "") : "";
|
|
16338
17028
|
}
|
|
16339
17029
|
|
|
17030
|
+
async function pullGitFooterSync(tabId = activeTabId) {
|
|
17031
|
+
if (!tabId || gitFooterSyncInFlightByTab.has(tabId)) return;
|
|
17032
|
+
const tabContext = activeTabContext(tabId);
|
|
17033
|
+
hideFooterTooltip();
|
|
17034
|
+
gitFooterSyncInFlightByTab.add(tabId);
|
|
17035
|
+
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
17036
|
+
try {
|
|
17037
|
+
const response = await api("/api/git-changes/pull", { method: "POST", body: { remote: "origin" }, tabId });
|
|
17038
|
+
if (!response.ok) {
|
|
17039
|
+
const detail = [response.error, response.hint, formatGitCommandResult(response.data)].filter(Boolean).join("\n\n").trim();
|
|
17040
|
+
throw new Error(detail || "git pull from origin failed");
|
|
17041
|
+
}
|
|
17042
|
+
addEvent("Pulled Git changes from origin.", "success");
|
|
17043
|
+
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
17044
|
+
} catch (error) {
|
|
17045
|
+
addEvent(error.message || String(error), "error");
|
|
17046
|
+
} finally {
|
|
17047
|
+
gitFooterSyncInFlightByTab.delete(tabId);
|
|
17048
|
+
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
17049
|
+
}
|
|
17050
|
+
}
|
|
17051
|
+
|
|
16340
17052
|
async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
16341
|
-
if (!tabId ||
|
|
16342
|
-
const outgoing =
|
|
17053
|
+
if (!tabId || gitFooterSyncInFlightByTab.has(tabId)) return;
|
|
17054
|
+
const outgoing = gitFooterSyncCounts(syncValue).ahead;
|
|
16343
17055
|
if (outgoing <= 0) return;
|
|
16344
17056
|
const tabContext = activeTabContext(tabId);
|
|
16345
17057
|
const tab = tabs.find((item) => item.id === tabId);
|
|
@@ -16351,7 +17063,7 @@ async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
|
16351
17063
|
: "";
|
|
16352
17064
|
if (!(await appConfirmText(`Run git push for ${outgoing} outgoing commit${outgoing === 1 ? "" : "s"} in ${target}?${protectedWarning}`, { affected: `Remote Git branch ${branch || "current branch"}`, confirmLabel: "Push commits" }))) return;
|
|
16353
17065
|
|
|
16354
|
-
|
|
17066
|
+
gitFooterSyncInFlightByTab.add(tabId);
|
|
16355
17067
|
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
16356
17068
|
try {
|
|
16357
17069
|
const response = await api("/api/git-workflow/push", { method: "POST", body: {}, tabId });
|
|
@@ -16393,7 +17105,7 @@ async function pushGitFooterSync(tabId = activeTabId, syncValue = "") {
|
|
|
16393
17105
|
} catch (error) {
|
|
16394
17106
|
addEvent(error.message || String(error), "error");
|
|
16395
17107
|
} finally {
|
|
16396
|
-
|
|
17108
|
+
gitFooterSyncInFlightByTab.delete(tabId);
|
|
16397
17109
|
if (isCurrentTabContext(tabContext)) renderFooter();
|
|
16398
17110
|
}
|
|
16399
17111
|
}
|
|
@@ -16414,13 +17126,19 @@ function renderGitFooterPayloadMeta(chip, tab, payload) {
|
|
|
16414
17126
|
} else if (chip.key === "worktree" && visible("webui-branch-picker")) {
|
|
16415
17127
|
options.onClick = () => setFooterBranchPickerOpen(!footerBranchPickerOpen);
|
|
16416
17128
|
action = "Click to manage branch worktrees for this repository.";
|
|
16417
|
-
} else if (chip.key === "sync" && visible("webui-sync-push")
|
|
17129
|
+
} else if (chip.key === "sync" && visible("webui-sync-push")) {
|
|
16418
17130
|
const tabId = tab?.id || activeTabId;
|
|
16419
|
-
const
|
|
16420
|
-
|
|
17131
|
+
const syncAction = gitFooterSyncAction(chip);
|
|
17132
|
+
const inFlight = tabId ? gitFooterSyncInFlightByTab.has(tabId) : false;
|
|
17133
|
+
if (syncAction === "pull") {
|
|
17134
|
+
options.onClick = () => pullGitFooterSync(tabId);
|
|
17135
|
+
action = inFlight ? "Pulling from origin." : "Click to pull from origin with fast-forward only.";
|
|
17136
|
+
} else if (syncAction === "push") {
|
|
17137
|
+
options.onClick = () => pushGitFooterSync(tabId, chip.value);
|
|
17138
|
+
action = inFlight ? "Pushing local commits to the configured remote." : "Click to push local commits to the configured remote.";
|
|
17139
|
+
}
|
|
16421
17140
|
options.ariaBusy = inFlight;
|
|
16422
17141
|
options.disabled = inFlight;
|
|
16423
|
-
action = inFlight ? "Pushing local commits to the configured remote." : "Click to push local commits to the configured remote.";
|
|
16424
17142
|
} else if (chip.key === "changes" && visible("webui-changes-modal")) {
|
|
16425
17143
|
options.onClick = () => openGitChangesDialog(tab?.id || activeTabId);
|
|
16426
17144
|
action = "Click to view the current git diff.";
|
|
@@ -16486,10 +17204,10 @@ function footerBranchPickerRenderKey() {
|
|
|
16486
17204
|
function gitFooterPickerStateKey(payload) {
|
|
16487
17205
|
const tabContext = activeTabContext();
|
|
16488
17206
|
const refreshInFlight = tabContext.tabId ? gitFooterPayloadRefreshInFlightByTab.has(tabContext.tabId) : false;
|
|
16489
|
-
const
|
|
17207
|
+
const syncInFlight = tabContext.tabId ? gitFooterSyncInFlightByTab.has(tabContext.tabId) : false;
|
|
16490
17208
|
const piCalibrationInFlight = tabContext.tabId ? gitFooterPiCalibrationInFlightByTab.has(tabContext.tabId) : false;
|
|
16491
17209
|
const refreshAvailable = hasLoadedRpcCommand("git-footer-refresh");
|
|
16492
|
-
return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${footerBranchPickerRenderKey()}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${
|
|
17210
|
+
return `${footerModelPickerOpen ? 1 : 0}|${footerThinkingPickerOpen ? 1 : 0}|${footerBranchPickerOpen ? 1 : 0}|${footerBranchPickerRenderKey()}|${mobileFooterExpanded ? 1 : 0}|${refreshInFlight ? 1 : 0}|${syncInFlight ? 1 : 0}|${piCalibrationInFlight ? 1 : 0}|${refreshAvailable ? 1 : 0}|${gitFooterPayloadVisibilityKey(payload)}`;
|
|
16493
17211
|
}
|
|
16494
17212
|
|
|
16495
17213
|
function updateGitFooterChipNodeValue(node, chip, valueSelector) {
|
|
@@ -20323,6 +21041,84 @@ function scheduleRefreshFooter(delay = 300, tabContext = activeTabContext()) {
|
|
|
20323
21041
|
}, delay);
|
|
20324
21042
|
}
|
|
20325
21043
|
|
|
21044
|
+
function semanticReconcileContextKey(tabContext = {}) {
|
|
21045
|
+
return `${tabContext.tabId || ""}:${Number(tabContext.generation) || 0}`;
|
|
21046
|
+
}
|
|
21047
|
+
|
|
21048
|
+
function mergeSemanticReconcileRequest(pendingByContext, dirty = {}, tabContext = {}) {
|
|
21049
|
+
const key = semanticReconcileContextKey(tabContext);
|
|
21050
|
+
let request = pendingByContext.get(key);
|
|
21051
|
+
if (!request) {
|
|
21052
|
+
request = { tabContext: { tabId: tabContext.tabId || null, generation: Number(tabContext.generation) || 0 }, dirty: {} };
|
|
21053
|
+
}
|
|
21054
|
+
let requested = false;
|
|
21055
|
+
for (const flag of SEMANTIC_RECONCILE_FLAGS) {
|
|
21056
|
+
if (!dirty[flag]) continue;
|
|
21057
|
+
request.dirty[flag] = true;
|
|
21058
|
+
requested = true;
|
|
21059
|
+
}
|
|
21060
|
+
if (requested) pendingByContext.set(key, request);
|
|
21061
|
+
return requested;
|
|
21062
|
+
}
|
|
21063
|
+
|
|
21064
|
+
function takeSemanticReconcileRequests(pendingByContext) {
|
|
21065
|
+
const requests = Array.from(pendingByContext.values());
|
|
21066
|
+
pendingByContext.clear();
|
|
21067
|
+
return requests;
|
|
21068
|
+
}
|
|
21069
|
+
|
|
21070
|
+
// Coalesced semantic reconciliation. Lifecycle boundaries declare which
|
|
21071
|
+
// non-transcript surfaces became dirty; each tab generation retains its own
|
|
21072
|
+
// request until the frame flush. Raw stream deltas never reach here.
|
|
21073
|
+
function scheduleSemanticReconcile(dirty = {}, tabContext = activeTabContext()) {
|
|
21074
|
+
if (!mergeSemanticReconcileRequest(semanticReconcilePending, dirty, tabContext)) return;
|
|
21075
|
+
if (semanticReconcileFrame !== null) return;
|
|
21076
|
+
const flush = () => {
|
|
21077
|
+
semanticReconcileFrame = null;
|
|
21078
|
+
flushSemanticReconcile();
|
|
21079
|
+
};
|
|
21080
|
+
if (typeof requestAnimationFrame === "function") semanticReconcileFrame = requestAnimationFrame(flush);
|
|
21081
|
+
else semanticReconcileFrame = setTimeout(flush, 0);
|
|
21082
|
+
}
|
|
21083
|
+
|
|
21084
|
+
function flushSemanticReconcile() {
|
|
21085
|
+
for (const { dirty, tabContext } of takeSemanticReconcileRequests(semanticReconcilePending)) {
|
|
21086
|
+
// Originating-tab settlement work is never reassigned. Workflow continuation
|
|
21087
|
+
// is tab-scoped and may run after the user has switched away.
|
|
21088
|
+
if (dirty.workflow) reconcileGitWorkflowContinuation(tabContext.tabId);
|
|
21089
|
+
if (dirty.usage) {
|
|
21090
|
+
scheduleRefreshCodexUsage(2200);
|
|
21091
|
+
scheduleRefreshClaudeUsage(2200);
|
|
21092
|
+
}
|
|
21093
|
+
|
|
21094
|
+
// DOM and active-session fetches are valid only for the still-current tab
|
|
21095
|
+
// generation; resetActiveTabUi/refreshAll owns the newly active tab.
|
|
21096
|
+
if (!isCurrentTabContext(tabContext)) continue;
|
|
21097
|
+
if (dirty.messages) scheduleRefreshMessages(120, tabContext);
|
|
21098
|
+
if (dirty.state) scheduleRefreshState(120, tabContext);
|
|
21099
|
+
if (dirty.footerData) scheduleRefreshFooter(300, tabContext);
|
|
21100
|
+
if (dirty.footer) renderFooter();
|
|
21101
|
+
if (dirty.feedback) renderFeedbackTray();
|
|
21102
|
+
if (dirty.usage) {
|
|
21103
|
+
refreshCodexFastMode(tabContext).catch((error) => addEvent(`Codex Fast mode refresh failed: ${error.message || String(error)}`, "warn"));
|
|
21104
|
+
}
|
|
21105
|
+
}
|
|
21106
|
+
}
|
|
21107
|
+
|
|
21108
|
+
// Continue a guided git workflow that was waiting on the agent turn. This is a
|
|
21109
|
+
// settlement-boundary concern, not a streaming concern.
|
|
21110
|
+
function reconcileGitWorkflowContinuation(workflowTabId = activeTabId) {
|
|
21111
|
+
const workflow = gitWorkflowForTab(workflowTabId, { create: false });
|
|
21112
|
+
if (!workflow?.active) return;
|
|
21113
|
+
if (workflow.step === "generating") {
|
|
21114
|
+
loadGitWorkflowMessage({ requireFresh: true, generationId: workflow.messageGenerationId, runId: workflow.runId, tabId: workflowTabId });
|
|
21115
|
+
} else if (workflow.step === "branchNaming") {
|
|
21116
|
+
loadGitWorkflowBranchName({ requireFresh: true, retries: 3, runId: workflow.runId, tabId: workflowTabId });
|
|
21117
|
+
} else if (workflow.step === "prGenerating") {
|
|
21118
|
+
loadGitWorkflowPr({ requireFresh: true, retries: 3, runId: workflow.runId, tabId: workflowTabId });
|
|
21119
|
+
}
|
|
21120
|
+
}
|
|
21121
|
+
|
|
20326
21122
|
function formatCodexPlanType(value) {
|
|
20327
21123
|
const text = String(value || "").trim();
|
|
20328
21124
|
if (!text) return "unknown plan";
|
|
@@ -23072,10 +23868,10 @@ function liveTodoProgressWidgetLinesFromText(text, tabId = activeTabId) {
|
|
|
23072
23868
|
return lines;
|
|
23073
23869
|
}
|
|
23074
23870
|
|
|
23075
|
-
// Coalesce
|
|
23076
|
-
//
|
|
23077
|
-
//
|
|
23078
|
-
//
|
|
23871
|
+
// Coalesce widget rebuilds to one per animation frame. Todo-progress records
|
|
23872
|
+
// are now derived only at authoritative message reconciliation, but several
|
|
23873
|
+
// semantic boundaries can land in the same frame, so the widget area must
|
|
23874
|
+
// still never be torn down/rebuilt more than once per frame.
|
|
23079
23875
|
function scheduleLiveWidgetRender() {
|
|
23080
23876
|
if (liveWidgetRenderFrame !== null) return;
|
|
23081
23877
|
const flush = () => {
|
|
@@ -23086,20 +23882,25 @@ function scheduleLiveWidgetRender() {
|
|
|
23086
23882
|
else liveWidgetRenderFrame = setTimeout(flush, 0);
|
|
23087
23883
|
}
|
|
23088
23884
|
|
|
23089
|
-
|
|
23090
|
-
|
|
23091
|
-
|
|
23092
|
-
|
|
23093
|
-
|
|
23094
|
-
|
|
23095
|
-
const
|
|
23096
|
-
|
|
23097
|
-
|
|
23098
|
-
|
|
23099
|
-
|
|
23100
|
-
|
|
23101
|
-
|
|
23102
|
-
|
|
23885
|
+
// Authoritative source for the todo-progress record: the settled assistant
|
|
23886
|
+
// text that message reconciliation just fetched. Raw stream tokens never
|
|
23887
|
+
// reach this path, so widget records change at most once per reconciliation
|
|
23888
|
+
// and only when the parsed checklist value actually differs.
|
|
23889
|
+
function authoritativeTodoProgressSourceText(messages = latestMessages) {
|
|
23890
|
+
for (let index = (messages?.length || 0) - 1; index >= 0; index -= 1) {
|
|
23891
|
+
const message = messages[index];
|
|
23892
|
+
if (message?.role !== "assistant") continue;
|
|
23893
|
+
const text = textFromContent(message.content);
|
|
23894
|
+
if (String(text || "").trim()) return text;
|
|
23895
|
+
}
|
|
23896
|
+
return "";
|
|
23897
|
+
}
|
|
23898
|
+
|
|
23899
|
+
function reconcileTodoProgressFromMessages(messages = latestMessages, tabId = activeTabId) {
|
|
23900
|
+
if (!tabId) return false;
|
|
23901
|
+
const text = authoritativeTodoProgressSourceText(messages);
|
|
23902
|
+
if (!text) return false;
|
|
23903
|
+
return syncLiveTodoProgressWidgetFromText(text, tabId);
|
|
23103
23904
|
}
|
|
23104
23905
|
|
|
23105
23906
|
function syncLiveTodoProgressWidgetFromText(text, tabId = activeTabId) {
|
|
@@ -23109,7 +23910,7 @@ function syncLiveTodoProgressWidgetFromText(text, tabId = activeTabId) {
|
|
|
23109
23910
|
if (tabId && todoProgressSignatureByTab.get(tabId) === signature) return false;
|
|
23110
23911
|
// liveTodoProgressWidgetLinesFromText already short-circuits unless the
|
|
23111
23912
|
// feature is enabled, so detection is settled here. Do NOT run
|
|
23112
|
-
// updateOptionalFeatureAvailability()
|
|
23913
|
+
// updateOptionalFeatureAvailability() from this path: it triggers git-footer
|
|
23113
23914
|
// payload reconciliation and a full optional-feature control rebuild.
|
|
23114
23915
|
// Availability is reconciled on command/state refreshes and RPC widget
|
|
23115
23916
|
// updates instead, keeping streaming output decoupled from chrome UI.
|
|
@@ -23480,6 +24281,7 @@ function renderAurReviewWidget() {
|
|
|
23480
24281
|
if (!isOptionalFeatureEnabled("aurReview")) return null;
|
|
23481
24282
|
const payload = parseAurReviewPayload(getWidgetLines(AUR_REVIEW_RPC_WIDGET_KEY));
|
|
23482
24283
|
if (!payload || payload.decision.state === "closed") return null;
|
|
24284
|
+
if (payload.origin === "guided-git" && payload.scope === "staged" && payload.decision.state === "approved") return null;
|
|
23483
24285
|
|
|
23484
24286
|
const node = make("section", "widget aur-review-widget");
|
|
23485
24287
|
node.setAttribute("aria-label", "Manual repository review");
|
|
@@ -27556,10 +28358,11 @@ function renderGitWorkflow() {
|
|
|
27556
28358
|
elements.gitWorkflowSteps.replaceChildren();
|
|
27557
28359
|
elements.gitWorkflowActions.replaceChildren();
|
|
27558
28360
|
|
|
27559
|
-
|
|
27560
|
-
//
|
|
27561
|
-
//
|
|
27562
|
-
const reviewStepAvailable =
|
|
28361
|
+
const preferences = gitWorkflow.preferences || gitWorkflowPreferences || {};
|
|
28362
|
+
// The saved option controls new workflows, while an already-required review
|
|
28363
|
+
// remains visible and fail-closed if setup or extension availability changes.
|
|
28364
|
+
const reviewStepAvailable = (preferences.reviewProcessEnabled !== false && guidedGitReviewAvailable(activeTabId))
|
|
28365
|
+
|| gitWorkflow.guidedReviewRequired === true;
|
|
27563
28366
|
const standardProcesses = reviewStepAvailable ? GIT_WORKFLOW_PROCESSES : GIT_WORKFLOW_PROCESSES.filter((process) => process.value !== "review");
|
|
27564
28367
|
const processes = gitWorkflow.mode === "initRepo" ? GIT_INIT_WORKFLOW_PROCESSES : standardProcesses;
|
|
27565
28368
|
const activeIndexMap = gitWorkflow.mode === "initRepo" ? GIT_INIT_WORKFLOW_ACTIVE_INDEX : GIT_WORKFLOW_ACTIVE_INDEX;
|
|
@@ -27586,7 +28389,6 @@ function renderGitWorkflow() {
|
|
|
27586
28389
|
return;
|
|
27587
28390
|
}
|
|
27588
28391
|
|
|
27589
|
-
const preferences = gitWorkflow.preferences || gitWorkflowPreferences || {};
|
|
27590
28392
|
if (gitWorkflow.step === "add") {
|
|
27591
28393
|
if (preferences.stagingPolicy === "all") {
|
|
27592
28394
|
addGitWorkflowAction("Run git add .", () => runGitAdd(), "primary", false);
|
|
@@ -27968,10 +28770,9 @@ async function startGitWorkflow(tabId = activeTabId, { skipSetup = false } = {})
|
|
|
27968
28770
|
pr: null,
|
|
27969
28771
|
prRequestedAt: 0,
|
|
27970
28772
|
...resetGuidedGitReviewPatch({ retainDeclinedStagedContentHash: false }),
|
|
27971
|
-
//
|
|
27972
|
-
//
|
|
27973
|
-
|
|
27974
|
-
guidedReviewRequired: guidedGitReviewAvailable(tabId),
|
|
28773
|
+
// The saved option and current capability decide whether a new flow requires
|
|
28774
|
+
// review; once required, later setup or extension changes cannot bypass it.
|
|
28775
|
+
guidedReviewRequired: preferences.reviewProcessEnabled !== false && guidedGitReviewAvailable(tabId),
|
|
27975
28776
|
preferences,
|
|
27976
28777
|
verificationConfirmed: false,
|
|
27977
28778
|
}, { tabId });
|
|
@@ -28303,7 +29104,7 @@ async function runGitAdd(tabId = gitWorkflowActionTabId()) {
|
|
|
28303
29104
|
const result = await gitWorkflowRequest("/api/git-workflow/add", { runId, tabId });
|
|
28304
29105
|
if (!result) return;
|
|
28305
29106
|
const output = `${formatGitCommandResult(result)}\n\nStaged.`;
|
|
28306
|
-
if (guidedGitReviewAvailable(tabId) || workflow.guidedReviewRequired === true) {
|
|
29107
|
+
if ((workflow.preferences?.reviewProcessEnabled !== false && guidedGitReviewAvailable(tabId)) || workflow.guidedReviewRequired === true) {
|
|
28307
29108
|
// A required gate never falls through to the legacy message flow just
|
|
28308
29109
|
// because its extension was disabled or disappeared after staging.
|
|
28309
29110
|
await requestGuidedGitReview(tabId, { output });
|
|
@@ -28327,7 +29128,7 @@ async function acceptCurrentGitStaging(tabId = gitWorkflowActionTabId()) {
|
|
|
28327
29128
|
const staged = Number(response.data?.summary?.staged || 0);
|
|
28328
29129
|
if (staged <= 0) throw new Error("No staged files are available. Use Review/select changes to stage the intended files first.");
|
|
28329
29130
|
const output = `Using the current staged set (${staged} file${staged === 1 ? "" : "s"}).`;
|
|
28330
|
-
if (guidedGitReviewAvailable(tabId) || workflow.guidedReviewRequired === true) {
|
|
29131
|
+
if ((workflow.preferences?.reviewProcessEnabled !== false && guidedGitReviewAvailable(tabId)) || workflow.guidedReviewRequired === true) {
|
|
28331
29132
|
await requestGuidedGitReview(tabId, { output });
|
|
28332
29133
|
} else {
|
|
28333
29134
|
setGitWorkflow({
|
|
@@ -32299,43 +33100,9 @@ function updateLiveToolCard(bubble, message) {
|
|
|
32299
33100
|
return true;
|
|
32300
33101
|
}
|
|
32301
33102
|
|
|
32302
|
-
function cancelQueuedLiveToolRunRender(toolCallId = "") {
|
|
32303
|
-
if (toolCallId) liveToolRenderQueue.delete(String(toolCallId));
|
|
32304
|
-
else liveToolRenderQueue.clear();
|
|
32305
|
-
if (liveToolRenderQueue.size === 0) {
|
|
32306
|
-
clearTimeout(liveToolRenderTimer);
|
|
32307
|
-
liveToolRenderTimer = null;
|
|
32308
|
-
}
|
|
32309
|
-
}
|
|
32310
|
-
|
|
32311
|
-
function clearLiveToolRenderQueue() {
|
|
32312
|
-
cancelQueuedLiveToolRunRender();
|
|
32313
|
-
}
|
|
32314
|
-
|
|
32315
|
-
function flushLiveToolRunRenderQueue() {
|
|
32316
|
-
const entries = Array.from(liveToolRenderQueue.values());
|
|
32317
|
-
clearLiveToolRenderQueue();
|
|
32318
|
-
for (const entry of entries) renderLiveToolRun(entry.run, { scroll: entry.scroll });
|
|
32319
|
-
}
|
|
32320
|
-
|
|
32321
|
-
function scheduleLiveToolRunRender(run, { scroll = false } = {}) {
|
|
32322
|
-
if (!run?.toolCallId) return;
|
|
32323
|
-
const id = String(run.toolCallId);
|
|
32324
|
-
const existing = liveToolRenderQueue.get(id);
|
|
32325
|
-
liveToolRenderQueue.set(id, { run, scroll: !!(existing?.scroll || scroll) });
|
|
32326
|
-
if (liveToolRenderTimer) return;
|
|
32327
|
-
liveToolRenderTimer = setTimeout(() => {
|
|
32328
|
-
liveToolRenderTimer = null;
|
|
32329
|
-
const flush = () => flushLiveToolRunRenderQueue();
|
|
32330
|
-
if (typeof requestAnimationFrame === "function") requestAnimationFrame(flush);
|
|
32331
|
-
else flush();
|
|
32332
|
-
}, TOOL_LIVE_UPDATE_THROTTLE_MS);
|
|
32333
|
-
}
|
|
32334
|
-
|
|
32335
33103
|
function renderLiveToolRun(run, { scroll = true } = {}) {
|
|
32336
33104
|
if (!run?.toolCallId) return;
|
|
32337
33105
|
const id = String(run.toolCallId);
|
|
32338
|
-
cancelQueuedLiveToolRunRender(id);
|
|
32339
33106
|
const existing = liveToolCards.get(id);
|
|
32340
33107
|
const existingConnected = !!(existing?.isConnected && existing.parentElement === elements.chat);
|
|
32341
33108
|
const shouldFollow = scroll && (autoFollowChat || isChatNearBottom());
|
|
@@ -32385,10 +33152,10 @@ function handleToolExecutionStart(event) {
|
|
|
32385
33152
|
if (run) renderLiveToolRun(run);
|
|
32386
33153
|
}
|
|
32387
33154
|
|
|
32388
|
-
function
|
|
33155
|
+
function applyTranscriptToolExecutionUpdate(event) {
|
|
32389
33156
|
const result = { ...(event.partialResult || {}), isError: false };
|
|
32390
33157
|
const run = upsertLiveToolRun(event, { result, isPartial: true, isError: false });
|
|
32391
|
-
if (run)
|
|
33158
|
+
if (run) renderLiveToolRun(run, { scroll: false });
|
|
32392
33159
|
}
|
|
32393
33160
|
|
|
32394
33161
|
function handleToolExecutionEnd(event) {
|
|
@@ -32729,7 +33496,11 @@ function runIndicatorDetail() {
|
|
|
32729
33496
|
return "Waiting for output or action…";
|
|
32730
33497
|
}
|
|
32731
33498
|
|
|
33499
|
+
// Transcript-owned ticker: it may only repaint the run-indicator bubble's own
|
|
33500
|
+
// stable text nodes. Canonical state reconciliation belongs to the separate
|
|
33501
|
+
// lifecycle watchdog below, so transcript rendering never issues network work.
|
|
32732
33502
|
function startRunIndicatorTicker() {
|
|
33503
|
+
startLifecycleStateWatchdog();
|
|
32733
33504
|
if (runIndicatorTimer) return;
|
|
32734
33505
|
runIndicatorTimer = setInterval(() => {
|
|
32735
33506
|
if (!runIndicatorIsActive()) {
|
|
@@ -32737,17 +33508,39 @@ function startRunIndicatorTicker() {
|
|
|
32737
33508
|
return;
|
|
32738
33509
|
}
|
|
32739
33510
|
updateRunIndicatorBubble();
|
|
32740
|
-
maybeRefreshRunIndicatorState();
|
|
32741
33511
|
}, RUN_INDICATOR_TICK_MS);
|
|
32742
33512
|
}
|
|
32743
33513
|
|
|
32744
33514
|
function stopRunIndicatorTicker() {
|
|
32745
33515
|
clearInterval(runIndicatorTimer);
|
|
32746
33516
|
runIndicatorTimer = null;
|
|
33517
|
+
stopLifecycleStateWatchdog();
|
|
33518
|
+
}
|
|
33519
|
+
|
|
33520
|
+
// Lifecycle-owned watchdog. It runs while a run is active and performs the
|
|
33521
|
+
// bounded canonical state recheck that keeps Stop/idle honest when a terminal
|
|
33522
|
+
// lifecycle event is dropped. It is time-driven, never output/token-driven.
|
|
33523
|
+
function startLifecycleStateWatchdog() {
|
|
33524
|
+
if (lifecycleStateWatchdogTimer) return;
|
|
33525
|
+
lifecycleStateWatchdogTimer = setInterval(() => {
|
|
33526
|
+
if (!runIndicatorIsActive()) {
|
|
33527
|
+
stopLifecycleStateWatchdog();
|
|
33528
|
+
return;
|
|
33529
|
+
}
|
|
33530
|
+
maybeRefreshRunIndicatorState();
|
|
33531
|
+
}, RUN_INDICATOR_STATE_RECHECK_MS);
|
|
33532
|
+
}
|
|
33533
|
+
|
|
33534
|
+
function stopLifecycleStateWatchdog() {
|
|
33535
|
+
clearInterval(lifecycleStateWatchdogTimer);
|
|
33536
|
+
lifecycleStateWatchdogTimer = null;
|
|
32747
33537
|
}
|
|
32748
33538
|
|
|
32749
33539
|
function createRunIndicatorBubble() {
|
|
32750
33540
|
runIndicatorBubble = make("article", "message runIndicator run-indicator-message streaming");
|
|
33541
|
+
// Stable transcript-owned activity root: streaming activity updates rewrite
|
|
33542
|
+
// only this bubble's own text nodes, never composer or chrome surfaces.
|
|
33543
|
+
runIndicatorBubble.dataset.streamOwned = "run-indicator";
|
|
32751
33544
|
runIndicatorBubble.setAttribute("aria-live", "polite");
|
|
32752
33545
|
runIndicatorBubble.setAttribute("aria-label", "Agent is running:");
|
|
32753
33546
|
|
|
@@ -32824,10 +33617,31 @@ function setRunIndicatorActivity(activity, { active = true, scroll = true } = {}
|
|
|
32824
33617
|
const needsRender = scroll || !hadRunIndicatorBubble || wasLocallyActive !== runIndicatorLocallyActive || previousActivity !== runIndicatorActivity;
|
|
32825
33618
|
if (needsRender) scheduleRunIndicatorRender({ scroll });
|
|
32826
33619
|
else if (runIndicatorIsActive()) startRunIndicatorTicker();
|
|
32827
|
-
|
|
33620
|
+
// Activity wording is transcript-owned. Composer/Stop chrome is reconciled
|
|
33621
|
+
// only when the lifecycle enum itself changes, so wording updates can never
|
|
33622
|
+
// reparent Steer/Follow-up controls or rewrite the run-active body class.
|
|
33623
|
+
syncLifecycleComposerState();
|
|
32828
33624
|
if (active) scheduleRunIndicatorGraceCheck();
|
|
32829
33625
|
}
|
|
32830
33626
|
|
|
33627
|
+
function currentLifecycleComposerSignature() {
|
|
33628
|
+
return [
|
|
33629
|
+
activeTabGeneration,
|
|
33630
|
+
isRunActive() ? "run" : "idle",
|
|
33631
|
+
isAbortAvailable() ? "abort" : "no-abort",
|
|
33632
|
+
abortRequestInFlight ? "aborting" : "ready",
|
|
33633
|
+
busyPromptBehavior,
|
|
33634
|
+
].join("|");
|
|
33635
|
+
}
|
|
33636
|
+
|
|
33637
|
+
function syncLifecycleComposerState({ force = false } = {}) {
|
|
33638
|
+
const signature = currentLifecycleComposerSignature();
|
|
33639
|
+
if (!force && signature === lifecycleComposerSignature) return false;
|
|
33640
|
+
lifecycleComposerSignature = signature;
|
|
33641
|
+
scheduleComposerModeButtonsUpdate();
|
|
33642
|
+
return true;
|
|
33643
|
+
}
|
|
33644
|
+
|
|
32831
33645
|
function clearRunIndicatorActivity({ render = true, deferRemoval = false } = {}) {
|
|
32832
33646
|
clearRunIndicatorGraceCheck();
|
|
32833
33647
|
runIndicatorLastStateCheckAt = 0;
|
|
@@ -32837,6 +33651,8 @@ function clearRunIndicatorActivity({ render = true, deferRemoval = false } = {})
|
|
|
32837
33651
|
runIndicatorRemovalDeferred = deferRemoval && runIndicatorBubble?.parentElement === elements.chat;
|
|
32838
33652
|
if (runIndicatorRemovalDeferred) stopRunIndicatorTicker();
|
|
32839
33653
|
else if (render) renderRunIndicator();
|
|
33654
|
+
stopLifecycleStateWatchdog();
|
|
33655
|
+
lifecycleComposerSignature = currentLifecycleComposerSignature();
|
|
32840
33656
|
updateComposerModeButtons();
|
|
32841
33657
|
}
|
|
32842
33658
|
|
|
@@ -32862,6 +33678,7 @@ function syncRunIndicatorFromState(state = currentState) {
|
|
|
32862
33678
|
} else {
|
|
32863
33679
|
renderRunIndicator();
|
|
32864
33680
|
}
|
|
33681
|
+
lifecycleComposerSignature = currentLifecycleComposerSignature();
|
|
32865
33682
|
updateComposerModeButtons();
|
|
32866
33683
|
}
|
|
32867
33684
|
|
|
@@ -35495,19 +36312,108 @@ function sessionSummaryStateForTab(tabId = activeTabId) {
|
|
|
35495
36312
|
return normalized;
|
|
35496
36313
|
}
|
|
35497
36314
|
|
|
36315
|
+
function sessionSummaryControlStatus(tabId) {
|
|
36316
|
+
const state = sessionSummaryStateForTab(tabId);
|
|
36317
|
+
if (state?.status === "generating") return "Generating session summary…";
|
|
36318
|
+
if (state?.status === "failure") return `Session summary failed: ${state.message || "unknown error"}`;
|
|
36319
|
+
if (state?.summaryMarkdown) return "Open the latest session summary";
|
|
36320
|
+
return "Open or create a session summary";
|
|
36321
|
+
}
|
|
36322
|
+
|
|
36323
|
+
function createTerminalTabSplitButton(tab) {
|
|
36324
|
+
const button = make("button", "terminal-tab-split-button");
|
|
36325
|
+
button.type = "button";
|
|
36326
|
+
button.draggable = false;
|
|
36327
|
+
const isOpenSplit = splitTabId === tab.id && !embeddedSplitMode && !isSidePanelOverlayView();
|
|
36328
|
+
button.disabled = embeddedSplitMode || isSidePanelOverlayView();
|
|
36329
|
+
button.setAttribute("aria-pressed", isOpenSplit ? "true" : "false");
|
|
36330
|
+
button.dataset.splitState = isOpenSplit ? "unsplit" : "split";
|
|
36331
|
+
const label = isOpenSplit ? `Close split view for ${tab.title || "Pi terminal"}` : `Split ${tab.title || "Pi terminal"} to the right`;
|
|
36332
|
+
applyStyledTooltip(button, label, { ariaLabel: label, targetKey: `terminal-tab:${tab.id}:split` });
|
|
36333
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
36334
|
+
const icon = document.createElementNS(ns, "svg");
|
|
36335
|
+
icon.setAttribute("class", "terminal-tab-action-icon terminal-tab-split-icon");
|
|
36336
|
+
icon.setAttribute("viewBox", "0 0 24 24");
|
|
36337
|
+
icon.setAttribute("aria-hidden", "true");
|
|
36338
|
+
icon.setAttribute("focusable", "false");
|
|
36339
|
+
const frame = document.createElementNS(ns, "rect");
|
|
36340
|
+
frame.setAttribute("x", "4");
|
|
36341
|
+
frame.setAttribute("y", "5");
|
|
36342
|
+
frame.setAttribute("width", "16");
|
|
36343
|
+
frame.setAttribute("height", "14");
|
|
36344
|
+
frame.setAttribute("rx", "2");
|
|
36345
|
+
frame.setAttribute("fill", "none");
|
|
36346
|
+
frame.setAttribute("stroke", "currentColor");
|
|
36347
|
+
frame.setAttribute("stroke-width", "2");
|
|
36348
|
+
const divider = document.createElementNS(ns, "path");
|
|
36349
|
+
divider.setAttribute("d", "M12 5v14M15 12h4m0 0-2-2m2 2-2 2");
|
|
36350
|
+
divider.setAttribute("fill", "none");
|
|
36351
|
+
divider.setAttribute("stroke", "currentColor");
|
|
36352
|
+
divider.setAttribute("stroke-width", "2");
|
|
36353
|
+
divider.setAttribute("stroke-linecap", "round");
|
|
36354
|
+
divider.setAttribute("stroke-linejoin", "round");
|
|
36355
|
+
icon.append(frame, divider);
|
|
36356
|
+
button.append(icon);
|
|
36357
|
+
button.addEventListener("click", (event) => {
|
|
36358
|
+
event.stopPropagation();
|
|
36359
|
+
void splitTerminalTab(tab.id, { triggerButton: button });
|
|
36360
|
+
});
|
|
36361
|
+
return button;
|
|
36362
|
+
}
|
|
36363
|
+
|
|
36364
|
+
function createTerminalTabActions(tab) {
|
|
36365
|
+
const actions = make("div", "terminal-tab-actions");
|
|
36366
|
+
actions.setAttribute("role", "group");
|
|
36367
|
+
actions.setAttribute("aria-label", `Actions for ${tab.title || "Pi terminal"}`);
|
|
36368
|
+
actions.append(createTerminalTabSplitButton(tab));
|
|
36369
|
+
const summary = createTerminalTabSessionSummaryButton(tab);
|
|
36370
|
+
if (summary) actions.append(summary);
|
|
36371
|
+
return actions;
|
|
36372
|
+
}
|
|
36373
|
+
|
|
36374
|
+
function createTerminalTabSessionSummaryButton(tab) {
|
|
36375
|
+
if (!tab?.id || !hasAvailableCommand("summary", { tabId: tab.id })) return null;
|
|
36376
|
+
const state = sessionSummaryStateForTab(tab.id);
|
|
36377
|
+
const status = sessionSummaryControlStatus(tab.id);
|
|
36378
|
+
const button = make("button", "terminal-tab-summary-button");
|
|
36379
|
+
button.type = "button";
|
|
36380
|
+
button.draggable = false;
|
|
36381
|
+
button.disabled = state?.status === "generating";
|
|
36382
|
+
button.setAttribute("aria-busy", state?.status === "generating" ? "true" : "false");
|
|
36383
|
+
button.setAttribute("aria-controls", "sessionSummaryOverlay");
|
|
36384
|
+
const label = `${status} for ${tab.title || "Pi terminal"}`;
|
|
36385
|
+
applyStyledTooltip(button, status, { ariaLabel: label, targetKey: `terminal-tab:${tab.id}:summary` });
|
|
36386
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
36387
|
+
const icon = document.createElementNS(ns, "svg");
|
|
36388
|
+
icon.setAttribute("class", "composer-icon");
|
|
36389
|
+
icon.setAttribute("viewBox", "0 0 24 24");
|
|
36390
|
+
icon.setAttribute("aria-hidden", "true");
|
|
36391
|
+
icon.setAttribute("focusable", "false");
|
|
36392
|
+
const page = document.createElementNS(ns, "path");
|
|
36393
|
+
page.setAttribute("d", "M5 4h14v16H5z");
|
|
36394
|
+
page.setAttribute("fill", "none");
|
|
36395
|
+
page.setAttribute("stroke", "currentColor");
|
|
36396
|
+
page.setAttribute("stroke-width", "2");
|
|
36397
|
+
page.setAttribute("stroke-linejoin", "round");
|
|
36398
|
+
const lines = document.createElementNS(ns, "path");
|
|
36399
|
+
lines.setAttribute("d", "M8 8h8M8 12h8M8 16h5");
|
|
36400
|
+
lines.setAttribute("fill", "none");
|
|
36401
|
+
lines.setAttribute("stroke", "currentColor");
|
|
36402
|
+
lines.setAttribute("stroke-width", "2");
|
|
36403
|
+
lines.setAttribute("stroke-linecap", "round");
|
|
36404
|
+
icon.append(page, lines);
|
|
36405
|
+
button.append(icon);
|
|
36406
|
+
button.addEventListener("click", (event) => {
|
|
36407
|
+
event.stopPropagation();
|
|
36408
|
+
void openSessionSummaryForTab(tab.id, { focusReturnKey: `terminal-tab:${tab.id}:summary` }).catch((error) => addEvent(error.message || String(error), "error"));
|
|
36409
|
+
});
|
|
36410
|
+
return button;
|
|
36411
|
+
}
|
|
36412
|
+
|
|
35498
36413
|
function renderSessionSummaryControls() {
|
|
35499
|
-
const available = !!activeTabId && hasAvailableCommand("summary", { tabId: activeTabId });
|
|
35500
36414
|
const setupAvailable = !!activeTabId && hasAvailableCommand("summary-setup", { tabId: activeTabId });
|
|
35501
|
-
const state = sessionSummaryStateForTab(activeTabId);
|
|
35502
|
-
const status = state?.status === "generating" ? "Generating session summary…" : state?.status === "failure" ? `Session summary failed: ${state.message || "unknown error"}` : state?.summaryMarkdown ? "Open the latest session summary" : "Open or create a session summary";
|
|
35503
|
-
for (const button of [elements.summaryHeaderButton, elements.summaryActionButton]) {
|
|
35504
|
-
if (!button) continue;
|
|
35505
|
-
button.hidden = !available;
|
|
35506
|
-
button.disabled = !available || state?.status === "generating";
|
|
35507
|
-
button.setAttribute("aria-busy", state?.status === "generating" ? "true" : "false");
|
|
35508
|
-
applyStyledTooltip(button, status, { ariaLabel: status, align: "end" });
|
|
35509
|
-
}
|
|
35510
36415
|
if (elements.optionsSummarySetupButton) elements.optionsSummarySetupButton.hidden = !setupAvailable;
|
|
36416
|
+
scheduleTabsRender();
|
|
35511
36417
|
}
|
|
35512
36418
|
|
|
35513
36419
|
function closeSessionSummaryOverlay({ restoreFocus = true } = {}) {
|
|
@@ -35515,9 +36421,19 @@ function closeSessionSummaryOverlay({ restoreFocus = true } = {}) {
|
|
|
35515
36421
|
if (!overlay || overlay.hidden) return;
|
|
35516
36422
|
overlay.hidden = true;
|
|
35517
36423
|
const focusReturn = sessionSummaryOverlayFocusReturn;
|
|
36424
|
+
const focusReturnKey = sessionSummaryOverlayFocusReturnKey;
|
|
36425
|
+
const keyedFocusReturn = focusReturnKey
|
|
36426
|
+
? [...elements.tabBar.querySelectorAll("button")].find((node) => terminalTabControlKey(node) === focusReturnKey)
|
|
36427
|
+
: null;
|
|
36428
|
+
const connectedFocusReturn = keyedFocusReturn || (focusReturn?.isConnected ? focusReturn : null);
|
|
35518
36429
|
sessionSummaryOverlayTabId = null;
|
|
35519
36430
|
sessionSummaryOverlayFocusReturn = null;
|
|
35520
|
-
|
|
36431
|
+
sessionSummaryOverlayFocusReturnKey = "";
|
|
36432
|
+
if (restoreFocus && connectedFocusReturn) {
|
|
36433
|
+
const groupKey = connectedFocusReturn.closest?.("[data-group-key]")?.dataset?.groupKey;
|
|
36434
|
+
if (groupKey) setOpenTerminalTabGroup(groupKey);
|
|
36435
|
+
queueMicrotask(() => connectedFocusReturn.focus({ preventScroll: true }));
|
|
36436
|
+
}
|
|
35521
36437
|
}
|
|
35522
36438
|
|
|
35523
36439
|
function renderSessionSummaryOverlay() {
|
|
@@ -35545,9 +36461,10 @@ function renderSessionSummaryOverlay() {
|
|
|
35545
36461
|
elements.sessionSummaryOverlayRefreshButton.textContent = generating ? "Generating…" : "Refresh";
|
|
35546
36462
|
}
|
|
35547
36463
|
|
|
35548
|
-
function openSessionSummaryOverlay(tabId, { loading = false } = {}) {
|
|
36464
|
+
function openSessionSummaryOverlay(tabId, { loading = false, focusReturnKey = "" } = {}) {
|
|
35549
36465
|
if (!tabId || !elements.sessionSummaryOverlay) return;
|
|
35550
36466
|
sessionSummaryOverlayFocusReturn = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
36467
|
+
sessionSummaryOverlayFocusReturnKey = focusReturnKey || terminalTabControlKey(sessionSummaryOverlayFocusReturn);
|
|
35551
36468
|
sessionSummaryOverlayTabId = tabId;
|
|
35552
36469
|
if (loading) {
|
|
35553
36470
|
const previous = sessionSummaryStateForTab(tabId);
|
|
@@ -35569,7 +36486,7 @@ function updateSessionSummaryForTab(tabId, value, { resetProjection = false } =
|
|
|
35569
36486
|
const normalized = normalizeSessionSummaryClientState(value, sessionSummaryByTab.get(tabId), { resetProjection });
|
|
35570
36487
|
if (!normalized) return null;
|
|
35571
36488
|
sessionSummaryByTab.set(tabId, normalized);
|
|
35572
|
-
|
|
36489
|
+
renderSessionSummaryControls();
|
|
35573
36490
|
if (sessionSummaryOverlayTabId === tabId) renderSessionSummaryOverlay();
|
|
35574
36491
|
return normalized;
|
|
35575
36492
|
}
|
|
@@ -35604,7 +36521,7 @@ async function requestSessionSummaryGeneration(tabId, { refresh = false } = {})
|
|
|
35604
36521
|
}
|
|
35605
36522
|
}
|
|
35606
36523
|
|
|
35607
|
-
async function openSessionSummaryForTab(tabId = activeTabId, { refresh = false } = {}) {
|
|
36524
|
+
async function openSessionSummaryForTab(tabId = activeTabId, { refresh = false, focusReturnKey = "" } = {}) {
|
|
35608
36525
|
if (!tabId || !hasAvailableCommand("summary", { tabId })) return;
|
|
35609
36526
|
let state = sessionSummaryStateForTab(tabId);
|
|
35610
36527
|
if (!state?.configured) {
|
|
@@ -35618,11 +36535,11 @@ async function openSessionSummaryForTab(tabId = activeTabId, { refresh = false }
|
|
|
35618
36535
|
updatedAt: new Date().toISOString(),
|
|
35619
36536
|
});
|
|
35620
36537
|
if (!response.data?.preferences?.configured) {
|
|
35621
|
-
await openNativeSessionSummarySetupDialog({ initialData: response.data });
|
|
36538
|
+
await openNativeSessionSummarySetupDialog({ initialData: response.data, tabId, focusReturnKey });
|
|
35622
36539
|
return;
|
|
35623
36540
|
}
|
|
35624
36541
|
}
|
|
35625
|
-
openSessionSummaryOverlay(tabId, { loading: refresh || !state?.summaryMarkdown });
|
|
36542
|
+
openSessionSummaryOverlay(tabId, { loading: refresh || !state?.summaryMarkdown, focusReturnKey });
|
|
35626
36543
|
if (refresh || !state?.summaryMarkdown) await requestSessionSummaryGeneration(tabId, { refresh }).catch(() => {});
|
|
35627
36544
|
}
|
|
35628
36545
|
|
|
@@ -36421,8 +37338,8 @@ function gitWorkflowSetupModelKey(model) {
|
|
|
36421
37338
|
return model?.provider && model?.id ? `${model.provider}/${model.id}` : "";
|
|
36422
37339
|
}
|
|
36423
37340
|
|
|
36424
|
-
async function openNativeSessionSummarySetupDialog({ initialData = null, onSaved } = {}) {
|
|
36425
|
-
nativeCommandTabId =
|
|
37341
|
+
async function openNativeSessionSummarySetupDialog({ initialData = null, onSaved, tabId = activeTabId, focusReturnKey = "" } = {}) {
|
|
37342
|
+
nativeCommandTabId = tabId;
|
|
36426
37343
|
openNativeCommandDialog({
|
|
36427
37344
|
title: "/summary-setup",
|
|
36428
37345
|
message: "Configure persistent background titles and Markdown summaries. Saving confirms the disclosure below, then immediately generates and opens the first summary.",
|
|
@@ -36519,10 +37436,11 @@ async function openNativeSessionSummarySetupDialog({ initialData = null, onSaved
|
|
|
36519
37436
|
const summaryPrompt = controls.summaryPrompt.textarea.value.trim();
|
|
36520
37437
|
if (!titlePrompt || !summaryPrompt) throw new Error("Both editable prompts are required.");
|
|
36521
37438
|
if (titlePrompt.length > SESSION_SUMMARY_PROMPT_MAX_CHARS || summaryPrompt.length > SESSION_SUMMARY_PROMPT_MAX_CHARS) throw new Error("Each editable prompt must not exceed 8 KiB.");
|
|
37439
|
+
const targetTabId = nativeCommandTabId || tabId || activeTabId;
|
|
36522
37440
|
const reviewed = await appConfirm({
|
|
36523
37441
|
title: "Save session summary setup?",
|
|
36524
37442
|
summary: `${disclosure.scope || "Selected active-branch text and tool names will be sent to the configured model."}\n\n${disclosure.cost || "Generation may incur provider usage."}`,
|
|
36525
|
-
affected: "Global session-summary preferences and the
|
|
37443
|
+
affected: "Global session-summary preferences and the selected tab's first generated summary",
|
|
36526
37444
|
undoable: false,
|
|
36527
37445
|
confirmLabel: "Save and generate",
|
|
36528
37446
|
danger: false,
|
|
@@ -36530,6 +37448,7 @@ async function openNativeSessionSummarySetupDialog({ initialData = null, onSaved
|
|
|
36530
37448
|
if (!reviewed) return;
|
|
36531
37449
|
const response = await nativeCommandApi("/api/session-summary/preferences", {
|
|
36532
37450
|
method: "PUT",
|
|
37451
|
+
tabId: targetTabId,
|
|
36533
37452
|
body: {
|
|
36534
37453
|
confirmed: true,
|
|
36535
37454
|
preferences: {
|
|
@@ -36542,7 +37461,6 @@ async function openNativeSessionSummarySetupDialog({ initialData = null, onSaved
|
|
|
36542
37461
|
},
|
|
36543
37462
|
},
|
|
36544
37463
|
});
|
|
36545
|
-
const targetTabId = nativeCommandTabId || activeTabId;
|
|
36546
37464
|
updateSessionSummaryForTab(targetTabId, response.data?.summary || {
|
|
36547
37465
|
version: SESSION_SUMMARY_PROTOCOL_VERSION,
|
|
36548
37466
|
status: "idle",
|
|
@@ -36553,7 +37471,7 @@ async function openNativeSessionSummarySetupDialog({ initialData = null, onSaved
|
|
|
36553
37471
|
});
|
|
36554
37472
|
nativeSettingsDirty = false;
|
|
36555
37473
|
closeNativeCommandDialog({ force: true });
|
|
36556
|
-
openSessionSummaryOverlay(targetTabId, { loading: true });
|
|
37474
|
+
openSessionSummaryOverlay(targetTabId, { loading: true, focusReturnKey });
|
|
36557
37475
|
await requestSessionSummaryGeneration(targetTabId, { refresh: true }).catch(() => {});
|
|
36558
37476
|
if (typeof onSaved === "function") await onSaved(response.data?.preferences);
|
|
36559
37477
|
} catch (error) {
|
|
@@ -36623,6 +37541,10 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
|
|
|
36623
37541
|
{ value: "preserve", label: "Use current staged set" },
|
|
36624
37542
|
{ value: "all", label: "Stage all with git add ." },
|
|
36625
37543
|
], "Review/select is the safe default and opens Git Changes for per-file staging.", { label: "safety", tone: "safety" }),
|
|
37544
|
+
reviewProcess: nativeSettingSelect("Manual review process", preferences.reviewProcessEnabled !== false ? "enabled" : "disabled", [
|
|
37545
|
+
{ value: "enabled", label: "Enabled when aur-review is available" },
|
|
37546
|
+
{ value: "disabled", label: "Disabled — continue to message generation" },
|
|
37547
|
+
], "When enabled, staged changes require explicit approval before message, worktree, or commit actions.", { label: "safety", tone: "safety" }),
|
|
36626
37548
|
delivery: nativeSettingSelect("Delivery path", preferences.deliveryMode || "ask", [
|
|
36627
37549
|
{ value: "ask", label: "Ask each workflow" },
|
|
36628
37550
|
{ value: "current", label: "Prefer current branch" },
|
|
@@ -36651,7 +37573,7 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
|
|
|
36651
37573
|
nativeSettingsNote("Persistence", `Saved globally in ${data.path || "the Pi Web UI settings file"}. Credentials are never stored here.`),
|
|
36652
37574
|
nativeSettingsSection("Generation profile", "Required model and effort for generated Git text.", [controls.model, controls.thinking], { open: true }),
|
|
36653
37575
|
nativeSettingsSection("Commit style", "Conventional Commit output preferences.", [controls.language, controls.defaultVariant, controls.scope], { open: true }),
|
|
36654
|
-
nativeSettingsSection("Workflow safety", "Staging, delivery, and verification defaults; push and PR confirmation remain mandatory.", [controls.staging, controls.delivery, controls.verification], { open: true }),
|
|
37576
|
+
nativeSettingsSection("Workflow safety", "Staging, review, delivery, and verification defaults; push and PR confirmation remain mandatory.", [controls.staging, controls.reviewProcess, controls.delivery, controls.verification], { open: true }),
|
|
36655
37577
|
);
|
|
36656
37578
|
elements.nativeCommandBody.replaceChildren(body);
|
|
36657
37579
|
elements.nativeCommandActions.replaceChildren();
|
|
@@ -36679,6 +37601,7 @@ async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
|
|
|
36679
37601
|
scope: controls.scope.select.value,
|
|
36680
37602
|
},
|
|
36681
37603
|
stagingPolicy: controls.staging.select.value,
|
|
37604
|
+
reviewProcessEnabled: controls.reviewProcess.select.value === "enabled",
|
|
36682
37605
|
deliveryMode: controls.delivery.select.value,
|
|
36683
37606
|
verificationPolicy: controls.verification.select.value,
|
|
36684
37607
|
},
|
|
@@ -37682,6 +38605,9 @@ function insertNumpadDecimal(event) {
|
|
|
37682
38605
|
return true;
|
|
37683
38606
|
}
|
|
37684
38607
|
|
|
38608
|
+
// Transcript-only. Message rendering may reconcile transcript state and the
|
|
38609
|
+
// transcript DOM, but never footer/feedback/widget chrome: those surfaces are
|
|
38610
|
+
// owned by the coalesced semantic reconciler.
|
|
37685
38611
|
function renderMessages(messages) {
|
|
37686
38612
|
latestMessages = messages || [];
|
|
37687
38613
|
reconcileOptimisticUserPrompts(latestMessages);
|
|
@@ -37690,8 +38616,6 @@ function renderMessages(messages) {
|
|
|
37690
38616
|
syncPromptHistoryFromMessages(latestMessages);
|
|
37691
38617
|
trackSkillsFromMessages(latestMessages, activeTabId);
|
|
37692
38618
|
renderAllMessages();
|
|
37693
|
-
renderFooter();
|
|
37694
|
-
renderFeedbackTray();
|
|
37695
38619
|
}
|
|
37696
38620
|
|
|
37697
38621
|
function cancelStreamBubbleHide() {
|
|
@@ -37836,10 +38760,6 @@ function handleCompactMessageUpdate(event) {
|
|
|
37836
38760
|
if (!reduced.changed) return true;
|
|
37837
38761
|
compactLiveState = reduced.state;
|
|
37838
38762
|
clearCompactToolShells();
|
|
37839
|
-
if (reduced.kind.startsWith("thinking")) setRunIndicatorActivity("Thinking…", { scroll: false });
|
|
37840
|
-
else if (reduced.kind.startsWith("toolcall")) setRunIndicatorActivity("Building tool call…", { scroll: false });
|
|
37841
|
-
else setRunIndicatorActivity("Writing response…", { scroll: false });
|
|
37842
|
-
compactLiveScheduler.request();
|
|
37843
38763
|
return true;
|
|
37844
38764
|
}
|
|
37845
38765
|
|
|
@@ -37899,15 +38819,7 @@ function applyOutputModeControl(event, tabContext = activeTabContext()) {
|
|
|
37899
38819
|
return true;
|
|
37900
38820
|
}
|
|
37901
38821
|
|
|
37902
|
-
function cancelStreamingAssistantTextRender() {
|
|
37903
|
-
clearTimeout(streamTextRenderTimer);
|
|
37904
|
-
streamTextRenderTimer = null;
|
|
37905
|
-
if (streamTextRenderFrame !== null && typeof cancelAnimationFrame === "function") cancelAnimationFrame(streamTextRenderFrame);
|
|
37906
|
-
streamTextRenderFrame = null;
|
|
37907
|
-
}
|
|
37908
|
-
|
|
37909
38822
|
function removeStreamBubble() {
|
|
37910
|
-
cancelStreamingAssistantTextRender();
|
|
37911
38823
|
cancelStreamBubbleHide();
|
|
37912
38824
|
removeLiveTranscriptBubble(streamBubble, "assistant");
|
|
37913
38825
|
streamBubble = null;
|
|
@@ -38054,18 +38966,6 @@ function renderStreamingAssistantText() {
|
|
|
38054
38966
|
}
|
|
38055
38967
|
}
|
|
38056
38968
|
|
|
38057
|
-
function scheduleStreamingAssistantTextRender({ immediate = false } = {}) {
|
|
38058
|
-
if (streamTextRenderTimer || streamTextRenderFrame !== null) return;
|
|
38059
|
-
const flush = () => {
|
|
38060
|
-
streamTextRenderTimer = null;
|
|
38061
|
-
streamTextRenderFrame = null;
|
|
38062
|
-
renderStreamingAssistantText();
|
|
38063
|
-
scheduleChatFollowScroll();
|
|
38064
|
-
};
|
|
38065
|
-
if (immediate && typeof requestAnimationFrame === "function") streamTextRenderFrame = requestAnimationFrame(flush);
|
|
38066
|
-
else streamTextRenderTimer = setTimeout(flush, immediate ? 0 : STREAM_OUTPUT_TOOLCALL_GUARD_MS);
|
|
38067
|
-
}
|
|
38068
|
-
|
|
38069
38969
|
function suppressStreamingAssistantTextBeforeToolCall() {
|
|
38070
38970
|
setStreamRawText("");
|
|
38071
38971
|
removeStreamBubble();
|
|
@@ -38162,7 +39062,6 @@ function showStreamingThinking(initialText = "") {
|
|
|
38162
39062
|
|
|
38163
39063
|
function resetStreamBubble({ preserveCompact = false } = {}) {
|
|
38164
39064
|
resetCompactLiveOutput({ remove: !preserveCompact });
|
|
38165
|
-
cancelStreamingAssistantTextRender();
|
|
38166
39065
|
cancelStreamBubbleHide();
|
|
38167
39066
|
streamBubble = null;
|
|
38168
39067
|
streamText = null;
|
|
@@ -38401,52 +39300,35 @@ function handleMessageUpdate(event) {
|
|
|
38401
39300
|
if (compactOutputActive() && handleCompactMessageUpdate(event)) return;
|
|
38402
39301
|
const update = event.assistantMessageEvent || {};
|
|
38403
39302
|
if (update.type === "thinking_start") {
|
|
38404
|
-
setRunIndicatorActivity("Thinking…", { scroll: false });
|
|
38405
39303
|
syncStreamingThinkingFromUpdate(event, update);
|
|
38406
|
-
scheduleChatFollowScroll();
|
|
38407
39304
|
} else if (update.type === "thinking_delta") {
|
|
38408
39305
|
const delta = thinkingDeltaText(update);
|
|
38409
|
-
setRunIndicatorActivity("Thinking…", { scroll: false });
|
|
38410
39306
|
const synced = syncStreamingThinkingFromUpdate(event, update);
|
|
38411
39307
|
if (thinkingOutputVisible && delta && (!synced || !streamThinking?.textContent)) {
|
|
38412
39308
|
showStreamingThinking("");
|
|
38413
39309
|
if (streamThinking) renderThinkingMarkdown(streamThinking, `${streamThinking._rawThinkingText || ""}${delta}`);
|
|
38414
39310
|
}
|
|
38415
|
-
scheduleChatFollowScroll();
|
|
38416
39311
|
} else if (update.type === "thinking_end") {
|
|
38417
39312
|
if (syncStreamingThinkingFromUpdate(event, update)) streamThinkingBubble?.classList.add("complete");
|
|
38418
|
-
setRunIndicatorActivity("Finished thinking; waiting for the next output or action…", { scroll: false });
|
|
38419
39313
|
} else if (update.type === "text_delta" || update.type === "text_end") {
|
|
38420
39314
|
syncStreamRawTextFromUpdate(event, update);
|
|
38421
|
-
|
|
38422
|
-
setRunIndicatorActivity("Writing response…", { scroll: false });
|
|
38423
|
-
scheduleStreamingAssistantTextRender({ immediate: !!(streamToolCallSeen || streamBubble) });
|
|
38424
|
-
// Streaming output must stay transcript-local. Full footer/status
|
|
38425
|
-
// reconciliation happens on message/state refreshes, not per token.
|
|
38426
|
-
scheduleChatFollowScroll();
|
|
39315
|
+
renderStreamingAssistantText();
|
|
38427
39316
|
} else if (update.type === "toolcall_start") {
|
|
38428
39317
|
streamToolCallSeen = true;
|
|
38429
39318
|
suppressStreamingAssistantTextBeforeToolCall();
|
|
38430
|
-
|
|
38431
|
-
setRunIndicatorActivity(`Building tool call: ${name}…`, { scroll: false });
|
|
38432
|
-
addEvent(`tool call started in assistant message`, "info");
|
|
39319
|
+
updateStreamingToolCallFromEvent(event, { reset: true });
|
|
38433
39320
|
} else if (update.type === "toolcall_delta") {
|
|
38434
39321
|
streamToolCallSeen = true;
|
|
38435
39322
|
suppressStreamingAssistantTextBeforeToolCall();
|
|
38436
|
-
|
|
38437
|
-
setRunIndicatorActivity(`Building tool call: ${name}…`, { scroll: false });
|
|
38438
|
-
scheduleChatFollowScroll();
|
|
39323
|
+
updateStreamingToolCallFromEvent(event, { appendDelta: true });
|
|
38439
39324
|
} else if (update.type === "toolcall_end") {
|
|
38440
39325
|
streamToolCallSeen = true;
|
|
38441
39326
|
suppressStreamingAssistantTextBeforeToolCall();
|
|
38442
|
-
|
|
38443
|
-
setRunIndicatorActivity(`Tool call ready: ${name}; waiting to run…`, { scroll: false });
|
|
39327
|
+
updateStreamingToolCallFromEvent(event, { complete: true });
|
|
38444
39328
|
} else if (update.type === "error") {
|
|
38445
39329
|
streamProviderErrorText = assistantStreamErrorMessage(event, update);
|
|
38446
|
-
setRunIndicatorActivity("Assistant stream reported an error…");
|
|
38447
39330
|
appendMessage({ role: "error", title: "assistant error", timestamp: Date.now(), content: streamProviderErrorText, level: "error" }, { streaming: true });
|
|
38448
39331
|
renderRunIndicator({ scroll: false });
|
|
38449
|
-
scheduleChatFollowScroll();
|
|
38450
39332
|
}
|
|
38451
39333
|
}
|
|
38452
39334
|
|
|
@@ -38742,7 +39624,13 @@ async function refreshMessages(tabContext = activeTabContext(), { authoritative
|
|
|
38742
39624
|
else if (preserveNormalStream) restoreStreamRenderAfterChatRebuild();
|
|
38743
39625
|
restoreChatTextSelection(selectionSnapshot);
|
|
38744
39626
|
markTabOutputSeen();
|
|
38745
|
-
|
|
39627
|
+
// Authoritative content just landed: derive the todo-progress record once
|
|
39628
|
+
// here instead of from raw token cadence, and let the coalesced semantic
|
|
39629
|
+
// reconciler own the footer/widget chrome that message data can change.
|
|
39630
|
+
// syncLiveTodoProgressWidgetFromText owns the frame-coalesced widget render
|
|
39631
|
+
// and only fires when the parsed checklist value actually changed.
|
|
39632
|
+
reconcileTodoProgressFromMessages(latestMessages, tabContext.tabId);
|
|
39633
|
+
scheduleSemanticReconcile({ footer: true }, tabContext);
|
|
38746
39634
|
}
|
|
38747
39635
|
|
|
38748
39636
|
async function refreshModels(tabContext = activeTabContext()) {
|
|
@@ -39527,6 +40415,7 @@ function renderCommands() {
|
|
|
39527
40415
|
async function refreshCommands(tabContext = activeTabContext()) {
|
|
39528
40416
|
if (!tabContext.tabId) return;
|
|
39529
40417
|
const response = await api("/api/commands", { tabId: tabContext.tabId });
|
|
40418
|
+
if (!tabs.some((tab) => tab.id === tabContext.tabId)) return;
|
|
39530
40419
|
const catalog = {
|
|
39531
40420
|
raw: normalizeCommands(response.data?.commands || [], { dedupe: false }),
|
|
39532
40421
|
available: normalizeCommands(response.data?.commands || []),
|
|
@@ -39535,6 +40424,7 @@ async function refreshCommands(tabContext = activeTabContext()) {
|
|
|
39535
40424
|
// while this request was in flight. Guided Git must never borrow another
|
|
39536
40425
|
// tab's extension availability or duplicate-command alias.
|
|
39537
40426
|
commandCatalogsByTab.set(tabContext.tabId, catalog);
|
|
40427
|
+
scheduleTabsRender();
|
|
39538
40428
|
if (!isCurrentTabContext(tabContext)) return;
|
|
39539
40429
|
rawAvailableCommands = catalog.raw;
|
|
39540
40430
|
availableCommands = catalog.available;
|
|
@@ -40965,7 +41855,39 @@ function handleInactiveTabEvent(event) {
|
|
|
40965
41855
|
}
|
|
40966
41856
|
}
|
|
40967
41857
|
|
|
41858
|
+
const TRANSCRIPT_STREAM_BARRIER_EVENT_TYPES = new Set([
|
|
41859
|
+
"agent_start",
|
|
41860
|
+
"message_start",
|
|
41861
|
+
"message_end",
|
|
41862
|
+
"tool_execution_start",
|
|
41863
|
+
"tool_execution_end",
|
|
41864
|
+
"agent_end",
|
|
41865
|
+
"agent_settled",
|
|
41866
|
+
"auto_retry_start",
|
|
41867
|
+
"auto_retry_end",
|
|
41868
|
+
"compaction_start",
|
|
41869
|
+
"compaction_end",
|
|
41870
|
+
"webui_output_mode",
|
|
41871
|
+
"pi_process_exit",
|
|
41872
|
+
"pi_process_error",
|
|
41873
|
+
]);
|
|
41874
|
+
|
|
41875
|
+
function dispatchTranscriptStreamEvent(event) {
|
|
41876
|
+
return streamOutputController.dispatch(event, {
|
|
41877
|
+
owner: transcriptStreamOwner(event?.tabId || activeTabId),
|
|
41878
|
+
});
|
|
41879
|
+
}
|
|
41880
|
+
|
|
41881
|
+
function flushTranscriptStreamBarrier(event) {
|
|
41882
|
+
if (!TRANSCRIPT_STREAM_BARRIER_EVENT_TYPES.has(event?.type)) return;
|
|
41883
|
+
streamOutputController.barrier(event.type);
|
|
41884
|
+
reconcileUnknownTranscriptEvidenceAtBarrier(event);
|
|
41885
|
+
if (event.type === "pi_process_exit" || event.type === "pi_process_error") streamOutputController.cancel();
|
|
41886
|
+
}
|
|
41887
|
+
|
|
40968
41888
|
function handleEvent(event) {
|
|
41889
|
+
if (dispatchTranscriptStreamEvent(event)) return;
|
|
41890
|
+
flushTranscriptStreamBarrier(event);
|
|
40969
41891
|
if (event?.type === "webui_session_summary") {
|
|
40970
41892
|
handleSessionSummaryEvent(event);
|
|
40971
41893
|
return;
|
|
@@ -40988,6 +41910,10 @@ function handleEvent(event) {
|
|
|
40988
41910
|
}
|
|
40989
41911
|
if (eventHasTabActivityPayload(event)) ingestEventTabActivity(event);
|
|
40990
41912
|
if (event?.type === "auto_retry_start" || event?.type === "auto_retry_end") trackAutoRetryStateFromEvent(event);
|
|
41913
|
+
// Advance the fallback tool-boundary epoch before inactive-tab routing.
|
|
41914
|
+
// Inactive tool boundaries are still tracked, so their agent_start must own
|
|
41915
|
+
// the same run identity semantics as the foreground tab.
|
|
41916
|
+
if (event?.type === "agent_start") beginToolBoundaryRun(event);
|
|
40991
41917
|
if (eventMayAffectSkillUsage(event)) trackSkillsFromEvent(event);
|
|
40992
41918
|
if (!eventTargetsActiveTab(event)) {
|
|
40993
41919
|
handleInactiveTabEvent(event);
|
|
@@ -41171,9 +42097,8 @@ function handleEvent(event) {
|
|
|
41171
42097
|
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ streaming: true });
|
|
41172
42098
|
setRunIndicatorActivity("Agent run started; waiting for first output or action…");
|
|
41173
42099
|
addEvent("agent started");
|
|
41174
|
-
|
|
41175
|
-
|
|
41176
|
-
renderFeedbackTray();
|
|
42100
|
+
syncLifecycleComposerState({ force: true });
|
|
42101
|
+
scheduleSemanticReconcile({ state: true, footer: true, feedback: true }, tabContext);
|
|
41177
42102
|
break;
|
|
41178
42103
|
case "agent_end":
|
|
41179
42104
|
if (compactOutputActive()) finishCompactLiveOutput(tabContext);
|
|
@@ -41187,9 +42112,7 @@ function handleEvent(event) {
|
|
|
41187
42112
|
}
|
|
41188
42113
|
addEvent("agent run ended; waiting for settlement");
|
|
41189
42114
|
if (runIndicatorIsActive()) setRunIndicatorActivity("Agent run ended; checking for retry or continuation…", { scroll: false });
|
|
41190
|
-
|
|
41191
|
-
scheduleRefreshState();
|
|
41192
|
-
scheduleRefreshFooter();
|
|
42115
|
+
scheduleSemanticReconcile({ messages: true, state: true, footerData: true }, tabContext);
|
|
41193
42116
|
break;
|
|
41194
42117
|
case "message_start":
|
|
41195
42118
|
if (event.message?.role === "assistant") {
|
|
@@ -41198,9 +42121,6 @@ function handleEvent(event) {
|
|
|
41198
42121
|
setRunIndicatorActivity("Starting assistant message…", { scroll: false });
|
|
41199
42122
|
}
|
|
41200
42123
|
break;
|
|
41201
|
-
case "message_update":
|
|
41202
|
-
handleMessageUpdate(event);
|
|
41203
|
-
break;
|
|
41204
42124
|
case "message_end": {
|
|
41205
42125
|
if (compactOutputActive()) finishCompactLiveOutput(tabContext);
|
|
41206
42126
|
streamMessageActive = false;
|
|
@@ -41211,9 +42131,9 @@ function handleEvent(event) {
|
|
|
41211
42131
|
}
|
|
41212
42132
|
streamProviderErrorText = "";
|
|
41213
42133
|
if (runIndicatorIsActive()) setRunIndicatorActivity("Assistant message finished; waiting for the next step…", { scroll: false });
|
|
41214
|
-
|
|
41215
|
-
|
|
41216
|
-
|
|
42134
|
+
// Authoritative message reconciliation derives the todo-progress record;
|
|
42135
|
+
// raw assistant tokens never rebuild widgets.
|
|
42136
|
+
scheduleSemanticReconcile({ messages: true, state: true, footerData: true }, tabContext);
|
|
41217
42137
|
break;
|
|
41218
42138
|
}
|
|
41219
42139
|
case "tool_execution_start":
|
|
@@ -41228,11 +42148,7 @@ function handleEvent(event) {
|
|
|
41228
42148
|
handleToolExecutionStart(event);
|
|
41229
42149
|
}
|
|
41230
42150
|
setRunIndicatorActivity(`Running tool: ${runIndicatorToolName(event.toolName)}…`);
|
|
41231
|
-
addEvent(`tool ${event.toolName} started`, "info", { toolCallId: event.toolCallId });
|
|
41232
|
-
break;
|
|
41233
|
-
case "tool_execution_update":
|
|
41234
|
-
if (!compactOutputActive()) handleToolExecutionUpdate(event);
|
|
41235
|
-
setRunIndicatorActivity(`Running tool: ${runIndicatorToolName(event.toolName)}…`, { scroll: false });
|
|
42151
|
+
if (claimToolBoundaryRecord(event, "log:start")) addEvent(`tool ${event.toolName} started`, "info", { toolCallId: event.toolCallId });
|
|
41236
42152
|
break;
|
|
41237
42153
|
case "tool_execution_end": {
|
|
41238
42154
|
if (voiceConversationActiveFor(event.tabId || activeTabId)) voiceConversation.setAssistantActivity({ toolRunning: false });
|
|
@@ -41246,10 +42162,10 @@ function handleEvent(event) {
|
|
|
41246
42162
|
handleToolExecutionEnd(event);
|
|
41247
42163
|
}
|
|
41248
42164
|
setRunIndicatorActivity(`Tool ${runIndicatorToolName(event.toolName)} ${event.isError ? "failed" : "finished"}; waiting for the agent's next step…`);
|
|
41249
|
-
addEvent(`tool ${event.toolName} ${event.isError ? "failed" : "finished"}`, event.isError ? "error" : "info", { toolCallId: event.toolCallId });
|
|
42165
|
+
if (claimToolBoundaryRecord(event, "log:end")) addEvent(`tool ${event.toolName} ${event.isError ? "failed" : "finished"}`, event.isError ? "error" : "info", { toolCallId: event.toolCallId });
|
|
41250
42166
|
// Compact tool shells deliberately defer rich body construction to the
|
|
41251
42167
|
// final transcript reconciliation; normal mode retains its live card.
|
|
41252
|
-
|
|
42168
|
+
scheduleSemanticReconcile({ footerData: true }, tabContext);
|
|
41253
42169
|
break;
|
|
41254
42170
|
}
|
|
41255
42171
|
case "compaction_start":
|
|
@@ -41269,9 +42185,7 @@ function handleEvent(event) {
|
|
|
41269
42185
|
if (!currentState?.isStreaming) clearRunIndicatorActivity();
|
|
41270
42186
|
markTabOutputSeen();
|
|
41271
42187
|
renderStatus();
|
|
41272
|
-
|
|
41273
|
-
scheduleRefreshMessages();
|
|
41274
|
-
scheduleRefreshFooter();
|
|
42188
|
+
scheduleSemanticReconcile({ state: true, messages: true, footerData: true }, tabContext);
|
|
41275
42189
|
break;
|
|
41276
42190
|
case "agent_settled":
|
|
41277
42191
|
promptRoutingTabs.delete(event.tabId || activeTabId);
|
|
@@ -41288,24 +42202,17 @@ function handleEvent(event) {
|
|
|
41288
42202
|
clearRunIndicatorActivity({ deferRemoval: !autoFollowChat || !isChatNearBottom() });
|
|
41289
42203
|
markTabOutputSeen();
|
|
41290
42204
|
requestGitFooterWebuiPayload(tabContext, { force: true });
|
|
41291
|
-
|
|
41292
|
-
|
|
41293
|
-
|
|
41294
|
-
|
|
41295
|
-
|
|
41296
|
-
|
|
41297
|
-
|
|
41298
|
-
|
|
41299
|
-
|
|
41300
|
-
|
|
41301
|
-
|
|
41302
|
-
loadGitWorkflowMessage({ requireFresh: true, generationId: workflow.messageGenerationId, runId: workflow.runId, tabId: workflowTabId });
|
|
41303
|
-
} else if (workflow?.active && workflow.step === "branchNaming") {
|
|
41304
|
-
loadGitWorkflowBranchName({ requireFresh: true, retries: 3, runId: workflow.runId, tabId: workflowTabId });
|
|
41305
|
-
} else if (workflow?.active && workflow.step === "prGenerating") {
|
|
41306
|
-
loadGitWorkflowPr({ requireFresh: true, retries: 3, runId: workflow.runId, tabId: workflowTabId });
|
|
41307
|
-
}
|
|
41308
|
-
}
|
|
42205
|
+
// Settlement is the one boundary allowed to reconcile the full changed
|
|
42206
|
+
// set; it runs once here through the coalesced semantic scheduler.
|
|
42207
|
+
syncLifecycleComposerState({ force: true });
|
|
42208
|
+
scheduleSemanticReconcile({
|
|
42209
|
+
state: true,
|
|
42210
|
+
messages: true,
|
|
42211
|
+
footerData: true,
|
|
42212
|
+
feedback: true,
|
|
42213
|
+
usage: true,
|
|
42214
|
+
workflow: true,
|
|
42215
|
+
}, tabContext);
|
|
41309
42216
|
break;
|
|
41310
42217
|
case "auto_retry_start": {
|
|
41311
42218
|
const seconds = Math.max(0, Math.ceil(Number(event.delayMs || 0) / 1000));
|
|
@@ -41366,6 +42273,7 @@ function handleEvent(event) {
|
|
|
41366
42273
|
function connectEvents(tabContext = activeTabContext(), { requestedMode = "auto", fallbackAttempted = false } = {}) {
|
|
41367
42274
|
eventSource?.close();
|
|
41368
42275
|
eventSource = null;
|
|
42276
|
+
streamOutputController.cancel();
|
|
41369
42277
|
resetCompactLiveOutput();
|
|
41370
42278
|
activeOutputMode = "normal";
|
|
41371
42279
|
outputModeAcknowledged = false;
|
|
@@ -41395,6 +42303,8 @@ function connectEvents(tabContext = activeTabContext(), { requestedMode = "auto"
|
|
|
41395
42303
|
};
|
|
41396
42304
|
source.onerror = () => {
|
|
41397
42305
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
42306
|
+
streamOutputController.flush();
|
|
42307
|
+
streamOutputController.cancel();
|
|
41398
42308
|
if (compactOutputActive()) compactLiveScheduler.flushNow();
|
|
41399
42309
|
addEvent("event stream disconnected; browser will retry", "warn");
|
|
41400
42310
|
fetch("/api/health", { cache: "no-store" }).catch((error) => setBackendOffline(true, error));
|
|
@@ -41571,16 +42481,7 @@ elements.newTabMenu?.addEventListener("focusout", () => {
|
|
|
41571
42481
|
elements.newTabCurrentDirectoryButton?.addEventListener("click", () => createTerminalTab(currentDirectoryForNewTab(), { triggerButton: elements.newTabCurrentDirectoryButton }));
|
|
41572
42482
|
elements.newTabChooseDirectoryButton?.addEventListener("click", () => createTerminalTabFromChosenDirectory({ triggerButton: elements.newTabChooseDirectoryButton }));
|
|
41573
42483
|
elements.newTabWorktreeButton?.addEventListener("click", () => openBranchWorktreePicker());
|
|
41574
|
-
elements.splitTabButton?.addEventListener("click", () => splitActiveTerminalTab());
|
|
41575
42484
|
elements.workspaceSaveButton?.addEventListener("click", () => saveWebuiWorkspace());
|
|
41576
|
-
const openActiveSessionSummary = () => {
|
|
41577
|
-
void openSessionSummaryForTab().catch((error) => addEvent(error.message || String(error), "error"));
|
|
41578
|
-
};
|
|
41579
|
-
elements.summaryHeaderButton?.addEventListener("click", openActiveSessionSummary);
|
|
41580
|
-
elements.summaryActionButton?.addEventListener("click", () => {
|
|
41581
|
-
setComposerActionsOpen(false);
|
|
41582
|
-
openActiveSessionSummary();
|
|
41583
|
-
});
|
|
41584
42485
|
elements.terminalSplitCloseButton?.addEventListener("click", () => closeTerminalSplitView());
|
|
41585
42486
|
elements.closeAllTabsButton.addEventListener("click", () => closeAllTerminalTabs());
|
|
41586
42487
|
elements.commandPaletteButton?.addEventListener("click", () => openCommandPalette());
|
|
@@ -42058,6 +42959,8 @@ function resetAbortLongPressAffordance() {
|
|
|
42058
42959
|
async function abortActiveRun({ source = "button" } = {}) {
|
|
42059
42960
|
if (abortRequestInFlight || !isAbortAvailable()) return;
|
|
42060
42961
|
const tabContext = activeTabContext();
|
|
42962
|
+
streamOutputController.barrier("user-abort");
|
|
42963
|
+
reconcileUnknownTranscriptEvidenceAtBarrier({ type: "user_abort", tabId: tabContext.tabId });
|
|
42061
42964
|
abortRequestInFlight = true;
|
|
42062
42965
|
resetAbortLongPressAffordance();
|
|
42063
42966
|
updateComposerModeButtons();
|
|
@@ -42254,6 +43157,33 @@ elements.themeSchemeToggle?.querySelectorAll("[data-scheme-mode]").forEach((butt
|
|
|
42254
43157
|
setThemeSchemeMode(button.dataset.schemeMode, { announce: true }).catch((error) => addEvent(error.message || String(error), "error"));
|
|
42255
43158
|
});
|
|
42256
43159
|
});
|
|
43160
|
+
elements.themeCustomizeButton?.addEventListener("click", () => openThemeCustomizer().catch((error) => addEvent(error.message || String(error), "error")));
|
|
43161
|
+
elements.themeCustomizerName?.addEventListener("input", updateThemeCustomizerFromVisual);
|
|
43162
|
+
elements.themeCustomizerScope?.addEventListener("change", () => {
|
|
43163
|
+
invalidateThemeCustomizerOverwrite();
|
|
43164
|
+
updateThemeCustomizerActions();
|
|
43165
|
+
});
|
|
43166
|
+
elements.themeCustomizerThinkingMax?.addEventListener("input", updateThemeCustomizerFromVisual);
|
|
43167
|
+
elements.themeCustomizerVars?.addEventListener("input", updateThemeCustomizerFromVisual);
|
|
43168
|
+
elements.themeCustomizerJson?.addEventListener("input", updateThemeCustomizerFromJson);
|
|
43169
|
+
elements.themeCustomizerCancelButton?.addEventListener("click", () => closeThemeCustomizer({ restore: true }));
|
|
43170
|
+
elements.themeCustomizerResetButton?.addEventListener("click", resetThemeCustomizerDraft);
|
|
43171
|
+
elements.themeCustomizerSaveButton?.addEventListener("click", () => saveThemeCustomizer().catch((error) => setThemeCustomizerStatus(error.message || String(error), "error")));
|
|
43172
|
+
elements.themeCustomizerOverwriteButton?.addEventListener("click", () => saveThemeCustomizer({ overwrite: true }).catch((error) => setThemeCustomizerStatus(error.message || String(error), "error")));
|
|
43173
|
+
elements.themeCustomizerDialog?.addEventListener("cancel", (event) => {
|
|
43174
|
+
event.preventDefault();
|
|
43175
|
+
if (themeCustomizerState?.saving) {
|
|
43176
|
+
setThemeCustomizerStatus("Wait for the theme save to finish before closing.", "warn");
|
|
43177
|
+
return;
|
|
43178
|
+
}
|
|
43179
|
+
closeThemeCustomizer({ restore: true });
|
|
43180
|
+
});
|
|
43181
|
+
elements.themeCustomizerDialog?.addEventListener("close", () => {
|
|
43182
|
+
const state = themeCustomizerState;
|
|
43183
|
+
if (!state || state.closing) return;
|
|
43184
|
+
restoreThemeCustomizerOpeningState(state.generation);
|
|
43185
|
+
themeCustomizerState = null;
|
|
43186
|
+
});
|
|
42257
43187
|
if (elements.backgroundChooseButton && elements.backgroundInput) {
|
|
42258
43188
|
elements.backgroundChooseButton.addEventListener("click", () => elements.backgroundInput.click());
|
|
42259
43189
|
elements.backgroundInput.addEventListener("change", () => {
|