@floydous/pi-agent-kernel 0.4.3 → 0.5.0
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 +1 -7
- package/CHANGELOG.md +36 -0
- package/README.md +6 -53
- package/config.example.toml +0 -8
- package/docs/README.md +1 -2
- package/docs/architecture.md +2 -3
- package/docs/configuration.md +10 -9
- package/docs/editing-and-verification.md +1 -3
- package/docs/retrieval.md +6 -11
- package/docs/testing.md +3 -3
- package/package.json +4 -2
- package/src/config/agent_kernel_command.ts +8 -39
- package/src/config/kernel_config.ts +30 -68
- package/src/config/toml.ts +6 -1
- package/src/editing/auto_heal.ts +1 -1
- package/src/editing/patch.ts +27 -16
- package/src/editing/post_edit_verification.ts +12 -10
- package/src/editing/smart_anchor.ts +7 -5
- package/src/editing/syntax-verify.ts +9 -5
- package/src/index.ts +15 -257
- package/src/retrieval/search_bm25.ts +4 -2
- package/src/retrieval/search_chunker.ts +1 -1
- package/src/retrieval/search_config.ts +4 -6
- package/src/retrieval/search_embedder.ts +3 -2
- package/src/retrieval/search_index.ts +82 -35
- package/src/retrieval/search_modal.ts +7 -8
- package/src/retrieval/{repomap.ts → tag_extractor.ts} +5 -292
- package/src/retrieval/tree_sitter_engine.ts +70 -34
- package/src/retrieval/workspace_walker.ts +6 -2
- package/src/safety/atomic_write.ts +1 -1
- package/src/safety/epistemic_guard.ts +105 -31
- package/src/safety/output_clamper.ts +14 -8
- package/src/tools/code_search_output.ts +2 -1
- package/src/tools/code_search_tool.ts +2 -5
- package/src/tools/context.ts +0 -14
- package/src/tools/edit_tool.ts +82 -115
- package/src/tools/read_tool.ts +42 -178
- package/src/ui/footer.ts +7 -7
- package/docs/lsp.md +0 -31
- package/src/lsp/adapters/base.ts +0 -42
- package/src/lsp/adapters/index.ts +0 -21
- package/src/lsp/adapters/python.ts +0 -37
- package/src/lsp/adapters/rust.ts +0 -35
- package/src/lsp/adapters/typescript.ts +0 -40
- package/src/lsp/index.ts +0 -13
- package/src/lsp/lsp_client.ts +0 -765
- package/src/lsp/lsp_detector.ts +0 -52
- package/src/lsp/lsp_formatter.ts +0 -323
- package/src/lsp/lsp_installer.ts +0 -320
- package/src/lsp/lsp_manager.ts +0 -202
- package/src/lsp/lsp_modal.ts +0 -675
- package/src/lsp/lsp_registry.ts +0 -600
- package/src/lsp/lsp_types.ts +0 -143
- package/src/retrieval/ast_search.ts +0 -999
- package/src/retrieval/symbol_reader.ts +0 -228
- package/src/tools/ast_search_formatter.ts +0 -161
- package/src/tools/ast_search_tool.ts +0 -146
- package/src/tools/lsp_tool.ts +0 -794
- package/src/tools/repo_map_tool.ts +0 -56
package/src/tools/edit_tool.ts
CHANGED
|
@@ -3,12 +3,10 @@ import { Type } from "typebox";
|
|
|
3
3
|
import { Text, makeOutputText } from "../ui/tui_utils";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
|
-
import { kernelDebug } from "../safety/kernel_debug";
|
|
7
6
|
import { writeFileSyncAtomic } from "../safety/atomic_write";
|
|
8
7
|
import {
|
|
9
8
|
applySurgicalPatch,
|
|
10
9
|
applyMultiBlockPatch,
|
|
11
|
-
findSurgicalPatchTargetRange,
|
|
12
10
|
preflightSurgicalPatchBlock,
|
|
13
11
|
} from "../editing/patch";
|
|
14
12
|
import {
|
|
@@ -22,7 +20,6 @@ import {
|
|
|
22
20
|
renderPostEditVerification,
|
|
23
21
|
verifyEditedFile,
|
|
24
22
|
} from "../editing/post_edit_verification";
|
|
25
|
-
import { LspManager } from "../lsp";
|
|
26
23
|
import {
|
|
27
24
|
globalEpistemicGuard,
|
|
28
25
|
resolveUserPath,
|
|
@@ -40,7 +37,7 @@ export async function withFileMutationLocks<T>(
|
|
|
40
37
|
operation: () => Promise<T>,
|
|
41
38
|
): Promise<T> {
|
|
42
39
|
const { withFileMutationQueue } = await import("@earendil-works/pi-coding-agent");
|
|
43
|
-
const keys = [...new Set(filePaths.map(mutationLockKey))].sort();
|
|
40
|
+
const keys = [...new Set(filePaths.map(mutationLockKey))].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
44
41
|
const run = (index: number): Promise<T> =>
|
|
45
42
|
index >= keys.length
|
|
46
43
|
? operation()
|
|
@@ -297,38 +294,7 @@ async function applyPreparedEdit(
|
|
|
297
294
|
|
|
298
295
|
await deps.invalidateSearchFile?.(ctx.cwd, resolvedPath);
|
|
299
296
|
|
|
300
|
-
const
|
|
301
|
-
if (readyLsp && readyLsp.getState() === "ready") {
|
|
302
|
-
try {
|
|
303
|
-
await readyLsp.changeDocument(resolvedPath, diskContent);
|
|
304
|
-
await readyLsp.saveDocument(resolvedPath, diskContent);
|
|
305
|
-
} catch (err) {
|
|
306
|
-
kernelDebug(err);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
const verification = await verifyEditedFile(
|
|
311
|
-
resolvedPath,
|
|
312
|
-
readyLsp
|
|
313
|
-
? async () => {
|
|
314
|
-
const result = await readyLsp.getDiagnosticsResult(resolvedPath);
|
|
315
|
-
return {
|
|
316
|
-
state: result.status,
|
|
317
|
-
findings: result.diagnostics.map((finding) => ({
|
|
318
|
-
line: finding.range.start.line + 1,
|
|
319
|
-
column: finding.range.start.character + 1,
|
|
320
|
-
message: finding.message,
|
|
321
|
-
severity:
|
|
322
|
-
finding.severity === 1
|
|
323
|
-
? ("error" as const)
|
|
324
|
-
: finding.severity === 2
|
|
325
|
-
? ("warning" as const)
|
|
326
|
-
: ("info" as const),
|
|
327
|
-
})),
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
: undefined,
|
|
331
|
-
);
|
|
297
|
+
const verification = await verifyEditedFile(resolvedPath);
|
|
332
298
|
|
|
333
299
|
const statusText = renderPostEditVerification(verification, undefined, relPath);
|
|
334
300
|
return {
|
|
@@ -344,84 +310,94 @@ async function applyPreparedEdit(
|
|
|
344
310
|
export function registerEditTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
345
311
|
// 7. Tool: `edit` (Unified Surgical Diff, Smart Anchor, & Multi-Block Editor - Replaces stock edit tool)
|
|
346
312
|
const benchmarkMethod = process.env.PI_EDIT_METHOD?.toLowerCase();
|
|
347
|
-
|
|
348
|
-
|
|
313
|
+
let editToolParameters: any;
|
|
314
|
+
let editToolDescription =
|
|
315
|
+
"Edit code with search/replace, multi-block 'edits', or multi-file 'files'. Valid after read or exact rg search.";
|
|
316
|
+
|
|
317
|
+
switch (benchmarkMethod) {
|
|
318
|
+
case "line-range":
|
|
319
|
+
editToolParameters = Type.Object({
|
|
349
320
|
path: Type.String({ description: "File path to edit" }),
|
|
350
321
|
start_line: Type.Number({ description: "First 1-based line to replace" }),
|
|
351
322
|
end_line: Type.Optional(Type.Number({ description: "Last 1-based line to replace, inclusive" })),
|
|
352
323
|
lines: Type.Array(Type.String(), { description: "Replacement lines (empty to delete)" }),
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
})
|
|
361
|
-
:
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
:
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
324
|
+
});
|
|
325
|
+
editToolDescription = "Edit code with numeric line ranges only: start_line, optional end_line, and replacement lines.";
|
|
326
|
+
break;
|
|
327
|
+
case "hash-anchor":
|
|
328
|
+
editToolParameters = Type.Object({
|
|
329
|
+
path: Type.String({ description: "File path to edit" }),
|
|
330
|
+
pos: Type.String({ description: "Start anchor copied from read output, e.g. '288#ZH'" }),
|
|
331
|
+
end: Type.Optional(Type.String({ description: "End anchor copied from read output, e.g. '294#VN'" })),
|
|
332
|
+
lines: Type.Array(Type.String(), { description: "Replacement lines (empty to delete)" }),
|
|
333
|
+
});
|
|
334
|
+
editToolDescription = "Edit code with LINE#HASH anchors only, copied from read output.";
|
|
335
|
+
break;
|
|
336
|
+
case "search-replace":
|
|
337
|
+
editToolParameters = Type.Object({
|
|
338
|
+
path: Type.String({ description: "File path to edit" }),
|
|
339
|
+
search: Type.String({ description: "Unique exact source block to replace" }),
|
|
340
|
+
replace: Type.String({ description: "Replacement source block" }),
|
|
341
|
+
});
|
|
342
|
+
editToolDescription = "Edit code with a unique exact search block and replacement block only.";
|
|
343
|
+
break;
|
|
344
|
+
case "adaptive":
|
|
345
|
+
editToolParameters = Type.Object({
|
|
346
|
+
path: Type.String({ description: "File path to edit" }),
|
|
347
|
+
search: Type.Optional(Type.String({ description: "Unique exact source block to replace" })),
|
|
348
|
+
replace: Type.Optional(Type.String({ description: "Replacement source block" })),
|
|
349
|
+
start_line: Type.Optional(Type.Number({ description: "First 1-based line to replace" })),
|
|
350
|
+
end_line: Type.Optional(Type.Number({ description: "Last 1-based line to replace, inclusive" })),
|
|
351
|
+
pos: Type.Optional(Type.String({ description: "LINE#HASH anchor copied from read output" })),
|
|
352
|
+
end: Type.Optional(Type.String({ description: "Ending LINE#HASH anchor" })),
|
|
353
|
+
lines: Type.Optional(Type.Array(Type.String(), { description: "Replacement lines (empty to delete)" })),
|
|
354
|
+
});
|
|
355
|
+
editToolDescription = "Edit code with search/replace or line range; use search first.";
|
|
356
|
+
break;
|
|
357
|
+
default:
|
|
358
|
+
editToolParameters = Type.Object(
|
|
359
|
+
{
|
|
360
|
+
path: Type.Optional(Type.String({ description: "Path to file to edit" })),
|
|
361
|
+
search: Type.Optional(Type.String({ description: "Exact block to replace" })),
|
|
362
|
+
replace: Type.Optional(Type.String({ description: "Replacement text" })),
|
|
363
|
+
line_hint: Type.Optional(Type.Number({ description: "Line hint for disambiguation" })),
|
|
364
|
+
edits: Type.Optional(
|
|
365
|
+
Type.Array(
|
|
366
|
+
Type.Object(
|
|
367
|
+
{
|
|
368
|
+
search: Type.Optional(Type.String()),
|
|
369
|
+
replace: Type.Optional(Type.String()),
|
|
370
|
+
line_hint: Type.Optional(Type.Number()),
|
|
371
|
+
},
|
|
372
|
+
{ additionalProperties: true },
|
|
395
373
|
),
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
),
|
|
408
|
-
|
|
409
|
-
|
|
374
|
+
{ description: "Targeted replacements" },
|
|
375
|
+
),
|
|
376
|
+
),
|
|
377
|
+
files: Type.Optional(
|
|
378
|
+
Type.Array(
|
|
379
|
+
Type.Object(
|
|
380
|
+
{
|
|
381
|
+
path: Type.String(),
|
|
382
|
+
search: Type.Optional(Type.String()),
|
|
383
|
+
replace: Type.Optional(Type.String()),
|
|
384
|
+
line_hint: Type.Optional(Type.Number()),
|
|
385
|
+
edits: Type.Optional(Type.Array(Type.Any())),
|
|
386
|
+
},
|
|
387
|
+
{ additionalProperties: true },
|
|
410
388
|
),
|
|
411
|
-
|
|
389
|
+
{ description: "Multi-file edits" },
|
|
390
|
+
),
|
|
391
|
+
),
|
|
392
|
+
},
|
|
393
|
+
{ additionalProperties: true },
|
|
394
|
+
);
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
412
397
|
const editToolDefinition: any = {
|
|
413
398
|
name: "edit",
|
|
414
399
|
label: "Code Editor",
|
|
415
|
-
description:
|
|
416
|
-
benchmarkMethod === "line-range"
|
|
417
|
-
? "Edit code with numeric line ranges only: start_line, optional end_line, and replacement lines."
|
|
418
|
-
: benchmarkMethod === "hash-anchor"
|
|
419
|
-
? "Edit code with LINE#HASH anchors only, copied from read output."
|
|
420
|
-
: benchmarkMethod === "search-replace"
|
|
421
|
-
? "Edit code with a unique exact search block and replacement block only."
|
|
422
|
-
: benchmarkMethod === "adaptive"
|
|
423
|
-
? "Edit code with search/replace or line range; use search first."
|
|
424
|
-
: "Edit code with search/replace, multi-block 'edits', or multi-file 'files'. Valid after read or exact rg search.",
|
|
400
|
+
description: editToolDescription,
|
|
425
401
|
promptSnippet: "Edit code using search/replace (optional line_hint), multi-block 'edits', or multi-file 'files'",
|
|
426
402
|
renderShell: "default",
|
|
427
403
|
parameters: editToolParameters,
|
|
@@ -564,15 +540,6 @@ export function registerEditTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
564
540
|
} catch (indexErr) {
|
|
565
541
|
rollbackFailures.push(`${path.basename(mutated)} index: ${indexErr instanceof Error ? indexErr.message : String(indexErr)}`);
|
|
566
542
|
}
|
|
567
|
-
try {
|
|
568
|
-
const client = LspManager.getInstance().getReadyClientForFile(mutated, ctx.cwd);
|
|
569
|
-
if (client?.getState() === "ready") {
|
|
570
|
-
await client.changeDocument(mutated, backup);
|
|
571
|
-
await client.saveDocument(mutated, backup);
|
|
572
|
-
}
|
|
573
|
-
} catch (lspErr) {
|
|
574
|
-
rollbackFailures.push(`${path.basename(mutated)} LSP: ${lspErr instanceof Error ? lspErr.message : String(lspErr)}`);
|
|
575
|
-
}
|
|
576
543
|
}
|
|
577
544
|
if (rollbackFailures.length > 0) {
|
|
578
545
|
return {
|
|
@@ -582,7 +549,7 @@ export function registerEditTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
582
549
|
};
|
|
583
550
|
}
|
|
584
551
|
return {
|
|
585
|
-
content: [{ type: "text", text: `[EDIT FAILED - ROLLED BACK] Multi-file edit aborted and all file/index/
|
|
552
|
+
content: [{ type: "text", text: `[EDIT FAILED - ROLLED BACK] Multi-file edit aborted and all file/index/guard state restored: ${failureReason}` }],
|
|
586
553
|
details: { rolledBack: true },
|
|
587
554
|
isError: true,
|
|
588
555
|
};
|
package/src/tools/read_tool.ts
CHANGED
|
@@ -3,18 +3,12 @@ import { Type } from "typebox";
|
|
|
3
3
|
import { Text, makeOutputText } from "../ui/tui_utils";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
|
-
import {
|
|
7
|
-
import { findSymbolSuggestions } from "../retrieval/ast_search";
|
|
8
|
-
import { computeLineHash, formatSmartAnchorLines } from "../editing/smart_anchor";
|
|
6
|
+
import { computeLineHash } from "../editing/smart_anchor";
|
|
9
7
|
import {
|
|
10
8
|
globalEpistemicGuard,
|
|
11
9
|
resolveUserPath,
|
|
12
10
|
} from "../safety/epistemic_guard";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
function countFileLines(filePath: string): number {
|
|
16
|
-
return fs.readFileSync(filePath, "utf8").split("\n").length;
|
|
17
|
-
}
|
|
11
|
+
import type { SessionDeps } from "./context";
|
|
18
12
|
|
|
19
13
|
const MAX_READ_LINES = 2_000;
|
|
20
14
|
const MAX_READ_BYTES = 50 * 1024;
|
|
@@ -58,7 +52,7 @@ function formatReadLine(
|
|
|
58
52
|
numberWidth: number,
|
|
59
53
|
benchmarkMethod: string | undefined,
|
|
60
54
|
): string {
|
|
61
|
-
const line = lines[index]
|
|
55
|
+
const line = lines[index] ?? "";
|
|
62
56
|
if (useAnchors) {
|
|
63
57
|
return `${String(index + 1).padStart(numberWidth, " ")}#${computeLineHash(lines, index)}│${line}`;
|
|
64
58
|
}
|
|
@@ -69,7 +63,7 @@ function formatReadLine(
|
|
|
69
63
|
}
|
|
70
64
|
|
|
71
65
|
function selectReadLineIndexes(
|
|
72
|
-
|
|
66
|
+
_lines: readonly string[],
|
|
73
67
|
startIdx: number,
|
|
74
68
|
endIdx: number,
|
|
75
69
|
formatLine: (index: number) => string,
|
|
@@ -99,52 +93,50 @@ function lineRanges(indexes: readonly number[]): Array<{ startLine: number; endL
|
|
|
99
93
|
|
|
100
94
|
/** Extracted from index.ts — registers the `read` tool. */
|
|
101
95
|
export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
102
|
-
// 6. Tool: `read` (
|
|
96
|
+
// 6. Tool: `read` (Bounded File Reader with Line-Windowing - Replaces stock read tool)
|
|
103
97
|
const editMethod = process.env.PI_EDIT_METHOD?.toLowerCase();
|
|
104
98
|
const benchmarkMethod = ["line-range", "search-replace", "hash-anchor", "adaptive"].includes(editMethod || "") ? editMethod : undefined;
|
|
105
99
|
const readMode = process.env.PI_READ_MODE?.toLowerCase();
|
|
100
|
+
let readToolDescription =
|
|
101
|
+
"Read file contents with 50KB / 2,000-line caps. Supports bounded line-range inspection via 'offset' and 'limit', or batch inspection across multiple files via 'paths'.";
|
|
102
|
+
switch (benchmarkMethod) {
|
|
103
|
+
case "line-range":
|
|
104
|
+
readToolDescription = "Read source with line numbers for numeric line-range edits.";
|
|
105
|
+
break;
|
|
106
|
+
case "search-replace":
|
|
107
|
+
readToolDescription = "Read source text for exact search/replace edits.";
|
|
108
|
+
break;
|
|
109
|
+
case "adaptive":
|
|
110
|
+
readToolDescription = "Read source with line numbers. Prefer unique search/replace; use line ranges when needed.";
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
106
115
|
const readToolDefinition: any = {
|
|
107
116
|
name: "read",
|
|
108
|
-
label: "Read File
|
|
109
|
-
description:
|
|
110
|
-
|
|
111
|
-
? "Read source with line numbers for numeric line-range edits."
|
|
112
|
-
: benchmarkMethod === "search-replace"
|
|
113
|
-
? "Read source text for exact search/replace edits."
|
|
114
|
-
: benchmarkMethod === "adaptive"
|
|
115
|
-
? "Read source with line numbers. Prefer unique search/replace; use line ranges when needed."
|
|
116
|
-
: "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.",
|
|
117
|
-
promptSnippet: "Read file contents, inspect line ranges, extract symbols, or read multiple files via 'paths'",
|
|
117
|
+
label: "Read File",
|
|
118
|
+
description: readToolDescription,
|
|
119
|
+
promptSnippet: "Read file contents, inspect line ranges, or read multiple files via 'paths'",
|
|
118
120
|
renderShell: "default",
|
|
119
121
|
parameters: Type.Object({
|
|
120
122
|
path: Type.Optional(
|
|
121
123
|
Type.String({
|
|
122
|
-
description: "
|
|
124
|
+
description: "Workspace-relative or absolute file path to inspect. For multiple files, use 'paths'",
|
|
123
125
|
}),
|
|
124
126
|
),
|
|
125
127
|
paths: Type.Optional(
|
|
126
128
|
Type.Array(Type.String(), {
|
|
127
|
-
description: "
|
|
128
|
-
}),
|
|
129
|
-
),
|
|
130
|
-
symbol: Type.Optional(
|
|
131
|
-
Type.String({
|
|
132
|
-
description: "Function, class, or type to extract",
|
|
129
|
+
description: "Array of file paths to read in a single batch (plain text only, bounded per file)",
|
|
133
130
|
}),
|
|
134
131
|
),
|
|
135
132
|
offset: Type.Optional(
|
|
136
133
|
Type.Number({
|
|
137
|
-
description: "
|
|
134
|
+
description: "1-based starting line number for windowed reads (best when examining code around an exact line coordinate from grep or test failures)",
|
|
138
135
|
}),
|
|
139
136
|
),
|
|
140
137
|
limit: Type.Optional(
|
|
141
138
|
Type.Number({
|
|
142
|
-
description: "Maximum lines to read",
|
|
143
|
-
}),
|
|
144
|
-
),
|
|
145
|
-
surrounding_lines: Type.Optional(
|
|
146
|
-
Type.Number({
|
|
147
|
-
description: "Extra surrounding context lines for symbol",
|
|
139
|
+
description: "Maximum number of lines to read starting from 'offset' (default: 250 for unconstrained reads; keep <= 60 for narrow inspection)",
|
|
148
140
|
}),
|
|
149
141
|
),
|
|
150
142
|
anchors: Type.Optional(
|
|
@@ -162,9 +154,9 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
162
154
|
_toolCallId: string,
|
|
163
155
|
params: any,
|
|
164
156
|
_signal: any,
|
|
165
|
-
|
|
157
|
+
_onUpdate: any,
|
|
166
158
|
ctx: any,
|
|
167
|
-
)
|
|
159
|
+
) {
|
|
168
160
|
let targetPaths: string[] = [];
|
|
169
161
|
if (params && typeof params === "object") {
|
|
170
162
|
if (Array.isArray(params.paths)) {
|
|
@@ -285,136 +277,7 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
285
277
|
};
|
|
286
278
|
}
|
|
287
279
|
|
|
288
|
-
|
|
289
|
-
if (readLimitError) {
|
|
290
|
-
return {
|
|
291
|
-
content: [{ type: "text", text: `[READ ERROR] ${readLimitError}: ${params.path}` }],
|
|
292
|
-
details: { error: "read_limit", maxBytes: MAX_READ_FILE_BYTES },
|
|
293
|
-
isError: true,
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Mode 1: Targeted AST symbol extraction
|
|
298
|
-
if (params.symbol && params.symbol.trim()) {
|
|
299
|
-
const sym = params.symbol.trim();
|
|
300
|
-
onUpdate?.({
|
|
301
|
-
content: [
|
|
302
|
-
{
|
|
303
|
-
type: "text",
|
|
304
|
-
text: `Extracting symbol '${sym}' from ${params.path}...`,
|
|
305
|
-
},
|
|
306
|
-
],
|
|
307
|
-
});
|
|
308
|
-
let symbolSnapshot: string;
|
|
309
|
-
try {
|
|
310
|
-
symbolSnapshot = fs.readFileSync(resolvedPath, "utf8");
|
|
311
|
-
} catch (error: any) {
|
|
312
|
-
return {
|
|
313
|
-
content: [
|
|
314
|
-
{ type: "text", text: `[READ ERROR] Unable to read ${params.path}: ${error.message}` },
|
|
315
|
-
],
|
|
316
|
-
isError: true,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
const res = extractSymbolContent(
|
|
320
|
-
resolvedPath,
|
|
321
|
-
sym,
|
|
322
|
-
{ surroundingLines: params.surrounding_lines },
|
|
323
|
-
symbolSnapshot,
|
|
324
|
-
);
|
|
325
|
-
|
|
326
|
-
if (!res.found) {
|
|
327
|
-
const suggestions = findSymbolSuggestions(
|
|
328
|
-
ctx.cwd,
|
|
329
|
-
resolvedPath,
|
|
330
|
-
sym,
|
|
331
|
-
);
|
|
332
|
-
let errorText: string;
|
|
333
|
-
if (res.error) {
|
|
334
|
-
errorText = res.error;
|
|
335
|
-
} else if (suggestions.length > 0) {
|
|
336
|
-
const formattedSuggestions = suggestions
|
|
337
|
-
.map(
|
|
338
|
-
(s) =>
|
|
339
|
-
`- ${s.name} (${s.filePath}:${s.line}) [${s.kind}] ${s.signature}`,
|
|
340
|
-
)
|
|
341
|
-
.join("\n");
|
|
342
|
-
errorText = `Symbol '${sym}' not found in ${params.path}.\nDid you mean:\n${formattedSuggestions}`;
|
|
343
|
-
} else {
|
|
344
|
-
errorText = `Symbol '${sym}' not found in ${params.path}. ` +
|
|
345
|
-
(speculativeToolsEnabled(deps.getConfig, ctx.cwd)
|
|
346
|
-
? `Use 'ast_search' to locate symbols or 'rg' in bash to search text.`
|
|
347
|
-
: `Use 'code_search' to locate code or 'rg' in bash to search text.`);
|
|
348
|
-
}
|
|
349
|
-
return {
|
|
350
|
-
content: [{ type: "text", text: errorText }],
|
|
351
|
-
details: {
|
|
352
|
-
error: "symbol_not_found",
|
|
353
|
-
query: sym,
|
|
354
|
-
candidates: suggestions.map((s) => ({
|
|
355
|
-
name: s.name,
|
|
356
|
-
filePath: s.filePath,
|
|
357
|
-
line: s.line,
|
|
358
|
-
kind: s.kind,
|
|
359
|
-
})),
|
|
360
|
-
},
|
|
361
|
-
isError: true,
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Record the exact snapshot used for extraction only after a successful
|
|
366
|
-
// symbol result; failed extraction must not authorize a mutation.
|
|
367
|
-
globalEpistemicGuard.recordFileRead(
|
|
368
|
-
resolvedPath,
|
|
369
|
-
deps.getSessionId(ctx),
|
|
370
|
-
ctx.cwd,
|
|
371
|
-
symbolSnapshot,
|
|
372
|
-
{
|
|
373
|
-
coverage: {
|
|
374
|
-
complete: false,
|
|
375
|
-
ranges: res.symbols.map((symbol) => ({
|
|
376
|
-
startLine: symbol.startLine,
|
|
377
|
-
endLine: symbol.endLine,
|
|
378
|
-
})),
|
|
379
|
-
totalLines: countFileLines(resolvedPath),
|
|
380
|
-
},
|
|
381
|
-
provenance: "symbol",
|
|
382
|
-
query: sym,
|
|
383
|
-
},
|
|
384
|
-
);
|
|
385
|
-
|
|
386
|
-
const config = deps.getConfig?.(ctx.cwd);
|
|
387
|
-
const defaultAnchors = config?.editing?.default_anchors ?? true;
|
|
388
|
-
const configuredReadMode = readMode ?? config?.editing?.read_mode ?? "auto";
|
|
389
|
-
const useAnchors = shouldUseAnchors(params, benchmarkMethod, configuredReadMode, defaultAnchors, true);
|
|
390
|
-
|
|
391
|
-
const allFileLines = symbolSnapshot.split("\n");
|
|
392
|
-
const formatted = res.symbols
|
|
393
|
-
.map((s) => {
|
|
394
|
-
const header = `// ${(path.relative(ctx.cwd, s.filePath) || s.filePath).replace(/\\/g, "/")}:${s.startLine}-${s.endLine} [${s.kind}] ${s.name}`;
|
|
395
|
-
const body = useAnchors
|
|
396
|
-
? formatSmartAnchorLines(allFileLines, s.startLine, s.endLine)
|
|
397
|
-
: benchmarkMethod === "line-range"
|
|
398
|
-
? allFileLines.slice(s.startLine - 1, s.endLine).map((line, index) => `${String(s.startLine + index).padStart(String(s.endLine).length, " ")}│${line}`).join("\n")
|
|
399
|
-
: s.content;
|
|
400
|
-
return `${header}\n${body}`;
|
|
401
|
-
})
|
|
402
|
-
.join("\n\n");
|
|
403
|
-
|
|
404
|
-
return {
|
|
405
|
-
content: [{ type: "text", text: formatted }],
|
|
406
|
-
details: {
|
|
407
|
-
count: res.symbols.length,
|
|
408
|
-
symbols: res.symbols.map((s) => ({
|
|
409
|
-
name: s.name,
|
|
410
|
-
kind: s.kind,
|
|
411
|
-
lines: `${s.startLine}-${s.endLine}`,
|
|
412
|
-
})),
|
|
413
|
-
},
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Mode 2: Standard file reading
|
|
280
|
+
// Single file read
|
|
418
281
|
try {
|
|
419
282
|
const readLimitError = validateReadableFile(resolvedPath);
|
|
420
283
|
if (readLimitError) {
|
|
@@ -568,8 +431,11 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
568
431
|
}
|
|
569
432
|
const isTruncated = oversizedFirstLine || hasMore || startIdx > 0;
|
|
570
433
|
if (isTruncated && hasMore && !oversizedFirstLine && hiddenLines === 0) {
|
|
571
|
-
const
|
|
572
|
-
|
|
434
|
+
const lastIdx = visibleIndexes[visibleIndexes.length - 1];
|
|
435
|
+
if (lastIdx !== undefined) {
|
|
436
|
+
const lastShown = lastIdx + 1;
|
|
437
|
+
outputLines.push(`\n[Showing ${visibleIndexes.length} of ${totalLines} lines. Use offset=${lastShown + 1} to continue.]`);
|
|
438
|
+
}
|
|
573
439
|
}
|
|
574
440
|
const coverageRanges = lineRanges(visibleIndexes);
|
|
575
441
|
|
|
@@ -609,19 +475,17 @@ export function registerReadTool(pi: ExtensionAPI, deps: SessionDeps): void {
|
|
|
609
475
|
`${theme.fg("toolTitle", theme.bold("read"))} [${theme.fg("accent", pathsSummary)}]`,
|
|
610
476
|
);
|
|
611
477
|
}
|
|
612
|
-
const
|
|
478
|
+
const path0 = Array.isArray(args?.paths) ? args.paths[0] : "";
|
|
479
|
+
const rawPath = args?.path || path0 || "";
|
|
613
480
|
const relPath = rawPath
|
|
614
481
|
? (path.relative(context.cwd, rawPath) || rawPath).replace(/\\/g, "/")
|
|
615
482
|
: "";
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
483
|
+
let range = "";
|
|
484
|
+
if (args?.offset || args?.limit) {
|
|
485
|
+
const off = args.offset ?? 1;
|
|
486
|
+
const lim = args.limit ? `-${off + args.limit - 1}` : "";
|
|
487
|
+
range = `:${off}${lim}`;
|
|
620
488
|
}
|
|
621
|
-
const range =
|
|
622
|
-
args?.offset || args?.limit
|
|
623
|
-
? `:${args.offset ?? 1}${args.limit ? `-${(args.offset ?? 1) + args.limit - 1}` : ""}`
|
|
624
|
-
: "";
|
|
625
489
|
return makeOutputText(
|
|
626
490
|
`${theme.fg("toolTitle", theme.bold("read"))} ${theme.fg("accent", relPath)}${theme.fg("warning", range)}`,
|
|
627
491
|
);
|
package/src/ui/footer.ts
CHANGED
|
@@ -63,7 +63,7 @@ export const Pastel = {
|
|
|
63
63
|
* Format numbers into compact token strings (e.g. 1.2k, 45k, 1.2M)
|
|
64
64
|
*/
|
|
65
65
|
export function formatTokens(count: number): string {
|
|
66
|
-
if (
|
|
66
|
+
if (!Number.isFinite(count) || count < 0) return "0";
|
|
67
67
|
if (count < 1000) return count.toString();
|
|
68
68
|
if (count < 10000) return `${(count / 1000).toFixed(1)}k`;
|
|
69
69
|
if (count < 1000000) return `${Math.round(count / 1000)}k`;
|
|
@@ -280,12 +280,12 @@ export function renderFooter(
|
|
|
280
280
|
|
|
281
281
|
// If retrieval is not yet recorded in extension statuses but searchIndex is provided, include it
|
|
282
282
|
if (searchIndex && !extEntries.some(([key]) => key === "retrieval")) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
283
|
+
let eff = "lean";
|
|
284
|
+
if (typeof searchIndex.getEffectiveProfile === "function") {
|
|
285
|
+
eff = searchIndex.getEffectiveProfile();
|
|
286
|
+
} else if (typeof searchIndex === "string") {
|
|
287
|
+
eff = searchIndex;
|
|
288
|
+
}
|
|
289
289
|
if (eff !== "off") {
|
|
290
290
|
const tag = formatSearchEngineTag(searchIndex, true);
|
|
291
291
|
extEntries.push(["retrieval", tag]);
|
package/docs/lsp.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Language Server Protocol
|
|
2
|
-
|
|
3
|
-
LSP support lives under `src/lsp/`. It provides language-server discovery,
|
|
4
|
-
client lifecycle management, formatting, diagnostics, and interactive controls.
|
|
5
|
-
|
|
6
|
-
## Components
|
|
7
|
-
|
|
8
|
-
- `lsp_registry.ts` describes supported language servers.
|
|
9
|
-
- `lsp_detector.ts` detects a file language and workspace root.
|
|
10
|
-
- `lsp_client.ts` manages JSON-RPC communication with a server process.
|
|
11
|
-
- `lsp_manager.ts` owns client reuse, lifecycle, and status reporting.
|
|
12
|
-
- `lsp_formatter.ts` renders diagnostics and navigation results for agents.
|
|
13
|
-
- `lsp_installer.ts` handles optional server installation.
|
|
14
|
-
- `lsp_modal.ts` provides the interactive server-control UI.
|
|
15
|
-
|
|
16
|
-
## Edit verification
|
|
17
|
-
|
|
18
|
-
Post-edit verification only reuses a client that is already ready for the
|
|
19
|
-
edited file. It does not start a new server solely to verify an edit. If a
|
|
20
|
-
client is unavailable, the result remains explicitly `not run`, `unavailable`,
|
|
21
|
-
or otherwise uncertain; it is never presented as `clean`.
|
|
22
|
-
|
|
23
|
-
The LSP tool can request diagnostics, definitions, references, hover details,
|
|
24
|
-
and document symbols. AST-based fallback behavior is kept in
|
|
25
|
-
`src/retrieval/ast_search.ts` for cases where no ready language server can
|
|
26
|
-
answer the request.
|
|
27
|
-
|
|
28
|
-
## Output formatting
|
|
29
|
-
|
|
30
|
-
- Diagnostics render in token-minimal format (`- [line:col] [SEV] [code] message (source)`) with no redundant `<path>` preamble. Clean files return strictly `<path> clean`.
|
|
31
|
-
- References support `exclude_tests` and `exclude_declaration` filters with bounded code window snippets (`windowAround`).
|
package/src/lsp/adapters/base.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { LspDiagnostic } from "../lsp_types";
|
|
2
|
-
|
|
3
|
-
export interface LspAdapter {
|
|
4
|
-
readonly languageKey: string;
|
|
5
|
-
getInitializationOptions?(rootDir: string): Record<string, any>;
|
|
6
|
-
getClientCapabilities?(): Record<string, any>;
|
|
7
|
-
handleServerRequest?(method: string, params: any, rootDir: string): any;
|
|
8
|
-
transformDiagnostics?(uri: string, diagnostics: LspDiagnostic[]): LspDiagnostic[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class BaseLspAdapter implements LspAdapter {
|
|
12
|
-
public readonly languageKey: string;
|
|
13
|
-
|
|
14
|
-
constructor(languageKey = "generic") {
|
|
15
|
-
this.languageKey = languageKey;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public getInitializationOptions(_rootDir: string): Record<string, any> {
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public getClientCapabilities(): Record<string, any> {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public handleServerRequest(method: string, params: any, rootDir: string): any {
|
|
27
|
-
switch (method) {
|
|
28
|
-
case "workspace/configuration":
|
|
29
|
-
return Array.isArray(params?.items) ? params.items.map(() => null) : [];
|
|
30
|
-
case "workspace/workspaceFolders":
|
|
31
|
-
return [{ uri: rootDir, name: "workspace" }];
|
|
32
|
-
case "workspace/applyEdit":
|
|
33
|
-
return { applied: false };
|
|
34
|
-
default:
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public transformDiagnostics(_uri: string, diagnostics: LspDiagnostic[]): LspDiagnostic[] {
|
|
40
|
-
return diagnostics;
|
|
41
|
-
}
|
|
42
|
-
}
|