opencode-github-sync 3.2.0 → 3.3.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.
Files changed (65) hide show
  1. package/README.md +353 -159
  2. package/README.zh-CN.md +246 -100
  3. package/dist/cli/i18n.d.ts +10 -0
  4. package/dist/cli/i18n.d.ts.map +1 -1
  5. package/dist/cli/i18n.js +24 -4
  6. package/dist/cli/i18n.js.map +1 -1
  7. package/dist/cli/index.js +50 -1
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/core/autosync.d.ts +2 -0
  10. package/dist/core/autosync.d.ts.map +1 -1
  11. package/dist/core/autosync.js +9 -0
  12. package/dist/core/autosync.js.map +1 -1
  13. package/dist/core/categories.js +1 -1
  14. package/dist/core/categories.js.map +1 -1
  15. package/dist/core/credentials.d.ts +40 -0
  16. package/dist/core/credentials.d.ts.map +1 -0
  17. package/dist/core/credentials.js +364 -0
  18. package/dist/core/credentials.js.map +1 -0
  19. package/dist/core/fsx.d.ts +2 -0
  20. package/dist/core/fsx.d.ts.map +1 -1
  21. package/dist/core/fsx.js +6 -0
  22. package/dist/core/fsx.js.map +1 -1
  23. package/dist/core/lease.d.ts +52 -0
  24. package/dist/core/lease.d.ts.map +1 -0
  25. package/dist/core/lease.js +235 -0
  26. package/dist/core/lease.js.map +1 -0
  27. package/dist/core/projects.d.ts +79 -0
  28. package/dist/core/projects.d.ts.map +1 -0
  29. package/dist/core/projects.js +192 -0
  30. package/dist/core/projects.js.map +1 -0
  31. package/dist/core/repair.d.ts +44 -0
  32. package/dist/core/repair.d.ts.map +1 -0
  33. package/dist/core/repair.js +81 -0
  34. package/dist/core/repair.js.map +1 -0
  35. package/dist/core/repo.d.ts +20 -2
  36. package/dist/core/repo.d.ts.map +1 -1
  37. package/dist/core/repo.js +65 -3
  38. package/dist/core/repo.js.map +1 -1
  39. package/dist/core/rows.d.ts +36 -0
  40. package/dist/core/rows.d.ts.map +1 -0
  41. package/dist/core/rows.js +75 -0
  42. package/dist/core/rows.js.map +1 -0
  43. package/dist/core/sessions.d.ts +32 -4
  44. package/dist/core/sessions.d.ts.map +1 -1
  45. package/dist/core/sessions.js +316 -104
  46. package/dist/core/sessions.js.map +1 -1
  47. package/dist/core/settings.d.ts +6 -0
  48. package/dist/core/settings.d.ts.map +1 -1
  49. package/dist/core/settings.js +1 -0
  50. package/dist/core/settings.js.map +1 -1
  51. package/dist/core/sqlite.d.ts +2 -0
  52. package/dist/core/sqlite.d.ts.map +1 -1
  53. package/dist/core/sqlite.js +14 -0
  54. package/dist/core/sqlite.js.map +1 -1
  55. package/dist/core/stage.d.ts +14 -1
  56. package/dist/core/stage.d.ts.map +1 -1
  57. package/dist/core/stage.js +63 -3
  58. package/dist/core/stage.js.map +1 -1
  59. package/dist/core/sync.d.ts.map +1 -1
  60. package/dist/core/sync.js +66 -16
  61. package/dist/core/sync.js.map +1 -1
  62. package/dist/plugin/index.d.ts.map +1 -1
  63. package/dist/plugin/index.js +2 -2
  64. package/dist/plugin/index.js.map +1 -1
  65. package/package.json +4 -4
package/README.md CHANGED
@@ -1,218 +1,268 @@
1
1
  <p align="center">
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">
2
+ <img src="https://raw.githubusercontent.com/lazyalex616/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
- <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="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>
7
+ <a href="https://github.com/lazyalex616/opencode-github-sync/actions/workflows/ci.yml"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/lazyalex616/opencode-github-sync/ci.yml?style=flat-square&color=9ece6a&labelColor=1a1e2b&label=ci"></a>
8
+ <a href="https://github.com/lazyalex616/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
+ <img alt="OpenCode" src="https://img.shields.io/badge/OpenCode-1.x%20·%202.x-e0af68?style=flat-square&labelColor=1a1e2b">
10
11
  </p>
11
12
 
12
13
  <p align="center">
13
- <a href="https://github.com/doomsday616/opencode-github-sync/blob/main/README.zh-CN.md">简体中文</a>
14
+ <a href="https://github.com/lazyalex616/opencode-github-sync/blob/main/README.zh-CN.md">简体中文</a>
14
15
  &nbsp;·&nbsp;
