How @knighted/develop stores pull request context across browser storage.
This guide focuses on PR-context ownership only.
PR context is stored in one place:
- IndexedDB (IDB): workspace snapshots used by the Workspaces drawer.
See the full storage ownership docs for non-PR keys:
- Database:
knighted-develop-workspaces - Object store:
prWorkspaces - Relevant fields in each workspace record:
prContextState:inactive|active|closedprNumber:number | nullprTitle,base,headrepo
- Not used for PR context state.
- No legacy PR-context migration/cleanup path is supported.
Use this matrix as the source of truth when debugging UI/storage mismatch.
| Scenario | IDB prContextState |
IDB prNumber |
localStorage PR fields | Notes |
|---|---|---|---|---|
| A. Local workspace only, no PR context | inactive |
null |
none | No connected PR context. |
| B. Workspace is for an active, open PR | active |
PR number | none | Push mode in PR controls. |
| C. Workspace is for a PR closed on GitHub | closed |
closed PR number | none | Historical context retained for debugging/reference. |
| D. Active PR immediately after push commit | active |
PR number | none | Committed tabs persist clean baseline (isDirty=false, syncedContent=content) and remain clean after reload. |
When the app loads, workspace restore scope depends on whether a repository is selected.
- If a repository is selected: use repository-scoped records only (
repomatch). - If no repository is selected: evaluate all stored workspace records.
If a repository is selected and no repository-scoped records are found, restore falls back to evaluating all stored workspace records.
Selection order:
- Load candidate records using the scope above.
- Compute preferred candidates from in-memory state:
- Preferred by id: existing in-memory active record id when available.
- Preferred by workspace key: current repository + head (
workspaceKey).
- If preferred-by-id or preferred-by-key exists and is
active, select it. - Otherwise select the first
activerecord in candidates. - Otherwise select preferred-by-id or preferred-by-key if present.
- Otherwise fall back to the first candidate by recency (
lastModifieddescending).
Notes:
- No
active workspacepointer is stored inlocalStorage. - Restore behavior is intentionally derived from IDB workspace records + in-memory runtime state.
- This avoids cross-storage drift between
localStorageand IndexedDB.
PR drawer field edits are treated as draft input.
- Editing PR base/head/title in the drawer does not persist workspace record metadata by itself.
- Workspace PR metadata is committed by explicit successful workflow outcomes (for example: successful Open PR, successful Push Commit, or successful Close PR/verified closed updates).
This keeps workspace records aligned to verified workflow outcomes instead of intermediate form state.
Multiple active PR workspaces may exist for the same repository.
- The model does not enforce a single-active-record-per-repository invariant.
- Restore selection still follows the algorithm above and picks one workspace to load into the current runtime.
PR workflow state is part of workspace state.
Storing it only in IDB avoids drift between storage systems and keeps a single source of truth for restore behavior.
When the UI does not match expected PR state:
- Check the IDB workspace record currently selected/opened and inspect:
prContextStateprNumberrepo,head,prTitle
- committed tab fields:
isDirty,syncedContent,content,syncedAt,lastSyncedRemoteSha
- Compare against the matrix above.
- If the PR is still open on GitHub, expect PR controls to return to Push mode and the workspace record to transition back to
active. - If the PR is no longer open, expect Open PR mode to remain and status messaging to explain verification results.
IndexedDB (all workspace records):
indexedDB.open('knighted-develop-workspaces').onsuccess = event => {
const db = event.target.result
db.transaction('prWorkspaces').objectStore('prWorkspaces').getAll().onsuccess = e => {
console.log(e.target.result)
}
}Close archives PR-linked context in IDB and clears active PR context in runtime.
- Matching workspace records for that PR context are persisted as
closed. - Close does not force an automatic fresh-local-workspace handoff.
- Workspace switching remains an explicit Workspaces action.