@firstpick/pi-package-webui 0.9.9 → 0.10.0
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/DEVELOPMENT.md +42 -13
- package/README.md +7 -7
- package/TECHNICAL.md +8 -8
- package/bin/pi-webui.mjs +197 -63
- package/index.ts +23 -33
- package/lib/git-workflow-preferences.mjs +51 -12
- package/lib/tui-model-profile-selector.mjs +183 -0
- package/lib/tui-resource-selector.mjs +173 -0
- package/package.json +1 -1
- package/public/app.js +220 -73
- package/public/index.html +2 -2
- package/public/service-worker.js +1 -1
- package/public/styles.css +63 -15
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/intercom-conversation-viewer.spec.mjs +76 -53
- package/tests/browser/user-noticeable-fixes.spec.mjs +51 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +3 -3
- package/tests/durable-rpc-supervisor-harness.test.mjs +9 -0
- package/tests/events-tree-context-menu-static.test.mjs +3 -3
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/file-viewer-image-static.test.mjs +3 -3
- package/tests/fixtures/fake-pi.mjs +3 -3
- package/tests/guided-git-activation-static.test.mjs +24 -12
- package/tests/guided-git-fallback-runtime.test.mjs +209 -270
- package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
- package/tests/guided-git-message-reliability-static.test.mjs +2 -1
- package/tests/guided-git-optional-feature.test.mjs +8 -5
- package/tests/http-endpoints-harness.test.mjs +22 -4
- package/tests/intercom-conversation-viewer-static.test.mjs +7 -6
- package/tests/intercom-tag-layout-static.test.mjs +35 -16
- package/tests/intercom-tag-overflow-layout.test.mjs +87 -0
- package/tests/main-output-loading-static.test.mjs +3 -3
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +11 -6
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +18 -3
- package/tests/resource-tui-extension.test.mjs +2 -1
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/tui-model-profile-selector.test.mjs +102 -0
- package/tests/tui-resource-selector.test.mjs +74 -0
- package/tests/webui-settings-locking.test.mjs +32 -1
- package/tests/windows-drive-cwd-picker-static.test.mjs +3 -3
package/bin/pi-webui.mjs
CHANGED
|
@@ -456,6 +456,7 @@ let optionalFeatureStartupReady = false;
|
|
|
456
456
|
const UPDATE_PACKAGE_NAMES = [...CORE_UPDATE_PACKAGE_NAMES].sort();
|
|
457
457
|
const NATURAL_CONVERSATION_STATUS_KEY = "natural-conversation";
|
|
458
458
|
const NATURAL_CONVERSATION_COMMAND_NAMES = ["talk", "voice", "conversation"];
|
|
459
|
+
const REPLAYABLE_CLEARED_EXTENSION_STATUS_KEYS = new Set(["feature-decision-output", "feature-category"]);
|
|
459
460
|
const GUIDED_GIT_START_STATUS_KEY = "git-guided-workflow:webui-start";
|
|
460
461
|
const GUIDED_GIT_START_PAYLOAD_TYPE = "firstpick.pi-extension-git-guided-workflow.start";
|
|
461
462
|
const GUIDED_GIT_START_PAYLOAD_VERSION = 1;
|
|
@@ -2878,9 +2879,19 @@ function gitWorkflowPreferenceOptions() {
|
|
|
2878
2879
|
};
|
|
2879
2880
|
}
|
|
2880
2881
|
|
|
2881
|
-
async function gitWorkflowPreferencesData(tab) {
|
|
2882
|
+
async function gitWorkflowPreferencesData(tab, { includeModels = true } = {}) {
|
|
2883
|
+
const preferencesPromise = readGitWorkflowPreferences();
|
|
2884
|
+
if (!includeModels) {
|
|
2885
|
+
const preferences = await preferencesPromise;
|
|
2886
|
+
return {
|
|
2887
|
+
preferences,
|
|
2888
|
+
configured: isGitWorkflowSetupComplete(preferences),
|
|
2889
|
+
options: gitWorkflowPreferenceOptions(),
|
|
2890
|
+
path: webuiSettingsFile(),
|
|
2891
|
+
};
|
|
2892
|
+
}
|
|
2882
2893
|
const [preferences, models] = await Promise.all([
|
|
2883
|
-
|
|
2894
|
+
preferencesPromise,
|
|
2884
2895
|
availableGitWorkflowModels(tab),
|
|
2885
2896
|
]);
|
|
2886
2897
|
return {
|
|
@@ -3113,24 +3124,58 @@ async function triggerSessionSummary(tab, { refresh = false } = {}) {
|
|
|
3113
3124
|
}
|
|
3114
3125
|
}
|
|
3115
3126
|
|
|
3116
|
-
function gitWorkflowGenerationPrompt(kind, preferences) {
|
|
3127
|
+
function gitWorkflowGenerationPrompt(kind, preferences, commandName) {
|
|
3117
3128
|
switch (kind) {
|
|
3118
3129
|
case "commit":
|
|
3119
|
-
return
|
|
3130
|
+
return `/${commandName} ${preferences.commit.language} ${preferences.commit.scope}`;
|
|
3120
3131
|
case "branch":
|
|
3121
|
-
return
|
|
3132
|
+
return `/${commandName}`;
|
|
3122
3133
|
case "pr":
|
|
3123
|
-
return
|
|
3134
|
+
return `/${commandName} ${preferences.commit.language}`;
|
|
3124
3135
|
default:
|
|
3125
3136
|
throw makeHttpError(400, "generation kind must be commit, branch, or pr");
|
|
3126
3137
|
}
|
|
3127
3138
|
}
|
|
3128
3139
|
|
|
3140
|
+
function guidedGitNativeCommandBase(kind) {
|
|
3141
|
+
if (kind === "commit") return "git-staged-msg";
|
|
3142
|
+
if (kind === "branch") return "git-branch-name";
|
|
3143
|
+
if (kind === "pr") return "pr";
|
|
3144
|
+
throw makeHttpError(400, "generation kind must be commit, branch, or pr");
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
async function resolveGuidedGitNativeCommand(tab, kind) {
|
|
3148
|
+
const baseName = guidedGitNativeCommandBase(kind);
|
|
3149
|
+
const response = await safeRpcData(tab, { type: "get_commands" }, STATUS_RPC_TIMEOUT_MS);
|
|
3150
|
+
const commands = Array.isArray(response.data?.commands) ? response.data.commands : [];
|
|
3151
|
+
const command = commands.find((candidate) => candidate?.source === "extension" && candidate?.name === baseName)
|
|
3152
|
+
|| commands.find((candidate) => candidate?.source === "extension" && String(candidate?.name || "").replace(/:\d+$/, "") === baseName);
|
|
3153
|
+
if (!response.ok || !command) {
|
|
3154
|
+
throw makeHttpError(409, `Guided Git requires the /${baseName} extension command in this Pi tab. Same-named prompt templates are not used.`);
|
|
3155
|
+
}
|
|
3156
|
+
return String(command.name);
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
const GUIDED_GIT_PROVIDER_FAILURE_MARKER = "FIRSTPICK_GUIDED_GIT_PROVIDER_FAILURE";
|
|
3160
|
+
const GUIDED_GIT_NATIVE_COMMAND_ERROR_GRACE_MS = 500;
|
|
3161
|
+
|
|
3129
3162
|
function boundedGitWorkflowGenerationError(message, fallback = "Guided Git generation failed") {
|
|
3130
3163
|
const text = typeof message === "string" ? message : fallback;
|
|
3131
3164
|
return text.replace(/[\r\n]+/g, " ").trim().slice(0, 240) || fallback;
|
|
3132
3165
|
}
|
|
3133
3166
|
|
|
3167
|
+
function isGuidedGitProviderGenerationFailure(error) {
|
|
3168
|
+
return String(error?.message || error || "").includes(GUIDED_GIT_PROVIDER_FAILURE_MARKER);
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
function guidedGitNativeCommandErrorFromEvent(record, event) {
|
|
3172
|
+
const commandName = String(record?.nativeCommandName || "");
|
|
3173
|
+
if (event?.type !== "extension_error" || event.event !== "command" || !commandName || event.extensionPath !== `command:${commandName}`) return null;
|
|
3174
|
+
const error = new Error(String(event.error || `/${commandName} failed`));
|
|
3175
|
+
error.guidedGitProviderGenerationFailure = isGuidedGitProviderGenerationFailure(error);
|
|
3176
|
+
return error;
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3134
3179
|
function gitWorkflowGenerationCancellationError() {
|
|
3135
3180
|
const error = makeHttpError(409, "Guided Git generation was cancelled");
|
|
3136
3181
|
error.code = "GIT_WORKFLOW_CANCELLED";
|
|
@@ -3198,23 +3243,49 @@ async function restoreGitWorkflowGenerationProfile(tab, expectedRecord = tab?.gi
|
|
|
3198
3243
|
return operation;
|
|
3199
3244
|
}
|
|
3200
3245
|
|
|
3201
|
-
async function
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3246
|
+
async function createGitWorkflowArtifactGeneration(tab, generationId, kind) {
|
|
3247
|
+
const createdAt = Date.now();
|
|
3248
|
+
if (kind === "commit") {
|
|
3249
|
+
// Keep generation dispatch compatible with tabs whose cwd has not become
|
|
3250
|
+
// a repository yet; staging boundaries still verify the real Git root.
|
|
3251
|
+
const root = await getGitRoot(tab.cwd).catch(() => path.resolve(tab.cwd));
|
|
3252
|
+
const cwd = gitWorkflowMessageCwd(root, tab.cwd);
|
|
3253
|
+
return {
|
|
3254
|
+
id: generationId,
|
|
3255
|
+
kind,
|
|
3256
|
+
root,
|
|
3257
|
+
cwd,
|
|
3258
|
+
createdAt,
|
|
3259
|
+
baseline: await readStableGitMessageArtifactPair(commitMessagePaths(cwd)),
|
|
3260
|
+
terminal: false,
|
|
3261
|
+
successful: false,
|
|
3262
|
+
};
|
|
3263
|
+
}
|
|
3264
|
+
const baseline = kind === "branch"
|
|
3265
|
+
? await readGitWorkflowBranchName(tab.cwd).catch(() => null)
|
|
3266
|
+
: await readGitWorkflowPrDescription(tab.cwd).catch(() => null);
|
|
3267
|
+
return { id: generationId, kind, cwd: path.resolve(tab.cwd), createdAt, baseline, terminal: false, successful: false };
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
async function assertGuidedGitNativeArtifactUpdated(tab, record) {
|
|
3271
|
+
const generation = record.artifactGeneration;
|
|
3272
|
+
if (!generation) throw new Error("Guided Git generation has no artifact correlation record");
|
|
3273
|
+
if (generation.kind === "commit") {
|
|
3274
|
+
const pair = await readStableGitMessageArtifactPair(commitMessagePaths(generation.cwd));
|
|
3275
|
+
const readiness = gitMessageArtifactPairReadiness(generation.baseline, pair);
|
|
3276
|
+
if (!readiness.ready) throw new Error(readiness.reason || "Native commit generation did not update both message artifacts");
|
|
3277
|
+
return;
|
|
3278
|
+
}
|
|
3279
|
+
const current = generation.kind === "branch"
|
|
3280
|
+
? await readGitWorkflowBranchName(tab.cwd)
|
|
3281
|
+
: await readGitWorkflowPrDescription(tab.cwd);
|
|
3282
|
+
if (generation.baseline
|
|
3283
|
+
&& current.path === generation.baseline.path
|
|
3284
|
+
&& current.mtimeMs === generation.baseline.mtimeMs
|
|
3285
|
+
&& current.ctimeMs === generation.baseline.ctimeMs
|
|
3286
|
+
&& current.ino === generation.baseline.ino) {
|
|
3287
|
+
throw new Error(`Native ${generation.kind} generation did not update its correlated artifact`);
|
|
3288
|
+
}
|
|
3218
3289
|
}
|
|
3219
3290
|
|
|
3220
3291
|
function emitGitWorkflowFallbackLifecycle(tab, record, phase) {
|
|
@@ -3269,6 +3340,7 @@ async function dispatchGitWorkflowGenerationAttempt(tab, record, profile, attemp
|
|
|
3269
3340
|
record.attemptRunStarted = false;
|
|
3270
3341
|
record.promptAccepted = false;
|
|
3271
3342
|
record.pendingSettlement = null;
|
|
3343
|
+
record.nativeCommandError = null;
|
|
3272
3344
|
if (record.currentModelKey !== `${profile.provider}/${profile.modelId}`) {
|
|
3273
3345
|
const modelResponse = await tab.rpc.send({ type: "set_model", provider: profile.provider, modelId: profile.modelId });
|
|
3274
3346
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
@@ -3283,14 +3355,19 @@ async function dispatchGitWorkflowGenerationAttempt(tab, record, profile, attemp
|
|
|
3283
3355
|
markTabWorking(tab);
|
|
3284
3356
|
const response = await tab.rpc.send({ type: "prompt", message: record.message });
|
|
3285
3357
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3286
|
-
if (response.success === false)
|
|
3358
|
+
if (response.success === false) {
|
|
3359
|
+
const error = new Error(response.error || "Guided Git generation prompt was rejected");
|
|
3360
|
+
error.guidedGitProviderGenerationFailure = isGuidedGitProviderGenerationFailure(response.error);
|
|
3361
|
+
throw error;
|
|
3362
|
+
}
|
|
3363
|
+
if (record.nativeCommandError) throw record.nativeCommandError;
|
|
3287
3364
|
record.promptAccepted = true;
|
|
3288
3365
|
const pendingSettlement = record.pendingSettlement;
|
|
3289
3366
|
if (pendingSettlement?.attempt === attempt) {
|
|
3290
3367
|
record.pendingSettlement = null;
|
|
3291
3368
|
void settleGitWorkflowGeneration(tab, record, pendingSettlement);
|
|
3292
3369
|
}
|
|
3293
|
-
|
|
3370
|
+
const result = {
|
|
3294
3371
|
accepted: true,
|
|
3295
3372
|
kind: record.kind,
|
|
3296
3373
|
message: record.message,
|
|
@@ -3299,11 +3376,23 @@ async function dispatchGitWorkflowGenerationAttempt(tab, record, profile, attemp
|
|
|
3299
3376
|
fallbackUsed: attempt === "fallback",
|
|
3300
3377
|
primaryGeneration: publicGitWorkflowGenerationProfile(record.primary),
|
|
3301
3378
|
};
|
|
3379
|
+
if (record.nativeGeneration) {
|
|
3380
|
+
try {
|
|
3381
|
+
await assertGuidedGitNativeArtifactUpdated(tab, record);
|
|
3382
|
+
} catch (artifactError) {
|
|
3383
|
+
if (!record.nativeCommandError) await delay(GUIDED_GIT_NATIVE_COMMAND_ERROR_GRACE_MS);
|
|
3384
|
+
if (record.nativeCommandError) throw record.nativeCommandError;
|
|
3385
|
+
throw artifactError;
|
|
3386
|
+
}
|
|
3387
|
+
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3388
|
+
await finishGitWorkflowGeneration(tab, record, { successful: true });
|
|
3389
|
+
}
|
|
3390
|
+
return result;
|
|
3302
3391
|
}
|
|
3303
3392
|
|
|
3304
3393
|
async function startGitWorkflowFallback(tab, record, primaryError) {
|
|
3305
3394
|
if (tab.gitWorkflowGeneration !== record || record.fallbackStarted || !record.fallback) return null;
|
|
3306
|
-
if (record.cancelled || !tab.rpc?.isRunning?.()) return null;
|
|
3395
|
+
if (record.cancelled || !tab.rpc?.isRunning?.() || primaryError?.guidedGitProviderGenerationFailure !== true) return null;
|
|
3307
3396
|
record.fallbackStarted = true;
|
|
3308
3397
|
record.attempt = "fallback";
|
|
3309
3398
|
record.attemptRunStarted = false;
|
|
@@ -3342,6 +3431,11 @@ async function settleGitWorkflowGeneration(tab, record, { failed, cancelled }) {
|
|
|
3342
3431
|
function consumeGitWorkflowGenerationEvent(tab, event, { finalError = false } = {}) {
|
|
3343
3432
|
const record = tab.gitWorkflowGeneration;
|
|
3344
3433
|
if (!record || record.finishing) return;
|
|
3434
|
+
const nativeCommandError = guidedGitNativeCommandErrorFromEvent(record, event);
|
|
3435
|
+
if (nativeCommandError) {
|
|
3436
|
+
record.nativeCommandError = nativeCommandError;
|
|
3437
|
+
return;
|
|
3438
|
+
}
|
|
3345
3439
|
if ((event?.type === "agent_end" || event?.type === "agent_settled") && event.aborted === true) record.cancelled = true;
|
|
3346
3440
|
if (event?.type === "agent_start") {
|
|
3347
3441
|
record.attemptRunStarted = true;
|
|
@@ -3382,6 +3476,9 @@ async function startGitWorkflowGeneration(tab, body = {}) {
|
|
|
3382
3476
|
promptAccepted: false,
|
|
3383
3477
|
pendingSettlement: null,
|
|
3384
3478
|
currentModelKey: "",
|
|
3479
|
+
nativeCommandName: "",
|
|
3480
|
+
nativeCommandError: null,
|
|
3481
|
+
nativeGeneration: true,
|
|
3385
3482
|
};
|
|
3386
3483
|
tab.gitWorkflowGeneration = record;
|
|
3387
3484
|
tab.gitWorkflowFallbackLifecycle = { generationId: record.generationId, kind, events: [] };
|
|
@@ -3394,7 +3491,10 @@ async function startGitWorkflowGeneration(tab, body = {}) {
|
|
|
3394
3491
|
const preferences = await readGitWorkflowPreferences();
|
|
3395
3492
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3396
3493
|
if (!isGitWorkflowSetupComplete(preferences)) throw makeHttpError(409, "Run /git-workflow-setup or open Guided Git Setup before generating Git text");
|
|
3397
|
-
|
|
3494
|
+
const nativeCommandName = await resolveGuidedGitNativeCommand(tab, kind);
|
|
3495
|
+
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3496
|
+
record.nativeCommandName = nativeCommandName;
|
|
3497
|
+
record.message = gitWorkflowGenerationPrompt(kind, preferences, nativeCommandName);
|
|
3398
3498
|
|
|
3399
3499
|
const state = await currentSessionState(tab);
|
|
3400
3500
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
@@ -3423,16 +3523,9 @@ async function startGitWorkflowGeneration(tab, body = {}) {
|
|
|
3423
3523
|
record.restore = { model: state.model || null, thinkingLevel: state.thinkingLevel || "off" };
|
|
3424
3524
|
record.currentModelKey = gitWorkflowModelKey(state.model);
|
|
3425
3525
|
tab.gitWorkflowGenerationRestore = record.restore;
|
|
3426
|
-
record.
|
|
3526
|
+
record.artifactGeneration = await createGitWorkflowArtifactGeneration(tab, record.generationId, kind);
|
|
3527
|
+
record.messageGeneration = kind === "commit" ? record.artifactGeneration : null;
|
|
3427
3528
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3428
|
-
record.artifactGeneration = record.messageGeneration || {
|
|
3429
|
-
id: record.generationId,
|
|
3430
|
-
kind,
|
|
3431
|
-
cwd: path.resolve(tab.cwd),
|
|
3432
|
-
createdAt: Date.now(),
|
|
3433
|
-
terminal: false,
|
|
3434
|
-
successful: false,
|
|
3435
|
-
};
|
|
3436
3529
|
tab.gitWorkflowArtifactGeneration = record.artifactGeneration;
|
|
3437
3530
|
if (record.messageGeneration) tab.gitWorkflowMessageGeneration = record.messageGeneration;
|
|
3438
3531
|
|
|
@@ -3440,7 +3533,7 @@ async function startGitWorkflowGeneration(tab, body = {}) {
|
|
|
3440
3533
|
return await dispatchGitWorkflowGenerationAttempt(tab, record, record.primary, "primary");
|
|
3441
3534
|
} catch (primaryError) {
|
|
3442
3535
|
markTabIdle(tab);
|
|
3443
|
-
if (record.fallback && !record.cancelled && tab.rpc?.isRunning?.()) {
|
|
3536
|
+
if (record.fallback && !record.cancelled && tab.rpc?.isRunning?.() && primaryError?.guidedGitProviderGenerationFailure === true) {
|
|
3444
3537
|
try {
|
|
3445
3538
|
const fallbackResult = await startGitWorkflowFallback(tab, record, primaryError);
|
|
3446
3539
|
if (fallbackResult) return fallbackResult;
|
|
@@ -7687,9 +7780,12 @@ async function readGitSigningDiagnostics(cwd) {
|
|
|
7687
7780
|
}
|
|
7688
7781
|
|
|
7689
7782
|
function gitWorkflowMessageCwd(root, cwd) {
|
|
7690
|
-
const
|
|
7691
|
-
|
|
7692
|
-
|
|
7783
|
+
const repositoryRoot = path.resolve(root);
|
|
7784
|
+
const suppliedCwd = path.resolve(String(cwd || repositoryRoot));
|
|
7785
|
+
if (suppliedCwd !== repositoryRoot && !pathInside(repositoryRoot, suppliedCwd)) {
|
|
7786
|
+
throw new Error(`Git workflow cwd must stay inside repository root: ${suppliedCwd}`);
|
|
7787
|
+
}
|
|
7788
|
+
return repositoryRoot;
|
|
7693
7789
|
}
|
|
7694
7790
|
|
|
7695
7791
|
function gitWorkflowMessageFileMeta(root, messageCwd, filePath) {
|
|
@@ -7727,7 +7823,17 @@ async function readGitWorkflowBranchName(cwd, { generationId = "", generation =
|
|
|
7727
7823
|
const branch = branchText.split(/\r?\n/).find((line) => line.trim())?.trim() || "";
|
|
7728
7824
|
if (!branch) throw new Error(`${branchPath} is empty`);
|
|
7729
7825
|
const branchFile = gitWorkflowMessageFileMeta(root, messageCwd, branchPath);
|
|
7730
|
-
return {
|
|
7826
|
+
return {
|
|
7827
|
+
root,
|
|
7828
|
+
cwd: messageCwd,
|
|
7829
|
+
branchPath,
|
|
7830
|
+
branchRelativePath: branchFile.relativePath,
|
|
7831
|
+
branchRepoRelativePath: branchFile.repoRelativePath,
|
|
7832
|
+
branch,
|
|
7833
|
+
mtimeMs: branchStat.mtimeMs,
|
|
7834
|
+
ctimeMs: branchStat.ctimeMs,
|
|
7835
|
+
ino: String(branchStat.ino),
|
|
7836
|
+
};
|
|
7731
7837
|
} catch (error) {
|
|
7732
7838
|
throw new Error(`Missing generated branch name file ${branchPath}. Run /git-branch-name first. ${sanitizeError(error)}`);
|
|
7733
7839
|
}
|
|
@@ -8504,8 +8610,8 @@ async function defaultGitRemote(root) {
|
|
|
8504
8610
|
|
|
8505
8611
|
function prDescriptionPath(root, branch) {
|
|
8506
8612
|
const base = path.resolve(root, "dev", "PR");
|
|
8507
|
-
const target = path.resolve(base, `${branch}.md`);
|
|
8508
|
-
if (target !== base
|
|
8613
|
+
const target = path.resolve(base, `${encodeURIComponent(branch)}.md`);
|
|
8614
|
+
if (path.dirname(target) !== base) throw new Error("Resolved PR description path escapes dev/PR");
|
|
8509
8615
|
return { base, prPath: target };
|
|
8510
8616
|
}
|
|
8511
8617
|
|
|
@@ -8516,7 +8622,15 @@ async function readGitWorkflowPrDescription(cwd, { generationId = "", generation
|
|
|
8516
8622
|
const { prPath } = prDescriptionPath(root, branch);
|
|
8517
8623
|
try {
|
|
8518
8624
|
const [body, info] = await Promise.all([readFile(prPath, "utf8"), stat(prPath)]);
|
|
8519
|
-
return {
|
|
8625
|
+
return {
|
|
8626
|
+
root,
|
|
8627
|
+
branch,
|
|
8628
|
+
path: prPath,
|
|
8629
|
+
body: body.trimEnd(),
|
|
8630
|
+
mtimeMs: info.mtimeMs,
|
|
8631
|
+
ctimeMs: info.ctimeMs,
|
|
8632
|
+
ino: String(info.ino),
|
|
8633
|
+
};
|
|
8520
8634
|
} catch (error) {
|
|
8521
8635
|
throw new Error(`Missing generated PR description ${prPath}. Run /pr first. ${sanitizeError(error)}`);
|
|
8522
8636
|
}
|
|
@@ -10068,6 +10182,7 @@ function supervisedTabMetadata(tab, { cwd = tab.cwd } = {}) {
|
|
|
10068
10182
|
sessionFile: tabRestorableSessionFile(tab),
|
|
10069
10183
|
gitWorkspace: tab.gitWorkspace || null,
|
|
10070
10184
|
createdAt: tab.createdAt,
|
|
10185
|
+
featureSystemPromptDetected: featureSystemPromptDetected(tab),
|
|
10071
10186
|
};
|
|
10072
10187
|
}
|
|
10073
10188
|
|
|
@@ -10219,6 +10334,17 @@ function extensionStatusMap(tab) {
|
|
|
10219
10334
|
return tab.extensionStatuses;
|
|
10220
10335
|
}
|
|
10221
10336
|
|
|
10337
|
+
function featureSystemPromptDetected(tab) {
|
|
10338
|
+
const statuses = extensionStatusMap(tab);
|
|
10339
|
+
return [...REPLAYABLE_CLEARED_EXTENSION_STATUS_KEYS].some((statusKey) => statuses.has(statusKey));
|
|
10340
|
+
}
|
|
10341
|
+
|
|
10342
|
+
function restoreFeatureSystemPromptDetection(tab, detected) {
|
|
10343
|
+
if (!detected) return;
|
|
10344
|
+
const statuses = extensionStatusMap(tab);
|
|
10345
|
+
for (const statusKey of REPLAYABLE_CLEARED_EXTENSION_STATUS_KEYS) statuses.set(statusKey, undefined);
|
|
10346
|
+
}
|
|
10347
|
+
|
|
10222
10348
|
function isGuidedGitWorkflowCommandMessage(message) {
|
|
10223
10349
|
return GUIDED_GIT_COMMAND_MESSAGE.test(String(message || "").trim());
|
|
10224
10350
|
}
|
|
@@ -10286,8 +10412,12 @@ function extensionWidgetMap(tab) {
|
|
|
10286
10412
|
function rememberExtensionStatusEvent(tab, event) {
|
|
10287
10413
|
if (event?.type !== "extension_ui_request" || event.method !== "setStatus" || !event.statusKey) return;
|
|
10288
10414
|
const statuses = extensionStatusMap(tab);
|
|
10289
|
-
|
|
10290
|
-
|
|
10415
|
+
const statusKey = String(event.statusKey);
|
|
10416
|
+
const featureWasDetected = featureSystemPromptDetected(tab);
|
|
10417
|
+
if (event.statusText) statuses.set(statusKey, String(event.statusText));
|
|
10418
|
+
else if (REPLAYABLE_CLEARED_EXTENSION_STATUS_KEYS.has(statusKey)) statuses.set(statusKey, undefined);
|
|
10419
|
+
else statuses.delete(statusKey);
|
|
10420
|
+
if (!featureWasDetected && featureSystemPromptDetected(tab)) scheduleSupervisorMetadataUpdate(tab);
|
|
10291
10421
|
}
|
|
10292
10422
|
|
|
10293
10423
|
function rememberExtensionWidgetEvent(tab, event) {
|
|
@@ -11397,6 +11527,7 @@ function attachRpcToTab(tab, rpc) {
|
|
|
11397
11527
|
tab.gitWorkflowMessageGeneration = null;
|
|
11398
11528
|
clearPendingExtensionUiRequests(tab);
|
|
11399
11529
|
clearExtensionStatuses(tab);
|
|
11530
|
+
scheduleSupervisorMetadataUpdate(tab);
|
|
11400
11531
|
clearExtensionWidgets(tab);
|
|
11401
11532
|
clearPendingGuidedGitLaunch(tab);
|
|
11402
11533
|
clearWebuiSubagents(tab);
|
|
@@ -11556,6 +11687,7 @@ async function hydrateManagedTabs(snapshot) {
|
|
|
11556
11687
|
gitWorkspace: metadata?.gitWorkspace || null,
|
|
11557
11688
|
rpc,
|
|
11558
11689
|
});
|
|
11690
|
+
restoreFeatureSystemPromptDetection(tab, metadata?.featureSystemPromptDetected === true);
|
|
11559
11691
|
attachRpcToTab(tab, rpc);
|
|
11560
11692
|
tabs.set(tab.id, tab);
|
|
11561
11693
|
workspaceFilesLiveWatcher.subscribe(tab.id, tab.cwd);
|
|
@@ -15028,28 +15160,29 @@ async function runCloneCommand(tab) {
|
|
|
15028
15160
|
});
|
|
15029
15161
|
}
|
|
15030
15162
|
|
|
15031
|
-
async function
|
|
15163
|
+
async function resumeSessionInNewTab(sourceTab, sessionPath) {
|
|
15032
15164
|
requirePersistentSessions();
|
|
15033
|
-
|
|
15034
|
-
const targetPath = resolveTabPath(tab, sessionPath);
|
|
15165
|
+
const targetPath = resolveTabPath(sourceTab, sessionPath);
|
|
15035
15166
|
if (!targetPath) throw makeHttpError(400, "sessionPath is required");
|
|
15036
15167
|
if (!targetPath.endsWith(".jsonl")) throw makeHttpError(400, "sessionPath must point to a .jsonl session file");
|
|
15037
15168
|
requireAllowedSessionPath(targetPath);
|
|
15038
15169
|
const targetStats = await stat(targetPath).catch(() => null);
|
|
15039
15170
|
if (!targetStats?.isFile()) throw makeHttpError(404, `Session file not found: ${targetPath}`);
|
|
15040
15171
|
const manager = SessionManager.open(targetPath, configuredSessionDir());
|
|
15041
|
-
const
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15045
|
-
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
}
|
|
15172
|
+
const sessionName = manager.getSessionName();
|
|
15173
|
+
const resumedTab = await createTab({
|
|
15174
|
+
title: sessionName ? uniqueTabTitle(sessionName, null) : undefined,
|
|
15175
|
+
titleSource: sessionName ? "explicit" : undefined,
|
|
15176
|
+
conversationStarted: true,
|
|
15177
|
+
cwd: manager.getCwd(),
|
|
15178
|
+
sessionFile: manager.getSessionFile(),
|
|
15179
|
+
});
|
|
15049
15180
|
return rpcSuccess("switch_session", {
|
|
15050
|
-
message:
|
|
15051
|
-
result:
|
|
15052
|
-
tab: tabMeta(
|
|
15181
|
+
message: "Resumed selected session in a new terminal tab.",
|
|
15182
|
+
result: { cancelled: false, sessionFile: manager.getSessionFile() },
|
|
15183
|
+
tab: tabMeta(resumedTab),
|
|
15184
|
+
tabs: listTabs(),
|
|
15185
|
+
sourceTab: tabMeta(sourceTab),
|
|
15053
15186
|
});
|
|
15054
15187
|
}
|
|
15055
15188
|
|
|
@@ -17088,8 +17221,8 @@ const server = createServer(async (req, res) => {
|
|
|
17088
17221
|
const body = await readJsonBody(req);
|
|
17089
17222
|
const tab = getRequestedTab(req, url, body);
|
|
17090
17223
|
ensureNaturalConversationRouteAllowed(tab, "session switching is blocked");
|
|
17091
|
-
const response = await
|
|
17092
|
-
sendJson(res, response.success === false ? 400 : 200,
|
|
17224
|
+
const response = await resumeSessionInNewTab(tab, body.sessionPath || body.path);
|
|
17225
|
+
sendJson(res, response.success === false ? 400 : 200, response);
|
|
17093
17226
|
return;
|
|
17094
17227
|
}
|
|
17095
17228
|
|
|
@@ -17315,7 +17448,8 @@ const server = createServer(async (req, res) => {
|
|
|
17315
17448
|
|
|
17316
17449
|
if (url.pathname === "/api/git-workflow/preferences" && req.method === "GET") {
|
|
17317
17450
|
const tab = getRequestedTab(req, url);
|
|
17318
|
-
|
|
17451
|
+
const includeModels = url.searchParams.get("includeModels") !== "false";
|
|
17452
|
+
sendJson(res, 200, { ok: true, data: await gitWorkflowPreferencesData(tab, { includeModels }) });
|
|
17319
17453
|
return;
|
|
17320
17454
|
}
|
|
17321
17455
|
|
package/index.ts
CHANGED
|
@@ -25,6 +25,8 @@ import {
|
|
|
25
25
|
resolveResourceSelection,
|
|
26
26
|
setExactModelProfile,
|
|
27
27
|
} from "./lib/resource-selection.mjs";
|
|
28
|
+
import { selectTuiModelProfile } from "./lib/tui-model-profile-selector.mjs";
|
|
29
|
+
import { selectTuiResources } from "./lib/tui-resource-selector.mjs";
|
|
28
30
|
|
|
29
31
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
30
32
|
const packageRoot = __dirname;
|
|
@@ -947,32 +949,6 @@ function registerTuiResourceController(pi: ExtensionAPI): void {
|
|
|
947
949
|
return true;
|
|
948
950
|
}
|
|
949
951
|
|
|
950
|
-
async function chooseResources(ctx: ExtensionCommandContext, title: string, visibleNames: string[], initiallyEnabled: string[]): Promise<string[] | undefined> {
|
|
951
|
-
const enabled = new Set(initiallyEnabled.filter((name) => visibleNames.includes(name)));
|
|
952
|
-
while (true) {
|
|
953
|
-
const actions = [
|
|
954
|
-
"Save selection",
|
|
955
|
-
"Enable all",
|
|
956
|
-
"Enable none",
|
|
957
|
-
...visibleNames.map((name) => `${enabled.has(name) ? "[x]" : "[ ]"} ${name}`),
|
|
958
|
-
];
|
|
959
|
-
const selected = await ctx.ui.select(title, actions);
|
|
960
|
-
if (!selected) return undefined;
|
|
961
|
-
if (selected === "Save selection") return visibleNames.filter((name) => enabled.has(name));
|
|
962
|
-
if (selected === "Enable all") {
|
|
963
|
-
visibleNames.forEach((name) => enabled.add(name));
|
|
964
|
-
continue;
|
|
965
|
-
}
|
|
966
|
-
if (selected === "Enable none") {
|
|
967
|
-
enabled.clear();
|
|
968
|
-
continue;
|
|
969
|
-
}
|
|
970
|
-
const name = selected.slice(4);
|
|
971
|
-
if (enabled.has(name)) enabled.delete(name);
|
|
972
|
-
else enabled.add(name);
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
|
|
976
952
|
function availableModels(ctx: ExtensionCommandContext): any[] {
|
|
977
953
|
return ctx.modelRegistry.getAvailable()
|
|
978
954
|
.filter((model: any) => model?.provider && model?.id)
|
|
@@ -1023,11 +999,19 @@ function registerTuiResourceController(pi: ExtensionAPI): void {
|
|
|
1023
999
|
ctx.ui.notify("No authenticated Pi models are available.", "warning");
|
|
1024
1000
|
return;
|
|
1025
1001
|
}
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1002
|
+
const configuredModelKeys = (Array.isArray(settings.resourceDefaults?.modelProfiles)
|
|
1003
|
+
? settings.resourceDefaults.modelProfiles
|
|
1004
|
+
: [])
|
|
1005
|
+
.filter((profile: any) => Array.isArray(profile?.[resourceType]?.[selectionKey]))
|
|
1006
|
+
.map((profile: any) => `${profile.provider}\0${profile.modelId}`);
|
|
1007
|
+
const model = await selectTuiModelProfile(ctx, {
|
|
1008
|
+
title: `${resourceLabel} Model Profile`,
|
|
1009
|
+
subtitle: "Choose a profile to edit. This does not switch the active model.",
|
|
1010
|
+
models,
|
|
1011
|
+
activeModelKey: modelKey(ctx.model),
|
|
1012
|
+
configuredModelKeys,
|
|
1013
|
+
});
|
|
1014
|
+
if (!model) return;
|
|
1031
1015
|
provider = model.provider;
|
|
1032
1016
|
modelId = model.id;
|
|
1033
1017
|
const action = await ctx.ui.select(`${resourceLabel} for ${provider}/${modelId}`, ["Edit selection", "Use inherited defaults"]);
|
|
@@ -1049,7 +1033,13 @@ function registerTuiResourceController(pi: ExtensionAPI): void {
|
|
|
1049
1033
|
}
|
|
1050
1034
|
}
|
|
1051
1035
|
|
|
1052
|
-
const
|
|
1036
|
+
const selectionTarget = scope === "Model default" ? `${provider}/${modelId} model profile` : scope;
|
|
1037
|
+
const selected = await selectTuiResources(ctx, {
|
|
1038
|
+
title: `${resourceLabel} Configuration`,
|
|
1039
|
+
subtitle: `${selectionTarget}. Changes apply only after Ctrl+S.`,
|
|
1040
|
+
resources: visibleNames,
|
|
1041
|
+
enabledResourceNames: previousNames || [],
|
|
1042
|
+
});
|
|
1053
1043
|
if (!selected) return;
|
|
1054
1044
|
if (scope === "Session only") {
|
|
1055
1045
|
const preserved = preserveUnavailableResourceNames(previousNames, visibleNames, selected);
|
|
@@ -1078,7 +1068,7 @@ function registerTuiResourceController(pi: ExtensionAPI): void {
|
|
|
1078
1068
|
});
|
|
1079
1069
|
}
|
|
1080
1070
|
await recompute(ctx);
|
|
1081
|
-
ctx.ui.notify(`${resourceLabel} ${
|
|
1071
|
+
ctx.ui.notify(`${resourceLabel} ${selectionTarget.toLowerCase()} saved.`, "info");
|
|
1082
1072
|
}
|
|
1083
1073
|
|
|
1084
1074
|
pi.registerCommand("tools", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdir, open, readFile, readdir, rename, rm, rmdir } from "node:fs/promises";
|
|
1
|
+
import { mkdir, open, readFile, readdir, rename, rm, rmdir, stat } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
@@ -31,6 +31,7 @@ const WEBUI_SETTINGS_VERSION = 8;
|
|
|
31
31
|
const WEBUI_SETTINGS_FILE_ENV = "PI_WEBUI_SETTINGS_FILE";
|
|
32
32
|
const WEBUI_SETTINGS_LOCK_TIMEOUT_MS = 2_000;
|
|
33
33
|
const WEBUI_SETTINGS_LOCK_RETRY_MS = 25;
|
|
34
|
+
const WEBUI_SETTINGS_LOCK_INVALID_RECORD_GRACE_MS = 1_000;
|
|
34
35
|
export const WEBUI_SIDE_PANEL_WIDTH_MIN_PX = 320;
|
|
35
36
|
export const WEBUI_SIDE_PANEL_WIDTH_MAX_PX = 4096;
|
|
36
37
|
const webuiSettingsUpdateQueues = new Map();
|
|
@@ -240,22 +241,51 @@ function lockOwnerIsDead(pid) {
|
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
243
|
|
|
244
|
+
function settingsLockRecordNameMetadata(name) {
|
|
245
|
+
const match = name.match(/^(\d+)-(\d+)-[^/]+\.json$/);
|
|
246
|
+
if (!match) return {};
|
|
247
|
+
const ownerPid = Number(match[1]);
|
|
248
|
+
const createdAt = Number(match[2]);
|
|
249
|
+
return {
|
|
250
|
+
ownerPid: Number.isSafeInteger(ownerPid) && ownerPid > 0 ? ownerPid : undefined,
|
|
251
|
+
createdAt: Number.isSafeInteger(createdAt) && createdAt > 0 ? createdAt : undefined,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
243
255
|
async function readSettingsLockRecords(lockDirectory) {
|
|
244
256
|
const names = (await readdir(lockDirectory)).filter((name) => name.endsWith(".json")).sort();
|
|
245
|
-
|
|
257
|
+
const records = await Promise.all(names.map(async (name) => {
|
|
246
258
|
const recordFile = path.join(lockDirectory, name);
|
|
259
|
+
const nameMetadata = settingsLockRecordNameMetadata(name);
|
|
247
260
|
try {
|
|
248
|
-
const value =
|
|
261
|
+
const [value, fileStat] = await Promise.all([
|
|
262
|
+
readFile(recordFile, "utf8").then((text) => JSON.parse(text)),
|
|
263
|
+
stat(recordFile),
|
|
264
|
+
]);
|
|
249
265
|
const valid = Number.isSafeInteger(value?.pid)
|
|
250
266
|
&& value.pid > 0
|
|
251
267
|
&& typeof value?.token === "string"
|
|
252
268
|
&& value.token.length > 0
|
|
253
269
|
&& ["pending", "active"].includes(value?.state);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
270
|
+
const createdAt = Number.isSafeInteger(value?.createdAt) && value.createdAt > 0
|
|
271
|
+
? value.createdAt
|
|
272
|
+
: nameMetadata.createdAt;
|
|
273
|
+
return {
|
|
274
|
+
...value,
|
|
275
|
+
ownerPid: nameMetadata.ownerPid,
|
|
276
|
+
createdAt,
|
|
277
|
+
name,
|
|
278
|
+
recordFile,
|
|
279
|
+
mtimeMs: fileStat.mtimeMs,
|
|
280
|
+
valid,
|
|
281
|
+
};
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (error?.code === "ENOENT") return undefined;
|
|
284
|
+
const fileStat = await stat(recordFile).catch(() => undefined);
|
|
285
|
+
return { ...nameMetadata, name, recordFile, mtimeMs: fileStat?.mtimeMs, valid: false };
|
|
257
286
|
}
|
|
258
287
|
}));
|
|
288
|
+
return records.filter(Boolean);
|
|
259
289
|
}
|
|
260
290
|
|
|
261
291
|
async function renameWithWindowsRetry(source, target) {
|
|
@@ -306,9 +336,10 @@ export async function withWebuiSettingsLock(storageFile, operation, {
|
|
|
306
336
|
await mkdir(lockDirectory, { mode: 0o700 }).catch((error) => {
|
|
307
337
|
if (error?.code !== "EEXIST") throw error;
|
|
308
338
|
});
|
|
309
|
-
const
|
|
339
|
+
const createdAt = Date.now();
|
|
340
|
+
const token = `${process.pid}-${createdAt}-${Math.random().toString(16).slice(2)}`;
|
|
310
341
|
const recordFile = path.join(lockDirectory, `${token}.json`);
|
|
311
|
-
const ownRecord = { pid: process.pid, token, state: "pending" };
|
|
342
|
+
const ownRecord = { pid: process.pid, token, state: "pending", createdAt };
|
|
312
343
|
let handle;
|
|
313
344
|
try {
|
|
314
345
|
handle = await open(recordFile, "wx", 0o600);
|
|
@@ -327,14 +358,22 @@ export async function withWebuiSettingsLock(storageFile, operation, {
|
|
|
327
358
|
try {
|
|
328
359
|
while (!acquired) {
|
|
329
360
|
let records = await readSettingsLockRecords(lockDirectory);
|
|
330
|
-
let
|
|
361
|
+
let removedStaleRecord = false;
|
|
331
362
|
for (const record of records) {
|
|
332
|
-
|
|
363
|
+
const ownerPid = record.valid ? record.pid : record.ownerPid;
|
|
364
|
+
const ownerIsDead = lockOwnerIsDead(ownerPid);
|
|
365
|
+
const recordAgeMs = Math.max(
|
|
366
|
+
Number.isFinite(record.mtimeMs) ? Date.now() - record.mtimeMs : 0,
|
|
367
|
+
Number.isSafeInteger(record.createdAt) ? Date.now() - record.createdAt : 0,
|
|
368
|
+
);
|
|
369
|
+
const invalidRecordIsStale = !record.valid
|
|
370
|
+
&& (ownerIsDead || recordAgeMs >= WEBUI_SETTINGS_LOCK_INVALID_RECORD_GRACE_MS);
|
|
371
|
+
if ((record.valid && ownerIsDead) || invalidRecordIsStale) {
|
|
333
372
|
await rm(record.recordFile, { force: true });
|
|
334
|
-
|
|
373
|
+
removedStaleRecord = true;
|
|
335
374
|
}
|
|
336
375
|
}
|
|
337
|
-
if (
|
|
376
|
+
if (removedStaleRecord) continue;
|
|
338
377
|
|
|
339
378
|
const active = records.filter((record) => record.valid && record.state === "active");
|
|
340
379
|
if (active.length === 1 && active[0].token === token) {
|