@linxiraos/pi-tui 1.4.11 → 1.4.13
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 +30 -233
- package/README.md +4 -1
- package/THIRD-PARTY-NOTICES.txt +4 -5
- package/dist/types/apps/shell-visualizer.d.ts +24 -0
- package/dist/types/autocomplete.d.ts +20 -0
- package/dist/types/chat/cache-invalidation-marker.d.ts +15 -7
- package/dist/types/chat/chat-transcript-builder.d.ts +5 -3
- package/dist/types/chat/display-preferences.d.ts +2 -0
- package/dist/types/chat/extension-types.d.ts +72 -1
- package/dist/types/chat/image-loading.d.ts +2 -2
- package/dist/types/chat/messages.d.ts +2 -3
- package/dist/types/chat/read-tool-group.d.ts +15 -2
- package/dist/types/chat/skill-message.d.ts +1 -0
- package/dist/types/chat/spotlight.d.ts +203 -0
- package/dist/types/chat/tool-execution.d.ts +26 -5
- package/dist/types/chat/transcript-actions.d.ts +11 -0
- package/dist/types/chat/transcript-browser.d.ts +9 -0
- package/dist/types/chat/transcript-presentation.d.ts +164 -0
- package/dist/types/chat/ttsr-notification.d.ts +2 -0
- package/dist/types/chrome/message-frame.d.ts +2 -0
- package/dist/types/chrome/transcript-container.d.ts +27 -6
- package/dist/types/components/loader.d.ts +0 -2
- package/dist/types/components/markdown.d.ts +11 -1
- package/dist/types/components/settings-list.d.ts +12 -2
- package/dist/types/frame-rate.d.ts +18 -0
- package/dist/types/hotkeys-markdown.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/keybinding-matchers.d.ts +4 -1
- package/dist/types/kitty-graphics.d.ts +1 -1
- package/dist/types/motion-effects.d.ts +10 -0
- package/dist/types/native/encode.d.ts +2 -0
- package/dist/types/native/measure.d.ts +10 -0
- package/dist/types/native/overlay.d.ts +1 -1
- package/dist/types/native/quiet.d.ts +5 -0
- package/dist/types/native/reconcile.d.ts +6 -1
- package/dist/types/native/spans.d.ts +6 -0
- package/dist/types/native/state.d.ts +4 -0
- package/dist/types/overlays/agent-hub.d.ts +6 -0
- package/dist/types/overlays/link-browser.d.ts +55 -0
- package/dist/types/overlays/running-subagent-badge.d.ts +1 -4
- package/dist/types/overlays/spotlight-sheet.d.ts +36 -0
- package/dist/types/prompt/composer-attachments.d.ts +5 -2
- package/dist/types/prompt/composer-cache.d.ts +7 -2
- package/dist/types/prompt/composer.d.ts +6 -11
- package/dist/types/prompt/custom-editor.d.ts +8 -2
- package/dist/types/prompt/gradient-highlight.d.ts +2 -2
- package/dist/types/prompt/magic-keywords.d.ts +2 -0
- package/dist/types/prompt/model-mention-autocomplete.d.ts +9 -7
- package/dist/types/prompt/model-mention-syntax.d.ts +6 -0
- package/dist/types/prompt/prompt-action-autocomplete.d.ts +2 -1
- package/dist/types/prompt/welcome.d.ts +19 -0
- package/dist/types/render/extension-links.d.ts +0 -6
- package/dist/types/render/index.d.ts +1 -0
- package/dist/types/render/link-hints.d.ts +78 -0
- package/dist/types/render/render-utils.d.ts +0 -2
- package/dist/types/setup/scenes/types.d.ts +8 -0
- package/dist/types/setup/scenes/updates.d.ts +6 -0
- package/dist/types/setup/wizard.d.ts +7 -2
- package/dist/types/spinner-clock.d.ts +34 -0
- package/dist/types/status-line/component.d.ts +8 -4
- package/dist/types/status-line/host.d.ts +62 -0
- package/dist/types/status-line/index.d.ts +1 -0
- package/dist/types/status-line/prompt-cache.d.ts +14 -0
- package/dist/types/status-line/schema.d.ts +1 -1
- package/dist/types/status-line/startup.d.ts +6 -0
- package/dist/types/status-line/types.d.ts +8 -21
- package/dist/types/theme/schema.d.ts +28 -1
- package/dist/types/theme/symbols.d.ts +1 -1
- package/dist/types/theme/theme-class.d.ts +12 -2
- package/dist/types/theme/theme.d.ts +1 -1
- package/dist/types/theme/tui-adapters.d.ts +7 -0
- package/dist/types/thinking.d.ts +12 -0
- package/dist/types/tools/ask.d.ts +1 -1
- package/dist/types/tools/bash.d.ts +21 -0
- package/dist/types/tools/find.d.ts +9 -1
- package/dist/types/tools/grep.d.ts +2 -1
- package/dist/types/tools/grouped-file-output.d.ts +17 -0
- package/dist/types/tools/job-widget.d.ts +2 -2
- package/dist/types/tools/lsp.d.ts +4 -2
- package/dist/types/tools/native-view.d.ts +4 -0
- package/dist/types/tools/renderer.d.ts +9 -1
- package/dist/types/tools/shell-trace.d.ts +10 -0
- package/dist/types/tools/shell-viz-render.d.ts +6 -0
- package/dist/types/tools/shell-viz.d.ts +16 -0
- package/dist/types/tools/wait.d.ts +2 -2
- package/dist/types/tools/web-search-types.d.ts +1 -0
- package/dist/types/tools/write.d.ts +2 -0
- package/dist/types/tui.d.ts +15 -1
- package/package.json +15 -11
- package/src/apps/shell-visualizer.d.ts +24 -0
- package/src/apps/shell-visualizer.ts +167 -0
- package/src/autocomplete.d.ts +20 -0
- package/src/autocomplete.ts +14 -0
- package/src/chat/assistant-message.ts +11 -6
- package/src/chat/cache-invalidation-marker.d.ts +15 -7
- package/src/chat/cache-invalidation-marker.ts +18 -9
- package/src/chat/chat-transcript-builder.d.ts +5 -3
- package/src/chat/chat-transcript-builder.ts +16 -12
- package/src/chat/display-preferences.d.ts +2 -0
- package/src/chat/display-preferences.ts +3 -0
- package/src/chat/extension-types.d.ts +72 -1
- package/src/chat/extension-types.ts +74 -1
- package/src/chat/image-loading.d.ts +2 -2
- package/src/chat/image-loading.ts +2 -2
- package/src/chat/messages.d.ts +2 -3
- package/src/chat/messages.ts +3 -8
- package/src/chat/read-tool-group.d.ts +15 -2
- package/src/chat/read-tool-group.ts +201 -41
- package/src/chat/skill-message.d.ts +1 -0
- package/src/chat/skill-message.ts +4 -0
- package/src/chat/spotlight.d.ts +203 -0
- package/src/chat/spotlight.ts +460 -0
- package/src/chat/tool-execution.d.ts +26 -5
- package/src/chat/tool-execution.ts +360 -38
- package/src/chat/transcript-actions.d.ts +11 -0
- package/src/chat/transcript-actions.ts +13 -1
- package/src/chat/transcript-browser.d.ts +9 -0
- package/src/chat/transcript-browser.ts +18 -0
- package/src/chat/transcript-presentation.d.ts +164 -0
- package/src/chat/transcript-presentation.ts +642 -0
- package/src/chat/ttsr-notification.d.ts +25 -0
- package/src/chat/ttsr-notification.ts +5 -0
- package/src/chrome/message-frame.d.ts +2 -0
- package/src/chrome/message-frame.ts +7 -0
- package/src/chrome/message-notice.d.ts +58 -0
- package/src/chrome/transcript-container.d.ts +27 -6
- package/src/chrome/transcript-container.ts +317 -66
- package/src/components/editor.ts +25 -1
- package/src/components/loader.d.ts +0 -2
- package/src/components/loader.ts +30 -18
- package/src/components/markdown.d.ts +11 -1
- package/src/components/markdown.ts +41 -16
- package/src/components/settings-list.d.ts +12 -2
- package/src/components/settings-list.ts +29 -13
- package/src/frame-rate.d.ts +18 -0
- package/src/frame-rate.ts +36 -0
- package/src/hotkeys-markdown.ts +9 -2
- package/src/index.d.ts +3 -0
- package/src/index.ts +3 -0
- package/src/keybinding-matchers.d.ts +4 -1
- package/src/keybinding-matchers.ts +13 -12
- package/src/kitty-graphics.d.ts +1 -1
- package/src/kitty-graphics.ts +3 -2
- package/src/motion-effects.d.ts +10 -0
- package/src/motion-effects.ts +27 -0
- package/src/native/backend.ts +66 -7
- package/src/native/encode.d.ts +2 -0
- package/src/native/encode.ts +2 -0
- package/src/native/measure.d.ts +10 -0
- package/src/native/measure.ts +185 -0
- package/src/native/overlay.d.ts +1 -1
- package/src/native/overlay.ts +1 -1
- package/src/native/quiet.d.ts +5 -0
- package/src/native/quiet.ts +105 -0
- package/src/native/reconcile.d.ts +6 -1
- package/src/native/reconcile.ts +16 -10
- package/src/native/spans.d.ts +6 -0
- package/src/native/spans.ts +40 -0
- package/src/native/state.d.ts +4 -0
- package/src/native/state.ts +18 -0
- package/src/overlays/agent-hub.ts +15 -2
- package/src/overlays/ask-dialog.ts +1 -0
- package/src/overlays/btw-history-panel.ts +73 -6
- package/src/overlays/link-browser.ts +295 -0
- package/src/overlays/running-subagent-badge.ts +2 -9
- package/src/overlays/settings-defs.ts +1 -1
- package/src/overlays/settings-selector.ts +17 -3
- package/src/overlays/spotlight-sheet.ts +478 -0
- package/src/overlays/usage-dashboard.ts +6 -5
- package/src/prompt/composer-attachments.d.ts +5 -2
- package/src/prompt/composer-attachments.ts +6 -6
- package/src/prompt/composer-cache.ts +17 -16
- package/src/prompt/composer.ts +30 -123
- package/src/prompt/custom-editor.ts +17 -13
- package/src/prompt/gradient-highlight.d.ts +2 -2
- package/src/prompt/gradient-highlight.ts +5 -4
- package/src/prompt/magic-keywords.d.ts +2 -0
- package/src/prompt/magic-keywords.ts +4 -1
- package/src/prompt/model-mention-autocomplete.ts +73 -20
- package/src/prompt/model-mention-syntax.d.ts +6 -0
- package/src/prompt/model-mention-syntax.ts +9 -0
- package/src/prompt/prompt-action-autocomplete.ts +49 -33
- package/src/prompt/tips.txt +1 -0
- package/src/prompt/welcome.ts +104 -2
- package/src/render/extension-links.d.ts +0 -6
- package/src/render/extension-links.ts +0 -20
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- package/src/render/link-hints.d.ts +78 -0
- package/src/render/link-hints.ts +299 -0
- package/src/render/render-utils.d.ts +0 -2
- package/src/render/render-utils.ts +0 -5
- package/src/setup/scenes/glyph.ts +1 -1
- package/src/setup/scenes/types.ts +8 -0
- package/src/setup/scenes/updates.ts +116 -0
- package/src/setup/wizard.ts +19 -8
- package/src/spinner-clock.d.ts +34 -0
- package/src/spinner-clock.ts +79 -0
- package/src/status-line/component.ts +145 -53
- package/src/status-line/host.ts +51 -0
- package/src/status-line/index.ts +1 -0
- package/src/status-line/presets.ts +3 -1
- package/src/status-line/prompt-cache.ts +154 -0
- package/src/status-line/schema.ts +1 -1
- package/src/status-line/segments.ts +33 -22
- package/src/status-line/startup.ts +22 -4
- package/src/status-line/types.ts +8 -22
- package/src/stdin-buffer.ts +89 -46
- package/src/terminal-capabilities.ts +3 -3
- package/src/terminal.ts +1 -8
- package/src/theme/loader.ts +3 -2
- package/src/theme/schema.d.ts +28 -1
- package/src/theme/schema.ts +30 -1
- package/src/theme/symbols.d.ts +1 -1
- package/src/theme/symbols.ts +15 -3
- package/src/theme/theme-class.d.ts +12 -2
- package/src/theme/theme-class.ts +23 -0
- package/src/theme/theme-schema.json +1 -1
- package/src/theme/theme.d.ts +1 -1
- package/src/theme/theme.ts +3 -7
- package/src/theme/tui-adapters.d.ts +7 -0
- package/src/theme/tui-adapters.ts +33 -1
- package/src/thinking.d.ts +12 -0
- package/src/thinking.ts +31 -0
- package/src/tools/ask.d.ts +1 -1
- package/src/tools/ask.ts +99 -38
- package/src/tools/ast-edit.ts +51 -32
- package/src/tools/ast-grep.ts +31 -19
- package/src/tools/bash.d.ts +21 -0
- package/src/tools/bash.ts +166 -24
- package/src/tools/find.d.ts +9 -1
- package/src/tools/find.ts +23 -2
- package/src/tools/grep.d.ts +2 -1
- package/src/tools/grep.ts +52 -36
- package/src/tools/grouped-file-output.d.ts +17 -0
- package/src/tools/grouped-file-output.ts +20 -2
- package/src/tools/job-widget.d.ts +2 -2
- package/src/tools/job-widget.ts +2 -2
- package/src/tools/lsp.d.ts +4 -2
- package/src/tools/lsp.ts +537 -642
- package/src/tools/native-view.d.ts +4 -0
- package/src/tools/native-view.ts +8 -2
- package/src/tools/renderer.d.ts +9 -1
- package/src/tools/renderer.ts +9 -1
- package/src/tools/shell-trace.d.ts +10 -0
- package/src/tools/shell-trace.ts +80 -0
- package/src/tools/shell-viz-render.d.ts +6 -0
- package/src/tools/shell-viz-render.ts +156 -0
- package/src/tools/shell-viz.d.ts +16 -0
- package/src/tools/shell-viz.ts +181 -0
- package/src/tools/streaming-output.ts +18 -8
- package/src/tools/wait.d.ts +2 -2
- package/src/tools/wait.ts +39 -34
- package/src/tools/web-search-types.d.ts +1 -0
- package/src/tools/web-search-types.ts +1 -0
- package/src/tools/write.d.ts +2 -0
- package/src/tools/write.ts +2 -0
- package/src/tui.d.ts +15 -1
- package/src/tui.ts +63 -6
- package/src/windows-input-mode.ts +7 -1
- package/dist/types/chat/collab-prompt-message.d.ts +0 -14
- package/dist/types/chrome/collab-qrcode.d.ts +0 -35
- package/src/chat/collab-prompt-message.d.ts +0 -14
- package/src/chat/collab-prompt-message.ts +0 -46
- package/src/chrome/collab-qrcode.ts +0 -99
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Spotlight sheet: how shaping reduced one tool result. A large glass sheet (role
|
|
3
|
+
* `zeta.overlay.spotlight`; it fills a narrow pane) in one column: what Spotlight was asked (the intent, the other
|
|
4
|
+
* request parameters a click away), a legend of why lines were shown or hidden beside the ranking step's budget and
|
|
5
|
+
* cutoff, then the original as one `code` element. Every run of lines the model did not see folds into one row
|
|
6
|
+
* labelled with the marker the model read in its place; each line's gutter takes the tone of why shaping showed or hid
|
|
7
|
+
* it, and its row is washed by its score's parts, a gradient across it from left to right like a heat map (by
|
|
8
|
+
* Spotlight's heat without a rank), and an overview strip above the lines maps the whole result. A fold hiding a hot
|
|
9
|
+
* line says why it was cut, on its row and in a hover card. The
|
|
10
|
+
* shaping notes the model saw follow the code. A held-out result's sheet shows the cut shaping would have made (its
|
|
11
|
+
* title says the model saw the original): folds, labels and notes come from the would-be text. Esc, Close or a
|
|
12
|
+
* backdrop click closes it; nothing enters the transcript.
|
|
13
|
+
*/
|
|
14
|
+
import { formatNumber, sanitizeText } from "@linxiraos/pi-utils";
|
|
15
|
+
import type { TspCodeFold, TspCodeMark, TspPropNode, TspSpan, TspTone } from "@linxiraos/pi-wire";
|
|
16
|
+
import {
|
|
17
|
+
SPOTLIGHT_VIEW_LINES,
|
|
18
|
+
type SpotlightDetails,
|
|
19
|
+
type SpotlightOriginal,
|
|
20
|
+
type SpotlightRank,
|
|
21
|
+
type SpotlightReason,
|
|
22
|
+
type SpotlightRequestParams,
|
|
23
|
+
heatAt,
|
|
24
|
+
rankPartAt,
|
|
25
|
+
reasonAt,
|
|
26
|
+
reasonShows,
|
|
27
|
+
spotlightHot,
|
|
28
|
+
spotlightSaving,
|
|
29
|
+
spotlightTone,
|
|
30
|
+
} from "../chat/spotlight";
|
|
31
|
+
import { matchesSelectCancel } from "../keybinding-matchers";
|
|
32
|
+
import { code, col, compact, node, propNode, row, span, text } from "../native/describe";
|
|
33
|
+
import type { NativeNode, NativeUiEvent } from "../native/node";
|
|
34
|
+
import { actionBar, actionButton } from "../native/overlay";
|
|
35
|
+
import type { Component } from "../tui";
|
|
36
|
+
import { truncateToWidth } from "../utils";
|
|
37
|
+
|
|
38
|
+
export interface SpotlightSheetOptions {
|
|
39
|
+
spotlight: SpotlightDetails & { original: SpotlightOriginal };
|
|
40
|
+
/** The original text, as its artifact holds it. */
|
|
41
|
+
original: string;
|
|
42
|
+
/**
|
|
43
|
+
* The text the model saw, or of a held-out result the would-be text its `shapedUrl` holds (its lines label folds and
|
|
44
|
+
* give the shaping notes, through the trace's `map`).
|
|
45
|
+
*/
|
|
46
|
+
reduced: string;
|
|
47
|
+
close(): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Why a hidden line went, as a fold says it. */
|
|
51
|
+
const CUT_WHY: Partial<Record<SpotlightReason, string>> = {
|
|
52
|
+
b: "cut by the budget",
|
|
53
|
+
r: "seen in an earlier call",
|
|
54
|
+
f: "folded",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** A class of line the summary counts: a reason that showed it, or how it was hidden. */
|
|
58
|
+
type LineClass = "a" | "s" | "n" | "c" | "hot" | "cut";
|
|
59
|
+
|
|
60
|
+
/** The summary's legend, in order: each class, its swatch tone and its label. */
|
|
61
|
+
const LEGEND: readonly { cls: LineClass; tone: TspTone; label: string }[] = [
|
|
62
|
+
{ cls: "a", tone: "accent", label: "kept by score" },
|
|
63
|
+
{ cls: "s", tone: "neutral", label: "kept as structure" },
|
|
64
|
+
{ cls: "n", tone: "user", label: "named" },
|
|
65
|
+
{ cls: "c", tone: "info", label: "kept as context" },
|
|
66
|
+
{ cls: "hot", tone: "error", label: "cut though hot" },
|
|
67
|
+
{ cls: "cut", tone: "muted", label: "cut" },
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
/** One legend entry (role `omp.spotlight.key`): a swatch and a muted label. */
|
|
71
|
+
function legendKey(swatch: NativeNode, label: string): NativeNode {
|
|
72
|
+
return row([swatch, text([span(label, "muted")])], { gap: "xs", align: "center", role: "omp.spotlight.key" });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** A count with thousands separators. */
|
|
76
|
+
function count(n: number): string {
|
|
77
|
+
return n.toLocaleString("en-US");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A score or heat to two decimals. */
|
|
81
|
+
function fixed(n: number): string {
|
|
82
|
+
return n.toFixed(2);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** One request parameter: its name, its values (dim dots between them), and how its row draws them. */
|
|
86
|
+
interface Param {
|
|
87
|
+
name: string;
|
|
88
|
+
values: readonly string[];
|
|
89
|
+
style?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The request's parameters that are not blank, in the sheet's order. */
|
|
93
|
+
function nonBlankParams(params: SpotlightRequestParams): Param[] {
|
|
94
|
+
const all: Param[] = [
|
|
95
|
+
{ name: "intent", values: [params.intent] },
|
|
96
|
+
{ name: "said", values: [params.said] },
|
|
97
|
+
{ name: "task", values: [params.task] },
|
|
98
|
+
{ name: "commands", values: params.commands, style: "mono" },
|
|
99
|
+
{ name: "source", values: [params.source], style: "mono" },
|
|
100
|
+
{ name: "probe", values: [params.probe], style: "mono" },
|
|
101
|
+
{ name: "model", values: [params.model, `${params.thinking} thinking`] },
|
|
102
|
+
];
|
|
103
|
+
return all.filter(param => param.values.some(value => sanitizeText(value).trim() !== ""));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* One parameter's row (role `omp.spotlight.param`): its name, then its non-blank values on one run of spaces and at
|
|
108
|
+
* most `lines` lines, whole in the tooltip; `end` (the toggle) last.
|
|
109
|
+
*/
|
|
110
|
+
function paramRow(param: Param, lines: number, end?: NativeNode): NativeNode {
|
|
111
|
+
const whole = param.values.map(value => sanitizeText(value).trim()).filter(Boolean);
|
|
112
|
+
const spans = whole.flatMap((value, i) => {
|
|
113
|
+
const part = span(value.replace(/\s+/g, " "), param.style);
|
|
114
|
+
// The separator takes the values' face: Geist spaces between mono runs read as none.
|
|
115
|
+
return i === 0 ? [part] : [span(" · ", param.style ? `dim ${param.style}` : "dim"), part];
|
|
116
|
+
});
|
|
117
|
+
const shown = text(spans, { lines, truncate: "end", title: whole.join("\n") });
|
|
118
|
+
return row(compact([text(param.name), shown, end]), { gap: "md", align: "baseline", role: "omp.spotlight.param" });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* What the result's Spotlight requests sent besides its lines (role `omp.spotlight.params`): collapsed, the first
|
|
123
|
+
* parameter (the intent) on one line and a toggle naming the rest; expanded, a row per parameter.
|
|
124
|
+
*/
|
|
125
|
+
function requestParams(params: SpotlightRequestParams, expanded: boolean): NativeNode | undefined {
|
|
126
|
+
const named = nonBlankParams(params);
|
|
127
|
+
if (named.length === 0) return undefined;
|
|
128
|
+
const rest = named.slice(1);
|
|
129
|
+
const toggle =
|
|
130
|
+
rest.length > 0
|
|
131
|
+
? text(expanded ? "fewer ▾" : `${rest.map(param => param.name).join(", ")} ▸`, {
|
|
132
|
+
role: "omp.spotlight.more",
|
|
133
|
+
actions: { click: "params" },
|
|
134
|
+
})
|
|
135
|
+
: undefined;
|
|
136
|
+
const rows = (expanded ? named : named.slice(0, 1)).map((param, i) =>
|
|
137
|
+
paramRow(param, expanded ? 2 : 1, i === 0 ? toggle : undefined),
|
|
138
|
+
);
|
|
139
|
+
return col(rows, { gap: "xs", role: "omp.spotlight.params" });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The class the summary counts original line `i` (0-based) in; undefined without a reason. */
|
|
143
|
+
function lineClass(original: SpotlightOriginal, i: number): LineClass | undefined {
|
|
144
|
+
const reason = reasonAt(original.why, i);
|
|
145
|
+
if (reason === undefined || reason === "-") return undefined;
|
|
146
|
+
if (reasonShows(reason)) return reason as LineClass;
|
|
147
|
+
return spotlightHot(original.heat, i) ? "hot" : "cut";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The summary row (role `omp.spotlight.summary`): a legend swatch and count per class of the shown lines (with
|
|
152
|
+
* reasons), then the ranking step's budget and cutoff and whether the view is cut; undefined when it has nothing.
|
|
153
|
+
*/
|
|
154
|
+
function summary(original: SpotlightOriginal, shown: number, total: number): NativeNode | undefined {
|
|
155
|
+
const items: NativeNode[] = [];
|
|
156
|
+
if (original.why !== undefined) {
|
|
157
|
+
const counts = new Map<LineClass, number>();
|
|
158
|
+
for (let i = 0; i < shown; i++) {
|
|
159
|
+
const cls = lineClass(original, i);
|
|
160
|
+
if (cls !== undefined) counts.set(cls, (counts.get(cls) ?? 0) + 1);
|
|
161
|
+
}
|
|
162
|
+
for (const { cls, tone, label } of LEGEND) {
|
|
163
|
+
const n = counts.get(cls);
|
|
164
|
+
if (n) items.push(legendKey(text("■", { role: "omp.spotlight.swatch", tone }), `${label} ${count(n)}`));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const facts: string[] = [];
|
|
168
|
+
const rank = original.rank;
|
|
169
|
+
if (rank) {
|
|
170
|
+
facts.push(
|
|
171
|
+
rank.budget !== undefined
|
|
172
|
+
? `budget ${count(rank.used ?? 0)} of ${count(rank.budget)} chars · cutoff ${fixed(rank.cutoff)}`
|
|
173
|
+
: `cutoff ${fixed(rank.cutoff)}`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (shown < total) facts.push(`first ${count(shown)} of ${count(total)} lines`);
|
|
177
|
+
if (items.length === 0 && facts.length === 0) return undefined;
|
|
178
|
+
const budget = facts.length > 0 && text([span(facts.join(" · "), "muted")], { role: "omp.spotlight.budget" });
|
|
179
|
+
return row(compact([...items, node("spacer", { grow: 1 }), budget]), {
|
|
180
|
+
gap: "md",
|
|
181
|
+
align: "center",
|
|
182
|
+
wrap: true,
|
|
183
|
+
role: "omp.spotlight.summary",
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The parts of original line `i`'s (0-based) score, in the rank's order. */
|
|
188
|
+
function rankParts(rank: SpotlightRank, i: number): number[] {
|
|
189
|
+
return rank.values.map(values => rankPartAt(values, i, rank.max));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The mark of original line `i` (0-based), numbered from its `start`: its heat, its reason's tone and its score's
|
|
194
|
+
* parts as the row's wash (each a rank in [0, 1]); undefined for a line with neither heat nor tone (a bare mark would
|
|
195
|
+
* draw the default accent bar).
|
|
196
|
+
*/
|
|
197
|
+
function lineMark(original: SpotlightOriginal, i: number): TspCodeMark | undefined {
|
|
198
|
+
const heat = heatAt(original.heat, i);
|
|
199
|
+
const tone = spotlightTone(original, i);
|
|
200
|
+
if (heat === undefined && tone === undefined) return undefined;
|
|
201
|
+
const mark: { line: number; heat?: number; tone?: TspTone; wash?: number[] } = { line: original.start + i };
|
|
202
|
+
if (heat !== undefined) mark.heat = heat;
|
|
203
|
+
if (tone !== undefined) mark.tone = tone;
|
|
204
|
+
if (original.rank) mark.wash = rankParts(original.rank, i);
|
|
205
|
+
return mark;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Whether each of the first `shown` original lines reached the model: by its reason when it has one, else `kept`. */
|
|
209
|
+
function shownMask(original: SpotlightOriginal, shown: number): boolean[] {
|
|
210
|
+
const mask = Array.from({ length: shown }, () => false);
|
|
211
|
+
for (const [from, to] of original.kept) {
|
|
212
|
+
for (let i = Math.max(1, from); i <= Math.min(shown, to); i++) mask[i - 1] = true;
|
|
213
|
+
}
|
|
214
|
+
for (let i = 0; i < shown; i++) {
|
|
215
|
+
const reason = reasonAt(original.why, i);
|
|
216
|
+
if (reason !== undefined && reason !== "-") mask[i] = reasonShows(reason);
|
|
217
|
+
}
|
|
218
|
+
return mask;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** The original's lines as the sheet shows them, and the model-facing lines its trace maps them to. */
|
|
222
|
+
interface SheetText {
|
|
223
|
+
original: SpotlightOriginal;
|
|
224
|
+
path: string | undefined;
|
|
225
|
+
/** The original's lines, up to the view cap. */
|
|
226
|
+
lines: readonly string[];
|
|
227
|
+
/** The text the model saw, line by line. */
|
|
228
|
+
reduced: readonly string[];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The model-facing marker standing for 0-based original lines `from..to`: the one `map` pair covering them all. */
|
|
232
|
+
function foldLabel(sheet: SheetText, from: number, to: number): string | undefined {
|
|
233
|
+
const map = sheet.original.map;
|
|
234
|
+
if (!map) return undefined;
|
|
235
|
+
let marker = -1;
|
|
236
|
+
for (let j = 0; j < map.length; j++) {
|
|
237
|
+
const entry = map[j];
|
|
238
|
+
if (!Array.isArray(entry) || entry[0] > from + 1 || entry[1] < to + 1) continue;
|
|
239
|
+
if (marker >= 0) return undefined;
|
|
240
|
+
marker = j;
|
|
241
|
+
}
|
|
242
|
+
const label = marker >= 0 ? sheet.reduced[marker]?.trimEnd() : undefined;
|
|
243
|
+
return label || undefined;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Why hot original line `i` (0-based) was cut, naming the line that took the budget's end when the budget cut it. */
|
|
247
|
+
function cutWhy(original: SpotlightOriginal, i: number): string | undefined {
|
|
248
|
+
const reason = reasonAt(original.why, i);
|
|
249
|
+
const last = original.rank?.last;
|
|
250
|
+
if (reason === "b" && original.rank && last) {
|
|
251
|
+
const total = rankParts(original.rank, last.line - 1).reduce((sum, part) => sum + part, 0);
|
|
252
|
+
return `cut by the budget: line ${original.start + last.line - 1} (${fixed(total)}) took the last ${count(last.chars)} chars`;
|
|
253
|
+
}
|
|
254
|
+
return reason === undefined ? undefined : CUT_WHY[reason];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** The hover card of a fold hiding hot original line `i` (0-based): the line as the sheet draws it, its score, why it went. */
|
|
258
|
+
function hotCard(sheet: SheetText, i: number): TspPropNode {
|
|
259
|
+
const { original } = sheet;
|
|
260
|
+
const rank = original.rank;
|
|
261
|
+
const line = original.start + i;
|
|
262
|
+
const why = cutWhy(original, i);
|
|
263
|
+
const parts = rank ? rankParts(rank, i) : [];
|
|
264
|
+
return propNode(
|
|
265
|
+
col(
|
|
266
|
+
compact([
|
|
267
|
+
text([span(`line ${line} · the hottest line this fold hides`, "muted")]),
|
|
268
|
+
code(sheet.lines[i] ?? "", {
|
|
269
|
+
path: sheet.path,
|
|
270
|
+
start: line,
|
|
271
|
+
numbers: true,
|
|
272
|
+
marks: compact([lineMark(original, i)]),
|
|
273
|
+
}),
|
|
274
|
+
rank &&
|
|
275
|
+
text([
|
|
276
|
+
span(
|
|
277
|
+
`${parts.map(fixed).join(" + ")} = ${fixed(parts.reduce((sum, part) => sum + part, 0))} · cutoff ${fixed(rank.cutoff)}`,
|
|
278
|
+
"muted",
|
|
279
|
+
),
|
|
280
|
+
]),
|
|
281
|
+
why !== undefined && text([span(why, "error")]),
|
|
282
|
+
]),
|
|
283
|
+
{ gap: "xs", role: "omp.spotlight.card" },
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The fold of 0-based original lines `from..to`, all hidden from the model: the marker it read for them, how many
|
|
290
|
+
* there are and their peak heat, and, when one scored hot, which and why it was cut (tinted, with a hover card).
|
|
291
|
+
*/
|
|
292
|
+
function fold(sheet: SheetText, from: number, to: number): TspCodeFold {
|
|
293
|
+
const { original } = sheet;
|
|
294
|
+
let peak: number | undefined;
|
|
295
|
+
let hot = -1;
|
|
296
|
+
let hotHeat = -1;
|
|
297
|
+
for (let i = from; i <= to; i++) {
|
|
298
|
+
const heat = heatAt(original.heat, i);
|
|
299
|
+
if (heat === undefined) continue;
|
|
300
|
+
if (peak === undefined || heat > peak) peak = heat;
|
|
301
|
+
if (heat > hotHeat && spotlightTone(original, i) === "error") {
|
|
302
|
+
hot = i;
|
|
303
|
+
hotHeat = heat;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const n = to - from + 1;
|
|
307
|
+
const note: TspSpan[] = [
|
|
308
|
+
span(`${count(n)} ${n === 1 ? "line" : "lines"}${peak === undefined ? "" : ` · peak ${fixed(peak)}`}`, "muted"),
|
|
309
|
+
];
|
|
310
|
+
const out: TspCodeFold = { from: original.start + from, to: original.start + to };
|
|
311
|
+
const label = foldLabel(sheet, from, to);
|
|
312
|
+
if (hot < 0) return { ...out, ...(label ? { label } : {}), note };
|
|
313
|
+
const why = CUT_WHY[reasonAt(original.why, hot) ?? "-"];
|
|
314
|
+
note.push(span(` · line ${original.start + hot}${why ? ` ${why}` : ""}`, "error"));
|
|
315
|
+
return { ...out, ...(label ? { label } : {}), note, tone: "error", hovercard: hotCard(sheet, hot) };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** One fold per maximal run of the shown lines the model did not see. */
|
|
319
|
+
function folds(sheet: SheetText): TspCodeFold[] {
|
|
320
|
+
const mask = shownMask(sheet.original, sheet.lines.length);
|
|
321
|
+
const out: TspCodeFold[] = [];
|
|
322
|
+
for (let i = 0; i < mask.length; i++) {
|
|
323
|
+
if (mask[i]) continue;
|
|
324
|
+
let end = i;
|
|
325
|
+
while (end + 1 < mask.length && !mask[end + 1]) end++;
|
|
326
|
+
out.push(fold(sheet, i, end));
|
|
327
|
+
i = end;
|
|
328
|
+
}
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Fewer original lines than this fit the sheet whole: an overview of them would only repeat the gutter. */
|
|
333
|
+
const OVERVIEW_MIN_LINES = 60;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* The original as one `code` element (role `omp.spotlight.code`): marks, folds, and the overview past
|
|
337
|
+
* {@link OVERVIEW_MIN_LINES}. Command output (no file) wraps, a file keeps its lines.
|
|
338
|
+
*/
|
|
339
|
+
function originalCode(sheet: SheetText): NativeNode {
|
|
340
|
+
const { original } = sheet;
|
|
341
|
+
const marks = compact(sheet.lines.map((_, i) => lineMark(original, i)));
|
|
342
|
+
const shut = folds(sheet);
|
|
343
|
+
return code(sheet.lines.join("\n"), {
|
|
344
|
+
role: "omp.spotlight.code",
|
|
345
|
+
path: sheet.path,
|
|
346
|
+
start: original.start,
|
|
347
|
+
numbers: true,
|
|
348
|
+
...(sheet.path ? {} : { wrap: true }),
|
|
349
|
+
...(sheet.lines.length >= OVERVIEW_MIN_LINES ? { overview: true } : {}),
|
|
350
|
+
...(marks.length > 0 ? { marks } : {}),
|
|
351
|
+
...(shut.length > 0 ? { folds: shut } : {}),
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* The shaping notes the model saw, or would have seen (its lines no original line maps to), under a heading; undefined
|
|
357
|
+
* without any.
|
|
358
|
+
*/
|
|
359
|
+
function shapingNotes(sheet: SheetText, heldOut: boolean): NativeNode | undefined {
|
|
360
|
+
const map = sheet.original.map;
|
|
361
|
+
if (!map) return undefined;
|
|
362
|
+
const notes: string[] = [];
|
|
363
|
+
for (let j = 0; j < map.length; j++) {
|
|
364
|
+
const line = map[j] === null ? sheet.reduced[j]?.trimEnd() : undefined;
|
|
365
|
+
if (line) notes.push(line);
|
|
366
|
+
}
|
|
367
|
+
if (notes.length === 0) return undefined;
|
|
368
|
+
const heading = heldOut ? "notes the model would have seen" : "notes the model saw";
|
|
369
|
+
return col([text([span(heading, "muted")]), ...notes.map(note => text([span(note, "muted mono")]))], {
|
|
370
|
+
gap: "xs",
|
|
371
|
+
role: "omp.spotlight.notes",
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* The footer's key to the rows' wash (role `omp.spotlight.legend`): the heat ramp (role `omp.spotlight.ramp`, drawn
|
|
377
|
+
* by the terminal) before the rank's parts in their order across a row.
|
|
378
|
+
*/
|
|
379
|
+
function rankLegend(rank: SpotlightRank): NativeNode {
|
|
380
|
+
const label =
|
|
381
|
+
rank.parts.length > 1 ? `row tint, left to right: ${rank.parts.join(" → ")}` : `row tint: ${rank.parts[0]}`;
|
|
382
|
+
return row([legendKey(text("", { role: "omp.spotlight.ramp" }), label)], {
|
|
383
|
+
align: "center",
|
|
384
|
+
role: "omp.spotlight.legend",
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export class SpotlightSheet implements Component {
|
|
389
|
+
readonly nativeOverlay: { role: string; head: string; size: "lg"; anchor: "center" };
|
|
390
|
+
readonly #options: SpotlightSheetOptions;
|
|
391
|
+
/** Every request parameter shown, not only the intent. */
|
|
392
|
+
#expanded = false;
|
|
393
|
+
/** The column below the parameters, which no toggle changes. */
|
|
394
|
+
#body: NativeNode[] | undefined;
|
|
395
|
+
#native: NativeNode | undefined;
|
|
396
|
+
|
|
397
|
+
constructor(options: SpotlightSheetOptions) {
|
|
398
|
+
this.#options = options;
|
|
399
|
+
const s = options.spotlight;
|
|
400
|
+
const saving = spotlightSaving(s);
|
|
401
|
+
const saved =
|
|
402
|
+
s.holdout || s.gated
|
|
403
|
+
? `would save ${formatNumber(Math.max(0, saving))} toks`
|
|
404
|
+
: saving >= 0
|
|
405
|
+
? `saved ${formatNumber(saving)} toks`
|
|
406
|
+
: `+${formatNumber(-saving)} toks`;
|
|
407
|
+
const heldOut = s.holdout
|
|
408
|
+
? "held out (the model saw the original) · "
|
|
409
|
+
: s.gated
|
|
410
|
+
? "kept whole for editing (the model saw the original) · "
|
|
411
|
+
: "";
|
|
412
|
+
this.nativeOverlay = {
|
|
413
|
+
role: "zeta.overlay.spotlight",
|
|
414
|
+
head: `⭐ Spotlight · ${heldOut}${s.tool} · ${formatNumber(s.inChars)} → ${formatNumber(s.outChars)} chars · ${saved}`,
|
|
415
|
+
size: "lg",
|
|
416
|
+
anchor: "center",
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
describe(): NativeNode {
|
|
421
|
+
if (this.#native) return this.#native;
|
|
422
|
+
const request = this.#options.spotlight.request;
|
|
423
|
+
this.#native = col(compact([request && requestParams(request, this.#expanded), ...this.#describeBody()]), {
|
|
424
|
+
gap: "md",
|
|
425
|
+
});
|
|
426
|
+
return this.#native;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
#describeBody(): NativeNode[] {
|
|
430
|
+
if (this.#body) return this.#body;
|
|
431
|
+
const { spotlight } = this.#options;
|
|
432
|
+
const original = spotlight.original;
|
|
433
|
+
const all = sanitizeText(this.#options.original).split("\n");
|
|
434
|
+
const sheet: SheetText = {
|
|
435
|
+
original,
|
|
436
|
+
path: original.path,
|
|
437
|
+
lines: all.slice(0, SPOTLIGHT_VIEW_LINES),
|
|
438
|
+
reduced: sanitizeText(this.#options.reduced).split("\n"),
|
|
439
|
+
};
|
|
440
|
+
const rank = original.rank;
|
|
441
|
+
this.#body = compact([
|
|
442
|
+
summary(original, sheet.lines.length, all.length),
|
|
443
|
+
originalCode(sheet),
|
|
444
|
+
shapingNotes(sheet, spotlight.holdout === true || spotlight.gated === true),
|
|
445
|
+
actionBar([...(rank ? [rankLegend(rank)] : []), null, actionButton("Close", "close", { keys: "escape" })]),
|
|
446
|
+
]);
|
|
447
|
+
return this.#body;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
render(width: number): string[] {
|
|
451
|
+
return [truncateToWidth(this.nativeOverlay.head, width), truncateToWidth("Esc closes", width)];
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
invalidate(): void {
|
|
455
|
+
this.#native = undefined;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
handleInput(data: string): void {
|
|
459
|
+
if (matchesSelectCancel(data)) this.#options.close();
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** Close runs what Esc runs; the parameters' toggle shows every parameter or only the intent. */
|
|
463
|
+
handleNativeEvent(event: NativeUiEvent): void {
|
|
464
|
+
if (event.type !== "action") return;
|
|
465
|
+
if (event.act === "close") this.#options.close();
|
|
466
|
+
else if (event.act === "params") {
|
|
467
|
+
this.#expanded = !this.#expanded;
|
|
468
|
+
this.#native = undefined;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** Whether a trace has an original to show. */
|
|
474
|
+
export function hasSpotlightOriginal(
|
|
475
|
+
spotlight: SpotlightDetails,
|
|
476
|
+
): spotlight is SpotlightDetails & { original: SpotlightOriginal } {
|
|
477
|
+
return spotlight.original !== undefined;
|
|
478
|
+
}
|
|
@@ -1056,7 +1056,7 @@ export class UsageDashboardComponent implements Component {
|
|
|
1056
1056
|
const refreshHint = this.#options.refresh ? "r refresh · " : "";
|
|
1057
1057
|
const hint =
|
|
1058
1058
|
this.#view === "detail"
|
|
1059
|
-
? `${scrollHint}${refreshHint}${cancel} back`
|
|
1059
|
+
? `${scrollHint}${refreshHint}${formatKeyHint("tab")} overview · ${cancel} back`
|
|
1060
1060
|
: `${scrollHint}${refreshHint}${formatKeyHint("enter")} details · ${cancel} close`;
|
|
1061
1061
|
this.#panel.title = title;
|
|
1062
1062
|
this.#header.setLines([checkedText ? theme.fg("dim", checkedText) : ""]);
|
|
@@ -1804,10 +1804,11 @@ export class UsageDashboardComponent implements Component {
|
|
|
1804
1804
|
void this.#refresh();
|
|
1805
1805
|
return;
|
|
1806
1806
|
}
|
|
1807
|
-
if (
|
|
1808
|
-
this.#view === "overview"
|
|
1809
|
-
|
|
1810
|
-
|
|
1807
|
+
if (matchesKey(data, "tab")) {
|
|
1808
|
+
this.#setView(this.#view === "overview" ? "detail" : "overview");
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
if (this.#view === "overview" && (matchesKey(data, "return") || matchesKey(data, "d"))) {
|
|
1811
1812
|
this.#setView("detail");
|
|
1812
1813
|
return;
|
|
1813
1814
|
}
|
|
@@ -22,9 +22,12 @@ export declare function modelChipStyle(label: string, restore?: string): string;
|
|
|
22
22
|
export declare function collapseSkillTokens(text: string, isKnown: (name: string) => boolean, register: (label: string, expansion: string) => void): string;
|
|
23
23
|
/**
|
|
24
24
|
* Replaces mentionable model selectors with their display chips and registers
|
|
25
|
-
* each chip's canonical selector as its atomic editor expansion.
|
|
25
|
+
* each chip's canonical `^selector` as its atomic editor expansion.
|
|
26
26
|
*/
|
|
27
|
-
export declare function collapseModelMentions(text: string,
|
|
27
|
+
export declare function collapseModelMentions(text: string, chipFor: (selector: string) => {
|
|
28
|
+
label: string;
|
|
29
|
+
selector: string;
|
|
30
|
+
} | undefined, register: (label: string, expansion: string) => void): string;
|
|
28
31
|
/** Compact atomic composer token for attachment `n` in the active symbol preset. */
|
|
29
32
|
export declare function chipLabel(kind: ChipKind, n: number): string;
|
|
30
33
|
/** Infers an attachment kind from a chip label emitted by any configured symbol preset. */
|
|
@@ -82,20 +82,20 @@ export function collapseSkillTokens(
|
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* Replaces mentionable model selectors with their display chips and registers
|
|
85
|
-
* each chip's canonical selector as its atomic editor expansion.
|
|
85
|
+
* each chip's canonical `^selector` as its atomic editor expansion.
|
|
86
86
|
*/
|
|
87
87
|
export function collapseModelMentions(
|
|
88
88
|
text: string,
|
|
89
|
-
|
|
89
|
+
chipFor: (selector: string) => { label: string; selector: string } | undefined,
|
|
90
90
|
register: (label: string, expansion: string) => void,
|
|
91
91
|
): string {
|
|
92
92
|
if (!text.includes("^") || !allowsModelMentions(text)) return text;
|
|
93
93
|
MODEL_MENTION_RE.lastIndex = 0;
|
|
94
94
|
return text.replace(MODEL_MENTION_RE, (match, delimiter: string, selector: string) => {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
register(label, modelMentionToken(selector));
|
|
98
|
-
return `${delimiter}${label}`;
|
|
95
|
+
const chip = chipFor(selector);
|
|
96
|
+
if (chip === undefined) return match;
|
|
97
|
+
register(chip.label, modelMentionToken(chip.selector));
|
|
98
|
+
return `${delimiter}${chip.label}`;
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* Settings-derived kinds (theme/composer preferences, status-bar inputs) are
|
|
7
7
|
* also written under the empty project, so a folder that never ran zetacode still
|
|
8
8
|
* paints with the user's theme and status bar: those are rarely
|
|
9
|
-
* project-specific, and path/branch render live.
|
|
9
|
+
* project-specific, and path/branch render live. Status inputs naming a
|
|
10
|
+
* project-scoped default model stay out of that fallback.
|
|
10
11
|
*
|
|
11
12
|
* ```text
|
|
12
13
|
* entries (project TEXT, kind TEXT, value TEXT JSON, PRIMARY KEY (project, kind))
|
|
@@ -232,12 +233,16 @@ export class ComposerCache {
|
|
|
232
233
|
|
|
233
234
|
/** Resolved theme and composer settings for the next prepaint. */
|
|
234
235
|
writeUi(cwd: string, preferences: ComposerPreferences, theme: ComposerThemePreferences): void {
|
|
235
|
-
this.#
|
|
236
|
+
this.#put([path.resolve(cwd), ANY_PROJECT], "ui", { preferences, theme });
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
/**
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
/**
|
|
240
|
+
* Status-bar inputs for the next prepaint's startup status line. `shared: false`
|
|
241
|
+
* keeps them out of the any-project fallback (a project-scoped default model).
|
|
242
|
+
*/
|
|
243
|
+
writeStatus(cwd: string, status: ComposerStatusCache, options: { shared?: boolean } = {}): void {
|
|
244
|
+
const project = path.resolve(cwd);
|
|
245
|
+
this.#put(options.shared === false ? [project] : [project, ANY_PROJECT], "status", status);
|
|
241
246
|
}
|
|
242
247
|
|
|
243
248
|
close(): void {
|
|
@@ -248,22 +253,18 @@ export class ComposerCache {
|
|
|
248
253
|
}
|
|
249
254
|
|
|
250
255
|
/**
|
|
251
|
-
* Best-effort upsert of
|
|
252
|
-
*
|
|
256
|
+
* Best-effort upsert of `kind` under every project key, atomically: a failed
|
|
257
|
+
* write only costs the next launch its speculation.
|
|
253
258
|
*/
|
|
254
|
-
#
|
|
255
|
-
const project = path.resolve(cwd);
|
|
259
|
+
#put(projects: readonly string[], kind: EntryKind, value: unknown): void {
|
|
256
260
|
const json = JSON.stringify(value);
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
if (this.#known.get(ownKey) === json && this.#known.get(anyKey) === json) return;
|
|
261
|
+
const keys = projects.map(project => `${project}\0${kind}`);
|
|
262
|
+
if (keys.every(key => this.#known.get(key) === json)) return;
|
|
260
263
|
try {
|
|
261
264
|
this.#db.transaction(() => {
|
|
262
|
-
this.#upsert.run(project, kind, json);
|
|
263
|
-
this.#upsert.run(ANY_PROJECT, kind, json);
|
|
265
|
+
for (const project of projects) this.#upsert.run(project, kind, json);
|
|
264
266
|
})();
|
|
265
|
-
this.#known.set(
|
|
266
|
-
this.#known.set(anyKey, json);
|
|
267
|
+
for (const key of keys) this.#known.set(key, json);
|
|
267
268
|
} catch (error) {
|
|
268
269
|
logger.debug("composer cache write failed", { kind, error: String(error) });
|
|
269
270
|
}
|