@firstpick/pi-package-webui 0.9.9 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/DEVELOPMENT.md +49 -15
  2. package/README.md +11 -9
  3. package/TECHNICAL.md +12 -8
  4. package/bin/pi-webui.mjs +202 -67
  5. package/index.ts +23 -33
  6. package/lib/git-workflow-preferences.mjs +51 -12
  7. package/lib/tui-model-profile-selector.mjs +183 -0
  8. package/lib/tui-resource-selector.mjs +173 -0
  9. package/package.json +1 -1
  10. package/public/app.js +365 -106
  11. package/public/index.html +10 -7
  12. package/public/service-worker.js +1 -1
  13. package/public/styles.css +114 -22
  14. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  15. package/tests/browser/interaction-continuity.spec.mjs +9 -3
  16. package/tests/browser/intercom-conversation-viewer.spec.mjs +76 -53
  17. package/tests/browser/user-noticeable-fixes.spec.mjs +51 -0
  18. package/tests/codex-fast-mode-static.test.mjs +2 -2
  19. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  20. package/tests/control-visibility-static.test.mjs +3 -3
  21. package/tests/controls-layout-static.test.mjs +3 -3
  22. package/tests/durable-rpc-supervisor-harness.test.mjs +9 -0
  23. package/tests/events-tree-context-menu-static.test.mjs +3 -3
  24. package/tests/fast-mode-client-static.test.mjs +1 -1
  25. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  26. package/tests/file-viewer-image-static.test.mjs +3 -3
  27. package/tests/fixtures/fake-pi.mjs +3 -3
  28. package/tests/guided-git-activation-static.test.mjs +24 -12
  29. package/tests/guided-git-fallback-runtime.test.mjs +209 -270
  30. package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
  31. package/tests/guided-git-message-reliability-static.test.mjs +2 -1
  32. package/tests/guided-git-optional-feature.test.mjs +8 -5
  33. package/tests/guided-git-publication-backend-static.test.mjs +10 -5
  34. package/tests/http-endpoints-harness.test.mjs +27 -13
  35. package/tests/intercom-conversation-viewer-static.test.mjs +7 -6
  36. package/tests/intercom-tag-layout-static.test.mjs +35 -16
  37. package/tests/intercom-tag-overflow-layout.test.mjs +87 -0
  38. package/tests/main-output-loading-static.test.mjs +18 -12
  39. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  40. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  41. package/tests/mobile-foundation-static.test.mjs +3 -3
  42. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  43. package/tests/mobile-static.test.mjs +19 -11
  44. package/tests/open-issue-wizard-static.test.mjs +1 -1
  45. package/tests/optional-feature-prompt-impact-static.test.mjs +67 -0
  46. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  47. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  48. package/tests/questionnaire-dialog.test.mjs +3 -3
  49. package/tests/remote-auth-settings-harness.test.mjs +18 -3
  50. package/tests/resource-tui-extension.test.mjs +2 -1
  51. package/tests/session-sampling-ui-static.test.mjs +3 -3
  52. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  53. package/tests/streaming-ui-coupling.test.mjs +2 -0
  54. package/tests/subagent-observability-static.test.mjs +2 -2
  55. package/tests/syntax-highlighting-static.test.mjs +3 -3
  56. package/tests/theme-customizer-static.test.mjs +1 -1
  57. package/tests/tui-model-profile-selector.test.mjs +102 -0
  58. package/tests/tui-resource-selector.test.mjs +74 -0
  59. package/tests/webui-settings-locking.test.mjs +32 -1
  60. 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
- readGitWorkflowPreferences(),
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 `/git-staged-msg ${preferences.commit.language} ${preferences.commit.scope}`;
3130
+ return `/${commandName} ${preferences.commit.language} ${preferences.commit.scope}`;
3120
3131
  case "branch":
3121
- return "/git-branch-name";
3132
+ return `/${commandName}`;
3122
3133
  case "pr":
