Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 75 additions & 1 deletion .claude-config/backup/daily-sync.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
# Daily sync: (1) back up the OPS repo to GitHub, (2) pull every project
# repo under PROJECTS/ so all clones stay current across machines, (3)
# garbage-collect local branches and worktrees whose PRs merged (branch-gc).
# garbage-collect local branches and worktrees whose PRs merged (branch-gc),
# (4) lapse setup rulings past their review date (desk lapse), then refresh the
# desk check's cache (bin/desk), the one line the session briefing shows.
# Runs via Linux cron / Windows Task Scheduler ("OPS Daily Backup", 09:00).
#
# Design:
Expand Down Expand Up @@ -286,8 +288,80 @@ gc_branches() {
fi
}

# --- Stage 4a: setup rulings that lapse (desk lapse) --------------------------------
# A ruling written at setup as a temporary measure (Kind `setup`, with a `review by` date 14
# days out) moves out of force after its review date unless its owner says keep. `desk lapse`
# moves each such row to CONTEXT/standing-orders-archive.md in one commit of those two files and
# leaves a one-time notice for the session briefing. Before the check, so the check reads the
# table the lapse left. desk itself decides what applies: a table with no Kind column (not
# migrated), no table, or the owner's own layout is "nothing to do" and nothing is touched,
# because only desk's parser can read the table. Non-fatal, matching the stages above: a refusal
# (an uncommitted edit to a due ruling's file, a git operation in progress, the sync's lock, an
# executable commit hook, since desk commits with plumbing, which runs none, and hooks are never
# bypassed) leaves the row in force and the check then shows it as past its review date. 120 s
# covers desk's 30 s flock and 10 s index waits.
run_lapse() {
local script="$OPS_DIR/.claude-config/bin/desk"
local lib="$OPS_DIR/.claude-config/hooks/hooklib.sh" py to rc out line
if [ ! -r "$script" ]; then
log "LAPSE: WARN desk unreadable at $script, skipping"
return 0
fi
if [ ! -r "$lib" ] || ! . "$lib" || ! py="$(hook_python)"; then
log "LAPSE: WARN Python 3 resolver unavailable, skipping"
return 0
fi
to="$(hook_timeout)" || to=""
if [ -n "$to" ]; then
out="$("$to" -k 5 120 "$py" "$script" lapse --root "$OPS_DIR" 2>&1)"; rc=$?
else
out="$("$py" "$script" lapse --root "$OPS_DIR" 2>&1)"; rc=$?
fi
while IFS= read -r line; do [ -n "$line" ] && log "LAPSE: $line"; done <<< "$out"
[ "$rc" -eq 0 ] || log "LAPSE: WARN desk lapse exited $rc (see output above for the outcome)"
return 0
}

# --- Stage 4b: the desk check -------------------------------------------------------
# desk (bin/desk) is a read-only check of the AI context on this box: stale core files, dead
# references in the always-loaded files, ruling rows, duplicate memory pools. One scan a day
# refreshes desk-last.json in ${OPS_STATE_DIR:-~/.local/state/ops}, the cache the session
# briefing reads; the briefing never scans. Last, so it reads the tree the pull, the cleanup and
# the lapse left. Non-fatal: a check that errors must not fail the sync. Not silent either: the
# outcome is one line in sync.log, and a failed scan leaves the last good cache untouched (desk
# never replaces a cache on error), so the briefing ages it out at 8 days instead of showing a
# false clean. The 300 s cap stops a hung git read from holding the sync.
run_desk() {
local script="$OPS_DIR/.claude-config/bin/desk"
local lib="$OPS_DIR/.claude-config/hooks/hooklib.sh" py to line rc
if [ ! -r "$script" ]; then
log "DESK: WARN desk unreadable at $script, skipping"
return 0
fi
if [ ! -r "$lib" ] || ! . "$lib" || ! py="$(hook_python)"; then
log "DESK: WARN Python 3 resolver unavailable, skipping"
return 0
fi
to="$(hook_timeout)" || to=""
log "DESK: running desk"
if [ -n "$to" ]; then
"$to" -k 5 300 "$py" "$script" --root "$OPS_DIR" >/dev/null 2>> "$LOG_FILE"; rc=$?
else
"$py" "$script" --root "$OPS_DIR" >/dev/null 2>> "$LOG_FILE"; rc=$?
fi
if [ "$rc" -ne 0 ]; then
log "DESK: WARN desk exited $rc (the previous cache is kept; see output above)"
return 0
fi
line="$("$py" "$script" --root "$OPS_DIR" --line 2>/dev/null)" || line=""
log "DESK: ${line:-nothing to show}"
return 0
}

log "===== daily-sync start ====="
backup_ops
sync_projects
gc_branches
run_lapse
run_desk
log "===== daily-sync complete ====="
Loading