caelum0x 44f9f21329
Some checks failed
ci / cargo test (abacus) (push) Has been cancelled
ci / cargo test (agent-runtime) (push) Has been cancelled
ci / cargo test (context-passport) (push) Has been cancelled
ci / cargo test (game-economy) (push) Has been cancelled
ci / cargo test (ledgerline) (push) Has been cancelled
ci / cargo test (mint) (push) Has been cancelled
ci / cargo test (rago) (push) Has been cancelled
ci / cargo test (relay) (push) Has been cancelled
ci / cargo test (toolgate) (push) Has been cancelled
ci / cargo test (turnstile) (push) Has been cancelled
ci / cargo test (vend) (push) Has been cancelled
ci / node suites (push) Has been cancelled
feat(RIT-RET): full account export, one click or rit export
New apps/rithub-export: one click at https://rithub.dev/export, or
`rit export` from the CLI, produces a downloadable .tar.gz of every repo
the signed-in account owns -- real `git bundle --all` per repo (+ wiki
if any; `git clone <bundle>` reproduces the exact commits, no history
rewriting), plus issues/pulls/releases+assets as documented JSON (the
engine's own public API object shape, each issue/pull carrying its full
comment thread). manifest.json indexes per-repo files + counts.

- Two ways in, one job underneath: the web page authenticates via a
  one-time real OAuth2 (PKCE) consent, same "no pasted tokens" pattern as
  apps/rithub-approvals (own encrypted-at-rest token store, own data
  dir/key); `rit export` brings its own Bearer token, no browser round
  trip. Git traffic goes loopback-to-the-engine, never the public domain
  (same reasoning as the 2026-11-26 import-timeout fix).
- One export at a time, box-wide (jobStore.mjs's boxTooBusy/
  hasActiveJob, os.loadavg() read directly) -- a request while busy gets
  a clear 503, matching railyard-box's own "no heavy job unless load1<6"
  rule instead of silently queuing a pile-up.
- Opt-in nightly copy, kept 7 days on our side (nightly.mjs): a sweep
  every 24h exports every opted-in login with a stored token, then prunes
  every archive past the retention window. An opt-in copy to the user's
  OWN storage target needs their own credentials -- documented as a real,
  separate follow-up, not built this pass (nightly.mjs's own comment has
  the exact extension point).
- Scope stated plainly: every repo the account *owns*, not an org repo
  it merely has access to -- org export is a natural follow-up.

Real bug found live while building this, fixed before shipping: the
token used to travel to `git clone` as a `-c http.extraHeader=...` argv
element, which Node's own child_process error message echoes back
verbatim the moment a clone legitimately fails (e.g. a repo with no wiki
yet) -- putting the raw token into this job's own persisted log, served
back through /export/api/jobs. Fixed via GIT_CONFIG_KEY_0/VALUE_0 env
vars instead of argv (git >=2.31); jobStore.mjs's appendLog also redacts
any token-shaped substring as an independent second layer. Confirmed live
after the fix: the exact same failing clone (nonexistent wiki) no longer
has the token anywhere in its error text or the on-disk index.

`rit export` added (packages/rithub-cli/src/export.mjs); CLI bumped
0.3.2 -> 0.3.5 across this pass and the sibling RIT-ACT commit
(--agent/export flags + README), published, confirmed live.

Live-verified on rithub.dev with a throwaway mail.tm test account, 2
repos, an issue+comment, a PR+comment, and a release+asset: `rit export`
produced an archive whose manifest counts (2 repos, 1 issue, 1 pull, 1
release, 1 asset) matched the live API exactly; `git clone` from both
repo bundles reproduced byte-for-byte the real branch SHAs (including a
non-default branch carrying an open PR); the issue/PR JSON carried the
real comment bodies; the release asset's downloaded bytes matched the
uploaded file exactly. Re-ran the same flow from the web UI (gstack):
one-time Authorize, "Export now" click, Download -- same result. A
different account's /export/api/jobs correctly saw an empty list (no
cross-account leak). Test account and all artifacts purged after.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-12-01 15:39:46 +03:00

62 lines
3.3 KiB
Markdown

# rithub-export
RIT-RET full account export (`plans/railyard.md` queue item 4, 2026-12-01).
One click at `https://rithub.dev/export`, or `rit export` from the CLI,
produces a downloadable `.tar.gz` of every repo the signed-in account
owns:
- `repos/<name>/repo.bundle` -- a real `git bundle --all` (every ref).
`git clone <bundle>` reproduces the exact commits, byte-for-byte, no
history rewriting. `wiki.bundle` alongside it when the repo has a wiki
with at least one page.
- `repos/<name>/issues.json`, `pulls.json`, `releases.json` -- the
engine's own public API object shape (the same one `/api/swagger`
documents), each issue/pull carrying its full comment thread
(`comments_full`), each release carrying its assets with a
`local_file` pointer into `repos/<name>/assets/<tag>/<filename>`.
- `manifest.json` -- one small index: per-repo file pointers and counts,
plus account-wide totals.
Two ways in, one job underneath (`src/exportJob.mjs` + `src/runner.mjs`):
the web page authenticates via a one-time real OAuth2 (PKCE) consent,
same "no pasted tokens" pattern as `apps/rithub-approvals`
(`src/oauthTokenStore.mjs`, AES-256-GCM at rest, own data dir/key, never
shared with another service); `rit export` just brings its own Bearer
token, no browser round trip needed. Git traffic goes loopback-to-the-
engine (`RITHUB_ENGINE_HOST`/`RITHUB_ENGINE_PORT`), never the public
domain -- same reasoning as the 2026-11-26 import-timeout fix.
**Scope, stated plainly:** every repo the signed-in account *owns* --
not an org repo it merely has collaborator/member access to. Account-
level export defaulting to someone else's org repo would be the wrong
default; an org-scoped export is a natural follow-up, not this pass's
job.
**One export at a time, box-wide** (`src/jobStore.mjs`'s `boxTooBusy`/
`hasActiveJob`): `git clone --mirror` across every repo an account owns
is exactly the kind of job railyard-box's standing "no heavy jobs unless
load1 < 6 and nothing else is building" rule exists for. A request while
busy gets a clear `503`, not a silently queued pile-up.
**Nightly copy, opt-in, kept 7 days on our side** (`src/nightly.mjs`,
`RITHUB_EXPORT_NIGHTLY_RETENTION_DAYS`): a sweep once every 24h runs a
real export for every opted-in login with a usable stored token, then
prunes every archive (manual or nightly) older than the retention
window. The task's other option -- an opt-in copy pushed to the user's
own storage target (S3, rsync, etc.) -- needs that user's own
credentials, a real secrets-handling surface this same-day pass
documents but does not build; `nightly.mjs`'s bottom comment has the
exact extension point for a future pass.
**A real bug found live while building this, fixed before shipping:**
the token used to travel to `git clone` as a `-c http.extraHeader=...`
argv element -- which Node's own child_process error message echoes
back verbatim the moment a clone legitimately fails (e.g. a repo with no
wiki yet). That put the raw token into this job's own persisted log,
served back through `/export/api/jobs`. Fixed in `exportJob.mjs`'s
`gitAuthEnv`: the token now travels via `GIT_CONFIG_KEY_0`/
`GIT_CONFIG_VALUE_0` env vars (git >=2.31) instead of argv, so it can
never appear in a thrown error's command-line text; `jobStore.mjs`'s
`appendLog` also redacts anything still shaped like a bearer/token value
as a second, independent layer.