Skip to content

feat: add autosync daemon with file watching and launchd support#1

Open
nateGeorge wants to merge 1 commit intoGareArc:mainfrom
nateGeorge:feat/autosync
Open

feat: add autosync daemon with file watching and launchd support#1
nateGeorge wants to merge 1 commit intoGareArc:mainfrom
nateGeorge:feat/autosync

Conversation

@nateGeorge
Copy link
Copy Markdown

Summary

Adds a background autosync daemon that keeps OpenCode config in sync automatically.

Features

  • File watching: Watches ~/.config/opencode/ for changes via fsnotify (native kqueue on macOS)
  • Periodic sync: Syncs on an interval (default: 5 minutes)
  • Debouncing: Rapid changes are debounced (default: 3 seconds) to avoid excessive syncs
  • Launchd integration: autosync install/uninstall/status commands manage a macOS launchd service
  • Optional: Disabled by default; opt-in via config

New Commands

opencode-sync watch                 # Run daemon in foreground
opencode-sync autosync install      # Install as launchd service (macOS)
opencode-sync autosync uninstall    # Remove launchd service
opencode-sync autosync status       # Show service status + recent logs

New Config Section

{
  "autosync": {
    "enabled": false,
    "pollInterval": "5m",
    "debounceDelay": "3s",
    "watchFiles": true
  }
}

Design Notes

  • The daemon runs sync (pull + push) on triggers
  • File watcher uses fsnotify which uses native kqueue on macOS — no polling, no external deps
  • The watch command can be run manually or via launchd
  • Launchd plist uses KeepAlive so the daemon restarts if it crashes
  • Logs go to ~/Library/Logs/opencode-sync/autosync.log

Testing

  • go build ./... passes
  • The watcher has been tested locally with manual file changes

Related

Inspired by the oc-sync plugin's auto-sync behavior, but implemented as a native CLI feature so it works without OpenCode running and supports any git host.

Adds a background autosync daemon that can:
- Watch OpenCode config directory for changes (via fsnotify)
- Sync periodically on an interval (default 5m)
- Debounce rapid changes to avoid excessive syncs
- Install/uninstall as a macOS launchd service

New commands:
- opencode-sync watch          # run daemon in foreground
- opencode-sync autosync install    # install launchd service
- opencode-sync autosync uninstall  # remove launchd service
- opencode-sync autosync status     # show service status

New config section (autosync):
- enabled:       bool   # default false
- pollInterval:  string # default 5m
- debounceDelay: string # default 3s
- watchFiles:    bool   # default true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant