@linxiraos/pi-tui 1.4.7 → 1.4.10

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 (181) hide show
  1. package/CHANGELOG.md +154 -231
  2. package/README.md +7 -1
  3. package/dist/types/app-keybindings.d.ts +5 -0
  4. package/dist/types/charts/table-data.d.ts +4 -2
  5. package/dist/types/chat/bash-execution.d.ts +4 -1
  6. package/dist/types/chat/eval-execution.d.ts +2 -0
  7. package/dist/types/chat/execution-shared.d.ts +14 -8
  8. package/dist/types/chat/figure-markdown.d.ts +2 -0
  9. package/dist/types/chat/svg-figure.d.ts +5 -0
  10. package/dist/types/chat/table-chart.d.ts +2 -0
  11. package/dist/types/chat/transcript-render-helpers.d.ts +11 -3
  12. package/dist/types/chrome/dynamic-border.d.ts +6 -0
  13. package/dist/types/chrome/transcript-status.d.ts +2 -2
  14. package/dist/types/components/editor.d.ts +15 -6
  15. package/dist/types/components/image.d.ts +6 -0
  16. package/dist/types/components/loader.d.ts +2 -0
  17. package/dist/types/keybinding-matchers.d.ts +7 -0
  18. package/dist/types/native/describe.d.ts +4 -2
  19. package/dist/types/native/node.d.ts +2 -3
  20. package/dist/types/native/overlay.d.ts +42 -2
  21. package/dist/types/native/state.d.ts +4 -0
  22. package/dist/types/overlays/btw-history-panel.d.ts +15 -0
  23. package/dist/types/overlays/btw-history.d.ts +24 -0
  24. package/dist/types/overlays/btw-inject.d.ts +22 -0
  25. package/dist/types/overlays/btw-panel.d.ts +7 -0
  26. package/dist/types/overlays/hook-editor.d.ts +2 -0
  27. package/dist/types/overlays/jobs-panel.d.ts +4 -0
  28. package/dist/types/overlays/model-browser.d.ts +1 -1
  29. package/dist/types/overlays/session-selector.d.ts +11 -2
  30. package/dist/types/prompt/composer.d.ts +13 -5
  31. package/dist/types/render/render-utils.d.ts +23 -1
  32. package/dist/types/setup/scenes/language.d.ts +3 -0
  33. package/dist/types/setup/scenes/types.d.ts +5 -0
  34. package/dist/types/setup/setup-version.d.ts +1 -1
  35. package/dist/types/setup/wizard.d.ts +1 -1
  36. package/dist/types/status-line/startup.d.ts +0 -15
  37. package/dist/types/terminal-capabilities.d.ts +1 -1
  38. package/dist/types/theme/symbols.d.ts +3 -1
  39. package/dist/types/theme/theme-class.d.ts +1 -0
  40. package/dist/types/theme/theme.d.ts +1 -1
  41. package/dist/types/theme/tui-adapters.d.ts +2 -0
  42. package/dist/types/thinking.d.ts +8 -6
  43. package/dist/types/tools/ast-grep.d.ts +2 -0
  44. package/dist/types/tools/eval.d.ts +2 -0
  45. package/dist/types/tools/find.d.ts +1 -1
  46. package/dist/types/tools/grouped-file-output.d.ts +100 -19
  47. package/dist/types/tools/hashline-format.d.ts +5 -0
  48. package/dist/types/tools/native-view.d.ts +2 -0
  49. package/dist/types/tools/output-meta.d.ts +27 -0
  50. package/dist/types/tools/read.d.ts +14 -4
  51. package/dist/types/tools/task.d.ts +4 -3
  52. package/dist/types/tools/wait.d.ts +2 -0
  53. package/dist/types/tui.d.ts +12 -0
  54. package/dist/types/utils.d.ts +4 -0
  55. package/package.json +9 -9
  56. package/src/app-keybindings.d.ts +5 -0
  57. package/src/app-keybindings.ts +5 -0
  58. package/src/apps/git/git-tui.ts +10 -17
  59. package/src/apps/git/sidebar.ts +21 -35
  60. package/src/apps/ps-top.ts +4 -12
  61. package/src/charts/chart-plan.ts +0 -29
  62. package/src/charts/table-data.d.ts +4 -2
  63. package/src/charts/table-data.ts +55 -6
  64. package/src/chat/bash-execution.d.ts +4 -1
  65. package/src/chat/bash-execution.ts +20 -9
  66. package/src/chat/chat-transcript-builder.ts +5 -2
  67. package/src/chat/eval-execution.d.ts +2 -0
  68. package/src/chat/eval-execution.ts +14 -7
  69. package/src/chat/execution-shared.d.ts +14 -8
  70. package/src/chat/execution-shared.ts +39 -18
  71. package/src/chat/figure-markdown.d.ts +2 -0
  72. package/src/chat/figure-markdown.ts +6 -4
  73. package/src/chat/read-tool-group.ts +56 -36
  74. package/src/chat/svg-figure.d.ts +5 -0
  75. package/src/chat/svg-figure.ts +55 -16
  76. package/src/chat/table-chart.d.ts +2 -0
  77. package/src/chat/table-chart.ts +19 -2
  78. package/src/chat/transcript-render-helpers.d.ts +11 -3
  79. package/src/chat/transcript-render-helpers.ts +70 -22
  80. package/src/chrome/dynamic-border.d.ts +6 -0
  81. package/src/chrome/dynamic-border.ts +28 -2
  82. package/src/chrome/transcript-status.d.ts +2 -2
  83. package/src/chrome/transcript-status.ts +5 -3
  84. package/src/components/editor.d.ts +15 -6
  85. package/src/components/editor.ts +123 -24
  86. package/src/components/image.d.ts +6 -0
  87. package/src/components/image.ts +13 -0
  88. package/src/components/key-value-list.ts +9 -9
  89. package/src/components/loader.d.ts +2 -0
  90. package/src/components/loader.ts +7 -0
  91. package/src/components/section.ts +1 -9
  92. package/src/components/table.ts +1 -9
  93. package/src/keybinding-matchers.d.ts +7 -0
  94. package/src/keybinding-matchers.ts +13 -0
  95. package/src/native/backend.ts +7 -3
  96. package/src/native/describe.d.ts +4 -2
  97. package/src/native/describe.ts +9 -4
  98. package/src/native/node.d.ts +2 -3
  99. package/src/native/node.ts +2 -3
  100. package/src/native/overlay.d.ts +42 -2
  101. package/src/native/overlay.ts +124 -16
  102. package/src/native/state.d.ts +4 -0
  103. package/src/native/state.ts +25 -5
  104. package/src/overlays/btw-history-panel.ts +106 -14
  105. package/src/overlays/btw-history.ts +65 -0
  106. package/src/overlays/btw-inject.ts +91 -0
  107. package/src/overlays/btw-panel.ts +53 -12
  108. package/src/overlays/extensions/extension-dashboard.ts +7 -8
  109. package/src/overlays/hook-editor.ts +6 -0
  110. package/src/overlays/jobs-panel.ts +82 -22
  111. package/src/overlays/login-dialog.ts +8 -26
  112. package/src/overlays/model-browser.ts +69 -10
  113. package/src/overlays/session-selector.ts +25 -5
  114. package/src/overlays/settings-defs.ts +2 -2
  115. package/src/overlays/settings-selector.ts +113 -11
  116. package/src/overlays/tree-selector.ts +83 -27
  117. package/src/overlays/usage-dashboard.ts +4 -6
  118. package/src/prompt/composer.ts +17 -5
  119. package/src/render/code-cell.ts +1 -1
  120. package/src/render/file-list.ts +4 -7
  121. package/src/render/render-utils.d.ts +23 -1
  122. package/src/render/render-utils.ts +38 -6
  123. package/src/setup/scenes/glyph.ts +1 -1
  124. package/src/setup/scenes/language.ts +122 -0
  125. package/src/setup/scenes/types.ts +6 -0
  126. package/src/setup/setup-version.ts +1 -1
  127. package/src/setup/wizard.ts +2 -0
  128. package/src/status-line/startup.ts +36 -70
  129. package/src/terminal-capabilities.d.ts +1 -1
  130. package/src/terminal-capabilities.ts +5 -0
  131. package/src/theme/symbols.d.ts +3 -1
  132. package/src/theme/symbols.ts +16 -9
  133. package/src/theme/theme-class.d.ts +1 -0
  134. package/src/theme/theme-class.ts +15 -3
  135. package/src/theme/theme.d.ts +1 -1
  136. package/src/theme/theme.ts +1 -0
  137. package/src/theme/tui-adapters.d.ts +2 -0
  138. package/src/theme/tui-adapters.ts +8 -3
  139. package/src/thinking.d.ts +8 -6
  140. package/src/thinking.ts +17 -11
  141. package/src/tmux.ts +1 -0
  142. package/src/tools/agent-tree.ts +13 -11
  143. package/src/tools/ask.ts +24 -37
  144. package/src/tools/ast-edit.ts +48 -93
  145. package/src/tools/ast-grep.d.ts +2 -0
  146. package/src/tools/ast-grep.ts +31 -67
  147. package/src/tools/bash.ts +7 -0
  148. package/src/tools/default-renderer.ts +1 -1
  149. package/src/tools/edit.ts +50 -43
  150. package/src/tools/eval.d.ts +2 -0
  151. package/src/tools/eval.ts +2 -0
  152. package/src/tools/fetch.ts +2 -1
  153. package/src/tools/find.d.ts +1 -1
  154. package/src/tools/find.ts +13 -5
  155. package/src/tools/github.ts +14 -46
  156. package/src/tools/glob.ts +2 -1
  157. package/src/tools/grep.ts +47 -277
  158. package/src/tools/grouped-file-output.d.ts +100 -19
  159. package/src/tools/grouped-file-output.ts +414 -103
  160. package/src/tools/hashline-format.d.ts +5 -0
  161. package/src/tools/hashline-format.ts +5 -0
  162. package/src/tools/json-tree.ts +1 -5
  163. package/src/tools/lsp.ts +210 -32
  164. package/src/tools/native-view.d.ts +2 -0
  165. package/src/tools/native-view.ts +11 -5
  166. package/src/tools/output-meta.d.ts +27 -0
  167. package/src/tools/output-meta.ts +68 -4
  168. package/src/tools/proc-render.ts +3 -3
  169. package/src/tools/read.d.ts +14 -4
  170. package/src/tools/read.ts +20 -5
  171. package/src/tools/task.d.ts +4 -3
  172. package/src/tools/task.ts +41 -81
  173. package/src/tools/vibe.ts +4 -4
  174. package/src/tools/wait.d.ts +2 -0
  175. package/src/tools/wait.ts +8 -5
  176. package/src/tools/write.ts +17 -27
  177. package/src/tools/yield.ts +1 -1
  178. package/src/tui.d.ts +12 -0
  179. package/src/tui.ts +91 -9
  180. package/src/utils.d.ts +4 -0
  181. package/src/utils.ts +10 -0
