fix(coding-agent): normalize read line-range labels (#10938)

- share range formatting across the TUI, exports, and examples
- add regression coverage without changing execution arguments
- fixes #9887
This commit is contained in:
Ramiz Wachtler 2026-10-14 15:20:04 +02:00 • committed by GitHub
parent 5712b134ed
commit 910149912c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 214 additions and 47 deletions

View file

@ -25,6 +25,7 @@ import {
createLsToolDefinition,
createReadToolDefinition,
createWriteToolDefinition,
formatReadLineRange,
} from "@earendil-works/pi-coding-agent";
import { Text } from "@earendil-works/pi-tui";
import { homedir } from "os";
@ -65,11 +66,9 @@ export default function (pi: ExtensionAPI) {
const path = shortenPath(args.path || "");
let pathDisplay = path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
// Show line range if specified
if (args.offset !== undefined || args.limit !== undefined) {
const startLine = args.offset ?? 1;
const endLine = args.limit !== undefined ? startLine + args.limit - 1 : "";
pathDisplay += theme.fg("warning", `:${startLine}${endLine ? `-${endLine}` : ""}`);
const lineRange = formatReadLineRange(args.offset, args.limit);
if (lineRange) {
pathDisplay += theme.fg("warning", lineRange);
}
return new Text(`${theme.fg("toolTitle", theme.bold("read"))} ${pathDisplay}`, 0, 0);

View file

@ -22,6 +22,7 @@ import { StringEnum } from "@earendil-works/pi-ai";
import {
CONFIG_DIR_NAME,
type ExtensionAPI,
formatReadLineRange,
getAgentDir,
getMarkdownTheme,
withFileMutationQueue,
@ -87,13 +88,10 @@ function formatToolCall(
case "read": {
const rawPath = (args.file_path || args.path || "...") as string;
const filePath = shortenPath(rawPath);
const offset = args.offset as number | undefined;
const limit = args.limit as number | undefined;
const lineRange = formatReadLineRange(args.offset, args.limit);
let text = themeFg("accent", filePath);
if (offset !== undefined || limit !== undefined) {
const startLine = offset ?? 1;
const endLine = limit !== undefined ? startLine + limit - 1 : "";
text += themeFg("warning", `:${startLine}${endLine ? `-${endLine}` : ""}`);
if (lineRange) {
text += themeFg("warning", lineRange);
}
return themeFg("muted", "read ") + text;
}