@oh-my-pi/pi-tui 18.8.6 → 18.8.8
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/CHANGELOG.md +45 -79
- package/README.md +7 -5
- package/dist/types/chat/assistant-message.d.ts +1 -0
- package/dist/types/chat/compaction-summary-message.d.ts +1 -0
- package/dist/types/chat/execution-shared.d.ts +6 -5
- package/dist/types/chat/user-message.d.ts +2 -0
- package/dist/types/components/box.d.ts +1 -0
- package/dist/types/components/disclosure.d.ts +1 -0
- package/dist/types/components/image.d.ts +1 -0
- package/dist/types/components/key-value-list.d.ts +1 -0
- package/dist/types/components/layout/row.d.ts +1 -0
- package/dist/types/components/layout/stack.d.ts +1 -0
- package/dist/types/components/markdown.d.ts +1 -0
- package/dist/types/components/scroll-view.d.ts +1 -0
- package/dist/types/components/section.d.ts +1 -0
- package/dist/types/components/table.d.ts +1 -0
- package/dist/types/components/text.d.ts +1 -0
- package/dist/types/components/truncated-text.d.ts +1 -0
- package/dist/types/keybinding-matchers.d.ts +3 -0
- package/dist/types/native/blobs.d.ts +3 -1
- package/dist/types/overlays/annotation-overlay.d.ts +12 -0
- package/dist/types/overlays/annotation-types.d.ts +2 -0
- package/dist/types/overlays/hook-selector.d.ts +9 -4
- package/dist/types/overlays/model-browser.d.ts +2 -2
- package/dist/types/overlays/model-hub.d.ts +21 -4
- package/dist/types/overlays/session-observer-registry.d.ts +2 -0
- package/dist/types/overlays/session-selector.d.ts +1 -1
- package/dist/types/overlays/usage-dashboard.d.ts +3 -1
- package/dist/types/render/output-pane.d.ts +1 -0
- package/dist/types/render/render-utils.d.ts +1 -0
- package/dist/types/render/tool-card.d.ts +6 -0
- package/dist/types/render/width-aware-text.d.ts +2 -0
- package/dist/types/status-line/types.d.ts +1 -1
- package/dist/types/terminal.d.ts +10 -2
- package/dist/types/theme/symbols.d.ts +1 -1
- package/dist/types/tools/eval.d.ts +1 -1
- package/dist/types/tools/native-view.d.ts +47 -0
- package/dist/types/tools/renderer.d.ts +15 -2
- package/dist/types/tools/write.d.ts +1 -1
- package/dist/types/tools/yield.d.ts +22 -0
- package/dist/types/tui.d.ts +31 -0
- package/dist/types/vim.d.ts +19 -5
- package/package.json +9 -9
- package/src/chat/advisor-message.ts +11 -0
- package/src/chat/assistant-message.ts +6 -0
- package/src/chat/compaction-summary-message.ts +8 -0
- package/src/chat/execution-shared.ts +42 -25
- package/src/chat/read-tool-group.ts +6 -4
- package/src/chat/skill-message.ts +6 -0
- package/src/chat/table-chart.ts +17 -20
- package/src/chat/tool-execution.ts +27 -2
- package/src/chat/user-message.ts +14 -0
- package/src/chrome/transcript-container.ts +32 -1
- package/src/components/box.ts +5 -0
- package/src/components/disclosure.ts +8 -0
- package/src/components/editor.ts +182 -5
- package/src/components/image.ts +7 -5
- package/src/components/key-value-list.ts +4 -0
- package/src/components/layout/row.ts +7 -0
- package/src/components/layout/stack.ts +7 -0
- package/src/components/markdown.ts +8 -0
- package/src/components/scroll-view.ts +5 -0
- package/src/components/section.ts +5 -0
- package/src/components/table.ts +4 -0
- package/src/components/text.ts +7 -0
- package/src/components/truncated-text.ts +5 -0
- package/src/keybinding-matchers.ts +6 -2
- package/src/native/backend.ts +16 -15
- package/src/native/blobs.ts +43 -10
- package/src/native/reconcile.ts +4 -0
- package/src/overlays/agent-hub.ts +7 -3
- package/src/overlays/annotation-overlay.ts +87 -6
- package/src/overlays/annotation-types.ts +2 -0
- package/src/overlays/hook-selector.ts +12 -5
- package/src/overlays/model-browser.ts +3 -3
- package/src/overlays/model-hub.ts +107 -27
- package/src/overlays/session-observer-registry.ts +10 -2
- package/src/overlays/session-selector.ts +29 -19
- package/src/overlays/snapcompact-shape-preview.ts +2 -3
- package/src/overlays/usage-dashboard.ts +70 -23
- package/src/prompt/attachment-chips.ts +13 -10
- package/src/prompt/composer.ts +1 -0
- package/src/render/output-pane.ts +6 -0
- package/src/render/render-utils.ts +11 -0
- package/src/render/tool-card.ts +15 -0
- package/src/render/width-aware-text.ts +5 -0
- package/src/status-line/segments.ts +3 -0
- package/src/status-line/types.ts +1 -1
- package/src/terminal.ts +24 -3
- package/src/theme/symbols.ts +5 -0
- package/src/tools/bash.ts +92 -42
- package/src/tools/edit.ts +142 -120
- package/src/tools/eval.ts +149 -123
- package/src/tools/fetch.ts +5 -6
- package/src/tools/index.ts +2 -0
- package/src/tools/mcp.ts +15 -2
- package/src/tools/native-view.ts +102 -1
- package/src/tools/read.ts +7 -5
- package/src/tools/renderer.ts +15 -2
- package/src/tools/write.ts +70 -56
- package/src/tools/yield.ts +225 -0
- package/src/tui.ts +93 -0
- package/src/vim.ts +333 -18
package/src/native/blobs.ts
CHANGED
|
@@ -18,7 +18,13 @@ export interface NativeBlob {
|
|
|
18
18
|
readonly bytes: Uint8Array;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const blobs = new Map<string, NativeBlob
|
|
21
|
+
const blobs = new Map<string, WeakRef<NativeBlob>>();
|
|
22
|
+
const registeredBlobs = new Map<string, NativeBlob>();
|
|
23
|
+
const releasedBlobs = new FinalizationRegistry<{ id: string; reference: WeakRef<NativeBlob> }>(({ id, reference }) => {
|
|
24
|
+
if (blobs.get(id) === reference) blobs.delete(id);
|
|
25
|
+
});
|
|
26
|
+
// Props spreads preserve ownership; wire serialization omits symbol keys.
|
|
27
|
+
const kBlob = Symbol("native.blob");
|
|
22
28
|
// Registration usually repeats with the same bytes object on every describe;
|
|
23
29
|
// the tag skips rehashing it.
|
|
24
30
|
const kBlobId = Symbol("native.blobId");
|
|
@@ -27,19 +33,42 @@ interface BlobTagged {
|
|
|
27
33
|
[kBlobId]?: string;
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
export function registerNativeBlob(bytes: Uint8Array, mime: string): string {
|
|
36
|
+
function getOrCreateBlob(bytes: Uint8Array, mime: string): NativeBlob {
|
|
32
37
|
const known = (bytes as BlobTagged)[kBlobId];
|
|
33
|
-
|
|
34
|
-
const id = new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
|
|
38
|
+
const id = known ?? new Bun.CryptoHasher("sha256").update(bytes).digest("hex");
|
|
35
39
|
(bytes as BlobTagged)[kBlobId] = id;
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
let blob = blobs.get(id)?.deref();
|
|
41
|
+
if (!blob) {
|
|
42
|
+
blob = { id, mime, bytes };
|
|
43
|
+
const reference = new WeakRef(blob);
|
|
44
|
+
blobs.set(id, reference);
|
|
45
|
+
releasedBlobs.register(blob, { id, reference });
|
|
46
|
+
}
|
|
47
|
+
return blob;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Register bytes for process-lifetime, id-only use. Prefer {@link nativeImageNode} for owned images. */
|
|
51
|
+
export function registerNativeBlob(bytes: Uint8Array, mime: string): string {
|
|
52
|
+
const blob = getOrCreateBlob(bytes, mime);
|
|
53
|
+
registeredBlobs.set(blob.id, blob);
|
|
54
|
+
return blob.id;
|
|
38
55
|
}
|
|
39
56
|
|
|
40
57
|
/** A registered blob by id. */
|
|
41
58
|
export function getNativeBlob(id: string): NativeBlob | undefined {
|
|
42
|
-
return blobs.get(id);
|
|
59
|
+
return blobs.get(id)?.deref();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** An image whose props own its bytes, including while hidden, unmounted, or awaiting upload. */
|
|
63
|
+
export function nativeImageNode(
|
|
64
|
+
bytes: Uint8Array,
|
|
65
|
+
mime: string,
|
|
66
|
+
p?: Omit<TspProps<"image">, "blob" | "builtin">,
|
|
67
|
+
key?: string,
|
|
68
|
+
): NativeNode {
|
|
69
|
+
const blob = getOrCreateBlob(bytes, mime);
|
|
70
|
+
const props = { ...p, blob: blob.id, [kBlob]: blob };
|
|
71
|
+
return node("image", props, undefined, key);
|
|
43
72
|
}
|
|
44
73
|
|
|
45
74
|
/**
|
|
@@ -53,9 +82,13 @@ export function base64ImageNode(
|
|
|
53
82
|
p?: Omit<TspProps<"image">, "blob" | "builtin" | "w" | "h">,
|
|
54
83
|
key?: string,
|
|
55
84
|
): NativeNode {
|
|
56
|
-
const blob = registerNativeBlob(Buffer.from(data, "base64"), mimeType);
|
|
57
85
|
const size = getImageDimensions(data, mimeType);
|
|
58
|
-
return
|
|
86
|
+
return nativeImageNode(
|
|
87
|
+
Buffer.from(data, "base64"),
|
|
88
|
+
mimeType,
|
|
89
|
+
size ? { ...p, w: size.widthPx, h: size.heightPx } : p,
|
|
90
|
+
key,
|
|
91
|
+
);
|
|
59
92
|
}
|
|
60
93
|
|
|
61
94
|
/** `image` nodes for base64 payloads, one per slot key, rebuilt only when the slot's payload changes. */
|
package/src/native/reconcile.ts
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
import * as logger from "@oh-my-pi/pi-utils/logger";
|
|
31
31
|
import { TSP_TEXT_KINDS, type TspKind, type TspNode, type TspOp, type TspScrollBy } from "@oh-my-pi/pi-wire";
|
|
32
32
|
import { type Component, Container, CURSOR_MARKER } from "../tui";
|
|
33
|
+
import { getNativeBlob } from "./blobs";
|
|
33
34
|
import { normalizeIconProps } from "./icons";
|
|
34
35
|
import type { DescribeContext, NativeChild, NativeNode, NativeRevealAt } from "./node";
|
|
35
36
|
import { isNativeSettled } from "./settle";
|
|
@@ -291,6 +292,7 @@ export class Reconciler {
|
|
|
291
292
|
this.#prevPortals = portals;
|
|
292
293
|
this.#regions = next;
|
|
293
294
|
for (const entry of this.#dels) this.#deleteEntry(entry);
|
|
295
|
+
this.#dels = [];
|
|
294
296
|
// Parked to survive a parent/child swap but absent from the new description.
|
|
295
297
|
for (const state of this.#parked) {
|
|
296
298
|
if (!state.parked) continue;
|
|
@@ -711,6 +713,8 @@ export class Reconciler {
|
|
|
711
713
|
owner: Owner,
|
|
712
714
|
entries: readonly Entry[],
|
|
713
715
|
): Readonly<Record<string, unknown>> | undefined {
|
|
716
|
+
// Dereferencing pins the blob through this synchronous reconcile/upload job, even after settling drops its node.
|
|
717
|
+
if (node.k === "image" && node.p?.blob) getNativeBlob(node.p.blob);
|
|
714
718
|
return normalizeIconProps(node.k, this.#resolveRefs(node, owner, entries));
|
|
715
719
|
}
|
|
716
720
|
|
|
@@ -951,12 +951,16 @@ export class AgentHubOverlayComponent<TRecord extends AgentRecordLike = AgentRec
|
|
|
951
951
|
return { ...item, depth, open: this.#childrenByParent.has(ref.id) ? true : undefined };
|
|
952
952
|
}
|
|
953
953
|
if (!metrics) return item;
|
|
954
|
+
// A running agent's active time ticks terminal-side from the age at send; a settled one
|
|
955
|
+
// is frozen text. Progress `durationMs` was current when its frame arrived, so age it to now
|
|
956
|
+
// — re-sending the stale value on every repaint rewinds Tern's clock. A first frame can
|
|
957
|
+
// report 0 ms, so a progress timestamp alone makes the row clockable.
|
|
958
|
+
const progressAt = observed?.progress ? observed.progressAt : undefined;
|
|
954
959
|
const facts: Record<string, string | number> = {
|
|
955
960
|
cost: formatCost(metrics.cost),
|
|
956
|
-
// A running agent's active time ticks terminal-side; a settled one is frozen text.
|
|
957
961
|
time:
|
|
958
|
-
ref.status === "running" && metrics.durationMs > 0
|
|
959
|
-
? metrics.durationMs
|
|
962
|
+
ref.status === "running" && (metrics.durationMs > 0 || progressAt !== undefined)
|
|
963
|
+
? metrics.durationMs + (progressAt === undefined ? 0 : Math.max(0, Date.now() - progressAt))
|
|
960
964
|
: formatDuration(metrics.durationMs),
|
|
961
965
|
req: metrics.requests,
|
|
962
966
|
tools: metrics.tools,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "../index";
|
|
14
14
|
import { compositeLineAt } from "../render/composite";
|
|
15
15
|
import { wrapLiteralLine } from "../utils";
|
|
16
|
-
import {
|
|
16
|
+
import { editorKey } from "../chrome/keybinding-hints";
|
|
17
17
|
import { formatKeyHint, formatKeyHints, type KeybindingsManager } from "../app-keybindings";
|
|
18
18
|
import type { Keybinding } from "../keybindings";
|
|
19
19
|
import { sanitizeText } from "@oh-my-pi/pi-utils";
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
topBorder,
|
|
39
39
|
topBorderSplit,
|
|
40
40
|
} from "../chrome/overlay-box";
|
|
41
|
-
import { matchesAppExternalEditor } from "../keybinding-matchers";
|
|
41
|
+
import { appExternalEditorKey, matchesAppExternalEditor } from "../keybinding-matchers";
|
|
42
42
|
import type { KeyName } from "../key-hint-format";
|
|
43
43
|
import { item, keyed, node, row as rowNode, span, text } from "../native/describe";
|
|
44
44
|
import { leafKey, type NativeChild, type NativeNode, type NativeUiEvent } from "../native/node";
|
|
@@ -70,6 +70,8 @@ export interface AnnotationOverlayCallbacks {
|
|
|
70
70
|
onWarning?(message: string): void;
|
|
71
71
|
/** Open the draft in the host's editor and invoke `commit` with its result. */
|
|
72
72
|
onAnnotationExternalEditor?(draft: string, commit: (text: string | null) => void): void | Promise<void>;
|
|
73
|
+
/** Open the current source in the host's editor. The overlay stays open. */
|
|
74
|
+
onExternalEditor?(): void | Promise<void>;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
export interface CodeReviewOverlayCallbacks extends AnnotationOverlayCallbacks {
|
|
@@ -171,6 +173,8 @@ export class AnnotationOverlay implements Focusable {
|
|
|
171
173
|
#editingAnnotationIndex: number | undefined;
|
|
172
174
|
#annotationChooser: AnnotationChooser | undefined;
|
|
173
175
|
#externalOperation = false;
|
|
176
|
+
/** Set once {@link replaceTextSource} runs; the paste result then carries the edited text. */
|
|
177
|
+
#textSourceEdited = false;
|
|
174
178
|
#finished = false;
|
|
175
179
|
#annotations: CommittedAnnotation[] = [];
|
|
176
180
|
#textAnnotations: CommittedTextAnnotation[] = [];
|
|
@@ -306,6 +310,61 @@ export class AnnotationOverlay implements Focusable {
|
|
|
306
310
|
return this.#textAnnotations.map(entry => ({ ...entry.annotation }));
|
|
307
311
|
}
|
|
308
312
|
|
|
313
|
+
/** Repo-relative path of the diff file under the cursor, if this is a code review. */
|
|
314
|
+
reviewFilePath(): string | undefined {
|
|
315
|
+
const file = this.#files[this.#fileIndex];
|
|
316
|
+
if (!file) return undefined;
|
|
317
|
+
return file.newPath ?? file.oldPath ?? file.path;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Current text-source bytes, including edits applied by {@link replaceTextSource}. */
|
|
321
|
+
textSourceText(): string | undefined {
|
|
322
|
+
return this.#textSource?.text;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Replace the text under review. Line notes whose quote still sits on the
|
|
327
|
+
* same row stay; a quote that moved to exactly one row is retargeted;
|
|
328
|
+
* every other line note is dropped. Returns how many were dropped.
|
|
329
|
+
*/
|
|
330
|
+
replaceTextSource(text: string): number {
|
|
331
|
+
if (!this.#textSource) return 0;
|
|
332
|
+
this.#textSource = { ...this.#textSource, text };
|
|
333
|
+
this.#textSourceEdited = true;
|
|
334
|
+
this.#textLines = splitTextLines(text);
|
|
335
|
+
this.#viewportDriven = false;
|
|
336
|
+
this.#sourceIndex = Math.min(this.#sourceIndex, Math.max(0, this.#textLines.length - 1));
|
|
337
|
+
let dropped = 0;
|
|
338
|
+
const kept: CommittedTextAnnotation[] = [];
|
|
339
|
+
for (const entry of this.#textAnnotations) {
|
|
340
|
+
if (entry.annotation.scope !== "line") {
|
|
341
|
+
kept.push(entry);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
const quote = entry.annotation.quote;
|
|
345
|
+
if (this.#textLines[entry.sourceIndex] === quote) {
|
|
346
|
+
kept.push(entry);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const matches = this.#textLines.flatMap((line, index) => (line === quote ? [index] : []));
|
|
350
|
+
const only = matches.length === 1 ? matches[0] : undefined;
|
|
351
|
+
if (only !== undefined) {
|
|
352
|
+
kept.push({
|
|
353
|
+
sourceIndex: only,
|
|
354
|
+
annotation: { ...entry.annotation, line: only + 1 },
|
|
355
|
+
});
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
dropped++;
|
|
359
|
+
}
|
|
360
|
+
this.#textAnnotations = kept;
|
|
361
|
+
// Earlier snapshots hold notes anchored to the old text; undo must not resurrect them.
|
|
362
|
+
this.#undoStack = [];
|
|
363
|
+
this.#annotationRev++;
|
|
364
|
+
this.#nativeBody = undefined;
|
|
365
|
+
return dropped;
|
|
366
|
+
}
|
|
367
|
+
|
|
309
368
|
handleInput(data: string): void {
|
|
310
369
|
if (this.#finished || this.#externalOperation) return;
|
|
311
370
|
if (this.#annotationChooser) {
|
|
@@ -328,6 +387,10 @@ export class AnnotationOverlay implements Focusable {
|
|
|
328
387
|
this.#escape();
|
|
329
388
|
return;
|
|
330
389
|
}
|
|
390
|
+
if (this.#callbacks.onExternalEditor && matchesAppExternalEditor(data)) {
|
|
391
|
+
void this.#openSourceEditor();
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
331
394
|
if (data === "A" && (this.#focus === "files" || this.#focus === "diff")) {
|
|
332
395
|
this.#startAnnotation(this.#textSource ? "text" : "file");
|
|
333
396
|
return;
|
|
@@ -514,6 +577,7 @@ export class AnnotationOverlay implements Focusable {
|
|
|
514
577
|
this.#finish({
|
|
515
578
|
action: "paste",
|
|
516
579
|
annotations: this.getTextAnnotations(),
|
|
580
|
+
...(this.#textSourceEdited ? { editedText: this.#textSource.text } : {}),
|
|
517
581
|
});
|
|
518
582
|
} else {
|
|
519
583
|
this.#finish({
|
|
@@ -832,6 +896,22 @@ export class AnnotationOverlay implements Focusable {
|
|
|
832
896
|
}
|
|
833
897
|
}
|
|
834
898
|
|
|
899
|
+
async #openSourceEditor(): Promise<void> {
|
|
900
|
+
const openEditor = this.#callbacks.onExternalEditor;
|
|
901
|
+
if (this.#externalOperation || !openEditor) return;
|
|
902
|
+
this.#externalOperation = true;
|
|
903
|
+
try {
|
|
904
|
+
await openEditor();
|
|
905
|
+
} catch (error) {
|
|
906
|
+
this.#callbacks.onWarning?.(
|
|
907
|
+
`Failed to open external editor: ${error instanceof Error ? error.message : String(error)}`,
|
|
908
|
+
);
|
|
909
|
+
} finally {
|
|
910
|
+
this.#externalOperation = false;
|
|
911
|
+
this.#tui.requestRender(true);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
835
915
|
#annotationCount(fileIndex: number): number {
|
|
836
916
|
let count = 0;
|
|
837
917
|
for (const entry of this.#annotations) if (entry.fileIndex === fileIndex) count++;
|
|
@@ -1091,8 +1171,7 @@ export class AnnotationOverlay implements Focusable {
|
|
|
1091
1171
|
`${editorKey("tui.input.newLine")} newline`,
|
|
1092
1172
|
`${this.#key("tui.select.cancel")} cancel`,
|
|
1093
1173
|
];
|
|
1094
|
-
|
|
1095
|
-
if (externalEditorKey) hints.push(`${externalEditorKey} editor`);
|
|
1174
|
+
hints.push(`${formatKeyHint(appExternalEditorKey())} editor`);
|
|
1096
1175
|
return [caption, ...this.#editor.render(width), this.#theme.fg("dim", hints.join(" · "))];
|
|
1097
1176
|
}
|
|
1098
1177
|
return [this.#theme.fg("dim", this.#helpText())];
|
|
@@ -1143,7 +1222,8 @@ export class AnnotationOverlay implements Focusable {
|
|
|
1143
1222
|
: this.#focus === "diff"
|
|
1144
1223
|
? `${upDown} line · ${formatKeyHint("shift")} faster · ${this.#key("tui.select.pageUp")}/${this.#key("tui.select.pageDown")} · ${formatKeyHints(["g", "shift+g"])} ends · ${formatKeyHint("a")} line note · ${formatKeyHint("shift+a")} ${this.#textSource ? "text" : "file"} note · ${editNote}`
|
|
1145
1224
|
: `${upDown} select · ${confirm} confirm`;
|
|
1146
|
-
|
|
1225
|
+
const editorHint = this.#callbacks.onExternalEditor ? ` · ${formatKeyHint(appExternalEditorKey())} editor` : "";
|
|
1226
|
+
return `${focusHelp} · ${formatKeyHint("u")} undo · ${formatKeyHint("tab")} regions${editorHint} · ${this.#key("tui.select.cancel")} cancel`;
|
|
1147
1227
|
}
|
|
1148
1228
|
|
|
1149
1229
|
#ensureCursorVisible(renderedRowBySource: readonly number[]): boolean {
|
|
@@ -1523,7 +1603,7 @@ export class AnnotationOverlay implements Focusable {
|
|
|
1523
1603
|
this.#hint("tui.input.submit", "save"),
|
|
1524
1604
|
this.#hint("tui.input.newLine", "newline"),
|
|
1525
1605
|
this.#hint("tui.select.cancel", "cancel"),
|
|
1526
|
-
|
|
1606
|
+
{ keys: [appExternalEditorKey()], label: "editor" },
|
|
1527
1607
|
],
|
|
1528
1608
|
"annotateHints",
|
|
1529
1609
|
),
|
|
@@ -1549,6 +1629,7 @@ export class AnnotationOverlay implements Focusable {
|
|
|
1549
1629
|
editNote,
|
|
1550
1630
|
]
|
|
1551
1631
|
: [upDown("select"), this.#hint("tui.select.confirm", "confirm")];
|
|
1632
|
+
if (this.#callbacks.onExternalEditor) hints.push({ keys: [appExternalEditorKey()], label: "editor" });
|
|
1552
1633
|
hints.push(key("u", "undo"), key("tab", "regions"), this.#hint("tui.select.cancel", "cancel"));
|
|
1553
1634
|
return [hintsRow(hints)];
|
|
1554
1635
|
}
|
|
@@ -94,6 +94,10 @@ export interface HookSelectorOptions {
|
|
|
94
94
|
/** Number of leading options (original order) that receive a selection
|
|
95
95
|
* marker. Defaults to every option when {@link selectionMarker} is set. */
|
|
96
96
|
markableCount?: number;
|
|
97
|
+
/** Describe as a card in the dock (the composer slot) instead of a picker
|
|
98
|
+
* sheet, so dock content above it (e.g. a `/omfg` candidate rule) stays
|
|
99
|
+
* visible and the transcript stays scrollable on native surfaces. */
|
|
100
|
+
inline?: boolean;
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
export interface HookSelectorOption {
|
|
@@ -210,6 +214,7 @@ export class HookSelectorComponent extends OverlayPanel {
|
|
|
210
214
|
#sliderComponent: Text | undefined;
|
|
211
215
|
#lastRenderWidth: number | undefined;
|
|
212
216
|
readonly #detailLines: readonly string[];
|
|
217
|
+
readonly #inline: boolean;
|
|
213
218
|
readonly #helpText: string | undefined;
|
|
214
219
|
/** Described option rows by original index; `marker` is the radio state baked into the label. */
|
|
215
220
|
readonly #nativeItems = new Map<number, { marker: boolean; node: NativeNode }>();
|
|
@@ -264,6 +269,7 @@ export class HookSelectorComponent extends OverlayPanel {
|
|
|
264
269
|
this.#baseTitle = this.title;
|
|
265
270
|
this.#detailLines = title.split(/\r?\n/).slice(1);
|
|
266
271
|
this.#helpText = opts?.helpText;
|
|
272
|
+
this.#inline = opts?.inline ?? false;
|
|
267
273
|
this.#onLeftCallback = opts?.onLeft;
|
|
268
274
|
this.#onRightCallback = opts?.onRight;
|
|
269
275
|
this.#onExternalEditorCallback = opts?.onExternalEditor;
|
|
@@ -726,13 +732,14 @@ export class HookSelectorComponent extends OverlayPanel {
|
|
|
726
732
|
}
|
|
727
733
|
|
|
728
734
|
/**
|
|
729
|
-
* A plain option list is a picker sheet. Otherwise
|
|
730
|
-
* title (plus the countdown `elapsed` when a
|
|
731
|
-
* lines, the slider as `tabs`, the options as
|
|
732
|
-
* option index, the search query while typing,
|
|
735
|
+
* A plain option list is a picker sheet. Otherwise (inline, slider, or
|
|
736
|
+
* countdown) a card headed by the title (plus the countdown `elapsed` when a
|
|
737
|
+
* timeout runs), the extra title lines, the slider as `tabs`, the options as
|
|
738
|
+
* a `list` keyed by original option index, the search query while typing,
|
|
739
|
+
* and the key hints.
|
|
733
740
|
*/
|
|
734
741
|
override describe(cx: DescribeContext): NativeNode {
|
|
735
|
-
if (cx.supports("picker") && !this.#slider && !this.#countdown) return this.#describePicker();
|
|
742
|
+
if (cx.supports("picker") && !this.#inline && !this.#slider && !this.#countdown) return this.#describePicker();
|
|
736
743
|
const items = this.#menu.visibleItems;
|
|
737
744
|
const selected = this.#menu.selectedKey;
|
|
738
745
|
const query = this.#menu.query;
|
|
@@ -126,8 +126,8 @@ export interface ResolvedModelRoleValue {
|
|
|
126
126
|
export interface ModelCompactionPoint {
|
|
127
127
|
/** Context tokens that trigger auto-compaction; undefined when auto-compaction is off or the window is unknown. */
|
|
128
128
|
tokens: number | undefined;
|
|
129
|
-
/**
|
|
130
|
-
|
|
129
|
+
/** Why it triggers there, in a few words: `fixed`, `85% of 400K base`, `80% of window`. */
|
|
130
|
+
basis?: string;
|
|
131
131
|
/** What sets it: the matching `compaction.modelThresholds` key, `global`, or `default`. */
|
|
132
132
|
source: string;
|
|
133
133
|
/** The model's own exact entry as editable text (`90k`, `80%`); absent when it has none. */
|
|
@@ -2174,7 +2174,7 @@ export class ModelBrowser implements Component {
|
|
|
2174
2174
|
const value =
|
|
2175
2175
|
compaction.tokens === undefined
|
|
2176
2176
|
? "off"
|
|
2177
|
-
: `${compaction.tokens.toLocaleString("en-US")}${compaction.
|
|
2177
|
+
: `${compaction.tokens.toLocaleString("en-US")}${compaction.basis !== undefined ? ` · ${compaction.basis}` : ""}`;
|
|
2178
2178
|
facts.push({
|
|
2179
2179
|
k: [span("Compacts at", "muted")],
|
|
2180
2180
|
v: [span(value, "mono"), span(` · ${compaction.source}`, "dim")],
|
|
@@ -48,7 +48,7 @@ import type {
|
|
|
48
48
|
ResolvedModelRoleValue,
|
|
49
49
|
} from "./model-browser";
|
|
50
50
|
import { AUTO_THINKING, type ConfiguredThinkingLevel, getConfiguredThinkingLevelMetadata } from "../thinking";
|
|
51
|
-
import { thinkingLevelGlyph } from "../render/render-utils";
|
|
51
|
+
import { sanitizeDisplayWarning, thinkingLevelGlyph } from "../render/render-utils";
|
|
52
52
|
import { theme } from "../theme/theme";
|
|
53
53
|
import { matchesSelectCancel, matchesSelectDown, matchesSelectUp } from "../keybinding-matchers";
|
|
54
54
|
import {
|
|
@@ -171,14 +171,30 @@ export interface ModelHubCallbacks {
|
|
|
171
171
|
/** Persist a new quick-switch cycle order (the ctrl+p role cycle). */
|
|
172
172
|
onCycleOrderChange?: (order: string[]) => void;
|
|
173
173
|
/**
|
|
174
|
-
* Persist typed text as `model`'s own compaction
|
|
175
|
-
* `
|
|
176
|
-
*
|
|
174
|
+
* Persist typed text as `model`'s own compaction limit: a token base the
|
|
175
|
+
* policy scales (`400k`), a fixed trigger (`f400k`), a percentage (`80%`), or
|
|
176
|
+
* empty to reset. Rejected input returns `{ kind: "error" }`; input that
|
|
177
|
+
* needs acknowledgement (one that opens the extended window) returns
|
|
178
|
+
* `{ kind: "confirm" }` until called again with the same text and
|
|
179
|
+
* `confirmed`. Either keeps the field open.
|
|
177
180
|
*/
|
|
178
|
-
onCompactionPointChange?: (
|
|
181
|
+
onCompactionPointChange?: (
|
|
182
|
+
model: Model,
|
|
183
|
+
input: string,
|
|
184
|
+
confirmed: boolean,
|
|
185
|
+
) => CompactionPointChangeResult | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* One short line on where `model` would compact with the typed limit
|
|
188
|
+
* (`compacts at 340K · 85% of 400K base`), shown beside the field while
|
|
189
|
+
* typing; undefined for input that does not parse or fit.
|
|
190
|
+
*/
|
|
191
|
+
previewCompactionPoint?: (model: Model, input: string) => string | undefined;
|
|
179
192
|
onCancel: () => void;
|
|
180
193
|
}
|
|
181
194
|
|
|
195
|
+
/** Why {@link ModelHubCallbacks.onCompactionPointChange} kept the field open. */
|
|
196
|
+
export type CompactionPointChangeResult = { kind: "error"; message: string } | { kind: "confirm"; message: string };
|
|
197
|
+
|
|
182
198
|
export interface ModelHubOptions {
|
|
183
199
|
/** Preselect this provider's sidebar entry (e.g. when reopening after /login). */
|
|
184
200
|
initialProviderId?: string;
|
|
@@ -232,12 +248,18 @@ type StripState =
|
|
|
232
248
|
input: Input;
|
|
233
249
|
}
|
|
234
250
|
| {
|
|
235
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* Footer text input setting `model`'s compaction limit; `error` is the last
|
|
253
|
+
* rejection, `confirm` the warning a second Enter on the same `value`
|
|
254
|
+
* accepts, `preview` the host's live line for the typed `value`.
|
|
255
|
+
*/
|
|
236
256
|
kind: "name";
|
|
237
257
|
purpose: "compaction";
|
|
238
258
|
model: Model;
|
|
239
259
|
input: Input;
|
|
240
260
|
error?: string;
|
|
261
|
+
confirm?: { value: string; message: string };
|
|
262
|
+
preview?: { value: string; text: string | undefined };
|
|
241
263
|
};
|
|
242
264
|
|
|
243
265
|
/** A Roles-view command; keys and the picker's action bar both run {@link ModelHubComponent}'s `#runRolesAction`. */
|
|
@@ -302,8 +324,41 @@ function providerInitials(providerId: string): string {
|
|
|
302
324
|
|
|
303
325
|
const PROVIDER_REFRESH_DEBOUNCE_MS = 120;
|
|
304
326
|
const RECENT_LIMIT = 15;
|
|
305
|
-
/** Accepted compaction
|
|
306
|
-
const COMPACTION_INPUT_HINT = "
|
|
327
|
+
/** Accepted compaction limit input, shown beside the field: a scaled base, a fixed trigger, or a percentage. */
|
|
328
|
+
const COMPACTION_INPUT_HINT = "400k base · f400k fixed · 80% · empty resets";
|
|
329
|
+
|
|
330
|
+
type CompactionStrip = Extract<StripState, { purpose: "compaction" }>;
|
|
331
|
+
|
|
332
|
+
/** Whether the compaction field still holds the text its pending warning was raised for. */
|
|
333
|
+
function compactionConfirmPending(strip: CompactionStrip): boolean {
|
|
334
|
+
return strip.confirm !== undefined && strip.confirm.value === strip.input.getValue();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The note beside the compaction field: the last error, a pending warning, the
|
|
339
|
+
* host's live preview of the typed limit, or (empty or unparsed input) the
|
|
340
|
+
* input syntax. Host text embeds model ids and config text, so it is
|
|
341
|
+
* sanitized for every render path (terminal footer, Tern picker and strip).
|
|
342
|
+
*/
|
|
343
|
+
function compactionNotice(
|
|
344
|
+
strip: CompactionStrip,
|
|
345
|
+
preview: ((model: Model, input: string) => string | undefined) | undefined,
|
|
346
|
+
): { text: string; style: "error" | "warning" | "dim" } {
|
|
347
|
+
if (strip.error) return { text: sanitizeDisplayWarning(strip.error), style: "error" };
|
|
348
|
+
// The footer hint and the primary action already say Enter accepts; the
|
|
349
|
+
// notice stays short so it fits beside the field.
|
|
350
|
+
if (strip.confirm && compactionConfirmPending(strip)) {
|
|
351
|
+
return { text: sanitizeDisplayWarning(strip.confirm.message), style: "warning" };
|
|
352
|
+
}
|
|
353
|
+
const value = strip.input.getValue();
|
|
354
|
+
if (preview && value.trim().length > 0) {
|
|
355
|
+
// Renders repeat per frame; ask the host once per typed value.
|
|
356
|
+
if (strip.preview?.value !== value) strip.preview = { value, text: preview(strip.model, value) };
|
|
357
|
+
if (strip.preview.text) return { text: sanitizeDisplayWarning(strip.preview.text), style: "dim" };
|
|
358
|
+
}
|
|
359
|
+
return { text: COMPACTION_INPUT_HINT, style: "dim" };
|
|
360
|
+
}
|
|
361
|
+
|
|
307
362
|
const MODEL_KIND_TABS: ReadonlyArray<"all" | ModelKind> = ["all", ...MODEL_KINDS];
|
|
308
363
|
const ROLE_TABS = ["all", "chat", "kind"] as const;
|
|
309
364
|
type RoleTab = (typeof ROLE_TABS)[number];
|
|
@@ -1800,9 +1855,16 @@ export class ModelHubComponent implements Component {
|
|
|
1800
1855
|
const strip = this.#strip;
|
|
1801
1856
|
if (strip?.kind !== "name") return;
|
|
1802
1857
|
if (strip.purpose === "compaction") {
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1805
|
-
|
|
1858
|
+
const value = strip.input.getValue();
|
|
1859
|
+
const result = this.#callbacks.onCompactionPointChange?.(strip.model, value, compactionConfirmPending(strip));
|
|
1860
|
+
if (result?.kind === "error") {
|
|
1861
|
+
strip.error = result.message;
|
|
1862
|
+
strip.confirm = undefined;
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
if (result?.kind === "confirm") {
|
|
1866
|
+
strip.error = undefined;
|
|
1867
|
+
strip.confirm = { value, message: result.message };
|
|
1806
1868
|
return;
|
|
1807
1869
|
}
|
|
1808
1870
|
this.#strip = null;
|
|
@@ -2721,7 +2783,9 @@ export class ModelHubComponent implements Component {
|
|
|
2721
2783
|
const strip = this.#strip;
|
|
2722
2784
|
if (strip) {
|
|
2723
2785
|
if (strip.kind === "name") {
|
|
2724
|
-
if (strip.purpose === "compaction")
|
|
2786
|
+
if (strip.purpose === "compaction") {
|
|
2787
|
+
return `${enter} ${compactionConfirmPending(strip) ? "accept" : "set"} compaction point · ${cancel} cancel`;
|
|
2788
|
+
}
|
|
2725
2789
|
if (strip.purpose === "preset") {
|
|
2726
2790
|
return `${enter} save preset · ${cancel} cancel`;
|
|
2727
2791
|
}
|
|
@@ -2808,19 +2872,23 @@ export class ModelHubComponent implements Component {
|
|
|
2808
2872
|
if (strip.kind === "name") {
|
|
2809
2873
|
const labelText =
|
|
2810
2874
|
strip.purpose === "compaction"
|
|
2811
|
-
?
|
|
2875
|
+
? `${strip.model.id} limit:`
|
|
2812
2876
|
: strip.purpose === "preset"
|
|
2813
2877
|
? "Preset name:"
|
|
2814
2878
|
: "New role name:";
|
|
2815
2879
|
const label = theme.fg("accent", labelText);
|
|
2816
|
-
|
|
2880
|
+
// A compaction point is at most a few characters (`1500k`, `12.5%`); a
|
|
2881
|
+
// narrow field leaves the row for its notice.
|
|
2882
|
+
const maxInputWidth = strip.purpose === "compaction" ? 10 : 32;
|
|
2883
|
+
const inputWidth = Math.max(8, Math.min(maxInputWidth, width - visibleWidth(labelText) - 24));
|
|
2817
2884
|
const inputLine = strip.input.render(inputWidth)[0] ?? "";
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2885
|
+
let hint: string;
|
|
2886
|
+
if (strip.purpose === "compaction") {
|
|
2887
|
+
const notice = compactionNotice(strip, this.#callbacks.previewCompactionPoint);
|
|
2888
|
+
hint = theme.fg(notice.style, notice.text);
|
|
2889
|
+
} else {
|
|
2890
|
+
hint = theme.fg("dim", "(letters, digits, - and _)");
|
|
2891
|
+
}
|
|
2824
2892
|
return truncateToWidth(`${label} ${inputLine} ${hint}`, width);
|
|
2825
2893
|
}
|
|
2826
2894
|
|
|
@@ -3475,7 +3543,12 @@ export class ModelHubComponent implements Component {
|
|
|
3475
3543
|
const apply =
|
|
3476
3544
|
strip.kind === "name"
|
|
3477
3545
|
? strip.purpose === "compaction"
|
|
3478
|
-
? pickerAction(
|
|
3546
|
+
? pickerAction(
|
|
3547
|
+
"compactionPoint",
|
|
3548
|
+
compactionConfirmPending(strip) ? "Accept compaction point" : "Set compaction point",
|
|
3549
|
+
"enter",
|
|
3550
|
+
{ primary: true },
|
|
3551
|
+
)
|
|
3479
3552
|
: pickerAction(
|
|
3480
3553
|
strip.purpose === "preset" ? "presetName" : "roleName",
|
|
3481
3554
|
strip.purpose === "preset" ? "Save preset" : "Create role",
|
|
@@ -3579,14 +3652,14 @@ export class ModelHubComponent implements Component {
|
|
|
3579
3652
|
#pickerStrip(strip: StripState): NonNullable<TspPickerProps["strip"]> {
|
|
3580
3653
|
if (strip.kind === "name") {
|
|
3581
3654
|
if (strip.purpose === "compaction") {
|
|
3655
|
+
const notice = compactionNotice(strip, this.#callbacks.previewCompactionPoint);
|
|
3582
3656
|
return {
|
|
3583
3657
|
label: [
|
|
3584
|
-
span("Compact ", "muted"),
|
|
3585
3658
|
span(strip.model.id, "mono"),
|
|
3586
|
-
span("
|
|
3659
|
+
span(" limit ", "muted"),
|
|
3587
3660
|
span(strip.input.getValue(), "mono"),
|
|
3588
3661
|
span("▏", "accent"),
|
|
3589
|
-
span(` ${
|
|
3662
|
+
span(` ${notice.text}`, notice.style),
|
|
3590
3663
|
],
|
|
3591
3664
|
items: [],
|
|
3592
3665
|
};
|
|
@@ -3965,13 +4038,14 @@ export class ModelHubComponent implements Component {
|
|
|
3965
4038
|
if (!strip) return undefined;
|
|
3966
4039
|
if (strip.kind === "name") {
|
|
3967
4040
|
if (strip.purpose === "compaction") {
|
|
4041
|
+
const notice = compactionNotice(strip, this.#callbacks.previewCompactionPoint);
|
|
3968
4042
|
return node(
|
|
3969
4043
|
"row",
|
|
3970
4044
|
{ gap: "sm", align: "center" },
|
|
3971
4045
|
[
|
|
3972
|
-
text([span(
|
|
4046
|
+
text([span(`${strip.model.id} limit:`, "accent")]),
|
|
3973
4047
|
col([strip.input], { grow: 1 }),
|
|
3974
|
-
text([span(
|
|
4048
|
+
text([span(notice.text, notice.style)], { wrap: "word" }),
|
|
3975
4049
|
],
|
|
3976
4050
|
"compactionPoint",
|
|
3977
4051
|
);
|
|
@@ -4030,7 +4104,13 @@ export class ModelHubComponent implements Component {
|
|
|
4030
4104
|
switch (strip.kind) {
|
|
4031
4105
|
case "name":
|
|
4032
4106
|
return strip.purpose === "compaction"
|
|
4033
|
-
? [
|
|
4107
|
+
? [
|
|
4108
|
+
keys(
|
|
4109
|
+
compactionConfirmPending(strip) ? "accept compaction point" : "set compaction point",
|
|
4110
|
+
"enter",
|
|
4111
|
+
),
|
|
4112
|
+
cancel("cancel"),
|
|
4113
|
+
]
|
|
4034
4114
|
: strip.purpose === "preset"
|
|
4035
4115
|
? [keys("save preset", "enter"), cancel("cancel")]
|
|
4036
4116
|
: [keys("create + pick model", "enter"), cancel("cancel")];
|
|
@@ -64,6 +64,8 @@ export interface ObservableSession {
|
|
|
64
64
|
lastUpdate: number;
|
|
65
65
|
/** Latest progress snapshot from the subagent executor */
|
|
66
66
|
progress?: AgentProgress;
|
|
67
|
+
/** `Date.now()` when {@link progress} arrived; its `durationMs` was current then. */
|
|
68
|
+
progressAt?: number;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
/** Coarse source of an observer change; callers use it to separate lifecycle work from high-frequency progress. */
|
|
@@ -225,6 +227,9 @@ export class SessionObserverRegistry {
|
|
|
225
227
|
existing.detached = payload.detached ?? existing.detached;
|
|
226
228
|
if (payload.description) existing.description = payload.description;
|
|
227
229
|
if (payload.sessionFile) existing.sessionFile = payload.sessionFile;
|
|
230
|
+
// A kept-alive or parked agent's next turn restarts its clock; the prior turn's
|
|
231
|
+
// snapshot must not be aged across the idle gap before the new turn's first frame.
|
|
232
|
+
if (payload.status === "started") existing.progressAt = undefined;
|
|
228
233
|
} else {
|
|
229
234
|
this.#sessions.set(payload.id, {
|
|
230
235
|
id: payload.id,
|
|
@@ -256,12 +261,14 @@ export class SessionObserverRegistry {
|
|
|
256
261
|
|
|
257
262
|
const sortOrder = this.#ensureSortOrder(id);
|
|
258
263
|
this.#ensureParentSortOrder(payload.parentToolCallId, sortOrder);
|
|
264
|
+
const now = Date.now();
|
|
259
265
|
if (existing) {
|
|
260
|
-
existing.lastUpdate =
|
|
266
|
+
existing.lastUpdate = now;
|
|
261
267
|
existing.index = payload.index;
|
|
262
268
|
existing.parentToolCallId = payload.parentToolCallId ?? existing.parentToolCallId;
|
|
263
269
|
existing.detached = payload.detached ?? existing.detached;
|
|
264
270
|
existing.progress = progress;
|
|
271
|
+
existing.progressAt = now;
|
|
265
272
|
if (progress.description) existing.description = progress.description;
|
|
266
273
|
if (payload.sessionFile) existing.sessionFile = payload.sessionFile;
|
|
267
274
|
} else {
|
|
@@ -276,8 +283,9 @@ export class SessionObserverRegistry {
|
|
|
276
283
|
parentToolCallId: payload.parentToolCallId,
|
|
277
284
|
detached: payload.detached,
|
|
278
285
|
index: payload.index,
|
|
279
|
-
lastUpdate:
|
|
286
|
+
lastUpdate: now,
|
|
280
287
|
progress,
|
|
288
|
+
progressAt: now,
|
|
281
289
|
});
|
|
282
290
|
}
|
|
283
291
|
this.#notifyListeners("progress");
|