@@ -26,6 +26,10 @@ export interface JobsPanelJob {
26
26
  readonly type: string;
27
27
  readonly status: "running" | "completed" | "failed" | "cancelled";
28
28
  readonly label: string;
29
+ /** What the job is for, in the model's words; rows and the detail lead with it over a command `label`. */
30
+ readonly intent?: string;
31
+ /** One line on what a command does and when it ends, from the cheap model; the detail shows it under the intent. */
32
+ readonly caption?: string;
29
33
  readonly startTime: number;
30
34
  readonly endTime?: number;
31
35
  /** Registry id of the agent that owns the job. */
@@ -130,6 +134,12 @@ export class JobsSheet implements Component {
130
134
  #native: { key: string; output: string | undefined; node: NativeNode } | undefined;
131
135
  /** Fallback output tail, reused while the selected job's output is unchanged. */
132
136
  #tail: { id: string; output: string; lines: readonly string[] } | undefined;
137
+ /**
138
+ * The selected job as last seen: its row, detail and the subagents placing
139
+ * it. The session evicts settled jobs on its own clock; while the user keeps
140
+ * one selected it stays listed with its last output, until they select another.
141
+ */
142
+ #held: { job: JobsPanelJob; detail: JobsPanelDetail | undefined; agents: readonly JobTreeAgent[] } | undefined;
133
143
 
134
144
  constructor(source: JobsSheetSource) {
135
145
  this.#source = source;
@@ -137,16 +147,17 @@ export class JobsSheet implements Component {
137
147
 
138
148
  describe(_cx: DescribeContext): NativeNode {
139
149
  const { rows, jobs, selected, cancellable } = this.#current();
140
- const detail = selected && this.#source.inspect(selected.id);
150
+ const detail = selected && this.#inspect(selected.id);
141
151
  const now = Date.now();
142
152
  // Elapsed nodes tick on their own; list values and the output pane redraw
143
- // when a job starts, settles, leaves or moves in the tree, its process
144
- // changes, its output grows, or (while one runs) once a second.
153
+ // when a job starts, settles, leaves or moves in the tree, gets its
154
+ // caption (it can land after the job settles), its process changes, its
155
+ // output grows, or (while one runs) once a second.
145
156
  const key = [
146
157
  rows
147
158
  .map(
148
159
  entry =>
149
- `${jobTreeGuide(entry, theme)}${entry.kind === "job" ? `${entry.job.id}:${entry.job.status}` : entry.agent.id}`,
160
+ `${jobTreeGuide(entry, theme)}${entry.kind === "job" ? `${entry.job.id}:${entry.job.status}:${entry.job.caption ?? ""}` : entry.agent.id}`,
150
161
  )
151
162
  .join(","),
152
163
  selected?.id,
@@ -194,15 +205,20 @@ export class JobsSheet implements Component {
194
205
  const cursor = job === selected ? ">" : " ";
195
206
  const age = formatDuration(jobAge(job, now));
196
207
  const agent = entry.agent && entry.agent.id !== job.label ? `${entry.agent.id}: ` : "";
197
- lines.push(
198
- truncateToWidth(
199
- `${cursor} ${guide}${job.status} ${job.type} ${age} ${agent}${collapseCommand(job.label)}`,
200
- width,
201
- ),
202
- );
208
+ // The intent is model-written: strip terminal controls and flatten it to one row like the command.
209
+ const title = shortenEmbeddedPaths(collapseCommand(sanitizeText(job.intent ?? job.label)));
210
+ lines.push(truncateToWidth(`${cursor} ${guide}${job.status} ${job.type} ${age} ${agent}${title}`, width));
203
211
  }
204
- const detail = selected && this.#source.inspect(selected.id);
212
+ const detail = selected && this.#inspect(selected.id);
205
213
  if (detail) {
214
+ if (selected.caption) {
215
+ for (const line of wrapTextWithAnsi(
216
+ shortenEmbeddedPaths(sanitizeText(selected.caption)),
217
+ Math.max(1, width - 3),
218
+ )) {
219
+ lines.push(` ${theme.fg("muted", line)}`);
220
+ }
221
+ }
206
222
  // Rows show the cut label; the selected job's command wraps here,
207
223
  // bounded so a long script never pushes the facts and output off the sheet.
208
224
  if (detail.command) {
@@ -221,7 +237,7 @@ export class JobsSheet implements Component {
221
237
  detail.artifactId && `artifact://${detail.artifactId}`,
222
238
  ]);
223
239
  if (facts.length > 0) lines.push(truncateToWidth(` ${facts.join(" · ")}`, width));
224
- if (detail.widget) {
240
+ if (detail.widget && widgetHasData(detail.widget)) {
225
241
  for (const line of renderJobWidgetLines(detail.widget, Math.max(0, width - 3), theme)) {
226
242
  lines.push(` ${line}`);
227
243
  }
@@ -262,15 +278,43 @@ export class JobsSheet implements Component {
262
278
  selected: JobsPanelJob | undefined;
263
279
  cancellable: boolean;
264
280
  } {
265
- const { running, recent, rootId, agents } = this.#source.load();
266
- const rows = buildJobTree([...running, ...recent], agents ?? [], rootId);
281
+ const snapshot = this.#source.load();
282
+ const { running, rootId } = snapshot;
283
+ let { recent, agents = [] } = snapshot;
284
+ // A settled job the session evicted stays listed while it is selected.
285
+ const held = this.#held?.job.id === this.#selectedId ? this.#held : undefined;
286
+ const evicted =
287
+ held !== undefined &&
288
+ held.job.status !== "running" &&
289
+ !running.some(job => job.id === held.job.id) &&
290
+ !recent.some(job => job.id === held.job.id);
291
+ if (evicted) {
292
+ recent = [...recent, held.job];
293
+ const known = new Set(agents.map(agent => agent.id));
294
+ agents = [...agents, ...held.agents.filter(agent => !known.has(agent.id))];
295
+ }
296
+ const rows = buildJobTree([...running, ...recent], agents, rootId);
267
297
  const jobs = rows.flatMap(entry => (entry.kind === "job" ? [entry.job] : []));
268
298
  const selected = jobs.find(job => job.id === this.#selectedId) ?? jobs[0];
269
299
  this.#selectedId = selected?.id;
300
+ if (!selected) this.#held = undefined;
301
+ else if (!evicted) {
302
+ const detail = held?.job.id === selected.id ? held.detail : undefined;
303
+ this.#held = { job: selected, detail, agents: snapshot.agents ?? [] };
304
+ }
270
305
  const owned = selected?.ownerId === undefined || selected.ownerId === rootId;
271
306
  return { rows, jobs, selected, cancellable: this.#source.cancel !== undefined && owned };
272
307
  }
273
308
 
309
+ /** The job's detail from the source, else the last one seen while it was held. */
310
+ #inspect(id: string): JobsPanelDetail | undefined {
311
+ const detail = this.#source.inspect(id);
312
+ const held = this.#held?.job.id === id ? this.#held : undefined;
313
+ if (!held) return detail;
314
+ if (detail) held.detail = detail;
315
+ return held.detail;
316
+ }
317
+
274
318
  #tailLines(id: string, output: string): readonly string[] {
275
319
  const cached = this.#tail;
276
320
  if (cached?.id === id && cached.output === output) return cached.lines;
@@ -297,6 +341,11 @@ function jobAge(job: JobsPanelJob, nowMs: number): number {
297
341
  return Math.max(0, (job.endTime ?? nowMs) - job.startTime);
298
342
  }
299
343
 
344
+ /** Whether a widget draws more than its title: one without data only repeats the job's heading. */
345
+ function widgetHasData(widget: JobWidgetView): boolean {
346
+ return widget.blocks.length > 0 || widget.headline !== undefined || Boolean(widget.stage);
347
+ }
348
+
300
349
  /**
301
350
  * The last `count` pieces of `text.trimEnd().split("\n")`, found by scanning
302
351
  * back from the end so a long running output is never split as a whole.
@@ -339,8 +388,9 @@ function describeJobList(rows: readonly JobTreeRow<JobsPanelJob>[], selected: Jo
339
388
 
340
389
  /**
341
390
  * One list row: the type icon tinted by status, the tree connector, the
342
- * subagent a task job runs, the one-line label (a process job's command in
343
- * mono, a task's work in prose) and how long it ran.
391
+ * subagent a task job runs, the one-line label (what the job is for when the
392
+ * model said, else a process job's command in mono or a task's work in prose)
393
+ * and how long it ran.
344
394
  */
345
395
  function describeJobItem(job: JobsPanelJob, agentName: string | undefined, guide: string, nowMs: number): NativeNode {
346
396
  const status = STATUS_LABEL[job.status];
@@ -349,13 +399,17 @@ function describeJobItem(job: JobsPanelJob, agentName: string | undefined, guide
349
399
  label: compact([
350
400
  guide !== "" && span(guide, "mono dim"),
351
401
  agentName !== undefined && agentName !== job.label && span(`${agentName} `, "strong"),
352
- job.type === "task" ? span(job.label) : span(collapseCommand(job.label), "mono"),
402
+ job.intent
403
+ ? span(job.intent)
404
+ : job.type === "task"
405
+ ? span(job.label)
406
+ : span(collapseCommand(job.label), "mono"),
353
407
  ]),
354
408
  value: [span(age, "mono")],
355
409
  icon: TYPE_ICON[job.type] ?? "job",
356
410
  tone: STATUS_TONE[job.status],
357
- title: `${job.label}\n${status} · ${job.type} · ${job.id}`,
358
- aria: `${job.label}, ${status.toLowerCase()}, ${age}`,
411
+ title: `${job.intent ? `${job.intent}\n` : ""}${job.caption ? `${job.caption}\n` : ""}${job.label}\n${status} · ${job.type} · ${job.id}`,
412
+ aria: `${job.intent ?? job.label}, ${status.toLowerCase()}, ${age}`,
359
413
  });
360
414
  }
361
415
 
@@ -388,8 +442,9 @@ function describeEmpty(): NativeNode {
388
442
 
389
443
  /**
390
444
  * The selected job: a status line (pill, live elapsed, type · id, Cancel job
391
- * when `cancellable`), its task or full command, facts and the output pane (or
392
- * its empty state).
445
+ * when `cancellable`), what it is for, what its command does (the cheap
446
+ * model's caption), its full command, facts, its widget
447
+ * when it has data to draw and the output pane (or its empty state).
393
448
  */
394
449
  function describeDetail(
395
450
  job: JobsPanelJob,
@@ -401,6 +456,7 @@ function describeDetail(
401
456
  const exit = detail?.exitCode;
402
457
  const age = Math.round(jobAge(job, nowMs));
403
458
  const command = detail?.command ?? (job.type === "task" ? undefined : job.label);
459
+ const title = job.intent ?? (command ? undefined : job.label);
404
460
  const pids = detail?.pids ?? [];
405
461
  const facts = compact([
406
462
  job.agentId ? { k: "Agent", v: [span(job.agentId, "mono")] } : undefined,
@@ -430,11 +486,15 @@ function describeDetail(
430
486
  ]),
431
487
  { role: "zeta.jobs.status", gap: "sm", align: "center" },
432
488
  ),
489
+ title ? text(title, { role: "zeta.jobs.title", wrap: "word" }) : undefined,
490
+ job.caption ? text([span(job.caption, "muted")], { role: "zeta.jobs.caption", wrap: "word" }) : undefined,
433
491
  command
434
492
  ? code(command, { lang: "bash", wrap: true, preview: { lines: 4 }, role: "zeta.jobs.command" })
435
493
  : text(job.label, { role: "zeta.jobs.title", wrap: "word" }),
436
494
  facts.length > 0 && node("kv", { items: facts, role: "zeta.jobs.facts" }),
437
- detail?.widget && node("col", { role: "zeta.jobs.widget" }, [describeJobWidget(detail.widget)], "widget"),
495
+ detail?.widget &&
496
+ widgetHasData(detail.widget) &&
497
+ node("col", { role: "zeta.jobs.widget" }, [describeJobWidget(detail.widget)], "widget"),
438
498
  node(
439
499
  "col",
440
500
  { role: "zeta.jobs.out", gap: "sm" },
@@ -468,18 +468,7 @@ export class LoginDialogComponent extends OverlayPanel {
468
468
  [
469
469
  node("icon", { name: "link" }, undefined, "icon"),
470
470
  keyed(shown, "url"),
471
- node(
472
- "row",
473
- {
474
- role: "zeta.btn",
475
- align: "center",
476
- actions: { click: "copy" },
477
- href: url,
478
- title: "Copy the sign-in link",
479
- },
480
- [text("Copy")],
481
- "copyLink",
482
- ),
471
+ actionButton("Copy", "copy", { key: "copyLink", href: url, title: "Copy the sign-in link" }),
483
472
  ],
484
473
  "link",
485
474
  );
@@ -487,20 +476,13 @@ export class LoginDialogComponent extends OverlayPanel {
487
476
 
488
477
  /** Open sign-in page (Tern opens the link itself): the primary action while nothing waits for an answer. */
489
478
  #describeOpen(url: string, primary: boolean): NativeNode {
490
- return node(
491
- "row",
492
- {
493
- role: "zeta.btn",
494
- gap: "xs",
495
- align: "center",
496
- actions: { click: "open" },
497
- href: url,
498
- title: `Open ${urlPlace(url)} in your browser`,
499
- ...(primary ? { tone: "accent" as const } : {}),
500
- },
501
- [text("Open sign-in page"), node("icon", { name: "open" }, undefined, "icon")],
502
- "openLink",
503
- );
479
+ return actionButton("Open sign-in page", "open", {
480
+ key: "openLink",
481
+ href: url,
482
+ title: `Open ${urlPlace(url)} in your browser`,
483
+ icon: "open",
484
+ tone: primary ? "accent" : undefined,
485
+ });
504
486
  }
505
487
 
506
488
  /** The stage running now: a spinner and what it waits for. */
@@ -10,7 +10,12 @@
10
10
  import { ThinkingLevel } from "@linxiraos/pi-agent-core";
11
11
  import type { Model } from "@linxiraos/pi-ai";
12
12
  import { buildModel } from "@linxiraos/pi-catalog/build";
13
- import { getEffectiveTokenCost, getModelPricingStatus, modelsAreEqual } from "@linxiraos/pi-catalog/models";
13
+ import {
14
+ getEffectiveTokenCost,
15
+ getFactoryDroidCreditRate,
16
+ getModelPricingStatus,
17
+ modelsAreEqual,
18
+ } from "@linxiraos/pi-catalog/models";
14
19
  import { modelKind, type ModelKind, type ModelPricingStatus } from "@linxiraos/pi-catalog/types";
15
20
  import type { Component } from "../tui";
16
21
  import { FuzzyCorpus, fuzzyRank } from "../fuzzy";
@@ -69,7 +74,8 @@ export type ModelRole =
69
74
  | "web"
70
75
  | "speech"
71
76
  | "dictation"
72
- | "judge";
77
+ | "judge"
78
+ | "taste";
73
79
  export const MODEL_ROLE_IDS: ModelRole[] = [
74
80
  "default",
75
81
  "smol",
@@ -87,6 +93,7 @@ export const MODEL_ROLE_IDS: ModelRole[] = [
87
93
  "speech",
88
94
  "dictation",
89
95
  "judge",
96
+ "taste",
90
97
  ];
91
98
  export const CHAT_MODEL_ROLE_IDS: ModelRole[] = [
92
99
  "default",
@@ -101,7 +108,7 @@ export const CHAT_MODEL_ROLE_IDS: ModelRole[] = [
101
108
  "advisor",
102
109
  "widget",
103
110
  ];
104
- export const KIND_ROLE_IDS: ModelRole[] = ["image", "web", "speech", "dictation", "judge"];
111
+ export const KIND_ROLE_IDS: ModelRole[] = ["image", "web", "speech", "dictation", "judge", "taste"];
105
112
 
106
113
  /** Measured model performance shown in browser rows. */
107
114
  export interface ModelBrowserPerf {
@@ -747,7 +754,7 @@ function isFreeModel(model: Model): boolean {
747
754
  const declared = declaredPricingStatus(model);
748
755
  if (declared !== undefined) return declared === "free";
749
756
  const cost = model.cost ? getEffectiveTokenCost(model.cost) : undefined;
750
- const credits = model.factoryDroidCredits;
757
+ const credits = getFactoryDroidCreditRate(model)?.rate;
751
758
  return (!cost || (cost.input === 0 && cost.output === 0)) && (credits === undefined || credits === 0);
752
759
  }
753
760
 
@@ -761,15 +768,22 @@ function formatCostLeg(n: number): string {
761
768
  return s.includes(".") ? s.replace(/\.?0+$/, "") : s;
762
769
  }
763
770
 
771
+ /** `2× from 2026-11-22` when a dated Factory Droid credit card changes the rate in force now; undefined otherwise. */
772
+ function nextCreditRateNote(model: Model): string | undefined {
773
+ const next = getFactoryDroidCreditRate(model)?.next;
774
+ return next ? `${formatCostLeg(next.rate)}× from ${new Date(next.at).toISOString().slice(0, 10)}` : undefined;
775
+ }
776
+
764
777
  /**
765
- * Adds Factory Droid's `N×` base Standard Credits rate to a dollar price,
766
- * replacing the price when the model has no dollar reference. Neither the
767
- * reference price nor the base credit rate includes live promotions.
778
+ * Adds Factory Droid's `N×` Standard Credits rate in force now (its dated
779
+ * `credit-rates` card applied) to a dollar price, replacing the price when the
780
+ * model has no dollar reference. The dollar reference never includes vendor
781
+ * promotions; the preview and detail facts name the next rate (`nextCreditRateNote`).
768
782
  */
769
783
  function withCreditBadge(model: Model, price: string): string {
770
- const credits = model.factoryDroidCredits;
784
+ const credits = getFactoryDroidCreditRate(model);
771
785
  if (credits === undefined) return price;
772
- const badge = `${formatCostLeg(credits)}×`;
786
+ const badge = `${formatCostLeg(credits.rate)}×`;
773
787
  const cost = getEffectiveTokenCost(model.cost);
774
788
  return cost.input !== 0 || cost.output !== 0 ? `${price} ${badge}` : badge;
775
789
  }
@@ -820,7 +834,9 @@ function previewPrice(model: Model): string {
820
834
  const cost = getEffectiveTokenCost(model.cost);
821
835
  const parts = [`$${formatCostLeg(cost.input)} in`, `$${formatCostLeg(cost.output)} out`];
822
836
  if (cost.cacheRead > 0) parts.push(`$${formatCostLeg(cost.cacheRead)} cache`);
823
- return withCreditBadge(model, parts.join(" · "));
837
+ const priced = withCreditBadge(model, parts.join(" · "));
838
+ const note = nextCreditRateNote(model);
839
+ return note ? `${priced} (${note})` : priced;
824
840
  }
825
841
 
826
842
  /**
@@ -1025,6 +1041,8 @@ export class ModelBrowser implements Component {
1025
1041
  | undefined;
1026
1042
  /** Theme-formatted catalog metric cells per item; rebuilt when the item's model or the theme changes. */
1027
1043
  #metricCells = new WeakMap<ModelBrowserItem, MetricCells>();
1044
+ /** Earliest dated credit-rate change among models whose rows are memoized; passing it rebuilds them. */
1045
+ #nextCreditChange = Number.POSITIVE_INFINITY;
1028
1046
  /** Non-separator items of the last ranked visible list, for {@link queryMatches}. */
1029
1047
  #queryMatches: { visible: readonly ModelBrowserItem[]; matches: readonly ModelBrowserItem[] } | undefined;
1030
1048
  #hoveredIndex: number | null = null;
@@ -1116,6 +1134,7 @@ export class ModelBrowser implements Component {
1116
1134
 
1117
1135
  /** Replace the scope's base items; the live query re-applies and selection is pinned by selector. */
1118
1136
  setItems(items: ModelBrowserItem[]): void {
1137
+ for (const item of items) this.#noteCreditChange(item.model);
1119
1138
  const selectedKey = this.getSelected()?.selector;
1120
1139
  this.#menu.setItems(this.#insertSeparator(items), selectedKey);
1121
1140
  this.onSelectionChange?.(this.getSelected());
@@ -1511,6 +1530,7 @@ export class ModelBrowser implements Component {
1511
1530
  #metricCellsFor(item: ModelBrowserItem): MetricCells {
1512
1531
  const cached = this.#metricCells.get(item);
1513
1532
  if (cached?.model === item.model && cached.theme === theme) return cached;
1533
+ this.#noteCreditChange(item.model);
1514
1534
  const intelligence = formatIntelligence(item.model);
1515
1535
  const ctx = formatContext(item.model);
1516
1536
  const cost = formatCostPair(item.model);
@@ -1627,6 +1647,9 @@ export class ModelBrowser implements Component {
1627
1647
  } else if (model.tps != null && Number.isFinite(model.tps) && model.tps > 0) {
1628
1648
  facts.push(`~${formatTps(model.tps)}`);
1629
1649
  }
1650
+ // Last fact before prose, so narrow widths cut it before capability and perf facts.
1651
+ const nextCredits = nextCreditRateNote(model);
1652
+ if (nextCredits) facts.push(nextCredits);
1630
1653
  if (model.description) {
1631
1654
  const description = formatDescription(model.description);
1632
1655
  if (description) facts.push(description);
@@ -1658,6 +1681,7 @@ export class ModelBrowser implements Component {
1658
1681
  }
1659
1682
 
1660
1683
  render(width: number): string[] {
1684
+ this.#syncCreditClock();
1661
1685
  const lines: string[] = [];
1662
1686
 
1663
1687
  const searchIcon = theme.fg("accent", theme.symbol("icon.search"));
@@ -1749,6 +1773,30 @@ export class ModelBrowser implements Component {
1749
1773
 
1750
1774
  invalidate(): void {}
1751
1775
 
1776
+ /** Called for every listed model and before a row is memoized: its credit rate changes at its next dated card. */
1777
+ #noteCreditChange(model: Model): void {
1778
+ const at = getFactoryDroidCreditRate(model)?.next?.at;
1779
+ if (at !== undefined && at < this.#nextCreditChange) this.#nextCreditChange = at;
1780
+ }
1781
+
1782
+ /**
1783
+ * A dated credit rate took effect since rows were memoized: rebuild every
1784
+ * memoized row, and re-rank the list, whose `free` search word follows the
1785
+ * rate too.
1786
+ */
1787
+ #syncCreditClock(): void {
1788
+ if (Date.now() < this.#nextCreditChange) return;
1789
+ this.#nextCreditChange = Number.POSITIVE_INFINITY;
1790
+ this.#metricCells = new WeakMap();
1791
+ this.#pickerPreview = undefined;
1792
+ this.#bumpPickerEpoch();
1793
+ this.#ranker = undefined;
1794
+ this.#menu.setItems(this.#menu.items);
1795
+ for (const item of this.#menu.items) {
1796
+ if (item.id !== "separator") this.#noteCreditChange(item.model);
1797
+ }
1798
+ }
1799
+
1752
1800
  #bumpNativeEpoch(): void {
1753
1801
  this.#nativeEpoch++;
1754
1802
  this.#itemNodes.clear();
@@ -1767,6 +1815,7 @@ export class ModelBrowser implements Component {
1767
1815
  * scrolls), and the selection's facts and role chips.
1768
1816
  */
1769
1817
  describe(): NativeNode {
1818
+ this.#syncCreditClock();
1770
1819
  this.#nativeSearch ??= row([text([span(theme.symbol("icon.search"), "accent")]), this.#searchInput], {
1771
1820
  gap: "sm",
1772
1821
  align: "center",
@@ -1837,6 +1886,7 @@ export class ModelBrowser implements Component {
1837
1886
  if (item.id === "separator") return node("rule", undefined, undefined, "separator");
1838
1887
  const cached = this.#itemNodes.get(item.selector);
1839
1888
  if (cached?.item === item) return cached.node;
1889
+ this.#noteCreditChange(item.model);
1840
1890
 
1841
1891
  const label: TspSpan[] = [];
1842
1892
  if (this.#showProvider) label.push(span(`${item.provider}/`, "dim"));
@@ -1879,6 +1929,7 @@ export class ModelBrowser implements Component {
1879
1929
  return prev.node;
1880
1930
  }
1881
1931
 
1932
+ if (selected) this.#noteCreditChange(selected.model);
1882
1933
  const children: NativeChild[] = [];
1883
1934
  if (selected) {
1884
1935
  const model = selected.model;
@@ -1903,6 +1954,8 @@ export class ModelBrowser implements Component {
1903
1954
  } else if (model.tps != null && Number.isFinite(model.tps) && model.tps > 0) {
1904
1955
  facts.push(`~${formatTps(model.tps)}`);
1905
1956
  }
1957
+ const nextCredits = nextCreditRateNote(model);
1958
+ if (nextCredits) facts.push(nextCredits);
1906
1959
  children.push(text([span(facts.join(" · "), "muted")], { wrap: "word" }));
1907
1960
  const description = model.description ? formatDescription(model.description) : "";
1908
1961
  if (description) children.push(text([span(description, "dim")], { wrap: "word", lines: 2 }));
@@ -1977,6 +2030,7 @@ export class ModelBrowser implements Component {
1977
2030
  * role moving) keeps the last whole `items` and patches it.
1978
2031
  */
1979
2032
  pickerItems(catalogue: readonly ModelBrowserItem[]): ModelPickerCatalogue {
2033
+ this.#syncCreditClock();
1980
2034
  const memo = this.#pickerItems;
1981
2035
  if (memo?.catalogue === catalogue && memo.epoch === this.#pickerEpoch && memo.roles === this.#roles) {
1982
2036
  return memo.value;
@@ -2028,6 +2082,7 @@ export class ModelBrowser implements Component {
2028
2082
  ) {
2029
2083
  return cached.value;
2030
2084
  }
2085
+ this.#noteCreditChange(model);
2031
2086
  const facts: Record<string, TspText | number> = {};
2032
2087
  const int = model.int != null && Number.isFinite(model.int) ? model.int : undefined;
2033
2088
  if (int !== undefined) facts.int = String(Math.round(int));
@@ -2174,6 +2229,7 @@ export class ModelBrowser implements Component {
2174
2229
  * below the list): one inline fact line and the held-role chips.
2175
2230
  */
2176
2231
  pickerPreview(mode: "full" | "compact", current?: string): readonly NativeChild[] {
2232
+ this.#syncCreditClock();
2177
2233
  const selected = this.getSelected();
2178
2234
  const item = selected && !this.#isDisabled(selected) ? selected : undefined;
2179
2235
  const key = `${mode}\0${current ?? ""}\0${this.#settings.revision}`;
@@ -2187,6 +2243,7 @@ export class ModelBrowser implements Component {
2187
2243
  ) {
2188
2244
  return memo.children;
2189
2245
  }
2246
+ if (item) this.#noteCreditChange(item.model);
2190
2247
  const children = item ? this.modelPreview(item, mode, current) : [];
2191
2248
  this.#pickerPreview = { item, epoch: this.#pickerEpoch, roles: this.#roles, key, children };
2192
2249
  return children;
@@ -2232,6 +2289,8 @@ export class ModelBrowser implements Component {
2232
2289
  if (ctx > 0) facts.push({ k: "ctx", v: formatNumber(ctx).toLowerCase() });
2233
2290
  if (out > 0) facts.push({ k: "out", v: formatNumber(out).toLowerCase() });
2234
2291
  facts.push({ k: "price", v: isFreeModel(model) ? "free" : formatCostDetail(model) });
2292
+ const nextCredits = nextCreditRateNote(model);
2293
+ if (nextCredits) facts.push({ k: "then", v: nextCredits });
2235
2294
  facts.push({ k: "reasoning", v: model.reasoning ? "yes" : "no" });
2236
2295
  const children: NativeChild[] = [node("kv", { items: facts, layout: "inline" })];
2237
2296
  const chips: NativeChild[] = [];
@@ -1485,10 +1485,15 @@ export interface SessionSelectorOptions<T extends SessionSelectorEntry = Session
1485
1485
  /** Persist the selected session's pin state (pin keys / the picker's Pin action). */
1486
1486
  onSetPinned?: (session: T, pinned: boolean) => Promise<void>;
1487
1487
  historyMatcher?: SessionHistoryMatcher;
1488
+ /**
1489
+ * Complete folder listing when the constructor's `sessions` are a preliminary
1490
+ * subset; replaces them once it settles.
1491
+ */
1492
+ completeSessions?: Promise<T[]>;
1488
1493
  /** Loads sessions across all projects for the all-projects scope toggle (Tab). */
1489
- loadAllSessions?: () => Promise<T[]>;
1494
+ loadAllSessions?: () => Promise<T[] | { sessions: T[] }>;
1490
1495
  /** Preloaded all-projects list; cached so the first Tab toggle is instant. */
1491
- allSessions?: T[];
1496
+ allSessions?: T[] | { sessions: T[] };
1492
1497
  /**
1493
1498
  * The host's resume model (project → workspace → conversation) and its
1494
1499
  * pure view builder. When set, the native `picker` describes the resume
@@ -1601,7 +1606,7 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1601
1606
  #onRename?: (session: T, title: string) => Promise<string | null>;
1602
1607
  #onSetPinned?: (session: T, pinned: boolean) => Promise<void>;
1603
1608
  #onRequestRender?: () => void;
1604
- readonly #loadAllSessions?: () => Promise<T[]>;
1609
+ readonly #loadAllSessions?: () => Promise<T[] | { sessions: T[] }>;
1605
1610
  #folderSessions: T[];
1606
1611
  readonly #folderShowCwd: boolean;
1607
1612
  #globalSessions: T[] | null = null;
@@ -1714,13 +1719,27 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1714
1719
  // Storage directory, not recorded cwd: one folder's sessions may record
1715
1720
  // symlink aliases of the same path, which must not turn the column on.
1716
1721
  this.#folderShowCwd = options.showCwd ?? new Set(sessions.map(session => path.dirname(session.path))).size > 1;
1717
- this.#globalSessions = options.allSessions ?? null;
1722
+ this.#globalSessions = Array.isArray(options.allSessions)
1723
+ ? options.allSessions
1724
+ : (options.allSessions?.sessions ?? null);
1718
1725
  this.#getTerminalRows = options.getTerminalRows ?? (() => 24);
1719
1726
  this.#fillHeight = options.fillHeight ?? false;
1720
1727
  this.#title = options.title ?? tuiText("ssTitleResume", "Resume Session");
1721
1728
  this.#actionLabel = options.actionLabel ?? "Resume";
1722
1729
  this.#pickerTitle = options.title;
1723
1730
  this.#standalone = options.standalone ?? false;
1731
+ if (options.completeSessions) {
1732
+ void options.completeSessions.then(rows => {
1733
+ const next = rows.filter(row => !this.#resumeHidden.has(row.path));
1734
+ const selected = this.#sessionList.selectedSession?.path;
1735
+ this.#folderSessions = next;
1736
+ if (this.#scope === "folder") {
1737
+ this.#sessionList.setSessions(next, this.#folderShowCwd);
1738
+ if (selected) this.#sessionList.selectSession(selected);
1739
+ }
1740
+ this.#onRequestRender?.();
1741
+ });
1742
+ }
1724
1743
  this.#resumeSource = options.resumeSource;
1725
1744
  this.#resumeScope = options.resumeSource?.initialScope ?? "workspace";
1726
1745
  this.#deleteMode = options.deleteMode ?? options.resumeSource?.deleteMode ?? "permanent";
@@ -1852,7 +1871,8 @@ export class SessionSelectorComponent<T extends SessionSelectorEntry = SessionSe
1852
1871
  this.#message = { kind: "loading", text: loading };
1853
1872
  this.#onRequestRender?.();
1854
1873
  try {
1855
- global = await this.#loadAllSessions();
1874
+ const loaded = await this.#loadAllSessions();
1875
+ global = Array.isArray(loaded) ? loaded : loaded.sessions;
1856
1876
  } catch (err) {
1857
1877
  this.#showError(err instanceof Error ? err.message : String(err));
1858
1878
  this.#toggling = false;
@@ -116,7 +116,7 @@ export const TAB_LEADS: Record<SettingTab, string> = {
116
116
  */
117
117
  export const TAB_GROUPS: Record<SettingTab, readonly string[]> = {
118
118
  appearance: ["General", "Theme", "Composer", "Status Line", "Display", "Images"],
119
- model: ["Thinking", "Sampling", "Prompt", "Roles", "Retry & Fallback", "Advisor", "Prewalk", "Vision"],
119
+ model: ["Thinking", "Sampling", "Prompt", "Catalog", "Roles", "Retry & Fallback", "Advisor", "Prewalk", "Vision"],
120
120
  interaction: [
121
121
  "Input",
122
122
  "Approvals",
@@ -132,7 +132,7 @@ export const TAB_GROUPS: Record<SettingTab, readonly string[]> = {
132
132
  "Skills",
133
133
  ],
134
134
  context: ["General", "Compaction", "Zeta Context Cache", "Rules (TTSR)", "Experimental"],
135
- memory: ["General", "Auto-Learn", "Mnemopi", "Hindsight", "Sharpshooter"],
135
+ memory: ["General", "Taste", "Auto-Learn", "Mnemopi", "Hindsight", "Sharpshooter"],
136
136
  files: ["Editing", "Reading", "Read Summaries", "LSP", "Session Trash"],
137
137
  shell: ["Bash", "Eval & Runtimes"],
138
138
  tools: [