dsh-memory-sync: Bidirectional sync of git memory directory at DSH startup

Preface

DSH’s memory directory defaults to ~/.dsh/memories. If one machine is running continuously and another laptop is used occasionally, relying on manual git pull / git push to synchronize is prone to omissions. A persistent sync process or cron job can solve this, but occupying a process for a long time means it stops when the machine is shut down.

dsh-memory-sync takes the third path: it only runs a three-stage sync once when Harness starts and then exits immediately. Below is an introduction to its positioning, configuration, and peer preparation.

What is this

dsh-memory-sync is maintained by QIC-9821 and is categorized under “Memories” in the community plugins directory. Current version 0.1.2, license MIT, requires Node.js ≥ 22 (can use Harness’s built-in runtime).

It solves the problem of sharing the git memory directory from a continuously running machine to another machine, automatically bi-directionally synchronizing every time DSH is opened, without needing a background persistent process or cron.

The synchronization uses a three-stage process: the local machine commits and pushes first, then the peer commits and pushes back to the same bare repository, and finally the local machine pulls back the peer’s commits. Only if all three stages succeed does the synchronization count as a success.

Core Features

  • Automatic sync on startup: Executed only when mounted within 300 seconds after the Harness process starts; reloading plugins during hot reload or development does not trigger this.
  • Bi-directional alignment: Both the local machine and the peer commit their own changes, mediated through the same git bare repository, with the local machine’s final pull retrieving the peer’s commits.
  • Self-healing on failure: Retries once after 60 seconds of initial failure; if it still fails, it writes a status file and pops up a system window notification, then retries silently every 10 minutes until success.
  • Agent can invoke memory_sync: The tool can be used to query status or trigger a sync immediately.
  • Lightweight dependencies: Relies only on local git and ssh, does not initiate other network requests, and does not upload telemetry.
  • Centralized storage: Status, logs, and locks are centralized in $DSH_HOME/memory-sync/.

Installation and Enablement

dsh plugin add dsh-memory-sync

Fixed version or installation from source directory:

dsh plugin add github:QIC-9821/dsh-memory-sync#v0.1.1
dsh plugin add /absolute/path/to/dsh-memory-sync

After installation, find “Sync memories on startup” in Harness settings to fill in the configuration, or write it directly into the profile slot:

- id: dsh-memory-sync
  name: 'dsh-memory-sync'
  config:
    repoPath: ''            # Leave empty = $DSH_HOME/memories
    remote: cloud
    branch: main
    mode: peer
    peerHost: 203.0.113.10
    peerUser: dsh
    peerKeyPath: C:/Users/me/.ssh/id_ed25519

Common configuration options:

Key Default Description
repoPath $DSH_HOME/memories Git working directory to sync
remote cloud Git remote name; tries origin, then cloud if not found
branch main Branch name
enabled true Master switch
runOnStartup true Run automatically on startup
startupGraceSec 300 Time after startup considered “startup” if mounted; exceeds this is treated as hot reload
mode peer peer = three-stage; local = pull/commit/push only on local machine
peerHost / peerUser Empty SSH target
peerKeyPath Empty Private key path; empty = use default SSH key
peerCommand /usr/local/bin/dsh-mem-sync Sync script to execute on the peer
peerEnvName cloud DSH_SYNC_NAME set during execution
retryDelaySec 60 Interval for first retry after startup failure; 0 disables it
healIntervalSec 600 Interval for silent self-healing after failure; 0 disables it
notifyOnFailure true Show system window on failure
commitPrefix sync Prefix for auto-commit message
gitPath git Git executable file
localTimeoutMs / peerTimeoutMs 120000 Timeout for individual stage
statusFile Empty Snapshot of the machine written to this file before each sync (e.g., ~/.dsh/memories/pc-status.md), committed along with the sync; empty = do not write

How it works

The plugin executes the three stages sequentially when mounted to Harness (i.e., on a startup):

  1. Local push: git pull --rebase --autostash → git add -A → commit if there are changes → git push; if push is rejected, fetch + rebase and try again.
  2. Peer commit: Execute a command on the remote via SSH (default DSH_SYNC_NAME=cloud /usr/local/bin/dsh-mem-sync), letting the peer commit and push its changes back to the same bare repository.
  3. Local pull back: Execute the same pull/commit/push again to retrieve the commits the peer just pushed.

When mode is set to local, only perform pull/commit/push on the local machine, skipping the peer.

Typical Usage: Peer Preparation

The peer only needs a bare repository and a sync command capable of committing, for example:

# Bare repository
git init --bare -b main /srv/dsh-memory.git
chown -R dsh:dsh /srv/dsh-memory.git
git --git-dir=/srv/dsh-memory.git symbolic-ref HEAD refs/heads/main

# Remote pointing to the bare repository for the peer's working copy (/home/dsh/.dsh/memories)
git -C /home/dsh/.dsh/memories remote add origin /srv/dsh-memory.git

# /usr/local/bin/dsh-mem-sync: pull --rebase --autostash → add/commit → push
chmod 755 /usr/local/bin/dsh-mem-sync

Add the local machine’s SSH public key to the peer user’s ~/.ssh/authorized_keys, and use ssh://dsh@host/srv/dsh-memory.git for the local remote. The plugin only handles “running in order at startup” and does not understand the repository layout.

Tools and Status Query

The memory_sync tool can be called within the Agent:

  • {"action":"run"}: Sync immediately once, returns exit code / duration / HEAD for all three stages.
  • {"action":"status"}: Last result, HEAD, dirty status, ahead/behind, and whether the peer is configured.

Runtime artifacts are all in $DSH_HOME/memory-sync/: last-run.json, sync.log, lock/sync.lock.

Applicable Scenarios and Notes

Suitable for: A constantly running server (or home machine) plus a laptop sharing a memory directory, wanting alignment immediately upon startup without maintaining a persistent process.

Notes:

  • The plugin runs with the permissions of the current DSH process; check the source code and license (MIT) before installing.
  • The plugin will commit and push all content in repoPath, and the machine snapshots generated by statusFile will also enter the repository; please verify the content yourself before syncing to a public repository.
  • The failure pop-up only contains the failed stage and git/ssh errors, not the contents of repository files.
  • For security vulnerabilities, please use the private channel in the repository’s SECURITY.md file; do not open public issues.

Conclusion

dsh-memory-sync converges “multi-machine alignment of memory directories” into a sequential operation run once at startup: no extra persistent burden, clear retry, alerting, and silent self-healing paths on failure, and traceable status logs.

  • Directory Page: https://www.skillhub.cn/plugins/QIC-9821/dsh-memory-sync
  • GitHub: https://github.com/QIC-9821/dsh-memory-sync
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye