Skip to content

feat: keep a project in step with a deployment's remote source - #77

Merged
bencode merged 1 commit into
mainfrom
feat/remote-source
Oct 3, 2026
Merged

bencode merged 1 commit into
mainfrom
feat/remote-source

Conversation

@bencode

@bencode bencode commented Oct 3, 2026

Copy link
Copy Markdown
Owner

What

A deployment can bind the reader to a remote source. The reader then keeps one project in step with it. It checks the source on its own, but only syncs when the reader asks. This is how brain2.lesscap.com serves the team knowledge base. The source itself is lesscap/work#1.

The reader stays generic. Nothing in it knows about GitHub, brain2, or who may read: sign-in belongs to the site in front of it.

Configuration

GAMMA_SOURCE_NAME=brain2
GAMMA_SOURCE_URL=/work/brain2   # same origin, behind the site's sign-in

The server returns these at GET /api/source. Without them it returns 404 and nothing changes.

Source protocol

// GET {url}
type SourceListing = { version: string; files: { path: string; version: string; size: number }[] }
// GET {url}/files/<path, each segment URL-encoded>   → the file

Versions are opaque strings. They only need to change when the content changes.

Behaviour

  • Opening. On a deployment with a source, the reader opens the project source-<name>, creating it if needed. A /p/<id> link to another project still wins.
  • Checking. The source is checked when the library opens and when the reader returns to the window, at most once a minute. If it changed, the file panel shows "brain2 has changes. Sync".
  • Sync. Sync downloads added and changed files, six at a time, and removes the files that left the source.
  • Local edits. A file edited in the library since the last sync is kept, and the status line names it. It is recorded as synced, so its next version arrives once the edit reaches the source, for example after saving to the local folder and pushing. No conflict can get stuck.
  • State. The only state is the last synced listing, kept as one value in localStorage under the project's workspace key. Deleting the project clears it. The file store and the database schema are unchanged.

Code

  • New code lives in features/source/:
    • protocol.ts: the protocol types and checks;
    • plan.ts: planSync and snapshotAfter, both pure;
    • use-source-sync.ts;
    • sync-status.tsx;
    • load-source.ts.
  • Server. source-config.ts and one route in app.ts.
  • Touch points. project-root (open the source's project), project-store (openSourceProject), the optional Project.source, one line in the file panel, library.reload, and one storage key base.

Verification

  • pnpm check passes. New tests:
    • planSync unit tests: changes, removals, edits kept, first sync, and the next version arriving;
    • a server test for /api/source;
    • an integration test that opens a deployment's source, syncs, then syncs again after the source changes, keeping a local edit and removing a deleted file;
    • a regression test that a deployment without a source opens as before.
  • End to end with lesscap/work#1 on one origin, against a local clone of brain2 (1629 files):
    • the reader opens /p/source-brain2, reports changes, and syncs in about 7.5 s;
    • a new upstream commit is reported again and arrives on the next Sync.

A deployment can name a remote source with GAMMA_SOURCE_NAME and
GAMMA_SOURCE_URL, served at /api/source. The reader then opens one
project for that source and checks it when the library opens and when
the reader returns to it. When the source has changed it says so, and
Sync brings in added and changed files and removes the ones that left.

A file edited in the library since the last sync is kept rather than
replaced, and counts as synced, so its next version arrives once the
edit reaches the source. The source is any address serving a listing of
paths and opaque versions and each file under its path; the reader
knows nothing about where it comes from or who may read it.
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