3123
- return `/pr ${preferences.commit.language}`;
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 createGitWorkflowMessageGeneration(tab, generationId) {
3202
- // Keep generation dispatch backward-compatible for tabs whose cwd has not
3203
- // become a repository yet; the Guided Git flow itself still verifies Git
3204
- // state at its staging/review boundaries.
3205
- const root = await getGitRoot(tab.cwd).catch(() => path.resolve(tab.cwd));
3206
- const cwd = gitWorkflowMessageCwd(root, tab.cwd);
3207
- const paths = commitMessagePaths(cwd);
3208
- return {
3209
- id: generationId,
3210
- kind: "commit",
3211
- root,
3212
- cwd,
3213
- createdAt: Date.now(),
3214
- baseline: await readStableGitMessageArtifactPair(paths),
3215
- terminal: false,
3216
- successful: false,
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) throw new Error(response.error || "Guided Git generation prompt was rejected");
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
- return {
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
- record.message = gitWorkflowGenerationPrompt(kind, preferences);
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.messageGeneration = kind === "commit" ? await createGitWorkflowMessageGeneration(tab, record.generationId) : null;
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 messageCwd = path.resolve(String(cwd || root));
7691
- if (!pathInside(root, messageCwd)) throw new Error(`Git workflow cwd must stay inside repository root: ${messageCwd}`);
7692
- return messageCwd;
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 { root, cwd: messageCwd, branchPath, branchRelativePath: branchFile.relativePath, branchRepoRelativePath: branchFile.repoRelativePath, branch, mtimeMs: branchStat.mtimeMs };
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 && !target.startsWith(`${base}${path.sep}`)) throw new Error("Resolved PR description path escapes dev/PR");
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 { root, branch, path: prPath, body: body.trimEnd(), mtimeMs: info.mtimeMs };
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
  }
@@ -8622,7 +8736,7 @@ function applyGitHubPublicationFailure(payload) {
8622
8736
  payload.code = "AUTH";
8623
8737
  payload.hint = "GitHub CLI is not authenticated. Run 'gh auth login' in a terminal, then retry.";
8624
8738
  } else if (/name already exists on this account|repository .+ already exists/.test(text)) {
8625
- payload.hint = "A GitHub repository with this name already exists for the authenticated account. Choose another repository name and retry.";
8739
+ payload.hint = "A GitHub repository with this directory name already exists for the authenticated account. Add that repository as a remote, or rename the local directory before retrying.";
8626
8740
  }
8627
8741
  return payload;
8628
8742
  }
@@ -8773,21 +8887,22 @@ async function handleGitWorkflowRequest(pathname, body = {}, tabOrCwd = options.
8773
8887
  payload.data.protectedBranch = protectedBranch;
8774
8888
  payload.data.forceWithLease = forceWithLease;
8775
8889
  if (remote) payload.data.remote = remote;
8890
+ else payload.data.repoName = path.basename(root);
8776
8891
  }
8777
8892
  return applyGitSyncFailure(payload, { push: true });
8778
8893
  }
8779
8894
  case "/api/git-workflow/publish": {
8780
- const repoName = cleanGitHubRepoName(body.repoName);
8895
+ const root = await getGitRoot(cwd);
8896
+ const repoName = cleanGitHubRepoName(path.basename(root));
8781
8897
  const visibility = String(body.visibility || "").trim();
8782
8898
  if (visibility !== "public" && visibility !== "private") throw makeHttpError(400, "visibility must be 'public' or 'private'");
8783
8899
  requireConfirmed(body, `Publishing GitHub repository ${repoName} as ${visibility}`);
8784
- const root = await getGitRoot(cwd);
8785
8900
  const remotes = await gitRemoteNames(root);
8786
8901
  if (remotes.length) throw makeHttpError(409, "GitHub publication requires a repository with no configured remotes. Existing remotes are not changed or repaired.");
8787
8902
  const branch = await currentGitBranch(root);
8788
8903
  const protectedBranch = PROTECTED_GIT_BRANCHES.has(branch);
8789
8904
  const payload = applyGitHubPublicationFailure(gitWorkflowCommandPayload(await runGitHubWorkflowCommand(
8790
- ["repo", "create", repoName, `--${visibility}`, "--source", root, "--remote", "origin", "--push"],
8905
+ ["repo", "create", repoName, `--${visibility}`, "--source", ".", "--remote", "origin", "--push"],
8791
8906
  { cwd: root, timeoutMs: 15 * 60 * 1000 },
8792
8907
  )));
8793
8908
  if (payload.ok) Object.assign(payload.data, { repoName, visibility, remote: "origin", branch, protectedBranch });
@@ -10068,6 +10183,7 @@ function supervisedTabMetadata(tab, { cwd = tab.cwd } = {}) {
10068
10183
  sessionFile: tabRestorableSessionFile(tab),
10069
10184
  gitWorkspace: tab.gitWorkspace || null,
10070
10185
  createdAt: tab.createdAt,
10186
+ featureSystemPromptDetected: featureSystemPromptDetected(tab),
10071
10187
  };
10072
10188
  }
