opencode-github-sync 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +340 -219
- package/README.zh-CN.md +242 -198
- package/dist/cli/app.d.ts +39 -0
- package/dist/cli/app.d.ts.map +1 -0
- package/dist/cli/app.js +179 -0
- package/dist/cli/app.js.map +1 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +39 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/i18n.d.ts +368 -0
- package/dist/cli/i18n.d.ts.map +1 -0
- package/dist/cli/i18n.js +773 -0
- package/dist/cli/i18n.js.map +1 -0
- package/dist/cli/index.js +312 -114
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/menu.d.ts +52 -0
- package/dist/cli/menu.d.ts.map +1 -0
- package/dist/cli/menu.js +1126 -0
- package/dist/cli/menu.js.map +1 -0
- package/dist/cli/render.d.ts +3 -0
- package/dist/cli/render.d.ts.map +1 -1
- package/dist/cli/render.js +6 -1
- package/dist/cli/render.js.map +1 -1
- package/dist/cli/ui.d.ts +62 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +383 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/core/autosync.d.ts +134 -0
- package/dist/core/autosync.d.ts.map +1 -0
- package/dist/core/autosync.js +507 -0
- package/dist/core/autosync.js.map +1 -0
- package/dist/core/bundle.d.ts +11 -0
- package/dist/core/bundle.d.ts.map +1 -0
- package/dist/core/bundle.js +87 -0
- package/dist/core/bundle.js.map +1 -0
- package/dist/core/categories.d.ts +37 -0
- package/dist/core/categories.d.ts.map +1 -0
- package/dist/core/categories.js +115 -0
- package/dist/core/categories.js.map +1 -0
- package/dist/core/compare.d.ts +21 -0
- package/dist/core/compare.d.ts.map +1 -0
- package/dist/core/compare.js +124 -0
- package/dist/core/compare.js.map +1 -0
- package/dist/core/env.d.ts +16 -0
- package/dist/core/env.d.ts.map +1 -0
- package/dist/core/env.js +47 -0
- package/dist/core/env.js.map +1 -0
- package/dist/core/git.d.ts +6 -0
- package/dist/core/git.d.ts.map +1 -1
- package/dist/core/git.js +44 -4
- package/dist/core/git.js.map +1 -1
- package/dist/core/guard.d.ts +36 -0
- package/dist/core/guard.d.ts.map +1 -0
- package/dist/core/guard.js +65 -0
- package/dist/core/guard.js.map +1 -0
- package/dist/core/history.d.ts +38 -0
- package/dist/core/history.d.ts.map +1 -0
- package/dist/core/history.js +98 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/notify.d.ts +9 -0
- package/dist/core/notify.d.ts.map +1 -0
- package/dist/core/notify.js +69 -0
- package/dist/core/notify.js.map +1 -0
- package/dist/core/recovery.d.ts +26 -0
- package/dist/core/recovery.d.ts.map +1 -0
- package/dist/core/recovery.js +56 -0
- package/dist/core/recovery.js.map +1 -0
- package/dist/core/repo.d.ts +15 -1
- package/dist/core/repo.d.ts.map +1 -1
- package/dist/core/repo.js +22 -2
- package/dist/core/repo.js.map +1 -1
- package/dist/core/scheduler.d.ts +138 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +531 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/settings.d.ts +61 -0
- package/dist/core/settings.d.ts.map +1 -1
- package/dist/core/settings.js +44 -2
- package/dist/core/settings.js.map +1 -1
- package/dist/core/setup.d.ts +20 -0
- package/dist/core/setup.d.ts.map +1 -1
- package/dist/core/setup.js +87 -4
- package/dist/core/setup.js.map +1 -1
- package/dist/core/stage.d.ts +5 -0
- package/dist/core/stage.d.ts.map +1 -1
- package/dist/core/stage.js +71 -2
- package/dist/core/stage.js.map +1 -1
- package/dist/core/sync.d.ts +25 -0
- package/dist/core/sync.d.ts.map +1 -1
- package/dist/core/sync.js +228 -38
- package/dist/core/sync.js.map +1 -1
- package/dist/core/update.d.ts +21 -0
- package/dist/core/update.d.ts.map +1 -0
- package/dist/core/update.js +75 -0
- package/dist/core/update.js.map +1 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +4 -3
- package/dist/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,175 +1,227 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="docs/
|
|
2
|
+
<img src="https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/docs/images/en/01-hero.png" alt="opencode-github-sync: one config, every machine" width="880">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<a href="https://www.npmjs.com/package/opencode-github-sync"><img alt="npm" src="https://img.shields.io/npm/v/opencode-github-sync?style=flat-square&color=7aa2f7&labelColor=1a1e2b"></a>
|
|
7
7
|
<a href="https://github.com/doomsday616/opencode-github-sync/actions/workflows/ci.yml"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/doomsday616/opencode-github-sync/ci.yml?style=flat-square&color=9ece6a&labelColor=1a1e2b&label=ci"></a>
|
|
8
|
-
<a href="
|
|
8
|
+
<a href="https://github.com/doomsday616/opencode-github-sync/blob/main/LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT-bb9af7?style=flat-square&labelColor=1a1e2b"></a>
|
|
9
9
|
<img alt="platform" src="https://img.shields.io/badge/macOS%20·%20Windows%20·%20Linux-9ece6a?style=flat-square&labelColor=1a1e2b&label=runs%20on">
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
12
|
<p align="center">
|
|
13
|
-
<a href="
|
|
13
|
+
<a href="https://github.com/doomsday616/opencode-github-sync/blob/main/README.zh-CN.md">简体中文</a>
|
|
14
14
|
·
|
|
15
|
-
<a href="#
|
|
15
|
+
<a href="#install">Install</a>
|
|
16
16
|
·
|
|
17
|
-
<a href="#
|
|
17
|
+
<a href="#pick-your-setup">Setup</a>
|
|
18
18
|
·
|
|
19
|
-
<a href="#
|
|
19
|
+
<a href="#how-autosync-works">Autosync</a>
|
|
20
20
|
·
|
|
21
21
|
<a href="#command-reference">Commands</a>
|
|
22
|
+
·
|
|
23
|
+
<a href="#troubleshooting">Troubleshooting</a>
|
|
22
24
|
</p>
|
|
23
25
|
|
|
24
26
|
---
|
|
25
27
|
|
|
26
|
-
You use OpenCode on more than one
|
|
27
|
-
and MCP servers
|
|
28
|
-
|
|
29
|
-
**opencode-github-sync** keeps them all in step through a private GitHub
|
|
30
|
-
repository — as an OpenCode plugin, as a CLI, or both.
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npm install -g opencode-github-sync
|
|
34
|
-
opencode-sync init # creates the private repo and configures this machine
|
|
35
|
-
opencode-sync push
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
<p align="center">
|
|
39
|
-
<img src="docs/demo.svg" alt="opencode-sync push" width="760">
|
|
40
|
-
</p>
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## Why another sync tool
|
|
45
|
-
|
|
46
|
-
Most config-sync tools stop being safe the moment real use hits them. These are
|
|
47
|
-
the three places that happens, and what this one does instead.
|
|
48
|
-
|
|
49
|
-
| | Typical approach | Here |
|
|
50
|
-
| ------------------ | ----------------------------------------------- | -------------------------------------------------------------------------- |
|
|
51
|
-
| **Machine differences** | Every machine forced identical | [Per-machine overrides](#per-machine-overrides) that sync can never overwrite |
|
|
52
|
-
| **Sessions** | Commit `opencode.db` — gigabytes, unmergeable | [Selective per-session shards](#session-sync), a few MB, conflict-free |
|
|
53
|
-
| **When it breaks** | Plugin-only: bad config means no way back | The CLI runs outside OpenCode and can always recover you |
|
|
28
|
+
You use OpenCode on more than one computer. Your config, agents, commands,
|
|
29
|
+
skills and MCP servers end up wherever you last touched them.
|
|
54
30
|
|
|
55
|
-
|
|
31
|
+
**opencode-github-sync** keeps every machine on the same setup through a
|
|
32
|
+
private GitHub repository. Run it by hand, or let one machine sync itself in
|
|
33
|
+
the background.
|
|
56
34
|
|
|
57
|
-
|
|
58
|
-
- **Every replacement is atomic.** A crash mid-sync cannot leave a half-written config that stops OpenCode from starting.
|
|
59
|
-
- **A push is verified against the remote.** `git push` can exit `0` without the remote moving; that is checked, not assumed.
|
|
60
|
-
- **Nothing runs twice at once.** A cross-process lock covers the plugin, the CLI and every OpenCode window.
|
|
61
|
-
- **Credentials are opt-in** and refused outright on a public repository.
|
|
62
|
-
- **Your hostname never leaves the machine.** Commits are signed with a stable pseudonym, so a corporate asset tag never lands in a repo that might not stay private.
|
|
35
|
+
## Install
|
|
63
36
|
|
|
64
|
-
|
|
37
|
+
**macOS / Linux**
|
|
65
38
|
|
|
66
|
-
|
|
39
|
+
```bash
|
|
40
|
+
curl -fsSL https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/install.sh | sh
|
|
41
|
+
```
|
|
67
42
|
|
|
68
|
-
|
|
43
|
+
**Windows** (PowerShell 5.1 or 7)
|
|
69
44
|
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
{
|
|
73
|
-
"$schema": "https://opencode.ai/config.json",
|
|
74
|
-
"plugin": ["opencode-github-sync"]
|
|
75
|
-
}
|
|
45
|
+
```powershell
|
|
46
|
+
irm https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/install.ps1 | iex
|
|
76
47
|
```
|
|
77
48
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
`"plugins"` instead. Do not list the plugin under both keys — OpenCode 2 loads
|
|
82
|
-
entries from both lists.
|
|
49
|
+
The installer checks for Node.js 18+ and git. If one is missing it shows the
|
|
50
|
+
command that would install it and asks before running anything. Then it runs
|
|
51
|
+
`npm install -g opencode-github-sync@latest` and opens the menu.
|
|
83
52
|
|
|
84
|
-
|
|
85
|
-
`opencode-
|
|
53
|
+
Already have Node.js? `npm install -g opencode-github-sync` and then
|
|
54
|
+
`opencode-sync` does the same thing.
|
|
86
55
|
|
|
87
|
-
|
|
88
|
-
optional push when a session goes idle, and an `opencode_sync` tool so you can
|
|
89
|
-
just ask for a sync in plain language.
|
|
56
|
+
### Set up a machine in one line
|
|
90
57
|
|
|
91
|
-
|
|
58
|
+
Pass options to skip the questions, for example when provisioning a new
|
|
59
|
+
machine:
|
|
92
60
|
|
|
93
61
|
```bash
|
|
94
|
-
|
|
62
|
+
curl -fsSL https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/install.sh | sh -s -- --mode auto --repo you/my-opencode-config
|
|
95
63
|
```
|
|
96
64
|
|
|
97
|
-
|
|
98
|
-
|
|
65
|
+
```powershell
|
|
66
|
+
& ([scriptblock]::Create((irm https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/install.ps1))) -Mode auto -Repo you/my-opencode-config
|
|
67
|
+
```
|
|
99
68
|
|
|
100
|
-
|
|
101
|
-
|
|
69
|
+
| Option | Meaning |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `--mode cli` / `-Mode cli` | Install the command only |
|
|
72
|
+
| `--mode link` | Link `--repo` and sync once |
|
|
73
|
+
| `--mode auto` | Link, sync once and turn on autosync |
|
|
74
|
+
| `--repo owner/name` | The repository (a git URL works too); created as private if it does not exist |
|
|
75
|
+
| `--interval N` | Autosync every N minutes (minimum 2, default 5) |
|
|
76
|
+
| `--lang en` / `zh-CN` | Interface language |
|
|
77
|
+
| `--proxy URL` | Proxy for npm and git, during install and for later syncs |
|
|
78
|
+
| `--yes` | Install missing Node.js or git without asking |
|
|
79
|
+
| `--package SPEC` | npm package spec to install (default `opencode-github-sync@latest`) |
|
|
80
|
+
| `--dry-run` | Print what would run, change nothing |
|
|
81
|
+
|
|
82
|
+
On Windows each option is the same word with a leading dash: `-Repo`,
|
|
83
|
+
`-Interval`, `-Lang`, `-Proxy`, `-Yes`, `-Package`, `-DryRun`.
|
|
84
|
+
|
|
85
|
+
When the repository already has content and this machine also has its own
|
|
86
|
+
files, setup takes the repository's version and keeps the replaced files in a
|
|
87
|
+
[recovery folder](#safety-features).
|
|
102
88
|
|
|
103
89
|
---
|
|
104
90
|
|
|
105
|
-
##
|
|
91
|
+
## Pick your setup
|
|
106
92
|
|
|
107
|
-
|
|
93
|
+
<p align="center">
|
|
94
|
+
<img src="https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/docs/images/en/03-pick-your-setup.png" alt="Command only, or primary device with autosync" width="760">
|
|
95
|
+
</p>
|
|
108
96
|
|
|
109
|
-
|
|
110
|
-
opencode-sync init # → <you>/my-opencode-config
|
|
111
|
-
opencode-sync init team-config # custom name
|
|
112
|
-
opencode-sync init my-org/shared # inside an organisation
|
|
113
|
-
opencode-sync push
|
|
114
|
-
```
|
|
97
|
+
The first time you run `opencode-sync` it asks how this machine should work.
|
|
115
98
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
| | Command only | Primary device + autosync |
|
|
100
|
+
| --- | --- | --- |
|
|
101
|
+
| How it syncs | You run `opencode-sync push` / `pull`, or the plugin pulls at startup | The operating system runs a sync every few minutes, even when OpenCode is closed |
|
|
102
|
+
| Good for | A machine you use now and then, a shared or locked-down machine | The machines you work on every day |
|
|
103
|
+
| Background job | None | Task Scheduler, launchd or a systemd timer |
|
|
119
104
|
|
|
120
|
-
|
|
105
|
+
You can change your mind any time from the **Autosync** menu. Autosync is
|
|
106
|
+
opt-in per machine: turning it on here never turns it on anywhere else.
|
|
121
107
|
|
|
122
|
-
|
|
123
|
-
opencode-sync link doomsday616/my-opencode-config
|
|
124
|
-
opencode-sync pull
|
|
125
|
-
```
|
|
108
|
+
---
|
|
126
109
|
|
|
127
|
-
|
|
110
|
+
## The menu
|
|
128
111
|
|
|
129
|
-
|
|
112
|
+
Run `opencode-sync` with no arguments.
|
|
130
113
|
|
|
131
|
-
|
|
132
|
-
opencode-sync
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
114
|
+
<p align="center">
|
|
115
|
+
<img src="https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/docs/menu.svg" alt="The opencode-sync menu" width="760">
|
|
116
|
+
</p>
|
|
117
|
+
|
|
118
|
+
Arrow keys or the shown hotkey pick an item, space ticks a checkbox, Enter
|
|
119
|
+
confirms and Esc goes back. When the input is not a terminal (a pipe, a script,
|
|
120
|
+
CI) every prompt becomes a numbered question, so the menu can be driven from a
|
|
121
|
+
file.
|
|
122
|
+
|
|
123
|
+
| Item | What you can do there |
|
|
124
|
+
| --- | --- |
|
|
125
|
+
| **Sync now** | Push and receive, receive only, push only, or preview first |
|
|
126
|
+
| **What to sync** | Tick main config, instruction files, agents, commands, plugins, skills, credentials, sessions; set session limits; add extra paths |
|
|
127
|
+
| **Autosync** | Turn it on or off, choose 5/10/15/30/60 minutes or your own interval, pause it, run while signed out (Windows), notifications |
|
|
128
|
+
| **Update** | Check npm for a newer version, upgrade, update automatically once a day |
|
|
129
|
+
| **This machine's overrides** | Open the overrides file in your editor, see what it changes |
|
|
130
|
+
| **Diagnostics** | git, node, gh, repository access, the scheduled job, the last log lines; export a support bundle |
|
|
131
|
+
| **Danger zone** | Make this machine match the repository, or the other way round (you type `overwrite` to confirm) |
|
|
132
|
+
| **Uninstall** | Remove the scheduled job, optionally unlink and remove the command. Your configuration is never deleted |
|
|
133
|
+
| **Network proxy** | A proxy for git, gh and npm, used only by opencode-sync |
|
|
134
|
+
| **Restore a file from history** | Pick a file, pick a version, put it back |
|
|
135
|
+
| **Devices** | Every machine that has synced and when, and renaming this one |
|
|
136
|
+
| **Large-change guard** | The limits that make a big push stop and ask |
|
|
137
|
+
| **Language** | English, 简体中文 or automatic |
|
|
138
|
+
|
|
139
|
+
Every command from earlier versions still works and is still scriptable.
|
|
136
140
|
|
|
137
141
|
---
|
|
138
142
|
|
|
139
143
|
## What gets synced
|
|
140
144
|
|
|
141
145
|
<p align="center">
|
|
142
|
-
<img src="docs/
|
|
146
|
+
<img src="https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/docs/images/en/02-how-it-works.png" alt="Each machine pushes and pulls through one private repository" width="760">
|
|
143
147
|
</p>
|
|
144
148
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
| `~/.config/opencode/` | repo root | config, agents, commands, skills, themes, MCP |
|
|
148
|
-
| `~/.local/share/opencode/` | `_data/` | project metadata, optional credentials |
|
|
149
|
-
| `~/.local/state/opencode/` | `_state/` | frecency, model cache, prompt history |
|
|
150
|
-
| `~/.agents/skills/` | `_agents/` | skills installed by the `skills` CLI |
|
|
151
|
-
| selected sessions | `_sessions/`| one gzipped shard per session |
|
|
149
|
+
Your `~/.config/opencode` folder becomes a working copy of the repository.
|
|
150
|
+
Everything else is mirrored into a folder inside it.
|
|
152
151
|
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
| On your machine | In the repository | What it holds |
|
|
153
|
+
| --- | --- | --- |
|
|
154
|
+
| `~/.config/opencode/` | the root | config, agents, commands, plugins, themes, instruction files |
|
|
155
|
+
| `~/.local/share/opencode/` | `_data/` | project metadata, and credentials if you opt in |
|
|
156
|
+
| `~/.local/state/opencode/` | `_state/` | model cache, recent files, prompt history |
|
|
157
|
+
| `~/.agents/skills/` | `_agents/` | skills installed with the `skills` CLI |
|
|
158
|
+
| selected sessions | `_sessions/` | one small compressed file per session |
|
|
159
|
+
| your extra paths | `_extra/` | anything else you add |
|
|
155
160
|
|
|
156
|
-
|
|
161
|
+
Each part can be switched off under **What to sync**. A part you switch off
|
|
162
|
+
stays local in both directions: your edits are not sent, and other machines'
|
|
163
|
+
versions do not replace yours.
|
|
157
164
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
```
|
|
165
|
+
**Never synced:** the `opencode.db` database, tool output, snapshots, logs,
|
|
166
|
+
`node_modules` and other generated folders, and opencode-sync's own settings
|
|
167
|
+
and overrides files.
|
|
163
168
|
|
|
164
169
|
---
|
|
165
170
|
|
|
166
|
-
##
|
|
171
|
+
## How autosync works
|
|
167
172
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
173
|
+
<p align="center">
|
|
174
|
+
<img src="https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/docs/images/en/04-autosync.png" alt="Each machine syncs on its own schedule, waits while you edit, and backs off on errors" width="760">
|
|
175
|
+
</p>
|
|
176
|
+
|
|
177
|
+
When autosync is on, the operating system starts `opencode-sync autosync run`
|
|
178
|
+
every few minutes and at sign-in (on Windows also when you unlock or reconnect
|
|
179
|
+
over Remote Desktop). Each run makes one decision:
|
|
180
|
+
|
|
181
|
+
1. **Is it quiet?** If any file in your config or skills folders changed in the
|
|
182
|
+
last minute, something is still being written. Sending now could publish a
|
|
183
|
+
half-saved file, so the push waits.
|
|
184
|
+
2. **Can it at least receive?** While busy, it still takes other machines'
|
|
185
|
+
changes, but only when this machine has nothing of its own waiting.
|
|
186
|
+
Otherwise it leaves everything for the next run.
|
|
187
|
+
3. **Push and receive.** Your changes go up, other machines' changes come down,
|
|
188
|
+
in one step.
|
|
189
|
+
|
|
190
|
+
The rules that keep this safe:
|
|
191
|
+
|
|
192
|
+
- **Machines take turns.** Each machine waits a fixed few seconds based on its
|
|
193
|
+
name, so two machines on the same schedule do not collide every time. If
|
|
194
|
+
another machine still gets there first, this one picks up the new commit and
|
|
195
|
+
tries again; that does not count as an error.
|
|
196
|
+
- **It backs off, but never gives up.** After three failures in a row
|
|
197
|
+
(typically no network) it waits 30 minutes, then an hour between attempts.
|
|
198
|
+
The first success puts it back on schedule.
|
|
199
|
+
- **It only interrupts you twice.** One notification when it starts backing
|
|
200
|
+
off, one when it recovers. Nothing for ordinary syncs.
|
|
201
|
+
- **It never runs twice at once.** A lock is shared by the scheduled job, the
|
|
202
|
+
CLI, the menu and every OpenCode window; if one is busy, the others skip.
|
|
203
|
+
- **It never confirms a large change.** Anything that trips the
|
|
204
|
+
[large-change guard](#safety-features) is held back and you get a
|
|
205
|
+
notification.
|
|
206
|
+
|
|
207
|
+
| Platform | Scheduler | Notes |
|
|
208
|
+
| --- | --- | --- |
|
|
209
|
+
| Windows | Task Scheduler | Runs hidden. To run while signed out, turn that on in the menu and install from an administrator terminal |
|
|
210
|
+
| macOS | launchd agent | `~/Library/LaunchAgents/com.opencode-github-sync.autosync.plist` |
|
|
211
|
+
| Linux | systemd user timer | Falls back to a crontab line. On a server, run `loginctl enable-linger` so it runs while you are logged out |
|
|
212
|
+
|
|
213
|
+
`opencode-sync autosync status` shows the last run, the last error and when it
|
|
214
|
+
will try next. With autosync on, the OpenCode plugin stops pushing on idle so
|
|
215
|
+
the two never compete; it still pulls when OpenCode starts.
|
|
171
216
|
|
|
172
|
-
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Per-machine overrides
|
|
220
|
+
|
|
221
|
+
Some settings belong to one machine only: a work proxy, a local tool path, an
|
|
222
|
+
MCP server that only exists on one box. Put them in
|
|
223
|
+
`~/.config/opencode/opencode-sync.overrides.jsonc`, or use **This machine's
|
|
224
|
+
overrides** in the menu:
|
|
173
225
|
|
|
174
226
|
```jsonc
|
|
175
227
|
{
|
|
@@ -181,175 +233,244 @@ Put those in `~/.config/opencode/opencode-sync.overrides.jsonc`:
|
|
|
181
233
|
```
|
|
182
234
|
|
|
183
235
|
```
|
|
184
|
-
repo opencode.jsonc shared
|
|
236
|
+
repo opencode.jsonc shared, committed
|
|
185
237
|
+ overrides.jsonc this machine only, never committed
|
|
186
|
-
─────────────────────────
|
|
187
|
-
= effective opencode.jsonc what OpenCode
|
|
238
|
+
───────────────────────── merged
|
|
239
|
+
= effective opencode.jsonc what OpenCode reads
|
|
188
240
|
```
|
|
189
241
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
key the overrides file claims is restored to the value the repository already
|
|
196
|
-
had before committing — so an overridden key is invisible to sync in both
|
|
197
|
-
directions, and your machine keeps its own settings the whole time.
|
|
198
|
-
|
|
199
|
-
> With no overrides file the config is copied byte for byte and your comments
|
|
200
|
-
> and formatting are untouched. The structural rewrite only happens once you
|
|
201
|
-
> actually opt in.
|
|
242
|
+
Objects merge key by key, lists and plain values replace, and `null` removes a
|
|
243
|
+
key. Before every push, any key the overrides file claims is put back to the
|
|
244
|
+
repository's value, so your machine-only values never reach other machines.
|
|
245
|
+
Without an overrides file, the config is copied exactly as written, comments
|
|
246
|
+
and all.
|
|
202
247
|
|
|
203
248
|
---
|
|
204
249
|
|
|
205
|
-
##
|
|
250
|
+
## Sessions
|
|
206
251
|
|
|
207
|
-
Off by default.
|
|
208
|
-
private
|
|
252
|
+
Off by default. Only turn it on for a private repository: conversations are
|
|
253
|
+
private.
|
|
209
254
|
|
|
210
255
|
```bash
|
|
211
256
|
opencode-sync sessions enable
|
|
212
257
|
opencode-sync sessions list
|
|
213
|
-
opencode-sync sessions include ses_065cad1caffeN3lf1RgLZno30 #
|
|
258
|
+
opencode-sync sessions include ses_065cad1caffeN3lf1RgLZno30 # always sync this one
|
|
214
259
|
opencode-sync sessions exclude ses_0ba19b4e7ffeMbSmWYi3Nj6xfZ # never sync this one
|
|
215
260
|
```
|
|
216
261
|
|
|
217
|
-
|
|
262
|
+
Sessions are not synced by committing the database. A real OpenCode database
|
|
263
|
+
grows to several gigabytes, mostly tool output, and git cannot merge it. Each
|
|
264
|
+
session is exported on its own as a small compressed file instead:
|
|
265
|
+
|
|
266
|
+
- **Small.** Only recent sessions (7 days and 50 sessions by default), and any
|
|
267
|
+
single session over 5 MB is skipped.
|
|
268
|
+
- **No conflicts in practice.** Two machines working on different sessions
|
|
269
|
+
touch different files. The same session edited in two places keeps the newer
|
|
270
|
+
version.
|
|
271
|
+
- **Safe to import.** Importing runs in one transaction, so a failure leaves
|
|
272
|
+
your database as it was.
|
|
273
|
+
|
|
274
|
+
Window, count and size limits are under **What to sync → Session settings**.
|
|
275
|
+
Session sync needs Node.js 22.5 or newer.
|
|
218
276
|
|
|
219
|
-
|
|
220
|
-
inside `part.data`. Git cannot delta-compress it, GitHub's LFS free tier is one
|
|
221
|
-
gigabyte, and copying a live database alongside its write-ahead log can capture
|
|
222
|
-
a torn state that only shows up much later.
|
|
277
|
+
---
|
|
223
278
|
|
|
224
|
-
|
|
225
|
-
JSON shard holding its own rows plus the project and workspace rows it needs:
|
|
279
|
+
## Safety features
|
|
226
280
|
|
|
227
|
-
|
|
228
|
-
-
|
|
229
|
-
|
|
230
|
-
real conflict is one session edited in two places, and there the newer
|
|
231
|
-
`time_updated` wins — an in-progress conversation is never clobbered by a
|
|
232
|
-
stale copy.
|
|
233
|
-
- **You choose what travels.** A time window, an explicit include list, a
|
|
234
|
-
project filter and a per-session size cap. Ancient sessions stay where they
|
|
235
|
-
are.
|
|
281
|
+
<p align="center">
|
|
282
|
+
<img src="https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/docs/images/en/05-safety-net.png" alt="One sync at a time, all-or-nothing writes, restore earlier versions, large-change guard" width="760">
|
|
283
|
+
</p>
|
|
236
284
|
|
|
237
|
-
|
|
238
|
-
|
|
285
|
+
- **Atomic replace.** Files are written beside their target and then swapped
|
|
286
|
+
in, so a crash mid-sync cannot leave a half-written config that stops
|
|
287
|
+
OpenCode from starting.
|
|
288
|
+
- **Push verification.** After pushing, the remote is read back. `git push`
|
|
289
|
+
can report success without the remote changing; that is checked, not
|
|
290
|
+
assumed.
|
|
291
|
+
- **One sync at a time.** A lock shared by the plugin, the CLI, the menu and
|
|
292
|
+
the scheduled job.
|
|
293
|
+
- **Large-change guard.** A push that adds more than 300 files, more than
|
|
294
|
+
10 MB in total, or any single file over 2 MB stops and asks. The limits are
|
|
295
|
+
adjustable. Generated folders such as `node_modules`, `.venv`, `venv`,
|
|
296
|
+
`__pycache__`, `dist` and `.cache` are never sent.
|
|
297
|
+
- **Recovery folder.** Before a forced pull, a "repository wins" first link,
|
|
298
|
+
or a restore from history, the files about to be replaced are copied to
|
|
299
|
+
`~/.local/share/opencode/opencode-sync-recovery/<time>-<reason>/`.
|
|
300
|
+
- **Credentials are opt-in** and refused outright when the repository is
|
|
301
|
+
public.
|
|
302
|
+
- **Your hostname stays private.** Commits name the machine by a stable
|
|
303
|
+
pseudonym (or a name you choose), never by its real hostname.
|
|
304
|
+
- **Symlinks are refused, not followed**, so a sync cannot copy files from
|
|
305
|
+
outside the folders it owns.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## OpenCode plugin
|
|
310
|
+
|
|
311
|
+
The plugin is optional. It pulls when OpenCode starts, can push when a session
|
|
312
|
+
goes idle, and adds an `opencode_sync` tool so you can ask for a sync in plain
|
|
313
|
+
language.
|
|
239
314
|
|
|
240
315
|
```jsonc
|
|
316
|
+
// ~/.config/opencode/opencode.json
|
|
241
317
|
{
|
|
242
|
-
"
|
|
243
|
-
|
|
244
|
-
"days": 7, // only sessions touched this recently
|
|
245
|
-
"maxSessions": 50, // hard cap per push, newest first
|
|
246
|
-
"maxSessionBytes": 5242880, // skip any single runaway session
|
|
247
|
-
"include": [], // always sync these, whatever the window says
|
|
248
|
-
"exclude": [], // never sync these
|
|
249
|
-
"directories": [] // only sessions under these project directories
|
|
250
|
-
}
|
|
318
|
+
"$schema": "https://opencode.ai/config.json",
|
|
319
|
+
"plugin": ["opencode-github-sync"]
|
|
251
320
|
}
|
|
252
321
|
```
|
|
253
322
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
323
|
+
This `"plugin"` form works on both OpenCode 1.x (1.3.4 and later) and
|
|
324
|
+
OpenCode 2.x: 1.x reads only `"plugin"`, and 2.x still accepts it alongside its
|
|
325
|
+
native `"plugins"` key. If you run only OpenCode 2, you can list it under
|
|
326
|
+
`"plugins"` instead. Do not list the plugin under both keys — OpenCode 2 loads
|
|
327
|
+
entries from both lists.
|
|
258
328
|
|
|
259
|
-
|
|
329
|
+
OpenCode 1.0–1.3.3 cannot load 3.1.0 and later; stay on
|
|
330
|
+
`opencode-github-sync@3.0.1` there.
|
|
260
331
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
| `opencode-sync link <owner/repo>` | Point this machine at an existing one |
|
|
265
|
-
| `opencode-sync push` | Share this machine's configuration |
|
|
266
|
-
| `opencode-sync pull` | Apply the shared configuration |
|
|
267
|
-
| `opencode-sync status` | Show what is in sync and what is not |
|
|
268
|
-
| `opencode-sync sessions list` | Recent sessions and their ids |
|
|
269
|
-
| `opencode-sync sessions enable` | Turn selective session sync on |
|
|
270
|
-
| `opencode-sync sessions include` | Pin a session, ignoring the time window |
|
|
271
|
-
| `opencode-sync overrides` | Create/locate the per-machine patch |
|
|
272
|
-
| `opencode-sync config` | Print the current settings |
|
|
273
|
-
|
|
274
|
-
| Flag | Effect |
|
|
275
|
-
| ----------- | ----------------------------------------------- |
|
|
276
|
-
| `--force` | Overwrite the other side on conflict (confirmed) |
|
|
277
|
-
| `--dry-run` | Report what would change, write nothing |
|
|
278
|
-
|
|
279
|
-
| Environment variable | Effect |
|
|
280
|
-
| ---------------------------- | ---------------------------------------- |
|
|
281
|
-
| `OPENCODE_SYNC_HOST_ALIAS` | Name this machine in commit messages |
|
|
282
|
-
| `OPENCODE_SYNC_VERBOSE=1` | Full file list and stack traces |
|
|
283
|
-
| `NO_COLOR` | Disable colour |
|
|
284
|
-
| `SYNC_REMOTE_URL` | Override the repository URL |
|
|
332
|
+
Keep the command installed even if you use the plugin. A plugin cannot repair
|
|
333
|
+
the configuration that stops OpenCode from loading it; `opencode-sync pull
|
|
334
|
+
--force` can.
|
|
285
335
|
|
|
286
336
|
---
|
|
287
337
|
|
|
288
|
-
##
|
|
338
|
+
## Command reference
|
|
289
339
|
|
|
290
|
-
|
|
340
|
+
| Command | What it does |
|
|
341
|
+
| --- | --- |
|
|
342
|
+
| `opencode-sync` | Open the menu (same as `opencode-sync menu`) |
|
|
343
|
+
| `opencode-sync init [name]` | Create a private sync repository with `gh` |
|
|
344
|
+
| `opencode-sync link <owner/repo or URL>` | Use an existing repository |
|
|
345
|
+
| `opencode-sync setup --mode cli\|link\|auto` | Non-interactive setup, used by the installers |
|
|
346
|
+
| `opencode-sync push` | Send this machine's changes |
|
|
347
|
+
| `opencode-sync pull` | Take the shared configuration |
|
|
348
|
+
| `opencode-sync status` | What is in sync and what is not |
|
|
349
|
+
| `opencode-sync autosync enable` / `disable` | Turn autosync on or off for this machine |
|
|
350
|
+
| `opencode-sync autosync install` / `uninstall` | Register or remove the scheduled job only |
|
|
351
|
+
| `opencode-sync autosync status` | Last run, last error, next attempt |
|
|
352
|
+
| `opencode-sync autosync run` | One scheduled pass, now |
|
|
353
|
+
| `opencode-sync autosync pause <hours>\|tomorrow` / `resume` | Pause or resume |
|
|
354
|
+
| `opencode-sync autosync reset` | Clear the failure counter |
|
|
355
|
+
| `opencode-sync sessions list\|enable\|disable` | Session sync |
|
|
356
|
+
| `opencode-sync sessions include\|exclude <id>` | Always or never sync one session |
|
|
357
|
+
| `opencode-sync overrides` | Create or locate the overrides file |
|
|
358
|
+
| `opencode-sync config` | Print the settings |
|
|
359
|
+
|
|
360
|
+
| Flag | Effect |
|
|
361
|
+
| --- | --- |
|
|
362
|
+
| `--force` | Overwrite the other side (asks you to type `yes`; `--yes` skips) |
|
|
363
|
+
| `--dry-run` | Show what would change, change nothing |
|
|
364
|
+
| `--allow-large` | Push even when the large-change guard objects |
|
|
365
|
+
| `--lang en\|zh-CN` | Interface language for this run |
|
|
366
|
+
|
|
367
|
+
| Environment variable | Effect |
|
|
368
|
+
| --- | --- |
|
|
369
|
+
| `OPENCODE_SYNC_LANG` | Interface language |
|
|
370
|
+
| `OPENCODE_SYNC_HOST_ALIAS` | Machine name used in commits |
|
|
371
|
+
| `OPENCODE_SYNC_PROXY` | Proxy for git, gh and npm |
|
|
372
|
+
| `OPENCODE_SYNC_VERBOSE=1` | Full file lists and stack traces |
|
|
373
|
+
| `SYNC_REMOTE_URL` | Override the repository URL |
|
|
374
|
+
| `NO_COLOR` | Plain output |
|
|
375
|
+
|
|
376
|
+
### Settings file
|
|
377
|
+
|
|
378
|
+
`~/.config/opencode/opencode-sync.jsonc` stays on this machine and is never
|
|
379
|
+
committed. The menu edits it for you; every key is optional.
|
|
291
380
|
|
|
292
381
|
```jsonc
|
|
293
382
|
{
|
|
294
383
|
"repo": { "owner": "you", "name": "my-opencode-config", "branch": "main" },
|
|
295
|
-
|
|
296
|
-
"
|
|
297
|
-
|
|
298
|
-
"includeCredentials": false, // auth.json / account.json — private repos only
|
|
384
|
+
"machineAlias": "laptop",
|
|
385
|
+
"includeCredentials": false,
|
|
299
386
|
"includeSkills": true,
|
|
300
387
|
"includeState": true,
|
|
301
|
-
"extraPaths": [],
|
|
302
|
-
|
|
303
|
-
"sessions": { "enabled": false },
|
|
304
|
-
|
|
305
|
-
"
|
|
306
|
-
"
|
|
388
|
+
"extraPaths": [".config/gh/config.yml"],
|
|
389
|
+
"categories": { "config": true, "instructions": true, "agents": true, "commands": true, "plugins": true },
|
|
390
|
+
"sessions": { "enabled": false, "days": 7, "maxSessions": 50, "maxSessionBytes": 5242880 },
|
|
391
|
+
"autosync": { "enabled": false, "intervalMinutes": 5, "settleSeconds": 60, "runWhenLoggedOff": false, "autoUpdate": false },
|
|
392
|
+
"guard": { "maxFiles": 300, "maxBytes": 10485760, "maxFileBytes": 2097152 },
|
|
393
|
+
"proxy": "",
|
|
394
|
+
"language": "",
|
|
395
|
+
"notifications": true,
|
|
396
|
+
"autoPullOnStartup": true,
|
|
397
|
+
"autoPushOnIdle": false
|
|
307
398
|
}
|
|
308
399
|
```
|
|
309
400
|
|
|
310
401
|
---
|
|
311
402
|
|
|
312
|
-
##
|
|
403
|
+
## Troubleshooting
|
|
313
404
|
|
|
314
|
-
**
|
|
315
|
-
|
|
316
|
-
|
|
405
|
+
**I am behind a proxy.** Pass `--proxy http://host:port` (or `-Proxy` on
|
|
406
|
+
Windows) to the installer. It is used for npm and git during the install and
|
|
407
|
+
saved for later syncs. You can change it any time under **Network proxy**.
|
|
317
408
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
git
|
|
322
|
-
|
|
409
|
+
**`curl | sh` does not ask me anything.** The script itself arrives through the
|
|
410
|
+
pipe, so it reads your answers from the terminal instead. In a session with no
|
|
411
|
+
terminal (CI, a Dockerfile) there is nobody to ask: pass `--mode` and `--repo`,
|
|
412
|
+
plus `--yes` if Node.js or git may need installing.
|
|
413
|
+
|
|
414
|
+
**Windows says running scripts is disabled.** `irm ... | iex` does not run a
|
|
415
|
+
script file, so the execution policy does not apply to it. If you downloaded
|
|
416
|
+
`install.ps1` and want to run it as a file, use
|
|
417
|
+
`powershell -ExecutionPolicy Bypass -File install.ps1`.
|
|
418
|
+
|
|
419
|
+
**`opencode-sync` is not found after installing.** npm installed it into a
|
|
420
|
+
folder that is not on your `PATH`. `npm prefix -g` shows the folder; add its
|
|
421
|
+
`bin` (or the folder itself on Windows) to `PATH`.
|
|
323
422
|
|
|
324
|
-
**
|
|
325
|
-
|
|
423
|
+
**Autosync is on but nothing happens.** Run `opencode-sync autosync status`. It
|
|
424
|
+
shows whether it is paused, backing off after errors, or waiting because files
|
|
425
|
+
are still changing. **Diagnostics** in the menu shows whether the scheduled job
|
|
426
|
+
is registered.
|
|
326
427
|
|
|
327
|
-
**
|
|
328
|
-
|
|
428
|
+
**A pull conflicted with my local edits.** Your edits are kept in a git stash
|
|
429
|
+
and the exact commands to get them back are printed. Nothing is lost.
|
|
329
430
|
|
|
330
|
-
**
|
|
331
|
-
|
|
431
|
+
**"This machine has N commits that were never pushed."** Pulling would throw
|
|
432
|
+
them away, so it stops. Run `opencode-sync push`, or `pull --force` to discard
|
|
433
|
+
them.
|
|
332
434
|
|
|
333
|
-
**
|
|
334
|
-
|
|
435
|
+
**Authentication failed.** Run `gh auth login -h github.com`. Private
|
|
436
|
+
repositories need the `repo` scope.
|
|
437
|
+
|
|
438
|
+
**OpenCode will not start after a sync.** This is what the command is for:
|
|
335
439
|
|
|
336
440
|
```bash
|
|
337
441
|
opencode-sync pull --force
|
|
338
442
|
```
|
|
339
443
|
|
|
444
|
+
The files it replaces go to the recovery folder first.
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
## Upgrading from 3.1.x
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
npm install -g opencode-github-sync@latest
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
Nothing else is required: your settings, overrides and repository keep
|
|
455
|
+
working, and autosync stays off until you turn it on. If you were using a
|
|
456
|
+
script of your own to sync on a timer, remove it before turning autosync on so
|
|
457
|
+
the two do not compete. If you used `autoPushOnIdle` in the plugin, autosync
|
|
458
|
+
replaces it on machines where you turn it on.
|
|
459
|
+
|
|
340
460
|
---
|
|
341
461
|
|
|
342
462
|
## Development
|
|
343
463
|
|
|
344
464
|
```bash
|
|
345
465
|
npm install
|
|
346
|
-
npm run check # lint
|
|
466
|
+
npm run check # lint, typecheck and tests
|
|
347
467
|
npm run build
|
|
348
468
|
```
|
|
349
469
|
|
|
350
|
-
The
|
|
351
|
-
|
|
352
|
-
|
|
470
|
+
The tests run against real git repositories on disk and simulate several
|
|
471
|
+
machines, so pushing, pulling, rebasing, autosync scheduling and the menu are
|
|
472
|
+
exercised end to end. Real scheduled jobs are only ever registered on
|
|
473
|
+
disposable CI runners.
|
|
353
474
|
|
|
354
475
|
---
|
|
355
476
|
|
|
@@ -367,7 +488,7 @@ round-trip are all exercised end to end.
|
|
|
367
488
|
|
|
368
489
|
## License
|
|
369
490
|
|
|
370
|
-
[MIT](
|
|
491
|
+
[MIT](https://github.com/doomsday616/opencode-github-sync/blob/main/LICENSE)
|
|
371
492
|
|
|
372
493
|
<p align="center">
|
|
373
494
|
<sub>If this saved you some time, a ⭐ is appreciated.</sub>
|