proper-base 0.2.7 → 0.3.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/README.md CHANGED
@@ -29,7 +29,7 @@ and footer layout.
29
29
 
30
30
  | Input | Behavior |
31
31
  | --- | --- |
32
- | Shift+Enter or Alt+Enter | Insert a newline. Alt+Enter no longer queues a follow-up. |
32
+ | Alt+Enter | Insert a newline instead of queuing a follow-up. Pi's own Shift+Enter and Ctrl+J stay intact. |
33
33
  | Home | Move to the current visible-row start, then the full prompt start. |
34
34
  | End | Move to the current logical-line end, then the full prompt end. |
35
35
  | Ctrl+C with text | Clear the prompt without arming exit. |
@@ -103,6 +103,12 @@ Scrolling away from current output adds a `↓ jump to bottom` row above the
103
103
  prompt. Clicking it returns to the newest output without disabling scrollbar
104
104
  dragging.
105
105
 
106
+ The transcript's top-right corner carries muted `↑` and `↓` arrows that walk
107
+ the viewport between your own prompts. Clicking `↓` past the last prompt scrolls
108
+ to the bottom. While you are scrolled up, a dimmer `position/total` reading sits
109
+ centred under the arrows and counts the prompts in the session; it disappears
110
+ once the viewport is following output again.
111
+
106
112
  ### Clipboard and model image context
107
113
 
108
114
  Ctrl+V and Ctrl+Shift+V both use Pi's image-or-text clipboard action. Readable
@@ -126,6 +132,22 @@ in model context for every tool loop in the turn that introduced them. A later
126
132
  user message replaces older image blocks only in the outbound context copy, so
127
133
  saved sessions, exports, resumes, and branches retain the originals.
128
134
 
135
+ ### Skill context
136
+
137
+ Pi expands `/skill:<name>` into a user message holding the whole `SKILL.md`
138
+ body, then treats it like any other message. Invoking the same skill twice
139
+ therefore sends two full copies, and compaction summarizes the body away while
140
+ the model keeps following instructions it can no longer read.
141
+
142
+ proper-base keeps each invoked skill present exactly once in the outbound
143
+ context. A repeat invocation of an unchanged body keeps its request and shows
144
+ the model a one-line already-loaded note instead of a second copy; a body that
145
+ changed with its arguments is sent in full. After a compaction, the newest body
146
+ of each dropped skill is restored on the first user turn following the summary,
147
+ truncated to a character ceiling per skill and in total so the restored text
148
+ cannot re-trigger the compaction that just ran. Only the outbound copy changes,
149
+ so saved sessions, exports, resumes, and branches retain the originals.
150
+
129
151
  ### Footer
130
152
 
131
153
  The built-in footer keeps path, branch, cumulative input, output, cache, cost,
package/index.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  type ExtensionAPI,
16
16
  type ExtensionContext,
17
17
  getAgentDir,
18
+ SessionManager,
18
19
  } from "@earendil-works/pi-coding-agent";
19
20
 