10073
10189
 
@@ -10219,6 +10335,17 @@ function extensionStatusMap(tab) {
10219
10335
  return tab.extensionStatuses;
10220
10336
  }
10221
10337
 
10338
+ function featureSystemPromptDetected(tab) {
10339
+ const statuses = extensionStatusMap(tab);
10340
+ return [...REPLAYABLE_CLEARED_EXTENSION_STATUS_KEYS].some((statusKey) => statuses.has(statusKey));
10341
+ }
10342
+
10343
+ function restoreFeatureSystemPromptDetection(tab, detected) {
10344
+ if (!detected) return;
10345
+ const statuses = extensionStatusMap(tab);
10346
+ for (const statusKey of REPLAYABLE_CLEARED_EXTENSION_STATUS_KEYS) statuses.set(statusKey, undefined);
10347
+ }
10348
+
10222
10349
  function isGuidedGitWorkflowCommandMessage(message) {
10223
10350
  return GUIDED_GIT_COMMAND_MESSAGE.test(String(message || "").trim());
10224
10351
  }
@@ -10286,8 +10413,12 @@ function extensionWidgetMap(tab) {
10286
10413
  function rememberExtensionStatusEvent(tab, event) {
10287
10414
  if (event?.type !== "extension_ui_request" || event.method !== "setStatus" || !event.statusKey) return;
10288
10415
  const statuses = extensionStatusMap(tab);
10289
- if (event.statusText) statuses.set(String(event.statusKey), String(event.statusText));
10290
- else statuses.delete(String(event.statusKey));
10416
+ const statusKey = String(event.statusKey);
10417
+ const featureWasDetected = featureSystemPromptDetected(tab);
10418
+ if (event.statusText) statuses.set(statusKey, String(event.statusText));
10419
+ else if (REPLAYABLE_CLEARED_EXTENSION_STATUS_KEYS.has(statusKey)) statuses.set(statusKey, undefined);
10420
+ else statuses.delete(statusKey);
10421
+ if (!featureWasDetected && featureSystemPromptDetected(tab)) scheduleSupervisorMetadataUpdate(tab);
10291
10422
  }
10292
10423
 
10293
10424
  function rememberExtensionWidgetEvent(tab, event) {
@@ -11397,6 +11528,7 @@ function attachRpcToTab(tab, rpc) {
11397
11528
  tab.gitWorkflowMessageGeneration = null;
11398
11529
  clearPendingExtensionUiRequests(tab);
11399
11530
  clearExtensionStatuses(tab);
11531
+ scheduleSupervisorMetadataUpdate(tab);
11400
11532
  clearExtensionWidgets(tab);
11401
11533
  clearPendingGuidedGitLaunch(tab);
11402
11534
  clearWebuiSubagents(tab);
@@ -11556,6 +11688,7 @@ async function hydrateManagedTabs(snapshot) {
11556
11688
  gitWorkspace: metadata?.gitWorkspace || null,
11557
11689
  rpc,
11558
11690
  });
11691
+ restoreFeatureSystemPromptDetection(tab, metadata?.featureSystemPromptDetected === true);
11559
11692
  attachRpcToTab(tab, rpc);
11560
11693
  tabs.set(tab.id, tab);
11561
11694
  workspaceFilesLiveWatcher.subscribe(tab.id, tab.cwd);
@@ -15028,28 +15161,29 @@ async function runCloneCommand(tab) {
15028
15161
  });
15029
15162
  }
15030
15163
 
