@firstpick/pi-package-webui 0.8.3 → 0.8.4
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 +67 -16
- package/bin/pi-webui.mjs +769 -130
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +26 -0
- package/lib/optional-feature-catalog.mjs +29 -0
- package/lib/optional-feature-migration.mjs +410 -0
- package/lib/session-summary-core.mjs +320 -0
- package/lib/session-summary-preferences.mjs +267 -0
- package/package.json +5 -42
- package/public/app.js +1280 -51
- package/public/index.html +42 -0
- package/public/styles.css +345 -1
- package/session-summary.ts +403 -0
- package/tests/aur-review-widget-static.test.mjs +3 -2
- package/tests/browser/session-summary.spec.mjs +271 -0
- package/tests/codex-fast-mode-static.test.mjs +8 -7
- package/tests/http-endpoints-harness.test.mjs +419 -3
- package/tests/mobile-static.test.mjs +90 -92
- package/tests/native-parity-harness.test.mjs +9 -1
- package/tests/native-parity.test.mjs +23 -1
- package/tests/optional-feature-migration-frontend.test.mjs +72 -0
- package/tests/optional-feature-migration.test.mjs +142 -0
- package/tests/session-summary-core.test.mjs +491 -0
- package/tests/session-summary-preferences.test.mjs +103 -0
package/public/app.js
CHANGED
|
@@ -20,6 +20,7 @@ const elements = {
|
|
|
20
20
|
terminalTabsToggleButton: $("#terminalTabsToggleButton"),
|
|
21
21
|
splitTabButton: $("#splitTabButton"),
|
|
22
22
|
workspaceSaveButton: $("#workspaceSaveButton"),
|
|
23
|
+
summaryHeaderButton: $("#summaryHeaderButton"),
|
|
23
24
|
newTabMenu: $("#newTabMenu"),
|
|
24
25
|
newTabButton: $("#newTabButton"),
|
|
25
26
|
newTabMenuPanel: $("#newTabMenuPanel"),
|
|
@@ -139,6 +140,7 @@ const elements = {
|
|
|
139
140
|
remoteMicStreamingConsentButton: $("#remoteMicStreamingConsentButton"),
|
|
140
141
|
newSessionButton: $("#newSessionButton"),
|
|
141
142
|
compactButton: $("#compactButton"),
|
|
143
|
+
summaryActionButton: $("#summaryActionButton"),
|
|
142
144
|
workflowModeControls: $("#workflowModeControls"),
|
|
143
145
|
workflowModeButton: $("#workflowModeButton"),
|
|
144
146
|
workflowOverlayOpenButton: $("#workflowOverlayOpenButton"),
|
|
@@ -165,6 +167,7 @@ const elements = {
|
|
|
165
167
|
optionsNameButton: $("#optionsNameButton"),
|
|
166
168
|
optionsCloneButton: $("#optionsCloneButton"),
|
|
167
169
|
optionsSettingsButton: $("#optionsSettingsButton"),
|
|
170
|
+
optionsSummarySetupButton: $("#optionsSummarySetupButton"),
|
|
168
171
|
optionsWorkflowSetupButton: $("#optionsWorkflowSetupButton"),
|
|
169
172
|
optionsSafetyGuardSetupButton: $("#optionsSafetyGuardSetupButton"),
|
|
170
173
|
optionsGitWorkflowSetupButton: $("#optionsGitWorkflowSetupButton"),
|
|
@@ -238,6 +241,17 @@ const elements = {
|
|
|
238
241
|
agentDoneNotificationsToggle: $("#agentDoneNotificationsToggle"),
|
|
239
242
|
agentDoneNotificationsStatus: $("#agentDoneNotificationsStatus"),
|
|
240
243
|
optionalFeaturesBox: $("#optionalFeaturesBox"),
|
|
244
|
+
optionalFeatureMigrationSurface: $("#optionalFeatureMigrationSurface"),
|
|
245
|
+
optionalFeatureMigrationDialog: $("#optionalFeatureMigrationDialog"),
|
|
246
|
+
optionalFeatureMigrationDialogTitle: $("#optionalFeatureMigrationDialogTitle"),
|
|
247
|
+
optionalFeatureMigrationDialogMessage: $("#optionalFeatureMigrationDialogMessage"),
|
|
248
|
+
optionalFeatureMigrationDialogSummary: $("#optionalFeatureMigrationDialogSummary"),
|
|
249
|
+
optionalFeatureMigrationChooseDetails: $("#optionalFeatureMigrationChooseDetails"),
|
|
250
|
+
optionalFeatureMigrationChoices: $("#optionalFeatureMigrationChoices"),
|
|
251
|
+
optionalFeatureMigrationDialogError: $("#optionalFeatureMigrationDialogError"),
|
|
252
|
+
optionalFeatureMigrationCancelButton: $("#optionalFeatureMigrationCancelButton"),
|
|
253
|
+
optionalFeatureMigrationLaterButton: $("#optionalFeatureMigrationLaterButton"),
|
|
254
|
+
optionalFeatureMigrationConfirmButton: $("#optionalFeatureMigrationConfirmButton"),
|
|
241
255
|
codexUsageBox: $("#codexUsageBox"),
|
|
242
256
|
refreshCodexUsageButton: $("#refreshCodexUsageButton"),
|
|
243
257
|
codexFastModeSelect: $("#codexFastModeSelect"),
|
|
@@ -354,6 +368,14 @@ const elements = {
|
|
|
354
368
|
attachmentTextStatus: $("#attachmentTextStatus"),
|
|
355
369
|
attachmentTextCancelButton: $("#attachmentTextCancelButton"),
|
|
356
370
|
attachmentTextSaveButton: $("#attachmentTextSaveButton"),
|
|
371
|
+
sessionSummaryOverlay: $("#sessionSummaryOverlay"),
|
|
372
|
+
sessionSummaryOverlayTitle: $("#sessionSummaryOverlayTitle"),
|
|
373
|
+
sessionSummaryOverlayMeta: $("#sessionSummaryOverlayMeta"),
|
|
374
|
+
sessionSummaryOverlayStatus: $("#sessionSummaryOverlayStatus"),
|
|
375
|
+
sessionSummaryOverlayBody: $("#sessionSummaryOverlayBody"),
|
|
376
|
+
sessionSummaryOverlayCloseButton: $("#sessionSummaryOverlayCloseButton"),
|
|
377
|
+
sessionSummaryOverlayCopyButton: $("#sessionSummaryOverlayCopyButton"),
|
|
378
|
+
sessionSummaryOverlayRefreshButton: $("#sessionSummaryOverlayRefreshButton"),
|
|
357
379
|
commandSearchInput: $("#commandSearchInput"),
|
|
358
380
|
commandsBox: $("#commandsBox"),
|
|
359
381
|
eventLog: $("#eventLog"),
|
|
@@ -600,6 +622,9 @@ let gitChangesRequestSerial = 0;
|
|
|
600
622
|
const gitChangesUntrackedContentRequests = new Set();
|
|
601
623
|
let nativeCommandTabId = null;
|
|
602
624
|
let nativeSettingsDirty = false;
|
|
625
|
+
let sessionSummaryOverlayTabId = null;
|
|
626
|
+
let sessionSummaryOverlayFocusReturn = null;
|
|
627
|
+
const sessionSummaryByTab = new Map();
|
|
603
628
|
let pathPickerState = null;
|
|
604
629
|
let firstTerminalCwdPromptShown = false;
|
|
605
630
|
let pathFastPicks = [];
|
|
@@ -2799,7 +2824,11 @@ const HIDDEN_COMMAND_NAMES = new Set(["webui-tree-navigate", "webui-helper"]);
|
|
|
2799
2824
|
HIDDEN_COMMAND_NAMES.add("stats-webui");
|
|
2800
2825
|
HIDDEN_COMMAND_NAMES.add("btw-status");
|
|
2801
2826
|
HIDDEN_COMMAND_NAMES.add("btw-transfer");
|
|
2802
|
-
const
|
|
2827
|
+
const SESSION_SUMMARY_PROTOCOL_VERSION = 1;
|
|
2828
|
+
const SESSION_SUMMARY_MARKDOWN_MAX_CHARS = 16 * 1024;
|
|
2829
|
+
const SESSION_SUMMARY_PROMPT_MAX_CHARS = 8 * 1024;
|
|
2830
|
+
const SESSION_SUMMARY_REQUEST_TIMEOUT_MS = 110 * 1000;
|
|
2831
|
+
const NATIVE_SELECTOR_COMMANDS = new Set(["model", "settings", "summary", "summary-setup", "workflow-setup", "safety-guard-setup", "git-workflow-setup", "theme", "fork", "clone", "name", "resume", "tree", "login", "logout", "scoped-models", "tools", "skills"]);
|
|
2803
2832
|
const SETTINGS_THINKING_OPTIONS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
2804
2833
|
const SETTINGS_TRANSPORT_OPTIONS = ["sse", "websocket", "websocket-cached", "auto"];
|
|
2805
2834
|
const SETTINGS_HTTP_IDLE_TIMEOUT_OPTIONS = [
|
|
@@ -2827,6 +2856,25 @@ const optionalFeaturePackageStatuses = new Map();
|
|
|
2827
2856
|
const optionalFeatureInstallMessages = new Map();
|
|
2828
2857
|
const optionalFeatureInstallStates = new Map();
|
|
2829
2858
|
const optionalFeatureInstallProgressTimers = new Map();
|
|
2859
|
+
const optionalFeatureMigrationResultEvents = new Set();
|
|
2860
|
+
let optionalFeatureBatchState = null;
|
|
2861
|
+
let optionalFeatureMigrationSnapshot = {
|
|
2862
|
+
phase: "checking",
|
|
2863
|
+
revision: "pending",
|
|
2864
|
+
installKind: "unknown",
|
|
2865
|
+
summary: { ready: 0, migratable: 0, missing: 0, conflicts: 0, disabled: 0, unknown: 0 },
|
|
2866
|
+
features: [],
|
|
2867
|
+
progress: null,
|
|
2868
|
+
completedAt: null,
|
|
2869
|
+
diagnostic: null,
|
|
2870
|
+
};
|
|
2871
|
+
let optionalFeatureMigrationCheckingStartedAt = Date.now();
|
|
2872
|
+
let optionalFeatureMigrationRenderTimer = null;
|
|
2873
|
+
let optionalFeatureMigrationDialogState = null;
|
|
2874
|
+
let optionalFeatureMigrationLastPhase = "";
|
|
2875
|
+
let optionalFeatureMigrationCompletionFocusKey = "";
|
|
2876
|
+
let optionalFeatureRestartNotice = null;
|
|
2877
|
+
let optionalFeaturePackageStatusesLoaded = false;
|
|
2830
2878
|
let optionalFeaturePackageStatusError = "";
|
|
2831
2879
|
const gitFooterPayloadRefreshInFlightByTab = new Set();
|
|
2832
2880
|
const gitFooterPayloadStateByTab = new Map();
|
|
@@ -7137,8 +7185,8 @@ function renderUpdateNotification(status = latestUpdateStatus, { force = false }
|
|
|
7137
7185
|
if (elements.updateNotificationMessage) {
|
|
7138
7186
|
let message = "Updates are available. Direct Web UI updates are only enabled from localhost on the host machine.";
|
|
7139
7187
|
if (canRunUpdate) {
|
|
7140
|
-
if (hasPiUpdate && hasPackageUpdate) message = "Run pi update --self for Pi only, or update all to use
|
|
7141
|
-
else if (hasPackageUpdate) message = "Update all
|
|
7188
|
+
if (hasPiUpdate && hasPackageUpdate) message = "Run pi update --self for Pi only, or update all to use Pi for configured packages and Optional Features while refreshing detected core Pi/Web UI package roots, then restart this Web UI server automatically.";
|
|
7189
|
+
else if (hasPackageUpdate) message = "Update all uses Pi for configured packages and Optional Features, then refreshes detected core Pi/Web UI package roots before restarting this Web UI server automatically.";
|
|
7142
7190
|
else message = "Run pi update --self for Pi only, then restart this Web UI server automatically.";
|
|
7143
7191
|
}
|
|
7144
7192
|
elements.updateNotificationMessage.textContent = message;
|
|
@@ -7380,8 +7428,8 @@ function piUpdateConfirmationText({ all = false } = {}) {
|
|
|
7380
7428
|
const workingWarning = hasWorkingTab() ? "\n\nOne or more Pi tabs look busy or blocked. Finish or abort in-flight work before updating if you need to preserve it." : "";
|
|
7381
7429
|
const versionText = items.length ? `\n\nDetected update: ${items.join(" · ")}.` : "";
|
|
7382
7430
|
const commandText = all ? '"pi update --all" when supported, otherwise "pi update --self" followed by "pi update --extensions"' : '"pi update --self"';
|
|
7383
|
-
const scope = all ? "Pi, configured packages
|
|
7384
|
-
const extra = all ? "
|
|
7431
|
+
const scope = all ? "Pi, configured packages including Optional Features, and detected core Pi/Web UI package roots" : "Pi only";
|
|
7432
|
+
const extra = all ? " Pi owns configured Optional Feature updates; direct npm/bun updates are limited to detected core Pi/Web UI package roots." : "";
|
|
7385
7433
|
return `Run ${scope} now?${versionText}\n\nThis will run ${commandText} on the Web UI host.${extra} After it finishes, Pi Web UI will restart itself. Browser clients will briefly disconnect, and managed Pi tabs/RPC processes will be restarted from saved session state when possible.${workingWarning}`;
|
|
7386
7434
|
}
|
|
7387
7435
|
|
|
@@ -9213,6 +9261,7 @@ async function handleVoiceConversationTurnEnd(tabContext = activeTabContext()) {
|
|
|
9213
9261
|
|
|
9214
9262
|
function renderOptionalFeatureDependentDisplays() {
|
|
9215
9263
|
renderOptionalFeatureControls();
|
|
9264
|
+
if (elements.optionalFeatureMigrationDialog?.open) renderOptionalFeatureMigrationDialog();
|
|
9216
9265
|
renderThemeSelect();
|
|
9217
9266
|
renderWidgets();
|
|
9218
9267
|
renderStatus();
|
|
@@ -9720,10 +9769,12 @@ function setActiveTabId(tabId, { remember = false } = {}) {
|
|
|
9720
9769
|
if (nextTabId !== activeTabId) {
|
|
9721
9770
|
activeTabGeneration += 1;
|
|
9722
9771
|
closeFeatureDecisionDialog({ restoreFocus: false });
|
|
9772
|
+
closeSessionSummaryOverlay({ restoreFocus: false });
|
|
9723
9773
|
}
|
|
9724
9774
|
activeTabId = nextTabId;
|
|
9725
9775
|
bindGitWorkflowToActiveTab();
|
|
9726
9776
|
renderFeatureCategoryTag(nextTabId);
|
|
9777
|
+
renderSessionSummaryControls();
|
|
9727
9778
|
if (remember) rememberActiveTab();
|
|
9728
9779
|
return activeTabContext(nextTabId);
|
|
9729
9780
|
}
|
|
@@ -12424,6 +12475,7 @@ function syncTabMetadata(nextTabs = []) {
|
|
|
12424
12475
|
setTabActivity(tab.id, tab.activity);
|
|
12425
12476
|
if (Object.prototype.hasOwnProperty.call(tab, "appRunner")) setAppRunnerData(tab.id, { activeRun: tab.appRunner });
|
|
12426
12477
|
if (Object.prototype.hasOwnProperty.call(tab, "conversationMode")) updateConversationModeForTab(tab.id, tab.conversationMode, { render: false });
|
|
12478
|
+
if (tab.sessionSummary) updateSessionSummaryForTab(tab.id, tab.sessionSummary);
|
|
12427
12479
|
}
|
|
12428
12480
|
for (const tabId of tabActivities.keys()) {
|
|
12429
12481
|
if (!liveIds.has(tabId)) {
|
|
@@ -12450,6 +12502,8 @@ function syncTabMetadata(nextTabs = []) {
|
|
|
12450
12502
|
if (voiceConversationTabId === tabId) stopVoiceConversationLoop();
|
|
12451
12503
|
clearGitWorkflowForTab(tabId);
|
|
12452
12504
|
commandCatalogsByTab.delete(tabId);
|
|
12505
|
+
sessionSummaryByTab.delete(tabId);
|
|
12506
|
+
if (sessionSummaryOverlayTabId === tabId) closeSessionSummaryOverlay({ restoreFocus: false });
|
|
12453
12507
|
clearGitFooterPayloadState(tabId);
|
|
12454
12508
|
gitFooterPayloadRequestSerialByTab.delete(tabId);
|
|
12455
12509
|
}
|
|
@@ -12467,8 +12521,10 @@ function applyTabMetadata(tab) {
|
|
|
12467
12521
|
else tabs[index] = { ...tabs[index], ...tab };
|
|
12468
12522
|
if (tab.activity) setTabActivity(tab.id, tab.activity);
|
|
12469
12523
|
if (Object.prototype.hasOwnProperty.call(tab, "conversationMode")) updateConversationModeForTab(tab.id, tab.conversationMode, { render: false });
|
|
12524
|
+
if (tab.sessionSummary) updateSessionSummaryForTab(tab.id, tab.sessionSummary);
|
|
12470
12525
|
renderConversationModeControls();
|
|
12471
12526
|
renderWorkflowModeControls();
|
|
12527
|
+
renderSessionSummaryControls();
|
|
12472
12528
|
renderTabs();
|
|
12473
12529
|
return true;
|
|
12474
12530
|
}
|
|
@@ -33864,6 +33920,26 @@ function optionalFeaturePackageStatus(featureId) {
|
|
|
33864
33920
|
return optionalFeaturePackageStatuses.get(featureId) || null;
|
|
33865
33921
|
}
|
|
33866
33922
|
|
|
33923
|
+
function optionalFeatureManualInstallCommand(feature) {
|
|
33924
|
+
return feature?.packageName ? `pi install npm:${feature.packageName}` : "";
|
|
33925
|
+
}
|
|
33926
|
+
|
|
33927
|
+
function optionalFeatureNeedsInstall(feature) {
|
|
33928
|
+
const status = optionalFeaturePackageStatus(feature?.id);
|
|
33929
|
+
if (!status || isOptionalFeatureDisabled(feature?.id)) return false;
|
|
33930
|
+
const legacyNeedsInstall = status.ready !== true && status.resourceConflict !== true;
|
|
33931
|
+
if (status.state) return ["missing", "legacy-migratable"].includes(status.state) && status.resourceConflict !== true;
|
|
33932
|
+
return legacyNeedsInstall;
|
|
33933
|
+
}
|
|
33934
|
+
|
|
33935
|
+
function optionalFeatureBatchCandidates(features = OPTIONAL_FEATURES) {
|
|
33936
|
+
return features.filter((feature) => optionalFeatureNeedsInstall(feature));
|
|
33937
|
+
}
|
|
33938
|
+
|
|
33939
|
+
function optionalFeatureBatchIsActive() {
|
|
33940
|
+
return optionalFeatureBatchState?.phase === "running";
|
|
33941
|
+
}
|
|
33942
|
+
|
|
33867
33943
|
function optionalFeaturePackageVersionLabel(status) {
|
|
33868
33944
|
if (!status?.installedVersion) return "";
|
|
33869
33945
|
return status.declaredSpec ? `${status.installedVersion} (expects ${status.declaredSpec})` : status.installedVersion;
|
|
@@ -33928,13 +34004,24 @@ function optionalFeatureInstallFailureFromError(error) {
|
|
|
33928
34004
|
const message = details.message || error?.message || String(error);
|
|
33929
34005
|
const hint = details.hint || (error?.backendOffline
|
|
33930
34006
|
? "The Web UI server connection failed. Check that pi-webui is still running, then retry."
|
|
33931
|
-
: "Run the shown
|
|
34007
|
+
: "Run the shown Pi command manually from the Web UI host to inspect the full installer output.");
|
|
33932
34008
|
return { ...details, message, hint, statusCode: error?.statusCode };
|
|
33933
34009
|
}
|
|
33934
34010
|
|
|
34011
|
+
function optionalFeatureInstallFailureFromBatchResult(result, feature) {
|
|
34012
|
+
const details = result?.optionalFeatureInstall || {};
|
|
34013
|
+
return {
|
|
34014
|
+
...details,
|
|
34015
|
+
message: details.message || result?.error || `Pi could not install ${feature.packageName}`,
|
|
34016
|
+
hint: details.hint || "Run the shown Pi command manually from the Web UI host to inspect the full installer output.",
|
|
34017
|
+
command: details.command || optionalFeatureManualInstallCommand(feature),
|
|
34018
|
+
};
|
|
34019
|
+
}
|
|
34020
|
+
|
|
33935
34021
|
async function copyOptionalFeatureInstallCommand(featureId) {
|
|
34022
|
+
const feature = OPTIONAL_FEATURE_BY_ID.get(featureId);
|
|
33936
34023
|
const state = optionalFeatureInstallState(featureId);
|
|
33937
|
-
const command = String(state?.command ||
|
|
34024
|
+
const command = String(state?.command || optionalFeatureManualInstallCommand(feature)).trim();
|
|
33938
34025
|
if (!command) {
|
|
33939
34026
|
addEvent("optional feature install command is not available yet", "warn");
|
|
33940
34027
|
return;
|
|
@@ -33947,6 +34034,444 @@ async function copyOptionalFeatureInstallCommand(featureId) {
|
|
|
33947
34034
|
}
|
|
33948
34035
|
}
|
|
33949
34036
|
|
|
34037
|
+
function optionalFeatureAuditFeature(featureId) {
|
|
34038
|
+
return optionalFeatureMigrationSnapshot.features.find((feature) => feature?.featureId === featureId) || null;
|
|
34039
|
+
}
|
|
34040
|
+
|
|
34041
|
+
function optionalFeatureDisplayLabel(featureId, packageName = "") {
|
|
34042
|
+
return OPTIONAL_FEATURE_BY_ID.get(featureId)?.label || packageName || featureId || "optional feature";
|
|
34043
|
+
}
|
|
34044
|
+
|
|
34045
|
+
function optionalFeatureCandidateSignature(snapshot, featureIds) {
|
|
34046
|
+
const requested = new Set(featureIds || []);
|
|
34047
|
+
return (snapshot?.features || [])
|
|
34048
|
+
.filter((feature) => requested.has(feature.featureId))
|
|
34049
|
+
.map((feature) => `${feature.featureId}:${feature.state}:${feature.sourceKind}:${feature.previouslyEnabled === true}`)
|
|
34050
|
+
.sort()
|
|
34051
|
+
.join("|");
|
|
34052
|
+
}
|
|
34053
|
+
|
|
34054
|
+
function optionalFeatureMigrationCandidates(featureIds = null, { includeBrowserDisabled = false } = {}) {
|
|
34055
|
+
const requested = featureIds ? new Set(featureIds) : null;
|
|
34056
|
+
return (optionalFeatureMigrationSnapshot.features || []).filter((feature) => {
|
|
34057
|
+
if (feature?.state !== "legacy-migratable") return false;
|
|
34058
|
+
if (requested && !requested.has(feature.featureId)) return false;
|
|
34059
|
+
return includeBrowserDisabled || !isOptionalFeatureDisabled(feature.featureId);
|
|
34060
|
+
});
|
|
34061
|
+
}
|
|
34062
|
+
|
|
34063
|
+
function optionalFeatureMigrationElapsedMs() {
|
|
34064
|
+
const progress = optionalFeatureMigrationSnapshot.progress;
|
|
34065
|
+
if (progress?.startedAt) {
|
|
34066
|
+
const startedAt = Date.parse(progress.startedAt);
|
|
34067
|
+
if (Number.isFinite(startedAt)) return Math.max(Number(progress.elapsedMs) || 0, Date.now() - startedAt);
|
|
34068
|
+
}
|
|
34069
|
+
if (optionalFeatureMigrationSnapshot.phase === "checking") return Date.now() - optionalFeatureMigrationCheckingStartedAt;
|
|
34070
|
+
return Number(progress?.elapsedMs) || 0;
|
|
34071
|
+
}
|
|
34072
|
+
|
|
34073
|
+
function optionalFeatureMigrationProgressText(progress = optionalFeatureMigrationSnapshot.progress) {
|
|
34074
|
+
if (!progress) return "";
|
|
34075
|
+
const elapsed = formatDuration(optionalFeatureMigrationElapsedMs());
|
|
34076
|
+
if (progress.phase === "migrating" && progress.currentFeatureId) {
|
|
34077
|
+
const label = optionalFeatureDisplayLabel(progress.currentFeatureId, progress.currentPackageName);
|
|
34078
|
+
return `Installing ${progress.index || (progress.completed || 0) + 1} of ${progress.total || 0}: ${label}${elapsed ? ` · elapsed ${elapsed}` : ""}`;
|
|
34079
|
+
}
|
|
34080
|
+
if (progress.phase === "partial") return `${progress.succeeded || 0} succeeded · ${progress.failed || 0} failed${elapsed ? ` · finished after ${elapsed}` : ""}`;
|
|
34081
|
+
if (progress.phase === "complete") return `${progress.succeeded || progress.total || 0} installed successfully${elapsed ? ` · finished after ${elapsed}` : ""}`;
|
|
34082
|
+
return "";
|
|
34083
|
+
}
|
|
34084
|
+
|
|
34085
|
+
function optionalFeatureMigrationPhaseMessage(phase) {
|
|
34086
|
+
switch (phase) {
|
|
34087
|
+
case "checking": return "checking optional features";
|
|
34088
|
+
case "ready": return "optional feature audit ready";
|
|
34089
|
+
case "action-required": return "optional feature audit needs attention";
|
|
34090
|
+
case "migrating": return "optional feature migration started";
|
|
34091
|
+
case "partial": return "optional feature migration finished with failures";
|
|
34092
|
+
case "complete": return "optional feature migration completed";
|
|
34093
|
+
case "degraded": return "optional feature audit degraded; Web UI is running core-only";
|
|
34094
|
+
default: return "";
|
|
34095
|
+
}
|
|
34096
|
+
}
|
|
34097
|
+
|
|
34098
|
+
function rememberOptionalFeatureMigrationEvent(key) {
|
|
34099
|
+
optionalFeatureMigrationResultEvents.add(key);
|
|
34100
|
+
while (optionalFeatureMigrationResultEvents.size > 256) optionalFeatureMigrationResultEvents.delete(optionalFeatureMigrationResultEvents.values().next().value);
|
|
34101
|
+
}
|
|
34102
|
+
|
|
34103
|
+
function announceOptionalFeatureMigrationSnapshot(snapshot) {
|
|
34104
|
+
if (snapshot.phase !== optionalFeatureMigrationLastPhase) {
|
|
34105
|
+
optionalFeatureMigrationLastPhase = snapshot.phase;
|
|
34106
|
+
const message = optionalFeatureMigrationPhaseMessage(snapshot.phase);
|
|
34107
|
+
if (message) addEvent(message, ["degraded", "action-required", "partial"].includes(snapshot.phase) ? "warn" : "info");
|
|
34108
|
+
}
|
|
34109
|
+
const progress = snapshot.progress;
|
|
34110
|
+
if (progress?.phase === "migrating" && progress.currentFeatureId) {
|
|
34111
|
+
const startKey = `${progress.startedAt || snapshot.revision}:start:${progress.currentFeatureId}`;
|
|
34112
|
+
if (!optionalFeatureMigrationResultEvents.has(startKey)) {
|
|
34113
|
+
rememberOptionalFeatureMigrationEvent(startKey);
|
|
34114
|
+
addEvent(optionalFeatureMigrationProgressText(progress), "info");
|
|
34115
|
+
}
|
|
34116
|
+
}
|
|
34117
|
+
for (const result of progress?.results || []) {
|
|
34118
|
+
const key = `${progress.startedAt || snapshot.revision}:${result.featureId}:${result.ok}:${result.kind || ""}`;
|
|
34119
|
+
if (optionalFeatureMigrationResultEvents.has(key)) continue;
|
|
34120
|
+
rememberOptionalFeatureMigrationEvent(key);
|
|
34121
|
+
const label = optionalFeatureDisplayLabel(result.featureId, result.packageName);
|
|
34122
|
+
addEvent(`${label}: ${result.ok ? "installed and verified" : result.message || "installation failed"}`, result.ok ? "info" : "error");
|
|
34123
|
+
}
|
|
34124
|
+
}
|
|
34125
|
+
|
|
34126
|
+
function applyOptionalFeatureProgressStates(snapshot) {
|
|
34127
|
+
const progress = snapshot.progress;
|
|
34128
|
+
if (!progress) return;
|
|
34129
|
+
const startedAt = Number.isFinite(Date.parse(progress.startedAt || "")) ? Date.parse(progress.startedAt) : Date.now();
|
|
34130
|
+
for (const result of progress.results || []) {
|
|
34131
|
+
const feature = OPTIONAL_FEATURE_BY_ID.get(result.featureId);
|
|
34132
|
+
const previous = optionalFeatureInstallState(result.featureId) || {};
|
|
34133
|
+
optionalFeatureInstallStates.set(result.featureId, {
|
|
34134
|
+
...previous,
|
|
34135
|
+
phase: result.ok ? "done" : "failed",
|
|
34136
|
+
actionLabel: progress.migration ? "Migrate" : "Install",
|
|
34137
|
+
startedAt: previous.startedAt || startedAt,
|
|
34138
|
+
endedAt: progress.completedAt ? Date.parse(progress.completedAt) || Date.now() : Date.now(),
|
|
34139
|
+
detail: result.message || (result.ok ? "Installed and verified" : "Installation failed"),
|
|
34140
|
+
hint: result.ok ? "The server verified this package registration." : "Retry this package or run the copied Pi command on the Web UI host.",
|
|
34141
|
+
command: previous.command || optionalFeatureManualInstallCommand(feature),
|
|
34142
|
+
errorKind: result.kind || previous.errorKind || "",
|
|
34143
|
+
});
|
|
34144
|
+
}
|
|
34145
|
+
if (progress.phase === "migrating" && progress.currentFeatureId) {
|
|
34146
|
+
const current = OPTIONAL_FEATURE_BY_ID.get(progress.currentFeatureId);
|
|
34147
|
+
const previous = optionalFeatureInstallState(progress.currentFeatureId) || {};
|
|
34148
|
+
optionalFeatureInstallStates.set(progress.currentFeatureId, {
|
|
34149
|
+
...previous,
|
|
34150
|
+
phase: "installing",
|
|
34151
|
+
actionLabel: progress.migration ? "Migrate" : "Install",
|
|
34152
|
+
startedAt: previous.startedAt || startedAt,
|
|
34153
|
+
endedAt: 0,
|
|
34154
|
+
detail: optionalFeatureMigrationProgressText(progress),
|
|
34155
|
+
hint: "Pi installs packages sequentially. This operation continues if the browser disconnects.",
|
|
34156
|
+
command: previous.command || optionalFeatureManualInstallCommand(current),
|
|
34157
|
+
});
|
|
34158
|
+
}
|
|
34159
|
+
if (progress.restartDeferred === true) {
|
|
34160
|
+
optionalFeatureRestartNotice = { autoRestarted: false, restartDeferred: true, tabId: activeTabId };
|
|
34161
|
+
} else if (progress.autoRestarted === true) {
|
|
34162
|
+
optionalFeatureRestartNotice = { autoRestarted: true, restartDeferred: false, tabId: activeTabId };
|
|
34163
|
+
}
|
|
34164
|
+
optionalFeatureBatchState = {
|
|
34165
|
+
phase: progress.phase === "migrating" ? "running" : progress.phase === "partial" ? "failed" : "done",
|
|
34166
|
+
scopeLabel: progress.migration ? "previous optional features" : "optional features",
|
|
34167
|
+
total: progress.total || 0,
|
|
34168
|
+
succeeded: progress.succeeded ?? (progress.results || []).filter((result) => result.ok).length,
|
|
34169
|
+
failed: progress.failed ?? (progress.results || []).filter((result) => !result.ok).length,
|
|
34170
|
+
startedAt,
|
|
34171
|
+
endedAt: progress.completedAt ? Date.parse(progress.completedAt) || Date.now() : 0,
|
|
34172
|
+
};
|
|
34173
|
+
}
|
|
34174
|
+
|
|
34175
|
+
function refreshOptionalFeatureMigrationElapsedText() {
|
|
34176
|
+
const detail = elements.optionalFeatureMigrationSurface?.querySelector(".optional-feature-migration-detail");
|
|
34177
|
+
if (!detail) return;
|
|
34178
|
+
if (optionalFeatureMigrationSnapshot.phase === "checking") {
|
|
34179
|
+
const elapsed = optionalFeatureMigrationElapsedMs();
|
|
34180
|
+
detail.textContent = elapsed >= 1000 ? `Read-only startup audit · elapsed ${formatDuration(elapsed)}` : "Read-only startup audit";
|
|
34181
|
+
} else if (optionalFeatureMigrationSnapshot.phase === "migrating") {
|
|
34182
|
+
detail.textContent = optionalFeatureMigrationProgressText(optionalFeatureMigrationSnapshot.progress) || "Preparing sequential Pi installs…";
|
|
34183
|
+
}
|
|
34184
|
+
}
|
|
34185
|
+
|
|
34186
|
+
function ensureOptionalFeatureMigrationRenderTimer() {
|
|
34187
|
+
const timed = ["checking", "migrating"].includes(optionalFeatureMigrationSnapshot.phase);
|
|
34188
|
+
if (timed && !optionalFeatureMigrationRenderTimer) {
|
|
34189
|
+
optionalFeatureMigrationRenderTimer = setInterval(() => {
|
|
34190
|
+
refreshOptionalFeatureMigrationElapsedText();
|
|
34191
|
+
if (optionalFeatureMigrationSnapshot.phase === "migrating") renderOptionalFeaturePanel();
|
|
34192
|
+
}, 1000);
|
|
34193
|
+
} else if (!timed && optionalFeatureMigrationRenderTimer) {
|
|
34194
|
+
clearInterval(optionalFeatureMigrationRenderTimer);
|
|
34195
|
+
optionalFeatureMigrationRenderTimer = null;
|
|
34196
|
+
}
|
|
34197
|
+
}
|
|
34198
|
+
|
|
34199
|
+
function optionalFeatureMigrationAction(label, handler, className = "") {
|
|
34200
|
+
const button = make("button", className, label);
|
|
34201
|
+
button.type = "button";
|
|
34202
|
+
button.addEventListener("click", handler);
|
|
34203
|
+
return button;
|
|
34204
|
+
}
|
|
34205
|
+
|
|
34206
|
+
function optionalFeatureConflictDescription(feature) {
|
|
34207
|
+
return `${optionalFeatureDisplayLabel(feature.featureId, feature.packageName)}: Pi package + top-level resource; the top-level copy was safely excluded.`;
|
|
34208
|
+
}
|
|
34209
|
+
|
|
34210
|
+
async function copyOptionalFeatureConflictFix(feature) {
|
|
34211
|
+
const text = [
|
|
34212
|
+
`Recommended fix for ${feature.packageName}:`,
|
|
34213
|
+
"Keep the registered Pi package as the canonical source.",
|
|
34214
|
+
"Disable or remove the duplicate top-level extension/skill/prompt/theme alias, then use Recheck in Pi Web UI.",
|
|
34215
|
+
].join("\n");
|
|
34216
|
+
try {
|
|
34217
|
+
await copyText(text);
|
|
34218
|
+
addEvent(`copied recommended conflict fix for ${optionalFeatureDisplayLabel(feature.featureId, feature.packageName)}`, "info");
|
|
34219
|
+
} catch (error) {
|
|
34220
|
+
addEvent(`could not copy optional feature conflict fix: ${error.message || String(error)}`, "warn");
|
|
34221
|
+
}
|
|
34222
|
+
}
|
|
34223
|
+
|
|
34224
|
+
function optionalFeatureFailureOutputTail() {
|
|
34225
|
+
const tails = [];
|
|
34226
|
+
for (const [featureId, state] of optionalFeatureInstallStates) {
|
|
34227
|
+
if (state?.phase !== "failed" || !state.outputTail) continue;
|
|
34228
|
+
tails.push(`${optionalFeatureDisplayLabel(featureId)}\n${String(state.outputTail).slice(-2000)}`);
|
|
34229
|
+
}
|
|
34230
|
+
return tails.join("\n\n").slice(-4000);
|
|
34231
|
+
}
|
|
34232
|
+
|
|
34233
|
+
async function restartOptionalFeatureTab() {
|
|
34234
|
+
const tabId = optionalFeatureRestartNotice?.tabId || activeTabId;
|
|
34235
|
+
try {
|
|
34236
|
+
await sendPrompt("prompt", "/reload", { targetTabId: tabId, throwOnError: true });
|
|
34237
|
+
optionalFeatureRestartNotice = null;
|
|
34238
|
+
renderOptionalFeatureMigrationSurface();
|
|
34239
|
+
} catch (error) {
|
|
34240
|
+
addEvent(`optional feature tab restart failed: ${error.message || String(error)}`, "error");
|
|
34241
|
+
}
|
|
34242
|
+
}
|
|
34243
|
+
|
|
34244
|
+
function renderOptionalFeatureMigrationSurface() {
|
|
34245
|
+
const surface = elements.optionalFeatureMigrationSurface;
|
|
34246
|
+
if (!surface) return;
|
|
34247
|
+
const snapshot = optionalFeatureMigrationSnapshot;
|
|
34248
|
+
const summary = snapshot.summary || {};
|
|
34249
|
+
const conflicts = (snapshot.features || []).filter((feature) => feature.state === "conflict");
|
|
34250
|
+
const progress = snapshot.progress;
|
|
34251
|
+
const card = make("div", `optional-feature-migration-card phase-${snapshot.phase}`);
|
|
34252
|
+
const copy = make("div", "optional-feature-migration-copy");
|
|
34253
|
+
const title = make("strong", "optional-feature-migration-title");
|
|
34254
|
+
const detail = make("span", "optional-feature-migration-detail");
|
|
34255
|
+
const actions = make("div", "optional-feature-migration-actions");
|
|
34256
|
+
|
|
34257
|
+
if (snapshot.phase === "checking") {
|
|
34258
|
+
title.textContent = "Checking optional features…";
|
|
34259
|
+
const elapsed = optionalFeatureMigrationElapsedMs();
|
|
34260
|
+
detail.textContent = elapsed >= 1000 ? `Read-only startup audit · elapsed ${formatDuration(elapsed)}` : "Read-only startup audit";
|
|
34261
|
+
} else if (snapshot.phase === "degraded") {
|
|
34262
|
+
title.textContent = "Web UI started safely without optional companions";
|
|
34263
|
+
detail.textContent = snapshot.diagnostic?.message || "The optional-feature audit could not establish a safe configuration.";
|
|
34264
|
+
actions.append(optionalFeatureMigrationAction("Recheck", () => recheckOptionalFeatureMigration(), "primary"));
|
|
34265
|
+
} else if (snapshot.phase === "migrating") {
|
|
34266
|
+
title.textContent = "Migrating optional features";
|
|
34267
|
+
detail.textContent = optionalFeatureMigrationProgressText(progress) || "Preparing sequential Pi installs…";
|
|
34268
|
+
} else if (snapshot.phase === "partial") {
|
|
34269
|
+
title.textContent = "Optional feature migration needs attention";
|
|
34270
|
+
detail.textContent = optionalFeatureMigrationProgressText(progress);
|
|
34271
|
+
const failedIds = (progress?.results || []).filter((result) => !result.ok).map((result) => result.featureId);
|
|
34272
|
+
if (failedIds.length) actions.append(optionalFeatureMigrationAction("Retry failed", () => openOptionalFeatureMigrationDialog({ featureIds: failedIds, retryFailed: true }), "primary"));
|
|
34273
|
+
actions.append(optionalFeatureMigrationAction("Copy commands", () => copyFailedOptionalFeatureCommands()));
|
|
34274
|
+
} else if (snapshot.phase === "complete") {
|
|
34275
|
+
title.textContent = "Optional feature migration complete";
|
|
34276
|
+
detail.textContent = optionalFeatureMigrationProgressText(progress) || `${summary.ready || 0} optional features ready`;
|
|
34277
|
+
} else if (snapshot.phase === "action-required") {
|
|
34278
|
+
title.textContent = conflicts.length ? "Optional feature conflicts were safely excluded" : "Previous optional features need migration";
|
|
34279
|
+
detail.textContent = conflicts.length
|
|
34280
|
+
? conflicts.map(optionalFeatureConflictDescription).join(" ")
|
|
34281
|
+
: `${summary.migratable || 0} previously available companion${summary.migratable === 1 ? "" : "s"} can be restored${snapshot.installKind === "upgrade" ? " after this Web UI upgrade" : ""}.`;
|
|
34282
|
+
if (summary.migratable > 0) {
|
|
34283
|
+
actions.append(optionalFeatureMigrationAction("Migrate…", () => openOptionalFeatureMigrationDialog(), "primary"));
|
|
34284
|
+
actions.append(optionalFeatureMigrationAction("Later", () => dismissOptionalFeatureMigration()));
|
|
34285
|
+
}
|
|
34286
|
+
for (const conflict of conflicts) actions.append(optionalFeatureMigrationAction("Copy recommended fix", () => copyOptionalFeatureConflictFix(conflict)));
|
|
34287
|
+
if (conflicts.length) actions.append(optionalFeatureMigrationAction("Recheck", () => recheckOptionalFeatureMigration()));
|
|
34288
|
+
} else {
|
|
34289
|
+
title.textContent = `Core ready · ${summary.ready || 0} optional feature${summary.ready === 1 ? "" : "s"} ready`;
|
|
34290
|
+
detail.textContent = summary.migratable > 0
|
|
34291
|
+
? "Migration was deferred. Restore remains available in Optional features."
|
|
34292
|
+
: summary.missing > 0 ? `${summary.missing} optional companion${summary.missing === 1 ? " is" : "s are"} not installed.` : "Optional feature audit complete.";
|
|
34293
|
+
}
|
|
34294
|
+
|
|
34295
|
+
copy.append(title, detail);
|
|
34296
|
+
card.append(copy);
|
|
34297
|
+
if (actions.childElementCount) card.append(actions);
|
|
34298
|
+
|
|
34299
|
+
if (conflicts.length) {
|
|
34300
|
+
const alert = make("div", "optional-feature-migration-alert sr-only", "Optional feature conflict detected; duplicate top-level resources were safely excluded.");
|
|
34301
|
+
alert.setAttribute("role", "alert");
|
|
34302
|
+
card.append(alert);
|
|
34303
|
+
}
|
|
34304
|
+
if (snapshot.phase === "partial") {
|
|
34305
|
+
const alert = make("div", "optional-feature-migration-alert sr-only", `${progress?.failed || 0} optional feature installations failed.`);
|
|
34306
|
+
alert.setAttribute("role", "alert");
|
|
34307
|
+
card.append(alert);
|
|
34308
|
+
}
|
|
34309
|
+
const outputTail = optionalFeatureFailureOutputTail();
|
|
34310
|
+
if (outputTail && snapshot.phase === "partial") card.append(make("pre", "optional-feature-migration-output", outputTail));
|
|
34311
|
+
|
|
34312
|
+
if (optionalFeatureRestartNotice) {
|
|
34313
|
+
const notice = make("div", "optional-feature-restart-notice");
|
|
34314
|
+
const noticeText = optionalFeatureRestartNotice.restartDeferred
|
|
34315
|
+
? "New optional features are ready. Restart is deferred because the affected tab was busy."
|
|
34316
|
+
: "Restarted tab to load new features.";
|
|
34317
|
+
notice.append(make("span", undefined, noticeText));
|
|
34318
|
+
if (optionalFeatureRestartNotice.restartDeferred) {
|
|
34319
|
+
notice.append(optionalFeatureMigrationAction("Restart tab", () => restartOptionalFeatureTab(), "primary"));
|
|
34320
|
+
} else {
|
|
34321
|
+
notice.append(optionalFeatureMigrationAction("Dismiss", () => {
|
|
34322
|
+
optionalFeatureRestartNotice = null;
|
|
34323
|
+
renderOptionalFeatureMigrationSurface();
|
|
34324
|
+
}));
|
|
34325
|
+
}
|
|
34326
|
+
card.append(notice);
|
|
34327
|
+
}
|
|
34328
|
+
|
|
34329
|
+
const focusKey = ["complete", "partial"].includes(snapshot.phase) ? `${snapshot.revision}:${snapshot.phase}:${progress?.completedAt || ""}` : "";
|
|
34330
|
+
if (focusKey) {
|
|
34331
|
+
card.tabIndex = -1;
|
|
34332
|
+
card.classList.add("optional-feature-migration-completion-summary");
|
|
34333
|
+
}
|
|
34334
|
+
surface.replaceChildren(card);
|
|
34335
|
+
surface.hidden = false;
|
|
34336
|
+
ensureOptionalFeatureMigrationRenderTimer();
|
|
34337
|
+
if (focusKey && focusKey !== optionalFeatureMigrationCompletionFocusKey) {
|
|
34338
|
+
optionalFeatureMigrationCompletionFocusKey = focusKey;
|
|
34339
|
+
queueMicrotask(() => card.isConnected && card.focus({ preventScroll: true }));
|
|
34340
|
+
}
|
|
34341
|
+
}
|
|
34342
|
+
|
|
34343
|
+
function applyOptionalFeatureMigrationSnapshot(snapshot, { announce = true } = {}) {
|
|
34344
|
+
if (!snapshot || typeof snapshot !== "object" || !Array.isArray(snapshot.features)) return false;
|
|
34345
|
+
if (snapshot.phase === "checking" && optionalFeatureMigrationSnapshot.phase !== "checking") optionalFeatureMigrationCheckingStartedAt = Date.now();
|
|
34346
|
+
optionalFeatureMigrationSnapshot = snapshot;
|
|
34347
|
+
optionalFeaturePackageStatuses.clear();
|
|
34348
|
+
for (const status of snapshot.features) {
|
|
34349
|
+
if (status?.featureId) optionalFeaturePackageStatuses.set(status.featureId, status);
|
|
34350
|
+
}
|
|
34351
|
+
optionalFeaturePackageStatusesLoaded = true;
|
|
34352
|
+
optionalFeaturePackageStatusError = "";
|
|
34353
|
+
applyOptionalFeatureProgressStates(snapshot);
|
|
34354
|
+
if (announce) announceOptionalFeatureMigrationSnapshot(snapshot);
|
|
34355
|
+
renderOptionalFeatureMigrationSurface();
|
|
34356
|
+
renderOptionalFeatureControls();
|
|
34357
|
+
return true;
|
|
34358
|
+
}
|
|
34359
|
+
|
|
34360
|
+
async function recheckOptionalFeatureMigration() {
|
|
34361
|
+
addEvent("rechecking optional features", "info");
|
|
34362
|
+
try {
|
|
34363
|
+
const response = await api("/api/optional-feature-migration/recheck", { method: "POST", body: {}, scoped: false });
|
|
34364
|
+
applyOptionalFeatureMigrationSnapshot(response.data);
|
|
34365
|
+
} catch (error) {
|
|
34366
|
+
addEvent(`optional feature recheck failed: ${error.message || String(error)}`, "error");
|
|
34367
|
+
}
|
|
34368
|
+
}
|
|
34369
|
+
|
|
34370
|
+
async function dismissOptionalFeatureMigration({ closeDialog = false, retryOnStale = true } = {}) {
|
|
34371
|
+
const revision = optionalFeatureMigrationSnapshot.revision;
|
|
34372
|
+
try {
|
|
34373
|
+
const response = await api("/api/optional-feature-migration/dismiss", { method: "POST", body: { revision }, scoped: false });
|
|
34374
|
+
applyOptionalFeatureMigrationSnapshot(response.data);
|
|
34375
|
+
if (closeDialog && elements.optionalFeatureMigrationDialog?.open) elements.optionalFeatureMigrationDialog.close();
|
|
34376
|
+
addEvent("optional feature migration deferred; the Migrate action remains available in Optional features", "info");
|
|
34377
|
+
} catch (error) {
|
|
34378
|
+
if (retryOnStale && error.statusCode === 409 && /stale|revision/i.test(error.message || "")) {
|
|
34379
|
+
await refreshOptionalFeaturePackageStatuses();
|
|
34380
|
+
return dismissOptionalFeatureMigration({ closeDialog, retryOnStale: false });
|
|
34381
|
+
}
|
|
34382
|
+
addEvent(`could not defer optional feature migration: ${error.message || String(error)}`, "error");
|
|
34383
|
+
}
|
|
34384
|
+
}
|
|
34385
|
+
|
|
34386
|
+
function renderOptionalFeatureMigrationDialog() {
|
|
34387
|
+
const state = optionalFeatureMigrationDialogState;
|
|
34388
|
+
if (!state || !elements.optionalFeatureMigrationChoices) return;
|
|
34389
|
+
const features = optionalFeatureMigrationCandidates(state.featureIds, { includeBrowserDisabled: true });
|
|
34390
|
+
const availableIds = new Set(features.map((feature) => feature.featureId));
|
|
34391
|
+
state.selected = new Set([...state.selected].filter((featureId) => availableIds.has(featureId) && !isOptionalFeatureDisabled(featureId)));
|
|
34392
|
+
elements.optionalFeatureMigrationChoices.replaceChildren();
|
|
34393
|
+
|
|
34394
|
+
for (const feature of features) {
|
|
34395
|
+
const item = make("div", "optional-feature-migration-choice");
|
|
34396
|
+
const choice = make("label", "optional-feature-migration-choice-label");
|
|
34397
|
+
const input = make("input");
|
|
34398
|
+
input.type = "checkbox";
|
|
34399
|
+
input.value = feature.featureId;
|
|
34400
|
+
input.checked = state.selected.has(feature.featureId);
|
|
34401
|
+
input.disabled = isOptionalFeatureDisabled(feature.featureId);
|
|
34402
|
+
input.addEventListener("change", () => {
|
|
34403
|
+
if (input.checked) state.selected.add(feature.featureId);
|
|
34404
|
+
else state.selected.delete(feature.featureId);
|
|
34405
|
+
renderOptionalFeatureMigrationDialog();
|
|
34406
|
+
});
|
|
34407
|
+
const label = make("span");
|
|
34408
|
+
label.append(make("strong", undefined, optionalFeatureDisplayLabel(feature.featureId, feature.packageName)));
|
|
34409
|
+
label.append(make("span", "optional-feature-migration-choice-package", feature.packageName));
|
|
34410
|
+
choice.append(input, label);
|
|
34411
|
+
const details = make("details", "optional-feature-migration-choice-details");
|
|
34412
|
+
details.append(
|
|
34413
|
+
make("summary", undefined, "Details"),
|
|
34414
|
+
make("span", undefined, `${feature.previouslyEnabled ? "Previously enabled" : "Previously disabled"} · source: ${feature.sourceKind || "legacy evidence"} · Pi will install ${feature.expectedSpec || feature.packageName}.`),
|
|
34415
|
+
);
|
|
34416
|
+
item.append(choice, details);
|
|
34417
|
+
elements.optionalFeatureMigrationChoices.append(item);
|
|
34418
|
+
}
|
|
34419
|
+
|
|
34420
|
+
const selectedFeatures = features.filter((feature) => state.selected.has(feature.featureId));
|
|
34421
|
+
elements.optionalFeatureMigrationDialogTitle.textContent = state.retryFailed ? "Retry failed optional features" : "Migrate optional features";
|
|
34422
|
+
elements.optionalFeatureMigrationDialogMessage.textContent = state.retryFailed
|
|
34423
|
+
? "Retry only the failed packages. Successful packages stay installed. This is the only confirmation before retry."
|
|
34424
|
+
: "Previously enabled features are selected unless they are disabled in this browser. Pi installs the confirmed selection sequentially.";
|
|
34425
|
+
elements.optionalFeatureMigrationDialogSummary.textContent = selectedFeatures.length
|
|
34426
|
+
? `${selectedFeatures.length} selected: ${selectedFeatures.map((feature) => optionalFeatureDisplayLabel(feature.featureId, feature.packageName)).join(", ")}. Pi may download code and update its package registration.`
|
|
34427
|
+
: "No features selected. Browser-disabled and previously disabled features remain unselected.";
|
|
34428
|
+
elements.optionalFeatureMigrationConfirmButton.textContent = state.retryFailed ? "Retry selected" : "Migrate selected";
|
|
34429
|
+
elements.optionalFeatureMigrationConfirmButton.disabled = selectedFeatures.length === 0 || optionalFeatureBatchIsActive();
|
|
34430
|
+
elements.optionalFeatureMigrationLaterButton.hidden = state.retryFailed;
|
|
34431
|
+
elements.optionalFeatureMigrationDialogError.hidden = !state.error;
|
|
34432
|
+
elements.optionalFeatureMigrationDialogError.textContent = state.error || "";
|
|
34433
|
+
elements.optionalFeatureMigrationChooseDetails.querySelector("summary").textContent = `Choose features (${selectedFeatures.length} selected)`;
|
|
34434
|
+
}
|
|
34435
|
+
|
|
34436
|
+
function openOptionalFeatureMigrationDialog({ featureIds = null, retryFailed = false } = {}) {
|
|
34437
|
+
const features = optionalFeatureMigrationCandidates(featureIds, { includeBrowserDisabled: true });
|
|
34438
|
+
if (!features.length) {
|
|
34439
|
+
addEvent("no migratable optional features are currently available", "info");
|
|
34440
|
+
return;
|
|
34441
|
+
}
|
|
34442
|
+
const selected = new Set(features
|
|
34443
|
+
.filter((feature) => retryFailed || feature.selectedByDefault === true)
|
|
34444
|
+
.filter((feature) => !isOptionalFeatureDisabled(feature.featureId))
|
|
34445
|
+
.map((feature) => feature.featureId));
|
|
34446
|
+
optionalFeatureMigrationDialogState = {
|
|
34447
|
+
featureIds: features.map((feature) => feature.featureId),
|
|
34448
|
+
selected,
|
|
34449
|
+
retryFailed,
|
|
34450
|
+
error: "",
|
|
34451
|
+
signature: optionalFeatureCandidateSignature(optionalFeatureMigrationSnapshot, features.map((feature) => feature.featureId)),
|
|
34452
|
+
};
|
|
34453
|
+
renderOptionalFeatureMigrationDialog();
|
|
34454
|
+
if (!elements.optionalFeatureMigrationDialog.open) elements.optionalFeatureMigrationDialog.showModal();
|
|
34455
|
+
queueMicrotask(() => elements.optionalFeatureMigrationConfirmButton?.focus({ preventScroll: true }));
|
|
34456
|
+
}
|
|
34457
|
+
|
|
34458
|
+
async function copyFailedOptionalFeatureCommands() {
|
|
34459
|
+
const commands = [...optionalFeatureInstallStates]
|
|
34460
|
+
.filter(([, state]) => state?.phase === "failed")
|
|
34461
|
+
.map(([featureId, state]) => state.command || optionalFeatureManualInstallCommand(OPTIONAL_FEATURE_BY_ID.get(featureId)))
|
|
34462
|
+
.filter(Boolean);
|
|
34463
|
+
if (!commands.length) {
|
|
34464
|
+
addEvent("no failed optional feature commands are available", "warn");
|
|
34465
|
+
return;
|
|
34466
|
+
}
|
|
34467
|
+
try {
|
|
34468
|
+
await copyText([...new Set(commands)].join("\n"));
|
|
34469
|
+
addEvent(`copied ${new Set(commands).size} failed optional feature command${new Set(commands).size === 1 ? "" : "s"}`, "info");
|
|
34470
|
+
} catch (error) {
|
|
34471
|
+
addEvent(`could not copy failed optional feature commands: ${error.message || String(error)}`, "warn");
|
|
34472
|
+
}
|
|
34473
|
+
}
|
|
34474
|
+
|
|
33950
34475
|
async function refreshQuestionnaireFeatureAvailability(tabContext = activeTabContext()) {
|
|
33951
34476
|
if (!tabContext.tabId) return false;
|
|
33952
34477
|
try {
|
|
@@ -33968,15 +34493,11 @@ async function refreshQuestionnaireFeatureAvailability(tabContext = activeTabCon
|
|
|
33968
34493
|
async function refreshOptionalFeaturePackageStatuses({ announce = false } = {}) {
|
|
33969
34494
|
try {
|
|
33970
34495
|
const response = await api("/api/optional-features", { scoped: false });
|
|
33971
|
-
|
|
33972
|
-
optionalFeaturePackageStatuses.clear();
|
|
33973
|
-
for (const status of response.data?.features || []) {
|
|
33974
|
-
if (status?.featureId) optionalFeaturePackageStatuses.set(status.featureId, status);
|
|
33975
|
-
}
|
|
34496
|
+
applyOptionalFeatureMigrationSnapshot(response.data, { announce: true });
|
|
33976
34497
|
await refreshQuestionnaireFeatureAvailability();
|
|
33977
|
-
renderOptionalFeatureControls();
|
|
33978
34498
|
return true;
|
|
33979
34499
|
} catch (error) {
|
|
34500
|
+
optionalFeaturePackageStatusesLoaded = false;
|
|
33980
34501
|
optionalFeaturePackageStatusError = error.message || String(error);
|
|
33981
34502
|
renderOptionalFeatureControls();
|
|
33982
34503
|
if (announce) addEvent(`optional feature package status check failed: ${optionalFeaturePackageStatusError}`, "warn");
|
|
@@ -34105,27 +34626,52 @@ function optionalFeatureStatus(featureId) {
|
|
|
34105
34626
|
return {
|
|
34106
34627
|
label: optionalFeatureInstallPhaseLabel(installState),
|
|
34107
34628
|
className: "updating",
|
|
34108
|
-
detail: optionalFeatureInstallDetail(installState, installMessage || "
|
|
34109
|
-
hint: "
|
|
34110
|
-
command: installState?.command ||
|
|
34629
|
+
detail: optionalFeatureInstallDetail(installState, installMessage || "Pi install is running; waiting for installer output"),
|
|
34630
|
+
hint: "Pi may be quiet while resolving the package; elapsed time updates here until it exits.",
|
|
34631
|
+
command: installState?.command || optionalFeatureManualInstallCommand(feature),
|
|
34111
34632
|
};
|
|
34112
34633
|
}
|
|
34113
34634
|
if (installState?.phase === "failed") {
|
|
34114
34635
|
return {
|
|
34115
34636
|
label: optionalFeatureInstallPhaseLabel(installState),
|
|
34116
34637
|
className: "failed",
|
|
34117
|
-
detail: optionalFeatureInstallDetail(installState, installState.detail || installMessage || "
|
|
34118
|
-
hint: installState.hint || "Copy the
|
|
34119
|
-
command: installState.command ||
|
|
34638
|
+
detail: optionalFeatureInstallDetail(installState, installState.detail || installMessage || "Pi install failed"),
|
|
34639
|
+
hint: installState.hint || "Copy the Pi command and run it manually from the Web UI host for full diagnostics.",
|
|
34640
|
+
command: installState.command || optionalFeatureManualInstallCommand(feature),
|
|
34120
34641
|
};
|
|
34121
34642
|
}
|
|
34122
34643
|
const doneDetail = installState?.phase === "done" ? optionalFeatureInstallDetail(installState, installMessage) : "";
|
|
34644
|
+
if (disabled) return {
|
|
34645
|
+
label: "Disabled",
|
|
34646
|
+
className: "disabled",
|
|
34647
|
+
detail: `Disabled in this browser and excluded from migration selection${versionSuffix}`,
|
|
34648
|
+
hint: "Enable it in Optional features before installing or restoring it.",
|
|
34649
|
+
};
|
|
34650
|
+
if (!packageStatus && !detected) return { label: "Checking", className: "updating", detail: "Checking Pi installation and registration status…" };
|
|
34651
|
+
if (packageStatus?.resourceConflict) return {
|
|
34652
|
+
label: "Duplicate conflict",
|
|
34653
|
+
className: "failed",
|
|
34654
|
+
detail: `Configured both as a Pi package and as a top-level resource; remove one registration before reloading${versionSuffix}`,
|
|
34655
|
+
hint: "Do not install again. Keep either the package entry or the extensions/skills/prompts/themes alias, not both.",
|
|
34656
|
+
};
|
|
34123
34657
|
if (packageStatus?.updateAvailable) return { label: "Update available", className: "updating", detail: packageStatus.updateReason || `Installed package is older than the Web UI expects${versionSuffix}` };
|
|
34124
34658
|
if (detected && managedWithTools) return { label: "Loaded", className: "enabled", detail: doneDetail || `Detected in the active Pi tab; manage access in Tools${versionSuffix}`, command: installState?.command || "" };
|
|
34125
34659
|
if (detected && !disabled) return { label: "Enabled", className: "enabled", detail: doneDetail || `Detected and enabled in Web UI${versionSuffix}`, command: installState?.command || "" };
|
|
34126
34660
|
if (detected && disabled) return { label: "Disabled", className: "disabled", detail: `Detected, but disabled in Web UI${versionSuffix}` };
|
|
34127
|
-
if (packageStatus?.
|
|
34128
|
-
return { label: "
|
|
34661
|
+
if (packageStatus?.locallyConfigured) return { label: "Available locally", className: "installed", detail: doneDetail || `Enabled as a top-level Pi resource; reload this tab if the capability is not detected yet${versionSuffix}` };
|
|
34662
|
+
if (packageStatus?.installed && packageStatus?.configured) return { label: "Installed", className: "installed", detail: doneDetail || `Registered with Pi but not loaded in the active tab${versionSuffix}`, command: installState?.command || "" };
|
|
34663
|
+
if (packageStatus?.installed && !packageStatus?.configured) return {
|
|
34664
|
+
label: "Registration needed",
|
|
34665
|
+
className: "missing",
|
|
34666
|
+
detail: doneDetail || `Package files exist, but the package is not registered in Pi settings${versionSuffix}`,
|
|
34667
|
+
command: optionalFeatureManualInstallCommand(feature),
|
|
34668
|
+
};
|
|
34669
|
+
return {
|
|
34670
|
+
label: "Install needed",
|
|
34671
|
+
className: "missing",
|
|
34672
|
+
detail: installMessage || "Package is not installed and registered with Pi",
|
|
34673
|
+
command: optionalFeatureManualInstallCommand(feature),
|
|
34674
|
+
};
|
|
34129
34675
|
}
|
|
34130
34676
|
|
|
34131
34677
|
function optionalFeatureTooltip(feature, status) {
|
|
@@ -34158,10 +34704,52 @@ function optionalFeatureWidgetHasSpecializedRenderer(key) {
|
|
|
34158
34704
|
return key.startsWith("btw:") || key.startsWith("release-npm:") || key.startsWith("release-aur:") || key === AUR_REVIEW_RPC_WIDGET_KEY || key === "workflow:subprocess" || key === WORKFLOW_INSPECTOR_WIDGET_KEY;
|
|
34159
34705
|
}
|
|
34160
34706
|
|
|
34707
|
+
function renderOptionalFeatureBatchToolbar() {
|
|
34708
|
+
const candidates = optionalFeatureBatchCandidates();
|
|
34709
|
+
const migratable = optionalFeatureMigrationCandidates();
|
|
34710
|
+
const busy = optionalFeatureBatchIsActive();
|
|
34711
|
+
const toolbar = make("div", "optional-feature-batch-toolbar");
|
|
34712
|
+
const action = make("button", "optional-feature-batch-action", busy ? "Installing…" : "Install all");
|
|
34713
|
+
action.type = "button";
|
|
34714
|
+
action.disabled = busy || optionalFeatureInstallInProgress.size > 0 || !optionalFeaturePackageStatusesLoaded || candidates.length === 0 || !!optionalFeaturePackageStatusError;
|
|
34715
|
+
action.setAttribute("aria-label", candidates.length
|
|
34716
|
+
? `Install all ${candidates.length} missing or unregistered optional features`
|
|
34717
|
+
: "All optional features are installed and registered");
|
|
34718
|
+
if (busy) action.setAttribute("aria-busy", "true");
|
|
34719
|
+
action.addEventListener("click", () => installOptionalFeatureBatch(OPTIONAL_FEATURES, { scopeLabel: "all optional features" }));
|
|
34720
|
+
|
|
34721
|
+
const actionGroup = make("div", "optional-feature-batch-actions");
|
|
34722
|
+
if (migratable.length) {
|
|
34723
|
+
const migrate = make("button", "optional-feature-batch-action primary", "Migrate…");
|
|
34724
|
+
migrate.type = "button";
|
|
34725
|
+
migrate.disabled = busy || optionalFeatureInstallInProgress.size > 0;
|
|
34726
|
+
migrate.setAttribute("aria-label", `Migrate ${migratable.length} previously available optional feature${migratable.length === 1 ? "" : "s"}`);
|
|
34727
|
+
migrate.addEventListener("click", () => openOptionalFeatureMigrationDialog());
|
|
34728
|
+
actionGroup.append(migrate);
|
|
34729
|
+
}
|
|
34730
|
+
actionGroup.append(action);
|
|
34731
|
+
|
|
34732
|
+
let summary = !optionalFeaturePackageStatusesLoaded
|
|
34733
|
+
? optionalFeaturePackageStatusError ? "Install availability unknown" : "Checking Pi package status…"
|
|
34734
|
+
: candidates.length ? `${candidates.length} missing or unregistered` : "All installed and registered";
|
|
34735
|
+
if (optionalFeatureMigrationSnapshot.phase === "checking") summary = "Checking optional features…";
|
|
34736
|
+
if (optionalFeatureBatchState?.phase === "running") {
|
|
34737
|
+
summary = optionalFeatureMigrationProgressText() || `Installing ${optionalFeatureBatchState.total} sequentially with Pi…`;
|
|
34738
|
+
} else if (["done", "failed"].includes(optionalFeatureBatchState?.phase)) {
|
|
34739
|
+
summary = `Batch finished: ${optionalFeatureBatchState.succeeded} succeeded, ${optionalFeatureBatchState.failed} failed.`;
|
|
34740
|
+
}
|
|
34741
|
+
const status = make("div", `optional-feature-batch-status${optionalFeatureBatchState?.failed ? " warning" : ""}`, summary);
|
|
34742
|
+
status.setAttribute("role", "status");
|
|
34743
|
+
status.setAttribute("aria-live", "polite");
|
|
34744
|
+
toolbar.append(status, actionGroup);
|
|
34745
|
+
return toolbar;
|
|
34746
|
+
}
|
|
34747
|
+
|
|
34161
34748
|
function renderOptionalFeaturePanel() {
|
|
34162
34749
|
if (!elements.optionalFeaturesBox) return;
|
|
34163
34750
|
elements.optionalFeaturesBox.replaceChildren();
|
|
34164
34751
|
elements.optionalFeaturesBox.classList.remove("muted");
|
|
34752
|
+
elements.optionalFeaturesBox.append(renderOptionalFeatureBatchToolbar());
|
|
34165
34753
|
|
|
34166
34754
|
if (optionalFeaturePackageStatusError) {
|
|
34167
34755
|
const notice = make("div", "optional-feature-panel-notice error");
|
|
@@ -34202,10 +34790,18 @@ function renderOptionalFeatureSection(section, features) {
|
|
|
34202
34790
|
sectionNode.dataset.optionalFeatureSection = section.id;
|
|
34203
34791
|
|
|
34204
34792
|
const header = make("div", "optional-feature-section-header");
|
|
34205
|
-
|
|
34206
|
-
|
|
34207
|
-
|
|
34208
|
-
|
|
34793
|
+
const headerActions = make("div", "optional-feature-section-actions");
|
|
34794
|
+
const candidates = optionalFeatureBatchCandidates(features);
|
|
34795
|
+
const installMissing = make("button", "optional-feature-section-install", optionalFeatureBatchIsActive() ? "Installing…" : "Install missing");
|
|
34796
|
+
installMissing.type = "button";
|
|
34797
|
+
installMissing.disabled = optionalFeatureBatchIsActive() || optionalFeatureInstallInProgress.size > 0 || !optionalFeaturePackageStatusesLoaded || candidates.length === 0 || !!optionalFeaturePackageStatusError;
|
|
34798
|
+
installMissing.setAttribute("aria-label", candidates.length
|
|
34799
|
+
? `Install ${candidates.length} missing or unregistered features in ${section.label}`
|
|
34800
|
+
: `All features in ${section.label} are installed and registered`);
|
|
34801
|
+
if (optionalFeatureBatchIsActive()) installMissing.setAttribute("aria-busy", "true");
|
|
34802
|
+
installMissing.addEventListener("click", () => installOptionalFeatureBatch(features, { scopeLabel: section.label }));
|
|
34803
|
+
headerActions.append(make("span", "optional-feature-section-count", String(features.length)), installMissing);
|
|
34804
|
+
header.append(make("div", "optional-feature-section-title", section.label), headerActions);
|
|
34209
34805
|
sectionNode.append(header);
|
|
34210
34806
|
if (section.description) sectionNode.append(make("div", "optional-feature-section-description", section.description));
|
|
34211
34807
|
|
|
@@ -34227,6 +34823,7 @@ function renderOptionalFeatureRow(feature) {
|
|
|
34227
34823
|
const tooltip = optionalFeatureTooltip(feature, status);
|
|
34228
34824
|
row.dataset.tooltip = tooltip;
|
|
34229
34825
|
row.setAttribute("aria-label", tooltip.replace(/\s+/g, " "));
|
|
34826
|
+
if (installing) row.setAttribute("aria-busy", "true");
|
|
34230
34827
|
row.tabIndex = 0;
|
|
34231
34828
|
|
|
34232
34829
|
const main = make("div", "optional-feature-main");
|
|
@@ -34235,7 +34832,8 @@ function renderOptionalFeatureRow(feature) {
|
|
|
34235
34832
|
main.append(title);
|
|
34236
34833
|
if (status.detail) {
|
|
34237
34834
|
const detail = make("div", `optional-feature-detail ${status.className === "failed" ? "error" : ""}`.trim(), status.detail);
|
|
34238
|
-
|
|
34835
|
+
if (status.className === "failed" && !installing) detail.setAttribute("role", "alert");
|
|
34836
|
+
else detail.setAttribute("aria-live", installing ? "polite" : "off");
|
|
34239
34837
|
main.append(detail);
|
|
34240
34838
|
}
|
|
34241
34839
|
if (installing) {
|
|
@@ -34255,7 +34853,7 @@ function renderOptionalFeatureRow(feature) {
|
|
|
34255
34853
|
const actions = make("div", "optional-feature-actions");
|
|
34256
34854
|
const action = make("button", "optional-feature-action");
|
|
34257
34855
|
action.type = "button";
|
|
34258
|
-
action.disabled = installing;
|
|
34856
|
+
action.disabled = installing || optionalFeatureBatchIsActive() || (!optionalFeaturePackageStatusesLoaded && !detected);
|
|
34259
34857
|
if (installing) {
|
|
34260
34858
|
action.textContent = installState?.actionLabel === "Update" ? "Updating…" : "Installing…";
|
|
34261
34859
|
action.setAttribute("aria-busy", "true");
|
|
@@ -34264,6 +34862,12 @@ function renderOptionalFeatureRow(feature) {
|
|
|
34264
34862
|
action.textContent = "Retry…";
|
|
34265
34863
|
action.classList.add(retryAsUpdate ? "update" : "install");
|
|
34266
34864
|
action.addEventListener("click", () => installOptionalFeature(feature.id, { update: retryAsUpdate }));
|
|
34865
|
+
} else if (isOptionalFeatureDisabled(feature.id)) {
|
|
34866
|
+
action.textContent = "Enable";
|
|
34867
|
+
action.addEventListener("click", () => setOptionalFeatureDisabled(feature.id, false));
|
|
34868
|
+
} else if (packageStatus?.resourceConflict) {
|
|
34869
|
+
action.textContent = "Conflict";
|
|
34870
|
+
action.disabled = true;
|
|
34267
34871
|
} else if (packageStatus?.updateAvailable) {
|
|
34268
34872
|
action.textContent = "Update…";
|
|
34269
34873
|
action.classList.add("update");
|
|
@@ -34299,7 +34903,7 @@ function renderOptionalFeatureRow(feature) {
|
|
|
34299
34903
|
successMessage: `${feature.label} was ${disabled ? "re-enabled" : "disabled again"}.`,
|
|
34300
34904
|
});
|
|
34301
34905
|
});
|
|
34302
|
-
} else if (packageStatus?.
|
|
34906
|
+
} else if (packageStatus?.ready) {
|
|
34303
34907
|
action.textContent = "Reload";
|
|
34304
34908
|
action.addEventListener("click", () => sendPrompt("prompt", "/reload"));
|
|
34305
34909
|
} else {
|
|
@@ -34308,9 +34912,21 @@ function renderOptionalFeatureRow(feature) {
|
|
|
34308
34912
|
action.addEventListener("click", () => installOptionalFeature(feature.id));
|
|
34309
34913
|
}
|
|
34310
34914
|
actions.append(action);
|
|
34915
|
+
if (failed) {
|
|
34916
|
+
const retryFailed = make("button", "optional-feature-action install", "Retry failed");
|
|
34917
|
+
retryFailed.type = "button";
|
|
34918
|
+
retryFailed.disabled = optionalFeatureBatchIsActive();
|
|
34919
|
+
retryFailed.addEventListener("click", () => {
|
|
34920
|
+
const audit = optionalFeatureAuditFeature(feature.id);
|
|
34921
|
+
if (audit?.state === "legacy-migratable") openOptionalFeatureMigrationDialog({ featureIds: [feature.id], retryFailed: true });
|
|
34922
|
+
else installOptionalFeature(feature.id, { update: packageStatus?.updateAvailable === true });
|
|
34923
|
+
});
|
|
34924
|
+
actions.replaceChildren(retryFailed);
|
|
34925
|
+
}
|
|
34311
34926
|
if (status.command) {
|
|
34312
34927
|
const copyCommand = make("button", "optional-feature-action copy-command", "Copy cmd");
|
|
34313
34928
|
copyCommand.type = "button";
|
|
34929
|
+
copyCommand.disabled = optionalFeatureBatchIsActive();
|
|
34314
34930
|
copyCommand.addEventListener("click", () => copyOptionalFeatureInstallCommand(feature.id));
|
|
34315
34931
|
actions.append(copyCommand);
|
|
34316
34932
|
}
|
|
@@ -34445,16 +35061,16 @@ function commandUnavailableMessage(commandName) {
|
|
|
34445
35061
|
|
|
34446
35062
|
async function installOptionalFeature(featureId, { update = false } = {}) {
|
|
34447
35063
|
const feature = OPTIONAL_FEATURE_BY_ID.get(featureId);
|
|
34448
|
-
if (!feature || optionalFeatureInstallInProgress.has(featureId)) return;
|
|
35064
|
+
if (!feature || optionalFeatureInstallInProgress.has(featureId) || optionalFeatureBatchIsActive()) return;
|
|
34449
35065
|
|
|
34450
35066
|
const actionLabel = update ? "Update" : "Install";
|
|
34451
35067
|
const warning = [
|
|
34452
35068
|
`${actionLabel} optional feature: ${feature.label}?`,
|
|
34453
35069
|
"",
|
|
34454
|
-
`This will run
|
|
34455
|
-
"
|
|
34456
|
-
"Progress, elapsed time, the
|
|
34457
|
-
"
|
|
35070
|
+
`This will run ${optionalFeatureManualInstallCommand(feature)} with the selected Pi CLI.`,
|
|
35071
|
+
"Pi can download code from npm and update its user package registration and package storage.",
|
|
35072
|
+
"Progress, elapsed time, the Pi command, and actionable failures will be shown in the optional-features row and activity log.",
|
|
35073
|
+
"Re-running the same Pi install command is the supported update path.",
|
|
34458
35074
|
"",
|
|
34459
35075
|
"Continue?",
|
|
34460
35076
|
].join("\n");
|
|
@@ -34462,34 +35078,34 @@ async function installOptionalFeature(featureId, { update = false } = {}) {
|
|
|
34462
35078
|
|
|
34463
35079
|
const startedAt = Date.now();
|
|
34464
35080
|
optionalFeatureInstallInProgress.add(featureId);
|
|
34465
|
-
optionalFeatureInstallMessages.set(featureId, `${actionLabel} preparing
|
|
35081
|
+
optionalFeatureInstallMessages.set(featureId, `${actionLabel} preparing with Pi…`);
|
|
34466
35082
|
setOptionalFeatureInstallState(featureId, {
|
|
34467
35083
|
phase: "preparing",
|
|
34468
35084
|
actionLabel,
|
|
34469
35085
|
startedAt,
|
|
34470
35086
|
endedAt: 0,
|
|
34471
|
-
detail: "Resolving
|
|
34472
|
-
hint: "The
|
|
34473
|
-
command:
|
|
35087
|
+
detail: "Resolving the selected Pi CLI…",
|
|
35088
|
+
hint: "The Pi installer has not started yet.",
|
|
35089
|
+
command: optionalFeatureManualInstallCommand(feature),
|
|
34474
35090
|
outputTail: "",
|
|
34475
35091
|
});
|
|
34476
35092
|
startOptionalFeatureInstallProgressTimer(featureId);
|
|
34477
|
-
addEvent(`${update ? "updating" : "installing"} optional feature ${feature.label} (${feature.packageName})…`, "warn");
|
|
35093
|
+
addEvent(`${update ? "updating" : "installing"} optional feature ${feature.label} (${feature.packageName}) with Pi…`, "warn");
|
|
34478
35094
|
setTimeout(() => {
|
|
34479
35095
|
const state = optionalFeatureInstallState(featureId);
|
|
34480
35096
|
if (optionalFeatureInstallInProgress.has(featureId) && state?.startedAt === startedAt && state.phase === "preparing") {
|
|
34481
|
-
optionalFeatureInstallMessages.set(featureId, `${actionLabel} running via
|
|
35097
|
+
optionalFeatureInstallMessages.set(featureId, `${actionLabel} running via Pi; waiting for installer output…`);
|
|
34482
35098
|
setOptionalFeatureInstallState(featureId, {
|
|
34483
35099
|
phase: "installing",
|
|
34484
|
-
detail: "
|
|
34485
|
-
hint: "
|
|
35100
|
+
detail: "Pi install is running; waiting for installer output…",
|
|
35101
|
+
hint: "Pi may be quiet while resolving the npm package. Keep this page open; elapsed time updates here.",
|
|
34486
35102
|
});
|
|
34487
35103
|
}
|
|
34488
35104
|
}, 1200);
|
|
34489
35105
|
|
|
34490
35106
|
try {
|
|
34491
35107
|
const response = await api("/api/optional-feature-install", { method: "POST", body: { featureId }, scoped: false });
|
|
34492
|
-
const command = response.data?.command ||
|
|
35108
|
+
const command = response.data?.command || optionalFeatureManualInstallCommand(feature);
|
|
34493
35109
|
disabledOptionalFeatures.delete(featureId);
|
|
34494
35110
|
storeDisabledOptionalFeatures();
|
|
34495
35111
|
optionalFeatureInstallMessages.set(featureId, response.data?.message || `${actionLabel} finished`);
|
|
@@ -34497,24 +35113,24 @@ async function installOptionalFeature(featureId, { update = false } = {}) {
|
|
|
34497
35113
|
phase: "refreshing",
|
|
34498
35114
|
actionLabel,
|
|
34499
35115
|
startedAt,
|
|
34500
|
-
detail: "
|
|
34501
|
-
hint: "
|
|
35116
|
+
detail: "Pi finished; checking installation and registration status…",
|
|
35117
|
+
hint: "Reload the active Pi tab to load newly registered resources.",
|
|
34502
35118
|
command,
|
|
34503
35119
|
outputTail: "",
|
|
34504
35120
|
});
|
|
34505
|
-
addEvent(response.data?.message || `${update ? "updated" : "installed"} ${feature.packageName}`, "info");
|
|
35121
|
+
addEvent(response.data?.message || `${update ? "updated" : "installed"} ${feature.packageName} with Pi`, "info");
|
|
34506
35122
|
const output = [response.data?.stderr, response.data?.stdout].filter(Boolean).join("\n").trim();
|
|
34507
|
-
if (output) addEvent(`
|
|
35123
|
+
if (output) addEvent(`Pi install output for ${feature.packageName}:\n${output.slice(-4000)}`, "info");
|
|
34508
35124
|
await refreshOptionalFeaturePackageStatuses({ announce: true });
|
|
34509
35125
|
setOptionalFeatureInstallState(featureId, {
|
|
34510
35126
|
phase: "done",
|
|
34511
35127
|
actionLabel,
|
|
34512
35128
|
endedAt: Date.now(),
|
|
34513
|
-
detail: response.data?.message || `${actionLabel} finished. Reload the active Pi tab to load newly
|
|
35129
|
+
detail: response.data?.message || `${actionLabel} finished. Reload the active Pi tab to load newly registered resources.`,
|
|
34514
35130
|
hint: "Use Reload if this row still says Installed instead of Enabled.",
|
|
34515
35131
|
command,
|
|
34516
35132
|
});
|
|
34517
|
-
if (await appConfirmText(`${feature.label} ${actionLabel.toLowerCase()} finished. Reload the active Pi tab now to
|
|
35133
|
+
if (await appConfirmText(`${feature.label} ${actionLabel.toLowerCase()} finished. Reload the active Pi tab now to load its resources?`, { affected: "The active Pi tab", confirmLabel: "Reload tab", danger: false })) {
|
|
34518
35134
|
sendPrompt("prompt", "/reload");
|
|
34519
35135
|
} else {
|
|
34520
35136
|
const tabContext = activeTabContext();
|
|
@@ -34530,7 +35146,7 @@ async function installOptionalFeature(featureId, { update = false } = {}) {
|
|
|
34530
35146
|
endedAt: Date.now(),
|
|
34531
35147
|
detail: failure.message,
|
|
34532
35148
|
hint: failure.hint,
|
|
34533
|
-
command: failure.command || optionalFeatureInstallState(featureId)?.command ||
|
|
35149
|
+
command: failure.command || optionalFeatureInstallState(featureId)?.command || optionalFeatureManualInstallCommand(feature),
|
|
34534
35150
|
outputTail: failure.outputTail || "",
|
|
34535
35151
|
errorKind: failure.kind || "unknown",
|
|
34536
35152
|
});
|
|
@@ -34542,6 +35158,221 @@ async function installOptionalFeature(featureId, { update = false } = {}) {
|
|
|
34542
35158
|
}
|
|
34543
35159
|
}
|
|
34544
35160
|
|
|
35161
|
+
async function installOptionalFeatureBatch(features, { scopeLabel = "optional features" } = {}) {
|
|
35162
|
+
if (optionalFeatureBatchIsActive() || optionalFeatureInstallInProgress.size > 0) return;
|
|
35163
|
+
const candidates = optionalFeatureBatchCandidates(features);
|
|
35164
|
+
if (!candidates.length) {
|
|
35165
|
+
addEvent(`no missing or unregistered ${scopeLabel} to install`, "info");
|
|
35166
|
+
return;
|
|
35167
|
+
}
|
|
35168
|
+
|
|
35169
|
+
const warning = [
|
|
35170
|
+
`Install ${candidates.length} missing or unregistered ${scopeLabel}?`,
|
|
35171
|
+
"",
|
|
35172
|
+
"The selected Pi CLI will run one install command at a time:",
|
|
35173
|
+
...candidates.map((feature) => optionalFeatureManualInstallCommand(feature)),
|
|
35174
|
+
"",
|
|
35175
|
+
"Pi can download code from npm and update its user package registration and package storage.",
|
|
35176
|
+
"The batch continues after individual failures and reports every result.",
|
|
35177
|
+
"The affected tab restarts automatically only when idle; busy work is never interrupted.",
|
|
35178
|
+
"",
|
|
35179
|
+
"Continue?",
|
|
35180
|
+
].join("\n");
|
|
35181
|
+
if (!(await appConfirmText(warning, {
|
|
35182
|
+
affected: `${candidates.length} optional feature package${candidates.length === 1 ? "" : "s"}`,
|
|
35183
|
+
confirmLabel: candidates.length === 1 ? "Install feature" : "Install features",
|
|
35184
|
+
}))) return;
|
|
35185
|
+
|
|
35186
|
+
await runOptionalFeatureBatch(candidates, {
|
|
35187
|
+
scopeLabel,
|
|
35188
|
+
migration: false,
|
|
35189
|
+
signatureFeatureIds: candidates.map((feature) => feature.id),
|
|
35190
|
+
candidateSignature: optionalFeatureCandidateSignature(optionalFeatureMigrationSnapshot, candidates.map((feature) => feature.id)),
|
|
35191
|
+
reopen: () => installOptionalFeatureBatch(features, { scopeLabel }),
|
|
35192
|
+
});
|
|
35193
|
+
}
|
|
35194
|
+
|
|
35195
|
+
async function postOptionalFeatureBatch({ featureIds, migration, signatureFeatureIds, candidateSignature, retryOnStale = true }) {
|
|
35196
|
+
const submit = () => api("/api/optional-feature-install-batch", {
|
|
35197
|
+
method: "POST",
|
|
35198
|
+
body: { tab: activeTabId, featureIds, revision: optionalFeatureMigrationSnapshot.revision, migration },
|
|
35199
|
+
scoped: false,
|
|
35200
|
+
});
|
|
35201
|
+
try {
|
|
35202
|
+
return await submit();
|
|
35203
|
+
} catch (error) {
|
|
35204
|
+
const staleRevision = error.statusCode === 409 && /stale|revision/i.test(error.message || "");
|
|
35205
|
+
if (!staleRevision || !retryOnStale) throw error;
|
|
35206
|
+
await refreshOptionalFeaturePackageStatuses();
|
|
35207
|
+
const refreshedSignature = optionalFeatureCandidateSignature(optionalFeatureMigrationSnapshot, signatureFeatureIds);
|
|
35208
|
+
if (refreshedSignature !== candidateSignature) {
|
|
35209
|
+
error.optionalFeatureCandidatesChanged = true;
|
|
35210
|
+
throw error;
|
|
35211
|
+
}
|
|
35212
|
+
try {
|
|
35213
|
+
return await submit();
|
|
35214
|
+
} catch (retryError) {
|
|
35215
|
+
const stillStale = retryError.statusCode === 409 && /stale|revision/i.test(retryError.message || "");
|
|
35216
|
+
if (stillStale) retryError.optionalFeatureRevisionChurn = true;
|
|
35217
|
+
throw retryError;
|
|
35218
|
+
}
|
|
35219
|
+
}
|
|
35220
|
+
}
|
|
35221
|
+
|
|
35222
|
+
function restoreOptionalFeatureInstallStates(previousStates) {
|
|
35223
|
+
for (const [featureId, state] of previousStates) {
|
|
35224
|
+
if (state) optionalFeatureInstallStates.set(featureId, state);
|
|
35225
|
+
else optionalFeatureInstallStates.delete(featureId);
|
|
35226
|
+
}
|
|
35227
|
+
}
|
|
35228
|
+
|
|
35229
|
+
async function runOptionalFeatureBatch(candidates, {
|
|
35230
|
+
scopeLabel = "optional features",
|
|
35231
|
+
migration = false,
|
|
35232
|
+
signatureFeatureIds = candidates.map((feature) => feature.id),
|
|
35233
|
+
candidateSignature = optionalFeatureCandidateSignature(optionalFeatureMigrationSnapshot, signatureFeatureIds),
|
|
35234
|
+
reopen = null,
|
|
35235
|
+
} = {}) {
|
|
35236
|
+
if (!candidates.length || optionalFeatureBatchIsActive() || optionalFeatureInstallInProgress.size > 0) return;
|
|
35237
|
+
const startedAt = Date.now();
|
|
35238
|
+
const actionLabel = migration ? "Migrate" : "Install";
|
|
35239
|
+
const featureIds = candidates.map((feature) => feature.id);
|
|
35240
|
+
const previousStates = new Map(candidates.map((feature) => [feature.id, optionalFeatureInstallState(feature.id)]));
|
|
35241
|
+
optionalFeatureBatchState = { phase: "running", scopeLabel, total: candidates.length, succeeded: 0, failed: 0, startedAt };
|
|
35242
|
+
candidates.forEach((feature, index) => {
|
|
35243
|
+
optionalFeatureInstallInProgress.add(feature.id);
|
|
35244
|
+
optionalFeatureInstallMessages.set(feature.id, `Queued (${index + 1} of ${candidates.length})…`);
|
|
35245
|
+
setOptionalFeatureInstallState(feature.id, {
|
|
35246
|
+
phase: "installing",
|
|
35247
|
+
actionLabel,
|
|
35248
|
+
startedAt,
|
|
35249
|
+
endedAt: 0,
|
|
35250
|
+
detail: `Installing ${index + 1} of ${candidates.length}: ${feature.label}`,
|
|
35251
|
+
hint: "Pi installs sequentially and continues after individual failures.",
|
|
35252
|
+
command: optionalFeatureManualInstallCommand(feature),
|
|
35253
|
+
outputTail: "",
|
|
35254
|
+
});
|
|
35255
|
+
startOptionalFeatureInstallProgressTimer(feature.id);
|
|
35256
|
+
});
|
|
35257
|
+
addEvent(`installing ${candidates.length} ${scopeLabel} sequentially with Pi`, "warn");
|
|
35258
|
+
|
|
35259
|
+
try {
|
|
35260
|
+
const response = await postOptionalFeatureBatch({ featureIds, migration, signatureFeatureIds, candidateSignature });
|
|
35261
|
+
const results = Array.isArray(response.data?.results) ? response.data.results : [];
|
|
35262
|
+
const resultByFeatureId = new Map(results.map((result) => [result?.featureId, result]));
|
|
35263
|
+
let succeeded = 0;
|
|
35264
|
+
let failed = 0;
|
|
35265
|
+
|
|
35266
|
+
for (const feature of candidates) {
|
|
35267
|
+
const result = resultByFeatureId.get(feature.id);
|
|
35268
|
+
if (result?.ok === true) {
|
|
35269
|
+
succeeded += 1;
|
|
35270
|
+
const data = result.data || {};
|
|
35271
|
+
const command = data.command || optionalFeatureManualInstallCommand(feature);
|
|
35272
|
+
optionalFeatureInstallMessages.set(feature.id, data.message || "Installed and registered with Pi");
|
|
35273
|
+
setOptionalFeatureInstallState(feature.id, {
|
|
35274
|
+
phase: "done",
|
|
35275
|
+
actionLabel,
|
|
35276
|
+
startedAt,
|
|
35277
|
+
endedAt: Date.now(),
|
|
35278
|
+
detail: data.message || "Installed and verified with Pi.",
|
|
35279
|
+
hint: response.data?.restart?.autoRestarted ? "The affected tab restarted automatically." : "The server verified this package registration.",
|
|
35280
|
+
command,
|
|
35281
|
+
outputTail: "",
|
|
35282
|
+
});
|
|
35283
|
+
const output = [data.stderr, data.stdout].filter(Boolean).join("\n").trim().slice(-4000);
|
|
35284
|
+
if (output) addEvent(`Pi install output for ${feature.packageName}:\n${output}`, "info");
|
|
35285
|
+
addEvent(data.message || `installed ${feature.packageName} with Pi`, "info");
|
|
35286
|
+
} else {
|
|
35287
|
+
failed += 1;
|
|
35288
|
+
const failure = optionalFeatureInstallFailureFromBatchResult(result, feature);
|
|
35289
|
+
optionalFeatureInstallMessages.set(feature.id, `${actionLabel} failed: ${failure.message}`);
|
|
35290
|
+
setOptionalFeatureInstallState(feature.id, {
|
|
35291
|
+
phase: "failed",
|
|
35292
|
+
actionLabel,
|
|
35293
|
+
startedAt,
|
|
35294
|
+
endedAt: Date.now(),
|
|
35295
|
+
detail: failure.message,
|
|
35296
|
+
hint: failure.hint,
|
|
35297
|
+
command: failure.command,
|
|
35298
|
+
outputTail: String(failure.outputTail || "").slice(-4000),
|
|
35299
|
+
errorKind: failure.kind || "unknown",
|
|
35300
|
+
});
|
|
35301
|
+
addEvent(`${actionLabel.toLowerCase()} optional feature ${feature.label} failed: ${failure.message}${failure.hint ? `\nHint: ${failure.hint}` : ""}`, "error");
|
|
35302
|
+
}
|
|
35303
|
+
}
|
|
35304
|
+
|
|
35305
|
+
optionalFeatureBatchState = { phase: failed ? "failed" : "done", scopeLabel, total: candidates.length, succeeded, failed, startedAt, endedAt: Date.now() };
|
|
35306
|
+
const restart = response.data?.restart || {};
|
|
35307
|
+
if (restart.autoRestarted || restart.restartDeferred) {
|
|
35308
|
+
optionalFeatureRestartNotice = { ...restart, tabId: activeTabId };
|
|
35309
|
+
addEvent(restart.autoRestarted ? "restarted tab to load new optional features" : "optional feature restart deferred because the tab is busy", restart.restartDeferred ? "warn" : "info");
|
|
35310
|
+
}
|
|
35311
|
+
await refreshOptionalFeaturePackageStatuses({ announce: true });
|
|
35312
|
+
addEvent(`optional feature batch finished: ${succeeded} succeeded, ${failed} failed`, failed ? "warn" : "info");
|
|
35313
|
+
renderOptionalFeatureMigrationSurface();
|
|
35314
|
+
// Backend-owned idle restart replaces the legacy post-batch prompt (formerly confirmLabel: "Reload tab").
|
|
35315
|
+
} catch (error) {
|
|
35316
|
+
if (error.optionalFeatureCandidatesChanged || error.optionalFeatureRevisionChurn) {
|
|
35317
|
+
restoreOptionalFeatureInstallStates(previousStates);
|
|
35318
|
+
optionalFeatureBatchState = null;
|
|
35319
|
+
if (error.optionalFeatureRevisionChurn) await refreshOptionalFeaturePackageStatuses();
|
|
35320
|
+
addEvent(error.optionalFeatureRevisionChurn
|
|
35321
|
+
? "optional feature audit changed repeatedly; refreshed the plan before asking again"
|
|
35322
|
+
: "optional feature choices changed while confirmation was open; refreshed the current migration plan", "warn");
|
|
35323
|
+
if (typeof reopen === "function") setTimeout(reopen, 0);
|
|
35324
|
+
} else if (error.statusCode === 409 && /already in progress|mutation|busy/i.test(error.message || "")) {
|
|
35325
|
+
restoreOptionalFeatureInstallStates(previousStates);
|
|
35326
|
+
optionalFeatureBatchState = null;
|
|
35327
|
+
await refreshOptionalFeaturePackageStatuses();
|
|
35328
|
+
addEvent("another optional feature operation is already running; recovered its server-owned progress", "warn");
|
|
35329
|
+
} else {
|
|
35330
|
+
const failure = optionalFeatureInstallFailureFromError(error);
|
|
35331
|
+
for (const feature of candidates) {
|
|
35332
|
+
optionalFeatureInstallMessages.set(feature.id, `Batch request failed: ${failure.message}`);
|
|
35333
|
+
setOptionalFeatureInstallState(feature.id, {
|
|
35334
|
+
phase: "failed",
|
|
35335
|
+
actionLabel,
|
|
35336
|
+
startedAt,
|
|
35337
|
+
endedAt: Date.now(),
|
|
35338
|
+
detail: failure.message,
|
|
35339
|
+
hint: failure.hint,
|
|
35340
|
+
command: failure.command || optionalFeatureManualInstallCommand(feature),
|
|
35341
|
+
outputTail: String(failure.outputTail || "").slice(-4000),
|
|
35342
|
+
errorKind: failure.kind || "batch-request",
|
|
35343
|
+
});
|
|
35344
|
+
}
|
|
35345
|
+
optionalFeatureBatchState = { phase: "failed", scopeLabel, total: candidates.length, succeeded: 0, failed: candidates.length, startedAt, endedAt: Date.now() };
|
|
35346
|
+
addEvent(`optional feature batch request failed: ${failure.message}${failure.hint ? `\nHint: ${failure.hint}` : ""}`, "error");
|
|
35347
|
+
}
|
|
35348
|
+
} finally {
|
|
35349
|
+
for (const feature of candidates) {
|
|
35350
|
+
optionalFeatureInstallInProgress.delete(feature.id);
|
|
35351
|
+
clearOptionalFeatureInstallProgressTimer(feature.id);
|
|
35352
|
+
}
|
|
35353
|
+
renderOptionalFeatureControls();
|
|
35354
|
+
renderOptionalFeatureMigrationSurface();
|
|
35355
|
+
}
|
|
35356
|
+
}
|
|
35357
|
+
|
|
35358
|
+
async function migrateSelectedOptionalFeatures() {
|
|
35359
|
+
const state = optionalFeatureMigrationDialogState;
|
|
35360
|
+
if (!state || optionalFeatureBatchIsActive()) return;
|
|
35361
|
+
const selectedIds = [...state.selected].filter((featureId) => !isOptionalFeatureDisabled(featureId));
|
|
35362
|
+
const candidates = selectedIds.map((featureId) => OPTIONAL_FEATURE_BY_ID.get(featureId)).filter(Boolean);
|
|
35363
|
+
if (!candidates.length) return;
|
|
35364
|
+
elements.optionalFeatureMigrationConfirmButton.disabled = true;
|
|
35365
|
+
elements.optionalFeatureMigrationDialogError.hidden = true;
|
|
35366
|
+
elements.optionalFeatureMigrationDialog.close();
|
|
35367
|
+
await runOptionalFeatureBatch(candidates, {
|
|
35368
|
+
scopeLabel: state.retryFailed ? "failed optional features" : "previous optional features",
|
|
35369
|
+
migration: true,
|
|
35370
|
+
signatureFeatureIds: state.featureIds,
|
|
35371
|
+
candidateSignature: state.signature,
|
|
35372
|
+
reopen: () => openOptionalFeatureMigrationDialog({ featureIds: state.featureIds, retryFailed: state.retryFailed }),
|
|
35373
|
+
});
|
|
35374
|
+
}
|
|
35375
|
+
|
|
34545
35376
|
function runPublishWorkflow(command) {
|
|
34546
35377
|
setComposerActionsOpen(false);
|
|
34547
35378
|
setPublishMenuOpen(false);
|
|
@@ -34584,6 +35415,176 @@ async function runNativeCommandMenu(command) {
|
|
|
34584
35415
|
await sendPrompt("prompt", command);
|
|
34585
35416
|
}
|
|
34586
35417
|
|
|
35418
|
+
function normalizeSessionSummaryClientState(value, previous = null, { resetProjection = false } = {}) {
|
|
35419
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || value.version !== SESSION_SUMMARY_PROTOCOL_VERSION) return null;
|
|
35420
|
+
const status = ["idle", "generating", "success", "failure"].includes(value.status) ? value.status : "idle";
|
|
35421
|
+
const title = typeof value.title === "string" && value.title.length <= 44 && !/[\r\n]/.test(value.title) ? value.title.trim() : "";
|
|
35422
|
+
const summaryMarkdown = typeof value.summaryMarkdown === "string" && value.summaryMarkdown.length <= SESSION_SUMMARY_MARKDOWN_MAX_CHARS
|
|
35423
|
+
? value.summaryMarkdown.trim()
|
|
35424
|
+
: "";
|
|
35425
|
+
const message = typeof value.message === "string" ? value.message.replace(/[\r\n]+/g, " ").slice(0, 512).trim() : "";
|
|
35426
|
+
const sessionId = typeof value.sessionId === "string" ? value.sessionId.slice(0, 128) : previous?.sessionId || "";
|
|
35427
|
+
const sessionChanged = !!(sessionId && previous?.sessionId && sessionId !== previous.sessionId);
|
|
35428
|
+
const inherited = resetProjection || sessionChanged ? null : previous;
|
|
35429
|
+
return {
|
|
35430
|
+
version: SESSION_SUMMARY_PROTOCOL_VERSION,
|
|
35431
|
+
status,
|
|
35432
|
+
configured: value.configured === true,
|
|
35433
|
+
enabled: value.enabled === true,
|
|
35434
|
+
durable: value.durable === true,
|
|
35435
|
+
sessionId,
|
|
35436
|
+
title: title || inherited?.title || "",
|
|
35437
|
+
summaryMarkdown: summaryMarkdown || inherited?.summaryMarkdown || "",
|
|
35438
|
+
message,
|
|
35439
|
+
updatedAt: typeof value.updatedAt === "string" ? value.updatedAt : new Date().toISOString(),
|
|
35440
|
+
};
|
|
35441
|
+
}
|
|
35442
|
+
|
|
35443
|
+
function sessionSummaryStateForTab(tabId = activeTabId) {
|
|
35444
|
+
if (!tabId) return null;
|
|
35445
|
+
const cached = sessionSummaryByTab.get(tabId);
|
|
35446
|
+
if (cached) return cached;
|
|
35447
|
+
const metadata = tabs.find((tab) => tab.id === tabId)?.sessionSummary;
|
|
35448
|
+
const normalized = normalizeSessionSummaryClientState(metadata);
|
|
35449
|
+
if (normalized) sessionSummaryByTab.set(tabId, normalized);
|
|
35450
|
+
return normalized;
|
|
35451
|
+
}
|
|
35452
|
+
|
|
35453
|
+
function renderSessionSummaryControls() {
|
|
35454
|
+
const available = !!activeTabId && hasAvailableCommand("summary", { tabId: activeTabId });
|
|
35455
|
+
const setupAvailable = !!activeTabId && hasAvailableCommand("summary-setup", { tabId: activeTabId });
|
|
35456
|
+
const state = sessionSummaryStateForTab(activeTabId);
|
|
35457
|
+
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";
|
|
35458
|
+
for (const button of [elements.summaryHeaderButton, elements.summaryActionButton]) {
|
|
35459
|
+
if (!button) continue;
|
|
35460
|
+
button.hidden = !available;
|
|
35461
|
+
button.disabled = !available || state?.status === "generating";
|
|
35462
|
+
button.setAttribute("aria-busy", state?.status === "generating" ? "true" : "false");
|
|
35463
|
+
applyStyledTooltip(button, status, { ariaLabel: status, align: "end" });
|
|
35464
|
+
}
|
|
35465
|
+
if (elements.optionsSummarySetupButton) elements.optionsSummarySetupButton.hidden = !setupAvailable;
|
|
35466
|
+
}
|
|
35467
|
+
|
|
35468
|
+
function closeSessionSummaryOverlay({ restoreFocus = true } = {}) {
|
|
35469
|
+
const overlay = elements.sessionSummaryOverlay;
|
|
35470
|
+
if (!overlay || overlay.hidden) return;
|
|
35471
|
+
overlay.hidden = true;
|
|
35472
|
+
const focusReturn = sessionSummaryOverlayFocusReturn;
|
|
35473
|
+
sessionSummaryOverlayTabId = null;
|
|
35474
|
+
sessionSummaryOverlayFocusReturn = null;
|
|
35475
|
+
if (restoreFocus && focusReturn?.isConnected) queueMicrotask(() => focusReturn.focus({ preventScroll: true }));
|
|
35476
|
+
}
|
|
35477
|
+
|
|
35478
|
+
function renderSessionSummaryOverlay() {
|
|
35479
|
+
const overlay = elements.sessionSummaryOverlay;
|
|
35480
|
+
if (!overlay || overlay.hidden || !sessionSummaryOverlayTabId) return;
|
|
35481
|
+
const tab = tabs.find((item) => item.id === sessionSummaryOverlayTabId);
|
|
35482
|
+
const state = sessionSummaryStateForTab(sessionSummaryOverlayTabId);
|
|
35483
|
+
elements.sessionSummaryOverlayTitle.textContent = state?.title || "Session summary";
|
|
35484
|
+
elements.sessionSummaryOverlayMeta.textContent = `${tab?.title || "Pi terminal"}${state?.durable === false ? " · in-memory session" : ""}`;
|
|
35485
|
+
const generating = state?.status === "generating";
|
|
35486
|
+
const failed = state?.status === "failure";
|
|
35487
|
+
elements.sessionSummaryOverlayStatus.textContent = generating
|
|
35488
|
+
? "Generating with the configured background model…"
|
|
35489
|
+
: failed
|
|
35490
|
+
? state.message || "Summary generation failed. The previous successful summary is preserved."
|
|
35491
|
+
: state?.summaryMarkdown
|
|
35492
|
+
? "Latest successful active-branch summary."
|
|
35493
|
+
: "No successful summary is available yet.";
|
|
35494
|
+
elements.sessionSummaryOverlayStatus.classList.toggle("error", failed);
|
|
35495
|
+
elements.sessionSummaryOverlayBody.replaceChildren();
|
|
35496
|
+
if (state?.summaryMarkdown) renderMarkdown(elements.sessionSummaryOverlayBody, state.summaryMarkdown);
|
|
35497
|
+
else elements.sessionSummaryOverlayBody.append(make("p", "muted", generating ? "Waiting for the first validated Markdown result…" : "Generate a summary to populate this view."));
|
|
35498
|
+
elements.sessionSummaryOverlayCopyButton.disabled = !state?.summaryMarkdown;
|
|
35499
|
+
elements.sessionSummaryOverlayRefreshButton.disabled = generating;
|
|
35500
|
+
elements.sessionSummaryOverlayRefreshButton.textContent = generating ? "Generating…" : "Refresh";
|
|
35501
|
+
}
|
|
35502
|
+
|
|
35503
|
+
function openSessionSummaryOverlay(tabId, { loading = false } = {}) {
|
|
35504
|
+
if (!tabId || !elements.sessionSummaryOverlay) return;
|
|
35505
|
+
sessionSummaryOverlayFocusReturn = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
35506
|
+
sessionSummaryOverlayTabId = tabId;
|
|
35507
|
+
if (loading) {
|
|
35508
|
+
const previous = sessionSummaryStateForTab(tabId);
|
|
35509
|
+
sessionSummaryByTab.set(tabId, normalizeSessionSummaryClientState({
|
|
35510
|
+
version: SESSION_SUMMARY_PROTOCOL_VERSION,
|
|
35511
|
+
status: "generating",
|
|
35512
|
+
configured: true,
|
|
35513
|
+
enabled: previous?.enabled === true,
|
|
35514
|
+
durable: previous?.durable === true,
|
|
35515
|
+
updatedAt: new Date().toISOString(),
|
|
35516
|
+
}, previous));
|
|
35517
|
+
}
|
|
35518
|
+
elements.sessionSummaryOverlay.hidden = false;
|
|
35519
|
+
renderSessionSummaryOverlay();
|
|
35520
|
+
}
|
|
35521
|
+
|
|
35522
|
+
function updateSessionSummaryForTab(tabId, value, { resetProjection = false } = {}) {
|
|
35523
|
+
if (!tabId) return null;
|
|
35524
|
+
const normalized = normalizeSessionSummaryClientState(value, sessionSummaryByTab.get(tabId), { resetProjection });
|
|
35525
|
+
if (!normalized) return null;
|
|
35526
|
+
sessionSummaryByTab.set(tabId, normalized);
|
|
35527
|
+
if (tabId === activeTabId) renderSessionSummaryControls();
|
|
35528
|
+
if (sessionSummaryOverlayTabId === tabId) renderSessionSummaryOverlay();
|
|
35529
|
+
return normalized;
|
|
35530
|
+
}
|
|
35531
|
+
|
|
35532
|
+
async function requestSessionSummaryGeneration(tabId, { refresh = false } = {}) {
|
|
35533
|
+
const previous = sessionSummaryStateForTab(tabId);
|
|
35534
|
+
updateSessionSummaryForTab(tabId, {
|
|
35535
|
+
version: SESSION_SUMMARY_PROTOCOL_VERSION,
|
|
35536
|
+
status: "generating",
|
|
35537
|
+
configured: true,
|
|
35538
|
+
enabled: previous?.enabled === true,
|
|
35539
|
+
durable: previous?.durable === true,
|
|
35540
|
+
updatedAt: new Date().toISOString(),
|
|
35541
|
+
});
|
|
35542
|
+
try {
|
|
35543
|
+
const signal = globalThis.AbortSignal?.timeout?.(SESSION_SUMMARY_REQUEST_TIMEOUT_MS);
|
|
35544
|
+
const response = await api("/api/session-summary/generate", { method: "POST", body: { refresh }, tabId, signal });
|
|
35545
|
+
if (response.data?.summary) updateSessionSummaryForTab(tabId, response.data.summary);
|
|
35546
|
+
if (response.data?.tab) applyTabMetadata(response.data.tab);
|
|
35547
|
+
return response;
|
|
35548
|
+
} catch (error) {
|
|
35549
|
+
updateSessionSummaryForTab(tabId, {
|
|
35550
|
+
version: SESSION_SUMMARY_PROTOCOL_VERSION,
|
|
35551
|
+
status: "failure",
|
|
35552
|
+
configured: true,
|
|
35553
|
+
enabled: previous?.enabled === true,
|
|
35554
|
+
durable: previous?.durable === true,
|
|
35555
|
+
message: error.message || String(error),
|
|
35556
|
+
updatedAt: new Date().toISOString(),
|
|
35557
|
+
});
|
|
35558
|
+
throw error;
|
|
35559
|
+
}
|
|
35560
|
+
}
|
|
35561
|
+
|
|
35562
|
+
async function openSessionSummaryForTab(tabId = activeTabId, { refresh = false } = {}) {
|
|
35563
|
+
if (!tabId || !hasAvailableCommand("summary", { tabId })) return;
|
|
35564
|
+
let state = sessionSummaryStateForTab(tabId);
|
|
35565
|
+
if (!state?.configured) {
|
|
35566
|
+
const response = await api("/api/session-summary/preferences", { tabId });
|
|
35567
|
+
state = updateSessionSummaryForTab(tabId, response.data?.summary || {
|
|
35568
|
+
version: SESSION_SUMMARY_PROTOCOL_VERSION,
|
|
35569
|
+
status: "idle",
|
|
35570
|
+
configured: response.data?.preferences?.configured === true,
|
|
35571
|
+
enabled: response.data?.preferences?.enabled === true,
|
|
35572
|
+
durable: false,
|
|
35573
|
+
updatedAt: new Date().toISOString(),
|
|
35574
|
+
});
|
|
35575
|
+
if (!response.data?.preferences?.configured) {
|
|
35576
|
+
await openNativeSessionSummarySetupDialog({ initialData: response.data });
|
|
35577
|
+
return;
|
|
35578
|
+
}
|
|
35579
|
+
}
|
|
35580
|
+
openSessionSummaryOverlay(tabId, { loading: refresh || !state?.summaryMarkdown });
|
|
35581
|
+
if (refresh || !state?.summaryMarkdown) await requestSessionSummaryGeneration(tabId, { refresh }).catch(() => {});
|
|
35582
|
+
}
|
|
35583
|
+
|
|
35584
|
+
function handleSessionSummaryEvent(event) {
|
|
35585
|
+
updateSessionSummaryForTab(event?.tabId, event?.summary, { resetProjection: event?.kind === "state" });
|
|
35586
|
+
}
|
|
35587
|
+
|
|
34587
35588
|
function slashCommandName(message) {
|
|
34588
35589
|
const match = String(message || "").trim().match(/^\/([^\s]+)$/);
|
|
34589
35590
|
return match ? match[1].toLowerCase() : "";
|
|
@@ -34848,6 +35849,19 @@ function nativeSettingToggle(label, checked, hint, badge) {
|
|
|
34848
35849
|
return { field, input };
|
|
34849
35850
|
}
|
|
34850
35851
|
|
|
35852
|
+
function nativeSettingTextarea(label, value, hint, { maxLength = SESSION_SUMMARY_PROMPT_MAX_CHARS, rows = 6, badge } = {}) {
|
|
35853
|
+
const field = make("label", "native-settings-field native-settings-textarea-field");
|
|
35854
|
+
field.append(nativeSettingsLabelRow(label, badge));
|
|
35855
|
+
const textarea = make("textarea", "dialog-editor native-settings-textarea");
|
|
35856
|
+
textarea.value = String(value || "");
|
|
35857
|
+
textarea.maxLength = maxLength;
|
|
35858
|
+
textarea.rows = rows;
|
|
35859
|
+
textarea.spellcheck = true;
|
|
35860
|
+
field.append(textarea);
|
|
35861
|
+
if (hint) field.append(make("span", "native-settings-hint", hint));
|
|
35862
|
+
return { field, textarea };
|
|
35863
|
+
}
|
|
35864
|
+
|
|
34851
35865
|
function nativeSettingsSection(title, description, controls, { open = true, badge } = {}) {
|
|
34852
35866
|
const section = make("details", "native-settings-section");
|
|
34853
35867
|
section.open = !!open;
|
|
@@ -35362,6 +36376,149 @@ function gitWorkflowSetupModelKey(model) {
|
|
|
35362
36376
|
return model?.provider && model?.id ? `${model.provider}/${model.id}` : "";
|
|
35363
36377
|
}
|
|
35364
36378
|
|
|
36379
|
+
async function openNativeSessionSummarySetupDialog({ initialData = null, onSaved } = {}) {
|
|
36380
|
+
nativeCommandTabId = activeTabId;
|
|
36381
|
+
openNativeCommandDialog({
|
|
36382
|
+
title: "/summary-setup",
|
|
36383
|
+
message: "Configure persistent background titles and Markdown summaries. Saving confirms the disclosure below, then immediately generates and opens the first summary.",
|
|
36384
|
+
});
|
|
36385
|
+
renderNativeLoading("Loading session summary preferences and available models…");
|
|
36386
|
+
|
|
36387
|
+
let data = initialData;
|
|
36388
|
+
if (!data) {
|
|
36389
|
+
try {
|
|
36390
|
+
const response = await nativeCommandApi("/api/session-summary/preferences");
|
|
36391
|
+
data = response.data || {};
|
|
36392
|
+
} catch (error) {
|
|
36393
|
+
setNativeCommandError(error.message || String(error));
|
|
36394
|
+
elements.nativeCommandBody.replaceChildren();
|
|
36395
|
+
return;
|
|
36396
|
+
}
|
|
36397
|
+
}
|
|
36398
|
+
|
|
36399
|
+
const preferences = data.preferences || {};
|
|
36400
|
+
const models = Array.isArray(data.models) ? data.models : [];
|
|
36401
|
+
if (!models.length) {
|
|
36402
|
+
setNativeCommandError("No authenticated Pi models are available. Run /login or configure a provider first.");
|
|
36403
|
+
elements.nativeCommandBody.replaceChildren();
|
|
36404
|
+
return;
|
|
36405
|
+
}
|
|
36406
|
+
const configuredKey = `${preferences.model?.provider || ""}/${preferences.model?.modelId || ""}`;
|
|
36407
|
+
const defaultKey = "openai-codex/gpt-5.6-luna";
|
|
36408
|
+
const modelKeys = new Set(models.map(gitWorkflowSetupModelKey));
|
|
36409
|
+
const initialModelKey = modelKeys.has(configuredKey) ? configuredKey : modelKeys.has(defaultKey) ? defaultKey : gitWorkflowSetupModelKey(models[0]);
|
|
36410
|
+
const modelOptions = models.map((model) => ({
|
|
36411
|
+
value: gitWorkflowSetupModelKey(model),
|
|
36412
|
+
label: `${gitWorkflowSetupModelKey(model)}${model.name && model.name !== model.id ? ` · ${model.name}` : ""}`,
|
|
36413
|
+
}));
|
|
36414
|
+
const controls = {
|
|
36415
|
+
model: nativeSettingSelect("Summary model", initialModelKey, modelOptions, "Dedicated authenticated provider/model. No fallback is used.", { label: "required", tone: "safety" }),
|
|
36416
|
+
thinking: nativeSettingSelect("Reasoning effort", preferences.model?.thinkingLevel || "low", SETTINGS_THINKING_OPTIONS, "Only levels supported by the selected model are offered.", { label: "required", tone: "safety" }),
|
|
36417
|
+
automatic: nativeSettingToggle("Generate automatically", preferences.enabled === true, "After eligible settled turns; automatic updates remain silent.", { label: "cost", tone: "safety" }),
|
|
36418
|
+
titleEnabled: nativeSettingToggle("Update generated titles", preferences.title?.enabled !== false, "Only default/automatic tab titles are eligible. Explicit names always win.", { label: "safe", tone: "safety" }),
|
|
36419
|
+
cadence: nativeSettingSelect("Title update cadence", preferences.title?.minSettledTurns || 3, [1, 2, 3, 5, 10, 20].map((value) => ({ value: String(value), label: `${value} settled user turn${value === 1 ? "" : "s"}` })), "Minimum turns between changed generated titles after the first title.", { label: "saved", tone: "browser" }),
|
|
36420
|
+
injectLatest: nativeSettingToggle("Inject latest summary into main-agent context", preferences.context?.injectLatest === true, "Off by default. When enabled, exactly one latest active-branch summary is injected as reference-only data.", { label: "privacy", tone: "safety" }),
|
|
36421
|
+
titlePrompt: nativeSettingTextarea("Editable title prompt", preferences.prompts?.title, "Maximum 8 KiB. This text is untrusted data, not system authority.", { rows: 4, badge: { label: "prompt", tone: "browser" } }),
|
|
36422
|
+
summaryPrompt: nativeSettingTextarea("Editable Markdown summary prompt", preferences.prompts?.summary, "Maximum 8 KiB. Generated Markdown is validated and capped at 16 KiB.", { rows: 7, badge: { label: "prompt", tone: "browser" } }),
|
|
36423
|
+
};
|
|
36424
|
+
const thinkingLevelsForModel = (modelKey) => {
|
|
36425
|
+
const levels = data.modelThinkingLevels?.[modelKey];
|
|
36426
|
+
return Array.isArray(levels) && levels.length ? levels : ["off"];
|
|
36427
|
+
};
|
|
36428
|
+
const syncThinkingLevels = () => {
|
|
36429
|
+
const current = controls.thinking.select.value || preferences.model?.thinkingLevel || "low";
|
|
36430
|
+
replaceNativeSettingSelectOptions(controls.thinking.select, thinkingLevelsForModel(controls.model.select.value), current);
|
|
36431
|
+
};
|
|
36432
|
+
controls.model.select.addEventListener("change", syncThinkingLevels);
|
|
36433
|
+
syncThinkingLevels();
|
|
36434
|
+
|
|
36435
|
+
const disclosure = data.disclosure || {};
|
|
36436
|
+
const body = make("div", "native-settings-panel session-summary-setup-panel");
|
|
36437
|
+
body.append(
|
|
36438
|
+
nativeSettingsNote("Privacy scope", disclosure.scope || "Active-branch user text, final assistant text, and tool names only. Thinking, images, tool arguments/results, credentials, and prior summaries are excluded."),
|
|
36439
|
+
nativeSettingsNote("Cost and provider behavior", disclosure.cost || "One configured-model request per eligible refresh; no provider fallback or automatic retry."),
|
|
36440
|
+
nativeSettingsNote("Persistence and context", disclosure.persistence || "Preferences and generated output are local. Main-agent context injection is off unless enabled."),
|
|
36441
|
+
nativeSettingsSection("Generation profile", "Choose the dedicated model, effort, and automatic-generation policy.", [controls.model, controls.thinking, controls.automatic], { open: true }),
|
|
36442
|
+
nativeSettingsSection("Titles", "Generated names never replace explicit session or browser names.", [controls.titleEnabled, controls.cadence], { open: true }),
|
|
36443
|
+
nativeSettingsSection("Prompts", "Editable instructions are bounded and treated as untrusted data.", [controls.titlePrompt, controls.summaryPrompt], { open: true }),
|
|
36444
|
+
nativeSettingsSection("Privacy and context", "The transcript scope is fixed to text and tool names; injection is separately opt-in.", [controls.injectLatest], { open: true }),
|
|
36445
|
+
);
|
|
36446
|
+
elements.nativeCommandBody.replaceChildren(body);
|
|
36447
|
+
elements.nativeCommandActions.replaceChildren();
|
|
36448
|
+
addNativeCommandAction("Cancel", closeNativeCommandDialog);
|
|
36449
|
+
|
|
36450
|
+
const signature = () => JSON.stringify({
|
|
36451
|
+
model: controls.model.select.value,
|
|
36452
|
+
thinking: controls.thinking.select.value,
|
|
36453
|
+
automatic: controls.automatic.input.checked,
|
|
36454
|
+
titleEnabled: controls.titleEnabled.input.checked,
|
|
36455
|
+
cadence: controls.cadence.select.value,
|
|
36456
|
+
injectLatest: controls.injectLatest.input.checked,
|
|
36457
|
+
titlePrompt: controls.titlePrompt.textarea.value,
|
|
36458
|
+
summaryPrompt: controls.summaryPrompt.textarea.value,
|
|
36459
|
+
});
|
|
36460
|
+
const initialSignature = signature();
|
|
36461
|
+
const updateDirty = () => { nativeSettingsDirty = signature() !== initialSignature; };
|
|
36462
|
+
for (const control of [controls.model.select, controls.thinking.select, controls.automatic.input, controls.titleEnabled.input, controls.cadence.select, controls.injectLatest.input, controls.titlePrompt.textarea, controls.summaryPrompt.textarea]) {
|
|
36463
|
+
control.addEventListener("input", updateDirty);
|
|
36464
|
+
control.addEventListener("change", updateDirty);
|
|
36465
|
+
}
|
|
36466
|
+
|
|
36467
|
+
const save = addNativeCommandAction("Save and generate", async () => {
|
|
36468
|
+
setNativeActionBusy(save, true, "Saving…");
|
|
36469
|
+
setNativeCommandError("");
|
|
36470
|
+
try {
|
|
36471
|
+
const selectedModel = models.find((model) => gitWorkflowSetupModelKey(model) === controls.model.select.value);
|
|
36472
|
+
if (!selectedModel) throw new Error("Select an available session summary model.");
|
|
36473
|
+
const titlePrompt = controls.titlePrompt.textarea.value.trim();
|
|
36474
|
+
const summaryPrompt = controls.summaryPrompt.textarea.value.trim();
|
|
36475
|
+
if (!titlePrompt || !summaryPrompt) throw new Error("Both editable prompts are required.");
|
|
36476
|
+
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.");
|
|
36477
|
+
const reviewed = await appConfirm({
|
|
36478
|
+
title: "Save session summary setup?",
|
|
36479
|
+
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."}`,
|
|
36480
|
+
affected: "Global session-summary preferences and the active tab's first generated summary",
|
|
36481
|
+
undoable: false,
|
|
36482
|
+
confirmLabel: "Save and generate",
|
|
36483
|
+
danger: false,
|
|
36484
|
+
});
|
|
36485
|
+
if (!reviewed) return;
|
|
36486
|
+
const response = await nativeCommandApi("/api/session-summary/preferences", {
|
|
36487
|
+
method: "PUT",
|
|
36488
|
+
body: {
|
|
36489
|
+
confirmed: true,
|
|
36490
|
+
preferences: {
|
|
36491
|
+
enabled: controls.automatic.input.checked,
|
|
36492
|
+
model: { provider: selectedModel.provider, modelId: selectedModel.id, thinkingLevel: controls.thinking.select.value },
|
|
36493
|
+
prompts: { title: titlePrompt, summary: summaryPrompt },
|
|
36494
|
+
input: { scope: "text-and-tool-names" },
|
|
36495
|
+
context: { injectLatest: controls.injectLatest.input.checked },
|
|
36496
|
+
title: { enabled: controls.titleEnabled.input.checked, minSettledTurns: Number(controls.cadence.select.value) },
|
|
36497
|
+
},
|
|
36498
|
+
},
|
|
36499
|
+
});
|
|
36500
|
+
const targetTabId = nativeCommandTabId || activeTabId;
|
|
36501
|
+
updateSessionSummaryForTab(targetTabId, response.data?.summary || {
|
|
36502
|
+
version: SESSION_SUMMARY_PROTOCOL_VERSION,
|
|
36503
|
+
status: "idle",
|
|
36504
|
+
configured: true,
|
|
36505
|
+
enabled: controls.automatic.input.checked,
|
|
36506
|
+
durable: false,
|
|
36507
|
+
updatedAt: new Date().toISOString(),
|
|
36508
|
+
});
|
|
36509
|
+
nativeSettingsDirty = false;
|
|
36510
|
+
closeNativeCommandDialog({ force: true });
|
|
36511
|
+
openSessionSummaryOverlay(targetTabId, { loading: true });
|
|
36512
|
+
await requestSessionSummaryGeneration(targetTabId, { refresh: true }).catch(() => {});
|
|
36513
|
+
if (typeof onSaved === "function") await onSaved(response.data?.preferences);
|
|
36514
|
+
} catch (error) {
|
|
36515
|
+
setNativeCommandError(error.message || String(error));
|
|
36516
|
+
} finally {
|
|
36517
|
+
setNativeActionBusy(save, false);
|
|
36518
|
+
}
|
|
36519
|
+
}, "primary");
|
|
36520
|
+
}
|
|
36521
|
+
|
|
35365
36522
|
async function openNativeGitWorkflowSetupDialog({ onSaved } = {}) {
|
|
35366
36523
|
openNativeCommandDialog({
|
|
35367
36524
|
title: "/git-workflow-setup",
|
|
@@ -36375,10 +37532,11 @@ async function openNativeAuthSelector(mode) {
|
|
|
36375
37532
|
}
|
|
36376
37533
|
|
|
36377
37534
|
async function handleNativeSlashSelectorCommand(message, { usesPromptInput = false } = {}) {
|
|
36378
|
-
const
|
|
37535
|
+
const summaryMatch = String(message || "").trim().match(/^\/summary(?:\s+(refresh))?$/i);
|
|
37536
|
+
const name = summaryMatch ? "summary" : slashCommandName(message);
|
|
36379
37537
|
if (!NATIVE_SELECTOR_COMMANDS.has(name)) return false;
|
|
36380
37538
|
const featureId = optionalFeatureIdForCommand(name);
|
|
36381
|
-
if (name === "workflow-setup" && !hasLoadedRpcCommand(name)) {
|
|
37539
|
+
if ((name === "workflow-setup" || name === "summary" || name === "summary-setup") && !hasLoadedRpcCommand(name)) {
|
|
36382
37540
|
const tabContext = activeTabContext();
|
|
36383
37541
|
addEvent(commandUnavailableMessage(name), "warn");
|
|
36384
37542
|
refreshCommands(tabContext).catch((error) => {
|
|
@@ -36407,6 +37565,12 @@ async function handleNativeSlashSelectorCommand(message, { usesPromptInput = fal
|
|
|
36407
37565
|
case "settings":
|
|
36408
37566
|
await openNativeSettingsDialog();
|
|
36409
37567
|
return true;
|
|
37568
|
+
case "summary":
|
|
37569
|
+
await openSessionSummaryForTab(activeTabId, { refresh: summaryMatch?.[1]?.toLowerCase() === "refresh" });
|
|
37570
|
+
return true;
|
|
37571
|
+
case "summary-setup":
|
|
37572
|
+
await openNativeSessionSummarySetupDialog();
|
|
37573
|
+
return true;
|
|
36410
37574
|
case "workflow-setup":
|
|
36411
37575
|
await openNativeWorkflowSetupDialog();
|
|
36412
37576
|
return true;
|
|
@@ -38330,6 +39494,7 @@ async function refreshCommands(tabContext = activeTabContext()) {
|
|
|
38330
39494
|
rawAvailableCommands = catalog.raw;
|
|
38331
39495
|
availableCommands = catalog.available;
|
|
38332
39496
|
updateOptionalFeatureAvailability();
|
|
39497
|
+
renderSessionSummaryControls();
|
|
38333
39498
|
renderCommands();
|
|
38334
39499
|
if (elements.commandPaletteDialog?.open) renderCommandPalette({ preserveScroll: true });
|
|
38335
39500
|
}
|
|
@@ -39756,6 +40921,26 @@ function handleInactiveTabEvent(event) {
|
|
|
39756
40921
|
}
|
|
39757
40922
|
|
|
39758
40923
|
function handleEvent(event) {
|
|
40924
|
+
if (event?.type === "webui_session_summary") {
|
|
40925
|
+
handleSessionSummaryEvent(event);
|
|
40926
|
+
return;
|
|
40927
|
+
}
|
|
40928
|
+
if (event?.type === "webui_optional_feature_migration") {
|
|
40929
|
+
applyOptionalFeatureMigrationSnapshot(event.snapshot);
|
|
40930
|
+
return;
|
|
40931
|
+
}
|
|
40932
|
+
if (["webui_optional_feature_restart_completed", "webui_optional_feature_restart_deferred"].includes(event?.type)) {
|
|
40933
|
+
optionalFeatureRestartNotice = {
|
|
40934
|
+
tabId: event.tabId || activeTabId,
|
|
40935
|
+
tabTitle: event.tabTitle || "terminal",
|
|
40936
|
+
autoRestarted: event.autoRestarted === true,
|
|
40937
|
+
restartDeferred: event.restartDeferred === true,
|
|
40938
|
+
reason: event.reason || "",
|
|
40939
|
+
};
|
|
40940
|
+
addEvent(event.autoRestarted ? "restarted tab to load new optional features" : "optional feature restart deferred because the tab is busy", event.restartDeferred ? "warn" : "info");
|
|
40941
|
+
renderOptionalFeatureMigrationSurface();
|
|
40942
|
+
return;
|
|
40943
|
+
}
|
|
39759
40944
|
if (eventHasTabActivityPayload(event)) ingestEventTabActivity(event);
|
|
39760
40945
|
if (event?.type === "auto_retry_start" || event?.type === "auto_retry_end") trackAutoRetryStateFromEvent(event);
|
|
39761
40946
|
if (eventMayAffectSkillUsage(event)) trackSkillsFromEvent(event);
|
|
@@ -40149,6 +41334,10 @@ function connectEvents(tabContext = activeTabContext(), { requestedMode = "auto"
|
|
|
40149
41334
|
});
|
|
40150
41335
|
const source = new EventSource(`/api/events?${parameters.toString()}`);
|
|
40151
41336
|
eventSource = source;
|
|
41337
|
+
source.onopen = () => {
|
|
41338
|
+
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
41339
|
+
refreshOptionalFeaturePackageStatuses().catch(() => {});
|
|
41340
|
+
};
|
|
40152
41341
|
source.onmessage = (message) => {
|
|
40153
41342
|
if (eventSource !== source || !isCurrentTabContext(tabContext)) return;
|
|
40154
41343
|
try {
|
|
@@ -40339,6 +41528,14 @@ elements.newTabChooseDirectoryButton?.addEventListener("click", () => createTerm
|
|
|
40339
41528
|
elements.newTabWorktreeButton?.addEventListener("click", () => openBranchWorktreePicker());
|
|
40340
41529
|
elements.splitTabButton?.addEventListener("click", () => splitActiveTerminalTab());
|
|
40341
41530
|
elements.workspaceSaveButton?.addEventListener("click", () => saveWebuiWorkspace());
|
|
41531
|
+
const openActiveSessionSummary = () => {
|
|
41532
|
+
void openSessionSummaryForTab().catch((error) => addEvent(error.message || String(error), "error"));
|
|
41533
|
+
};
|
|
41534
|
+
elements.summaryHeaderButton?.addEventListener("click", openActiveSessionSummary);
|
|
41535
|
+
elements.summaryActionButton?.addEventListener("click", () => {
|
|
41536
|
+
setComposerActionsOpen(false);
|
|
41537
|
+
openActiveSessionSummary();
|
|
41538
|
+
});
|
|
40342
41539
|
elements.terminalSplitCloseButton?.addEventListener("click", () => closeTerminalSplitView());
|
|
40343
41540
|
elements.closeAllTabsButton.addEventListener("click", () => closeAllTerminalTabs());
|
|
40344
41541
|
elements.commandPaletteButton?.addEventListener("click", () => openCommandPalette());
|
|
@@ -40500,6 +41697,7 @@ elements.optionsRemoteButton.addEventListener("click", () => runNativeCommandMen
|
|
|
40500
41697
|
elements.optionsNameButton.addEventListener("click", () => runNativeCommandMenu("/name"));
|
|
40501
41698
|
elements.optionsCloneButton.addEventListener("click", () => runNativeCommandMenu("/clone"));
|
|
40502
41699
|
elements.optionsSettingsButton.addEventListener("click", () => runNativeCommandMenu("/settings"));
|
|
41700
|
+
elements.optionsSummarySetupButton?.addEventListener("click", () => runNativeCommandMenu("/summary-setup"));
|
|
40503
41701
|
elements.optionsWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/workflow-setup"));
|
|
40504
41702
|
elements.optionsSafetyGuardSetupButton?.addEventListener("click", () => runNativeCommandMenu("/safety-guard-setup"));
|
|
40505
41703
|
elements.optionsGitWorkflowSetupButton?.addEventListener("click", () => runNativeCommandMenu("/git-workflow-setup"));
|
|
@@ -40508,6 +41706,28 @@ elements.optionsForkButton.addEventListener("click", () => runNativeCommandMenu(
|
|
|
40508
41706
|
elements.optionsTreeButton.addEventListener("click", () => runNativeCommandMenu("/tree"));
|
|
40509
41707
|
elements.optionsStatsButton?.addEventListener("click", () => openStatsOverlay({ refresh: true }));
|
|
40510
41708
|
elements.optionsFooterVisibilityButton?.addEventListener("click", openGitFooterVisibilityDialog);
|
|
41709
|
+
elements.sessionSummaryOverlayCloseButton?.addEventListener("click", () => closeSessionSummaryOverlay());
|
|
41710
|
+
elements.sessionSummaryOverlayCopyButton?.addEventListener("click", async () => {
|
|
41711
|
+
const state = sessionSummaryStateForTab(sessionSummaryOverlayTabId);
|
|
41712
|
+
if (!state?.summaryMarkdown) return;
|
|
41713
|
+
try {
|
|
41714
|
+
await copyText(state.summaryMarkdown);
|
|
41715
|
+
elements.sessionSummaryOverlayStatus.textContent = "Markdown copied to the clipboard.";
|
|
41716
|
+
} catch (error) {
|
|
41717
|
+
elements.sessionSummaryOverlayStatus.textContent = `Copy failed: ${error.message || String(error)}`;
|
|
41718
|
+
elements.sessionSummaryOverlayStatus.classList.add("error");
|
|
41719
|
+
}
|
|
41720
|
+
});
|
|
41721
|
+
elements.sessionSummaryOverlayRefreshButton?.addEventListener("click", () => {
|
|
41722
|
+
const tabId = sessionSummaryOverlayTabId;
|
|
41723
|
+
if (tabId) void requestSessionSummaryGeneration(tabId, { refresh: true }).catch(() => {});
|
|
41724
|
+
});
|
|
41725
|
+
document.addEventListener("keydown", (event) => {
|
|
41726
|
+
if (event.key !== "Escape" || elements.sessionSummaryOverlay?.hidden || document.querySelector("dialog[open]")) return;
|
|
41727
|
+
event.preventDefault();
|
|
41728
|
+
event.stopImmediatePropagation();
|
|
41729
|
+
closeSessionSummaryOverlay();
|
|
41730
|
+
}, true);
|
|
40511
41731
|
elements.gitFooterVisibilitySelectAllButton?.addEventListener("click", () => setGitFooterVisibilitySelection(true));
|
|
40512
41732
|
elements.gitFooterVisibilitySelectNoneButton?.addEventListener("click", () => setGitFooterVisibilitySelection(false));
|
|
40513
41733
|
elements.gitFooterVisibilityCloseButton?.addEventListener("click", closeGitFooterVisibilityDialog);
|
|
@@ -41836,6 +43056,14 @@ elements.promptInput.addEventListener("blur", () => {
|
|
|
41836
43056
|
}, 120);
|
|
41837
43057
|
});
|
|
41838
43058
|
|
|
43059
|
+
elements.optionalFeatureMigrationCancelButton?.addEventListener("click", () => elements.optionalFeatureMigrationDialog?.close());
|
|
43060
|
+
elements.optionalFeatureMigrationLaterButton?.addEventListener("click", () => dismissOptionalFeatureMigration({ closeDialog: true }));
|
|
43061
|
+
elements.optionalFeatureMigrationConfirmButton?.addEventListener("click", migrateSelectedOptionalFeatures);
|
|
43062
|
+
elements.optionalFeatureMigrationDialog?.addEventListener("cancel", (event) => {
|
|
43063
|
+
event.preventDefault();
|
|
43064
|
+
elements.optionalFeatureMigrationDialog.close();
|
|
43065
|
+
});
|
|
43066
|
+
|
|
41839
43067
|
installModalPrimitives();
|
|
41840
43068
|
initializeIssueWizard();
|
|
41841
43069
|
resizePromptInput();
|
|
@@ -41848,6 +43076,7 @@ restoreBusyPromptBehaviorSetting();
|
|
|
41848
43076
|
updateComposerModeButtons();
|
|
41849
43077
|
installSessionSkillTagResizeHandling();
|
|
41850
43078
|
updateOptionalFeatureAvailability();
|
|
43079
|
+
renderOptionalFeatureMigrationSurface();
|
|
41851
43080
|
refreshOptionalFeaturePackageStatuses({ announce: true });
|
|
41852
43081
|
renderAppRunnerControls();
|
|
41853
43082
|
renderLoadedPromptListPreview();
|