Repository navigation
Ask AI: name a text selection's source lines in the question - #1732
Merged
Merged
Conversation
A text-selection Ask AI question (side chat, Ask this session, agent terminal) now says which lines the selection is on, e.g. 'Source: /docs/plan.md, line 41', so a phrase that occurs more than once in the document is no longer ambiguous. Fixes #1731
Extract App's Ask AI scope mapping to packages/editor/askScope.ts and unit-test it (lineEnd defaults to lineStart; converted sources drop the lines). Assert a single-block selection's question names the same span as the exported annotation's heading. Qualify the docs: that parity holds for a selection within one block.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1731
When you select text in a markdown document and ask a question with Ask AI, the question now says which lines the selection is on:
A selection inside a block that spans several lines, or across several blocks, gives a range:
lines 41–44. Before this change the question carried only the path, so the agent could not tell which occurrence of a repeated phrase you meant.What the line is
It is the source line span of the block that holds the selection. For a selection within one block, this is the same span the exported annotation for that selection prints,
(line 41)or(lines 41–44), so the question and the feedback name the same place. A selection over several blocks gives a range from the first block's start line to the last block's end line; the export names only the first block in that case. Frontmatter is counted, so the numbers are file lines. Lines inside a block are not resolved further, because the rendered text does not map back to source lines reliably once inline markdown is involved.Where it applies
buildDefaultPrompt's output, and the agent terminal and side chat now share one scope mapping (packages/editor/askScope.ts).Not changed:
detail(feat(diagrams): Ask AI from a diagram comment #1695).--markdown, URLs) sends no lines. Those lines belong to the converted markdown, not to the file the agent would read.For
@plannotator/uihostsEverything is optional and additive:
CommentAskAIContext.lineStart?/lineEnd?,AIQuestion.scope.lineStart?/lineEnd?,CommentPopoverState.blockIds?, and a new pure helperselectionSourceLines(blocks, blockIds)inutils/parser. A scope without lines produces the same prompt bytes as before. This is documented inpackages/ui/HANDOFF.md.Tests
packages/ui/components/Viewer.askAISelectionLine.test.tsx(DOM, added to the CI DOM step): renders the real Viewer and web-highlighter on a document that has the same phrase on line 3 and on line 9. Selecting each occurrence and clicking Ask AI gives the right line, and the prompt names line 9, not line 3. Both tests fail without the Viewer change.packages/ui/utils/parser.selectionLines.test.ts: frontmatter offset, wrapped paragraphs, code fences, multi-block ranges, unknown and diff ids, and parity with the export's(line N)heading for single-block selections (after frontmatter, and a wrapped paragraph).packages/editor/askScope.test.ts: the App mapping. A lonelineStartbecomes a one-line range, a converted source drops the lines, and a context without lines gets no line keys.packages/ui/utils/aiPrompt.test.ts: theSource:line formatting, and identical output when no lines (or invalid ones) are given.bun test,bun run typecheck, the related DOM tests, the review/hook/opencode builds, and the guides.showcheck:manifestall pass.