Skip to content

Show line range in agent host file-read tool display#312062

Merged
roblourens merged 5 commits intomainfrom
roblou/agents/add-line-range-to-file-read
Apr 23, 2026
Merged

Show line range in agent host file-read tool display#312062
roblourens merged 5 commits intomainfrom
roblou/agents/add-line-range-to-file-read

Conversation

@roblourens
Copy link
Copy Markdown
Member

When the Copilot CLI's view tool is called with a view_range argument, the agent host now surfaces the line range in both the invocation message and the past-tense message, instead of just showing the file name.

Before: "Reading file.ts" / "Read file.ts"
After: "Reading file.ts, lines 10 to 20" / "Read file.ts, lines 10 to 20" (or "line 10" for a single line)

All changes are in src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts:

  • Added ICopilotViewToolArgs extending ICopilotFileToolArgs with optional view_range?: number[].
  • Added a formatViewRange helper that defensively parses the [start, end] array (handling missing/-1 end-of-file sentinels).
  • Updated the View cases in getInvocationMessage and getPastTenseMessage to render the range when present.

The read permission display path is unchanged — the Copilot SDK's read permission request only carries path + intention, not view_range. The line range only flows through the tool.execution_start parsed parameters.

(Written by Copilot)

When the Copilot CLI's `view` tool is called with a `view_range`, surface
the line range in the invocation and past-tense messages so users see e.g.
"Reading file.ts, lines 10 to 20" instead of just "Reading file.ts".

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 23, 2026 02:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the agent host’s Copilot CLI tool-call display strings so view tool invocations/completions can show a requested line range (when provided via view_range) rather than only the file name.

Changes:

  • Add ICopilotViewToolArgs with optional view_range?: number[] for view tool parameters.
  • Add formatViewRange helper to parse/normalize view_range.
  • Update getInvocationMessage / getPastTenseMessage View cases to render “line …” / “lines … to …” variants.
Show a summary per file
File Description
src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts Parses view_range and includes the formatted line/range in view tool start/complete messages.

Copilot's findings

Comments suppressed due to low confidence (1)

src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts:95

  • formatViewRange currently accepts non-integer and non-positive line numbers (e.g. 0, 1.5) and can also return an endLine that is less than startLine (e.g. [10, 5]), which then renders as “lines 10 to 5”. Since view_range is documented as 1-based inclusive, it should defensively validate Number.isInteger, startLine >= 1, and (when endLine is a number) endLine >= startLine (and treat invalid ranges as absent).
function formatViewRange(view_range: number[] | undefined): { startLine: number; endLine: number | undefined } | undefined {
	if (!Array.isArray(view_range) || view_range.length < 1) {
		return undefined;
	}
	const startLine = view_range[0];
	if (typeof startLine !== 'number' || !isFinite(startLine)) {
		return undefined;
	}
	const rawEnd = view_range.length >= 2 ? view_range[1] : undefined;
	const endLine = typeof rawEnd === 'number' && isFinite(rawEnd) && rawEnd >= 0 ? rawEnd : undefined;
	return { startLine, endLine };
}
  • Files reviewed: 1/1 changed files
  • Comments generated: 3

Comment thread src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts
Comment thread src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts Outdated
Comment thread src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts Outdated
roblourens and others added 2 commits April 22, 2026 19:41
Drop the EOF-sentinel handling and require a strictly valid two-element
range (`length === 2`, integers, `start >= 0`, `end >= start`); fall back
to the path-only display otherwise. Mirrors `formatViewToolInvocation`
in the Copilot Chat extension and addresses review feedback on the
`-1` end-of-file sentinel and the stale doc comment.

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Copilot CLI uses `-1` as the documented "to end of file" sentinel
for the second element of `view_range`. The Copilot Chat extension
doesn't handle this and either drops the range or renders "-1"
literally; do better here by rendering "from line {n} to the end".

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: b88dca15 Current: cdbe8cf5

Changed (2)

chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Light
Before After
before after
agentSessionsViewer/CompletedUnread/Dark
Before After
before after

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roblourens roblourens marked this pull request as ready for review April 23, 2026 03:03
@roblourens roblourens enabled auto-merge (squash) April 23, 2026 03:03
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roblourens roblourens merged commit f9eafcd into main Apr 23, 2026
26 checks passed
@roblourens roblourens deleted the roblou/agents/add-line-range-to-file-read branch April 23, 2026 03:42
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants