@bismawy/pi-arnative 0.18.2 → 0.19.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.
@@ -19,7 +19,7 @@ import { boxRow, createHoldRepeat, inSpans, type BoxTheme, type HoldRepeat, type
19
19
  import { chatboxPrimaryPaint } from "../chatbox.ts";
20
20
  import { patchOnce } from "../patch.ts";
21
21
  import { TOOL_LAYOUT_KEY, choiceSetting } from "../preset-store.ts";
22
- import { expandedBoxBodyLimit, fmtMs, getToolTiming, paintScrollEdge, shortPath, spinIcon } from "./tools.ts";
22
+ import { activeEditDiff, expandedBoxBodyLimit, fmtMs, getToolTiming, shortPath, spinIcon, tallBoxBottomHideThreshold, type EditDiffMode } from "./tools.ts";
23
23
 
24
24
  export type ToolLayoutMode = "Grouped" | "Classic";
25
25
  export const TOOL_LAYOUT_CHOICES: readonly ToolLayoutMode[] = ["Grouped", "Classic"];
@@ -249,8 +249,6 @@ function isSilentIntermediateAssistant(child: unknown): child is AssistantLike {
249
249
  const TEST_TOOL_MARKER = Symbol.for("pi-arnative.testTool");
250
250
  const TEST_ASSISTANT_MARKER = Symbol.for("pi-arnative.testAssistant");
251
251
  const PROGRESS_BOX_MARKER = Symbol.for("pi-arnative.turnProgressBox");
252
- const SCROLL_HOLD_KEY = Symbol.for("pi-arnative.toolBoxScrollHold");
253
- const SCROLL_OFFSET_KEY = Symbol.for("pi-arnative.toolBoxScrollOffset");
254
252
 
255
253
  export function isProgressBox(child: unknown): child is TurnProgressBoxComponent {
256
254
  return Boolean(child && typeof child === "object" && (child as Record<symbol, unknown>)[PROGRESS_BOX_MARKER] === true);
@@ -714,8 +712,20 @@ function renderTopBorder(
714
712
  return truncateToWidth(raw, width, "");
715
713
  }
716
714
 
717
- function renderBottomBorder(width: number, dim: (s: string) => string): string {
718
- return dim(`╰${"─".repeat(Math.max(0, width - 2))}╯`);
715
+ function renderBottomBorder(
716
+ width: number,
717
+ dim: (s: string) => string,
718
+ centerStyled = "",
719
+ ): string {
720
+ const plain = dim(`╰${"─".repeat(Math.max(0, width - 2))}╯`);
721
+ if (width < 6 || !centerStyled) return plain;
722
+ const inner = width - 2;
723
+ const labelW = visibleWidth(centerStyled);
724
+ if (inner < labelW + 4) return plain;
725
+ const totalDashes = inner - (labelW + 2);
726
+ const leftDashes = Math.floor(totalDashes / 2);
727
+ const rightDashes = totalDashes - leftDashes;
728
+ return `${dim(`╰${"─".repeat(leftDashes)} `)}${centerStyled}${dim(` ${"─".repeat(rightDashes)}╯`)}`;
719
729
  }
720
730
 
721
731
  function frameRowExact(content: string, dim: (s: string) => string): string {
@@ -763,11 +773,13 @@ export class TurnProgressBoxComponent {
763
773
  private requestRender?: () => void;
764
774
  private detailRenderCache = new WeakMap<
765
775
  object,
766
- { width: number; result: unknown; expanded: boolean; scrollOffset: number; lines: string[] }
776
+ { width: number; result: unknown; expanded: boolean; editDiff: EditDiffMode; lines: string[] }
767
777
  >();
768
778
  private frameCache: {
769
779
  width: number;
770
780
  maxBody: number;
781
+ bottomHideThreshold: number;
782
+ editDiff: EditDiffMode;
771
783
  theme: unknown;
772
784
  spin: string;
773
785
  interactionVersion: number;
@@ -865,25 +877,15 @@ export class TurnProgressBoxComponent {
865
877
  for (const item of this.items) {
866
878
  if (isToolComponent(item)) {
867
879
  if (item.isPartial || !item.result) return true;
868
- if ((item as unknown as Record<symbol, unknown>)[SCROLL_HOLD_KEY] !== undefined) return true;
869
880
  }
870
881
  if (isIntermediateAssistant(item) && item.isStreaming) return true;
871
882
  }
872
883
  return false;
873
884
  }
874
885
 
875
- /** 32-bit FNV-1a scroll offset hash across the box viewport and contained tools so render-cache detects scroll ticks at any turn length. */
886
+ /** Current box viewport scroll offset so render-cache detects scroll ticks. */
876
887
  getScrollSignature(): number {
877
- let sig = 0x811c9dc5 | 0;
878
- const ownOffset = this.state.scrollOffset == null ? -1 : this.state.scrollOffset | 0;
879
- sig = Math.imul(sig ^ ownOffset, 0x01000193) | 0;
880
- for (const item of this.items) {
881
- if (isToolComponent(item)) {
882
- const offset = Number((item as unknown as Record<symbol, unknown>)[SCROLL_OFFSET_KEY] ?? 0) | 0;
883
- sig = Math.imul(sig ^ offset, 0x01000193) | 0;
884
- }
885
- }
886
- return sig;
888
+ return this.state.scrollOffset == null ? -1 : this.state.scrollOffset | 0;
887
889
  }
888
890
 
889
891
  invalidate(): void {
@@ -905,11 +907,9 @@ export class TurnProgressBoxComponent {
905
907
  (this.isDetailOpen(item) ? 8 : 0) |
906
908
  (item.hideComponent ? 16 : 0);
907
909
  const dur = Math.trunc(durationMsOf(item));
908
- const off = Number((item as unknown as Record<symbol, unknown>)[SCROLL_OFFSET_KEY] ?? 0) | 0;
909
910
  const contentLen = Array.isArray(item.result?.content) ? item.result.content.length : 0;
910
911
  sig = Math.imul(sig ^ flags, 0x01000193) | 0;
911
912
  sig = Math.imul(sig ^ dur, 0x01000193) | 0;
912
- sig = Math.imul(sig ^ off, 0x01000193) | 0;
913
913
  sig = Math.imul(sig ^ contentLen, 0x01000193) | 0;
914
914
  } else if (isIntermediateAssistant(item)) {
915
915
  sig = Math.imul(sig ^ (item.isStreaming ? 3 : 1), 0x01000193) | 0;
@@ -958,6 +958,8 @@ export class TurnProgressBoxComponent {
958
958
  if (width < 8) return [];
959
959
  const th = getActiveTheme<BoxTheme>();
960
960
  const maxBody = expandedBoxBodyLimit();
961
+ const bottomHideThreshold = tallBoxBottomHideThreshold();
962
+ const editDiff = activeEditDiff();
961
963
  const spin = spinIcon();
962
964
  const itemsSig = this.computeItemsSig();
963
965
  const autoHoldOpen = Boolean(this.state.autoHoldOpen);
@@ -966,6 +968,8 @@ export class TurnProgressBoxComponent {
966
968
  fc &&
967
969
  fc.width === width &&
968
970
  fc.maxBody === maxBody &&
971
+ fc.bottomHideThreshold === bottomHideThreshold &&
972
+ fc.editDiff === editDiff &&
969
973
  fc.theme === th &&
970
974
  fc.spin === spin &&
971
975
  fc.interactionVersion === this.state.interactionVersion &&
@@ -1040,6 +1044,8 @@ export class TurnProgressBoxComponent {
1040
1044
  this.frameCache = {
1041
1045
  width,
1042
1046
  maxBody,
1047
+ bottomHideThreshold,
1048
+ editDiff,
1043
1049
  theme: th,
1044
1050
  spin,
1045
1051
  interactionVersion: this.state.interactionVersion,
@@ -1169,7 +1175,6 @@ export class TurnProgressBoxComponent {
1169
1175
 
1170
1176
  const indentCols = 2 + visibleWidth(detailIndent); // `│ ` + detailIndent
1171
1177
  const detailWidth = Math.max(16, width - indentCols - 2);
1172
- const toolScroll = Number((tool as unknown as Record<symbol, unknown>)[SCROLL_OFFSET_KEY] ?? 0);
1173
1178
  const cachedDetail = !toolRunning ? this.detailRenderCache.get(tool) : undefined;
1174
1179
  let rawDetail: readonly string[];
1175
1180
  if (
@@ -1177,7 +1182,7 @@ export class TurnProgressBoxComponent {
1177
1182
  cachedDetail.width === detailWidth &&
1178
1183
  cachedDetail.result === tool.result &&
1179
1184
  cachedDetail.expanded === detailOpen &&
1180
- cachedDetail.scrollOffset === toolScroll
1185
+ cachedDetail.editDiff === editDiff
1181
1186
  ) {
1182
1187
  rawDetail = cachedDetail.lines;
1183
1188
  } else {
@@ -1187,7 +1192,7 @@ export class TurnProgressBoxComponent {
1187
1192
  width: detailWidth,
1188
1193
  result: tool.result,
1189
1194
  expanded: detailOpen,
1190
- scrollOffset: toolScroll,
1195
+ editDiff,
1191
1196
  lines: [...rawDetail],
1192
1197
  });
1193
1198
  }
@@ -1213,9 +1218,15 @@ export class TurnProgressBoxComponent {
1213
1218
  }
1214
1219
  }
1215
1220
 
1216
- // Cap tall boxes with the same adaptive viewport limit and `↑/↓ N more` border
1217
- // affordances used by chatbox and expanded tool boxes.
1218
- const maxOffset = Math.max(0, bodyLines.length - maxBody);
1221
+ // Cap tall step lists with the adaptive viewport limit and `↑/↓ N more` border
1222
+ // affordances, while giving any explicitly opened `[show]` tool detail full vertical
1223
+ // room so results are never clipped by the outer Progress frame.
1224
+ let openDetailLines = 0;
1225
+ for (const d of logicalDetails) {
1226
+ openDetailLines += d.endBodyRow - d.startBodyRow + 1;
1227
+ }
1228
+ const effectiveMaxBody = maxBody + openDetailLines;
1229
+ const maxOffset = Math.max(0, bodyLines.length - effectiveMaxBody);
1219
1230
  let offset = 0;
1220
1231
  if (maxOffset === 0) {
1221
1232
  this.stopScrollHold();
@@ -1230,7 +1241,7 @@ export class TurnProgressBoxComponent {
1230
1241
  offset = maxOffset;
1231
1242
  }
1232
1243
 
1233
- const visibleBody = maxOffset > 0 ? bodyLines.slice(offset, offset + maxBody) : bodyLines;
1244
+ const visibleBody = maxOffset > 0 ? bodyLines.slice(offset, offset + effectiveMaxBody) : bodyLines;
1234
1245
  const above = offset;
1235
1246
  const below = bodyLines.length - (offset + visibleBody.length);
1236
1247
  const aboveLabel = above > 0 ? `\u2191 ${above} more` : "";
@@ -1239,12 +1250,18 @@ export class TurnProgressBoxComponent {
1239
1250
 
1240
1251
  // Leading spacer separates the progress box cleanly from the preceding user bubble.
1241
1252
  const topLine = renderTopBorder(width, headerLeft, aboveLabel ? scrollPaint(aboveLabel) : "", headerRight, dim);
1242
- const plainBot = renderBottomBorder(width, dim);
1243
- const botLine = belowLabel ? paintScrollEdge(plainBot, "╰", "╯", belowLabel, width, dim, scrollPaint) : plainBot;
1253
+ const showBottomHide = visibleBody.length + 2 > bottomHideThreshold;
1254
+ const botCenter = [belowLabel ? scrollPaint(belowLabel) : "", showBottomHide ? dim(HIDE_LABEL) : ""]
1255
+ .filter(Boolean)
1256
+ .join(` ${dim("·")} `);
1257
+ const botLine = renderBottomBorder(width, dim, botCenter);
1244
1258
  const lines: string[] = ["", topLine, ...visibleBody, botLine];
1245
1259
  const botRow = lines.length - 1;
1246
1260
 
1247
- const headerBoxToggleSpans = buttonSpan(topLine, 1, HIDE_LABEL, width - 1);
1261
+ const headerBoxToggleSpans = [
1262
+ ...buttonSpan(topLine, 1, HIDE_LABEL, width - 1),
1263
+ ...(showBottomHide ? buttonSpan(botLine, botRow, HIDE_LABEL, width - 1) : []),
1264
+ ];
1248
1265
  const headerToggleSpans = showAllToggle ? buttonSpan(topLine, 1, toggleText, width - 1) : [];
1249
1266
  const scrollUpSpans = aboveLabel ? buttonSpan(topLine, 1, aboveLabel, width - 1) : [];
1250
1267
  const scrollDownSpans = belowLabel ? buttonSpan(botLine, botRow, belowLabel, width - 1) : [];
@@ -1282,7 +1299,7 @@ export class TurnProgressBoxComponent {
1282
1299
 
1283
1300
  this.lastHitMap = {
1284
1301
  width,
1285
- maxBody,
1302
+ maxBody: effectiveMaxBody,
1286
1303
  boxExpanded: true,
1287
1304
  summaryRow: null,
1288
1305
  headerBoxToggleSpans,
@@ -1300,6 +1317,8 @@ export class TurnProgressBoxComponent {
1300
1317
  this.frameCache = {
1301
1318
  width,
1302
1319
  maxBody,
1320
+ bottomHideThreshold,
1321
+ editDiff,
1303
1322
  theme: th,
1304
1323
  spin,
1305
1324
  interactionVersion: this.state.interactionVersion,
@@ -9,7 +9,7 @@
9
9
  * - Known, settled transcript children inside `chatContainer` cache their `render(width)` output
10
10
  * and reuse it until `width` changes, `rows` changes (for expanded tool boxes), the
11
11
  * session/model resets, or the component mutates (`invalidate`, `updateContent`,
12
- * `updateDisplay`, `setExpanded`, `handleMouse`, `SCROLL_OFFSET`, etc.).
12
+ * `updateDisplay`, `setExpanded`, `handleMouse`, etc.).
13
13
  * - Active components (`isStreaming`, `isPartial`, `argsPending`, `status === "running"`,
14
14
  * active thinking dot animation, or active hold-scroll) always render fresh, while all
15
15
  * earlier settled history hits the per-child cache in O(1).
@@ -34,11 +34,7 @@ import {
34
34
  import { Text } from "@earendil-works/pi-tui";
35
35
  import { patchOnce } from "../patch.ts";
36
36
  import { RENDER_CACHE_KEY, choiceSetting } from "../preset-store.ts";
37
- import {
38
- TOOL_BOX_SCROLL_HOLD_KEY as SCROLL_HOLD_KEY,
39
- TOOL_BOX_SCROLL_OFFSET_KEY as SCROLL_OFFSET_KEY,
40
- getRuntime,
41
- } from "../runtime.ts";
37
+ import { getRuntime } from "../runtime.ts";
42
38
  import {
43
39
  activeToolLayout,
44
40
  isProgressBox,
@@ -174,6 +170,7 @@ export function clearRenderCache(): void {
174
170
  state.epoch += 1;
175
171
  state.childCache = new WeakMap();
176
172
  state.containerCache = new WeakMap();
173
+ state.dynamicFrameCache = new WeakMap();
177
174
  }
178
175
 
179
176
  function findWidthEntry<T extends { width: number }>(
@@ -225,7 +222,6 @@ export function isDynamicChild(child: unknown): boolean {
225
222
  if (c.isStreaming === true) return true;
226
223
  if (c.isPartial === true || c.argsPending === true) return true;
227
224
  if (c.status === "running") return true;
228
- if (c[SCROLL_HOLD_KEY] !== undefined) return true;
229
225
  const thinking = getRuntime().thinkingLabelState;
230
226
  if (thinking?.active?.has(child)) return true;
231
227
  return false;
@@ -362,7 +358,7 @@ function childMetaOf(child: unknown, state: RenderCacheState): ChildMeta {
362
358
  return {
363
359
  version: state.versions.get(cObj) ?? 0,
364
360
  interactionVersion: 0,
365
- scrollOffset: Number(cObj[SCROLL_OFFSET_KEY] ?? 0),
361
+ scrollOffset: 0,
366
362
  expanded: Boolean(cObj.expanded),
367
363
  };
368
364
  }
@@ -821,5 +817,4 @@ export default function registerRenderCache(pi: ExtensionAPI): void {
821
817
 
822
818
  export const __test = {
823
819
  RENDER_CACHE_CONFIG_KEY,
824
- SCROLL_OFFSET_KEY,
825
820
  };
@@ -23,7 +23,7 @@ import { createBashTool, createEditTool, createFindTool, createGrepTool, createL
23
23
  import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
24
24
  import { homedir } from "node:os";
25
25
  import { join } from "node:path";
26
- import { createHoldRepeat, inSpans, renderBoxLines as box, type HoldRepeat, type TextSpan, textSpans } from "../box.ts";
26
+ import { inSpans, renderBoxLines as box, type TextSpan, textSpans } from "../box.ts";
27
27
  import { getActiveTheme, stripAnsi, softSecondaryOf } from "../ansi.ts";
28
28
  import { actionWord } from "../todos.ts";
29
29
  import {
@@ -35,10 +35,6 @@ import {
35
35
  type EditDiffMode,
36
36
  } from "../edit-diff.ts";
37
37
  import { markPatched, originalOf } from "../patch.ts";
38
- import {
39
- TOOL_BOX_SCROLL_HOLD_KEY as SCROLL_HOLD,
40
- TOOL_BOX_SCROLL_OFFSET_KEY as SCROLL_OFFSET,
41
- } from "../runtime.ts";
42
38
 
43
39
  export { EDIT_DIFF_CHOICES, activeEditDiff, formatEditDiff, setEditDiff, type EditDiffMode };
44
40
 
@@ -357,34 +353,6 @@ export function stripEdgesKeepingImages(lines: string[]): string[] {
357
353
  // target: every other cell of the box keeps pi's text selection, so the output stays
358
354
  // copyable. Recomputed on every render, because the label moves with the width and the key.
359
355
  const HINT_SPANS = Symbol.for("pi-arnative.toolBoxHintSpans");
360
-
361
- function stopScrollHold(comp: Record<symbol, unknown>): void {
362
- const hold = comp[SCROLL_HOLD] as HoldRepeat | undefined;
363
- if (hold && typeof hold.stop === "function") hold.stop();
364
- comp[SCROLL_HOLD] = undefined;
365
- }
366
-
367
- function startScrollHold(
368
- comp: Record<symbol, unknown> & { expanded?: boolean; ui?: { requestRender?: () => void } },
369
- dir: -1 | 1,
370
- ): void {
371
- stopScrollHold(comp);
372
- const hold = createHoldRepeat();
373
- comp[SCROLL_HOLD] = hold;
374
- hold.start(() => {
375
- if (!comp.expanded) return false;
376
- const meta = (comp[SCROLL_META] as { maxOffset: number; step: number } | undefined) ?? { maxOffset: 0, step: 6 };
377
- const cur = Number(comp[SCROLL_OFFSET] ?? 0);
378
- const next = Math.max(0, Math.min(meta.maxOffset, cur + dir * meta.step));
379
- if (next === cur) return false;
380
- comp[SCROLL_OFFSET] = next;
381
- comp.ui?.requestRender?.();
382
- return true;
383
- });
384
- }
385
- const SCROLL_UP_SPANS = Symbol.for("pi-arnative.toolBoxScrollUpSpans");
386
- const SCROLL_DOWN_SPANS = Symbol.for("pi-arnative.toolBoxScrollDownSpans");
387
- const SCROLL_META = Symbol.for("pi-arnative.toolBoxScrollMeta");
388
356
  // A press already toggled this box; the release and the synthesized click that follow it
389
357
  // must not toggle it a second time.
390
358
  const PRESS_TOGGLED = Symbol.for("pi-arnative.toolBoxPressToggled");
@@ -394,18 +362,9 @@ export function expandedBoxBodyLimit(rows = process.stdout.rows || 28): number {
394
362
  return Math.min(12, Math.max(6, Math.floor(rows * 0.35)));
395
363
  }
396
364
 
397
- function boxTokenPaint(tokens: readonly string[]): (text: string) => string {
398
- const th = getActiveTheme<{ fg?(c: string, t: string): string }>();
399
- if (!th?.fg) return (s) => s;
400
- for (const token of tokens) {
401
- try {
402
- const probe = th.fg(token, "x");
403
- if (typeof probe === "string" && probe.includes("x")) return (s) => th.fg!(token, s);
404
- } catch {
405
- // try next token
406
- }
407
- }
408
- return (s) => s;
365
+ /** Expanded boxes taller than this threshold add a centered bottom-border `[hide]` control. */
366
+ export function tallBoxBottomHideThreshold(rows = process.stdout.rows || 28): number {
367
+ return Math.max(8, rows - 6);
409
368
  }
410
369
 
411
370
  export function paintScrollEdge(
@@ -429,42 +388,6 @@ export function paintScrollEdge(
429
388
  return `${bgOpen}${content}${bgClose}`;
430
389
  }
431
390
 
432
- function capExpandedToolBox(
433
- drawn: string[],
434
- scrollOffset: number,
435
- maxBody: number,
436
- width: number,
437
- borderPaint: (text: string) => string,
438
- primaryPaint: (text: string) => string,
439
- ): { lines: string[]; maxOffset: number; aboveLabel: string; belowLabel: string; botRow: number } {
440
- if (drawn.length < 4 || !stripAnsi(drawn[0] ?? "").trimStart().startsWith("\u256d")) {
441
- return { lines: drawn, maxOffset: 0, aboveLabel: "", belowLabel: "", botRow: -1 };
442
- }
443
- let botIdx = -1;
444
- for (let i = drawn.length - 1; i >= 2; i--) {
445
- const p = stripAnsi(drawn[i]!).trim();
446
- if (p.startsWith("\u2570") && p.endsWith("\u256f")) {
447
- botIdx = i;
448
- break;
449
- }
450
- }
451
- if (botIdx < 3) return { lines: drawn, maxOffset: 0, aboveLabel: "", belowLabel: "", botRow: -1 };
452
- const body = drawn.slice(2, botIdx);
453
- if (body.length <= maxBody) return { lines: drawn, maxOffset: 0, aboveLabel: "", belowLabel: "", botRow: botIdx };
454
-
455
- const maxOffset = body.length - maxBody;
456
- const offset = Math.max(0, Math.min(scrollOffset, maxOffset));
457
- const visible = body.slice(offset, offset + maxBody);
458
- const above = offset;
459
- const below = body.length - (offset + visible.length);
460
- const aboveLabel = above > 0 ? `\u2191 ${above} more` : "";
461
- const belowLabel = below > 0 ? `\u2193 ${below} more` : "";
462
- const top = aboveLabel ? paintScrollEdge(drawn[0]!, "\u256d", "\u256e", aboveLabel, width, borderPaint, primaryPaint) : drawn[0]!;
463
- const bot = belowLabel ? paintScrollEdge(drawn[botIdx]!, "\u2570", "\u256f", belowLabel, width, borderPaint, primaryPaint) : drawn[botIdx]!;
464
- const lines = [top, drawn[1]!, ...visible, bot, ...drawn.slice(botIdx + 1)];
465
- return { lines, maxOffset, aboveLabel, belowLabel, botRow: 2 + visible.length };
466
- }
467
-
468
391
  // The patches below reinstall on every module load (pi's /reload re-evaluates the
469
392
  // extension in the same process), so a UI fix applies without restarting pi; see
470
393
  // lib/patch.ts for the originals/mark bookkeeping that makes that safe.
@@ -476,81 +399,58 @@ if (ToolExecutionComponent?.prototype?.render) {
476
399
  const stripped = OWN_BOX.has(this.toolName) || boxTheirRenderers(this) || !hasOwnRendererDef(this);
477
400
  this[STRIPPED_BOX] = stripped;
478
401
  let drawn = stripped ? stripEdgesKeepingImages(lines) : lines;
479
- if (stripped && this.expanded) {
480
- const maxBody = expandedBoxBodyLimit();
481
- const capped = capExpandedToolBox(
482
- drawn,
483
- Number(this[SCROLL_OFFSET] ?? 0),
484
- maxBody,
485
- width,
486
- boxTokenPaint(["dim"]),
487
- boxTokenPaint(["dim"]),
488
- );
489
- drawn = capped.lines;
490
- this[SCROLL_OFFSET] = Math.max(0, Math.min(Number(this[SCROLL_OFFSET] ?? 0), capped.maxOffset));
491
- this[SCROLL_META] = { maxOffset: capped.maxOffset, step: Math.max(1, Math.floor(maxBody / 2)) };
492
- this[SCROLL_UP_SPANS] = capped.aboveLabel ? textSpans([drawn[0]!], capped.aboveLabel) : [];
493
- this[SCROLL_DOWN_SPANS] =
494
- capped.belowLabel && capped.botRow >= 0
495
- ? textSpans([drawn[capped.botRow]!], capped.belowLabel).map((s) => ({ ...s, row: capped.botRow }))
496
- : [];
497
- } else {
498
- stopScrollHold(this);
499
- this[SCROLL_OFFSET] = 0;
500
- this[SCROLL_UP_SPANS] = [];
501
- this[SCROLL_DOWN_SPANS] = [];
502
- this[SCROLL_META] = undefined;
402
+ let botHideRow = -1;
403
+ if (stripped && this.expanded && drawn.length > tallBoxBottomHideThreshold()) {
404
+ for (let i = drawn.length - 1; i >= 2; i--) {
405
+ const p = stripAnsi(drawn[i]!).trim();
406
+ if (p.startsWith("\u2570") && p.endsWith("\u256f")) {
407
+ const th = getActiveTheme<{ fg?(c: string, t: string): string }>();
408
+ const dim = (s: string) => (th?.fg ? th.fg("dim", s) : s);
409
+ const next = [...drawn];
410
+ next[i] = paintScrollEdge(drawn[i]!, "\u2570", "\u256f", HINT_COLLAPSE, width, dim, dim);
411
+ drawn = next;
412
+ botHideRow = i;
413
+ break;
414
+ }
415
+ }
503
416
  }
504
417
  // Only a box this module laid out is measured here; a renderer pi owns keeps pi's
505
418
  // own mouse path, since its row offsets come from a layout it did not show us.
506
- // Title rows only (frame + title): a [show] inside the output must not become a button.
507
- this[HINT_SPANS] = stripped
419
+ // Title rows (frame + title) plus optional bottom-border [hide]: a [show] inside
420
+ // the output must not become a button.
421
+ const topHints = stripped
508
422
  ? [...textSpans(drawn, HINT_EXPAND), ...textSpans(drawn, HINT_COLLAPSE)].filter((span) => span.row <= 1)
509
423
  : [];
424
+ const botHints =
425
+ botHideRow >= 0
426
+ ? textSpans([drawn[botHideRow]!], HINT_COLLAPSE).map((span) => ({ ...span, row: botHideRow }))
427
+ : [];
428
+ this[HINT_SPANS] = [...topHints, ...botHints];
510
429
  return drawn;
511
430
  });
512
431
 
513
- // Click to expand/collapse or scroll, on the hint/more text alone. pi toggles on the
514
- // "click" it synthesizes from a press and a release at the same cell, so a one-cell
515
- // drift made the hint look inert, and the stripped row above the box left its top
516
- // border dead. A left press on the button acts at once and the release plus the click
517
- // that follow are swallowed; the click clears the flag, not the release, or that click
518
- // would trigger twice. Any other cell is left to pi: a press there starts a selection,
519
- // so the output can be copied.
432
+ // Click to expand/collapse on the hint text alone. pi toggles on the "click" it
433
+ // synthesizes from a press and a release at the same cell, so a one-cell drift made
434
+ // the hint look inert, and the stripped row above the box left its top border dead.
435
+ // A left press on the button acts at once and the release plus the click that follow
436
+ // are swallowed; the click clears the flag, not the release, or that click would
437
+ // trigger twice. Any other cell is left to pi: a press there starts a selection, so
438
+ // the output can be copied.
520
439
  const origMouse = originalOf<(this: PatchedToolComponent, event: ToolMouseEventLike) => unknown>(proto, "handleMouse");
521
440
  proto.handleMouse = markPatched(function (this: PatchedToolComponent, event: ToolMouseEventLike): unknown {
522
441
  const onHint = (this[HINT_SPANS] as TextSpan[] | undefined)?.length
523
442
  ? inSpans(this[HINT_SPANS] as TextSpan[], event.y, event.x)
524
443
  : false;
525
- const onUp = (this[SCROLL_UP_SPANS] as TextSpan[] | undefined)?.length
526
- ? inSpans(this[SCROLL_UP_SPANS] as TextSpan[], event.y, event.x)
527
- : false;
528
- const onDown = (this[SCROLL_DOWN_SPANS] as TextSpan[] | undefined)?.length
529
- ? inSpans(this[SCROLL_DOWN_SPANS] as TextSpan[], event.y, event.x)
530
- : false;
531
- if ((onHint || onUp || onDown) && event.type === "press" && event.button === "left") {
532
- stopScrollHold(this);
444
+ if (onHint && event.type === "press" && event.button === "left") {
533
445
  // A child of the box (an image preview) keeps its own press.
534
446
  const childHit = origMouse.call(this, event);
535
447
  if (childHit) return childHit;
536
- if (onHint) {
537
- if (!this.result) return undefined;
538
- this.setExpanded(!this.expanded);
539
- this[PRESS_TOGGLED] = true;
540
- return { handled: true, render: true };
541
- }
542
- const meta = (this[SCROLL_META] as { maxOffset: number; step: number } | undefined) ?? { maxOffset: 0, step: 6 };
543
- const cur = Number(this[SCROLL_OFFSET] ?? 0);
544
- const dir: -1 | 1 = onUp ? -1 : 1;
545
- const next = Math.max(0, Math.min(meta.maxOffset, cur + dir * meta.step));
546
- this[SCROLL_OFFSET] = next;
448
+ if (!this.result) return undefined;
449
+ this.setExpanded(!this.expanded);
547
450
  this[PRESS_TOGGLED] = true;
548
- startScrollHold(this, dir);
549
- this.ui?.requestRender?.();
550
451
  return { handled: true, render: true };
551
452
  }
552
453
  if (this[PRESS_TOGGLED] && (event.type === "release" || event.type === "click")) {
553
- stopScrollHold(this);
554
454
  if (event.type === "click") this[PRESS_TOGGLED] = false;
555
455
  return { handled: true, render: false };
556
456
  }
@@ -32,6 +32,12 @@ export const PAYLOAD_LIMIT_KEY = "payloadLimit";
32
32
  export const EDIT_DIFF_KEY = "editDiff";
33
33
  /** Tool transcript layout: `"Grouped"` (ADE phase progress box) or `"Classic"` (per-tool boxes). */
34
34
  export const TOOL_LAYOUT_KEY = "toolLayout";
35
+ /** Smart `ask_user_question` custom model (`""` = active session model, or `"provider/modelId"`). */
36
+ export const ASK_MODEL_KEY = "askModel";
37
+ /** Smart `ask_user_question` delegation mode: `"Hybrid"` (default), `"Refine"`, or `"Off"`. */
38
+ export const ASK_MODE_KEY = "askMode";
39
+ /** Smart `ask_user_question` reasoning level: `"off"`, `"low"` (default), `"medium"`, `"high"`. */
40
+ export const ASK_THINKING_KEY = "askThinking";
35
41
 
36
42
  // Resolved per call, not at import: the self-check points getAgentDir() at a fixture dir.
37
43
  // Everything pi-arnative writes lives in one folder (agent dir/arnative); the config moved
@@ -104,7 +110,7 @@ export function loadNumber(key: string, range: { min: number; max: number }): nu
104
110
  /** Reading order of `config.json`: the presets in the order the settings menu shows them,
105
111
  * then `layoutVersion`, then anything else (a key from another module or a newer version).
106
112
  * Times a user edits the file by hand or reads it back. */
107
- const KEY_ORDER = ["headerPreset", "footerPreset", "footerCost", "chatboxPreset", "chatboxPrompt", "chatboxDialog", "budgetDay", "budgetMonth", "budgetEnforce", "spinnerPreset", "spinnerGradient", "layoutVersion", "autoCompact", "payloadLimit", "modelHeal", "renderCache", "editDiff", "toolLayout"];
113
+ const KEY_ORDER = ["headerPreset", "footerPreset", "footerCost", "chatboxPreset", "chatboxPrompt", "chatboxDialog", "budgetDay", "budgetMonth", "budgetEnforce", "spinnerPreset", "spinnerGradient", "layoutVersion", "autoCompact", "payloadLimit", "modelHeal", "renderCache", "editDiff", "toolLayout", "askModel", "askMode", "askThinking"];
108
114
 
109
115
  /** The record in {@link KEY_ORDER}; unknown keys keep the order they were written in. */
110
116
  function ordered(record: Record<string, unknown>): Record<string, unknown> {
package/lib/runtime.ts CHANGED
@@ -11,10 +11,6 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
11
11
 
12
12
  const RUNTIME_KEY = Symbol.for("pi-arnative.runtime");
13
13
 
14
- // Per-component instance tags shared across `tools.ts` and `render-cache.ts`.
15
- export const TOOL_BOX_SCROLL_HOLD_KEY = Symbol.for("pi-arnative.toolBoxScrollHold");
16
- export const TOOL_BOX_SCROLL_OFFSET_KEY = Symbol.for("pi-arnative.toolBoxScrollOffset");
17
-
18
14
  export interface ActiveClockSnapshot {
19
15
  active: number;
20
16
  runStarted: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bismawy/pi-arnative",
3
- "version": "0.18.2",
3
+ "version": "0.19.0",
4
4
  "description": "Refined aesthetics. Cohesive tools. Built for Pi. Warm themes, rounded tool boxes, tabbed header, compact footer and a /usage dashboard.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -36,7 +36,8 @@
36
36
  "peerDependencies": {
37
37
  "@earendil-works/pi-ai": "*",
38
38
  "@earendil-works/pi-coding-agent": "*",
39
- "@earendil-works/pi-tui": "*"
39
+ "@earendil-works/pi-tui": "*",
40
+ "typebox": "*"
40
41
  },
41
42
  "scripts": {
42
43
  "dev": "pi --extension ./extensions/index.ts",