@oh-my-pi/pi-coding-agent 17.3.4 → 17.3.5

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 (121) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/{CHANGELOG-trcc215s.md → CHANGELOG-tt9k4jpr.md} +68 -0
  3. package/dist/cli.js +3146 -3153
  4. package/dist/docs-index.generated.txt +1 -1
  5. package/dist/types/config/model-discovery.d.ts +2 -0
  6. package/dist/types/config/model-registry.d.ts +6 -1
  7. package/dist/types/config/settings-schema.d.ts +10 -0
  8. package/dist/types/debug/report-bundle.d.ts +7 -2
  9. package/dist/types/extensibility/extensions/loader.d.ts +2 -0
  10. package/dist/types/extensibility/extensions/runner.d.ts +3 -3
  11. package/dist/types/extensibility/extensions/types.d.ts +2 -0
  12. package/dist/types/extensibility/legacy-pi-ai-shim.d.ts +4 -0
  13. package/dist/types/launch/presence.d.ts +11 -0
  14. package/dist/types/lsp/client.d.ts +22 -0
  15. package/dist/types/lsp/workspace-diagnostics.d.ts +2 -0
  16. package/dist/types/mcp/config.d.ts +3 -1
  17. package/dist/types/modes/components/tool-execution.d.ts +3 -1
  18. package/dist/types/registry/agent-lifecycle.d.ts +11 -0
  19. package/dist/types/registry/agent-registry.d.ts +4 -0
  20. package/dist/types/session/agent-session-types.d.ts +0 -2
  21. package/dist/types/session/agent-session.d.ts +20 -0
  22. package/dist/types/session/date-cwd-reminder.d.ts +22 -0
  23. package/dist/types/session/irc-bridge.d.ts +2 -0
  24. package/dist/types/session/messages.d.ts +4 -0
  25. package/dist/types/session/session-loader.d.ts +18 -11
  26. package/dist/types/session/session-maintenance.d.ts +6 -2
  27. package/dist/types/session/session-manager.d.ts +19 -3
  28. package/dist/types/session/session-tools.d.ts +0 -1
  29. package/dist/types/session/turn-recovery.d.ts +7 -7
  30. package/dist/types/tools/browser/attach.d.ts +16 -0
  31. package/dist/types/tools/browser/launch.d.ts +2 -2
  32. package/dist/types/tools/browser.d.ts +1 -1
  33. package/dist/types/tools/builtin-names.d.ts +1 -1
  34. package/dist/types/tools/hub/jobs.d.ts +6 -0
  35. package/dist/types/tools/hub/types.d.ts +6 -0
  36. package/dist/types/vibe/runtime.d.ts +3 -3
  37. package/package.json +13 -13
  38. package/src/auto-thinking/classifier.ts +37 -23
  39. package/src/cli/models-cli.ts +1 -1
  40. package/src/commit/analysis/conventional.ts +15 -9
  41. package/src/commit/analysis/summary.ts +15 -9
  42. package/src/commit/changelog/generate.ts +15 -9
  43. package/src/commit/map-reduce/map-phase.ts +3 -19
  44. package/src/commit/map-reduce/reduce-phase.ts +15 -9
  45. package/src/config/model-discovery.ts +3 -3
  46. package/src/config/model-registry.ts +29 -16
  47. package/src/config/settings-schema.ts +13 -0
  48. package/src/debug/report-bundle.ts +25 -59
  49. package/src/discovery/claude-plugins.ts +2 -1
  50. package/src/discovery/claude.ts +4 -2
  51. package/src/discovery/helpers.ts +5 -0
  52. package/src/edit/renderer.ts +48 -19
  53. package/src/extensibility/extensions/loader.ts +9 -5
  54. package/src/extensibility/extensions/runner.ts +124 -21
  55. package/src/extensibility/extensions/types.ts +2 -0
  56. package/src/extensibility/extensions/wrapper.ts +16 -10
  57. package/src/extensibility/legacy-pi-ai-shim.ts +4 -0
  58. package/src/extensibility/plugins/marketplace/manager.ts +15 -18
  59. package/src/irc/bus.ts +1 -1
  60. package/src/launch/broker.ts +8 -1
  61. package/src/launch/presence.ts +77 -1
  62. package/src/lsp/client.ts +35 -3
  63. package/src/lsp/clients/biome-client.ts +47 -93
  64. package/src/lsp/servers.ts +17 -11
  65. package/src/lsp/tool.ts +2 -4
  66. package/src/lsp/workspace-diagnostics.ts +24 -2
  67. package/src/mcp/config.ts +50 -6
  68. package/src/memories/index.ts +29 -25
  69. package/src/mnemopi/backend.ts +13 -11
  70. package/src/modes/components/ask-dialog.ts +25 -5
  71. package/src/modes/components/tool-execution.ts +10 -6
  72. package/src/modes/components/welcome.ts +4 -1
  73. package/src/modes/controllers/extension-ui-controller.ts +52 -32
  74. package/src/modes/controllers/selector-controller.ts +6 -0
  75. package/src/modes/controllers/tan-command-controller.ts +1 -0
  76. package/src/modes/interactive-mode.ts +49 -10
  77. package/src/modes/theme/defaults/birch.json +2 -2
  78. package/src/prompts/system/checkpoint-active-notice.md +5 -0
  79. package/src/prompts/system/date-cwd-reminder.md +3 -0
  80. package/src/prompts/system/project-prompt.md +0 -1
  81. package/src/prompts/system/rewind-report.md +1 -3
  82. package/src/prompts/tools/browser.md +1 -0
  83. package/src/prompts/tools/rewind.md +1 -13
  84. package/src/registry/agent-lifecycle.ts +34 -0
  85. package/src/registry/agent-registry.ts +27 -2
  86. package/src/registry/persisted-agents.ts +40 -20
  87. package/src/sdk.ts +32 -2
  88. package/src/session/agent-session-types.ts +0 -2
  89. package/src/session/agent-session.ts +178 -46
  90. package/src/session/date-cwd-reminder.ts +77 -0
  91. package/src/session/irc-bridge.ts +5 -0
  92. package/src/session/messages.ts +5 -1
  93. package/src/session/session-loader.ts +106 -64
  94. package/src/session/session-maintenance.ts +189 -115
  95. package/src/session/session-manager.ts +142 -35
  96. package/src/session/session-persistence.ts +4 -4
  97. package/src/session/session-storage.ts +18 -5
  98. package/src/session/session-tools.ts +5 -10
  99. package/src/session/turn-recovery.ts +102 -20
  100. package/src/session/unexpected-stop-classifier.ts +33 -21
  101. package/src/system-prompt.ts +0 -5
  102. package/src/task/executor.ts +4 -15
  103. package/src/task/persisted-revive.ts +3 -6
  104. package/src/tools/ask.ts +10 -3
  105. package/src/tools/browser/attach.ts +80 -25
  106. package/src/tools/browser/launch.ts +44 -15
  107. package/src/tools/browser/relay/daemon.ts +3 -7
  108. package/src/tools/browser/render.ts +1 -1
  109. package/src/tools/browser/shared-daemon.ts +3 -7
  110. package/src/tools/browser.ts +5 -5
  111. package/src/tools/builtin-names.ts +7 -3
  112. package/src/tools/checkpoint.ts +1 -7
  113. package/src/tools/hub/index.ts +1 -1
  114. package/src/tools/hub/jobs.ts +20 -3
  115. package/src/tools/hub/types.ts +6 -0
  116. package/src/tools/render-utils.ts +53 -21
  117. package/src/tools/think.ts +15 -3
  118. package/src/tts/speech-enhancer.ts +19 -14
  119. package/src/utils/commit-message-generator.ts +14 -12
  120. package/src/utils/title-generator.ts +23 -19
  121. package/src/vibe/runtime.ts +32 -17