15
16
  <a href="#install">Install</a>
16
17
  &nbsp;·&nbsp;
17
- <a href="#pick-your-setup">Setup</a>
18
+ <a href="#opencode-2">OpenCode 2</a>
18
19
  &nbsp;·&nbsp;
19
- <a href="#how-autosync-works">Autosync</a>
20
+ <a href="#autosync">Autosync</a>
20
21
  &nbsp;·&nbsp;
21
- <a href="#command-reference">Commands</a>
22
+ <a href="#commands">Commands</a>
22
23
  &nbsp;·&nbsp;
23
24
  <a href="#troubleshooting">Troubleshooting</a>
24
25
  </p>
25
26
 
26
27
  ---
27
28
 
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.
29
+ You use OpenCode on more than one computer, and every machine drifts: a new
30
+ agent here, an MCP server there, a skill you installed on the laptop and forgot
31
+ on the desktop.
32
+
33
+ **opencode-github-sync** keeps all of them on one setup through a private
34
+ GitHub repository. Run it by hand when you want, or let your everyday machines
35
+ sync themselves in the background. It works with OpenCode 1 and OpenCode 2,
36
+ and both can share the same repository.
37
+
38
+ **What you get**
39
+
40
+ - Config, instruction files, agents, commands, plugins, themes and skills on
41
+ every machine.
42
+ - Optionally your logins and your recent conversations, too.
43
+ - Settings that belong to one machine stay on that machine.
44
+ - Nothing is overwritten without a copy kept first, and a broken sync can be
45
+ repaired from the command line even when OpenCode will not start.
46
+
47
+ ## Contents
48
+
49
+ - [Install](#install)
50
+ - [First run](#first-run)
51
+ - [What gets synced](#what-gets-synced)
52
+ - [OpenCode 2](#opencode-2)
53
+ - [Autosync](#autosync)
54
+ - [Per-machine overrides](#per-machine-overrides)
55
+ - [Sessions](#sessions)
56
+ - [Credentials](#credentials)
57
+ - [Safety](#safety)
58
+ - [The menu](#the-menu)
59
+ - [OpenCode plugin](#opencode-plugin)
60
+ - [Commands](#commands)
61
+ - [Settings file](#settings-file)
62
+ - [Troubleshooting](#troubleshooting)
63
+ - [Upgrading](#upgrading)
64
+ - [Development](#development)
30
65
 
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.
66
+ ---
34
67
 
35
68
  ## Install
36
69
 
37
70
  **macOS / Linux**
38
71
 
39
72
  ```bash
40
- curl -fsSL https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/install.sh | sh
73
+ curl -fsSL https://raw.githubusercontent.com/lazyalex616/opencode-github-sync/main/install.sh | sh
41
74
  ```
42
75
 
43
76
  **Windows** (PowerShell 5.1 or 7)
44
77
 
45
78
  ```powershell
46
- irm https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/install.ps1 | iex
79
+ irm https://raw.githubusercontent.com/lazyalex616/opencode-github-sync/main/install.ps1 | iex
47
80
  ```
48
81
 
49
82
  The installer checks for Node.js 18+ and git. If one is missing it shows the
50
83
  command that would install it and asks before running anything. Then it runs
51
84
  `npm install -g opencode-github-sync@latest` and opens the menu.
52
85
 
53
- Already have Node.js? `npm install -g opencode-github-sync` and then
54
- `opencode-sync` does the same thing.
86
+ Already have Node.js? This does the same:
87
+
88
+ ```bash
89
+ npm install -g opencode-github-sync
90
+ opencode-sync
91
+ ```
92
+
93
+ **Requirements**
94
+
95
+ | | Needed for |
96
+ | --- | --- |
97
+ | Node.js 18 or newer | everything |
98
+ | Node.js 22.5 or newer | sessions, and credentials on OpenCode 2 (they use Node's built-in SQLite) |
99
+ | git | everything |
100
+ | GitHub CLI (`gh`), signed in | only `init`, which creates the repository for you |
101
+ | OpenCode 1.3.4+ or 2.x | the optional plugin |
55
102
 
56
103
  ### Set up a machine in one line
57
104
 
58
- Pass options to skip the questions, for example when provisioning a new
105
+ Pass options to skip every question, for example when preparing a new
59
106
  machine:
60
107
 
61
108
  ```bash
62
- curl -fsSL https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/install.sh | sh -s -- --mode auto --repo you/my-opencode-config
109
+ curl -fsSL https://raw.githubusercontent.com/lazyalex616/opencode-github-sync/main/install.sh | sh -s -- --mode auto --repo you/my-opencode-config
63
110
  ```
64
111
 
65
112
  ```powershell
66
- & ([scriptblock]::Create((irm https://raw.githubusercontent.com/doomsday616/opencode-github-sync/main/install.ps1))) -Mode auto -Repo you/my-opencode-config
113
+ & ([scriptblock]::Create((irm https://raw.githubusercontent.com/lazyalex616/opencode-github-sync/main/install.ps1))) -Mode auto -Repo you/my-opencode-config
67
114
  ```
68
115
 
69
116
  | Option | Meaning |
70
117
  | --- | --- |
71
- | `--mode cli` / `-Mode cli` | Install the command only |
118
+ | `--mode cli` | Install the command only |
72
119
  | `--mode link` | Link `--repo` and sync once |
73
120
  | `--mode auto` | Link, sync once and turn on autosync |
74
121
  | `--repo owner/name` | The repository (a git URL works too); created as private if it does not exist |
75
122
  | `--interval N` | Autosync every N minutes (minimum 2, default 5) |
76
123
  | `--lang en` / `zh-CN` | Interface language |
77
124
  | `--proxy URL` | Proxy for npm and git, during install and for later syncs |
78
- | `--yes` | Install missing Node.js or git without asking |
125
+ | `--yes` | Install a missing Node.js or git without asking |
79
126
  | `--package SPEC` | npm package spec to install (default `opencode-github-sync@latest`) |
80
127
  | `--dry-run` | Print what would run, change nothing |
81
128
 
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).
129
+ On Windows each option is the same word with one leading dash: `-Mode`,
130
+ `-Repo`, `-Interval`, `-Lang`, `-Proxy`, `-Yes`, `-Package`, `-DryRun`.
88
131
 
89
132
  ---
90
133
 
91
- ## Pick your setup
134
+ ## First run
92
135
 
93
136
  <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">
137
+ <img src="https://raw.githubusercontent.com/lazyalex616/opencode-github-sync/main/docs/images/en/03-pick-your-setup.png" alt="Command only, or primary device with autosync" width="760">
95
138
  </p>
96
139
 
97
- The first time you run `opencode-sync` it asks how this machine should work.
140
+ The first time you run `opencode-sync` it asks how this machine should work:
98
141
 
99
142
  | | Command only | Primary device + autosync |
100
143
  | --- | --- | --- |
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 |
144
+ | How it syncs | You run `opencode-sync push` / `pull`, or the plugin pulls when OpenCode starts | The operating system syncs every few minutes, even while OpenCode is closed |
102
145
  | Good for | A machine you use now and then, a shared or locked-down machine | The machines you work on every day |
103
146
  | Background job | None | Task Scheduler, launchd or a systemd timer |
104
147
 
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.
107
-
108
- ---
148
+ Then it links a repository:
109
149
 
110
- ## The menu
150
+ - **No repository yet?** It creates a private one with `gh` (or run
151
+ `opencode-sync init`).
152
+ - **Already have one?** Pick it from the list, or give `owner/name` or any git
153
+ URL (or run `opencode-sync link owner/name`).
111
154
 
112
- Run `opencode-sync` with no arguments.
113
-
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 |
155
+ If the repository already has content and this machine has its own files, the
156
+ menu shows the differences and lets you pick a side. The losing side's files
157
+ are copied to the [recovery folder](#safety) first.
138
158
 
139
- Every command from earlier versions still works and is still scriptable.
159
+ You can change your mind any time under **Autosync**. Autosync is per machine:
160
+ turning it on here never turns it on anywhere else.
140
161
 
141
162
  ---
142
163
 
143
164
  ## What gets synced
144
165
 
145
166
  <p align="center">
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">
167
+ <img src="https://raw.githubusercontent.com/lazyalex616/opencode-github-sync/main/docs/images/en/02-how-it-works.png" alt="Each machine pushes and pulls through one private repository" width="760">
147
168
  </p>
148
169
 
149
170
  Your `~/.config/opencode` folder becomes a working copy of the repository.
150
- Everything else is mirrored into a folder inside it.
171
+ Everything that lives elsewhere is mirrored into a folder inside it.
151
172
 
152
173
  | On your machine | In the repository | What it holds |
153
174
  | --- | --- | --- |
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 |
175
+ | `~/.config/opencode/` | the root | `opencode.json(c)`, `tui.json(c)`, OpenCode 2's `cli.json`, agents, commands, plugins, themes, instruction files |
176
+ | `~/.local/share/opencode/` | `_data/` | project metadata; logins if you [opt in](#credentials) |
177
+ | `~/.local/state/opencode/` | `_state/` | model cache and other interface state |
157
178
  | `~/.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 |
179
+ | selected sessions | `_sessions/` | one small compressed file per session, if you [opt in](#sessions) |
180
+ | your extra paths | `_extra/` | any other file or folder you add, such as `.config/gh/config.yml` |
160
181
 
161
182
  Each part can be switched off under **What to sync**. A part you switch off
162
183
  stays local in both directions: your edits are not sent, and other machines'
163
184
  versions do not replace yours.
164
185
 
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.
186
+ **Never synced**
187
+
188
+ - The `opencode.db` database itself, tool output, snapshots and logs. Sessions
189
+ travel as separate small files instead.
190
+ - `node_modules` and other generated folders.
191
+ - opencode-sync's own settings and overrides files.
192
+ - Anything that describes one machine rather than your setup: OpenCode 2's
193
+ `service.json` (one in the config folder and one in the state folder; each
194
+ holds the local background service's password), lock files, prompt history,
195
+ recent-file lists, and `cli.json` plugin entries that point into this
196
+ machine's home folder.
168
197
 
169
198
  ---
170
199
 
171
- ## How autosync works
200
+ ## OpenCode 2
201
+
202
+ opencode-github-sync 3.3.0 and later support OpenCode 2 (`@opencode/cli`) fully.
203
+ Machines on OpenCode 1 and OpenCode 2 can use one repository side by side.
204
+
205
+ What is different on OpenCode 2, and what this tool does about it:
206
+
207
+ | OpenCode 2 changed | What opencode-sync does |
208
+ | --- | --- |
209
+ | Sessions live in new tables, and a fresh OpenCode 2 database has no old ones | Reads and writes OpenCode 2's own tables. OpenCode 1 machines keep their own format; each side imports only its own kind and leaves the other's in place |
210
+ | `/session` lists only the sessions of the current folder's project | Each imported session is placed in the project OpenCode 2 uses for that folder on the receiving machine, so it appears in `/session` |
211
+ | Sessions migrated from 1.x can vanish from `/session` | `opencode-sync repair-sessions` moves them back where `/session` looks |
212
+ | Logins live in the database, and `auth.json` is read at most once | With credential sync on, logins are copied between the two around every sync |
213
+ | Interface preferences moved to `cli.json` | Shared as part of the main config, without this machine's plugin paths |
214
+ | A `service.json` with a password sits in the config folder | Never committed, and removed from repositories an older version wrote it into |
215
+ | Configuration reloads by itself | The "restart OpenCode" hint only appears where a restart is still needed: OpenCode 1, or a changed plugin |
216
+
217
+ To move a machine from OpenCode 1 to 2, see [Upgrading to OpenCode 2](#upgrading-to-opencode-2).
218
+
219
+ ---
220
+
221
+ ## Autosync
172
222
 
173
223
  <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">
224
+ <img src="https://raw.githubusercontent.com/lazyalex616/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
225
  </p>
176
226
 
177
227
  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:
228
+ every few minutes and at sign-in (on Windows also when you unlock the screen or
229
+ reconnect over Remote Desktop). Each run makes one decision:
180
230
 
181
- 1. **Is it quiet?** If any file in your config or skills folders changed in the
231
+ 1. **Is it quiet?** If a file in your config or skills folders changed in the
182
232
  last minute, something is still being written. Sending now could publish a
183
233
  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.
234
+ 2. **Can it at least receive?** While you are busy it still takes other
235
+ machines' changes, but only when this machine has nothing of its own
236
+ waiting. Otherwise everything waits for the next run.
237
+ 3. **Push and receive.** Your changes go up and other machines' changes come
238
+ down in one step.
239
+
240
+ The rules that keep it safe:
241
+
242
+ - **Machines take turns.** Each machine waits a few seconds, fixed per machine,
243
+ so two machines on the same schedule do not collide every time. If another
244
+ machine still gets there first, this one takes the new commit and tries
245
+ again; that does not count as an error.
246
+ - **It backs off but never gives up.** After three failures in a row (usually
247
+ no network) it waits 30 minutes, then an hour between attempts. The first
248
+ success puts it back on schedule.
249
+ - **It interrupts you twice at most.** One notification when it starts backing
250
+ off, one when it recovers. Ordinary syncs are silent.
251
+ - **It never runs twice at once.** One lock is shared by the scheduled job, the
252
+ command, the menu and every OpenCode window; whoever finds it busy skips.
253
+ - **It never approves a large change by itself.** Anything that trips the
254
+ [large-change guard](#safety) is held back and you get a notification.
255
+ - **It renews a shared ChatGPT login.** See [Credentials](#credentials).
206
256
 
207
257
  | Platform | Scheduler | Notes |
208
258
  | --- | --- | --- |
209
- | Windows | Task Scheduler | Runs hidden. To run while signed out, turn that on in the menu and install from an administrator terminal |
259
+ | Windows | Task Scheduler | Runs hidden. To run while signed out, turn it on in the menu and install from an administrator terminal |
210
260
  | macOS | launchd agent | `~/Library/LaunchAgents/com.opencode-github-sync.autosync.plist` |
211
261
  | 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
262
 
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.
263
+ `opencode-sync autosync status` shows the last run, the last error and the next
264
+ attempt. With autosync on, the plugin stops pushing on idle so the two never
265
+ compete; it still pulls when OpenCode starts.
216
266
 
217
267
  ---
218
268
 
@@ -240,16 +290,16 @@ overrides** in the menu:
240
290
  ```
241
291
 
242
292
  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
293
+ key. Before every push, each key the overrides file claims is put back to the
244
294
  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
295
+ Without an overrides file the config is copied exactly as written, comments
246
296
  and all.
247
297
 
248
298
  ---
249
299
 
250
300
  ## Sessions
251
301
 
252
- Off by default. Only turn it on for a private repository: conversations are
302
+ Off by default. Turn it on only for a private repository: conversations are
253
303
  private.
254
304
 
255
305
  ```bash
@@ -260,45 +310,94 @@ opencode-sync sessions exclude ses_0ba19b4e7ffeMbSmWYi3Nj6xfZ # never sync this
260
310
  ```
261
311
 
262
312
  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.
313
+ grows to several gigabytes, mostly tool output, and git cannot merge it.
314
+ Instead each session is exported on its own as a small compressed file:
315
+
316
+ - **Small.** Only recent sessions travel (7 days and 50 sessions by default),
317
+ and any single session over 5 MB is skipped.
318
+ - **Conflicts are rare and resolved.** Two machines working on different
319
+ sessions touch different files. When one session changed on two machines, the
320
+ newer copy wins; on OpenCode 2 the replaced local copy is saved to the
321
+ recovery folder first if it had messages the newer one lacks.
322
+ - **Never disturbs a running conversation.** A session that is busy on this
323
+ machine is not replaced, and runtime state (busy, compacting, retry counters)
324
+ is never carried over, so a receiving machine never resumes a conversation on
325
+ its own.
326
+ - **Lands in the right place.** On OpenCode 2 an imported session is placed in
327
+ the project OpenCode 2 uses for its folder here. A folder under the other
328
+ machine's home is matched to the same folder under yours; a folder this
329
+ machine does not have puts the session in your home folder's project.
330
+ - **Safe to import.** Each session is imported in one transaction, so a failure
331
+ leaves your database as it was.
273
332
 
274
333
  Window, count and size limits are under **What to sync → Session settings**.
275
- Session sync needs Node.js 22.5 or newer.
334
+ Sessions need Node.js 22.5 or newer.
335
+
336
+ **Sessions missing from `/session` after upgrading to OpenCode 2?** OpenCode's
337
+ own migration leaves some of them in a project `/session` never shows. Their
338
+ content is intact:
339
+
340
+ ```bash
341
+ opencode-sync repair-sessions # preview: what would move where
342
+ opencode-sync repair-sessions --apply # move them
343
+ ```
276
344
 
277
345
  ---
278
346
 
279
- ## Safety features
347
+ ## Credentials
348
+
349
+ Off by default, and refused outright when the repository is public. Turn it on
350
+ under **What to sync → Credentials** or with `"includeCredentials": true`.
351
+
352
+ On OpenCode 1, `auth.json` is synced as a file. On OpenCode 2, which keeps
353
+ logins in its database, opencode-sync also copies between the database and
354
+ `auth.json` around every sync:
355
+
356
+ - The account you pick in OpenCode (for example after `/connect` or switching
357
+ accounts) is what the other machines receive. A running OpenCode picks up an
358
+ incoming account on its next request, without a restart.
359
+ - A renewed login updates the existing account instead of adding a copy. When
360
+ both sides changed, the one that expires later wins.
361
+ - An account missing from an incoming copy never logs this machine out.
362
+ Logging out on a machine removes that account from the shared copy.
363
+ - A broken or half-written `auth.json` is never overwritten.
364
+ - To tell which side changed, only hashes of the last synced values are kept,
365
+ in `opencode-sync-credentials.json` next to the database. Never the secrets.
366
+
367
+ **Shared ChatGPT login.** Renewing an OpenAI login invalidates the previous
368
+ one, so machines that each renew the same login log each other out. With
369
+ credential sync on, only one machine renews it: the scheduled job claims a
370
+ lease in the sync repository (an atomic operation on GitHub's side), renews
371
+ three days before the login expires, and the next sync hands the new login to
372
+ every other machine. A claim older than 15 minutes is considered abandoned and
373
+ can be taken over. Set `"openaiRefreshLease": false` to turn this off.
374
+
375
+ ---
376
+
377
+ ## Safety
280
378
 
281
379
  <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">
380
+ <img src="https://raw.githubusercontent.com/lazyalex616/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
381
  </p>
284
382
 
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
383
+ - **All-or-nothing writes.** Files are written beside their target and then
384
+ swapped in, so a crash mid-sync cannot leave a half-written config that stops
287
385
  OpenCode from starting.
288
386
  - **Push verification.** After pushing, the remote is read back. `git push`
289
387
  can report success without the remote changing; that is checked, not
290
388
  assumed.
291
- - **One sync at a time.** A lock shared by the plugin, the CLI, the menu and
292
- the scheduled job.
389
+ - **One sync at a time.** A lock shared by the plugin, the command, the menu
390
+ and the scheduled job.
293
391
  - **Large-change guard.** A push that adds more than 300 files, more than
294
392
  10 MB in total, or any single file over 2 MB stops and asks. The limits are
295
393
  adjustable. Generated folders such as `node_modules`, `.venv`, `venv`,
296
394
  `__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
395
+ - **Recovery folder.** Before a forced pull, a "repository wins" first link, a
396
+ restore from history, or replacing a session that was continued on both
397
+ machines, what is about to be replaced is copied to
299
398
  `~/.local/share/opencode/opencode-sync-recovery/<time>-<reason>/`.
300
- - **Credentials are opt-in** and refused outright when the repository is
301
- public.
399
+ - **Machine secrets stay home.** OpenCode 2's `service.json`, lock files and
400
+ per-machine histories are never committed.
302
401
  - **Your hostname stays private.** Commits name the machine by a stable
303
402
  pseudonym (or a name you choose), never by its real hostname.
304
403
  - **Symlinks are refused, not followed**, so a sync cannot copy files from
@@ -306,6 +405,37 @@ Session sync needs Node.js 22.5 or newer.
306
405
 
307
406
  ---
308
407
 
408
+ ## The menu
409
+
410
+ Run `opencode-sync` with no arguments.
411
+
412
+ <p align="center">
413
+ <img src="https://raw.githubusercontent.com/lazyalex616/opencode-github-sync/main/docs/menu.svg" alt="The opencode-sync menu" width="760">
414
+ </p>
415
+
416
+ Arrow keys or the shown hotkey pick an item, space ticks a checkbox, Enter
417
+ confirms and Esc goes back. When the input is not a terminal (a pipe, a script,
418
+ CI) every prompt becomes a numbered question, so the menu can be driven from a
419
+ file.
420
+
421
+ | Item | What you can do there |
422
+ | --- | --- |
423
+ | **Sync now** | Push and receive, receive only, push only, or preview first |
424
+ | **What to sync** | Tick main config, instruction files, agents, commands, plugins, skills, credentials, sessions; set session limits; add extra paths |
425
+ | **Autosync** | On or off; every 5/10/15/30/60 minutes or your own interval; pause; run while signed out (Windows); notifications |
426
+ | **Update** | Check npm for a newer version, upgrade, or update automatically once a day |
427
+ | **This machine's overrides** | Open the overrides file in your editor and see what it changes |
428
+ | **Diagnostics** | git, node, gh, repository access, the scheduled job, the last log lines; export a support bundle |
429
+ | **Danger zone** | Make this machine match the repository, or the other way round (type `overwrite` to confirm) |
430
+ | **Uninstall** | Remove the scheduled job, optionally unlink and remove the command. Your configuration is never deleted |
431
+ | **Network proxy** | A proxy for git, gh and npm, used only by opencode-sync |
432
+ | **Restore a file from history** | Pick a file, pick a version, put it back |
433
+ | **Devices** | Every machine that has synced and when; rename this one |
434
+ | **Large-change guard** | The limits that make a big push stop and ask |
435
+ | **Language** | English, 简体中文 or automatic |
436
+
437
+ ---
438
+
309
439
  ## OpenCode plugin
310
440
 
311
441
  The plugin is optional. It pulls when OpenCode starts, can push when a session
@@ -320,22 +450,19 @@ language.
320
450
  }
321
451
  ```
322
452
 
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.
328
-
329
- OpenCode 1.0–1.3.3 cannot load 3.1.0 and later; stay on
330
- `opencode-github-sync@3.0.1` there.
453
+ The `"plugin"` key works on OpenCode 1.x (1.3.4 and later) and 2.x. If you run
454
+ only OpenCode 2 you can use its native `"plugins"` key instead, but do not list
455
+ the plugin under both: OpenCode 2 loads entries from both lists. OpenCode
456
+ 1.0–1.3.3 cannot load 3.1.0 and later; stay on `opencode-github-sync@3.0.1`
457
+ there.
331
458
 
332
459
  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
460
+ a configuration that stops OpenCode from loading it; `opencode-sync pull
334
461
  --force` can.
335
462
 
336
463
  ---
337
464
 
338
- ## Command reference
465
+ ## Commands
339
466
 
340
467
  | Command | What it does |
341
468
  | --- | --- |
@@ -354,6 +481,7 @@ the configuration that stops OpenCode from loading it; `opencode-sync pull
354
481
  | `opencode-sync autosync reset` | Clear the failure counter |
355
482
  | `opencode-sync sessions list\|enable\|disable` | Session sync |
356
483
  | `opencode-sync sessions include\|exclude <id>` | Always or never sync one session |
484
+ | `opencode-sync repair-sessions [--apply]` | OpenCode 2: move sessions missing from `/session` into their project (preview without `--apply`) |
357
485
  | `opencode-sync overrides` | Create or locate the overrides file |
358
486
  | `opencode-sync config` | Print the settings |
359
487
 
@@ -373,7 +501,9 @@ the configuration that stops OpenCode from loading it; `opencode-sync pull
373
501
  | `SYNC_REMOTE_URL` | Override the repository URL |
374
502
  | `NO_COLOR` | Plain output |
375
503
 
376
- ### Settings file
504
+ ---
505
+
506
+ ## Settings file
377
507
 
378
508
  `~/.config/opencode/opencode-sync.jsonc` stays on this machine and is never
379
509
  committed. The menu edits it for you; every key is optional.
@@ -383,6 +513,7 @@ committed. The menu edits it for you; every key is optional.
383
513
  "repo": { "owner": "you", "name": "my-opencode-config", "branch": "main" },
384
514
  "machineAlias": "laptop",
385
515
  "includeCredentials": false,
516
+ "openaiRefreshLease": true,
386
517
  "includeSkills": true,
387
518
  "includeState": true,
388
519
  "extraPaths": [".config/gh/config.yml"],
@@ -398,23 +529,36 @@ committed. The menu edits it for you; every key is optional.
398
529
  }
399
530
  ```
400
531
 
532
+ | Key | Meaning |
533
+ | --- | --- |
534
+ | `machineAlias` | Name for this machine in commits; unset means a stable pseudonym |
535
+ | `includeCredentials` | Sync logins ([Credentials](#credentials)); private repositories only |
536
+ | `openaiRefreshLease` | With credentials on, let one machine at a time renew a shared ChatGPT login |
537
+ | `includeSkills` / `includeState` | Sync `~/.agents/skills` / `~/.local/state/opencode` |
538
+ | `extraPaths` | Extra files or folders, relative to your home folder |
539
+ | `categories` | Which parts of the config folder are shared |
540
+ | `sessions` | [Session](#sessions) window, count and size limits |
541
+ | `autosync` | [Autosync](#autosync) interval, quiet period, run while signed out, daily self-update |
542
+ | `guard` | [Large-change guard](#safety) limits |
543
+ | `autoPullOnStartup` / `autoPushOnIdle` | What the [plugin](#opencode-plugin) does |
544
+
401
545
  ---
402
546
 
403
547
  ## Troubleshooting
404
548
 
405
549
  **I am behind a proxy.** Pass `--proxy http://host:port` (or `-Proxy` on
406
550
  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**.
551
+ saved for later syncs, including the ChatGPT login renewal. Change it any time
552
+ under **Network proxy**.
408
553
 
409
554
  **`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.
555
+ pipe, so it reads your answers from the terminal instead. Where there is no
556
+ terminal (CI, a Dockerfile) nobody can answer: pass `--mode` and `--repo`, plus
557
+ `--yes` if Node.js or git may need installing.
413
558
 
414
559
  **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`.
560
+ script file, so the execution policy does not apply. To run a downloaded
561
+ `install.ps1` as a file, use `powershell -ExecutionPolicy Bypass -File install.ps1`.
418
562
 
419
563
  **`opencode-sync` is not found after installing.** npm installed it into a
420
564
  folder that is not on your `PATH`. `npm prefix -g` shows the folder; add its
@@ -425,6 +569,19 @@ shows whether it is paused, backing off after errors, or waiting because files
425
569
  are still changing. **Diagnostics** in the menu shows whether the scheduled job
426
570
  is registered.
427
571
 
572
+ **A synced session does not show up in `/session` (OpenCode 2).** Open
573
+ OpenCode in the session's folder; `/session` lists only that folder's project.
574
+ Sessions from before your upgrade to OpenCode 2: run
575
+ `opencode-sync repair-sessions --apply`.
576
+
577
+ **Sessions are not synced at all.** Check `opencode-sync status` shows session
578
+ sync as on, and that `node --version` is 22.5 or newer.
579
+
580
+ **A login did not arrive on another machine (OpenCode 2).** Credentials must be
581
+ on for both machines. Run a sync on the machine where you logged in, then on
582
+ the other one. If two accounts of one provider are both marked active, nothing
583
+ is changed for that provider; switch accounts once in OpenCode to settle it.
584
+
428
585
  **A pull conflicted with my local edits.** Your edits are kept in a git stash
429
586
  and the exact commands to get them back are printed. Nothing is lost.
430
587
 
@@ -445,17 +602,53 @@ The files it replaces go to the recovery folder first.
445
602
 
446
603
  ---
447
604
 
448
- ## Upgrading from 3.1.x
605
+ ## Upgrading
606
+
607
+ ### Upgrading to OpenCode 2
608
+
609
+ Upgrade opencode-github-sync to 3.3.0 or later on every machine first. 3.2.x
610
+ cannot read OpenCode 2 sessions, and it commits OpenCode 2's `service.json`.
611
+
612
+ 1. Install OpenCode 2. With npm 12 its install scripts must be allowed, or the
613
+ `opencode` command is only a placeholder:
614
+
615
+ ```bash
616
+ npm install -g @opencode/cli --allow-scripts=@opencode/cli
617
+ ```
618
+
619
+ 2. Optionally stop OpenCode 2 from updating itself in the background; an
620
+ unattended self-update through npm 12 can break the install:
621
+
622
+ ```bash
623
+ opencode service set env OPENCODE_DISABLE_AUTOUPDATE 1
624
+ ```
625
+
626
+ 3. Start OpenCode 2 once so it migrates your 1.x data, then bring back the
627
+ sessions `/session` no longer shows:
628
+
629
+ ```bash
630
+ opencode-sync repair-sessions # preview
631
+ opencode-sync repair-sessions --apply
632
+ ```
633
+
634
+ **If you synced with 3.2.x on OpenCode 2**, your repository may contain
635
+ `service.json` and `_state/service.json`. 3.3.0 removes them on its next push,
636
+ but they stay in the repository's history. The password in them only opens the
637
+ local background service of that machine. To remove them from history as well,
638
+ delete the repository and push again from one machine.
639
+
640
+ ### Upgrading from 3.1.x or 3.2.x
449
641
 
450
642
  ```bash
451
643
  npm install -g opencode-github-sync@latest
452
644
  ```
453
645
 
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.
646
+ Nothing else is required: settings, overrides and the repository keep working,
647
+ and autosync stays off until you turn it on. If you sync on a timer with a
648
+ script of your own, remove it before turning autosync on so the two do not
649
+ compete. If you used `autoPushOnIdle` in the plugin, autosync replaces it on
650
+ machines where you turn it on. The [changelog](./CHANGELOG.md) lists every
651
+ change.
459
652
 
460
653
  ---
461
654
 
@@ -469,18 +662,19 @@ npm run build
469
662
 
470
663
  The tests run against real git repositories on disk and simulate several
471
664
  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.
665
+ exercised end to end. Session and credential tests use the schema of a real
666
+ OpenCode 2.2.5 database and fake tokens only. Real scheduled jobs are only ever
667
+ registered on disposable CI runners.
474
668
 
475
669
  ---
476
670
 
477
671
  ## Star history
478
672
 
479
- <a href="https://star-history.com/#doomsday616/opencode-github-sync&Date">
673
+ <a href="https://star-history.com/#lazyalex616/opencode-github-sync&Date">
480
674
  <picture>
481
- <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=doomsday616/opencode-github-sync&type=Date&theme=dark">
482
- <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=doomsday616/opencode-github-sync&type=Date">
483
- <img alt="Star history chart" src="https://api.star-history.com/svg?repos=doomsday616/opencode-github-sync&type=Date" width="640">
675
+ <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=lazyalex616/opencode-github-sync&type=Date&theme=dark">
676
+ <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=lazyalex616/opencode-github-sync&type=Date">
677
+ <img alt="Star history chart" src="https://api.star-history.com/svg?repos=lazyalex616/opencode-github-sync&type=Date" width="640">
484
678
  </picture>
485
679
  </a>
486
680
 
@@ -488,7 +682,7 @@ disposable CI runners.
488
682
 
489
683
  ## License
490
684
 
491
- [MIT](https://github.com/doomsday616/opencode-github-sync/blob/main/LICENSE)
685
+ [MIT](https://github.com/lazyalex616/opencode-github-sync/blob/main/LICENSE)
492
686
 
493
687
  <p align="center">
494
688
  <sub>If this saved you some time, a ⭐ is appreciated.</sub>