feat(scripts): auto-sync — real-time bidirectional git sync per repo#41
Open
abdout wants to merge 3 commits into
Open
feat(scripts): auto-sync — real-time bidirectional git sync per repo#41abdout wants to merge 3 commits into
abdout wants to merge 3 commits into
Conversation
Adds a background service that watches every databayt repo at ~/<name>
and keeps it in sync with origin without manual intervention. Local
commits push within ~2s; remote commits pull within ~60s.
The design implements the user-chosen "real-time + polling" model:
Push side (real-time):
FileSystemWatcher (Windows) / fswatch (macOS) / inotifywait (Linux)
on .git/refs/heads. On change → 2s debounce → git push.
Pull side (polling):
Every 60s per repo: git fetch + git pull --rebase. Skipped when
the working tree is dirty (in-flight work is sacred). On conflict,
git rebase --abort is called and the failure logged.
Per-repo isolation:
One repo failing (auth, no upstream, force-push) doesn't stop the
others — each iteration of the loop catches its own exceptions.
Files:
.claude/scripts/auto-sync.ps1 193 LOC — Windows runtime
.claude/scripts/auto-sync.sh 171 LOC — macOS/Linux runtime
.claude/scripts/auto-sync-install.ps1 110 LOC — Task Scheduler register
.claude/scripts/auto-sync-install.sh 143 LOC — launchd / systemd-user
content/docs/auto-sync.mdx full user-facing doc page
Install (user-scoped, no admin/sudo):
# Windows
& "$env:USERPROFILE\.claude\scripts\auto-sync-install.ps1" -Install
# macOS / Linux
~/.claude/scripts/auto-sync-install.sh --install
Service registration:
Windows: Task Scheduler 'At logon' trigger, restart on failure 3×,
allowed on battery, no execution time limit, runs hidden.
macOS: launchd LaunchAgent with KeepAlive=true + RunAtLoad=true.
Linux: systemd --user service with Restart=always + RestartSec=10,
WantedBy=default.target.
Logs at ~/.claude/logs/auto-sync-<date>.log with structured levels
(INFO / PUSH / PULL / WARN / ERROR) per repo per event.
Reads ~/.claude/memory/repositories.json for the repo list; falls
back to the canonical 11-repo set if absent. Works with both the
old ~/oss/<name> layout and the new ~/<name> layout (PR #38).
Both scripts validated: `bash -n` clean, PowerShell parse clean.
Refs #28
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PowerShell's [CmdletBinding()] auto-provides -Verbose as a common parameter, so declaring [switch]$Verbose explicitly raises a runtime 'parameter defined multiple times' error on invocation. Drop the explicit declaration and detect verbose mode via $VerbosePreference — the user-facing flag name (-Verbose) is unchanged. Verified on a live machine: -DryRun -Once -Verbose -PollInterval 5 now runs cleanly, discovers all 11 repos at ~/<name>, completes one poll cycle, and exits without warnings. Refs #28 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace em-dash/middle-dot/box-drawing/emoji chars with ASCII equivalents. PS 5 (powershell.exe used by Task Scheduler) reads .ps1 as Windows-1252 without a BOM, so UTF-8 multibyte chars caused 'string is missing terminator' parse errors and the task exited 1 right after launch. Verified end-to-end on Windows: powershell.exe runs clean, scheduled task State=Running, 11 repos tracked. Refs #28 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
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.
Summary
A background service that keeps every databayt repo at
~/<name>continuously synced with GitHub. Local commits push within ~2s; remote commits pull within ~60s. No manualgit push/git pullfor the common case.Implements the "Real-time (file watcher)" sync model — the option you picked in the design question.
How it works
Per-repo isolation — one repo failing (no upstream, auth broken, force-push) never stops the others. Each iteration catches its own exceptions.
Working-tree-sacred — if
git status --porcelainshows changes, the pull is skipped. Your in-flight work is never touched.Conflict-safe pull —
git pull --rebasefails →git rebase --abort→ log error → next cycle tries again.Files added
.claude/scripts/auto-sync.ps1.claude/scripts/auto-sync.sh.claude/scripts/auto-sync-install.ps1.claude/scripts/auto-sync-install.shcontent/docs/auto-sync.mdxTotal: 757 lines added across 5 new files, zero existing files modified.
Install (user-scoped, no admin/sudo)
Configuration (flags)
-PollInterval/--poll-interval-Debounce/--debounce-DryRun/--dry-run-Once/--once-Verbose/--verboseLogs
Format:
[HH:MM:SS] [LEVEL] [repo-name ] messageStored at
~/.claude/logs/auto-sync-<date>.log. Levels:INFO,PUSH,PULL,WARN,ERROR.What it does NOT do
The doc page has a "what auto-sync does NOT do" section that's explicit about this — auto-sync is a co-pilot for the linear-commit common case, not a magic merger.
Relationship to
maintainmaintainruns once daily at 09:00 (full doctor + sync-repos burst).auto-syncruns continuously between maintain runs. Run both — they complement each other.Test plan
[PSParser]::Tokenizeclean on both scriptsbash -nclean on both scripts~/kun, see PUSH log within ~5slaunchctl listshows the agentsystemctl --user status kun-auto-syncshows activeDependencies
Targets
maindirectly. No dependency on the bootstrap chain (PRs 29-36, 37, 38). Works with both~/oss/<name>(current main) and~/<name>(PR #38) layouts — reads~/.claude/memory/repositories.jsonfirst, falls back to canonical list otherwise.Why this completes the "auto-synced" requirement
The user requirement was: "I expect all databayt org repos to be in the root and synced with github with auto synced." PR #38 puts them at root. This PR makes them auto-synced. Together they fulfill the requirement for every teammate.
Refs #28
🤖 Generated with Claude Code