Skip to content

refactor: give PrRef, ChangedFile and PullRequest one home each - #349

Merged
nownabe merged 1 commit into
mainfrom
refactor/299-unify-types
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
refactor/299-unify-types

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Why

lib/github.ts and lib/pr/ typed the same pull-request concepts twice. Two definitions of one concept drift: Topbar took the loose ChangedFile (status: string) while its parent already passed the strict union from lib/pr/types, and App.tsx kept a PullInfo adapter whose only job was to flatten PullRequest.author for Topbar. deriveRole re-derived a role AppState.role already computes — and computes better, since #273 added the deleted-fork (headRepo === null) guard that deriveRole never had. Nothing called it.

Type-level refactor only: no behaviour change.

What

  • PrRef — one definition, in lib/pr/types.ts. The copies in lib/github.ts and lib/pr/github-transport.ts are gone; all 18 import sites point at lib/pr/types (no re-export needed).
  • ChangedFile — the loose copy in lib/github.ts is deleted. Topbar.tsx and tests/Topbar.test.tsx now take the union-typed one from lib/pr/types.
  • CommentAnchor / CommentKind / CommentStatus / ReviewComment — deleted; re-verified as having zero importers anywhere in entrypoints/, lib/ or tests/.
  • deriveRole — deleted with its six test cases. App.tsx has read role from repositoryAppState.role since [Medium] Fork PRs: PullRequest has no head repository, so Commit targets the base repo #273 and never called it; the behaviour is covered by the role cases in tests/pr/appstate.test.ts. The Role type export stays in reviewItems.ts where its five importers expect it.
  • PullInfo — deleted. Topbar's pull prop is now PullRequest | null, it renders pull.author.login, and App.tsx passes pullRequest straight through — the pull useMemo is gone. pullStatus / PullStatus stay: SubmitConfirmModal still consumes prStatus for the merged/closed warning from [Low] No PR lifecycle gating: commits and reviews go to merged or closed PRs #288.
  • lib/github.ts header rewritten to describe what actually remains (pullStatus, buildSuggestionBlock, avatarUrl, buildBlobPermalink — no network, no data model). The file is not moved.

110 lines net removed (157 deletions, 47 insertions across 22 files), matching the issue's estimate.

Red-step evidence

The failing check for a type-level refactor is bun run typecheck. After deleting the duplicates from lib/github.ts and before repointing imports, tsc --noEmit failed with 14 errors, e.g.:

entrypoints/review/App.tsx(79,8): error TS2459: Module '"../../lib/github"' declares 'PrRef' locally, but it is not exported.
entrypoints/review/App.tsx(80,8): error TS2305: Module '"../../lib/github"' has no exported member 'PullInfo'.
entrypoints/review/components/Topbar.tsx(12,8): error TS2305: Module '"../../../lib/github"' has no exported member 'ChangedFile'.
lib/drafts.ts(9,15): error TS2459: Module '"./github"' declares 'PrRef' locally, but it is not exported.

Removing PrRef from github-transport.ts produced a second red of 7 errors (bootstrap.ts, remote-fetcher.ts, review-threads.ts and their tests), and deleting deriveRole a third of 8 (tests/reviewItems.test.ts). Each was driven to green by repointing imports — that error list is the exhaustive importer census.

Checks

bun run test 818 pass / 0 fail (822 before; the 4 removed are the deriveRole cases) · check:lint · check:format · typecheck · build all pass.

Closes #299

lib/github.ts and lib/pr/ typed the same PR concepts twice, so a shape change on one side silently left the other behind — Topbar took the loose ChangedFile while its parent passed the strict one. Collapse every duplicate onto lib/pr/types.ts and drop the derivations the data layer already owns: deriveRole (AppState.role has covered it, headRepo guard included, since #273) and the PullInfo adapter App.tsx built only to feed Topbar.
@nownabe nownabe self-assigned this Sep 20, 2026
@nownabe
nownabe merged commit 9747969 into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the refactor/299-unify-types branch September 20, 2026 10:12
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
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.

[Refactor] Unify duplicated types and derivations: PrRef, ChangedFile, PullInfo, deriveRole

1 participant