After the first three parts of this series, my local setup had grown into a cohesive engineering toolkit: the agyr launcher, a directory-scoped session picker, a 5-color terminal title bar, a lazy-loading MCP proxy, escape-blocking Hooks, global Skills, and a Chrome tab-group extension.

The more tailored the setup got, the harder one worry became to ignore: if this drive dies, or if I spin up a macOS laptop or fresh devbox tomorrow, do I really have to rebuild everything by hand from notes?

I checked existing Antigravity backup tools on GitHub (antigravity-storage-manager, antigravity-sync, etc.). Most of them focus exclusively on the IDE and chat history, missing the CLI-side scripts scattered across ~/.gemini/bin, ~/.agents/skills, ~/.agy-powerline, systemd, and ~/.zshrc. Meanwhile, throwing the whole directory into Git or symlinking it with GNU Stow immediately pollutes the repo with 1.1 GB of conversation databases, 244 MB of node_modules, and transient runtime caches.

This post walks through the backup and bootstrap system with zero third-party dependencies I landed on: manifest.json + sync.py + init.sh, paired with cross-platform script fixes and a daily systemd --user auto-push timer. Day to day, backups happen silently in the background; on a new machine, one ./init.sh brings the entire environment back online.

Allowlist backup, cross-platform porting, and one-click bootstrap architecture for AGY environments


1. Auditing 1.4 GB: What Actually Belongs in Git

