Skip to main content
Glama
README.md
# repo-snapshot

Export your local Git repositories to a timestamped, browsable snapshot on a cloud drive, once a
day or on demand. Chat assistants and other tools that can read the drive but not your machine
(or that hit Git host API limits) can then read your code from the snapshot.

Each run, in parallel and per repository:

1. fetches and safely fast-forwards clean default branches (dirty, diverged or locked trees are
   never touched, only reported),
2. exports committed content with `git archive` as `zips/<repo>.zip` plus a browsable
   `repos/<repo>/` tree with identical contents and a SHA-256 for every zip,
3. blocks any repo that contains secret-looking filenames or a `gitleaks` finding before upload,
4. uploads to a staging folder, promotes it atomically with a server-side rename, archives the
   previous snapshot and applies daily/weekly/monthly retention.

One failing repo never stops the others. Only run-level failures (no `rclone`, expired drive
login, nothing exported) abort the run, and they leave the previous snapshot untouched.

It works with no AI client at all. The same operations are also an MCP server and a portable
skill for Claude Code, Codex and Antigravity.

## Requirements

Python 3.11+, `git`, [`rclone`](https://rclone.org) with a configured remote (credentials stay in
rclone), and [`gitleaks`](https://github.com/gitleaks/gitleaks) (required by default; set
`secret_scan.required = false` to fall back to the filename guard only).

## Install

```bash
uv tool install repo-snapshot            # CLI only
uv tool install 'repo-snapshot[mcp]'     # CLI plus the MCP server
```

## Quick start

```bash
mkdir -p ~/.config/repo-snapshot
cp config/repo-snapshot.template.toml ~/.config/repo-snapshot/config.toml   # then edit it
repo-snapshot doctor          # tools, config, drive reachability, free space
repo-snapshot run --dry-run   # plan only: nothing is written locally or remotely
repo-snapshot run             # the real thing
```

Other commands: `sync`, `export [--no-upload --output-dir DIR]`, `archive [--dry-run]`,
`status`, `config show [--effective]`, `logs path [--latest]`, `logs prune`. Every command
that reports results accepts `--json`.

### Exit codes

| Code | Meaning |
|---:|---|
| 0 | Everything synced, exported, scanned, uploaded and promoted |
| 2 | Usage error |
| 3 | Run-fatal: missing tool, drive auth or reachability, no disk, peer run active, nothing exported, upload or promotion failure, or a secret under `on_finding = "fail_run"` |
| 10 | Partial success: a snapshot was promoted but at least one repo needs attention (dirty, diverged, locked, sync error, export failure, blocked secret) or housekeeping failed |
| 78 | Configuration error (unknown key, bad value, missing or malformed file) |

A systemd unit should treat `10` as success-with-warnings (`SuccessExitStatus=0 10`).

## Configuration

Layers, lowest to highest precedence: packaged defaults, machine defaults (`[logging]` only),
`~/.config/repo-snapshot/config.toml`, `--config PATH` or `REPO_SNAPSHOT_CONFIG`,
`REPO_SNAPSHOT_SECTION__KEY` environment variables, then repeatable `--set section.key=value`.
Unknown keys are errors. See `config/repo-snapshot.template.toml` for every setting.

Repository selection is fail-closed: `exclude_repos` globs and symlinks are rejected before any
Git read, `allowed_remote_owners` and `denied_remote_patterns` filter on the origin URL, and
`include_repos` only bypasses the owner allowlist.

## Logs

`run`, `sync`, `export`, `archive`, `status`, `doctor` and `mcp serve` each write a trace-level log to
`~/.logs/repo-snapshot/YYYY/MM/DD/repo-snapshot-<command>-<pid>-<UTC>.log` (mode 0600), appends to
`.runs.jsonl`, updates `latest`, and redacts environment secrets and token shapes before writing.
`repo-snapshot logs prune` applies the `[logging.retention]` budget. The last run summary is in
`~/.local/state/repo-snapshot/last-run.json`.

## MCP and client plugins

```bash
repo-snapshot mcp serve --transport stdio        # tools: snapshot_run / sync / archive / status / doctor
repo-snapshot mcp call snapshot_status           # same dispatcher, no SDK needed
repo-snapshot plugin generate --host claude --out ./plugin-claude   # or codex, agy
```

`snapshot_archive` defaults to `dry_run = true`. Over stdio, logs go to stderr so stdout carries
only protocol frames. The streamable-HTTP transport binds loopback only, validates `Origin` and
requires a per-run bearer token written to a 0600 file in the state directory. Generated plugins
contain thin manifests that launch the installed `repo-snapshot`; they ship no `bin/` directory.

## Scheduling

`repo-snapshot run` is a plain command with stable exit codes, so any scheduler works. With
systemd, a user timer with `Persistent=true` and `SuccessExitStatus=0 10` is enough.

## Development

```bash
uv sync --all-extras
uv run pytest -q
uv run ruff check .
python scripts/oss_hygiene.py        # no private ids, hosts or paths in tracked files
```

MIT licensed.