plannotator icon indicating copy to clipboard operation
plannotator copied to clipboard

Ask AI: include the line number of a text selection in annotate mode

Open de-tre opened this issue 1 month ago • 0 comments

Summary

When I select text in an annotate session and ask a question via Ask AI, the question carries the selected text and the file path, but no line number. With the agent terminal running, the agent only gets the path, so it has to search the file for the text. If the selected phrase occurs more than once, it cannot tell which occurrence I mean. Annotations, by contrast, are exported with a line number (## 1. (line 43) Feedback on: "...").

Current behaviour

Seen with Plannotator 0.27.21 on Linux (WSL2): plannotator annotate <file.md>, Claude Code in the agent terminal. Selecting a sentence and asking a question sends this to the terminal (shortened):

# Plannotator Ask

Before answering, read this file from the current workspace: /path/to/doc.md. Use the selected/context text below to understand what the user is asking about.

Current document: /path/to/doc.md

Current annotations:
# File Feedback
...
## 1. (line 43) Feedback on: "..."
...

Question:
Re: Selected text
Source: /path/to/doc.md

Selected text:
<the selected sentence, in a code fence>

<my question>

The classic Ask AI side chat gets the same Re: Selected text / Source / Selected text block. It has the document in its system prompt, so it can find the text, but it has the same problem with repeated phrases.

This is not specific to my version: on current main, the selection branch in packages/ui/hooks/useAIChat.ts builds the question from scope.label, scope.sourcePath, scope.text and scope.detail, and AIQuestion.scope in packages/ui/types.ts has no line field.

Requested behaviour

Add the source line (or line range) of the selection to the question, for example:

Re: Selected text
Source: /path/to/doc.md, line 41

The start line of the enclosing block would already be enough in most cases, and it would match the line shown in the exported feedback. Exact lines of the selection would be even better if they are cheap to compute.

Why it seems feasible

  • The markdown parser already records a start line for every block, and the exported feedback uses it for the (line N) in each annotation heading.
  • Code-review questions already carry line X / lines X-Y, and since 0.28.1 a question from a diagram comment carries its line in the document (#1695). #1694 added similar context for HTML pinpoints. A plain text selection in annotate mode seems to be the remaining case without a location.
  • Ask this session (0.28) appears to go through the same question formatting, so it would benefit as well. I have not tested that.

Workaround for now: select a longer passage that occurs only once, or name the section in the question.

Thanks again so much for reading and considering. Plannotator has been an absolute gem so far.

de-tre avatar Oct 06 '26 12:10 de-tre