@linxiraos/pi-tui 1.4.7 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +154 -231
- package/README.md +7 -1
- package/dist/types/app-keybindings.d.ts +5 -0
- package/dist/types/charts/table-data.d.ts +4 -2
- package/dist/types/chat/bash-execution.d.ts +4 -1
- package/dist/types/chat/eval-execution.d.ts +2 -0
- package/dist/types/chat/execution-shared.d.ts +14 -8
- package/dist/types/chat/figure-markdown.d.ts +2 -0
- package/dist/types/chat/svg-figure.d.ts +5 -0
- package/dist/types/chat/table-chart.d.ts +2 -0
- package/dist/types/chat/transcript-render-helpers.d.ts +11 -3
- package/dist/types/chrome/dynamic-border.d.ts +6 -0
- package/dist/types/chrome/transcript-status.d.ts +2 -2
- package/dist/types/components/editor.d.ts +15 -6
- package/dist/types/components/image.d.ts +6 -0
- package/dist/types/components/loader.d.ts +2 -0
- package/dist/types/keybinding-matchers.d.ts +7 -0
- package/dist/types/native/describe.d.ts +4 -2
- package/dist/types/native/node.d.ts +2 -3
- package/dist/types/native/overlay.d.ts +42 -2
- package/dist/types/native/state.d.ts +4 -0
- package/dist/types/overlays/btw-history-panel.d.ts +15 -0
- package/dist/types/overlays/btw-history.d.ts +24 -0
- package/dist/types/overlays/btw-inject.d.ts +22 -0
- package/dist/types/overlays/btw-panel.d.ts +7 -0
- package/dist/types/overlays/hook-editor.d.ts +2 -0
- package/dist/types/overlays/jobs-panel.d.ts +4 -0
- package/dist/types/overlays/model-browser.d.ts +1 -1
- package/dist/types/overlays/session-selector.d.ts +11 -2
- package/dist/types/prompt/composer.d.ts +13 -5
- package/dist/types/render/render-utils.d.ts +23 -1
- package/dist/types/setup/scenes/language.d.ts +3 -0
- package/dist/types/setup/scenes/types.d.ts +5 -0
- package/dist/types/setup/setup-version.d.ts +1 -1
- package/dist/types/setup/wizard.d.ts +1 -1
- package/dist/types/status-line/startup.d.ts +0 -15
- package/dist/types/terminal-capabilities.d.ts +1 -1
- package/dist/types/theme/symbols.d.ts +3 -1
- package/dist/types/theme/theme-class.d.ts +1 -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 +100 -19
- package/dist/types/tools/hashline-format.d.ts +5 -0
- package/dist/types/tools/native-view.d.ts +2 -0
- package/dist/types/tools/output-meta.d.ts +27 -0
- package/dist/types/tools/read.d.ts +14 -4
- package/dist/types/tools/task.d.ts +4 -3
- package/dist/types/tools/wait.d.ts +2 -0
- package/dist/types/tui.d.ts +12 -0
- package/dist/types/utils.d.ts +4 -0
- package/package.json +9 -9
- package/src/app-keybindings.d.ts +5 -0
- package/src/app-keybindings.ts +5 -0
- 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.d.ts +4 -2
- package/src/charts/table-data.ts +55 -6
- package/src/chat/bash-execution.d.ts +4 -1
- package/src/chat/bash-execution.ts +20 -9
- package/src/chat/chat-transcript-builder.ts +5 -2
- package/src/chat/eval-execution.d.ts +2 -0
- package/src/chat/eval-execution.ts +14 -7
- package/src/chat/execution-shared.d.ts +14 -8
- package/src/chat/execution-shared.ts +39 -18
- package/src/chat/figure-markdown.d.ts +2 -0
- package/src/chat/figure-markdown.ts +6 -4
- package/src/chat/read-tool-group.ts +56 -36
- package/src/chat/svg-figure.d.ts +5 -0
- package/src/chat/svg-figure.ts +55 -16
- package/src/chat/table-chart.d.ts +2 -0
- package/src/chat/table-chart.ts +19 -2
- package/src/chat/transcript-render-helpers.d.ts +11 -3
- package/src/chat/transcript-render-helpers.ts +70 -22
- package/src/chrome/dynamic-border.d.ts +6 -0
- package/src/chrome/dynamic-border.ts +28 -2
- package/src/chrome/transcript-status.d.ts +2 -2
- package/src/chrome/transcript-status.ts +5 -3
- package/src/components/editor.d.ts +15 -6
- package/src/components/editor.ts +123 -24
- package/src/components/image.d.ts +6 -0
- package/src/components/image.ts +13 -0
- package/src/components/key-value-list.ts +9 -9
- package/src/components/loader.d.ts +2 -0
- package/src/components/loader.ts +7 -0
- package/src/components/section.ts +1 -9
- package/src/components/table.ts +1 -9
- package/src/keybinding-matchers.d.ts +7 -0
- package/src/keybinding-matchers.ts +13 -0
- package/src/native/backend.ts +7 -3
- package/src/native/describe.d.ts +4 -2
- package/src/native/describe.ts +9 -4
- package/src/native/node.d.ts +2 -3
- package/src/native/node.ts +2 -3
- package/src/native/overlay.d.ts +42 -2
- package/src/native/overlay.ts +124 -16
- package/src/native/state.d.ts +4 -0
- package/src/native/state.ts +25 -5
- package/src/overlays/btw-history-panel.ts +106 -14
- package/src/overlays/btw-history.ts +65 -0
- package/src/overlays/btw-inject.ts +91 -0
- package/src/overlays/btw-panel.ts +53 -12
- package/src/overlays/extensions/extension-dashboard.ts +7 -8
- package/src/overlays/hook-editor.ts +6 -0
- package/src/overlays/jobs-panel.ts +82 -22
- package/src/overlays/login-dialog.ts +8 -26
- package/src/overlays/model-browser.ts +69 -10
- package/src/overlays/session-selector.ts +25 -5
- package/src/overlays/settings-defs.ts +2 -2
- package/src/overlays/settings-selector.ts +113 -11
- package/src/overlays/tree-selector.ts +83 -27
- package/src/overlays/usage-dashboard.ts +4 -6
- package/src/prompt/composer.ts +17 -5
- package/src/render/code-cell.ts +1 -1
- package/src/render/file-list.ts +4 -7
- package/src/render/render-utils.d.ts +23 -1
- package/src/render/render-utils.ts +38 -6
- package/src/setup/scenes/glyph.ts +1 -1
- package/src/setup/scenes/language.ts +122 -0
- package/src/setup/scenes/types.ts +6 -0
- package/src/setup/setup-version.ts +1 -1
- package/src/setup/wizard.ts +2 -0
- package/src/status-line/startup.ts +36 -70
- package/src/terminal-capabilities.d.ts +1 -1
- package/src/terminal-capabilities.ts +5 -0
- package/src/theme/symbols.d.ts +3 -1
- package/src/theme/symbols.ts +16 -9
- package/src/theme/theme-class.d.ts +1 -0
- package/src/theme/theme-class.ts +15 -3
- package/src/theme/theme.d.ts +1 -1
- package/src/theme/theme.ts +1 -0
- package/src/theme/tui-adapters.d.ts +2 -0
- package/src/theme/tui-adapters.ts +8 -3
- package/src/thinking.d.ts +8 -6
- package/src/thinking.ts +17 -11
- package/src/tmux.ts +1 -0
- package/src/tools/agent-tree.ts +13 -11
- package/src/tools/ask.ts +24 -37
- package/src/tools/ast-edit.ts +48 -93
- package/src/tools/ast-grep.d.ts +2 -0
- package/src/tools/ast-grep.ts +31 -67
- package/src/tools/bash.ts +7 -0
- package/src/tools/default-renderer.ts +1 -1
- package/src/tools/edit.ts +50 -43
- package/src/tools/eval.d.ts +2 -0
- package/src/tools/eval.ts +2 -0
- package/src/tools/fetch.ts +2 -1
- package/src/tools/find.d.ts +1 -1
- package/src/tools/find.ts +13 -5
- package/src/tools/github.ts +14 -46
- package/src/tools/glob.ts +2 -1
- package/src/tools/grep.ts +47 -277
- package/src/tools/grouped-file-output.d.ts +100 -19
- package/src/tools/grouped-file-output.ts +414 -103
- package/src/tools/hashline-format.d.ts +5 -0
- package/src/tools/hashline-format.ts +5 -0
- package/src/tools/json-tree.ts +1 -5
- package/src/tools/lsp.ts +210 -32
- package/src/tools/native-view.d.ts +2 -0
- package/src/tools/native-view.ts +11 -5
- package/src/tools/output-meta.d.ts +27 -0
- package/src/tools/output-meta.ts +68 -4
- package/src/tools/proc-render.ts +3 -3
- package/src/tools/read.d.ts +14 -4
- package/src/tools/read.ts +20 -5
- package/src/tools/task.d.ts +4 -3
- package/src/tools/task.ts +41 -81
- package/src/tools/vibe.ts +4 -4
- package/src/tools/wait.d.ts +2 -0
- package/src/tools/wait.ts +8 -5
- package/src/tools/write.ts +17 -27
- package/src/tools/yield.ts +1 -1
- package/src/tui.d.ts +12 -0
- package/src/tui.ts +91 -9
- package/src/utils.d.ts +4 -0
- package/src/utils.ts +10 -0
package/src/tools/grep.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
|
-
import { isRecord
|
|
2
|
+
import { isRecord } from "@linxiraos/pi-utils";
|
|
3
3
|
import type { Component } from "../tui";
|
|
4
4
|
import { Text } from "../components/text";
|
|
5
5
|
import type {
|
|
@@ -31,11 +31,19 @@ import {
|
|
|
31
31
|
formatCount,
|
|
32
32
|
formatEmptyMessage,
|
|
33
33
|
formatErrorMessage,
|
|
34
|
-
formatMoreItems,
|
|
35
34
|
PREVIEW_LIMITS,
|
|
36
|
-
replaceTabs,
|
|
37
35
|
} from "../render/render-utils";
|
|
38
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
classifyGroupedLines,
|
|
38
|
+
createCodeFrameStyler,
|
|
39
|
+
createGroupedRowStyler,
|
|
40
|
+
describeGroupedOutput,
|
|
41
|
+
fitGroupsToBudget,
|
|
42
|
+
groupedLinkTargets,
|
|
43
|
+
groupLineIndicesByBlank,
|
|
44
|
+
groupsByFile,
|
|
45
|
+
isMatchRow,
|
|
46
|
+
} from "./grouped-file-output";
|
|
39
47
|
|
|
40
48
|
/** Display metadata for grep tool results. */
|
|
41
49
|
export interface GrepToolDetails {
|
|
@@ -93,258 +101,12 @@ const EXPANDED_TEXT_LIMIT = PREVIEW_LIMITS.EXPANDED_LINES * 2;
|
|
|
93
101
|
/** Files a collapsed native grep shows (§7.3). */
|
|
94
102
|
const NATIVE_COLLAPSED_FILES = 2;
|
|
95
103
|
|
|
96
|
-
const SEARCH_CODE_FRAME_LINE_RE = /^\s*\*?(\d+)│/;
|
|
97
|
-
|
|
98
104
|
function searchScopeMeta(details: GrepToolDetails | undefined, searchPath?: string): string | undefined {
|
|
99
105
|
if (!details?.scopePath) return undefined;
|
|
100
106
|
const label = searchPath ? fileHyperlink(searchPath, details.scopePath) : details.scopePath;
|
|
101
107
|
return `in ${label}`;
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
function isStringArray(value: unknown): value is string[] {
|
|
105
|
-
return Array.isArray(value) && value.every((item: unknown) => typeof item === "string");
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function isStringRecord(value: unknown): value is Record<string, string> {
|
|
109
|
-
if (!isRecord(value)) return false;
|
|
110
|
-
for (const key in value) {
|
|
111
|
-
if (typeof value[key] !== "string") return false;
|
|
112
|
-
}
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function samePath(filePath: string): string {
|
|
117
|
-
return filePath;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** Keep only path metadata from the original details; display text always comes from sanitized details. */
|
|
121
|
-
function grepLinkTargets(details: GrepToolDetails | undefined, rawDetails: unknown) {
|
|
122
|
-
if (details === rawDetails) {
|
|
123
|
-
return {
|
|
124
|
-
target: samePath,
|
|
125
|
-
searchPath: details?.searchPath,
|
|
126
|
-
fileScope: details?.searchPath,
|
|
127
|
-
displayTargets: details?.displayTargets,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
const raw = typeof rawDetails === "object" && rawDetails !== null ? rawDetails : {};
|
|
131
|
-
const rawCwd = "cwd" in raw && typeof raw.cwd === "string" ? raw.cwd : undefined;
|
|
132
|
-
const rawSearchPath = "searchPath" in raw && typeof raw.searchPath === "string" ? raw.searchPath : undefined;
|
|
133
|
-
const rawFiles = "files" in raw && isStringArray(raw.files) ? raw.files : undefined;
|
|
134
|
-
const rawDisplayTargets =
|
|
135
|
-
"displayTargets" in raw && isStringRecord(raw.displayTargets) ? raw.displayTargets : undefined;
|
|
136
|
-
let displayTargets = details?.displayTargets;
|
|
137
|
-
if (rawDisplayTargets) {
|
|
138
|
-
displayTargets = {};
|
|
139
|
-
for (const label in rawDisplayTargets) {
|
|
140
|
-
displayTargets[sanitizeText(label)] = rawDisplayTargets[label]!;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const pathTargets = new Map<string, string>();
|
|
145
|
-
const displayBase = details?.cwd ?? details?.searchPath;
|
|
146
|
-
const rawBase = rawCwd ?? rawSearchPath ?? displayBase;
|
|
147
|
-
if (displayBase && rawBase && rawFiles && details?.files) {
|
|
148
|
-
for (let index = 0; index < Math.min(details.files.length, rawFiles.length); index++) {
|
|
149
|
-
const displayFile = path.resolve(displayBase, details.files[index]!);
|
|
150
|
-
const rawFile = path.resolve(rawBase, rawFiles[index]!);
|
|
151
|
-
pathTargets.set(displayFile, rawFile);
|
|
152
|
-
// Folded directory headers must retain the original path as well.
|
|
153
|
-
let displayDir = path.dirname(displayFile);
|
|
154
|
-
let rawDir = path.dirname(rawFile);
|
|
155
|
-
while (displayDir !== path.dirname(displayDir) && rawDir !== path.dirname(rawDir)) {
|
|
156
|
-
pathTargets.set(displayDir, rawDir);
|
|
157
|
-
displayDir = path.dirname(displayDir);
|
|
158
|
-
rawDir = path.dirname(rawDir);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
const target = (displayPath: string): string => {
|
|
163
|
-
const known = pathTargets.get(displayPath);
|
|
164
|
-
if (known) return known;
|
|
165
|
-
if (rawCwd && details?.cwd) return path.resolve(rawCwd, path.relative(details.cwd, displayPath));
|
|
166
|
-
return displayPath;
|
|
167
|
-
};
|
|
168
|
-
return {
|
|
169
|
-
target,
|
|
170
|
-
searchPath: rawSearchPath ?? details?.searchPath,
|
|
171
|
-
fileScope: rawSearchPath ?? details?.searchPath,
|
|
172
|
-
displayTargets,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function linkUrlLikeSearchHeader(
|
|
177
|
-
raw: string,
|
|
178
|
-
styled: string,
|
|
179
|
-
resolvedPath?: string,
|
|
180
|
-
): { line: string; absPath?: string } {
|
|
181
|
-
if (resolvedPath) return { line: fileHyperlink(resolvedPath, styled), absPath: resolvedPath };
|
|
182
|
-
return { line: uriHyperlink(raw, styled) };
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function parseSearchDisplayLineNumber(line: string): number | undefined {
|
|
186
|
-
const match = SEARCH_CODE_FRAME_LINE_RE.exec(line);
|
|
187
|
-
if (!match) return undefined;
|
|
188
|
-
return Number.parseInt(match[1]!, 10);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const SEARCH_MATCH_LINE_RE = /^\s*\*\d+(?:│|[:|])/;
|
|
192
|
-
|
|
193
|
-
function isSearchMatchLine(line: string): boolean {
|
|
194
|
-
return SEARCH_MATCH_LINE_RE.test(line);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function isSearchHeaderLine(line: string): boolean {
|
|
198
|
-
return /^#+ /.test(line);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const URL_HEADER_PREFIX_RE = /^#+\s+/;
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Build a memoized per-line styler for search display output. Classification
|
|
205
|
-
* and URL-target tracking walk the whole output once (nested directory stacks
|
|
206
|
-
* span blank-line groups), but styling and hyperlinking run only for the rows
|
|
207
|
-
* a preview actually shows.
|
|
208
|
-
*/
|
|
209
|
-
function createSearchLineStyler(
|
|
210
|
-
lines: readonly string[],
|
|
211
|
-
headerBase: string | undefined,
|
|
212
|
-
fileScope: string | undefined,
|
|
213
|
-
uiTheme: Theme,
|
|
214
|
-
displayTargets: Record<string, string> | undefined,
|
|
215
|
-
target: (displayPath: string) => string,
|
|
216
|
-
): (index: number) => string {
|
|
217
|
-
const contexts = classifyGroupedLines(lines, headerBase, fileScope);
|
|
218
|
-
// `classifyGroupedLines` can't resolve internal URLs (TUI-only), so track the
|
|
219
|
-
// resolved URL target here and use it for the body lines that follow.
|
|
220
|
-
const urlRaw: (string | undefined)[] = Array.from({ length: lines.length }, () => undefined);
|
|
221
|
-
const urlFiles: (string | undefined)[] = Array.from({ length: lines.length }, () => undefined);
|
|
222
|
-
let urlFile: string | undefined;
|
|
223
|
-
for (let index = 0; index < lines.length; index++) {
|
|
224
|
-
const ctx = contexts[index]!;
|
|
225
|
-
if (ctx.kind === "dir") {
|
|
226
|
-
urlFile = undefined;
|
|
227
|
-
} else if (ctx.kind === "file") {
|
|
228
|
-
if (ctx.isUrl) {
|
|
229
|
-
const raw = lines[index]!.replace(URL_HEADER_PREFIX_RE, "")
|
|
230
|
-
.trimEnd()
|
|
231
|
-
.replace(/\s+\([^)]*\)\s*$/, "");
|
|
232
|
-
urlRaw[index] = raw;
|
|
233
|
-
urlFile = displayTargets?.[raw];
|
|
234
|
-
} else {
|
|
235
|
-
urlFile = undefined;
|
|
236
|
-
}
|
|
237
|
-
} else {
|
|
238
|
-
urlFiles[index] = urlFile;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const styledLines: (string | undefined)[] = Array.from({ length: lines.length }, () => undefined);
|
|
242
|
-
return index => {
|
|
243
|
-
const cached = styledLines[index];
|
|
244
|
-
if (cached !== undefined) return cached;
|
|
245
|
-
const line = lines[index]!;
|
|
246
|
-
const ctx = contexts[index]!;
|
|
247
|
-
let styled: string;
|
|
248
|
-
if (ctx.kind === "dir") {
|
|
249
|
-
const accent = uiTheme.fg("accent", line);
|
|
250
|
-
styled = ctx.headerPath ? fileHyperlink(target(ctx.headerPath), accent) : accent;
|
|
251
|
-
} else if (ctx.kind === "file") {
|
|
252
|
-
const raw = urlRaw[index];
|
|
253
|
-
if (raw !== undefined) {
|
|
254
|
-
styled = linkUrlLikeSearchHeader(raw, uiTheme.fg("accent", line), displayTargets?.[raw]).line;
|
|
255
|
-
} else {
|
|
256
|
-
// Root-level files keep the bright accent; nested file headers are dimmed.
|
|
257
|
-
const tinted = uiTheme.fg(ctx.depth === 1 ? "accent" : "dim", line);
|
|
258
|
-
styled = ctx.headerPath ? fileHyperlink(target(ctx.headerPath), tinted) : tinted;
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
const tinted = uiTheme.fg("toolOutput", line);
|
|
262
|
-
const lineNumber = parseSearchDisplayLineNumber(line);
|
|
263
|
-
const filePath = ctx.filePath ? target(ctx.filePath) : urlFiles[index];
|
|
264
|
-
styled = filePath && lineNumber !== undefined ? fileHyperlink(filePath, tinted, { line: lineNumber }) : tinted;
|
|
265
|
-
}
|
|
266
|
-
styledLines[index] = styled;
|
|
267
|
-
return styled;
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function compactSearchPreviewGroup(group: readonly number[], lines: readonly string[]): readonly number[] {
|
|
272
|
-
const compact = group.filter(index => isSearchHeaderLine(lines[index]!) || isSearchMatchLine(lines[index]!));
|
|
273
|
-
return compact.length > 0 ? compact : group;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function countPreviewMatches(group: readonly number[], lines: readonly string[], hasMarkedMatches: boolean): number {
|
|
277
|
-
let count = 0;
|
|
278
|
-
for (const index of group) {
|
|
279
|
-
const line = lines[index]!;
|
|
280
|
-
if (hasMarkedMatches ? isSearchMatchLine(line) : !isSearchHeaderLine(line) && line.length > 0) count++;
|
|
281
|
-
}
|
|
282
|
-
return count;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function renderBudgetedSearchGroups(
|
|
286
|
-
groups: readonly (readonly number[])[],
|
|
287
|
-
lines: readonly string[],
|
|
288
|
-
styleLine: (index: number) => string,
|
|
289
|
-
maxLines: number,
|
|
290
|
-
matchCount: number,
|
|
291
|
-
uiTheme: Theme,
|
|
292
|
-
compact: boolean,
|
|
293
|
-
): string[] {
|
|
294
|
-
if (maxLines <= 0) return [];
|
|
295
|
-
const renderedGroups = groups
|
|
296
|
-
.map(group => (compact ? compactSearchPreviewGroup(group, lines) : group))
|
|
297
|
-
.filter(group => group.length > 0);
|
|
298
|
-
if (renderedGroups.length === 0) return [];
|
|
299
|
-
|
|
300
|
-
let totalLines = 0;
|
|
301
|
-
let totalMarkedMatches = 0;
|
|
302
|
-
let totalFallbackMatches = 0;
|
|
303
|
-
for (const group of renderedGroups) {
|
|
304
|
-
totalLines += group.length;
|
|
305
|
-
totalMarkedMatches += countPreviewMatches(group, lines, true);
|
|
306
|
-
totalFallbackMatches += countPreviewMatches(group, lines, false);
|
|
307
|
-
}
|
|
308
|
-
const hasMarkedMatches = totalMarkedMatches > 0;
|
|
309
|
-
const needsSummary = totalLines > maxLines;
|
|
310
|
-
const contentBudget = needsSummary ? Math.max(maxLines - 1, 0) : maxLines;
|
|
311
|
-
const visibleGroups: (readonly number[])[] = [];
|
|
312
|
-
let visibleLineCount = 0;
|
|
313
|
-
let visibleMatches = 0;
|
|
314
|
-
for (const group of renderedGroups) {
|
|
315
|
-
if (visibleLineCount >= contentBudget) break;
|
|
316
|
-
const available = contentBudget - visibleLineCount;
|
|
317
|
-
const take = Math.min(group.length, available);
|
|
318
|
-
if (take <= 0) break;
|
|
319
|
-
const visibleGroup = group.slice(0, take);
|
|
320
|
-
visibleGroups.push(visibleGroup);
|
|
321
|
-
visibleLineCount += visibleGroup.length;
|
|
322
|
-
visibleMatches += countPreviewMatches(visibleGroup, lines, hasMarkedMatches);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
const totalMatches = hasMarkedMatches ? totalMarkedMatches : Math.max(matchCount, totalFallbackMatches);
|
|
326
|
-
const hiddenMatches = Math.max(totalMatches - visibleMatches, 0);
|
|
327
|
-
const hiddenLines = Math.max(totalLines - visibleLineCount, 0);
|
|
328
|
-
const hasSummary = needsSummary && (hiddenMatches > 0 || hiddenLines > 0);
|
|
329
|
-
const out: string[] = [];
|
|
330
|
-
for (let i = 0; i < visibleGroups.length; i++) {
|
|
331
|
-
const group = visibleGroups[i]!;
|
|
332
|
-
const isLast = !hasSummary && i === visibleGroups.length - 1;
|
|
333
|
-
const prefix = `${uiTheme.fg("dim", getTreeBranch(isLast, uiTheme))} `;
|
|
334
|
-
const continuePrefix = uiTheme.fg("dim", getTreeContinuePrefix(isLast, uiTheme));
|
|
335
|
-
out.push(`${prefix}${replaceTabs(styleLine(group[0]!))}`);
|
|
336
|
-
for (let j = 1; j < group.length; j++) {
|
|
337
|
-
out.push(`${continuePrefix}${replaceTabs(styleLine(group[j]!))}`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
if (hasSummary) {
|
|
341
|
-
const hiddenLabel =
|
|
342
|
-
hiddenMatches > 0 ? formatMoreItems(hiddenMatches, "match") : formatMoreItems(hiddenLines, "line");
|
|
343
|
-
out.push(`${uiTheme.fg("dim", uiTheme.tree.last)} ${uiTheme.fg("muted", hiddenLabel)}`);
|
|
344
|
-
}
|
|
345
|
-
return out;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
110
|
function grepStatusIcon(uiTheme: Theme): string {
|
|
349
111
|
return uiTheme.fg("toolTitle", uiTheme.symbol("icon.search"));
|
|
350
112
|
}
|
|
@@ -423,7 +185,12 @@ export const grepToolRenderer = {
|
|
|
423
185
|
},
|
|
424
186
|
);
|
|
425
187
|
}
|
|
426
|
-
|
|
188
|
+
// The scope label links to the original (unsanitized) search path.
|
|
189
|
+
const rawDetails = options.renderContext?.rawDetails;
|
|
190
|
+
const searchPath =
|
|
191
|
+
isRecord(rawDetails) && typeof rawDetails.searchPath === "string"
|
|
192
|
+
? rawDetails.searchPath
|
|
193
|
+
: details?.searchPath;
|
|
427
194
|
|
|
428
195
|
const matchCount = details?.matchCount ?? 0;
|
|
429
196
|
const fileCount = details?.fileCount ?? 0;
|
|
@@ -446,7 +213,7 @@ export const grepToolRenderer = {
|
|
|
446
213
|
|
|
447
214
|
if (matchCount === 0) {
|
|
448
215
|
const meta = ["0 matches"];
|
|
449
|
-
const scopeMeta = searchScopeMeta(details,
|
|
216
|
+
const scopeMeta = searchScopeMeta(details, searchPath);
|
|
450
217
|
if (scopeMeta) meta.push(scopeMeta);
|
|
451
218
|
const header = renderStatusLine(
|
|
452
219
|
{ icon: "warning", title: "Grep", titleColor: "toolTitle", description: args?.pattern, meta },
|
|
@@ -459,7 +226,7 @@ export const grepToolRenderer = {
|
|
|
459
226
|
|
|
460
227
|
const summaryParts = [formatCount("match", matchCount), formatCount("file", fileCount)];
|
|
461
228
|
const meta = [...summaryParts];
|
|
462
|
-
const scopeMeta = searchScopeMeta(details,
|
|
229
|
+
const scopeMeta = searchScopeMeta(details, searchPath);
|
|
463
230
|
if (scopeMeta) meta.push(scopeMeta);
|
|
464
231
|
if (truncated) meta.push(uiTheme.fg("warning", tuiText("grepTruncated", "truncated")));
|
|
465
232
|
const description = args?.pattern ?? undefined;
|
|
@@ -476,20 +243,26 @@ export const grepToolRenderer = {
|
|
|
476
243
|
|
|
477
244
|
const textContent = result.details?.displayContent ?? result.content?.find(c => c.type === "text")?.text ?? "";
|
|
478
245
|
const allLines = textContent.split("\n");
|
|
479
|
-
//
|
|
480
|
-
//
|
|
481
|
-
//
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const styleLine =
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
);
|
|
492
|
-
const
|
|
246
|
+
// Classify the whole output so nested directory headers resolve across blank-line
|
|
247
|
+
// groups. Display paths are cwd-relative (`searchPath` for results that predate
|
|
248
|
+
// `cwd`); a single-file search's headerless lines belong to the searched file.
|
|
249
|
+
const contexts = classifyGroupedLines(allLines, details?.cwd ?? details?.searchPath, details?.searchPath);
|
|
250
|
+
const styleCodeFrame = createCodeFrameStyler(allLines, contexts, "toolOutput", uiTheme);
|
|
251
|
+
const styleLine = createGroupedRowStyler(allLines, contexts, uiTheme, {
|
|
252
|
+
linkTarget: groupedLinkTargets(contexts, textContent, details, rawDetails),
|
|
253
|
+
styleBody: index => styleCodeFrame(index) ?? uiTheme.fg("toolOutput", allLines[index]!),
|
|
254
|
+
linkLines: true,
|
|
255
|
+
});
|
|
256
|
+
const matchGroups = groupsByFile(groupLineIndicesByBlank(allLines), contexts);
|
|
257
|
+
// Output without `*` match marks (legacy results) counts its body rows as matches.
|
|
258
|
+
const marked = allLines.some(isMatchRow);
|
|
259
|
+
const isMatch = marked
|
|
260
|
+
? (index: number) => isMatchRow(allLines[index]!)
|
|
261
|
+
: (index: number) => contexts[index]!.kind === "content" && allLines[index]!.length > 0;
|
|
262
|
+
// Collapsed previews drop context rows, keeping each file row and its matches.
|
|
263
|
+
const compactGroups = marked
|
|
264
|
+
? matchGroups.map(group => group.filter(index => contexts[index]!.kind === "file" || isMatch(index)))
|
|
265
|
+
: matchGroups;
|
|
493
266
|
|
|
494
267
|
const extraLines: string[] = [];
|
|
495
268
|
if (missingNote) extraLines.push(missingNote);
|
|
@@ -497,18 +270,15 @@ export const grepToolRenderer = {
|
|
|
497
270
|
return createCachedComponent(
|
|
498
271
|
() => options.expanded,
|
|
499
272
|
width => {
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
273
|
+
const limit = options.expanded ? EXPANDED_TEXT_LIMIT : COLLAPSED_TEXT_LIMIT;
|
|
274
|
+
const { shown, summary } = fitGroupsToBudget(
|
|
275
|
+
options.expanded ? matchGroups : compactGroups,
|
|
276
|
+
Math.max(limit - extraLines.length, 0),
|
|
277
|
+
{ isUnit: isMatch, unit: "match", total: matchCount },
|
|
503
278
|
);
|
|
504
|
-
const matchLines =
|
|
505
|
-
|
|
506
|
-
allLines,
|
|
507
|
-
styleLine,
|
|
508
|
-
budget,
|
|
509
|
-
matchCount,
|
|
279
|
+
const matchLines = renderTreeList(
|
|
280
|
+
{ items: shown, trailingSummary: summary, renderItem: group => group.map(styleLine) },
|
|
510
281
|
uiTheme,
|
|
511
|
-
!options.expanded,
|
|
512
282
|
);
|
|
513
283
|
return fitHeaderedRows(header, [...matchLines, ...extraLines], width);
|
|
514
284
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { NativeNode } from "../native/node";
|
|
2
|
+
import { type Theme, type ThemeColor } from "../theme/theme";
|
|
2
3
|
/**
|
|
3
4
|
* One file's contribution to a grouped file output. The header itself is generated
|
|
4
5
|
* by `formatGroupedFiles` (one `#` per nesting level); use `headerSuffix` to tack
|
|
@@ -51,22 +52,35 @@ export interface FileMatchSection {
|
|
|
51
52
|
* Files with no model lines are omitted.
|
|
52
53
|
*/
|
|
53
54
|
export declare function formatFileMatches(files: string[], grouped: boolean, renderFile: (filePath: string) => FileMatchSection): GroupedFilesOutput;
|
|
54
|
-
/**
|
|
55
|
+
/** Whether a row of grouped output is a code-frame row the search matched (`*12│…`). */
|
|
56
|
+
export declare function isMatchRow(line: string): boolean;
|
|
57
|
+
/** Per-line classification of grouped output, used by renderers for file rows and hyperlinks. */
|
|
55
58
|
export interface GroupedLineContext {
|
|
56
59
|
/** Directory header, file header, or any non-header body/content line. */
|
|
57
60
|
kind: "dir" | "file" | "content";
|
|
58
61
|
/** Number of leading `#` for headers; 0 for content lines. */
|
|
59
62
|
depth: number;
|
|
60
|
-
/** Resolved absolute path of the
|
|
63
|
+
/** Resolved absolute path of the file a header points at (when resolvable). */
|
|
61
64
|
headerPath?: string;
|
|
65
|
+
/**
|
|
66
|
+
* For file headers, the full display path: the folded directory chain joined
|
|
67
|
+
* with the name, without `#` markers or the hashline tag.
|
|
68
|
+
*/
|
|
69
|
+
displayPath?: string;
|
|
70
|
+
/** For file headers, a trailing parenthesized note such as `(2 replacements)`. */
|
|
71
|
+
suffix?: string;
|
|
62
72
|
/** For content lines, the absolute path of the owning file (line hyperlinks). */
|
|
63
73
|
filePath?: string;
|
|
64
|
-
/**
|
|
65
|
-
|
|
74
|
+
/**
|
|
75
|
+
* The internal or url-like target, as written, that a header names or a
|
|
76
|
+
* content line belongs to; the caller resolves it (no filesystem path).
|
|
77
|
+
*/
|
|
78
|
+
url?: string;
|
|
66
79
|
}
|
|
67
80
|
/**
|
|
68
81
|
* Walk grouped output lines, tracking a directory stack keyed by header depth, so
|
|
69
|
-
* each header and body line can be linked back to its absolute filesystem path
|
|
82
|
+
* each header and body line can be linked back to its absolute filesystem path
|
|
83
|
+
* and each file header to its full display path.
|
|
70
84
|
* Reconstruction is stack-based (not per-blank-group) so nested directory headers
|
|
71
85
|
* resolve correctly across the whole output.
|
|
72
86
|
*
|
|
@@ -75,9 +89,64 @@ export interface GroupedLineContext {
|
|
|
75
89
|
* formatted relative to cwd regardless of the (sub)directory the search was
|
|
76
90
|
* scoped to. `fileScope` is the initial owning file for body lines that appear
|
|
77
91
|
* before any header (single-file scopes have no `#` headers); it defaults to
|
|
78
|
-
* `headerBase` and should be passed the scoped file's absolute path.
|
|
92
|
+
* `headerBase` and should be passed the scoped file's absolute path. A URL base
|
|
93
|
+
* or scope (`local://…`) is no filesystem path: headerless lines belong to the
|
|
94
|
+
* URL, and headers under a URL base get no path.
|
|
79
95
|
*/
|
|
80
96
|
export declare function classifyGroupedLines(lines: readonly string[], headerBase: string | undefined, fileScope?: string | undefined): GroupedLineContext[];
|
|
97
|
+
/**
|
|
98
|
+
* Line groups with one file per group, for terminal tree lists: `# dir/`
|
|
99
|
+
* header rows are dropped (each file row carries its full path), and every
|
|
100
|
+
* file row starts a group of its own, so each file gets its own branch instead
|
|
101
|
+
* of hanging under the previous file of its directory. Rows before a group's
|
|
102
|
+
* first file row (notes, a single-file scope's matches) keep their group.
|
|
103
|
+
*/
|
|
104
|
+
export declare function groupsByFile(groups: readonly (readonly number[])[], contexts: readonly GroupedLineContext[]): number[][];
|
|
105
|
+
/** Details fields a grouped-output tool records for links: the display base paths and resolved URL targets. */
|
|
106
|
+
export interface GroupedLinkDetails {
|
|
107
|
+
cwd?: string;
|
|
108
|
+
searchPath?: string;
|
|
109
|
+
displayTargets?: Record<string, string>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Link targets for the rows of sanitized grouped output: a file row's file, a
|
|
113
|
+
* body row's owning file, and for an internal URL the file `displayTargets`
|
|
114
|
+
* resolves it to. Destinations keep the original path bytes: while the raw
|
|
115
|
+
* `displayContent` still aligns line-for-line with the sanitized `displayText`,
|
|
116
|
+
* a row takes its raw classification's target. Raw text never links a row the
|
|
117
|
+
* sanitized output leaves unlinked.
|
|
118
|
+
*/
|
|
119
|
+
export declare function groupedLinkTargets(contexts: readonly GroupedLineContext[], displayText: string, details: GroupedLinkDetails | undefined, rawDetails: unknown): (index: number) => string | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* A memoized styler for the rows of grouped output, so a collapsed preview
|
|
122
|
+
* styles only the rows it shows. A file row is its full path (dim directory,
|
|
123
|
+
* name in {@link FILE_NAME_COLOR}; a URL whole in that color) and any dim
|
|
124
|
+
* suffix, linked to `linkTarget`'s file or, for an unresolved URL, the URL.
|
|
125
|
+
* Body rows come from `styleBody`, tabs expanded; with `linkLines` a numbered
|
|
126
|
+
* code-frame row links to its line in the owning file.
|
|
127
|
+
*/
|
|
128
|
+
export declare function createGroupedRowStyler(lines: readonly string[], contexts: readonly GroupedLineContext[], theme: Theme, options: {
|
|
129
|
+
linkTarget: (index: number) => string | undefined;
|
|
130
|
+
styleBody: (index: number) => string;
|
|
131
|
+
linkLines?: boolean;
|
|
132
|
+
}): (index: number) => string;
|
|
133
|
+
/**
|
|
134
|
+
* Fit line groups (one file each) into `budget` rows, the `… N more` summary row
|
|
135
|
+
* included: whole groups first, then the next group cut short when it can still
|
|
136
|
+
* show a row under its file row (the first group always shows its head). The
|
|
137
|
+
* summary counts the `unit`s left out, the rows `isUnit` accepts, out of `total`
|
|
138
|
+
* when the caller knows it; with none left out it counts hidden lines. `gap`
|
|
139
|
+
* rows separate shown groups (framed lists put a blank line between files).
|
|
140
|
+
*/
|
|
141
|
+
export declare function fitGroupsToBudget(groups: readonly (readonly number[])[], budget: number, options: {
|
|
142
|
+
isUnit: (index: number) => boolean;
|
|
143
|
+
unit: string;
|
|
144
|
+
total?: number;
|
|
145
|
+
gap?: number;
|
|
146
|
+
}): {
|
|
147
|
+
shown: (readonly number[])[];
|
|
148
|
+
summary: string;
|
|
149
|
+
};
|
|
81
150
|
/**
|
|
82
151
|
* Split line indices into blank-line-separated groups, mirroring
|
|
83
152
|
* `splitGroupsByBlankLine`: when any blank line is present, break on runs of
|
|
@@ -85,6 +154,15 @@ export declare function classifyGroupedLines(lines: readonly string[], headerBas
|
|
|
85
154
|
* indices lets callers slice parallel arrays (raw lines, styled lines, contexts).
|
|
86
155
|
*/
|
|
87
156
|
export declare function groupLineIndicesByBlank(rawLines: readonly string[]): number[][];
|
|
157
|
+
/**
|
|
158
|
+
* Styled code-frame rows of grouped search output, highlighted in each owning
|
|
159
|
+
* file's language (`lang` overrides it when the highlighter knows it). A run of
|
|
160
|
+
* consecutive line numbers in one file highlights together on its first
|
|
161
|
+
* request; a gap row, a jump in line numbers or another file starts a new run.
|
|
162
|
+
* Rows without a numbered code frame (headers, gap rows, notes) return
|
|
163
|
+
* undefined, for the caller to style.
|
|
164
|
+
*/
|
|
165
|
+
export declare function createCodeFrameStyler(lines: readonly string[], contexts: readonly GroupedLineContext[], color: ThemeColor, theme: Theme, lang?: string): (index: number) => string | undefined;
|
|
88
166
|
/** One event of {@link walkGroupedOutput}: a directory header, a file header, or a non-blank body line. */
|
|
89
167
|
export type GroupedOutputEvent = {
|
|
90
168
|
readonly kind: "dir";
|
|
@@ -98,35 +176,38 @@ export type GroupedOutputEvent = {
|
|
|
98
176
|
};
|
|
99
177
|
/**
|
|
100
178
|
* Walk grouped output (`# dir/`, `## file.ts (suffix)`, body lines), resolving
|
|
101
|
-
* each file header to its full display path (
|
|
102
|
-
*
|
|
179
|
+
* each file header to its full display path (see {@link classifyGroupedLines})
|
|
180
|
+
* and dropping blank separator lines.
|
|
103
181
|
*/
|
|
104
182
|
export declare function walkGroupedOutput(lines: readonly string[]): Generator<GroupedOutputEvent>;
|
|
105
|
-
/** One source line for {@link numberedCode}: its number (`null` for an elision marker), text and match mark. */
|
|
183
|
+
/** One source line for {@link numberedCode}: its number (`null` for an elision marker, which adds no line), text and match mark. */
|
|
106
184
|
export interface NumberedLine {
|
|
107
185
|
n: number | null;
|
|
108
186
|
text: string;
|
|
109
187
|
mark?: boolean;
|
|
110
188
|
}
|
|
111
189
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
190
|
+
* One numbered `code` block for possibly non-contiguous source lines (match
|
|
191
|
+
* lines `mark`ed by their line number): `start` when the numbers run on
|
|
192
|
+
* consecutively, else `nums` (each line's number), from whose jumps Tern draws
|
|
193
|
+
* the `…` gap rows in the gutter. Elision markers (`n: null`) add no line; the
|
|
194
|
+
* numbers jump around them. `path` is the file the lines come from: Tern picks
|
|
195
|
+
* their grammar from it and draws no header (the row or head above names the
|
|
196
|
+
* file). `wrap` soft-wraps long lines instead of scrolling the block sideways.
|
|
197
|
+
* `undefined` when no line is numbered.
|
|
118
198
|
*/
|
|
119
199
|
export declare function numberedCode(lines: readonly NumberedLine[], opts?: {
|
|
120
200
|
path?: string;
|
|
121
201
|
wrap?: boolean;
|
|
122
|
-
}): NativeNode
|
|
202
|
+
}): NativeNode | undefined;
|
|
123
203
|
/**
|
|
124
204
|
* Describe grouped search output (grep / ast-grep / ast-edit display content)
|
|
125
205
|
* by file (§7.3 grep): per file a 22px path row (dim dir, strong name, the
|
|
126
206
|
* header's suffix or the match count as a chip), then its lines as
|
|
127
|
-
* {@link numberedCode} with match lines marked
|
|
128
|
-
* runs. Unnumbered body lines stay plain
|
|
129
|
-
* first files (the caller says how many
|
|
207
|
+
* one {@link numberedCode} block with match lines marked (gaps between
|
|
208
|
+
* non-adjacent runs drawn in its gutter). Unnumbered body lines stay plain
|
|
209
|
+
* `code`. `maxFiles` keeps only the first files (the caller says how many
|
|
210
|
+
* were left out). `file` owns the lines
|
|
130
211
|
* before any header: a single-file search prints none, yet its lines get the
|
|
131
212
|
* same file row as a directory search's.
|
|
132
213
|
*/
|