15031
- async function switchTabSession(tab, sessionPath) {
15164
+ async function resumeSessionInNewTab(sourceTab, sessionPath) {
15032
15165
  requirePersistentSessions();
15033
- await requireIdleForSessionAction(tab, "switching sessions");
15034
- const targetPath = resolveTabPath(tab, sessionPath);
15166
+ const targetPath = resolveTabPath(sourceTab, sessionPath);
15035
15167
  if (!targetPath) throw makeHttpError(400, "sessionPath is required");
15036
15168
  if (!targetPath.endsWith(".jsonl")) throw makeHttpError(400, "sessionPath must point to a .jsonl session file");
15037
15169
  requireAllowedSessionPath(targetPath);
15038
15170
  const targetStats = await stat(targetPath).catch(() => null);
15039
15171
  if (!targetStats?.isFile()) throw makeHttpError(404, `Session file not found: ${targetPath}`);
15040
15172
  const manager = SessionManager.open(targetPath, configuredSessionDir());
15041
- const response = await tab.rpc.send({ type: "switch_session", sessionPath: manager.getSessionFile() });
15042
- if (response.success === false) return response;
15043
- if (!response.data?.cancelled) {
15044
- tab.cwd = manager.getCwd();
15045
- scheduleSupervisorMetadataUpdate(tab);
15046
- const state = await safeRpcData(tab, { type: "get_state" }, STATUS_RPC_TIMEOUT_MS);
15047
- if (state.ok) rememberTabState(tab, state.data);
15048
- }
15173
+ const sessionName = manager.getSessionName();
15174
+ const resumedTab = await createTab({
15175
+ title: sessionName ? uniqueTabTitle(sessionName, null) : undefined,
15176
+ titleSource: sessionName ? "explicit" : undefined,
15177
+ conversationStarted: true,
15178
+ cwd: manager.getCwd(),
15179
+ sessionFile: manager.getSessionFile(),
15180
+ });
15049
15181
  return rpcSuccess("switch_session", {
15050
- message: response.data?.cancelled ? "Resume cancelled." : "Resumed selected session.",
15051
- result: response.data,
15052
- tab: tabMeta(tab),
15182
+ message: "Resumed selected session in a new terminal tab.",
15183
+ result: { cancelled: false, sessionFile: manager.getSessionFile() },
15184
+ tab: tabMeta(resumedTab),
15185
+ tabs: listTabs(),
15186
+ sourceTab: tabMeta(sourceTab),
15053
15187
  });
15054
15188
  }
15055
15189
 
@@ -17088,8 +17222,8 @@ const server = createServer(async (req, res) => {
17088
17222
  const body = await readJsonBody(req);
17089
17223
  const tab = getRequestedTab(req, url, body);
17090
17224
  ensureNaturalConversationRouteAllowed(tab, "session switching is blocked");
17091
- const response = await switchTabSession(tab, body.sessionPath || body.path);
17092
- sendJson(res, response.success === false ? 400 : 200, responseWithTab(response, tab));
17225
+ const response = await resumeSessionInNewTab(tab, body.sessionPath || body.path);
17226
+ sendJson(res, response.success === false ? 400 : 200, response);
17093
17227
  return;
17094
17228
  }
17095
17229
 
@@ -17315,7 +17449,8 @@ const server = createServer(async (req, res) => {
17315
17449
 
17316
17450
  if (url.pathname === "/api/git-workflow/preferences" && req.method === "GET") {
17317
17451
  const tab = getRequestedTab(req, url);
17318
- sendJson(res, 200, { ok: true, data: await gitWorkflowPreferencesData(tab) });
17452
+ const includeModels = url.searchParams.get("includeModels") !== "false";
17453
+ sendJson(res, 200, { ok: true, data: await gitWorkflowPreferencesData(tab, { includeModels }) });
17319
17454
  return;
17320
17455
  }
17321
17456
 
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 labels = models.map((model: any) => `${model.provider}/${model.id}${model.name && model.name !== model.id ? ` — ${model.name}` : ""}`);
1027
- const selectedLabel = await ctx.ui.select(`Exact model for ${resourceLabel.toLowerCase()}`, labels);
1028
- if (!selectedLabel) return;
1029
- const selectedIndex = labels.indexOf(selectedLabel);
1030
- const model = models[selectedIndex];
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 selected = await chooseResources(ctx, `${resourceLabel}: toggle resources, then save`, visibleNames, previousNames || []);
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} ${scope.toLowerCase()} saved.`, "info");
1071
+ ctx.ui.notify(`${resourceLabel} ${selectionTarget.toLowerCase()} saved.`, "info");
1082
1072
  }
1083
1073
 
1084
1074
  pi.registerCommand("tools", {