# gitproxy (Gleam) Gleam port of [nandi.uk/gitproxy](https://tangled.org/nandi.uk/gitproxy): a **Git remote helper** that stores whole-repo snapshots on an **AT Protocol PDS**, plus a small **HTTP appview** to browse them. ## What it does 1. **Push** — `git fast-export` → upload stream as a PDS blob → write `org.latha.gitproxy.snapshot` record 2. **Fetch** — load latest snapshot for `repoId` → `git fast-import` into the local repo 3. **Browse** — appview resolves a handle, loads the snapshot publicly, serves commits/files over HTTP Remote URLs: ```text atgit://handle/repo aproto://handle/repo ``` ## Requirements - Gleam 1.17+ and Erlang/OTP - Git on `PATH` - Auth for push: **browser OAuth** (preferred) or a Bluesky/ATProto **app password** ## Setup ```bash cd gitproxy gleam deps download gleam test ``` Install remote helpers on your `PATH` (symlink is fine): ```bash ln -s "$PWD/bin/git-remote-atgit" ~/.local/bin/git-remote-atgit ln -s "$PWD/bin/git-remote-aproto" ~/.local/bin/git-remote-aproto ``` ## Usage ### OAuth login (recommended) ```bash gleam run -- login you.bsky.social # opens a browser; session is stored under $XDG_STATE_HOME/gitproxy git remote add origin atgit://you.bsky.social/my-project git push -u origin main git fetch origin gleam run -- whoami you.bsky.social gleam run -- logout you.bsky.social ``` If no session exists, the first `git push` / `git fetch` will also start OAuth interactively. ### App password (optional) ```bash export APROTO_APP_PASSWORD='xxxx-xxxx-xxxx-xxxx' git remote add origin atgit://you.bsky.social/my-project git push -u origin main git fetch origin ``` Appview (public browse of existing snapshots; no password required for list/getBlob): ```bash gleam run -- appview 8787 # open http://127.0.0.1:8787 ``` ## Layout | Path | Role | |------|------| | `src/gitproxy/helper.gleam` | Git remote-helper protocol | | `src/gitproxy/git.gleam` | `fast-export` / `fast-import` / ref rewrite | | `src/gitproxy/store.gleam` | Snapshot save/load | | `src/gitproxy/pds.gleam` | Live PDS client + in-memory PDS for tests | | `src/gitproxy/appview.gleam` | Mist HTTP server | | `src/gitproxy/view.gleam` | Reconstruct repo view from PDS | | `bin/git-remote-*` | Git helper entrypoints | | `priv/public/` | Appview static UI | ## Auth & config Auth is resolved in order: 1. `APROTO_APP_PASSWORD` / `BLUESKY_APP_PASSWORD` (legacy app password, Bearer JWT) 2. Saved OAuth session from `gitproxy login` (DPoP-bound tokens) 3. Interactive browser OAuth on first remote-helper use | Variable / command | Purpose | |--------------------|---------| | `gitproxy login [handle]` | Public loopback OAuth (`http://127.0.0.1:4120x/callback`) | | `gitproxy logout [handle]` | Delete saved OAuth session | | `gitproxy whoami [handle]` | Print DID / PDS from saved session | | `APROTO_APP_PASSWORD` / `BLUESKY_APP_PASSWORD` | App password for push (skips OAuth) | | `APROTO_COLLECTION_PREFIX` | Default `org.latha.gitproxy` | | `APROTO_HANDLE` | Fallback handle if URL is incomplete | | `PORT` | Appview port | ## Storage model - Collection: `{prefix}.snapshot` - Record fields: `repoId`, `snapshotId`, `createdAt`, `streamSha256`, `blob`, `refs` - Each push creates a new snapshot; “latest” is newest `createdAt` for that `repoId` ## Differences from the JS original - Browser OAuth is ported as a **public loopback client** (PKCE + PAR + DPoP ES256), matching the Node helper’s flow - Cloudflare Worker / container deploy not ported (run appview with `gleam run -- appview`) - Same snapshot + remote-helper semantics and collection namespace ## Licence Apache-2.0