@firstpick/pi-package-webui 0.9.8 → 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 +911 -0
- package/README.md +8 -8
- package/TECHNICAL.md +415 -0
- package/bin/pi-webui.mjs +237 -64
- 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/lib/windows-drive-roots.mjs +114 -0
- package/package.json +3 -1
- package/public/app.js +274 -90
- package/public/index.html +7 -3
- package/public/service-worker.js +1 -1
- package/public/styles.css +76 -16
- 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/browser/windows-drive-parent.spec.mjs +198 -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 +81 -0
- package/tests/windows-drive-roots.test.mjs +130 -0
package/bin/pi-webui.mjs
CHANGED
|
@@ -59,6 +59,12 @@ import {
|
|
|
59
59
|
findWindowsReservedGitPath,
|
|
60
60
|
windowsReservedGitPathFailure,
|
|
61
61
|
} from "../lib/git-command-errors.mjs";
|
|
62
|
+
import {
|
|
63
|
+
WINDOWS_DRIVES_PICKER_PATH,
|
|
64
|
+
createWindowsDriveRootDiscovery,
|
|
65
|
+
isWindowsDriveRoot,
|
|
66
|
+
windowsDrivesPickerData,
|
|
67
|
+
} from "../lib/windows-drive-roots.mjs";
|
|
62
68
|
import { ComponentUpdateState, sanitizeComponentUpdateError, validateComponentUpdateRequest, validateUpdateApplyRequest, validateUpdatePlanRequest } from "../lib/component-update-state.mjs";
|
|
63
69
|
import { resolveCanonicalPiRuntime, resolveWebuiRuntimeIdentity } from "../lib/update/resolver.mjs";
|
|
64
70
|
import { bundledPackageOwnership, packageOwnerRoot } from "../lib/update/package-layout.mjs";
|
|
@@ -450,6 +456,7 @@ let optionalFeatureStartupReady = false;
|
|
|
450
456
|
const UPDATE_PACKAGE_NAMES = [...CORE_UPDATE_PACKAGE_NAMES].sort();
|
|
451
457
|
const NATURAL_CONVERSATION_STATUS_KEY = "natural-conversation";
|
|
452
458
|
const NATURAL_CONVERSATION_COMMAND_NAMES = ["talk", "voice", "conversation"];
|
|
459
|
+
const REPLAYABLE_CLEARED_EXTENSION_STATUS_KEYS = new Set(["feature-decision-output", "feature-category"]);
|
|
453
460
|
const GUIDED_GIT_START_STATUS_KEY = "git-guided-workflow:webui-start";
|
|
454
461
|
const GUIDED_GIT_START_PAYLOAD_TYPE = "firstpick.pi-extension-git-guided-workflow.start";
|
|
455
462
|
const GUIDED_GIT_START_PAYLOAD_VERSION = 1;
|
|
@@ -2872,9 +2879,19 @@ function gitWorkflowPreferenceOptions() {
|
|
|
2872
2879
|
};
|
|
2873
2880
|
}
|
|
2874
2881
|
|
|
2875
|
-
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
|
+
}
|
|
2876
2893
|
const [preferences, models] = await Promise.all([
|
|
2877
|
-
|
|
2894
|
+
preferencesPromise,
|
|
2878
2895
|
availableGitWorkflowModels(tab),
|
|
2879
2896
|
]);
|
|
2880
2897
|
return {
|
|
@@ -3107,24 +3124,58 @@ async function triggerSessionSummary(tab, { refresh = false } = {}) {
|
|
|
3107
3124
|
}
|
|
3108
3125
|
}
|
|
3109
3126
|
|
|
3110
|
-
function gitWorkflowGenerationPrompt(kind, preferences) {
|
|
3127
|
+
function gitWorkflowGenerationPrompt(kind, preferences, commandName) {
|
|
3111
3128
|
switch (kind) {
|
|
3112
3129
|
case "commit":
|
|
3113
|
-
return
|
|
3130
|
+
return `/${commandName} ${preferences.commit.language} ${preferences.commit.scope}`;
|
|
3114
3131
|
case "branch":
|
|
3115
|
-
return
|
|
3132
|
+
return `/${commandName}`;
|
|
3116
3133
|
case "pr":
|
|
3117
|
-
return
|
|
3134
|
+
return `/${commandName} ${preferences.commit.language}`;
|
|
3118
3135
|
default:
|
|
3119
3136
|
throw makeHttpError(400, "generation kind must be commit, branch, or pr");
|
|
3120
3137
|
}
|
|
3121
3138
|
}
|
|
3122
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
|
+
|
|
3123
3162
|
function boundedGitWorkflowGenerationError(message, fallback = "Guided Git generation failed") {
|
|
3124
3163
|
const text = typeof message === "string" ? message : fallback;
|
|
3125
3164
|
return text.replace(/[\r\n]+/g, " ").trim().slice(0, 240) || fallback;
|
|
3126
3165
|
}
|
|
3127
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
|
+
|
|
3128
3179
|
function gitWorkflowGenerationCancellationError() {
|
|
3129
3180
|
const error = makeHttpError(409, "Guided Git generation was cancelled");
|
|
3130
3181
|
error.code = "GIT_WORKFLOW_CANCELLED";
|
|
@@ -3192,23 +3243,49 @@ async function restoreGitWorkflowGenerationProfile(tab, expectedRecord = tab?.gi
|
|
|
3192
3243
|
return operation;
|
|
3193
3244
|
}
|
|
3194
3245
|
|
|
3195
|
-
async function
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
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
|
+
}
|
|
3212
3289
|
}
|
|
3213
3290
|
|
|
3214
3291
|
function emitGitWorkflowFallbackLifecycle(tab, record, phase) {
|
|
@@ -3263,6 +3340,7 @@ async function dispatchGitWorkflowGenerationAttempt(tab, record, profile, attemp
|
|
|
3263
3340
|
record.attemptRunStarted = false;
|
|
3264
3341
|
record.promptAccepted = false;
|
|
3265
3342
|
record.pendingSettlement = null;
|
|
3343
|
+
record.nativeCommandError = null;
|
|
3266
3344
|
if (record.currentModelKey !== `${profile.provider}/${profile.modelId}`) {
|
|
3267
3345
|
const modelResponse = await tab.rpc.send({ type: "set_model", provider: profile.provider, modelId: profile.modelId });
|
|
3268
3346
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
@@ -3277,14 +3355,19 @@ async function dispatchGitWorkflowGenerationAttempt(tab, record, profile, attemp
|
|
|
3277
3355
|
markTabWorking(tab);
|
|
3278
3356
|
const response = await tab.rpc.send({ type: "prompt", message: record.message });
|
|
3279
3357
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3280
|
-
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;
|
|
3281
3364
|
record.promptAccepted = true;
|
|
3282
3365
|
const pendingSettlement = record.pendingSettlement;
|
|
3283
3366
|
if (pendingSettlement?.attempt === attempt) {
|
|
3284
3367
|
record.pendingSettlement = null;
|
|
3285
3368
|
void settleGitWorkflowGeneration(tab, record, pendingSettlement);
|
|
3286
3369
|
}
|
|
3287
|
-
|
|
3370
|
+
const result = {
|
|
3288
3371
|
accepted: true,
|
|
3289
3372
|
kind: record.kind,
|
|
3290
3373
|
message: record.message,
|
|
@@ -3293,11 +3376,23 @@ async function dispatchGitWorkflowGenerationAttempt(tab, record, profile, attemp
|
|
|
3293
3376
|
fallbackUsed: attempt === "fallback",
|
|
3294
3377
|
primaryGeneration: publicGitWorkflowGenerationProfile(record.primary),
|
|
3295
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;
|
|
3296
3391
|
}
|
|
3297
3392
|
|
|
3298
3393
|
async function startGitWorkflowFallback(tab, record, primaryError) {
|
|
3299
3394
|
if (tab.gitWorkflowGeneration !== record || record.fallbackStarted || !record.fallback) return null;
|
|
3300
|
-
if (record.cancelled || !tab.rpc?.isRunning?.()) return null;
|
|
3395
|
+
if (record.cancelled || !tab.rpc?.isRunning?.() || primaryError?.guidedGitProviderGenerationFailure !== true) return null;
|
|
3301
3396
|
record.fallbackStarted = true;
|
|
3302
3397
|
record.attempt = "fallback";
|
|
3303
3398
|
record.attemptRunStarted = false;
|
|
@@ -3336,6 +3431,11 @@ async function settleGitWorkflowGeneration(tab, record, { failed, cancelled }) {
|
|
|
3336
3431
|
function consumeGitWorkflowGenerationEvent(tab, event, { finalError = false } = {}) {
|
|
3337
3432
|
const record = tab.gitWorkflowGeneration;
|
|
3338
3433
|
if (!record || record.finishing) return;
|
|
3434
|
+
const nativeCommandError = guidedGitNativeCommandErrorFromEvent(record, event);
|
|
3435
|
+
if (nativeCommandError) {
|
|
3436
|
+
record.nativeCommandError = nativeCommandError;
|
|
3437
|
+
return;
|
|
3438
|
+
}
|
|
3339
3439
|
if ((event?.type === "agent_end" || event?.type === "agent_settled") && event.aborted === true) record.cancelled = true;
|
|
3340
3440
|
if (event?.type === "agent_start") {
|
|
3341
3441
|
record.attemptRunStarted = true;
|
|
@@ -3376,6 +3476,9 @@ async function startGitWorkflowGeneration(tab, body = {}) {
|
|
|
3376
3476
|
promptAccepted: false,
|
|
3377
3477
|
pendingSettlement: null,
|
|
3378
3478
|
currentModelKey: "",
|
|
3479
|
+
nativeCommandName: "",
|
|
3480
|
+
nativeCommandError: null,
|
|
3481
|
+
nativeGeneration: true,
|
|
3379
3482
|
};
|
|
3380
3483
|
tab.gitWorkflowGeneration = record;
|
|
3381
3484
|
tab.gitWorkflowFallbackLifecycle = { generationId: record.generationId, kind, events: [] };
|
|
@@ -3388,7 +3491,10 @@ async function startGitWorkflowGeneration(tab, body = {}) {
|
|
|
3388
3491
|
const preferences = await readGitWorkflowPreferences();
|
|
3389
3492
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3390
3493
|
if (!isGitWorkflowSetupComplete(preferences)) throw makeHttpError(409, "Run /git-workflow-setup or open Guided Git Setup before generating Git text");
|
|
3391
|
-
|
|
3494
|
+
const nativeCommandName = await resolveGuidedGitNativeCommand(tab, kind);
|
|
3495
|
+
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3496
|
+
record.nativeCommandName = nativeCommandName;
|
|
3497
|
+
record.message = gitWorkflowGenerationPrompt(kind, preferences, nativeCommandName);
|
|
3392
3498
|
|
|
3393
3499
|
const state = await currentSessionState(tab);
|
|
3394
3500
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
@@ -3417,16 +3523,9 @@ async function startGitWorkflowGeneration(tab, body = {}) {
|
|
|
3417
3523
|
record.restore = { model: state.model || null, thinkingLevel: state.thinkingLevel || "off" };
|
|
3418
3524
|
record.currentModelKey = gitWorkflowModelKey(state.model);
|
|
3419
3525
|
tab.gitWorkflowGenerationRestore = record.restore;
|
|
3420
|
-
record.
|
|
3526
|
+
record.artifactGeneration = await createGitWorkflowArtifactGeneration(tab, record.generationId, kind);
|
|
3527
|
+
record.messageGeneration = kind === "commit" ? record.artifactGeneration : null;
|
|
3421
3528
|
assertGitWorkflowGenerationOwnership(tab, record);
|
|
3422
|
-
record.artifactGeneration = record.messageGeneration || {
|
|
3423
|
-
id: record.generationId,
|
|
3424
|
-
kind,
|
|
3425
|
-
cwd: path.resolve(tab.cwd),
|
|
3426
|
-
createdAt: Date.now(),
|
|
3427
|
-
terminal: false,
|
|
3428
|
-
successful: false,
|
|
3429
|
-
};
|
|
3430
3529
|
tab.gitWorkflowArtifactGeneration = record.artifactGeneration;
|
|
3431
3530
|
if (record.messageGeneration) tab.gitWorkflowMessageGeneration = record.messageGeneration;
|
|
3432
3531
|
|
|
@@ -3434,7 +3533,7 @@ async function startGitWorkflowGeneration(tab, body = {}) {
|
|
|
3434
3533
|
return await dispatchGitWorkflowGenerationAttempt(tab, record, record.primary, "primary");
|
|
3435
3534
|
} catch (primaryError) {
|
|
3436
3535
|
markTabIdle(tab);
|
|
3437
|
-
if (record.fallback && !record.cancelled && tab.rpc?.isRunning?.()) {
|
|
3536
|
+
if (record.fallback && !record.cancelled && tab.rpc?.isRunning?.() && primaryError?.guidedGitProviderGenerationFailure === true) {
|
|
3438
3537
|
try {
|
|
3439
3538
|
const fallbackResult = await startGitWorkflowFallback(tab, record, primaryError);
|
|
3440
3539
|
if (fallbackResult) return fallbackResult;
|
|
@@ -5641,7 +5740,37 @@ function pathPickerRoots(activeCwd, viewedCwd) {
|
|
|
5641
5740
|
]);
|
|
5642
5741
|
}
|
|
5643
5742
|
|
|
5743
|
+
const discoverWindowsDriveRoots = createWindowsDriveRootDiscovery({ runCommand });
|
|
5744
|
+
|
|
5745
|
+
function knownWindowsDrivePaths(activeCwd) {
|
|
5746
|
+
return [
|
|
5747
|
+
activeCwd,
|
|
5748
|
+
options.cwd,
|
|
5749
|
+
process.env.USERPROFILE,
|
|
5750
|
+
process.env.HOME,
|
|
5751
|
+
process.env.HOMEDRIVE,
|
|
5752
|
+
process.env.SystemDrive,
|
|
5753
|
+
process.env.SystemRoot,
|
|
5754
|
+
];
|
|
5755
|
+
}
|
|
5756
|
+
|
|
5757
|
+
function windowsDriveDiscoveryCwd() {
|
|
5758
|
+
return process.env.SystemRoot || process.env.WINDIR || path.dirname(process.execPath);
|
|
5759
|
+
}
|
|
5760
|
+
|
|
5761
|
+
async function getWindowsDrivesPickerData(activeCwd) {
|
|
5762
|
+
const driveRoots = await discoverWindowsDriveRoots({
|
|
5763
|
+
cwd: windowsDriveDiscoveryCwd(),
|
|
5764
|
+
knownPaths: knownWindowsDrivePaths(activeCwd),
|
|
5765
|
+
});
|
|
5766
|
+
return windowsDrivesPickerData(driveRoots, pathPickerRoots(activeCwd, activeCwd));
|
|
5767
|
+
}
|
|
5768
|
+
|
|
5644
5769
|
async function getDirectoryPickerData(viewPath, activeCwd) {
|
|
5770
|
+
if (platform() === "win32" && viewPath === WINDOWS_DRIVES_PICKER_PATH) {
|
|
5771
|
+
return getWindowsDrivesPickerData(activeCwd);
|
|
5772
|
+
}
|
|
5773
|
+
|
|
5645
5774
|
const cwd = await resolveCwd(viewPath || activeCwd, activeCwd);
|
|
5646
5775
|
let entries;
|
|
5647
5776
|
try {
|
|
@@ -5658,11 +5787,14 @@ async function getDirectoryPickerData(viewPath, activeCwd) {
|
|
|
5658
5787
|
return { name: entry.name, cwd: entryPath, displayCwd: displayPath(entryPath), hidden: entry.name.startsWith(".") };
|
|
5659
5788
|
});
|
|
5660
5789
|
const parent = path.dirname(cwd);
|
|
5790
|
+
const parentPath = platform() === "win32" && isWindowsDriveRoot(cwd)
|
|
5791
|
+
? WINDOWS_DRIVES_PICKER_PATH
|
|
5792
|
+
: parent === cwd ? null : parent;
|
|
5661
5793
|
|
|
5662
5794
|
return {
|
|
5663
5795
|
cwd,
|
|
5664
5796
|
displayCwd: displayPath(cwd),
|
|
5665
|
-
parent:
|
|
5797
|
+
parent: parentPath,
|
|
5666
5798
|
roots: pathPickerRoots(activeCwd, cwd),
|
|
5667
5799
|
directories,
|
|
5668
5800
|
truncated: directoryEntries.length > directories.length,
|
|
@@ -7648,9 +7780,12 @@ async function readGitSigningDiagnostics(cwd) {
|
|
|
7648
7780
|
}
|
|
7649
7781
|
|
|
7650
7782
|
function gitWorkflowMessageCwd(root, cwd) {
|
|
7651
|
-
const
|
|
7652
|
-
|
|
7653
|
-
|
|
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;
|
|
7654
7789
|
}
|
|
7655
7790
|
|
|
7656
7791
|
function gitWorkflowMessageFileMeta(root, messageCwd, filePath) {
|
|
@@ -7688,7 +7823,17 @@ async function readGitWorkflowBranchName(cwd, { generationId = "", generation =
|
|
|
7688
7823
|
const branch = branchText.split(/\r?\n/).find((line) => line.trim())?.trim() || "";
|
|
7689
7824
|
if (!branch) throw new Error(`${branchPath} is empty`);
|
|
7690
7825
|
const branchFile = gitWorkflowMessageFileMeta(root, messageCwd, branchPath);
|
|
7691
|
-
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
|
+
};
|
|
7692
7837
|
} catch (error) {
|
|
7693
7838
|
throw new Error(`Missing generated branch name file ${branchPath}. Run /git-branch-name first. ${sanitizeError(error)}`);
|
|
7694
7839
|
}
|
|
@@ -8465,8 +8610,8 @@ async function defaultGitRemote(root) {
|
|
|
8465
8610
|
|
|
8466
8611
|
function prDescriptionPath(root, branch) {
|
|
8467
8612
|
const base = path.resolve(root, "dev", "PR");
|
|
8468
|
-
const target = path.resolve(base, `${branch}.md`);
|
|
8469
|
-
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");
|
|
8470
8615
|
return { base, prPath: target };
|
|
8471
8616
|
}
|
|
8472
8617
|
|
|
@@ -8477,7 +8622,15 @@ async function readGitWorkflowPrDescription(cwd, { generationId = "", generation
|
|
|
8477
8622
|
const { prPath } = prDescriptionPath(root, branch);
|
|
8478
8623
|
try {
|
|
8479
8624
|
const [body, info] = await Promise.all([readFile(prPath, "utf8"), stat(prPath)]);
|
|
8480
|
-
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
|
+
};
|
|
8481
8634
|
} catch (error) {
|
|
8482
8635
|
throw new Error(`Missing generated PR description ${prPath}. Run /pr first. ${sanitizeError(error)}`);
|
|
8483
8636
|
}
|
|
@@ -10029,6 +10182,7 @@ function supervisedTabMetadata(tab, { cwd = tab.cwd } = {}) {
|
|
|
10029
10182
|
sessionFile: tabRestorableSessionFile(tab),
|
|
10030
10183
|
gitWorkspace: tab.gitWorkspace || null,
|
|
10031
10184
|
createdAt: tab.createdAt,
|
|
10185
|
+
featureSystemPromptDetected: featureSystemPromptDetected(tab),
|
|
10032
10186
|
};
|
|
10033
10187
|
}
|
|
10034
10188
|
|
|
@@ -10180,6 +10334,17 @@ function extensionStatusMap(tab) {
|
|
|
10180
10334
|
return tab.extensionStatuses;
|
|
10181
10335
|
}
|
|
10182
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
|
+
|
|
10183
10348
|
function isGuidedGitWorkflowCommandMessage(message) {
|
|
10184
10349
|
return GUIDED_GIT_COMMAND_MESSAGE.test(String(message || "").trim());
|
|
10185
10350
|
}
|
|
@@ -10247,8 +10412,12 @@ function extensionWidgetMap(tab) {
|
|
|
10247
10412
|
function rememberExtensionStatusEvent(tab, event) {
|
|
10248
10413
|
if (event?.type !== "extension_ui_request" || event.method !== "setStatus" || !event.statusKey) return;
|
|
10249
10414
|
const statuses = extensionStatusMap(tab);
|
|
10250
|
-
|
|
10251
|
-
|
|
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);
|
|
10252
10421
|
}
|
|
10253
10422
|
|
|
10254
10423
|
function rememberExtensionWidgetEvent(tab, event) {
|
|
@@ -11358,6 +11527,7 @@ function attachRpcToTab(tab, rpc) {
|
|
|
11358
11527
|
tab.gitWorkflowMessageGeneration = null;
|
|
11359
11528
|
clearPendingExtensionUiRequests(tab);
|
|
11360
11529
|
clearExtensionStatuses(tab);
|
|
11530
|
+
scheduleSupervisorMetadataUpdate(tab);
|
|
11361
11531
|
clearExtensionWidgets(tab);
|
|
11362
11532
|
clearPendingGuidedGitLaunch(tab);
|
|
11363
11533
|
clearWebuiSubagents(tab);
|
|
@@ -11517,6 +11687,7 @@ async function hydrateManagedTabs(snapshot) {
|
|
|
11517
11687
|
gitWorkspace: metadata?.gitWorkspace || null,
|
|
11518
11688
|
rpc,
|
|
11519
11689
|
});
|
|
11690
|
+
restoreFeatureSystemPromptDetection(tab, metadata?.featureSystemPromptDetected === true);
|
|
11520
11691
|
attachRpcToTab(tab, rpc);
|
|
11521
11692
|
tabs.set(tab.id, tab);
|
|
11522
11693
|
workspaceFilesLiveWatcher.subscribe(tab.id, tab.cwd);
|
|
@@ -14989,28 +15160,29 @@ async function runCloneCommand(tab) {
|
|
|
14989
15160
|
});
|
|
14990
15161
|
}
|
|
14991
15162
|
|
|
14992
|
-
async function
|
|
15163
|
+
async function resumeSessionInNewTab(sourceTab, sessionPath) {
|
|
14993
15164
|
requirePersistentSessions();
|
|
14994
|
-
|
|
14995
|
-
const targetPath = resolveTabPath(tab, sessionPath);
|
|
15165
|
+
const targetPath = resolveTabPath(sourceTab, sessionPath);
|
|
14996
15166
|
if (!targetPath) throw makeHttpError(400, "sessionPath is required");
|
|
14997
15167
|
if (!targetPath.endsWith(".jsonl")) throw makeHttpError(400, "sessionPath must point to a .jsonl session file");
|
|
14998
15168
|
requireAllowedSessionPath(targetPath);
|
|
14999
15169
|
const targetStats = await stat(targetPath).catch(() => null);
|
|
15000
15170
|
if (!targetStats?.isFile()) throw makeHttpError(404, `Session file not found: ${targetPath}`);
|
|
15001
15171
|
const manager = SessionManager.open(targetPath, configuredSessionDir());
|
|
15002
|
-
const
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
}
|
|
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
|
+
});
|
|
15010
15180
|
return rpcSuccess("switch_session", {
|
|
15011
|
-
message:
|
|
15012
|
-
result:
|
|
15013
|
-
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),
|
|
15014
15186
|
});
|
|
15015
15187
|
}
|
|
15016
15188
|
|
|
@@ -17049,8 +17221,8 @@ const server = createServer(async (req, res) => {
|
|
|
17049
17221
|
const body = await readJsonBody(req);
|
|
17050
17222
|
const tab = getRequestedTab(req, url, body);
|
|
17051
17223
|
ensureNaturalConversationRouteAllowed(tab, "session switching is blocked");
|
|
17052
|
-
const response = await
|
|
17053
|
-
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);
|
|
17054
17226
|
return;
|
|
17055
17227
|
}
|
|
17056
17228
|
|
|
@@ -17276,7 +17448,8 @@ const server = createServer(async (req, res) => {
|
|
|
17276
17448
|
|
|
17277
17449
|
if (url.pathname === "/api/git-workflow/preferences" && req.method === "GET") {
|
|
17278
17450
|
const tab = getRequestedTab(req, url);
|
|
17279
|
-
|
|
17451
|
+
const includeModels = url.searchParams.get("includeModels") !== "false";
|
|
17452
|
+
sendJson(res, 200, { ok: true, data: await gitWorkflowPreferencesData(tab, { includeModels }) });
|
|
17280
17453
|
return;
|
|
17281
17454
|
}
|
|
17282
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", {
|