Let the editor request an immediate notes sync
Deploy with Docker Compose / deploy (push) Successful in 9s

Waiting out SILVERBULLET_GIT_INTERVAL is annoying when you want a note on
another device now. The sidecar's sleep is now split into short slices that
watch sync-request.md in the vault; when its modification time changes, it
syncs on the spot. The "Sync notes" toolbar button in the vault's Sync.md
writes that file.

The trigger file is deliberately never deleted here. Deleting it would fight
SilverBullet's client sync, which would re-upload its cached copy and produce
a delete/recreate loop while a tab is open; only the mtime is significant. It
is gitignored in the notes repo, so it never reaches a commit.

Signalling through a file in the shared vault rather than shell.run or a
docker socket: both containers already have that directory, so this adds no
capability to either, which is the same reasoning behind using a sidecar
instead of SilverBullet's own shell backend.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BCQFvkvorAw1xwhd5gL2qZ
This commit is contained in:
2026-09-22 13:40:51 +01:00
co-authored by Claude Opus 5
parent e5e43f3e0b
commit 507bdb5939
+35 -3
View File
@@ -6,11 +6,22 @@
# deliberately a separate container rather than SilverBullet's own shell backend:
# the editor is protected only by the nginx admin gate, and enabling a shell
# backend would hand anyone past that gate command execution inside the container.
#
# ON-DEMAND SYNC
# Waiting out the interval is annoying when you want a note on another device
# now, so the editor can ask for an immediate sync. The "Sync notes" button in
# SilverBullet (defined in the vault's own Sync.md) writes a timestamp to
# TRIGGER_FILE; this script notices the modification time change and syncs on
# the spot. The file is gitignored in the notes repo and is never deleted here
# — deleting it would fight SilverBullet's client, which would re-upload its
# cached copy and cause a delete/recreate loop. Only the mtime matters.
set -u
SPACE=/space
INTERVAL="${SYNC_INTERVAL:-300}"
TRIGGER_FILE="$SPACE/${SYNC_TRIGGER_FILE:-sync-request.md}"
POLL=2
log() { echo "[git-sync] $(date -Iseconds) $*"; }
@@ -24,9 +35,12 @@ if [ ! -d "$SPACE/.git" ]; then
fi
cd "$SPACE" || exit 1
log "watching $SPACE every ${INTERVAL}s"
while true; do
trigger_mtime() {
[ -f "$TRIGGER_FILE" ] && stat -c %Y "$TRIGGER_FILE" 2>/dev/null || echo ""
}
sync_once() {
git add -A
if ! git diff --cached --quiet; then
if git commit -q -m "notes: $(date -Iseconds)"; then
@@ -40,6 +54,24 @@ while true; do
git pull --rebase --autostash -q || log "WARN: pull failed (conflict, auth or network)"
git push -q || log "WARN: push failed (conflict, auth or network)"
fi
}
sleep "$INTERVAL"
last_trigger=$(trigger_mtime)
log "watching $SPACE every ${INTERVAL}s (on-demand via ${TRIGGER_FILE#$SPACE/})"
while true; do
sync_once
# Sleep in short slices so an on-demand request is picked up quickly.
waited=0
while [ "$waited" -lt "$INTERVAL" ]; do
sleep "$POLL"
waited=$((waited + POLL))
now=$(trigger_mtime)
if [ -n "$now" ] && [ "$now" != "$last_trigger" ]; then
last_trigger="$now"
log "sync requested from the editor"
break
fi
done
done