Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192//// gitproxy — Git remote helper + appview for AT Protocol PDS snapshots.
import argvimport gitproxy/appviewimport gitproxy/helperimport gitproxy/oauthimport gitproxy/pdsimport gitproxy/remote_specimport gitproxy/sysimport gleam/intimport gleam/result
pub fn main() -> Nil { let args = argv.load().arguments case args { ["appview", ..rest] -> { let port = case rest { [p, ..] -> int.parse(p) |> result.unwrap(8787) [] -> sys.env_or("PORT", "8787") |> int.parse |> result.unwrap(8787) } appview.start(port) } ["login"] -> run_login("") ["login", handle] -> run_login(handle) ["logout"] -> run_logout("") ["logout", handle] -> run_logout(handle) ["whoami"] -> run_whoami("") ["whoami", handle] -> run_whoami(handle) ["remote-helper", url] -> run_remote_helper(url) ["remote-helper", _name, url] -> run_remote_helper(url) [url] -> run_remote_helper(url) [_name, url] -> run_remote_helper(url) _ -> { sys.write_stderr(usage()) sys.halt(2) } }}
fn run_login(handle_arg: String) -> Nil { let handle = case handle_arg { "" -> sys.env_or("APROTO_HANDLE", "") h -> h } case handle { "" -> { sys.eprint("usage: gitproxy login <handle>") sys.eprint(" or set APROTO_HANDLE") sys.halt(2) } handle -> case pds.resolve(handle) { Error(e) -> { sys.eprint(pds.error_message(e)) sys.halt(1) } Ok(identity) -> case oauth.login(handle, identity.pds, oauth.default_scope) { Error(e) -> { sys.eprint(oauth.error_message(e)) sys.halt(1) } Ok(session) -> { sys.write_stdout( "Logged in as " <> session.handle <> " (" <> session.did <> ")\n", ) sys.write_stdout( "Session saved under " <> sys.state_dir() <> "\n", ) sys.halt(0) } } } }}
fn run_logout(handle_arg: String) -> Nil { let handle = case handle_arg { "" -> sys.env_or("APROTO_HANDLE", "") h -> h } case handle { "" -> { sys.eprint("usage: gitproxy logout <handle>") sys.halt(2) } handle -> case oauth.delete_session(handle) { Error(e) -> { sys.eprint(oauth.error_message(e)) sys.halt(1) } Ok(_) -> { sys.write_stdout("Logged out " <> handle <> "\n") sys.halt(0) } } }}
fn run_whoami(handle_arg: String) -> Nil { let handle = case handle_arg { "" -> sys.env_or("APROTO_HANDLE", "") h -> h } case handle { "" -> { sys.eprint("usage: gitproxy whoami <handle>") sys.halt(2) } handle -> case oauth.load_session(handle) { Error(e) -> { sys.eprint(oauth.error_message(e)) sys.halt(1) } Ok(session) -> { sys.write_stdout( session.handle <> "\n" <> "did: " <> session.did <> "\n" <> "pds: " <> session.pds <> "\n" <> "scope: " <> session.scope <> "\n", ) sys.halt(0) } } }}
fn run_remote_helper(url: String) -> Nil { let fallback = sys.env_or("APROTO_HANDLE", "") case remote_spec.parse(url, fallback) { Error(e) -> { sys.eprint(remote_spec.error_message(e)) sys.halt(1) } Ok(spec) -> case pds.live_from_env(spec.handle, pds.default_prefix()) { Error(e) -> { sys.eprint(pds.error_message(e)) sys.halt(1) } Ok(client) -> case helper.run(helper.stdio(), url, client) { Ok(_) -> sys.halt(0) Error(e) -> { sys.eprint(helper.error_message(e)) sys.halt(1) } } } }}
fn usage() -> String { "gitproxy — store git repos as AT Protocol PDS snapshots
Usage: gitproxy login [handle] Browser OAuth login (saves session) gitproxy logout [handle] Delete saved OAuth session gitproxy whoami [handle] Show saved session identity gitproxy remote-helper <url> Run as git remote helper gitproxy appview [port] Browse snapshots over HTTP (default 8787)
Git remotes (install bin/ on PATH): git remote add origin atgit://handle/repo git remote add origin aproto://handle/repo
Auth (first match wins): 1. APROTO_APP_PASSWORD / BLUESKY_APP_PASSWORD (app password) 2. Saved OAuth session from `gitproxy login` 3. Interactive browser OAuth on first push/fetch
Optional: APROTO_COLLECTION_PREFIX default org.latha.gitproxy APROTO_HANDLE fallback handle when URL is incomplete PORT appview port
"}