Before writing a single line of sync code, I ran du -sh ~/.gemini/* to measure actual disk usage. The breakdown was counterintuitive: out of 1.4 GB, the unique hand-written code and configs that would actually hurt to lose total only 1.1 MB:

Tier Paths & Measured Size Backup Strategy
Core Configs & Scripts (~1.1 MB) ~/.gemini/bin/ (92K)
~/.gemini/config/ (544K, excluding node_modules)
~/.gemini/antigravity-cli/{settings.json,title.py}
~/.gemini/chrome-tab-group-ext/ (20K)
~/.gemini/memory/knowledge-graph.jsonl (108K)
~/.agents/skills/ (excluding cloud synced/)
~/.agy-powerline/{statusline.config.json,install.json,statusline.js}
~/.config/systemd/user/antigravity-cli-daemon.service
Strict allowlist in a private Git repo
Rebuildable Dependencies (244 MB) ~/.gemini/mcp-servers/* Skip node_modules; track only the 4 pairs of package.json + package-lock.json and restore exact versions in ~10s via npm ci
Sensitive Credentials (8 KB) ~/.gemini/secrets/jira.env Never commit; keep only templates/jira.env.example in the repo
Bulk Runtime Data (1.1 GB) ~/.gemini/antigravity-cli/{conversations,brain,log,cache} Exclude from Git; if archival is needed, run cold snapshots separately via sqlite3.backup()

Two easy-to-miss corners turned up during the audit:

  • ~/.agents/skills/: Global custom Skills (code-review, debug-root-cause, git-commit, etc.) live here rather than under ~/.gemini/. Be sure to exclude its synced/ subdirectory, which is automatically synced from the cloud.
  • ~/.gemini/memory/knowledge-graph.jsonl: Cross-session knowledge-graph memory is plain-text JSONL. Tracking it in your private Git repo gives you full version history over your memory graph for free.

2. Decoupling agyr from ~/.zshrc First

Never back up your entire ~/.zshrc verbatim—it is full of machine-specific CUDA paths, proxy settings, and company-specific paths.

I extracted the 80 lines of D-Bus/Keyring setup and the agyr() function from Part 1 into a standalone file at `/.gemini/bin/agyr.zsh(replacing hardcoded/home/user/.local/binpaths with$HOME/.local/binalong the way), leaving only a three-line marker block at the end of~/.zshrc`:

1
2
3
# >>> ai-env agyr >>>
[[ -r "$HOME/.gemini/bin/agyr.zsh" ]] && source "$HOME/.gemini/bin/agyr.zsh"
# <<< ai-env agyr <<<

On any new machine, the restore script idempotently appends or updates only the block between those markers—it never clobbers the host’s existing .zshrc.


3. The Allowlist Syncer: Path Normalization, Multi-Host Merging & Secret-Leak Guard

Rather than pulling in chezmoi (I had no desire to install another tool and memorize .tmpl syntax just to back up AGY), I built manifest.json + sync.py using only the Python standard library. The repo layout reserves top-level files/agy/, files/claude/, and files/codex/ directories so other AI toolchains can drop into the same pipeline later.

Here is the end-to-end data flow:

1. Why Field-Level JSON Merging (strip_keys) Is Mandatory

On a single workstation, whole-file copying looks fine. The moment you sync between a Linux work box and a personal macOS laptop, two files will constantly fight each other:

  • trustedWorkspaces in settings.json (each machine has completely different repository paths);
  • userSettings.cliRemoteControlHostname and remoteControlHostname in config.json (each machine runs its own remote-control instance name).

Declaring strip_keys in manifest.json decouples them cleanly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
"version": 2,
"placeholder": "__HOME__",
"node_placeholder": "__NODE__",
"max_file_bytes": 2097152,
"items": [
{
"id": "gemini-config-json",
"type": "file",
"source": ".gemini/config/config.json",
"repo": "files/agy/gemini/config/config.json",
"templated": true,
"mode": "0600",
"strip_keys": [
"userSettings.cliRemoteControlHostname",
"userSettings.remoteControlHostname"
]
},
{
"id": "gemini-cli-settings",
"type": "file",
"source": ".gemini/antigravity-cli/settings.json",
"repo": "files/agy/gemini/antigravity-cli/settings.json",
"templated": true,
"mode": "0600",
"strip_keys": ["trustedWorkspaces"]
}
]
}

During export, sync.py strips those keys and replaces the local shutil.which("node") binary path (e.g., /usr/bin/node) with __NODE__. During restore, if the target JSON already exists, it merges the target machine’s existing host-specific keys back in and expands __NODE__ to the local Node path (such as /opt/homebrew/bin/node on Apple Silicon macOS):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def restore_file(src: Path, dest: Path, *, templated: bool, replacements: list[tuple[str, str]],
strip_keys: list[str] | None = None, mode: int | None = None) -> None:
raw = src.read_bytes()
if templated and is_text_bytes(raw):
text = apply_replacements(raw.decode("utf-8"), replacements)
raw = text.encode("utf-8")

if strip_keys and dest.is_file() and is_text_bytes(raw):
incoming = json.loads(raw.decode("utf-8"))
existing = json.loads(dest.read_text(encoding="utf-8"))
if isinstance(incoming, dict) and isinstance(existing, dict):
for key_path in strip_keys:
found, val = get_nested(existing, key_path)
if found:
set_nested(incoming, key_path, val)
raw = (json.dumps(incoming, ensure_ascii=False, indent=2) + "\n").encode("utf-8")

write_file_atomic(dest, raw, mode=mode)

2. Four-Layer Pre-Commit Secret-Leak Guard (sync.py check)

Even a private repo shouldn’t run without guardrails. Before git commit, sync.py push enforces four mandatory checks; any hit aborts immediately and fires a desktop alert:

  • Blocked directories & filenames: Rejects any secrets/, node_modules/, .git/, *.env (only *.env.example is allowed), *.key, *.pem, or *.db.
  • 2 MB per-file cap: Stops an accidental SQLite database or stray binary from slipping into an allowlisted directory.
  • Secret pattern regexes: Scans for ghp_/gho_, sk-, AKIA..., PRIVATE KEY, and JIRA_PERSONAL_TOKEN=<non-empty value>.
  • Unnormalized path check: Verifies no raw local $HOME path leaked into any templated entry.

4. Four Cross-Platform Fixes That Make macOS & Windows Actually Work

Once the backup repo was live, I audited every script from Parts 1 and 2 line by line against macOS and Windows. That surfaced four hard Linux assumptions guaranteed to break elsewhere, and I fixed all four:

Original Implementation Failure Mode on Other OSes Cross-Platform Fix
title.sh (bash 4 mapfile + jq + sha256sum) macOS ships bash 3.2 (no mapfile) and lacks sha256sum (uses shasum -a 256) Rewrote as an 80-line zero-dependency title.py and switched settings.json to python3 ~/.gemini/antigravity-cli/title.py
ask-question-state.py only called xdotool / notify-send Silent on macOS; hardcoded /tmp Switched to tempfile.gettempdir() and added a sys.platform == "darwin" branch using osascript for frontmost terminal checks and system notifications
chrome-devtools-mcp-lazy.py hardcoded /usr/bin/google-chrome and import fcntl Chrome lives at /Applications/Google Chrome.app/... on macOS; native Windows Python crashes with ImportError: fcntl Auto-detected Chrome/Docker paths by sys.platform; used fcntl on POSIX and msvcrt on Windows; launched directly via python3 in mcp_config.json and dropped the .sh wrapper
chrome-tab-group-ext had no "key" field Chrome hashes the local absolute directory path to derive the extension ID, so any OS or username change alters the ID—forcing manual copy-paste on each new host Embedded a fixed RSA public key in manifest.json ("key") to permanently pin the Extension ID across hosts

1. Pinning a Permanent ID for an Unpacked Chrome Extension

Most developers don’t realize how Chrome computes IDs for unpacked extensions: without a "key" in manifest.json, Chrome hashes the folder’s absolute path. **Once you embed a Base64-encoded DER RSA public key in "key", Chrome derives the ID strictly from the first 16 bytes of that key’s SHA-256 digest (mapped to a-p)**—yielding the exact same 32-character ID on every OS and directory path:

1
2
3
4
5
6
7
8
9
10
import base64, hashlib, subprocess

# Extract only the public key for manifest.json; discard the private key without writing it to disk
priv = subprocess.check_output(["openssl", "genrsa", "2048"], stderr=subprocess.DEVNULL)
pub_der = subprocess.check_output(["openssl", "rsa", "-pubout", "-outform", "DER"], input=priv, stderr=subprocess.DEVNULL)
b64_key = base64.b64encode(pub_der).decode("ascii")
digest = hashlib.sha256(pub_der).hexdigest()[:32]
ext_id = "".join(chr(ord("a") + int(c, 16)) for c in digest)
print("EXT_ID =", ext_id)
print("PUB_KEY =", b64_key)

Paste the generated PUB_KEY into the "key" field of ~/.gemini/chrome-tab-group-ext/manifest.json, save EXT_ID to extension_id in the same folder, and track both in the backup repo. On every new machine, load the unpacked folder once and you never have to copy-paste extension IDs again.

2. Injection-Safe Native macOS Notifications (ask-question-state.py)

One small detail worth getting right: when firing macOS notifications via osascript from Python, never interpolate the title or body into an AppleScript string with an f-string—a quote inside a project name causes a syntax error or command injection. Pass them cleanly as arguments through on run argv:

1
2
3
4
5
6
7
8
9
if sys.platform == "darwin":
osascript = shutil.which("osascript")
if osascript:
script = "on run argv\ndisplay notification (item 2 of argv) with title (item 1 of argv)\nend run"
subprocess.Popen(
[osascript, "-e", script, title, body],
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
start_new_session=True, close_fds=True,
)

5. One-Click Bootstrap (init.sh) & Daily Scheduled Auto-Push

sync.py restore alone isn’t enough—on a fresh host, I want to run git clone followed by a single ./init.sh and let it handle every automatable step.

init.sh supports --target DIR and --skip-npm specifically for repeated dry-run drills inside empty /tmp directories (an untested backup isn’t a backup):

1
2
3
4
5
6
# Simulate restoring onto a macOS host with existing workspaces and hostname
python3 sync.py restore --target /tmp/test-cross-machine --node-bin /opt/homebrew/bin/node

# Run init.sh twice to verify idempotency (no duplicate .zshrc blocks; exact 700/600/755 permissions)
./init.sh --target /tmp/test-restore --skip-npm
./init.sh --target /tmp/test-restore --skip-npm

Finally, a systemd --user timer solves the inevitable human failure mode of forgetting manual pushes two weeks later:

1
2
3
4
5
6
7
8
9
10
11
# ~/.config/systemd/user/ai-env-backup.timer
[Unit]
Description=Daily backup of local AI/AGY environment

[Timer]
OnCalendar=*-*-* 20:30:00
RandomizedDelaySec=10m
Persistent=true

[Install]
WantedBy=timers.target

Persistent=true ensures that if the machine is powered off at 20:30, the missed run triggers automatically on the next boot. The paired .service unit invokes python3 .../sync.py push --quiet: if nothing has changed, it exits 0 silently; when changes exist (such as updated scripts or memory-graph entries) and pass the secret-leak guard, it commits and pushes over SSH.

After enabling a systemd --user timer, always run systemctl --user start <service> manually at least once instead of trusting list-timers alone. systemd executes units in a stripped-down environment, so a live run is the only way to confirm your SSH key, Git author config, and remote push path actually work unattended.


Series Navigation