Metadata-Version: 2.4
Name: organum-backup
Version: 0.4.0
Summary: Encrypted, restorable snapshots of the places agent state lives - a careful wrapper around restic and your own rclone remote.
Author: Jihoon Jeong
License-Expression: MIT
Project-URL: Homepage, https://ludex-lab.github.io/organum/
Project-URL: Repository, https://github.com/ludex-lab/organum-backup
Keywords: backup,restic,rclone,agent,organism-engineering
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# organum-backup

Encrypted, restorable snapshots of the places agent state lives — a careful wrapper around
[restic](https://restic.net) and **your own** [rclone](https://rclone.org) remote.

> **Status: 0.4.0 (macOS on Apple Silicon).**
> Install via `pip install organum-backup` or `pip install "organum[backup]"`.

Part of the [organum](https://github.com/ludex-lab/organum) family, shipped as its own package:
organum's core stays standard-library-only and read-only; this tool downloads nothing by itself
but drives restic and rclone, reads one Keychain item, and writes when you restore.

## Why it exists

Agents keep their memory, session stores and working state in places git does not protect —
ignored folders, SQLite files, app data. On 2026-11-21 one mistaken `git sparse-checkout` in a
working repository deleted some fifty ignored folders of agent state. Nothing on the machine had a copy
newer than two months. That morning's snapshot from this tool restored them into a separate
folder, and the workspace reopened the same evening.

## Bring your own remote (no bundled OAuth client)

`organum-backup` ships **no OAuth client, no cloud credentials, and no bundled binaries**.
Install `restic` (v0.19+) and `rclone` yourself (e.g. `brew install restic rclone`), then point your
profile's `repository` at either:

1. **A local path** (`"kind": "local"`, `"location": "/Volumes/BackupDrive/organum-backup"`), or
2. **Any `rclone` remote you configure** (`"kind": "rclone"`, `"location": "my-remote:PersonalBackup"`):
   S3, Backblaze B2, Cloudflare R2, SFTP, Google Drive (with your own OAuth client in `rclone config`),
   or any other backend `rclone` supports.

Store a **printable ASCII** repository password in macOS Keychain (non-ASCII items are rejected because
macOS `security -w` hex-encodes them, breaking standalone `restic` compatibility):

```sh
PASS="$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')"
security add-generic-password -s organum.backup -a personal-files -w "$PASS"
# Write $PASS down in your offline password manager / recovery kit before clearing your shell!
```

Initialize and run your first backup:

```sh
organum-backup doctor --profile /abs/path/to/profile.json --rclone-config /abs/path/to/rclone.conf
organum-backup init   --profile /abs/path/to/profile.json --rclone-config /abs/path/to/rclone.conf --execute
organum-backup backup --profile /abs/path/to/profile.json --rclone-config /abs/path/to/rclone.conf --execute
```

## What it does

- `backup` — a restic snapshot of the folders you list, to a restic repository on a local path
  or on any rclone remote you configured.
- `source_capture` (optional) — before each backup, a private stable copy of live files that
  cannot be read safely in place: SQLite databases through the online-backup API (committed WAL
  content included, `quick_check` verified, companion `-wal`/`-shm`/`-journal` races tolerated),
  ordinary files as bounded stable copies.
- `snapshots`, `ls`, `restore` — list snapshots; look inside one (`ls --snapshot ID --path /a/folder`
  lists that folder's own entries); restore a whole snapshot, or one folder of it with
  `--path`, into a **new** folder.
  On a new machine, where the profile's capture plan is not present, `restore --recovery`
  takes no target: it restores into a new folder under `<profile folder>/recovery/` (private,
  made by the tool) and the receipt names that folder.
- `rollback-check` — read-only: one sheet of what an older version (v0.3.1) would not know if you went
  back to it — both state files, whether the last success is bound to a saved receipt, how far the old
  state is behind, lock files, the capture marker, the two LaunchAgent files. Exit 0 means no line asks
  for a look, 2 that one does (`attention`) or that the sheet could not be made (`blocked`).
- `launchd-template` — prints the LaunchAgent plist (`organum.backup.<profile>.<device>`,
  `Disabled=true`, installed `organum-backup` absolute entry point, private log paths) without writing anything.
- `schedule-plan` — read-only: inspects LaunchAgent files (plus `launchctl print` with `--ask-launchd`
  and `ps` with `--ask-processes`) and prints the exact ordered commands to install or switch cleanly.
- `run-if-due` — a schedule decision for launchd: daily time, defer on battery, catch up.
  After three failed backups the schedule halts (`status: halted`, exit 2) until you run `resume --execute`.
- `organum-backup-desk` — a loopback-only bilingual (English / Korean) web desk for the same actions.
  `GET /` contains **no session secret**; startup prints a single-use terminal code (valid 120s, max 5 tries)
  exchanged via `POST /bootstrap` for an in-memory session secret. Exits automatically after 15 minutes idle
  (held while a job runs). Real execution is **off by default** (pass `--allow-execute` to enable).

## Threat model

- **What `organum-backup` protects against:**
  - Accidental local deletion, repo corruption, or silent SQLite WAL loss (including `git sparse-checkout`
    or tool bugs wiping ignored folders).
  - Browser-side cross-site attacks against `organum-backup-desk` (loopback-only bind, strict `Host`/`Origin`/
    `Sec-Fetch-Site`, CSP `default-src 'none'`, zero `innerHTML`, no secret in `GET /`, single-use terminal
    bootstrap code, memory-only session, 15-minute idle exit).
  - Other user accounts on the same Mac (private `0700` state/staging/log/recovery folders; terminal code
    is never written to disk or logs; Keychain password passes only via subprocess environment, never argv
    or receipts).
  - Overwriting live files during restore (`--overwrite never`, target must not exist and must not overlap
    sources, profile, state, or Keychain).
- **What it does NOT protect against:**
  - A process running under the **same macOS user account** that can read your terminal, memory, or login
    Keychain — such a process can already read the backup password and modify your files directly, and the
    desk does not claim otherwise.
  - Loss of the encryption password (there is no backdoor or key escrow).
  - Host-wide atomic snapshots across unrelated apps (each SQLite DB is a verified online backup; ordinary
    files are bounded stable copies captured sequentially).

## Restore with restic alone (no vendor lock-in)

Your snapshots are standard `restic` repositories. Even without `organum-backup` installed, you can
restore directly on any machine with `restic` (and `rclone` if remote):

```sh
export RESTIC_PASSWORD="$(security find-generic-password -s organum.backup -a personal-files -w)"
# Local repository:
restic -r /path/to/repo/personal-files/mac-primary snapshots
restic -r /path/to/repo/personal-files/mac-primary restore latest --target /path/to/new-empty-folder
# Or rclone remote:
restic -o rclone.args="serve restic --stdio --config /path/to/rclone.conf" \
  -r rclone:my-remote:PersonalBackup/personal-files/mac-primary restore latest --target /path/to/new-empty-folder
```

## Design choices worth knowing

- The repository password goes from the macOS Keychain to the engine's environment only —
  never to argv, logs, receipts or the browser.
- Engines run without a shell, in a fixed minimal environment, against a strictly validated
  profile (exact keys, duplicate keys refused, symlinked paths refused).
- Nothing is deleted automatically. Retention is recorded, not enforced.
- One run at a time, by a `flock` on a file that is never removed; the engine inherits it.
- Success is evidence, not an exit code: one final JSON summary and a full snapshot id.
- Every real `backup`, `init`, `restore`, `resume`, and halt (once) leaves an immutable receipt in
  `<profile folder>/.organum-backup-state/receipts/<repository key>/`.

## Develop

```sh
PYTHONPATH=src python3 -m unittest discover -s tests      # Python >= 3.11
node tests/test_ui.cjs && node tests/test_bridge_ui.cjs    # Node, synthetic DOM
PYTHONPATH=src python3 tools/reproduce_wal.py              # 442 WAL databases at a file limit of 256
```

One opt-in test drives a real restic binary against a throwaway local repository (no Keychain,
no rclone, no network):

```sh
ORGANUM_BACKUP_RESTIC=/path/to/restic PYTHONPATH=src python3 -m unittest discover -s tests -p 'test_real_restic.py'
```

## Origin and credits

Built in the Yeoul village as "personal backup" (v0.1.1 – v0.3.1); this repository starts from
v0.3.1 as received. See [CREDITS.md](CREDITS.md) and [records/](records/).

MIT License.
