Skip to content

Add manual re-anchor for orphaned comments - #26

Draft
tnsardesai wants to merge 2 commits into
mainfrom
hypeship/reanchor-orphaned-comments
Draft

Add manual re-anchor for orphaned comments#26
tnsardesai wants to merge 2 commits into
mainfrom
hypeship/reanchor-orphaned-comments

Conversation

@tnsardesai

@tnsardesai tnsardesai commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Automatic re-anchoring (tier 1/2/3 on every doc write) only un-orphans a thread when its original quote is restored verbatim. When the quoted text is rewritten — the common case — the thread stays orphaned forever with no way to point it at the replacement passage.

This adds manual re-anchoring:

  • API: PATCH /api/v1/docs/:slug/comments/:id gains an anchor field.
    • {"anchor":{"exact":"the new passage","prefix":"...","suffix":"..."}} re-anchors the thread: the new selector is resolved against the current doc text via the same resolveInitialAnchor path used at creation (offsets re-stamped, anchored_version set, orphaned recomputed — a quote that doesn't resolve yet keeps the thread orphaned with the new selector, so a later restoring edit can still un-orphan it).
    • {"anchor":null} detaches the thread to a doc-level comment.
    • Permission mirrors delete: the comment's author (own) or the document owner (any); root comments only (matching POST /comments' reply rule).
  • Viewer: a re-anchor action on orphaned cards (your own threads, or any thread if you own the doc) starts a pick-a-passage flow — rail banner explains, the next doc selection shows a confirm bar, confirm PATCHes and the thread re-anchors in place. Server enforces either way.
  • Docs: llms.txt / SKILL.md and the OpenAPI spec updated (artifacts regenerated via gen:skill / gen:spec; spec:check passes).

Testing

  • npx tsc --noEmit, npm run build, npm test (174 unit tests), npm run spec:check — all pass.
  • scripts/e2e.ts extended: rewrite the doc so the quote disappears → thread orphaned → re-anchor to a surviving quote → un-orphaned → anchor:null → doc-level; plus permission coverage (owner re-anchors a grantee's thread → 200; non-author editor → 403). Not run — it exercises the real email path against production and needs local env secrets I don't have here.

Automatic re-anchoring only un-orphans a thread when its original quote
comes back verbatim; a thread whose text was rewritten stays orphaned
forever. PATCH /comments/:id now accepts an anchor field: a new quote
re-resolves against the current doc text (un-orphaning on success), and
null detaches the thread to a doc-level comment. Author-only, root
comments only — same rules as body edit and POST /comments.

The viewer shows a re-anchor action on the author's own orphaned cards:
pick a replacement passage in the doc, confirm in a floating bar, and
the thread re-anchors in place.

Spec + skill artifacts regenerated; e2e covers orphan -> re-anchor ->
detach.
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
justhtml Ready Ready Preview Aug 6, 2026 7:53pm

Mirrors the delete rule (author own, owner any): the owner can repair
orphaned threads on their document regardless of who authored them. The
viewer shows the re-anchor action to the owner on every orphaned card;
e2e covers owner-reanchors-grantee's-thread and non-author-editor 403.
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.

1 participant