20
21
  import {
@@ -30,6 +31,11 @@ import {
30
31
  installReverseHistorySearch,
31
32
  type ReverseHistorySearchController,
32
33
  } from "./src/editor-navigation.ts";
34
+ import {
35
+ FastOverlay,
36
+ fastToggleNotice,
37
+ isFastToggle,
38
+ } from "./src/fast-mode.ts";
33
39
  import { installFooterColors } from "./src/footer-colors.ts";
34
40
  import {
35
41
  isRecallable,
@@ -49,7 +55,11 @@ import {
49
55
  createPromptDisplay,
50
56
  PROMPT_DISPLAY_ENTRY,
51
57
  } from "./src/prompt-display.ts";
58
+ import { installPromptJump } from "./src/prompt-jump.ts";
52
59
  import { installRecorder } from "./src/recorder.ts";
60
+ import { installSelectionDismiss } from "./src/selection-dismiss.ts";
61
+ import { installFastSessionList } from "./src/session-list.ts";
62
+ import { pinSkillContext } from "./src/skill-context.ts";
53
63
  import { installSmartSelection } from "./src/smart-selection.ts";
54
64
  import {
55
65
  appendPrompt,
@@ -109,10 +119,11 @@ function installKeybindings(keybindings: EditorKeybindings): void {
109
119
  "ctrl+shift+v" as const,
110
120
  ]),
111
121
  ];
122
+ // Shift+Enter is already Pi's `tui.input.newLine` default; only Alt+Enter
123
+ // needs adding, and only because it must leave `app.message.followUp`.
112
124
  const newLineKeys = [
113
125
  ...new Set([
114
126
  ...keybindings.getKeys("tui.input.newLine"),
115
- "shift+enter" as const,
116
127
  "alt+enter" as const,
117
128
  ]),
118
129
  ];
@@ -160,8 +171,33 @@ type PendingPrompt = {
160
171
  processed: boolean;
161
172
  cancelled: boolean;
162
173
  entryId?: string;
174
+ originId?: string | undefined;
163
175
  };
164
- type RestoreRequest = { entryId: string };
176
+ type RestoreRequest = { entryId: string; originId?: string | undefined };
177
+
178
+ /**
179
+ * Extensions may append transcript entries between submission and the prompt's
180
+ * own session entry; proper-pacify writes one before it rewrites the text. Those
181
+ * entries are the prompt's parents, so navigating to the prompt keeps them and
182
+ * leaves orphan rows behind. Aim at the leaf the submission started from, unless
183
+ * it is a prompt entry of its own (navigating there would drop that turn too) or
184
+ * no longer an ancestor because the tree moved meanwhile.
185
+ */
186
+ function cancelTargetId(
187
+ ctx: ExtensionContext,
188
+ request: RestoreRequest,
189
+ ): string {
190
+ if (!request.originId) return request.entryId;
191
+ const origin = ctx.sessionManager.getEntry(request.originId);
192
+ if (!origin || origin.type === "custom_message") return request.entryId;
193
+ if (origin.type === "message" && origin.message.role === "user") {
194
+ return request.entryId;
195
+ }
196
+ const ancestor = ctx.sessionManager
197
+ .getBranch(request.entryId)
198
+ .some((entry) => entry.id === request.originId);
199
+ return ancestor ? request.originId : request.entryId;
200
+ }
165
201
 
166
202
  /**
167
203
  * `details` shape of the `ask_user_question` tool result, from
@@ -212,17 +248,52 @@ function decodeModelReference(value: string): ModelReference | undefined {
212
248
 
213
249
  export default function (pi: ExtensionAPI) {
214
250
  enableScribeImageCapability();
251
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Session listing]]
252
+ installFastSessionList(SessionManager, getAgentDir());
253
+
254
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Fast tier scopes]]
255
+ const fastOverlay = new FastOverlay(getAgentDir());
256
+ pi.on("before_provider_request", (event, ctx) =>
257
+ fastOverlay.rewritePayload(event.payload, ctx.model ?? undefined),
258
+ );
259
+ pi.registerCommand?.("fast-global", {
260
+ description: "Toggle CLIProxyAPI Fast mode for all sessions.",
261
+ handler: async (args, ctx) => {
262
+ if (args.trim()) {
263
+ ctx.ui.notify("Usage: /fast-global", "error");
264
+ return;
265
+ }
266
+ let enabled: boolean;
267
+ try {
268
+ enabled = fastOverlay.toggleGlobal();
269
+ } catch (error) {
270
+ const message = error instanceof Error ? error.message : String(error);
271
+ ctx.ui.notify(`Failed to save Fast mode: ${message}`, "error");
272
+ return;
273
+ }
274
+ const notice = fastToggleNotice({
275
+ scope: "global",
276
+ enabled,
277
+ otherEnabled: fastOverlay.isSessionEnabled(),
278
+ modelSupported: fastOverlay.supportsModel(ctx.model ?? undefined),
279
+ });
280
+ ctx.ui.notify(notice.message, notice.level);
281
+ },
282
+ });
215
283
 
216
284
  let removeFooterColors: (() => void) | undefined;
217
285
  let removeJumpToBottom: (() => void) | undefined;
286
+ let removePromptJump: (() => void) | undefined;
218
287
  let removePromptClear: (() => void) | undefined;
219
288
  let removeSmartSelection: (() => void) | undefined;
289
+ let removeSelectionDismiss: (() => void) | undefined;
220
290
  let imagePreview: ImagePreviewController | undefined;
221
291
  let removeTerminalInput: (() => void) | undefined;
222
292
  let transcriptCleanup: TranscriptCleanupController | undefined;
223
293
  let activeEditor: PromptEditor | undefined;
224
294
  let activeTui: EditorTui | undefined;
225
295
  let submittedPrompt: string | undefined;
296
+ let submittedOriginId: string | undefined;
226
297
  let pendingPrompt: PendingPrompt | undefined;
227
298
  let restoreRequest: RestoreRequest | undefined;
228
299
  let sessionTitlePending = false;
@@ -296,11 +367,12 @@ export default function (pi: ExtensionAPI) {
296
367
 
297
368
  const target = ctx.sessionManager.getEntry(request.entryId);
298
369
  if (target?.type !== "message" || target.message.role !== "user") return;
370
+ const targetId = cancelTargetId(ctx, request);
299
371
  try {
300
- if (ctx.sessionManager.getLeafId() === request.entryId) {
301
- pi.appendEntry(CANCEL_ANCHOR, { targetId: request.entryId });
372
+ if (ctx.sessionManager.getLeafId() === targetId) {
373
+ pi.appendEntry(CANCEL_ANCHOR, { targetId });
302
374
  }
303
- await ctx.navigateTree(request.entryId, { summarize: false });
375
+ await ctx.navigateTree(targetId, { summarize: false });
304
376
  } catch (error) {
305
377
  ctx.ui.notify(
306
378
  `Could not remove cancelled prompt: ${error instanceof Error ? error.message : String(error)}`,
@@ -326,6 +398,7 @@ export default function (pi: ExtensionAPI) {
326
398
  if (event.source !== "interactive" || !event.text.trim()) return;
327
399
  pendingPrompt = {
328
400
  text: submittedPrompt ?? event.text,
401
+ originId: submittedPrompt ? submittedOriginId : undefined,
329
402
  processed: false,
330
403
  cancelled: false,
331
404
  };
@@ -355,8 +428,12 @@ export default function (pi: ExtensionAPI) {
355
428
  });
356
429
 
357
430
  // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Model image context]]
358
- pi.on("context", (event) => {
359
- const messages = omitPriorTurnImages(event.messages);
431
+ // @lat: [[lat.md/proper-base/lifecycle#Prompt history lifecycle#Skill context]]
432
+ pi.on("context", (event, ctx) => {
433
+ const messages = pinSkillContext(
434
+ omitPriorTurnImages(event.messages),
435
+ ctx.sessionManager.getBranch(),
436
+ );
360
437
  if (messages !== event.messages) return { messages };
361
438
  });
362
439
 
@@ -447,7 +524,7 @@ export default function (pi: ExtensionAPI) {
447
524
  ? ctx.sessionManager.getEntry(candidate.entryId)
448
525
  : findPendingEntry(ctx);
449
526
  if (entry?.type === "message" && entry.message.role === "user") {
450
- restoreRequest = { entryId: entry.id };
527
+ restoreRequest = { entryId: entry.id, originId: candidate.originId };
451
528
  pendingPrompt = undefined;
452
529
  pi.sendUserMessage(`/${CANCEL_PROMPT_COMMAND}`, {
453
530
  expandPromptTemplates: true,
@@ -476,10 +553,14 @@ export default function (pi: ExtensionAPI) {
476
553
  removeFooterColors = undefined;
477
554
  removeJumpToBottom?.();
478
555
  removeJumpToBottom = undefined;
556
+ removePromptJump?.();
557
+ removePromptJump = undefined;
479
558
  removePromptClear?.();
480
559
  removePromptClear = undefined;
481
560
  removeSmartSelection?.();
482
561
  removeSmartSelection = undefined;
562
+ removeSelectionDismiss?.();
563
+ removeSelectionDismiss = undefined;
483
564
  imagePreview?.dispose();
484
565
  imagePreview = undefined;
485
566
  removeTerminalInput?.();
@@ -496,6 +577,8 @@ export default function (pi: ExtensionAPI) {
496
577
  });
497
578
 
498
579
  pi.on("session_start", async (_event, ctx) => {
580
+ // Session Fast never survives into a new or restored session.
581
+ fastOverlay.resetSession();
499
582
  promptDisplay.restore(ctx.sessionManager.getBranch());
500
583
  sessionTitlePending =
501
584
  !pi.getSessionName?.() &&
@@ -560,6 +643,10 @@ export default function (pi: ExtensionAPI) {
560
643
  !sourceText.trimStart().startsWith("!")
561
644
  ) {
562
645
  submittedPrompt = sourceText;
646
+ // Captured here rather than on the `input` event: extensions that
647
+ // wrap Pi's input dispatch have already appended their own entries
648
+ // by the time that event reaches this extension.
649
+ submittedOriginId = ctx.sessionManager.getLeafId() ?? undefined;
563
650
  }
564
651
  };
565
652
 
@@ -578,9 +665,16 @@ export default function (pi: ExtensionAPI) {
578
665
  transcriptCleanup = installTranscriptCleanup(tui, ctx);
579
666
  removeSmartSelection?.();
580
667
  removeSmartSelection = installSmartSelection(tui);
668
+ removeSelectionDismiss?.();
669
+ removeSelectionDismiss = installSelectionDismiss(tui);
581
670
  historyGuard = installHistoryGuard(editor);
582
671
  removeJumpToBottom?.();
583
672
  removeJumpToBottom = installJumpToBottom(editor, tui);
673
+ removePromptJump?.();
674
+ removePromptJump = installPromptJump(tui, {
675
+ color: (value) => ctx.ui.theme.fg("muted", value),
676
+ subtle: (value) => ctx.ui.theme.fg("dim", value),
677
+ });
584
678
  imagePreview?.dispose();
585
679
  imagePreview = installImagePreview(editor, tui, {
586
680
  fallbackColor: (value) => ctx.ui.theme.fg("dim", value),
@@ -592,6 +686,20 @@ export default function (pi: ExtensionAPI) {
592
686
  editor,
593
687
  record,
594
688
  (text) => imagePreview?.prepare(text) ?? text,
689
+ // pi dispatches extension commands before the `input` event, so the
690
+ // provider's global `/fast` can only be repurposed as a session
691
+ // toggle by consuming it at the editor before pi ever parses it.
692
+ (text) => {
693
+ if (!isFastToggle(text)) return false;
694
+ const notice = fastToggleNotice({
695
+ scope: "session",
696
+ enabled: fastOverlay.toggleSession(),
697
+ otherEnabled: fastOverlay.isGlobalEnabled(),
698
+ modelSupported: fastOverlay.supportsModel(ctx.model ?? undefined),
699
+ });
700
+ ctx.ui.notify(notice.message, notice.level);
701
+ return true;
702
+ },
595
703
  );
596
704
  installModelAutocompleteSubmit(editor, keybindings);
597
705
  removePromptClear?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proper-base",
3
- "version": "0.2.7",
3
+ "version": "0.3.0",
4
4
  "description": "Baseline Pi behavior for session naming, history, prompt editing, fullscreen navigation, and footer styling",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -19,6 +19,16 @@ const INLINE_SLASH_INSTALLED = Symbol.for(
19
19
  "pi-proper-base.inline-slash-autocomplete",
20
20
  );
21
21
 
22
+ /**
23
+ * One collator for the `/model` sort. `localeCompare` with an options object
24
+ * constructs a collator per call, which the per-keystroke sort would pay
25
+ * hundreds of times per keypress.
26
+ */
27
+ const MODEL_ORDER = new Intl.Collator("en", {
28
+ numeric: true,
29
+ sensitivity: "base",
30
+ });
31
+
22
32
  type AutocompleteEditor = Component & {
23
33
  autocompleteList?: {
24
34
  getSelectedItem(): { description?: string } | null;
@@ -192,10 +202,8 @@ export function sortModelAutocompleteDescending(
192
202
  ...suggestions,
193
203
  items: [...items].sort(
194
204
  (a, b) =>
195
- b.label.localeCompare(a.label, "en", {
196
- numeric: true,
197
- sensitivity: "base",
198
- }) || b.value.localeCompare(a.value),
205
+ MODEL_ORDER.compare(b.label, a.label) ||
206
+ b.value.localeCompare(a.value),
199
207
  ),
200
208
  };
201
209
  },
@@ -335,9 +343,17 @@ export function installAutocompleteDetails(
335
343
  const render = target.render.bind(target);
336
344
  target.render = (width: number) => {
337
345
  const lines = render(width);
346
+ // rowsBelow re-renders every component below the editor, so frames
347
+ // without a selected description skip the measurement entirely.
348
+ const description = target.autocompleteList?.getSelectedItem()?.description;
349
+ if (!description) {
350
+ detail.setDescription(undefined, 0);
351
+ releaseOverlay();
352
+ return lines;
353
+ }
338
354
  margin.bottom = lines.length + rowsBelow(tui, target, width);
339
355
  detail.setDescription(
340
- target.autocompleteList?.getSelectedItem()?.description,
356
+ description,
341
357
  Math.max(0, tui.terminal.rows - margin.bottom),
342
358
  );
343
359
  if (detail.isVisible() && isMounted(tui, target)) ensureOverlay();
@@ -0,0 +1,210 @@
1
+ import { readFileSync, statSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ const CONFIG_FILE_NAME = "cliproxyapi.json";
5
+ const MODELS_CACHE_FILE_NAME = "cliproxyapi-models.json";
6
+ const DEFAULT_PROVIDER_ID = "cliproxyapi";
7
+ const PRIORITY_TIER = "priority";
8
+ const FAST_COMMAND = "/fast";
9
+
10
+ type JsonObject = Record<string, unknown>;
11
+
12
+ /** The request-model fields this module reads. */
13
+ export type FastModel = { provider: string; id: string };
14
+
15
+ export type FastNotice = { message: string; level: "info" | "warning" };
16
+
17
+ function readJsonObject(path: string): JsonObject | undefined {
18
+ try {
19
+ const parsed: unknown = JSON.parse(readFileSync(path, "utf8"));
20
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed)
21
+ ? (parsed as JsonObject)
22
+ : undefined;
23
+ } catch {
24
+ return undefined;
25
+ }
26
+ }
27
+
28
+ /** Mirror of the provider's boolean-setting grammar for `CLIPROXYAPI_FAST`. */
29
+ function parseBooleanSetting(value: string): boolean | undefined {
30
+ switch (value.trim().toLowerCase()) {
31
+ case "1":
32
+ case "true":
33
+ case "yes":
34
+ case "on":
35
+ return true;
36
+ case "0":
37
+ case "false":
38
+ case "no":
39
+ case "off":
40
+ return false;
41
+ default:
42
+ return undefined;
43
+ }
44
+ }
45
+
46
+ /** Whether submitted editor text is exactly the `/fast` toggle. */
47
+ export function isFastToggle(text: string): boolean {
48
+ return text.trim() === FAST_COMMAND;
49
+ }
50
+
51
+ /**
52
+ * Session and global Fast preferences layered over the CLIProxyAPI provider.
53
+ *
54
+ * The provider's own `/fast` persists one flag and refreshes it only at
55
+ * extension load, so it is neither session-scoped nor live across sessions.
56
+ * This overlay owns the final `service_tier` decision instead: the session
57
+ * flag lives in memory and dies with the session, while the global flag is
58
+ * the provider's persisted `fast` key, re-read on every request so a toggle
59
+ * in one session reaches every running session's next request.
60
+ */
61
+ export class FastOverlay {
62
+ private sessionEnabled = false;
63
+ private modelsCache: { mtimeMs: number; ids: Set<string> } | undefined;
64
+ private readonly agentDir: string;
65
+ private readonly env: Record<string, string | undefined>;
66
+
67
+ constructor(
68
+ agentDir: string,
69
+ env: Record<string, string | undefined> = process.env,
70
+ ) {
71
+ this.agentDir = agentDir;
72
+ this.env = env;
73
+ }
74
+
75
+ private configPath(): string {
76
+ return join(this.agentDir, CONFIG_FILE_NAME);
77
+ }
78
+
79
+ /** Session Fast is never persisted; a new session always starts off. */
80
+ resetSession(): void {
81
+ this.sessionEnabled = false;
82
+ }
83
+
84
+ isSessionEnabled(): boolean {
85
+ return this.sessionEnabled;
86
+ }
87
+
88
+ toggleSession(): boolean {
89
+ this.sessionEnabled = !this.sessionEnabled;
90
+ return this.sessionEnabled;
91
+ }
92
+
93
+ /**
94
+ * The provider's Fast default: `CLIPROXYAPI_FAST` when set, else the
95
+ * persisted `fast` key. Re-read per call so other sessions' writes count.
96
+ */
97
+ isGlobalEnabled(): boolean {
98
+ const envValue = this.env.CLIPROXYAPI_FAST;
99
+ if (envValue !== undefined) {
100
+ const parsed = parseBooleanSetting(envValue);
101
+ if (parsed !== undefined) return parsed;
102
+ }
103
+ return readJsonObject(this.configPath())?.fast === true;
104
+ }
105
+
106
+ /**
107
+ * Flip the persisted global flag, preserving every other config key and
108
+ * the provider's own file format. Write failures propagate to the caller.
109
+ */
110
+ toggleGlobal(): boolean {
111
+ const existing = readJsonObject(this.configPath()) ?? {};
112
+ const next = !this.isGlobalEnabled();
113
+ writeFileSync(
114
+ this.configPath(),
115
+ `${JSON.stringify({ ...existing, fast: next }, null, 2)}\n`,
116
+ "utf8",
117
+ );
118
+ return next;
119
+ }
120
+
121
+ /** The configured provider id the overlay scopes itself to. */
122
+ providerId(): string {
123
+ const envId = this.env.CLIPROXYAPI_PROVIDER_ID?.trim();
124
+ if (envId) return envId;
125
+ const fileId = readJsonObject(this.configPath())?.providerId;
126
+ return typeof fileId === "string" && fileId.trim()
127
+ ? fileId.trim()
128
+ : DEFAULT_PROVIDER_ID;
129
+ }
130
+
131
+ /** Whether the provider's cached catalog marks this model Fast-capable. */
132
+ supportsModel(model: FastModel | undefined): boolean {
133
+ if (!model || model.provider !== this.providerId()) return false;
134
+ const path = join(this.agentDir, MODELS_CACHE_FILE_NAME);
135
+ let mtimeMs: number;
136
+ try {
137
+ mtimeMs = statSync(path).mtimeMs;
138
+ } catch {
139
+ this.modelsCache = undefined;
140
+ return false;
141
+ }
142
+ if (this.modelsCache?.mtimeMs !== mtimeMs) {
143
+ const ids = readJsonObject(path)?.fastModelIds;
144
+ this.modelsCache = {
145
+ mtimeMs,
146
+ ids: new Set(
147
+ Array.isArray(ids)
148
+ ? ids.filter((id): id is string => typeof id === "string")
149
+ : [],
150
+ ),
151
+ };
152
+ }
153
+ return this.modelsCache.ids.has(model.id);
154
+ }
155
+
156
+ /**
157
+ * The replacement payload for pi's `before_provider_request`, or
158
+ * `undefined` to keep it. Adds `service_tier` when Fast is on for a
159
+ * capable model of this provider, and strips a priority tier the
160
+ * provider's stale in-memory flag injected when Fast is off, so a global
161
+ * toggle takes effect on every running session's next request.
162
+ */
163
+ rewritePayload(payload: unknown, model: FastModel | undefined): unknown {
164
+ if (!model || model.provider !== this.providerId()) return undefined;
165
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
166
+ return undefined;
167
+ }
168
+ const record = payload as JsonObject;
169
+ const effective = this.sessionEnabled || this.isGlobalEnabled();
170
+ if (effective && this.supportsModel(model)) {
171
+ if (record.service_tier === PRIORITY_TIER) return undefined;
172
+ return { ...record, service_tier: PRIORITY_TIER };
173
+ }
174
+ if (!effective && record.service_tier === PRIORITY_TIER) {
175
+ const { service_tier: _dropped, ...rest } = record;
176
+ return rest;
177
+ }
178
+ return undefined;
179
+ }
180
+ }
181
+
182
+ /** User-facing toggle feedback shared by `/fast` and `/fast-global`. */
183
+ export function fastToggleNotice(options: {
184
+ scope: "session" | "global";
185
+ enabled: boolean;
186
+ otherEnabled: boolean;
187
+ modelSupported: boolean;
188
+ }): FastNotice {
189
+ const { scope, enabled, otherEnabled, modelSupported } = options;
190
+ const where =
191
+ scope === "session" ? "for this session" : "globally for all sessions";
192
+ if (!enabled) {
193
+ const residual = otherEnabled
194
+ ? scope === "session"
195
+ ? " Global Fast mode is still on."
196
+ : " This session's Fast mode is still on."
197
+ : "";
198
+ return {
199
+ message: `Fast mode disabled ${where}.${residual}`,
200
+ level: "info",
201
+ };
202
+ }
203
+ if (!modelSupported) {
204
+ return {
205
+ message: `Fast mode enabled ${where}, but the current model does not support it.`,
206
+ level: "warning",
207
+ };
208
+ }
209
+ return { message: `Fast mode enabled ${where}.`, level: "info" };
210
+ }
@@ -502,7 +502,11 @@ export function installImagePreview(
502
502
  target.render = (width: number) => {
503
503
  const lines = render.call(target, width);
504
504
  sync(target.getText?.() ?? "");
505
- margin.bottom = lines.length + rowsBelow(tui, target, width);
505
+ // rowsBelow re-renders every component below the editor, so frames
506
+ // without a visible preview skip the measurement entirely.
507
+ if (isVisible()) {
508
+ margin.bottom = lines.length + rowsBelow(tui, target, width);
509
+ }
506
510
  return lines;
507
511
  };
508
512
  target[INSTALLED] = controller;
@@ -38,7 +38,7 @@ function scrollableTui(tui: TUI): ScrollableTui | undefined {
38
38
  * respond to the mouse; if that internal field ever changes shape the button
39
39
  * keeps rendering and simply stops reacting.
40
40
  */
41
- function prioritize(tui: TUI, listener: TuiInputListener): void {
41
+ export function prioritize(tui: TUI, listener: TuiInputListener): void {
42
42
  const listeners = (tui as ListenerHost).inputListeners;
43
43
  if (!listeners?.has(listener)) return;
44
44
  const rest = [...listeners].filter((entry) => entry !== listener);