@oh-my-pi/pi-tui 18.11.0 → 18.11.2
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 +52 -146
- package/dist/types/apps/git/git-tui.d.ts +16 -2
- package/dist/types/autocomplete.d.ts +2 -0
- package/dist/types/charts/chart-svg.d.ts +7 -13
- package/dist/types/chat/table-chart.d.ts +11 -15
- package/dist/types/chrome/transcript-container.d.ts +2 -0
- package/dist/types/components/image.d.ts +2 -0
- package/dist/types/components/markdown.d.ts +37 -0
- package/dist/types/native/blobs.d.ts +11 -11
- package/dist/types/overlays/agent-hub-projection.d.ts +10 -5
- package/dist/types/overlays/job-tree.d.ts +50 -0
- package/dist/types/overlays/jobs-panel.d.ts +24 -11
- package/dist/types/prompt/composer.d.ts +20 -0
- package/dist/types/prompt/custom-editor.d.ts +2 -0
- package/dist/types/prompt/image-references.d.ts +22 -0
- package/dist/types/prompt/macos-spelling.d.ts +2 -1
- package/dist/types/prompt/prose-gate.d.ts +3 -0
- package/dist/types/prompt/queued-messages.d.ts +1 -1
- package/dist/types/prompt/typing-word.d.ts +25 -0
- package/dist/types/render/hyperlink.d.ts +2 -0
- package/dist/types/render/utils.d.ts +1 -1
- package/dist/types/status-line/context-usage.d.ts +3 -0
- package/dist/types/status-line/host.d.ts +6 -4
- package/dist/types/status-line/startup.d.ts +6 -6
- package/dist/types/stdin-buffer.d.ts +7 -0
- package/dist/types/terminal.d.ts +8 -4
- package/dist/types/tools/eval.d.ts +5 -0
- package/dist/types/tools/grouped-file-output.d.ts +2 -0
- package/dist/types/tools/read.d.ts +5 -4
- package/dist/types/tui.d.ts +10 -0
- package/package.json +9 -9
- package/src/apps/git/git-tui.ts +27 -10
- package/src/apps/git/sidebar.ts +5 -1
- package/src/autocomplete.ts +21 -19
- package/src/bracketed-paste.ts +9 -2
- package/src/charts/chart-svg.ts +19 -22
- package/src/chat/assistant-message.ts +37 -12
- package/src/chat/bash-execution.ts +7 -2
- package/src/chat/image-loading.ts +4 -6
- package/src/chat/read-tool-group.ts +1 -0
- package/src/chat/table-chart.ts +24 -57
- package/src/chat/tool-execution.ts +11 -4
- package/src/chat/user-message.ts +22 -15
- package/src/chrome/transcript-container.ts +10 -0
- package/src/components/editor.ts +12 -12
- package/src/components/image.ts +23 -6
- package/src/components/markdown.ts +375 -6
- package/src/components/settings-list.ts +2 -4
- package/src/native/blobs.ts +22 -6
- package/src/native/reconcile.ts +19 -15
- package/src/overlays/agent-hub-projection.ts +63 -12
- package/src/overlays/btw-history-panel.ts +30 -23
- package/src/overlays/extensions/extension-list.ts +4 -6
- package/src/overlays/job-tree.ts +177 -0
- package/src/overlays/jobs-panel.ts +107 -49
- package/src/overlays/settings-selector.ts +3 -0
- package/src/prompt/composer.ts +180 -23
- package/src/prompt/custom-editor.ts +19 -1
- package/src/prompt/image-references.ts +79 -2
- package/src/prompt/macos-spelling.ts +28 -5
- package/src/prompt/prose-gate.ts +3 -0
- package/src/prompt/queued-messages.ts +9 -2
- package/src/prompt/typing-word.ts +59 -0
- package/src/render/code-cell.ts +8 -1
- package/src/render/hyperlink.ts +5 -0
- package/src/render/utils.ts +1 -1
- package/src/render/width-aware-text.ts +6 -5
- package/src/status-line/component.ts +22 -10
- package/src/status-line/context-usage.ts +22 -16
- package/src/status-line/footer.ts +18 -35
- package/src/status-line/host.ts +6 -1
- package/src/status-line/startup.ts +6 -6
- package/src/stdin-buffer.ts +11 -1
- package/src/terminal.ts +136 -42
- package/src/tools/ast-grep.ts +2 -2
- package/src/tools/edit.ts +16 -1
- package/src/tools/eval.ts +51 -11
- package/src/tools/grouped-file-output.ts +6 -1
- package/src/tools/read.ts +6 -5
- package/src/tools/write.ts +1 -1
- package/src/tui.ts +61 -30
- package/src/utils.ts +5 -3
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ImageContent } from "@oh-my-pi/pi-ai";
|
|
2
2
|
import { logger } from "@oh-my-pi/pi-utils";
|
|
3
|
+
import type { TspSpan } from "@oh-my-pi/pi-wire";
|
|
4
|
+
import { span } from "../native/describe";
|
|
5
|
+
import { isNativeRendering } from "../native/state";
|
|
6
|
+
import { fileHyperlink, fileLinkSpan, isHyperlinkEnabled, isNativeLinkEnabled } from "../render/hyperlink";
|
|
3
7
|
import { blobExtensionForImageMimeType } from "./image-format";
|
|
4
8
|
|
|
5
9
|
/** Materialized image destination returned by the host blob writer. */
|
|
6
10
|
interface ImageBlobResult {
|
|
7
11
|
displayPath: string;
|
|
8
12
|
}
|
|
9
|
-
import { fileHyperlink } from "../render/hyperlink";
|
|
10
|
-
|
|
11
13
|
/** Probed pixel dimensions riding on the draft image object itself; `null` records a failed
|
|
12
14
|
* probe so the chips band never re-decodes a corrupt header every frame. */
|
|
13
15
|
const kImageDims = Symbol("omp.imageDimensions");
|
|
@@ -100,3 +102,78 @@ export function materializeImageReferenceLinksSync(
|
|
|
100
102
|
const links = images.map((image, index) => materializeImageReferenceLink(image, index + 1, putBlob));
|
|
101
103
|
return links.some(link => link !== undefined) ? links : undefined;
|
|
102
104
|
}
|
|
105
|
+
|
|
106
|
+
let hostBlobWriter: ImageBlobWriterSync | undefined;
|
|
107
|
+
/** Blob paths already written for an image payload, keyed by mime type and content hash. */
|
|
108
|
+
const blobLinks = new Map<string, string>();
|
|
109
|
+
const BLOB_LINK_CACHE_LIMIT = 256;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Register the host's blob writer that backs links for images without a file of their
|
|
113
|
+
* own. Returns a disposer that unregisters it unless another writer replaced it since.
|
|
114
|
+
*/
|
|
115
|
+
export function setImageBlobWriter(next: ImageBlobWriterSync): () => void {
|
|
116
|
+
hostBlobWriter = next;
|
|
117
|
+
blobLinks.clear();
|
|
118
|
+
return () => {
|
|
119
|
+
if (hostBlobWriter !== next) return;
|
|
120
|
+
hostBlobWriter = undefined;
|
|
121
|
+
blobLinks.clear();
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Whether transcript images carry links under the current `tui.hyperlinks` policy: a
|
|
127
|
+
* native surface honours only an explicit `off`, text mode the resolved OSC 8 support.
|
|
128
|
+
* Renderers caching a linked image key their cache on it.
|
|
129
|
+
*/
|
|
130
|
+
export function imageLinksEnabled(): boolean {
|
|
131
|
+
return isNativeRendering() ? isNativeLinkEnabled() : isHyperlinkEnabled();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The file a transcript image opens: `sourcePath` when it was read from one, else a
|
|
136
|
+
* blob copy of its bytes written through the host. Undefined when links are disabled
|
|
137
|
+
* or no file exists, so a disabled policy never writes blobs.
|
|
138
|
+
*/
|
|
139
|
+
export function transcriptImageLink(
|
|
140
|
+
image: Pick<ImageContent, "data" | "mimeType">,
|
|
141
|
+
sourcePath?: string,
|
|
142
|
+
): string | undefined {
|
|
143
|
+
if (!imageLinksEnabled()) return undefined;
|
|
144
|
+
if (sourcePath) return sourcePath;
|
|
145
|
+
if (!hostBlobWriter || !image.data) return undefined;
|
|
146
|
+
const key = `${image.mimeType}:${Bun.hash(image.data)}`;
|
|
147
|
+
const cached = blobLinks.get(key);
|
|
148
|
+
if (cached) return cached;
|
|
149
|
+
const link = materializeImageReferenceLink({ type: "image", ...image }, 1, hostBlobWriter);
|
|
150
|
+
if (!link) return undefined;
|
|
151
|
+
if (blobLinks.size >= BLOB_LINK_CACHE_LIMIT) {
|
|
152
|
+
const oldest = blobLinks.keys().next();
|
|
153
|
+
if (!oldest.done) blobLinks.delete(oldest.value);
|
|
154
|
+
}
|
|
155
|
+
blobLinks.set(key, link);
|
|
156
|
+
return link;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** `text` (an image's placeholder) as an OSC 8 link to the image's file; plain when hyperlinks are off or no file exists. */
|
|
160
|
+
export function linkedImageText(
|
|
161
|
+
text: string,
|
|
162
|
+
image: Pick<ImageContent, "data" | "mimeType">,
|
|
163
|
+
sourcePath?: string,
|
|
164
|
+
): string {
|
|
165
|
+
if (!isHyperlinkEnabled()) return text;
|
|
166
|
+
const target = transcriptImageLink(image, sourcePath);
|
|
167
|
+
return target ? fileHyperlink(target, text) : text;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Native counterpart of {@link linkedImageText}: a span linking to the image's file when one exists. */
|
|
171
|
+
export function linkedImageSpan(
|
|
172
|
+
text: string,
|
|
173
|
+
image: Pick<ImageContent, "data" | "mimeType">,
|
|
174
|
+
sourcePath: string | undefined,
|
|
175
|
+
s?: string,
|
|
176
|
+
): TspSpan {
|
|
177
|
+
const target = transcriptImageLink(image, sourcePath);
|
|
178
|
+
return target ? fileLinkSpan(target, text, s) : span(text, s);
|
|
179
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as native from "@oh-my-pi/pi-natives";
|
|
2
2
|
import { TERMINAL } from "../index";
|
|
3
3
|
import type { EditorInlineReplacement, EditorTextAssistProvider, EditorWordReplacements } from "../components/editor";
|
|
4
|
-
import { logger } from "@oh-my-pi/pi-utils";
|
|
4
|
+
import { logger, withTimeout } from "@oh-my-pi/pi-utils";
|
|
5
5
|
import { isMagicKeyword } from "./magic-keywords";
|
|
6
6
|
import { maskNonProse } from "./markdown-prose";
|
|
7
7
|
import { isProseWord, lineContext, ProseSource, type SpellingDecorationContext } from "./prose-gate";
|
|
@@ -45,6 +45,12 @@ const NATIVE_BACKEND: SpellingBackend = {
|
|
|
45
45
|
spellingGuesses: (text, start, length) => native.macOSSpellingGuesses(text, start, length),
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The native side awaits a `flume::bounded(1)` reply with no timeout, so a stuck call
|
|
50
|
+
* stays pending and never reaches the `catch` that disables the provider.
|
|
51
|
+
*/
|
|
52
|
+
const BACKEND_TIMEOUT_MS = 2_000;
|
|
53
|
+
|
|
48
54
|
/**
|
|
49
55
|
* Bridges Apple's spelling service into the editor's typo and autocorrection
|
|
50
56
|
* paths. Word completion is the cross-platform `WordCompletionProvider`
|
|
@@ -113,7 +119,8 @@ export class MacOSSpellingProvider implements EditorTextAssistProvider {
|
|
|
113
119
|
|
|
114
120
|
/**
|
|
115
121
|
* Misspelled prose ranges in `text` (offsets into it), in order and
|
|
116
|
-
* non-overlapping
|
|
122
|
+
* non-overlapping, except ones touching `context.typing` (the word still
|
|
123
|
+
* being typed). Schedules the verification check for uncached text; its
|
|
117
124
|
* result arrives through {@link onUpdate}.
|
|
118
125
|
*/
|
|
119
126
|
typoRanges(text: string, context: SpellingDecorationContext): readonly native.SpellingRange[] {
|
|
@@ -131,9 +138,13 @@ export class MacOSSpellingProvider implements EditorTextAssistProvider {
|
|
|
131
138
|
const ranges = cached ?? this.#projectTypoRanges(text);
|
|
132
139
|
if (!ranges || ranges.length === 0) return [];
|
|
133
140
|
const kept: native.SpellingRange[] = [];
|
|
141
|
+
const typing = context.typing?.line === context.line ? context.typing : undefined;
|
|
134
142
|
let cursor = 0;
|
|
135
143
|
for (const range of ranges) {
|
|
136
144
|
const end = range.start + range.length;
|
|
145
|
+
if (typing && context.startCol + range.start <= typing.end && typing.start <= context.startCol + end) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
137
148
|
// Overlapping or out-of-bounds ranges (stale native data, edit projection)
|
|
138
149
|
// must never re-emit already-rendered text: that doubles it on screen and
|
|
139
150
|
// desyncs the rendered width from the measured width (cursor drift).
|
|
@@ -167,7 +178,11 @@ export class MacOSSpellingProvider implements EditorTextAssistProvider {
|
|
|
167
178
|
const context = lineContext(lines, cursorLine);
|
|
168
179
|
if (!this.#prose.isProse(context, start, start + word.length)) return null;
|
|
169
180
|
try {
|
|
170
|
-
const correction = await
|
|
181
|
+
const correction = await withTimeout(
|
|
182
|
+
this.backend.autocorrectWord(textBeforeCursor, start, word.length),
|
|
183
|
+
BACKEND_TIMEOUT_MS,
|
|
184
|
+
`macOS spelling service did not respond within ${BACKEND_TIMEOUT_MS}ms`,
|
|
185
|
+
);
|
|
171
186
|
if (!correction || correction === word) return null;
|
|
172
187
|
return { replaceLen: word.length + boundary.length, insert: correction + boundary };
|
|
173
188
|
} catch (error) {
|
|
@@ -200,7 +215,11 @@ export class MacOSSpellingProvider implements EditorTextAssistProvider {
|
|
|
200
215
|
try {
|
|
201
216
|
const seen = new Set<string>();
|
|
202
217
|
const items: string[] = [];
|
|
203
|
-
for (const guess of await
|
|
218
|
+
for (const guess of await withTimeout(
|
|
219
|
+
this.backend.spellingGuesses(line, range.start, range.length),
|
|
220
|
+
BACKEND_TIMEOUT_MS,
|
|
221
|
+
`macOS spelling service did not respond within ${BACKEND_TIMEOUT_MS}ms`,
|
|
222
|
+
)) {
|
|
204
223
|
if (!guess || seen.has(guess)) continue;
|
|
205
224
|
seen.add(guess);
|
|
206
225
|
items.push(guess);
|
|
@@ -305,7 +324,11 @@ export class MacOSSpellingProvider implements EditorTextAssistProvider {
|
|
|
305
324
|
async #fetchTypoRanges(text: string, generation: number): Promise<readonly native.SpellingRange[]> {
|
|
306
325
|
let checked: readonly native.SpellingRange[];
|
|
307
326
|
try {
|
|
308
|
-
checked = await
|
|
327
|
+
checked = await withTimeout(
|
|
328
|
+
this.backend.checkSpelling(text),
|
|
329
|
+
BACKEND_TIMEOUT_MS,
|
|
330
|
+
`macOS spelling service did not respond within ${BACKEND_TIMEOUT_MS}ms`,
|
|
331
|
+
);
|
|
309
332
|
} catch (error) {
|
|
310
333
|
this.#disable(error);
|
|
311
334
|
return [];
|
package/src/prompt/prose-gate.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { maskNonProse } from "./markdown-prose";
|
|
2
|
+
import type { TypingWord } from "./typing-word";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Client-side gates shared by the prose assistants (macOS typo/autocorrect and
|
|
@@ -19,6 +20,8 @@ export interface SpellingDecorationContext {
|
|
|
19
20
|
lines: readonly string[];
|
|
20
21
|
line: number;
|
|
21
22
|
startCol: number;
|
|
23
|
+
/** The word being typed: typo marks touching it wait until the caret leaves it. */
|
|
24
|
+
typing?: TypingWord | undefined;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
function tokenAt(text: string, start: number, end: number): string {
|
|
@@ -18,7 +18,7 @@ export interface QueuedMessageGroup {
|
|
|
18
18
|
* Messages queued while the agent works, above the editor. ANSI: a heading
|
|
19
19
|
* per group, numbered dim rows and the dequeue hint. Natively (§8.1): a
|
|
20
20
|
* stack of pills, each `corner-down-right` · the text · `⌥↑ Edit`, the total
|
|
21
|
-
*
|
|
21
|
+
* (`N queued`, not a position) in the first pill when more than one waits; the edit control sends
|
|
22
22
|
* `queue.edit`, answered like the dequeue key.
|
|
23
23
|
*/
|
|
24
24
|
export class QueuedMessagesBand extends Container {
|
|
@@ -63,7 +63,14 @@ export class QueuedMessagesBand extends Container {
|
|
|
63
63
|
),
|
|
64
64
|
];
|
|
65
65
|
if (pills.length === 0 && count > 1) {
|
|
66
|
-
children.push(
|
|
66
|
+
children.push(
|
|
67
|
+
node(
|
|
68
|
+
"badge",
|
|
69
|
+
{ text: `${count} queued`, title: `${count} messages queued`, role: "omp.queue.count" },
|
|
70
|
+
undefined,
|
|
71
|
+
"count",
|
|
72
|
+
),
|
|
73
|
+
);
|
|
67
74
|
}
|
|
68
75
|
children.push(
|
|
69
76
|
node(
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The word being typed in the composer. Misspelling marks hold off on it until
|
|
3
|
+
* the caret leaves it (a space or punctuation, a caret move, losing focus), the
|
|
4
|
+
* way Slack and Chromium mark a typo only once its word is done; marks on other
|
|
5
|
+
* words stay while typing.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** A word of one logical line, as UTF-16 columns `[start, end)`. */
|
|
9
|
+
export interface TypingWord {
|
|
10
|
+
line: number;
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Letters, marks and digits, with apostrophes joining contractions. */
|
|
16
|
+
const WORD_CHAR = /[\p{L}\p{M}\p{N}'\u2019]/u;
|
|
17
|
+
|
|
18
|
+
/** The run of word characters around column `col` of `line` (`undefined` between non-word characters). */
|
|
19
|
+
function wordAround(line: string, col: number): { start: number; end: number } | undefined {
|
|
20
|
+
let start = col;
|
|
21
|
+
while (start > 0 && WORD_CHAR.test(line.charAt(start - 1))) start--;
|
|
22
|
+
let end = col;
|
|
23
|
+
while (end < line.length && WORD_CHAR.test(line.charAt(end))) end++;
|
|
24
|
+
return start < end ? { start, end } : undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Follows an editor's text revision and caret to know which word is being typed. */
|
|
28
|
+
export class TypingWordTracker {
|
|
29
|
+
#revision: number | undefined;
|
|
30
|
+
#word: TypingWord | undefined;
|
|
31
|
+
|
|
32
|
+
/** The word being typed, if any. */
|
|
33
|
+
get word(): TypingWord | undefined {
|
|
34
|
+
return this.#word;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Catch up with the editor: an edit that leaves the caret in (or right after)
|
|
39
|
+
* a word starts typing it; a caret move out of that word, or losing focus,
|
|
40
|
+
* ends it. The first call only records the revision, so a restored draft is
|
|
41
|
+
* not held. Returns whether the held word changed.
|
|
42
|
+
*/
|
|
43
|
+
update(revision: number, lines: readonly string[], line: number, col: number, focused: boolean): boolean {
|
|
44
|
+
const before = this.#word;
|
|
45
|
+
const edited = this.#revision !== undefined && this.#revision !== revision;
|
|
46
|
+
this.#revision = revision;
|
|
47
|
+
if (!focused) {
|
|
48
|
+
this.#word = undefined;
|
|
49
|
+
} else if (edited) {
|
|
50
|
+
const span = wordAround(lines[line] ?? "", col);
|
|
51
|
+
this.#word = span && { line, start: span.start, end: span.end };
|
|
52
|
+
} else if (before && (before.line !== line || col < before.start || col > before.end)) {
|
|
53
|
+
this.#word = undefined;
|
|
54
|
+
}
|
|
55
|
+
return (
|
|
56
|
+
before?.line !== this.#word?.line || before?.start !== this.#word?.start || before?.end !== this.#word?.end
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/render/code-cell.ts
CHANGED
|
@@ -258,7 +258,14 @@ export function describeCodeCell(options: Omit<CodeCellOptions, "width">, theme:
|
|
|
258
258
|
const sections: NativeOutputBlockSection[] = [
|
|
259
259
|
{
|
|
260
260
|
key: "code",
|
|
261
|
-
body: [
|
|
261
|
+
body: [
|
|
262
|
+
code(options.code ?? "", {
|
|
263
|
+
lang: options.language,
|
|
264
|
+
start,
|
|
265
|
+
numbers: start !== undefined || undefined,
|
|
266
|
+
wrap: true,
|
|
267
|
+
}),
|
|
268
|
+
],
|
|
262
269
|
},
|
|
263
270
|
];
|
|
264
271
|
const output = describeCellOutput(options.output, expanded, outputMaxLines);
|
package/src/render/hyperlink.ts
CHANGED
|
@@ -196,6 +196,11 @@ export function urlLinkSpan(target: string, displayText: string, s = "link"): Ts
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
/** Whether native link spans and nodes may carry an `href`: everything but an explicit `off` policy. */
|
|
200
|
+
export function isNativeLinkEnabled(): boolean {
|
|
201
|
+
return hyperlinkMode !== "off";
|
|
202
|
+
}
|
|
203
|
+
|
|
199
204
|
/**
|
|
200
205
|
* A native link span to a filesystem path as a plain `file://` URI (the
|
|
201
206
|
* terminal opens it through the system; the location stays in the visible
|
package/src/render/utils.ts
CHANGED
|
@@ -76,7 +76,7 @@ export interface RenderCache {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/** Build indentation and continuing branches for ancestor levels. */
|
|
79
|
-
export function buildTreePrefix(ancestors: boolean[], theme: Theme): string {
|
|
79
|
+
export function buildTreePrefix(ancestors: readonly boolean[], theme: Theme): string {
|
|
80
80
|
return ancestors.map(hasNext => (hasNext ? `${theme.tree.vertical} ` : " ")).join("");
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -25,7 +25,6 @@ export class WidthAwareText implements Component {
|
|
|
25
25
|
#cachedContentWidth = -1;
|
|
26
26
|
#cachedText: string | undefined;
|
|
27
27
|
#ignoreTight = false;
|
|
28
|
-
#nativeCols = -1;
|
|
29
28
|
#native: NativeNode | undefined;
|
|
30
29
|
|
|
31
30
|
constructor(format: (contentWidth: number) => string, paddingX = 1, paddingY = 1) {
|
|
@@ -71,10 +70,12 @@ export class WidthAwareText implements Component {
|
|
|
71
70
|
* (the only width a describer knows) and again on `reformat()`.
|
|
72
71
|
*/
|
|
73
72
|
describe(cx: DescribeContext): NativeNode {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
// Native describe emits no padding, so the formatter gets the full
|
|
74
|
+
// column budget — the same width a native Text.describe() would use.
|
|
75
|
+
const contentWidth = Math.max(1, cx.cols);
|
|
76
|
+
if (this.#cachedText === undefined || contentWidth !== this.#cachedContentWidth) {
|
|
77
|
+
this.#cachedContentWidth = contentWidth;
|
|
78
|
+
this.#cachedText = this.#format(contentWidth);
|
|
78
79
|
this.#inner.setText(this.#cachedText);
|
|
79
80
|
}
|
|
80
81
|
this.#native ??= col([this.#inner]);
|
|
@@ -372,6 +372,7 @@ interface ContextUsageMemo {
|
|
|
372
372
|
length: number;
|
|
373
373
|
lastFingerprint: string | undefined;
|
|
374
374
|
modelContextWindow: number;
|
|
375
|
+
toolSchemasInContext: boolean;
|
|
375
376
|
contextUsageRevision: number;
|
|
376
377
|
toolSchemaMetadataRevision: number;
|
|
377
378
|
settingsRevision: number;
|
|
@@ -766,9 +767,12 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
766
767
|
// than poison the fresh cache or advance its throttle.
|
|
767
768
|
#jjCacheGeneration = 0;
|
|
768
769
|
|
|
769
|
-
// PR lookup
|
|
770
|
+
// PR lookup cache. `#cachedPrContext` is the branch/repo `#cachedPr` was
|
|
771
|
+
// resolved for; it is never shown for any other branch. Expiry forces a
|
|
772
|
+
// refetch while keeping that branch's PR visible until the lookup lands.
|
|
770
773
|
#cachedPr: { number: number; url: string } | null | undefined = undefined;
|
|
771
774
|
#cachedPrContext: PrCacheContext | undefined = undefined;
|
|
775
|
+
#cachedPrExpired = false;
|
|
772
776
|
#prLookupInFlight = false;
|
|
773
777
|
#defaultBranch?: string;
|
|
774
778
|
#defaultBranchCwd: string | undefined = undefined;
|
|
@@ -1445,8 +1449,8 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
1445
1449
|
// was designed to avoid. Explicit Git/repository invalidation (watcher
|
|
1446
1450
|
// HEAD-move, cwd/repo switch) goes through {@link invalidateGitCaches}.
|
|
1447
1451
|
// A tool may open, close, or merge a PR without moving HEAD. Expire the
|
|
1448
|
-
// settled PR
|
|
1449
|
-
this.#
|
|
1452
|
+
// settled PR on ordinary activity while leaving HEAD work intact.
|
|
1453
|
+
this.#cachedPrExpired = true;
|
|
1450
1454
|
}
|
|
1451
1455
|
#invalidateSessionCaches(): void {
|
|
1452
1456
|
this.#clearUsageStartTimer();
|
|
@@ -1477,7 +1481,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
1477
1481
|
this.#branchResolveActive = undefined;
|
|
1478
1482
|
this.#branchLastFetch = undefined;
|
|
1479
1483
|
this.#branchCacheGeneration++;
|
|
1480
|
-
this.#
|
|
1484
|
+
this.#cachedPrExpired = true;
|
|
1481
1485
|
// A HEAD move (commit, checkout, reset) changes the dirty counts; keep the
|
|
1482
1486
|
// stale counts on screen but refetch on the next render. The generation
|
|
1483
1487
|
// bump stops an in-flight pre-move result from re-stamping freshness.
|
|
@@ -1798,11 +1802,16 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
1798
1802
|
const branch = this.#getBranchLabel(activeRepoCache, this.#resolveRepository(activeRepoCache));
|
|
1799
1803
|
const currentContext = branch ? createPrCacheContext(branch, this.#cachedBranchRepoId ?? null) : null;
|
|
1800
1804
|
|
|
1801
|
-
if (canReuseCachedPr(this.#cachedPr, this.#cachedPrContext, currentContext)) {
|
|
1805
|
+
if (!this.#cachedPrExpired && canReuseCachedPr(this.#cachedPr, this.#cachedPrContext, currentContext)) {
|
|
1802
1806
|
return this.#cachedPr ?? null;
|
|
1803
1807
|
}
|
|
1804
1808
|
|
|
1805
|
-
|
|
1809
|
+
// Keep an expired PR visible during the refetch only on the branch it
|
|
1810
|
+
// was resolved for; after a checkout the old PR must not linger.
|
|
1811
|
+
const stalePr =
|
|
1812
|
+
currentContext && isSamePrCacheContext(this.#cachedPrContext, currentContext)
|
|
1813
|
+
? (this.#cachedPr ?? null)
|
|
1814
|
+
: null;
|
|
1806
1815
|
|
|
1807
1816
|
if (!branch) {
|
|
1808
1817
|
this.#cachedPr = null;
|
|
@@ -1810,10 +1819,9 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
1810
1819
|
return null;
|
|
1811
1820
|
}
|
|
1812
1821
|
|
|
1813
|
-
//
|
|
1814
|
-
if (branch === "detached" || this.#isDefaultBranch(branch, gitCwd)
|
|
1815
|
-
|
|
1816
|
-
}
|
|
1822
|
+
// Detached HEAD and the default branch never carry a PR; no lookup.
|
|
1823
|
+
if (branch === "detached" || this.#isDefaultBranch(branch, gitCwd)) return null;
|
|
1824
|
+
if (this.#prLookupInFlight) return stalePr;
|
|
1817
1825
|
|
|
1818
1826
|
this.#prLookupInFlight = true;
|
|
1819
1827
|
const lookupContext = currentContext;
|
|
@@ -1835,6 +1843,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
1835
1843
|
if (lookupContext && isSamePrCacheContext(latestContext, lookupContext)) {
|
|
1836
1844
|
this.#cachedPr = value;
|
|
1837
1845
|
this.#cachedPrContext = lookupContext;
|
|
1846
|
+
this.#cachedPrExpired = false;
|
|
1838
1847
|
}
|
|
1839
1848
|
};
|
|
1840
1849
|
try {
|
|
@@ -2395,6 +2404,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
2395
2404
|
getCachedContextBreakdown(): { usedTokens: number; contextWindow: number } {
|
|
2396
2405
|
const messages = this.session.messages ?? EMPTY_MESSAGES;
|
|
2397
2406
|
const modelContextWindow = this.session.model?.contextWindow ?? 0;
|
|
2407
|
+
const toolSchemasInContext = this.session.model?.toolSchemasInContext !== false;
|
|
2398
2408
|
const length = messages.length;
|
|
2399
2409
|
const lastFingerprint = length > 0 ? messageFingerprint(messages[length - 1]!) : undefined;
|
|
2400
2410
|
// Bumps when the in-flight pending snapshot is set/cleared. Without it a
|
|
@@ -2416,6 +2426,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
2416
2426
|
cache.length === length &&
|
|
2417
2427
|
cache.lastFingerprint === lastFingerprint &&
|
|
2418
2428
|
cache.modelContextWindow === modelContextWindow &&
|
|
2429
|
+
cache.toolSchemasInContext === toolSchemasInContext &&
|
|
2419
2430
|
cache.contextUsageRevision === contextUsageRevision &&
|
|
2420
2431
|
cache.systemPromptRef === systemPrompt &&
|
|
2421
2432
|
cache.toolsRef === tools &&
|
|
@@ -2436,6 +2447,7 @@ export class StatusLineComponent<TSession extends StatusLineSession = StatusLine
|
|
|
2436
2447
|
length,
|
|
2437
2448
|
lastFingerprint,
|
|
2438
2449
|
modelContextWindow,
|
|
2450
|
+
toolSchemasInContext,
|
|
2439
2451
|
contextUsageRevision,
|
|
2440
2452
|
toolSchemaMetadataRevision,
|
|
2441
2453
|
settingsRevision,
|
|
@@ -141,6 +141,7 @@ export function computeCompactionBoundaries(
|
|
|
141
141
|
|
|
142
142
|
/** Stable inputs used to cache non-message token estimates. */
|
|
143
143
|
export interface NonMessageTokenSource {
|
|
144
|
+
readonly model?: Model;
|
|
144
145
|
readonly systemPrompt?: readonly string[];
|
|
145
146
|
readonly agent?: {
|
|
146
147
|
readonly state?: {
|
|
@@ -270,30 +271,32 @@ export function estimateToolSchemaTokens(tools: ToolSchemaSource, tokenizer: Tok
|
|
|
270
271
|
return tokens;
|
|
271
272
|
}
|
|
272
273
|
|
|
274
|
+
/** Count schemas carried on every request, excluding server-side deferred catalogs. */
|
|
275
|
+
export function estimateContextToolSchemaTokens(
|
|
276
|
+
tools: ToolSchemaSource,
|
|
277
|
+
tokenizer: Tokenizer,
|
|
278
|
+
model: Model | undefined,
|
|
279
|
+
sourceRevision = 0,
|
|
280
|
+
): number {
|
|
281
|
+
return model?.toolSchemasInContext === false ? 0 : estimateToolSchemaTokens(tools, tokenizer, sourceRevision);
|
|
282
|
+
}
|
|
283
|
+
|
|
273
284
|
/**
|
|
274
285
|
* Compute just the NON-MESSAGE token total: system prompt (with its skills
|
|
275
286
|
* section subtracted, since skills are tokenized separately) + system context
|
|
276
287
|
* (the rest of the system-prompt array) + tools + skills.
|
|
277
288
|
*
|
|
278
289
|
* Exposed so callers like `StatusLineComponent` can cache the non-message
|
|
279
|
-
* total separately from the message total.
|
|
280
|
-
*
|
|
281
|
-
* streaming turn. Splitting the two lets the caller refresh each on its own
|
|
282
|
-
* cadence — non-message recomputed only when the inputs identity changes,
|
|
283
|
-
* messages walked incrementally as new entries append.
|
|
290
|
+
* total separately from the growing message total. A model switch can change
|
|
291
|
+
* which tool schemas occupy context without changing the roster.
|
|
284
292
|
*/
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
//
|
|
288
|
-
// both, and #estimateStoredContextTokens adds a third. Memoize on the identity
|
|
289
|
-
// of the three input arrays so the expensive parts (system-prompt tokenization
|
|
290
|
-
// and the per-tool JSON.stringify(toolWireSchema) inside estimateToolSchemaTokens)
|
|
291
|
-
// run at most once per input change rather than per call. The identity keys are
|
|
292
|
-
// the same stable references the StatusLineComponent cache already trusts
|
|
293
|
-
// (setSystemPrompt/setTools replace the array reference rather than mutating it).
|
|
293
|
+
// The per-turn threshold and compaction paths call these helpers repeatedly.
|
|
294
|
+
// Cache by prompt, roster, skills, tokenizer, revision, and model schema policy;
|
|
295
|
+
// setSystemPrompt/setTools replace their arrays rather than mutating them.
|
|
294
296
|
interface NonMessageTokenCache {
|
|
295
297
|
systemPromptRef: readonly string[];
|
|
296
298
|
toolsRef: ToolSchemaSource;
|
|
299
|
+
toolSchemasInContext: boolean;
|
|
297
300
|
toolsRevision: number;
|
|
298
301
|
sourceRevision: number;
|
|
299
302
|
skillful: boolean;
|
|
@@ -326,6 +329,7 @@ function nonMessageTokenCacheEntry(
|
|
|
326
329
|
const cachedSession: CachedNonMessageTokenSource = session;
|
|
327
330
|
const systemPromptRef = session.systemPrompt ?? EMPTY_STRING_PARTS;
|
|
328
331
|
const toolsRef = session.agent?.state?.tools ?? EMPTY_TOOLS;
|
|
332
|
+
const toolSchemasInContext = session.model?.toolSchemasInContext !== false;
|
|
329
333
|
const toolsRevision = getToolSchemaMetadataRevision(toolsRef);
|
|
330
334
|
const skillsRef = session.renderedSkills ?? session.skills ?? EMPTY_SKILLS;
|
|
331
335
|
let entry = cachedSession[NON_MESSAGE_TOKEN_CACHE];
|
|
@@ -333,6 +337,7 @@ function nonMessageTokenCacheEntry(
|
|
|
333
337
|
entry &&
|
|
334
338
|
entry.systemPromptRef === systemPromptRef &&
|
|
335
339
|
entry.toolsRef === toolsRef &&
|
|
340
|
+
entry.toolSchemasInContext === toolSchemasInContext &&
|
|
336
341
|
entry.toolsRevision === toolsRevision &&
|
|
337
342
|
entry.sourceRevision === sourceRevision &&
|
|
338
343
|
entry.skillsRef === skillsRef &&
|
|
@@ -343,6 +348,7 @@ function nonMessageTokenCacheEntry(
|
|
|
343
348
|
entry = {
|
|
344
349
|
systemPromptRef,
|
|
345
350
|
toolsRef,
|
|
351
|
+
toolSchemasInContext,
|
|
346
352
|
toolsRevision,
|
|
347
353
|
sourceRevision,
|
|
348
354
|
skillful: true,
|
|
@@ -366,7 +372,7 @@ export function computeNonMessageTokens(
|
|
|
366
372
|
const tools = session.agent?.state?.tools ?? EMPTY_TOOLS;
|
|
367
373
|
const tokens =
|
|
368
374
|
tokenizer.countTokens(Array.from(systemPromptParts, part => part ?? "")) +
|
|
369
|
-
|
|
375
|
+
estimateContextToolSchemaTokens(tools, tokenizer, session.model, sourceRevision);
|
|
370
376
|
entry.tokens = tokens;
|
|
371
377
|
return tokens;
|
|
372
378
|
}
|
|
@@ -398,7 +404,7 @@ export function computeNonMessageBreakdown(
|
|
|
398
404
|
renderedSkills(session.renderedSkills ?? session.skills ?? EMPTY_SKILLS, tools),
|
|
399
405
|
tokenizer,
|
|
400
406
|
);
|
|
401
|
-
const toolsTokens =
|
|
407
|
+
const toolsTokens = estimateContextToolSchemaTokens(tools, tokenizer, session.model, sourceRevision);
|
|
402
408
|
const systemPromptParts = session.systemPrompt ?? EMPTY_STRING_PARTS;
|
|
403
409
|
const systemContextTokens = tokenizer.countTokens(Array.from(systemPromptParts.slice(1), part => part ?? ""));
|
|
404
410
|
const systemPromptTokens = Math.max(0, tokenizer.countTokens(systemPromptParts[0] ?? "") - skillsTokens);
|
|
@@ -176,22 +176,11 @@ export class FooterComponent implements Component {
|
|
|
176
176
|
*/
|
|
177
177
|
describe(): NativeNode {
|
|
178
178
|
const state = this.session.state;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
let premiumRequests = 0;
|
|
185
|
-
for (const entry of this.session.sessionManager.getEntries()) {
|
|
186
|
-
if (entry.type === "message" && entry.message?.role === "assistant") {
|
|
187
|
-
input += entry.message.usage.input;
|
|
188
|
-
output += entry.message.usage.output;
|
|
189
|
-
cacheRead += entry.message.usage.cacheRead;
|
|
190
|
-
cacheWrite += entry.message.usage.cacheWrite;
|
|
191
|
-
cost += entry.message.usage.cost.total;
|
|
192
|
-
premiumRequests += entry.message.usage.premiumRequests ?? 0;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
179
|
+
// Cumulative usage: the session manager's running rollup spans every entry
|
|
180
|
+
// in the session (so it survives compaction) and already folds in the usage
|
|
181
|
+
// completed `task` tool results carry, which is where subagent spend lands.
|
|
182
|
+
const { input, output, cacheRead, cacheWrite, cost, premiumRequests } =
|
|
183
|
+
this.session.sessionManager.getUsageStatistics();
|
|
195
184
|
const segs: NativeNode[] = [];
|
|
196
185
|
const seg = (key: string, props: TspProps<"seg">): void => {
|
|
197
186
|
segs.push(node("seg", { role: `omp.footer.${key}`, ...props }, undefined, key));
|
|
@@ -255,25 +244,19 @@ export class FooterComponent implements Component {
|
|
|
255
244
|
render(width: number): readonly string[] {
|
|
256
245
|
const state = this.session.state;
|
|
257
246
|
|
|
258
|
-
//
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
totalCacheWrite += entry.message.usage.cacheWrite;
|
|
272
|
-
totalCost += entry.message.usage.cost.total;
|
|
273
|
-
totalPremiumRequests += entry.message.usage.premiumRequests ?? 0;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
247
|
+
// Cumulative usage comes from the session manager's running rollup, which
|
|
248
|
+
// spans every entry in the session and folds in the usage completed `task`
|
|
249
|
+
// tool results carry (subagent spend). Context usage below is a separate
|
|
250
|
+
// question and stays window-scoped on purpose. Destructured straight off the
|
|
251
|
+
// rollup: a repaint must not allocate a second copy of these six fields.
|
|
252
|
+
const {
|
|
253
|
+
input: totalInput,
|
|
254
|
+
output: totalOutput,
|
|
255
|
+
cacheRead: totalCacheRead,
|
|
256
|
+
cacheWrite: totalCacheWrite,
|
|
257
|
+
cost: totalCost,
|
|
258
|
+
premiumRequests: totalPremiumRequests,
|
|
259
|
+
} = this.session.sessionManager.getUsageStatistics();
|
|
277
260
|
// Calculate context usage from session (handles compaction correctly).
|
|
278
261
|
// After compaction, tokens are unknown until the next LLM response.
|
|
279
262
|
const contextUsage = this.session.getContextUsage();
|
package/src/status-line/host.ts
CHANGED
|
@@ -71,7 +71,12 @@ export interface FooterSession {
|
|
|
71
71
|
autoResolvedThinkingLevel(): string | undefined;
|
|
72
72
|
getContextUsage: StatusLineSession["getContextUsage"];
|
|
73
73
|
modelRegistry: Pick<StatusLineSession["modelRegistry"], "isUsingOAuth">;
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Cumulative session rollup. Unlike the active-window stats it spans every
|
|
76
|
+
* entry in the session, so compaction does not reset the counters, and it
|
|
77
|
+
* folds in usage carried by completed `task` tool results.
|
|
78
|
+
*/
|
|
79
|
+
sessionManager: { getUsageStatistics: StatusLineSession["sessionManager"]["getUsageStatistics"] };
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Status line for the speculative first frame, before any session exists.
|
|
3
3
|
*
|
|
4
|
-
* InteractiveMode persists {@link StatusLineStartupData} (settings plus the
|
|
5
|
-
*
|
|
6
|
-
* real {@link StatusLineComponent} as a fresh, unnamed session at
|
|
7
|
-
* terminal width. Path and git branch are read live; context usage is
|
|
8
|
-
* unknown so the gauge shows the window without a percent.
|
|
4
|
+
* InteractiveMode persists {@link StatusLineStartupData} (settings plus the
|
|
5
|
+
* resolved default role model and status inputs); the next launch renders it
|
|
6
|
+
* through the real {@link StatusLineComponent} as a fresh, unnamed session at
|
|
7
|
+
* the live terminal width. Path and git branch are read live; context usage is
|
|
8
|
+
* reported unknown so the gauge shows the window without a percent.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts ignore
|
|
@@ -32,7 +32,7 @@ import type { StatusLineSettings } from "./types";
|
|
|
32
32
|
export interface StatusLineStartupData {
|
|
33
33
|
readonly settings: StatusLineSettings;
|
|
34
34
|
readonly gitEnabled: boolean;
|
|
35
|
-
/** Model
|
|
35
|
+
/** Model resolved for the next fresh session's default role. */
|
|
36
36
|
readonly model?: Model;
|
|
37
37
|
readonly thinkingLevel?: ThinkingLevel;
|
|
38
38
|
readonly autoThinking: boolean;
|