Local AGY Environment Backup, Cross-Platform Porting & One-Click Bootstrap
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.

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 itssynced/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 /.gemini/bin/agyr.zshagyr() function from Part 1 into a standalone file at `(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 | # >>> 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:
flowchart LR
LOC["Local Files<br/>~/.gemini · ~/.agents · ~/.agy-powerline"] --> EXP["sync.py export"]
EXP --> NORM["Path Normalization<br/>$HOME → __HOME__<br/>node → __NODE__"]
NORM --> STRIP["strip_keys Drops Host Fields<br/>trustedWorkspaces / remoteControlHostname"]
STRIP --> CHK{"sync.py check<br/>Secrets / 2MB Cap / Blocked Names"}
CHK -- "Violation" --> BLOCK["Block Commit + Desktop Alert"]
CHK -- "Pass" --> GIT["Private Git Repo<br/>(ai-env-backup)"]
GIT --> RES["sync.py restore"]
RES --> MERGE["Expand __HOME__/__NODE__<br/>Preserve Existing Host Fields"]
MERGE --> NEW["New Machine / Other Host"]
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:
trustedWorkspacesinsettings.json(each machine has completely different repository paths);userSettings.cliRemoteControlHostnameandremoteControlHostnameinconfig.json(each machine runs its own remote-control instance name).
Declaring strip_keys in manifest.json decouples them cleanly:
1 | { |
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 | def restore_file(src: Path, dest: Path, *, templated: bool, replacements: list[tuple[str, str]], |
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.exampleis 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, andJIRA_PERSONAL_TOKEN=<non-empty value>. - Unnormalized path check: Verifies no raw local
$HOMEpath leaked into anytemplatedentry.
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 | import base64, hashlib, subprocess |
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 | if sys.platform == "darwin": |
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.
sequenceDiagram
participant U as Developer (New Host)
participant I as ./init.sh
participant S as sync.py restore
participant N as npm ci (mcp-servers)
participant D as systemd --user
U->>I: ./init.sh
I->>I: [1/5] Preflight check: python3/git/node/npm/jq/xdotool
I->>S: [2/5] Restore configs, expand __HOME__/__NODE__, inject .zshrc
I->>I: [3/5] Create 0700 secrets/ and place jira.env.example
I->>N: [4/5] Run npm ci across 4 MCP dirs for lockfile-exact install
I->>D: [5/5] Enable remote-control daemon & daily backup timer
I-->>U: Print manual checklist (agy login / fill jira.env / load extension)
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 | # Simulate restoring onto a macOS host with existing workspaces and hostname |
Finally, a systemd --user timer solves the inevitable human failure mode of forgetting manual pushes two weeks later:
1 | # ~/.config/systemd/user/ai-env-backup.timer |
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
- Previous: Project-Level
.agent/Isolation, Dual-Protocol Hooks & Read-Only DB/Redis Plugins - Next: Preventing Multi-Session Chrome Collisions: Tab Ownership Isolation, Desktop Input Mutex & the 6th Status Color
- Series Index: Google Antigravity (AGY) Engineering in Practice · Series Index
- Fundamentals Series: Google Antigravity (AGY) Field Guide · Series Index









