#!/usr/bin/env bash # roam-sync.sh — git auto-sync for the org-roam knowledge base (spec D8). # # Commit any local changes, rebase onto the remote, push. Run by the # roam-sync systemd user timer (scripts/systemd/) every 15 minutes so # Craig's hand edits travel without a manual git step. This script is the # roam repo's only committer (the 2026-06-24 one-git-owner rule): the tree # is chronically dirty from live captures, so a second committer risks # sweeping an in-flight capture into a stray commit. Agents edit the working # tree under the roam-write lock, then trigger this unit (systemctl --user # start roam-sync.service) instead of committing themselves — see # claude-rules/knowledge-base.md and the inbox workflow's roam mode. # # On a rebase conflict: abort the rebase (never leave the repo mid-rebase # for a timer to mangle), keep the local commit, exit 1 so the failure is # visible in `systemctl --user status roam-sync`. # # Usage: roam-sync.sh [repo-path] (default ~/org/roam) set -euo pipefail repo="${1:-$HOME/org/roam}" if ! git -C "$repo" rev-parse --git-dir >/dev/null 2>&1; then echo "roam-sync: $repo is not a git repo" >&2 exit 1 fi cd "$repo" # Commit local changes first so the rebase replays them. if [ -n "$(git status --porcelain)" ]; then git add -A git commit -qm "chore: auto-sync $(date '+%Y-%m-%d %H:%M %z')" fi if ! git pull --rebase -q 2>&1; then git rebase --abort 2>/dev/null || true echo "roam-sync: rebase conflict in $repo — local commit kept, resolve by hand" >&2 exit 1 fi git push -q