@oh-my-pi/pi-tui 18.14.1 → 18.14.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 +24 -0
- package/dist/types/charts/table-data.d.ts +4 -2
- package/dist/types/chat/transcript-render-helpers.d.ts +3 -3
- package/dist/types/native/describe.d.ts +4 -2
- package/dist/types/native/overlay.d.ts +42 -2
- package/dist/types/native/state.d.ts +4 -0
- package/dist/types/prompt/composer.d.ts +13 -5
- package/dist/types/render/render-utils.d.ts +2 -0
- package/dist/types/theme/theme.d.ts +1 -1
- package/dist/types/theme/tui-adapters.d.ts +2 -0
- package/dist/types/thinking.d.ts +8 -6
- package/dist/types/tools/ast-grep.d.ts +2 -0
- package/dist/types/tools/eval.d.ts +2 -0
- package/dist/types/tools/find.d.ts +1 -1
- package/dist/types/tools/grouped-file-output.d.ts +24 -11
- package/dist/types/tools/read.d.ts +4 -4
- package/dist/types/tools/task.d.ts +2 -2
- package/package.json +9 -9
- package/src/apps/git/git-tui.ts +10 -17
- package/src/apps/git/sidebar.ts +21 -35
- package/src/apps/ps-top.ts +4 -12
- package/src/charts/chart-plan.ts +0 -29
- package/src/charts/table-data.ts +55 -6
- package/src/chat/transcript-render-helpers.ts +18 -16
- package/src/native/backend.ts +7 -3
- package/src/native/describe.ts +9 -4
- package/src/native/overlay.ts +124 -16
- package/src/native/state.ts +25 -5
- package/src/overlays/extensions/extension-dashboard.ts +7 -8
- package/src/overlays/login-dialog.ts +8 -26
- package/src/overlays/tree-selector.ts +64 -18
- package/src/overlays/usage-dashboard.ts +2 -4
- package/src/prompt/composer.ts +17 -5
- package/src/render/render-utils.ts +2 -0
- package/src/theme/theme-class.ts +12 -3
- package/src/theme/theme.ts +1 -0
- package/src/theme/tui-adapters.ts +8 -3
- package/src/thinking.ts +17 -11
- package/src/tools/ast-grep.ts +10 -2
- package/src/tools/eval.ts +2 -0
- package/src/tools/find.ts +7 -2
- package/src/tools/grep.ts +8 -2
- package/src/tools/grouped-file-output.ts +172 -47
- package/src/tools/lsp.ts +158 -8
- package/src/tools/read.ts +6 -5
- package/src/tools/task.ts +2 -2
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
TruncatedText,
|
|
11
11
|
truncateToWidth,
|
|
12
12
|
} from "../index";
|
|
13
|
-
import { isRecord, sanitizeText } from "@oh-my-pi/pi-utils";
|
|
13
|
+
import { isRecord, oklabDistance, sanitizeText } from "@oh-my-pi/pi-utils";
|
|
14
14
|
/** Available session-tree display filters. */
|
|
15
15
|
export const TREE_FILTER_MODES = ["default", "no-tools", "user-only", "labeled-only", "all"] as const;
|
|
16
16
|
/** Session-tree display filter. */
|
|
@@ -170,10 +170,38 @@ function stripSystemWrapperTags(content: string): string {
|
|
|
170
170
|
/** Per-message cap on text folded into the tree search index. */
|
|
171
171
|
const SEARCH_TEXT_LIMIT = 200;
|
|
172
172
|
|
|
173
|
-
/** One theme-colored piece of an entry's display text. */
|
|
173
|
+
/** One theme-colored piece of an entry's display text; `strong` draws it bold. */
|
|
174
174
|
interface EntryPart {
|
|
175
175
|
t: string;
|
|
176
176
|
s?: ThemeColor;
|
|
177
|
+
strong?: boolean;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** An entry part as a native span. */
|
|
181
|
+
function partSpan(part: EntryPart): TspSpan {
|
|
182
|
+
const style = part.strong ? (part.s ? `${part.s} strong` : "strong") : part.s;
|
|
183
|
+
return span(treeRowText(part.t), style);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** OKLab distance under which two role colors read as the same color. */
|
|
187
|
+
const SAME_COLOR_DISTANCE = 0.05;
|
|
188
|
+
|
|
189
|
+
let assistantLabel: { theme: typeof theme; color: ThemeColor } | undefined;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The `assistant:` label color: `success`, unless it looks like the `user:` label's
|
|
193
|
+
* `accent` (`dark-terminal`, `*-poimandres`); then the path color, then `muted`.
|
|
194
|
+
*/
|
|
195
|
+
function assistantLabelColor(): ThemeColor {
|
|
196
|
+
if (assistantLabel?.theme !== theme) {
|
|
197
|
+
const accent = theme.getColorHex("accent");
|
|
198
|
+
const color =
|
|
199
|
+
(["success", "statusLinePath"] as const).find(
|
|
200
|
+
c => oklabDistance(theme.getColorHex(c), accent) >= SAME_COLOR_DISTANCE,
|
|
201
|
+
) ?? "muted";
|
|
202
|
+
assistantLabel = { theme, color };
|
|
203
|
+
}
|
|
204
|
+
return assistantLabel.color;
|
|
177
205
|
}
|
|
178
206
|
|
|
179
207
|
/** A cached native tree item and the inputs it was built from. */
|
|
@@ -239,6 +267,8 @@ class TreeList implements Component {
|
|
|
239
267
|
| undefined;
|
|
240
268
|
/** Bumped on every label edit: labels are item badges. */
|
|
241
269
|
#labelVersion = 0;
|
|
270
|
+
/** Theme the native item caches were built under: labels bake in the `assistant:` color. */
|
|
271
|
+
#nativeTheme = theme;
|
|
242
272
|
#pickerItems:
|
|
243
273
|
| { rows: readonly TreeRow<TreeSelectorNode, string>[]; labels: number; items: TspPickerItem[] }
|
|
244
274
|
| undefined;
|
|
@@ -708,6 +738,7 @@ class TreeList implements Component {
|
|
|
708
738
|
* only `order` (the visible entries) and the selection.
|
|
709
739
|
*/
|
|
710
740
|
pickerView(): TreePickerView {
|
|
741
|
+
this.#syncNativeTheme();
|
|
711
742
|
const allRows = this.#tree.allRows;
|
|
712
743
|
if (this.#pickerItems?.rows !== allRows || this.#pickerItems.labels !== this.#labelVersion) {
|
|
713
744
|
// Real branch points get a disclosure; linear chains stay flat at their head's depth.
|
|
@@ -739,7 +770,7 @@ class TreeList implements Component {
|
|
|
739
770
|
#pickerItem(row: TreeRow<TreeSelectorNode, string>, open: boolean): TspPickerItem {
|
|
740
771
|
const item = row.item;
|
|
741
772
|
const entry = item.entry;
|
|
742
|
-
const label = this.#entryParts(item).map(
|
|
773
|
+
const label = this.#entryParts(item).map(partSpan);
|
|
743
774
|
let kind: TspPickerItem["node"] = "marker";
|
|
744
775
|
let role: string | undefined;
|
|
745
776
|
if (isUserRequestEntry(entry)) {
|
|
@@ -808,6 +839,7 @@ class TreeList implements Component {
|
|
|
808
839
|
* instead of drawn tree connectors.
|
|
809
840
|
*/
|
|
810
841
|
describeList(): NativeNode {
|
|
842
|
+
this.#syncNativeTheme();
|
|
811
843
|
const rows = this.#tree.rows;
|
|
812
844
|
let items = this.#itemsNative;
|
|
813
845
|
if (items?.rows !== rows) {
|
|
@@ -857,6 +889,15 @@ class TreeList implements Component {
|
|
|
857
889
|
];
|
|
858
890
|
}
|
|
859
891
|
|
|
892
|
+
/** Drop native items built under another theme. */
|
|
893
|
+
#syncNativeTheme(): void {
|
|
894
|
+
if (this.#nativeTheme === theme) return;
|
|
895
|
+
this.#nativeTheme = theme;
|
|
896
|
+
this.#pickerItems = undefined;
|
|
897
|
+
this.#itemsNative = undefined;
|
|
898
|
+
this.#itemCache.clear();
|
|
899
|
+
}
|
|
900
|
+
|
|
860
901
|
#describeRow(row: TreeRow<TreeSelectorNode, string>): NativeNode {
|
|
861
902
|
const item = row.item;
|
|
862
903
|
const branch = row.parentKey !== undefined && row.siblingCount > 1;
|
|
@@ -865,9 +906,7 @@ class TreeList implements Component {
|
|
|
865
906
|
const label: TspSpan[] = [];
|
|
866
907
|
if (this.#activePathIds.has(row.key)) label.push(span(`${theme.md.bullet} `, "accent"));
|
|
867
908
|
if (item.label) label.push(span(`[${treeRowText(item.label)}] `, "warning"));
|
|
868
|
-
for (const part of this.#entryParts(item))
|
|
869
|
-
label.push(span(treeRowText(part.t), part.s));
|
|
870
|
-
}
|
|
909
|
+
for (const part of this.#entryParts(item)) label.push(partSpan(part));
|
|
871
910
|
const described = node("item", { label, icon: branch ? "branch" : undefined }, undefined, row.key);
|
|
872
911
|
this.#itemCache.set(row.key, { label: item.label, branch, node: described });
|
|
873
912
|
return described;
|
|
@@ -1056,8 +1095,11 @@ class TreeList implements Component {
|
|
|
1056
1095
|
#getEntryDisplayText(node: TreeSelectorNode, isSelected: boolean): string {
|
|
1057
1096
|
let result = "";
|
|
1058
1097
|
for (const part of this.#entryParts(node)) {
|
|
1059
|
-
|
|
1060
|
-
|
|
1098
|
+
let value = treeRowText(part.t);
|
|
1099
|
+
if (part.s) value = theme.fg(part.s, value);
|
|
1100
|
+
// A selected row is bolded whole; nested bold would close it early.
|
|
1101
|
+
if (part.strong && !isSelected) value = theme.bold(value);
|
|
1102
|
+
result += value;
|
|
1061
1103
|
}
|
|
1062
1104
|
return isSelected ? theme.bold(result) : result;
|
|
1063
1105
|
}
|
|
@@ -1074,7 +1116,10 @@ class TreeList implements Component {
|
|
|
1074
1116
|
if (role === "user") {
|
|
1075
1117
|
const msgWithContent = msg as { content?: unknown };
|
|
1076
1118
|
const content = normalize(this.#extractContent(msgWithContent.content));
|
|
1077
|
-
return [
|
|
1119
|
+
return [
|
|
1120
|
+
{ t: "user: ", s: "accent", strong: true },
|
|
1121
|
+
{ t: content, s: "accent", strong: true },
|
|
1122
|
+
];
|
|
1078
1123
|
}
|
|
1079
1124
|
if (role === "developer") {
|
|
1080
1125
|
const msgWithContent = msg as { content?: unknown };
|
|
@@ -1086,15 +1131,10 @@ class TreeList implements Component {
|
|
|
1086
1131
|
}
|
|
1087
1132
|
if (role === "assistant") {
|
|
1088
1133
|
const presentation = resolveAssistantErrorPresentation(msg);
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
{ t: "assistant: ", s: "success" },
|
|
1092
|
-
{ t: presentation.text, s: "dim" },
|
|
1093
|
-
];
|
|
1094
|
-
}
|
|
1134
|
+
const head: EntryPart = { t: "assistant: ", s: assistantLabelColor() };
|
|
1135
|
+
if (presentation.kind === "compact-recovered") return [head, { t: presentation.text, s: "dim" }];
|
|
1095
1136
|
const msgWithContent = msg as { content?: unknown; stopReason?: string; errorMessage?: string };
|
|
1096
1137
|
const textContent = normalize(this.#extractContent(msgWithContent.content));
|
|
1097
|
-
const head: EntryPart = { t: "assistant: ", s: "success" };
|
|
1098
1138
|
if (textContent) return [head, { t: textContent }];
|
|
1099
1139
|
if (presentation.kind === "full") {
|
|
1100
1140
|
return [head, { t: normalize(presentation.text).slice(0, 80), s: "error" }];
|
|
@@ -1118,10 +1158,16 @@ class TreeList implements Component {
|
|
|
1118
1158
|
if (entry.customType === "advisor") {
|
|
1119
1159
|
const { qualifier, text } = advisorTreeDisplay(entry.details);
|
|
1120
1160
|
const label = qualifier ? `advisor (${qualifier}): ` : "advisor: ";
|
|
1121
|
-
return [
|
|
1161
|
+
return [
|
|
1162
|
+
{ t: label, s: "customMessageLabel" },
|
|
1163
|
+
{ t: normalize(text), s: "muted" },
|
|
1164
|
+
];
|
|
1122
1165
|
}
|
|
1123
1166
|
const content = stripSystemWrapperTags(this.#joinTextContent(entry.content));
|
|
1124
|
-
return [
|
|
1167
|
+
return [
|
|
1168
|
+
{ t: `[${entry.customType}]: `, s: "customMessageLabel" },
|
|
1169
|
+
{ t: normalize(content), s: "muted" },
|
|
1170
|
+
];
|
|
1125
1171
|
}
|
|
1126
1172
|
case "compaction": {
|
|
1127
1173
|
const tokens = Math.round(entry.tokensBefore / 1000);
|
|
@@ -43,7 +43,7 @@ import { editorKey, editorKeys } from "../chrome/keybinding-hints";
|
|
|
43
43
|
import type { TspSpan, TspTableColumn, TspText, TspTone } from "@oh-my-pi/pi-wire";
|
|
44
44
|
import { col, elapsed, node, span, text } from "../native/describe";
|
|
45
45
|
import { type DescribeContext, leafKey, type NativeChild, type NativeNode, type NativeUiEvent } from "../native/node";
|
|
46
|
-
import { actionBar, actionButton } from "../native/overlay";
|
|
46
|
+
import { actionBar, actionButton, segmentedTabs } from "../native/overlay";
|
|
47
47
|
|
|
48
48
|
/** Local calendar-day activity consumed by the usage heatmap. */
|
|
49
49
|
export interface DailyActivityPoint {
|
|
@@ -1135,8 +1135,7 @@ export class UsageDashboardComponent implements Component {
|
|
|
1135
1135
|
);
|
|
1136
1136
|
}
|
|
1137
1137
|
const children: NativeChild[] = [
|
|
1138
|
-
|
|
1139
|
-
"tabs",
|
|
1138
|
+
segmentedTabs(
|
|
1140
1139
|
{
|
|
1141
1140
|
items: [
|
|
1142
1141
|
{ id: "overview", label: "Overview" },
|
|
@@ -1144,7 +1143,6 @@ export class UsageDashboardComponent implements Component {
|
|
|
1144
1143
|
],
|
|
1145
1144
|
active: this.#view,
|
|
1146
1145
|
},
|
|
1147
|
-
undefined,
|
|
1148
1146
|
"tabs",
|
|
1149
1147
|
),
|
|
1150
1148
|
node("spacer", { grow: 1 }),
|
package/src/prompt/composer.ts
CHANGED
|
@@ -103,6 +103,13 @@ export interface RuntimeChildrenOptions {
|
|
|
103
103
|
* to the roots below the transcript in render order.
|
|
104
104
|
*/
|
|
105
105
|
readonly nativeDock?: readonly Component[];
|
|
106
|
+
/**
|
|
107
|
+
* Below-transcript containers whose children continue `main` on a TSP
|
|
108
|
+
* terminal, one block each after the transcript's, instead of riding in the
|
|
109
|
+
* dock: output on its way into the transcript (shell runs deferred until the
|
|
110
|
+
* next prompt) reads as its tail, and keeps its block when it moves in.
|
|
111
|
+
*/
|
|
112
|
+
readonly nativeTail?: readonly Container[];
|
|
106
113
|
/**
|
|
107
114
|
* Below-transcript roots the user opens and closes (the editor surface that
|
|
108
115
|
* drafts and dialogs swap into, docked reports). Their rows never become
|
|
@@ -259,6 +266,7 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
|
|
|
259
266
|
#headerAfter: readonly Component[] = [];
|
|
260
267
|
#runtimeChildren: readonly Component[] = [];
|
|
261
268
|
#nativeDock: readonly Component[] | undefined;
|
|
269
|
+
#nativeTail: readonly Container[] = [];
|
|
262
270
|
/** Cache-driven status line shown until {@link setStatusComponent} mounts the session's. */
|
|
263
271
|
#startupStatus: StatusLineComponent | undefined;
|
|
264
272
|
#runtimeMounted = false;
|
|
@@ -653,10 +661,11 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
|
|
|
653
661
|
/**
|
|
654
662
|
* Describe the whole surface for a TSP terminal. `main` is the flowing
|
|
655
663
|
* document: the header (welcome, extras) and every transcript block as its
|
|
656
|
-
* own component child
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
664
|
+
* own component child, then the children of the
|
|
665
|
+
* {@link RuntimeChildrenOptions.nativeTail} roots. `dock` is the live chrome
|
|
666
|
+
* below the transcript in render order: pending messages, HUDs, the working
|
|
667
|
+
* row, the editor and the status line. There is no history/viewport split:
|
|
668
|
+
* retirement, resize replay and hover bands are ANSI concerns.
|
|
660
669
|
*/
|
|
661
670
|
describeSurface(): NativeSurface {
|
|
662
671
|
if (!this.#started || this.#stopped) return this.#nativeSurface;
|
|
@@ -673,7 +682,9 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
|
|
|
673
682
|
} else {
|
|
674
683
|
const transcript = roots[transcriptIndex] as TranscriptContainer;
|
|
675
684
|
main.push(...roots.slice(0, transcriptIndex), ...transcript.nativeBlocks());
|
|
676
|
-
|
|
685
|
+
for (const root of this.#nativeTail) main.push(...root.children);
|
|
686
|
+
const tail: readonly Component[] = this.#nativeTail;
|
|
687
|
+
dock.push(...(this.#nativeDock ?? roots.slice(transcriptIndex + 1).filter(root => !tail.includes(root))));
|
|
677
688
|
}
|
|
678
689
|
}
|
|
679
690
|
const previous = this.#nativeSurface;
|
|
@@ -1259,6 +1270,7 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
|
|
|
1259
1270
|
this.#chromeFloorPromoted = false;
|
|
1260
1271
|
this.#resetIdleChrome();
|
|
1261
1272
|
this.#nativeDock = options.nativeDock;
|
|
1273
|
+
this.#nativeTail = options.nativeTail ?? [];
|
|
1262
1274
|
this.#transientChrome = new Set(options.transientChrome);
|
|
1263
1275
|
this.#selfClearingChrome = new Set(options.selfClearingChrome);
|
|
1264
1276
|
this.#transientFloor = undefined;
|
|
@@ -103,6 +103,8 @@ export const PREVIEW_LIMITS = {
|
|
|
103
103
|
EXPANDED_LINES: 12,
|
|
104
104
|
/** Items (files, results) shown in collapsed view */
|
|
105
105
|
COLLAPSED_ITEMS: 8,
|
|
106
|
+
/** Definition, type-definition and implementation locations shown in collapsed view */
|
|
107
|
+
LOCATIONS_COLLAPSED: 2,
|
|
106
108
|
/** Output preview lines in collapsed view */
|
|
107
109
|
OUTPUT_COLLAPSED: 3,
|
|
108
110
|
/** Output preview lines in expanded view */
|
package/src/theme/theme-class.ts
CHANGED
|
@@ -138,6 +138,15 @@ const LANG_BRAND_COLORS: Partial<Record<SymbolKey, string>> = {
|
|
|
138
138
|
const BACKGROUND_RESET_PATTERN = /\x1b\[(?:0|49)m/g;
|
|
139
139
|
const FOREGROUND_RESET_PATTERN = /\x1b\[(?:0|39)m/g;
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Color `text` with the foreground `ansi`, restoring it after every nested reset so the rest of `text`
|
|
143
|
+
* keeps it (`fg("dim", `${fg("success", "+2")} more`)`); only the foreground is reset at the end.
|
|
144
|
+
*/
|
|
145
|
+
function wrapForeground(ansi: string, text: string): string {
|
|
146
|
+
const body = text.includes("\x1b[") ? text.replace(FOREGROUND_RESET_PATTERN, `$&${ansi}`) : text;
|
|
147
|
+
return `${ansi}${body}\x1b[39m`;
|
|
148
|
+
}
|
|
149
|
+
|
|
141
150
|
// Prebuilt stylers: each `chalk.<style>` access builds a fresh builder. Builders share the
|
|
142
151
|
// root chalk context, so later `chalk.level` changes still apply.
|
|
143
152
|
const boldStyler = chalk.bold;
|
|
@@ -350,7 +359,7 @@ export class Theme {
|
|
|
350
359
|
fg(color: ThemeColor, text: string): string {
|
|
351
360
|
const ansi = this.#fgColors[color];
|
|
352
361
|
if (!ansi) throw new Error(`Unknown theme color: ${color}`);
|
|
353
|
-
return
|
|
362
|
+
return wrapForeground(ansi, text);
|
|
354
363
|
}
|
|
355
364
|
|
|
356
365
|
/** Apply a foreground, replacing terminal-default tokens with the theme's contrast-safe fallback. */
|
|
@@ -362,7 +371,7 @@ export class Theme {
|
|
|
362
371
|
resolved = ansi === "\x1b[39m" ? colorToAnsi(this.getColorHex(color), this.mode) : ansi;
|
|
363
372
|
this.#resolvedFgColors.set(color, resolved);
|
|
364
373
|
}
|
|
365
|
-
return
|
|
374
|
+
return wrapForeground(resolved, text);
|
|
366
375
|
}
|
|
367
376
|
|
|
368
377
|
bg(color: ThemeBg, text: string): string {
|
|
@@ -390,7 +399,7 @@ export class Theme {
|
|
|
390
399
|
*/
|
|
391
400
|
fgOnBg(color: ThemeColor, background: ThemeBg, text: string): string {
|
|
392
401
|
const ansi = this.getFgOnBgAnsi(color, background);
|
|
393
|
-
return
|
|
402
|
+
return wrapForeground(ansi, text);
|
|
394
403
|
}
|
|
395
404
|
|
|
396
405
|
bold(text: string): string {
|
package/src/theme/theme.ts
CHANGED
|
@@ -96,12 +96,17 @@ function highlightCached(code: string, validLang: string | undefined, highlightT
|
|
|
96
96
|
return highlighted;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
/** Whether {@link highlightCode} colors `lang`; text in any other language comes back unstyled. */
|
|
100
|
+
export function isHighlightLanguage(lang: string | undefined): lang is string {
|
|
101
|
+
return lang !== undefined && nativeSupportsLanguage(lang);
|
|
102
|
+
}
|
|
103
|
+
|
|
99
104
|
/**
|
|
100
105
|
* Highlight code with syntax coloring based on file extension or language.
|
|
101
106
|
* Returns array of highlighted lines.
|
|
102
107
|
*/
|
|
103
108
|
export function highlightCode(code: string, lang?: string, highlightTheme: Theme = theme): string[] {
|
|
104
|
-
const validLang =
|
|
109
|
+
const validLang = isHighlightLanguage(lang) ? lang : undefined;
|
|
105
110
|
const highlighted = highlightCached(code, validLang, highlightTheme);
|
|
106
111
|
// Always return a fresh array: callers (e.g. renderCodeCell) push extra lines
|
|
107
112
|
// onto the result, which would corrupt the cached string otherwise.
|
|
@@ -110,7 +115,7 @@ export function highlightCode(code: string, lang?: string, highlightTheme: Theme
|
|
|
110
115
|
|
|
111
116
|
/** Create a stateful highlighter for progressive terminal rendering. */
|
|
112
117
|
export function createHighlightStream(lang?: string, highlightTheme: Theme = theme): NativeHighlightStream | null {
|
|
113
|
-
const validLang =
|
|
118
|
+
const validLang = isHighlightLanguage(lang) ? lang : undefined;
|
|
114
119
|
if (!validLang) return null;
|
|
115
120
|
// Workspace loads skip the natives version sentinel, so a stale local
|
|
116
121
|
// `.node` can omit `HighlightStream` after a pull. Napi constructors can
|
|
@@ -305,7 +310,7 @@ export function getMarkdownTheme(): MarkdownTheme {
|
|
|
305
310
|
})
|
|
306
311
|
: undefined,
|
|
307
312
|
highlightCode: (code: string, lang?: string): string[] => {
|
|
308
|
-
const validLang =
|
|
313
|
+
const validLang = isHighlightLanguage(lang) ? lang : undefined;
|
|
309
314
|
const highlighted = highlightCached(code, validLang, theme);
|
|
310
315
|
if (highlighted !== null) return highlighted.split("\n");
|
|
311
316
|
return code.split("\n").map(line => theme.fg("mdCodeBlock", line));
|
package/src/thinking.ts
CHANGED
|
@@ -312,23 +312,21 @@ export function resolveTaskEffortLevel(
|
|
|
312
312
|
break;
|
|
313
313
|
}
|
|
314
314
|
if (maxEffort === undefined) return resolved;
|
|
315
|
+
if (model) assertModelSupportsEffortCeiling(model, maxEffort);
|
|
315
316
|
const maxIndex = THINKING_EFFORTS.indexOf(maxEffort);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const modelName = model ? `${model.provider}/${model.id}` : "Selected model";
|
|
319
|
-
throw new RangeError(`${modelName} has no supported thinking effort at or below task.maxEffort=${maxEffort}`);
|
|
320
|
-
}
|
|
317
|
+
// Without a model the full canonical range always holds `maxEffort` itself.
|
|
318
|
+
const ceiling = supported.findLast(candidate => THINKING_EFFORTS.indexOf(candidate) <= maxIndex) ?? maxEffort;
|
|
321
319
|
return THINKING_EFFORTS.indexOf(resolved) > THINKING_EFFORTS.indexOf(ceiling) ? ceiling : resolved;
|
|
322
320
|
}
|
|
323
321
|
|
|
324
322
|
/**
|
|
325
323
|
* Clamps a concrete thinking selector to a per-session effort ceiling (e.g. a
|
|
326
|
-
* task spawn's `task.maxEffort
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
324
|
+
* task spawn's `task.maxEffort`). Unset/`inherit`/`off` retain their existing
|
|
325
|
+
* meaning, as do levels already at or below the ceiling. Levels above it snap
|
|
326
|
+
* to the highest model-supported effort at or below the ceiling. A model whose
|
|
327
|
+
* floor exceeds the ceiling has nothing valid to snap to; the requested level
|
|
328
|
+
* is returned unchanged and the caller must reject or skip such models (see
|
|
329
|
+
* {@link modelSupportsEffortCeiling}).
|
|
332
330
|
*/
|
|
333
331
|
export function clampThinkingLevelToCeiling(
|
|
334
332
|
model: Model | undefined,
|
|
@@ -367,6 +365,14 @@ export function modelSupportsEffortCeiling(model: Model, ceiling: Effort): boole
|
|
|
367
365
|
return supported.some(candidate => THINKING_EFFORTS.indexOf(candidate) <= maxIndex);
|
|
368
366
|
}
|
|
369
367
|
|
|
368
|
+
/** Throws when `model` has no supported effort at or below `task.maxEffort`, so a capped spawn fails instead of running at its floor. */
|
|
369
|
+
export function assertModelSupportsEffortCeiling(model: Model, maxEffort: Effort): void {
|
|
370
|
+
if (modelSupportsEffortCeiling(model, maxEffort)) return;
|
|
371
|
+
throw new RangeError(
|
|
372
|
+
`${model.provider}/${model.id} has no supported thinking effort at or below task.maxEffort=${maxEffort}`,
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
370
376
|
/**
|
|
371
377
|
* The provisional concrete level shown while `auto` is configured but before a
|
|
372
378
|
* turn has been classified, and the fallback when classification fails. Prefers
|
package/src/tools/ast-grep.ts
CHANGED
|
@@ -14,7 +14,12 @@ import {
|
|
|
14
14
|
PREVIEW_LIMITS,
|
|
15
15
|
toPathList,
|
|
16
16
|
} from "../render/render-utils";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
classifyGroupedLines,
|
|
19
|
+
createCodeFrameStyler,
|
|
20
|
+
describeGroupedOutput,
|
|
21
|
+
groupLineIndicesByBlank,
|
|
22
|
+
} from "./grouped-file-output";
|
|
18
23
|
import { code, compact, node, span } from "../native/describe";
|
|
19
24
|
import type { NativeChild } from "../native/node";
|
|
20
25
|
import { errorText, noteText, resultText, toolHead } from "./native-view";
|
|
@@ -51,6 +56,8 @@ interface AstGrepRenderArgs {
|
|
|
51
56
|
/** Legacy pre-`path` argument name; kept so historical transcripts still render a scope. */
|
|
52
57
|
paths?: string[];
|
|
53
58
|
skip?: number;
|
|
59
|
+
/** Language the search parsed the files as; highlighting follows it over the file extension. */
|
|
60
|
+
lang?: string;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
const COLLAPSED_MATCH_LIMIT = PREVIEW_LIMITS.COLLAPSED_LINES * 2;
|
|
@@ -124,6 +131,7 @@ export const astGrepToolRenderer = {
|
|
|
124
131
|
// Resolve hyperlinks over the whole output so nested directory headers
|
|
125
132
|
// reconstruct across the blank-line groups the tree list collapses by.
|
|
126
133
|
const contexts = classifyGroupedLines(allLines, details?.cwd ?? details?.searchPath, details?.searchPath);
|
|
134
|
+
const styleCodeFrame = createCodeFrameStyler(allLines, contexts, "toolOutput", uiTheme, args?.lang);
|
|
127
135
|
// The displayed lines are sanitized, but OSC 8 destinations must retain the
|
|
128
136
|
// original path bytes. Only substitute targets for headers already linked
|
|
129
137
|
// by the sanitized output; never let raw text create additional links.
|
|
@@ -159,7 +167,7 @@ export const astGrepToolRenderer = {
|
|
|
159
167
|
const tinted = uiTheme.fg(ctx.depth === 1 ? "accent" : "dim", line);
|
|
160
168
|
styled = target ? fileHyperlink(target, tinted) : tinted;
|
|
161
169
|
} else {
|
|
162
|
-
styled = uiTheme.fg(line.startsWith(" meta:") ? "dim" : "toolOutput", line);
|
|
170
|
+
styled = styleCodeFrame(index) ?? uiTheme.fg(line.startsWith(" meta:") ? "dim" : "toolOutput", line);
|
|
163
171
|
}
|
|
164
172
|
styledLines[index] = styled;
|
|
165
173
|
return styled;
|
package/src/tools/eval.ts
CHANGED
|
@@ -120,6 +120,8 @@ export interface EvalToolDetails {
|
|
|
120
120
|
statusEvents?: EvalStatusEvent[];
|
|
121
121
|
/** Evictable events dropped from the front of `statusEvents` (see {@link recordStatusEvent}). */
|
|
122
122
|
statusEventsElided?: number;
|
|
123
|
+
/** Text the cell's tool calls sent to `out://`, oldest first; transcripts draw each as a reply after the call. */
|
|
124
|
+
replies?: string[];
|
|
123
125
|
isError?: boolean;
|
|
124
126
|
meta?: OutputMeta;
|
|
125
127
|
/** First backend that produced cells. Kept for transcript compatibility. */
|
package/src/tools/find.ts
CHANGED
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
PREVIEW_LIMITS,
|
|
18
18
|
replaceTabs,
|
|
19
19
|
} from "../render/render-utils";
|
|
20
|
-
import
|
|
20
|
+
import { getLanguageFromPath } from "../lang-from-path";
|
|
21
|
+
import { highlightCode, isHighlightLanguage, type Theme, type ThemeColor } from "../theme/theme";
|
|
21
22
|
import type { Component } from "../tui";
|
|
22
23
|
import type { OutputMeta } from "./output-meta";
|
|
23
24
|
import type {
|
|
@@ -171,10 +172,14 @@ function renderHit(hit: FindHit, rangeLimit: number, cwd: string | undefined, ra
|
|
|
171
172
|
`${gauge(hit.contentScore, theme)} ${theme.fg(scoreColor(hit.contentScore), hit.contentScore.toFixed(2))} ${link(theme.fg("accent", hit.rel))} ${theme.fg("dim", coverage)}`,
|
|
172
173
|
];
|
|
173
174
|
const ranges = [...hit.ranges].sort((a, b) => b.p - a.p || a.start - b.start).slice(0, rangeLimit);
|
|
175
|
+
const lang = getLanguageFromPath(hit.rel);
|
|
174
176
|
ranges.forEach((range, index) => {
|
|
175
177
|
const span = range.start === range.end ? String(range.start) : `${range.start}-${range.end}`;
|
|
176
178
|
const ref = link(theme.fg("muted", `:${span}`), range.start);
|
|
177
|
-
const
|
|
179
|
+
const source = replaceTabs(range.snippet.trim());
|
|
180
|
+
const snippet = isHighlightLanguage(lang)
|
|
181
|
+
? highlightCode(source, lang, theme).join("\n")
|
|
182
|
+
: theme.fg("toolOutput", source);
|
|
178
183
|
const branch = theme.fg("dim", getTreeBranch(index === ranges.length - 1, theme));
|
|
179
184
|
lines.push(` ${branch} ${ref} ${theme.fg("dim", range.p.toFixed(2))} ${snippet}`);
|
|
180
185
|
});
|
package/src/tools/grep.ts
CHANGED
|
@@ -34,7 +34,12 @@ import {
|
|
|
34
34
|
PREVIEW_LIMITS,
|
|
35
35
|
replaceTabs,
|
|
36
36
|
} from "../render/render-utils";
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
classifyGroupedLines,
|
|
39
|
+
createCodeFrameStyler,
|
|
40
|
+
describeGroupedOutput,
|
|
41
|
+
groupLineIndicesByBlank,
|
|
42
|
+
} from "./grouped-file-output";
|
|
38
43
|
|
|
39
44
|
/** Display metadata for grep tool results. */
|
|
40
45
|
export interface GrepToolDetails {
|
|
@@ -214,6 +219,7 @@ function createSearchLineStyler(
|
|
|
214
219
|
target: (displayPath: string) => string,
|
|
215
220
|
): (index: number) => string {
|
|
216
221
|
const contexts = classifyGroupedLines(lines, headerBase, fileScope);
|
|
222
|
+
const styleCodeFrame = createCodeFrameStyler(lines, contexts, "toolOutput", uiTheme);
|
|
217
223
|
// `classifyGroupedLines` can't resolve internal URLs (TUI-only), so track the
|
|
218
224
|
// resolved URL target here and use it for the body lines that follow.
|
|
219
225
|
const urlRaw: (string | undefined)[] = Array.from({ length: lines.length }, () => undefined);
|
|
@@ -257,7 +263,7 @@ function createSearchLineStyler(
|
|
|
257
263
|
styled = ctx.headerPath ? fileHyperlink(target(ctx.headerPath), tinted) : tinted;
|
|
258
264
|
}
|
|
259
265
|
} else {
|
|
260
|
-
const tinted = uiTheme.fg("toolOutput", line);
|
|
266
|
+
const tinted = styleCodeFrame(index) ?? uiTheme.fg("toolOutput", line);
|
|
261
267
|
const lineNumber = parseSearchDisplayLineNumber(line);
|
|
262
268
|
const filePath = ctx.filePath ? target(ctx.filePath) : urlFiles[index];
|
|
263
269
|
styled = filePath && lineNumber !== undefined ? fileHyperlink(filePath, tinted, { line: lineNumber }) : tinted;
|