feat(tools): scheduled USER-tree backup to a private repo (Linux scheduling)#1663
Open
elhoim wants to merge 1 commit into
Open
feat(tools): scheduled USER-tree backup to a private repo (Linux scheduling)#1663elhoim wants to merge 1 commit into
elhoim wants to merge 1 commit into
Conversation
…private repo
ConfigSystem.md documents the USER tree as its own private GitHub repo kept in
sync by ~/.claude/.git/hooks/pre-push. That trigger only fires when the operator
pushes the SYSTEM tree, and it presupposes ~/.claude is itself a git repo, which
is not true of every install. On those installs the USER tree — identity, TELOS,
projects, operational rules — has no off-machine copy at all, and
BackupBeforeUpgrade.sh does not cover it (it stores LIFEOS/USER as a bare
symlink entry, by design).
BackupUserData.ts is the trigger-independent half: a scheduled job that commits
and pushes the USER tree when it changed and no-ops when it didn't. It carries
the same boundary gates the two-repo-push workflow applies, in tool form.
Four refusals, all fail-closed:
1. Remote visibility re-checked every run via gh; anything other than a
confirmed PRIVATE blocks the push (a repo can be flipped public later).
2. Remotes named LifeOS, or owned by the upstream, rejected outright.
3. Staged files scanned for 8 classes of secret before the commit is created.
4. Exclusive lock, so it cannot race itself or a manual push.
Scheduling is Linux-only: the tool shells out to git and gh and nothing else,
but the documented schedule is a Linux user crontab and that is the only
scheduler it has been verified on. macOS operators should wrap the same command
in a launchd agent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
LIFEOS/TOOLS/BackupUserData.ts, a scheduled job that mirrors the USER tree to its private GitHub repo, plus its README and aConfigSystem.mdsection documenting it.Why
ConfigSystem.md§ Two-repo sync specifies the USER tree as its own private repo, kept in sync by~/.claude/.git/hooks/pre-push. That trigger has two preconditions: the operator has to actually push the SYSTEM tree, and~/.claudehas to be a git repo. Neither holds on every install.Where they don't hold, the USER tree — identity, DA identity, TELOS, projects, operational rules — has no off-machine copy at all.
BackupBeforeUpgrade.shdoesn't close that gap either: it archives the SYSTEM tree and storesLIFEOS/USERas a bare symlink entry, deliberately.This is the trigger-independent half of the same mechanism, not a replacement for the pre-push hook. On an install where the hook works, the two compose: the hook syncs on push, this syncs on a schedule.
The four refusals
Fail-closed throughout; each is a non-zero exit with a logged reason, never a silent skip.
gh repo view --json visibility,isPrivate.PUBLIC, an API error, an unparseable answer, or a missingghall block the push. Per-run rather than once at setup, because a repo can be flipped public at any time.LifeOS(any case) or whose owner is the upstream is rejected outright. USER data never goes near the public release path.When nothing changed it exits
0withstatus=noopand creates no commit, so history records real change rather than the clock. One JSONL line per run lands inMEMORY/OBSERVABILITY/user-backup.jsonl.Scheduling is Linux-only
Worth stating plainly, since it's the main limit on this PR. The tool itself is platform-neutral: it shells out to
gitand the GitHub CLI and nothing else. The schedule is a Linux user crontab, and that is the only scheduler it has been verified on. macOS operators should wrap the same command in alaunchdagent (the shape LifeOS already uses forcom.lifeos.pulse.plist) rather than assuming the crontab path works. The README and the doc section both say so.Verification
Verified on Linux against a real private repo, not a fixture:
gh api; deleted it, ran, the same call returned 404.HEADidentical and created no commit.--check-visibilityagainst a real public repo refused (exit 1); against a private one, passed.danielmiessler/LifeOSand a fork'sLifeOS, accepted a normal user-data slug.status=locked.env -iwith a stripped cron environment. No auth or PATH failures.Not verified on macOS or with
launchd— see above.Notes for review
.env*, key material, and the credentials directory are excluded, and credentials stay in~/.claude/.envas they do today.LIFEOS_GH_BINexists because the GitHub CLI may be a wrapper rather than a plainghonPATH(e.g. when LifeOS runs as a system user distinct from the operator's own account).