@floydous/pi-agent-kernel 0.3.1 → 0.3.3
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/AGENT_KERNEL_SYS_PROMPT.md +10 -0
- package/CHANGELOG.md +44 -10
- package/README.md +61 -78
- package/config.toml +8 -2
- package/package.json +3 -1
- package/src/config/kernel_config.ts +24 -6
- package/src/editing/auto_heal.ts +232 -0
- package/src/editing/patch.ts +214 -17
- package/src/editing/post_edit_verification.ts +3 -2
- package/src/editing/smart_anchor.ts +420 -0
- package/src/index.ts +212 -152
- package/src/retrieval/repomap.ts +2 -1
- package/src/retrieval/search_bm25.ts +14 -1
- package/src/retrieval/search_chunker.ts +69 -3
- package/src/retrieval/search_config.ts +5 -6
- package/src/retrieval/search_index.ts +208 -82
- package/src/retrieval/symbol_reader.ts +34 -4
- package/src/safety/epistemic_guard.ts +304 -38
- package/src/safety/output_clamper.ts +28 -4
- package/src/tools/ast_search_tool.ts +19 -8
- package/src/tools/code_search_tool.ts +43 -29
- package/src/tools/edit_tool.ts +510 -197
- package/src/tools/read_tool.ts +265 -28
- package/src/ui/footer.ts +45 -19
- package/src/dedup/content_store.ts +0 -365
- package/src/dedup/recall_tool.ts +0 -155
package/src/tools/read_tool.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as path from "node:path";
|
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
6
|
import { extractSymbolContent } from "../retrieval/symbol_reader";
|
|
7
7
|
import { findSymbolSuggestions } from "../retrieval/ast_search";
|
|
8
|
+
import { computeLineHash, formatSmartAnchorLines } from "../editing/smart_anchor";
|
|
8
9
|
import {
|
|
9
10
|
globalEpistemicGuard,
|
|
10
11
|
resolveUserPath,
|
|
@@ -15,23 +16,105 @@ function countFileLines(filePath: string): number {
|
|
|
15
16
|
return fs.readFileSync(filePath, "utf8").split("\n").length;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
const MAX_READ_LINES = 2_000;
|
|
20
|
+
const MAX_READ_BYTES = 50 * 1024;
|
|
21
|
+
|
|
22
|
+
function shouldUseAnchors(
|
|
23
|
+
params: any,
|
|
24
|
+
benchmarkMethod: string | undefined,
|
|
25
|
+
readMode: string | undefined,
|
|
26
|
+
defaultAnchors: boolean,
|
|
27
|
+
targeted: boolean,
|
|
28
|
+
): boolean {
|
|
29
|
+
if (params.anchors === true) return true;
|
|
30
|
+
if (params.raw === true || params.anchors === false) return false;
|
|
31
|
+
if (readMode === "plain") return false;
|
|
32
|
+
if (readMode === "anchored") return true;
|
|
33
|
+
if (benchmarkMethod === "hash-anchor") return true;
|
|
34
|
+
if (benchmarkMethod === "line-range" || benchmarkMethod === "search-replace" || benchmarkMethod === "adaptive") return false;
|
|
35
|
+
if (targeted) return defaultAnchors === true;
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function formatReadLine(
|
|
40
|
+
lines: readonly string[],
|
|
41
|
+
index: number,
|
|
42
|
+
useAnchors: boolean,
|
|
43
|
+
numberWidth: number,
|
|
44
|
+
benchmarkMethod: string | undefined,
|
|
45
|
+
): string {
|
|
46
|
+
const line = lines[index]!;
|
|
47
|
+
if (useAnchors) {
|
|
48
|
+
return `${String(index + 1).padStart(numberWidth, " ")}#${computeLineHash(lines, index)}│${line}`;
|
|
49
|
+
}
|
|
50
|
+
if (benchmarkMethod === "line-range" || benchmarkMethod === "adaptive") {
|
|
51
|
+
return `${String(index + 1).padStart(numberWidth, " ")}│${line}`;
|
|
52
|
+
}
|
|
53
|
+
return line;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function selectReadLineIndexes(
|
|
57
|
+
lines: readonly string[],
|
|
58
|
+
startIdx: number,
|
|
59
|
+
endIdx: number,
|
|
60
|
+
formatLine: (index: number) => string,
|
|
61
|
+
): number[] {
|
|
62
|
+
const indexes = Array.from({ length: endIdx - startIdx }, (_, index) => startIdx + index);
|
|
63
|
+
const fits = (candidate: readonly number[]) =>
|
|
64
|
+
candidate.length <= MAX_READ_LINES &&
|
|
65
|
+
Buffer.byteLength(candidate.map(formatLine).join("\n"), "utf8") <= MAX_READ_BYTES;
|
|
66
|
+
if (indexes.length <= MAX_READ_LINES && fits(indexes)) return indexes;
|
|
67
|
+
const first = indexes[0];
|
|
68
|
+
if (first !== undefined && Buffer.byteLength(formatLine(first), "utf8") > MAX_READ_BYTES) return [];
|
|
69
|
+
let headCount = Math.min(MAX_READ_LINES, indexes.length);
|
|
70
|
+
while (headCount > 0 && !fits(indexes.slice(0, headCount))) headCount--;
|
|
71
|
+
return indexes.slice(0, headCount);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function lineRanges(indexes: readonly number[]): Array<{ startLine: number; endLine: number }> {
|
|
75
|
+
const ranges: Array<{ startLine: number; endLine: number }> = [];
|
|
76
|
+
for (const index of indexes) {
|
|
77
|
+
const line = index + 1;
|
|
78
|
+
const previous = ranges[ranges.length - 1];
|
|
79
|
+
if (previous && previous.endLine === line - 1) previous.endLine = line;
|
|
80
|
+
else ranges.push({ startLine: line, endLine: line });
|
|
81
|
+
}
|
|
82
|
+
return ranges;
|
|
83
|
+
}
|
|
84
|
+
|
|
18
85
|
/** Extracted from index.ts — registers the `read` tool. */
|
|
19
86
|
export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
20
87
|
// 6. Tool: `read` (Unified File Reader with Surgical AST Symbol Extraction - Replaces stock read tool)
|
|
88
|
+
const editMethod = process.env.PI_EDIT_METHOD?.toLowerCase();
|
|
89
|
+
const benchmarkMethod = ["line-range", "search-replace", "hash-anchor", "adaptive"].includes(editMethod || "") ? editMethod : undefined;
|
|
90
|
+
const readMode = process.env.PI_READ_MODE?.toLowerCase();
|
|
21
91
|
const readToolDefinition: any = {
|
|
22
92
|
name: "read",
|
|
23
93
|
label: "Read File / Symbol",
|
|
24
94
|
description:
|
|
25
|
-
|
|
26
|
-
|
|
95
|
+
benchmarkMethod === "line-range"
|
|
96
|
+
? "Read source with line numbers for numeric line-range edits."
|
|
97
|
+
: benchmarkMethod === "search-replace"
|
|
98
|
+
? "Read source text for exact search/replace edits."
|
|
99
|
+
: benchmarkMethod === "adaptive"
|
|
100
|
+
? "Read source with line numbers. Prefer unique search/replace; use line ranges when needed."
|
|
101
|
+
: "Read file contents (plain text), extract a symbol via 'symbol', or read multiple files via 'paths'. Bounded at 2,000 lines or 50KB. Use 'offset'/'limit' for ranges.",
|
|
102
|
+
promptSnippet: "Read file contents, inspect line ranges, extract symbols, or read multiple files via 'paths'",
|
|
27
103
|
renderShell: "default",
|
|
28
104
|
parameters: Type.Object({
|
|
29
|
-
path: Type.
|
|
30
|
-
|
|
31
|
-
|
|
105
|
+
path: Type.Optional(
|
|
106
|
+
Type.String({
|
|
107
|
+
description: "File path (relative or absolute). For multiple files, use 'paths'",
|
|
108
|
+
}),
|
|
109
|
+
),
|
|
110
|
+
paths: Type.Optional(
|
|
111
|
+
Type.Array(Type.String(), {
|
|
112
|
+
description: "Read multiple files in one turn",
|
|
113
|
+
}),
|
|
114
|
+
),
|
|
32
115
|
symbol: Type.Optional(
|
|
33
116
|
Type.String({
|
|
34
|
-
description: "
|
|
117
|
+
description: "Function, class, or type to extract",
|
|
35
118
|
}),
|
|
36
119
|
),
|
|
37
120
|
offset: Type.Optional(
|
|
@@ -46,7 +129,17 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
46
129
|
),
|
|
47
130
|
surrounding_lines: Type.Optional(
|
|
48
131
|
Type.Number({
|
|
49
|
-
description: "Extra surrounding context lines for symbol
|
|
132
|
+
description: "Extra surrounding context lines for symbol",
|
|
133
|
+
}),
|
|
134
|
+
),
|
|
135
|
+
anchors: Type.Optional(
|
|
136
|
+
Type.Boolean({
|
|
137
|
+
description: "Narrow ranges (<100 lines) with LINE#HASH│ anchors (default: false, plain text)",
|
|
138
|
+
}),
|
|
139
|
+
),
|
|
140
|
+
raw: Type.Optional(
|
|
141
|
+
Type.Boolean({
|
|
142
|
+
description: "Clean raw text without line numbers or anchors",
|
|
50
143
|
}),
|
|
51
144
|
),
|
|
52
145
|
}),
|
|
@@ -57,15 +150,113 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
57
150
|
onUpdate: any,
|
|
58
151
|
ctx: any,
|
|
59
152
|
): Promise<any> {
|
|
60
|
-
|
|
153
|
+
let targetPaths: string[] = [];
|
|
154
|
+
if (params && typeof params === "object") {
|
|
155
|
+
if (Array.isArray(params.paths)) {
|
|
156
|
+
targetPaths = params.paths.filter((p: any) => typeof p === "string" && p.trim().length > 0);
|
|
157
|
+
} else if (typeof params.paths === "string" && params.paths.trim().length > 0) {
|
|
158
|
+
targetPaths = [params.paths.trim()];
|
|
159
|
+
} else if (Array.isArray(params.path)) {
|
|
160
|
+
targetPaths = params.path.filter((p: any) => typeof p === "string" && p.trim().length > 0);
|
|
161
|
+
} else if (typeof params.path === "string" && params.path.trim().length > 0) {
|
|
162
|
+
targetPaths = [params.path.trim()];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (targetPaths.length === 0) {
|
|
61
167
|
return {
|
|
62
168
|
content: [
|
|
63
|
-
{ type: "text", text: "[READ ERROR] Missing required 'path' parameter." },
|
|
169
|
+
{ type: "text", text: "[READ ERROR] Missing required 'path' or 'paths' parameter." },
|
|
64
170
|
],
|
|
65
171
|
isError: true,
|
|
66
172
|
};
|
|
67
173
|
}
|
|
68
174
|
|
|
175
|
+
// Batch mode: multiple files in one turn
|
|
176
|
+
if (targetPaths.length > 1) {
|
|
177
|
+
const MAX_BATCH_PATHS = 20;
|
|
178
|
+
const MAX_BATCH_BYTES = 24 * 1024; // 24KB aggregate ceiling across batch
|
|
179
|
+
const MAX_BATCH_FILE_LINES = 150; // max 150 lines per file in batch mode
|
|
180
|
+
const pathsToRead = targetPaths.slice(0, MAX_BATCH_PATHS);
|
|
181
|
+
const results: string[] = [];
|
|
182
|
+
const detailsList: any[] = [];
|
|
183
|
+
let hasAnySuccess = false;
|
|
184
|
+
let cumulativeBytes = 0;
|
|
185
|
+
|
|
186
|
+
for (let i = 0; i < pathsToRead.length; i++) {
|
|
187
|
+
const filePath = pathsToRead[i];
|
|
188
|
+
if (cumulativeBytes >= MAX_BATCH_BYTES) {
|
|
189
|
+
results.push(`[...] Remaining ${pathsToRead.length - i} file(s) skipped: batch byte limit reached (24KB) [...]`);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
const resolvedPath = resolveUserPath(filePath, ctx.cwd);
|
|
193
|
+
const relPath = path.relative(ctx.cwd, resolvedPath) || filePath;
|
|
194
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
195
|
+
results.push(`=== file: ${relPath} ===\nFile not found: ${filePath}`);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const content = fs.readFileSync(resolvedPath, "utf-8");
|
|
200
|
+
const lines = content.split("\n");
|
|
201
|
+
const totalLines = lines.length;
|
|
202
|
+
const fileOffset = params.offset && params.offset > 0 ? params.offset : 1;
|
|
203
|
+
const fileLimit = params.limit ? Math.min(params.limit, MAX_BATCH_FILE_LINES) : MAX_BATCH_FILE_LINES;
|
|
204
|
+
const startIdx = Math.max(0, fileOffset - 1);
|
|
205
|
+
const endIdx = Math.min(totalLines, startIdx + fileLimit);
|
|
206
|
+
|
|
207
|
+
const numberWidth = String(totalLines).length;
|
|
208
|
+
// Batch reads are always plain text to protect token budgets
|
|
209
|
+
const formatLine = (index: number) => formatReadLine(lines, index, false, numberWidth, benchmarkMethod);
|
|
210
|
+
const visibleIndexes = selectReadLineIndexes(lines, startIdx, endIdx, formatLine);
|
|
211
|
+
const outputLines = visibleIndexes.map(formatLine);
|
|
212
|
+
const isTruncated = (startIdx + visibleIndexes.length) < totalLines || startIdx > 0;
|
|
213
|
+
if (isTruncated) {
|
|
214
|
+
outputLines.push(`[truncated: ${relPath}, returned lines ${startIdx + 1}-${startIdx + visibleIndexes.length} of ${totalLines}. Continue with read(path, offset=${startIdx + visibleIndexes.length + 1})]`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
globalEpistemicGuard.recordFileRead(
|
|
218
|
+
resolvedPath,
|
|
219
|
+
deps.getSessionId(ctx),
|
|
220
|
+
ctx.cwd,
|
|
221
|
+
content,
|
|
222
|
+
{
|
|
223
|
+
coverage: {
|
|
224
|
+
complete: !isTruncated,
|
|
225
|
+
ranges: lineRanges(visibleIndexes),
|
|
226
|
+
totalLines,
|
|
227
|
+
},
|
|
228
|
+
provenance: "read",
|
|
229
|
+
},
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const formattedOutput = `=== file: ${relPath} (${totalLines} lines) ===\n${outputLines.join("\n")}`;
|
|
233
|
+
cumulativeBytes += Buffer.byteLength(formattedOutput, "utf8");
|
|
234
|
+
results.push(formattedOutput);
|
|
235
|
+
detailsList.push({ path: filePath, totalLines, shownLines: visibleIndexes.length, truncated: isTruncated });
|
|
236
|
+
hasAnySuccess = true;
|
|
237
|
+
|
|
238
|
+
if (cumulativeBytes >= MAX_BATCH_BYTES && i < pathsToRead.length - 1) {
|
|
239
|
+
results.push(`[...] Remaining ${pathsToRead.length - 1 - i} file(s) skipped: batch byte limit reached (24KB) [...]`);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
} catch (err: any) {
|
|
243
|
+
results.push(`=== file: ${relPath} ===\nError reading file: ${err.message}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (targetPaths.length > MAX_BATCH_PATHS) {
|
|
248
|
+
results.push(`[...] Note: Truncated to first ${MAX_BATCH_PATHS} files (${targetPaths.length - MAX_BATCH_PATHS} omitted).`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
content: [{ type: "text", text: results.join("\n\n") }],
|
|
253
|
+
details: { batch: true, count: pathsToRead.length, files: detailsList },
|
|
254
|
+
isError: !hasAnySuccess,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Single file read
|
|
259
|
+
params.path = targetPaths[0];
|
|
69
260
|
const resolvedPath = resolveUserPath(params.path, ctx.cwd);
|
|
70
261
|
if (!fs.existsSync(resolvedPath)) {
|
|
71
262
|
return {
|
|
@@ -160,11 +351,22 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
160
351
|
},
|
|
161
352
|
);
|
|
162
353
|
|
|
354
|
+
const config = deps.getConfig?.(ctx.cwd);
|
|
355
|
+
const defaultAnchors = config?.editing?.default_anchors ?? true;
|
|
356
|
+
const configuredReadMode = readMode ?? config?.editing?.read_mode ?? "auto";
|
|
357
|
+
const useAnchors = shouldUseAnchors(params, benchmarkMethod, configuredReadMode, defaultAnchors, true);
|
|
358
|
+
|
|
359
|
+
const allFileLines = symbolSnapshot.split("\n");
|
|
163
360
|
const formatted = res.symbols
|
|
164
|
-
.map(
|
|
165
|
-
(s)
|
|
166
|
-
|
|
167
|
-
|
|
361
|
+
.map((s) => {
|
|
362
|
+
const header = `// ${path.relative(ctx.cwd, s.filePath) || s.filePath}:${s.startLine}-${s.endLine} [${s.kind}] ${s.name}`;
|
|
363
|
+
const body = useAnchors
|
|
364
|
+
? formatSmartAnchorLines(allFileLines, s.startLine, s.endLine)
|
|
365
|
+
: benchmarkMethod === "line-range"
|
|
366
|
+
? allFileLines.slice(s.startLine - 1, s.endLine).map((line, index) => `${String(s.startLine + index).padStart(String(s.endLine).length, " ")}│${line}`).join("\n")
|
|
367
|
+
: s.content;
|
|
368
|
+
return `${header}\n${body}`;
|
|
369
|
+
})
|
|
168
370
|
.join("\n\n");
|
|
169
371
|
|
|
170
372
|
return {
|
|
@@ -275,11 +477,11 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
275
477
|
}
|
|
276
478
|
|
|
277
479
|
const offset = params.offset ?? 1;
|
|
278
|
-
const limit = params.limit ??
|
|
480
|
+
const limit = params.limit ?? totalLines;
|
|
279
481
|
const startIdx = offset - 1;
|
|
280
482
|
|
|
281
483
|
// Offset past the end of file: return a clean error instead of an
|
|
282
|
-
// empty slice with an inverted
|
|
484
|
+
// empty slice with an inverted header and bogus continuation hint.
|
|
283
485
|
if (startIdx >= totalLines) {
|
|
284
486
|
return {
|
|
285
487
|
content: [
|
|
@@ -292,18 +494,46 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
292
494
|
isError: true,
|
|
293
495
|
};
|
|
294
496
|
}
|
|
497
|
+
const config = deps.getConfig?.(ctx.cwd);
|
|
498
|
+
const defaultAnchors = config?.editing?.default_anchors ?? true;
|
|
499
|
+
const configuredReadMode = readMode ?? config?.editing?.read_mode ?? "auto";
|
|
500
|
+
const useAnchors = shouldUseAnchors(params, benchmarkMethod, configuredReadMode, defaultAnchors, false);
|
|
295
501
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
502
|
+
// Guardrail against excessive anchored line bloat
|
|
503
|
+
const MAX_ANCHOR_LINES = 100;
|
|
504
|
+
let effectiveLimit = limit;
|
|
505
|
+
let anchorNotice = "";
|
|
506
|
+
if (useAnchors && effectiveLimit > MAX_ANCHOR_LINES) {
|
|
507
|
+
effectiveLimit = MAX_ANCHOR_LINES;
|
|
508
|
+
anchorNotice = `\n[Notice: Anchored read capped to 100 lines to prevent token bloat. For broader inspection, use plain read without 'anchors'.]`;
|
|
509
|
+
}
|
|
510
|
+
const endIdx = Math.min(totalLines, startIdx + effectiveLimit);
|
|
300
511
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
512
|
+
const numberWidth = String(totalLines).length;
|
|
513
|
+
const formatLine = (index: number) => formatReadLine(lines, index, useAnchors, numberWidth, benchmarkMethod);
|
|
514
|
+
const firstLineBytes = Buffer.byteLength(formatLine(startIdx), "utf8");
|
|
515
|
+
const oversizedFirstLine = firstLineBytes > MAX_READ_BYTES;
|
|
516
|
+
const visibleIndexes = oversizedFirstLine ? [] : selectReadLineIndexes(lines, startIdx, endIdx, formatLine);
|
|
517
|
+
const hiddenLines = endIdx - startIdx - visibleIndexes.length;
|
|
518
|
+
const hasMore = hiddenLines > 0 || endIdx < totalLines;
|
|
519
|
+
const outputLines = oversizedFirstLine
|
|
520
|
+
? [`[Line ${startIdx + 1} is ${firstLineBytes} bytes, exceeds ${MAX_READ_BYTES} byte limit. Use bash to inspect this line in chunks.]`]
|
|
521
|
+
: visibleIndexes.map(formatLine);
|
|
522
|
+
if (hiddenLines > 0 && !oversizedFirstLine) {
|
|
523
|
+
outputLines.push(`[...] ${hiddenLines} lines omitted [...]. Use offset=${startIdx + visibleIndexes.length + 1} to continue.`);
|
|
524
|
+
}
|
|
525
|
+
if (anchorNotice) {
|
|
526
|
+
outputLines.push(anchorNotice);
|
|
527
|
+
}
|
|
528
|
+
const isTruncated = oversizedFirstLine || hasMore || startIdx > 0;
|
|
529
|
+
if (isTruncated && hasMore && !oversizedFirstLine && hiddenLines === 0) {
|
|
530
|
+
const lastShown = visibleIndexes[visibleIndexes.length - 1]! + 1;
|
|
531
|
+
outputLines.push(`\n[Showing ${visibleIndexes.length} of ${totalLines} lines. Use offset=${lastShown + 1} to continue.]`);
|
|
304
532
|
}
|
|
533
|
+
const coverageRanges = lineRanges(visibleIndexes);
|
|
305
534
|
|
|
306
|
-
// Record only
|
|
535
|
+
// Record only the lines actually exposed to the model. The full content
|
|
536
|
+
// still supplies the freshness fingerprint without authorizing hidden lines.
|
|
307
537
|
globalEpistemicGuard.recordFileRead(
|
|
308
538
|
resolvedPath,
|
|
309
539
|
deps.getSessionId(ctx),
|
|
@@ -311,8 +541,8 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
311
541
|
content,
|
|
312
542
|
{
|
|
313
543
|
coverage: {
|
|
314
|
-
complete: !isTruncated,
|
|
315
|
-
ranges:
|
|
544
|
+
complete: !isTruncated && startIdx === 0 && endIdx === totalLines,
|
|
545
|
+
ranges: coverageRanges,
|
|
316
546
|
totalLines,
|
|
317
547
|
},
|
|
318
548
|
provenance: "read",
|
|
@@ -320,8 +550,8 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
320
550
|
);
|
|
321
551
|
|
|
322
552
|
return {
|
|
323
|
-
content: [{ type: "text", text:
|
|
324
|
-
details: { totalLines, offset, limit, shownLines:
|
|
553
|
+
content: [{ type: "text", text: outputLines.join("\n") }],
|
|
554
|
+
details: { totalLines, offset, limit, shownLines: visibleIndexes.length, truncated: isTruncated },
|
|
325
555
|
};
|
|
326
556
|
} catch (err: any) {
|
|
327
557
|
return {
|
|
@@ -331,7 +561,14 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
331
561
|
}
|
|
332
562
|
},
|
|
333
563
|
renderCall(args: any, theme: any, context: any) {
|
|
334
|
-
const
|
|
564
|
+
const targetPaths = Array.isArray(args?.paths) ? args.paths : (Array.isArray(args?.path) ? args.path : []);
|
|
565
|
+
if (targetPaths.length > 1) {
|
|
566
|
+
const pathsSummary = targetPaths.map((p: string) => path.relative(context.cwd, p) || p).join(", ");
|
|
567
|
+
return makeOutputText(
|
|
568
|
+
`${theme.fg("toolTitle", theme.bold("read"))} [${theme.fg("accent", pathsSummary)}]`,
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
const rawPath = args?.path || (Array.isArray(args?.paths) ? args.paths[0] : "") || "";
|
|
335
572
|
const relPath = rawPath
|
|
336
573
|
? path.relative(context.cwd, rawPath) || rawPath
|
|
337
574
|
: "";
|
package/src/ui/footer.ts
CHANGED
|
@@ -119,20 +119,22 @@ export function formatSearchEngineTag(
|
|
|
119
119
|
eff = searchIndexOrProfile.getProfile();
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
let label = "retrieval:bm25";
|
|
123
122
|
if (eff === "lean") {
|
|
124
|
-
label = "retrieval:bm25";
|
|
125
|
-
|
|
123
|
+
const label = "retrieval:bm25";
|
|
124
|
+
const text = withColor ? Pastel.searchLean(label) : label;
|
|
125
|
+
return `🌿 ${text}`;
|
|
126
126
|
}
|
|
127
127
|
if (eff === "hybrid") {
|
|
128
|
-
label = "retrieval:hybrid-256d";
|
|
129
|
-
|
|
128
|
+
const label = "retrieval:hybrid-256d";
|
|
129
|
+
const text = withColor ? Pastel.searchHybrid(label) : label;
|
|
130
|
+
return `◈ ${text}`;
|
|
130
131
|
}
|
|
131
132
|
if (eff === "full") {
|
|
132
|
-
label = "retrieval:dense-768d";
|
|
133
|
-
|
|
133
|
+
const label = "retrieval:dense-768d";
|
|
134
|
+
const text = withColor ? Pastel.searchFull(label) : label;
|
|
135
|
+
return `🧠 ${text}`;
|
|
134
136
|
}
|
|
135
|
-
label = `retrieval:${eff}`;
|
|
137
|
+
const label = `retrieval:${eff}`;
|
|
136
138
|
return withColor ? Pastel.searchOff(label) : label;
|
|
137
139
|
}
|
|
138
140
|
|
|
@@ -162,11 +164,9 @@ export function renderFooter(
|
|
|
162
164
|
}
|
|
163
165
|
parts.push(workspaceFormatted);
|
|
164
166
|
|
|
165
|
-
//
|
|
166
|
-
const searchTag = formatSearchEngineTag(searchIndex, true);
|
|
167
|
-
parts.push(searchTag);
|
|
167
|
+
// (Retrieval engine status is rendered on the extension status line alongside Ponytail)
|
|
168
168
|
|
|
169
|
-
//
|
|
169
|
+
// 2. Context Window Usage
|
|
170
170
|
const contextUsage = ctx.getContextUsage?.();
|
|
171
171
|
const model = ctx.model;
|
|
172
172
|
const contextWindow = contextUsage?.contextWindow ?? model?.contextWindow ?? 0;
|
|
@@ -272,16 +272,42 @@ export function renderFooter(
|
|
|
272
272
|
|
|
273
273
|
const lines: string[] = [mainLine];
|
|
274
274
|
|
|
275
|
-
//
|
|
275
|
+
// Extension statuses on Line 2 (alongside external extensions like Ponytail)
|
|
276
276
|
const extStatuses = footerData?.getExtensionStatuses?.();
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
277
|
+
const extEntries: Array<[string, string]> = extStatuses
|
|
278
|
+
? Array.from(extStatuses.entries()).filter(([, text]) => Boolean(text))
|
|
279
|
+
: [];
|
|
280
|
+
|
|
281
|
+
// If retrieval is not yet recorded in extension statuses but searchIndex is provided, include it
|
|
282
|
+
if (searchIndex && !extEntries.some(([key]) => key === "retrieval")) {
|
|
283
|
+
const eff =
|
|
284
|
+
typeof searchIndex.getEffectiveProfile === "function"
|
|
285
|
+
? searchIndex.getEffectiveProfile()
|
|
286
|
+
: typeof searchIndex === "string"
|
|
287
|
+
? searchIndex
|
|
288
|
+
: "lean";
|
|
289
|
+
if (eff !== "off") {
|
|
290
|
+
const tag = formatSearchEngineTag(searchIndex, true);
|
|
291
|
+
extEntries.push(["retrieval", tag]);
|
|
283
292
|
}
|
|
284
293
|
}
|
|
285
294
|
|
|
295
|
+
if (extEntries.length > 0) {
|
|
296
|
+
// Put retrieval first, then sort other extensions alphabetically
|
|
297
|
+
extEntries.sort(([a], [b]) => {
|
|
298
|
+
if (a === "retrieval") return -1;
|
|
299
|
+
if (b === "retrieval") return 1;
|
|
300
|
+
return a.localeCompare(b);
|
|
301
|
+
});
|
|
302
|
+
const statusTexts = extEntries.map(([, text]) => text);
|
|
303
|
+
lines.push(
|
|
304
|
+
truncateToWidth(
|
|
305
|
+
statusTexts.join(` ${Pastel.bullet} `),
|
|
306
|
+
width,
|
|
307
|
+
theme.fg("dim", "..."),
|
|
308
|
+
),
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
286
312
|
return lines;
|
|
287
313
|
}
|