Skip to content

fix(doc-api): retarget comment-anchor guidance to query.match wire shape#3433

Merged
caio-pizzol merged 2 commits into
mainfrom
caio-pizzol/comment-anchor-retarget-supersedes-3224
May 21, 2026
Merged

fix(doc-api): retarget comment-anchor guidance to query.match wire shape#3433
caio-pizzol merged 2 commits into
mainfrom
caio-pizzol/comment-anchor-retarget-supersedes-3224

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Retargets @bjohas's #3224 to the actual API shape superdoc_search emits.

@bjohas correctly spotted that highlightRange is snippet-relative and unsafe as a comment range. The original patch then pointed agents at result.items[0].context.textRanges[0], which is the doc.find output shape; superdoc_search actually dispatches to doc.query.match, whose items carry target (a SelectionTarget), snippet, highlightRange, and blocks, with no context field. The wire shape is verified at four layers: schema (schemas.ts:4960-4971), adapter source (query-match-adapter.ts:567-602), the existing test suite, and a runtime pinning test.

The description and prompt template now build the target from items[0].blocks: single-block matches use {kind:"text", blockId: blocks[0].blockId, range: blocks[0].range}; cross-block matches use a TextTarget with segments. Both are accepted by comments.create per schemas.ts:4874-4878. The shipped MCP catalog and prompt artifacts are regenerated. A regression test in query-match-adapter.test.ts pins the wire shape so the broken path can't drift back.

Supersedes #3224 only because GitHub blocks maintainer pushes to org-owned forks (the OpenDevEd fork is an organization, not a user account). @bjohas's original commit is preserved here via cherry-pick -x, linking back to the source SHA.

A related bug at packages/superdoc/AGENTS.md:235 (same misuse of items[0].target against comments.create) is out of scope here; will track separately.

bjohas and others added 2 commits May 21, 2026 18:48
… anchoring

highlightRange is snippet-relative (offset by up to SNIPPET_PADDING=30
chars from the start of the block). Telling LLMs to build target.range
from it produces silently mis-anchored comments or TARGET_NOT_FOUND
errors.

The correct field is context.textRanges[0], which is a complete
block-relative TextAddress ({kind:"text", blockId, range:{start,end}})
and can be passed straight through as the comment target.

Update the superdoc_comment tool description accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
(cherry picked from commit 16fca2d)
@bjohas correctly identified that highlightRange is snippet-relative and
unsafe for comment ranges. The original patch pointed at
items[0].context.textRanges[0], which is doc.find output shape.
superdoc_search dispatches to doc.query.match, whose items expose
{target, snippet, highlightRange, blocks} with no `context` field.

Retarget the description prose and the prompt template to build the
comment target from items[0].blocks:
  - single block: {kind: "text", blockId: blocks[0].blockId, range: blocks[0].range}
  - cross block:  {kind: "text", segments: blocks.map(b => ({blockId: b.blockId, range: b.range}))}

Both shapes are accepted by comments.create (TextAddress | TextTarget).
items[0].target is a SelectionTarget and is not accepted.

Regenerate the shipped MCP catalog and prompt artifacts, and add a
regression test that pins the wire shape so the broken path can't be
reintroduced.

A related bug at packages/superdoc/AGENTS.md (same misuse of
items[0].target) is a follow-up; separate PR.

(cherry picked from commit cc0ebe16bc3aff2c31c8aec3fe3008fa017faf15)
@caio-pizzol caio-pizzol requested a review from a team as a code owner May 21, 2026 21:50
@github-actions
Copy link
Copy Markdown
Contributor

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@caio-pizzol caio-pizzol merged commit 1066522 into main May 21, 2026
71 checks passed
@caio-pizzol caio-pizzol deleted the caio-pizzol/comment-anchor-retarget-supersedes-3224 branch May 21, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants