Repository navigation
fix(review): map comment positions between head and edited coordinates - #348
Merged
Merged
Conversation
nownabe
force-pushed
the
fix/283-edited-coordinates
branch
from
September 20, 2026 07:37
c705ba3 to
c6370bd
Compare
nownabe
force-pushed
the
fix/283-edited-coordinates
branch
from
September 20, 2026 08:39
c6370bd to
b92735c
Compare
nownabe
force-pushed
the
fix/283-edited-coordinates
branch
2 times, most recently
from
September 20, 2026 08:59
09b468b to
734b754
Compare
nownabe
force-pushed
the
fix/283-edited-coordinates
branch
from
September 20, 2026 09:02
734b754 to
8241f5d
Compare
nownabe
force-pushed
the
fix/283-edited-coordinates
branch
from
September 20, 2026 09:03
8241f5d to
3e536e7
Compare
nownabe
force-pushed
the
fix/283-edited-coordinates
branch
from
September 20, 2026 09:05
3e536e7 to
b976c83
Compare
nownabe
force-pushed
the
fix/283-edited-coordinates
branch
from
September 20, 2026 09:10
b976c83 to
f0ab5d1
Compare
New anchors took their line numbers from the live editor document, which may carry unsubmitted local edits, but stamped them with the head sha; existing head-coordinate positions were drawn onto that same edited document. Two lines inserted at the top therefore sent GitHub the wrong line (or a 422) and drew every comment below the insertion two lines too high. One memoised line map, head to edited, is now the single bridge: highlights, thread ranges, jumps and suggestion marks map through it and skip a comment whose line is being edited, and addDraft maps the selection back, refusing one that touches an edited line. Closes #283
nownabe
force-pushed
the
fix/283-edited-coordinates
branch
from
September 20, 2026 09:11
f0ab5d1 to
858a7be
Compare
nownabe
added a commit
that referenced
this pull request
Sep 20, 2026
…#350) ## Why `docs/` had accumulated statements that no longer describe the code: a wire format two versions old, a storage backend that was never built, an ADR rule the UI does not follow, and superpowers specs that contradict the ADRs without saying so. A newcomer following the reading order AGENTS.md prescribes was being misled. Documentation only — no behaviour change. The ADRs were amended heavily between the issue and this PR (#303–#348), so every item was re-audited against the code on `main` (`9465718`) before editing; two were already fixed and are recorded as such below. ## What Per item of #294: 1. **ADR 0003 §7 "Legacy metadata is discarded"** → rewritten as "read, never rewritten". `lib/pr/metadata.ts` accepts `bark:v1` and its `docreview:v1` alias read-only (`extractMetadata` → `parseV1`) and maps them to the v2 shape; only an unparseable, invalid or unknown-version payload is dropped. The note says why there is no migration path: v1 payloads live in comment bodies on github.com, which no client release can rewrite. The two cross-references that repeated the old claim (ADR 0001 and ADR 0002 closing notes) now distinguish local legacy keys, which *are* dropped, from on-GitHub metadata, which is not. 2. **ADR 0004 §5 force-push bullet** → replaced. `GET contents?ref={sha}` addresses a commit object, not a ref, so a force-pushed sha normally stays fetchable (and PR heads are retained under `refs/pull/N/head`); re-anchoring proceeds through the line map as usual, and only a real 404 (garbage-collected commit, path or repo gone) leaves `FileContent` missing and yields `outdated`. Design doc §12-3 is closed accordingly. 3. **ADR 0005 §1/§5 manual refresh** → amended to match the code rather than gating the fab. `DebugFab` is always rendered; the Refresh button lives one click deeper, inside the debug popover, next to the internal-state dump. §5 carries an explicit amendment note saying that is accepted for v1 and why. `docs/design-principle.md`'s floating-controls bullet now states the rule the two FABs actually follow: reveal-only may ship, behaviour-changing is build-gated (`.role-fab` / `BARK_DEV_ROLE_SWITCH`). 4. **Design doc §7.1 / §7.7 / §10** → the raw-JSON `bark:v1` example is replaced by a real `bark:v2` base64 envelope with its decoded payload, the optional `resolved` and `quoteDigest`/`quoteLength` (#334) fields, and a pointer to `lib/pr/metadata.ts` as the authoritative field list. §7.7 now describes `chrome.storage.local` as the only store, lists the three per-PR keys, and states plainly that the IndexedDB plan was never built; §10's "persist state to IndexedDB" bullet and its ETag sentence are rewritten to what the client does. 5. **2026-06-18 resolve spec** → the superseded banner added by #310 is present and correct; verified, not touched. Its *plan* had none, so it got one. The design doc's authority paragraph now covers `docs/superpowers/` explicitly: history, not authority, and the absence of a banner is not a promise of currency. 6. **§7.9 `addressed` vs ADR 0004 `shifted`** → ADR 0004 §4 gains a paragraph stating that `shifted` is the raw mechanical signal and R9's `addressed` (#3) is derived from it plus the review rounds, specified separately and stored nowhere. Design doc §7.9 now references the ADR statuses instead of inventing its own, and notes that the `addressedBySha` in `lib/github.ts` is an unreferenced legacy type, not part of the model. 7. **Design doc §11 status** → R8 cross-file navigation is marked shipped (the changed-`.md` selector in `Topbar.tsx`, fed by `RemoteState.changedFiles`), so M5 is done and M4 (R9/R10) is the remaining open work. 8. **ADR statements not implemented** — decided in favour of the code: - **ADR 0002 §6** rewritten to describe materialise-at-submit as implemented: `SuggestionEdit` is persisted on its own `:suggestion-edits` key (400 ms debounce, read-modify-write per path), stays "live" in the editor until Submit, and only then becomes draft `Comment`s whose id is derived, not minted, from `(path, baseSha, range, replacement)` (#337/#308). The stale "lost on reload" trade-off and the auto-save Deferred item are replaced by the real consequence: two persistence paths, with folding `SuggestionEdit` into the Repository as the deferred work. - **ADR 0005 §2** "already-fetched pairs are retained" deleted. A full refresh replaces `RemoteState` wholesale, refetching every pair; the sentence is replaced by why that is fine (ETag `If-None-Match` on every GET, 304 costs no rate limit) and a pointer to the still-deferred persistent cache. - **ADR 0001 §4 `useAppState`** — already fixed by #329; §4 is the conflict policy and names no hook. Verified, no change. Also folded in (from the #299 agent, found while reviewing PR #349): - **AGENTS.md / README.md layout** described `lib/github.ts` as "GitHub API". It is not: it holds PR types and four pure helpers, while the client, the Repository pipeline, re-anchoring and the wire format all live in `lib/pr/`. Both are rewritten around `lib/pr/` as the place to start, and the non-existent `lib/reanchor.ts` is dropped. (`CLAUDE.md` is a symlink to `AGENTS.md`, so one edit covers both.) - **2026-06-21 author-role-derivation spec and plan** describe `deriveRole` and a `GitHubClient.getAuthenticatedUser` lookup; the live derivation is `computeRole` in `lib/pr/appstate.ts`, which also withholds `author` when `headRepo` is `null` (#273). Both files get a Superseded banner pointing there and at ADR 0002 §4. Every ADR amended here records it in the header in ADR 0004's existing `- Amended: <date> (#issue) — <what>` format; two prior amendments that had changed an ADR body without a header line (#267 on ADR 0004/0005, #289 on ADR 0001) are backfilled from their commits, and ADR 0002's in-place 2026-07-22 note is now also listed in the header. ## Testing No test accompanies this change: it edits only Markdown, and there is no assertion a docs edit could make fail. The verification was reading each claim against the code it describes — `lib/pr/metadata.ts`, `lib/pr/reanchor.ts`, `lib/pr/remote-fetcher.ts`, `lib/pr/chrome-storage.ts`, `lib/drafts.ts`, `entrypoints/review/hooks/useSuggestionEdits.ts`, `entrypoints/review/components/DebugFab.tsx`, `entrypoints/review/reviewItems.ts` — and the base64 example in §7.1 is generated, not hand-written, so it decodes to the JSON printed beneath it. ## Checks `bun run test` (822 pass / 0 fail, 65 files) · `check:lint` · `check:format` · `typecheck` · `build` — all clean. Note for future docs PRs: `oxfmt` **does** format Markdown in this repo, and it reflowed the README table. ## Noted, out of scope - `lib/storage.ts:2-3` still promises "IndexedDB: per-PR pending comments/ suggestions, snapshots (later slice)" in its header comment — the same drift as item 4, but in code. Left for a code PR since this one touches no `.ts`. - `lib/github.ts` keeps the dead `CommentStatus` / `ReviewComment` / `addressedBySha` types that nothing imports. PR #349 removes them. - Nothing links to `docs/superpowers/` or `docs/chrome-web-store/`, and `docs/adr/` has no index page. The authority paragraph now explains what `superpowers/` is, which covers the misleading part; an index is a separate question. Closes #294
nownabe
added a commit
that referenced
this pull request
Sep 20, 2026
…per (#352) ## Why `App.tsx` held the same logic two or three times, so a rule change (a `baseSha` fallback, a `parentLocalId` lookup) had to be made in every copy. This gives each one a single home. Folding the FileEdit sync into one helper also removed a latent race, see "Behaviour change" below. ## What Re-audited issue #300's six items against current `main`; three were already resolved by earlier PRs and are untouched here: | # | Item | Status | |---|------|--------| | 1 | "drafts → Repository" loop in `submitReview` vs `submitAuthor` | **already resolved** — #351 (issue #282) deleted `submitAuthor`'s loop; only `submitReview` still has one | | 2 | FileEdits sync (mirror effect vs `submitAuthor`) | **done** — #341 (issue #278) had unified the *building* via `fileEditsFromEdits`; the upsert/discard loop was still duplicated, now `syncFileEditsToRepository()` | | 3 | `parentLocalId` resolution (`addReply`, `submitReview`) | **done** — one `parentLocalIdFor(thread)` | | 4 | "Drop accepted decisions" (two in-memory copies + `clearAcceptedDecisions`) | **done** — `useDismissedSuggestions.clearAccepted(ids)`; the `setDismissed` escape hatch it existed for is gone from the hook's API | | 5 | `resetSuggestionEdits(); saveSuggestionEdits(ref, {})` in `discardAllPending` | **done** — `await discardAllPersistedEdits()`; `saveSuggestionEdits` is no longer imported by `App.tsx` | | 6 | `jumpTo` vs `jumpToOffsets` | **already resolved** — #348 (issue #283) folded `jumpTo` into `jumpToCid` → `jumpToOffsets` | Net line change: **−30 lines in `App.tsx`** (49 added / 79 removed); **−15 lines of production code overall** (`App.tsx` + the two hook files), +37 lines of test. ## Behaviour change (one, deliberate) `syncFileEditsToRepository` skips a FileEdit whose current state is past `"draft"`. `submitAuthor` used to upsert unconditionally, and that redundant write was the only thing keeping the mirror effect from re-running *during* `submitDrafts()`, seeing the FileEdit as `"syncing"` and writing it back as a `"draft"` — cancelling the commit it belonged to. Without the guard, both `tests/AppSubmitFailure.test.tsx` author-submit tests fail (no `commit` call at all, so the accepted thread is never resolved); with it they pass. Everything else is pure extraction. ## Red-test evidence New hook test, `tests/useDismissedSuggestions.test.tsx` → `useDismissedSuggestions — clearAccepted`, written before the implementation: ``` TypeError: result.current.clearAccepted is not a function. (In 'result.current.clearAccepted([1])', 'result.current.clearAccepted' is undefined) (fail) useDismissedSuggestions — clearAccepted > drops only the named ids and purges them from storage (fail) useDismissedSuggestions — clearAccepted > without a ref: updates state, does NOT touch storage 5 pass 2 fail ``` The existing App-level suites (`AppSubmitFailure`, `AppEditedCoordinates`, `AppPrRef`, `AppRejectSuggestion`) are the safety net for the extraction itself and stay green. ## Checks `bun run test` 818 pass / 0 fail (64 files) · `check:lint` · `check:format` · `typecheck` · `build` — all clean. Closes #300
nownabe
pushed a commit
that referenced
this pull request
Sep 20, 2026
🤖 I have created a release *beep* *boop* --- ## [0.4.0](bark-v0.3.0...bark-v0.4.0) (2026-09-20) ### Features * **pr:** accept .markdown and .mdx as Markdown ([#322](#322)) ([e22ee68](e22ee68)), closes [#293](#293) * **pr:** commit fork pull requests to the fork's repository ([#342](#342)) ([4e2adef](4e2adef)), closes [#273](#273) * **pr:** create a top-level draft Comment's Thread with it ([#323](#323)) ([6e192f3](6e192f3)), closes [#272](#272) * **pr:** resolve out-of-diff threads via the root comment fence ([#310](#310)) ([7e0ecb9](7e0ecb9)), closes [#270](#270) * **reanchor:** bounded region search for single-line anchors and line-local suggestion merge ([#309](#309)) ([0f735da](0f735da)), closes [#269](#269) * **reanchor:** locate multi-line anchors per endpoint in the region search ([#347](#347)) ([f4fd457](f4fd457)), closes [#311](#311) * **review:** preview the merge for shifted suggestions in the editor ([#354](#354)) ([f822f41](f822f41)), closes [#312](#312) ### Bug Fixes * **anchor:** define anchor.quote as the source text at anchor.range ([#327](#327)) ([11a935d](11a935d)), closes [#276](#276) * **background:** focus an existing review tab instead of opening a second one ([#325](#325)) ([58efa63](58efa63)), closes [#277](#277) * **pr:** compose the quote and permalink for every out-of-diff post ([#351](#351)) ([f85b99b](f85b99b)), closes [#282](#282) * **pr:** count patch lines starting with ++ or -- in parseRightRanges ([#314](#314)) ([9dfbd46](9dfbd46)), closes [#284](#284) * **pr:** keep the rel=next link in the ETag cache so 304 pages still paginate ([#318](#318)) ([6472de2](6472de2)), closes [#286](#286) * **pr:** offer Resolve only when GitHub would accept it ([#335](#335)) ([b05fdcc](b05fdcc)), closes [#274](#274) * **pr:** park a failed resolve toggle in synced, not draft ([#320](#320)) ([56e815b](56e815b)), closes [#275](#275) * **pr:** post drafts in the current head's coordinates ([#303](#303)) ([28ef345](28ef345)) * **pr:** recover comments stuck in syncing instead of re-posting them ([#305](#305)) ([3548086](3548086)) * **pr:** refuse commits to a merged or closed PR ([#330](#330)) ([2a239ff](2a239ff)), closes [#288](#288) * **pr:** refuse to submit a draft whose quoted text changed upstream ([#346](#346)) ([d4118a4](d4118a4)), closes [#313](#313) * **pr:** route replies on the parent's GitHub object kind ([#326](#326)) ([1df6462](1df6462)), closes [#285](#285) * **pr:** serialise refresh and execution under one Repository lock ([#336](#336)) ([1864488](1864488)), closes [#281](#281) * **pr:** sweep entities left syncing at the end of a submit ([#331](#331)) ([108caa9](108caa9)), closes [#271](#271) * **release:** pin publish-browser-extension to ^4.0.5 ([#263](#263)) ([b77104f](b77104f)) * **review:** derive a suggestion draft's cid from the hunk it materialises ([#337](#337)) ([963339d](963339d)), closes [#308](#308) * **review:** end a whole-line selection on the line it actually covers ([#319](#319)) ([3364d18](3364d18)), closes [#291](#291) * **review:** map comment positions between head and edited coordinates ([#348](#348)) ([9465718](9465718)), closes [#283](#283) * **review:** reject a suggestion by resolving its thread on GitHub ([#340](#340)) ([d088a8d](d088a8d)), closes [#287](#287) * **review:** resolve accepted-suggestion threads only after the commit lands ([#341](#341)) ([770f901](770f901)), closes [#278](#278) * **review:** surface failed comment posts and keep the reviewer's edits ([#307](#307)) ([48cb675](48cb675)) * **review:** validate the PR number from the review URL ([#321](#321)) ([457a942](457a942)), closes [#295](#295) * **storage:** bound chrome.storage.local growth and stop quota errors losing drafts ([#332](#332)) ([1f96120](1f96120)), closes [#289](#289) * **suggest:** consume a longer closing fence instead of leaking a backtick ([#316](#316)) ([d2e0683](d2e0683)), closes [#290](#290) ### Performance Improvements * **reanchor:** replace the LCS table with a memoised line-level Myers diff ([#344](#344)) ([8caebdd](8caebdd)), closes [#280](#280) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please-nownabe-bark[bot] <295690643+release-please-nownabe-bark[bot]@users.noreply.github.com>
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.
Why
displayPositionandComment.anchorare expressed in the coordinates ofFileContent(headSha, path); the editor shows the locally editedsource(thereviewer's live suggestions, the author's staged accepts). The two spaces were
mixed without a mapping:
addDrafttookstartLine/endLinefrom the live editor document butstamped
sha: headSha, so a reviewer who inserted two lines at the top andthen commented on base line 10 sent GitHub line 12 — the wrong line, or a 422
when it falls outside the hunk.
buildSuggestionMarksappliedhead-coordinate positions to
lineStartsbuilt from the editedsource, soevery comment below an insertion was drawn two lines too high.
applyAcceptedSuggestionalready translated head → edited for exactly thisreason (#177); the comment paths did not.
What
One direction map,
headToEdited = buildLineMap(baseSource, source)(memoisedin App,
nullwhen the texts are equal), is the single bridge. Every place thatdraws or jumps to a comment maps
dp.rangethrough it and skips the commentwhen either endpoint's line has local edits — the same rule
applyExactQuotealready used, since a line being rewritten has no stable position.
addDraftmaps the selection back through the inverted map and refuses a selection
that touches a locally edited line or that is not contiguous in head
coordinates.
invertLineMap.headRangeToEditedOffsetsandeditedSpanToHeadnext tothe existing base→edited mapping;
applyAcceptedSuggestiontakes the map asan optional argument (App passes its memo instead of rebuilding it per click),
and
applyExactQuotenow goes throughheadRangeToEditedOffsets.buildSuggestionMarkstakesheadToEdited.toEditedOffsetshelper, and the wiring of the highlight effect,
threadRanges,jumpTo,jumpToDraft,buildSuggestionMarksandacceptSuggestion. Draft highlights,thread ranges and jumps now read the draft's
CommentView.displayPositioninstead of its raw stored range, which also fixes the pre-existing case of a
draft anchored at an older sha.
jumpTofolds intojumpToOffsets(theminimal part of [Refactor] De-duplicate App.tsx submit, FileEdit sync, accepted-purge and jump helpers #300).
Known consequence, worth stating: a comment on a line the author is currently
editing disappears from the editor until the edit is submitted or discarded. It
stays in the sidebar with its normal status (no
outdatedbadge). This isconsistent with accept refusing on the same line, and the alternative — drawing
it at a nearby line — would put the highlight over the wrong text.
addDraft's refusal is a Snackbar via the existingreportError; no new UI.Red-test evidence
tests/pr/linemap.test.ts→invertLineMap:SyntaxError: Export named 'invertLineMap' not found in module lib/pr/linemap.ts.tests/suggest.test.ts→ "head ↔ edited coordinates (issue [Medium] New comment anchors use edited-document coordinates but are stamped with the head sha #283)":SyntaxError: Export named 'editedSpanToHead' not found in module lib/suggest.ts.tests/reviewItems.test.ts→ "a suggestion below two locally inserted linesis drawn at its mapped line":
Expected length: 1, Received length: 0(thehead offset landed on the wrong text, so the quote check dropped the mark).
tests/reviewItems.test.ts→ "a suggestion on a locally edited line is notdrawn":
Expected length: 0, Received length: 1.tests/AppEditedCoordinates.test.tsx→ "a comment on unedited text isanchored in head coordinates": the recorded anchor was
{sl: 4, el: 4}instead of
{sl: 2, el: 2}— the editor's line numbers stamped with the headsha.
tests/AppEditedCoordinates.test.tsx→ "a selection on a locally insertedline is refused with a message": no Snackbar appeared and the comment was
upserted.
The App-level test drives the real App (the
AppSubmitFailureharness: mockedwxt/browser+ bootstrap, fetch stub,happyDOM.setURL) as a reviewer with"X\nY\n" + BASEpersisted as the file's edit. It stubsEditorView.prototype.coordsAtPosbecause happy-dom has no layout, soCodeMirror would never place the selection bubble; the stub is restored in
afterAll.Guards: the
null-map identity cases in the unit tests and the whole existingsuite (including the #307/#308 App harness) cover "no local edits" behaviour
unchanged.
Checks
bun run test(749 pass, 0 fail),check:lint,check:format,typecheck,buildall pass.Closes #283