@@ -4,6 +4,7 @@ import {
4
4
  Markdown,
5
5
  type MarkdownTheme,
6
6
  matchesKey,
7
+ padding,
7
8
  renderInlineMarkdown,
8
9
  replaceTabs,
9
10
  ScrollView,
@@ -12,6 +13,7 @@ import {
12
13
  Text,
13
14
  type TUI,
14
15
  truncateToWidth,
16
+ visibleWidth,
15
17
  wrapTextWithAnsi,
16
18
  } from "@oh-my-pi/pi-tui";
17
19
  import type {
@@ -315,8 +317,18 @@ function renderRowLabel(
315
317
  const cursor = selected ? theme.fg("accent", `${theme.nav.cursor} `) : " ";
316
318
  const label = renderInlineMarkdown(rowItem.label, mdTheme, t => theme.fg(color, t));
317
319
  const noteMarker = state.note && state.noteRowKey === rowItem.key ? theme.fg("success", " ✎ note") : "";
318
- const firstLine = `${cursor}${marker}${label}${noteMarker}`;
319
- const lines = [truncateToWidth(firstLine, width, Ellipsis.Unicode)];
320
+ // `width` is already the inner content width consumed by row(); when a
321
+ // scrollbar is needed, renderRows() calls this again with one less column.
322
+ // Keep the cursor, option marker, first wrapped label line, and optional
323
+ // note marker within that budget so the outer fit() never truncates them.
324
+ const noteWidth = noteMarker ? visibleWidth(noteMarker) : 0;
325
+ const labelWidth = Math.max(1, width - visibleWidth(cursor) - visibleWidth(marker) - noteWidth);
326
+ const wrappedLabel = wrapTextWithAnsi(label, labelWidth);
327
+ const indent = padding(visibleWidth(cursor) + visibleWidth(marker));
328
+ const lines = [`${cursor}${marker}${wrappedLabel[0] ?? ""}${noteMarker}`];
329
+ for (let i = 1; i < wrappedLabel.length; i++) {
330
+ lines.push(`${indent}${wrappedLabel[i] ?? ""}`);
331
+ }
320
332
  if (rowItem.kind === "option") {
321
333
  const option = question.options[rowItem.optionIndex ?? -1];
322
334
  if (option?.description?.trim()) {
@@ -602,7 +614,9 @@ export class AskDialogComponent implements Component {
602
614
  return `Enter submit · ↑/↓ scroll ·${scroll} ${cancel}`;
603
615
  }
604
616
  const question = this.#questions[this.#currentQuestionIndex()];
605
- const action = question?.multi ? "Space/Enter toggle · n note" : "Enter select · n note";
617
+ // Enter advances in multi-question dialogs and submits single-question ones.
618
+ const enterAction = this.#questions.length > 1 ? "next" : "submit";
619
+ const action = question?.multi ? `Space toggle · Enter ${enterAction}` : "Enter select · n note";
606
620
  const tabs = this.#hasSubmitTab() ? " · Tab/←/→" : "";
607
621
  if (this.#questionCanPage && indicator) {
608
622
  return `${action} · ↑/↓${tabs} · ${cancel} · ${pageKeysLabel()} ${indicator}`;
@@ -680,8 +694,14 @@ export class AskDialogComponent implements Component {
680
694
  const option = question.options[rowItem.optionIndex ?? -1];
681
695
  if (!option) return;
682
696
  if (question.multi) {
683
- // Multi is toggle-only: Enter and Space both toggle, and the
684
- // answer is confirmed from the Submit tab.
697
+ if (isEnter) {
698
+ // Enter confirms the current selection without toggling the
699
+ // focused option; Space toggles. Advances to the next question
700
+ // (submitting only for a single-question dialog), matching
701
+ // single-select Enter (#8252).
702
+ this.#advanceAfterQuestion();
703
+ return;
704
+ }
685
705
  if (state.selectedOptions.has(option.label)) {
686
706
  state.selectedOptions.delete(option.label);
687
707
  clearNoteIfRow(state, rowItem.key);
@@ -734,10 +734,11 @@ export class ToolExecutionComponent extends Container implements NativeScrollbac
734
734
  * region (a later block streams below it), or — while it is still the
735
735
  * live tail — its head rows were committed because the frame outgrew the
736
736
  * viewport. Committed rows are immutable, so from that point every further
737
- * partial snapshot is dropped. Rows restyle static gray only when nothing
738
- * is committed yet; otherwise the bytes stay exactly as painted. One-way —
739
- * blocks never re-enter the live region. Returns whether the block is
740
- * frozen.
737
+ * partial snapshot is dropped. A hidden, wholly uncommitted block keeps
738
+ * accepting snapshots so revealing it starts from current progress. Rows
739
+ * restyle static gray only when nothing is committed yet; otherwise the
740
+ * bytes stay exactly as painted. One-way — blocks never re-enter the live
741
+ * region. Returns whether the block is frozen.
741
742
  */
742
743
  #maybeFreezeBackgroundTask(): boolean {
743
744
  if (this.#backgroundTaskFrozen) return true;
@@ -745,7 +746,7 @@ export class ToolExecutionComponent extends Container implements NativeScrollbac
745
746
  const asyncState = (this.#result?.details as { async?: { state?: string } } | undefined)?.async?.state;
746
747
  if (asyncState !== "running") return false;
747
748
  const uncommitted = this.#liveRegion.isBlockUncommitted?.(this) ?? true;
748
- if (uncommitted && this.#liveRegion.isBlockInLiveRegion(this)) return false;
749
+ if (uncommitted && (!this.#toolActivityVisible || this.#liveRegion.isBlockInLiveRegion(this))) return false;
749
750
  this.#backgroundTaskFrozen = true;
750
751
  this.#updateSpinnerAnimation();
751
752
  if (uncommitted) {
@@ -825,10 +826,13 @@ export class ToolExecutionComponent extends Container implements NativeScrollbac
825
826
  * Reports `false` while it can still visually change so the
826
827
  * {@link TranscriptContainer} keeps it inside the repaintable live region:
827
828
  * a foreground tool awaiting its result, or one streaming partial output.
829
+ * Hidden blocks render no rows, so they cannot gate later streaming content.
830
+ * Visibility toggles reset and replay the transcript before revealing them.
828
831
  * A final (non-partial) result, a background-async tool the agent has moved
829
- * past, or an explicit {@link seal} flips it to `true`.
832
+ * past, or an explicit {@link seal} also flips it to `true`.
830
833
  */
831
834
  isTranscriptBlockFinalized(): boolean {
835
+ if (!this.#toolActivityVisible) return true;
832
836
  if (this.#sealed) return true;
833
837
  if (this.#result === undefined) return false;
834
838
  // A displaceable snapshot stays live: its rows are kept out of native
@@ -248,7 +248,10 @@ export class WelcomeComponent implements Component {
248
248
  visibleWidth(this.modelName),
249
249
  visibleWidth(this.providerName),
250
250
  );
251
- const desiredLeftCol = Math.min(preferredLeftCol, Math.max(minLeftCol, Math.floor(dualContentWidth * 0.35)));
251
+ const desiredLeftCol = Math.max(
252
+ Math.min(preferredLeftCol, Math.max(minLeftCol, Math.floor(dualContentWidth * 0.35))),
253
+ leftMinContentWidth,
254
+ );
252
255
  const dualLeftCol =
253
256
  dualContentWidth >= minRightCol + 1
254
257
  ? Math.min(desiredLeftCol, dualContentWidth - minRightCol)
@@ -1053,53 +1053,73 @@ export class ExtensionUiController {
1053
1053
  const savedText = this.ctx.editor.getText();
1054
1054
  const keybindings = KeybindingsManager.inMemory();
1055
1055
 
1056
- const { promise, resolve } = Promise.withResolvers<T>();
1056
+ const { promise, resolve, reject } = Promise.withResolvers<T>();
1057
1057
  let component: (Component & { dispose?(): void }) | undefined;
1058
1058
  let overlayHandle: OverlayHandle | undefined;
1059
1059
  let closed = false;
1060
+ let editorReplaced = false;
1060
1061
 
1061
- const close = (result: T) => {
1062
- if (closed) return;
1063
- closed = true;
1062
+ const cleanup = () => {
1064
1063
  component?.dispose?.();
1065
1064
  overlayHandle?.hide();
1066
1065
  overlayHandle = undefined;
1067
- if (!options?.overlay) {
1066
+ if (editorReplaced) {
1068
1067
  this.ctx.editorContainer.clear();
1069
1068
  this.ctx.editorContainer.addChild(this.ctx.editor);
1070
1069
  this.ctx.editor.setText(savedText);
1071
1070
  }
1072
1071
  this.ctx.ui.setFocus(this.ctx.editor);
1073
1072
  this.ctx.ui.requestRender();
1074
- resolve(result);
1075
1073
  };
1076
-
1077
- Promise.try(() => factory(this.ctx.ui, theme, keybindings, close)).then(c => {
1078
- if (closed) {
1079
- c.dispose?.();
1080
- return;
1081
- }
1082
- component = c;
1083
- if (options?.overlay) {
1084
- const overlayOptions =
1085
- typeof options.overlayOptions === "function" ? options.overlayOptions() : options.overlayOptions;
1086
- overlayHandle = this.ctx.ui.showOverlay(
1087
- component,
1088
- overlayOptions ?? {
1089
- anchor: "bottom-center",
1090
- width: "100%",
1091
- maxHeight: "100%",
1092
- margin: 0,
1093
- },
1094
- );
1095
- options.onHandle?.(overlayHandle);
1096
- return;
1074
+ const finish = (settle: () => void) => {
1075
+ if (closed) return;
1076
+ closed = true;
1077
+ options?.signal?.removeEventListener("abort", onAbort);
1078
+ try {
1079
+ cleanup();
1080
+ } finally {
1081
+ settle();
1097
1082
  }
1098
- this.ctx.editorContainer.clear();
1099
- this.ctx.editorContainer.addChild(component);
1100
- this.ctx.ui.setFocus(component);
1101
- this.ctx.ui.requestRender();
1102
- });
1083
+ };
1084
+ const fail = (error: unknown) => finish(() => reject(error));
1085
+ const onAbort = () => fail(options?.signal?.reason ?? new DOMException("Dialog aborted", "AbortError"));
1086
+ const close = (result: T) => finish(() => resolve(result));
1087
+
1088
+ if (options?.signal?.aborted) {
1089
+ fail(options.signal.reason ?? new DOMException("Dialog aborted", "AbortError"));
1090
+ return promise;
1091
+ }
1092
+ options?.signal?.addEventListener("abort", onAbort, { once: true });
1093
+
1094
+ Promise.try(() => factory(this.ctx.ui, theme, keybindings, close))
1095
+ .then(c => {
1096
+ if (closed) {
1097
+ c.dispose?.();
1098
+ return;
1099
+ }
1100
+ component = c;
1101
+ if (options?.overlay) {
1102
+ const overlayOptions =
1103
+ typeof options.overlayOptions === "function" ? options.overlayOptions() : options.overlayOptions;
1104
+ overlayHandle = this.ctx.ui.showOverlay(
1105
+ component,
1106
+ overlayOptions ?? {
1107
+ anchor: "bottom-center",
1108
+ width: "100%",
1109
+ maxHeight: "100%",
1110
+ margin: 0,
1111
+ },
1112
+ );
1113
+ options.onHandle?.(overlayHandle);
1114
+ return;
1115
+ }
1116
+ editorReplaced = true;
1117
+ this.ctx.editorContainer.clear();
1118
+ this.ctx.editorContainer.addChild(component);
1119
+ this.ctx.ui.setFocus(component);
1120
+ this.ctx.ui.requestRender();
1121
+ })
1122
+ .catch(fail);
1103
1123
  return promise;
1104
1124
  }
1105
1125
 
@@ -562,6 +562,12 @@ export class SelectorController {
562
562
  this.ctx.rebuildChatFromMessages();
563
563
  this.ctx.ui.resetDisplay();
564
564
  break;
565
+ case "display.showTokenUsage":
566
+ // Rebuild reruns usage-row detection under the new setting; resetDisplay
567
+ // retires rows already committed to native scrollback.
568
+ this.ctx.rebuildChatFromMessages();
569
+ this.ctx.ui.resetDisplay();
570
+ break;
565
571
  case "tui.tight":
566
572
  setTuiTight(value as boolean);
567
573
  this.ctx.ui.invalidate();
@@ -111,6 +111,7 @@ export class TanCommandController {
111
111
  let jobId = "";
112
112
  try {
113
113
  const cloneManager = await SessionManager.forkFrom(parentFile, cwd, sessionDir, undefined, {
114
+ copyArtifacts: false,
114
115
  suppressBreadcrumb: true,
115
116
  sessionFile: cloneFile,
116
117
  });
@@ -50,6 +50,7 @@ import {
50
50
  logger,
51
51
  postmortem,
52
52
  prompt,
53
+ sanitizeText,
53
54
  setProjectDir,
54
55
  } from "@oh-my-pi/pi-utils";
55
56
  import chalk from "@oh-my-pi/pi-utils/chalk";
@@ -390,16 +391,20 @@ export interface InteractiveModeOptions {
390
391
  /**
391
392
  * Anchored live-region container for the HUD/status rows between the transcript
392
393
  * and the editor (working loader, todo + subagent HUDs, transient notification
393
- * panels). While it has content every row is live: it reports a seam at 0 so the
394
- * engine never commits these anchored, rebuilt-in-place rows to native
395
- * scrollback — otherwise stale duplicates pile up above the live copy on short
396
- * terminals once the loader sits below a tall HUD. The transcript's own seam,
394
+ * panels). While it has content every row is live: it reports a seam at 0 and
395
+ * pins that live region so the engine never commits these anchored,
396
+ * rebuilt-in-place rows to native scrollback — otherwise stale duplicates pile
397
+ * up above the live copy on short terminals once the loader sits below a tall HUD. The transcript's own seam,
397
398
  * when present, sits higher and wins (topmost-seam merge in TUI.render).
398
399
  */
399
400
  class AnchoredLiveContainer extends Container implements NativeScrollbackLiveRegion {
400
401
  getNativeScrollbackLiveRegionStart(): number | undefined {
401
402
  return this.children.length > 0 ? 0 : undefined;
402
403
  }
404
+
405
+ isNativeScrollbackLiveRegionPinned(): boolean {
406
+ return true;
407
+ }
403
408
  }
404
409
 
405
410
  /**
@@ -814,7 +819,7 @@ export class InteractiveMode implements InteractiveModeContext {
814
819
  this.editor.onAutocompleteUpdate = () => {
815
820
  this.ui.requestRender();
816
821
  };
817
- this.editor.setShimmerRepaintHandler(() => this.ui.requestComponentRender(this.editor));
822
+ this.editor.setShimmerRepaintHandler(() => this.ui.requestDirectWrite(this.editor));
818
823
  this.#syncEditorMaxHeight();
819
824
  this.#resizeHandler = () => {
820
825
  this.#syncEditorMaxHeight();
@@ -1108,6 +1113,15 @@ export class InteractiveMode implements InteractiveModeContext {
1108
1113
  // before initHooksAndCustomTools/#reconcileModeFromSession/#enterPlanMode —
1109
1114
  // all of which can reach setSessionName during init.
1110
1115
  this.#eventBusUnsubscribers.push(
1116
+ this.sessionManager.onPersistenceError(error => {
1117
+ const detail = truncateToWidth(
1118
+ replaceTabs(sanitizeText(error.message)).replace(/[\r\n]+/g, " "),
1119
+ TRUNCATE_LENGTHS.LINE,
1120
+ );
1121
+ this.showWarning(
1122
+ `Session persistence failed: ${detail}. Unsaved entries remain in memory; persistence will retry on the next entry.`,
1123
+ );
1124
+ }),
1111
1125
  this.sessionManager.onSessionNameChanged(() => {
1112
1126
  setSessionTerminalTitle(this.sessionManager.getSessionName(), this.sessionManager.getCwd());
1113
1127
  this.#handleSessionAccentInputsChanged();
@@ -1177,6 +1191,9 @@ export class InteractiveMode implements InteractiveModeContext {
1177
1191
 
1178
1192
  this.#eventBusUnsubscribers.push(
1179
1193
  this.session.subscribe(event => {
1194
+ if (event.type === "model_changed") {
1195
+ this.#updateWelcomeModel();
1196
+ }
1180
1197
  void this.#handleGoalSessionEvent(event);
1181
1198
  }),
1182
1199
  onStatusLineSessionAccentChanged(() => {
@@ -1184,6 +1201,11 @@ export class InteractiveMode implements InteractiveModeContext {
1184
1201
  this.#handleSessionAccentInputsChanged();
1185
1202
  }),
1186
1203
  );
1204
+ // Resync the welcome banner to the live model: init-time reconciliations
1205
+ // (#reconcileModeFromSession, #enterPlanMode for plan.defaultOnStartup)
1206
+ // can change the model before this subscription exists, so the
1207
+ // model_changed events they emit are never observed by the handler above.
1208
+ this.#updateWelcomeModel();
1187
1209
  this.#eventBusUnsubscribers.push(
1188
1210
  onModelRolesChanged(() => {
1189
1211
  void this.#reapplyPlanModeModelOnRoleChange();
@@ -3509,10 +3531,18 @@ export class InteractiveMode implements InteractiveModeContext {
3509
3531
  if (!this.vibeModeEnabled) {
3510
3532
  return;
3511
3533
  }
3512
- const ownerScope = this.#vibeModeOwnerScope;
3513
- const killed = await VibeSessionRegistry.global().killAll(this.#vibeParentSession(), ownerScope);
3514
- await this.session.deactivateVibeTools(this.#vibeModePreviousTools ?? []);
3515
- this.session.setVibeModeState(undefined);
3534
+ // Tear down with the queued-message drain suppressed: aborting the active
3535
+ // turn would otherwise let a queued user steer/follow-up restart on the
3536
+ // still-live Vibe tools before this teardown removes them (issue #8326).
3537
+ let killed = 0;
3538
+ await this.session.runModeExitTeardown(async () => {
3539
+ if (this.session.isStreaming) {
3540
+ await this.session.abort();
3541
+ }
3542
+ killed = await VibeSessionRegistry.global().killAll(this.#vibeParentSession(), this.#vibeModeOwnerScope);
3543
+ await this.session.deactivateVibeTools(this.#vibeModePreviousTools ?? []);
3544
+ this.session.setVibeModeState(undefined);
3545
+ });
3516
3546
  this.vibeModeEnabled = false;
3517
3547
  this.#vibeModePreviousTools = undefined;
3518
3548
  this.#vibeModeOwnerScope = undefined;
@@ -4252,7 +4282,7 @@ export class InteractiveMode implements InteractiveModeContext {
4252
4282
  nextEditor.onAutocompleteUpdate = () => {
4253
4283
  this.ui.requestRender();
4254
4284
  };
4255
- nextEditor.setShimmerRepaintHandler(() => this.ui.requestComponentRender(this.editor));
4285
+ nextEditor.setShimmerRepaintHandler(() => this.ui.requestDirectWrite(nextEditor));
4256
4286
  nextEditor.setTopBorderProvider(availableWidth => this.statusLine.getTopBorder(availableWidth));
4257
4287
  nextEditor.setMaxHeight(this.#computeEditorMaxHeight());
4258
4288
  if (this.historyStorage) {
@@ -4430,6 +4460,15 @@ export class InteractiveMode implements InteractiveModeContext {
4430
4460
  );
4431
4461
  }
4432
4462
 
4463
+ #updateWelcomeModel(): void {
4464
+ if (!this.#welcomeComponent) {
4465
+ return;
4466
+ }
4467
+
4468
+ this.#welcomeComponent.setModel(this.session.model?.name ?? "Unknown", this.session.model?.provider ?? "Unknown");
4469
+ this.ui.requestRender();
4470
+ }
4471
+
4433
4472
  #updateWelcomeLspServers(): void {
4434
4473
  if (!this.#welcomeComponent) {
4435
4474
  return;
@@ -33,9 +33,9 @@
33
33
  "thinkingText": "warmGray",
34
34
  "selectedBg": "selectedBg",
35
35
  "userMessageBg": "userMsgBg",
36
- "userMessageText": "",
36
+ "userMessageText": "forestFloor",
37
37
  "customMessageBg": "customMsgBg",
38
- "customMessageText": "",
38
+ "customMessageText": "forestFloor",
39
39
  "customMessageLabel": "#5a7a52",
40
40
  "toolPendingBg": "toolPendingBg",
41
41
  "toolSuccessBg": "toolSuccessBg",
@@ -0,0 +1,5 @@
1
+ <system-notice>
2
+ Exploration checkpoint active.
3
+ - MUST `rewind` with findings once exploration is done.
4
+ - MUST `rewind` before yielding.
5
+ </system-notice>
@@ -0,0 +1,3 @@
1
+ <system-reminder>
2
+ Today: {{date}}; current working directory: '{{cwd}}'. Do not repeat this information in your reply.
3
+ </system-reminder>
@@ -47,7 +47,6 @@ Additional workspace directories. This CURRENT workspace state supersedes worksp
47
47
  {{/each}}
48
48
  </workspace-roots>
49
49
  {{/if}}
50
- Today: {{date}}; current working directory: '{{cwd}}'.
51
50
 
52
51
  <critical>
53
52
  - Each response MUST advance the task; completion only stopping condition.
@@ -1,6 +1,4 @@
1
- Checkpoint: complete; exploratory branch rewound.
2
- Context: branch summary and retained report below.
3
- NEVER call `rewind` again for this checkpoint; continue from retained report.
1
+ Checkpoint called and rewound. Report retained below. Need explore again → new `checkpoint`.
4
2
 
5
3
  Report:
6
4
  {{report}}
@@ -21,6 +21,7 @@ Drives real Chromium tab; full puppeteer access via JS.
21
21
 
22
22
  - `app.path` → NEVER tamper with a real desktop app (no stealth patches).
23
23
  - `app.relay: true` → drive the user's own Chrome tabs via the omp browser relay (auto-started; needs the OMP Browser Relay extension installed). `app.target` picks a tab by URL/title substring; without it the visible tab is adopted without stealing focus.
24
+ - `close` releases the named tool session. It closes tool-owned headless pages and owned cmux surfaces, but NEVER closes pages in CDP-connected or relay browsers. Spawned-browser pages remain open unless `kill: true` terminates their process.
24
25
  - Selectors: CSS + puppeteer `aria/…`, `text/…`, `xpath/…`, `pierce/…`. Playwright-only pseudos (`:has-text()`, `:visible`) are REJECTED.
25
26
  </instruction>
26
27
 
@@ -1,13 +1 @@
1
- End active checkpoint; rewind context to it, replacing intermediate exploration with your report.
2
-
3
- Call immediately after investigative work started by `checkpoint`.
4
-
5
- Requirements:
6
- - `report` MUST be concise, factual, actionable; include key findings, decisions, unresolved risks.
7
- - AVOID raw scratch logs unless essential.
8
- - MUST call before yielding if checkpoint active.
9
-
10
- Behavior:
11
- - No active checkpoint → error. Checkpoint already rewound → continue from retained report; NEVER retry.
12
- - Success → session rewinds, retains your report as context, closes checkpoint.
13
- - Successful rewind final for that checkpoint; repeat calls error.
1
+ End the active checkpoint; rewind context to it, replacing intermediate exploration with your report.
@@ -174,6 +174,40 @@ export class AgentLifecycleManager {
174
174
  );
175
175
  }
176
176
 
177
+ /**
178
+ * Reclaim a provably-dead parked corpse so a fresh spawn can reuse its id.
179
+ * Refuses live, adopted, in-flight, or cold-revivable refs. For a parked ref
180
+ * restored from disk, the persisted factory is consulted before removal
181
+ * because cold revivers are created lazily by {@link ensureLive}.
182
+ *
183
+ * Only refs in the registry this manager owns are touched; the transcript
184
+ * stays readable at `history://<id>`. Returns true when the corpse was
185
+ * unregistered.
186
+ */
187
+ async reclaimDeadCorpse(id: string, expected: AgentRef): Promise<boolean> {
188
+ const ref = this.#registry.get(id);
189
+ if (ref !== expected || ref.status !== "parked" || ref.session) return false;
190
+ if (this.#adopted.has(id) || this.#parks.has(id) || this.#revivals.has(id)) return false;
191
+
192
+ const persistedFactory = ref.sessionFile ? this.#persistedReviverFactory : undefined;
193
+ if (persistedFactory) {
194
+ try {
195
+ if (await persistedFactory(ref)) return false;
196
+ } catch (error) {
197
+ logger.warn("AgentLifecycleManager.reclaimDeadCorpse: persisted reviver probe failed", {
198
+ id,
199
+ error: error instanceof Error ? error.message : String(error),
200
+ });
201
+ return false;
202
+ }
203
+ // The factory awaited I/O; another lifecycle operation may now own or
204
+ // have replaced this ref. Revalidate every reclaim invariant.
205
+ if (this.#registry.get(id) !== ref || ref.status !== "parked" || ref.session) return false;
206
+ if (this.#adopted.has(id) || this.#parks.has(id) || this.#revivals.has(id)) return false;
207
+ }
208
+ return this.#registry.unregister(id, ref);
209
+ }
210
+
177
211
  /**
178
212
  * True when this manager owns `registry` — i.e. its adopt/park/revive state
179
213
  * describes that registry's refs. Lets a caller holding a specific registry
@@ -9,6 +9,7 @@
9
9
  * revival) and are only removed on explicit release/teardown.
10
10
  */
11
11
 
12
+ import { logger } from "@oh-my-pi/pi-utils";
12
13
  import type { AgentSession } from "../session/agent-session";
13
14
  import { oneLineLabel } from "../task/types";
14
15
 
@@ -135,6 +136,11 @@ export class AgentRegistry {
135
136
  return expected === undefined || ref === expected || ref.session === expected;
136
137
  }
137
138
 
139
+ #rejectStatusUpdate(id: string, status: AgentStatus, reason: string): false {
140
+ logger.debug("Agent registry status update rejected", { id, status, reason });
141
+ return false;
142
+ }
143
+
138
144
  register(input: RegisterInput): AgentRef {
139
145
  const now = Date.now();
140
146
  const ref: AgentRef = {
@@ -181,10 +187,15 @@ export class AgentRegistry {
181
187
 
182
188
  setStatus(id: string, status: AgentStatus, expected?: AgentRefExpectation): boolean {
183
189
  const ref = this.#refs.get(id);
184
- if (!ref || !this.#matchesExpected(ref, expected)) return false;
190
+ if (!ref) return this.#rejectStatusUpdate(id, status, "missing-ref");
191
+ if (!this.#matchesExpected(ref, expected)) {
192
+ return this.#rejectStatusUpdate(id, status, "session-ownership-changed");
193
+ }
185
194
  // `aborted` is terminal: delayed progress/revival work from the killed
186
195
  // generation must never transition the tombstone back to a live status.
187
- if (ref.status === "aborted") return status === "aborted";
196
+ if (ref.status === "aborted") {
197
+ return status === "aborted" || this.#rejectStatusUpdate(id, status, "aborted-is-terminal");
198
+ }
188
199
  if (ref.status === status) return true;
189
200
  ref.status = status;
190
201
  // Activity describes current work; it is meaningless once the agent
@@ -270,6 +281,20 @@ export class AgentRegistry {
270
281
  );
271
282
  }
272
283
 
284
+ /** Whether a ref's claimed running state is corroborated by its attached live session. */
285
+ isRunning(ref: AgentRef): boolean {
286
+ if (ref.status !== "running") return false;
287
+ return ref.session?.isStreaming === true;
288
+ }
289
+
290
+ /** Mirror a session's authoritative run-state notifications into its owned registry ref. */
291
+ syncSessionStatus(id: string, session: AgentSession): () => void {
292
+ const unsubscribe = session.subscribeRunState(status => {
293
+ this.setStatus(id, status, session);
294
+ });
295
+ return unsubscribe;
296
+ }
297
+
273
298
  onChange(listener: RegistryListener): () => void {
274
299
  this.#listeners.add(listener);
275
300
  return () => this.#listeners.delete(listener);
@@ -25,6 +25,8 @@ interface PersistedAgentMetadata {
25
25
  createdAt?: number;
26
26
  lastActivity?: number;
27
27
  history?: AgentHistorySummary;
28
+ /** True when the file is only a SessionManager header (no session_init, no messages). */
29
+ incomplete?: boolean;
28
30
  }
29
31
 
30
32
  interface PersistedTranscript {
@@ -244,6 +246,8 @@ async function readPersistedAgentMetadata(sessionFile: string): Promise<Persiste
244
246
  let createdAt: number | undefined;
245
247
  let activity: string | undefined;
246
248
  let history: AgentHistorySummary = {};
249
+ let hasSessionInit = false;
250
+ let hasConversation = false;
247
251
  try {
248
252
  await visitEntriesFromFileStream(
249
253
  sessionFile,
@@ -264,7 +268,12 @@ async function readPersistedAgentMetadata(sessionFile: string): Promise<Persiste
264
268
  }
265
269
  return;
266
270
  }
271
+ if (record.type === "message" || record.type === "custom_message") {
272
+ hasConversation = true;
273
+ return;
274
+ }
267
275
  if (record.type !== "session_init") return;
276
+ hasSessionInit = true;
268
277
  createdAt ??= timestampOf(record.timestamp);
269
278
  if (typeof record.task === "string") activity = summarizePersistedTask(record.task);
270
279
  const inferred = typeof record.systemPrompt === "string" ? inferBundledAgent(record.systemPrompt) : {};
@@ -290,6 +299,7 @@ async function readPersistedAgentMetadata(sessionFile: string): Promise<Persiste
290
299
  activity,
291
300
  createdAt: createdAt ?? file?.birthtimeMs,
292
301
  lastActivity: file?.mtimeMs,
302
+ incomplete: !hasSessionInit && !hasConversation,
293
303
  history: {
294
304
  ...history,
295
305
  ...(hasOutput ? { outputPath } : {}),
@@ -425,26 +435,36 @@ async function registerPersistedSubagentsFromDir(
425
435
  if (!registry.get(id)) {
426
436
  const metadata = await readPersistedAgentMetadata(sessionFile);
427
437
  if (!shouldContinue()) return;
428
- registry.register({
429
- id,
430
- displayName: id,
431
- kind: "sub",
432
- parentId: parentId ?? MAIN_AGENT_ID,
433
- session: null,
434
- sessionFile,
435
- activity: metadata.activity,
436
- createdAt: metadata.createdAt,
437
- lastActivity: metadata.lastActivity,
438
- history: metadata.history,
439
- status: tombstoned ? "aborted" : "parked",
440
- });
441
- const ref = registry.get(id);
442
- transcripts.push({
443
- id,
444
- sessionFile,
445
- createdAt: ref?.createdAt,
446
- lastActivity: ref?.lastActivity,
447
- });
438
+ // Metadata reads yield. A spawn may claim the id while this scan is
439
+ // inspecting the file; never replace that live generation with a
440
+ // transcript-derived parked ref.
441
+ const unclaimed = !registry.get(id);
442
+ // SessionManager.open writes title+session before createAgentSession
443
+ // claims the id. Parking that stub makes the spawn's expectedAgentRef:null
444
+ // CAS fail with "already owned by another session generation".
445
+ if (unclaimed && metadata.incomplete && !tombstoned) continue;
446
+ if (unclaimed) {
447
+ registry.register({
448
+ id,
449
+ displayName: id,
450
+ kind: "sub",
451
+ parentId: parentId ?? MAIN_AGENT_ID,
452
+ session: null,
453
+ sessionFile,
454
+ activity: metadata.activity,
455
+ createdAt: metadata.createdAt,
456
+ lastActivity: metadata.lastActivity,
457
+ history: metadata.history,
458
+ status: tombstoned ? "aborted" : "parked",
459
+ });
460
+ const ref = registry.get(id);
461
+ transcripts.push({
462
+ id,
463
+ sessionFile,
464
+ createdAt: ref?.createdAt,
465
+ lastActivity: ref?.lastActivity,
466
+ });
467
+ }
448
468
  }
449
469
  await registerPersistedSubagentsFromDir(
450
470
  registry,